| @@ 10-113 (lines=104) @@ | ||
| 7 | use \stdClass; |
|
| 8 | use function Safe\substr; |
|
| 9 | ||
| 10 | class C490 extends Element implements ElementInterface |
|
| 11 | { |
|
| 12 | const REG = 'C490'; |
|
| 13 | const LEVEL = 4; |
|
| 14 | const PARENT = 'C400'; |
|
| 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,', |
|
| 22 | 'format' => '' |
|
| 23 | ], |
|
| 24 | 'CFOP' => [ |
|
| 25 | 'type' => 'numeric', |
|
| 26 | 'regex' => '^(\d{4})$', |
|
| 27 | 'required' => true, |
|
| 28 | 'info' => 'Código Fiscal de Operação e Prestação', |
|
| 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 | incluídas as despesas acessórias e acréscimos', |
|
| 44 | 'format' => '15v2' |
|
| 45 | ], |
|
| 46 | 'VL_BC_ICMS' => [ |
|
| 47 | 'type' => 'numeric', |
|
| 48 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
| 49 | 'required' => true, |
|
| 50 | 'info' => 'Valor acumulado da base de cálculo do ICMS, referente à combinação |
|
| 51 | de CST_ICMS, CFOP, e alíquota do ICMS.', |
|
| 52 | 'format' => '15v2' |
|
| 53 | ], |
|
| 54 | 'VL_ICMS' => [ |
|
| 55 | 'type' => 'numeric', |
|
| 56 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
| 57 | 'required' => true, |
|
| 58 | 'info' => 'Valor acumulado do ICMS, referente à combinação de CST_ICMS, CFOP e alíquota do ICMS.', |
|
| 59 | 'format' => '15v2' |
|
| 60 | ], |
|
| 61 | 'COD_OBS' => [ |
|
| 62 | 'type' => 'string', |
|
| 63 | 'regex' => '^.{0,6}$', |
|
| 64 | 'required' => false, |
|
| 65 | 'info' => 'Código da observação do lançamento fiscal (campo 02 do Registro 0460)', |
|
| 66 | 'format' => '' |
|
| 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 | public function postValidation() |
|
| 82 | { |
|
| 83 | //pega o fim da string do CST_ICMS e faz a verificacao |
|
| 84 | $cstIcmsLast = (int) substr($this->std->cst_icms, -2); |
|
| 85 | if (in_array($cstIcmsLast, [30, 40, 41, 50, 60])) { |
|
| 86 | if ($this->values->vl_bc_icms != 0) { |
|
| 87 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 88 | " O do campo VL_BC_ICMS deve ser Igual 0"); |
|
| 89 | } |
|
| 90 | if ($this->values->aliq_icms != 0) { |
|
| 91 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 92 | " O do campo VL_ICMS deve ser Igual 0"); |
|
| 93 | } |
|
| 94 | if ($this->values->vl_icms != 0) { |
|
| 95 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 96 | " O do campo ALIQ_ICMS deve ser Igual 0"); |
|
| 97 | } |
|
| 98 | } elseif (!in_array($cstIcmsLast, [51, 90])) { |
|
| 99 | if ($this->values->vl_bc_icms <= 0) { |
|
| 100 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 101 | " O do campo VL_BC_ICMS deve ser maior do que 0"); |
|
| 102 | } |
|
| 103 | if ($this->values->aliq_icms <= 0) { |
|
| 104 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 105 | " O do campo ALIQ_ICMS deve ser maior do que 0"); |
|
| 106 | } |
|
| 107 | if ($this->values->vl_icms <= 0) { |
|
| 108 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 109 | " O do campo VL_ICMS deve ser maior do que 0"); |
|
| 110 | } |
|
| 111 | } |
|
| 112 | } |
|
| 113 | } |
|
| 114 | ||
| @@ 14-118 (lines=105) @@ | ||
| 11 | * REGISTRO C850: REGISTRO ANALÍTICO DO CF-e-SAT (CODIGO 59) |
|
| 12 | * @package NFePHP\EFD\Elements\ICMSIPI |
|
| 13 | */ |
|
| 14 | class C850 extends Element implements ElementInterface |
|
| 15 | { |
|
| 16 | const REG = 'C850'; |
|
| 17 | const LEVEL = 3; |
|
| 18 | const PARENT = 'C800'; |
|
| 19 | ||
| 20 | protected $parameters = [ |
|
| 21 | 'CST_ICMS' => [ |
|
| 22 | 'type' => 'numeric', |
|
| 23 | 'regex' => '^(\d{1,3})$', |
|
| 24 | 'required' => true, |
|
| 25 | 'info' => 'Código da Situação Tributária, conforme a Tabela indicada no item 4.3.1', |
|
| 26 | 'format' => '' |
|
| 27 | ], |
|
| 28 | 'CFOP' => [ |
|
| 29 | 'type' => 'numeric', |
|
| 30 | 'regex' => '^(\d{1,4})$', |
|
| 31 | 'required' => true, |
|
| 32 | 'info' => 'Código Fiscal de Operação e Prestação do agrupamento de itens', |
|
| 33 | 'format' => '' |
|
| 34 | ], |
|
| 35 | 'ALIQ_ICMS' => [ |
|
| 36 | 'type' => 'numeric', |
|
| 37 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
| 38 | 'required' => false, |
|
| 39 | 'info' => 'Alíquota do ICMS', |
|
| 40 | 'format' => '6v2' |
|
| 41 | ], |
|
| 42 | 'VL_OPR' => [ |
|
| 43 | 'type' => 'numeric', |
|
| 44 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
| 45 | 'required' => true, |
|
| 46 | 'info' => '“Valor total do CF-e” na combinação de CST_ICMS, CFOP e alíquota do ICMS, |
|
| 47 | correspondente ao somatório do valor líquido dos itens.', |
|
| 48 | 'format' => '15v2' |
|
| 49 | ], |
|
| 50 | 'VL_BC_ICMS' => [ |
|
| 51 | 'type' => 'string', |
|
| 52 | 'regex' => '^.{1,2}$', |
|
| 53 | 'required' => true, |
|
| 54 | 'info' => 'N', |
|
| 55 | 'format' => '15v2' |
|
| 56 | ], |
|
| 57 | 'VL_ICMS' => [ |
|
| 58 | 'type' => 'numeric', |
|
| 59 | 'regex' => '^\d+(\.\d*)?|\.\d+$', |
|
| 60 | 'required' => true, |
|
| 61 | 'info' => 'Parcela correspondente ao "Valor do ICMS" referente à |
|
| 62 | combinação de CST_ICMS, CFOP e alíquota do ICMS.', |
|
| 63 | 'format' => '15v2' |
|
| 64 | ], |
|
| 65 | 'COD_OBS' => [ |
|
| 66 | 'type' => 'string', |
|
| 67 | 'regex' => '^.{0,6}$', |
|
| 68 | 'required' => false, |
|
| 69 | 'info' => 'Código da observação do lançamento fiscal', |
|
| 70 | 'format' => '' |
|
| 71 | ], |
|
| 72 | ||
| 73 | ]; |
|
| 74 | ||
| 75 | /** |
|
| 76 | * Constructor |
|
| 77 | * @param \stdClass $std |
|
| 78 | */ |
|
| 79 | public function __construct(\stdClass $std) |
|
| 80 | { |
|
| 81 | parent::__construct(self::REG); |
|
| 82 | $this->std = $this->standarize($std); |
|
| 83 | $this->postValidation(); |
|
| 84 | } |
|
| 85 | ||
| 86 | public function postValidation() |
|
| 87 | { |
|
| 88 | //pega o fim da string do CST_ICMS e faz a verificacao |
|
| 89 | $cstIcmsLast = (int) substr($this->std->cst_icms, -2); |
|
| 90 | if (in_array($cstIcmsLast, [40, 41, 50, 60])) { |
|
| 91 | if ($this->values->vl_bc_icms != 0) { |
|
| 92 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 93 | " O do campo VL_BC_ICMS deve ser Igual 0"); |
|
| 94 | } |
|
| 95 | if ($this->values->aliq_icms != 0) { |
|
| 96 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 97 | " O do campo VL_ICMS deve ser Igual 0"); |
|
| 98 | } |
|
| 99 | if ($this->values->vl_icms != 0) { |
|
| 100 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 101 | " O do campo ALIQ_ICMS deve ser Igual 0"); |
|
| 102 | } |
|
| 103 | } elseif (!in_array($cstIcmsLast, [51, 90])) { |
|
| 104 | if ($this->values->vl_bc_icms <= 0) { |
|
| 105 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 106 | " O do campo VL_BC_ICMS deve ser maior do que 0"); |
|
| 107 | } |
|
| 108 | if ($this->values->aliq_icms <= 0) { |
|
| 109 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 110 | " O do campo ALIQ_ICMS deve ser maior do que 0"); |
|
| 111 | } |
|
| 112 | if ($this->values->vl_icms <= 0) { |
|
| 113 | throw new \InvalidArgumentException("[" . self::REG . "] " . |
|
| 114 | " O do campo VL_ICMS deve ser maior do que 0"); |
|
| 115 | } |
|
| 116 | } |
|
| 117 | } |
|
| 118 | } |
|
| 119 | ||