Completed
Push — master ( 74d6ff...309b24 )
by Roberto
43:07 queued 28:08
created

C510::strToFloat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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