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 C510 extends Element implements ElementInterface |
11
|
|
|
{ |
12
|
|
|
const REG = 'C510'; |
13
|
|
|
const LEVEL = 3; |
14
|
|
|
const PARENT = 'C500'; |
15
|
|
|
|
16
|
|
|
protected $parameters = [ |
17
|
|
|
'NUM_ITEM' => [ |
18
|
|
|
'type' => 'numeric', |
19
|
|
|
'regex' => '^(\d{1,3})$', |
20
|
|
|
'required' => true, |
21
|
|
|
'info' => 'Número sequencial do item no documento fiscal', |
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
|
|
|
'COD_CLASS' => [ |
32
|
|
|
'type' => 'numeric', |
33
|
|
|
'regex' => '^(\d{4})$', |
34
|
|
|
'required' => false, |
35
|
|
|
'info' => 'Código de classificação do item de energia', |
36
|
|
|
'format' => '' |
37
|
|
|
], |
38
|
|
|
'QTD' => [ |
39
|
|
|
'type' => 'numeric', |
40
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
41
|
|
|
'required' => false, |
42
|
|
|
'info' => 'Quantidade do item', |
43
|
|
|
'format' => '15v3' |
44
|
|
|
], |
45
|
|
|
'UNID' => [ |
46
|
|
|
'type' => 'string', |
47
|
|
|
'regex' => '^.{0,6}$', |
48
|
|
|
'required' => false, |
49
|
|
|
'info' => 'Unidade do item (Campo 02 do registro 0190)', |
50
|
|
|
'format' => '' |
51
|
|
|
], |
52
|
|
|
'VL_ITEM' => [ |
53
|
|
|
'type' => 'numeric', |
54
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
55
|
|
|
'required' => true, |
56
|
|
|
'info' => 'Valor do item', |
57
|
|
|
'format' => '15v2' |
58
|
|
|
], |
59
|
|
|
'VL_DESC' => [ |
60
|
|
|
'type' => 'numeric', |
61
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
62
|
|
|
'required' => false, |
63
|
|
|
'info' => 'Valor total do desconto', |
64
|
|
|
'format' => '15v2' |
65
|
|
|
], |
66
|
|
|
'CST_ICMS' => [ |
67
|
|
|
'type' => 'numeric', |
68
|
|
|
'regex' => '^(\d{3})$', |
69
|
|
|
'required' => true, |
70
|
|
|
'info' => 'Código da Situação Tributária', |
71
|
|
|
'format' => '' |
72
|
|
|
], |
73
|
|
|
'CFOP' => [ |
74
|
|
|
'type' => 'numeric', |
75
|
|
|
'regex' => '^(\d{4})$', |
76
|
|
|
'required' => true, |
77
|
|
|
'info' => 'Código Fiscal de Operação e Prestação', |
78
|
|
|
'format' => '' |
79
|
|
|
], |
80
|
|
|
'VL_BC_ICMS' => [ |
81
|
|
|
'type' => 'numeric', |
82
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
83
|
|
|
'required' => false, |
84
|
|
|
'info' => 'Valor da base de cálculo do ICMS', |
85
|
|
|
'format' => '15v2' |
86
|
|
|
], |
87
|
|
|
'ALIQ_ICMS' => [ |
88
|
|
|
'type' => 'numeric', |
89
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
90
|
|
|
'required' => false, |
91
|
|
|
'info' => 'Alíquota do ICMS', |
92
|
|
|
'format' => '6v2' |
93
|
|
|
], |
94
|
|
|
'VL_ICMS' => [ |
95
|
|
|
'type' => 'numeric', |
96
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
97
|
|
|
'required' => false, |
98
|
|
|
'info' => 'Valor do ICMS creditado/debitado', |
99
|
|
|
'format' => '15v2' |
100
|
|
|
], |
101
|
|
|
'VL_BC_ICMS_ST' => [ |
102
|
|
|
'type' => 'numeric', |
103
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
104
|
|
|
'required' => false, |
105
|
|
|
'info' => 'Valor da base de cálculo referente à substituição tributária', |
106
|
|
|
'format' => '15v2' |
107
|
|
|
], |
108
|
|
|
'ALIQ_ST' => [ |
109
|
|
|
'type' => 'numeric', |
110
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
111
|
|
|
'required' => false, |
112
|
|
|
'info' => 'Alíquota do ICMS da substituição tributária na unidade da federação de destino', |
113
|
|
|
'format' => '6v2' |
114
|
|
|
], |
115
|
|
|
'VL_ICMS_ST' => [ |
116
|
|
|
'type' => 'numeric', |
117
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
118
|
|
|
'required' => false, |
119
|
|
|
'info' => 'Valor do ICMS referente à substituição tributária', |
120
|
|
|
'format' => '15v2' |
121
|
|
|
], |
122
|
|
|
'IND_REC' => [ |
123
|
|
|
'type' => 'string', |
124
|
|
|
'regex' => '^(0|1)$', |
125
|
|
|
'required' => true, |
126
|
|
|
'info' => 'Indicador do tipo de receita', |
127
|
|
|
'format' => '' |
128
|
|
|
], |
129
|
|
|
'COD_PART' => [ |
130
|
|
|
'type' => 'string', |
131
|
|
|
'regex' => '^.{0,60}$', |
132
|
|
|
'required' => false, |
133
|
|
|
'info' => 'Código do participante receptor da receita', |
134
|
|
|
'format' => '' |
135
|
|
|
], |
136
|
|
|
'VL_PIS' => [ |
137
|
|
|
'type' => 'numeric', |
138
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
139
|
|
|
'required' => false, |
140
|
|
|
'info' => 'Valor do PIS', |
141
|
|
|
'format' => '15v2' |
142
|
|
|
], |
143
|
|
|
'VL_COFINS' => [ |
144
|
|
|
'type' => 'numeric', |
145
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
146
|
|
|
'required' => false, |
147
|
|
|
'info' => 'Valor da COFINS', |
148
|
|
|
'format' => '15v2' |
149
|
|
|
], |
150
|
|
|
'COD_CTA' => [ |
151
|
|
|
'type' => 'string', |
152
|
|
|
'regex' => '^.*$', |
153
|
|
|
'required' => false, |
154
|
|
|
'info' => 'Código da conta analítica contábil debitada/creditada', |
155
|
|
|
'format' => '' |
156
|
|
|
], |
157
|
|
|
]; |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Constructor |
161
|
|
|
* @param \stdClass $std |
162
|
|
|
*/ |
163
|
|
|
public function __construct(\stdClass $std) |
164
|
|
|
{ |
165
|
|
|
parent::__construct(self::REG); |
166
|
|
|
$this->std = $this->standarize($std); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function postValidation() |
170
|
|
|
{ |
171
|
|
|
//pega o fim da string do CST_ICMS e faz a verificacao |
172
|
|
|
$cstIcmsLast = (int) substr($this->std-> cst_icms, -2); |
173
|
|
|
if (in_array($cstIcmsLast, [30, 40, 41, 50, 60])) { |
174
|
|
|
if ($this->values->vl_br_icms != 0) { |
175
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
176
|
|
|
" O do campo VL_BC_ICMS deve ser Igual 0"); |
177
|
|
|
} |
178
|
|
|
if ($this->values->aliq_icms != 0) { |
179
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
180
|
|
|
" O do campo VL_ICMS deve ser Igual 0"); |
181
|
|
|
} |
182
|
|
|
if ($this->values->vl_icms != 0) { |
183
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
184
|
|
|
" O do campo ALIQ_ICMS deve ser Igual 0"); |
185
|
|
|
} |
186
|
|
|
} elseif (!in_array($cstIcmsLast, [51, 90])) { |
187
|
|
|
if ($this->values->vl_bc_icms <= 0) { |
188
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
189
|
|
|
" O do campo VL_BC_ICMS deve ser maior do que 0"); |
190
|
|
|
} |
191
|
|
|
if ($this->values->aliq_icms <= 0) { |
192
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
193
|
|
|
" O do campo ALIQ_ICMS deve ser maior do que 0"); |
194
|
|
|
} |
195
|
|
|
if ($this->values->vl_icms <= 0) { |
196
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
197
|
|
|
" O do campo VL_ICMS deve ser maior do que 0"); |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|