1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MIT License |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 MZ Desenvolvimento de Sistemas LTDA |
6
|
|
|
* |
7
|
|
|
* @author Francimar Alves <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
11
|
|
|
* in the Software without restriction, including without limitation the rights |
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
14
|
|
|
* furnished to do so, subject to the following conditions: |
15
|
|
|
* |
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
17
|
|
|
* copies or substantial portions of the Software. |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
25
|
|
|
* SOFTWARE. |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
namespace NFe\Entity\Imposto\Fundo; |
29
|
|
|
|
30
|
|
|
use NFe\Common\Util; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Valor e Percentual do imposto para o Fundo de Combate à Pobreza retido |
34
|
|
|
* anteriormente por substituição tributária |
35
|
|
|
*/ |
36
|
|
|
class Retido extends Substituido |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Constroi uma instância de Retido vazia |
42
|
|
|
* @param array $retido Array contendo dados do Retido |
43
|
|
|
*/ |
44
|
42 |
|
public function __construct($retido = []) |
45
|
|
|
{ |
46
|
42 |
|
parent::__construct($retido); |
47
|
42 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Converte a instância da classe para um array de campos com valores |
51
|
|
|
* @return array Array contendo todos os campos e valores da instância |
52
|
|
|
*/ |
53
|
1 |
|
public function toArray($recursive = false) |
54
|
|
|
{ |
55
|
1 |
|
$retido = parent::toArray($recursive); |
56
|
1 |
|
return $retido; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Atribui os valores do array para a instância atual |
61
|
|
|
* @param mixed $retido Array ou instância de Retido, para copiar os valores |
62
|
|
|
* @return Retido A própria instância da classe |
63
|
|
|
*/ |
64
|
42 |
|
public function fromArray($retido = []) |
65
|
|
|
{ |
66
|
42 |
|
if ($retido instanceof Retido) { |
67
|
|
|
$retido = $retido->toArray(); |
68
|
42 |
|
} elseif (!is_array($retido)) { |
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
42 |
|
parent::fromArray($retido); |
72
|
42 |
|
$this->setGrupo(self::GRUPO_FCPSTRET); |
73
|
42 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Verifica se o elemento informado contém os dados dessa instância |
78
|
|
|
* @param DOMElement $element Nó que pode contér os dados dessa instância |
79
|
|
|
* @return boolean True se contém os dados dessa instância ou false caso contrário |
80
|
|
|
*/ |
81
|
29 |
|
public function exists($element) |
82
|
|
|
{ |
83
|
|
|
// se o primeiro campo obrigatório existir, significa que deve ter os outros campos |
84
|
29 |
|
return Util::nodeExists( |
85
|
29 |
|
$element, |
86
|
29 |
|
'vBCFCPSTRet' |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Cria um nó XML do retido de acordo com o leiaute da NFe |
92
|
|
|
* @param string $name Nome do nó que será criado |
93
|
|
|
* @return DOMElement Nó que contém todos os campos da classe |
94
|
|
|
*/ |
95
|
2 |
|
public function getNode($name = null) |
96
|
|
|
{ |
97
|
2 |
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
98
|
2 |
|
$element = $dom->createElement(is_null($name)?'FCPSTRet':$name); |
99
|
2 |
|
Util::appendNode($element, 'vBCFCPSTRet', $this->getBase(true)); |
100
|
2 |
|
Util::appendNode($element, 'pFCPSTRet', $this->getAliquota(true)); |
101
|
2 |
|
Util::appendNode($element, 'vFCPSTRet', $this->getValor(true)); |
102
|
2 |
|
return $element; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Carrega as informações do nó e preenche a instância da classe |
107
|
|
|
* @param DOMElement $element Nó do xml com todos as tags dos campos |
108
|
|
|
* @param string $name Nome do nó que será carregado |
109
|
|
|
* @return DOMElement Instância do nó que foi carregado |
110
|
|
|
*/ |
111
|
1 |
|
public function loadNode($element, $name = null) |
112
|
|
|
{ |
113
|
1 |
|
$name = is_null($name)?'FCPSTRet':$name; |
114
|
1 |
|
if ($element->nodeName != $name) { |
115
|
|
|
$_fields = $element->getElementsByTagName($name); |
116
|
|
|
if ($_fields->length == 0) { |
117
|
|
|
throw new \Exception('Tag "'.$name.'" não encontrada', 404); |
118
|
|
|
} |
119
|
|
|
$element = $_fields->item(0); |
120
|
|
|
} |
121
|
1 |
|
$this->setBase( |
122
|
1 |
|
Util::loadNode( |
123
|
1 |
|
$element, |
124
|
1 |
|
'vBCFCPSTRet', |
125
|
1 |
|
'Tag "vBCFCPSTRet" do campo "Base" não encontrada' |
126
|
|
|
) |
127
|
|
|
); |
128
|
1 |
|
$this->setAliquota( |
129
|
1 |
|
Util::loadNode( |
130
|
1 |
|
$element, |
131
|
1 |
|
'pFCPSTRet', |
132
|
1 |
|
'Tag "pFCPST" do campo "Aliquota" não encontrada' |
133
|
|
|
) |
134
|
|
|
); |
135
|
1 |
|
return $element; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|