Skip to content

Commit

Permalink
Merge pull request #1073 from robmachado/master
Browse files Browse the repository at this point in the history
inclusa função para habilitar ou não a validação dos numeros GTIN
  • Loading branch information
robmachado authored Aug 29, 2024
2 parents 73c9ab7 + 92a873f commit bd9aae6
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ class Make
* @var bool
*/
protected $flagISSQNCalc = false;
/**
* @var bool
*/
protected $checkgtin = false;

/**
* Função construtora cria um objeto DOMDocument
Expand Down Expand Up @@ -401,6 +405,16 @@ public function setOnlyAscii(bool $option = false)
$this->replaceAccentedChars = $option;
}

/**
* Set if GTIN is or not validate
* @param bool $option
* @return void
*/
public function setCheckGtin(bool $option = true)
{
$this->checkgtin = $option;
}

/**
* Returns xml string and assembly it is necessary
*/
Expand Down Expand Up @@ -1830,18 +1844,19 @@ public function tagprod(stdClass $std): DOMElement
$cean = !empty($std->cEAN) ? trim(strtoupper($std->cEAN)) : '';
$ceantrib = !empty($std->cEANTrib) ? trim(strtoupper($std->cEANTrib)) : '';
//throw exception if not is Valid
try {
Gtin::isValid($cean);
} catch (\InvalidArgumentException $e) {
$this->errors[] = "cEANT {$cean} " . $e->getMessage();
}
if ($this->checkgtin) {
try {
Gtin::isValid($cean);
} catch (\InvalidArgumentException $e) {
$this->errors[] = "cEANT {$cean} " . $e->getMessage();
}

try {
Gtin::isValid($ceantrib);
} catch (\InvalidArgumentException $e) {
$this->errors[] = "cEANTrib {$ceantrib} " . $e->getMessage();
try {
Gtin::isValid($ceantrib);
} catch (\InvalidArgumentException $e) {
$this->errors[] = "cEANTrib {$ceantrib} " . $e->getMessage();
}
}

$CRT = $this->emit->getElementsByTagName("CRT")->item(0)->nodeValue ?? null;
$idDest = $this->ide->getElementsByTagName("idDest")->item(0)->nodeValue ?? null;
$allowEmptyNcm = $CRT == 4 && $idDest == 1;
Expand Down

0 comments on commit bd9aae6

Please sign in to comment.