Exemplo n.º 1
0
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         $this->productkey = 'GICRM|' . $this->productcode;
         $currencyHelper = Yii::app()->currencyHelper;
         if ($this->costofgoodssold->value == 'Labor') {
             if ($this->departmentreference->id < 0) {
                 $this->addError('departmentreference', Zurmo::t('Core', 'Department Reference cannot be blank'));
                 $currencyHelper->resetErrors();
                 return false;
             } else {
                 $deptRefId = $this->departmentreference->id;
                 $deptRefs = DepartmentReference::getDeptRefById(intval($deptRefId));
                 $this->laborCost = $deptRefs[0]->laborCost;
                 $this->burdenCost = $deptRefs[0]->burdonCost;
                 $this->costperunit = $this->laborCost + $this->burdenCost;
                 $this->unitdirectcost = $this->laborCost + $this->burdenCost;
             }
             if ($this->id < 0) {
                 $this->productcode = 'L-' . $this->productcode;
             }
             return true;
         }
         if ($this->costofgoodssold->value == 'Equipment' || $this->costofgoodssold->value == 'Material' || $this->costofgoodssold->value == 'Subcontractor' || $this->costofgoodssold->value == 'Other') {
             if ($this->unitofmeasure == '(None)') {
                 $this->addError('unitofmeasure', Zurmo::t('Core', 'Please select Unit Of Measure'));
                 $currencyHelper->resetErrors();
                 return false;
             }
             if ($this->costperunit == '') {
                 $this->addError('costperunit', Zurmo::t('Core', 'Cost Rate cannot be blank'));
                 $currencyHelper->resetErrors();
                 return false;
             } else {
                 $cost = floatval($this->costperunit);
                 $this->unitdirectcost = $cost;
             }
             if ($this->id < 0) {
                 if ($this->costofgoodssold->value == 'Equipment') {
                     $this->productcode = 'E-' . $this->productcode;
                 }
                 if ($this->costofgoodssold->value == 'Material') {
                     $this->productcode = 'M-' . $this->productcode;
                 }
                 if ($this->costofgoodssold->value == 'Subcontractor') {
                     $this->productcode = 'S-' . $this->productcode;
                 }
                 if ($this->costofgoodssold->value == 'Other') {
                     $this->productcode = 'O-' . $this->productcode;
                 }
             }
             return true;
         }
         if ($this->costofgoodssold->value == 'Assembly') {
             if (empty($_POST['Costbook']['assemblydetailsearch']['values']) && preg_match('/edit/', $_SERVER['REQUEST_URI'])) {
                 $this->assemblydetailsearch = NULL;
                 $this->assemblydetail = NULL;
             }
             if ($this->unitofmeasure == '(None)') {
                 $this->addError('unitofmeasure', Zurmo::t('Core', 'Please select Unit Of Measure'));
                 $currencyHelper->resetErrors();
                 return false;
             }
             if ($this->id < 0) {
                 $this->productcode = 'A-' . $this->productcode;
             }
             return true;
         }
     } else {
         return false;
     }
 }