Example #1
0
 /**
  * Retorna o valor antigo do registro antes de realizar a atualização
  *
  * @return Tools_Model_LogErro_Mapper
  */
 public function getValueOld()
 {
     if (!$this->_dataOld instanceof Tools_Model_LogErro_Mapper) {
         $this->_dataOld = new Tools_Model_LogErro_Mapper();
         $this->_dataOld->setId($this->getId());
         $this->_dataOld->retrive();
     }
     return $this->_dataOld;
 }
Example #2
0
 public static function log($proc, $message)
 {
     if (self::$_instance == null) {
         self::$_instance = new Tools_Model_LogErro_Mapper();
     }
     self::$_instance->newRow();
     self::$_instance->setProcedimento($proc)->setDhLog(ZendT_Type_Date::nowDateTime())->setMensagem(substr($message, 0, 999))->insert();
     return true;
 }
Example #3
0
 /**
  * 
  */
 public function run()
 {
     $_job = new Tools_DataView_Job_MapperView();
     $_job->setId($this->jobId)->retrieve();
     try {
         $start = ZendT_Type_Date::nowDateTime();
         $config = array('useragent' => 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/44.0', 'encodecookies' => false, 'timeout' => 60 * 60);
         $params = Tools_Interface_Job::prepareParams($_job->getParametro()->toPhp());
         $_client = new Zend_Http_Client($_job->getProcedimento()->toPhp(), $config);
         if (count($params) > 0) {
             foreach ($params as $name => $value) {
                 $_client->setParameterGet($name, $value);
             }
         }
         $response = $_client->request();
         $message = $response->getBody();
         if ($message == '' || $message == 'OK') {
         } else {
             Tools_Model_LogErro_Mapper::log($_job->getProcedimento()->toPhp(), $message);
         }
         $finish = ZendT_Type_Date::nowDateTime();
         $diff = $start->diff($finish);
         $_job->setTempoUlExec($diff->i);
     } catch (Exception $ex) {
         $message = 'Mensagem: ' . $ex->getMessage() . "\n";
         $message .= 'Erro: ' . $ex->getTraceAsString() . "\n";
         Tools_Model_LogErro_Mapper::log($_job->getProcedimento()->toPhp(), $message);
         $_job->setTempoUlExec(0);
     }
     $_job->setDhUltExec(ZendT_Type_Date::nowDateTime());
     $_job->setStatus('A');
     $_job->update();
     return true;
 }
Example #4
0
 public function run()
 {
     $_job = new Tools_DataView_Job_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('job.dh_pro_exec', ZendT_Type_Date::nowDateTime(), '<=');
     $_where->addFilter('job.dh_fim_exec', ZendT_Type_Date::nowDateTime(), '>=');
     $_where->addFilter('job.status', 'A');
     $_job->findAll($_where, '*');
     while ($_job->fetch()) {
         $_now = ZendT_Type_Date::nowDateTime();
         while ($_job->getDhProExec()->toPhp() <= $_now->toPhp()) {
             if ($_job->getTpFrequencia()->toPhp() == 'H') {
                 $_job->getDhProExec()->addHour($_job->getNumFrequencia()->toPhp());
             } else {
                 if ($_job->getTpFrequencia()->toPhp() == 'D') {
                     $_job->getDhProExec()->addDay($_job->getNumFrequencia()->toPhp());
                 } else {
                     if ($_job->getTpFrequencia()->toPhp() == 'M') {
                         $_job->getDhProExec()->addMonth($_job->getNumFrequencia()->toPhp());
                     }
                 }
             }
         }
         $_job->setStatus('E');
         $_job->update();
         try {
             if ($_job->getFormaExec()->toPhp() == 'C') {
                 $_adapter = new Tools_Interface_Job_Php();
             } else {
                 $_adapter = new Tools_Interface_Job_Http();
             }
             $_adapter->jobId = $_job->getId()->toPhp();
             $_th = new ZendT_Thread();
             $_th->start($_adapter, 'run');
         } catch (Exception $ex) {
             $message = 'Mensagem: ' . $ex->getMessage() . "\n";
             $message .= 'Erro: ' . $ex->getTraceAsString() . "\n";
             Tools_Model_LogErro_Mapper::log($_job->getProcedimento()->toPhp(), $message);
         }
     }
 }
Example #5
0
 /**
  * 
  */
 public function run()
 {
     $_job = new Tools_DataView_Job_MapperView();
     $_job->setId($this->jobId)->retrieve();
     try {
         $start = ZendT_Type_Date::nowDateTime();
         $params = Tools_Interface_Job::prepareParams($_job->getParametro()->toPhp());
         $procedimento = explode("::", $_job->getProcedimento()->toPhp());
         $_obj = new $procedimento[0]();
         $_obj->{$procedimento[1]}($params);
         $finish = ZendT_Type_Date::nowDateTime();
         $diff = $start->diff($finish);
         $_job->setTempoUlExec($diff->i);
     } catch (Exception $ex) {
         $message = 'Mensagem: ' . $ex->getMessage() . "\n";
         $message .= 'Erro: ' . $ex->getTraceAsString() . "\n";
         Tools_Model_LogErro_Mapper::log($_job->getProcedimento()->toPhp(), $message);
         $_job->setTempoUlExec(0);
     }
     $_job->setDhUltExec(ZendT_Type_Date::nowDateTime());
     $_job->setStatus('A');
     $_job->update();
     return true;
 }
Example #6
0
 /**
  * Retorna o SQL Base
  */
 protected function _getSqlBase()
 {
     $sql = parent::_getSqlBase();
     return $sql;
 }
Example #7
0
 public function runLaudos($where = array())
 {
     $this->_log('Iniciado: ' . date('d/m/Y H:s:i'));
     Auth_Session_User::refresh('JOB_VSP');
     $this->_token = $this->_doLogin();
     $_pedido = new Vendas_DataView_Pedido_MapperView();
     $_vistoria = new Vendas_DataView_Vistoria_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('pedido.id_empresa', Auth_Session_User::getInstance()->getIdEmpresa());
     if (isset($where['placa'])) {
         $_where->addFilter('veiculo.placa', $where['placa']);
     } else {
         $_where->addFilter('pedido.status_edi', 'N');
     }
     if (isset($where['cnpj_cliente']) && $where['cnpj_cliente']) {
         $_where->addFilter('cliente.codigo', $where['cnpj_cliente']);
         //33164021000100
     }
     if (isset($where['dt_emis']) && $where['dt_emis']) {
         if (!is_array($where['dt_emis'])) {
             $where['dt_emis'] = array($where['dt_emis']);
         }
         $where['dt_emis'][0] = new ZendT_Type_Date($where['dt_emis'][0], 'Date');
         if (!isset($where['dt_emis'][1])) {
             $where['dt_emis'][1] = $where['dt_emis'][0];
         } else {
             $where['dt_emis'][1] = new ZendT_Type_Date($where['dt_emis'][1], 'Date');
         }
         $_where->addFilter('pedido.dt_emis', $where['dt_emis'], 'BETWEEN');
     }
     $sql = "(SELECT 1" . "  FROM " . Vendas_DataView_Vistoria_MapperView::$table . " as vistoria " . " WHERE vistoria.id_pedido = pedido.id" . "   AND vistoria.laudo IS NULL)";
     $_where->addFilterExists($sql);
     $_pedido->findAll($_where, '*');
     $total = $_pedido->getCountRows();
     $seq = 1;
     while ($row = $_pedido->fetch()) {
         try {
             $this->_log("Processando " . $seq . " de " . $total . ", Placa: " . $row['placa_veiculo']);
             $_vistoria->newRow();
             $_vistoria->setIdPedido($row['id'])->retrieve();
             if ($_vistoria->getLaudo(true)->toPhp() == '' && $_vistoria->getNumero(true)->toPhp() != '') {
                 $laudo = $this->_laudo($_vistoria->getNumero()->get());
                 if ($laudo) {
                     $_laudo = new ZendT_File(str_replace(array('-', '/'), '_', $_vistoria->getNumero()->get()) . '.pdf', $laudo, 'application/pdf');
                     $dataLaudo = array();
                     $dataLaudo['file'] = $_laudo;
                     $_vistoria->setLaudo($dataLaudo);
                     $_vistoria->update();
                 }
             }
         } catch (Exception $ex) {
             $message = 'Mensagem: ' . $ex->getMessage() . "\n";
             $message .= 'Erro: ' . $ex->getTraceAsString() . "\n";
             Vendas_Model_LogPedido_Mapper::log($_pedido->getId(), $ex->getMessage());
             Tools_Model_LogErro_Mapper::log('Vendas_Interface_Vsp_Tokio', $message);
             $this->_log('Placa: ' . $row['placa_veiculo'] . ', Erro: ' . $message);
         }
         $seq++;
     }
     $this->_log('Finalizado: ' . date('d/m/Y H:s:i'));
     echo "OK";
 }
Example #8
0
 public function run($where = '')
 {
     $this->_log('Iniciado: ' . date('d/m/Y H:s:i'));
     Auth_Session_User::refresh('JOB_VSP');
     $_pedido = new Vendas_DataView_Pedido_MapperView();
     $_vistoria = new Vendas_DataView_Vistoria_MapperView();
     $_where = new ZendT_Db_Where();
     $_where->addFilter('pedido.id_empresa', Auth_Session_User::getInstance()->getIdEmpresa());
     $_where->addFilter('cliente.codigo', '33164021000100');
     if (isset($where['placa'])) {
         $_where->addFilter('veiculo.placa', $where['placa']);
     } else {
         $_where->addFilter('pedido.status_edi', 'N');
     }
     if (isset($where['dt_emis']) && $where['dt_emis']) {
         if (!is_array($where['dt_emis'])) {
             $where['dt_emis'] = array($where['dt_emis']);
         }
         $where['dt_emis'][0] = new ZendT_Type_Date($where['dt_emis'][0], 'Date');
         if (!isset($where['dt_emis'][1])) {
             $where['dt_emis'][1] = $where['dt_emis'][0];
         } else {
             $where['dt_emis'][1] = new ZendT_Type_Date($where['dt_emis'][1], 'Date');
         }
         $_where->addFilter('pedido.dt_emis', $where['dt_emis'], 'BETWEEN');
     }
     $sql = "(SELECT 1" . "  FROM " . Vendas_DataView_Vistoria_MapperView::$table . " as vistoria " . " WHERE vistoria.id_pedido = pedido.id" . "   AND vistoria.laudo IS NOT NULL)";
     $_where->addFilterExists($sql);
     $_pedido->findAll($_where, '*');
     $total = $_pedido->getCountRows();
     $seq = 1;
     while ($row = $_pedido->fetch()) {
         try {
             $this->_log("Processando " . $seq . " de " . $total . ", Placa: " . $row['placa_veiculo']);
             $_vistoria->newRow()->setIdPedido($_pedido->getId())->retrieve();
             $pdf = $_vistoria->getLaudo()->getFile();
             $fileName = $pdf->getFilename();
             $dtConclusao = date("d/m/Y", $_vistoria->getDtEmis()->toPhp());
             /* var_dump($fileName);
                exit; */
             $this->postPdf($row['placa_veiculo'], $row['sinistro'], $fileName, $dtConclusao);
             $_pedido->setStatusEdi('T');
         } catch (Exception $ex) {
             $message = 'Mensagem: ' . $ex->getMessage() . "\n";
             //$message.= 'Erro: ' . $ex->getTraceAsString() . "\n";
             $_pedido->setStatusEdi('E');
             Vendas_Model_LogPedido_Mapper::log($_pedido->getId(), $ex->getMessage());
             Tools_Model_LogErro_Mapper::log('Vendas_Interface_Vsp_Tokio', $message);
             $this->_log('Placa: ' . $row['placa_veiculo'] . ', Erro: ' . $message);
         }
         $_pedido->update();
         $seq++;
     }
     echo "OK";
     $this->_log('Finalizado: ' . date('d/m/Y H:s:i'));
 }
Example #9
0
 /**
  * 
  */
 public function run($params = array())
 {
     $message = var_export($params, true);
     Tools_Model_LogErro_Mapper::log('Tools_Interface_Job_Test', $message);
     return $params;
 }