public function createTercerosOp(Gyuser_Model_Operations $obj, $chequesList = null)
 {
     try {
         //1. create operation
         $data = array('type' => 2, 'client_id' => $obj->getClient_id(), 'date' => $obj->getDate(), 'amount' => $obj->getAmount(), 'state_order_id' => 2, 'tasa_porcentual' => $obj->getTasa_porcentual(), 'date_added' => date('Y-m-d H:i:s'));
         $opId = $this->getDbTable()->insert($data);
         if (!$opId) {
             throw Exception("Hubo un error al crear la operación de cheques de terceros.");
         }
         //2. insert checks
         $chequesMapper = new Gyuser_Model_ChequesDataMapper();
         $chequesMapper->addChequesTerceros($opId, $chequesList);
         //3. set client to active
         $clientMapper = new Gyuser_Model_UserDataMapper();
         $clientObj = new Gyuser_Model_User();
         $clientObj->setId($obj->getClient_id());
         $clientObj->setClient_type(3);
         //active
         $clientMapper->UpdateUserType($clientObj);
         return $opId;
         //**********************************************************************
         /*
         $cheques = new Gyuser_Model_Cheques();
         $cheques->setOperation_id($obj->getId());
         $cheques->setCheques_list($chequesList);
         
         $mapper = new Gyuser_Model_OperationsDataMapper();
         $arc_hrs = $mapper->GetAcreditacionHrsByOperationId($obj);
         
         
         $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()
         );
         */
         /*    
                     $id = (int) $obj->getId();
                     if (!$id) {
            unset($data['id']);
         
                     } else {
            $id = $this->getDbTable()->update($data, array('id = ?' => $id));
            return $id;
                     }
         * 
         */
     } catch (Exception $e) {
     }
 }
 public function operationsformajaxAction()
 {
     try {
         $this->_helper->layout->disableLayout();
         $this->_helper->viewRenderer->setNoRender();
         $request = $this->getRequest();
         if ($this->getRequest()->isPost()) {
             $mapper = new Gyuser_Model_OperationsDataMapper();
             $Obj = new Gyuser_Model_Operations();
             $Obj->setClient_id($request->client_id);
             date_default_timezone_set('Europe/Vienna');
             list($Day, $Month, $Year) = explode('/', $request->date);
             $stampeddate = mktime(12, 0, 0, $Month, $Day, $Year);
             $realDate = date("Y-m-d", $stampeddate);
             $Obj->setDate($realDate);
             $Obj->setAmount($request->amount);
             $Obj->setState($request->state);
             $Obj->setObservations($request->observations);
             $Obj->setCave_id($request->cave);
             $Obj->setBank_account_id($request->bank_account_id);
             if ($request->id) {
                 $Obj->setId($request->id);
             }
             $id = $mapper->save($Obj);
             if ($id) {
                 //set client type to active
                 $clientMapper = new Gyuser_Model_UserDataMapper();
                 $clientObj = new Gyuser_Model_User();
                 $clientObj->setId($request->client_id);
                 $clientObj->setClient_type(3);
                 //active
                 $clientMapper->UpdateUserType($clientObj);
                 echo $id;
             } else {
                 echo "f";
             }
         }
     } catch (Exception $e) {
         echo $e;
     }
 }
 public function RejectChequeWithGastos(Gyuser_Model_Cheques $obj)
 {
     try {
         $chequeDetails = $this->FindWithOperationNames($obj);
         $amount = (int) $this->GetAmounByChequeId($obj);
         $gastos = (int) $obj->getRejected_gastos();
         $gastos_type = $obj->getRejected_type();
         $rejectedCostProv = 'null';
         if ($chequeDetails->getLiquidacion_id()) {
             //the cheque has been passed to a provider
             $provMapper = new Gyuser_Model_ProvidersDataMapper();
             $prov = $provMapper->GetProviderByIdSimple($chequeDetails->getProvider_id());
             if ($gastos_type == "Denuncia") {
                 $rejectedCostProv = $prov->getGastos_denuncia();
             } elseif ($gastos_type == "Sin Fondos") {
                 $rejectedCostProv = $prov->getGastos_rechazo();
             }
             /*  
                             if ($chequeDetails->getCave_id()) { //the cave id property checks the provider_id field on DB, if it's not null then it's from a provider.
                $supMapper = new Gyuser_Model_SupplierOperationsDataMapper();
                $supObj = new Gyuser_Model_SupplierOperations();
                $supObj->setId($chequeDetails->getCave_id());
                $supList = $supMapper->GetCaveById($supObj); //looks for provider id (not cave)
                if ($gastos_type == "Denuncia")
                    $rejectedCostProv = $supList->getGastos_denuncia();
                elseif ($gastos_type == "Sin Fondos")
                    $rejectedCostProv = $supList->getGastos_rechazo();
                             }
                             else { //it's from lavalle
                $caveMapper = new Gyuser_Model_OtherCavesDataMapper();
                $caves = new Gyuser_Model_OtherCaves();
                $caves->setId('1'); //lavalle
                $lavalle = $caveMapper->GetCaveById($caves);
                $x = 1;
                if ($gastos_type == "Denuncia") {
                    $x = 1;
                    $rejectedCostProv = $lavalle->getGastos_denuncia();
                } elseif ($gastos_type == "Sin Fondos") {
                    $rejectedCostProv = $lavalle->getGastos_rechazo();
                }
                             }
             * 
             */
         }
         $amount = $amount + $gastos;
         $data = array('status' => 3, 'balance' => $amount, 'rejected_cost' => $gastos, 'rejected_type' => $gastos_type, 'rejected_cost_prov' => $rejectedCostProv);
         $success = $this->getDbTable()->update($data, array('id = ?' => $obj->getId()));
         if ($success) {
             $opId = $this->GetChequeOpId($obj->getId());
             //update op status to 11 = 'En Cobranza'
             $opMapper = new Gyuser_Model_OperationsDataMapper();
             $opMapper->setOperationEnCobranza($opId);
             $clientMapper = new Gyuser_Model_UserDataMapper();
             $clientId = $clientMapper->getClientByChequeId($obj->getId());
             if ($clientId) {
                 $client = new Gyuser_Model_User();
                 $client->setId($clientId);
                 $client->setClient_type(4);
                 $clientMapper->UpdateUserType($client);
             } else {
                 throw new Exception('The cheque status was updated to rejected but the client type could not be updated (to 4 = cobranza)');
             }
             //$chequeDetails = $this->FindWithOperationNames($obj);
             $mapper = new Gyuser_Model_NotificationsDataMapper();
             $obj = new Gyuser_Model_Notifications();
             $obj->setTitle('Cheque rechazado');
             $Operation_id = $chequeDetails->getOperation_id();
             $check_n = $chequeDetails->getCheck_n();
             $check_date = $chequeDetails->getDate();
             $operator_id = $request->operator_id;
             $obj->setOperator_id($Operation_id);
             $obj->setComment("El cheque {$check_n} con fecha {$check_date} op.{$Operation_id} fue rechazado por {$gastos_type}");
             $obj->setAction_date(date('Y-m-d h:i:s'));
             $result = $mapper->SaveWhenRejected($obj);
         } else {
             throw new Exception('There was an error updating the cheques table');
         }
         return $result;
     } catch (Exception $e) {
         echo $e;
     }
 }
 public function findClient(Gyuser_Model_User $obj)
 {
     /*$table = $this->getDbTable();
       $row = $table->fetchRow(
               $table->select()
                     ->join(array('client_types' => 'CT'),'clients.client_type = CT.id')
                     ->where('id = ?', $obj->getId())
       );*/
     /*
     * TRY THIS
     * $select->from(array('opr' => 'operations'), array('*'));
             $select->joinLeft(array('ocvs' => 'other_caves'), 'opr.cave_id = ocvs.id', array('name as cave_name'));
     */
     $db = Zend_Db_Table::getDefaultAdapter();
     $stmt = $db->query("SELECT C.*, CT.name AS client_type_name FROM clients C JOIN client_types CT on C.client_type = CT.id WHERE C.id =" . $obj->getId());
     $rows = $stmt->fetchAll();
     if ($rows) {
         $row = $rows[0];
         $CUIL = $row['CUIL'];
         if ($CUIL) {
             $CUIL1 = substr($CUIL, 0, 2);
             $CUIL2 = substr($CUIL, 2, 8);
             $CUIL3 = substr($CUIL, 10, 1);
             $CUIL = $CUIL1 . '-' . $CUIL2 . '-' . $CUIL3;
         }
         $tel_cell = $this->LandPhoneFormat($row['tel_cell']);
         $tel_otro = $this->LandPhoneFormat($row['tel_otro']);
         $tel_lab = $this->LandPhoneFormat($row['tel_lab']);
         $tel_part = $this->LandPhoneFormat($row['tel_part']);
         //$tel_cell_code = $this->CellPhoneAreaCodeFormat($row['tel_cell_code'];
         $tel_otro_code = $this->areaCodeOut($row['tel_otro_code, $tel_otro']);
         $tel_lab_code = $this->areaCodeOut($row['tel_lab_code, $tel_lab']);
         $tel_part_code = $this->areaCodeOut($row['tel_part_code, $tel_part']);
         $entry = new Gyuser_Model_User();
         $entry->setId($row['id']);
         $entry->setClient_type($row['client_type']);
         //$entry->setClient_type_name($row['client_type_name']);
         $entry->setFirst_name($row['first_name']);
         $entry->setLast_name($row['last_name']);
         $entry->setDNI($row['DNI']);
         $entry->setCUIL($CUIL);
         $entry->setTel_cell($tel_cell);
         $entry->setTel_lab($tel_lab);
         $entry->setTel_otro($tel_otro);
         $entry->setTel_part($tel_part);
         //$entry->setTel_cell_code($tel_cell_code']);
         $entry->setTel_lab_code($tel_lab_code);
         $entry->setTel_otro_code($tel_otro_code);
         $entry->setTel_part_code($tel_part_code);
         $entry->setEmail($row['email']);
         $entry->setActivity($row['activity']);
         $entry->setDate_added(date("d/m/Y", strtotime($row['date_added'])));
         $entry->setOperator($row['operator']);
         $entry->setContact_point($row['contact_point']);
         $entry->setExtra_info($row['extra_info']);
         $entry->setBusiness($row['business']);
         $entry->setBusiness_CUIT($row['business_CUIT']);
         $entry->setType_change($row['type_change']);
     }
     return $entry;
 }