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\UblComponent\Invoice; |
15
|
|
|
use F72X\Sunat\DataMap; |
16
|
|
|
use F72X\Sunat\SunatVars; |
17
|
|
|
use F72X\Sunat\Operations; |
18
|
|
|
use F72X\Sunat\Catalogo; |
19
|
|
|
use F72X\Tools\UblHelper; |
20
|
|
|
use F72X\Tools\LogoMgr; |
21
|
|
|
use F72X\Tools\QrGenerator; |
22
|
|
|
|
23
|
|
|
abstract class SunatInvoice extends Invoice { |
24
|
|
|
|
25
|
|
|
use BillMixin; |
26
|
|
|
const UBL_VERSION_ID = '2.1'; |
27
|
|
|
const CUSTUMIZATION_ID = '2.0'; |
28
|
|
|
|
29
|
|
|
public function __construct(DataMap $DataMap) { |
30
|
|
|
$this->dataMap = $DataMap; |
31
|
|
|
$currencyCode = $DataMap->getCurrencyCode(); |
32
|
|
|
// Invoice Type |
33
|
|
|
$this->setInvoiceTypeCode($DataMap->getDocumentType()); |
34
|
|
|
// ID |
35
|
|
|
$this->setID($DataMap->getDocumentId()); |
36
|
|
|
// Tipo de operación |
37
|
|
|
$this->setProfileID($DataMap->getOperationType()); |
38
|
|
|
// Fecha de emisión |
39
|
|
|
$this->setIssueDate($DataMap->getIssueDate()); |
40
|
|
|
// Tipo de moneda |
41
|
|
|
$this->setDocumentCurrencyCode($currencyCode); |
42
|
|
|
// Orden de compra |
43
|
|
|
$this->addInvoiceOrderReference(); |
44
|
|
|
// Información de la empresa |
45
|
|
|
$this->addInvoiceAccountingSupplierParty(); |
46
|
|
|
// Información del cliente |
47
|
|
|
$this->addInvoiceAccountingCustomerParty(); |
48
|
|
|
// Total items |
49
|
|
|
$this->setLineCountNumeric($DataMap->getTotalItems()); |
50
|
|
|
// Detalle |
51
|
|
|
$this->addDocumentItems('InvoiceLine'); |
52
|
|
|
// Impuestos |
53
|
|
|
$this->addDocumentTaxes(); |
54
|
|
|
// Descuentos globales |
55
|
|
|
$ac = $DataMap->getAllowancesAndCharges(); |
56
|
|
|
$baseAmount = $DataMap->getBillableAmount(); |
57
|
|
|
UblHelper::addAllowancesCharges($this, $ac, $baseAmount, $currencyCode); |
58
|
|
|
// Totales |
59
|
|
|
$this->addInvoiceLegalMonetaryTotal(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getReadyToPrintData() { |
63
|
|
|
$dataMap = $this->getDataMap(); |
64
|
|
|
$currency = Catalogo::getCurrencyPlural($dataMap->getCurrencyCode()); |
65
|
|
|
$payableAmount = $dataMap->getPayableAmount(); |
66
|
|
|
$payableInWords = Operations::getAmountInWords($payableAmount, $currency); |
67
|
|
|
return [ |
68
|
|
|
'companyRuc' => Company::getRUC(), |
69
|
|
|
'companyAddress' => Company::getAddress(), |
70
|
|
|
'companyCity' => Company::getCity(), |
71
|
|
|
'edocHeaderContent' => Company::getEdocHeaderContent(), |
72
|
|
|
'edocFooterContent' => Company::getEdocFooterContent(), |
73
|
|
|
'documentSeries' => $dataMap->getDocumentSeries(), |
74
|
|
|
'documentNumber' => $dataMap->getDocumentNumber(), |
75
|
|
|
'officialDocumentName' => $dataMap->getOfficialDocumentName(), |
76
|
|
|
'currency' => $currency, |
77
|
|
|
'customerRegName' => $dataMap->getCustomerRegName(), |
78
|
|
|
'customerDocNumber' => $dataMap->getCustomerDocNumber(), |
79
|
|
|
'customerAddress' => $dataMap->getCustomerAddress(), |
80
|
|
|
'issueDate' => $dataMap->getIssueDate()->format('d-m-Y'), |
81
|
|
|
'igvPercent' => SunatVars::IGV_PERCENT, |
82
|
|
|
'logo' => LogoMgr::getLogoString(), |
83
|
|
|
'qr' => QrGenerator::getQrString($dataMap), // QR Code |
84
|
|
|
'taxableOperations' => Operations::formatAmount($dataMap->getTotalTaxableOperations()), // Total operaciones gravadas |
85
|
|
|
'freeOperations' => Operations::formatAmount($dataMap->getTotalFreeOperations()), // Total operaciones gratuitas |
86
|
|
|
'unaffectedOperations' => Operations::formatAmount($dataMap->getTotalUnaffectedOperations()), // Total operaciones inafectas |
87
|
|
|
'exemptedOperations' => Operations::formatAmount($dataMap->getTotalExemptedOperations()), // Total operaciones exoneradas |
88
|
|
|
'totalAllowances' => Operations::formatAmount($dataMap->getTotalAllowances()), // Total operaciones exoneradas |
89
|
|
|
'igvAmount' => Operations::formatAmount($dataMap->getIGV()), // Total a pagar |
90
|
|
|
'payableAmount' => Operations::formatAmount($payableAmount), // Total a pagar |
91
|
|
|
'payableInWords' => $payableInWords, // Monto en palabras |
92
|
|
|
'items' => self::getReadyToPrintDataItems($dataMap) // Items |
93
|
|
|
]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
private static function getReadyToPrintDataItems(DataMap $inv) { |
97
|
|
|
$Items = $inv->getItems(); |
98
|
|
|
$ln = $Items->getCount(); |
99
|
|
|
$items2 = []; |
100
|
|
|
for ($i = 0; $i < $ln; $i++) { |
101
|
|
|
$items2[]= [ |
102
|
|
|
'productCode' => $Items->getProductCode($i), |
103
|
|
|
'quantity' => $Items->getQunatity($i), |
104
|
|
|
'unitName' => Catalogo::getUnitName($Items->getUnitCode($i)), |
105
|
|
|
'unitBillableValue' => Operations::formatAmount($Items->getUnitBillableValue($i)), |
106
|
|
|
'itemPayableAmount' => Operations::formatAmount($Items->getPayableAmount($i)), |
107
|
|
|
'description' => $Items->getDescription($i) |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
return $items2; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|