Esempio n. 1
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";
 }
Esempio n. 2
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'));
 }