public function savepaymentforrejectedchequeajaxAction()
 {
     try {
         $this->_helper->layout->disableLayout();
         $this->_helper->viewRenderer->setNoRender();
         $request = $this->getRequest();
         if ($this->getRequest()->isPost()) {
             $paymentType = $request->payment_type;
             switch ($paymentType) {
                 case 1:
                     $Obj = new Gyuser_Model_Cobranzas();
                     $Obj->setClient_id($request->client_id);
                     $Obj->setOperation_id($request->operation_id);
                     $Obj->setCheque_id($request->cheque_id);
                     $Obj->setDate_paid($request->date_paid);
                     $Obj->setPaid_amount($request->paid_amount);
                     $Obj->setPrevious_balance($request->previous_balance);
                     $Obj->setCurrent_balance($request->current_balance);
                     $Obj->setPayment_type($request->payment_type);
                     break;
                 case 2:
                     $Obj = new Gyuser_Model_Cobranzas();
                     $Obj->setClient_id($request->client_id);
                     $Obj->setOperation_id($request->operation_id);
                     $Obj->setCheque_id($request->cheque_id);
                     $Obj->setDate_paid($request->date_paid);
                     $Obj->setPaid_amount($request->paid_amount);
                     $Obj->setPrevious_balance($request->previous_balance);
                     $Obj->setCurrent_balance($request->current_balance);
                     $Obj->setPayment_type($request->payment_type);
                     $chqObj = new Gyuser_Model_Cheques();
                     $chqObj->setAmount($request->paid_amount);
                     $chqObj->setStatus(1);
                     $chqObj->setRejected_bank_id($request->rejected_bank_id);
                     $chqObj->setOperation_id($request->operation_id);
                     $chqObj->setClient_id($request->client_id);
                     $chqObj->setCheck_n($request->new_cheque_n);
                     $chqObj->setDate($request->cheque_date);
                     $chqObj->setRejected_check_payment(1);
                     $Obj->setCheques_obj($chqObj);
                     break;
                 case 3:
                     $Obj = new Gyuser_Model_Cobranzas();
                     $Obj->setClient_id($request->client_id);
                     $Obj->setOperation_id($request->operation_id);
                     $Obj->setCheque_id($request->cheque_id);
                     $Obj->setDate_paid($request->date_paid);
                     $Obj->setPaid_amount($request->paid_amount);
                     $Obj->setPrevious_balance($request->previous_balance);
                     $Obj->setCurrent_balance($request->current_balance);
                     $Obj->setPayment_type($request->payment_type);
                     $chqObj = new Gyuser_Model_Cheques();
                     $chqObj->setAmount($request->paid_amount);
                     $chqObj->setStatus(1);
                     $chqObj->setOperation_id($request->operation_id);
                     $chqObj->setClient_id($request->client_id);
                     $chqObj->setCheck_n($request->new_cheque_n);
                     $chqObj->setDate($request->cheque_date);
                     $chqObj->setRejected_check_payment(2);
                     $Obj->setCheques_obj($chqObj);
                     $bankObj = new Gyuser_Model_BankAccounts();
                     $bankObj->setUser_id($request->client_id);
                     $bankObj->setBank_name($request->bank_name);
                     $bankObj->setBranch($request->branch);
                     $bankObj->setAccount_n($request->account_n);
                     $bankObj->setOpening_date($request->opening_date);
                     $bankObj->setZip_code($request->check_zip_code);
                     $bankObj->setLocation_capital($request->location_capital);
                     $Obj->setBank_accounts_obj($bankObj);
                     break;
             }
             $mapper = new Gyuser_Model_CobranzasDataMapper();
             $id = $mapper->SavePaymentForRejectedCheque($Obj);
             echo $id;
         }
     } catch (Exception $e) {
         echo $e;
     }
 }
 public function addChequesTerceros($opId, $chequesListJson)
 {
     try {
         //$chequesList = utf8_encode($chequesList);//html_entity_decode($chequesList);
         $chequesList = json_decode($chequesListJson);
         $chequesFlag = false;
         $adminMapper = new Gyuser_Model_AdminDataMapper();
         $adminSettings = $adminMapper->getAdminSettings();
         foreach ($chequesList as $cheque) {
             unset($clientId);
             unset($bankId);
             unset($chequeId);
             //1. add client
             $clientMapper = new Gyuser_Model_UserDataMapper();
             $client = new Gyuser_Model_User();
             $client->setFirst_name($cheque->first_name);
             $client->setLast_name($cheque->last_name);
             $client->setDNI($cheque->DNI);
             $client->setCUIL($cheque->CUIL);
             $clientId = $clientMapper->createTerceroClient($client);
             if (!$clientId) {
                 throw Exception('Error creating cheque tercero client on DB');
             }
             //2. add bank account
             $bankMapper = new Gyuser_Model_BankAccountsDataMapper();
             $bank = new Gyuser_Model_BankAccounts();
             $bank->setUser_id($clientId);
             $bank->setBank_name($cheque->bank_name);
             $bank->setAccount_n($cheque->account_n);
             $bank->setBranch($cheque->branch);
             $bank->setZip_code($cheque->zip_code);
             $bank->setLocation_capital($cheque->location_capital);
             $bank->setOpening_date($cheque->account_date);
             $bankId = $bankMapper->save($bank);
             if (!$bankId) {
                 throw Exception('Error inserting bank account for cheque tercero on DB');
             }
             //3. add cheque
             list($Day, $Month, $Year) = explode('/', $cheque->check_date);
             $stampeddate = mktime(12, 0, 0, $Month, $Day, $Year);
             $date = date("Y-m-d", $stampeddate);
             $amount = floatval($cheque->check_amount);
             if ($cheque->location_capital == '1') {
                 $acreditacionHrs = $adminSettings->getTiempo_ac_capital();
             } else {
                 $acreditacionHrs = $adminSettings->getTiempo_ac_interior();
             }
             $data = array('operation_id' => $opId, 'client_id' => $clientId, 'bank_account_id' => $bankId, 'date' => $date, 'check_n' => $cheque->check_n, 'amount' => $amount, 'acreditacion_hrs' => $acreditacionHrs, 'local' => 1, 'status' => 6);
             $chequeId = $this->getDbTable()->insert($data);
             if (!$chequeId) {
                 throw Exception('Error inserting cheque tercero on DB');
             }
         }
         return $opId;
     } catch (Exception $e) {
     }
 }