|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NFePHP\EFD\Elements\Contribuicoes; |
|
4
|
|
|
|
|
5
|
|
|
use NFePHP\EFD\Common\Element; |
|
6
|
|
|
use NFePHP\EFD\Common\ElementInterface; |
|
7
|
|
|
use \stdClass; |
|
8
|
|
|
|
|
9
|
|
View Code Duplication |
class C185 extends Element implements ElementInterface |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
const REG = 'C185'; |
|
12
|
|
|
const LEVEL = 4; |
|
13
|
|
|
const PARENT = 'C180'; |
|
14
|
|
|
|
|
15
|
|
|
protected $parameters = [ |
|
16
|
|
|
'CST_COFINS' => [ |
|
17
|
|
|
'type' => 'numeric', |
|
18
|
|
|
'regex' => '^((0[1-9])|49|99)$', |
|
19
|
|
|
'required' => false, |
|
20
|
|
|
'info' => 'Código da Situação Tributária referente a COFINS, conforme a Tabela indicada no item 4.3.4.', |
|
21
|
|
|
'format' => '' |
|
22
|
|
|
], |
|
23
|
|
|
'CFOP' => [ |
|
24
|
|
|
'type' => 'numeric', |
|
25
|
|
|
'regex' => '^(\d{4})$', |
|
26
|
|
|
'required' => false, |
|
27
|
|
|
'info' => 'Código fiscal de operação e prestação', |
|
28
|
|
|
'format' => '' |
|
29
|
|
|
], |
|
30
|
|
|
'VL_ITEM' => [ |
|
31
|
|
|
'type' => 'numeric', |
|
32
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
33
|
|
|
'required' => false, |
|
34
|
|
|
'info' => 'Valor do item', |
|
35
|
|
|
'format' => '15v2' |
|
36
|
|
|
], |
|
37
|
|
|
'VL_DESC' => [ |
|
38
|
|
|
'type' => 'numeric', |
|
39
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
40
|
|
|
'required' => false, |
|
41
|
|
|
'info' => 'Valor do desconto comercial / exclusão da base de cálculo', |
|
42
|
|
|
'format' => '15v2' |
|
43
|
|
|
], |
|
44
|
|
|
'VL_BC_COFINS' => [ |
|
45
|
|
|
'type' => 'numeric', |
|
46
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
47
|
|
|
'required' => false, |
|
48
|
|
|
'info' => 'Valor da base de cálculo da COFINS', |
|
49
|
|
|
'format' => '15v2' |
|
50
|
|
|
], |
|
51
|
|
|
'ALIQ_COFINS' => [ |
|
52
|
|
|
'type' => 'numeric', |
|
53
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
54
|
|
|
'required' => false, |
|
55
|
|
|
'info' => 'Alíquota da COFINS (em percentual)', |
|
56
|
|
|
'format' => '8v4' |
|
57
|
|
|
], |
|
58
|
|
|
'QUANT_BC_COFINS' => [ |
|
59
|
|
|
'type' => 'numeric', |
|
60
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
61
|
|
|
'required' => false, |
|
62
|
|
|
'info' => 'Quantidade – Base de cálculo da COFINS', |
|
63
|
|
|
'format' => '15v3' |
|
64
|
|
|
], |
|
65
|
|
|
'ALIQ_COFINS_QUANT' => [ |
|
66
|
|
|
'type' => 'numeric', |
|
67
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
68
|
|
|
'required' => false, |
|
69
|
|
|
'info' => 'Alíquota da COFINS (em reais)', |
|
70
|
|
|
'format' => '15v4' |
|
71
|
|
|
], |
|
72
|
|
|
'VL_COFINS' => [ |
|
73
|
|
|
'type' => 'numeric', |
|
74
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
75
|
|
|
'required' => false, |
|
76
|
|
|
'info' => 'Valor da COFINS', |
|
77
|
|
|
'format' => '15v2' |
|
78
|
|
|
], |
|
79
|
|
|
'COD_CTA' => [ |
|
80
|
|
|
'type' => 'string', |
|
81
|
|
|
'regex' => '^.{0,255}$', |
|
82
|
|
|
'required' => false, |
|
83
|
|
|
'info' => 'Código da conta analítica contábil debitada/creditada', |
|
84
|
|
|
'format' => '' |
|
85
|
|
|
], |
|
86
|
|
|
|
|
87
|
|
|
]; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Constructor |
|
91
|
|
|
* @param \stdClass $std |
|
92
|
|
|
*/ |
|
93
|
|
|
public function __construct(\stdClass $std) |
|
94
|
|
|
{ |
|
95
|
|
|
parent::__construct(self::REG); |
|
96
|
|
|
$this->std = $this->standarize($std); |
|
97
|
|
|
$this->postValidation(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function postValidation() |
|
101
|
|
|
{ |
|
102
|
|
|
$multiplicacao = $this->values->vl_bc_cofins * $this->values->aliq_cofins; |
|
103
|
|
|
if ($this->values->quant_bc_cofins > 0) { |
|
104
|
|
|
$multiplicacao = $this->values->quant_bc_cofins * $this->values->aliq_cofins_quant; |
|
105
|
|
|
} |
|
106
|
|
|
if (number_format($this->values->vl_cofins, 2) != number_format($multiplicacao, 2)) { |
|
107
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
108
|
|
|
"O campo VL_COFINS deve de ser o calculo da multiplicacao " . |
|
109
|
|
|
"da base de calculo do cofins com a aliquota do cofins"); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.