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; |
29
|
|
|
|
30
|
|
|
use NFe\Common\Util; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Empresa que irá emitir as notas fiscais |
34
|
|
|
*/ |
35
|
|
|
class Emitente extends Pessoa |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Código de Regime Tributário. Este campo será obrigatoriamente preenchido |
40
|
|
|
* com: 1 – Simples Nacional; 2 – Simples Nacional – excesso de sublimite |
41
|
|
|
* de receita bruta; 3 – Regime Normal. |
42
|
|
|
*/ |
43
|
|
|
const REGIME_SIMPLES = 'simples'; |
44
|
|
|
const REGIME_EXCESSO = 'excesso'; |
45
|
|
|
const REGIME_NORMAL = 'normal'; |
46
|
|
|
|
47
|
|
|
private $fantasia; |
48
|
|
|
private $regime; |
49
|
|
|
|
50
|
15 |
|
public function __construct($emitente = array()) |
51
|
|
|
{ |
52
|
15 |
|
parent::__construct($emitente); |
53
|
15 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Nome fantasia do da empresa emitente |
57
|
|
|
*/ |
58
|
7 |
|
public function getFantasia($normalize = false) |
59
|
|
|
{ |
60
|
7 |
|
if (!$normalize) { |
61
|
7 |
|
return $this->fantasia; |
62
|
|
|
} |
63
|
7 |
|
return $this->fantasia; |
64
|
|
|
} |
65
|
|
|
|
66
|
15 |
|
public function setFantasia($fantasia) |
67
|
|
|
{ |
68
|
15 |
|
$this->fantasia = $fantasia; |
69
|
15 |
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Código de Regime Tributário. Este campo será obrigatoriamente preenchido |
74
|
|
|
* com: 1 – Simples Nacional; 2 – Simples Nacional – excesso de sublimite |
75
|
|
|
* de receita bruta; 3 – Regime Normal. |
76
|
|
|
*/ |
77
|
7 |
|
public function getRegime($normalize = false) |
78
|
|
|
{ |
79
|
7 |
|
if (!$normalize) { |
80
|
3 |
|
return $this->regime; |
81
|
|
|
} |
82
|
7 |
|
switch ($this->regime) { |
83
|
7 |
|
case self::REGIME_SIMPLES: |
84
|
3 |
|
return '1'; |
85
|
4 |
|
case self::REGIME_EXCESSO: |
86
|
|
|
return '2'; |
87
|
4 |
|
case self::REGIME_NORMAL: |
88
|
|
|
return '3'; |
89
|
4 |
|
} |
90
|
4 |
|
return $this->regime; |
91
|
|
|
} |
92
|
|
|
|
93
|
15 |
|
public function setRegime($regime) |
94
|
|
|
{ |
95
|
15 |
|
$this->regime = $regime; |
96
|
15 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
3 |
|
public function toArray() |
100
|
|
|
{ |
101
|
3 |
|
$emitente = parent::toArray(); |
102
|
3 |
|
$emitente['fantasia'] = $this->getFantasia(); |
103
|
3 |
|
$emitente['regime'] = $this->getRegime(); |
104
|
3 |
|
return $emitente; |
105
|
|
|
} |
106
|
|
|
|
107
|
15 |
|
public function fromArray($emitente = array()) |
108
|
|
|
{ |
109
|
15 |
|
if ($emitente instanceof Emitente) { |
110
|
3 |
|
$emitente = $emitente->toArray(); |
111
|
15 |
|
} elseif (!is_array($emitente)) { |
112
|
3 |
|
return $this; |
113
|
|
|
} |
114
|
15 |
|
parent::fromArray($emitente); |
115
|
15 |
|
if (is_null($this->getEndereco())) { |
116
|
|
|
$this->setEndereco(new Endereco()); |
117
|
|
|
} |
118
|
15 |
|
if (isset($emitente['fantasia'])) { |
119
|
3 |
|
$this->setFantasia($emitente['fantasia']); |
120
|
3 |
|
} else { |
121
|
15 |
|
$this->setFantasia(null); |
122
|
|
|
} |
123
|
15 |
|
if (!isset($emitente['regime']) || is_null($emitente['regime'])) { |
124
|
15 |
|
$this->setRegime(self::REGIME_SIMPLES); |
125
|
15 |
|
} else { |
126
|
3 |
|
$this->setRegime($emitente['regime']); |
127
|
|
|
} |
128
|
15 |
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
7 |
|
public function getNode($name = null) |
132
|
|
|
{ |
133
|
7 |
|
$dom = new \DOMDocument('1.0', 'UTF-8'); |
134
|
7 |
|
$element = $dom->createElement(is_null($name)?'emit':$name); |
135
|
7 |
|
Util::appendNode($element, 'CNPJ', $this->getCNPJ(true)); |
136
|
7 |
|
Util::appendNode($element, 'xNome', $this->getRazaoSocial(true)); |
137
|
7 |
|
if (!is_null($this->getFantasia())) { |
138
|
7 |
|
Util::appendNode($element, 'xFant', $this->getFantasia(true)); |
139
|
7 |
|
} |
140
|
7 |
|
$endereco = $this->getEndereco()->getNode('enderEmit'); |
141
|
7 |
|
$endereco = $dom->importNode($endereco, true); |
142
|
7 |
|
if (!is_null($this->getTelefone())) { |
143
|
7 |
|
Util::appendNode($endereco, 'fone', $this->getTelefone(true)); |
144
|
7 |
|
} |
145
|
7 |
|
$element->appendChild($endereco); |
146
|
7 |
|
Util::appendNode($element, 'IE', $this->getIE(true)); |
147
|
7 |
|
if (!is_null($this->getIM())) { |
148
|
7 |
|
Util::appendNode($element, 'IM', $this->getIM(true)); |
149
|
7 |
|
} |
150
|
7 |
|
Util::appendNode($element, 'CRT', $this->getRegime(true)); |
151
|
7 |
|
return $element; |
152
|
|
|
} |
153
|
|
|
|
154
|
4 |
|
public function loadNode($element, $name = null) |
155
|
|
|
{ |
156
|
4 |
|
$name = is_null($name)?'emit':$name; |
157
|
4 |
|
$element = parent::loadNode($element, $name); |
158
|
4 |
|
$this->setFantasia(Util::loadNode($element, 'xFant')); |
159
|
4 |
|
$this->setRegime( |
160
|
4 |
|
Util::loadNode( |
161
|
4 |
|
$element, |
162
|
4 |
|
'CRT', |
163
|
|
|
'Tag "CRT" do campo "Regime" não encontrada' |
164
|
4 |
|
) |
165
|
4 |
|
); |
166
|
4 |
|
return $element; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|