/** * Import COAs skipping same value and updating changed * @param $clientID * @param $projectID * @param $importedCoas */ public static function addSingleCOA($clientID, $projectID, $singleCoa,$list_existing_items) { $result = true; try { if (in_array($singleCoa['acctNumber'], $list_existing_items)) { //such item exists - need to be checked for unique or not $existing_coa = Coa::model()->findByAttributes(array( 'COA_Acct_Number' => $singleCoa['acctNumber'], 'Client_ID' => $clientID, 'Project_ID' => $projectID )); $coaClass = CoaClass::model()->findByAttributes(array( 'Project_ID' => $projectID, 'Class_Shortcut' => $singleCoa['class'], )); if ($coaClass->COA_Class_ID == $existing_coa->COA_Class_ID && $singleCoa['budget'] == $existing_coa->COA_Budget && $existing_coa->COA_Name == $singleCoa['name'] ) { } else { $existing_coa->COA_Class_ID = $coaClass->COA_Class_ID; $existing_coa->COA_Budget = $singleCoa['budget']; $existing_coa->COA_Name = $singleCoa['name']; $existing_coa->save(); $result = $existing_coa; } } else { //item with such number doesn't exists - need to be added to system $coaClass = CoaClass::model()->findByAttributes(array( 'Project_ID' => $projectID, 'Class_Shortcut' => $singleCoa['class'], )); $coa = new Coa(); $coa->Client_ID = $clientID; $coa->COA_Acct_Number = $singleCoa['acctNumber']; $coa->Project_ID = $projectID; $coa->COA_Name = $singleCoa['name']; $coa->COA_Class_ID = $coaClass->COA_Class_ID; $coa->COA_Budget = $singleCoa['budget']; $coa->COA_Current_Total = Coa::getCurrentTotal($projectID, $singleCoa['acctNumber'], $singleCoa['budget']); $coa->save(); $result = $coa; } } catch (Exception $e) { $result = false; } return $result; }
/** * Update COA current budget for all Dists */ public function updateCoaCurrentBudget() { foreach($this->dists as $dist) { $coa = Coa::model()->findByAttributes(array( 'COA_Acct_Number' => $dist->PO_Dists_GL_Code_Full, 'Project_ID' => $this->document->Project_ID, )); if ($coa) { $coa->COA_Current_Total = Coa::getCurrentTotal($this->document->Project_ID, $dist->PO_Dists_GL_Code_Full, $coa->COA_Budget); if ($coa->validate()) { $coa->save(); } } } }