Пример #1
0
 public function OpTercerosStateChange($opId, $newStateId, $tasaAnual = null, $chequesListJson = null)
 {
     $success = 0;
     $obj = new Gyuser_Model_Operations();
     $obj->setId($opId);
     $opResult = $this->GetStateByOperationId($obj);
     $currentStateId = (int) $opResult['stateid'];
     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:
                 //cerrada
                 $chequesMapper = new Gyuser_Model_ChequesDataMapper();
                 $informesCompletos = $chequesMapper->checkInformesCompletos($opId);
                 if ($informesCompletos) {
                     $data = array('state_order_id' => $newStateId);
                 }
                 break;
             case 6:
                 //op. en camino
                 $opAmount = 0;
                 $opTodayVal = 0;
                 $adminMapper = new Gyuser_Model_AdminDataMapper();
                 $admin = $adminMapper->getAdminSettings();
                 $prov = new Gyuser_Model_Providers();
                 $prov->setAcreditacion_capital($admin->getTiempo_ac_capital());
                 $prov->setAcreditacion_interior($admin->getTiempo_ac_interior());
                 $prov->setGastos_general($admin->getGastos_general());
                 $prov->setGastos_interior($admin->getGastos_interior());
                 $prov->setImpuesto_al_cheque($admin->getImpuesto_al_cheque());
                 $prov->setTasa_anual($tasaAnual);
                 $chequesMapper = new Gyuser_Model_ChequesDataMapper();
                 $cheque = new Gyuser_Model_Cheques();
                 $cheques = $chequesMapper->GetChequesByOpId($opId);
                 //gets only cheques with status 7 (aprobados)
                 foreach ($cheques as $cheque) {
                     $cDetails = $chequesMapper->saveDetails($cheque->getId(), $prov);
                     $opAmount += $cDetails['amount'];
                     $opTodayVal += $cDetails['terceros_today_value'];
                 }
                 $data = array('amount' => $opAmount, 'amount_today' => $opTodayVal, 'ac_date' => date('Y-m-d'), 'tasa_porcentual' => $tasaAnual, 'state_order_id' => $newStateId);
                 break;
             case 9:
                 //consolidated / cheques en cartera
                 $chequesList = json_decode($chequesListJson);
                 $chequesMapper = new Gyuser_Model_ChequesDataMapper();
                 $chequesTotals = $chequesMapper->consolidateCheques($chequesList);
                 $data = array('amount' => $chequesTotals['amount'], 'amount_today' => $chequesTotals['todayValue'], 'state_order_id' => $newStateId);
                 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;
         }
         if ($data) {
             $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;
 }