public function SavePaymentForRejectedCheque(Gyuser_Model_Cobranzas $obj) { list($Day, $Month, $Year) = explode('/', $obj->getDate_paid()); $stampeddate = mktime(12, 0, 0, $Month, $Day, $Year); $Date_paid = date("Y-m-d", $stampeddate); $paymentType = $obj->getPayment_type(); $data = array('client_id' => $obj->getClient_id(), 'operation_id' => $obj->getOperation_id(), 'cheque_id' => $obj->getCheque_id(), 'date_paid' => $Date_paid, 'paid_amount' => $obj->getPaid_amount(), 'previous_balance' => $obj->getPrevious_balance(), 'current_balance' => $obj->getCurrent_balance(), 'payment_type' => $obj->getPayment_type()); $id = (int) $this->getDbTable()->insert($data); if ($id) { $chqMapper = new Gyuser_Model_ChequesDataMapper(); $chqObj = new Gyuser_Model_Cheques(); $chqObj->setBalance($obj->getCurrent_balance()); $chqObj->setId($obj->getCheque_id()); //$chqObj->setRejected_check_payment(1); $updateRes = $chqMapper->UpdateRejectedChequeBalance($chqObj); if ($paymentType == 2) { //cheque propio $newCheObj = $obj->getCheques_obj(); $newCheRes = $chqMapper->InsertChequeForRejectedCheque($newCheObj); if (!$newCheRes) { throw Exception('Error inserting cheque for rejected check on DB'); } } elseif ($paymentType == 3) { //cheque de tercero $BankMapper = new Gyuser_Model_BankAccountsDataMapper(); $newBankObj = $obj->getBank_accounts_obj(); $newBankId = $BankMapper->save($newBankObj); if (!$newBankId) { throw Exception('Error inserting bank account for rejected check on DB'); } $newCheObj = $obj->getCheques_obj(); $newCheObj->setRejected_bank_id($newBankId); $newCheRes = $chqMapper->InsertChequeForRejectedCheque($newCheObj); if (!$newCheRes) { throw Exception('Error inserting cheque for rejected check on DB'); } } if ($updateRes) { /// check if the operation has no pending checks, if it doesn't mark the whole operation as saldada $opMapper = new Gyuser_Model_OperationsDataMapper(); $operationPayed = $opMapper->checkOperationSaldada($obj->getOperation_id()); if ($operationPayed) { $id = $opMapper->setOperationSaldada($obj->getOperation_id()); if (!$id) { throw new Exception('There was an error updating the operation to operacion saldada'); } } else { //op. not yet payed. Here we might have no checks in cobranza but we can still have pending checks because of date. $operationInCobranza = $opMapper->checkOperationCobranza($obj->getOperation_id()); if (!$operationInCobranza) { //no checks in cobranza $id = $opMapper->setOperationEnCartera($obj->getOperation_id()); //get operation back to "cheques en cartera" state if (!$id) { throw new Exception('There was an error updating the operation to cheques en cartera'); } } } /// check if the user has no more cobranzas ops, if it doesn't set it as active $clMapper = new Gyuser_Model_UserDataMapper(); $cobranzasOp = $clMapper->checkCobranzasOp($obj->getClient_id()); if (!$cobranzasOp) { //FIX!! Gus asked to pass clients to active once they finish paying cobranzas $id = $clMapper->setActiveClient($obj->getClient_id()); //$id = $clMapper->setPasiveClient($obj->getClient_id()); if ($id) { $id = -1; } else { throw new Exception('There was an error setting the client to active'); } } } else { throw new Exception('There was an error updating the rejected check balance'); } } else { throw new Exception('There was an error adding the new payment for rejected check'); } return $id; }
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) { } }
public function getalldetailsbyclientidajaxAction() { try { //echo "it works!"; $request = $this->getRequest(); if ($this->getRequest()->isPost()) { $clientid = $request->client_id; $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $mapper = new Gyuser_Model_AddressDataMapper(); $Obj = new Gyuser_Model_Address(); $Obj->setClient_id($clientid); $addresses = $mapper->GetAddressByClientId($Obj); $mapper = new Gyuser_Model_BankAccountsDataMapper(); $obj = new Gyuser_Model_BankAccounts(); $obj->setUser_id($clientid); $bankdetails = $mapper->GetBankDetailsByUserId($obj); $mapper = new Gyuser_Model_PriorOperationsDataMapper(); $obj = new Gyuser_Model_PriorOperations(); $obj->setClient_id($clientid); $prior = $mapper->GetPriorByClientId($obj); $mapper = new Gyuser_Model_OperationsDataMapper(); $obj = new Gyuser_Model_Operations(); $obj->setClient_id($clientid); $operations = $mapper->GetOperationsByClientId($obj); $mapper = new Gyuser_Model_UserDataMapper(); $obj = new Gyuser_Model_User(); $obj->setId($clientid); $clientInfo = $mapper->findContacto($obj); $clientDetails = array('bankdetails' => $bankdetails, 'addresses' => $addresses, 'prior' => $prior, 'operations' => $operations, 'clientInfo' => $clientInfo); if ($clientDetails) { echo json_encode($clientDetails); } else { echo "f"; } } } catch (Exception $e) { echo $e; } }
public function DeleteClientDetails(Gyuser_Model_User $obj) { try { $table = $this->getDbTable(); $set = array('status' => 0); $where = array('id = ?' => $obj->getId()); $result = $table->update($set, $where); if ($result) { $addressMapper = new Gyuser_Model_AddressDataMapper(); $addressObj = new Gyuser_Model_Address(); $addressObj->setClient_id($obj->getId()); $addressMapper->DeleteClientAddress($addressObj); $bankMapper = new Gyuser_Model_BankAccountsDataMapper(); $bankObj = new Gyuser_Model_BankAccounts(); $bankObj->setUser_id($obj->getId()); $bankMapper->DeleteClientBankAccounts($bankObj); } return $result; } catch (Exception $e) { echo $e; } }