Test Failed
Push — master ( 1f5d45...b072a0 )
by JAIME ELMER
04:15
created

NotaCredito::xmlSerialize()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 42
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 29
nc 4
nop 1
dl 0
loc 42
rs 9.456
c 0
b 0
f 0
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\CreditNote;
18
use Sabre\Xml\Writer;
19
20
class NotaCredito extends CreditNote {
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('CreditNoteLine');
46
        // Impuestos
47
        $this->addDocumentTaxes();
48
        // Totales
49
        $this->addInvoiceLegalMonetaryTotal();
50
    }
51
    public function xmlSerialize(Writer $writer) {
52
        $companyRUC = Company::getRUC();
53
        $companyName = Company::getCompanyName();
54
        // SchemaNS::EXT . 'UBLExtensions'
55
        $UBLExtensions = TemplateMgr::getTpl('UBLExtensions.xml');
56
        $Signature     = TemplateMgr::getTpl('Signature.xml', [
57
                    'ruc'         => $companyRUC,
58
                    'companyName' => $companyName
59
        ]);
60
        $this->writeLineJump($writer);
61
        $writer->writeRaw($UBLExtensions);
62
63
        $writer->write([
64
            SchemaNS::CBC . 'UBLVersionID'         => $this->UBLVersionID,
65
            SchemaNS::CBC . 'CustomizationID'      => $this->CustomizationID,
66
            SchemaNS::CBC . 'ID'                   => $this->ID,
67
            SchemaNS::CBC . 'IssueDate'            => $this->IssueDate->format('Y-m-d'),
68
            SchemaNS::CBC . 'IssueTime'            => $this->IssueDate->format('H:i:s'),
69
            SchemaNS::CBC . 'DocumentCurrencyCode' => $this->DocumentCurrencyCode,
70
            SchemaNS::CAC . 'DiscrepancyResponse'  => $this->DiscrepancyResponse,
71
            SchemaNS::CAC . 'BillingReference'     => $this->BillingReference
72
        ]);
73
74
        // Despatch Document Reference
75
        if ($this->DespatchDocumentReference) {
76
            $writer->write([
77
                SchemaNS::CAC . 'DespatchDocumentReference' => $this->DespatchDocumentReference
78
            ]);
79
        }
80
        // cac:Signature
81
        $writer->writeRaw($Signature);
82
        $writer->write([
83
            SchemaNS::CAC . 'AccountingSupplierParty' => $this->AccountingSupplierParty,
84
            SchemaNS::CAC . 'AccountingCustomerParty' => $this->AccountingCustomerParty,
85
            SchemaNS::CAC . 'TaxTotal'                => $this->TaxTotal,
86
            SchemaNS::CAC . 'LegalMonetaryTotal'      => $this->LegalMonetaryTotal
87
        ]);
88
89
        // Detalle
90
        foreach ($this->CreditNoteLines as $Line) {
91
            $writer->write([
92
                SchemaNS::CAC . 'CreditNoteLine' => $Line
93
            ]);
94
        }
95
    }
96
97
}
98