Skip to content

Commit 46d377e

Browse files
authored
Merge pull request #4 from giansalex/feature/ubl-21
Validator for UBL 2.1
2 parents 73a9f25 + df31551 commit 46d377e

18 files changed

Lines changed: 685 additions & 10 deletions

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Travis-CI](https://img.shields.io/travis/giansalex/greenter-validator.svg?label=travis-ci&branch=master&style=flat-square)](https://travis-ci.org/giansalex/greenter-validator)
44
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b237d274d88d47fbab43ddac252d73a9)](https://www.codacy.com/app/giansalex/greenter-validator?utm_source=github.com&utm_medium=referral&utm_content=giansalex/greenter-validator&utm_campaign=Badge_Grade)
5-
Symfony Validator for [Greenter](https://github.com/giansalex/greenter)
5+
Symfony Validator for [Greenter](https://github.com/giansalex/greenter) (UBL v2.0, v2.1)
66

77
## Install
88
Using composer from [packagist.org](https://packagist.org/packages/greenter/validator)
@@ -18,6 +18,8 @@ use Greenter\Validator\SymfonyValidator;
1818
$invoice = createInvoice();
1919

2020
$validator = new SymfonyValidator();
21+
// Para UBL 2.1
22+
// $validator = new SymfonyValidator(null, '2.1');
2123
$errors = $validator->validate($invoice);
2224

2325
var_dump($errors);

src/Validator/Loader/AddressLoader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ public function load(ClassMetadata $metadata)
2929
$metadata->addPropertyConstraint('distrito', new Assert\Length(['max' => 100]));
3030
$metadata->addPropertyConstraint('urbanizacion', new Assert\Length(['max' => 25]));
3131
$metadata->addPropertyConstraint('direccion', new Assert\Length(['max' => 100]));
32+
$metadata->addPropertyConstraint('codLocal', new Assert\NotBlank());
3233
}
3334
}

src/Validator/Loader/SalePerceptionLoader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public function load(ClassMetadata $metadata)
2222
'choices' => ['01', '02', '03'],
2323
]),
2424
]);
25-
// $metadata->addPropertyConstraint('tasa', new Assert\NotBlank());
2625
$metadata->addPropertyConstraint('mtoBase', new Assert\NotBlank());
2726
$metadata->addPropertyConstraint('mto', new Assert\NotBlank());
2827
$metadata->addPropertyConstraint('mtoTotal', new Assert\NotBlank());

src/Validator/Loader/SummaryDetailLoader.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,15 @@ public function load(ClassMetadata $metadata)
4444
]);
4545
$metadata->addPropertyConstraint('docReferencia', new Assert\Valid());
4646
$metadata->addPropertyConstraint('percepcion', new Assert\Valid());
47-
$metadata->addPropertyConstraint('total', new Assert\NotBlank());
48-
$metadata->addPropertyConstraint('mtoIGV', new Assert\NotBlank());
47+
$metadata->addPropertyConstraints('total', [
48+
new Assert\NotBlank(),
49+
new Assert\Type(['type' => 'numeric']),
50+
]);
51+
$metadata->addPropertyConstraints('mtoIGV', [
52+
new Assert\NotBlank(),
53+
new Assert\Type(['type' => 'numeric']),
54+
]);
55+
$metadata->addPropertyConstraint('mtoIvap', new Assert\Type(['type' => 'numeric']));
4956
$metadata->addConstraint(new Assert\Callback([$this, 'validate']));
5057
}
5158

src/Validator/Loader/SummaryLoader.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
namespace Greenter\Validator\Loader;
1010

11+
use DateTime;
1112
use Greenter\Model\Summary\Summary;
1213
use Greenter\Validator\Metadata\LoaderMetadataInterface;
1314
use Symfony\Component\Validator\Constraints as Assert;
15+
use Greenter\Validator\Constraint as MyAssert;
1416
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1517
use Symfony\Component\Validator\Mapping\ClassMetadata;
1618

@@ -39,13 +41,17 @@ public function load(ClassMetadata $metadata)
3941
new Assert\Count(['min' => 1, 'max' => 500, 'maxMessage' => 'Solo se permite un maximo de 500 items']),
4042
new Assert\Valid(),
4143
]);
44+
$metadata->addPropertyConstraints('moneda', [
45+
new Assert\NotBlank(),
46+
new MyAssert\Currency(),
47+
]);
4248
$metadata->addConstraint(new Assert\Callback([$this, 'validate']));
4349
}
4450

