InvoiceLine::setPrice()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
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.0
7
 * 
8
 * Copyright 2019, Jaime Cruz
9
 */
10
11
namespace F72X\UblComponent;
12
13
use F72X\Sunat\Operations;
14
use Sabre\Xml\Writer;
15
16
class InvoiceLine extends BaseComponent {
17
18
    const DECIMALS = 2;
19
20
    protected $currencyID;
21
    protected $ID;
22
    protected $unitCode = 'NIU';
23
    protected $InvoicedQuantity;
24
    protected $LineExtensionAmount;
25
26
    /** @var PricingReference */
27
    protected $PricingReference;
28
29
    /** @var AllowanceCharge[] */
30
    protected $AllowanceCharges = [];
31
32
    /** @var TaxTotal */
33
    protected $TaxTotal;
34
35
    /** @var Item */
36
    protected $Item;
37
38
    /** @var Price */
39
    protected $Price;
40
41
    protected $validations = [
42
        'currencyID',
43
        'ID',
44
        'InvoicedQuantity',
45
        'unitCode',
46
        'LineExtensionAmount',
47
        'PricingReference',
48
        'TaxTotal',
49
        'Item',
50
        'Price'
51
    ];
52
53
    function xmlSerialize(Writer $writer) {
54
        $this->validate();
55
        $writer->write([
56
            SchemaNS::CBC . 'ID' => $this->ID,
57
            [
58
                'name'          => SchemaNS::CBC . 'InvoicedQuantity',
59
                'value'         => $this->InvoicedQuantity,
60
                'attributes'    => [
61
                    'unitCode'                  => $this->unitCode,
62
                    'unitCodeListID'            => 'UN/ECE rec 20',
63
                    'unitCodeListAgencyName'    => 'United Nations Economic Commission for Europe'
64
                ]
65
            ],
66
            [
67
                'name'          => SchemaNS::CBC . 'LineExtensionAmount',
68
                'value'         => Operations::formatAmount($this->LineExtensionAmount, self::DECIMALS),
69
                'attributes'    => [
70
                    'currencyID' => $this->currencyID
71
                ]
72
            ],
73
            SchemaNS::CAC . 'PricingReference' => $this->PricingReference
74
        ]);
75
        // Cargos y descuentos
76
        foreach ($this->AllowanceCharges as $AllowanceCharge) {
77
            $writer->write([
78
                SchemaNS::CAC . 'AllowanceCharge' => $AllowanceCharge
79
            ]);
80
        }
81
        $writer->write([
82
            SchemaNS::CAC . 'TaxTotal'  => $this->TaxTotal,
83
            SchemaNS::CAC . 'Item'      => $this->Item,
84
            SchemaNS::CAC . 'Price'     => $this->Price
85
        ]);
86
87
    }
88
89
    public function getCurrencyID() {
90
        return $this->currencyID;
91
    }
92
93
    public function setCurrencyID($currencyID) {
94
        $this->currencyID = $currencyID;
95
        return $this;
96
    }
97
98
    public function getID() {
99
        return $this->ID;
100
    }
101
102
    public function setID($ID) {
103
        $this->ID = $ID;
104
        return $this;
105
    }
106
    public function getUnitCode() {
107
        return $this->unitCode;
108
    }
109
110
    public function setUnitCode($unitCode) {
111
        $this->unitCode = $unitCode;
112
        return $this;
113
    }
114
115
    public function getInvoicedQuantity() {
116
        return $this->InvoicedQuantity;
117
    }
118
119
    public function setInvoicedQuantity($InvoicedQuantity) {
120
        $this->InvoicedQuantity = $InvoicedQuantity;
121
        return $this;
122
    }
123
124
    public function getLineExtensionAmount() {
125
        return $this->LineExtensionAmount;
126
    }
127
128
    public function setLineExtensionAmount($LineExtensionAmount) {
129
        $this->LineExtensionAmount = $LineExtensionAmount;
130
        return $this;
131
    }
132
    public function getPricingReference() {
133
        return $this->PricingReference;
134
    }
135
136
    public function setPricingReference(PricingReference $PricingReference) {
137
        $this->PricingReference = $PricingReference;
138
        return $this;
139
    }
140
    public function getAllowanceCharges() {
141
        return $this->AllowanceCharges;
142
    }
143
144
    public function setAllowanceCharges(array $AllowanceCharges) {
145
        $this->AllowanceCharges = $AllowanceCharges;
146
        return $this;
147
    }
148
149
    /**
150
     * 
151
     * @param AllowanceCharge $AllowanceCharge
152
     * @return $this
153
     */
154
    public function addAllowanceCharge(AllowanceCharge $AllowanceCharge) {
155
        $this->AllowanceCharges[] = $AllowanceCharge;
156
        return $this;
157
    }
158
159
    public function getTaxTotal() {
160
        return $this->TaxTotal;
161
    }
162
163
    public function setTaxTotal(TaxTotal $TaxTotal) {
164
        $this->TaxTotal = $TaxTotal;
165
        return $this;
166
    }
167
168
    public function getItem() {
169
        return $this->Item;
170
    }
171
172
    public function setItem(Item $Item) {
173
        $this->Item = $Item;
174
        return $this;
175
    }
176
177
    public function getPrice() {
178
        return $this->Price;
179
    }
180
181
    public function setPrice(Price $Price) {
182
        $this->Price = $Price;
183
        return $this;
184
    }
185
186
}
187