1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NFePHP\DA\NFe; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use NFePHP\DA\Legacy\Dom; |
7
|
|
|
use NFePHP\DA\Legacy\Pdf; |
8
|
|
|
use NFePHP\DA\Legacy\Common; |
9
|
|
|
|
10
|
|
|
class Danfe extends Common |
11
|
|
|
{ |
12
|
|
|
const FPDF_FONTPATH = 'font/'; |
13
|
|
|
const SIT_CANCELADA = 1; |
14
|
|
|
const SIT_DENEGADA = 2; |
15
|
|
|
const SIT_DPEC = 3; |
16
|
|
|
const SIT_NONE = 0; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* alinhamento padrão do logo (C-Center) |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
public $logoAlign = 'C'; |
24
|
|
|
/** |
25
|
|
|
* Posição |
26
|
|
|
* @var float |
27
|
|
|
*/ |
28
|
|
|
public $yDados = 0; |
29
|
|
|
/** |
30
|
|
|
* Situação |
31
|
|
|
* @var integer |
32
|
|
|
*/ |
33
|
|
|
public $situacaoExterna = 0; |
34
|
|
|
/** |
35
|
|
|
* Numero DPEC |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $numero_registro_dpec = ''; |
40
|
|
|
/** |
41
|
|
|
* quantidade de canhotos a serem montados, geralmente 1 ou 2 |
42
|
|
|
* |
43
|
|
|
* @var integer |
44
|
|
|
*/ |
45
|
|
|
public $qCanhoto = 1; |
46
|
|
|
|
47
|
|
|
//########################################################### |
48
|
|
|
// INÍCIO ATRIBUTOS DE PARÂMETROS DE EXIBIÇÃO |
49
|
|
|
//########################################################### |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Parâmetro para exibir ou ocultar os valores do PIS/COFINS. |
53
|
|
|
* @var boolean |
54
|
|
|
*/ |
55
|
|
|
public $exibirPIS = true; |
56
|
|
|
/** |
57
|
|
|
* Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos. |
58
|
|
|
* @var boolean |
59
|
|
|
*/ |
60
|
|
|
public $exibirIcmsInterestadual = true; |
61
|
|
|
/** |
62
|
|
|
* Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos. |
63
|
|
|
* @var boolean |
64
|
|
|
*/ |
65
|
|
|
public $exibirValorTributos = true; |
66
|
|
|
/** |
67
|
|
|
* Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento |
68
|
|
|
* e as informações de fatura/duplicata. |
69
|
|
|
* @var boolean |
70
|
|
|
*/ |
71
|
|
|
public $exibirTextoFatura = false; |
72
|
|
|
/** |
73
|
|
|
* Parâmetro do controle se deve concatenar automaticamente informações complementares |
74
|
|
|
* na descrição do produto, como por exemplo, informações sobre impostos. |
75
|
|
|
* @var boolean |
76
|
|
|
*/ |
77
|
|
|
public $descProdInfoComplemento = true; |
78
|
|
|
/** |
79
|
|
|
* Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto. |
80
|
|
|
* @var boolean |
81
|
|
|
*/ |
82
|
|
|
public $descProdQuebraLinha = true; |
83
|
|
|
|
84
|
|
|
//########################################################### |
85
|
|
|
//PROPRIEDADES DA CLASSE |
86
|
|
|
//########################################################### |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* objeto fpdf() |
90
|
|
|
* @var object |
91
|
|
|
*/ |
92
|
|
|
protected $pdf; |
93
|
|
|
/** |
94
|
|
|
* XML NFe |
95
|
|
|
* @var string |
96
|
|
|
*/ |
97
|
|
|
protected $xml; |
98
|
|
|
/** |
99
|
|
|
* path para logomarca em jpg |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
protected $logomarca = ''; |
103
|
|
|
/** |
104
|
|
|
* mesagens de erro |
105
|
|
|
* @var string |
106
|
|
|
*/ |
107
|
|
|
protected $errMsg = ''; |
108
|
|
|
/** |
109
|
|
|
* status de erro true um erro ocorreu false sem erros |
110
|
|
|
* @var boolean |
111
|
|
|
*/ |
112
|
|
|
protected $errStatus = false; |
113
|
|
|
/** |
114
|
|
|
* orientação da DANFE |
115
|
|
|
* P-Retrato ou L-Paisagem |
116
|
|
|
* @var string |
117
|
|
|
*/ |
118
|
|
|
protected $orientacao = 'P'; |
119
|
|
|
/** |
120
|
|
|
* formato do papel |
121
|
|
|
* @var string |
122
|
|
|
*/ |
123
|
|
|
protected $papel = 'A4'; |
124
|
|
|
/** |
125
|
|
|
* destino do arquivo pdf |
126
|
|
|
* I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local |
127
|
|
|
* @var string |
128
|
|
|
*/ |
129
|
|
|
protected $destino = 'I'; |
130
|
|
|
/** |
131
|
|
|
* diretorio para salvar o pdf com a opção de destino = F |
132
|
|
|
* @var string |
133
|
|
|
*/ |
134
|
|
|
protected $pdfDir = ''; |
135
|
|
|
/** |
136
|
|
|
* Nome da Fonte para gerar o DANFE |
137
|
|
|
* @var string |
138
|
|
|
*/ |
139
|
|
|
protected $fontePadrao = 'Times'; |
140
|
|
|
/** |
141
|
|
|
* versão |
142
|
|
|
* @var string |
143
|
|
|
*/ |
144
|
|
|
protected $version = '2.2.8'; |
145
|
|
|
/** |
146
|
|
|
* Texto |
147
|
|
|
* @var string |
148
|
|
|
*/ |
149
|
|
|
protected $textoAdic = ''; |
150
|
|
|
/** |
151
|
|
|
* Largura |
152
|
|
|
* @var float |
153
|
|
|
*/ |
154
|
|
|
protected $wAdic = 0; |
155
|
|
|
/** |
156
|
|
|
* largura imprimivel, em milímetros |
157
|
|
|
* @var float |
158
|
|
|
*/ |
159
|
|
|
protected $wPrint; |
160
|
|
|
/** |
161
|
|
|
* Comprimento (altura) imprimivel, em milímetros |
162
|
|
|
* @var float |
163
|
|
|
*/ |
164
|
|
|
protected $hPrint; |
165
|
|
|
/** |
166
|
|
|
* largura do canhoto (25mm) apenas para a formatação paisagem |
167
|
|
|
* @var float |
168
|
|
|
*/ |
169
|
|
|
protected $wCanhoto = 25; |
170
|
|
|
/** |
171
|
|
|
* Formato chave |
172
|
|
|
* @var string |
173
|
|
|
*/ |
174
|
|
|
protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####"; |
175
|
|
|
/** |
176
|
|
|
* quantidade de itens já processados na montagem do DANFE |
177
|
|
|
* @var integer |
178
|
|
|
*/ |
179
|
|
|
protected $qtdeItensProc; |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Document |
183
|
|
|
* @var DOMDocument |
184
|
|
|
*/ |
185
|
|
|
protected $dom; |
186
|
|
|
/** |
187
|
|
|
* Node |
188
|
|
|
* @var DOMNode |
189
|
|
|
*/ |
190
|
|
|
protected $infNFe; |
191
|
|
|
/** |
192
|
|
|
* Node |
193
|
|
|
* @var DOMNode |
194
|
|
|
*/ |
195
|
|
|
protected $ide; |
196
|
|
|
/** |
197
|
|
|
* Node |
198
|
|
|
* @var DOMNode |
199
|
|
|
*/ |
200
|
|
|
protected $entrega; |
201
|
|
|
/** |
202
|
|
|
* Node |
203
|
|
|
* @var DOMNode |
204
|
|
|
*/ |
205
|
|
|
protected $retirada; |
206
|
|
|
/** |
207
|
|
|
* Node |
208
|
|
|
* @var DOMNode |
209
|
|
|
*/ |
210
|
|
|
protected $emit; |
211
|
|
|
/** |
212
|
|
|
* Node |
213
|
|
|
* @var DOMNode |
214
|
|
|
*/ |
215
|
|
|
protected $dest; |
216
|
|
|
/** |
217
|
|
|
* Node |
218
|
|
|
* @var DOMNode |
219
|
|
|
*/ |
220
|
|
|
protected $enderEmit; |
221
|
|
|
/** |
222
|
|
|
* Node |
223
|
|
|
* @var DOMNode |
224
|
|
|
*/ |
225
|
|
|
protected $enderDest; |
226
|
|
|
/** |
227
|
|
|
* Node |
228
|
|
|
* @var DOMNode |
229
|
|
|
*/ |
230
|
|
|
protected $det; |
231
|
|
|
/** |
232
|
|
|
* Node |
233
|
|
|
* @var DOMNode |
234
|
|
|
*/ |
235
|
|
|
protected $cobr; |
236
|
|
|
/** |
237
|
|
|
* Node |
238
|
|
|
* @var DOMNode |
239
|
|
|
*/ |
240
|
|
|
protected $dup; |
241
|
|
|
/** |
242
|
|
|
* Node |
243
|
|
|
* @var DOMNode |
244
|
|
|
*/ |
245
|
|
|
protected $ICMSTot; |
246
|
|
|
/** |
247
|
|
|
* Node |
248
|
|
|
* @var DOMNode |
249
|
|
|
*/ |
250
|
|
|
protected $ISSQNtot; |
251
|
|
|
/** |
252
|
|
|
* Node |
253
|
|
|
* @var DOMNode |
254
|
|
|
*/ |
255
|
|
|
protected $transp; |
256
|
|
|
/** |
257
|
|
|
* Node |
258
|
|
|
* @var DOMNode |
259
|
|
|
*/ |
260
|
|
|
protected $transporta; |
261
|
|
|
/** |
262
|
|
|
* Node |
263
|
|
|
* @var DOMNode |
264
|
|
|
*/ |
265
|
|
|
protected $veicTransp; |
266
|
|
|
/** |
267
|
|
|
* Node reboque |
268
|
|
|
* @var DOMNode |
269
|
|
|
*/ |
270
|
|
|
protected $reboque; |
271
|
|
|
/** |
272
|
|
|
* Node infAdic |
273
|
|
|
* @var DOMNode |
274
|
|
|
*/ |
275
|
|
|
protected $infAdic; |
276
|
|
|
/** |
277
|
|
|
* Tipo de emissão |
278
|
|
|
* @var integer |
279
|
|
|
*/ |
280
|
|
|
protected $tpEmis; |
281
|
|
|
/** |
282
|
|
|
* Node infProt |
283
|
|
|
* @var DOMNode |
284
|
|
|
*/ |
285
|
|
|
protected $infProt; |
286
|
|
|
/** |
287
|
|
|
* 1-Retrato/ 2-Paisagem |
288
|
|
|
* @var integer |
289
|
|
|
*/ |
290
|
|
|
protected $tpImp; |
291
|
|
|
/** |
292
|
|
|
* Node compra |
293
|
|
|
* @var DOMNode |
294
|
|
|
*/ |
295
|
|
|
protected $compra; |
296
|
|
|
/** |
297
|
|
|
* ativa ou desativa o modo de debug |
298
|
|
|
* @var integer |
299
|
|
|
*/ |
300
|
|
|
protected $debugMode=2; |
301
|
|
|
/** |
302
|
|
|
* Creditos para integrador |
303
|
|
|
* @var string |
304
|
|
|
*/ |
305
|
|
|
protected $creditos = ''; |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* __construct |
309
|
|
|
* |
310
|
|
|
* @name __construct |
311
|
|
|
* @param string $docXML Conteúdo XML da NF-e (com ou sem a tag nfeProc) |
312
|
|
|
* @param string $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem |
313
|
|
|
* @param string $sPapel Tamanho do papel (Ex. A4) |
314
|
|
|
* @param string $sPathLogo Caminho para o arquivo do logo |
315
|
|
|
* @param string $sDestino Estabelece a direção do envio do documento PDF I-browser D-browser com download S- |
316
|
|
|
* @param string $sDirPDF Caminho para o diretorio de armazenamento dos arquivos PDF |
317
|
|
|
* @param string $fonteDANFE Nome da fonte alternativa do DAnfe |
318
|
|
|
* @param integer $mododebug 0-Não 1-Sim e 2-nada (2 default) |
319
|
|
|
*/ |
320
|
|
|
public function __construct( |
321
|
|
|
$docXML = '', |
322
|
|
|
$sOrientacao = '', |
323
|
|
|
$sPapel = '', |
324
|
|
|
$sPathLogo = '', |
325
|
|
|
$sDestino = 'I', |
326
|
|
|
$sDirPDF = '', |
327
|
|
|
$fonteDANFE = '', |
328
|
|
|
$mododebug = 2 |
329
|
|
|
) { |
330
|
|
|
//set_time_limit(1800); |
331
|
|
|
if (is_numeric($mododebug)) { |
332
|
|
|
$this->debugMode = $mododebug; |
|
|
|
|
333
|
|
|
} |
334
|
|
|
if ($mododebug == 1) { |
335
|
|
|
//ativar modo debug |
336
|
|
|
error_reporting(E_ALL); |
337
|
|
|
ini_set('display_errors', 'On'); |
338
|
|
|
} |
339
|
|
|
if ($mododebug == 0) { |
340
|
|
|
//desativar modo debug |
341
|
|
|
error_reporting(0); |
342
|
|
|
ini_set('display_errors', 'Off'); |
343
|
|
|
} |
344
|
|
|
$this->orientacao = $sOrientacao; |
345
|
|
|
$this->papel = $sPapel; |
346
|
|
|
$this->pdf = ''; |
|
|
|
|
347
|
|
|
$this->xml = $docXML; |
348
|
|
|
$this->logomarca = $sPathLogo; |
349
|
|
|
$this->destino = $sDestino; |
350
|
|
|
$this->pdfDir = $sDirPDF; |
351
|
|
|
// verifica se foi passa a fonte a ser usada |
352
|
|
|
if (empty($fonteDANFE)) { |
353
|
|
|
$this->fontePadrao = 'Times'; |
354
|
|
|
} else { |
355
|
|
|
$this->fontePadrao = $fonteDANFE; |
356
|
|
|
} |
357
|
|
|
//se for passado o xml |
358
|
|
|
if (! empty($this->xml)) { |
359
|
|
|
$this->dom = new Dom(); |
|
|
|
|
360
|
|
|
$this->dom->loadXML($this->xml); |
361
|
|
|
$this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0); |
|
|
|
|
362
|
|
|
$this->infNFe = $this->dom->getElementsByTagName("infNFe")->item(0); |
|
|
|
|
363
|
|
|
$this->ide = $this->dom->getElementsByTagName("ide")->item(0); |
|
|
|
|
364
|
|
|
$this->entrega = $this->dom->getElementsByTagName("entrega")->item(0); |
|
|
|
|
365
|
|
|
$this->retirada = $this->dom->getElementsByTagName("retirada")->item(0); |
|
|
|
|
366
|
|
|
$this->emit = $this->dom->getElementsByTagName("emit")->item(0); |
|
|
|
|
367
|
|
|
$this->dest = $this->dom->getElementsByTagName("dest")->item(0); |
|
|
|
|
368
|
|
|
$this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0); |
|
|
|
|
369
|
|
|
$this->enderDest = $this->dom->getElementsByTagName("enderDest")->item(0); |
|
|
|
|
370
|
|
|
$this->det = $this->dom->getElementsByTagName("det"); |
|
|
|
|
371
|
|
|
$this->cobr = $this->dom->getElementsByTagName("cobr")->item(0); |
|
|
|
|
372
|
|
|
$this->dup = $this->dom->getElementsByTagName('dup'); |
|
|
|
|
373
|
|
|
$this->ICMSTot = $this->dom->getElementsByTagName("ICMSTot")->item(0); |
|
|
|
|
374
|
|
|
$this->ISSQNtot = $this->dom->getElementsByTagName("ISSQNtot")->item(0); |
|
|
|
|
375
|
|
|
$this->transp = $this->dom->getElementsByTagName("transp")->item(0); |
|
|
|
|
376
|
|
|
$this->transporta = $this->dom->getElementsByTagName("transporta")->item(0); |
|
|
|
|
377
|
|
|
$this->veicTransp = $this->dom->getElementsByTagName("veicTransp")->item(0); |
|
|
|
|
378
|
|
|
$this->reboque = $this->dom->getElementsByTagName("reboque")->item(0); |
|
|
|
|
379
|
|
|
$this->infAdic = $this->dom->getElementsByTagName("infAdic")->item(0); |
|
|
|
|
380
|
|
|
$this->compra = $this->dom->getElementsByTagName("compra")->item(0); |
|
|
|
|
381
|
|
|
$this->tpEmis = $this->ide->getElementsByTagName("tpEmis")->item(0)->nodeValue; |
382
|
|
|
$this->tpImp = $this->ide->getElementsByTagName("tpImp")->item(0)->nodeValue; |
383
|
|
|
$this->infProt = $this->dom->getElementsByTagName("infProt")->item(0); |
|
|
|
|
384
|
|
|
//valida se o XML é uma NF-e modelo 55, pois não pode ser 65 (NFC-e) |
385
|
|
|
if ($this->pSimpleGetValue($this->ide, "mod") != '55') { |
386
|
|
|
throw new InvalidArgumentException("O xml do DANFE deve ser uma NF-e modelo 55"); |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Add the credits to the integrator in the footer message |
393
|
|
|
* @param string $message |
394
|
|
|
*/ |
395
|
|
|
public function creditsIntegratorFooter($message = '') |
396
|
|
|
{ |
397
|
|
|
$this->creditos = trim($message); |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* monta |
402
|
|
|
* |
403
|
|
|
* @name monta |
404
|
|
|
* @param string $orientacao |
405
|
|
|
* @param string $papel |
406
|
|
|
* @param string $logoAlign |
407
|
|
|
* @return string |
408
|
|
|
*/ |
409
|
|
|
public function monta( |
410
|
|
|
$orientacao = '', |
411
|
|
|
$papel = 'A4', |
412
|
|
|
$logoAlign = 'C', |
413
|
|
|
$situacaoExterna = self::SIT_NONE, |
414
|
|
|
$classPdf = false, |
415
|
|
|
$dpecNumReg = '', |
416
|
|
|
$margSup = 2, |
417
|
|
|
$margEsq = 2, |
418
|
|
|
$margInf = 2 |
419
|
|
|
) { |
420
|
|
|
return $this->montaDANFE( |
421
|
|
|
$orientacao, |
422
|
|
|
$papel, |
423
|
|
|
$logoAlign, |
424
|
|
|
$situacaoExterna, |
425
|
|
|
$classPdf, |
426
|
|
|
$dpecNumReg, |
427
|
|
|
$margSup, |
428
|
|
|
$margEsq, |
429
|
|
|
$margInf |
430
|
|
|
); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* printDocument |
435
|
|
|
* |
436
|
|
|
* @param string $nome |
437
|
|
|
* @param string $destino |
438
|
|
|
* @param string $printer |
439
|
|
|
* @return object pdf |
440
|
|
|
*/ |
441
|
|
|
public function printDocument($nome = '', $destino = 'I', $printer = '') |
|
|
|
|
442
|
|
|
{ |
443
|
|
|
$arq = $this->pdf->Output($nome, $destino); |
444
|
|
|
if ($destino == 'S') { |
|
|
|
|
445
|
|
|
//aqui pode entrar a rotina de impressão direta |
446
|
|
|
} |
447
|
|
|
return $arq; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* montaDANFE |
452
|
|
|
* Monta a DANFE conforme as informações fornecidas para a classe durante sua |
453
|
|
|
* construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens. |
454
|
|
|
* A definição de margens e posições iniciais para a impressão são estabelecidas |
455
|
|
|
* pelo conteúdo da funçao e podem ser modificados. |
456
|
|
|
* |
457
|
|
|
* @param string $orientacao (Opcional) Estabelece a orientação da impressão |
458
|
|
|
* (ex. P-retrato), se nada for fornecido será usado o padrão da NFe |
459
|
|
|
* @param string $papel (Opcional) Estabelece o tamanho do papel (ex. A4) |
460
|
|
|
* @return string O ID da NFe numero de 44 digitos extraido do arquivo XML |
461
|
|
|
*/ |
462
|
|
|
public function montaDANFE( |
463
|
|
|
$orientacao = '', |
464
|
|
|
$papel = 'A4', |
465
|
|
|
$logoAlign = 'C', |
466
|
|
|
$situacaoExterna = self::SIT_NONE, |
467
|
|
|
$classPdf = false, |
468
|
|
|
$depecNumReg = '', |
469
|
|
|
$margSup = 2, |
470
|
|
|
$margEsq = 2, |
471
|
|
|
$margInf = 2 |
472
|
|
|
) { |
473
|
|
|
//se a orientação estiver em branco utilizar o padrão estabelecido na NF |
474
|
|
|
if ($orientacao == '') { |
475
|
|
|
if ($this->tpImp == '1') { |
476
|
|
|
$orientacao = 'P'; |
477
|
|
|
} else { |
478
|
|
|
$orientacao = 'L'; |
479
|
|
|
} |
480
|
|
|
} |
481
|
|
|
$this->orientacao = $orientacao; |
482
|
|
|
$this->papel = $papel; |
483
|
|
|
$this->logoAlign = $logoAlign; |
484
|
|
|
$this->situacao_externa = $situacaoExterna; |
|
|
|
|
485
|
|
|
$this->numero_registro_dpec = $depecNumReg; |
486
|
|
|
//instancia a classe pdf |
487
|
|
|
if ($classPdf) { |
488
|
|
|
$this->pdf = $classPdf; |
|
|
|
|
489
|
|
|
} else { |
490
|
|
|
$this->pdf = new Pdf($this->orientacao, 'mm', $this->papel); |
491
|
|
|
} |
492
|
|
|
//margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à |
493
|
|
|
//margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui |
494
|
|
|
//apenas para controle se necessário ser maior do que a margem superior |
495
|
|
|
// posição inicial do conteúdo, a partir do canto superior esquerdo da página |
496
|
|
|
$xInic = $margEsq; |
497
|
|
|
$yInic = $margSup; |
498
|
|
|
if ($this->orientacao == 'P') { |
499
|
|
|
if ($papel == 'A4') { |
500
|
|
|
$maxW = 210; |
501
|
|
|
$maxH = 297; |
502
|
|
|
} |
503
|
|
|
} else { |
504
|
|
|
if ($papel == 'A4') { |
505
|
|
|
$maxH = 210; |
506
|
|
|
$maxW = 297; |
507
|
|
|
//se paisagem multiplica a largura do canhoto pela quantidade de canhotos |
508
|
|
|
$this->wCanhoto *= $this->qCanhoto; |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
//total inicial de paginas |
512
|
|
|
$totPag = 1; |
|
|
|
|
513
|
|
|
//largura imprimivel em mm: largura da folha menos as margens esq/direita |
514
|
|
|
$this->wPrint = $maxW-($margEsq*2); |
|
|
|
|
515
|
|
|
//comprimento (altura) imprimivel em mm: altura da folha menos as margens |
516
|
|
|
//superior e inferior |
517
|
|
|
$this->hPrint = $maxH-$margSup-$margInf; |
|
|
|
|
518
|
|
|
// estabelece contagem de paginas |
519
|
|
|
$this->pdf->aliasNbPages(); |
520
|
|
|
// fixa as margens |
521
|
|
|
$this->pdf->setMargins($margEsq, $margSup); |
522
|
|
|
$this->pdf->setDrawColor(0, 0, 0); |
523
|
|
|
$this->pdf->setFillColor(255, 255, 255); |
524
|
|
|
// inicia o documento |
525
|
|
|
$this->pdf->open(); |
526
|
|
|
// adiciona a primeira página |
527
|
|
|
$this->pdf->addPage($this->orientacao, $this->papel); |
528
|
|
|
$this->pdf->setLineWidth(0.1); |
529
|
|
|
$this->pdf->setTextColor(0, 0, 0); |
530
|
|
|
|
531
|
|
|
//################################################################## |
532
|
|
|
// CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS |
533
|
|
|
//################################################################## |
534
|
|
|
//Verificando quantas linhas serão usadas para impressão das duplicatas |
535
|
|
|
$linhasDup = 0; |
536
|
|
|
if (($this->dup->length > 0) && ($this->dup->length <= 7)) { |
537
|
|
|
$linhasDup = 1; |
538
|
|
|
} elseif (($this->dup->length > 7) && ($this->dup->length <= 14)) { |
539
|
|
|
$linhasDup = 2; |
540
|
|
|
} elseif (($this->dup->length > 14) && ($this->dup->length <= 21)) { |
541
|
|
|
$linhasDup = 3; |
542
|
|
|
} elseif ($this->dup->length > 21) { |
543
|
|
|
// chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe, |
544
|
|
|
// só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento), |
545
|
|
|
// se não oculpa espaço d+, cada linha comporta até 7 duplicatas. |
546
|
|
|
$linhasDup = 3; |
547
|
|
|
} |
548
|
|
|
//verifica se será impressa a linha dos serviços ISSQN |
549
|
|
|
$linhaISSQN = 0; |
550
|
|
|
if ((isset($this->ISSQNtot)) && ($this->pSimpleGetValue($this->ISSQNtot, 'vServ') > 0)) { |
551
|
|
|
$linhaISSQN = 1; |
552
|
|
|
} |
553
|
|
|
//calcular a altura necessária para os dados adicionais |
554
|
|
|
if ($this->orientacao == 'P') { |
555
|
|
|
$this->wAdic = round($this->wPrint*0.66, 0); |
556
|
|
|
} else { |
557
|
|
|
$this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0); |
558
|
|
|
} |
559
|
|
|
$fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
560
|
|
|
$this->textoAdic = ''; |
561
|
|
|
if (isset($this->retirada)) { |
562
|
|
|
$txRetCNPJ = ! empty($this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue) ? |
563
|
|
|
$this->retirada->getElementsByTagName("CNPJ")->item(0)->nodeValue : |
564
|
|
|
''; |
565
|
|
|
$txRetxLgr = ! empty($this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue) ? |
566
|
|
|
$this->retirada->getElementsByTagName("xLgr")->item(0)->nodeValue : |
567
|
|
|
''; |
568
|
|
|
$txRetnro = ! empty($this->retirada->getElementsByTagName("nro")->item(0)->nodeValue) ? |
569
|
|
|
$this->retirada->getElementsByTagName("nro")->item(0)->nodeValue : |
570
|
|
|
's/n'; |
571
|
|
|
$txRetxCpl = $this->pSimpleGetValue($this->retirada, "xCpl", " - "); |
572
|
|
|
$txRetxBairro = ! empty($this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue) ? |
573
|
|
|
$this->retirada->getElementsByTagName("xBairro")->item(0)->nodeValue : |
574
|
|
|
''; |
575
|
|
|
$txRetxMun = ! empty($this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue) ? |
576
|
|
|
$this->retirada->getElementsByTagName("xMun")->item(0)->nodeValue : |
577
|
|
|
''; |
578
|
|
|
$txRetUF = ! empty($this->retirada->getElementsByTagName("UF")->item(0)->nodeValue) ? |
579
|
|
|
$this->retirada->getElementsByTagName("UF")->item(0)->nodeValue : |
580
|
|
|
''; |
581
|
|
|
$this->textoAdic .= "LOCAL DE RETIRADA : ". |
582
|
|
|
$txRetCNPJ. |
583
|
|
|
'-' . |
584
|
|
|
$txRetxLgr . |
585
|
|
|
', ' . |
586
|
|
|
$txRetnro . |
587
|
|
|
' ' . |
588
|
|
|
$txRetxCpl . |
589
|
|
|
' - ' . |
590
|
|
|
$txRetxBairro . |
591
|
|
|
' ' . |
592
|
|
|
$txRetxMun . |
593
|
|
|
' - ' . |
594
|
|
|
$txRetUF . |
595
|
|
|
"\r\n"; |
596
|
|
|
} |
597
|
|
|
//dados do local de entrega da mercadoria |
598
|
|
|
if (isset($this->entrega)) { |
599
|
|
|
$txRetCNPJ = ! empty($this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue) ? |
600
|
|
|
$this->entrega->getElementsByTagName("CNPJ")->item(0)->nodeValue : ''; |
601
|
|
|
$txRetxLgr = ! empty($this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue) ? |
602
|
|
|
$this->entrega->getElementsByTagName("xLgr")->item(0)->nodeValue : ''; |
603
|
|
|
$txRetnro = ! empty($this->entrega->getElementsByTagName("nro")->item(0)->nodeValue) ? |
604
|
|
|
$this->entrega->getElementsByTagName("nro")->item(0)->nodeValue : 's/n'; |
605
|
|
|
$txRetxCpl = $this->pSimpleGetValue($this->entrega, "xCpl", " - "); |
606
|
|
|
$txRetxBairro = ! empty($this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue) ? |
607
|
|
|
$this->entrega->getElementsByTagName("xBairro")->item(0)->nodeValue : ''; |
608
|
|
|
$txRetxMun = ! empty($this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue) ? |
609
|
|
|
$this->entrega->getElementsByTagName("xMun")->item(0)->nodeValue : ''; |
610
|
|
|
$txRetUF = ! empty($this->entrega->getElementsByTagName("UF")->item(0)->nodeValue) ? |
611
|
|
|
$this->entrega->getElementsByTagName("UF")->item(0)->nodeValue : ''; |
612
|
|
|
if ($this->textoAdic != '') { |
613
|
|
|
$this->textoAdic .= ". \r\n"; |
614
|
|
|
} |
615
|
|
|
$this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl. |
616
|
|
|
' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n"; |
617
|
|
|
} |
618
|
|
|
//informações adicionais |
619
|
|
|
$this->textoAdic .= $this->pGeraInformacoesDasNotasReferenciadas(); |
620
|
|
|
if (isset($this->infAdic)) { |
621
|
|
|
$i = 0; |
622
|
|
|
if ($this->textoAdic != '') { |
623
|
|
|
$this->textoAdic .= ". \r\n"; |
624
|
|
|
} |
625
|
|
|
$this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue) ? |
626
|
|
|
'Inf. Contribuinte: ' . |
627
|
|
|
trim($this->pAnfavea($this->infAdic->getElementsByTagName("infCpl")->item(0)->nodeValue)) : ''; |
628
|
|
|
$infPedido = $this->pGeraInformacoesDaTagCompra(); |
629
|
|
|
if ($infPedido != "") { |
630
|
|
|
$this->textoAdic .= $infPedido; |
631
|
|
|
} |
632
|
|
|
$this->textoAdic .= $this->pSimpleGetValue($this->dest, "email", ' Email do Destinatário: '); |
633
|
|
|
$this->textoAdic .= ! empty($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) ? |
634
|
|
|
"\r\n Inf. fisco: " . |
635
|
|
|
trim($this->infAdic->getElementsByTagName("infAdFisco")->item(0)->nodeValue) : ''; |
636
|
|
|
$obsCont = $this->infAdic->getElementsByTagName("obsCont"); |
637
|
|
|
if (isset($obsCont)) { |
638
|
|
|
foreach ($obsCont as $obs) { |
639
|
|
|
$campo = $obsCont->item($i)->getAttribute("xCampo"); |
640
|
|
|
$xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue) ? |
641
|
|
|
$obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue : ''; |
642
|
|
|
$this->textoAdic .= "\r\n" . $campo . ': ' . trim($xTexto); |
643
|
|
|
$i++; |
644
|
|
|
} |
645
|
|
|
} |
646
|
|
|
} |
647
|
|
|
//INCLUSO pela NT 2013.003 Lei da Transparência |
648
|
|
|
//verificar se a informação sobre o valor aproximado dos tributos |
649
|
|
|
//já se encontra no campo de informações adicionais |
650
|
|
|
if ($this->exibirValorTributos) { |
651
|
|
|
$flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor'); |
652
|
|
|
$flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl'); |
653
|
|
|
$flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox'); |
654
|
|
|
$flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') || |
655
|
|
|
strpos(strtolower(trim($this->textoAdic)), 'imp')); |
656
|
|
|
$vTotTrib = $this->pSimpleGetValue($this->ICMSTot, 'vTotTrib'); |
657
|
|
|
if ($vTotTrib != '' && !$flagVTT) { |
658
|
|
|
$this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ " . number_format($vTotTrib, 2, ",", "."); |
659
|
|
|
} |
660
|
|
|
} |
661
|
|
|
//fim da alteração NT 2013.003 Lei da Transparência |
662
|
|
|
$this->textoAdic = str_replace(";", "\n", $this->textoAdic); |
663
|
|
|
$alinhas = explode("\n", $this->textoAdic); |
664
|
|
|
$numlinhasdados = 0; |
665
|
|
|
foreach ($alinhas as $linha) { |
666
|
|
|
$numlinhasdados += $this->pGetNumLines($linha, $this->wAdic, $fontProduto); |
667
|
|
|
} |
668
|
|
|
$hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0); |
669
|
|
|
if ($hdadosadic < 10) { |
670
|
|
|
$hdadosadic = 10; |
671
|
|
|
} |
672
|
|
|
//altura disponivel para os campos da DANFE |
673
|
|
|
$hcabecalho = 47;//para cabeçalho |
674
|
|
|
$hdestinatario = 25;//para destinatario |
675
|
|
|
$hduplicatas = 12;//para cada grupo de 7 duplicatas |
676
|
|
|
$himposto = 18;// para imposto |
677
|
|
|
$htransporte = 25;// para transporte |
678
|
|
|
$hissqn = 11;// para issqn |
679
|
|
|
$hfooter = 5;// para rodape |
680
|
|
|
$hCabecItens = 4;//cabeçalho dos itens |
681
|
|
|
//alturas disponiveis para os dados |
682
|
|
|
$hDispo1 = $this->hPrint - 10 - ($hcabecalho + |
683
|
|
|
$hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte + |
684
|
|
|
($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens + |
685
|
|
|
$this->pSizeExtraTextoFatura()); |
686
|
|
|
if ($this->orientacao == 'P') { |
687
|
|
|
$hDispo1 -= 23 * $this->qCanhoto;//para canhoto |
688
|
|
|
$w = $this->wPrint; |
689
|
|
|
} else { |
690
|
|
|
$hcanhoto = $this->hPrint;//para canhoto |
|
|
|
|
691
|
|
|
$w = $this->wPrint - $this->wCanhoto; |
692
|
|
|
} |
693
|
|
|
$hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4; |
694
|
|
|
//Contagem da altura ocupada para impressão dos itens |
695
|
|
|
$fontProduto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
696
|
|
|
$i = 0; |
697
|
|
|
$numlinhas = 0; |
|
|
|
|
698
|
|
|
$hUsado = $hCabecItens; |
699
|
|
|
$w2 = round($w*0.28, 0); |
700
|
|
|
$hDispo = $hDispo1; |
701
|
|
|
$totPag = 1; |
702
|
|
|
while ($i < $this->det->length) { |
703
|
|
|
$texto = $this->pDescricaoProduto($this->det->item($i)); |
704
|
|
|
$numlinhas = $this->pGetNumLines($texto, $w2, $fontProduto); |
705
|
|
|
$hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2); |
706
|
|
|
if ($hUsado > $hDispo) { |
707
|
|
|
$totPag++; |
708
|
|
|
$hDispo = $hDispo2; |
709
|
|
|
$hUsado = $hCabecItens; |
710
|
|
|
// Remove canhoto para páginas secundárias em modo paisagem ('L') |
711
|
|
|
$w2 = round($this->wPrint*0.28, 0); |
712
|
|
|
$i--; // decrementa para readicionar o item que não coube nessa pagina na outra. |
713
|
|
|
} |
714
|
|
|
$i++; |
715
|
|
|
} //fim da soma das areas de itens usadas |
716
|
|
|
$qtdeItens = $i; //controle da quantidade de itens no DANFE |
717
|
|
|
//montagem da primeira página |
718
|
|
|
$pag = 1; |
719
|
|
|
$x = $xInic; |
720
|
|
|
$y = $yInic; |
721
|
|
|
//coloca o(s) canhoto(s) da NFe |
722
|
|
|
if ($this->orientacao == 'P') { |
723
|
|
|
for ($i = 1; $i <= $this->qCanhoto; $i++) { |
724
|
|
|
$y = $this->pCanhoto($x, $y); |
725
|
|
|
} |
726
|
|
|
} else { |
727
|
|
|
for ($i = 1; $i <= $this->qCanhoto; $i++) { |
728
|
|
|
$this->pCanhoto($x, $y); |
729
|
|
|
$x = 25 * $i; |
730
|
|
|
} |
731
|
|
|
} |
732
|
|
|
//coloca o cabeçalho |
733
|
|
|
$y = $this->pCabecalhoDANFE($x, $y, $pag, $totPag); |
734
|
|
|
//coloca os dados do destinatário |
735
|
|
|
$y = $this->pDestinatarioDANFE($x, $y+1); |
736
|
|
|
//coloca os dados das faturas |
737
|
|
|
$y = $this->pFaturaDANFE($x, $y+1); |
738
|
|
|
//coloca os dados dos impostos e totais da NFe |
739
|
|
|
$y = $this->pImpostoDANFE($x, $y+1); |
740
|
|
|
//coloca os dados do trasnporte |
741
|
|
|
$y = $this->pTransporteDANFE($x, $y+1); |
742
|
|
|
//itens da DANFE |
743
|
|
|
$nInicial = 0; |
744
|
|
|
$y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens); |
745
|
|
|
//coloca os dados do ISSQN |
746
|
|
|
if ($linhaISSQN == 1) { |
747
|
|
|
$y = $this->pIssqnDANFE($x, $y+4); |
748
|
|
|
} else { |
749
|
|
|
$y += 4; |
750
|
|
|
} |
751
|
|
|
//coloca os dados adicionais da NFe |
752
|
|
|
$y = $this->pDadosAdicionaisDANFE($x, $y, $hdadosadic); |
753
|
|
|
//coloca o rodapé da página |
754
|
|
|
if ($this->orientacao == 'P') { |
755
|
|
|
$this->pRodape($xInic, $y-1); |
756
|
|
|
} else { |
757
|
|
|
$this->pRodape($xInic, $this->hPrint + 1); |
758
|
|
|
} |
759
|
|
|
//loop para páginas seguintes |
760
|
|
|
for ($n = 2; $n <= $totPag; $n++) { |
761
|
|
|
// fixa as margens |
762
|
|
|
$this->pdf->setMargins($margEsq, $margSup); |
763
|
|
|
//adiciona nova página |
764
|
|
|
$this->pdf->addPage($this->orientacao, $this->papel); |
765
|
|
|
//ajusta espessura das linhas |
766
|
|
|
$this->pdf->setLineWidth(0.1); |
767
|
|
|
//seta a cor do texto para petro |
768
|
|
|
$this->pdf->setTextColor(0, 0, 0); |
769
|
|
|
// posição inicial do relatorio |
770
|
|
|
$x = $xInic; |
771
|
|
|
$y = $yInic; |
772
|
|
|
//coloca o cabeçalho na página adicional |
773
|
|
|
$y = $this->pCabecalhoDANFE($x, $y, $n, $totPag); |
774
|
|
|
//coloca os itens na página adicional |
775
|
|
|
$y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens); |
776
|
|
|
//coloca o rodapé da página |
777
|
|
|
if ($this->orientacao == 'P') { |
778
|
|
|
$this->pRodape($xInic, $y + 4); |
779
|
|
|
} else { |
780
|
|
|
$this->pRodape($xInic, $this->hPrint + 4); |
781
|
|
|
} |
782
|
|
|
//se estiver na última página e ainda restar itens para inserir, adiciona mais uma página |
783
|
|
|
if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) { |
784
|
|
|
$totPag++; |
785
|
|
|
} |
786
|
|
|
} |
787
|
|
|
//retorna o ID na NFe |
788
|
|
|
if ($classPdf!==false) { |
789
|
|
|
$aR = array( |
790
|
|
|
'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")), |
791
|
|
|
'classe_PDF'=>$this->pdf); |
792
|
|
|
return $aR; |
|
|
|
|
793
|
|
|
} else { |
794
|
|
|
return str_replace('NFe', '', $this->infNFe->getAttribute("Id")); |
795
|
|
|
} |
796
|
|
|
}//fim da função montaDANFE |
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* anfavea |
800
|
|
|
* Função para transformar o campo cdata do padrão ANFAVEA para |
801
|
|
|
* texto imprimível |
802
|
|
|
* |
803
|
|
|
* @param string $cdata campo CDATA |
804
|
|
|
* @return string conteúdo do campo CDATA como string |
805
|
|
|
*/ |
806
|
|
|
protected function pAnfavea($cdata = '') |
807
|
|
|
{ |
808
|
|
|
if ($cdata == '') { |
809
|
|
|
return ''; |
810
|
|
|
} |
811
|
|
|
//remove qualquer texto antes ou depois da tag CDATA |
812
|
|
|
$cdata = str_replace('<![CDATA[', '<CDATA>', $cdata); |
813
|
|
|
$cdata = str_replace(']]>', '</CDATA>', $cdata); |
814
|
|
|
$cdata = preg_replace('/\s\s+/', ' ', $cdata); |
815
|
|
|
$cdata = str_replace("> <", "><", $cdata); |
816
|
|
|
$len = strlen($cdata); |
817
|
|
|
$startPos = strpos($cdata, '<'); |
818
|
|
|
if ($startPos === false) { |
819
|
|
|
return $cdata; |
820
|
|
|
} |
821
|
|
|
for ($x=$len; $x>0; $x--) { |
822
|
|
|
if (substr($cdata, $x, 1) == '>') { |
823
|
|
|
$endPos = $x; |
824
|
|
|
break; |
825
|
|
|
} |
826
|
|
|
} |
827
|
|
|
if ($startPos > 0) { |
828
|
|
|
$parte1 = substr($cdata, 0, $startPos); |
829
|
|
|
} else { |
830
|
|
|
$parte1 = ''; |
831
|
|
|
} |
832
|
|
|
$parte2 = substr($cdata, $startPos, $endPos-$startPos+1); |
|
|
|
|
833
|
|
|
if ($endPos < $len) { |
834
|
|
|
$parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1); |
835
|
|
|
} else { |
836
|
|
|
$parte3 = ''; |
837
|
|
|
} |
838
|
|
|
$texto = trim($parte1).' '.trim($parte3); |
839
|
|
|
if (strpos($parte2, '<CDATA>') === false) { |
840
|
|
|
$cdata = '<CDATA>'.$parte2.'</CDATA>'; |
841
|
|
|
} else { |
842
|
|
|
$cdata = $parte2; |
843
|
|
|
} |
844
|
|
|
//Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML |
845
|
|
|
$cdata = str_replace('<FONTE IBPT>', '', $cdata); |
846
|
|
|
//carrega o xml CDATA em um objeto DOM |
847
|
|
|
$dom = new Dom(); |
848
|
|
|
$dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG); |
849
|
|
|
//$xml = $dom->saveXML(); |
|
|
|
|
850
|
|
|
//grupo CDATA infADprod |
851
|
|
|
$id = $dom->getElementsByTagName('id')->item(0); |
852
|
|
|
$div = $dom->getElementsByTagName('div')->item(0); |
853
|
|
|
$entg = $dom->getElementsByTagName('entg')->item(0); |
854
|
|
|
$dest = $dom->getElementsByTagName('dest')->item(0); |
855
|
|
|
$ctl = $dom->getElementsByTagName('ctl')->item(0); |
856
|
|
|
$ref = $dom->getElementsByTagName('ref')->item(0); |
857
|
|
|
if (isset($id)) { |
858
|
|
|
if ($id->hasAttributes()) { |
859
|
|
|
foreach ($id->attributes as $attr) { |
860
|
|
|
$name = $attr->nodeName; |
861
|
|
|
$value = $attr->nodeValue; |
862
|
|
|
$texto .= " $name : $value"; |
863
|
|
|
} |
864
|
|
|
} |
865
|
|
|
} |
866
|
|
|
if (isset($div)) { |
867
|
|
|
if ($div->hasAttributes()) { |
868
|
|
|
foreach ($div->attributes as $attr) { |
869
|
|
|
$name = $attr->nodeName; |
870
|
|
|
$value = $attr->nodeValue; |
871
|
|
|
$texto .= " $name : $value"; |
872
|
|
|
} |
873
|
|
|
} |
874
|
|
|
} |
875
|
|
|
if (isset($entg)) { |
876
|
|
|
if ($entg->hasAttributes()) { |
877
|
|
|
foreach ($entg->attributes as $attr) { |
878
|
|
|
$name = $attr->nodeName; |
879
|
|
|
$value = $attr->nodeValue; |
880
|
|
|
$texto .= " $name : $value"; |
881
|
|
|
} |
882
|
|
|
} |
883
|
|
|
} |
884
|
|
|
if (isset($dest)) { |
885
|
|
|
if ($dest->hasAttributes()) { |
886
|
|
|
foreach ($dest->attributes as $attr) { |
887
|
|
|
$name = $attr->nodeName; |
888
|
|
|
$value = $attr->nodeValue; |
889
|
|
|
$texto .= " $name : $value"; |
890
|
|
|
} |
891
|
|
|
} |
892
|
|
|
} |
893
|
|
|
if (isset($ctl)) { |
894
|
|
|
if ($ctl->hasAttributes()) { |
895
|
|
|
foreach ($ctl->attributes as $attr) { |
896
|
|
|
$name = $attr->nodeName; |
897
|
|
|
$value = $attr->nodeValue; |
898
|
|
|
$texto .= " $name : $value"; |
899
|
|
|
} |
900
|
|
|
} |
901
|
|
|
} |
902
|
|
|
if (isset($ref)) { |
903
|
|
|
if ($ref->hasAttributes()) { |
904
|
|
|
foreach ($ref->attributes as $attr) { |
905
|
|
|
$name = $attr->nodeName; |
906
|
|
|
$value = $attr->nodeValue; |
907
|
|
|
$texto .= " $name : $value"; |
908
|
|
|
} |
909
|
|
|
} |
910
|
|
|
} |
911
|
|
|
//grupo CADATA infCpl |
912
|
|
|
$t = $dom->getElementsByTagName('transmissor')->item(0); |
913
|
|
|
$r = $dom->getElementsByTagName('receptor')->item(0); |
914
|
|
|
$versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ? |
915
|
|
|
'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : ''; |
916
|
|
|
$especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ? |
917
|
|
|
'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : ''; |
918
|
|
|
$fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ? |
919
|
|
|
'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : ''; |
920
|
|
|
$dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ? |
921
|
|
|
'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : ''; |
922
|
|
|
$texto .= "".$versao.$especieNF.$fabEntrega.$dca; |
923
|
|
|
if (isset($t)) { |
924
|
|
|
if ($t->hasAttributes()) { |
925
|
|
|
$texto .= " Transmissor "; |
926
|
|
|
foreach ($t->attributes as $attr) { |
927
|
|
|
$name = $attr->nodeName; |
928
|
|
|
$value = $attr->nodeValue; |
929
|
|
|
$texto .= " $name : $value"; |
930
|
|
|
} |
931
|
|
|
} |
932
|
|
|
} |
933
|
|
|
if (isset($r)) { |
934
|
|
|
if ($r->hasAttributes()) { |
935
|
|
|
$texto .= " Receptor "; |
936
|
|
|
foreach ($r->attributes as $attr) { |
937
|
|
|
$name = $attr->nodeName; |
938
|
|
|
$value = $attr->nodeValue; |
939
|
|
|
$texto .= " $name : $value"; |
940
|
|
|
} |
941
|
|
|
} |
942
|
|
|
} |
943
|
|
|
return $texto; |
944
|
|
|
} |
945
|
|
|
|
946
|
|
|
/** |
947
|
|
|
* Dados brutos do PDF |
948
|
|
|
* @return string |
949
|
|
|
*/ |
950
|
|
|
public function render() |
951
|
|
|
{ |
952
|
|
|
return $this->pdf->getPdf(); |
953
|
|
|
} |
954
|
|
|
|
955
|
|
|
protected function pNotaCancelada() |
956
|
|
|
{ |
957
|
|
|
if (!isset($this->nfeProc)) { |
958
|
|
|
return false; |
959
|
|
|
} |
960
|
|
|
$cStat = $this->pSimpleGetValue($this->nfeProc, "cStat"); |
961
|
|
|
return $cStat == '101' || |
962
|
|
|
$cStat == '151' || |
963
|
|
|
$cStat == '135' || |
964
|
|
|
$cStat == '155' || |
965
|
|
|
$this->situacao_externa == self::SIT_CANCELADA; |
|
|
|
|
966
|
|
|
} |
967
|
|
|
|
968
|
|
|
protected function pNotaDPEC() |
969
|
|
|
{ |
970
|
|
|
return $this->situacao_externa == self::SIT_DPEC && $this->numero_registro_dpec != ''; |
|
|
|
|
971
|
|
|
} |
972
|
|
|
|
973
|
|
|
protected function pNotaDenegada() |
974
|
|
|
{ |
975
|
|
|
if (!isset($this->nfeProc)) { |
976
|
|
|
return false; |
977
|
|
|
} |
978
|
|
|
//NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA |
979
|
|
|
//1 VEZ NO ARQUIVO INTEIRO |
980
|
|
|
$cStat = $this->pSimpleGetValue($this->nfeProc, "cStat"); |
981
|
|
|
return $cStat == '110' || |
982
|
|
|
$cStat == '301' || |
983
|
|
|
$cStat == '302' || |
984
|
|
|
$this->situacao_externa == self::SIT_DENEGADA; |
|
|
|
|
985
|
|
|
} |
986
|
|
|
|
987
|
|
|
/** |
988
|
|
|
*cabecalhoDANFE |
989
|
|
|
* Monta o cabelhalho da DANFE (retrato e paisagem) |
990
|
|
|
* |
991
|
|
|
* @param number $x Posição horizontal inicial, canto esquerdo |
992
|
|
|
* @param number $y Posição vertical inicial, canto superior |
993
|
|
|
* @param number $pag Número da Página |
994
|
|
|
* @param number $totPag Total de páginas |
995
|
|
|
* @return number Posição vertical final |
996
|
|
|
*/ |
997
|
|
|
protected function pCabecalhoDANFE($x = 0, $y = 0, $pag = '1', $totPag = '1') |
998
|
|
|
{ |
999
|
|
|
$oldX = $x; |
1000
|
|
|
$oldY = $y; |
1001
|
|
|
if ($this->orientacao == 'P') { |
1002
|
|
|
$maxW = $this->wPrint; |
1003
|
|
|
} else { |
1004
|
|
|
if ($pag == 1) { // primeira página |
1005
|
|
|
$maxW = $this->wPrint - $this->wCanhoto; |
1006
|
|
|
} else { // páginas seguintes |
1007
|
|
|
$maxW = $this->wPrint; |
1008
|
|
|
} |
1009
|
|
|
} |
1010
|
|
|
//#################################################################################### |
1011
|
|
|
//coluna esquerda identificação do emitente |
1012
|
|
|
$w = round($maxW*0.41, 0); |
1013
|
|
|
if ($this->orientacao == 'P') { |
1014
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'); |
1015
|
|
|
} else { |
1016
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'); |
1017
|
|
|
} |
1018
|
|
|
$w1 = $w; |
1019
|
|
|
$h=32; |
1020
|
|
|
$oldY += $h; |
1021
|
|
|
$this->pTextBox($x, $y, $w, $h); |
1022
|
|
|
$texto = 'IDENTIFICAÇÃO DO EMITENTE'; |
1023
|
|
|
$this->pTextBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, ''); |
1024
|
|
|
//estabelecer o alinhamento |
1025
|
|
|
//pode ser left L, center C, right R, full logo L |
1026
|
|
|
//se for left separar 1/3 da largura para o tamanho da imagem |
1027
|
|
|
//os outros 2/3 serão usados para os dados do emitente |
1028
|
|
|
//se for center separar 1/2 da altura para o logo e 1/2 para os dados |
1029
|
|
|
//se for right separa 2/3 para os dados e o terço seguinte para o logo |
1030
|
|
|
//se não houver logo centraliza dos dados do emitente |
1031
|
|
|
// coloca o logo |
1032
|
|
|
if (!empty($this->logomarca)) { |
1033
|
|
|
$logoInfo = getimagesize($this->logomarca); |
1034
|
|
|
$type = strtolower(explode('/', $logoInfo['mime'])[1]); |
1035
|
|
|
if ($type == 'png') { |
1036
|
|
|
$this->logomarca = $this->imagePNGtoJPG($this->logomarca); |
1037
|
|
|
$type == 'jpg'; |
1038
|
|
|
} |
1039
|
|
|
//largura da imagem em mm |
1040
|
|
|
$logoWmm = ($logoInfo[0]/72)*25.4; |
1041
|
|
|
//altura da imagem em mm |
1042
|
|
|
$logoHmm = ($logoInfo[1]/72)*25.4; |
1043
|
|
|
if ($this->logoAlign=='L') { |
1044
|
|
|
$nImgW = round($w/3, 0); |
1045
|
|
|
$nImgH = round($logoHmm * ($nImgW/$logoWmm), 0); |
1046
|
|
|
$xImg = $x+1; |
1047
|
|
|
$yImg = round(($h-$nImgH)/2, 0)+$y; |
1048
|
|
|
//estabelecer posições do texto |
1049
|
|
|
$x1 = round($xImg + $nImgW +1, 0); |
1050
|
|
|
$y1 = round($h/3+$y, 0); |
1051
|
|
|
$tw = round(2*$w/3, 0); |
1052
|
|
|
} elseif ($this->logoAlign=='C') { |
1053
|
|
|
$nImgH = round($h/3, 0); |
1054
|
|
|
$nImgW = round($logoWmm * ($nImgH/$logoHmm), 0); |
1055
|
|
|
$xImg = round(($w-$nImgW)/2+$x, 0); |
1056
|
|
|
$yImg = $y+3; |
1057
|
|
|
$x1 = $x; |
1058
|
|
|
$y1 = round($yImg + $nImgH + 1, 0); |
1059
|
|
|
$tw = $w; |
1060
|
|
|
} elseif ($this->logoAlign=='R') { |
1061
|
|
|
$nImgW = round($w/3, 0); |
1062
|
|
|
$nImgH = round($logoHmm * ($nImgW/$logoWmm), 0); |
1063
|
|
|
$xImg = round($x+($w-(1+$nImgW)), 0); |
1064
|
|
|
$yImg = round(($h-$nImgH)/2, 0)+$y; |
1065
|
|
|
$x1 = $x; |
1066
|
|
|
$y1 = round($h/3+$y, 0); |
1067
|
|
|
$tw = round(2*$w/3, 0); |
1068
|
|
|
} elseif ($this->logoAlign=='F') { |
1069
|
|
|
$nImgH = round($h-5, 0); |
1070
|
|
|
$nImgW = round($logoWmm * ($nImgH/$logoHmm), 0); |
1071
|
|
|
$xImg = round(($w-$nImgW)/2+$x, 0); |
1072
|
|
|
$yImg = $y+3; |
1073
|
|
|
$x1 = $x; |
1074
|
|
|
$y1 = round($yImg + $nImgH + 1, 0); |
1075
|
|
|
$tw = $w; |
1076
|
|
|
} |
1077
|
|
|
$type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null; |
1078
|
|
|
$this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, $type); |
|
|
|
|
1079
|
|
|
} else { |
1080
|
|
|
$x1 = $x; |
1081
|
|
|
$y1 = round($h/3+$y, 0); |
1082
|
|
|
$tw = $w; |
1083
|
|
|
} |
1084
|
|
|
// monta as informações apenas se diferente de full logo |
1085
|
|
|
if ($this->logoAlign !== 'F') { |
1086
|
|
|
//Nome emitente |
1087
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'); |
1088
|
|
|
$texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue; |
1089
|
|
|
$this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, ''); |
|
|
|
|
1090
|
|
|
//endereço |
1091
|
|
|
$y1 = $y1+5; |
1092
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>''); |
1093
|
|
|
$fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue) |
1094
|
|
|
? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue |
1095
|
|
|
: ''; |
1096
|
|
|
$lgr = $this->pSimpleGetValue($this->enderEmit, "xLgr"); |
1097
|
|
|
$nro = $this->pSimpleGetValue($this->enderEmit, "nro"); |
1098
|
|
|
$cpl = $this->pSimpleGetValue($this->enderEmit, "xCpl", " - "); |
1099
|
|
|
$bairro = $this->pSimpleGetValue($this->enderEmit, "xBairro"); |
1100
|
|
|
$CEP = $this->pSimpleGetValue($this->enderEmit, "CEP"); |
1101
|
|
|
$CEP = $this->pFormat($CEP, "#####-###"); |
1102
|
|
|
$mun = $this->pSimpleGetValue($this->enderEmit, "xMun"); |
1103
|
|
|
$UF = $this->pSimpleGetValue($this->enderEmit, "UF"); |
1104
|
|
|
$texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - " |
1105
|
|
|
. $CEP . "\n" . $mun . " - " . $UF . " " |
1106
|
|
|
. "Fone/Fax: " . $fone; |
1107
|
|
|
$this->pTextBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, ''); |
1108
|
|
|
} |
1109
|
|
|
|
1110
|
|
|
//#################################################################################### |
1111
|
|
|
//coluna central Danfe |
1112
|
|
|
$x += $w; |
1113
|
|
|
$w=round($maxW * 0.17, 0);//35; |
1114
|
|
|
$w2 = $w; |
1115
|
|
|
$h = 32; |
1116
|
|
|
$this->pTextBox($x, $y, $w, $h); |
1117
|
|
|
|
1118
|
|
|
if (! $this->pNotaCancelada()) { |
1119
|
|
|
// A PRINCIPIO NÃO PRECISAVA, POIS A NFE ESTÁ AUTORIZADA, |
1120
|
|
|
// SÓ SE RETIRA O DANFE PARA NOTAS NÃO AUTORIZADAS |
1121
|
|
|
$texto = "DANFE"; |
1122
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'); |
1123
|
|
|
$this->pTextBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, ''); |
1124
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>''); |
1125
|
|
|
$texto = 'Documento Auxiliar da Nota Fiscal Eletrônica'; |
1126
|
|
|
$h = 20; |
1127
|
|
|
$this->pTextBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false); |
1128
|
|
|
} |
1129
|
|
|
|
1130
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>''); |
1131
|
|
|
$texto = '0 - ENTRADA'; |
1132
|
|
|
$y1 = $y + 14; |
1133
|
|
|
$h = 8; |
1134
|
|
|
$this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
1135
|
|
|
$texto = '1 - SAÍDA'; |
1136
|
|
|
$y1 = $y + 17; |
1137
|
|
|
$this->pTextBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
1138
|
|
|
//tipo de nF |
1139
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'); |
1140
|
|
|
$y1 = $y + 13; |
1141
|
|
|
$h = 7; |
1142
|
|
|
$texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue; |
1143
|
|
|
$this->pTextBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, ''); |
1144
|
|
|
//numero da NF |
1145
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1146
|
|
|
$y1 = $y + 20; |
1147
|
|
|
$numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT); |
1148
|
|
|
$numNF = $this->pFormat($numNF, "###.###.###"); |
1149
|
|
|
$texto = "Nº. " . $numNF; |
1150
|
|
|
$this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1151
|
|
|
//Série |
1152
|
|
|
$y1 = $y + 23; |
1153
|
|
|
$serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT); |
1154
|
|
|
$texto = "Série " . $serie; |
1155
|
|
|
$this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1156
|
|
|
//numero paginas |
1157
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I'); |
1158
|
|
|
$y1 = $y + 26; |
1159
|
|
|
$texto = "Folha " . $pag . "/" . $totPag; |
1160
|
|
|
$this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1161
|
|
|
|
1162
|
|
|
//#################################################################################### |
1163
|
|
|
//coluna codigo de barras |
1164
|
|
|
$x += $w; |
1165
|
|
|
$w = ($maxW-$w1-$w2);//85; |
1166
|
|
|
$w3 = $w; |
1167
|
|
|
$h = 32; |
1168
|
|
|
$this->pTextBox($x, $y, $w, $h); |
1169
|
|
|
$this->pdf->SetFillColor(0, 0, 0); |
1170
|
|
|
$chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id")); |
1171
|
|
|
$bW = 75; |
1172
|
|
|
$bH = 12; |
1173
|
|
|
//codigo de barras |
1174
|
|
|
$this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH); |
1175
|
|
|
//linhas divisorias |
1176
|
|
|
$this->pdf->Line($x, $y+4+$bH, $x+$w, $y+4+$bH); |
1177
|
|
|
$this->pdf->Line($x, $y+12+$bH, $x+$w, $y+12+$bH); |
1178
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1179
|
|
|
$y1 = $y+4+$bH; |
1180
|
|
|
$h = 7; |
1181
|
|
|
$texto = 'CHAVE DE ACESSO'; |
1182
|
|
|
$this->pTextBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
1183
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'); |
1184
|
|
|
$y1 = $y+8+$bH; |
1185
|
|
|
$texto = $this->pFormat($chave_acesso, $this->formatoChave); |
1186
|
|
|
$this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, ''); |
1187
|
|
|
$y1 = $y+12+$bH; |
1188
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>''); |
1189
|
|
|
$chaveContingencia=""; |
1190
|
|
|
if ($this->pNotaDPEC()) { |
1191
|
|
|
$cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC'; |
1192
|
|
|
} else { |
1193
|
|
|
$cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO'; |
1194
|
|
|
} |
1195
|
|
|
if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) { |
1196
|
|
|
$cabecalhoProtoAutorizacao = "DADOS DA NF-E"; |
1197
|
|
|
$chaveContingencia = $this->pGeraChaveAdicionalDeContingencia(); |
1198
|
|
|
$this->pdf->SetFillColor(0, 0, 0); |
1199
|
|
|
//codigo de barras |
1200
|
|
|
$this->pdf->Code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2); |
1201
|
|
|
} else { |
1202
|
|
|
$texto = 'Consulta de autenticidade no portal nacional da NF-e'; |
1203
|
|
|
$this->pTextBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, ''); |
1204
|
|
|
$y1 = $y+16+$bH; |
1205
|
|
|
$texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'; |
1206
|
|
|
$this->pTextBox( |
1207
|
|
|
$x+2, |
1208
|
|
|
$y1, |
1209
|
|
|
$w-2, |
1210
|
|
|
$h, |
1211
|
|
|
$texto, |
1212
|
|
|
$aFont, |
1213
|
|
|
'T', |
1214
|
|
|
'C', |
1215
|
|
|
0, |
1216
|
|
|
'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora' |
1217
|
|
|
); |
1218
|
|
|
} |
1219
|
|
|
|
1220
|
|
|
//#################################################################################### |
1221
|
|
|
//Dados da NF do cabeçalho |
1222
|
|
|
//natureza da operação |
1223
|
|
|
$texto = 'NATUREZA DA OPERAÇÃO'; |
1224
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1225
|
|
|
$w = $w1+$w2; |
1226
|
|
|
$y = $oldY; |
1227
|
|
|
$oldY += $h; |
1228
|
|
|
$x = $oldX; |
1229
|
|
|
$h = 7; |
1230
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1231
|
|
|
$texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue; |
1232
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1233
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1234
|
|
|
$x += $w; |
1235
|
|
|
$w = $w3; |
1236
|
|
|
//PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E |
1237
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1238
|
|
|
$this->pTextBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, ''); |
1239
|
|
|
// algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser |
1240
|
|
|
// testada antes de tentar obter a informação. |
1241
|
|
|
// NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!! |
1242
|
|
|
// Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização. |
1243
|
|
|
// Na minha opinião, deveríamos mostra-lo, mas o manual da NFe v4.01 diz outra coisa... |
1244
|
|
|
if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) { |
1245
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'); |
1246
|
|
|
$texto = $this->pFormat($chaveContingencia, "#### #### #### #### #### #### #### #### ####"); |
1247
|
|
|
$cStat = ''; |
|
|
|
|
1248
|
|
|
} else { |
1249
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1250
|
|
|
if ($this->pNotaDPEC()) { |
1251
|
|
|
$texto = $this->numero_registro_dpec; |
1252
|
|
|
$cStat = ''; |
|
|
|
|
1253
|
|
|
} else { |
1254
|
|
|
if (isset($this->nfeProc)) { |
1255
|
|
|
$texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ? |
1256
|
|
|
$this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : ''; |
1257
|
|
|
$tsHora = $this->pConvertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue); |
1258
|
|
|
if ($texto != '') { |
1259
|
|
|
$texto .= " - " . date('d/m/Y H:i:s', $tsHora); |
1260
|
|
|
} |
1261
|
|
|
$cStat = $this->nfeProc->getElementsByTagName("cStat")->item(0)->nodeValue; |
|
|
|
|
1262
|
|
|
} else { |
1263
|
|
|
$texto = ''; |
1264
|
|
|
$cStat = ''; |
|
|
|
|
1265
|
|
|
} |
1266
|
|
|
} |
1267
|
|
|
} |
1268
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1269
|
|
|
//#################################################################################### |
1270
|
|
|
//INSCRIÇÃO ESTADUAL |
1271
|
|
|
$w = round($maxW * 0.333, 0); |
1272
|
|
|
$y += $h; |
1273
|
|
|
$oldY += $h; |
1274
|
|
|
$x = $oldX; |
1275
|
|
|
$texto = 'INSCRIÇÃO ESTADUAL'; |
1276
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1277
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1278
|
|
|
$texto = $this->pSimpleGetValue($this->emit, "IE"); |
1279
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1280
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1281
|
|
|
//INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT. |
1282
|
|
|
$x += $w; |
1283
|
|
|
$texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.'; |
1284
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1285
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1286
|
|
|
$texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue) |
1287
|
|
|
? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue |
1288
|
|
|
: ''; |
1289
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1290
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1291
|
|
|
//CNPJ |
1292
|
|
|
$x += $w; |
1293
|
|
|
$w = ($maxW-(2*$w)); |
1294
|
|
|
$texto = 'CNPJ / CPF'; |
1295
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1296
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1297
|
|
|
//Pegando valor do CPF/CNPJ |
1298
|
|
|
if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) { |
1299
|
|
|
$texto = $this->pFormat( |
1300
|
|
|
$this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue, |
1301
|
|
|
"###.###.###/####-##" |
1302
|
|
|
); |
1303
|
|
|
} else { |
1304
|
|
|
$texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ? |
1305
|
|
|
$this->pFormat( |
1306
|
|
|
$this->emit->getElementsByTagName("CPF")->item(0)->nodeValue, |
1307
|
|
|
"###.###.###-##" |
1308
|
|
|
) : ''; |
1309
|
|
|
} |
1310
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1311
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1312
|
|
|
|
1313
|
|
|
//#################################################################################### |
1314
|
|
|
//Indicação de NF Homologação, cancelamento e falta de protocolo |
1315
|
|
|
$tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue; |
1316
|
|
|
//indicar cancelamento |
1317
|
|
|
if ($this->pNotaCancelada()) { |
1318
|
|
|
//101 Cancelamento |
1319
|
|
|
$x = 10; |
1320
|
|
|
$y = $this->hPrint-130; |
1321
|
|
|
$h = 25; |
1322
|
|
|
$w = $maxW-(2*$x); |
1323
|
|
|
$this->pdf->SetTextColor(90, 90, 90); |
1324
|
|
|
$texto = "NFe CANCELADA"; |
1325
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'); |
1326
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1327
|
|
|
$this->pdf->SetTextColor(0, 0, 0); |
1328
|
|
|
} |
1329
|
|
|
|
1330
|
|
|
if ($this->pNotaDPEC() || $this->tpEmis == 4) { |
1331
|
|
|
//DPEC |
1332
|
|
|
$x = 10; |
1333
|
|
|
$y = $this->hPrint-130; |
1334
|
|
|
$h = 25; |
1335
|
|
|
$w = $maxW-(2*$x); |
1336
|
|
|
$this->pdf->SetTextColor(200, 200, 200); |
1337
|
|
|
$texto = "DANFE impresso em contingência -\n". |
1338
|
|
|
"DPEC regularmente recebido pela Receita\n". |
1339
|
|
|
"Federal do Brasil"; |
1340
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'); |
1341
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1342
|
|
|
$this->pdf->SetTextColor(0, 0, 0); |
1343
|
|
|
} |
1344
|
|
|
if ($this->pNotaDenegada()) { |
1345
|
|
|
//110 301 302 Denegada |
|
|
|
|
1346
|
|
|
$x = 10; |
1347
|
|
|
$y = $this->hPrint-130; |
1348
|
|
|
$h = 25; |
1349
|
|
|
$w = $maxW-(2*$x); |
1350
|
|
|
$this->pdf->SetTextColor(90, 90, 90); |
1351
|
|
|
$texto = "NFe USO DENEGADO"; |
1352
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'); |
1353
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1354
|
|
|
$y += $h; |
1355
|
|
|
$h = 5; |
1356
|
|
|
$w = $maxW-(2*$x); |
1357
|
|
|
if (isset($this->infProt)) { |
1358
|
|
|
$xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue; |
1359
|
|
|
} else { |
1360
|
|
|
$xMotivo = ''; |
1361
|
|
|
} |
1362
|
|
|
$texto = "SEM VALOR FISCAL\n".$xMotivo; |
1363
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'); |
1364
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1365
|
|
|
$this->pdf->SetTextColor(0, 0, 0); |
1366
|
|
|
} |
1367
|
|
|
//indicar sem valor |
1368
|
|
|
if ($tpAmb != 1) { |
1369
|
|
|
$x = 10; |
1370
|
|
|
if ($this->orientacao == 'P') { |
1371
|
|
|
$y = round($this->hPrint*2/3, 0); |
1372
|
|
|
} else { |
1373
|
|
|
$y = round($this->hPrint/2, 0); |
1374
|
|
|
} |
1375
|
|
|
$h = 5; |
1376
|
|
|
$w = $maxW-(2*$x); |
1377
|
|
|
$this->pdf->SetTextColor(90, 90, 90); |
1378
|
|
|
$texto = "SEM VALOR FISCAL"; |
1379
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'); |
1380
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1381
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'); |
1382
|
|
|
$texto = "AMBIENTE DE HOMOLOGAÇÃO"; |
1383
|
|
|
$this->pTextBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1384
|
|
|
$this->pdf->SetTextColor(0, 0, 0); |
1385
|
|
|
} else { |
1386
|
|
|
$x = 10; |
1387
|
|
|
if ($this->orientacao == 'P') { |
1388
|
|
|
$y = round($this->hPrint*2/3, 0); |
1389
|
|
|
} else { |
1390
|
|
|
$y = round($this->hPrint/2, 0); |
1391
|
|
|
}//fim orientacao |
1392
|
|
|
$h = 5; |
1393
|
|
|
$w = $maxW-(2*$x); |
1394
|
|
|
$this->pdf->SetTextColor(90, 90, 90); |
1395
|
|
|
//indicar FALTA DO PROTOCOLO se NFe não for em contingência |
1396
|
|
|
if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) { |
1397
|
|
|
//Contingência |
1398
|
|
|
$texto = "DANFE Emitido em Contingência"; |
1399
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'); |
1400
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1401
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'); |
1402
|
|
|
$texto = "devido à problemas técnicos"; |
1403
|
|
|
$this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1404
|
|
|
} else { |
1405
|
|
|
if (!isset($this->nfeProc)) { |
1406
|
|
|
if (!$this->pNotaDPEC()) { |
1407
|
|
|
$texto = "SEM VALOR FISCAL"; |
1408
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'); |
1409
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1410
|
|
|
} |
1411
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'); |
1412
|
|
|
$texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ"; |
1413
|
|
|
if (!$this->pNotaDPEC()) { |
1414
|
|
|
$this->pTextBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1415
|
|
|
} else { |
1416
|
|
|
$this->pTextBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, ''); |
1417
|
|
|
} |
1418
|
|
|
}//fim nefProc |
1419
|
|
|
}//fim tpEmis |
1420
|
|
|
$this->pdf->SetTextColor(0, 0, 0); |
1421
|
|
|
} |
1422
|
|
|
return $oldY; |
1423
|
|
|
} //fim cabecalhoDANFE |
1424
|
|
|
|
1425
|
|
|
/** |
1426
|
|
|
* destinatarioDANFE |
1427
|
|
|
* Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem) |
1428
|
|
|
* |
1429
|
|
|
* @name destinatarioDANFE |
1430
|
|
|
* @param number $x Posição horizontal canto esquerdo |
1431
|
|
|
* @param number $y Posição vertical canto superior |
1432
|
|
|
* @return number Posição vertical final |
1433
|
|
|
*/ |
1434
|
|
|
protected function pDestinatarioDANFE($x = 0, $y = 0) |
1435
|
|
|
{ |
1436
|
|
|
//#################################################################################### |
1437
|
|
|
//DESTINATÁRIO / REMETENTE |
1438
|
|
|
$oldX = $x; |
1439
|
|
|
$oldY = $y; |
|
|
|
|
1440
|
|
|
if ($this->orientacao == 'P') { |
1441
|
|
|
$maxW = $this->wPrint; |
1442
|
|
|
} else { |
1443
|
|
|
$maxW = $this->wPrint - $this->wCanhoto; |
1444
|
|
|
} |
1445
|
|
|
$w = $maxW; |
1446
|
|
|
$h = 7; |
1447
|
|
|
$texto = 'DESTINATÁRIO / REMETENTE'; |
1448
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
1449
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
1450
|
|
|
//NOME / RAZÃO SOCIAL |
1451
|
|
|
$w = round($maxW*0.61, 0); |
1452
|
|
|
$w1 = $w; |
1453
|
|
|
$y += 3; |
1454
|
|
|
$texto = 'NOME / RAZÃO SOCIAL'; |
1455
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1456
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1457
|
|
|
$texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue; |
1458
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1459
|
|
|
if ($this->orientacao == 'P') { |
1460
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, ''); |
1461
|
|
|
} else { |
1462
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, ''); |
1463
|
|
|
} |
1464
|
|
|
//CNPJ / CPF |
1465
|
|
|
$x += $w; |
1466
|
|
|
$w = round($maxW*0.23, 0); |
1467
|
|
|
$w2 = $w; |
1468
|
|
|
$texto = 'CNPJ / CPF'; |
1469
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1470
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1471
|
|
|
//Pegando valor do CPF/CNPJ |
1472
|
|
|
if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) { |
1473
|
|
|
$texto = $this->pFormat( |
1474
|
|
|
$this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue, |
1475
|
|
|
"###.###.###/####-##" |
1476
|
|
|
); |
1477
|
|
|
} else { |
1478
|
|
|
$texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ? |
1479
|
|
|
$this->pFormat( |
1480
|
|
|
$this->dest->getElementsByTagName("CPF")->item(0)->nodeValue, |
1481
|
|
|
"###.###.###-##" |
1482
|
|
|
) : ''; |
1483
|
|
|
} |
1484
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1485
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1486
|
|
|
//DATA DA EMISSÃO |
1487
|
|
|
$x += $w; |
1488
|
|
|
$w = $maxW-($w1+$w2); |
1489
|
|
|
$wx = $w; |
1490
|
|
|
$texto = 'DATA DA EMISSÃO'; |
1491
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1492
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1493
|
|
|
$dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ? |
1494
|
|
|
$this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : ''; |
1495
|
|
|
if ($dEmi == '') { |
1496
|
|
|
$dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ? |
1497
|
|
|
$this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : ''; |
1498
|
|
|
$aDemi = explode('T', $dEmi); |
1499
|
|
|
$dEmi = $aDemi[0]; |
1500
|
|
|
} |
1501
|
|
|
$texto = $this->pYmd2dmy($dEmi); |
1502
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1503
|
|
|
if ($this->orientacao == 'P') { |
1504
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1505
|
|
|
} else { |
1506
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, ''); |
1507
|
|
|
} |
1508
|
|
|
//ENDEREÇO |
1509
|
|
|
$w = round($maxW*0.47, 0); |
1510
|
|
|
$w1 = $w; |
1511
|
|
|
$y += $h; |
1512
|
|
|
$x = $oldX; |
1513
|
|
|
$texto = 'ENDEREÇO'; |
1514
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1515
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1516
|
|
|
$texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue; |
1517
|
|
|
$texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue; |
1518
|
|
|
$texto .= $this->pSimpleGetValue($this->dest, "xCpl", " - "); |
1519
|
|
|
|
1520
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1521
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true); |
1522
|
|
|
//BAIRRO / DISTRITO |
1523
|
|
|
$x += $w; |
1524
|
|
|
$w = round($maxW*0.21, 0); |
1525
|
|
|
$w2 = $w; |
1526
|
|
|
$texto = 'BAIRRO / DISTRITO'; |
1527
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1528
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1529
|
|
|
$texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue; |
1530
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1531
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1532
|
|
|
//CEP |
1533
|
|
|
$x += $w; |
1534
|
|
|
$w = $maxW-$w1-$w2-$wx; |
1535
|
|
|
$w2 = $w; |
|
|
|
|
1536
|
|
|
$texto = 'CEP'; |
1537
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1538
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1539
|
|
|
$texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ? |
1540
|
|
|
$this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : ''; |
1541
|
|
|
$texto = $this->pFormat($texto, "#####-###"); |
1542
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1543
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1544
|
|
|
//DATA DA SAÍDA |
1545
|
|
|
$x += $w; |
1546
|
|
|
$w = $wx; |
1547
|
|
|
$texto = 'DATA DA SAÍDA/ENTRADA'; |
1548
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1549
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1550
|
|
|
$dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ? |
1551
|
|
|
$this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : ''; |
1552
|
|
|
if ($dSaiEnt == '') { |
1553
|
|
|
$dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ? |
1554
|
|
|
$this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : ''; |
1555
|
|
|
$aDsaient = explode('T', $dSaiEnt); |
1556
|
|
|
$dSaiEnt = $aDsaient[0]; |
1557
|
|
|
} |
1558
|
|
|
$texto = $this->pYmd2dmy($dSaiEnt); |
1559
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1560
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1561
|
|
|
//MUNICÍPIO |
1562
|
|
|
$w = $w1; |
1563
|
|
|
$y += $h; |
1564
|
|
|
$x = $oldX; |
1565
|
|
|
$texto = 'MUNICÍPIO'; |
1566
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1567
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1568
|
|
|
$texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue; |
1569
|
|
|
if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) { |
1570
|
|
|
$texto .= " - " . $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue; |
1571
|
|
|
} |
1572
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1573
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, ''); |
1574
|
|
|
//UF |
1575
|
|
|
$x += $w; |
1576
|
|
|
$w = 8; |
1577
|
|
|
$texto = 'UF'; |
1578
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1579
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1580
|
|
|
$texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue; |
1581
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1582
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1583
|
|
|
//FONE / FAX |
1584
|
|
|
$x += $w; |
1585
|
|
|
$w = round(($maxW -$w1-$wx-8)/2, 0); |
1586
|
|
|
$w3 = $w; |
1587
|
|
|
$texto = 'FONE / FAX'; |
1588
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1589
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1590
|
|
|
$texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ? |
1591
|
|
|
$this->dest->getElementsByTagName("fone")->item(0)->nodeValue : ''; |
1592
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1593
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1594
|
|
|
//INSCRIÇÃO ESTADUAL |
1595
|
|
|
$x += $w; |
1596
|
|
|
$w = $maxW -$w1-$wx-8-$w3; |
1597
|
|
|
$texto = 'INSCRIÇÃO ESTADUAL'; |
1598
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1599
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1600
|
|
|
$IE = $this->dest->getElementsByTagName("IE"); |
1601
|
|
|
$texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : ''; |
1602
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1603
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1604
|
|
|
//HORA DA SAÍDA |
1605
|
|
|
$x += $w; |
1606
|
|
|
$w = $wx; |
1607
|
|
|
$texto = 'HORA DA SAÍDA/ENTRADA'; |
1608
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1609
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1610
|
|
|
$hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ? |
1611
|
|
|
$this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : ''; |
1612
|
|
|
if ($hSaiEnt == '') { |
1613
|
|
|
$dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ? |
1614
|
|
|
$this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : ''; |
1615
|
|
|
$tsDhSaiEnt = $this->pConvertTime($dhSaiEnt); |
1616
|
|
|
if ($tsDhSaiEnt != '') { |
1617
|
|
|
$hSaiEnt = date('H:i:s', $tsDhSaiEnt); |
1618
|
|
|
} |
1619
|
|
|
} |
1620
|
|
|
$texto = $hSaiEnt; |
1621
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1622
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1623
|
|
|
return ($y + $h); |
1624
|
|
|
} //fim da função destinatarioDANFE |
1625
|
|
|
|
1626
|
|
|
/** |
1627
|
|
|
* pGetTextoFatura |
1628
|
|
|
* Gera a String do Texto da Fatura |
1629
|
|
|
* |
1630
|
|
|
* @name getTextoFatura |
1631
|
|
|
* @return uma String com o texto ou ""; |
1632
|
|
|
*/ |
1633
|
|
|
protected function pGetTextoFatura() |
1634
|
|
|
{ |
1635
|
|
|
if (isset($this->cobr)) { |
1636
|
|
|
$fat = $this->cobr->getElementsByTagName("fat")->item(0); |
1637
|
|
|
if (isset($fat)) { |
1638
|
|
|
if (!empty($this->pSimpleGetValue($this->ide, "indPag"))) { |
1639
|
|
|
$textoIndPag = ""; |
1640
|
|
|
$indPag = $this->pSimpleGetValue($this->ide, "indPag"); |
1641
|
|
|
if ($indPag === "0") { |
1642
|
|
|
$textoIndPag = "Pagamento à Vista - "; |
1643
|
|
|
} elseif ($indPag === "1") { |
1644
|
|
|
$textoIndPag = "Pagamento à Prazo - "; |
1645
|
|
|
} |
1646
|
|
|
$nFat = $this->pSimpleGetValue($fat, "nFat", "Fatura: "); |
1647
|
|
|
$vOrig = $this->pSimpleGetValue($fat, "vOrig", " Valor Original: "); |
1648
|
|
|
$vDesc = $this->pSimpleGetValue($fat, "vDesc", " Desconto: "); |
1649
|
|
|
$vLiq = $this->pSimpleGetValue($fat, "vLiq", " Valor Líquido: "); |
1650
|
|
|
$texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq; |
1651
|
|
|
return $texto; |
1652
|
|
|
} else { |
1653
|
|
|
$pag = $this->dom->getElementsByTagName("pag"); |
1654
|
|
|
if ($tPag = $this->pSimpleGetValue($pag->item(0), "tPag")) { |
1655
|
|
|
return $this->tipoPag($tPag); |
1656
|
|
|
} |
1657
|
|
|
} |
1658
|
|
|
} |
1659
|
|
|
} |
1660
|
|
|
return ""; |
1661
|
|
|
} //fim getTextoFatura |
1662
|
|
|
|
1663
|
|
|
/** |
1664
|
|
|
* pSizeExtraTextoFatura |
1665
|
|
|
* Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata. |
1666
|
|
|
* |
1667
|
|
|
* @name pSizeExtraTextoFatura |
1668
|
|
|
* @return integer |
1669
|
|
|
*/ |
1670
|
|
|
protected function pSizeExtraTextoFatura() |
1671
|
|
|
{ |
1672
|
|
|
$textoFatura = $this->pGetTextoFatura(); |
1673
|
|
|
//verificar se existem duplicatas |
1674
|
|
|
if ($this->dup->length == 0 && $textoFatura !== "") { |
1675
|
|
|
return 10; |
1676
|
|
|
} |
1677
|
|
|
return 0; |
1678
|
|
|
} |
1679
|
|
|
|
1680
|
|
|
/** |
1681
|
|
|
* faturaDANFE |
1682
|
|
|
* Monta o campo de duplicatas da DANFE (retrato e paisagem) |
1683
|
|
|
* |
1684
|
|
|
* @name faturaDANFE |
1685
|
|
|
* @param number $x Posição horizontal canto esquerdo |
1686
|
|
|
* @param number $y Posição vertical canto superior |
1687
|
|
|
* @return number Posição vertical final |
1688
|
|
|
*/ |
1689
|
|
|
protected function pFaturaDANFE($x, $y) |
1690
|
|
|
{ |
1691
|
|
|
$linha = 1; |
1692
|
|
|
$h = 8+3; |
|
|
|
|
1693
|
|
|
$oldx = $x; |
1694
|
|
|
$textoFatura = $this->pGetTextoFatura(); |
1695
|
|
|
//verificar se existem duplicatas |
1696
|
|
|
if ($this->dup->length > 0 || $textoFatura !== "") { |
1697
|
|
|
//##################################################################### |
1698
|
|
|
//FATURA / DUPLICATA |
1699
|
|
|
$texto = "FATURA / DUPLICATA"; |
1700
|
|
|
if ($this->orientacao == 'P') { |
1701
|
|
|
$w = $this->wPrint; |
1702
|
|
|
} else { |
1703
|
|
|
$w = 271; |
1704
|
|
|
} |
1705
|
|
|
$h = 8; |
1706
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
1707
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
1708
|
|
|
$y += 3; |
1709
|
|
|
$dups = ""; |
|
|
|
|
1710
|
|
|
$dupcont = 0; |
1711
|
|
|
$nFat = $this->dup->length; |
|
|
|
|
1712
|
|
|
if ($textoFatura !== "" && $this->exibirTextoFatura) { |
1713
|
|
|
$myH=6; |
1714
|
|
|
$myW = $this->wPrint; |
1715
|
|
|
if ($this->orientacao == 'L') { |
1716
|
|
|
$myW -= $this->wCanhoto; |
1717
|
|
|
} |
1718
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>''); |
1719
|
|
|
$this->pTextBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, ''); |
1720
|
|
|
$y+=$myH+1; |
1721
|
|
|
} |
1722
|
|
|
if ($this->orientacao == 'P') { |
1723
|
|
|
$w = round($this->wPrint/7.018, 0)-1; |
1724
|
|
|
} else { |
1725
|
|
|
$w = 28; |
1726
|
|
|
} |
1727
|
|
|
$increm = 1; |
1728
|
|
|
foreach ($this->dup as $k => $d) { |
1729
|
|
|
$nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ? |
1730
|
|
|
$this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : ''; |
1731
|
|
|
$dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ? |
1732
|
|
|
$this->pYmd2dmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : ''; |
1733
|
|
|
$vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ? |
1734
|
|
|
'R$ ' . number_format( |
1735
|
|
|
$this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue, |
1736
|
|
|
2, |
1737
|
|
|
",", |
1738
|
|
|
"." |
1739
|
|
|
) : ''; |
1740
|
|
|
$h = 8; |
1741
|
|
|
$texto = ''; |
|
|
|
|
1742
|
|
|
if ($nDup!='0' && $nDup!='') { |
1743
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1744
|
|
|
$this->pTextBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, ''); |
1745
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
1746
|
|
|
$this->pTextBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, ''); |
1747
|
|
|
} else { |
1748
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1749
|
|
|
$this->pTextBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, ''); |
1750
|
|
|
} |
1751
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1752
|
|
|
$this->pTextBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, ''); |
1753
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
1754
|
|
|
$this->pTextBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, ''); |
1755
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1756
|
|
|
$this->pTextBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, ''); |
1757
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
1758
|
|
|
$this->pTextBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, ''); |
1759
|
|
|
$x += $w+$increm; |
1760
|
|
|
$dupcont += 1; |
1761
|
|
|
if ($this->orientacao == 'P') { |
1762
|
|
|
$maxDupCont = 6; |
1763
|
|
|
} else { |
1764
|
|
|
$maxDupCont = 8; |
1765
|
|
|
} |
1766
|
|
|
if ($dupcont > $maxDupCont) { |
1767
|
|
|
$y += 9; |
1768
|
|
|
$x = $oldx; |
1769
|
|
|
$dupcont = 0; |
1770
|
|
|
$linha += 1; |
1771
|
|
|
} |
1772
|
|
|
if ($linha == 5) { |
1773
|
|
|
$linha = 4; |
1774
|
|
|
break; |
1775
|
|
|
} |
1776
|
|
|
} |
1777
|
|
|
if ($dupcont == 0) { |
1778
|
|
|
$y -= 9; |
1779
|
|
|
$linha--; |
1780
|
|
|
} |
1781
|
|
|
return ($y+$h); |
1782
|
|
|
} else { |
1783
|
|
|
$linha = 0; |
|
|
|
|
1784
|
|
|
return ($y-2); |
1785
|
|
|
} |
1786
|
|
|
} //fim da função faturaDANFE |
1787
|
|
|
|
1788
|
|
|
/** |
1789
|
|
|
* impostoDanfeHelper |
1790
|
|
|
* Auxilia a montagem dos campos de impostos e totais da DANFE |
1791
|
|
|
* |
1792
|
|
|
* @name impostoDanfeHelper |
1793
|
|
|
* @param float $x Posição horizontal canto esquerdo |
1794
|
|
|
* @param float $y Posição vertical canto superior |
1795
|
|
|
* @param float $w Largura do campo |
1796
|
|
|
* @param float $h Altura do campo |
1797
|
|
|
* @param float $h Título do campo |
1798
|
|
|
* @param float $h Valor do imposto |
1799
|
|
|
* @return float Sugestão do $x do próximo imposto |
1800
|
|
|
*/ |
1801
|
|
|
protected function pImpostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto) |
1802
|
|
|
{ |
1803
|
|
|
$valorImposto = '0, 00'; |
1804
|
|
|
$the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0); |
1805
|
|
|
if (isset($the_field)) { |
1806
|
|
|
$the_value = $the_field->nodeValue; |
1807
|
|
|
if (!empty($the_value)) { |
1808
|
|
|
$valorImposto = number_format($the_value, 2, ",", "."); |
1809
|
|
|
} |
1810
|
|
|
} |
1811
|
|
|
|
1812
|
|
|
$fontTitulo = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1813
|
|
|
$fontValor = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1814
|
|
|
$this->pTextBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, ''); |
1815
|
|
|
$this->pTextBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, ''); |
1816
|
|
|
|
1817
|
|
|
$next_x = $x + $w; |
1818
|
|
|
return $next_x; |
1819
|
|
|
} |
1820
|
|
|
|
1821
|
|
|
/** |
1822
|
|
|
* impostoDANFE |
1823
|
|
|
* Monta o campo de impostos e totais da DANFE (retrato e paisagem) |
1824
|
|
|
* |
1825
|
|
|
* @param number $x Posição horizontal canto esquerdo |
1826
|
|
|
* @param number $y Posição vertical canto superior |
1827
|
|
|
* @return number Posição vertical final |
1828
|
|
|
*/ |
1829
|
|
|
protected function pImpostoDANFE($x, $y) |
1830
|
|
|
{ |
1831
|
|
|
$x_inicial = $x; |
1832
|
|
|
//##################################################################### |
1833
|
|
|
|
1834
|
|
|
|
1835
|
|
|
$campos_por_linha = 9; |
1836
|
|
|
if (!$this->exibirPIS) { |
1837
|
|
|
$campos_por_linha--; |
1838
|
|
|
} |
1839
|
|
|
if (!$this->exibirIcmsInterestadual) { |
1840
|
|
|
$campos_por_linha -= 2; |
1841
|
|
|
} |
1842
|
|
|
|
1843
|
|
|
if ($this->orientacao == 'P') { |
1844
|
|
|
$maxW = $this->wPrint; |
1845
|
|
|
$title_size = 31; |
1846
|
|
|
} else { |
1847
|
|
|
$maxW = $this->wPrint - $this->wCanhoto; |
1848
|
|
|
$title_size = 40; |
1849
|
|
|
} |
1850
|
|
|
$w = $maxW / $campos_por_linha; |
1851
|
|
|
|
1852
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
1853
|
|
|
$texto = "CÁLCULO DO IMPOSTO"; |
1854
|
|
|
$this->pTextBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, ''); |
1855
|
|
|
$y += 3; |
1856
|
|
|
$h = 7; |
1857
|
|
|
|
1858
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC"); |
1859
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS"); |
1860
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST"); |
1861
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST"); |
1862
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII"); |
1863
|
|
|
|
1864
|
|
|
if ($this->exibirIcmsInterestadual) { |
1865
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet"); |
1866
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FCP", "vFCPUFDest"); |
1867
|
|
|
} |
1868
|
|
|
|
1869
|
|
|
if ($this->exibirPIS) { |
1870
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS"); |
1871
|
|
|
} |
1872
|
|
|
|
1873
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd"); |
|
|
|
|
1874
|
|
|
|
1875
|
|
|
// |
1876
|
|
|
|
1877
|
|
|
$y += $h; |
1878
|
|
|
$x = $x_inicial; |
1879
|
|
|
|
1880
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete"); |
1881
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg"); |
1882
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc"); |
1883
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro"); |
1884
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI"); |
1885
|
|
|
|
1886
|
|
|
if ($this->exibirIcmsInterestadual) { |
1887
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest"); |
1888
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib"); |
1889
|
|
|
} |
1890
|
|
|
|
1891
|
|
|
if ($this->exibirPIS) { |
1892
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS"); |
1893
|
|
|
} |
1894
|
|
|
$x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF"); |
|
|
|
|
1895
|
|
|
|
1896
|
|
|
return ($y+$h); |
1897
|
|
|
} //fim impostoDANFE |
1898
|
|
|
|
1899
|
|
|
/** |
1900
|
|
|
* transporteDANFE |
1901
|
|
|
* Monta o campo de transportes da DANFE (retrato e paisagem) |
1902
|
|
|
* |
1903
|
|
|
* @name transporteDANFE |
1904
|
|
|
* @param float $x Posição horizontal canto esquerdo |
1905
|
|
|
* @param float $y Posição vertical canto superior |
1906
|
|
|
* @return float Posição vertical final |
1907
|
|
|
*/ |
1908
|
|
|
protected function pTransporteDANFE($x, $y) |
1909
|
|
|
{ |
1910
|
|
|
$oldX = $x; |
1911
|
|
|
if ($this->orientacao == 'P') { |
1912
|
|
|
$maxW = $this->wPrint; |
1913
|
|
|
} else { |
1914
|
|
|
$maxW = $this->wPrint - $this->wCanhoto; |
1915
|
|
|
} |
1916
|
|
|
//##################################################################### |
1917
|
|
|
//TRANSPORTADOR / VOLUMES TRANSPORTADOS |
1918
|
|
|
$texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS"; |
1919
|
|
|
$w = $maxW; |
1920
|
|
|
$h = 7; |
1921
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
1922
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
1923
|
|
|
//NOME / RAZÃO SOCIAL |
1924
|
|
|
$w1 = $maxW*0.29; |
1925
|
|
|
$y += 3; |
1926
|
|
|
$texto = 'NOME / RAZÃO SOCIAL'; |
1927
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1928
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1929
|
|
|
if (isset($this->transporta)) { |
1930
|
|
|
$texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ? |
1931
|
|
|
$this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : ''; |
1932
|
|
|
} else { |
1933
|
|
|
$texto = ''; |
1934
|
|
|
} |
1935
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1936
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, ''); |
1937
|
|
|
//FRETE POR CONTA |
1938
|
|
|
$x += $w1; |
1939
|
|
|
$w2 = $maxW*0.15; |
1940
|
|
|
$texto = 'FRETE'; |
1941
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1942
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1943
|
|
|
$tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ? |
1944
|
|
|
$this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0'; |
1945
|
|
|
switch ($tipoFrete) { |
1946
|
|
|
case 0: |
1947
|
|
|
$texto = "0-Por conta do Rem"; |
1948
|
|
|
break; |
1949
|
|
|
case 1: |
1950
|
|
|
$texto = "1-Por conta do Dest"; |
1951
|
|
|
break; |
1952
|
|
|
case 2: |
1953
|
|
|
$texto = "2-Por conta de Terceiros"; |
1954
|
|
|
break; |
1955
|
|
|
case 3: |
1956
|
|
|
$texto = "3-Próprio por conta do Rem"; |
1957
|
|
|
break; |
1958
|
|
|
case 4: |
1959
|
|
|
$texto = "4-Próprio por conta do Dest"; |
1960
|
|
|
break; |
1961
|
|
|
case 9: |
1962
|
|
|
$texto = "9-Sem Transporte"; |
1963
|
|
|
break; |
1964
|
|
|
} |
1965
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1966
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, ''); |
1967
|
|
|
//CÓDIGO ANTT |
1968
|
|
|
$x += $w2; |
1969
|
|
|
$texto = 'CÓDIGO ANTT'; |
1970
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1971
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1972
|
|
|
if (isset($this->veicTransp)) { |
1973
|
|
|
$texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ? |
1974
|
|
|
$this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : ''; |
1975
|
|
|
} else { |
1976
|
|
|
$texto = ''; |
1977
|
|
|
} |
1978
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1979
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1980
|
|
|
//PLACA DO VEÍC |
1981
|
|
|
$x += $w2; |
1982
|
|
|
$texto = 'PLACA DO VEÍCULO'; |
1983
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
1984
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, ''); |
1985
|
|
|
if (isset($this->veicTransp)) { |
1986
|
|
|
$texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ? |
1987
|
|
|
$this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : ''; |
1988
|
|
|
} elseif (isset($this->reboque)) { |
1989
|
|
|
$texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ? |
1990
|
|
|
$this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : ''; |
1991
|
|
|
} else { |
1992
|
|
|
$texto = ''; |
1993
|
|
|
} |
1994
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
1995
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, ''); |
1996
|
|
|
//UF |
1997
|
|
|
$x += $w2; |
1998
|
|
|
$w3 = round($maxW*0.04, 0); |
1999
|
|
|
$texto = 'UF'; |
2000
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2001
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2002
|
|
|
if (isset($this->veicTransp)) { |
2003
|
|
|
$texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ? |
2004
|
|
|
$this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : ''; |
2005
|
|
|
} elseif (isset($this->reboque)) { |
2006
|
|
|
$texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ? |
2007
|
|
|
$this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : ''; |
2008
|
|
|
} else { |
2009
|
|
|
$texto = ''; |
2010
|
|
|
} |
2011
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2012
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2013
|
|
|
//CNPJ / CPF |
2014
|
|
|
$x += $w3; |
2015
|
|
|
$w = $maxW-($w1+3*$w2+$w3); |
2016
|
|
|
$texto = 'CNPJ / CPF'; |
2017
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2018
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2019
|
|
|
if (isset($this->transporta)) { |
2020
|
|
|
$texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ? |
2021
|
|
|
$this->pFormat( |
2022
|
|
|
$this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue, |
2023
|
|
|
"##.###.###/####-##" |
2024
|
|
|
) : ''; |
2025
|
|
|
if ($texto == '') { |
2026
|
|
|
$texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ? |
2027
|
|
|
$this->pFormat( |
2028
|
|
|
$this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue, |
2029
|
|
|
"###.###.###-##" |
2030
|
|
|
) : ''; |
2031
|
|
|
} |
2032
|
|
|
} else { |
2033
|
|
|
$texto = ''; |
2034
|
|
|
} |
2035
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2036
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2037
|
|
|
//##################################################################### |
2038
|
|
|
//ENDEREÇO |
2039
|
|
|
$y += $h; |
2040
|
|
|
$x = $oldX; |
2041
|
|
|
$h = 7; |
2042
|
|
|
$w1 = $maxW*0.44; |
2043
|
|
|
$texto = 'ENDEREÇO'; |
2044
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2045
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2046
|
|
|
if (isset($this->transporta)) { |
2047
|
|
|
$texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ? |
2048
|
|
|
$this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : ''; |
2049
|
|
|
} else { |
2050
|
|
|
$texto = ''; |
2051
|
|
|
} |
2052
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2053
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, ''); |
2054
|
|
|
//MUNICÍPIO |
2055
|
|
|
$x += $w1; |
2056
|
|
|
$w2 = round($maxW*0.30, 0); |
2057
|
|
|
$texto = 'MUNICÍPIO'; |
2058
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2059
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2060
|
|
|
if (isset($this->transporta)) { |
2061
|
|
|
$texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ? |
2062
|
|
|
$this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : ''; |
2063
|
|
|
} else { |
2064
|
|
|
$texto = ''; |
2065
|
|
|
} |
2066
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2067
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2068
|
|
|
//UF |
2069
|
|
|
$x += $w2; |
2070
|
|
|
$w3 = round($maxW*0.04, 0); |
2071
|
|
|
$texto = 'UF'; |
2072
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2073
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2074
|
|
|
if (isset($this->transporta)) { |
2075
|
|
|
$texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ? |
2076
|
|
|
$this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : ''; |
2077
|
|
|
} else { |
2078
|
|
|
$texto = ''; |
2079
|
|
|
} |
2080
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2081
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2082
|
|
|
//INSCRIÇÃO ESTADUAL |
2083
|
|
|
$x += $w3; |
2084
|
|
|
$w = $maxW-($w1+$w2+$w3); |
2085
|
|
|
$texto = 'INSCRIÇÃO ESTADUAL'; |
2086
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2087
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2088
|
|
|
$texto = ''; |
2089
|
|
|
if (isset($this->transporta)) { |
2090
|
|
|
if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) { |
2091
|
|
|
$texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue; |
2092
|
|
|
} |
2093
|
|
|
} |
2094
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2095
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2096
|
|
|
//Tratar Multiplos volumes |
2097
|
|
|
$volumes = $this->transp->getElementsByTagName('vol'); |
2098
|
|
|
$quantidade = 0; |
2099
|
|
|
$especie = ''; |
2100
|
|
|
$marca = ''; |
2101
|
|
|
$numero = ''; |
2102
|
|
|
$texto = ''; |
|
|
|
|
2103
|
|
|
$pesoBruto=0; |
2104
|
|
|
$pesoLiquido=0; |
2105
|
|
|
foreach ($volumes as $volume) { |
2106
|
|
|
$quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ? |
2107
|
|
|
$volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0; |
2108
|
|
|
$pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ? |
2109
|
|
|
$volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0; |
2110
|
|
|
$pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ? |
2111
|
|
|
$volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0; |
2112
|
|
|
$texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ? |
2113
|
|
|
$this->transp->getElementsByTagName("esp")->item(0)->nodeValue : ''; |
2114
|
|
|
if ($texto != $especie && $especie != '') { |
2115
|
|
|
//tem várias especies |
2116
|
|
|
$especie = 'VARIAS'; |
2117
|
|
|
} else { |
2118
|
|
|
$especie = $texto; |
2119
|
|
|
} |
2120
|
|
|
$texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ? |
2121
|
|
|
$this->transp->getElementsByTagName("marca")->item(0)->nodeValue : ''; |
2122
|
|
|
if ($texto != $marca && $marca != '') { |
2123
|
|
|
//tem várias especies |
2124
|
|
|
$marca = 'VARIAS'; |
2125
|
|
|
} else { |
2126
|
|
|
$marca = $texto; |
2127
|
|
|
} |
2128
|
|
|
$texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ? |
2129
|
|
|
$this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : ''; |
2130
|
|
|
if ($texto != $numero && $numero != '') { |
2131
|
|
|
//tem várias especies |
2132
|
|
|
$numero = 'VARIOS'; |
2133
|
|
|
} else { |
2134
|
|
|
$numero = $texto; |
2135
|
|
|
} |
2136
|
|
|
} |
2137
|
|
|
|
2138
|
|
|
//##################################################################### |
2139
|
|
|
//QUANTIDADE |
2140
|
|
|
$y += $h; |
2141
|
|
|
$x = $oldX; |
2142
|
|
|
$h = 7; |
2143
|
|
|
$w1 = round($maxW*0.10, 0); |
2144
|
|
|
$texto = 'QUANTIDADE'; |
2145
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2146
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2147
|
|
|
if (!empty($quantidade)) { |
2148
|
|
|
$texto = $quantidade; |
2149
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2150
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2151
|
|
|
} |
2152
|
|
|
//ESPÉCIE |
2153
|
|
|
$x += $w1; |
2154
|
|
|
$w2 = round($maxW*0.17, 0); |
2155
|
|
|
$texto = 'ESPÉCIE'; |
2156
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2157
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2158
|
|
|
$texto = $especie; |
2159
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2160
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2161
|
|
|
//MARCA |
2162
|
|
|
$x += $w2; |
2163
|
|
|
$texto = 'MARCA'; |
2164
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2165
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2166
|
|
|
$texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ? |
2167
|
|
|
$this->transp->getElementsByTagName("marca")->item(0)->nodeValue : ''; |
2168
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2169
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2170
|
|
|
//NUMERAÇÃO |
2171
|
|
|
$x += $w2; |
2172
|
|
|
$texto = 'NUMERAÇÃO'; |
2173
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2174
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2175
|
|
|
$texto = $numero; |
2176
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2177
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, ''); |
2178
|
|
|
//PESO BRUTO |
2179
|
|
|
$x += $w2; |
2180
|
|
|
$w3 = round($maxW*0.20, 0); |
2181
|
|
|
$texto = 'PESO BRUTO'; |
2182
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2183
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2184
|
|
|
if (is_numeric($pesoBruto) && $pesoBruto > 0) { |
2185
|
|
|
$texto = number_format($pesoBruto, 3, ",", "."); |
2186
|
|
|
} else { |
2187
|
|
|
$texto = ''; |
2188
|
|
|
} |
2189
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2190
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, ''); |
2191
|
|
|
//PESO LÍQUIDO |
2192
|
|
|
$x += $w3; |
2193
|
|
|
$w = $maxW -($w1+3*$w2+$w3); |
2194
|
|
|
$texto = 'PESO LÍQUIDO'; |
2195
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2196
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2197
|
|
|
if (is_numeric($pesoLiquido) && $pesoLiquido > 0) { |
2198
|
|
|
$texto = number_format($pesoLiquido, 3, ",", "."); |
2199
|
|
|
} else { |
2200
|
|
|
$texto = ''; |
2201
|
|
|
} |
2202
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2203
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, ''); |
2204
|
|
|
return ($y+$h); |
2205
|
|
|
} //fim transporteDANFE |
2206
|
|
|
|
2207
|
|
|
|
2208
|
|
|
|
2209
|
|
|
protected function pDescricaoProdutoHelper($origem, $campo, $formato) |
2210
|
|
|
{ |
2211
|
|
|
$valor_original = $origem->getElementsByTagName($campo)->item(0); |
2212
|
|
|
if (!isset($valor_original)) { |
2213
|
|
|
return ""; |
2214
|
|
|
} |
2215
|
|
|
$valor_original = $valor_original->nodeValue; |
2216
|
|
|
$valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : ''; |
2217
|
|
|
|
2218
|
|
|
if ($valor != "") { |
2219
|
|
|
return sprintf($formato, $valor); |
2220
|
|
|
} |
2221
|
|
|
return ""; |
2222
|
|
|
} |
2223
|
|
|
|
2224
|
|
|
/** |
2225
|
|
|
* descricaoProduto |
2226
|
|
|
* Monta a string de descrição de cada Produto |
2227
|
|
|
* |
2228
|
|
|
* @name descricaoProduto |
2229
|
|
|
* @param DOMNode itemProd |
2230
|
|
|
* @return string descricao do produto |
2231
|
|
|
*/ |
2232
|
|
|
protected function pDescricaoProduto($itemProd) |
2233
|
|
|
{ |
2234
|
|
|
$prod = $itemProd->getElementsByTagName('prod')->item(0); |
2235
|
|
|
$ICMS = $itemProd->getElementsByTagName("ICMS")->item(0); |
2236
|
|
|
$ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0); |
2237
|
|
|
$impostos = ''; |
2238
|
|
|
|
2239
|
|
|
if (!empty($ICMS)) { |
2240
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%"); |
2241
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%"); |
2242
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%"); |
2243
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s"); |
2244
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s"); |
2245
|
|
|
} |
2246
|
|
|
if (!empty($ICMSUFDest)) { |
2247
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%"); |
2248
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%"); |
2249
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%"); |
2250
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s"); |
2251
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s"); |
2252
|
|
|
$impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s"); |
2253
|
|
|
} |
2254
|
|
|
$infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue) ? |
2255
|
|
|
substr($this->pAnfavea($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue), 0, 500) : ''; |
2256
|
|
|
if (! empty($infAdProd)) { |
2257
|
|
|
$infAdProd = trim($infAdProd); |
2258
|
|
|
$infAdProd .= ' '; |
2259
|
|
|
} |
2260
|
|
|
$loteTxt =''; |
2261
|
|
|
$rastro = $prod->getElementsByTagName("med"); |
2262
|
|
|
if (!isset($rastro)) { |
2263
|
|
|
$rastro = $prod->getElementsByTagName("rastro"); |
2264
|
|
|
} |
2265
|
|
|
if (isset($rastro)) { |
2266
|
|
|
$i = 0; |
2267
|
|
|
while ($i < $rastro->length) { |
2268
|
|
|
$loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'nLote', ' Lote: '); |
2269
|
|
|
$loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'qLote', ' Quant: '); |
2270
|
|
|
$loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dFab', ' Fab: '); |
2271
|
|
|
$loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dVal', ' Val: '); |
2272
|
|
|
$loteTxt .= $this->pSimpleGetValue($rastro->item($i), 'vPMC', ' PMC: '); |
2273
|
|
|
$i++; |
2274
|
|
|
} |
2275
|
|
|
if ($loteTxt != '') { |
2276
|
|
|
$loteTxt.= ' '; |
2277
|
|
|
} |
2278
|
|
|
} |
2279
|
|
|
//NT2013.006 FCI |
2280
|
|
|
$nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ? |
2281
|
|
|
' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : ''; |
2282
|
|
|
$tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : ''); |
2283
|
|
|
$texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n ".$tmp_ad:''); |
2284
|
|
|
if ($this->descProdQuebraLinha) { |
2285
|
|
|
$texto = str_replace(";", "\n", $texto); |
2286
|
|
|
} |
2287
|
|
|
return $texto; |
2288
|
|
|
} |
2289
|
|
|
|
2290
|
|
|
/** |
2291
|
|
|
* itensDANFE |
2292
|
|
|
* Monta o campo de itens da DANFE (retrato e paisagem) |
2293
|
|
|
* |
2294
|
|
|
* @name itensDANFE |
2295
|
|
|
* @param float $x Posição horizontal canto esquerdo |
2296
|
|
|
* @param float $y Posição vertical canto superior |
2297
|
|
|
* @param float $nInicio Número do item inicial |
2298
|
|
|
* @param float $max Número do item final |
|
|
|
|
2299
|
|
|
* @param float $hmax Altura máxima do campo de itens em mm |
2300
|
|
|
* @return float Posição vertical final |
2301
|
|
|
*/ |
2302
|
|
|
protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7) |
2303
|
|
|
{ |
2304
|
|
|
$oldX = $x; |
2305
|
|
|
$oldY = $y; |
2306
|
|
|
$totItens = $this->det->length; |
2307
|
|
|
//##################################################################### |
2308
|
|
|
//DADOS DOS PRODUTOS / SERVIÇOS |
2309
|
|
|
$texto = "DADOS DOS PRODUTOS / SERVIÇOS "; |
2310
|
|
|
if ($this->orientacao == 'P') { |
2311
|
|
|
$w = $this->wPrint; |
2312
|
|
|
} else { |
2313
|
|
|
if ($nInicio < 2) { // primeira página |
2314
|
|
|
$w = $this->wPrint - $this->wCanhoto; |
2315
|
|
|
} else { // páginas seguintes |
2316
|
|
|
$w = $this->wPrint; |
2317
|
|
|
} |
2318
|
|
|
} |
2319
|
|
|
$h = 4; |
2320
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
2321
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
2322
|
|
|
$y += 3; |
2323
|
|
|
//desenha a caixa dos dados dos itens da NF |
2324
|
|
|
$hmax += 1; |
2325
|
|
|
$texto = ''; |
|
|
|
|
2326
|
|
|
$this->pTextBox($x, $y, $w, $hmax); |
2327
|
|
|
//################################################################################## |
2328
|
|
|
// cabecalho LOOP COM OS DADOS DOS PRODUTOS |
2329
|
|
|
//CÓDIGO PRODUTO |
2330
|
|
|
$texto = "CÓDIGO PRODUTO"; |
2331
|
|
|
$w1 = round($w*0.09, 0); |
2332
|
|
|
$h = 4; |
2333
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2334
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2335
|
|
|
$this->pdf->Line($x+$w1, $y, $x+$w1, $y+$hmax); |
2336
|
|
|
//DESCRIÇÃO DO PRODUTO / SERVIÇO |
2337
|
|
|
$x += $w1; |
2338
|
|
|
$w2 = round($w*0.28, 0); |
2339
|
|
|
$texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO'; |
2340
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2341
|
|
|
$this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2342
|
|
|
$this->pdf->Line($x+$w2, $y, $x+$w2, $y+$hmax); |
2343
|
|
|
//NCM/SH |
2344
|
|
|
$x += $w2; |
2345
|
|
|
$w3 = round($w*0.06, 0); |
2346
|
|
|
$texto = 'NCM/SH'; |
2347
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2348
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2349
|
|
|
$this->pdf->Line($x+$w3, $y, $x+$w3, $y+$hmax); |
2350
|
|
|
//O/CST ou O/CSOSN |
2351
|
|
|
$x += $w3; |
2352
|
|
|
$w4 = round($w*0.05, 0); |
2353
|
|
|
$texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2 |
2354
|
|
|
if ($this->pSimpleGetValue($this->emit, 'CRT') == '3') { |
2355
|
|
|
$texto = 'O/CST';//Regime Normal |
2356
|
|
|
} |
2357
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2358
|
|
|
$this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2359
|
|
|
$this->pdf->Line($x+$w4, $y, $x+$w4, $y+$hmax); |
2360
|
|
|
//CFOP |
2361
|
|
|
$x += $w4; |
2362
|
|
|
$w5 = round($w*0.04, 0); |
2363
|
|
|
$texto = 'CFOP'; |
2364
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2365
|
|
|
$this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2366
|
|
|
$this->pdf->Line($x+$w5, $y, $x+$w5, $y+$hmax); |
2367
|
|
|
//UN |
2368
|
|
|
$x += $w5; |
2369
|
|
|
$w6 = round($w*0.03, 0); |
2370
|
|
|
$texto = 'UN'; |
2371
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2372
|
|
|
$this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2373
|
|
|
$this->pdf->Line($x+$w6, $y, $x+$w6, $y+$hmax); |
2374
|
|
|
//QUANT |
2375
|
|
|
$x += $w6; |
2376
|
|
|
$w7 = round($w*0.07, 0); |
2377
|
|
|
$texto = 'QUANT'; |
2378
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2379
|
|
|
$this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2380
|
|
|
$this->pdf->Line($x+$w7, $y, $x+$w7, $y+$hmax); |
2381
|
|
|
//VALOR UNIT |
2382
|
|
|
$x += $w7; |
2383
|
|
|
$w8 = round($w*0.06, 0); |
2384
|
|
|
$texto = 'VALOR UNIT'; |
2385
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2386
|
|
|
$this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2387
|
|
|
$this->pdf->Line($x+$w8, $y, $x+$w8, $y+$hmax); |
2388
|
|
|
//VALOR TOTAL |
2389
|
|
|
$x += $w8; |
2390
|
|
|
$w9 = round($w*0.06, 0); |
2391
|
|
|
$texto = 'VALOR TOTAL'; |
2392
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2393
|
|
|
$this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2394
|
|
|
$this->pdf->Line($x+$w9, $y, $x+$w9, $y+$hmax); |
2395
|
|
|
//B.CÁLC ICMS |
2396
|
|
|
$x += $w9; |
2397
|
|
|
$w10 = round($w*0.06, 0); |
2398
|
|
|
$texto = 'B.CÁLC ICMS'; |
2399
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2400
|
|
|
$this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2401
|
|
|
$this->pdf->Line($x+$w10, $y, $x+$w10, $y+$hmax); |
2402
|
|
|
//VALOR ICMS |
2403
|
|
|
$x += $w10; |
2404
|
|
|
$w11 = round($w*0.06, 0); |
2405
|
|
|
$texto = 'VALOR ICMS'; |
2406
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2407
|
|
|
$this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2408
|
|
|
$this->pdf->Line($x+$w11, $y, $x+$w11, $y+$hmax); |
2409
|
|
|
//VALOR IPI |
2410
|
|
|
$x += $w11; |
2411
|
|
|
$w12 = round($w*0.05, 0); |
2412
|
|
|
$texto = 'VALOR IPI'; |
2413
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2414
|
|
|
$this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2415
|
|
|
$this->pdf->Line($x+$w12, $y, $x+$w12, $y+$hmax); |
2416
|
|
|
//ALÍQ. ICMS |
2417
|
|
|
$x += $w12; |
2418
|
|
|
$w13 = round($w*0.035, 0); |
2419
|
|
|
$texto = 'ALÍQ. ICMS'; |
2420
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2421
|
|
|
$this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2422
|
|
|
$this->pdf->Line($x+$w13, $y, $x+$w13, $y+$hmax); |
2423
|
|
|
//ALÍQ. IPI |
2424
|
|
|
$x += $w13; |
2425
|
|
|
$w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13); |
2426
|
|
|
$texto = 'ALÍQ. IPI'; |
2427
|
|
|
$this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false); |
2428
|
|
|
$this->pdf->Line($oldX, $y+$h+1, $oldX + $w, $y+$h+1); |
2429
|
|
|
$y += 5; |
2430
|
|
|
//################################################################################## |
2431
|
|
|
// LOOP COM OS DADOS DOS PRODUTOS |
2432
|
|
|
$i = 0; |
2433
|
|
|
$hUsado = $hCabecItens; |
2434
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
2435
|
|
|
foreach ($this->det as $d) { |
2436
|
|
|
if ($i >= $nInicio) { |
2437
|
|
|
$thisItem = $this->det->item($i); |
2438
|
|
|
//carrega as tags do item |
2439
|
|
|
$prod = $thisItem->getElementsByTagName("prod")->item(0); |
2440
|
|
|
$imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0); |
2441
|
|
|
$ICMS = $imposto->getElementsByTagName("ICMS")->item(0); |
2442
|
|
|
$IPI = $imposto->getElementsByTagName("IPI")->item(0); |
2443
|
|
|
$textoProduto = $this->pDescricaoProduto($thisItem); |
2444
|
|
|
$linhaDescr = $this->pGetNumLines($textoProduto, $w2, $aFont); |
2445
|
|
|
$h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2); |
2446
|
|
|
$hUsado += $h; |
2447
|
|
|
if ($pag != $totpag) { |
2448
|
|
|
if ($hUsado >= $hmax && $i < $totItens) { |
2449
|
|
|
//ultrapassa a capacidade para uma única página |
2450
|
|
|
//o restante dos dados serão usados nas proximas paginas |
2451
|
|
|
$nInicio = $i; |
2452
|
|
|
break; |
2453
|
|
|
} |
2454
|
|
|
} |
2455
|
|
|
$y_linha=$y+$h; |
2456
|
|
|
// linha entre itens |
2457
|
|
|
$this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120); |
2458
|
|
|
//corrige o x |
2459
|
|
|
$x=$oldX; |
2460
|
|
|
//codigo do produto |
2461
|
|
|
$texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue; |
2462
|
|
|
$this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, ''); |
2463
|
|
|
$x += $w1; |
2464
|
|
|
//DESCRIÇÃO |
2465
|
|
|
if ($this->orientacao == 'P') { |
2466
|
|
|
$this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false); |
2467
|
|
|
} else { |
2468
|
|
|
$this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false); |
2469
|
|
|
} |
2470
|
|
|
$x += $w2; |
2471
|
|
|
//NCM |
2472
|
|
|
$texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ? |
2473
|
|
|
$prod->getElementsByTagName("NCM")->item(0)->nodeValue : ''; |
2474
|
|
|
$this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, ''); |
2475
|
|
|
$x += $w3; |
2476
|
|
|
//CST |
2477
|
|
|
if (isset($ICMS)) { |
2478
|
|
|
$origem = $this->pSimpleGetValue($ICMS, "orig"); |
2479
|
|
|
$cst = $this->pSimpleGetValue($ICMS, "CST"); |
2480
|
|
|
$csosn = $this->pSimpleGetValue($ICMS, "CSOSN"); |
2481
|
|
|
$texto = $origem.$cst.$csosn; |
2482
|
|
|
$this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, ''); |
2483
|
|
|
} |
2484
|
|
|
//CFOP |
2485
|
|
|
$x += $w4; |
2486
|
|
|
$texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue; |
2487
|
|
|
$this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, ''); |
2488
|
|
|
//Unidade |
2489
|
|
|
$x += $w5; |
2490
|
|
|
$texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue; |
2491
|
|
|
$this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, ''); |
2492
|
|
|
$x += $w6; |
2493
|
|
|
if ($this->orientacao == 'P') { |
2494
|
|
|
$alinhamento = 'R'; |
2495
|
|
|
} else { |
2496
|
|
|
$alinhamento = 'R'; |
2497
|
|
|
} |
2498
|
|
|
// QTDADE |
2499
|
|
|
$texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", "."); |
2500
|
|
|
$this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); |
2501
|
|
|
$x += $w7; |
2502
|
|
|
// Valor Unitário |
2503
|
|
|
$texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", "."); |
2504
|
|
|
$this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); |
2505
|
|
|
$x += $w8; |
2506
|
|
|
// Valor do Produto |
2507
|
|
|
$texto = ""; |
2508
|
|
|
if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) { |
2509
|
|
|
$texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", "."); |
2510
|
|
|
} |
2511
|
|
|
$this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); |
2512
|
|
|
//Valor da Base de calculo |
2513
|
|
|
$x += $w9; |
2514
|
|
|
if (isset($ICMS)) { |
2515
|
|
|
$texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ? |
2516
|
|
|
number_format( |
2517
|
|
|
$ICMS->getElementsByTagName("vBC")->item(0)->nodeValue, |
2518
|
|
|
2, |
2519
|
|
|
",", |
2520
|
|
|
"." |
2521
|
|
|
) : '0, 00'; |
2522
|
|
|
$this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); |
2523
|
|
|
} |
2524
|
|
|
//Valor do ICMS |
2525
|
|
|
$x += $w10; |
2526
|
|
|
if (isset($ICMS)) { |
2527
|
|
|
$texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ? |
2528
|
|
|
number_format( |
2529
|
|
|
$ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue, |
2530
|
|
|
2, |
2531
|
|
|
",", |
2532
|
|
|
"." |
2533
|
|
|
) : '0, 00'; |
2534
|
|
|
$this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); |
2535
|
|
|
} |
2536
|
|
|
//Valor do IPI |
2537
|
|
|
$x += $w11; |
2538
|
|
|
if (isset($IPI)) { |
2539
|
|
|
$texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ? |
2540
|
|
|
number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :''; |
2541
|
|
|
} else { |
2542
|
|
|
$texto = ''; |
2543
|
|
|
} |
2544
|
|
|
$this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, ''); |
2545
|
|
|
// %ICMS |
2546
|
|
|
$x += $w12; |
2547
|
|
|
if (isset($ICMS)) { |
2548
|
|
|
$texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ? |
2549
|
|
|
number_format( |
2550
|
|
|
$ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue, |
2551
|
|
|
2, |
2552
|
|
|
",", |
2553
|
|
|
"." |
2554
|
|
|
) : '0, 00'; |
2555
|
|
|
$this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, ''); |
2556
|
|
|
} |
2557
|
|
|
//%IPI |
2558
|
|
|
$x += $w13; |
2559
|
|
|
if (isset($IPI)) { |
2560
|
|
|
$texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ? |
2561
|
|
|
number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : ''; |
2562
|
|
|
} else { |
2563
|
|
|
$texto = ''; |
2564
|
|
|
} |
2565
|
|
|
$this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, ''); |
2566
|
|
|
$y += $h; |
2567
|
|
|
$i++; |
2568
|
|
|
//incrementa o controle dos itens processados. |
2569
|
|
|
$this->qtdeItensProc++; |
2570
|
|
|
} else { |
2571
|
|
|
$i++; |
2572
|
|
|
} |
2573
|
|
|
} |
2574
|
|
|
return $oldY+$hmax; |
2575
|
|
|
} |
2576
|
|
|
|
2577
|
|
|
/** |
2578
|
|
|
* issqnDANFE |
2579
|
|
|
* Monta o campo de serviços do DANFE |
2580
|
|
|
* |
2581
|
|
|
* @name issqnDANFE (retrato e paisagem) |
2582
|
|
|
* @param float $x Posição horizontal canto esquerdo |
2583
|
|
|
* @param float $y Posição vertical canto superior |
2584
|
|
|
* @return float Posição vertical final |
2585
|
|
|
*/ |
2586
|
|
|
protected function pIssqnDANFE($x, $y) |
2587
|
|
|
{ |
2588
|
|
|
$oldX = $x; |
|
|
|
|
2589
|
|
|
//##################################################################### |
2590
|
|
|
//CÁLCULO DO ISSQN |
2591
|
|
|
$texto = "CÁLCULO DO ISSQN"; |
2592
|
|
|
$w = $this->wPrint; |
2593
|
|
|
$h = 7; |
2594
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
2595
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, ''); |
2596
|
|
|
//INSCRIÇÃO MUNICIPAL |
2597
|
|
|
$y += 3; |
2598
|
|
|
$w = round($this->wPrint*0.23, 0); |
2599
|
|
|
$texto = 'INSCRIÇÃO MUNICIPAL'; |
2600
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2601
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2602
|
|
|
//inscrição municipal |
2603
|
|
|
$texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ? |
2604
|
|
|
$this->emit->getElementsByTagName("IM")->item(0)->nodeValue : ''; |
2605
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2606
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, ''); |
2607
|
|
|
//VALOR TOTAL DOS SERVIÇOS |
2608
|
|
|
$x += $w; |
2609
|
|
|
$texto = 'VALOR TOTAL DOS SERVIÇOS'; |
2610
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2611
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2612
|
|
|
if (isset($this->ISSQNtot)) { |
2613
|
|
|
$texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ? |
2614
|
|
|
$this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : ''; |
2615
|
|
|
$texto = number_format($texto, 2, ",", "."); |
2616
|
|
|
} else { |
2617
|
|
|
$texto = ''; |
2618
|
|
|
} |
2619
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2620
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, ''); |
2621
|
|
|
//BASE DE CÁLCULO DO ISSQN |
2622
|
|
|
$x += $w; |
2623
|
|
|
$texto = 'BASE DE CÁLCULO DO ISSQN'; |
2624
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2625
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2626
|
|
|
if (isset($this->ISSQNtot)) { |
2627
|
|
|
$texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ? |
2628
|
|
|
$this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : ''; |
2629
|
|
|
$texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : ''; |
2630
|
|
|
} else { |
2631
|
|
|
$texto = ''; |
2632
|
|
|
} |
2633
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2634
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, ''); |
2635
|
|
|
//VALOR TOTAL DO ISSQN |
2636
|
|
|
$x += $w; |
2637
|
|
|
if ($this->orientacao == 'P') { |
2638
|
|
|
$w = $this->wPrint - (3 * $w); |
2639
|
|
|
} else { |
2640
|
|
|
$w = $this->wPrint - (3 * $w)-$this->wCanhoto; |
2641
|
|
|
} |
2642
|
|
|
$texto = 'VALOR TOTAL DO ISSQN'; |
2643
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2644
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2645
|
|
|
if (isset($this->ISSQNtot)) { |
2646
|
|
|
$texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ? |
2647
|
|
|
$this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : ''; |
2648
|
|
|
$texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : ''; |
2649
|
|
|
} else { |
2650
|
|
|
$texto = ''; |
2651
|
|
|
} |
2652
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2653
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, ''); |
2654
|
|
|
return ($y+$h+1); |
2655
|
|
|
} |
2656
|
|
|
|
2657
|
|
|
/** |
2658
|
|
|
*dadosAdicionaisDANFE |
2659
|
|
|
* Coloca o grupo de dados adicionais da NFe. (retrato e paisagem) |
2660
|
|
|
* |
2661
|
|
|
* @name dadosAdicionaisDANFE |
2662
|
|
|
* @param float $x Posição horizontal canto esquerdo |
2663
|
|
|
* @param float $y Posição vertical canto superior |
2664
|
|
|
* @param float $h altura do campo |
2665
|
|
|
* @return float Posição vertical final (eixo Y) |
2666
|
|
|
*/ |
2667
|
|
|
protected function pDadosAdicionaisDANFE($x, $y, $h) |
2668
|
|
|
{ |
2669
|
|
|
//################################################################################## |
2670
|
|
|
//DADOS ADICIONAIS |
2671
|
|
|
$texto = "DADOS ADICIONAIS"; |
2672
|
|
|
if ($this->orientacao == 'P') { |
2673
|
|
|
$w = $this->wPrint; |
2674
|
|
|
} else { |
2675
|
|
|
$w = $this->wPrint-$this->wCanhoto; |
2676
|
|
|
} |
2677
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
2678
|
|
|
$this->pTextBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, ''); |
2679
|
|
|
//INFORMAÇÕES COMPLEMENTARES |
2680
|
|
|
$texto = "INFORMAÇÕES COMPLEMENTARES"; |
2681
|
|
|
$y += 3; |
2682
|
|
|
$w = $this->wAdic; |
2683
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'); |
2684
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2685
|
|
|
//o texto com os dados adicionais foi obtido na função montaDANFE |
2686
|
|
|
//e carregado em uma propriedade privada da classe |
2687
|
|
|
//$this->wAdic com a largura do campo |
2688
|
|
|
//$this->textoAdic com o texto completo do campo |
2689
|
|
|
$y += 1; |
2690
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
2691
|
|
|
$this->pTextBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false); |
2692
|
|
|
//RESERVADO AO FISCO |
2693
|
|
|
$texto = "RESERVADO AO FISCO"; |
2694
|
|
|
$x += $w; |
2695
|
|
|
$y -= 1; |
2696
|
|
|
if ($this->orientacao == 'P') { |
2697
|
|
|
$w = $this->wPrint-$w; |
2698
|
|
|
} else { |
2699
|
|
|
$w = $this->wPrint-$w-$this->wCanhoto; |
2700
|
|
|
} |
2701
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'); |
2702
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, ''); |
2703
|
|
|
//inserir texto informando caso de contingência |
2704
|
|
|
// 1 - Normal - emissão normal; |
2705
|
|
|
// 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança; |
2706
|
|
|
// 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional; |
2707
|
|
|
// 4 - Contingência DPEC - emissão em contingência com envio da Declaração |
2708
|
|
|
// Prévia de Emissão em Contingência; |
2709
|
|
|
// 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de |
2710
|
|
|
// Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA); |
2711
|
|
|
// 6 - Contingência SVC-AN |
2712
|
|
|
// 7 - Contingência SVC-RS |
2713
|
|
|
$xJust = $this->pSimpleGetValue($this->ide, 'xJust', 'Justificativa: '); |
2714
|
|
|
$dhCont = $this->pSimpleGetValue($this->ide, 'dhCont', ' Entrada em contingência : '); |
2715
|
|
|
$texto = ''; |
2716
|
|
|
switch ($this->tpEmis) { |
2717
|
|
|
case 2: |
2718
|
|
|
$texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust; |
2719
|
|
|
break; |
2720
|
|
|
case 3: |
2721
|
|
|
$texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust; |
2722
|
|
|
break; |
2723
|
|
|
case 4: |
2724
|
|
|
$texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust; |
2725
|
|
|
break; |
2726
|
|
|
case 5: |
2727
|
|
|
$texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust; |
2728
|
|
|
break; |
2729
|
|
|
case 6: |
2730
|
|
|
$texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust; |
2731
|
|
|
break; |
2732
|
|
|
case 7: |
2733
|
|
|
$texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust; |
2734
|
|
|
break; |
2735
|
|
|
} |
2736
|
|
|
$y += 2; |
2737
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
2738
|
|
|
$this->pTextBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false); |
2739
|
|
|
return $y+$h; |
2740
|
|
|
} |
2741
|
|
|
|
2742
|
|
|
/** |
2743
|
|
|
* pRodape |
2744
|
|
|
* Monta o rodapé no final da DANFE com a data/hora de impressão e informações |
2745
|
|
|
* sobre a API NfePHP |
2746
|
|
|
* |
2747
|
|
|
* @name pRodape |
2748
|
|
|
* @param float $xInic Posição horizontal canto esquerdo |
|
|
|
|
2749
|
|
|
* @param float $yFinal Posição vertical final para impressão |
|
|
|
|
2750
|
|
|
* @return void |
2751
|
|
|
*/ |
2752
|
|
|
protected function pRodape($x, $y) |
2753
|
|
|
{ |
2754
|
|
|
if ($this->orientacao == 'P') { |
2755
|
|
|
$w = $this->wPrint; |
2756
|
|
|
} else { |
2757
|
|
|
$w = $this->wPrint-$this->wCanhoto; |
2758
|
|
|
$x = $this->wCanhoto; |
2759
|
|
|
} |
2760
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'); |
2761
|
|
|
$texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s'); |
2762
|
|
|
$this->pTextBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false); |
|
|
|
|
2763
|
|
|
$texto = $this->creditos . " Powered by NFePHP"; |
2764
|
|
|
$this->pTextBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, ''); |
|
|
|
|
2765
|
|
|
} |
2766
|
|
|
|
2767
|
|
|
/** |
2768
|
|
|
* pCcanhotoDANFE |
2769
|
|
|
* Monta o canhoto da DANFE (retrato e paisagem) |
2770
|
|
|
* |
2771
|
|
|
* @name canhotoDANFE |
2772
|
|
|
* @param number $x Posição horizontal canto esquerdo |
2773
|
|
|
* @param number $y Posição vertical canto superior |
2774
|
|
|
* @return number Posição vertical final |
2775
|
|
|
* |
2776
|
|
|
* TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente |
2777
|
|
|
*/ |
2778
|
|
|
protected function pCanhoto($x, $y) |
2779
|
|
|
{ |
2780
|
|
|
$oldX = $x; |
2781
|
|
|
$oldY = $y; |
2782
|
|
|
//################################################################################# |
2783
|
|
|
//canhoto |
2784
|
|
|
//identificação do tipo de nf entrada ou saida |
2785
|
|
|
$tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue; |
2786
|
|
|
if ($tpNF == '0') { |
2787
|
|
|
//NFe de Entrada |
2788
|
|
|
$emitente = ''; |
2789
|
|
|
$emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - "; |
2790
|
|
|
$emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", "; |
2791
|
|
|
$emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - "; |
2792
|
|
|
$emitente .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " "); |
2793
|
|
|
$emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " "; |
2794
|
|
|
$emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-"; |
2795
|
|
|
$emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . ""; |
2796
|
|
|
$destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " "; |
2797
|
|
|
} else { |
2798
|
|
|
//NFe de Saída |
2799
|
|
|
$emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " "; |
2800
|
|
|
$destinatario = ''; |
2801
|
|
|
$destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - "; |
2802
|
|
|
$destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", "; |
2803
|
|
|
$destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " "; |
2804
|
|
|
$destinatario .= $this->pSimpleGetValue($this->enderDest, "xCpl", " - ", " "); |
2805
|
|
|
$destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " "; |
2806
|
|
|
$destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-"; |
2807
|
|
|
$destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " "; |
2808
|
|
|
} |
2809
|
|
|
//identificação do sistema emissor |
2810
|
|
|
//linha separadora do canhoto |
2811
|
|
|
if ($this->orientacao == 'P') { |
2812
|
|
|
$w = round($this->wPrint * 0.81, 0); |
2813
|
|
|
} else { |
2814
|
|
|
//linha separadora do canhoto - 238 |
2815
|
|
|
//posicao altura |
2816
|
|
|
$y = $this->wPrint-85; |
2817
|
|
|
//altura |
2818
|
|
|
$w = $this->wPrint-85-24; |
2819
|
|
|
} |
2820
|
|
|
$h = 10; |
2821
|
|
|
//desenha caixa |
2822
|
|
|
$texto = ''; |
2823
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
2824
|
|
|
$aFontSmall = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2825
|
|
|
if ($this->orientacao == 'P') { |
2826
|
|
|
$this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false); |
2827
|
|
|
} else { |
2828
|
|
|
$this->pTextBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false); |
2829
|
|
|
} |
2830
|
|
|
$numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT); |
2831
|
|
|
$serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT); |
2832
|
|
|
$texto = "RECEBEMOS DE "; |
2833
|
|
|
$texto .= $emitente; |
2834
|
|
|
$texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA "; |
2835
|
|
|
if ($this->orientacao == 'P') { |
2836
|
|
|
$texto .= "ABAIXO"; |
2837
|
|
|
} else { |
2838
|
|
|
$texto .= "AO LADO"; |
2839
|
|
|
} |
2840
|
|
|
$texto .= ". EMISSÃO: "; |
2841
|
|
|
$dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ? |
2842
|
|
|
$this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : ''; |
2843
|
|
|
if ($dEmi == '') { |
2844
|
|
|
$dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ? |
2845
|
|
|
$this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : ''; |
2846
|
|
|
$aDemi = explode('T', $dEmi); |
2847
|
|
|
$dEmi = $aDemi[0]; |
2848
|
|
|
} |
2849
|
|
|
$texto .= $this->pYmd2dmy($dEmi) ." "; |
2850
|
|
|
$texto .= "VALOR TOTAL: R$ "; |
2851
|
|
|
$texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " "; |
2852
|
|
|
$texto .= "DESTINATÁRIO: "; |
2853
|
|
|
$texto .= $destinatario; |
2854
|
|
|
if ($this->orientacao == 'P') { |
2855
|
|
|
$this->pTextBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false); |
2856
|
|
|
$x1 = $x + $w; |
2857
|
|
|
$w1 = $this->wPrint - $w; |
2858
|
|
|
$texto = "NF-e"; |
2859
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'); |
2860
|
|
|
$this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, ''); |
2861
|
|
|
$texto = "Nº. " . $this->pFormat($numNF, "###.###.###") . " \n"; |
2862
|
|
|
$texto .= "Série $serie"; |
2863
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'); |
2864
|
|
|
$this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, ''); |
2865
|
|
|
//DATA DE RECEBIMENTO |
2866
|
|
|
$texto = "DATA DE RECEBIMENTO"; |
2867
|
|
|
$y += $h; |
2868
|
|
|
$w2 = round($this->wPrint*0.17, 0); //35; |
2869
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2870
|
|
|
$this->pTextBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, ''); |
2871
|
|
|
//IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR |
2872
|
|
|
$x += $w2; |
2873
|
|
|
$w3 = $w-$w2; |
2874
|
|
|
$texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"; |
2875
|
|
|
$this->pTextBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, ''); |
2876
|
|
|
$x = $oldX; |
2877
|
|
|
$y += 9; |
2878
|
|
|
$this->pdf->DashedHLine($x, $y, $this->wPrint, 0.1, 80); |
2879
|
|
|
$y += 2; |
2880
|
|
|
return $y; |
2881
|
|
|
} else { |
2882
|
|
|
$x--; |
2883
|
|
|
$x = $this->pTextBox90($x, $y, $w-1, $h, $texto, $aFontSmall, 'C', 'L', 0, '', false); |
|
|
|
|
2884
|
|
|
//NUMERO DA NOTA FISCAL LOGO NFE |
2885
|
|
|
$w1 = 16; |
2886
|
|
|
$x1 = $oldX; |
2887
|
|
|
$y = $oldY; |
2888
|
|
|
$texto = "NF-e"; |
2889
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'); |
2890
|
|
|
$this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, ''); |
2891
|
|
|
$texto = "Nº.\n" . $this->pFormat($numNF, "###.###.###") . " \n"; |
2892
|
|
|
$texto .= "Série $serie"; |
2893
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'); |
2894
|
|
|
$this->pTextBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, ''); |
2895
|
|
|
//DATA DO RECEBIMENTO |
2896
|
|
|
$texto = "DATA DO RECEBIMENTO"; |
2897
|
|
|
$y = $this->wPrint-85; |
2898
|
|
|
$x = 12; |
2899
|
|
|
$w2 = round($this->wPrint*0.17, 0); //35; |
2900
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>6, 'style'=>''); |
2901
|
|
|
$this->pTextBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, ''); |
2902
|
|
|
//IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR |
2903
|
|
|
$y -= $w2; |
2904
|
|
|
$w3 = $w-$w2; |
2905
|
|
|
$texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR"; |
2906
|
|
|
$aFont = array('font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''); |
2907
|
|
|
$x = $this->pTextBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, ''); |
2908
|
|
|
$this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67); |
2909
|
|
|
return $x; |
2910
|
|
|
} |
2911
|
|
|
} |
2912
|
|
|
|
2913
|
|
|
/** |
2914
|
|
|
* pGeraInformacoesDaTagCompra |
2915
|
|
|
* Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia. |
2916
|
|
|
* Aviso: Esta função não leva em consideração dados na tag xPed do item. |
2917
|
|
|
* |
2918
|
|
|
* @name pGeraInformacoesDaTagCompra |
2919
|
|
|
* @return string com as informacoes dos pedidos. |
2920
|
|
|
*/ |
2921
|
|
|
protected function pGeraInformacoesDaTagCompra() |
2922
|
|
|
{ |
2923
|
|
|
$saida = ""; |
2924
|
|
|
if (isset($this->compra)) { |
2925
|
|
|
if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) { |
2926
|
|
|
$saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue; |
2927
|
|
|
} |
2928
|
|
|
if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) { |
2929
|
|
|
$saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue; |
2930
|
|
|
} |
2931
|
|
|
if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) { |
2932
|
|
|
$saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue; |
2933
|
|
|
} |
2934
|
|
|
} |
2935
|
|
|
return $saida; |
2936
|
|
|
} |
2937
|
|
|
|
2938
|
|
|
/** |
2939
|
|
|
* pGeraChaveAdicionalDeContingencia |
2940
|
|
|
* |
2941
|
|
|
* @name pGeraChaveAdicionalDeContingencia |
2942
|
|
|
* @return string chave |
2943
|
|
|
*/ |
2944
|
|
|
protected function pGeraChaveAdicionalDeContingencia() |
2945
|
|
|
{ |
2946
|
|
|
//cUF tpEmis CNPJ vNF ICMSp ICMSs DD DV |
2947
|
|
|
// Quantidade de caracteres 02 01 14 14 01 01 02 01 |
|
|
|
|
2948
|
|
|
$forma = "%02d%d%s%014d%01d%01d%02d"; |
2949
|
|
|
$cUF = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue; |
2950
|
|
|
$CNPJ = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue; |
2951
|
|
|
$CNPJ = substr($CNPJ, -14); |
2952
|
|
|
$vNF = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100; |
2953
|
|
|
$vICMS = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue; |
2954
|
|
|
if ($vICMS > 0) { |
2955
|
|
|
$vICMS = 1; |
2956
|
|
|
} |
2957
|
|
|
$icmss = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue; |
2958
|
|
|
if ($icmss > 0) { |
2959
|
|
|
$icmss = 1; |
2960
|
|
|
} |
2961
|
|
|
$dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ? |
2962
|
|
|
$this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : ''; |
2963
|
|
|
if ($dEmi == '') { |
2964
|
|
|
$dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ? |
2965
|
|
|
$this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : ''; |
2966
|
|
|
$aDemi = explode('T', $dEmi); |
2967
|
|
|
$dEmi = $aDemi[0]; |
2968
|
|
|
} |
2969
|
|
|
$dd = $dEmi; |
2970
|
|
|
$rpos = strrpos($dd, '-'); |
2971
|
|
|
$dd = substr($dd, $rpos +1); |
2972
|
|
|
$chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd); |
2973
|
|
|
$chave = $chave . $this->pModulo11($chave); |
2974
|
|
|
return $chave; |
2975
|
|
|
} |
2976
|
|
|
|
2977
|
|
|
/** |
2978
|
|
|
* pGeraInformacoesDasNotasReferenciadas |
2979
|
|
|
* Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não |
2980
|
|
|
* Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01 |
2981
|
|
|
* em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000] |
2982
|
|
|
* |
2983
|
|
|
* @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas. |
2984
|
|
|
*/ |
2985
|
|
|
protected function pGeraInformacoesDasNotasReferenciadas() |
2986
|
|
|
{ |
2987
|
|
|
$formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]"; |
2988
|
|
|
$formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]"; |
2989
|
|
|
$formaNfRef = "\r\nNF Ref.: série:%d numero:%d emit:%s em %s modelo: %d"; |
2990
|
|
|
$formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d"; |
2991
|
|
|
$formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s"; |
2992
|
|
|
$saida=''; |
2993
|
|
|
$nfRefs = $this->ide->getElementsByTagName('NFref'); |
2994
|
|
|
if (0 === $nfRefs->length) { |
2995
|
|
|
return $saida; |
2996
|
|
|
} |
2997
|
|
|
foreach ($nfRefs as $nfRef) { |
2998
|
|
|
if (empty($nfRef)) { |
2999
|
|
|
continue; |
3000
|
|
|
} |
3001
|
|
|
$refNFe = $nfRef->getElementsByTagName('refNFe'); |
3002
|
|
|
foreach ($refNFe as $chave_acessoRef) { |
3003
|
|
|
$chave_acesso = $chave_acessoRef->nodeValue; |
3004
|
|
|
$chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave); |
3005
|
|
|
$data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2); |
3006
|
|
|
$cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##"); |
3007
|
|
|
$serie = substr($chave_acesso, 22, 3); |
3008
|
|
|
$numero = substr($chave_acesso, 25, 9); |
3009
|
|
|
$saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF); |
3010
|
|
|
} |
3011
|
|
|
$refNF = $nfRef->getElementsByTagName('refNF'); |
3012
|
|
|
foreach ($refNF as $umaRefNFe) { |
3013
|
|
|
$data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue; |
3014
|
|
|
$cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue; |
3015
|
|
|
$mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue; |
3016
|
|
|
$serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue; |
3017
|
|
|
$numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue; |
3018
|
|
|
$data = substr($data, 2, 2) . "/20" . substr($data, 0, 2); |
3019
|
|
|
$cnpj = $this->pFormat($cnpj, "##.###.###/####-##"); |
3020
|
|
|
$saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod); |
3021
|
|
|
} |
3022
|
|
|
$refCTe = $nfRef->getElementsByTagName('refCTe'); |
3023
|
|
|
foreach ($refCTe as $chave_acessoRef) { |
3024
|
|
|
$chave_acesso = $chave_acessoRef->nodeValue; |
3025
|
|
|
$chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave); |
3026
|
|
|
$data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2); |
3027
|
|
|
$cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##"); |
3028
|
|
|
$serie = substr($chave_acesso, 22, 3); |
3029
|
|
|
$numero = substr($chave_acesso, 25, 9); |
3030
|
|
|
$saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF); |
3031
|
|
|
} |
3032
|
|
|
$refECF = $nfRef->getElementsByTagName('refECF'); |
3033
|
|
|
foreach ($refECF as $umaRefNFe) { |
3034
|
|
|
$mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue; |
3035
|
|
|
$nECF = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue; |
3036
|
|
|
$nCOO = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue; |
3037
|
|
|
$saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO); |
3038
|
|
|
} |
3039
|
|
|
$refNFP = $nfRef->getElementsByTagName('refNFP'); |
3040
|
|
|
foreach ($refNFP as $umaRefNFe) { |
3041
|
|
|
$data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue; |
3042
|
|
|
$cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ? |
3043
|
|
|
$umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue : |
3044
|
|
|
''; |
3045
|
|
|
$cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ? |
3046
|
|
|
$umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : ''; |
3047
|
|
|
$mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue; |
3048
|
|
|
$serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue; |
3049
|
|
|
$numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue; |
3050
|
|
|
$ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue; |
3051
|
|
|
$data = substr($data, 2, 2) . "/20" . substr($data, 0, 2); |
3052
|
|
|
if ($cnpj == '') { |
3053
|
|
|
$cpf_cnpj = $this->pFormat($cpf, "###.###.###-##"); |
3054
|
|
|
} else { |
3055
|
|
|
$cpf_cnpj = $this->pFormat($cnpj, "##.###.###/####-##"); |
3056
|
|
|
} |
3057
|
|
|
$saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie); |
3058
|
|
|
} |
3059
|
|
|
} |
3060
|
|
|
return $saida; |
3061
|
|
|
} |
3062
|
|
|
|
3063
|
|
|
private function imagePNGtoJPG($original) |
3064
|
|
|
{ |
3065
|
|
|
$image = imagecreatefrompng($original); |
3066
|
|
|
ob_start(); |
3067
|
|
|
imagejpeg($image, null, 100); |
3068
|
|
|
imagedestroy($image); |
3069
|
|
|
$stringdata = ob_get_contents(); // read from buffer |
3070
|
|
|
ob_end_clean(); |
3071
|
|
|
return 'data://text/plain;base64,'.base64_encode($stringdata); |
3072
|
|
|
} |
3073
|
|
|
} |
3074
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.