C610   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 170
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 170
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B postValidation() 0 36 10
1
<?php
2
3
namespace NFePHP\EFD\Elements\ICMSIPI;
4
5
use NFePHP\EFD\Common\Element;
6
use NFePHP\EFD\Common\ElementInterface;
7
use \stdClass;
8
use function Safe\substr;
9
10
class C610 extends Element implements ElementInterface
11
{
12
    const REG = 'C610';
13
    const LEVEL = 3;
14
    const PARENT = 'C600';
15
16
    protected $parameters = [
17
        'COD_CLASS' => [
18
            'type' => 'numeric',
19
            'regex' => '^(\d{4})$',
20
            'required' => false,
21
            'info' => 'Código de classificação do item de energia elétrica',
22
            'format' => ''
23
        ],
24
        'COD_ITEM' => [
25
            'type' => 'string',
26
            'regex' => '^.{1,60}$',
27
            'required' => true,
28
            'info' => 'Código do item (campo 02 do Registro 0200)',
29
            'format' => ''
30
        ],
31
        'QTD' => [
32
            'type' => 'numeric',
33
            'regex' => '^\d+(\.\d*)?|\.\d+$',
34
            'required' => true,
35
            'info' => 'Quantidade acumulada do item',
36
            'format' => '15v3'
37
        ],
38
        'UNID' => [
39
            'type' => 'string',
40
            'regex' => '^.{1,6}$',
41
            'required' => true,
42
            'info' => 'Unidade do item (Campo 02 do registro 0190)',
43
            'format' => ''
44
        ],
45
        'VL_ITEM' => [
46
            'type' => 'numeric',
47
            'regex' => '^\d+(\.\d*)?|\.\d+$',
48
            'required' => true,
49
            'info' => 'Valor acumulado do item',
50
            'format' => '15v2'
51
        ],
52
        'VL_DESC' => [
53
            'type' => 'numeric',
54
            'regex' => '^\d+(\.\d*)?|\.\d+$',
55
            'required' => false,
56
            'info' => 'Valor acumulado dos descontos',
57
            'format' => '15v2'
58
        ],
59
        'CST_ICMS' => [
60
            'type' => 'numeric',
61
            'regex' => '^(\d{3})$',
62
            'required' => true,
63
            'info' => 'Código da Situação Tributária, conforme a Tabela indicada no item 4.3.1',
64
            'format' => ''
65
        ],
66
        'CFOP' => [
67
            'type' => 'numeric',
68
            'regex' => '^(\d{4})$',
69
            'required' => true,
70
            'info' => 'Código Fiscal de Operação e Prestação conforme tabela indicada no item 4.2.2.',
71
            'format' => ''
72
        ],
73
        'ALIQ_ICMS' => [
74
            'type' => 'numeric',
75
            'regex' => '^\d+(\.\d*)?|\.\d+$',
76
            'required' => false,
77
            'info' => 'Alíquota do ICMS',
78
            'format' => '6v2'
79
        ],
80
        'VL_BC_ICMS' => [
81
            'type' => 'numeric',
82
            'regex' => '^\d+(\.\d*)?|\.\d+$',
83
            'required' => false,
84
            'info' => 'Valor acumulado da base de cálculo do ICMS',
85
            'format' => '15v2'
86
        ],
87
        'VL_ICMS' => [
88
            'type' => 'numeric',
89
            'regex' => '^\d+(\.\d*)?|\.\d+$',
90
            'required' => false,
91
            'info' => 'Valor acumulado do ICMS debitado',
92
            'format' => '15v2'
93
        ],
94
        'VL_BC_ICMS_ST' => [
95
            'type' => 'numeric',
96
            'regex' => '^\d+(\.\d*)?|\.\d+$',
97
            'required' => false,
98
            'info' => 'Valor da base de cálculo do ICMS substituição tributária',
99
            'format' => '15v2'
100
        ],
101
        'VL_ICMS_ST' => [
102
            'type' => 'numeric',
103
            'regex' => '^\d+(\.\d*)?|\.\d+$',
104
            'required' => false,
105
            'info' => 'Valor do ICMS retido por substituição tributária',
106
            'format' => '15v2'
107
        ],
108
        'VL_PIS' => [
109
            'type' => 'numeric',
110
            'regex' => '^\d+(\.\d*)?|\.\d+$',
111
            'required' => false,
112
            'info' => 'Valor do PIS',
113
            'format' => '15v2'
114
        ],
115
        'VL_COFINS' => [
116
            'type' => 'numeric',
117
            'regex' => '^\d+(\.\d*)?|\.\d+$',
118
            'required' => false,
119
            'info' => 'Valor da COFINS',
120
            'format' => '15v2'
121
        ],
122
        'COD_CTA' => [
123
            'type' => 'string',
124
            'regex' => '^(.*)$',
125
            'required' => false,
126
            'info' => 'Código da conta analítica contábil debitada/creditada',
127
            'format' => ''
128
        ],
129
130
    ];
131
132
    /**
133
     * Constructor
134
     * @param \stdClass $std
135
     */
136
    public function __construct(\stdClass $std)
137
    {
138
        parent::__construct(self::REG);
139
        $this->std = $this->standarize($std);
140
        $this->postValidation();
141
    }
142
143
    public function postValidation()
144
    {
145
        if ($this->values->qtd <= 0) {
146
            throw new \InvalidArgumentException("[" . self::REG . "] " .
147
                " O do campo QTD deve ser maior do que 0");
148
        }
149
        //pega o fim da string do CST_ICMS e faz a verificacao
150
        $cstIcmsLast = (int) substr($this->std->cst_icms, -2);
151
        if (in_array($cstIcmsLast, [30, 40, 41, 50, 60])) {
152
            if ($this->values->vl_bc_icms != 0) {
153
                throw new \InvalidArgumentException("[" . self::REG . "] " .
154
                    " O do campo VL_BC_ICMS deve ser Igual 0");
155
            }
156
            if ($this->values->aliq_icms != 0) {
157
                throw new \InvalidArgumentException("[" . self::REG . "] " .
158
                    " O do campo VL_ICMS deve ser Igual 0");
159
            }
160
            if ($this->values->vl_icms != 0) {
161
                throw new \InvalidArgumentException("[" . self::REG . "] " .
162
                    " O do campo ALIQ_ICMS deve ser Igual 0");
163
            }
164
        } elseif (!in_array($cstIcmsLast, [51, 90])) {
165
            if ($this->values->vl_bc_icms <= 0) {
166
                throw new \InvalidArgumentException("[" . self::REG . "] " .
167
                    " O do campo VL_BC_ICMS deve ser maior do que 0");
168
            }
169
            if ($this->values->aliq_icms <= 0) {
170
                throw new \InvalidArgumentException("[" . self::REG . "] " .
171
                    " O do campo ALIQ_ICMS deve ser maior do que 0");
172
            }
173
            if ($this->values->vl_icms <= 0) {
174
                throw new \InvalidArgumentException("[" . self::REG . "] " .
175
                    " O do campo VL_ICMS deve ser maior do que 0");
176
            }
177
        }
178
    }
179
}
180