diff --git a/custom/modules/Contacts/SticLogicHooksCode.php b/custom/modules/Contacts/SticLogicHooksCode.php index 985d2593c9c..12e2fb87d04 100644 --- a/custom/modules/Contacts/SticLogicHooksCode.php +++ b/custom/modules/Contacts/SticLogicHooksCode.php @@ -24,13 +24,13 @@ class ContactsLogicHooks { public function before_save(&$bean, $event, $arguments) { // Calculate age - if ($bean->birthdate != $bean->fetched_row['birthdate']) { + if (empty($bean->fetched_row) || $bean->birthdate != $bean->fetched_row['birthdate']) { include_once 'custom/modules/Contacts/SticUtils.php'; $bean->stic_age_c = ContactsUtils::getAge($bean->birthdate); } // Bring Incorpora location data, if there is any - if ($bean->fetched_row['stic_incorpora_locations_id_c'] != $bean->stic_incorpora_locations_id_c) { + if (empty($bean->fetched_row) || $bean->fetched_row['stic_incorpora_locations_id_c'] != $bean->stic_incorpora_locations_id_c) { include_once 'modules/stic_Incorpora_Locations/Utils.php'; stic_Incorpora_LocationsUtils::transferLocationData($bean); } @@ -49,7 +49,7 @@ public function after_save(&$bean, $event, $arguments) { // End of Patch issue // Generate automatic Call - if ($bean->stic_postal_mail_return_reason_c != $bean->fetched_row['stic_postal_mail_return_reason_c']) { + if (empty($bean->fetched_row) || $bean->stic_postal_mail_return_reason_c != $bean->fetched_row['stic_postal_mail_return_reason_c']) { include_once 'custom/modules/Contacts/SticUtils.php'; ContactsUtils::generateCallFromReturnMailReason($bean); } diff --git a/custom/modules/Contacts/SticUtils.php b/custom/modules/Contacts/SticUtils.php index 2667e27a7ed..2d9aa4ecc1a 100644 --- a/custom/modules/Contacts/SticUtils.php +++ b/custom/modules/Contacts/SticUtils.php @@ -83,7 +83,7 @@ public static function getAge($birthday) public static function generateCallFromReturnMailReason($contactBean) { $reasons = array('wrong_address', 'unknown', 'rejected'); - if (in_array($contactBean->stic_postal_mail_return_reason_c, $reasons)) { + if (!empty($contactBean->stic_postal_mail_return_reason_c) && in_array($contactBean->stic_postal_mail_return_reason_c, $reasons)) { global $current_user, $timedate, $app_strings; // Create the new call diff --git a/data/SugarBean.php b/data/SugarBean.php index a676884b4b6..9929b97bd3e 100755 --- a/data/SugarBean.php +++ b/data/SugarBean.php @@ -2522,7 +2522,11 @@ public function cleanBean() // STIC Custom - 20221213 - JCH - Trim name & varchar type values on save when the value is not null // STIC#902 // STIC#982 - if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && !is_null($this->$key)) { + // STIC-Custom 20241218 EPS - Avoid using property "key" if it is not setted + // https://github.com/SinergiaTIC/SinergiaCRM/pull/470 + // if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && !is_null($this->$key)) { + if (isset($def['type']) && in_array($def['type'], ['name', 'varchar']) && property_exists($this, $key) && !empty($this->$key)) { + // END STIC-Custom (EPS 20241218) $this->$key = trim($this->$key); } // END STIC diff --git a/modules/stic_Incorpora_Locations/Utils.php b/modules/stic_Incorpora_Locations/Utils.php index 66ace07055c..628ed78e454 100644 --- a/modules/stic_Incorpora_Locations/Utils.php +++ b/modules/stic_Incorpora_Locations/Utils.php @@ -41,12 +41,22 @@ public static function transferLocationData($recordBean) { $inc_state = 'inc_state' .$sufix; $stic_incorpora_locations_id = 'stic_incorpora_locations_id' .$sufix; - $location_bean = BeanFactory::getBean('stic_Incorpora_Locations', $recordBean->$stic_incorpora_locations_id); - $recordBean->$inc_town_code = $location_bean->town_code; - $recordBean->$inc_town = $location_bean->town; - $recordBean->$inc_municipality_code = $location_bean->municipality_code; - $recordBean->$inc_municipality = $location_bean->municipality; - $recordBean->$inc_state_code = $location_bean->state_code; - $recordBean->$inc_state = $location_bean->state; + if(!empty($recordBean->$stic_incorpora_locations_id)) { + $location_bean = BeanFactory::getBean('stic_Incorpora_Locations', $recordBean->$stic_incorpora_locations_id); + $recordBean->$inc_town_code = $location_bean->town_code; + $recordBean->$inc_town = $location_bean->town; + $recordBean->$inc_municipality_code = $location_bean->municipality_code; + $recordBean->$inc_municipality = $location_bean->municipality; + $recordBean->$inc_state_code = $location_bean->state_code; + $recordBean->$inc_state = $location_bean->state; + } + else { + $recordBean->$inc_town_code = ''; + $recordBean->$inc_town = ''; + $recordBean->$inc_municipality_code = ''; + $recordBean->$inc_municipality = ''; + $recordBean->$inc_state_code = ''; + $recordBean->$inc_state = ''; + } } } \ No newline at end of file