Example #1
0
    /**
     * Save AP Dists
     * @param $apId
     * @param $distsToSave
     */
    public static function saveAPDists($apId, $distsToSave)
    {
        GlDistDetails::model()->deleteAllByAttributes(array(
            'AP_ID' => $apId,
        ));
        $error_array = 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 = Helper::shortenString($distToSave['GL_Dist_Detail_Desc'],125);
            }

            if ($distToSave['GL_Dist_Detail_Amt'] == '') {
                $newDist->GL_Dist_Detail_Amt = 0;
            } else {
                $newDist->GL_Dist_Detail_Amt = $distToSave['GL_Dist_Detail_Amt'];
            }

            if ($newDist->validate()) {
                $newDist->save();
            } else {$error_array[]='Dist validation error'.$distToSave['GL_Dist_Detail_COA_Acct_Number'];}

            if ($coa) {
                if ($coa->validate()) {
                    $coa->save();
                } else {$error_array[]='Coa validation error'.$distToSave['GL_Dist_Detail_COA_Acct_Number'];}
            }
        }

        return $error_array;
    }