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\Transporte; |
29
|
|
|
|
30
|
|
|
use NFe\Common\Util; |
31
|
|
|
use NFe\Entity\Imposto; |
32
|
|
|
use NFe\Entity\Municipio; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* ICMS retido do Transportador |
36
|
|
|
*/ |
37
|
|
|
class Tributo extends Imposto |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
private $servico; |
41
|
|
|
private $cfop; |
42
|
|
|
private $municipio; |
43
|
|
|
|
44
|
49 |
|
public function __construct($tributo = []) |
45
|
|
|
{ |
46
|
49 |
|
parent::__construct($tributo); |
47
|
49 |
|
} |
48
|
|
|
|
49
|
15 |
|
public function getServico($normalize = false) |
50
|
|
|
{ |
51
|
15 |
|
if (!$normalize) { |
52
|
11 |
|
return $this->servico; |
53
|
|
|
} |
54
|
8 |
|
return Util::toCurrency($this->servico); |
55
|
|
|
} |
56
|
|
|
|
57
|
49 |
|
public function setServico($servico) |
58
|
|
|
{ |
59
|
49 |
|
$this->servico = $servico; |
60
|
49 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
15 |
|
public function getCFOP($normalize = false) |
64
|
|
|
{ |
65
|
15 |
|
if (!$normalize) { |
66
|
11 |
|
return $this->cfop; |
67
|
|
|
} |
68
|
8 |
|
return $this->cfop; |
69
|
|
|
} |
70
|
|
|
|
71
|
49 |
|
public function setCFOP($cfop) |
72
|
|
|
{ |
73
|
49 |
|
$this->cfop = $cfop; |
74
|
49 |
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
15 |
|
public function getMunicipio() |
78
|
|
|
{ |
79
|
15 |
|
return $this->municipio; |
80
|
|
|
} |
81
|
|
|
|
82
|
49 |
|
public function setMunicipio($municipio) |
83
|
|
|
{ |
84
|
49 |
|
$this->municipio = $municipio; |
85
|
49 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
11 |
|
public function toArray($recursive = false) |
89
|
|
|
{ |
90
|
11 |
|
$tributo = parent::toArray($recursive); |
91
|
11 |
|
$tributo['servico'] = $this->getServico(); |
92
|
11 |
|
$tributo['cfop'] = $this->getCFOP(); |
93
|
11 |
|
if (!is_null($this->getMunicipio()) && $recursive) { |
94
|
1 |
|
$tributo['municipio'] = $this->getMunicipio()->toArray($recursive); |
95
|
|
|
} else { |
96
|
10 |
|
$tributo['municipio'] = $this->getMunicipio(); |
97
|
|
|
} |
98
|
11 |
|
return $tributo; |
99
|
|
|
} |
100
|
|
|
|
101
|
49 |
|
public function fromArray($tributo = []) |
102
|
|
|
{ |
103
|
49 |
|
if ($tributo instanceof Tributo) { |
104
|
10 |
|
$tributo = $tributo->toArray(); |
105
|
49 |
|
} elseif (!is_array($tributo)) { |
106
|
1 |
|
return $this; |
107
|
|
|
} |
108
|
49 |
|
parent::fromArray($tributo); |
109
|
49 |
|
if (isset($tributo['servico'])) { |
110
|
4 |
|
$this->setServico($tributo['servico']); |
111
|
|
|
} else { |
112
|
49 |
|
$this->setServico(null); |
113
|
|
|
} |
114
|
49 |
|
if (isset($tributo['cfop'])) { |
115
|
4 |
|
$this->setCFOP($tributo['cfop']); |
116
|
|
|
} else { |
117
|
49 |
|
$this->setCFOP(null); |
118
|
|
|
} |
119
|
49 |
|
$this->setMunicipio(new Municipio(isset($tributo['municipio']) ? $tributo['municipio'] : [])); |
120
|
49 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
8 |
|
public function getNode($name = null) |
124
|
|
|
{ |
125
|
8 |
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
126
|
8 |
|
$element = $dom->createElement(is_null($name)?'retTransp':$name); |
127
|
8 |
|
Util::appendNode($element, 'vServ', $this->getServico(true)); |
128
|
8 |
|
Util::appendNode($element, 'vBCRet', $this->getBase(true)); |
129
|
8 |
|
Util::appendNode($element, 'pICMSRet', $this->getAliquota(true)); |
130
|
8 |
|
Util::appendNode($element, 'vICMSRet', $this->getValor(true)); |
131
|
8 |
|
Util::appendNode($element, 'CFOP', $this->getCFOP(true)); |
132
|
8 |
|
if (is_null($this->getMunicipio())) { |
133
|
|
|
return $element; |
134
|
|
|
} |
135
|
8 |
|
$municipio = $this->getMunicipio(); |
136
|
8 |
|
$municipio->checkCodigos(); |
137
|
8 |
|
Util::appendNode($element, 'cMunFG', $municipio->getCodigo(true)); |
138
|
8 |
|
return $element; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
4 |
|
public function loadNode($element, $name = null) |
143
|
|
|
{ |
144
|
4 |
|
$name = is_null($name)?'retTransp':$name; |
145
|
4 |
|
if ($element->nodeName != $name) { |
146
|
|
|
$_fields = $element->getElementsByTagName($name); |
147
|
|
|
if ($_fields->length == 0) { |
148
|
|
|
throw new \Exception('Tag "'.$name.'" do Tributo não encontrada', 404); |
149
|
|
|
} |
150
|
|
|
$element = $_fields->item(0); |
151
|
|
|
} |
152
|
4 |
|
$this->setServico( |
153
|
4 |
|
Util::loadNode( |
154
|
4 |
|
$element, |
155
|
4 |
|
'vServ', |
156
|
4 |
|
'Tag "vServ" do campo "Servico" não encontrada no Tributo' |
157
|
|
|
) |
158
|
|
|
); |
159
|
4 |
|
$this->setBase( |
160
|
4 |
|
Util::loadNode( |
161
|
4 |
|
$element, |
162
|
4 |
|
'vBCRet', |
163
|
4 |
|
'Tag "vBCRet" do campo "Base" não encontrada no Tributo' |
164
|
|
|
) |
165
|
|
|
); |
166
|
4 |
|
$this->setAliquota( |
167
|
4 |
|
Util::loadNode( |
168
|
4 |
|
$element, |
169
|
4 |
|
'pICMSRet', |
170
|
4 |
|
'Tag "pICMSRet" do campo "Aliquota" não encontrada no Tributo' |
171
|
|
|
) |
172
|
|
|
); |
173
|
4 |
|
$this->setCFOP( |
174
|
4 |
|
Util::loadNode( |
175
|
4 |
|
$element, |
176
|
4 |
|
'CFOP', |
177
|
4 |
|
'Tag "CFOP" do campo "CFOP" não encontrada no Tributo' |
178
|
|
|
) |
179
|
|
|
); |
180
|
4 |
|
$municipio = null; |
181
|
4 |
|
$codigo = Util::loadNode($element, 'cMunFG'); |
182
|
4 |
|
if (!is_null($codigo)) { |
183
|
4 |
|
$municipio = new Municipio(); |
184
|
4 |
|
$municipio->setCodigo($codigo); |
185
|
|
|
} |
186
|
4 |
|
$this->setMunicipio($municipio); |
187
|
4 |
|
return $element; |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|