Code Duplication    Length = 121-123 lines in 2 locations

src/Elements/ICMSIPI/C490.php 1 location

@@ 9-129 (lines=121) @@
6
use NFePHP\EFD\Common\ElementInterface;
7
use \stdClass;
8
9
class C490 extends Element implements ElementInterface
10
{
11
    const REG = 'C490';
12
    const LEVEL = 4;
13
    const PARENT = 'C400';
14
15
    protected $parameters = [
16
        'CST_ICMS' => [
17
            'type' => 'numeric',
18
            'regex' => '^(\d{3})$',
19
            'required' => true,
20
            'info' => 'Código da Situação Tributária,',
21
            'format' => ''
22
        ],
23
        'CFOP' => [
24
            'type' => 'numeric',
25
            'regex' => '^(\d{4})$',
26
            'required' => true,
27
            'info' => 'Código Fiscal de Operação e Prestação',
28
            'format' => ''
29
        ],
30
        'ALIQ_ICMS' => [
31
            'type' => 'numeric',
32
            'regex' => '^\d+(\.\d*)?|\.\d+$',
33
            'required' => false,
34
            'info' => 'Alíquota do ICMS',
35
            'format' => '6v2'
36
        ],
37
        'VL_OPR' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => true,
41
            'info' => 'Valor da operação correspondente à combinação de CST_ICMS, CFOP, e alíquota do ICMS, 
42
            incluídas as despesas acessórias e acréscimos',
43
            'format' => '15v2'
44
        ],
45
        'VL_BC_ICMS' => [
46
            'type' => 'numeric',
47
            'regex' => '^\d+(\.\d*)?|\.\d+$',
48
            'required' => true,
49
            'info' => 'Valor acumulado da base de cálculo do ICMS, referente à combinação 
50
            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' => true,
57
            'info' => 'Valor acumulado do ICMS, referente à combinação de CST_ICMS, CFOP e alíquota do ICMS.',
58
            'format' => '15v2'
59
        ],
60
        'COD_OBS' => [
61
            'type' => 'string',
62
            'regex' => '^.{0,6}$',
63
            'required' => false,
64
            'info' => 'Código da observação do lançamento fiscal (campo 02 do Registro 0460)',
65
            'format' => ''
66
        ],
67
    ];
68
69
    /**
70
     * Constructor
71
     * @param \stdClass $std
72
     */
73
    public function __construct(\stdClass $std)
74
    {
75
        parent::__construct(self::REG);
76
        $this->std = $this->standarize($std);
77
        $this->postValidation();
78
    }
79
80
81
    /**
82
     * Transforma o valor com virgula em float para poder fazer os calculos de verificacao
83
     * @param $vlr
84
     * @return mixed
85
     */
86
    private function strToFloat($vlr)
87
    {
88
        return (float)str_replace(',', '.', $this->std->$vlr);
89
    }
90
91
92
    public function postValidation()
93
    {
94
        //transforma os valores em float
95
        $vlBcIcms = $this->strToFloat('vl_bc_icms');
96
        $aliqIcms = $this->strToFloat('aliq_icms');
97
        $vlIcms = $this->strToFloat('vl_icms');
98
99
        //pega o fim da string do CST_ICMS e faz a verificacao
100
        $cstIcmsLast = (int)substr($this->std-> cst_icms, -2);
101
        if (in_array($cstIcmsLast, [30, 40, 41, 50, 60])) {
102
            if ($vlBcIcms != 0) {
103
                throw new \InvalidArgumentException("[" . self::REG . "] " .
104
                    " O do campo VL_BC_ICMS deve ser Igual 0");
105
            }
106
            if ($aliqIcms != 0) {
107
                throw new \InvalidArgumentException("[" . self::REG . "] " .
108
                    " O do campo VL_ICMS deve ser Igual 0");
109
            }
110
            if ($vlIcms != 0) {
111
                throw new \InvalidArgumentException("[" . self::REG . "] " .
112
                    " O do campo ALIQ_ICMS deve ser Igual 0");
113
            }
114
        } elseif (!in_array($cstIcmsLast, [51, 90])) {
115
            if ($vlBcIcms <= 0) {
116
                throw new \InvalidArgumentException("[" . self::REG . "] " .
117
                    " O do campo VL_BC_ICMS deve ser maior do que 0");
118
            }
119
            if ($aliqIcms <= 0) {
120
                throw new \InvalidArgumentException("[" . self::REG . "] " .
121
                    " O do campo ALIQ_ICMS deve ser maior do que 0");
122
            }
123
            if ($vlIcms <= 0) {
124
                throw new \InvalidArgumentException("[" . self::REG . "] " .
125
                    " O do campo VL_ICMS deve ser maior do que 0");
126
            }
127
        }
128
    }
129
}
130

src/Elements/ICMSIPI/C850.php 1 location

