-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ReceptorResidenciaFiscal validator with tests
* Added ComprobanteRegimenFiscal Validator with tests * Removed registerAsserts function, used put function directly instead * The parameter $attributes must be array instead of string[] * Added ComprobanteResidenciaFiscal and its Tests * Fix comprobante must not have ResidenciaFiscal neither NumRegIdTrib * Fix comprobante must not have ResidenciaFiscal neither NumRegIdTrib * Renamed ComprobanteResidenciaFiscal to ReceptorResidenciaFiscal
- Loading branch information
1 parent
270a7a3
commit ecaea32
Showing
4 changed files
with
183 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/CfdiUtils/Validate/Cfdi33/Standard/ReceptorResidenciaFiscal.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
namespace CfdiUtils\Validate\Cfdi33\Standard; | ||
|
||
use CfdiUtils\Nodes\Node; | ||
use CfdiUtils\Nodes\NodeInterface; | ||
use CfdiUtils\Validate\Asserts; | ||
use CfdiUtils\Validate\Cfdi33\Abstracts\AbstractDiscoverableVersion33; | ||
use CfdiUtils\Validate\Status; | ||
|
||
/** | ||
* ComprobanteResidenciaFiscal | ||
* | ||
* Valida que: | ||
* - RESFISC01: Si el RFC no es XEXX010101000 entonces la residencia fiscal no debe existir | ||
* - RESFISC02: Si el RFC sí es XEXX010101000 y existe el complemento de comercio exterior | ||
* entonces la residencia fiscal debe establecerse y no puede ser "MEX" | ||
* - RESFISC03: Si el RFC sí es XEXX010101000 y se registró el número de registro de identificación fiscal | ||
* entonces la residencia fiscal debe establecerse y no puede ser "MEX" | ||
*/ | ||
class ReceptorResidenciaFiscal extends AbstractDiscoverableVersion33 | ||
{ | ||
private function registerAsserts(Asserts $asserts) | ||
{ | ||
$assertDescriptions = [ | ||
'RESFISC01' => 'Si el RFC no es XEXX010101000 entonces la residencia fiscal no debe existir', | ||
'RESFISC02' => 'Si el RFC sí es XEXX010101000 y existe el complemento de comercio exterior' | ||
. ' entonces la residencia fiscal debe establecerse y no puede ser "MEX"', | ||
'RESFISC03' => 'Si el RFC sí es XEXX010101000 y se registró el número de registro de identificación fiscal' | ||
. ' entonces la residencia fiscal debe establecerse y no puede ser "MEX"', | ||
]; | ||
foreach ($assertDescriptions as $code => $title) { | ||
$asserts->put($code, $title); | ||
} | ||
} | ||
public function validate(NodeInterface $comprobante, Asserts $asserts) | ||
{ | ||
$this->registerAsserts($asserts); | ||
|
||
$receptor = $comprobante->searchNode('cfdi:Receptor'); | ||
if ($receptor === null) { | ||
$receptor = new Node('cfdi:Receptor'); | ||
} | ||
|
||
if ('XEXX010101000' !== $receptor['Rfc']) { | ||
$asserts->putStatus( | ||
'RESFISC01', | ||
Status::when(! isset($receptor['ResidenciaFiscal'])) | ||
); | ||
return; | ||
} | ||
|
||
$existsComercioExterior = (null !== $comprobante->searchNode('cfdi:Complemento', 'cce11:ComercioExterior')); | ||
$isValidResidenciaFiscal = '' !== $receptor['ResidenciaFiscal'] && $receptor['ResidenciaFiscal'] !== 'MEX'; | ||
if ($existsComercioExterior) { | ||
$asserts->putStatus( | ||
'RESFISC02', | ||
Status::when($isValidResidenciaFiscal) | ||
); | ||
} | ||
if (isset($receptor['NumRegIdTrib'])) { | ||
$asserts->putStatus( | ||
'RESFISC03', | ||
Status::when($isValidResidenciaFiscal) | ||
); | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ReceptorResidenciaFiscalTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
namespace CfdiUtilsTests\Validate\Cfdi33\Standard; | ||
|
||
use CfdiUtils\Nodes\Node; | ||
use CfdiUtils\Validate\Cfdi33\Standard\ReceptorResidenciaFiscal; | ||
use CfdiUtils\Validate\Status; | ||
use CfdiUtilsTests\Validate\ValidateTestCase; | ||
|
||
class ReceptorResidenciaFiscalTest extends ValidateTestCase | ||
{ | ||
/** @var ReceptorResidenciaFiscal */ | ||
protected $validator; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->validator = new ReceptorResidenciaFiscal(); | ||
} | ||
|
||
public function providerValidCases() | ||
{ | ||
return [ | ||
// RESFISC01: Si el RFC no es XEXX010101000 entonces la residencia fiscal no debe existir | ||
[null, null, null, false, 'RESFISC01'], | ||
['', null, null, false, 'RESFISC01'], | ||
['XXXXXXXXXXXX', null, null, false, 'RESFISC01'], | ||
// RESFISC02: Si el RFC sí es XEXX010101000 y existe el complemento de comercio exterior | ||
// entonces la residencia fiscal debe establecerse y no puede ser "MEX" | ||
['XEXX010101000', 'XXX', null, true, 'RESFISC02'], | ||
// RESFISC03: Si el RFC sí es XEXX010101000 y se registró el número de registro de identificación fiscal | ||
// entonces la residencia fiscal debe establecerse y no puede ser "MEX" | ||
['XEXX010101000', 'XXX', '1234', false, 'RESFISC03'], | ||
]; | ||
} | ||
|
||
/** | ||
* @param $receptorRfc | ||
* @param $residenciaFiscal | ||
* @param $numRegIdTrib | ||
* @param $putComercioExterior | ||
* @param $ok | ||
* @dataProvider providerValidCases | ||
*/ | ||
public function testValidCase($receptorRfc, $residenciaFiscal, $numRegIdTrib, $putComercioExterior, $ok) | ||
{ | ||
$this->comprobante->addChild(new Node('cfdi:Receptor', [ | ||
'Rfc' => $receptorRfc, | ||
'ResidenciaFiscal' => $residenciaFiscal, | ||
'NumRegIdTrib' => $numRegIdTrib, | ||
])); | ||
if ($putComercioExterior) { | ||
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [ | ||
new Node('cce11:ComercioExterior'), | ||
])); | ||
} | ||
$this->runValidate(); | ||
$this->assertFalse($this->asserts->hasErrors()); | ||
$this->assertStatusEqualsCode(Status::ok(), $ok); | ||
} | ||
|
||
public function providerInvalidCases() | ||
{ | ||
return [ | ||
// RESFISC01: Si el RFC no es XEXX010101000 entonces la residencia fiscal no debe existir | ||
[null, '', null, false, 'RESFISC01'], | ||
['', '', null, false, 'RESFISC01'], | ||
['XXXXXXXXXXXX', '', null, false, 'RESFISC01'], | ||
[null, 'GER', null, false, 'RESFISC01'], | ||
['', 'GER', null, false, 'RESFISC01'], | ||
['XXXXXXXXXXXX', 'GER', null, false, 'RESFISC01'], | ||
// RESFISC02: Si el RFC sí es XEXX010101000 y existe el complemento de comercio exterior | ||
// entonces la residencia fiscal debe establecerse y no puede ser "MEX" | ||
['XEXX010101000', null, null, true, 'RESFISC02'], | ||
['XEXX010101000', '', null, true, 'RESFISC02'], | ||
['XEXX010101000', 'MEX', null, true, 'RESFISC02'], | ||
// RESFISC03: Si el RFC sí es XEXX010101000 y se registró el número de registro de identificación fiscal | ||
// entonces la residencia fiscal debe establecerse y no puede ser "MEX" | ||
['XEXX010101000', null, '1234', false, 'RESFISC03'], | ||
['XEXX010101000', '', '1234', false, 'RESFISC03'], | ||
['XEXX010101000', 'MEX', '1234', false, 'RESFISC03'], | ||
]; | ||
} | ||
|
||
/** | ||
* @param $receptorRfc | ||
* @param $residenciaFiscal | ||
* @param $numRegIdTrib | ||
* @param $putComercioExterior | ||
* @param $error | ||
* @dataProvider providerinValidCases | ||
*/ | ||
public function testInvalidCase($receptorRfc, $residenciaFiscal, $numRegIdTrib, $putComercioExterior, $error) | ||
{ | ||
$this->comprobante->addChild(new Node('cfdi:Receptor', [ | ||
'Rfc' => $receptorRfc, | ||
'ResidenciaFiscal' => $residenciaFiscal, | ||
'NumRegIdTrib' => $numRegIdTrib, | ||
])); | ||
if ($putComercioExterior) { | ||
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [ | ||
new Node('cce11:ComercioExterior'), | ||
])); | ||
} | ||
$this->runValidate(); | ||
$this->assertStatusEqualsCode(Status::error(), $error); | ||
} | ||
|
||
public function testValidCaseWithoutReceptorNode() | ||
{ | ||
$this->runValidate(); | ||
$this->assertFalse($this->asserts->hasErrors()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters