Skip to content

Commit

Permalink
Merge pull request #1020 from robmachado/master
Browse files Browse the repository at this point in the history
docs para insucesso na entrega
  • Loading branch information
robmachado committed Feb 12, 2024
2 parents c659273 + ddc82c1 commit 3f7133f
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 2 deletions.
114 changes: 114 additions & 0 deletions docs/metodos/InsucessoEntrega.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Registro de Insucesso na Entrega da Mercadoria

**Função:** Evento fiscal da NF-e visa registrar as operações de transporte que ocorreram, mas que por algum motivo (recusa do destinatário ou a sua não localização, por exemplo), não foi possível a conclusão do serviço com a efetivação da entrega da mercadoria ao recebedor.

**Processo:** síncrono.

**Método:** nfeRecepcaoEvento

```php

use NFePHP\NFe\Tools;
use NFePHP\Common\Certificate;
use NFePHP\NFe\Common\Standardize;

try {
//$content = conteúdo do certificado PFX
$tools = new Tools($configJson, Certificate::readPfx($content, 'senha'));

//dados do evento de insucesso na entrega
$std = new \stdClass();
//$std->verAplic = '1.2.3'; //opcional se declarado anteriormente - versão da aplicação que está gerando o evento
$std->nSeqEvento = 1;
$std->chNFe = '12345678901234567890123456789012345678901234'; //chave de 44 digitos da nota do fornecedor
$std->imagem = 'kakakakakakakakak'; // aqui pode ser colocada uma imagem ou uma string que fará parte do hash
$std->latitude = null;
$std->longitude = null;
$std->data_tentativa = '2021-04-25T10:34:13-03:00'; //data de recebimento
$std->tentativas = 3;
$std->tipo_motivo = 1;
//1 – Recebedor não encontrado
//2 – Recusa do recebedor
//3 – Endereço inexistente
//4 – Outros (exige informar justificativa)
$std->justificativa = null;
$std->cancelar = false; //permite cancelar um registro de insucesso de entrega se for true

$response = $tools->sefazInsucessoEntrega($std);

//transforma o xml de retorno em um stdClass
$st = new Standardize();
$std = $st->toStd($xmlResp);

//verifique se o evento foi processado
if ($std->cStat != 128) {
//houve alguma falha e o evento não foi processado
//TRATAR
} else {
$cStat = $std->retEvento->infEvento->cStat;
if ($cStat == '135' || $cStat == '136') {
//SUCESSO PROTOCOLAR A SOLICITAÇÂO ANTES DE GUARDAR
$xml = Complements::toAuthorize($tools->lastRequest, $xmlResp);
//grave o XML protocolado
} else {
//houve alguma falha no evento
//TRATAR
}
}
} catch (\Exception $e) {
echo str_replace("\n", "<br/>", $e->getMessage());
}
```

# Cancelamento de evento de Insucesso na Entrega

**Função:** Cancelar o evento de insucesso na entrega anteriormente autorizado

**Processo:** síncrono.

**Método:** nfeRecepcaoEvento

```php

use NFePHP\NFe\Tools;
use NFePHP\Common\Certificate;
use NFePHP\NFe\Common\Standardize;

try {
//$content = conteúdo do certificado PFX
$tools = new Tools($configJson, Certificate::readPfx($content, 'senha'));

//dados do evento de insucesso na entrega
$std = new \stdClass();
//$std->verAplic = '1.2.3'; //opcional se declarado anteriormente - versão da aplicação que está gerando o evento
$std->nSeqEvento = 1;
$std->chNFe = '12345678901234567890123456789012345678901234'; //chave de 44 digitos da nota do fornecedor
$std->protocolo = '123456789012345'; //protocolo de autoriação do evento que se deseja cancelar
$std->cancelar = true; //permite cancelar um registro de insucesso de entrega se for true

$response = $tools->sefazInsucessoEntrega($std);

//transforma o xml de retorno em um stdClass
$st = new Standardize();
$std = $st->toStd($xmlResp);

//verifique se o evento foi processado
if ($std->cStat != 128) {
//houve alguma falha e o evento não foi processado
//TRATAR
} else {
$cStat = $std->retEvento->infEvento->cStat;
if ($cStat == '135' || $cStat == '136') {
//SUCESSO PROTOCOLAR A SOLICITAÇÂO ANTES DE GUARDAR
$xml = Complements::toAuthorize($tools->lastRequest, $xmlResp);
//grave o XML protocolado
} else {
//houve alguma falha no evento
//TRATAR
}
}
} catch (\Exception $e) {
echo str_replace("\n", "<br/>", $e->getMessage());
}
```

