These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace NFePHP\DA\NFe; |
||
4 | |||
5 | /** |
||
6 | * Classe para a impressão em PDF do Documento Auxiliar de NFe Consumidor |
||
7 | * NOTA: Esta classe não é a indicada para quem faz uso de impressoras térmicas ESCPOS |
||
8 | * |
||
9 | * @category Library |
||
10 | * @package nfephp-org/sped-da |
||
11 | * @copyright 2009-2019 NFePHP |
||
12 | * @license http://www.gnu.org/licenses/lesser.html LGPL v3 |
||
13 | * @link http://github.com/nfephp-org/sped-da for the canonical source repository |
||
14 | * @author Roberto Spadim <roberto at spadim dot com dot br> |
||
15 | */ |
||
16 | use Exception; |
||
17 | use InvalidArgumentException; |
||
18 | use NFePHP\DA\Legacy\Dom; |
||
19 | use NFePHP\DA\Legacy\Pdf; |
||
20 | use NFePHP\DA\Legacy\Common; |
||
21 | use Com\Tecnick\Barcode\Barcode; |
||
22 | use DateTime; |
||
23 | |||
24 | class Danfce extends Common |
||
25 | { |
||
26 | protected $papel; |
||
27 | protected $paperwidth = 80; |
||
28 | protected $creditos; |
||
29 | protected $xml; // string XML NFe |
||
30 | protected $logomarca=''; // path para logomarca em jpg |
||
31 | protected $formatoChave="#### #### #### #### #### #### #### #### #### #### ####"; |
||
32 | protected $debugMode=0; //ativa ou desativa o modo de debug |
||
33 | protected $tpImp; //ambiente |
||
34 | protected $fontePadrao='Times'; |
||
35 | protected $nfeProc; |
||
36 | protected $nfe; |
||
37 | protected $infNFe; |
||
38 | protected $ide; |
||
39 | protected $enderDest; |
||
40 | protected $ICMSTot; |
||
41 | protected $imposto; |
||
42 | protected $emit; |
||
43 | protected $enderEmit; |
||
44 | protected $qrCode; |
||
45 | protected $urlChave; |
||
46 | protected $det; |
||
47 | protected $infAdic; |
||
48 | protected $textoAdic; |
||
49 | protected $tpEmis; |
||
50 | protected $pag; |
||
51 | protected $vTroco; |
||
52 | protected $dest; |
||
53 | protected $imgQRCode; |
||
54 | protected $urlQR = ''; |
||
55 | protected $pdf; |
||
56 | protected $margemInterna = 2; |
||
57 | protected $hMaxLinha = 9; |
||
58 | protected $hBoxLinha = 6; |
||
59 | protected $hLinha = 3; |
||
60 | |||
61 | /** |
||
62 | * __contruct |
||
63 | * |
||
64 | * @param string $docXML |
||
65 | * @param string $sPathLogo |
||
66 | * @param string $mododebug |
||
67 | * @param string $idToken |
||
68 | * @param string $Token |
||
69 | */ |
||
70 | public function __construct( |
||
71 | $docXML = '', |
||
72 | $sPathLogo = '', |
||
73 | $mododebug = 0, |
||
74 | // habilita os erros do sistema |
||
75 | $idToken = '', |
||
76 | $emitToken = '', |
||
77 | $urlQR = '' |
||
78 | ) { |
||
79 | if (is_numeric($mododebug)) { |
||
80 | $this->debugMode = $mododebug; |
||
81 | } |
||
82 | if ($this->debugMode) { |
||
83 | //ativar modo debug |
||
84 | error_reporting(E_ALL); |
||
85 | ini_set('display_errors', 'On'); |
||
86 | } else { |
||
87 | //desativar modo debug |
||
88 | error_reporting(0); |
||
89 | ini_set('display_errors', 'Off'); |
||
90 | } |
||
91 | $this->xml = $docXML; |
||
92 | $this->logomarca = $sPathLogo; |
||
93 | |||
94 | $this->fontePadrao = empty($fonteDANFE) ? 'Times' : $fonteDANFE; |
||
95 | $this->aFontTit = array('font' => $this->fontePadrao, 'size' => 9, 'style' => 'B'); |
||
96 | $this->aFontTex = array('font' => $this->fontePadrao, 'size' => 8, 'style' => ''); |
||
97 | |||
98 | if (!empty($this->xml)) { |
||
99 | $this->dom = new Dom(); |
||
100 | $this->dom->loadXML($this->xml); |
||
101 | $this->nfeProc = $this->dom->getElementsByTagName("nfeProc")->item(0); |
||
102 | $this->nfe = $this->dom->getElementsByTagName("NFe")->item(0); |
||
103 | $this->infNFe = $this->dom->getElementsByTagName("infNFe")->item(0); |
||
104 | $this->ide = $this->dom->getElementsByTagName("ide")->item(0); |
||
105 | $this->emit = $this->dom->getElementsByTagName("emit")->item(0); |
||
106 | $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0); |
||
107 | $this->det = $this->dom->getElementsByTagName("det"); |
||
108 | $this->dest = $this->dom->getElementsByTagName("dest")->item(0); |
||
109 | $this->imposto = $this->dom->getElementsByTagName("imposto")->item(0); |
||
110 | $this->ICMSTot = $this->dom->getElementsByTagName("ICMSTot")->item(0); |
||
111 | $this->tpImp = $this->ide->getElementsByTagName("tpImp")->item(0)->nodeValue; |
||
112 | $this->infAdic = $this->dom->getElementsByTagName("infAdic")->item(0); |
||
113 | $this->tpEmis = $this->dom->getValue($this->ide, "tpEmis"); |
||
114 | |||
115 | //se for o layout 4.0 busca pelas tags de detalhe do pagamento |
||
116 | //senao, busca pelas tags de pagamento principal |
||
117 | if ($this->infNFe->getAttribute("versao") == "4.00") { |
||
118 | $this->pag = $this->dom->getElementsByTagName("detPag"); |
||
119 | |||
120 | $tagPag = $this->dom->getElementsByTagName("pag")->item(0); |
||
121 | $this->vTroco = $this->getTagValue($tagPag, "vTroco"); |
||
122 | } else { |
||
123 | $this->pag = $this->dom->getElementsByTagName("pag"); |
||
124 | } |
||
125 | } |
||
126 | $this->qrCode = !empty($this->dom->getElementsByTagName('qrCode')->item(0)->nodeValue) |
||
127 | ? $this->dom->getElementsByTagName('qrCode')->item(0)->nodeValue : null; |
||
128 | $this->urlChave = !empty($this->dom->getElementsByTagName('urlChave')->item(0)->nodeValue) |
||
129 | ? $this->dom->getElementsByTagName('urlChave')->item(0)->nodeValue : null; |
||
130 | if ($this->getTagValue($this->ide, "mod") != '65') { |
||
131 | throw new InvalidArgumentException("O xml do DANFE deve ser uma NFC-e modelo 65"); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Ativa ou desativa o modo debug |
||
137 | * @param bool $activate |
||
138 | * @return bool |
||
139 | */ |
||
140 | public function debugMode($activate = null) |
||
141 | { |
||
142 | if (isset($activate) && is_bool($activate)) { |
||
143 | $this->debugmode = $activate; |
||
144 | } |
||
145 | if ($this->debugmode) { |
||
146 | //ativar modo debug |
||
147 | error_reporting(E_ALL); |
||
148 | ini_set('display_errors', 'On'); |
||
149 | } else { |
||
150 | //desativar modo debug |
||
151 | error_reporting(0); |
||
152 | ini_set('display_errors', 'Off'); |
||
153 | } |
||
154 | return $this->debugmode; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * Add the credits to the integrator in the footer message |
||
159 | * @param string $message |
||
160 | */ |
||
161 | public function creditsIntegratorFooter($message = '') |
||
162 | { |
||
163 | $this->creditos = trim($message); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Dados brutos do PDF |
||
168 | * @return string |
||
169 | */ |
||
170 | public function render() |
||
171 | { |
||
172 | if (empty($this->pdf)) { |
||
173 | $this->monta(); |
||
174 | } |
||
175 | return $this->pdf->getPdf(); |
||
176 | } |
||
177 | |||
178 | |||
179 | public function paperWidth($width = 80) |
||
180 | { |
||
181 | if (is_int($width) && $width > 60) { |
||
182 | $this->paperwidth = $width; |
||
183 | } |
||
184 | return $this->paperwidth; |
||
185 | } |
||
186 | |||
187 | public function monta( |
||
188 | $logo = null, |
||
189 | $depecNumReg = '', |
||
190 | $logoAlign = 'C' |
||
191 | ) { |
||
192 | $this->logomarca = $logo; |
||
193 | $qtdItens = $this->det->length; |
||
194 | $qtdPgto = $this->pag->length; |
||
195 | $hMaxLinha = $this->hMaxLinha; |
||
196 | $hBoxLinha = $this->hBoxLinha; |
||
197 | $hLinha = $this->hLinha; |
||
198 | $tamPapelVert = 160 + 16 + 12 + (($qtdItens - 1) * $hMaxLinha) + ($qtdPgto * $hLinha); |
||
199 | // verifica se existe informações adicionais |
||
200 | $this->textoAdic = ''; |
||
201 | if (isset($this->infAdic)) { |
||
202 | $this->textoAdic .= !empty($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue) ? |
||
203 | 'Inf. Contribuinte: '. |
||
204 | trim($this->anfaveaDANFE($this->infAdic->getElementsByTagName('infCpl')->item(0)->nodeValue)) : ''; |
||
205 | if (!empty($this->textoAdic)) { |
||
206 | $this->textoAdic = str_replace(";", "\n", $this->textoAdic); |
||
207 | $alinhas = explode("\n", $this->textoAdic); |
||
208 | $numlinhasdados = 0; |
||
209 | $tempPDF = new Pdf(); // cria uma instancia temporaria da class pdf |
||
210 | $tempPDF->setFont('times', '', '8'); // seta a font do PDF |
||
211 | foreach ($alinhas as $linha) { |
||
212 | $linha = trim($linha); |
||
213 | $numlinhasdados += $tempPDF->wordWrap($linha, 76 - 0.2); |
||
214 | } |
||
215 | $hdadosadic = round(($numlinhasdados + 1) * $tempPDF->fontSize, 0); |
||
216 | if ($hdadosadic < 5) { |
||
217 | $hdadosadic = 5; |
||
218 | } |
||
219 | // seta o tamanho do papel |
||
220 | $tamPapelVert += $hdadosadic; |
||
221 | } |
||
222 | } |
||
223 | $this->orientacao = 'P'; |
||
224 | $this->papel = [$this->paperwidth, $tamPapelVert]; |
||
225 | $this->logoAlign = $logoAlign; |
||
226 | //$this->situacao_externa = $situacaoExterna; |
||
227 | $this->numero_registro_dpec = $depecNumReg; |
||
228 | $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel); |
||
229 | |||
230 | //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à |
||
231 | //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui |
||
232 | //apenas para controle se necessário ser maior do que a margem superior |
||
233 | $margSup = 2; |
||
234 | $margEsq = 2; |
||
235 | $margInf = 2; |
||
236 | // posição inicial do conteúdo, a partir do canto superior esquerdo da página |
||
237 | $xInic = $margEsq; |
||
238 | $yInic = $margSup; |
||
239 | $maxW = 80; |
||
240 | $maxH = $tamPapelVert; |
||
241 | //total inicial de paginas |
||
242 | $totPag = 1; |
||
243 | //largura imprimivel em mm: largura da folha menos as margens esq/direita |
||
244 | $this->wPrint = $maxW-($margEsq*2); |
||
245 | //comprimento (altura) imprimivel em mm: altura da folha menos as margens |
||
246 | //superior e inferior |
||
247 | $this->hPrint = $maxH-$margSup-$margInf; |
||
248 | // estabelece contagem de paginas |
||
249 | $this->pdf->aliasNbPages(); |
||
250 | $this->pdf->setMargins($margEsq, $margSup); // fixa as margens |
||
251 | $this->pdf->setDrawColor(0, 0, 0); |
||
252 | $this->pdf->setFillColor(255, 255, 255); |
||
253 | $this->pdf->open(); // inicia o documento |
||
254 | $this->pdf->addPage($this->orientacao, $this->papel); // adiciona a primeira página |
||
255 | $this->pdf->setLineWidth(0.1); // define a largura da linha |
||
256 | $this->pdf->setTextColor(0, 0, 0); |
||
257 | $this->pdf->textBox(0, 0, $maxW, $maxH); // POR QUE PRECISO DESA LINHA? |
||
258 | $hcabecalho = 27;//para cabeçalho (dados emitente mais logomarca) (FIXO) |
||
259 | $hcabecalhoSecundario = 10 + 3;//para cabeçalho secundário (cabeçalho sefaz) (FIXO) |
||
260 | $hprodutos = $hLinha + ($qtdItens * $hMaxLinha) ;//box poduto |
||
261 | $hTotal = 12; //box total (FIXO) |
||
262 | $hpagamentos = $hLinha + ($qtdPgto * $hLinha) + 3;//para pagamentos |
||
263 | if (!empty($this->vTroco)) { |
||
264 | $hpagamentos += $hLinha; |
||
265 | } |
||
266 | |||
267 | $hmsgfiscal = 21 + 2; // para imposto (FIXO) |
||
268 | $hcliente = !isset($this->dest) ? 6 : 12; // para cliente (FIXO) |
||
269 | $hcontingencia = $this->tpEmis == 9 ? 6 : 0; // para contingência (FIXO) |
||
270 | $hQRCode = 50; // para qrcode (FIXO) |
||
271 | $hCabecItens = 4; //cabeçalho dos itens |
||
272 | |||
273 | $hUsado = $hCabecItens; |
||
274 | $w2 = round($this->wPrint * 0.31, 0); |
||
275 | $totPag = 1; |
||
276 | $pag = 1; |
||
277 | $x = $xInic; |
||
278 | //COLOCA CABEÇALHO |
||
279 | $y = $yInic; |
||
280 | $y = $this->cabecalhoDANFE($x, $y, $hcabecalho, $pag, $totPag); |
||
281 | //COLOCA CABEÇALHO SECUNDÁRIO |
||
282 | $y = $hcabecalho; |
||
283 | $y = $this->cabecalhoSecundarioDANFE($x, $y, $hcabecalhoSecundario); |
||
284 | $jj = $hcabecalho + $hcabecalhoSecundario; |
||
285 | //COLOCA PRODUTOS |
||
286 | $y = $xInic + $hcabecalho + $hcabecalhoSecundario; |
||
287 | $y = $this->produtosDANFE($x, $y, $hprodutos); |
||
288 | //COLOCA TOTAL |
||
289 | $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos; |
||
290 | $y = $this->totalDANFE($x, $y, $hTotal); |
||
291 | //COLOCA PAGAMENTOS |
||
292 | $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal; |
||
293 | $y = $this->pagamentosDANFE($x, $y, $hpagamentos); |
||
294 | //COLOCA MENSAGEM FISCAL |
||
295 | $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal+ $hpagamentos; |
||
296 | $y = $this->fiscalDANFE($x, $y, $hmsgfiscal); |
||
297 | //COLOCA CONSUMIDOR |
||
298 | $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos + $hTotal + $hpagamentos + $hmsgfiscal; |
||
299 | $y = $this->consumidorDANFE($x, $y, $hcliente); |
||
300 | //COLOCA QRCODE |
||
301 | $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos |
||
302 | + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente; |
||
303 | $y = $this->qrCodeDANFE($x, $y, $hQRCode); |
||
304 | |||
305 | //adiciona as informações opcionais |
||
306 | if (!empty($this->textoAdic)) { |
||
307 | $y = $xInic + $hcabecalho + $hcabecalhoSecundario + $hprodutos |
||
308 | + $hTotal + $hpagamentos + $hmsgfiscal + $hcliente + $hQRCode; |
||
309 | $hInfAdic = 0; |
||
310 | $y = $this->infAdic($x, $y, $hInfAdic); |
||
311 | } |
||
312 | } |
||
313 | |||
314 | protected function cabecalhoDANFE($x = 0, $y = 0, $h = 0, $pag = '1', $totPag = '1') |
||
315 | { |
||
316 | $emitRazao = $this->getTagValue($this->emit, "xNome"); |
||
317 | $emitCnpj = $this->getTagValue($this->emit, "CNPJ"); |
||
318 | $emitCnpj = $this->formatField($emitCnpj, "##.###.###/####-##"); |
||
319 | $emitIE = $this->getTagValue($this->emit, "IE"); |
||
320 | $emitIM = $this->getTagValue($this->emit, "IM"); |
||
321 | $emitFone = $this->getTagValue($this->enderEmit, "fone"); |
||
322 | $foneLen = strlen($emitFone); |
||
323 | if ($foneLen>0) { |
||
324 | $ddd = substr($emitFone, 0, 2); |
||
325 | $fone1 = substr($emitFone, -8); |
||
326 | $digito9 = ' '; |
||
327 | if ($foneLen == 11) { |
||
328 | $digito9 = substr($emitFone, 2, 1); |
||
329 | } |
||
330 | $emitFone = ' - ('.$ddd.') '.$digito9. ' ' . substr($fone1, 0, 4) . '-' . substr($fone1, -4); |
||
331 | } else { |
||
332 | $emitFone = ''; |
||
333 | } |
||
334 | $emitLgr = $this->getTagValue($this->enderEmit, "xLgr"); |
||
335 | $emitNro = $this->getTagValue($this->enderEmit, "nro"); |
||
336 | $emitCpl = $this->getTagValue($this->enderEmit, "xCpl", ""); |
||
337 | $emitBairro = $this->getTagValue($this->enderEmit, "xBairro"); |
||
338 | $emitCEP = $this->formatField($this->getTagValue($this->enderEmit, "CEP"), "#####-###"); |
||
339 | $emitMun = $this->getTagValue($this->enderEmit, "xMun"); |
||
340 | $emitUF = $this->getTagValue($this->enderEmit, "UF"); |
||
341 | // CONFIGURAÇÃO DE POSIÇÃO |
||
342 | $margemInterna = $this->margemInterna; |
||
343 | $maxW = $this->wPrint; |
||
344 | $h = $h-($margemInterna); |
||
345 | //COLOCA LOGOMARCA |
||
346 | if (is_file($this->logomarca)) { |
||
347 | $xImg = $margemInterna; |
||
348 | $yImg = $margemInterna + 1; |
||
349 | $this->pdf->image($this->logomarca, $xImg, $yImg, 30, 22.5); |
||
350 | $xRs = ($maxW*0.4) + $margemInterna; |
||
351 | $wRs = ($maxW*0.6); |
||
352 | $alignEmit = 'L'; |
||
353 | } else { |
||
354 | $xRs = $margemInterna; |
||
355 | $wRs = ($maxW*1); |
||
356 | $alignEmit = 'L'; |
||
357 | } |
||
358 | //COLOCA RAZÃO SOCIAL |
||
359 | $texto = $emitRazao; |
||
360 | $texto = $texto . "\nCNPJ:" . $emitCnpj; |
||
361 | $texto = $texto . "\nIE:" . $emitIE; |
||
362 | if (!empty($emitIM)) { |
||
363 | $texto = $texto . " - IM:" . $emitIM; |
||
364 | } |
||
365 | $texto = $texto . "\n" . $emitLgr . "," . $emitNro . " " . $emitCpl . "," . $emitBairro |
||
366 | . ". CEP:" . $emitCEP . ". " . $emitMun . "-" . $emitUF . $emitFone; |
||
367 | $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>''); |
||
368 | $this->pdf->textBox($xRs, $y, $wRs, $h, $texto, $aFont, 'C', $alignEmit, 0, '', false); |
||
369 | } |
||
370 | |||
371 | protected function cabecalhoSecundarioDANFE($x = 0, $y = 0, $h = 0) |
||
372 | { |
||
373 | $margemInterna = $this->margemInterna; |
||
374 | $maxW = $this->wPrint; |
||
375 | $w = ($maxW*1); |
||
376 | $hBox1 = 7; |
||
377 | $texto = "DANFE NFC-e\nDocumento Auxiliar da Nota Fiscal de Consumidor Eletrônica"; |
||
378 | $aFont = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'); |
||
379 | $this->pdf->textBox($x, $y, $w, $hBox1, $texto, $aFont, 'C', 'C', 0, '', false); |
||
380 | $hBox2 = 4; |
||
381 | $yBox2 = $y + $hBox1; |
||
382 | $texto = "\nNFC-e não permite aproveitamento de crédito de ICMS"; |
||
383 | $aFont = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
||
384 | $this->pdf->textBox($x, $yBox2, $w, $hBox2, $texto, $aFont, 'C', 'C', 0, '', false); |
||
385 | } |
||
386 | |||
387 | protected function produtosDANFE($x = 0, $y = 0, $h = 0) |
||
388 | { |
||
389 | $margemInterna = $this->margemInterna; |
||
390 | $maxW = $this->wPrint; |
||
391 | $qtdItens = $this->det->length; |
||
392 | $w = ($maxW*1); |
||
393 | $hLinha = $this->hLinha; |
||
394 | $aFontCabProdutos = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
||
395 | $wBoxCod = $w*0.17; |
||
396 | $texto = "CÓDIGO"; |
||
397 | $this->pdf->textBox($x, $y, $wBoxCod, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false); |
||
398 | $wBoxDescricao = $w*0.43; |
||
399 | $xBoxDescricao = $wBoxCod + $x; |
||
400 | $texto = "DESCRICÃO"; |
||
401 | $this->pdf->textBox( |
||
402 | $xBoxDescricao, |
||
403 | $y, |
||
404 | $wBoxDescricao, |
||
405 | $hLinha, |
||
406 | $texto, |
||
407 | $aFontCabProdutos, |
||
408 | 'T', |
||
409 | 'L', |
||
410 | 0, |
||
411 | '', |
||
412 | false |
||
413 | ); |
||
414 | $wBoxQt = $w*0.08; |
||
415 | $xBoxQt = $wBoxDescricao + $xBoxDescricao; |
||
416 | $texto = "QT"; |
||
417 | $this->pdf->textBox($xBoxQt, $y, $wBoxQt, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false); |
||
418 | $wBoxUn = $w*0.06; |
||
419 | $xBoxUn = $wBoxQt + $xBoxQt; |
||
420 | $texto = "UN"; |
||
421 | $this->pdf->textBox($xBoxUn, $y, $wBoxUn, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false); |
||
422 | $wBoxVl = $w*0.13; |
||
423 | $xBoxVl = $wBoxUn + $xBoxUn; |
||
424 | $texto = "VALOR"; |
||
425 | $this->pdf->textBox($xBoxVl, $y, $wBoxVl, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false); |
||
426 | $wBoxTotal = $w*0.13; |
||
427 | $xBoxTotal = $wBoxVl + $xBoxVl; |
||
428 | $texto = "TOTAL"; |
||
429 | $this->pdf->textBox($xBoxTotal, $y, $wBoxTotal, $hLinha, $texto, $aFontCabProdutos, 'T', 'L', 0, '', false); |
||
430 | $hBoxLinha = $this->hBoxLinha; |
||
431 | $hMaxLinha = $this->hMaxLinha; |
||
432 | $cont = 0; |
||
433 | $aFontProdutos = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>''); |
||
434 | if ($qtdItens > 0) { |
||
435 | foreach ($this->det as $detI) { |
||
436 | $thisItem = $detI; |
||
437 | $prod = $thisItem->getElementsByTagName("prod")->item(0); |
||
438 | $nitem = $thisItem->getAttribute("nItem"); |
||
439 | $cProd = $this->getTagValue($prod, "cProd"); |
||
440 | $xProd = $this->getTagValue($prod, "xProd"); |
||
441 | $qCom = number_format($this->getTagValue($prod, "qCom"), 2, ",", "."); |
||
442 | $uCom = $this->getTagValue($prod, "uCom"); |
||
443 | $vUnCom = number_format($this->getTagValue($prod, "vUnCom"), 2, ",", "."); |
||
444 | $vProd = number_format($this->getTagValue($prod, "vProd"), 2, ",", "."); |
||
445 | //COLOCA PRODUTO |
||
446 | $yBoxProd = $y + $hLinha + ($cont*$hMaxLinha); |
||
447 | //COLOCA PRODUTO CÓDIGO |
||
448 | $wBoxCod = $w*0.17; |
||
449 | $texto = $cProd; |
||
450 | $this->pdf->textBox( |
||
451 | $x, |
||
452 | $yBoxProd, |
||
453 | $wBoxCod, |
||
454 | $hMaxLinha, |
||
455 | $texto, |
||
456 | $aFontProdutos, |
||
457 | 'C', |
||
458 | 'C', |
||
459 | 0, |
||
460 | '', |
||
461 | false |
||
462 | ); |
||
463 | //COLOCA PRODUTO DESCRIÇÃO |
||
464 | $wBoxDescricao = $w*0.43; |
||
465 | $xBoxDescricao = $wBoxCod + $x; |
||
466 | $texto = $xProd; |
||
467 | $this->pdf->textBox( |
||
468 | $xBoxDescricao, |
||
469 | $yBoxProd, |
||
470 | $wBoxDescricao, |
||
471 | $hMaxLinha, |
||
472 | $texto, |
||
473 | $aFontProdutos, |
||
474 | 'C', |
||
475 | 'L', |
||
476 | 0, |
||
477 | '', |
||
478 | false |
||
479 | ); |
||
480 | //COLOCA PRODUTO QUANTIDADE |
||
481 | $wBoxQt = $w*0.08; |
||
482 | $xBoxQt = $wBoxDescricao + $xBoxDescricao; |
||
483 | $texto = $qCom; |
||
484 | $this->pdf->textBox( |
||
485 | $xBoxQt, |
||
486 | $yBoxProd, |
||
487 | $wBoxQt, |
||
488 | $hMaxLinha, |
||
489 | $texto, |
||
490 | $aFontProdutos, |
||
491 | 'C', |
||
492 | 'C', |
||
493 | 0, |
||
494 | '', |
||
495 | false |
||
496 | ); |
||
497 | //COLOCA PRODUTO UNIDADE |
||
498 | $wBoxUn = $w*0.06; |
||
499 | $xBoxUn = $wBoxQt + $xBoxQt; |
||
500 | $texto = $uCom; |
||
501 | $this->pdf->textBox( |
||
502 | $xBoxUn, |
||
503 | $yBoxProd, |
||
504 | $wBoxUn, |
||
505 | $hMaxLinha, |
||
506 | $texto, |
||
507 | $aFontProdutos, |
||
508 | 'C', |
||
509 | 'C', |
||
510 | 0, |
||
511 | '', |
||
512 | false |
||
513 | ); |
||
514 | //COLOCA PRODUTO VL UNITÁRIO |
||
515 | $wBoxVl = $w*0.13; |
||
516 | $xBoxVl = $wBoxUn + $xBoxUn; |
||
517 | $texto = $vUnCom; |
||
518 | $this->pdf->textBox( |
||
519 | $xBoxVl, |
||
520 | $yBoxProd, |
||
521 | $wBoxVl, |
||
522 | $hMaxLinha, |
||
523 | $texto, |
||
524 | $aFontProdutos, |
||
525 | 'C', |
||
526 | 'R', |
||
527 | 0, |
||
528 | '', |
||
529 | false |
||
530 | ); |
||
531 | //COLOCA PRODUTO VL TOTAL |
||
532 | $wBoxTotal = $w*0.13; |
||
533 | $xBoxTotal = $wBoxVl + $xBoxVl; |
||
534 | $texto = $vProd; |
||
535 | $this->pdf->textBox( |
||
536 | $xBoxTotal, |
||
537 | $yBoxProd, |
||
538 | $wBoxTotal, |
||
539 | $hMaxLinha, |
||
540 | $texto, |
||
541 | $aFontProdutos, |
||
542 | 'C', |
||
543 | 'R', |
||
544 | 0, |
||
545 | '', |
||
546 | false |
||
547 | ); |
||
548 | |||
549 | $cont++; |
||
550 | } |
||
551 | } |
||
552 | } |
||
553 | |||
554 | protected function totalDANFE($x = 0, $y = 0, $h = 0) |
||
555 | { |
||
556 | $margemInterna = $this->margemInterna; |
||
557 | $maxW = $this->wPrint; |
||
558 | $hLinha = 3; |
||
559 | $wColEsq = ($maxW*0.7); |
||
560 | $wColDir = ($maxW*0.3); |
||
561 | $xValor = $x + $wColEsq; |
||
562 | $qtdItens = $this->det->length; |
||
563 | $vProd = $this->getTagValue($this->ICMSTot, "vProd"); |
||
564 | $vNF = $this->getTagValue($this->ICMSTot, "vNF"); |
||
565 | $vDesc = $this->getTagValue($this->ICMSTot, "vDesc"); |
||
566 | $vFrete = $this->getTagValue($this->ICMSTot, "vFrete"); |
||
567 | $vTotTrib = $this->getTagValue($this->ICMSTot, "vTotTrib"); |
||
568 | $texto = "Qtd. Total de Itens"; |
||
569 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
570 | $this->pdf->textBox($x, $y, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false); |
||
571 | $texto = $qtdItens; |
||
572 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
573 | $this->pdf->textBox($xValor, $y, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false); |
||
574 | $yTotal = $y + ($hLinha); |
||
575 | $texto = "Total de Produtos"; |
||
576 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
577 | $this->pdf->textBox($x, $yTotal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false); |
||
578 | $texto = "R$ " . number_format($vProd, 2, ",", "."); |
||
579 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
580 | $this->pdf->textBox($xValor, $yTotal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false); |
||
581 | $yDesconto = $y + ($hLinha*2); |
||
582 | $texto = "Descontos"; |
||
583 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
584 | $this->pdf->textBox($x, $yDesconto, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false); |
||
585 | $texto = "R$ " . $vDesc; |
||
586 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
587 | $this->pdf->textBox($xValor, $yDesconto, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false); |
||
588 | $yFrete= $y + ($hLinha*3); |
||
589 | $texto = "Frete"; |
||
590 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
591 | $this->pdf->textBox($x, $yFrete, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false); |
||
592 | $texto = "R$ " . $vFrete; |
||
593 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
594 | $this->pdf->textBox($xValor, $yFrete, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false); |
||
595 | $yTotalFinal = $y + ($hLinha*4); |
||
596 | $texto = "Total"; |
||
597 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
598 | $this->pdf->textBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false); |
||
599 | $texto = "R$ " . $vNF; |
||
600 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
601 | $this->pdf->textBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false); |
||
602 | $yTotalFinal = $y + ($hLinha*5); |
||
603 | $texto = "Informação dos Tributos Totais Incidentes"; |
||
604 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'']; |
||
605 | $this->pdf->textBox($x, $yTotalFinal, $wColEsq, $hLinha, $texto, $aFont, 'T', 'L', 0, '', false); |
||
606 | $texto = "R$ " . $vTotTrib; |
||
607 | $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B']; |
||
608 | $this->pdf->textBox($xValor, $yTotalFinal, $wColDir, $hLinha, $texto, $aFont, 'T', 'R', 0, '', false); |
||
609 | } |
||
610 | |||
611 | protected function pagamentosDANFE($x = 0, $y = 0, $h = 0) |
||
612 | { |
||
613 | $y += 6; |
||
614 | $margemInterna = $this->margemInterna; |
||
615 | $maxW = $this->wPrint; |
||
616 | $qtdPgto = $this->pag->length; |
||
617 | $w = ($maxW*1); |
||
618 | $hLinha = $this->hLinha; |
||
619 | $wColEsq = ($maxW*0.7); |
||
620 | $wColDir = ($maxW*0.3); |
||
621 | $xValor = $x + $wColEsq; |
||
622 | $aFontPgto = array('font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'); |
||
623 | $wBoxEsq = $w*0.7; |
||
624 | $texto = "FORMA DE PAGAMENTO"; |
||
625 | $this->pdf->textBox($x, $y, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false); |
||
626 | $wBoxDir = $w*0.3; |
||
627 | $xBoxDescricao = $x + $wBoxEsq; |
||
628 | $texto = "VALOR PAGO"; |
||
629 | $this->pdf->textBox($xBoxDescricao, $y, $wBoxDir, $hLinha, $texto, $aFontPgto, 'T', 'R', 0, '', false); |
||
630 | $cont = 0; |
||
631 | if ($qtdPgto > 0) { |
||
632 | foreach ($this->pag as $pagI) { |
||
633 | $tPag = $this->getTagValue($pagI, "tPag"); |
||
634 | $tPagNome = $this->tipoPag($tPag); |
||
635 | $tPnome = $tPagNome; |
||
636 | $vPag = number_format($this->getTagValue($pagI, "vPag"), 2, ",", "."); |
||
637 | $card = $pagI->getElementsByTagName("card")->item(0); |
||
638 | $cardCNPJ = ''; |
||
639 | $tBand = ''; |
||
640 | $tBandNome = ''; |
||
641 | if (isset($card)) { |
||
642 | $cardCNPJ = $this->getTagValue($card, "CNPJ"); |
||
643 | $tBand = $this->getTagValue($card, "tBand"); |
||
644 | $cAut = $this->getTagValue($card, "cAut"); |
||
645 | $tBandNome = self::getCardName($tBand); |
||
646 | } |
||
647 | //COLOCA PRODUTO |
||
648 | $yBoxProd = $y + $hLinha + ($cont*$hLinha); |
||
649 | //COLOCA PRODUTO CÓDIGO |
||
650 | $texto = $tPagNome; |
||
651 | $this->pdf->textBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false); |
||
652 | //COLOCA PRODUTO DESCRIÇÃO |
||
653 | $xBoxDescricao = $wBoxEsq + $x; |
||
654 | $texto = "R$ " . $vPag; |
||
655 | $this->pdf->textBox( |
||
656 | $xBoxDescricao, |
||
657 | $yBoxProd, |
||
658 | $wBoxDir, |
||
659 | $hLinha, |
||
660 | $texto, |
||
661 | $aFontPgto, |
||
662 | 'C', |
||
663 | 'R', |
||
664 | 0, |
||
665 | '', |
||
666 | false |
||
667 | ); |
||
668 | $cont++; |
||
669 | } |
||
670 | |||
671 | if (!empty($this->vTroco)) { |
||
672 | $yBoxProd = $y + $hLinha + ($cont*$hLinha); |
||
673 | //COLOCA PRODUTO CÓDIGO |
||
674 | $texto = 'Troco'; |
||
675 | $this->pdf->textBox($x, $yBoxProd, $wBoxEsq, $hLinha, $texto, $aFontPgto, 'T', 'L', 0, '', false); |
||
676 | //COLOCA PRODUTO DESCRIÇÃO |
||
677 | $xBoxDescricao = $wBoxEsq + $x; |
||
678 | $texto = "R$ " . number_format($this->vTroco, 2, ",", "."); |
||
679 | $this->pdf->textBox( |
||
680 | $xBoxDescricao, |
||
681 | $yBoxProd, |
||
682 | $wBoxDir, |
||
683 | $hLinha, |
||
684 | $texto, |
||
685 | $aFontPgto, |
||
686 | 'C', |
||
687 | 'R', |
||
688 | 0, |
||
689 | '', |
||
690 | false |
||
691 | ); |
||
692 | } |
||
693 | } |
||
694 | } |
||
695 | |||
696 | protected function fiscalDANFE($x = 0, $y = 0, $h = 0) |
||
697 | { |
||
698 | $y += 6; |
||
699 | $margemInterna = $this->margemInterna; |
||
700 | $maxW = $this->wPrint; |
||
701 | $w = ($maxW*1); |
||
702 | $hLinha = $this->hLinha; |
||
703 | $aFontTit = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B']; |
||
704 | $aFontTex = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'']; |
||
705 | $digVal = $this->getTagValue($this->nfe, "DigestValue"); |
||
706 | $chNFe = str_replace('NFe', '', $this->infNFe->getAttribute("Id")); |
||
707 | $tpAmb = $this->getTagValue($this->ide, 'tpAmb'); |
||
708 | |||
709 | if ($this->checkCancelada()) { |
||
710 | //101 Cancelamento |
||
711 | $this->pdf->setTextColor(255, 0, 0); |
||
712 | $texto = "NFCe CANCELADA"; |
||
713 | $this->pdf->textBox($x, $y - 25, $w, $h, $texto, $aFontTit, 'C', 'C', 0, ''); |
||
714 | $this->pdf->setTextColor(0, 0, 0); |
||
715 | } |
||
716 | |||
717 | if ($this->checkDenegada()) { |
||
718 | //uso denegado |
||
719 | $this->pdf->setTextColor(255, 0, 0); |
||
720 | $texto = "NFCe CANCELADA"; |
||
721 | $this->pdf->textBox($x, $y - 25, $w, $h, $texto, $aFontTit, 'C', 'C', 0, ''); |
||
722 | $this->pdf->SetTextColor(0, 0, 0); |
||
723 | } |
||
724 | |||
725 | $cUF = $this->getTagValue($this->ide, 'cUF'); |
||
726 | $nNF = $this->getTagValue($this->ide, 'nNF'); |
||
727 | $serieNF = str_pad($this->getTagValue($this->ide, "serie"), 3, "0", STR_PAD_LEFT); |
||
728 | $dhEmi = $this->getTagValue($this->ide, "dhEmi"); |
||
729 | $dhEmilocal = new \DateTime($dhEmi); |
||
730 | $dhEmiLocalFormat = $dhEmilocal->format('d/m/Y H:i:s'); |
||
731 | $texto = "ÁREA DE MENSAGEM FISCAL"; |
||
732 | $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false); |
||
733 | $yTex1 = $y + ($hLinha*1); |
||
734 | $hTex1 = $hLinha*2; |
||
735 | $texto = "Número " . $nNF . " Série " . $serieNF . " " .$dhEmiLocalFormat . " - Via Consumidor"; |
||
736 | $this->pdf->textBox($x, $yTex1, $w, $hTex1, $texto, $aFontTex, 'C', 'C', 0, '', false); |
||
737 | $yTex2 = $y + ($hLinha*3); |
||
738 | $hTex2 = $hLinha*2; |
||
739 | |||
740 | $texto = !empty($this->urlChave) ? "Consulte pela Chave de Acesso em " . $this->urlChave : ''; |
||
741 | $this->pdf->textBox($x, $yTex2, $w, $hTex2, $texto, $aFontTex, 'C', 'C', 0, '', false); |
||
742 | $texto = "CHAVE DE ACESSO"; |
||
743 | $yTit2 = $y + ($hLinha*5); |
||
744 | $this->pdf->textBox($x, $yTit2, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false); |
||
745 | $yTex3 = $y + ($hLinha*6); |
||
746 | $texto = $chNFe; |
||
747 | $this->pdf->textBox($x, $yTex3, $w, $hLinha, $texto, $aFontTex, 'C', 'C', 0, '', false); |
||
748 | } |
||
749 | |||
750 | protected function consumidorDANFE($x = 0, $y = 0, $h = 0) |
||
751 | { |
||
752 | $y += 6; |
||
753 | $margemInterna = $this->margemInterna; |
||
754 | $maxW = $this->wPrint; |
||
755 | $w = ($maxW*1); |
||
756 | $hLinha = $this->hLinha; |
||
757 | $aFontTit = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B']; |
||
758 | $aFontTex = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'']; |
||
759 | $texto = "CONSUMIDOR"; |
||
760 | $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false); |
||
761 | if (isset($this->dest)) { |
||
762 | $considEstrangeiro = !empty($this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue) |
||
763 | ? $this->dest->getElementsByTagName("idEstrangeiro")->item(0)->nodeValue |
||
764 | : ''; |
||
765 | $consCPF = !empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) |
||
766 | ? $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue |
||
767 | : ''; |
||
768 | $consCNPJ = !empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue) |
||
769 | ? $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue |
||
770 | : ''; |
||
771 | $cDest = $consCPF.$consCNPJ.$considEstrangeiro; //documentos do consumidor |
||
772 | $enderDest = $this->dest->getElementsByTagName("enderDest")->item(0); |
||
773 | $consNome = $this->getTagValue($this->dest, "xNome"); |
||
774 | $consLgr = $this->getTagValue($enderDest, "xLgr"); |
||
775 | $consNro = $this->getTagValue($enderDest, "nro"); |
||
776 | $consCpl = $this->getTagValue($enderDest, "xCpl", " - "); |
||
777 | $consBairro = $this->getTagValue($enderDest, "xBairro"); |
||
778 | $consCEP = $this->formatField($this->getTagValue($enderDest, "CEP")); |
||
779 | $consMun = $this->getTagValue($enderDest, "xMun"); |
||
780 | $consUF = $this->getTagValue($enderDest, "UF"); |
||
781 | $considEstrangeiro = $this->getTagValue($this->dest, "idEstrangeiro"); |
||
782 | $consCPF = $this->getTagValue($this->dest, "CPF"); |
||
783 | $consCNPJ = $this->getTagValue($this->dest, "CNPJ"); |
||
784 | $consDoc = ""; |
||
785 | if (!empty($consCNPJ)) { |
||
786 | $consDoc = "CNPJ: $consCNPJ"; |
||
787 | } elseif (!empty($consCPF)) { |
||
788 | $consDoc = "CPF: $consCPF"; |
||
789 | } elseif (!empty($considEstrangeiro)) { |
||
790 | $consDoc = "id: $considEstrangeiro"; |
||
791 | } |
||
792 | $consEnd = ""; |
||
793 | if (!empty($consLgr)) { |
||
794 | $consEnd = $consLgr |
||
795 | . "," |
||
796 | . $consNro |
||
797 | . " " |
||
798 | . $consCpl |
||
799 | . "," |
||
800 | . $consBairro |
||
801 | . ". CEP:" |
||
802 | . $consCEP |
||
803 | . ". " |
||
804 | . $consMun |
||
805 | . "-" |
||
806 | . $consUF; |
||
807 | } |
||
808 | $yTex1 = $y + $hLinha; |
||
809 | $texto = $consNome; |
||
810 | if (!empty($consDoc)) { |
||
811 | $texto .= " - ". $consDoc . "\n" . $consEnd; |
||
812 | $this->pdf->textBox($x, $yTex1, $w, $hLinha*3, $texto, $aFontTex, 'C', 'C', 0, '', false); |
||
813 | } |
||
814 | } else { |
||
815 | $yTex1 = $y + $hLinha; |
||
816 | $texto = "Consumidor não identificado"; |
||
817 | $this->pdf->textBox($x, $yTex1, $w, $hLinha, $texto, $aFontTex, 'C', 'C', 0, '', false); |
||
818 | } |
||
819 | } |
||
820 | |||
821 | protected function qrCodeDANFE($x = 0, $y = 0, $h = 0) |
||
822 | { |
||
823 | $y += 6; |
||
824 | $margemInterna = $this->margemInterna; |
||
825 | $maxW = $this->wPrint; |
||
826 | $w = ($maxW*1)+4; |
||
827 | $hLinha = $this->hLinha; |
||
828 | $hBoxLinha = $this->hBoxLinha; |
||
829 | $aFontTit = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'); |
||
0 ignored issues
–
show
|
|||
830 | $aFontTex = array('font'=>$this->fontePadrao, 'size'=>8, 'style'=>''); |
||
831 | $dhRecbto = ''; |
||
832 | $nProt = ''; |
||
833 | if (isset($this->nfeProc)) { |
||
834 | $nProt = $this->getTagValue($this->nfeProc, "nProt"); |
||
835 | $dhRecbto = $this->getTagValue($this->nfeProc, "dhRecbto"); |
||
836 | } |
||
837 | $barcode = new Barcode(); |
||
838 | $bobj = $barcode->getBarcodeObj( |
||
839 | 'QRCODE,M', |
||
840 | $this->qrCode, |
||
841 | -4, |
||
842 | -4, |
||
843 | 'black', |
||
844 | array(-2, -2, -2, -2) |
||
845 | )->setBackgroundColor('white'); |
||
846 | $qrcode = $bobj->getPngData(); |
||
847 | $wQr = 50; |
||
848 | $hQr = 50; |
||
849 | $yQr = ($y+$margemInterna); |
||
850 | $xQr = ($w/2) - ($wQr/2); |
||
851 | // prepare a base64 encoded "data url" |
||
852 | $pic = 'data://text/plain;base64,' . base64_encode($qrcode); |
||
853 | $info = getimagesize($pic); |
||
854 | $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG'); |
||
855 | $dt = new DateTime($dhRecbto); |
||
856 | $yQr = ($yQr+$hQr+$margemInterna); |
||
857 | $this->pdf->textBox($x, $yQr, $w-4, $hBoxLinha, "Protocolo de Autorização: " . $nProt . "\n" |
||
858 | . $dt->format('d/m/Y H:i:s'), $aFontTex, 'C', 'C', 0, '', false); |
||
859 | } |
||
860 | |||
861 | protected function infAdic($x = 0, $y = 0, $h = 0) |
||
862 | { |
||
863 | $y += 17; |
||
864 | $margemInterna = $this->margemInterna; |
||
865 | $maxW = $this->wPrint; |
||
866 | $w = ($maxW * 1); |
||
867 | $hLinha = $this->hLinha; |
||
868 | $aFontTit = ['font' => $this->fontePadrao, 'size' => 8, 'style' => 'B']; |
||
869 | $aFontTex = ['font' => $this->fontePadrao, 'size' => 8, 'style' => '']; |
||
870 | // seta o textbox do titulo |
||
871 | $texto = "INFORMAÇÃO ADICIONAL"; |
||
872 | $heigthText = $this->pdf->textBox($x, $y, $w, $hLinha, $texto, $aFontTit, 'C', 'C', 0, '', false); |
||
873 | |||
874 | // seta o textbox do texto adicional |
||
875 | $this->pdf->textBox($x, $y+3, $w-2, $hLinha-3, $this->textoAdic, $aFontTex, 'T', 'L', 0, '', false); |
||
876 | } |
||
877 | |||
878 | /** |
||
879 | * anfavea |
||
880 | * Função para transformar o campo cdata do padrão ANFAVEA para |
||
881 | * texto imprimível |
||
882 | * |
||
883 | * @param string $cdata campo CDATA |
||
884 | * @return string conteúdo do campo CDATA como string |
||
885 | */ |
||
886 | protected function anfaveaDANFE($cdata = '') |
||
887 | { |
||
888 | if ($cdata == '') { |
||
889 | return ''; |
||
890 | } |
||
891 | //remove qualquer texto antes ou depois da tag CDATA |
||
892 | $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata); |
||
893 | $cdata = str_replace(']]>', '</CDATA>', $cdata); |
||
894 | $cdata = preg_replace('/\s\s+/', ' ', $cdata); |
||
895 | $cdata = str_replace("> <", "><", $cdata); |
||
896 | $len = strlen($cdata); |
||
897 | $startPos = strpos($cdata, '<'); |
||
898 | if ($startPos === false) { |
||
899 | return $cdata; |
||
900 | } |
||
901 | for ($x=$len; $x>0; $x--) { |
||
902 | if (substr($cdata, $x, 1) == '>') { |
||
903 | $endPos = $x; |
||
904 | break; |
||
905 | } |
||
906 | } |
||
907 | if ($startPos > 0) { |
||
908 | $parte1 = substr($cdata, 0, $startPos); |
||
909 | } else { |
||
910 | $parte1 = ''; |
||
911 | } |
||
912 | $parte2 = substr($cdata, $startPos, $endPos-$startPos+1); |
||
913 | if ($endPos < $len) { |
||
914 | $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1); |
||
915 | } else { |
||
916 | $parte3 = ''; |
||
917 | } |
||
918 | $texto = trim($parte1).' '.trim($parte3); |
||
919 | if (strpos($parte2, '<CDATA>') === false) { |
||
920 | $cdata = '<CDATA>'.$parte2.'</CDATA>'; |
||
921 | } else { |
||
922 | $cdata = $parte2; |
||
923 | } |
||
924 | //carrega o xml CDATA em um objeto DOM |
||
925 | $dom = new Dom(); |
||
926 | $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG); |
||
927 | //$xml = $dom->saveXML(); |
||
928 | //grupo CDATA infADprod |
||
929 | $id = $dom->getElementsByTagName('id')->item(0); |
||
930 | $div = $dom->getElementsByTagName('div')->item(0); |
||
931 | $entg = $dom->getElementsByTagName('entg')->item(0); |
||
932 | $dest = $dom->getElementsByTagName('dest')->item(0); |
||
933 | $ctl = $dom->getElementsByTagName('ctl')->item(0); |
||
934 | $ref = $dom->getElementsByTagName('ref')->item(0); |
||
935 | if (isset($id)) { |
||
936 | if ($id->hasAttributes()) { |
||
937 | foreach ($id->attributes as $attr) { |
||
938 | $name = $attr->nodeName; |
||
939 | $value = $attr->nodeValue; |
||
940 | $texto .= " $name : $value"; |
||
941 | } |
||
942 | } |
||
943 | } |
||
944 | if (isset($div)) { |
||
945 | if ($div->hasAttributes()) { |
||
946 | foreach ($div->attributes as $attr) { |
||
947 | $name = $attr->nodeName; |
||
948 | $value = $attr->nodeValue; |
||
949 | $texto .= " $name : $value"; |
||
950 | } |
||
951 | } |
||
952 | } |
||
953 | if (isset($entg)) { |
||
954 | if ($entg->hasAttributes()) { |
||
955 | foreach ($entg->attributes as $attr) { |
||
956 | $name = $attr->nodeName; |
||
957 | $value = $attr->nodeValue; |
||
958 | $texto .= " $name : $value"; |
||
959 | } |
||
960 | } |
||
961 | } |
||
962 | if (isset($dest)) { |
||
963 | if ($dest->hasAttributes()) { |
||
964 | foreach ($dest->attributes as $attr) { |
||
965 | $name = $attr->nodeName; |
||
966 | $value = $attr->nodeValue; |
||
967 | $texto .= " $name : $value"; |
||
968 | } |
||
969 | } |
||
970 | } |
||
971 | if (isset($ctl)) { |
||
972 | if ($ctl->hasAttributes()) { |
||
973 | foreach ($ctl->attributes as $attr) { |
||
974 | $name = $attr->nodeName; |
||
975 | $value = $attr->nodeValue; |
||
976 | $texto .= " $name : $value"; |
||
977 | } |
||
978 | } |
||
979 | } |
||
980 | if (isset($ref)) { |
||
981 | if ($ref->hasAttributes()) { |
||
982 | foreach ($ref->attributes as $attr) { |
||
983 | $name = $attr->nodeName; |
||
984 | $value = $attr->nodeValue; |
||
985 | $texto .= " $name : $value"; |
||
986 | } |
||
987 | } |
||
988 | } |
||
989 | //grupo CADATA infCpl |
||
990 | $t = $dom->getElementsByTagName('transmissor')->item(0); |
||
991 | $r = $dom->getElementsByTagName('receptor')->item(0); |
||
992 | $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ? |
||
993 | 'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : ''; |
||
994 | $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ? |
||
995 | 'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : ''; |
||
996 | $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ? |
||
997 | 'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : ''; |
||
998 | $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ? |
||
999 | 'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : ''; |
||
1000 | $texto .= "".$versao.$especieNF.$fabEntrega.$dca; |
||
1001 | if (isset($t)) { |
||
1002 | if ($t->hasAttributes()) { |
||
1003 | $texto .= " Transmissor "; |
||
1004 | foreach ($t->attributes as $attr) { |
||
1005 | $name = $attr->nodeName; |
||
1006 | $value = $attr->nodeValue; |
||
1007 | $texto .= " $name : $value"; |
||
1008 | } |
||
1009 | } |
||
1010 | } |
||
1011 | if (isset($r)) { |
||
1012 | if ($r->hasAttributes()) { |
||
1013 | $texto .= " Receptor "; |
||
1014 | foreach ($r->attributes as $attr) { |
||
1015 | $name = $attr->nodeName; |
||
1016 | $value = $attr->nodeValue; |
||
1017 | $texto .= " $name : $value"; |
||
1018 | } |
||
1019 | } |
||
1020 | } |
||
1021 | return $texto; |
||
1022 | } |
||
1023 | |||
1024 | protected static function getCardName($tBand) |
||
1025 | { |
||
1026 | switch ($tBand) { |
||
1027 | case '01': |
||
1028 | $tBandNome = 'VISA'; |
||
1029 | break; |
||
1030 | case '02': |
||
1031 | $tBandNome = 'MASTERCARD'; |
||
1032 | break; |
||
1033 | case '03': |
||
1034 | $tBandNome = 'AMERICAM EXPRESS'; |
||
1035 | break; |
||
1036 | case '04': |
||
1037 | $tBandNome = 'SOROCRED'; |
||
1038 | break; |
||
1039 | case '99': |
||
1040 | $tBandNome = 'OUTROS'; |
||
1041 | break; |
||
1042 | default: |
||
1043 | $tBandNome = ''; |
||
1044 | } |
||
1045 | return $tBandNome; |
||
1046 | } |
||
1047 | |||
1048 | protected function checkCancelada() |
||
1049 | { |
||
1050 | if (!isset($this->nfeProc)) { |
||
1051 | return false; |
||
1052 | } |
||
1053 | $cStat = $this->getTagValue($this->nfeProc, "cStat"); |
||
1054 | return $cStat == '101' || |
||
1055 | $cStat == '151' || |
||
1056 | $cStat == '135' || |
||
1057 | $cStat == '155'; |
||
1058 | } |
||
1059 | |||
1060 | protected function checkDenegada() |
||
1061 | { |
||
1062 | if (!isset($this->nfeProc)) { |
||
1063 | return false; |
||
1064 | } |
||
1065 | //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA |
||
1066 | //1 VEZ NO ARQUIVO INTEIRO |
||
1067 | $cStat = $this->getTagValue($this->nfeProc, "cStat"); |
||
1068 | return $cStat == '110' || |
||
1069 | $cStat == '301' || |
||
1070 | $cStat == '302'; |
||
1071 | } |
||
1072 | } |
||
1073 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.