コード例 #1
0
 public function createliquidacionAction()
 {
     try {
         $request = $this->getRequest();
         if ($this->getRequest()->isPost()) {
             $liqDataId = 0;
             $liqId = (int) $request->id;
             //if there's an empty string it defaults to 0
             $liqDate = $request->date;
             $variableDate = false;
             $lMapper = new Gyuser_Model_LiquidacionesDataMapper();
             $liq = new Gyuser_Model_Liquidaciones();
             $liq->setProvider_id($request->provider_id);
             $liq->setCommitted((int) $request->committed);
             $pMapper = new Gyuser_Model_ProvidersDataMapper();
             $prov = $pMapper->GetProviderById($liq->getProvider_id());
             $cMapper = new Gyuser_Model_ChequesDataMapper();
             $oMapper = new Gyuser_Model_OperationsDataMapper();
             //if liq has already been submitted then cleanup previous
             //selected cheques, rejected cheques and operations
             if ($liqId) {
                 $chequesList = $cMapper->UpdateLiquidacionDeleted($liqId);
                 $opertationsList = $oMapper->UpdateLiquidacionDeleted($liqId);
             } else {
                 $liqId = $lMapper->createNewLiq();
             }
             //check liq id has been created.
             if ($liqId) {
                 $liq->setId($liqId);
                 //depending on the status of the liquidacion
                 //set the appropriate dates and/or liq data
                 if ($liq->getCommitted() == 0) {
                     //set current date and current prov values
                     list($Day, $Month, $Year) = explode('/', $liqDate);
                     $liqDate = mktime(12, 0, 0, $Month, $Day, $Year);
                     $liqDate = date("Y-m-d", $liqDate);
                     $today = date("Y-m-d");
                     if ($liqDate != $today) {
                         $liq->setDate($liqDate);
                         $variableDate = true;
                     } else {
                         $liq->setDate($today);
                     }
                     //even if this date won't be stored in db, we needed to calculate checks today value
                     $provData = $prov;
                     //set the current provider values as prov data
                 } elseif ($liq->getCommitted() == 2) {
                     //status is en camino. save date and prov values
                     $liqData = $lMapper->GetLiquidacionesById($liq);
                     //set date as today or as date selected by user
                     if ($liqData['variable_date']) {
                         $liq->setDate($liqData['date']);
                         $variableDate = true;
                     } else {
                         $liq->setDate(date('Y-m-d'));
                     }
                     //set current prov values into liq for db save
                     $liq->setTasa_anual($prov->getTasa_anual());
                     $liq->setImpuesto_al_cheque($prov->getImpuesto_al_cheque());
                     $liq->setAcreditacion_capital($prov->getAcreditacion_capital());
                     $liq->setAcreditacion_interior($prov->getAcreditacion_interior());
                     $liq->setGastos_general($prov->getGastos_general());
                     $liq->setGastos_interior($prov->getGastos_interior());
                     $liq->setGastos_cheque_a_1($prov->getGastos_cheque_a_1());
                     $liq->setGastos_cheque_menor_a_1($prov->getGastos_cheque_menor_a_1());
                     $liq->setGastos_cheque_a_2($prov->getGastos_cheque_a_2());
                     $liq->setGastos_cheque_menor_a_2($prov->getGastos_cheque_menor_a_2());
                     $liq->setDate_delivered(date("Y-m-d"));
                     $provData = $prov;
                     //set the current provider values as prov data
                 } elseif ($liq->getCommitted() == 1) {
                     //to be consolidated get the prov values stored in liq
                     $liqData = $lMapper->GetLiquidacionesById($liq);
                     //set date as date saved on step 2
                     $liq->setDate($liqData['date']);
                     $provData = $lMapper->getProvData($liqId);
                     //set the saved prov data on liq to calculate checks values
                 }
                 /* update Liquidacion id in cheques */
                 $checksJson = json_decode($request->cheques_json);
                 $checkObj = new Gyuser_Model_Cheques();
                 $checkObj->setLiquidacion_id($liqId);
                 $checkObj->setProvider_id($liq->getProvider_id());
                 foreach ($checksJson as $check) {
                     $checkObj->setId($check->cheque_id);
                     if ($check->acreditacion_hrs) {
                         $checkObj->setAcreditacion_hrs($check->acreditacion_hrs);
                     }
                     $cMapper->UpdateLiquidacion($checkObj);
                 }
                 /* update Liquidacion id in rejected cheques */
                 $rejected_cheques_json = json_decode($request->rejected_cheques_json);
                 $rejCheckTotal = 0;
                 foreach ($rejected_cheques_json as $check) {
                     $checkDetails = $cMapper->getCheckDetails($check->rejected_cheque_id);
                     $gastos_type = $checkDetails->getRejected_type();
                     if ($gastos_type == "Denuncia") {
                         $checkDetails->setRejected_cost_prov($prov->getGastos_denuncia());
                     } elseif ($gastos_type == "Sin Fondos") {
                         $checkDetails->setRejected_cost_prov($prov->getGastos_rechazo());
                     }
                     //set the current liq id as the liq id where the rejected check was payed
                     $checkDetails->setRejected_liq_id($liqId);
                     //add the check total to the rej checks total
                     $rejCheckTotal += $checkDetails->getAmount() + $checkDetails->getRejected_cost_prov();
                     $cMapper->UpdateRejectedCheques($checkDetails);
                 }
                 $opsTotal = 0;
                 /* update Liquidacion id in operations */
                 $operations_json = json_decode($request->operations_json);
                 $opDetails = new Gyuser_Model_Operations();
                 $opDetails->setLiquidacion_id($liqId);
                 $commissionRate = $prov->getComisionRate();
                 foreach ($operations_json as $operation) {
                     $opDetails->setId($operation->operation_id);
                     $oMapper->UpdateLiquidacion($opDetails);
                     $amount = (double) $oMapper->GetAmount($operation->operation_id);
                     $commissionAmt = (double) $pMapper->calculateComisionAmt($amount, $commissionRate);
                     $opsTotal += (double) $pMapper->calculateProvPayment($amount, $commissionAmt);
                 }
                 $checksTotals = $cMapper->GetChequesTotalsJson($liq->getProvider_id(), $checksJson, $provData, $liq->getDate());
                 $acreditacion = floatval($request->acreditacion);
                 $amountDebt = $rejCheckTotal + $opsTotal - $acreditacion;
                 $accountBalance = $checksTotals['payingAmount'] - $amountDebt;
                 $liq->setId($liqId);
                 $liq->setAcreditacion($acreditacion);
                 $liq->setAmount_debt($amountDebt);
                 $liq->setAmount_payed($checksTotals['payingAmount']);
                 $liq->setPrevious_account_balance($prov->getBalance());
                 $liq->setCurrent_account_balance($accountBalance);
                 $liq->setChecks_qty($checksTotals['chequeChkCount']);
                 $liq->setAverage_days($checksTotals['dayAvg']);
                 $liq->setTotal_bruto($checksTotals['bruto']);
                 $liq->setImpuesto_al_cheque_amt($checksTotals['impuestoAlCheque']);
                 //the amount for impuesto al cheque
                 $liq->setIntereses($checksTotals['intereses']);
                 //also called descuento
                 $liq->setGastos_interior_fee($checksTotals['gastosInterior']);
                 //the amount for interior gastos
                 $liq->setGastos_general_fee($checksTotals['gastosGeneral']);
                 //the amount for general gastos
                 $liq->setGastos_varios($checksTotals['gastosOtros']);
                 $liq->setTotal_neto($checksTotals['payingAmount']);
                 $lMapper->createLiq($liq, $variableDate);
                 //update current balance
                 $prov->setBalance($accountBalance);
                 $pMapper->UpdateBalance($prov);
             } else {
                 throw new Exception('error inserting new liquidacion');
             }
             $this->_helper->redirector('providers', 'liquidaciones', 'gyuser', array('provider_id' => $request->provider_id));
         }
     } catch (Exception $e) {
         echo $e;
     }
 }
