1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NFePHP\EFD\Elements\Contribuicoes; |
4
|
|
|
|
5
|
|
|
use NFePHP\EFD\Common\Element; |
6
|
|
|
use NFePHP\EFD\Common\ElementInterface; |
7
|
|
|
|
8
|
|
View Code Duplication |
class D101 extends Element implements ElementInterface |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
const REG = 'D101'; |
11
|
|
|
const LEVEL = 4; |
12
|
|
|
const PARENT = 'D100'; |
13
|
|
|
|
14
|
|
|
protected $parameters = [ |
15
|
|
|
'IND_NAT_FRT' => [ |
16
|
|
|
'type' => 'string', |
17
|
|
|
'regex' => '^(0|1|2|3|4|5|9)$', |
18
|
|
|
'required' => false, |
19
|
|
|
'info' => 'Indicador da Natureza do Frete Contratado, referente a ' . |
20
|
|
|
' 0 – Operações de vendas, com ônus suportado pelo estabelecimento vendedor ' . |
21
|
|
|
' 1 – Operações de vendas, com ônus suportado pelo adquirente ' . |
22
|
|
|
' 2 – Operações de compras (bens para revenda, matérias-prima e outros produtos, ' . |
23
|
|
|
'geradores de crédito) ' . |
24
|
|
|
' 3 – Operações de compras (bens para revenda, matérias-prima e outros produtos, não ' . |
25
|
|
|
'geradores de crédito) ' . |
26
|
|
|
' 4 – Transferência de produtos acabados entre ', |
27
|
|
|
'format' => '' |
28
|
|
|
], |
29
|
|
|
'VL_ITEM' => [ |
30
|
|
|
'type' => 'numeric', |
31
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
32
|
|
|
'required' => false, |
33
|
|
|
'info' => 'Valor total dos itens ', |
34
|
|
|
'format' => '15v2' |
35
|
|
|
], |
36
|
|
|
'CST_PIS' => [ |
37
|
|
|
'type' => 'string', |
38
|
|
|
'regex' => '^((5[0-6])|(6[0-6])|(7[0-5])|98|99)$', |
39
|
|
|
'required' => false, |
40
|
|
|
'info' => 'Código da Situação Tributária referente ao PIS/PASEP ', |
41
|
|
|
'format' => '' |
42
|
|
|
], |
43
|
|
|
'NAT_BC_CRED' => [ |
44
|
|
|
'type' => 'string', |
45
|
|
|
'regex' => '^.{2}$', |
46
|
|
|
'required' => false, |
47
|
|
|
'info' => 'Código da Base de Cálculo do Crédito, conforme a Tabela indicada no item 4.3.7. ', |
48
|
|
|
'format' => '' |
49
|
|
|
], |
50
|
|
|
'VL_BC_PIS' => [ |
51
|
|
|
'type' => 'numeric', |
52
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
53
|
|
|
'required' => false, |
54
|
|
|
'info' => 'Valor da base de cálculo do PIS/PASEP ', |
55
|
|
|
'format' => '15v2' |
56
|
|
|
], |
57
|
|
|
'ALIQ_PIS' => [ |
58
|
|
|
'type' => 'numeric', |
59
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
60
|
|
|
'required' => false, |
61
|
|
|
'info' => 'Alíquota do PIS/PASEP (em percentual) ', |
62
|
|
|
'format' => '8v4' |
63
|
|
|
], |
64
|
|
|
'VL_PIS' => [ |
65
|
|
|
'type' => 'numeric', |
66
|
|
|
'regex' => '^\d+(\.\d*)?|\.\d+$', |
67
|
|
|
'required' => false, |
68
|
|
|
'info' => 'Valor do PIS/PASEP ', |
69
|
|
|
'format' => '15v2' |
70
|
|
|
], |
71
|
|
|
'COD_CTA' => [ |
72
|
|
|
'type' => 'string', |
73
|
|
|
'regex' => '^.{0,255}$', |
74
|
|
|
'required' => false, |
75
|
|
|
'info' => 'Código da conta analítica contábil debitada/creditada ', |
76
|
|
|
'format' => '' |
77
|
|
|
], |
78
|
|
|
|
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Constructor |
83
|
|
|
* @param \stdClass $std |
84
|
|
|
*/ |
85
|
|
|
public function __construct(\stdClass $std) |
86
|
|
|
{ |
87
|
|
|
parent::__construct(self::REG); |
88
|
|
|
$this->std = $this->standarize($std); |
89
|
|
|
$this->postValidation(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function postValidation() |
93
|
|
|
{ |
94
|
|
|
$multiplicacao = $this->values->vl_bc_pis * $this->values->aliq_pis; |
95
|
|
|
if (number_format($this->values->vl_pis, 2) != number_format($multiplicacao / 100, 2)) { |
96
|
|
|
throw new \InvalidArgumentException("[" . self::REG . "] " . |
97
|
|
|
"O campo VL_PIS deve de ser o calculo da multiplicacao " . |
98
|
|
|
"da base de calculo do PIS com a aliquota do PIS, o resultado dividido por 100"); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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.