1 | <?php |
||
2 | |||
3 | /** |
||
4 | * MÓDULO DE EMISIÓN ELECTRÓNICA F72X |
||
5 | * UBL 2.1 |
||
6 | * Version 1.0 |
||
7 | * |
||
8 | * Copyright 2019, Jaime Cruz |
||
9 | */ |
||
10 | |||
11 | namespace F72X\Sunat\Document; |
||
12 | |||
13 | use F72X\Company; |
||
14 | use F72X\Tools\TemplateMgr; |
||
15 | use F72X\UblComponent\SchemaNS; |
||
16 | use Sabre\Xml\Writer; |
||
17 | |||
18 | class Factura extends SunatInvoice { |
||
19 | |||
20 | protected $UBLVersionID = '2.1'; |
||
21 | protected $CustomizationID = '2.0'; |
||
22 | |||
23 | public function xmlSerialize(Writer $writer) { |
||
24 | $dataMap = $this->getDataMap(); |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
25 | $companyRUC = Company::getRUC(); |
||
26 | $companyName = Company::getCompanyName(); |
||
27 | // SchemaNS::EXT . 'UBLExtensions' |
||
28 | $UBLExtensions = TemplateMgr::getTpl('UBLExtensions.xml'); |
||
29 | $Signature = TemplateMgr::getTpl('Signature.xml', [ |
||
30 | 'ruc' => $companyRUC, |
||
31 | 'companyName' => $companyName |
||
32 | ]); |
||
33 | $this->writeLineJump($writer); |
||
34 | $writer->writeRaw($UBLExtensions); |
||
35 | |||
36 | $writer->write([ |
||
37 | SchemaNS::CBC . 'UBLVersionID' => $this->UBLVersionID, |
||
38 | SchemaNS::CBC . 'CustomizationID' => $this->CustomizationID, |
||
39 | [ |
||
40 | 'name' => SchemaNS::CBC . 'ProfileID', |
||
41 | 'value' => $this->ProfileID, |
||
42 | 'attributes' => [ |
||
43 | 'schemeName' => 'SUNAT:Identificador de Tipo de Operación', |
||
44 | 'schemeAgencyName' => 'PE:SUNAT', |
||
45 | 'schemeURI' => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo17' |
||
46 | ] |
||
47 | ], |
||
48 | SchemaNS::CBC . 'ID' => $this->ID, |
||
49 | SchemaNS::CBC . 'IssueDate' => $this->IssueDate->format('Y-m-d'), |
||
50 | SchemaNS::CBC . 'IssueTime' => $this->IssueDate->format('H:i:s') |
||
51 | ]); |
||
52 | if ($this->DueDate) { |
||
53 | $writer->write([ |
||
54 | SchemaNS::CBC . 'DueDate' => $this->DueDate->format('Y-m-d') |
||
55 | ]); |
||
56 | } |
||
57 | $writer->write([ |
||
58 | [ |
||
59 | 'name' => SchemaNS::CBC . 'InvoiceTypeCode', |
||
60 | 'value' => $this->InvoiceTypeCode, |
||
61 | 'attributes' => [ |
||
62 | 'listAgencyName' => 'PE:SUNAT', |
||
63 | 'listID' => $this->ProfileID, |
||
64 | 'listName' => 'Tipo de Documento', |
||
65 | 'listSchemeURI' => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo51', |
||
66 | 'listURI' => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01', |
||
67 | 'name' => 'Tipo de Operacion' |
||
68 | ] |
||
69 | ] |
||
70 | ]); |
||
71 | |||
72 | // Write notes |
||
73 | foreach ($this->Notes as $InvoiceLine) { |
||
74 | $writer->write($InvoiceLine); |
||
75 | } |
||
76 | |||
77 | $writer->write([ |
||
78 | [ |
||
79 | 'name' => SchemaNS::CBC . 'DocumentCurrencyCode', |
||
80 | 'value' => $this->DocumentCurrencyCode, |
||
81 | 'attributes' => [ |
||
82 | 'listID' => 'ISO 4217 Alpha', |
||
83 | 'listName' => 'Currency', |
||
84 | 'listAgencyName' => 'United Nations Economic Commission for Europe' |
||
85 | ] |
||
86 | ], |
||
87 | SchemaNS::CBC . 'LineCountNumeric' => $this->LineCountNumeric |
||
88 | ]); |
||
89 | |||
90 | // Order Reference |
||
91 | if ($this->OrderReference) { |
||
92 | $writer->write([ |
||
93 | SchemaNS::CAC . 'OrderReference' => $this->OrderReference |
||
94 | ]); |
||
95 | } |
||
96 | |||
97 | // Despatch Document Reference |
||
98 | if ($this->DespatchDocumentReference) { |
||
99 | $writer->write([ |
||
100 | SchemaNS::CAC . 'DespatchDocumentReference' => $this->DespatchDocumentReference |
||
101 | ]); |
||
102 | } |
||
103 | // cac:Signature |
||
104 | $writer->writeRaw($Signature); |
||
105 | // cac:AccountingSupplierParty/AccountingCustomerParty |
||
106 | $writer->write([ |
||
107 | SchemaNS::CAC . 'AccountingSupplierParty' => $this->AccountingSupplierParty, |
||
108 | SchemaNS::CAC . 'AccountingCustomerParty' => $this->AccountingCustomerParty |
||
109 | ]); |
||
110 | // Cargos y descuentos |
||
111 | foreach ($this->AllowanceCharges as $AllowanceCharge) { |
||
112 | $writer->write([ |
||
113 | SchemaNS::CAC . 'AllowanceCharge' => $AllowanceCharge |
||
114 | ]); |
||
115 | } |
||
116 | // Información de forma de pago |
||
117 | foreach ($this->PaymentTerms as $item) { |
||
118 | $writer->write([ |
||
119 | SchemaNS::CAC . 'PaymentTerms' => $item |
||
120 | ]); |
||
121 | } |
||
122 | |||
123 | $writer->write([ |
||
124 | SchemaNS::CAC . 'TaxTotal' => $this->TaxTotal |
||
125 | ]); |
||
126 | $writer->write([ |
||
127 | SchemaNS::CAC . 'LegalMonetaryTotal' => $this->LegalMonetaryTotal |
||
128 | ]); |
||
129 | |||
130 | // Detalle |
||
131 | foreach ($this->InvoiceLines as $InvoiceLine) { |
||
132 | $writer->write([ |
||
133 | SchemaNS::CAC . 'InvoiceLine' => $InvoiceLine |
||
134 | ]); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | } |
||
139 |