Passed
Push — master ( c1d1cf...f48ccd )
by Francimar
03:58
created

Parcial::getModalidade()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 9.372

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 13
cts 18
cp 0.7221
rs 7.1428
c 0
b 0
f 0
cc 8
eloc 17
nc 8
nop 1
crap 9.372
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
 * Tributação pelo ICMS
34
 * 30 - Isenta ou não tributada e com cobrança do ICMS
35
 * por substituição tributária, estende de Base
36
 */
37
class Parcial extends Base
38
{
39
40
    /**
41
     * Modalidade de determinação da BC do ICMS ST:
42
     * 0 – Preço tabelado ou
43
     * máximo  sugerido;
44
     * 1 - Lista Negativa (valor);
45
     * 2 - Lista Positiva
46
     * (valor);
47
     * 3 - Lista Neutra (valor);
48
     * 4 - Margem Valor Agregado (%);
49
     * 5 -
50
     * Pauta (valor).
51
     */
52
    const MODALIDADE_TABELADO = 'tabelado';
53
    const MODALIDADE_NEGATIVO = 'negativo';
54
    const MODALIDADE_POSITIVO = 'positivo';
55
    const MODALIDADE_NEUTRO = 'neutro';
56
    const MODALIDADE_AGREGADO = 'agregado';
57
    const MODALIDADE_PAUTA = 'pauta';
58
59
    private $modalidade;
60
    private $margem;
61
    private $reducao;
62
63 64
    public function __construct($parcial = array())
64
    {
65 64
        parent::__construct($parcial);
66 64
        $this->setTributacao('30');
67 64
    }
68
69
    /**
70
     * Modalidade de determinação da BC do ICMS ST:
71
     * 0 – Preço tabelado ou
72
     * máximo  sugerido;
73
     * 1 - Lista Negativa (valor);
74
     * 2 - Lista Positiva
75
     * (valor);
76
     * 3 - Lista Neutra (valor);
77
     * 4 - Margem Valor Agregado (%);
78
     * 5 -
79
     * Pauta (valor).
80
     */
81 63
    public function getModalidade($normalize = false)
82
    {
83 63
        if (!$normalize) {
84 61
            return $this->modalidade;
85
        }
86 16
        switch ($this->modalidade) {
87 16
            case self::MODALIDADE_TABELADO:
88
                return '0';
89 16
            case self::MODALIDADE_NEGATIVO:
90
                return '1';
91 16
            case self::MODALIDADE_POSITIVO:
92
                return '2';
93 16
            case self::MODALIDADE_NEUTRO:
94
                return '3';
95 16
            case self::MODALIDADE_AGREGADO:
96 8
                return '4';
97 8
            case self::MODALIDADE_PAUTA:
98
                return '5';
99 8
        }
100 8
        return $this->modalidade;
101
    }
102
103 64
    public function setModalidade($modalidade)
104
    {
105 64
        $this->modalidade = $modalidade;
106 64
        return $this;
107
    }
108
109 30
    public function getMargem($normalize = false)
110
    {
111 30
        if (!$normalize) {
112 22
            return $this->margem;
113
        }
114 16
        return Util::toFloat($this->margem);
115
    }
116
117 64
    public function setMargem($margem)
118
    {
119 64
        $this->margem = $margem;
120 64
        return $this;
121
    }
122
123 30
    public function getReducao($normalize = false)
124
    {
125 30
        if (!$normalize) {
126 23
            return $this->reducao;
127
        }
128 16
        return Util::toFloat($this->reducao);
129
    }
130
131 64
    public function setReducao($reducao)
132
    {
133 64
        $this->reducao = $reducao;
134 64
        return $this;
135
    }
136
137 22
    public function toArray($recursive = false)
138
    {
139 22
        $parcial = parent::toArray($recursive);
140 22
        $parcial['modalidade'] = $this->getModalidade();
141 22
        $parcial['margem'] = $this->getMargem();
142 22
        $parcial['reducao'] = $this->getReducao();
143 22
        return $parcial;
144
    }
145
146 64
    public function fromArray($parcial = array())
147
    {
148 64
        if ($parcial instanceof Parcial) {
149 1
            $parcial = $parcial->toArray();
150 64
        } elseif (!is_array($parcial)) {
151 1
            return $this;
152
        }
153 64
        parent::fromArray($parcial);
154 64
        if (isset($parcial['modalidade'])) {
155 8
            $this->setModalidade($parcial['modalidade']);
156 8
        } else {
157 64
            $this->setModalidade(null);
158
        }
159 64
        if (isset($parcial['margem'])) {
160 8
            $this->setMargem($parcial['margem']);
161 8
        } else {
162 64
            $this->setMargem(null);
163
        }
164 64
        if (isset($parcial['reducao'])) {
165 8
            $this->setReducao($parcial['reducao']);
166 8
        } else {
167 64
            $this->setReducao(null);
168
        }
169 64
        return $this;
170
    }
171
172 12
    public function getNode($name = null)
173
    {
174 12
        $dom = new \DOMDocument('1.0', 'UTF-8');
175 12
        $element = $dom->createElement(is_null($name)?'IMCS30':$name);
176 12
        Util::appendNode($element, 'orig', $this->getOrigem(true));
177 12
        Util::appendNode($element, 'CST', $this->getTributacao(true));
178 12
        Util::appendNode($element, 'modBCST', $this->getModalidade(true));
179 12
        Util::appendNode($element, 'pMVAST', $this->getMargem(true));
180 12
        Util::appendNode($element, 'pRedBCST', $this->getReducao(true));
181 12
        Util::appendNode($element, 'vBCST', $this->getBase(true));
182 12
        Util::appendNode($element, 'pICMSST', $this->getAliquota(true));
183 12
        Util::appendNode($element, 'vICMSST', $this->getValor(true));
184 12
        return $element;
185
    }
186
187 6
    public function loadNode($element, $name = null)
188
    {
189 6
        $name = is_null($name)?'IMCS30':$name;
190 6
        if ($element->nodeName != $name) {
191
            $_fields = $element->getElementsByTagName($name);
192
            if ($_fields->length == 0) {
193
                throw new \Exception('Tag "'.$name.'" do ICMS Parcial não encontrada', 404);
194
            }
195
            $element = $_fields->item(0);
196
        }
197 6
        $this->setOrigem(
198 6
            Util::loadNode(
199 6
                $element,
200 6
                'orig',
201
                'Tag "orig" do campo "Origem" não encontrada no ICMS Parcial'
202 6
            )
203 6
        );
204 6
        $this->setTributacao(
205 6
            Util::loadNode(
206 6
                $element,
207 6
                'CST',
208
                'Tag "CST" do campo "Tributacao" não encontrada no ICMS Parcial'
209 6
            )
210 6
        );
211 6
        $this->setModalidade(
212 6
            Util::loadNode(
213 6
                $element,
214 6
                'modBCST',
215
                'Tag "modBCST" do campo "Modalidade" não encontrada no ICMS Parcial'
216 6
            )
217 6
        );
218 6
        $this->setMargem(
219 6
            Util::loadNode(
220 6
                $element,
221 6
                'pMVAST',
222
                'Tag "pMVAST" do campo "Margem" não encontrada no ICMS Parcial'
223 6
            )
224 6
        );
225 6
        $this->setReducao(
226 6
            Util::loadNode(
227 6
                $element,
228 6
                'pRedBCST',
229
                'Tag "pRedBCST" do campo "Reducao" não encontrada no ICMS Parcial'
230 6
            )
231 6
        );
232 6
        $this->setBase(
233 6
            Util::loadNode(
234 6
                $element,
235 6
                'vBCST',
236
                'Tag "vBCST" do campo "Base" não encontrada no ICMS Parcial'
237 6
            )
238 6
        );
239 6
        $this->setAliquota(
240 6
            Util::loadNode(
241 6
                $element,
242 6
                'pICMSST',
243
                'Tag "pICMSST" do campo "Aliquota" não encontrada no ICMS Parcial'
244 6
            )
245 6
        );
246 6
        return $element;
247
    }
248
}
249