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

inclusa função para habilitar ou não a validação dos numeros GTIN #1073

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
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