Esempio n. 1
0
 protected function _pedido($data)
 {
     $idPedido = 0;
     try {
         $idVeiculo = $this->_veiculo($data);
         //$this->_log('Veiculo OK');
         $idCliente = $this->_cliente($data);
         //$this->_log('Cliente OK');
         $idFuncionario = $this->_funcionario($data);
         //$this->_log('Funcionario OK');
         $dtEmis = $this->_toDate($data->dataVistoria);
         $this->_pedido->newRow();
         $ini = clone $dtEmis;
         $fim = clone $dtEmis;
         $ini->addDay(-7);
         $fim->addDay(+7);
         $_where = new ZendT_Db_Where();
         $_where->addFilter('pedido.id_veiculo', $idVeiculo);
         $_where->addFilter('pedido.id_empresa', Auth_Session_User::getInstance()->getIdEmpresa());
         $_where->addFilter('pedido.dt_emis', array($ini, $fim), 'BETWEEN');
         $exists = $this->_pedido->exists($_where);
         $this->_pedido->setIdCliente($idCliente)->setIdFuncionario($idFuncionario)->setDtEmis($dtEmis)->setIdVeiculo($idVeiculo);
         if (!$exists) {
             $itemPedido = array();
             $itemPedido['id_produto'] = $this->_produto->getId();
             $itemPedido['qtd_item'] = 1;
             $this->_pedido->setItemPedido($itemPedido);
             $pagtoPedido = array();
             $pagtoPedido['id_forma_pagto'] = $this->_formaPagto->getId();
             $this->_pedido->setPagamento($pagtoPedido);
             //echo 'Inserindo' . "\n";
             $this->_pedido->insert();
             //echo 'Inserido' . "\n";
         } else {
             //echo 'Atualizando' . "\n";
             $this->_pedido->update();
             //echo 'Atualizado' . "\n";
         }
         //$this->_log('Pedido OK');
         $data->id_pedido = $this->_pedido->getId();
         $data->id_veiculo = $idVeiculo;
         //echo "Pedido: " . $data->id_pedido;
         $this->_vistoria($data);
         //$this->_log('Vistoria OK');
         $idPedido = $this->_pedido->getId();
     } catch (Exception $ex) {
         $this->_log('Placa: ' . $data->placa . '. Erro: ' . $ex->getMessage());
     }
     return $idPedido;
 }
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'));
 }