65 changes: 65 additions & 0 deletions fake/fakeSefazInsucessoEntrega.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'On');
require_once '../bootstrap.php';

use NFePHP\NFe\Tools;
use NFePHP\Common\Certificate;
use NFePHP\Common\Soap\SoapFake;
use NFePHP\NFe\Common\FakePretty;

try {

$arr = [
"atualizacao" => "2016-11-03 18:01:21",
"tpAmb" => 2,
"razaosocial" => "SUA RAZAO SOCIAL LTDA",
"cnpj" => "99999999999999",
"siglaUF" => "SP",
"schemes" => "PL_009_V4",
"versao" => '4.00',
"tokenIBPT" => "AAAAAAA",
"CSC" => "GPB0JBWLUR6HWFTVEAS6RJ69GPCROFPBBB8G",
"CSCid" => "000001",
"proxyConf" => [
"proxyIp" => "",
"proxyPort" => "",
"proxyUser" => "",
"proxyPass" => ""
]
];
$configJson = json_encode($arr);
$soap = new SoapFake();
$soap->disableCertValidation(true);

$content = file_get_contents('expired_certificate.pfx');
$tools = new Tools($configJson, Certificate::readPfx($content, 'associacao'));
$tools->model('55');
$tools->setVerAplic('5.1.34');
$tools->loadSoapClass($soap);

$std = new \stdClass();
//$std->verAplic = '1.2.3'; //opcional se declarado anteriormente - versão da aplicação que está gerando o evento
$std->nSeqEvento = 1;
$std->chNFe = '12345678901234567890123456789012345678901234'; //chave de 44 digitos da nota do fornecedor
$std->imagem = 'kakakakakakakakak'; // aqui pode ser colocada uma imagem ou uma string que fará parte do hash
$std->latitude = null;
$std->longitude = null;
$std->data_tentativa = '2021-04-25T10:34:13-03:00'; //data de recebimento
$std->tentativas = 3;
$std->tipo_motivo = 1;
//1 – Recebedor não encontrado
//2 – Recusa do recebedor
//3 – Endereço inexistente
//4 – Outros (exige informar justificativa)
$std->justificativa = null;
$std->cancelar = false; //permite cancelar um registro de insucesso de entrega se for true

$response = $tools->sefazInsucessoEntrega($std);

echo FakePretty::prettyPrint($response);

} catch (\Exception $e) {
echo $e->getMessage();
}
2 changes: 0 additions & 2 deletions src/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,15 +754,13 @@ public function sefazInsucessoEntrega(\stdClass $std): string
. "<verAplic>{$std->verAplic}</verAplic>";
if (!$std->cancelar) {
$tagAdic .= "<dhTentativaEntrega>{$std->data_tentativa}</dhTentativaEntrega>";

$n = null;
if (!empty($std->tentativas) && is_numeric($std->tentativas)) {
$n = (int)$std->tentativas;
}
if (!empty($n)) {
$tagAdic .= "<nTentativa>{$n}</nTentativa>";
}

$tagAdic .= "<tpMotivo>{$std->tipo_motivo}</tpMotivo>";
$justificativa = null;
if ($std->tipo_motivo == 4) {
Expand Down

0 comments on commit 3f7133f

Please sign in to comment.