/** * Generates from array of dists array of dist's models. Used for generating PO document without saving metadata to database. * @param $poId * @param $distsToSave */ public static function preparePODistsArray($poId, $distsToSave) { $resultArray = array(); $coaStructure = Coa::getProjectCoaStructure(Yii::app()->user->projectID); foreach ($distsToSave as $distToSave) { $distToSave['PO_Dists_Description']= substr($distToSave['PO_Dists_Description'],0,125); $newDist = new PoDists(); $newDist->PO_ID = $poId; if ($distToSave['PO_Dists_GL_Code'] == '') { $newDist->PO_Dists_GL_Code = null; } else { //full functionality not available from ver 13210 $newDist->Short_Hand = $distToSave['PO_Dists_GL_Code']; $constructed_value = Coa::constructCoaNumber(Yii::app()->user->projectID, $distToSave['PO_Dists_GL_Code']); $newDist->PO_Dists_GL_Code =$constructed_value; $coa=Coa::model()->findByAttributes(array('COA_Acct_Number'=>$newDist->PO_Dists_GL_Code)); if ($coa) {$coa->COA_Used = 1;} } if ($distToSave['PO_Dists_Description'] == '') { $newDist->PO_Dists_Description = '-'; } else { $newDist->PO_Dists_Description = $distToSave['PO_Dists_Description']; } if ($distToSave['PO_Dists_Amount'] == '') { $newDist->PO_Dists_Amount = 0; } else { $newDist->PO_Dists_Amount = $distToSave['PO_Dists_Amount']; } array_push($resultArray,$newDist); } return $resultArray; }
/** * Prepare AP Dists Models * @param $apId * @param $distsToSave */ public static function prepareAPDistsModelsArray($apId, $distsToSave) { $result = array(); $coaStructure = Coa::getProjectCoaStructure(Yii::app()->user->projectID); foreach ($distsToSave as $distToSave) { $newDist = new GlDistDetails(); $newDist->AP_ID = $apId; if ($distToSave['GL_Dist_Detail_COA_Acct_Number'] == '') { $newDist->GL_Dist_Detail_COA_Acct_Number = null; } else { //full functionality not available from ver 13210 $newDist->Short_Hand = $distToSave['GL_Dist_Detail_COA_Acct_Number']; $constructed_value = Coa::constructCoaNumber(Yii::app()->user->projectID, $distToSave['GL_Dist_Detail_COA_Acct_Number']); //$newDist->GL_Dist_Detail_COA_Acct_Number =$distToSave['GL_Dist_Detail_COA_Acct_Number']; $newDist->GL_Dist_Detail_COA_Acct_Number =$constructed_value; $coa=Coa::model()->findByAttributes(array('COA_Acct_Number'=>$newDist->GL_Dist_Detail_COA_Acct_Number)); if ($coa) {$coa->COA_Used = 1;} } if ($distToSave['GL_Dist_Detail_Desc'] == '') { $newDist->GL_Dist_Detail_Desc = '-'; } else { $newDist->GL_Dist_Detail_Desc = $distToSave['GL_Dist_Detail_Desc']; } if ($distToSave['GL_Dist_Detail_Amt'] == '') { $newDist->GL_Dist_Detail_Amt = 0; } else { $newDist->GL_Dist_Detail_Amt = $distToSave['GL_Dist_Detail_Amt']; } array_push($result,$newDist); } return $result; }
/** * Get COA_Acct_Number by user input and COA structure settings * @param $projectID * @param $userInput * @return string */ public static function getCoaAcctNumbByUserInput($projectID, $userInput) { $projectID = intval($projectID); $coaStructure = Coa::getProjectCoaStructure($projectID); $coaAccountNumb = ''; if ($coaStructure !== null && $coaStructure->COA_Allow_Manual_Coding != 1) { if ($coaStructure->COA_Break_Number > 0 && (strpos($userInput,$coaStructure->COA_Break_Character) === false || $coaStructure->COA_Break_Character == '')) { $coaAccountNumb = $userInput; } else { $prefix=$head=$modifier=$root=$conjun=$tail=$suffix = ''; $prefix = $coaStructure->COA_Prefix > 0 ? $coaStructure->COA_Prefix_Val : ''; $modifier = $coaStructure->COA_Modifier > 0 ? $coaStructure->COA_Modifier_Val : ''; $conjun = $coaStructure->COA_Conjun > 0 ? $coaStructure->COA_Conjun_Val : ''; $suffix = $coaStructure->COA_Suffix > 0 ? $coaStructure->COA_Suffix_Val : ''; if ($coaStructure->COA_Break_Character == '' || $coaStructure->COA_Break_Number == 0) { $inputParts = array($userInput); } else { $inputParts = explode($coaStructure->COA_Break_Character,$userInput); } foreach ($inputParts as $inputPart) { if ($coaStructure->COA_Head > 0 && $head == '') { $head = $inputPart; } else if ($coaStructure->COA_Root > 0 && $root == '') { $root = $inputPart; } else if ($coaStructure->COA_Tail > 0 && $tail == '') { $tail = $inputPart; } } $coaAccountNumb = $prefix.$head.$modifier.$root.$conjun.$tail.$suffix; } } else { $coaAccountNumb = $userInput; } return $coaAccountNumb; }