@@ 9-131 (lines=123) @@
6
use NFePHP\EFD\Common\ElementInterface;
7
use \stdClass;
8
9
class C850 extends Element implements ElementInterface
10
{
11
    const REG = 'C850';
12
    const LEVEL = 3;
13
    const PARENT = 'C800';
14
15
    protected $parameters = [
16
        'CST_ICMS' => [
17
            'type' => 'numeric',
18
            'regex' => '^(\d{1,3})$',
19
            'required' => true,
20
            'info' => 'Código da Situação Tributária, conforme a Tabela indicada no item 4.3.1',
21
            'format' => ''
22
        ],
23
        'CFOP' => [
24
            'type' => 'numeric',
25
            'regex' => '^(\d{1,4})$',
26
            'required' => true,
27
            'info' => 'Código Fiscal de Operação e Prestação do agrupamento de itens',
28
            'format' => ''
29
        ],
30
        'ALIQ_ICMS' => [
31
            'type' => 'numeric',
32
            'regex' => '^\d+(\.\d*)?|\.\d+$',
33
            'required' => false,
34
            'info' => 'Alíquota do ICMS',
35
            'format' => '6v2'
36
        ],
37
        'VL_OPR' => [
38
            'type' => 'numeric',
39
            'regex' => '^\d+(\.\d*)?|\.\d+$',
40
            'required' => true,
41
            'info' => '“Valor total do CF-e” na combinação de CST_ICMS, CFOP e alíquota do ICMS, 
42
            correspondente ao somatório do valor líquido dos itens.',
43
            'format' => '15v2'
44
        ],
45
        'VL_BC_ICMS' => [
46
            'type' => 'string',
47
            'regex' => '^.{1,2}$',
48
            'required' => true,
49
            'info' => 'N',
50
            'format' => ''
51
        ],
52
        'VL_ICMS' => [
53
            'type' => 'numeric',
54
            'regex' => '^\d+(\.\d*)?|\.\d+$',
55
            'required' => true,
56
            'info' => 'Parcela correspondente ao "Valor do ICMS" referente à 
57
            combinação de CST_ICMS, CFOP e alíquota do ICMS.',
58
            'format' => '15v2'
59
        ],
60
        'COD_OBS' => [
61
            'type' => 'string',
62
            'regex' => '^.{0,6}$',
63
            'required' => false,
64
            'info' => 'Código da observação do lançamento fiscal',
65
            'format' => ''
66
        ],
67
68
    ];
69
70
    /**
71
     * Constructor
72
     * @param \stdClass $std
73
     */
74
    public function __construct(\stdClass $std)
75
    {
76
        parent::__construct(self::REG);
77
        $this->std = $this->standarize($std);
78
        $this->postValidation();
79
    }
80
81
82
83
    /**
84
     * Transforma o valor com virgula em float para poder fazer os calculos de verificacao
85
     * @param $vlr
86
     * @return mixed
87
     */
88
    private function strToFloat($vlr)
89
    {
90
        return (float)str_replace(',', '.', $this->std->$vlr);
91
    }
92
93
94
    public function postValidation()
95
    {
96
        //transforma os valores em float
97
        $vlBcIcms = $this->strToFloat('vl_bc_icms');
98
        $aliqIcms = $this->strToFloat('aliq_icms');
99
        $vlIcms = $this->strToFloat('vl_icms');
100
101
        //pega o fim da string do CST_ICMS e faz a verificacao
102
        $cstIcmsLast = (int)substr($this->std-> cst_icms, -2);
103
        if (in_array($cstIcmsLast, [40, 41, 50, 60])) {
104
            if ($vlBcIcms != 0) {
105
                throw new \InvalidArgumentException("[" . self::REG . "] " .
106
                    " O do campo VL_BC_ICMS deve ser Igual 0");
107
            }
108
            if ($aliqIcms != 0) {
109
                throw new \InvalidArgumentException("[" . self::REG . "] " .
110
                    " O do campo VL_ICMS deve ser Igual 0");
111
            }
112
            if ($vlIcms != 0) {
113
                throw new \InvalidArgumentException("[" . self::REG . "] " .
114
                    " O do campo ALIQ_ICMS deve ser Igual 0");
115
            }
116
        } elseif (!in_array($cstIcmsLast, [51, 90])) {
117
            if ($vlBcIcms <= 0) {
118
                throw new \InvalidArgumentException("[" . self::REG . "] " .
119
                    " O do campo VL_BC_ICMS deve ser maior do que 0");
120
            }
121
            if ($aliqIcms <= 0) {
122
                throw new \InvalidArgumentException("[" . self::REG . "] " .
123
                    " O do campo ALIQ_ICMS deve ser maior do que 0");
124
            }
125
            if ($vlIcms <= 0) {
126
                throw new \InvalidArgumentException("[" . self::REG . "] " .
127
                    " O do campo VL_ICMS deve ser maior do que 0");
128
            }
129
        }
130
    }
131
}
132