Skip to content

Commit

Permalink
Merge pull request #1054 from nfephp-org/adicionando-parametros-para-…
Browse files Browse the repository at this point in the history
…testes

Parametrizando variáveis dinâmicas
  • Loading branch information
gersonfs authored Jun 3, 2024
2 parents 65dfa15 + a29c12a commit 59d8862
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,13 @@ public function sefazDistDFe(int $ultNSU = 0, int $numNSU = 0, string $chave = n
* @return string
* @throws InvalidArgumentException
*/
public function sefazCCe(string $chave, string $xCorrecao, int $nSeqEvento = 1): string
{
public function sefazCCe(
string $chave,
string $xCorrecao,
int $nSeqEvento = 1,
?\DateTimeInterface $dhEvento = null,
?string $lote = null
): string {
if (empty($chave) || empty($xCorrecao)) {
throw new InvalidArgumentException('CC-e: chave ou motivo da correcao vazio!');
}
Expand All @@ -445,7 +450,7 @@ public function sefazCCe(string $chave, string $xCorrecao, int $nSeqEvento = 1):
$tagAdic = "<xCorrecao>"
. $xCorrecao
. "</xCorrecao><xCondUso>$xCondUso</xCondUso>";
return $this->sefazEvento($uf, $chave, self::EVT_CCE, $nSeqEvento, $tagAdic);
return $this->sefazEvento($uf, $chave, self::EVT_CCE, $nSeqEvento, $tagAdic, $dhEvento, $lote);
}

/**
Expand Down Expand Up @@ -979,7 +984,9 @@ public function sefazEvento(
string $chave,
int $tpEvento,
int $nSeqEvento = 1,
string $tagAdic = ''
string $tagAdic = '',
?\DateTimeInterface $dhEvento = null,
?string $lote = null
): string {
$eventos = [
self::EVT_CCE => ['versao' => '1.00', 'nome' => 'envCCe'],
Expand Down Expand Up @@ -1014,7 +1021,10 @@ public function sefazEvento(
$cnpj = $this->config->cnpj ?? '';
$dt = new \DateTime(date("Y-m-d H:i:sP"), new \DateTimeZone($this->timezone));
$dt->setTimezone(new \DateTimeZone($this->timezone));
$dhEvento = $dt->format('Y-m-d\TH:i:sP');
$dhEventoString = $dt->format('Y-m-d\TH:i:sP');
if ($dhEvento != null) {
$dhEventoString = $dhEvento->format('Y-m-d\TH:i:sP');
}
$sSeqEvento = str_pad((string)$nSeqEvento, 2, "0", STR_PAD_LEFT);
$eventId = "ID" . $tpEvento . $chave . $sSeqEvento;
$cOrgao = UFList::getCodeByUF($uf);
Expand All @@ -1028,7 +1038,7 @@ public function sefazEvento(
$request .= "<CPF>$cnpj</CPF>";
}
$request .= "<chNFe>$chave</chNFe>"
. "<dhEvento>$dhEvento</dhEvento>"
. "<dhEvento>$dhEventoString</dhEvento>"
. "<tpEvento>$tpEvento</tpEvento>"
. "<nSeqEvento>$nSeqEvento</nSeqEvento>"
. "<verEvento>$verEvento</verEvento>"
Expand All @@ -1049,7 +1059,9 @@ public function sefazEvento(
$this->canonical
);
$request = Strings::clearXmlString($request, true);
$lote = $dt->format('YmdHis') . random_int(0, 9);
if ($lote == null) {
$lote = $dt->format('YmdHis') . random_int(0, 9);
}
$request = "<envEvento xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">"
. "<idLote>$lote</idLote>"
. $request
Expand Down

0 comments on commit 59d8862

Please sign in to comment.