Skip to content

Commit

Permalink
ajustes
Browse files Browse the repository at this point in the history
  • Loading branch information
robmachado committed Oct 22, 2021
1 parent 45ace47 commit b727c35
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/testZ50.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use NFePHP\Sintegra\Elements\Z50;

$std = new stdClass();
$std->CNPJ = '00431733813';//'66291561000103'; //Obrig CNPJ/CPF do remetente nas entradas e dos destinátarios nas saídas
$std->CNPJ = '66291561000103'; //Obrig CNPJ/CPF do remetente nas entradas e dos destinátarios nas saídas
$std->IE = '283305054'; //opcional IE do remetente ou isento ou null
$std->DATA_EMISSAO = '20050502'; //Obrig data de emissão
$std->UF = 'SC'; //Obrig Sigla da Unidade da Federação do remetente
Expand Down
4 changes: 4 additions & 0 deletions examples/testZ53.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@

header("Content-Type: text/plain");
echo "{$z53}";

echo "\n";
echo "\n";
print_r($z53->errors);

} catch (\Exception $e) {
echo $e->getMessage();
Expand Down
22 changes: 22 additions & 0 deletions src/Common/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use NFePHP\Common\Strings;
use stdClass;
use Brazanation\Documents;

abstract class Element implements ElementInterface
{
Expand Down Expand Up @@ -200,6 +201,27 @@ protected function isFieldInError($input, $param, $fieldname, $element, $require
}
return;
}

/**
* Valida o CNPJ ou CPF passado no campo CNPJ
*
* @return void
*/
protected function validDoc()
{
if (substr($this->std->cnpj, 0, 3) == '000') {
$result = Documents\Cpf::createFromString($this->std->cnpj);
} else {
$result = Documents\Cnpj::createFromString($this->std->cnpj);
}
if ($result === false) {
$this->errors[] = (object) [
'message' => "[$this->reg] campo: CNPJ/CPF "
. "[{$this->std->cnpj}] é INCORRETO ou FALSO.",
'std' => $this->std
];
}
}

/**
* Formata os campos float
Expand Down
22 changes: 0 additions & 22 deletions src/Elements/Z50.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

use NFePHP\Sintegra\Common\Element;
use NFePHP\Sintegra\Common\ElementInterface;
use Brazanation\Documents;

class Z50 extends Element implements ElementInterface
{
Expand Down Expand Up @@ -229,25 +228,4 @@ public function postValidation()
}
$this->validDoc();
}

/**
* Valida o CNPJ ou CPF passado no campo CNPJ
*
* @return void
*/
private function validDoc()
{
if (substr($this->std->cnpj, 0, 3) == '000') {
$result = Documents\Cpf::createFromString($this->std->cnpj);
} else {
$result = Documents\Cnpj::createFromString($this->std->cnpj);
}
if ($result === false) {
$this->errors[] = (object) [
'message' => "[$this->reg] campo: CNPJ/CPF "
. "[{$this->std->cnpj}] é INCORRETO ou FALSO.",
'std' => $this->std
];
}
}
}
2 changes: 1 addition & 1 deletion src/Elements/Z53.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Z53 extends Element implements ElementInterface
protected $parameters = [
'CNPJ' => [
'type' => 'string',
'regex' => '^[0-9]{14}$',
'regex' => '^[0-9]{11,14}$',
'required' => false,
'info' => 'CNPJ do remetente nas entradas e dos destinátarios nas saídas',
'format' => '',
Expand Down
2 changes: 1 addition & 1 deletion src/Elements/Z88EAN.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Z88EAN extends Element implements ElementInterface
protected $parameters = [
'VERSAO_EAN' => [
'type' => 'numeric',
'regex' => '^[0-9]{11,14}$',
'regex' => '^[0-9]{8,14}$',
'required' => true,
'info' => 'Versão do código EAN (08, 12, 13 ou 14)',
'format' => '',
Expand Down

0 comments on commit b727c35

Please sign in to comment.