Example #1
0
 public function save($check_notify = false)
 {
     //if probability is empty, set it based on the sales stage
     if ($this->probability === '' && !empty($this->sales_stage)) {
         $this->mapProbabilityFromSalesStage();
     }
     //if the id is set (previously saved bean) and sales_status is still New, update to in progress
     if (isset($this->id) && !$this->new_with_id && $this->sales_status == Opportunity::STATUS_NEW) {
         $this->sales_status = Opportunity::STATUS_IN_PROGRESS;
     }
     // verify that base_rate is set to the correct amount, moved in from SugarBean
     // as we need this to run before perform_save (which does calculations with base_rate)
     if (isset($this->field_defs['currency_id']) && isset($this->field_defs['base_rate'])) {
         SugarCurrency::verifyCurrencyBaseRateSet($this);
     }
     SugarAutoLoader::requireWithCustom('modules/Opportunities/SaveOverload.php');
     perform_save($this);
     return parent::save($check_notify);
 }
Example #2
0
 /**
  * Implements a generic insert and update logic for any SugarBean
  * This method only works for subclasses that implement the same variable names.
  * This method uses the presence of an id field that is not null to signify and update.
  * The id field should not be set otherwise.
  *
  * @param boolean $check_notify Optional, default false, if set to true assignee of the record is notified via email.
  * @todo Add support for field type validation and encoding of parameters.
  */
 function save($check_notify = false)
 {
     $this->in_save = true;
     // cn: SECURITY - strip XSS potential vectors
     $this->cleanBean();
     // This is used so custom/3rd-party code can be upgraded with fewer issues, this will be removed in a future release
     $this->fixUpFormatting();
     global $timedate;
     global $current_user, $action;
     $isUpdate = true;
     if (empty($this->id) || !empty($this->new_with_id)) {
         $isUpdate = false;
     }
     if (empty($this->date_modified) || $this->update_date_modified) {
         $this->date_modified = $GLOBALS['timedate']->nowDb();
     }
     $this->_checkOptimisticLocking($action, $isUpdate);
     if (!empty($this->modified_by_name)) {
         $this->old_modified_by_name = $this->modified_by_name;
     }
     if ($this->update_modified_by) {
         $this->modified_user_id = 1;
         if (!empty($current_user)) {
             $this->modified_user_id = $current_user->id;
             $this->modified_by_name = $current_user->user_name;
         }
     }
     if ($this->deleted != 1) {
         $this->deleted = 0;
     }
     if (!$isUpdate) {
         if (empty($this->date_entered)) {
             $this->date_entered = $this->date_modified;
         }
         if ($this->set_created_by == true) {
             // created by should always be this user
             $this->created_by = isset($current_user) ? $current_user->id : "";
         }
         if ($this->new_with_id == false) {
             $this->id = create_guid();
         }
     }
     // if the module has a team_id field and no team_id is specified, set team_id as the current_user's default team
     // currently, the default_team is only enforced in the presentation layer-- this enforces it at the data layer as well
     $usedDefaultTeam = false;
     if (empty($this->team_id) && isset($this->field_defs['team_id']) && isset($current_user)) {
         $this->team_id = $current_user->team_id;
         $usedDefaultTeam = true;
     }
     // if this bean has a currency_id and base_rate, verify that base_rate is set to the correct amount
     if (isset($this->field_defs['currency_id']) && isset($this->field_defs['base_rate'])) {
         SugarCurrency::verifyCurrencyBaseRateSet($this, $isUpdate);
     }
     require_once "data/BeanFactory.php";
     BeanFactory::registerBean($this);
     if (!static::inOperation('saving_related') && static::enterOperation('updating_relationships')) {
         // let subclasses save related field changes
         $this->save_relationship_changes($isUpdate);
         static::leaveOperation('updating_relationships');
     }
     $this->updateCalculatedFields();
     if ($isUpdate && !$this->update_date_entered) {
         unset($this->date_entered);
     }
     // call the custom business logic
     $custom_logic_arguments = array('check_notify' => $check_notify, 'isUpdate' => $isUpdate);
     $this->call_custom_logic("before_save", $custom_logic_arguments);
     unset($custom_logic_arguments);
     if (isset($this->custom_fields)) {
         $this->custom_fields->bean = $this;
         $this->custom_fields->save($isUpdate);
     }
     //rrs new functionality to check if the team_id is set and the team_set_id is not set,
     //then see what we can do about saving to team_set_id. It is important for this code block to be below
     //the 'before_save' custom logic hook as that is where workflow is called.
     if (isset($this->field_defs['team_id'])) {
         if (empty($this->teams)) {
             $this->load_relationship('teams');
         }
         if (!empty($this->teams)) {
             //we do not need to the TeamSetLink to update the bean's table here
             //since it will be handled below.
             $this->teams->save(false, $usedDefaultTeam);
         }
     }
     // use the db independent query generator
     $this->preprocess_fields_on_save();
     $dataChanges = $this->db->getDataChanges($this);
     //construct the SQL to create the audit record if auditing is enabled.
     $auditDataChanges = array();
     if ($this->is_AuditEnabled()) {
         if ($isUpdate && !isset($this->fetched_row)) {
             $GLOBALS['log']->debug('Auditing: Retrieve was not called, audit record will not be created.');
         } else {
             $auditFields = $this->getAuditEnabledFieldDefinitions();
             $auditDataChanges = array_intersect_key($dataChanges, $auditFields);
         }
     }
     $this->_sendNotifications($check_notify);
     if ($isUpdate) {
         $this->db->update($this);
     } elseif ($this->db->insert($this)) {
         //Now that the record has been saved, we don't want to insert again on further saves
         $this->new_with_id = false;
     }
     if (!empty($auditDataChanges) && is_array($auditDataChanges)) {
         foreach ($auditDataChanges as $change) {
             $this->db->save_audit_records($this, $change);
         }
     }
     $this->updateRelatedCalcFields();
     // populate fetched row with newest changes in the bean
     foreach ($dataChanges as $change) {
         $this->fetched_row[$change['field_name']] = $change['after'];
     }
     // the reason we need to skip this is so that any RelatedBeans that are targeted to be saved
     // after the delete happens, wait to be saved till them.
     if (!static::inOperation('delete')) {
         SugarRelationship::resaveRelatedBeans();
     }
     //rrs - bug 7908
     $this->process_workflow_alerts();
     //rrs
     //If we aren't in setup mode and we have a current user and module, then we track
     if (isset($GLOBALS['current_user']) && isset($this->module_dir)) {
         $this->track_view($current_user->id, $this->module_dir, 'save');
     }
     $this->call_custom_logic('after_save', array('isUpdate' => $isUpdate, 'dataChanges' => $dataChanges));
     $this->in_save = false;
     return $this->id;
 }
