|
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\ICMS; |
|
29
|
|
|
|
|
30
|
|
|
use NFe\Common\Util; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Tributção pelo ICMS |
|
34
|
|
|
* 20 - Com redução de base de cálculo, estende de |
|
35
|
|
|
* Normal |
|
36
|
|
|
*/ |
|
37
|
|
|
class Reducao extends Normal |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
private $reducao; |
|
41
|
|
|
|
|
42
|
38 |
|
public function __construct($reducao = array()) |
|
43
|
|
|
{ |
|
44
|
38 |
|
parent::__construct($reducao); |
|
45
|
38 |
|
$this->setTributacao('20'); |
|
46
|
38 |
|
} |
|
47
|
|
|
|
|
48
|
17 |
|
public function getReducao($normalize = false) |
|
49
|
|
|
{ |
|
50
|
17 |
|
if (!$normalize) { |
|
51
|
11 |
|
return $this->reducao; |
|
52
|
|
|
} |
|
53
|
16 |
|
return Util::toFloat($this->reducao); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
38 |
|
public function setReducao($reducao) |
|
57
|
|
|
{ |
|
58
|
38 |
|
if (trim($reducao) != '') { |
|
59
|
15 |
|
$reducao = floatval($reducao); |
|
60
|
15 |
|
} |
|
61
|
38 |
|
$this->reducao = $reducao; |
|
62
|
38 |
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Calcula o valor do reduzido da base de cálculo |
|
67
|
|
|
*/ |
|
68
|
5 |
|
public function getReduzido($normalize = false) |
|
69
|
|
|
{ |
|
70
|
5 |
|
if ($normalize) { |
|
71
|
|
|
return Util::toCurrency($this->getReduzido()); |
|
72
|
|
|
} |
|
73
|
5 |
|
return ($this->getBase() * (100.0 - $this->getReducao())) / 100.0; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
4 |
|
public function toArray() |
|
77
|
|
|
{ |
|
78
|
4 |
|
$reducao = parent::toArray(); |
|
79
|
4 |
|
$reducao['reducao'] = $this->getReducao(); |
|
80
|
4 |
|
return $reducao; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
38 |
|
public function fromArray($reducao = array()) |
|
84
|
|
|
{ |
|
85
|
38 |
|
if ($reducao instanceof Reducao) { |
|
86
|
1 |
|
$reducao = $reducao->toArray(); |
|
87
|
38 |
|
} elseif (!is_array($reducao)) { |
|
88
|
1 |
|
return $this; |
|
89
|
|
|
} |
|
90
|
38 |
|
parent::fromArray($reducao); |
|
91
|
38 |
|
if (isset($reducao['reducao'])) { |
|
92
|
2 |
|
$this->setReducao($reducao['reducao']); |
|
93
|
2 |
|
} else { |
|
94
|
38 |
|
$this->setReducao(null); |
|
95
|
|
|
} |
|
96
|
38 |
|
return $this; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
16 |
|
public function getNode($name = null) |
|
100
|
|
|
{ |
|
101
|
16 |
|
$element = parent::getNode(is_null($name)?'ICMS20':$name); |
|
102
|
16 |
|
$dom = $element->ownerDocument; |
|
|
|
|
|
|
103
|
16 |
|
Util::appendNode($element, 'pRedBC', $this->getReducao(true)); |
|
104
|
16 |
|
return $element; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
7 |
|
public function loadNode($element, $name = null) |
|
108
|
|
|
{ |
|
109
|
7 |
|
$name = is_null($name)?'ICMS20':$name; |
|
110
|
7 |
|
$element = parent::loadNode($element, $name); |
|
111
|
7 |
|
$this->setReducao( |
|
112
|
7 |
|
Util::loadNode( |
|
113
|
7 |
|
$element, |
|
114
|
7 |
|
'pRedBC', |
|
115
|
|
|
'Tag "pRedBC" do campo "Reducao" não encontrada na Reducao' |
|
116
|
7 |
|
) |
|
117
|
7 |
|
); |
|
118
|
7 |
|
return $element; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.