public function saveAction()
 {
     $columns = $this->_model->info(Zend_Db_Table_Abstract::COLS);
     $array = array();
     $this->_model->getAdapter()->beginTransaction();
     $message = '';
     // Declaração dos Render() do Zend para a Validação do Formulário
     $formRenders = array($this->_form->addElementsForm(), $this->_form->addElementsExistantStock(), $this->_form->addElementsStockControl());
     // Função que valida os Campos do Formulario com multiplos Render()
     parent::validateMultipleForm($formRenders);
     // <-----
     try {
         foreach ($this->_values as $id => $value) {
             if (isset($value) && $value != '' && in_array($id, $columns)) {
                 $array[$id] = addslashes($value);
             }
         }
         if ($this->_values['cdsupply'] != null) {
             $array['fgsupplycontrol'] = 1;
             if ($this->_values['cdsupplycentre'] != null && $this->_values['cdsupplier'] != null) {
                 date_default_timezone_set('UTC');
                 $supplystockModel = new SupplystockModel();
                 $arraySupplyStock = array();
                 $arraySupplyStock['cdsupply'] = $this->_values['cdsupply'];
                 $arraySupplyStock['cdsupplycentre'] = $this->_values['cdsupplycentre'];
                 $arraySupplyStock['cdsupplier'] = $this->_values['cdsupplier'];
                 $dtcheckin = date("Y-m-d") . " " . date("H:i");
                 $arraySupplyStock['dtcheckin'] = $dtcheckin;
                 if ($this->_values['vlsupplyunit'] != null) {
                     $vlunitprice = $this->_values['vlsupplyunit'];
                     $vlsupplytoDB = str_replace(" ", "", $vlunitprice);
                     $vlsupplytoDB = str_replace(",", ".", $vlsupplytoDB);
                     $vlsupplytoDB = str_replace("R\$", "", $vlsupplytoDB);
                     $arraySupplyStock['vlunitprice'] = $vlsupplytoDB;
                 }
                 if ($this->_values['nrsupplyquantity'] != null) {
                     $supplyModel = new SupplyModel();
                     $arraySupplyStock['qtquantity'] = $this->_values['nrsupplyquantity'];
                     $arraySupplyStock['qtsupplybalance'] = $this->_values['nrsupplyquantity'];
                     $qtdebalance = $supplyModel->fetchRow("cdsupply = " . $this->_values['cdsupply']);
                     $supplyModel->update(array("qtbalance" => $qtdebalance['qtbalance'] + $arraySupplyStock['qtsupplybalance']), "cdsupply = " . $this->_values['cdsupply']);
                 }
                 $supplystockModel->insert($arraySupplyStock);
             }
         } else {
             $array['fgsupplycontrol'] = 2;
         }
         $this->_model->insert($array);
         $message = "Cadastro realizado com sucesso.";
         $this->_model->getAdapter()->commit();
     } catch (Exception $e) {
         $this->_model->getAdapter()->rollBack();
         $message = '';
         $message = "Erro na operação.";
         $message = $e->getMessage();
     }
     $this->view->message = $message;
 }
 public function saveAction()
 {
     $supplyModel = new SupplyModel();
     $data = $this->_request->getParam('data');
     $dataDecode = json_decode($data);
     /* Validação de disponibilidade do item em estoque. */
     $this->_model->getAdapter()->beginTransaction();
     try {
         foreach ($dataDecode as $value) {
             /* VERIFICA SALDO DO ITEM NO ESTOQUE E ATUALIZA O VALOR DE ACORDO COM A MOVIMENTAÇÃO */
             $supplyData = $supplyModel->fetchRow('cdsupply = ' . $value->cdsupply);
             if ($value->qtquantity <= round($supplyData->qtbalance)) {
                 if ($value->cdfgtypemove == 1 || $value->cdfgtypemove == 5) {
                     $supplyModel->update(array('qtbalance' => round($supplyData->qtbalance) - $value->qtquantity), 'cdsupply = ' . $value->cdsupply);
                 }
                 $dtout = new Zend_Date($value->dtcheckout, 'dd-MM-YYYY');
                 $dtcheckout = $dtout->toString("YYYY-MM-dd");
                 $HRout = new Zend_Date($value->hrcheckout, 'HH:mm:ss');
                 $HRcheckout = $HRout->toString("HH:mm:ss");
                 $dthrcheckout = $dtcheckout . " " . $HRcheckout;
                 if (isset($value->dtcheckin) && $value->dtcheckin != '') {
                     $dtin = new Zend_Date($value->dtcheckin, 'dd-MM-YYYY');
                     $dtcheckin = $dtin->toString("YYYY-MM-dd");
                     $HRin = new Zend_Date($value->hrcheckin, 'HH:mm:ss');
                     $HRcheckin = $HRin->toString("HH:mm:ss");
                     $dthrcheckin = $dtcheckin . " " . $HRcheckin;
                 } else {
                     $dthrcheckin = '';
                 }
                 /* CRIA O REGISTRO NA TABELA DE MOVIMENTAÇÕES (supplyflow) */
                 $flow = array('cdsupply' => $value->cdsupply, 'cdsupplycentrefrom' => $value->cdsupplyfrom, 'cdsupplycentreto' => $value->cdsupplyto, 'fgsupplyioreason' => $value->cdfgtypemove, 'qtquantity' => $value->qtquantity, 'dtcheckin' => $dthrcheckin, 'dtcheckout' => $dthrcheckout);
                 /* INSERE AS MOVIMENTAÇÕES NA TABELA */
                 $insertFlow = $this->_model->insert($flow);
             } else {
                 return false;
             }
         }
         $this->_model->getAdapter()->commit();
         $message = "Movimentação efetuada com sucesso.";
     } catch (Exception $e) {
         $this->_model->getAdapter()->rollBack();
         $message = "Erro na inserção dos dados.";
         $message = $e->getMessage();
     }
     $this->view->message = $message;
 }
 public function saveAction()
 {
     parent::saveAction();
     /* Instancia classe SupplyStock */
     $supplystockModel = new SupplystockModel();
     /* Instancia classe Supply */
     $supplyModel = new SupplyModel();
     /* Instancia classe SupplyFlow */
     $supplyflowModel = new SupplyflowModel();
     $supplies = json_decode($_GET['supply'], true);
     $i = 0;
     $supply = array();
     $supplystockModel->getAdapter()->beginTransaction();
     try {
         foreach ($supplies as $row) {
             $data = explode("-", $_POST['dtcheckout']);
             if ($row['dtexpires'] != "Indeterminado") {
                 $expire = explode("-", $row['dtexpires']);
             }
             $valor = substr($row['vlunitprice'], 2);
             /* Adiciona lista de Itens na SupplyStock */
             $supply[$i] = array('cdsupply' => $row['cdsupply'], 'qtquantity' => $row['qtquantity'], 'qtsupplybalance' => $row['qtquantity'], 'cdsupplycentre' => $_POST['cdsupplycentrefrom'], 'dtexpire' => $expire[2] . "-" . $expire[1] . "-" . $expire[0] . " 00:00:00", 'dtcheckin' => $data[2] . "-" . $data[1] . "-" . $data[0] . " " . $_POST['hrcheckin'] . ":00", 'cdsupplier' => $_POST['cdsupplyentrysupplier'], 'idinvoice' => $_POST['cdsupplyinvoice'], 'idbatch' => $_POST['cdsupplylot'], 'vlunitprice' => $valor);
             /* Insere registros na StockFlow */
             $supplyflow[$i] = array('cdsupply' => $row['cdsupply'], 'qtquantity' => $row['qtquantity'], 'cdsupplycentreto' => $_POST['cdsupplycentrefrom'], 'fgsupplyioreason' => '4', 'dtcheckin' => date("Y-m-d H:i:s"), 'dtcheckout' => date("Y-m-d H:i:s"), 'cdsupplycentrefrom' => null);
             /* Atualiza quantidade de itens na Supply */
             $dataSupplier = $supplyModel->fetchRow($supplyModel->getSupplyByCdSupply($row['cdsupply']));
             $dataSupplier['qtbalance'] = $dataSupplier['qtbalance'] + $row['qtquantity'];
             $array['qtbalance'] = $dataSupplier['qtbalance'];
             $supplyModel->update($array, 'cdsupply = ' . $row['cdsupply']);
             $supplystockModel->insert($supply[$i]);
             $supplyflowModel->insert($supplyflow[$i]);
             $i++;
         }
         $lastId = $supplystockModel->getAdapter()->lastInsertId();
         $message = "Cadastro efetuado com sucesso.<br>Número no Protocolo gerado: " . $lastId;
         $supplystockModel->getAdapter()->commit();
     } catch (Exception $e) {
         $supplystockModel->getAdapter()->rollBack();
         $message = "Erro na inserção dos dados.";
     }
     $this->view->message = $message;
 }
 public function saveAction()
 {
     parent::saveAction();
     $supplysupplyflowtypeModel = new SupplysupplyflowtypeModel();
     $supplyModel = new SupplyModel();
     $supplyModel->getAdapter()->beginTransaction();
     $paramSupplyArray = array();
     $paramSupplyflowtype = array();
     $message = '';
     $paramSupplyArray = array('idsupply' => $_POST['idsupply'], 'nmsupply' => $_POST['nmsupply'], 'cdsupplytype' => $_POST['cdsupplytype'], 'cdmeasurementunit' => $_POST['cdmeasurementunit'], 'dspreparation' => $_POST['dspreparation'], 'fgtype' => $this->_request->getParam('fgtype'));
     if ($this->_request->getParam('cdsupply') != '') {
         $supplyModel->update($paramSupplyArray, "cdsupply = " . $this->_request->getParam('cdsupply'));
         $paramSupplyflowtype = array('cdsupply' => $this->_request->getParam('cdsupply'), 'cdsupplyflowtype' => $this->_request->getParam('cdsupplyflowtype'));
         $supplysupplyflowtypeModel->update($paramSupplyflowtype, "cdsupply = " . $this->_request->getParam('cdsupply'));
         $message = "Alteração realizada com sucesso!";
         $supplyModel->getAdapter()->commit();
     } else {
         $cdsupply = $supplyModel->insert($paramSupplyArray);
         $paramSupplyflowtype = array('cdsupply' => $cdsupply, 'cdsupplyflowtype' => $this->_request->getParam('cdsupplyflowtype'));
         $supplysupplyflowtypeModel->insert($paramSupplyflowtype);
         $message = "Cadastro efetuado com sucesso!";
         $supplyModel->getAdapter()->commit();
     }
     $this->view->message = $message;
 }
 public function editmedicinedataAction()
 {
     $values = $this->_request->getParams();
     $RequestMedicineModel = new RequestmedicineModel();
     $SupplyStockModel = new SupplyStockModel();
     $SupplyModel = new SupplyModel();
     $RequestMedicineModel->getAdapter()->beginTransaction();
     try {
         if ($values['oper'] == 'del') {
             if (isset($values['nrstockdiscount'])) {
                 $cdsupply = $SupplyModel->fetchRow($SupplyModel->getCdSupplyByRequestMedicine($values['id']));
                 $qtquantitySupplyStock = $SupplyStockModel->fetchRow("cdsupply = " . $cdsupply['cdsupply']);
                 $qtquantitySupply = $SupplyModel->fetchRow("cdsupply = " . $cdsupply['cdsupply']);
                 $stockReturn = $values['nrstockdiscount'];
                 if ($stockReturn != null && $stockReturn != '') {
                     $SupplyStockModel->update(array("qtquantity" => $qtquantitySupplyStock['qtquantity'] + $stockReturn, "qtsupplybalance" => $qtquantitySupplyStock['qtsupplybalance'] + $stockReturn), "cdsupply = " . $cdsupply['cdsupply']);
                     $SupplyModel->update(array("qtbalance" => $qtquantitySupply['qtbalance'] + $stockReturn), "cdsupply = " . $cdsupply['cdsupply']);
                 }
             }
             $RequestMedicineModel->delete("cdrequestmedicine = " . $values['id']);
         }
         $RequestMedicineModel->getAdapter()->commit();
     } catch (exception $e) {
         $RequestMedicineModel->getAdapter()->rollback();
     }
 }