Skip to content

Commit b5c9b05

Browse files
committed
added Voided/Reversion Parser , close #3
1 parent a7123fa commit b5c9b05

17 files changed

Lines changed: 875 additions & 15 deletions

src/Greenter/Parser/NoteParser.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public function parse($value)
5454
$this->rootNode = $root;
5555
$isNcr = $root->nodeName == 'CreditNote';
5656

57-
$inv = new Note();
58-
$docFac = explode('-', $xml->getValue('cbc:ID', $root));
59-
$this->loadDocAfectado($inv);
60-
$inv->setSerie($docFac[0])
61-
->setCorrelativo($docFac[1])
57+
$note = new Note();
58+
$idNum = explode('-', $xml->getValue('cbc:ID', $root));
59+
$this->loadDocAfectado($note);
60+
$note->setSerie($idNum[0])
61+
->setCorrelativo($idNum[1])
6262
->setTipoDoc($isNcr ? '07' : '08')
6363
->setTipoMoneda($xml->getValue('cbc:DocumentCurrencyCode', $root))
6464
->setFechaEmision(new \DateTime($xml->getValue('cbc:IssueDate', $root)))
@@ -67,15 +67,15 @@ public function parse($value)
6767

6868
$extensions = $xml->getNode('ext:UBLExtensions', $root);
6969
$additional = $xml->getNode('//sac:AdditionalInformation', $extensions);
70-
$this->loadTotals($inv, $additional);
71-
$this->loadTributos($inv);
70+
$this->loadTotals($note, $additional);
71+
$this->loadTributos($note);
7272
$monetaryTotal = $xml->getNode($isNcr ? 'cac:LegalMonetaryTotal': 'cac:RequestedMonetaryTotal', $root);
73-
$inv->setMtoOtrosTributos(floatval($xml->getValue('cbc:ChargeTotalAmount', $monetaryTotal, 0)))
73+
$note->setMtoOtrosTributos(floatval($xml->getValue('cbc:ChargeTotalAmount', $monetaryTotal, 0)))
7474
->setMtoImpVenta($xml->getValue('cbc:PayableAmount', $monetaryTotal, 0))
7575
->setDetails(iterator_to_array($this->getDetails($isNcr)))
7676
->setLegends(iterator_to_array($this->getLegends($additional)));
7777

78-
return $inv;
78+
return $note;
7979
}
8080

