Passed
Branch develop (477450)
by JAIME ELMER
06:26
created

SunatInvoice::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 1
dl 0
loc 32
rs 9.6666
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\UblComponent\Invoice;
14
use F72X\Sunat\DataMap;
15
use F72X\Tools\UblHelper;
16
17
abstract class SunatInvoice extends Invoice {
18
19
    use BillMixin;
20
    const UBL_VERSION_ID = '2.1';
21
    const CUSTUMIZATION_ID = '2.0';
22
23
    public function __construct(DataMap $Invoice) {
24
        $this->dataMap = $Invoice;
25
        $currencyCode = $Invoice->getCurrencyCode();
26
        $Items = $Invoice->getItems();
27
        // Invoice Type
28
        $this->setInvoiceTypeCode($Invoice->getDocumentType());
29
        // ID
30
        $this->setID($Invoice->getInvoiceId());
31
        // Tipo de operación
32
        $this->setProfileID($Invoice->getOperationType());
33
        // Fecha de emisión
34
        $this->setIssueDate($Invoice->getIssueDate());
35
        // Tipo de moneda
36
        $this->setDocumentCurrencyCode($currencyCode);
37
        // Orden de compra
38
        $this->addInvoiceOrderReference();
39
        // Información de la empresa
40
        $this->addInvoiceAccountingSupplierParty();
41
        // Información del cliente
42
        $this->addInvoiceAccountingCustomerParty();
43
        // Total items
44
        $this->setLineCountNumeric($Invoice->getTotalItems());
45
        // Detalle
46
        $this->addDocumentItems('InvoiceLine');
47
        // Impuestos
48
        $this->addDocumentTaxes();
49
        // Descuentos globales
50
        $ac = $Invoice->getAllowancesAndCharges();
51
        $baseAmount = $Items->getTotalTaxableAmount();
52
        UblHelper::addAllowancesCharges($this, $ac, $baseAmount, $currencyCode);
53
        // Totales
54
        $this->addInvoiceLegalMonetaryTotal();
55
    }
56
57
}
58