コード例 #2
0
 public function OperationStateChange(Gyuser_Model_Operations $obj, $chequesList = null, $chequeId = null)
 {
     $success = 0;
     $opResult = $this->GetStateByOperationId($obj);
     $currentStateId = (int) $opResult['stateid'];
     $newStateId = $obj->getState();
     //fix get op client_id and bank_account_id
     $op = $this->getDetailsByOpId($obj->getId());
     $obj->setClient_id($op->getClient_id());
     $obj->setBank_account_id($op->getBank_account_id());
     if ($currentStateId < $newStateId) {
         switch ($newStateId) {
             case 2:
                 $data = array('state_order_id' => $obj->getState(), 'cave_id' => $obj->getCave_id());
                 break;
             case 3:
             case 4:
                 $data = array('state_order_id' => $obj->getState(), 'report' => $obj->getReport());
                 break;
             case 5:
                 $mapper = new Gyuser_Model_OperationsDataMapper();
                 $arc_hrs = $mapper->GetAcreditacionHrsByOperationId($obj);
                 $chequesMapper = new Gyuser_Model_ChequesDataMapper();
                 $cheques = new Gyuser_Model_Cheques();
                 $cheques->setOperation_id($obj->getId());
                 $cheques->setClient_id($obj->getClient_id());
                 $cheques->setBank_account_id($obj->getBank_account_id());
                 $cheques->setAcreditacion_hrs($arc_hrs);
                 $cheques->setCheques_list($chequesList);
                 $result = $chequesMapper->SaveCheques($cheques);
                 $iMapper = new Gyuser_Model_InterestsDataMapper();
                 $interests = new Gyuser_Model_Interests();
                 $interests = $iMapper->getInterestRate($obj->getInterests_id());
                 $data = array('state_order_id' => $obj->getState(), 'amount' => $obj->getAmount(), 'plan_id' => $obj->getPlan_id(), 'interests_id' => $obj->getInterests_id(), 'tasa_porcentual' => $interests->getRate());
                 break;
             case 8:
             case 9:
                 $chequesMapper = new Gyuser_Model_ChequesDataMapper();
                 $cheques = new Gyuser_Model_Cheques();
                 $cheques->setId($chequeId);
                 $cheques->setOperation_id($obj->getId());
                 $cheques->setClient_id($obj->getClient_id());
                 $cheques->setBank_account_id($obj->getBank_account_id());
                 $cheques->setCheques_list($chequesList);
                 $chequesResult = $chequesMapper->SaveCheques($cheques);
                 $data = array('amount' => $obj->getAmount(), 'plan_id' => $obj->getPlan_id(), 'state_order_id' => $obj->getState());
                 break;
             case 6:
             case 7:
                 $chequesMapper = new Gyuser_Model_ChequesDataMapper();
                 $cheques = new Gyuser_Model_Cheques();
                 $cheques->setOperation_id($obj->getId());
                 $data = array('state_order_id' => $obj->getState());
                 break;
             case 99:
                 $chequesMapper = new Gyuser_Model_ChequesDataMapper();
                 $cheques = new Gyuser_Model_Cheques();
                 $cheques->setOperation_id($obj->getId());
                 $result = $chequesMapper->deleteByOperationId($cheques);
                 $data = array('state_order_id' => $obj->getState());
                 break;
             default:
                 $data = array('state_order_id' => $obj->getState());
                 break;
         }
         $id = (int) $obj->getId();
         $id = $this->getDbTable()->update($data, array('id = ?' => $id));
         $success = 1;
     } elseif ($currentStateId >= $newStateId) {
         //new state is smaller or equal to current state
         $success = 2;
     }
     //2 = the state has already been changed.
     return $success;
 }