8181
private function loadTotals(Note $inv, \DOMNode $node)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Giansalex
5+
* Date: 08/11/2017
6+
* Time: 21:29
7+
*/
8+
9+
namespace Greenter\Xml\Parser;
10+
11+
use Greenter\Model\Company\Company;
12+
use Greenter\Model\DocumentInterface;
13+
use Greenter\Model\Voided\Voided;
14+
use Greenter\Model\Voided\VoidedDetail;
15+
use Greenter\Parser\DocumentParserInterface;
16+
use Greenter\Xml\XmlReader;
17+
18+
/**
19+
* Class VoidedParser
20+
* @package Greenter\Xml\Parser
21+
*/
22+
class VoidedParser implements DocumentParserInterface
23+
{
24+
/**
25+
* @var XmlReader
26+
*/
27+
private $reader;
28+
29+
/**
30+
* @var \DOMElement
31+
*/
32+
private $rootNode;
33+
34+
/**
35+
* @param $value
36+
* @return DocumentInterface
37+
*/
38+
public function parse($value)
39+
{
40+
$this->load($value);
41+
$xml = $this->reader;
42+
43+
$voided = new Voided();
44+
$root = $this->rootNode;
45+
$id = explode('-', $xml->getValue('cbc:ID', $root));
46+
47+
$voided->setCorrelativo($id[2])
48+
->setFecGeneracion(new \DateTime($xml->getValue('cbc:ReferenceDate', $root)))
49+
->setFecComunicacion(new \DateTime($xml->getValue('cbc:IssueDate', $root)))
50+
->setCompany($this->getCompany())
51+
->setDetails(iterator_to_array($this->getDetails()));
52+
53+
return $voided;
54+
}
55+
56+
private function load($value)
57+
{
58+
$this->reader = new XmlReader();
59+
60+
if ($value instanceof \DOMDocument) {
61+
$this->reader->loadDom($value);
62+
} else {
63+
$this->reader->loadXml($value);
64+
}
65+
66+
$this->rootNode = $this->reader->getXpath()->document->documentElement;
67+
}
68+
69+
private function getCompany()
70+
{
71+
$xml = $this->reader;
72+
$node = $xml->getNode('cac:AccountingSupplierParty',$this->rootNode);
73+
74+
$cl = new Company();
75+
$cl->setRuc($xml->getValue('cbc:CustomerAssignedAccountID', $node))
76+
->setNombreComercial($xml->getValue('cac:Party/cac:PartyName/cbc:Name', $node))
77+
->setRazonSocial($xml->getValue('cac:Party/cac:PartyLegalEntity/cbc:RegistrationName', $node));
78+
79+
return $cl;
80+
}
81+
82+
private function getDetails()
83+
{
84+
$xml = $this->reader;
85+
$nodes = $xml->getNodes('sac:VoidedDocumentsLine', $this->rootNode);
86+
87+
foreach ($nodes as $node) {
88+
$det = new VoidedDetail();
89+
$det->setTipoDoc($xml->getValue('cbc:DocumentTypeCode', $node))
90+
->setSerie($xml->getValue('sac:DocumentSerialID', $node))
91+
->setCorrelativo($xml->getValue('sac:DocumentNumberID', $node))
92+
->setDesMotivoBaja($xml->getValue('sac:VoidReasonDescription', $node));
93+
94+
yield $det;
95+
}
96+
}
97+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by izegarrav (EMBRACE) -->
3+
<VoidedDocuments xmlns="urn:sunat:names:specification:ubl:peru:schema:xsd:VoidedDocuments-1" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<ext:UBLExtensions>
5+
6+
</ext:UBLExtensions>
7+
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
8+
<cbc:CustomizationID>1.0</cbc:CustomizationID>
9+
<cbc:ID>RA-20170731-0008</cbc:ID>
10+
<cbc:ReferenceDate>2017-07-31</cbc:ReferenceDate>
11+
<cbc:IssueDate>2017-07-31</cbc:IssueDate>
12+
<cbc:Note>CONSOLIDAD DE DOCUMENTOS NUMERADOS NO EMITIDOS</cbc:Note>
13+
<cac:Signature>
14+
<cbc:ID>IDSignKG</cbc:ID>
15+
<cac:SignatoryParty>
16+
<cac:PartyIdentification>
17+
<cbc:ID>20338570041</cbc:ID>
18+
</cac:PartyIdentification>
19+
<cac:PartyName>
20+
<cbc:Name>PRAXAIR PERU SRL</cbc:Name>
21+
</cac:PartyName>
22+
</cac:SignatoryParty>
23+
<cac:DigitalSignatureAttachment>
24+
<cac:ExternalReference>
25+
<cbc:URI>#signature</cbc:URI>
26+
</cac:ExternalReference>
27+
</cac:DigitalSignatureAttachment>
28+
</cac:Signature>
29+
<cac:AccountingSupplierParty>
30+
<cbc:CustomerAssignedAccountID>20338570041</cbc:CustomerAssignedAccountID>
31+
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
32+
<cac:Party>
33+
<cac:PartyLegalEntity>
34+
<cbc:RegistrationName>PRAXAIR PERU</cbc:RegistrationName>
35+
</cac:PartyLegalEntity>
36+
</cac:Party>
37+
</cac:AccountingSupplierParty>
38+
<sac:VoidedDocumentsLine>
39+
<cbc:LineID>1</cbc:LineID>
40+
<cbc:DocumentTypeCode>03</cbc:DocumentTypeCode>
41+
<sac:DocumentSerialID>BG99</sac:DocumentSerialID>
42+
<sac:DocumentNumberID>14</sac:DocumentNumberID>
43+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
44+
</sac:VoidedDocumentsLine>
45+
</VoidedDocuments>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by izegarrav (EMBRACE) -->
3+
<VoidedDocuments xmlns="urn:sunat:names:specification:ubl:peru:schema:xsd:VoidedDocuments-1" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<ext:UBLExtensions>
5+
6+
</ext:UBLExtensions>
7+
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
8+
<cbc:CustomizationID>1.0</cbc:CustomizationID>
9+
<cbc:ID>RA-20170628-0018</cbc:ID>
10+
<cbc:ReferenceDate>2017-06-28</cbc:ReferenceDate>
11+
<cbc:IssueDate>2017-06-28</cbc:IssueDate>
12+
<cbc:Note>CONSOLIDAD DE DOCUMENTOS NUMERADOS NO EMITIDOS</cbc:Note>
13+
<cac:Signature>
14+
<cbc:ID>IDSignKG</cbc:ID>
15+
<cac:SignatoryParty>
16+
<cac:PartyIdentification>
17+
<cbc:ID>20338570041</cbc:ID>
18+
</cac:PartyIdentification>
19+
<cac:PartyName>
20+
<cbc:Name>PRAXAIR PERU SRL</cbc:Name>
21+
</cac:PartyName>
22+
</cac:SignatoryParty>
23+
<cac:DigitalSignatureAttachment>
24+
<cac:ExternalReference>
25+
<cbc:URI>#signature</cbc:URI>
26+
</cac:ExternalReference>
27+
</cac:DigitalSignatureAttachment>
28+
</cac:Signature>
29+
<cac:AccountingSupplierParty>
30+
<cbc:CustomerAssignedAccountID>20338570041</cbc:CustomerAssignedAccountID>
31+
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
32+
<cac:Party>
33+
<cac:PartyLegalEntity>
34+
<cbc:RegistrationName>PRAXAIR PERU SRL</cbc:RegistrationName>
35+
</cac:PartyLegalEntity>
36+
</cac:Party>
37+
</cac:AccountingSupplierParty>
38+
<sac:VoidedDocumentsLine>
39+
<cbc:LineID>1</cbc:LineID>
40+
<cbc:DocumentTypeCode>03</cbc:DocumentTypeCode>
41+
<sac:DocumentSerialID>BG99</sac:DocumentSerialID>
42+
<sac:DocumentNumberID>6</sac:DocumentNumberID>
43+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
44+
</sac:VoidedDocumentsLine>
45+
<sac:VoidedDocumentsLine>
46+
<cbc:LineID>2</cbc:LineID>
47+
<cbc:DocumentTypeCode>01</cbc:DocumentTypeCode>
48+
<sac:DocumentSerialID>FG99</sac:DocumentSerialID>
49+
<sac:DocumentNumberID>302</sac:DocumentNumberID>
50+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
51+
</sac:VoidedDocumentsLine>
52+
<sac:VoidedDocumentsLine>
53+
<cbc:LineID>3</cbc:LineID>
54+
<cbc:DocumentTypeCode>07</cbc:DocumentTypeCode>
55+
<sac:DocumentSerialID>FG99</sac:DocumentSerialID>
56+
<sac:DocumentNumberID>152</sac:DocumentNumberID>
57+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
58+
</sac:VoidedDocumentsLine><sac:VoidedDocumentsLine>
59+
<cbc:LineID>4</cbc:LineID>
60+
<cbc:DocumentTypeCode>08</cbc:DocumentTypeCode>
61+
<sac:DocumentSerialID>FG99</sac:DocumentSerialID>
62+
<sac:DocumentNumberID>402</sac:DocumentNumberID>
63+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
64+
</sac:VoidedDocumentsLine>
65+
</VoidedDocuments>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by izegarrav (EMBRACE) -->
3+
<VoidedDocuments xmlns="urn:sunat:names:specification:ubl:peru:schema:xsd:VoidedDocuments-1" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<ext:UBLExtensions>
5+
6+
</ext:UBLExtensions>
7+
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
8+
<cbc:CustomizationID>1.0</cbc:CustomizationID>
9+
<cbc:ID>RA-20170628-0046</cbc:ID>
10+
<!--Fecha del documento a dar de baja-->
11+
<cbc:ReferenceDate>2017-06-28</cbc:ReferenceDate>
12+
<!--Fecha de generacion de la comunicacion-->
13+
<cbc:IssueDate>2017-06-28</cbc:IssueDate>
14+
<cbc:Note>CONSOLIDAD DE DOCUMENTOS NUMERADOS NO EMITIDOS</cbc:Note>
15+
<cac:Signature>
16+
<cbc:ID>IDSignKG</cbc:ID>
17+
<cac:SignatoryParty>
18+
<cac:PartyIdentification>
19+
<cbc:ID>20338570041</cbc:ID>
20+
</cac:PartyIdentification>
21+
<cac:PartyName>
22+
<cbc:Name>PRAXAIR PERU SRL PRAXAIR PERU SRL PRAXAIR PERU SRL PRAXAIR PERU SRL PRAXAIR PERU SRL PRAXAIR PERUSRL</cbc:Name>
23+
</cac:PartyName>
24+
</cac:SignatoryParty>
25+
<cac:DigitalSignatureAttachment>
26+
<cac:ExternalReference>
27+
<cbc:URI>#signature</cbc:URI>
28+
</cac:ExternalReference>
29+
</cac:DigitalSignatureAttachment>
30+
</cac:Signature>
31+
<cac:AccountingSupplierParty>
32+
<cbc:CustomerAssignedAccountID>20338570041</cbc:CustomerAssignedAccountID>
33+
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
34+
<cac:Party>
35+
<cac:PartyLegalEntity>
36+
<cbc:RegistrationName>PRAXAIR PERU SRL</cbc:RegistrationName>
37+
</cac:PartyLegalEntity>
38+
</cac:Party>
39+
</cac:AccountingSupplierParty>
40+
<sac:VoidedDocumentsLine>
41+
<cbc:LineID>1</cbc:LineID>
42+
<cbc:DocumentTypeCode>03</cbc:DocumentTypeCode>
43+
<sac:DocumentSerialID>BG99</sac:DocumentSerialID>
44+
<sac:DocumentNumberID>4</sac:DocumentNumberID>
45+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
46+
</sac:VoidedDocumentsLine>
47+
<sac:VoidedDocumentsLine>
48+
<cbc:LineID>2</cbc:LineID>
49+
<cbc:DocumentTypeCode>01</cbc:DocumentTypeCode>
50+
<sac:DocumentSerialID>FG99</sac:DocumentSerialID>
51+
<sac:DocumentNumberID>304</sac:DocumentNumberID>
52+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
53+
</sac:VoidedDocumentsLine>
54+
</VoidedDocuments>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- edited with XMLSpy v2009 sp1 (http://www.altova.com) by izegarrav (EMBRACE) -->
3+
<VoidedDocuments xmlns="urn:sunat:names:specification:ubl:peru:schema:xsd:VoidedDocuments-1" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<ext:UBLExtensions>
5+
6+
</ext:UBLExtensions>
7+
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
8+
<cbc:CustomizationID>1.0</cbc:CustomizationID>
9+
<cbc:ID>RA-20170628-0047</cbc:ID>
10+
<!--Fecha del documento a dar de baja-->
11+
<cbc:ReferenceDate>2017-06-28</cbc:ReferenceDate>
12+
<!--Fecha de generacion de la comunicacion-->
13+
<cbc:IssueDate>2017-06-28</cbc:IssueDate>
14+
<cbc:Note>CONSOLIDAD DE DOCUMENTOS NUMERADOS NO EMITIDOS</cbc:Note>
15+
<cac:Signature>
16+
<cbc:ID>IDSignKG</cbc:ID>
17+
<cac:SignatoryParty>
18+
<cac:PartyIdentification>
19+
<cbc:ID>20338570041</cbc:ID>
20+
</cac:PartyIdentification>
21+
<cac:PartyName>
22+
<cbc:Name>PRAXAIR PERU SRL</cbc:Name>
23+
</cac:PartyName>
24+
</cac:SignatoryParty>
25+
<cac:DigitalSignatureAttachment>
26+
<cac:ExternalReference>
27+
<cbc:URI>#signature</cbc:URI>
28+
</cac:ExternalReference>
29+
</cac:DigitalSignatureAttachment>
30+
</cac:Signature>
31+
<cac:AccountingSupplierParty>
32+
<cbc:CustomerAssignedAccountID>20338570041</cbc:CustomerAssignedAccountID>
33+
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
34+
<cac:Party>
35+
<cac:PartyLegalEntity>
36+
<cbc:RegistrationName>PRAXAIR PERU SRL</cbc:RegistrationName>
37+
</cac:PartyLegalEntity>
38+
</cac:Party>
39+
</cac:AccountingSupplierParty>
40+
<sac:VoidedDocumentsLine>
41+
<cbc:LineID>1</cbc:LineID>
42+
<cbc:DocumentTypeCode>03</cbc:DocumentTypeCode>
43+
<sac:DocumentSerialID>BG99</sac:DocumentSerialID>
44+
<sac:DocumentNumberID>7</sac:DocumentNumberID>
45+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
46+
</sac:VoidedDocumentsLine>
47+
<sac:VoidedDocumentsLine>
48+
<cbc:LineID>2</cbc:LineID>
49+
<cbc:DocumentTypeCode>01</cbc:DocumentTypeCode>
50+
<sac:DocumentSerialID>FG99</sac:DocumentSerialID>
51+
<sac:DocumentNumberID>307</sac:DocumentNumberID>
52+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
53+
</sac:VoidedDocumentsLine><sac:VoidedDocumentsLine>
54+
<cbc:LineID>3</cbc:LineID>
55+
<cbc:DocumentTypeCode>07</cbc:DocumentTypeCode>
56+
<sac:DocumentSerialID>FG99</sac:DocumentSerialID>
57+
<sac:DocumentNumberID>155</sac:DocumentNumberID>
58+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
59+
</sac:VoidedDocumentsLine><sac:VoidedDocumentsLine>
60+
<cbc:LineID>4</cbc:LineID>
61+
<cbc:DocumentTypeCode>08</cbc:DocumentTypeCode>
62+
<sac:DocumentSerialID>FG99</sac:DocumentSerialID>
63+
<sac:DocumentNumberID>405</sac:DocumentNumberID>
64+
<sac:VoidReasonDescription>ERROR SISTEMA</sac:VoidReasonDescription>
65+
</sac:VoidedDocumentsLine>
66+
</VoidedDocuments>

0 commit comments

Comments
 (0)