1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MÓDULO DE EMISIÓN ELECTRÓNICA F72X |
5
|
|
|
* UBL 2.1 |
6
|
|
|
* Version 1.1 |
7
|
|
|
* |
8
|
|
|
* Copyright 2018, Jaime Cruz |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace F72X\Sunat\Document; |
12
|
|
|
|
13
|
|
|
use F72X\Company; |
14
|
|
|
use F72X\Tools\TemplateMgr; |
15
|
|
|
use F72X\Sunat\DataMap; |
16
|
|
|
use F72X\UblComponent\SchemaNS; |
17
|
|
|
use F72X\UblComponent\DebitNote; |
18
|
|
|
use Sabre\Xml\Writer; |
19
|
|
|
|
20
|
|
|
class NotaDebito extends DebitNote { |
21
|
|
|
|
22
|
|
|
use BillMixin, NoteMixin; |
23
|
|
|
|
24
|
|
|
protected $UBLVersionID = '2.1'; |
25
|
|
|
protected $CustomizationID = '2.0'; |
26
|
|
|
|
27
|
|
|
public function __construct(DataMap $DataMap) { |
28
|
|
|
$this->dataMap = $DataMap; |
29
|
|
|
$currencyCode = $DataMap->getCurrencyCode(); |
30
|
|
|
// ID |
31
|
|
|
$this->setID($DataMap->getDocumentId()); |
32
|
|
|
// Fecha de emisión |
33
|
|
|
$this->setIssueDate($DataMap->getIssueDate()); |
34
|
|
|
// Tipo de moneda |
35
|
|
|
$this->setDocumentCurrencyCode($currencyCode); |
36
|
|
|
// Motivo de emisión |
37
|
|
|
$this->addDiscrepancyResponse(); |
38
|
|
|
// Motivo de emisión |
39
|
|
|
$this->addBillingReference(); |
40
|
|
|
// Información de la empresa |
41
|
|
|
$this->addInvoiceAccountingSupplierParty(); |
42
|
|
|
// Información del cliente |
43
|
|
|
$this->addInvoiceAccountingCustomerParty(); |
44
|
|
|
// Detalle |
45
|
|
|
$this->addDocumentItems('DebitNoteLine'); |
46
|
|
|
// Impuestos |
47
|
|
|
$this->addDocumentTaxes(); |
48
|
|
|
// Totales |
49
|
|
|
$this->addRequestedMonetaryTotal(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function xmlSerialize(Writer $writer) { |
53
|
|
|
$companyRUC = Company::getRUC(); |
54
|
|
|
$companyName = Company::getCompanyName(); |
55
|
|
|
// SchemaNS::EXT . 'UBLExtensions' |
56
|
|
|
$UBLExtensions = TemplateMgr::getTpl('UBLExtensions.xml'); |
57
|
|
|
$Signature = TemplateMgr::getTpl('Signature.xml', [ |
58
|
|
|
'ruc' => $companyRUC, |
59
|
|
|
'companyName' => $companyName |
60
|
|
|
]); |
61
|
|
|
$this->writeLineJump($writer); |
62
|
|
|
$writer->writeRaw($UBLExtensions); |
63
|
|
|
|
64
|
|
|
$writer->write([ |
65
|
|
|
SchemaNS::CBC . 'UBLVersionID' => $this->UBLVersionID, |
66
|
|
|
SchemaNS::CBC . 'CustomizationID' => $this->CustomizationID, |
67
|
|
|
SchemaNS::CBC . 'ID' => $this->ID, |
68
|
|
|
SchemaNS::CBC . 'IssueDate' => $this->IssueDate->format('Y-m-d'), |
69
|
|
|
SchemaNS::CBC . 'IssueTime' => $this->IssueDate->format('H:i:s'), |
70
|
|
|
SchemaNS::CBC . 'DocumentCurrencyCode' => $this->DocumentCurrencyCode, |
71
|
|
|
SchemaNS::CAC . 'DiscrepancyResponse' => $this->DiscrepancyResponse, |
72
|
|
|
SchemaNS::CAC . 'BillingReference' => $this->BillingReference |
73
|
|
|
]); |
74
|
|
|
|
75
|
|
|
// Despatch Document Reference |
76
|
|
|
if ($this->DespatchDocumentReference) { |
77
|
|
|
$writer->write([ |
78
|
|
|
SchemaNS::CAC . 'DespatchDocumentReference' => $this->DespatchDocumentReference |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
// cac:Signature |
82
|
|
|
$writer->writeRaw($Signature); |
83
|
|
|
$writer->write([ |
84
|
|
|
SchemaNS::CAC . 'AccountingSupplierParty' => $this->AccountingSupplierParty, |
85
|
|
|
SchemaNS::CAC . 'AccountingCustomerParty' => $this->AccountingCustomerParty, |
86
|
|
|
SchemaNS::CAC . 'TaxTotal' => $this->TaxTotal, |
87
|
|
|
SchemaNS::CAC . 'RequestedMonetaryTotal' => $this->RequestedMonetaryTotal |
88
|
|
|
]); |
89
|
|
|
|
90
|
|
|
// Detalle |
91
|
|
|
foreach ($this->DebitNoteLines as $Line) { |
92
|
|
|
$writer->write([ |
93
|
|
|
SchemaNS::CAC . 'DebitNoteLine' => $Line |
94
|
|
|
]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|