public function actionEdit($id) { //get boject by id $deptReference = DepartmentReference::getById(intval($id)); //Security check ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($deptReference); //create view and render $editAndDetailsView = $this->makeEditAndDetailsView($this->attemptToSaveModelFromPost($deptReference), 'Edit'); $view = new DepartmentReferencesPageView(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this, $editAndDetailsView)); echo $view->render(); }
public function addAgreementProductsCalculation(Costbook $costbook, $quantity, $frequency, $optId) { $tQty = 0; $opportunityProduct = new OpportunityProduct(); $opportunityProduct->Quantity = (double) $quantity; $opportunityProduct->Frequency = (double) $frequency; $opportunityProduct->name = 'Love Name - ' . $costbook->id; //$opportunityProduct->Product = $costbook; $tQty = (double) $quantity; if ($opportunityProduct->Frequency > 0) { $tQty *= $opportunityProduct->Frequency; } //Labor Product calculation if ($costbook->costofgoodssold == 'Labor') { $currencies = Currency::getAll(); $opportunityProduct->Total_MHR = round($costbook->costperunit * $tQty); if ($costbook->departmentreference != null) { $deptReference = DepartmentReference::GetById(intval($costbook->departmentreference)); $burdenCost = new CurrencyValue(); $burdenCost->value = round($deptReference->burdonCost * $tQty, 2); $burdenCost->currency = $currencies[0]; $opportunityProduct->Burden_Cost = $burdenCost; $laborCost = new CurrencyValue(); $laborCost->value = round($deptReference->laborCost * $tQty, 2); $laborCost->currency = $currencies[0]; $opportunityProduct->Labor_Cost = $laborCost; } } $opportunityProduct->Category_GPM = 40; $totalDirectCost = new CurrencyValue(); $totalDirectCost->value = round($opportunityProduct->Labor_Cost->value + $opportunityProduct->Burden_Cost->value, 2); $totalDirectCost->currency = $currencies[0]; $opportunityProduct->Total_Direct_Cost = $totalDirectCost; $finalCost = new CurrencyValue(); $finalCost->value = round($opportunityProduct->Total_Direct_Cost->value / (1 - $opportunityProduct->Category_GPM / 100), 2); $finalCost->currency = $currencies[0]; $opportunityProduct->Final_Cost = $finalCost; $opportunityProduct->opportunity = $opportunity = Opportunity::GetById(intval($optId)); $opportunityProduct->save(); }
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; } }