public function saveAction()
 {
     //  parent::saveAction();
     $message = '';
     $AccountEntryModel = new AccountentryModel();
     $AccountEntryModel->getAdapter()->beginTransaction();
     $AccountCheckModel = new AccountcheckModel();
     $accountentrycheckModel = new AccountcheckaccountentryModel();
     $paramAccountentry = array();
     $paramAccountcheck = array();
     $paramentrycheckArray = array();
     $dtentrydate = $this->_request->getParam("dtentrydate");
     if ($dtentrydate != '' && isset($dtentrydate)) {
         $dtentrydate = new Zend_Date($dtentrydate, 'dd-MM-YYYY');
         $dtentrydate = $dtentrydate->toString('YYYY-MM-dd');
     }
     $dttransactiondate = $this->_request->getParam("dttransactiondate");
     if ($dttransactiondate != '' && isset($dttransactiondate)) {
         $dttransactiondate = new Zend_Date($dttransactiondate, 'dd-MM-YYYY');
         $dttransactiondate = $dttransactiondate->toString('YYYY-MM-dd');
     }
     $dtinvoicedate = $this->_request->getParam("dtinvoicedate");
     if ($dtinvoicedate != '' && isset($dtinvoicedate)) {
         $dtinvoicedate = new Zend_Date($dtinvoicedate, 'dd-MM-YYYY');
         $dtinvoicedate = $dtinvoicedate->toString('YYYY-MM-dd');
     }
     $dtdeadline = $this->_request->getParam("dtdeadline");
     if ($dtdeadline != '' && isset($dtdeadline)) {
         $dtdeadline = new Zend_Date($dtdeadline, 'dd-MM-YYYY');
         $dtdeadline = $dtdeadline->toString('YYYY-MM-dd');
     }
     $dtaccountcheckdate = $this->_request->getParam("dtaccountcheckdate");
     if ($dtaccountcheckdate != '' && isset($dtaccountcheckdate)) {
         $dtaccountcheckdate = new Zend_Date($dtaccountcheckdate, 'dd-MM-YYYY');
         $dtaccountcheckdate = $dtaccountcheckdate->toString('YYYY-MM-dd');
     }
     $supplierModel = new SupplierModel();
     $covenantModel = new CovenantModel();
     if ($this->_request->getParam('fgclienttype') == 'a' && $this->_request->getParam('cdclient') != '') {
         if ($this->_request->getParam('cdclient') != null && $this->_request->getParam('cdclient') != '') {
             $favored = $this->_request->getParam('cdclient');
         }
     } else {
         if ($this->_request->getParam('fgclienttype') == 'b' && $this->_request->getParam('cdclient') != '') {
             if ($this->_request->getParam('cdclient') != null && $this->_request->getParam('cdclient') != '') {
                 $patientData = $covenantModel->fetchRow('cdcovenant = ' . $this->_request->getParam('cdclient'));
                 $favored = $patientData->cdcovenant;
             }
         }
     }
     if ($this->_request->getParam('cdsupplier') != '' && $this->_request->getParam('fgopernature') != '') {
         $paramAccountentry = array('cdsupplier' => $this->_request->getParam('cdsupplier'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'cdusergslab' => $this->_request->getParam('cduser'), 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'), 'cdopernature' => $this->_request->getParam('fgopernature'));
     } else {
         if ($this->_request->getParam('cdsupplier') != '') {
             $paramAccountentry = array('cdsupplier' => $this->_request->getParam('cdsupplier'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'cdusergslab' => $this->_request->getParam('cduser'), 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'));
         } else {
             if ($this->_request->getParam('cdclient') != '' && $this->_request->getParam('fgclienttype') == 'a' && $this->_request->getParam('fgopernature') != '') {
                 $paramAccountentry = array('cdusergslab' => $this->_request->getParam('cduser'), 'cdclient' => $favored, 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'), 'cdopernature' => $this->_request->getParam('fgopernature'));
             } else {
                 if ($this->_request->getParam('cdclient') != '' && $this->_request->getParam('fgclienttype') == 'a') {
                     $paramAccountentry = array('cdusergslab' => $this->_request->getParam('cduser'), 'cdclient' => $favored, 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'));
                 } else {
                     if ($this->_request->getParam('cdclient') != '' && $this->_request->getParam('fgclienttype') == 'b' && $this->_request->getParam('fgopernature') != '') {
                         $paramAccountentry = array('cdusergslab' => $this->_request->getParam('cduser'), 'cdclient' => $favored, 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'), 'cdopernature' => $this->_request->getParam('fgopernature'));
                     } else {
                         if ($this->_request->getParam('cdclient') != '' && $this->_request->getParam('fgclienttype') == 'b') {
                             $paramAccountentry = array('cdusergslab' => $this->_request->getParam('cduser'), 'cdclient' => $favored, 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'));
                         } else {
                             if ($this->_request->getParam('cdclient') == '' && $this->_request->getParam('cdsupplier') == '' && $this->_request->getParam('fgopernature') != '') {
                                 $paramAccountentry = array('cdusergslab' => $this->_request->getParam('cduser'), 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'), 'cdopernature' => $this->_request->getParam('fgopernature'));
                             } else {
                                 if ($this->_request->getParam('cdclient') == '' && $this->_request->getParam('cdsupplier') == '') {
                                     $paramAccountentry = array('cdusergslab' => $this->_request->getParam('cduser'), 'nraccountentry' => $this->_request->getParam('nraccountentry'), 'fgaccountentrytype' => $this->_request->getParam('fgaccountentrytype'), 'cdsupply' => $this->_request->getParam('cdsupply'), 'fgaccountcheck' => $this->_request->getParam('fgaccountcheck'), 'dtdeadline' => $dtdeadline, 'vlinvoicevalue' => $this->_request->getParam('vlinvoicevalue'), 'idinvoiceref' => $this->_request->getParam('idinvoiceref'), 'dttransactiondate' => $dttransactiondate, 'dtentrydate' => $dtentrydate, 'dtinvoicedate' => $dtinvoicedate, 'dsaccountentrydescription' => $this->_request->getParam('dsaccountentrydescription'), 'fgclienttype' => $this->_request->getParam('fgclienttype'));
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $paramAccountcheck = array('cdusergslab' => $this->_request->getParam('cdusergslab'), 'dtaccountcheckdate' => $dtaccountcheckdate, 'vlaccountcheckvalue' => $this->_request->getParam('vlaccountcheckvalue'), 'vltotaltaxvalue' => $this->_request->getParam('vltotaltaxvalue'), 'vlnetvalue' => $this->_request->getParam('vlnetvalue'));
     //update
     if ($this->_request->getParam('cdaccountentry') != '' && $this->_request->getParam('fgaccountcheck') == '0') {
         $this->_model->update($paramAccountentry, 'cdaccountentry = ' . $this->_request->getParam('cdaccountentry'));
         $cdaccountcheck = $AccountCheckModel->insert($paramAccountcheck);
         $AccountCheckModel->getAdapter()->commit();
         $message = "Baixa realizada com sucesso";
     } else {
         if ($this->_request->getParam('cdaccountentry') != '' && $this->_request->getParam('fgaccountcheck') == '1') {
             $this->_model->update($paramAccountentry, 'cdaccountentry = ' . $this->_request->getParam('cdaccountentry'));
             $cdaccountcheck = $AccountCheckModel->insert($paramAccountcheck);
             $AccountCheckModel->getAdapter()->commit();
             $paramentrycheckArray = array('cdaccountentry' => $this->_request->getParam('cdaccountentry'), 'cdaccountcheck' => $cdaccountcheck);
             $accountentrycheckModel->getAdapter()->beginTransaction();
             $accountentrycheckModel->insert($paramentrycheckArray);
             $accountentrycheckModel->getAdapter()->commit();
             $message = "Baixa realizada com sucesso";
         } else {
             if ($this->_request->getParam('cdaccountentry') == '' && $this->_request->getParam('fgaccountcheck') == '0') {
                 $AccountEntryModel->insert($paramAccountentry);
                 $message = "Cadastro efetuado com sucesso";
                 $AccountEntryModel->getAdapter()->commit();
             } else {
                 if ($this->_request->getParam('cdaccountentry') == '' && $this->_request->getParam('fgaccountcheck') == '1') {
                     $cdaccountentry = $this->_model->insert($paramAccountentry);
                     $cdaccountcheck = $AccountCheckModel->insert($paramAccountcheck);
                     $message = "Cadastro efetuado com sucesso";
                     $this->_model->getAdapter()->commit();
                     $AccountCheckModel->getAdapter()->beginTransaction();
                     $AccountCheckModel->getAdapter()->commit();
                     $paramentrycheckArray = array('cdaccountentry' => $cdaccountentry, 'cdaccountcheck' => $cdaccountcheck);
                     $accountentrycheckModel->getAdapter()->beginTransaction();
                     $accountentrycheckModel->insert($paramentrycheckArray);
                     $accountentrycheckModel->getAdapter()->commit();
                 }
             }
         }
     }
     $this->view->message = $message;
 }
 public function searchgridAction()
 {
     $var = $this->_request->getParams();
     $dtbegindate = null;
     $dtenddate = null;
     //      $displaymode = null;
     $accountentryModel = new AccountentryModel();
     $billingModel = new BillingModel();
     $dtbegindate = $this->_request->getParam("dtbegindate");
     $dtenddate = $this->_request->getParam("dtenddate");
     //$displaymode = $this->_request->getParam("displaymode");
     $array = array();
     $accountentryModel->getAdapter()->beginTransaction();
     try {
         $datebegin = new Zend_Date($array['dtbegindate'], 'dd-MM-YYYY');
         $datebegin = $datebegin->toString('YYYY-MM-dd HH:mm:ss');
         $dateend = new Zend_Date($array['dtenddate'], 'dd-MM-YYYY');
         $dateend = $dateend->toString('YYYY-MM-dd HH:mm:ss');
         // print_r($dataperiodaccount);
         /* Faturamento */
         $dataperiodBilling = $billingModel->fetchAll($billingModel->getdataBilling($datebegin, $dateend, $displaymode));
         // print_r($dataperiodBilling);
         $page = $this->_request->getParam("page", 1);
         $limit = $this->_request->getParam("rows");
         $count = count($accounts_receivable);
         $responce = new stdClass();
         /* Manipulação de dados para a grid */
         $varsome = 0;
         $index = 0;
         foreach ($accounts_receivable as $row) {
             $responce->cash_entry = $row->vlinvoicevalue;
             //   $responce->cash_exit = $row->nmcovenant;
             //   $responce->average_balance_period = $row->nmcovenant;
             //   $responce->accumulated_balance = $row->nmcovenant;
             $index++;
         }
         $this->view->search = $responce;
         //  print_r($responce);
     } catch (Exception $e) {
         $accountentryModel->getAdapter()->rollback();
         echo $e->getMessage();
     }
 }