Greetings all,
I am trying to make the AOS Quotes took automatically generate a quote name at creation, but the module does not seem to recognize logic hooks. When I put the logic_hooks PHP into /custom/modules/AOS_Quotes it does nothing, however if it put it in /custom/modules/AOS_Products_Quotes then it will change the name of the products according to the logic.
Here’s what I have:
<?php
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'GenerateQuoteName', 'custom/modules/AOS_Products_Quotes/QuoteNameGenerator.php','Quote_Name_Generator', 'setname');
?>
and
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); //prevent processing without trggering by sugar
class Quote_Name_Generator
{
function setname($bean)
{
$idin = $bean->id
function sqlcon($sqlobj, $idtoget) //converts sql object to string
{
$arFromSQL = mysqli_fetch_assoc($sqlobj); //converts input object to array
$resFromSQL = $arFromSQL[$idtoget]; //extracts target value
return $resFromSQL;
}
$tsDatefrombean = strtotime(sqlcon($bean->db->query("SELECT date_entered FROM aos_quotes WHERE id = '$idin' LIMIT 1"), "date_entered")); //Get Creation Date
$strUserfound = sqlcon($bean->db->query("SELECT assigned_user_id FROM aos_quotes WHERE id = '$idin' LIMIT 1"), "assigned_user_id"); //Get the NUID for the Creating user
$strUserinits = sqlcon($bean->db->query("SELECT userinitials_c FROM users_cstm WHERE id_c = '$strUserfound' LIMIT 1"), "userinitials_c"); //Get the User Initials from the users database
$strQuoteName = 'Q-' . date('ymd', $tsDatefrombean) . '-' . $strUserinits . $bean->number; //Generate RMA name
$bean->name = $strQuoteName; //Update the Name field to use the RMA name
$bean->save(); //We have to tell the bean to save, since this whole function occurs after the initial save
}
}
?>
While I made this code for a different module entirely, it does still work correctly for a few other modules as well as it will modify product names when I save a quote and have it in the AOS_Products_Quotes module.