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 C590 extends Element implements ElementInterface |
11
|
|
|
{ |
12
|
|
|
const REG = 'C590'; |
13
|
|
|
const LEVEL = 3; |
14
|
|
|
const PARENT = 'C500'; |
15
|
|
|
|
16
|
|
|
protected $parameters = [ |
17
|
|
|
'CST_ICMS' => [ |
18
|
|
|
'type' => 'numeric', |
19
|
|
|
'regex' => '^(\d{3})$', |
20
|
|
|
'required' => true, |
21
|
|
|
'info' => 'Código da Situação Tributária, conforme a Tabela indicada no item 4.3.1.', |
22
|
|
|
'format' => '' |
23
|
|
|
], |
24
|
|
|
'CFOP' => [ |
25
|
|
|
'type' => 'numeric', |
26
|
|
|
'regex' => '^(\d{4})$', |
27
|
|
|
'required' => true, |
28
|
|
|
'info' => 'Código Fiscal de agrupamento de itens', |
29
|
|
|
'format' => '' |
30
|
|
|
], |
31
|
|
|
'ALIQ_ICMS' => [ |
32
|
|
|
'type' => 'numeric', |
33
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
34
|
|
|
'required' => false, |
35
|
|
|
'info' => 'Alíquota do ICMS', |
36
|
|
|
'format' => '6v2' |
37
|
|
|
], |
38
|
|
|
'VL_OPR' => [ |
39
|
|
|
'type' => 'numeric', |
40
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
41
|
|
|
'required' => true, |
42
|
|
|
'info' => 'Valor da operação correspondente à combinação de CST_ICMS, CFOP, e alíquota do ICMS.', |
43
|
|
|
'format' => '15v2' |
44
|
|
|
], |
45
|
|
|
'VL_BC_ICMS' => [ |
46
|
|
|
'type' => 'numeric', |
47
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
48
|
|
|
'required' => false, |
49
|
|
|
'info' => 'Parcela correspondente ao "Valor da base de cálculo do ICMS" |
50
|
|
|
referente à combinação de CST_ICMS, CFOP e alíquota do ICMS.', |
51
|
|
|
'format' => '15v2' |
52
|
|
|
], |
53
|
|
|
'VL_ICMS' => [ |
54
|
|
|
'type' => 'numeric', |
55
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
56
|
|
|
'required' => false, |
57
|
|
|
'info' => 'Parcela correspondente ao "Valor do ICMS" referente à combinação |
58
|
|
|
de CST_ICMS, CFOP e alíquota do ICMS.', |
59
|
|
|
'format' => '15v2' |
60
|
|
|
], |
61
|
|
|
'VL_BC_ICMS_ST' => [ |
62
|
|
|
'type' => 'numeric', |
63
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
64
|
|
|
'required' => false, |
65
|
|
|
'info' => 'Parcela correspondente ao "Valor da base de cálculo do ICMS" da substituição |
66
|
|
|
tributária referente à combinação de CST_ICMS, CFOP e alíquota do ICMS.', |
67
|
|
|
'format' => '15v2' |
68
|
|
|
], |
69
|
|
|
'VL_ICMS_ST' => [ |
70
|
|
|
'type' => 'numeric', |
71
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
72
|
|
|
'required' => false, |
73
|
|
|
'info' => 'Parcela correspondente ao valor creditado/debitado do ICMS ' |
74
|
|
|
. 'da substituição tributária, referente à combinação de CST_ICMS, ' |
75
|
|
|
. 'CFOP, e alíquota do ICMS', |
76
|
|
|
'format' => '15v2' |
77
|
|
|
], |
78
|
|
|
'VL_RED_BC' => [ |
79
|
|
|
'type' => 'numeric', |
80
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
81
|
|
|
'required' => false, |
82
|
|
|
'info' => 'Valor não tributado em função da redução da base de cálculo do ICMS, |
83
|
|
|
referente à combinação de CST_ICMS, CFOP e alíquota do ICMS.', |
84
|
|
|
'format' => '15v2' |
85
|
|
|
], |
86
|
|
|
'COD_OBS' => [ |
87
|
|
|
'type' => 'string', |
88
|
|
|
'regex' => '^.{0,6}$', |
89
|
|
|
'required' => false, |
90
|
|
|
'info' => 'Código da observação do lançamento fiscal (campo 02 do Registro 0460)', |
91
|
|
|
'format' => '' |
92
|
|
|
], |
93
|
|
|
|
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Constructor |
98
|
|
|
* @param \stdClass $std |
99
|
|
|
*/ |
100
|
|
|
public function __construct(\stdClass $std) |
101
|
|
|
{ |
102
|
|
|
parent::__construct(self::REG); |
103
|
|
|
$this->std = $this->standarize($std); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function postValidation() |
107
|
|
|
{ |
108
|
|
|
//pega o fim da string do CST_ICMS e faz a verificacao |
109
|
|
|
$cstIcmsLast = (int) substr($this->std-> cst_icms, -2); |
110
|
|
|
if (in_array($cstIcmsLast, [30, 40, 41, 50, 60])) { |
111
|
|
|
if ($this->values->vl_bc_icms != 0) { |
112
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
113
|
|
|
" O do campo VL_BC_ICMS deve ser Igual 0"); |
114
|
|
|
} |
115
|
|
|
if ($this->values->aliq_icms != 0) { |
116
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
117
|
|
|
" O do campo VL_ICMS deve ser Igual 0"); |
118
|
|
|
} |
119
|
|
|
if ($this->values->vl_icms != 0) { |
120
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
121
|
|
|
" O do campo ALIQ_ICMS deve ser Igual 0"); |
122
|
|
|
} |
123
|
|
|
} elseif (!in_array($cstIcmsLast, [51, 90])) { |
124
|
|
|
if ($this->values->vl_bc_icms <= 0) { |
125
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
126
|
|
|
" O do campo VL_BC_ICMS deve ser maior do que 0"); |
127
|
|
|
} |
128
|
|
|
if ($this->values->aliq_icms <= 0) { |
129
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
130
|
|
|
" O do campo ALIQ_ICMS deve ser maior do que 0"); |
131
|
|
|
} |
132
|
|
|
if ($this->values->vl_icms <= 0) { |
133
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
134
|
|
|
" O do campo VL_ICMS deve ser maior do que 0"); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|