public function clientinfoAction()
 {
     $this->_helper->layout()->disableLayout();
     $this->_helper->ViewRenderer->setScriptAction('client-info');
     //_event_id, _operator_id,_item_id
     if (false === ($client_id = $this->_getParam('param1', false))) {
         throw new Exception('Tampered URI');
     }
     //echo $client_id;
     $client = new Gyuser_Model_User();
     $client->setId($client_id);
     $mapper = new Gyuser_Model_UserDataMapper();
     $this->view->clientInfo = $mapper->ClientDetailsById($client);
     $model = new Gyuser_Model_CRMTasks();
     $this->view->clientId = $client_id;
     $this->view->clientHistory = $model->getClientHistory($client_id);
 }
 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 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 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 CreatePDF(Gyuser_Model_User $obj, $typeid, $status, $operationid)
    {
        $clietid = $obj->getId();
        $param = array();
        if ($status) {
            $param = array('compress' => 0, 'Attachment' => 0);
        }
        switch ($typeid) {
            case 1:
                $mapper = new Gyuser_Model_UserDataMapper();
                $result = $mapper->ClientDetailsById($obj);
                $fn = $result->getFirst_name();
                $ln = $result->getLast_name();
                $dni = $result->GetDNI();
                $html = '<html><body>' . '<table style="font-size:30px;font-weight:bold;font-family:Helvetica,Arial;">' . '<tr>' . '<td>Nombre</td>' . '<td>: </td>' . "<td>{$fn}</td>" . '</tr>' . '<tr>' . '<td>Apellido</td>' . '<td>: </td>' . "<td>{$ln}</td>" . '</tr>' . '<tr>' . '<td>DNI</td>' . '<td>: </td>' . "<td>{$dni}</td>" . '</tr>' . '</table>' . '</body></html>';
                $dompdf = new DOMPDF();
                $dompdf->load_html($html);
                $dompdf->render();
                $dompdf->stream("Mutuo-1.pdf", $param);
                break;
            case 2:
                $mapper = new Gyuser_Model_UserDataMapper();
                $result = $mapper->ClientDetailsById($obj);
                $fn = $result->getFirst_name();
                $ln = $result->getLast_name();
                $dni = $result->GetDNI();
                $chequeObj = new Gyuser_Model_Cheques();
                $chequeObj->setOperation_id($operationid);
                $chequeMapper = new Gyuser_Model_ChequesDataMapper();
                $chequesList = $chequeMapper->GetChequeDetailsByUserId($chequeObj);
                $html = '<html>
					  <style>
                                        .cheques{
                                            width:100%;
                                            border:1px solid #ccc;
                                        }
                                            .cheques td,.cheques th{
                                                    border:2px solid #ccc;
                                                    font-family:Helvetica,Arial;
                                                    padding:10px;
        				}
        				.cheques th{
        					font-size:20px;
        					font-weight:bold;
        				}
        				.h1Txt{
        					text-decoration:underline;
        					font-family:Helvetica,Arial;
        				}
					  </style>

					  <body>' . '<table style="font-size:30px;font-weight:bold;font-family:Helvetica,Arial;">' . '<tr>' . '<td>Nombre</td>' . '<td>: </td>' . "<td>{$fn}</td>" . '</tr>' . '<tr>' . '<td>Apellido</td>' . '<td>: </td>' . "<td>{$ln}</td>" . '</tr>' . '<tr>' . '<td>DNI</td>' . '<td>: </td>' . "<td>{$dni}</td>" . '</tr>' . '</table><br/><br/>';
                if ($chequesList) {
                    $html .= '<table class="cheques"><tr><th>Fecha</th><th>Numero De Cheque</th><th>Importe</th></tr>';
                    foreach ($chequesList as $cheque) {
                        $html .= '<tr>';
                        $html .= '<td >' . $cheque['date'] . '</td>';
                        $html .= '<td >' . $cheque['check_n'] . '</td>';
                        $html .= '<td >' . $cheque['amount'] . '</td>';
                        $html .= '</tr>';
                    }
                    $html .= '</table>';
                }
                $html .= '</body></html>';
                $dompdf = new DOMPDF();
                $dompdf->load_html($html);
                $dompdf->render();
                $dompdf->stream("Mutuo-2.pdf", $param);
                break;
            case 3:
                $mapper = new Gyuser_Model_UserDataMapper();
                $result = $mapper->ClientDetailsById($obj);
                $fn = $result->getFirst_name();
                $ln = $result->getLast_name();
                $dni = $result->GetDNI();
                $telc = $result->getTel_cell_code() . ' ' . $result->getTel_cell();
                $tell = $result->getTel_lab_code() . ' ' . $result->getTel_lab();
                $telo = $result->getTel_otro_code() . ' ' . $result->getTel_otro();
                $telp = $result->getTel_part_code() . ' ' . $result->getTel_part();
                $chequeObj = new Gyuser_Model_Cheques();
                $chequeObj->setOperation_id($operationid);
                $chequeMapper = new Gyuser_Model_ChequesDataMapper();
                $chequesList = $chequeMapper->GetChequeDetailsByUserId($chequeObj);
                $addressMapper = new Gyuser_Model_AddressDataMapper();
                $addressObj = new Gyuser_Model_Address();
                $addressObj->setClient_id($clietid);
                $address = $addressMapper->GetDeliveryAddressByClientId($addressObj);
                $html = '<html>
					  <style>
					    .cheques{
					    	width:100%;
					    	border:1px solid #ccc;
					    }
					  	.cheques td,.cheques th{
					  		border:2px solid #ccc;
					  		font-family:Helvetica,Arial;
					  		padding:10px;
        				}
        				.cheques th{
        					font-size:20px;
        					font-weight:bold;
        				}
        				.address td{
        					font-family:Helvetica,Arial;
					  		padding:10px;
					  		font-size:20px;
        				}
					  </style>

					  <body>' . '<table style="font-size:30px;font-weight:bold;font-family:Helvetica,Arial;">' . '<tr>' . '<td>Nombre</td>' . '<td>: </td>' . "<td>{$fn}</td>" . '</tr>' . '<tr>' . '<td>Apellido</td>' . '<td>: </td>' . "<td>{$ln}</td>" . '</tr>' . '<tr>' . '<td>DNI</td>' . '<td>: </td>' . "<td>{$dni}</td>" . '</tr>' . '</table><br/><br/><h1 class="h1Txt">Cheques</h1>';
                if ($chequesList) {
                    $html .= '<table class="cheques"><tr><th>Fecha</th><th>Numero De Cheque</th><th>Importe</th></tr>';
                    foreach ($chequesList as $cheque) {
                        $html .= '<tr>';
                        $html .= '<td >' . $cheque['date'] . '</td>';
                        $html .= '<td >' . $cheque['check_n'] . '</td>';
                        $html .= '<td >' . $cheque['amount'] . '</td>';
                        $html .= '</tr>';
                    }
                    $html .= '</table>';
                }
                $html .= '<br/><br/><h1 class="h1Txt">Domicilios</h1>';
                if ($address) {
                    $str = '';
                    $jsonData = $address;
                    $id = $jsonData['id'];
                    $street = $jsonData['street'];
                    $city = $jsonData['city'];
                    $state = $jsonData['state'];
                    $state_name = $jsonData['state_name'];
                    $country = $jsonData['country'];
                    $html .= '<table class="address">' . '<tr>' . '<td width="100">Domicilio</td><td> : </td><td>' . $street . '</td>' . '</tr>' . '<tr>' . '<td>Barrio / Ciudad</td><td> : </td><td>' . $city . '</td>' . '</tr>' . '<tr>' . '<td>Provincia</td><td> : </td><td>' . $state_name . '</td>' . '</tr>' . '<tr>' . '<td>Tel�fono</td><td> : </td><td>' . $telc . '<br/>' . $tell . '<br/>' . $telo . '<br/>' . $telp . '<br/></td>' . '</tr>' . '</table>';
                }
                $html .= '</body></html>';
                $dompdf = new DOMPDF();
                $dompdf->load_html($html);
                $dompdf->render();
                $dompdf->stream("Mutuo-3.pdf", $param);
                break;
            default:
                break;
        }
    }
 public function updateOpAndClientsStatus()
 {
     $table = $this->getDbTable();
     $select = $table->select();
     $select->setIntegrityCheck(false);
     $select->from(array('operations'), array('id', 'client_id'));
     $resultSet = $table->fetchAll($select);
     $opMapper = new Gyuser_Model_OperationsDataMapper();
     $clMapper = new Gyuser_Model_UserDataMapper();
     foreach ($resultSet as $row) {
         /// check if the operation has no pending checks, if it doesn't mark the whole operation as saldada
         $operationPayed = $opMapper->checkOperationSaldada($row->id);
         if ($operationPayed) {
             $id = $opMapper->setOperationSaldada($row->id);
             /// check if the client has no pending operations, if it doesn't mark the client type as pasivo
             $pasiveClient = $clMapper->checkPasiveClient($row->client_id);
             if ($pasiveClient) {
                 $id = $clMapper->setPasiveClient($row->client_id);
             }
         } elseif ($opMapper->checkOperationCobranza($row->id)) {
             //operation is en cobranza
             /// check if the client has no pending operations, if it doesn't mark the client type as pasivo
             $id = $clMapper->setCobranzaClient($row->client_id);
         } else {
             //operation is not saldada and is not in cobranza (client active)
             $cobranzas = $clMapper->checkCobranzasOp($row->client_id);
             if (!$cobranzas) {
                 /// check if the client has no other operations in cobranza and mark it as active
                 $id = $clMapper->setActiveClient($row->client_id);
             }
         }
     }
 }