|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Author Newton Pasqualini Filho (newtonpasqualini at gmail dot com) |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace NFePHP\DA\NFe; |
|
6
|
|
|
|
|
7
|
|
|
use NFePHP\DA\Legacy\Dom; |
|
8
|
|
|
use NFePHP\DA\Legacy\Pdf; |
|
9
|
|
|
use \NFePHP\DA\Common\DaCommon; |
|
10
|
|
|
|
|
11
|
|
|
class DanfeSimples extends DaCommon |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Tamanho do Papel |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
public $papel = 'A5'; |
|
20
|
|
|
/** |
|
21
|
|
|
* XML NFe |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $xml; |
|
26
|
|
|
/** |
|
27
|
|
|
* mesagens de erro |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $errMsg = ''; |
|
32
|
|
|
/** |
|
33
|
|
|
* status de erro true um erro ocorreu false sem erros |
|
34
|
|
|
* |
|
35
|
|
|
* @var boolean |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $errStatus = false; |
|
38
|
|
|
/** |
|
39
|
|
|
* Dom Document |
|
40
|
|
|
* |
|
41
|
|
|
* @var \NFePHP\DA\Legacy\Dom |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $dom; |
|
44
|
|
|
/** |
|
45
|
|
|
* Node |
|
46
|
|
|
* |
|
47
|
|
|
* @var \DOMNode |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $infNFe; |
|
50
|
|
|
/** |
|
51
|
|
|
* Node |
|
52
|
|
|
* |
|
53
|
|
|
* @var \DOMNode |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $ide; |
|
56
|
|
|
/** |
|
57
|
|
|
* Node |
|
58
|
|
|
* |
|
59
|
|
|
* @var \DOMNode |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $entrega; |
|
62
|
|
|
/** |
|
63
|
|
|
* Node |
|
64
|
|
|
* |
|
65
|
|
|
* @var \DOMNode |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $retirada; |
|
68
|
|
|
/** |
|
69
|
|
|
* Node |
|
70
|
|
|
* |
|
71
|
|
|
* @var \DOMNode |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $emit; |
|
74
|
|
|
/** |
|
75
|
|
|
* Node |
|
76
|
|
|
* |
|
77
|
|
|
* @var \DOMNode |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $dest; |
|
80
|
|
|
/** |
|
81
|
|
|
* Node |
|
82
|
|
|
* |
|
83
|
|
|
* @var \DOMNode |
|
84
|
|
|
*/ |
|
85
|
|
|
protected $enderEmit; |
|
86
|
|
|
/** |
|
87
|
|
|
* Node |
|
88
|
|
|
* |
|
89
|
|
|
* @var \DOMNode |
|
90
|
|
|
*/ |
|
91
|
|
|
protected $enderDest; |
|
92
|
|
|
/** |
|
93
|
|
|
* Node |
|
94
|
|
|
* |
|
95
|
|
|
* @var \DOMNode |
|
96
|
|
|
*/ |
|
97
|
|
|
protected $det; |
|
98
|
|
|
/** |
|
99
|
|
|
* Node |
|
100
|
|
|
* |
|
101
|
|
|
* @var \DOMNode |
|
102
|
|
|
*/ |
|
103
|
|
|
protected $cobr; |
|
104
|
|
|
/** |
|
105
|
|
|
* Node |
|
106
|
|
|
* |
|
107
|
|
|
* @var \DOMNode |
|
108
|
|
|
*/ |
|
109
|
|
|
protected $dup; |
|
110
|
|
|
/** |
|
111
|
|
|
* Node |
|
112
|
|
|
* |
|
113
|
|
|
* @var \DOMNode |
|
114
|
|
|
*/ |
|
115
|
|
|
protected $ICMSTot; |
|
116
|
|
|
/** |
|
117
|
|
|
* Node |
|
118
|
|
|
* |
|
119
|
|
|
* @var \DOMNode |
|
120
|
|
|
*/ |
|
121
|
|
|
protected $ISSQNtot; |
|
122
|
|
|
/** |
|
123
|
|
|
* Node |
|
124
|
|
|
* |
|
125
|
|
|
* @var \DOMNode |
|
126
|
|
|
*/ |
|
127
|
|
|
protected $transp; |
|
128
|
|
|
/** |
|
129
|
|
|
* Node |
|
130
|
|
|
* |
|
131
|
|
|
* @var \DOMNode |
|
132
|
|
|
*/ |
|
133
|
|
|
protected $transporta; |
|
134
|
|
|
/** |
|
135
|
|
|
* Node |
|
136
|
|
|
* |
|
137
|
|
|
* @var \DOMNode |
|
138
|
|
|
*/ |
|
139
|
|
|
protected $veicTransp; |
|
140
|
|
|
/** |
|
141
|
|
|
* Node reboque |
|
142
|
|
|
* |
|
143
|
|
|
* @var \DOMNode |
|
144
|
|
|
*/ |
|
145
|
|
|
protected $reboque; |
|
146
|
|
|
/** |
|
147
|
|
|
* Node infAdic |
|
148
|
|
|
* |
|
149
|
|
|
* @var \DOMNode |
|
150
|
|
|
*/ |
|
151
|
|
|
protected $infAdic; |
|
152
|
|
|
/** |
|
153
|
|
|
* Tipo de emissão |
|
154
|
|
|
* |
|
155
|
|
|
* @var integer |
|
156
|
|
|
*/ |
|
157
|
|
|
protected $tpEmis; |
|
158
|
|
|
/** |
|
159
|
|
|
* Node infProt |
|
160
|
|
|
* |
|
161
|
|
|
* @var \DOMNode |
|
162
|
|
|
*/ |
|
163
|
|
|
protected $infProt; |
|
164
|
|
|
/** |
|
165
|
|
|
* 1-Retrato/ 2-Paisagem |
|
166
|
|
|
* |
|
167
|
|
|
* @var integer |
|
168
|
|
|
*/ |
|
169
|
|
|
protected $tpImp; |
|
170
|
|
|
/** |
|
171
|
|
|
* Node compra |
|
172
|
|
|
* |
|
173
|
|
|
* @var \DOMNode |
|
174
|
|
|
*/ |
|
175
|
|
|
protected $compra; |
|
176
|
|
|
|
|
177
|
|
|
/* |
|
178
|
|
|
* Guarda a estrutura da NF como Array para |
|
179
|
|
|
* interagir de maneira nativa com os dados |
|
180
|
|
|
* do XML da NFe |
|
181
|
|
|
*/ |
|
182
|
|
|
protected $nfeArray = []; |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* __construct |
|
186
|
|
|
* |
|
187
|
|
|
* @name __construct |
|
188
|
|
|
* |
|
189
|
|
|
* @param string $xml Conteúdo XML da NF-e (com ou sem a tag nfeProc) |
|
190
|
|
|
*/ |
|
191
|
|
|
public function __construct($xml, $orientacao = 'P') |
|
192
|
|
|
{ |
|
193
|
|
|
$this->loadDoc($xml); |
|
194
|
|
|
$this->orientacao = $orientacao; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
private function loadDoc($xml) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->xml = $xml; |
|
200
|
|
|
if (!empty($xml)) { |
|
201
|
|
|
$stdClass = simplexml_load_string($xml); |
|
202
|
|
|
$json = json_encode($stdClass, JSON_OBJECT_AS_ARRAY); |
|
203
|
|
|
$this->nfeArray = json_decode($json, JSON_OBJECT_AS_ARRAY); |
|
204
|
|
|
if (!isset($this->nfeArray['NFe']['infNFe']['@attributes']['Id'])){ |
|
205
|
|
|
throw new Exception('XML não parece ser uma NF-e!'); |
|
206
|
|
|
} |
|
207
|
|
|
if ($this->nfeArray['protNFe']['infProt']['cStat'] != '100'){ |
|
208
|
|
|
throw new Exception('NF-e não autorizada!'); |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
protected function monta( |
|
214
|
|
|
$logo = '' |
|
215
|
|
|
) { |
|
216
|
|
|
$this->pdf = ''; |
|
|
|
|
|
|
217
|
|
|
$this->logomarca = $this->adjustImage($logo); |
|
218
|
|
|
//se a orientação estiver em branco utilizar o padrão estabelecido na NF |
|
219
|
|
|
if (empty($this->orientacao)) { |
|
220
|
|
|
$this->orientacao = 'L'; |
|
221
|
|
|
} |
|
222
|
|
|
$this->pdf = new Pdf($this->orientacao, 'mm', $this->papel); |
|
223
|
|
|
if ($this->orientacao == 'L') { |
|
224
|
|
|
if ($this->papel == 'A5') { |
|
225
|
|
|
$this->maxW = 210; |
|
|
|
|
|
|
226
|
|
|
$this->maxH = 148; |
|
|
|
|
|
|
227
|
|
|
} |
|
228
|
|
|
} else { |
|
229
|
|
|
if ($this->papel == 'A5') { |
|
230
|
|
|
$this->maxW = 148; |
|
|
|
|
|
|
231
|
|
|
$this->maxH = 210; |
|
|
|
|
|
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
// estabelece contagem de paginas |
|
235
|
|
|
$this->pdf->aliasNbPages(); |
|
236
|
|
|
// fixa as margens |
|
237
|
|
|
$this->pdf->setMargins($this->margesq, $this->margsup); |
|
238
|
|
|
$this->pdf->setDrawColor(0, 0, 0); |
|
239
|
|
|
$this->pdf->setFillColor(255, 255, 255); |
|
240
|
|
|
// inicia o documento |
|
241
|
|
|
$this->pdf->open(); |
|
242
|
|
|
// adiciona a primeira página |
|
243
|
|
|
$this->pdf->addPage($this->orientacao, $this->papel); |
|
244
|
|
|
$this->pdf->setLineWidth(0.1); |
|
245
|
|
|
$this->pdf->settextcolor(0, 0, 0); |
|
246
|
|
|
|
|
247
|
|
|
// LINHA 1 |
|
248
|
|
|
$this->pdf->setFont('Arial', 'B', 12); |
|
249
|
|
|
$this->pdf->cell(($this->maxW - ($this->margesq * 2)), 6, "DANFE SIMPLIFICADO - ETIQUETA", 1, 1, 'C', 1); |
|
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
// LINHA 2 |
|
252
|
|
|
$dataEmissao = date('d/m/Y', strtotime("{$this->nfeArray['NFe']['infNFe']['ide']['dhEmi']}")); |
|
253
|
|
|
$c1 = ($this->maxW - ($this->margesq * 2)) / 4; |
|
254
|
|
|
$this->pdf->setFont('Arial', 'B', 10); |
|
255
|
|
|
$this->pdf->cell($c1, 5, "TIPO NF", 1, 0, 'C', 1); |
|
|
|
|
|
|
256
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
257
|
|
|
$this->pdf->cell($c1, 5, "{$this->nfeArray['NFe']['infNFe']['ide']['tpNF']} - " . |
|
258
|
|
|
($this->nfeArray['NFe']['infNFe']['ide']['tpNF']==1 ? 'Saida':'Entrada'), |
|
259
|
|
|
1, 0, 'C', 1); |
|
|
|
|
|
|
260
|
|
|
$this->pdf->setFont('Arial', 'B', 10); |
|
261
|
|
|
$this->pdf->cell($c1, 5, "DATA EMISSAO", 1, 0, 'C', 1); |
|
|
|
|
|
|
262
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
263
|
|
|
$this->pdf->cell($c1, 5, "{$dataEmissao}", 1, 1, 'C', 1); |
|
|
|
|
|
|
264
|
|
|
|
|
265
|
|
|
// LINHA 3 |
|
266
|
|
|
$this->pdf->setFont('Arial', 'B', 10); |
|
267
|
|
|
$this->pdf->cell($c1, 5, "NUMERL", 1, 0, 'C', 1); |
|
|
|
|
|
|
268
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
269
|
|
|
$this->pdf->cell($c1, 5, "{$this->nfeArray['NFe']['infNFe']['ide']['nNF']}", 1, 0, 'C', 1); |
|
|
|
|
|
|
270
|
|
|
$this->pdf->setFont('Arial', 'B', 10); |
|
271
|
|
|
$this->pdf->cell($c1, 5, "SERIE", 1, 0, 'C', 1); |
|
|
|
|
|
|
272
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
273
|
|
|
$this->pdf->cell($c1, 5, "{$this->nfeArray['NFe']['infNFe']['ide']['serie']}", 1, 1, 'C', 1); |
|
|
|
|
|
|
274
|
|
|
|
|
275
|
|
|
// LINHA 4 |
|
276
|
|
|
$chave = substr($this->nfeArray['NFe']['infNFe']['@attributes']['Id'], 3); |
|
277
|
|
|
$this->pdf->setFont('Arial', 'B', 10); |
|
278
|
|
|
$this->pdf->cell($c1, 5, "CHAVE DE ACESSO", 1, 0, 'C', 1); |
|
|
|
|
|
|
279
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
280
|
|
|
$this->pdf->cell(($c1 * 3), 5, "{$chave}", 1, 1, 'C', 1); |
|
|
|
|
|
|
281
|
|
|
|
|
282
|
|
|
// LINHA 5 |
|
283
|
|
|
$this->pdf->setFont('Arial', 'B', 10); |
|
284
|
|
|
$this->pdf->cell($c1, 5, "PROTOCOLO", 1, 0, 'C', 1); |
|
|
|
|
|
|
285
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
286
|
|
|
$dataProto = date("d/m/Y H:i:s", strtotime($this->nfeArray['protNFe']['infProt']['dhRecbto'])); |
|
287
|
|
|
$this->pdf->cell(($c1 * 3), 5, "{$this->nfeArray['protNFe']['infProt']['nProt']} - {$dataProto}", 1, 1, 'C', 1); |
|
|
|
|
|
|
288
|
|
|
|
|
289
|
|
|
$this->pdf->ln(); |
|
290
|
|
|
$y = $this->pdf->getY(); |
|
291
|
|
|
$this->pdf->setFillColor(0, 0, 0); |
|
292
|
|
|
$this->pdf->code128(($c1/2), $y, $chave, ($c1 * 3), 15); |
|
293
|
|
|
$this->pdf->setFillColor(255, 255, 255); |
|
294
|
|
|
$this->pdf->ln(); |
|
295
|
|
|
$this->pdf->ln(); |
|
296
|
|
|
$this->pdf->ln(); |
|
297
|
|
|
$this->pdf->ln(); |
|
298
|
|
|
|
|
299
|
|
|
// LINHA 6 |
|
300
|
|
|
$this->pdf->setFont('Arial', 'B', 12); |
|
301
|
|
|
$this->pdf->cell(($c1 * 4), 6, "EMITENTE", 1, 1, 'C', 1); |
|
|
|
|
|
|
302
|
|
|
|
|
303
|
|
|
// LINHA 7 |
|
304
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
305
|
|
|
$this->pdf->cell(($c1 * 4), 5, "{$this->nfeArray['NFe']['infNFe']['emit']['xNome']}", 1, 1, 'C', 1); |
|
|
|
|
|
|
306
|
|
|
|
|
307
|
|
|
// LINHA 8 |
|
308
|
|
|
$cpfCnpj = (isset($this->nfeArray['NFe']['infNFe']['emit']['CNPJ']) ? $this->nfeArray['NFe']['infNFe']['emit']['CNPJ']:$this->nfeArray['NFe']['infNFe']['emit']['CPF']); |
|
309
|
|
|
$this->pdf->cell(($c1 * 2), 5, "CNPJ/CPF {$cpfCnpj}", 1, 0, 'C', 1); |
|
|
|
|
|
|
310
|
|
|
$this->pdf->cell(($c1 * 2), 5, @"RG/IE {$this->nfeArray['NFe']['infNFe']['emit']['IE']}", 1, 1, 'C', 1); |
|
|
|
|
|
|
311
|
|
|
|
|
312
|
|
|
// LINHA 9 |
|
313
|
|
|
$this->pdf->setFont('Arial', 'B', 12); |
|
314
|
|
|
$this->pdf->cell(($c1 * 4), 6, "DESTINATARIO", 1, 1, 'C', 1); |
|
|
|
|
|
|
315
|
|
|
|
|
316
|
|
|
// LINHA 10 |
|
317
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
318
|
|
|
$this->pdf->cell(($c1 * 4), 5, "{$this->nfeArray['NFe']['infNFe']['dest']['xNome']}", 1, 1, 'C', 1); |
|
|
|
|
|
|
319
|
|
|
|
|
320
|
|
|
// LINHA 11 |
|
321
|
|
|
$cpfCnpj = (isset($this->nfeArray['NFe']['infNFe']['dest']['CNPJ']) ? $this->nfeArray['NFe']['infNFe']['dest']['CNPJ']:$this->nfeArray['NFe']['infNFe']['dest']['CPF']); |
|
322
|
|
|
$this->pdf->cell(($c1 * 2), 5, "CNPJ/CPF {$cpfCnpj}", 1, 0, 'C', 1); |
|
|
|
|
|
|
323
|
|
|
$this->pdf->cell(($c1 * 2), 5, @"RG/IE {$this->nfeArray['NFe']['infNFe']['dest']['IE']}", 1, 1, 'C', 1); |
|
|
|
|
|
|
324
|
|
|
|
|
325
|
|
|
if (isset($this->nfeArray['NFe']['infNFe']['entrega'])) |
|
326
|
|
|
{ |
|
327
|
|
|
$enderecoLinha1 = "{$this->nfeArray['NFe']['infNFe']['entrega']['xLgr']}"; |
|
328
|
|
|
if (!empty($this->nfeArray['NFe']['infNFe']['entrega']['nro'])) |
|
329
|
|
|
{ |
|
330
|
|
|
$enderecoLinha1 .= ", {$this->nfeArray['NFe']['infNFe']['entrega']['nro']}"; |
|
331
|
|
|
} |
|
332
|
|
|
$enderecoLinha2 = ''; |
|
333
|
|
|
if (!empty($this->nfeArray['NFe']['infNFe']['entrega']['xCpl'])) |
|
334
|
|
|
{ |
|
335
|
|
|
$enderecoLinha2 .= "{$this->nfeArray['NFe']['infNFe']['entrega']['xCpl']} - "; |
|
336
|
|
|
} |
|
337
|
|
|
$enderecoLinha2 .= "{$this->nfeArray['NFe']['infNFe']['entrega']['xMun']}" |
|
338
|
|
|
. " / {$this->nfeArray['NFe']['infNFe']['entrega']['UF']}" |
|
339
|
|
|
. " - CEP {$this->nfeArray['NFe']['infNFe']['entrega']['CEP']}"; |
|
340
|
|
|
} else { |
|
341
|
|
|
$enderecoLinha1 = "{$this->nfeArray['NFe']['infNFe']['dest']['enderDest']['xLgr']}"; |
|
342
|
|
|
if (!empty($this->nfeArray['NFe']['infNFe']['dest']['enderDest']['nro'])) |
|
343
|
|
|
{ |
|
344
|
|
|
$enderecoLinha1 .= ", {$this->nfeArray['NFe']['infNFe']['dest']['enderDest']['nro']}"; |
|
345
|
|
|
} |
|
346
|
|
|
$enderecoLinha2 = ''; |
|
347
|
|
|
if (!empty($this->nfeArray['NFe']['infNFe']['dest']['enderDest']['xCpl'])) |
|
348
|
|
|
{ |
|
349
|
|
|
$enderecoLinha2 .= "{$this->nfeArray['NFe']['infNFe']['dest']['enderDest']['xCpl']} - "; |
|
350
|
|
|
} |
|
351
|
|
|
$enderecoLinha2 .= "{$this->nfeArray['NFe']['infNFe']['dest']['enderDest']['xMun']}" |
|
352
|
|
|
. " / {$this->nfeArray['NFe']['infNFe']['dest']['enderDest']['UF']}" |
|
353
|
|
|
. " - CEP {$this->nfeArray['NFe']['infNFe']['dest']['enderDest']['CEP']}"; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
// LINHA 12 |
|
357
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
358
|
|
|
$this->pdf->cell(($c1 * 4), 5, "{$enderecoLinha1}", 1, 1, 'C', 1); |
|
|
|
|
|
|
359
|
|
|
|
|
360
|
|
|
// LINHA 13 |
|
361
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
362
|
|
|
$this->pdf->cell(($c1 * 4), 5, "{$enderecoLinha2}", 1, 1, 'C', 1); |
|
|
|
|
|
|
363
|
|
|
|
|
364
|
|
|
// LINHA 14 |
|
365
|
|
|
$this->pdf->setFont('Arial', 'B', 12); |
|
366
|
|
|
$this->pdf->cell(($c1 * 2), 6, "TOTAL DA NF-e", 1, 0, 'C', 1); |
|
|
|
|
|
|
367
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
368
|
|
|
$vNF = number_format($this->nfeArray['NFe']['infNFe']['total']['ICMSTot']['vNF'], 2, ',', '.'); |
|
369
|
|
|
$this->pdf->cell(($c1 * 2), 6, "R$ {$vNF}", 1, 1, 'C', 1); |
|
|
|
|
|
|
370
|
|
|
|
|
371
|
|
|
// LINHA 15 |
|
372
|
|
|
$this->pdf->setFont('Arial', 'B', 12); |
|
373
|
|
|
$this->pdf->cell(($c1 * 4), 6, "DADOS ADICIONAIS", 1, 1, 'C', 1); |
|
|
|
|
|
|
374
|
|
|
|
|
375
|
|
|
// LINHA 16 |
|
376
|
|
|
$this->pdf->setFont('Arial', '', 10); |
|
377
|
|
|
$this->pdf->multiCell(($c1 * 4), 5, "{$this->nfeArray['NFe']['infNFe']['infAdic']['infCpl']}", 1, 1, 'J', 1); |
|
|
|
|
|
|
378
|
|
|
} |
|
379
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..