4551
public function validate($object, ExecutionContextInterface $context)
4652
{
4753
/**@var $object Summary */
48-
if ($object->getFecResumen() > new \DateTime()) {
54+
if ($object->getFecResumen() > new DateTime()) {
4955
$context->buildViolation('2236')
5056
->atPath('fecResumen')
5157
->addViolation();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Greenter\Validator\Loader\v21;
4+
5+
use Greenter\Validator\Metadata\LoaderMetadataInterface;
6+
use Symfony\Component\Validator\Constraints as Assert;
7+
use Symfony\Component\Validator\Mapping\ClassMetadata;
8+
9+
class ChargeLoader implements LoaderMetadataInterface
10+
{
11+
public function load(ClassMetadata $metadata)
12+
{
13+
$metadata->addPropertyConstraints('factor', [
14+
new Assert\NotBlank(),
15+
new Assert\Type(['type' => 'numeric']),
16+
]);
17+
$metadata->addPropertyConstraints('monto', [
18+
new Assert\NotBlank(),
19+
new Assert\Type(['type' => 'numeric']),
20+
]);
21+
$metadata->addPropertyConstraints('montoBase', [
22+
new Assert\NotBlank(),
23+
new Assert\Type(['type' => 'numeric']),
24+
]);
25+
$metadata->addPropertyConstraint('codTipo', new Assert\NotBlank());
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
4+
namespace Greenter\Validator\Loader\v21;
5+
6+
use Greenter\Validator\Metadata\LoaderMetadataInterface;
7+
use Symfony\Component\Validator\Constraints as Assert;
8+
use Symfony\Component\Validator\Mapping\ClassMetadata;
9+
10+
class DetailAttributeLoader implements LoaderMetadataInterface
11+
{
12+
public function load(ClassMetadata $metadata)
13+
{
14+
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
15+
$metadata->addPropertyConstraint('code', new Assert\NotBlank());
16+
$metadata->addPropertyConstraint('fecInicio', new Assert\DateTime());
17+
$metadata->addPropertyConstraint('fecFin', new Assert\DateTime());
18+
$metadata->addPropertyConstraint('duracion', new Assert\Type(['type' => 'int']));
19+
}
20+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Greenter\Validator\Loader\v21;
4+
5+
use Greenter\Validator\Metadata\LoaderMetadataInterface;
6+
use Symfony\Component\Validator\Constraints as Assert;
7+
use Symfony\Component\Validator\Mapping\ClassMetadata;
8+
9+
class DetractionLoader implements LoaderMetadataInterface
10+
{
11+
public function load(ClassMetadata $metadata)
12+
{
13+
$metadata->addPropertyConstraints('percent', [
14+
new Assert\NotBlank(),
15+
new Assert\Type(['type' => 'numeric']),
16+
]);
17+
$metadata->addPropertyConstraints('mount', [
18+
new Assert\NotBlank(),
19+
new Assert\Type(['type' => 'numeric']),
20+
]);
21+
$metadata->addPropertyConstraint('codMedioPago', new Assert\NotBlank());
22+
$metadata->addPropertyConstraint('ctaBanco', new Assert\NotBlank());
23+
$metadata->addPropertyConstraint('codBienDetraccion', new Assert\NotBlank());
24+
}
25+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
namespace Greenter\Validator\Loader\v21;
4+
5+
use Greenter\Validator\Metadata\LoaderMetadataInterface;
6+
use Symfony\Component\Validator\Constraints as Assert;
7+
use Greenter\Validator\Constraint as MyAssert;
8+
use Symfony\Component\Validator\Mapping\ClassMetadata;
9+
10+
class InvoiceLoader implements LoaderMetadataInterface
11+
{
12+
public function load(ClassMetadata $metadata)
13+
{
14+
$metadata->addPropertyConstraints('tipoOperacion', [
15+
new Assert\NotBlank(),
16+
]);
17+
$metadata->addPropertyConstraints('tipoDoc', [
18+
new Assert\NotBlank(),
19+
]);
20+
$metadata->addPropertyConstraints('serie', [
21+
new Assert\NotBlank(),
22+
new Assert\Length(['max' => 4]),
23+
]);
24+
$metadata->addPropertyConstraints('correlativo', [
25+
new Assert\NotBlank(),
26+
new Assert\Length(['max' => 8]),
27+
]);
28+
$metadata->addPropertyConstraints('fechaEmision', [
29+
new Assert\NotBlank(),
30+
new Assert\DateTime(),
31+
]);
32+
$metadata->addPropertyConstraint('fecVencimiento', new Assert\DateTime());
33+
$metadata->addPropertyConstraints('tipoMoneda', [
34+
new Assert\NotBlank(),
35+
new MyAssert\Currency(),
36+
]);
37+
$metadata->addPropertyConstraints('mtoOperGravadas', [
38+
new Assert\Type(['type' => 'numeric']),
39+
]);
40+
$metadata->addPropertyConstraints('mtoOperInafectas', [
41+
new Assert\Type(['type' => 'numeric']),
42+
]);
43+
$metadata->addPropertyConstraints('mtoOperExoneradas', [
44+
new Assert\Type(['type' => 'numeric']),
45+
]);
46+
$metadata->addPropertyConstraints('mtoOperGratuitas', [
47+
new Assert\Type(['type' => 'numeric']),
48+
]);
49+
$metadata->addPropertyConstraints('mtoOperExportacion', [
50+
new Assert\Type(['type' => 'numeric']),
51+
]);
52+
$metadata->addPropertyConstraint('mtoIGV', new Assert\Type(['type' => 'numeric']));
53+
$metadata->addPropertyConstraint('mtoISC', new Assert\Type(['type' => 'numeric']));
54+
$metadata->addPropertyConstraint('mtoBaseIsc', new Assert\Type(['type' => 'numeric']));
55+
$metadata->addPropertyConstraint('mtoOtrosTributos', new Assert\Type(['type' => 'numeric']));
56+
$metadata->addPropertyConstraint('mtoBaseOth', new Assert\Type(['type' => 'numeric']));
57+
$metadata->addPropertyConstraint('mtoDescuentos', new Assert\Type(['type' => 'numeric']));
58+
$metadata->addPropertyConstraint('sumOtrosCargos', new Assert\Type(['type' => 'numeric']));
59+
$metadata->addPropertyConstraint('totalAnticipos', new Assert\Type(['type' => 'numeric']));
60+
$metadata->addPropertyConstraints('totalImpuestos', [
61+
new Assert\NotBlank(),
62+
new Assert\Type(['type' => 'numeric']),
63+
]);
64+
$metadata->addPropertyConstraints('valorVenta', [
65+
new Assert\NotBlank(),
66+
new Assert\Type(['type' => 'numeric']),
67+
]);
68+
$metadata->addPropertyConstraints('mtoImpVenta', [
69+
new Assert\NotBlank(),
70+
new Assert\Type(['type' => 'numeric']),
71+
]);
72+
$metadata->addPropertyConstraints('client', [
73+
new Assert\NotBlank(),
74+
new Assert\Valid(),
75+
]);
76+
$metadata->addPropertyConstraints('company', [
77+
new Assert\NotBlank(),
78+
new Assert\Valid(),
79+
]);
80+
$metadata->addPropertyConstraint('seller', new Assert\Valid());
81+
$metadata->addPropertyConstraint('details', new Assert\Valid());
82+
$metadata->addPropertyConstraint('legends', new Assert\Valid());
83+
$metadata->addPropertyConstraint('guias', new Assert\Valid());
84+
$metadata->addPropertyConstraint('anticipos', new Assert\Valid());
85+
$metadata->addPropertyConstraint('detraccion', new Assert\Valid());
86+
$metadata->addPropertyConstraint('relDocs', new Assert\Valid());
87+
$metadata->addPropertyConstraint('perception', new Assert\Valid());
88+
$metadata->addPropertyConstraint('cargos', new Assert\Valid());
89+
$metadata->addPropertyConstraint('descuentos', new Assert\Valid());
90+
}
91+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Giansalex
5+
* Date: 18/07/2017
6+
* Time: 22:27.
7+
*/
8+
9+
namespace Greenter\Validator\Loader\v21;
10+
11+
use Greenter\Validator\Metadata\LoaderMetadataInterface;
12+
use Symfony\Component\Validator\Constraints as Assert;
13+
use Greenter\Validator\Constraint as MyAssert;
14+
use Symfony\Component\Validator\Mapping\ClassMetadata;
15+
16+
class NoteLoader implements LoaderMetadataInterface
17+
{
18+
public function load(ClassMetadata $metadata)
19+
{
20+
$metadata->addPropertyConstraints('tipoDoc', [
21+
new Assert\NotBlank(),
22+
]);
23+
$metadata->addPropertyConstraints('serie', [
24+
new Assert\NotBlank(),
25+
new Assert\Length(['max' => 4]),
26+
]);
27+
$metadata->addPropertyConstraints('correlativo', [
28+
new Assert\NotBlank(),
29+
new Assert\Length(['max' => 8]),
30+
]);
31+
$metadata->addPropertyConstraints('fechaEmision', [
32+
new Assert\NotBlank(),
33+
new Assert\DateTime(),
34+
]);
35+
$metadata->addPropertyConstraints('tipoMoneda', [
36+
new Assert\NotBlank(),
37+
new MyAssert\Currency(),
38+
]);
39+
$metadata->addPropertyConstraint('codMotivo', new Assert\NotBlank());
40+
$metadata->addPropertyConstraint('tipDocAfectado', new Assert\NotBlank());
41+
$metadata->addPropertyConstraint('numDocfectado', new Assert\NotBlank());
42+
$metadata->addPropertyConstraints('desMotivo', [
43+
new Assert\NotBlank(),
44+
new Assert\Length(['max' => 500]),
45+
]);
46+
$metadata->addPropertyConstraints('mtoOperGravadas', [
47+
new Assert\Type(['type' => 'numeric']),
48+
]);
49+
$metadata->addPropertyConstraints('mtoOperInafectas', [
50+
new Assert\Type(['type' => 'numeric']),
51+
]);
52+
$metadata->addPropertyConstraints('mtoOperExoneradas', [
53+
new Assert\Type(['type' => 'numeric']),
54+
]);
55+
$metadata->addPropertyConstraints('mtoOperGratuitas', [
56+
new Assert\Type(['type' => 'numeric']),
57+
]);
58+
$metadata->addPropertyConstraints('mtoOperExportacion', [
59+
new Assert\Type(['type' => 'numeric']),
60+
]);
61+
$metadata->addPropertyConstraints('totalImpuestos', [
62+
new Assert\NotBlank(),
63+
new Assert\Type(['type' => 'numeric']),
64+
]);
65+
$metadata->addPropertyConstraints('mtoImpVenta', [
66+
new Assert\NotBlank(),
67+
new Assert\Type(['type' => 'numeric']),
68+
]);
69+
$metadata->addPropertyConstraints('client', [
70+
new Assert\NotBlank(),
71+
new Assert\Valid(),
72+
]);
73+
$metadata->addPropertyConstraints('company', [
74+
new Assert\NotBlank(),
75+
new Assert\Valid(),
76+
]);
77+
$metadata->addPropertyConstraint('mtoIGV', new Assert\Type(['type' => 'numeric']));
78+
$metadata->addPropertyConstraint('mtoISC', new Assert\Type(['type' => 'numeric']));
79+
$metadata->addPropertyConstraint('mtoBaseIsc', new Assert\Type(['type' => 'numeric']));
80+
$metadata->addPropertyConstraint('mtoOtrosTributos', new Assert\Type(['type' => 'numeric']));
81+
$metadata->addPropertyConstraint('mtoBaseOth', new Assert\Type(['type' => 'numeric']));
82+
$metadata->addPropertyConstraint('sumOtrosCargos', new Assert\Type(['type' => 'numeric']));
83+
$metadata->addPropertyConstraint('details', new Assert\Valid());
84+
$metadata->addPropertyConstraint('legends', new Assert\Valid());
85+
$metadata->addPropertyConstraint('guias', new Assert\Valid());
86+
$metadata->addPropertyConstraint('relDocs', new Assert\Valid());
87+
$metadata->addPropertyConstraint('perception', new Assert\Valid());
88+
}
89+
}

0 commit comments

Comments
 (0)