Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajuste dos eventos de conciliação para atender NT2024.002_v1.00 #1079

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions fake/fakeSefazCancela.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"tpAmb" => 2,
"razaosocial" => "SUA RAZAO SOCIAL LTDA",
"cnpj" => "99999999999999",
"siglaUF" => "SP",
"siglaUF" => "AM",
"schemes" => "PL_009_V4",
"versao" => '4.00',
"tokenIBPT" => "AAAAAAA",
Expand All @@ -35,17 +35,17 @@

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

$chave = '35345678901234567890123456789012345678901234';
$chave = '13345678901234567890123456789012345678901234';
$justificativa = 'nfe com erros de digitação';
$nProt = '123456789012345';
$response = $tools->sefazCancela($chave, $justificativa, $nProt);

echo FakePretty::prettyPrint($response);

} catch (\Exception $e) {
echo $e->getMessage();
}
}
6 changes: 5 additions & 1 deletion fake/fakeSefazConcilicacao.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"tpAmb" => 2,
"razaosocial" => "SUA RAZAO SOCIAL LTDA",
"cnpj" => "99999999999999",
"siglaUF" => "SP",
"siglaUF" => "MG",
"schemes" => "PL_009_V4",
"versao" => '4.00',
"tokenIBPT" => "AAAAAAA",
Expand Down Expand Up @@ -70,13 +70,17 @@
$std->detPag[0]->dPag = '2024-07-30'; //Obrigatório data do pagamento

//grupo OPCIONAL de informações sobre envolvidos no pagamento

$std->detPag[0]->CNPJPag = '12345678901234'; //opcional, caso seja informado a UFPag também deverá ser informada
// CNPJ transacional do pagamento - Preencher informando o CNPJ do estabelecimento onde o pagamento foi
// processado/transacionado/recebido quando a emissão do documento fiscal ocorrer em estabelecimento distinto

$std->detPag[0]->UFPag = 'SP'; //opcional, caso seja informado a CNPJPag também deverá ser informada
// UF do CNPJ do estabelecimento onde o pagamento foi processado/transacionado/recebido

$std->detPag[0]->CNPJIF = '11111111111111'; //opcinal
//CNPJ da instituição financeira, de pagamento, adquirente ou subadquirente.

$std->detPag[0]->tBand = '20'; //opcional Bandeira da operadora de cartão
//01 Visa
//02 Mastercard
Expand Down
6 changes: 3 additions & 3 deletions fake/fakeSefazDistDfe.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
$tools->loadSoapClass($soap);

$ultNSU = 0;
$numNSU = null;
$numNSU = 0;

$response = $tools->sefazDistDFe($ultNSU, $numNSU);

echo FakePretty::prettyPrint($response);

} catch (\Exception $e) {
echo $e->getMessage();
}
}
8 changes: 4 additions & 4 deletions fake/fakeSefazManifesta.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
$tools->model('55');
$tools->setVerAplic('5.1.34');
$tools->loadSoapClass($soap);

$chave = "35345678901234567890123456789012345678901234";
$justificativa = null;
$justificativa = '';
$tipo = $tools::EVT_CIENCIA;
$response = $tools->sefazManifesta($chave, $tipo, $justificativa);

echo FakePretty::prettyPrint($response);

} catch (\Exception $e) {
echo $e->getMessage();
}
}
11 changes: 8 additions & 3 deletions src/Common/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,14 @@
throw new \RuntimeException("Servico [$service] indisponivel UF [$uf] ou modelo [$this->modelo]");
}
}
$this->urlcUF = $this->getcUF($uf); //recuperação do cUF
if ($this->urlcUF > 91) {
$this->urlcUF = $this->getcUF($this->config->siglaUF); //foi solicitado dado de SVCRS ou SVCAN
//NT 2024.002 1.00 Maio/2024, comentário P08 elemento cOrgao
if ($uf === 'SVRS') {
$this->urlcUF = 92;

Check warning on line 461 in src/Common/Tools.php

View check run for this annotation

Codecov / codecov/patch

src/Common/Tools.php#L461

Added line #L461 was not covered by tests
} else {
$this->urlcUF = $this->getcUF($uf); //recuperação do cUF
if ($this->urlcUF > 91) {
$this->urlcUF = $this->getcUF($this->config->siglaUF); //foi solicitado dado de SVCRS ou SVCAN

Check warning on line 465 in src/Common/Tools.php

View check run for this annotation

Codecov / codecov/patch

src/Common/Tools.php#L465

Added line #L465 was not covered by tests
}
}
$this->urlVersion = $stdServ->$service->version; //recuperação da versão
$this->urlService = $stdServ->$service->url; //recuperação da url do serviço
Expand Down
23 changes: 17 additions & 6 deletions src/Common/Webservices.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ public function __construct(string $xml)
*/
public function get(string $sigla, $amb, int $modelo): \stdClass
{
$autfile = realpath(__DIR__ . '/../../storage/autorizadores.json');
$autorizadores = json_decode(file_get_contents($autfile), true);
if (!key_exists($sigla, $autorizadores[$modelo])) {
throw new \RuntimeException("Nao existe autorizador [$sigla] para os webservices do modelo [$modelo]");
}
$auto = $autorizadores[$modelo][$sigla];
$auto = self::getAuth($sigla, $modelo);
if (empty($auto) || empty($this->std)) {
throw new \RuntimeException('Falhou autorizador, parece vazio');
}
Expand All @@ -72,6 +67,22 @@ public function get(string $sigla, $amb, int $modelo): \stdClass
return $svw;
}

/**
* Obtem a sigla do autorizador para um estado origem e modelo de documento fiscal
* @param string $sigla
* @param int $modelo
* @return string
*/
public static function getAuth(string $sigla, int $modelo): string
{
$autfile = realpath(__DIR__ . '/../../storage/autorizadores.json');
$autorizadores = json_decode(file_get_contents($autfile), true);
if (!key_exists($sigla, $autorizadores[$modelo])) {
throw new \RuntimeException("Nao existe autorizador [$sigla] para os webservices do modelo [$modelo]");
}
return $autorizadores[$modelo][$sigla];
}

/**
* Return WS parameters in a stdClass
*/
Expand Down
25 changes: 20 additions & 5 deletions src/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use NFePHP\Common\Signer;
use NFePHP\Common\UFList;
use NFePHP\NFe\Common\Tools as ToolsCommon;
use NFePHP\NFe\Common\Webservices;
use NFePHP\NFe\Traits\TraitEPECNfce;
use RuntimeException;
use InvalidArgumentException;
Expand Down Expand Up @@ -869,13 +870,24 @@
}
}
//cancela um evento anterior de conciliação financeira
if ($std->cancela) {
if ($std->cancelar) {

Check warning on line 873 in src/Tools.php

View check run for this annotation

Codecov / codecov/patch

src/Tools.php#L873

Added line #L873 was not covered by tests
$tpEvento = self::EVT_CANCELA_CONCILIACAO;
$tagAdic = "<verAplic>{$std->verAplic}</verAplic>"
. "<nProtEvento>{$std->protocolo}</nProtEvento>";
}
/*
NT 2024.002 1.00 Maio/2024, comentário P08 elemento cOrgao
Se for referente a uma NFe (mod 55) usar a SVRS
Se for referente a uma BFCe (mod 65) usar a URL normal
*/
$uf = $this->config->siglaUF;
if ((int)$this->modelo === 55) {
$uf = 'SVRS';

Check warning on line 885 in src/Tools.php

View check run for this annotation

Codecov / codecov/patch

src/Tools.php#L883-L885

Added lines #L883 - L885 were not covered by tests
} else {
$uf = Webservices::getAuth($uf, $this->modelo);

Check warning on line 887 in src/Tools.php

View check run for this annotation

Codecov / codecov/patch

src/Tools.php#L887

Added line #L887 was not covered by tests
}
return $this->sefazEvento(
'AN',
$uf,

Check warning on line 890 in src/Tools.php

View check run for this annotation

Codecov / codecov/patch

src/Tools.php#L890

Added line #L890 was not covered by tests
$std->chNFe,
$tpEvento,
$std->nSeqEvento,
Expand Down Expand Up @@ -1124,7 +1136,12 @@
}
$sSeqEvento = str_pad((string)$nSeqEvento, 2, "0", STR_PAD_LEFT);
$eventId = "ID" . $tpEvento . $chave . $sSeqEvento;
$cOrgao = UFList::getCodeByUF($uf);
//NT 2024.002 versão 1.00 - Maio 2024, comentário P08 elemento cOrgao
if ($tpEvento === self::EVT_CONCILIACAO && $uf === 'SVRS') {
$cOrgao = 92;

Check warning on line 1141 in src/Tools.php

View check run for this annotation

Codecov / codecov/patch

src/Tools.php#L1141

Added line #L1141 was not covered by tests
} else {
$cOrgao = UFList::getCodeByUF($uf);
}
$request = "<evento xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">"
. "<infEvento Id=\"$eventId\">"
. "<cOrgao>$cOrgao</cOrgao>"
Expand All @@ -1139,7 +1156,6 @@
. "<tpEvento>$tpEvento</tpEvento>"
. "<nSeqEvento>$nSeqEvento</nSeqEvento>"
. "<verEvento>$verEvento</verEvento>"
//em alguns casos haverá um verAplic nesta posição ??? ver xsd conciliação
. "<detEvento versao=\"$verEvento\">"
. "<descEvento>$descEvento</descEvento>"
. "$tagAdic"
Expand Down Expand Up @@ -1170,7 +1186,6 @@
$this->isValid($this->urlVersion, $request, 'envEvento');
}
$this->lastRequest = $request;
//return $request;
$parameters = ['nfeDadosMsg' => $request];
$body = "<nfeDadosMsg xmlns=\"$this->urlNamespace\">$request</nfeDadosMsg>";
$this->lastResponse = $this->sendRequest($body, $parameters);
Expand Down