Example #3
0
if (empty($focus->id)) {
    // bug 14323, add this to create products firsts, and create the quotes at last,
    // so the workflow can manipulate the products.
    $focus->id = create_guid();
    $focus->new_with_id = true;
}
//remove the relate id element if this is a duplicate
if (isset($_REQUEST['duplicateSave']) && isset($_REQUEST['relate_id'])) {
    //this is a 'create duplicate' quote, keeping the relate_id in focus will assign the quote product bundles
    //to the original quote, not the new duplicate one, so we will unset the element
    unset($_REQUEST['relate_id']);
}
// since the ProductBundles and Products get the BaseRate from the Quote
// make sure it's set correctly before we do any of that processing.
// This will ensure that SugarLogic doesn't do weird conversion.
SugarCurrency::verifyCurrencyBaseRateSet($focus, !$focus->new_with_id);
global $beanFiles;
require_once $beanFiles['Product'];
$GLOBALS['log']->debug("Saving associated products");
$i = 0;
if (isset($_POST['product_count'])) {
    $product_count = $_POST['product_count'];
}
//totals keys is a list of tables for the products bundles
if (isset($_REQUEST['total'])) {
    $total_keys = array_keys($_REQUEST['total']);
} else {
    $total_keys = array();
}
$product_bundels = array();
for ($k = 0; $k < sizeof($total_keys); $k++) {