Skip to content

Commit cc6c1a7

Browse files
committed
Version 2.12.0
2 parents d04c0f2 + 0b86450 commit cc6c1a7

19 files changed

+812
-141
lines changed

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
[![Scrutinizer][badge-quality]][quality]
1111
[![Coverage Status][badge-coverage]][coverage]
1212
[![Total Downloads][badge-downloads]][downloads]
13-
[![SensioLabsInsight][badge-sensiolabs]][sensiolabs]
1413

1514
> PHP Common utilities for Mexican CFDI 3.2 & 3.3
1615
@@ -22,8 +21,10 @@ También te esperamos en el [canal #phpcfdi de discord](https://discord.gg/aFGYX
2221
The documentation related to this library and its API is documented in [Read the docs][documentation].
2322
It is written in **spanish language** since is the language of the intented audience.
2423

25-
**Warning: this project will be migrated to `phpcfdi/cfdiutils`, don't have a release date yet**
24+
**Nota: Este proyecto será migrado a `phpcfdi/cfdiutils`, aún no tenemos fecha planeada**
2625

26+
No olvides visitar <https://www.phpcfdi.com> donde contamos con muchas más librerías relacionadas con
27+
CFDI y herramientas del SAT. Y próximamente el lugar donde publicaremos la versión `3.y.z`.
2728

2829
## Main features
2930

@@ -96,18 +97,16 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
9697
[build]: https://travis-ci.org/eclipxe13/CfdiUtils?branch=master
9798
[appveyor]: https://ci.appveyor.com/project/eclipxe13/cfdiutils/branch/master
9899
[quality]: https://scrutinizer-ci.com/g/eclipxe13/CfdiUtils/?branch=master
99-
[sensiolabs]: https://insight.sensiolabs.com/projects/87975c73-2f3b-480a-8cce-e78b15986d7b
100100
[coverage]: https://scrutinizer-ci.com/g/eclipxe13/CfdiUtils/code-structure/master/code-coverage/src/CfdiUtils/
101101
[downloads]: https://packagist.org/packages/eclipxe/CfdiUtils
102102

103-
[badge-source]: http://img.shields.io/badge/source-eclipxe13/CfdiUtils-blue.svg?logo=github&style=flat-square
104-
[badge-documentation]: https://img.shields.io/readthedocs/cfdiutils/stable.svg?logo=read-the-docs&style=flat-square
105-
[badge-discord]: https://img.shields.io/discord/459860554090283019.svg?logo=discord&style=flat-square
106-
[badge-release]: https://img.shields.io/github/release/eclipxe13/CfdiUtils.svg?style=flat-square
107-
[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
108-
[badge-build]: https://img.shields.io/travis/eclipxe13/CfdiUtils/master.svg?logo=travis&style=flat-square
109-
[badge-appveyor]: https://img.shields.io/appveyor/ci/eclipxe13/cfdiutils/master.svg?logo=appveyor&style=flat-square
110-
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/CfdiUtils/master.svg?logo=scrutinizer-ci&style=flat-square
111-
[badge-sensiolabs]: https://insight.sensiolabs.com/projects/87975c73-2f3b-480a-8cce-e78b15986d7b/mini.png
112-
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/eclipxe13/CfdiUtils/master.svg?logo=scrutinizer-ci&style=flat-square
113-
[badge-downloads]: https://img.shields.io/packagist/dt/eclipxe/CfdiUtils.svg?style=flat-square
103+
[badge-source]: http://img.shields.io/badge/source-eclipxe13/CfdiUtils-blue?logo=github&style=flat-square
104+
[badge-documentation]: https://img.shields.io/readthedocs/cfdiutils/stable?logo=read-the-docs&style=flat-square
105+
[badge-discord]: https://img.shields.io/discord/459860554090283019?logo=discord&style=flat-square
106+
[badge-release]: https://img.shields.io/github/release/eclipxe13/CfdiUtils?style=flat-square
107+
[badge-license]: https://img.shields.io/github/license/eclipxe13/CfdiUtils?style=flat-square
108+
[badge-build]: https://img.shields.io/travis/eclipxe13/CfdiUtils/master?logo=travis&style=flat-square
109+
[badge-appveyor]: https://img.shields.io/appveyor/ci/eclipxe13/cfdiutils/master?logo=appveyor&style=flat-square
110+
[badge-quality]: https://img.shields.io/scrutinizer/g/eclipxe13/CfdiUtils/master?logo=scrutinizer-ci&style=flat-square
111+
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/eclipxe13/CfdiUtils/master?logo=scrutinizer-ci&style=flat-square
112+
[badge-downloads]: https://img.shields.io/packagist/dt/eclipxe/CfdiUtils?style=flat-square

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"keywords": ["cfdi", "cfdi33", "mexico", "electronic invoice"],
55
"homepage": "https://github.com/eclipxe13/CfdiUtils",
66
"support": {
7-
"wiki": "https://github.com/eclipxe13/CfdiUtils/wiki",
8-
"issues": "https://github.com/eclipxe13/CfdiUtils/issues"
7+
"issues": "https://github.com/eclipxe13/CfdiUtils/issues",
8+
"docs": "https://cfdiutils.readthedocs.io/"
99
},
1010
"license": "MIT",
1111
"authors": [
@@ -31,6 +31,7 @@
3131
"ext-openssl": "*",
3232
"ext-soap": "*",
3333
"ext-iconv": "*",
34+
"ext-json": "*",
3435
"symfony/process": "^3.4|^4.2",
3536
"eclipxe/xmlresourceretriever": "^1.3.0",
3637
"eclipxe/xmlschemavalidator": "^2.0.2"

docs/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
- Remove `CfdiUtils\ConsultaCfdiSat\Config::getWsdlLocation()`, `CfdiUtils\ConsultaCfdiSat\Config::getWsdlLocation()`
2626
and fix `CfdiUtils\ConsultaCfdiSat\Config::__construct()`.
2727
- Remove file `ConsultaCFDIServiceSAT.svc.xml`.
28+
- Change visibility of `CfdiUtils\Cleaner\Cleaner#removeIncompleteSchemaLocation()` to private.
29+
30+
31+
## Version 2.12.0 2019-09-03
32+
33+
- Add `CfdiCreator33::moveSatDefinitionsToComprobante()` method to move xml definitions
34+
(`xmlns:*` and `xsi:schemaLocation`) to root node where namespace starts with `http://www.sat.gob.mx`.
35+
- Add `CfdiUtils\Nodes\NodeNsDefinitionsMover` that allows to move all (or filtered) namespace definitions
36+
(`xmlns:*` and `xsi:schemaLocation`) to root node.
37+
- Improve `XmlNodeImporter` to read xml as `<node xmlns="namespace"/>`.
38+
- Create `SchemaLocations`, this utility helps to manage the content of `xsi:schemaLocation` attribute.
39+
- Refactor `Cleaner`, internal improvements and use of `SchemaLocations`.
40+
- Mark `CfdiUtils\Cleaner\Cleaner:removeIncompleteSchemaLocation()` as internal, it should always be private
41+
- Fix composer.json links
2842

2943

3044
## Version 2.11.0 2019-08-06

docs/crear/complementos-aun-no-implementados.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,15 @@ $creator->saveXml('archivo_con_complemento.xml');
5656
Dado el ejemplo anterior, el comprobante contendrá la siguiente información:
5757

5858
```xml
59-
<Comprobante>
59+
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3"
60+
xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd">
6061
<!-- ... nodos del comprobante ... -->
61-
<Complemento>
62+
<cfdi:Complemento>
6263
<!-- ... otros complementos ... -->
63-
<leyendasFisc:LeyendasFiscales
64-
xmlns:leyendasFisc="http://www.sat.gob.mx/leyendasFiscales"
65-
xsi:schemaLocation = "http://www.sat.gob.mx/leyendasFiscales http://www.sat.gob.mx/sitio_internet/cfd/leyendasFiscales/leyendasFisc.xsd"
66-
version="1.0">
67-
<leyendasFisc:Leyenda
68-
disposicionFiscal="RESDERAUTH"
69-
norma = "Artíclo 2. Fracción IV."
70-
textoLeyenda = "El software desarrollado se entrega con licencia MIT" />
64+
<leyendasFisc:LeyendasFiscales version="1.0" xmlns:leyendasFisc="http://www.sat.gob.mx/leyendasFiscales"
65+
xsi:schemaLocation = "http://www.sat.gob.mx/leyendasFiscales http://www.sat.gob.mx/sitio_internet/cfd/leyendasFiscales/leyendasFisc.xsd">
66+
<leyendasFisc:Leyenda disposicionFiscal="RESDERAUTH" norma = "Artíclo 2. Fracción IV." textoLeyenda = "El software desarrollado se entrega con licencia MIT" />
7167
</leyendasFisc:LeyendasFiscales>
72-
</Complemento>
73-
</Comprobante>
68+
</cfdi:Complemento>
69+
</cfdi:Comprobante>
7470
```

docs/crear/crear-cfdi.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Esta clase es una especie de pegamento de todas las pequeñas utilerías y estru
3636
y realiza validaciones adicionales.
3737
Consulta la [documentación de validaciones](../validar/validacion-cfdi.md) para más información.
3838

39+
- `moveSatDefinitionsToComprobante(): void`: Mueve las declaraciones de espacios de nombres `xmlns:*`
40+
y las declaraciones de ubicación de esquemas `xsi:schemaLocation` al nodo raíz.
3941

4042
## Pasos básicos de creación de un CFDI
4143

@@ -73,6 +75,9 @@ $creator->addSumasConceptos(null, 2);
7375
// método de ayuda para generar el sello (obtener la cadena de origen y firmar con la llave privada)
7476
$creator->addSello('file:// ... ruta para mi archivo key convertido a PEM ...', 'contraseña de la llave');
7577

78+
// método de ayuda para mover las declaraciones de espacios de nombre al nodo raíz
79+
$creator->moveSatDefinitionsToComprobante();
80+
7681
// método de ayuda para validar usando las validaciones estándar de creación de la librería
7782
$asserts = $creator->validate();
7883
$asserts->hasErrors(); // contiene si hay o no errores
@@ -92,8 +97,53 @@ A diferencia de los nodos, los elementos contienen métodos de ayuda que pemiten
9297
por ejemplo `CfdiUtils\Elements\Cfdi33\Comprobante` contiene un método llamado `addReceptor()`
9398
con el que se puede insertar en el lugar correcto el nodo "Receptor" incluyendo un arreglo de atributos.
9499

100+
## Acerca de las definiciones de espacios de nombre
101+
102+
A partir de la versión `2.12.0` se agregó el método `moveSatDefinitionsToComprobante()` que ayuda a mover las
103+
definiciones de espacios de nombres al nodo principal `cfdi:Comprobante`.
104+
105+
Si no se llama a este método, las definciones de espacios de nombres quedarán en el nodo que las utiliza, por
106+
ejemplo:
107+
108+
```xml
109+
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3"
110+
xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd">
111+
<!-- ... nodos del comprobante ... -->
112+
<cfdi:Complemento>
113+
<!-- ... otros complementos ... -->
114+
<leyendasFisc:LeyendasFiscales version="1.0" xmlns:leyendasFisc="http://www.sat.gob.mx/leyendasFiscales"
115+
xsi:schemaLocation = "http://www.sat.gob.mx/leyendasFiscales http://www.sat.gob.mx/sitio_internet/cfd/leyendasFiscales/leyendasFisc.xsd">
116+
<leyendasFisc:Leyenda disposicionFiscal="RESDERAUTH" norma = "Artíclo 2. Fracción IV." textoLeyenda = "El software desarrollado se entrega con licencia MIT" />
117+
</leyendasFisc:LeyendasFiscales>
118+
</cfdi:Complemento>
119+
</cfdi:Comprobante>
120+
```
121+
122+
Y si aplica este método las definiciones cambiarán de lugar, quedando como:
123+
124+
```xml
125+
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:leyendasFisc="http://www.sat.gob.mx/leyendasFiscales"
126+
xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd http://www.sat.gob.mx/leyendasFiscales http://www.sat.gob.mx/sitio_internet/cfd/leyendasFiscales/leyendasFisc.xsd">
127+
<!-- ... nodos del comprobante ... -->
128+
<cfdi:Complemento>
129+
<!-- ... otros complementos ... -->
130+
<leyendasFisc:LeyendasFiscales version="1.0">
131+
<leyendasFisc:Leyenda disposicionFiscal="RESDERAUTH" norma = "Artíclo 2. Fracción IV." textoLeyenda = "El software desarrollado se entrega con licencia MIT" />
132+
</leyendasFisc:LeyendasFiscales>
133+
</cfdi:Complemento>
134+
</cfdi:Comprobante>
135+
```
136+
137+
En realidad, esto no es una regla importarte e incluso se podría decir que sale de la práctica común de XML.
138+
Sin embargo, en la documentación técnica del SAT lo documenta como *mandatorio*. Es decir, se está obligado
139+
a seguir esta definición.
140+
141+
Si no creaste tus CFDI con esta estructura malamente requerida por el SAT, no te preocupes, en caso de ser
142+
necesario podrías hasta modificar tus CFDI anteriores (aun cuando tengan sello) porque la ubicación de las
143+
definiciones de los espacios de nombres no participan en la formación de la cadena de origen.
144+
95145

96-
## Formación de el texto de los códigos QR
146+
## Formación del texto de los códigos QR
97147

98148
La formación del texto que se incluye en los códigos QR tiene reglas específicas
99149
y puede utilizarse el objeto `\CfdiUtils\ConsultaCfdiSat\RequestParameters`

src/CfdiUtils/CfdiCreator33.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use CfdiUtils\Elements\Cfdi33\Comprobante;
1212
use CfdiUtils\Elements\Cfdi33\Helpers\SumasConceptosWriter;
1313
use CfdiUtils\Nodes\NodeInterface;
14+
use CfdiUtils\Nodes\NodeNsDefinitionsMover;
1415
use CfdiUtils\Nodes\XmlNodeUtils;
1516
use CfdiUtils\PemPrivateKey\PemPrivateKey;
1617
use CfdiUtils\SumasConceptos\SumasConceptos;
@@ -98,6 +99,17 @@ public function asXml(): string
9899
return XmlNodeUtils::nodeToXmlString($this->comprobante, true);
99100
}
100101

102+
public function moveSatDefinitionsToComprobante()
103+
{
104+
$nodeNsDefinitionsMover = new NodeNsDefinitionsMover();
105+
$nodeNsDefinitionsMover->setNamespaceFilter(
106+
function (string $namespaceUri): bool {
107+
return ('http://www.sat.gob.mx/' === (substr($namespaceUri, 0, 22) ?: ''));
108+
}
109+
);
110+
$nodeNsDefinitionsMover->process($this->comprobante);
111+
}
112+
101113
public function saveXml(string $filename): bool
102114
{
103115
return (false !== file_put_contents($filename, $this->asXml()));

0 commit comments

Comments
 (0)