Passed
Push — master ( 62cd76...600996 )
by Roberto
46s queued 10s
created

src/CTe/DacteOS.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

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\CTe;
4
5
/**
6
 * Classe para ageração do PDF da CTe, conforme regras e estruturas
7
 * estabelecidas pela SEFAZ.
8
 *
9
 * @category  Library
10
 * @package   nfephp-org/sped-da
11
 * @name      Dacte .php
12
 * @copyright 2009-2019 NFePHP
13
 * @license   http://www.gnu.org/licenses/lesser.html LGPL v3
14
 * @link      http://github.com/nfephp-org/sped-da for the canonical source repository
15
 * @author    Roberto L. Machado <linux dot rlm at gmail dot com>
16
 */
17
18
use Com\Tecnick\Barcode\Barcode;
19
use Exception;
20
use NFePHP\DA\Legacy\Dom;
21
use NFePHP\DA\Legacy\Pdf;
22
use NFePHP\DA\Legacy\Common;
23
24
class DacteOS extends Common
25
{
26
27
    protected $logoAlign = 'C';
28
    protected $yDados = 0;
29
    protected $numero_registro_dpec = '';
30
    protected $pdf;
31
    protected $xml;
32
    protected $logomarca = '';
33
    protected $errMsg = '';
34
    protected $errStatus = false;
35
    protected $orientacao = 'P';
36
    protected $papel = 'A4';
37
    protected $fontePadrao = 'Times';
38
    protected $wPrint;
39
    protected $hPrint;
40
    protected $dom;
41
    protected $infCte;
42
    protected $infPercurso;
43
    protected $infCteComp;
44
    protected $chaveCTeRef;
45
    protected $tpCTe;
46
    protected $ide;
47
    protected $emit;
48
    protected $enderEmit;
49
    protected $infCarga;
50
    protected $infQ;
51
    protected $seg;
52
    protected $modal;
53
    protected $rodo;
54
    protected $moto;
55
    protected $veic;
56
    protected $ferrov;
57
    protected $Comp;
58
    protected $infNF;
59
    protected $infNFe;
60
    protected $compl;
61
    protected $ICMS;
62
    protected $imp;
63
    protected $toma4;
64
    protected $toma03;
65
    protected $tpEmis;
66
    protected $tpImp;
67
    protected $tpAmb;
68
    protected $vPrest;
69
    protected $infServico;
70
    protected $wAdic = 150;
71
    protected $textoAdic = '';
72
    protected $debugmode = false;
73
    protected $formatPadrao;
74
    protected $formatNegrito;
75
    protected $aquav;
76
    protected $preVisualizar;
77
    protected $flagDocOrigContinuacao;
78
    protected $arrayNFe = array();
79
    protected $siteDesenvolvedor;
80
    protected $nomeDesenvolvedor;
81
    protected $totPag;
82
    protected $idDocAntEle = [];
83
    protected $lota;
84
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
85
    protected $margemInterna = 0;
86
    private $creditos;
87
88
    /**
89
     * __construct
90
     *
91
     * @param string $xml Arquivo XML da CTe
92
     */
93
    public function __construct(
94
        $xml = ''
95
    ) {
96
        $this->debugMode();
97
        $this->loadDoc($xml);
98
    }
99
100
    /**
101
     * Ativa ou desativa o modo debug
102
     * @param bool $activate
103
     * @return bool
104
     */
105
    private function debugMode($activate = null)
106
    {
107
        if (isset($activate) && is_bool($activate)) {
108
            $this->debugmode = $activate;
109
        }
110
        if ($this->debugmode) {
111
            error_reporting(E_ALL);
112
            ini_set('display_errors', 'On');
113
        } else {
114
            error_reporting(0);
115
            ini_set('display_errors', 'Off');
116
        }
117
        return $this->debugmode;
118
    }
119
120
    private function loadDoc($xml)
121
    {
122
        $this->xml = $xml;
123
        if (!empty($xml)) {
124
            $this->dom = new Dom();
125
            $this->dom->loadXML($this->xml);
126
            $this->cteProc = $this->dom->getElementsByTagName("cteOSProc")->item(0);
127
            if (empty($this->dom->getElementsByTagName("infCte")->item(0))) {
128
                throw new \Exception('Isso não é um CT-e.');
129
            }
130
            $this->infCte = $this->dom->getElementsByTagName("infCte")->item(0);
131
            $this->ide = $this->dom->getElementsByTagName("ide")->item(0);
132
            if ($this->getTagValue($this->ide, "mod") != '67') {
133
                throw new \Exception("O xml deve ser CT-e modelo 67.");
134
            }
135
            $this->emit = $this->dom->getElementsByTagName("emit")->item(0);
136
            $this->enderEmit = $this->dom->getElementsByTagName("enderEmit")->item(0);
137
            $this->infPercurso = $this->dom->getElementsByTagName("infPercurso");
138
            $this->infCarga = $this->dom->getElementsByTagName("infCarga")->item(0);
139
            $this->infQ = $this->dom->getElementsByTagName("infQ");
140
            $this->seg = $this->dom->getElementsByTagName("seg")->item(0);
141
            $this->rodo = $this->dom->getElementsByTagName("rodoOS")->item(0);
142
            $this->veic = $this->dom->getElementsByTagName("veic");
143
            $this->ferrov = $this->dom->getElementsByTagName("ferrov")->item(0);
144
            // adicionar outros modais
145
            $this->infCteComp = $this->dom->getElementsByTagName("infCteComp")->item(0);
146
            $this->chaveCTeRef = $this->getTagValue($this->infCteComp, "chave");
147
            $this->vPrest = $this->dom->getElementsByTagName("vPrest")->item(0);
148
            $this->Comp = $this->dom->getElementsByTagName("Comp");
149
            $this->infNF = $this->dom->getElementsByTagName("infNF");
150
            $this->infNFe = $this->dom->getElementsByTagName("infNFe");
151
            $this->infOutros = $this->dom->getElementsByTagName("infOutros");
152
            $this->infServico = $this->dom->getElementsByTagName("infServico");
153
            $this->compl = $this->dom->getElementsByTagName("compl");
154
            $this->ICMS = $this->dom->getElementsByTagName("ICMS")->item(0);
155
            $this->ICMSSN = $this->dom->getElementsByTagName("ICMSSN")->item(0);
156
            $this->imp = $this->dom->getElementsByTagName("imp")->item(0);
157
158
            $vTrib = $this->getTagValue($this->imp, "vTotTrib");
159
            if (!is_numeric($vTrib)) {
160
                $vTrib = 0;
161
            }
162
            $textoAdic = number_format($vTrib, 2, ",", ".");
163
            $this->textoAdic = "o valor aproximado de tributos incidentes sobre o preço deste serviço é de R$"
164
                .$textoAdic;
165
            $this->toma = $this->dom->getElementsByTagName("toma")->item(0);
166
            $this->enderToma = $this->getTagValue($this->toma, "enderToma");
167
            //modal aquaviário
168
            $this->aquav = $this->dom->getElementsByTagName("aquav")->item(0);
169
            $seguro = $this->getTagValue($this->seg, "respSeg");
170
            switch ($seguro) {
171
                case '4':
172
                    $this->respSeg = 'Emitente';
173
                    break;
174
                case '5':
175
                    $this->respSeg = 'Tomador do Serviço';
176
                    break;
177
                default:
178
                    $this->respSeg = '';
179
                    break;
180
            }
181
            $this->tpEmis = $this->getTagValue($this->ide, "tpEmis");
182
            $this->tpImp = $this->getTagValue($this->ide, "tpImp");
183
            $this->tpAmb = $this->getTagValue($this->ide, "tpAmb");
184
            $this->tpCTe = $this->getTagValue($this->ide, "tpCTe");
185
            $this->protCTe = $this->dom->getElementsByTagName("protCTe")->item(0);
186
            $this->qrCodMDFe = $this->dom->getElementsByTagName('qrCodCTe')->item(0) ?
187
                $this->dom->getElementsByTagName('qrCodCTe')->item(0)->nodeValue : 'SEM INFORMAÇÃO DE QRCODE';
188
            //01-Rodoviário; //02-Aéreo; //03-Aquaviário; //04-Ferroviário;//05-Dutoviário
189
            $this->modal = $this->getTagValue($this->ide, "modal");
190
        }
191
    }
192
193
    /**
194
     * Dados brutos do PDF
195
     * @return string
196
     */
197
    public function render()
198
    {
199
        if (empty($this->pdf)) {
200
            $this->monta();
201
        }
202
        return $this->pdf->getPdf();
203
    }
204
205
206
    protected function cteDPEC()
207
    {
208
        return $this->numero_registro_dpec != '';
209
    }
210
211
212
    /**
213
     * montaDACTE
214
     * Esta função monta a DACTE conforme as informações fornecidas para a classe
215
     * durante sua construção.
216
     * A definição de margens e posições iniciais para a impressão são estabelecidas no
217
     * pelo conteúdo da funçao e podem ser modificados.
218
     *
219
     * @param  string $orientacao (Opcional) Estabelece a orientação da
220
     *                impressão (ex. P-retrato), se nada for fornecido será
221
     *                usado o padrão da NFe
222
     * @param  string $papel (Opcional) Estabelece o tamanho do papel (ex. A4)
223
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
224
     */
225
    public function monta(
226
        $logo = '',
227
        $orientacao = '',
228
        $papel = 'A4',
229
        $logoAlign = 'C'
230
    ) {
231
        $this->pdf = '';
232
        $this->logomarca = $logo;
233
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
234
        if ($orientacao == '') {
235
            if ($this->tpImp == '1') {
236
                $orientacao = 'P';
237
            } else {
238
                $orientacao = 'P';
239
            }
240
        }
241
        $this->orientacao = $orientacao;
242
        $this->papel = $papel;
243
        $this->logoAlign = $logoAlign;
244
        //instancia a classe pdf
245
        $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
246
        $this->formatPadrao = array(
247
            'font' => $this->fontePadrao,
248
            'size' => 6,
249
            'style' => '');
250
        $this->formatNegrito = array(
251
            'font' => $this->fontePadrao,
252
            'size' => 7,
253
            'style' => 'B');
254
        if ($this->orientacao == 'P') {
255
            // margens do PDF
256
            $margSup = 2;
257
            $margEsq = 2;
258
            $margDir = 2;
259
            // posição inicial do relatorio
260
            $xInic = 1;
261
            $yInic = 1;
262
            if ($papel == 'A4') {
263
                //A4 210x297mm
264
                $maxW = 210;
265
                $maxH = 297;
266
            }
267
        } else {
268
            // margens do PDF
269
            $margSup = 3;
270
            $margEsq = 3;
271
            $margDir = 3;
272
            // posição inicial do relatorio
273
            $xInic = 5;
274
            $yInic = 5;
275
            if ($papel == 'A4') {
276
                //A4 210x297mm
277
                $maxH = 210;
278
                $maxW = 297;
279
                $this->wCanhoto = 25;
280
            }
281
        }
282
        //total inicial de paginas
283
        $totPag = 1;
284
        //largura imprimivel em mm
285
        $this->wPrint = $maxW - ($margEsq + $xInic);
286
        //comprimento imprimivel em mm
287
        $this->hPrint = $maxH - ($margSup + $yInic);
288
        // estabelece contagem de paginas
289
        $this->pdf->aliasNbPages();
290
        // fixa as margens
291
        $this->pdf->setMargins($margEsq, $margSup, $margDir);
292
        $this->pdf->setDrawColor(0, 0, 0);
293
        $this->pdf->setFillColor(255, 255, 255);
294
        // inicia o documento
295
        $this->pdf->open();
296
        // adiciona a primeira página
297
        $this->pdf->addPage($this->orientacao, $this->papel);
298
        $this->pdf->setLineWidth(0.1);
299
        $this->pdf->setTextColor(0, 0, 0);
300
        //calculo do numero de páginas ???
301
        $totPag = 1;
302
        //montagem da primeira página
303
        $pag = 1;
304
        $x = $xInic;
305
        $y = $yInic;
306
        //coloca o cabeçalho
307
        //$r = $this->cabecalho($x, $y, $pag, $totPag);
308
        $y += 70;
309
        $r = $this->tomador($x, $y);
310
        if ($this->tpCTe == '0') {
311
            //Normal
312
            $y += 10;
313
            $x = $xInic;
314
            //$r = $this->zDocOrig($x, $y);
315
            $r = $this->infPrestacaoServico($x, $y);
316
            $y += 53;
317
            $x = $xInic;
318
            $r = $this->compValorServ($x, $y);
319
            $y += 25;
320
            $x = $xInic;
321
            $r = $this->impostos($x, $y);
322
            $y += 13;
323
            $x = $xInic;
324
            $r = $this->observacoes($x, $y);
325
            $y += 19;
326
            $x = $xInic;
327
            $r = $this->seguro($x, $y);
328
            $y = $y-12;
329
            switch ($this->modal) {
330
                case '1':
331
                    $y += 24.9;
332
                    $x = $xInic;
333
                    $r = $this->modalRod($x, $y);
334
                    break;
335
                case '2':
336
                    $y += 17.9;
337
                    $x = $xInic;
338
                    // TODO fmertins 31/10/14: este método não existe...
339
                    $r = $this->modalAereo($x, $y);
340
                    break;
341
                case '3':
342
                    $y += 17.9;
343
                    $x = $xInic;
344
                    $r = $this->modalAquaviario($x, $y);
345
                    break;
346
                case '4':
347
                    $y += 17.9;
348
                    $x = $xInic;
349
                    $r = $this->modalFerr($x, $y);
350
                    break;
351
                case '5':
352
                    $y += 17.9;
353
                    $x = $xInic;
354
                    // TODO fmertins 31/10/14: este método não existe...
355
                    $r = $this->modalDutoviario($x, $y);
356
                    break;
357
            }
358
            if ($this->modal == '1') {
359
                if ($this->lota == 1) {
360
                    $y += 37;
361
                } else {
362
                    $y += 8.9;
363
                }
364
            } elseif ($this->modal == '3') {
365
                $y += 24.15;
366
            } else {
367
                $y += 37;
368
            }
369
        } else {
370
            $r = $this->cabecalho(1, 1, $pag, $totPag);
371
            //Complementado
372
            $y += 10;
373
            $x = $xInic;
374
            $r = $this->docCompl($x, $y);
375
            $y += 80;
376
            $x = $xInic;
377
            $r = $this->compValorServ($x, $y);
378
            $y += 25;
379
            $x = $xInic;
380
            $r = $this->impostos($x, $y);
381
            $y += 13;
382
            $x = $xInic;
383
            $r = $this->observacoes($x, $y);
384
            $y += 15;
385
        }
386
        $x = $xInic;
387
        $y += 1;
388
        $r = $this->dadosAdic($x, $y, $pag, $totPag);
389
390
        $y += 21;
391
        //$y += 11;
392
        $y = $this->canhoto($x, $y);
393
394
        //coloca o rodapé da página
395
        if ($this->orientacao == 'P') {
396
            $this->rodape(2, $this->hPrint - 2);
397
        } else {
398
            $this->rodape($xInic, $this->hPrint + 2.3);
399
        }
400
        if ($this->flagDocOrigContinuacao == 1) {
401
            $this->docOrigContinuacao(1, 71);
402
        }
403
    }
404
405
    /**
406
     * cabecalho
407
     * Monta o cabelhalho da DACTE ( retrato e paisagem )
408
     *
409
     * @param  number $x Posição horizontal inicial, canto esquerdo
410
     * @param  number $y Posição vertical inicial, canto superior
411
     * @param  number $pag Número da Página
412
     * @param  number $totPag Total de páginas
413
     * @return number Posição vertical final
414
     */
415
    protected function cabecalho($x = 0, $y = 0, $pag = '1', $totPag = '1')
416
    {
417
        $oldX = $x;
418
        $oldY = $y;
419
        if ($this->orientacao == 'P') {
420
            $maxW = $this->wPrint;
421
        } else {
422
            if ($pag == 1) {
423
                // primeira página
424
                $maxW = $this->wPrint - $this->wCanhoto;
425
            } else {
426
                // páginas seguintes
427
                $maxW = $this->wPrint;
428
            }
429
        }
430
        //##################################################################
431
        //coluna esquerda identificação do emitente
432
        $w = round($maxW * 0.42);
433
        if ($this->orientacao == 'P') {
434
            $aFont = array(
435
                'font' => $this->fontePadrao,
436
                'size' => 6,
437
                'style' => '');
438
        } else {
439
            $aFont = $this->formatNegrito;
440
        }
441
        $w1 = $w;
442
        $h = 35;
443
        $oldY += $h;
444
        //desenha a caixa
445
        $this->pdf->textBox($x, $y, $w + 2, $h + 1);
446
        // coloca o logo
447
        if (!empty($this->logomarca)) {
448
            $logoInfo = getimagesize($this->logomarca);
449
            //largura da imagem em mm
450
            $logoWmm = ($logoInfo[0] / 72) * 25.4;
451
            //altura da imagem em mm
452
            $logoHmm = ($logoInfo[1] / 72) * 25.4;
453
            if ($this->logoAlign == 'L') {
454
                $nImgW = round($w / 3, 0);
455
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
456
                $xImg = $x + 1;
457
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
458
                //estabelecer posições do texto
459
                $x1 = round($xImg + $nImgW + 1, 0);
460
                $y1 = round($h / 3 + $y, 0);
461
                $tw = round(2 * $w / 3, 0);
462
            } elseif ($this->logoAlign == 'C') {
463
                $nImgH = round($h / 3, 0);
464
                $nImgW = round($logoWmm * ($nImgH / $logoHmm), 0);
465
                $xImg = round(($w - $nImgW) / 2 + $x, 0);
466
                $yImg = $y + 3;
467
                $x1 = $x;
468
                $y1 = round($yImg + $nImgH + 1, 0);
469
                $tw = $w;
470
            } elseif ($this->logoAlign == 'R') {
471
                $nImgW = round($w / 3, 0);
472
                $nImgH = round($logoHmm * ($nImgW / $logoWmm), 0);
473
                $xImg = round($x + ($w - (1 + $nImgW)), 0);
474
                $yImg = round(($h - $nImgH) / 2, 0) + $y;
475
                $x1 = $x;
476
                $y1 = round($h / 3 + $y, 0);
477
                $tw = round(2 * $w / 3, 0);
478
            }
479
            $this->pdf->image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, 'jpeg');
480
        } else {
481
            $x1 = $x;
482
            $y1 = round($h / 3 + $y, 0);
483
            $tw = $w;
484
        }
485
        //Nome emitente
486
        $aFont = array(
487
            'font' => $this->fontePadrao,
488
            'size' => 9,
489
            'style' => 'B');
490
        $texto = $this->getTagValue($this->emit, "xNome");
491
        $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
492
        //endereço
493
        $y1 = $y1 + 3;
494
        $aFont = array(
495
            'font' => $this->fontePadrao,
496
            'size' => 7,
497
            'style' => '');
498
        $fone = $this->getTagValue($this->enderEmit, "fone")!=""? $this->formatFone($this->enderEmit):'';
499
        $lgr = $this->getTagValue($this->enderEmit, "xLgr");
500
        $nro = $this->getTagValue($this->enderEmit, "nro");
501
        $cpl = $this->getTagValue($this->enderEmit, "xCpl");
502
        $bairro = $this->getTagValue($this->enderEmit, "xBairro");
503
        $CEP = $this->getTagValue($this->enderEmit, "CEP");
504
        $CEP = $this->formatField($CEP, "#####-###");
505
        $mun = $this->getTagValue($this->enderEmit, "xMun");
506
        $UF = $this->getTagValue($this->enderEmit, "UF");
507
        $xPais = $this->getTagValue($this->enderEmit, "xPais");
508
        $texto = $lgr . "," . $nro . "\n" . $bairro . " - "
509
            . $CEP . " - " . $mun . " - " . $UF . " " . $xPais
510
            . "\n  Fone/Fax: " . $fone;
511
        $this->pdf->textBox($x1 - 5, $y1 + 2, $tw + 5, 8, $texto, $aFont, 'T', 'C', 0, '');
512
        //CNPJ/CPF IE
513
        $cpfCnpj = $this->formatCNPJCPF($this->emit);
514
        $ie = $this->getTagValue($this->emit, "IE");
515
        $texto = 'CNPJ/CPF:  ' . $cpfCnpj . '     Insc.Estadual: ' . $ie;
516
        $this->pdf->textBox($x1 - 1, $y1 + 12, $tw + 5, 8, $texto, $aFont, 'T', 'C', 0, '');
517
        //outra caixa
518
        $h1 = 17.5;
519
        $y1 = $y + $h + 1;
520
        $this->pdf->textBox($x, $y1, $w + 2, $h1);
521
        //TIPO DO CT-E
522
        $texto = 'TIPO DO CTE';
523
        $wa = 37;
524
        $aFont = array(
525
            'font' => $this->fontePadrao,
526
            'size' => 8,
527
            'style' => '');
528
        $this->pdf->textBox($x, $y1, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '');
529
        $tpCTe = $this->getTagValue($this->ide, "tpCTe");
530
        //0 - CT-e Normal,1 - CT-e de Complemento de Valores,
531
        //2 - CT-e de Anulação de Valores,3 - CT-e Substituto
532
        switch ($tpCTe) {
533
            case '0':
534
                $texto = 'Normal';
535
                break;
536
            case '1':
537
                $texto = 'Complemento de Valores';
538
                break;
539
            case '2':
540
                $texto = 'Anulação de Valores';
541
                break;
542
            case '3':
543
                $texto = 'Substituto';
544
                break;
545
            default:
546
                $texto = 'ERRO' . $tpCTe . $tpServ;
547
        }
548
        $aFont = $this->formatNegrito;
549
        $this->pdf->textBox($x, $y1 + 3, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '', false);
550
        //TIPO DO SERVIÇO
551
        $texto = 'TIPO DO SERVIÇO';
552
        $wb = 36;
553
        $aFont = array(
554
            'font' => $this->fontePadrao,
555
            'size' => 8,
556
            'style' => '');
557
        $this->pdf->textBox($x + $wa + 4.5, $y1, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '');
558
        $tpServ = $this->getTagValue($this->ide, "tpServ");
559
        //'6' => 'Transporte de Pessoas', '7' => 'Transporte de Valores', '8' => 'Transporte de Bagagem'
560
        switch ($tpServ) {
561
            case '6':
562
                $texto = 'Transporte de Pessoas';
563
                break;
564
            case '7':
565
                $texto = 'Transporte de Valores';
566
                break;
567
            case '8':
568
                $texto = 'Transporte de Bagagem';
569
                break;
570
            default:
571
                $texto = 'ERRO' . $tpServ;
572
        }
573
        $aFont = $this->formatNegrito;
574
        $this->pdf->textBox($x + $wa + 4.5, $y1 + 3, $w * 0.5, $h1, $texto, $aFont, 'T', 'C', 0, '', false);
575
        $this->pdf->line($w * 0.5, $y1, $w * 0.5, $y1 + $h1);
576
        //TOMADOR DO SERVIÇO
577
        $aFont = $this->formatNegrito;
578
579
        //##################################################################
580
        //coluna direita
581
        $x += $w + 2;
582
        $w = round($maxW * 0.335);
583
        $w1 = $w;
584
        $h = 11;
585
        $this->pdf->textBox($x, $y, $w + 10, $h + 1);
586
        $texto = "DACTE OS";
587
        $aFont = array(
588
            'font' => $this->fontePadrao,
589
            'size' => 10,
590
            'style' => 'B');
591
        $this->pdf->textBox($x, $y + 1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
592
        $aFont = array(
593
            'font' => $this->fontePadrao,
594
            'size' => 9,
595
            'style' => '');
596
        $texto = "Documento Auxiliar do Conhecimento\nde Transporte Eletrônico para Outros Serviços";
597
        $h = 10;
598
        $this->pdf->textBox($x, $y + 4, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
599
        $x1 = $x + $w + 2;
600
        $w = round($maxW * 0.22, 0);
601
        $w2 = $w;
602
        $h = 11;
603
        $this->pdf->textBox($x1 + 8, $y, $w - 7.5, $h + 1);
604
        $texto = "MODAL";
605
        $aFont = array(
606
            'font' => $this->fontePadrao,
607
            'size' => 10,
608
            'style' => '');
609
        $this->pdf->textBox($x1, $y + 1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
610
        switch ($this->modal) {
611
            case '1':
612
                $texto = 'Rodoviário';
613
                break;
614
            case '2':
615
                $texto = 'Aéreo';
616
                break;
617
            case '3':
618
                $texto = 'Aquaviário';
619
                break;
620
            case '4':
621
                $texto = 'Ferroviário';
622
                break;
623
            case '5':
624
                $texto = 'Dutoviário';
625
                break;
626
        }
627
        $aFont = array(
628
            'font' => $this->fontePadrao,
629
            'size' => 10,
630
            'style' => 'B');
631
        $this->pdf->textBox($x1, $y + 5, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
632
        //outra caixa
633
        $y += 12;
634
        $h = 9;
635
        $w = $w1 + 10;
636
        $this->pdf->textBox($x, $y, $w, $h + 1);
637
        //modelo
638
        $wa = 12;
639
        $xa = $x;
640
        $texto = 'MODELO';
641
        $aFont = array(
642
            'font' => $this->fontePadrao,
643
            'size' => 8,
644
            'style' => '');
645
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
646
        $texto = $this->getTagValue($this->ide, "mod");
647
        $aFont = $this->formatNegrito;
648
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
649
        $this->pdf->line($x + $wa, $y, $x + $wa, $y + $h + 1);
650
        //serie
651
        $xa += $wa;
652
        $texto = 'SÉRIE';
653
        $aFont = array(
654
            'font' => $this->fontePadrao,
655
            'size' => 8,
656
            'style' => '');
657
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
658
        $texto = $this->getTagValue($this->ide, "serie");
659
        $aFont = $this->formatNegrito;
660
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
661
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
662
        //numero
663
        $xa += $wa;
664
        $wa = 20;
665
        $texto = 'NÚMERO';
666
        $aFont = array(
667
            'font' => $this->fontePadrao,
668
            'size' => 8,
669
            'style' => '');
670
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
671
        $texto = $this->getTagValue($this->ide, "nCT");
672
        $aFont = $this->formatNegrito;
673
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
674
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
675
        //data  hora de emissão
676
        $xa += $wa;
677
        $wa = 35;
678
        $texto = 'DATA E HORA DE EMISSÃO';
679
        $aFont = array(
680
            'font' => $this->fontePadrao,
681
            'size' => 8,
682
            'style' => '');
683
        $this->pdf->textBox($xa, $y + 1, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
684
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
685
        $texto = !empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
686
            date('d/m/Y H:i:s', $this->convertTime($this->getTagValue($this->ide, "dhEmi"))) : '';
0 ignored issues
show
The method convertTime() does not seem to exist on object<NFePHP\DA\CTe\DacteOS>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
687
        $aFont = $this->formatNegrito;
688
        $this->pdf->textBox($xa, $y + 5, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
689
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h + 1);
690
        //outra caixa
691
        $y += $h + 1;
692
        $h = 23;
693
        $h1 = 14;
694
        //$this->pdf->textBox($x, $y, $w + 0.5, $h1);
695
        //CODIGO DE BARRAS
696
        $chave_acesso = str_replace('CTe', '', $this->infCte->getAttribute("Id"));
697
        $bW = 75;
698
        $bH = 10;
699
        //codigo de barras
700
        $this->pdf->setFillColor(0, 0, 0);
701
        $this->pdf->code128($x + 2, $y + 2, $chave_acesso, $bW, $bH);
702
        $this->pdf->line($xa + $wa, $y, $xa + $wa, $y + $h - 1);
703
        $this->pdf->textBox($x, $y + $h1, $w + 0.5, $h1 - 6);
704
        $texto = 'CHAVE DE ACESSO';
705
        $aFont = $this->formatPadrao;
706
        $this->pdf->textBox($x + 1, $y + $h1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
707
        $aFont = $this->formatNegrito;
708
        $texto = $this->formatField($chave_acesso, $this->formatoChave);
709
        $this->pdf->textBox($x + 1, $y + $h1 + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
710
        $this->pdf->textBox($x, $y + $h1 + 8, $w + 0.5, $h1 - 4.5);
711
        $texto = "Consulta de autenticidade no portal nacional do CT-e, ";
712
        $texto .= "no site da Sefaz Autorizadora, \r\n ou em http://www.cte.fazenda.gov.br";
713
        if ($this->tpEmis == 5 || $this->tpEmis == 7 || $this->tpEmis == 8) {
714
            $texto = "";
715
            $this->pdf->setFillColor(0, 0, 0);
716
            if ($this->tpEmis == 5) {
717
                $chaveContingencia = $this->geraChaveAdicCont();
718
                $this->pdf->code128($x + 20, $y1 + 10, $chaveContingencia, $bW * .9, $bH / 2);
719
            } else {
720
                $chaveContingencia = $this->getTagValue($this->protCTe, "nProt");
721
                $this->pdf->code128($x + 40, $y1 + 10, $chaveContingencia, $bW * .4, $bH / 2);
722
            }
723
            //codigo de barras
724
        }
725
        $aFont = array(
726
            'font' => $this->fontePadrao,
727
            'size' => 8,
728
            'style' => '');
729
        $this->pdf->textBox($x, $y + $h1 + 9, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
730
        //outra caixa
731
        $y += $h + 1;
732
        $h = 8.5;
733
        $wa = $w;
734
        $this->pdf->textBox($x, $y + 7.5, $w + 0.5, $h);
735
        if ($this->cteDPEC()) {
736
            $texto = 'NÚMERO DE REGISTRO DPEC';
737
        } elseif ($this->tpEmis == 5 || $this->tpEmis == 7 || $this->tpEmis == 8) {
738
            $texto = "DADOS DO CT-E";
739
        } else {
740
            $texto = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
741
        }
742
        $aFont = $this->formatPadrao;
743
        $this->pdf->textBox($x, $y + 7.5, $wa, $h, $texto, $aFont, 'T', 'L', 0, '');
744
        if ($this->cteDPEC()) {
745
            $texto = $this->numero_registro_dpec;
746
        } elseif ($this->tpEmis == 5) {
747
            $chaveContingencia = $this->geraChaveAdicCont();
748
            $aFont = array(
749
                'font' => $this->fontePadrao,
750
                'size' => 8,
751
                'style' => 'B');
752
            $texto = $this->formatField($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
753
            $cStat = '';
754
        } else {
755
            $texto = $this->getTagValue($this->protCTe, "nProt") . " - ";
756
            // empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue)
757
            if (!empty($this->protCTe)
758
                && !empty($this->protCTe->getElementsByTagName("dhRecbto")->item(0)->nodeValue)
759
            ) {
760
                $texto .= date(
761
                    'd/m/Y   H:i:s',
762
                    $this->convertTime($this->getTagValue($this->protCTe, "dhRecbto"))
0 ignored issues
show
The method convertTime() does not seem to exist on object<NFePHP\DA\CTe\DacteOS>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
763
                );
764
            }
765
            $texto = $this->getTagValue($this->protCTe, "nProt") == '' ? '' : $texto;
766
        }
767
        $aFont = $this->formatNegrito;
768
        $this->pdf->textBox($x, $y + 12, $wa, $h, $texto, $aFont, 'T', 'C', 0, '');
769
770
        if ($this->qrCodMDFe !== null) {
771
            $this->qrCodeDacteOs($y-25);
772
            $w = 38;
773
            $x += 79;
774
            $this->pdf->textBox($x, $y - 34, $w + 0.5, $h + 41.5);
775
        }
776
        //CFOP
777
        $x = $oldX;
778
        $h = 8.5;
779
        $w = round($maxW * 0.42);
780
        $y1 = $y + 7.5;
781
        $this->pdf->textBox($x, $y1, $w + 2, $h);
782
        $texto = 'CFOP - NATUREZA DA PRESTAÇÃO';
783
        $aFont = array(
784
            'font' => $this->fontePadrao,
785
            'size' => 8,
786
            'style' => '');
787
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
788
        $texto = $this->getTagValue($this->ide, "CFOP") . ' - ' . $this->getTagValue($this->ide, "natOp");
789
        $aFont = $this->formatNegrito;
790
        $this->pdf->textBox($x, $y1 + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
791
        //ORIGEM DA PRESTAÇÃO
792
        $y += $h + 7.5;
793
        $x = $oldX;
794
        $h = 8;
795
        $w = ($maxW * 0.33);
796
        $this->pdf->textBox($x, $y, $w + 0.5, $h);
797
        $texto = 'INÍCIO DA PRESTAÇÃO';
798
        $aFont = array(
799
            'font' => $this->fontePadrao,
800
            'size' => 8,
801
            'style' => '');
802
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
803
        $texto = $this->getTagValue($this->ide, "xMunIni") . ' - ' . $this->getTagValue($this->ide, "UFIni");
804
        $aFont = $this->formatNegrito;
805
        $this->pdf->textBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
806
        //PERCURSO DO VEÍCULO
807
        $x = $oldX + 69;
808
        $oldX = $x;
809
        $h = 8;
810
        $w = ($maxW * 0.334);
811
        $this->pdf->textBox($x, $y, $w + 0.5, $h);
812
        $texto = 'PERCURSO DO VEÍCULO';
813
        $aFont = array(
814
            'font' => $this->fontePadrao,
815
            'size' => 8,
816
            'style' => '');
817
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
818
        $texto = '';
819
        $first = true;
820
        if (!empty($this->infPercurso)) {
821
            foreach ($this->infPercurso as $k => $d) {
822
                if (!$first) {
823
                    $texto .= ' - ';
824
                } else {
825
                    $first = false;
826
                }
827
                $texto .= $this->infPercurso->item($k)->getElementsByTagName('UFPer')->item(0)->nodeValue;
828
            }
829
        }
830
        $aFont = $this->formatNegrito;
831
        $this->pdf->textBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
832
        //DESTINO DA PRESTAÇÃO
833
        $x = $oldX + $w + 1;
834
        $h = 8;
835
        $w = $w - 1.3;
836
        $this->pdf->textBox($x - 0.5, $y, $w + 0.5, $h);
837
        $texto = 'TÉRMINO DA PRESTAÇÃO';
838
        $aFont = array(
839
            'font' => $this->fontePadrao,
840
            'size' => 8,
841
            'style' => '');
842
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
843
        $texto = $this->getTagValue($this->ide, "xMunFim") . ' - ' . $this->getTagValue($this->ide, "UFFim");
844
        $aFont = $this->formatNegrito;
845
        $this->pdf->textBox($x, $y + 3.5, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
846
        //#########################################################################
847
        //Indicação de CTe Homologação, cancelamento e falta de protocolo
848
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
849
        //indicar cancelamento
850
        $cStat = $this->getTagValue($this->cteProc, "cStat");
851
        if ($cStat == '101' || $cStat == '135') {
852
            //101 Cancelamento
853
            $x = 10;
854
            $y = $this->hPrint - 130;
855
            $h = 25;
856
            $w = $maxW - (2 * $x);
857
            $this->pdf->setTextColor(90, 90, 90);
858
            $texto = "CTe CANCELADO";
859
            $aFont = array(
860
                'font' => $this->fontePadrao,
861
                'size' => 48,
862
                'style' => 'B');
863
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
864
            $this->pdf->setTextColor(0, 0, 0);
865
        }
866
        $cStat = $this->getTagValue($this->cteProc, "cStat");
867
        if ($cStat == '110' ||
868
            $cStat == '301' ||
869
            $cStat == '302'
870
        ) {
871
            //110 Denegada
872
            $x = 10;
873
            $y = $this->hPrint - 130;
874
            $h = 25;
875
            $w = $maxW - (2 * $x);
876
            $this->pdf->setTextColor(90, 90, 90);
877
            $texto = "CTe USO DENEGADO";
878
            $aFont = array(
879
                'font' => $this->fontePadrao,
880
                'size' => 48,
881
                'style' => 'B');
882
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
883
            $y += $h;
884
            $h = 5;
885
            $w = $maxW - (2 * $x);
886
            $texto = "SEM VALOR FISCAL";
887
            $aFont = array(
888
                'font' => $this->fontePadrao,
889
                'size' => 48,
890
                'style' => 'B');
891
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
892
            $this->pdf->setTextColor(0, 0, 0);
893
        }
894
        //indicar sem valor
895
        if ($tpAmb != 1 && $this->preVisualizar=='0') { // caso não seja uma DA de produção
896
            $x = 10;
897
            if ($this->orientacao == 'P') {
898
                $y = round($this->hPrint / 2, 0);
899
            } else {
900
                $y = round($this->hPrint / 2, 0);
901
            }
902
            $h = 5;
903
            $w = $maxW - (2 * $x);
904
            $this->pdf->setTextColor(90, 90, 90);
905
            $texto = "SEM VALOR FISCAL";
906
            $aFont = array(
907
                'font' => $this->fontePadrao,
908
                'size' => 48,
909
                'style' => 'B');
910
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
911
            $aFont = array(
912
                'font' => $this->fontePadrao,
913
                'size' => 30,
914
                'style' => 'B');
915
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
916
            $this->pdf->textBox($x, $y + 14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
917
            $this->pdf->setTextColor(0, 0, 0);
918
        } elseif ($this->preVisualizar=='1') { // caso seja uma DA de Pré-Visualização
919
            $h = 5;
920
            $w = $maxW - (2 * 10);
921
            $x = 55;
922
            $y = 240;
923
            $this->pdf->setTextColor(255, 100, 100);
924
            $aFont = array(
925
                'font' => $this->fontePadrao,
926
                'size' => 40,
927
                'style' => 'B');
928
            $texto = "Pré-visualização";
929
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
930
            $this->pdf->setTextColor(255, 100, 100);
931
            $aFont = array(
932
                'font' => $this->fontePadrao,
933
                'size' => 41,
934
                'style' => 'B');
935
            $texto = "Sem Validade Jurídica";
936
            $this->pdf->textBox90($x+20, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
937
            $this->pdf->setTextColor(90, 90, 90);
938
            $texto = "SEM VALOR FISCAL";
939
            $aFont = array(
940
                'font' => $this->fontePadrao,
941
                'size' => 48,
942
                'style' => 'B');
943
            $this->pdf->textBox90($x+40, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
944
            $this->pdf->setTextColor(0, 0, 0); // voltar a cor default
945
        } else {
946
            $x = 10;
947
            if ($this->orientacao == 'P') {
948
                $y = round($this->hPrint * 2 / 3, 0);
949
            } else {
950
                $y = round($this->hPrint / 2, 0);
951
            } //fim orientacao
952
            $h = 5;
953
            $w = $maxW - (2 * $x);
954
            $this->pdf->setTextColor(90, 90, 90);
955
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
956
            if (($this->tpEmis == 5 || $this->tpEmis == 7 || $this->tpEmis == 8) && !$this->cteDPEC()) {
957
                //Contingência
958
                $texto = "DACTE Emitido em Contingência";
959
                $aFont = array(
960
                    'font' => $this->fontePadrao,
961
                    'size' => 48,
962
                    'style' => 'B');
963
                $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
964
                $aFont = array(
965
                    'font' => $this->fontePadrao,
966
                    'size' => 30,
967
                    'style' => 'B');
968
                $texto = "devido à problemas técnicos";
969
                $this->pdf->textBox($x, $y + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
970
            } else {
971
                if (!isset($this->protCTe)) {
972
                    if (!$this->cteDPEC()) {
973
                        $texto = "SEM VALOR FISCAL";
974
                        $aFont = array(
975
                            'font' => $this->fontePadrao,
976
                            'size' => 48,
977
                            'style' => 'B');
978
                        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
979
                    }
980
                    $aFont = array(
981
                        'font' => $this->fontePadrao,
982
                        'size' => 30,
983
                        'style' => 'B');
984
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
985
                    if (!$this->cteDPEC()) {
986
                        $this->pdf->textBox($x, $y + 12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
987
                    } else {
988
                        $this->pdf->textBox($x, $y + 25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
989
                    }
990
                } //fim cteProc
991
                if ($this->tpEmis == 4) {
992
                    //DPEC
993
                    $x = 10;
994
                    $y = $this->hPrint - 130;
995
                    $h = 25;
996
                    $w = $maxW - (2 * $x);
997
                    $this->pdf->setTextColor(200, 200, 200); // 90,90,90 é muito escuro
998
                    $texto = "DACTE impresso em contingência -\n"
999
                        . "DPEC regularmente recebido pela Receita\n"
1000
                        . "Federal do Brasil";
1001
                    $aFont = array(
1002
                        'font' => $this->fontePadrao,
1003
                        'size' => 48,
1004
                        'style' => 'B');
1005
                    $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1006
                    $this->pdf->setTextColor(0, 0, 0);
1007
                }
1008
            } //fim tpEmis
1009
            $this->pdf->setTextColor(0, 0, 0);
1010
        }
1011
        return $oldY;
1012
    }
1013
1014
    /**
1015
     * rodapeDACTE
1016
     * Monta o rodape no final da DACTE ( retrato e paisagem )
1017
     *
1018
     * @param number $xInic Posição horizontal canto esquerdo
1019
     * @param number $yFinal Posição vertical final para impressão
1020
     */
1021
    protected function rodape($x, $y)
1022
    {
1023
        $texto = "Impresso em  " . date('d/m/Y   H:i:s');
1024
        $w = $this->wPrint - 4;
1025
        $aFont = array(
1026
            'font' => $this->fontePadrao,
1027
            'size' => 6,
1028
            'style' => '');
1029
        $this->pdf->textBox($x-1, $y+2, $w, 4, $texto, $aFont, 'T', 'L', 0, '');
1030
        
1031
        $texto = $this->creditos .  "  Powered by NFePHP®";
1032
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
1033
    }
1034
1035
    /**
1036
     * tomador
1037
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1038
     *
1039
     * @param  number $x Posição horizontal canto esquerdo
1040
     * @param  number $y Posição vertical canto superior
1041
     * @return number Posição vertical final
1042
     */
1043
    protected function tomador($x = 0, $y = 0)
1044
    {
1045
        $oldX = $x;
1046
        $oldY = $y;
1047
        if ($this->orientacao == 'P') {
1048
            $maxW = $this->wPrint;
1049
        } else {
1050
            $maxW = $this->wPrint - $this->wCanhoto;
1051
        }
1052
        $w = $maxW;
1053
        $h = 10;
1054
        $texto = 'TOMADOR DO SERVIÇO';
1055
        $aFont = $this->formatPadrao;
1056
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1057
        $aFont = $this->formatNegrito;
1058
        $texto = $this->getTagValue($this->toma, "xNome");
1059
        $this->pdf->textBox($x + 29, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1060
        $x = $maxW * 0.60;
1061
        $texto = 'MUNICÍPIO';
1062
        $aFont = $this->formatPadrao;
1063
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1064
        $texto = $this->getTagValue($this->toma, "xMun");
1065
        $aFont = $this->formatNegrito;
1066
        $this->pdf->textBox($x + 15, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1067
        $x = $maxW * 0.85;
1068
        $texto = 'UF';
1069
        $aFont = $this->formatPadrao;
1070
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1071
        $texto = $this->getTagValue($this->toma, "UF");
1072
        $aFont = $this->formatNegrito;
1073
        $this->pdf->textBox($x + 4, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1074
        $x = $w - 18;
1075
        $texto = 'CEP';
1076
        $aFont = $this->formatPadrao;
1077
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1078
        $texto = $this->formatField($this->getTagValue($this->toma, "CEP"), "#####-###");
1079
        $aFont = $this->formatNegrito;
1080
        $this->pdf->textBox($x + 6, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1081
        $y += 3;
1082
        $x = $oldX;
1083
        $texto = 'ENDEREÇO';
1084
        $aFont = $this->formatPadrao;
1085
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1086
        $aFont = $this->formatNegrito;
1087
        $texto = $this->getTagValue($this->toma, "xLgr") . ',';
1088
        $texto .= $this->getTagValue($this->toma, "nro");
1089
        $texto .= ($this->getTagValue($this->toma, "xCpl") != "") ?
1090
            ' - ' . $this->getTagValue($this->toma, "xCpl") : '';
1091
        $texto .= ' - ' . $this->getTagValue($this->toma, "xBairro");
1092
        $this->pdf->textBox($x + 16, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1093
        $y += 3;
1094
        $texto = 'CNPJ/CPF';
1095
        $aFont = $this->formatPadrao;
1096
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1097
        $texto = $this->formatCNPJCPF($this->toma);
1098
        $aFont = $this->formatNegrito;
1099
        $this->pdf->textBox($x + 13, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1100
        $x = $x + 65;
1101
        $texto = 'INSCRIÇÃO ESTADUAL';
1102
        $aFont = $this->formatPadrao;
1103
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1104
        $texto = $this->getTagValue($this->toma, "IE");
1105
        $aFont = $this->formatNegrito;
1106
        $this->pdf->textBox($x + 28, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1107
        $x = $w * 0.75;
1108
        $texto = 'PAÍS';
1109
        $aFont = $this->formatPadrao;
1110
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1111
        $texto = $this->getTagValue($this->toma, "xPais") != "" ?
1112
            $this->getTagValue($this->toma, "xPais") : 'BRASIL';
1113
        $aFont = $this->formatNegrito;
1114
        $this->pdf->textBox($x + 6, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1115
        $x = $w - 27;
1116
        $texto = 'FONE';
1117
        $aFont = $this->formatPadrao;
1118
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1119
        $texto = $this->getTagValue($this->toma, "fone")!=""? $this->formatFone($this->toma):'';
1120
        $aFont = $this->formatNegrito;
1121
        $this->pdf->textBox($x + 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1122
    }
1123
1124
    /**
1125
     * compValorServ
1126
     * Monta o campo com os componentes da prestação de serviços.
1127
     *
1128
     * @param  number $x Posição horizontal canto esquerdo
1129
     * @param  number $y Posição vertical canto superior
1130
     * @return number Posição vertical final
1131
     */
1132
    protected function compValorServ($x = 0, $y = 0)
1133
    {
1134
        $oldX = $x;
1135
        $oldY = $y;
1136
        if ($this->orientacao == 'P') {
1137
            $maxW = $this->wPrint;
1138
        } else {
1139
            $maxW = $this->wPrint - $this->wCanhoto;
1140
        }
1141
        $w = $maxW;
1142
        $h = 25;
1143
        $texto = 'COMPONENTES DO VALOR DA PRESTAÇÃO DO SERVIÇO';
1144
        $aFont = $this->formatPadrao;
1145
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1146
        $y += 3.4;
1147
        $this->pdf->line($x, $y, $w + 1, $y);
1148
        $texto = 'NOME';
1149
        $aFont = $this->formatPadrao;
1150
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1151
        $yIniDados = $y;
1152
        $x = $w * 0.14;
1153
        $texto = 'VALOR';
1154
        $aFont = $this->formatPadrao;
1155
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1156
        $x = $w * 0.28;
1157
        $this->pdf->line($x, $y, $x, $y + 21.5);
1158
        $texto = 'NOME';
1159
        $aFont = $this->formatPadrao;
1160
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1161
        $x = $w * 0.42;
1162
        $texto = 'VALOR';
1163
        $aFont = $this->formatPadrao;
1164
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1165
        $x = $w * 0.56;
1166
        $this->pdf->line($x, $y, $x, $y + 21.5);
1167
        $texto = 'NOME';
1168
        $aFont = $this->formatPadrao;
1169
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1170
        $x = $w * 0.70;
1171
        $texto = 'VALOR';
1172
        $aFont = $this->formatPadrao;
1173
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1174
        $x = $w * 0.86;
1175
        $this->pdf->line($x, $y, $x, $y + 21.5);
1176
        $y += 1;
1177
        $texto = 'VALOR TOTAL DO SERVIÇO';
1178
        $aFont = $this->formatPadrao;
1179
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1180
        $texto = number_format($this->getTagValue($this->vPrest, "vTPrest"), 2, ",", ".");
1181
        $aFont = array(
1182
            'font' => $this->fontePadrao,
1183
            'size' => 9,
1184
            'style' => 'B');
1185
        $this->pdf->textBox($x, $y + 4, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1186
        $y += 10;
1187
        $this->pdf->line($x, $y, $w + 1, $y);
1188
        $y += 1;
1189
        $texto = 'VALOR A RECEBER';
1190
        $aFont = $this->formatPadrao;
1191
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1192
        $texto = number_format($this->getTagValue($this->vPrest, "vRec"), 2, ",", ".");
1193
        $aFont = array(
1194
            'font' => $this->fontePadrao,
1195
            'size' => 9,
1196
            'style' => 'B');
1197
        $this->pdf->textBox($x, $y + 4, $w * 0.14, $h, $texto, $aFont, 'T', 'C', 0, '');
1198
        $auxX = $oldX;
1199
        $yIniDados += 4;
1200
1201
        foreach ($this->Comp as $k => $d) {
1202
            $nome = $this->Comp->item($k)->getElementsByTagName('xNome')->item(0)->nodeValue;
1203
            $valor = number_format(
1204
                $this->Comp->item($k)->getElementsByTagName('vComp')->item(0)->nodeValue,
1205
                2,
1206
                ",",
1207
                "."
1208
            );
1209
            if ($auxX > $w * 0.60) {
1210
                $yIniDados = $yIniDados + 4;
1211
                $auxX = $oldX;
1212
            }
1213
            $texto = $nome;
1214
            $aFont = $this->formatPadrao;
1215
            $this->pdf->textBox($auxX, $yIniDados, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1216
            $auxX += $w * 0.14;
1217
            $texto = $valor;
1218
            $aFont = $this->formatPadrao;
1219
            $this->pdf->textBox($auxX, $yIniDados, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1220
            $auxX += $w * 0.14;
1221
        }
1222
    } //fim da função compValorDACTE
1223
1224
    /**
1225
     * impostos
1226
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1227
     *
1228
     * @param  number $x Posição horizontal canto esquerdo
1229
     * @param  number $y Posição vertical canto superior
1230
     * @return number Posição vertical final
1231
     */
1232
    protected function impostos($x = 0, $y = 0)
1233
    {
1234
        $oldX = $x;
1235
        $oldY = $y;
1236
        if ($this->orientacao == 'P') {
1237
            $maxW = $this->wPrint;
1238
        } else {
1239
            $maxW = $this->wPrint - $this->wCanhoto;
1240
        }
1241
        $w = $maxW;
1242
        $h = 13;
1243
        $texto = 'INFORMAÇÕES RELATIVAS AO IMPOSTO';
1244
        $aFont = $this->formatPadrao;
1245
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1246
1247
        $y += 3.4;
1248
        $this->pdf->line($x, $y, $w + 1, $y);
1249
        $texto = 'SITUAÇÃO TRIBUTÁRIA';
1250
        $aFont = $this->formatPadrao;
1251
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1252
1253
        $x += $w * 0.26;
1254
        $this->pdf->line($x, $y, $x, $y + 9.5);
1255
        $texto = 'BASE DE CALCULO';
1256
        $aFont = $this->formatPadrao;
1257
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1258
1259
        $wCol02=0.18;
1260
        $x += $w * $wCol02;
1261
        $this->pdf->line($x, $y, $x, $y + 9.5);
1262
        $texto = 'ALÍQ ICMS';
1263
        $aFont = $this->formatPadrao;
1264
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1265
1266
        $x += $w * $wCol02;
1267
        $this->pdf->line($x, $y, $x, $y + 9.5);
1268
        $texto = 'VALOR ICMS';
1269
        $aFont = $this->formatPadrao;
1270
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1271
1272
        $x += $w * $wCol02;
1273
        $this->pdf->line($x, $y, $x, $y + 9.5);
1274
        $texto = '% RED. BC ICMS';
1275
        $aFont = $this->formatPadrao;
1276
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1277
1278
        /*$x += $w * 0.14;
1279
        $this->pdf->line($x, $y, $x, $y + 9.5);
1280
        $texto = 'ICMS ST';
1281
        $aFont = $this->formatPadrao;
1282
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1283
         * */
1284
1285
        $x = $oldX;
1286
        $y = $y + 4;
1287
        $texto = $this->getTagValue($this->ICMS, "CST");
1288
        switch ($texto) {
1289
            case '00':
1290
                $texto = "00 - Tributação normal ICMS";
1291
                break;
1292
            case '20':
1293
                $texto = "20 - Tributação com BC reduzida do ICMS";
1294
                break;
1295
            case '40':
1296
                $texto = "40 - ICMS isenção";
1297
                break;
1298
            case '41':
1299
                $texto = "41 - ICMS não tributada";
1300
                break;
1301
            case '51':
1302
                $texto = "51 - ICMS diferido";
1303
                break;
1304
            case '60':
1305
                $texto = "60 - ICMS cobrado anteriormente por substituição tributária";
1306
                break;
1307
            case '90':
1308
                $texto = "90 - ICMS outros";
1309
                break;
1310
        }
1311
        $texto = $this->getTagValue($this->ICMSSN, "indSN") == 1 ? 'Simples Nacional' : $texto;
1312
        $aFont = $this->formatNegrito;
1313
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1314
        $x += $w * 0.26;
1315
1316
        $texto = !empty($this->ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
1317
            number_format($this->getTagValue($this->ICMS, "vBC"), 2, ",", ".") : '';
1318
        $aFont = $this->formatNegrito;
1319
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1320
        $x += $w * $wCol02;
1321
1322
        $texto = !empty($this->ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
1323
            number_format($this->getTagValue($this->ICMS, "pICMS"), 2, ",", ".") : '';
1324
        $aFont = $this->formatNegrito;
1325
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1326
        $x += $w * $wCol02;
1327
1328
        $texto = !empty($this->ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
1329
            number_format($this->getTagValue($this->ICMS, "vICMS"), 2, ",", ".") : '';
1330
        $aFont = $this->formatNegrito;
1331
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1332
        $x += $w * $wCol02;
1333
1334
        $texto = !empty($this->ICMS->getElementsByTagName("pRedBC")->item(0)->nodeValue) ?
1335
            number_format($this->getTagValue($this->ICMS, "pRedBC"), 2, ",", ".").'%' :'';
1336
        $aFont = $this->formatNegrito;
1337
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1338
1339
        /*$x += $w * 0.14;
1340
        $texto = '';
1341
        $aFont = $this->formatNegrito;
1342
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');*/
1343
    } //fim da função compValorDACTE
1344
1345
    /**
1346
     * geraChaveAdicCont
1347
     *
1348
     * @return string chave
1349
     */
1350
    protected function geraChaveAdicCont()
1351
    {
1352
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
1353
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
1354
        $forma = "%02d%d%s%014d%01d%01d%02d";
1355
        $cUF = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
1356
        $CNPJ = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
1357
        $CNPJ = substr($CNPJ, -14);
1358
        $vCT = number_format($this->getTagValue($this->vPrest, "vRec"), 2, "", "") * 100;
1359
        $ICMS_CST = $this->getTagValue($this->ICMS, "CST");
1360
        switch ($ICMS_CST) {
1361
            case '00':
1362
            case '20':
1363
                $ICMSp = '1';
1364
                $ICMSs = '2';
1365
                break;
1366
            case '40':
1367
            case '41':
1368
            case '51':
1369
            case '90':
1370
                $ICMSp = '2';
1371
                $ICMSs = '2';
1372
                break;
1373
            case '60':
1374
                $ICMSp = '2';
1375
                $ICMSs = '1';
1376
                break;
1377
        }
1378
        $dd = $this->ide->getElementsByTagName('dEmi')->item(0)->nodeValue;
1379
        $rpos = strrpos($dd, '-');
1380
        $dd = substr($dd, $rpos + 1);
1381
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vCT, $ICMSp, $ICMSs, $dd);
1382
        $chave = $chave . $this->pModulo11($chave);
1383
        return $chave;
1384
    } //fim geraChaveAdicCont
1385
1386
    /**
1387
     * infPrestacaoServico
1388
     * Monta o campo com das informações da prestação do serviço
1389
     *
1390
     * @param  number $x Posição horizontal canto esquerdo
1391
     * @param  number $y Posição vertical canto superior
1392
     * @return number Posição vertical final
1393
     */
1394
    protected function infPrestacaoServico($x = 0, $y = 0)
1395
    {
1396
        $oldX = $x;
1397
        $oldY = $y;
1398
        if ($this->orientacao == 'P') {
1399
            $maxW = $this->wPrint;
1400
        } else {
1401
            $maxW = $this->wPrint - $this->wCanhoto;
1402
        }
1403
        $w = $maxW;
1404
1405
        // SE FOR RODOVIARIO ( BTR-SEMPRE SERÁ )
1406
        if ($this->modal == '1') {
1407
            // 0 - Não; 1 - Sim Será lotação quando houver um único conhecimento de transporte por veículo,
1408
            // ou combinação veicular, e por viagem
1409
            $h = $this->lota == 1 ? 35 : 53;
1410
        } elseif ($this->modal == '3') {
1411
            $h = 37.6;
1412
        } else {
1413
            $h = 35;
1414
        }
1415
        $texto = 'INFORMAÇÕES DA PRESTAÇÃO DO SERVIÇO';
1416
        $aFont = $this->formatPadrao;
1417
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1418
        $descr1 = 'QUANTIDADE';
1419
        $descr2 = 'DESCRIÇÃO DO SERVIÇO PRESTADO';
1420
1421
        $y += 3.4;
1422
        $this->pdf->line($x, $y, $w + 1, $y); // LINHA ABAIXO DO TEXTO: "DOCUMENTOS ORIGINÁRIOS
1423
        $texto = $descr1;
1424
        $aFont = $this->formatPadrao;
1425
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1426
        $yIniDados = $y;
1427
1428
        $x += $w * 0.14;
1429
        if ($this->modal == '1') {
1430
            if ($this->lota == 1) {
1431
                $this->pdf->line($x, $y, $x, $y + 31.5); // TESTE
1432
            } else {
1433
                $this->pdf->line($x, $y, $x, $y + 49.5); // TESTE
1434
            }
1435
        } elseif ($this->modal == '3') {
1436
            $this->pdf->line($x, $y, $x, $y + 34.1);
1437
        } else {
1438
            $this->pdf->line($x, $y, $x, $y + 21.5);
1439
        }
1440
1441
        $x += $w * 0.08;
1442
        $texto = $descr2;
1443
        $aFont = $this->formatPadrao;
1444
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1445
1446
        //$auxX = $oldX;
1447
        //$yIniDados += 3;
1448
1449
        $x = $oldX;
1450
        $y = $y + 4;
1451
        $texto = number_format($this->getTagValue($this->infQ->item(0), "qCarga"), 3, ",", ".");
1452
        $aFont = $this->formatNegrito;
1453
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1454
        $x += $w * 0.26;
1455
1456
        $x = $oldX + 35;
1457
        $texto = $this->getTagValue($this->infServico->item(0), "xDescServ");
1458
        $aFont = $this->formatNegrito;
1459
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1460
        $x += $w * 0.26;
1461
1462
1463
        $r = $this->cabecalho(1, 1, '1', $this->totPag);
1464
        $contador = 0;
1465
    }
1466
1467
    /**
1468
     * docCompl
1469
     * Monta o campo com os dados do remetente na DACTE.
1470
     *
1471
     * @param number $x Posição horizontal canto esquerdo
1472
     * @param number $y Posição vertical canto superior
1473
     * @return number Posição vertical final
1474
     */
1475
    protected function docCompl($x = 0, $y = 0)
1476
    {
1477
        $oldX = $x;
1478
        $oldY = $y;
1479
        if ($this->orientacao == 'P') {
1480
            $maxW = $this->wPrint;
1481
        } else {
1482
            $maxW = $this->wPrint - $this->wCanhoto;
1483
        }
1484
        $w = $maxW;
1485
        $h = 80;
1486
        $texto = 'DETALHAMENTO DO CT-E COMPLEMENTADO';
1487
        $aFont = $this->formatPadrao;
1488
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1489
        $descr1 = 'CHAVE DO CT-E COMPLEMENTADO';
1490
        $descr2 = 'VALOR COMPLEMENTADO';
1491
        $y += 3.4;
1492
        $this->pdf->line($x, $y, $w + 1, $y);
1493
        $texto = $descr1;
1494
        $aFont = $this->formatPadrao;
1495
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1496
        $yIniDados = $y;
1497
        $x += $w * 0.37;
1498
        $texto = $descr2;
1499
        $aFont = $this->formatPadrao;
1500
        $this->pdf->textBox($x - 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1501
        $x += $w * 0.13;
1502
        $this->pdf->line($x, $y, $x, $y + 76.5);
1503
        $texto = $descr1;
1504
        $aFont = $this->formatPadrao;
1505
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1506
        $x += $w * 0.3;
1507
        $texto = $descr2;
1508
        $aFont = $this->formatPadrao;
1509
        $this->pdf->textBox($x + 8, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1510
        $auxX = $oldX;
1511
        $yIniDados += 4;
1512
        if ($auxX > $w * 0.90) {
1513
            $yIniDados = $yIniDados + 4;
1514
            $auxX = $oldX;
1515
        }
1516
        $texto = $this->chaveCTeRef;
1517
        $aFont = array(
1518
            'font' => $this->fontePadrao,
1519
            'size' => 8,
1520
            'style' => '');
1521
        $this->pdf->textBox($auxX, $yIniDados, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1522
        $texto = number_format($this->getTagValue($this->vPrest, "vTPrest"), 2, ",", ".");
1523
        $aFont = array(
1524
            'font' => $this->fontePadrao,
1525
            'size' => 8,
1526
            'style' => '');
1527
        $this->pdf->textBox($w * 0.40, $yIniDados, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1528
    }
1529
    
1530
    /**
1531
     * observacoes
1532
     * Monta o campo com os dados do remetente na DACTE.
1533
     *
1534
     * @param  number $x Posição horizontal canto esquerdo
1535
     * @param  number $y Posição vertical canto superior
1536
     * @return number Posição vertical final
1537
     */
1538
    protected function observacoes($x = 0, $y = 0)
1539
    {
1540
        $oldX = $x;
1541
        $oldY = $y;
1542
        if ($this->orientacao == 'P') {
1543
            $maxW = $this->wPrint;
1544
        } else {
1545
            $maxW = $this->wPrint - $this->wCanhoto;
1546
        }
1547
        $w = $maxW;
1548
        //$h = 18;
1549
        $h = 18.8;
1550
        $texto = 'OBSERVAÇÕES GERAIS';
1551
        $aFont = $this->formatPadrao;
1552
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1553
        $y += 3.4;
1554
        $this->pdf->line($x, $y, $w + 1, $y);
1555
        $auxX = $oldX;
1556
        $yIniDados = $y;
1557
        $texto = '';
1558
        foreach ($this->compl as $k => $d) {
1559
            $xObs = $this->getTagValue($this->compl->item($k), "xObs");
1560
            $texto .= $xObs;
1561
        }
1562
        $textoObs = explode("Motorista:", $texto);
1563
        $textoObs[1] = isset($textoObs[1]) ? "Motorista: ".$textoObs[1]: '';
1564
        $texto .= $this->getTagValue($this->imp, "infAdFisco", "\r\n");
1565
        $aFont = array(
1566
            'font' => $this->fontePadrao,
1567
            'size' => 7.5,
1568
            'style' => '');
1569
        $this->pdf->textBox($x, $y, $w, $h, $textoObs[0], $aFont, 'T', 'L', 0, '', false);
1570
        $this->pdf->textBox($x, $y+11.5, $w, $h, $textoObs[1], $aFont, 'T', 'L', 0, '', false);
1571
    }
1572
1573
    /**
1574
     * seguro
1575
     * Monta o campo com os dados de seguro do CT-e OS.
1576
     *
1577
     * @param  number $x Posição horizontal canto esquerdo
1578
     * @param  number $y Posição vertical canto superior
1579
     * @return number Posição vertical final
1580
     */
1581
    protected function seguro($x = 0, $y = 0)
1582
    {
1583
        $oldX = $x;
1584
        $oldY = $y;
1585
        if ($this->orientacao == 'P') {
1586
            $maxW = $this->wPrint;
1587
        } else {
1588
            $maxW = $this->wPrint - $this->wCanhoto;
1589
        }
1590
        $w = $maxW;
1591
        $h = 13;
1592
        $texto = 'SEGURO DA VIAGEM';
1593
        $aFont = $this->formatPadrao;
1594
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1595
1596
        $y += 3.4;
1597
        $this->pdf->line($x, $y, $w + 1, $y);
1598
        $texto = 'RESPONSÁVEL';
1599
        $aFont = $this->formatPadrao;
1600
        $this->pdf->textBox($x, $y, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
1601
1602
        $x += $w * 0.33;
1603
        $this->pdf->line($x, $y, $x, $y + 9.5);
1604
        $texto = 'NOME DA SEGURADORA';
1605
        $aFont = $this->formatPadrao;
1606
        $this->pdf->textBox($x, $y, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
1607
1608
        $wCol02=0.33;
1609
        $x += $w * $wCol02;
1610
        $this->pdf->line($x, $y, $x, $y + 9.5);
1611
        $texto = 'NÚMERO DA APÓLICE';
1612
        $aFont = $this->formatPadrao;
1613
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1614
1615
        $x = $oldX;
1616
        $y = $y + 4;
1617
        $texto = $this->respSeg;
1618
        $aFont = $this->formatNegrito;
1619
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1620
        $x += $w * 0.26;
1621
1622
        $texto = '';
1623
        $aFont = $this->formatNegrito;
1624
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1625
        $x += $w * $wCol02;
1626
1627
        $texto = '';
1628
        $aFont = $this->formatNegrito;
1629
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1630
        $x += $w * $wCol02;
1631
    }
1632
1633
    /**
1634
     * modalRod
1635
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1636
     *
1637
     * @param  number $x Posição horizontal canto esquerdo
1638
     * @param  number $y Posição vertical canto superior
1639
     * @return number Posição vertical final
1640
     */
1641
    protected function modalRod($x = 0, $y = 0)
1642
    {
1643
        $oldX = $x;
1644
        $oldY = $y;
1645
        if ($this->orientacao == 'P') {
1646
            $maxW = $this->wPrint;
1647
        } else {
1648
            $maxW = $this->wPrint - $this->wCanhoto;
1649
        }
1650
        $w = $maxW;
1651
        $h = 13;
1652
        $texto = 'DADOS ESPECÍFICOS DO MODAL RODOVIÁRIO';
1653
        $aFont = $this->formatPadrao;
1654
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1655
1656
        $y += 3.4;
1657
        $this->pdf->line($x, $y, $w + 1, $y);
1658
        $texto = 'TERMO DE AUTORIZAÇÃO DE FRETAMENTO';
1659
        $aFont = $this->formatPadrao;
1660
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1661
1662
        $x += $w * 0.26;
1663
        $this->pdf->line($x, $y, $x, $y + 9.5);
1664
        $texto = 'Nº DE REGISTRO ESTADUAL';
1665
        $aFont = $this->formatPadrao;
1666
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');
1667
1668
        $wCol02=0.18;
1669
        $x += $w * $wCol02;
1670
        $this->pdf->line($x, $y, $x, $y + 9.5);
1671
        $texto = 'PLACA DO VEÍCULO';
1672
        $aFont = $this->formatPadrao;
1673
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1674
1675
        $x += $w * $wCol02;
1676
        $this->pdf->line($x, $y, $x, $y + 9.5);
1677
        $texto = 'RENAVAM DO VEÍCULO';
1678
        $aFont = $this->formatPadrao;
1679
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1680
1681
        $x += $w * $wCol02;
1682
        $this->pdf->line($x, $y, $x, $y + 9.5);
1683
        $texto = 'CNPJ/CPF';
1684
        $aFont = $this->formatPadrao;
1685
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1686
1687
        $x = $oldX;
1688
        $y = $y + 4;
1689
        $texto = $this->getTagValue($this->rodo, "TAF");
1690
        $aFont = $this->formatNegrito;
1691
        $this->pdf->textBox($x, $y, $w * 0.26, $h, $texto, $aFont, 'T', 'L', 0, '');
1692
        $x += $w * 0.26;
1693
1694
        $texto = $this->getTagValue($this->rodo, "NroRegEstadual");
1695
        $aFont = $this->formatNegrito;
1696
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1697
        $x += $w * $wCol02;
1698
1699
        $texto = $this->getTagValue($this->veic->item(0), "placa");
1700
        $aFont = $this->formatNegrito;
1701
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1702
        $x += $w * $wCol02;
1703
1704
        $texto = $this->getTagValue($this->veic->item(0), "RENAVAM");
1705
        $aFont = $this->formatNegrito;
1706
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1707
        $x += $w * $wCol02;
1708
1709
        $texto = !empty($this->getTagValue($this->veic->item(0), "CPF")) ?
1710
            $this->getTagValue($this->veic->item(0), "CPF") :
1711
            (!empty($this->getTagValue($this->veic->item(0), "CNPJ")) ?
1712
            $this->getTagValue($this->veic->item(0), "CNPJ") : '');
1713
        $aFont = $this->formatNegrito;
1714
        $this->pdf->textBox($x, $y, $w * $wCol02, $h, $texto, $aFont, 'T', 'L', 0, '');
1715
1716
        /*$x += $w * 0.14;
1717
        $texto = '';
1718
        $aFont = $this->formatNegrito;
1719
        $this->pdf->textBox($x, $y, $w * 0.14, $h, $texto, $aFont, 'T', 'L', 0, '');*/
1720
    }
1721
1722
    /**
1723
     * modalAquaviario
1724
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1725
     *
1726
     * @param  number $x Posição horizontal canto esquerdo
1727
     * @param  number $y Posição vertical canto superior
1728
     * @return number Posição vertical final
1729
     */
1730
    protected function modalAquaviario($x = 0, $y = 0)
1731
    {
1732
        $oldX = $x;
1733
        $oldY = $y;
1734
        if ($this->orientacao == 'P') {
1735
            $maxW = $this->wPrint;
1736
        } else {
1737
            $maxW = $this->wPrint - $this->wCanhoto;
1738
        }
1739
        $w = $maxW;
1740
        $h = 8.5;
1741
        $texto = 'DADOS ESPECÍFICOS DO MODAL AQUAVIÁRIO';
1742
        $aFont = $this->formatPadrao;
1743
        $this->pdf->textBox($x, $y, $w, $h * 3.2, $texto, $aFont, 'T', 'C', 1, '');
1744
        $y += 3.4;
1745
        $this->pdf->line($x, $y, $w + 1, $y);
1746
        $texto = 'PORTO DE EMBARQUE';
1747
        $aFont = $this->formatPadrao;
1748
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1749
        $texto = $this->getTagValue($this->aquav, "prtEmb");
1750
        $aFont = $this->formatNegrito;
1751
        $this->pdf->textBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1752
        $x += $w * 0.50;
1753
        $this->pdf->line($x, $y, $x, $y + 7.7);
1754
        $texto = 'PORTO DE DESTINO';
1755
        $aFont = $this->formatPadrao;
1756
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1757
        $texto = $this->getTagValue($this->aquav, "prtDest");
1758
        $aFont = $this->formatNegrito;
1759
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1760
        $y += 8;
1761
        $this->pdf->line(208, $y, 1, $y);
1762
        $x = 1;
1763
        $texto = 'IDENTIFICAÇÃO DO NAVIO / REBOCADOR';
1764
        $aFont = $this->formatPadrao;
1765
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1766
        $texto = $this->getTagValue($this->aquav, "xNavio");
1767
        $aFont = $this->formatNegrito;
1768
        $this->pdf->textBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1769
        $x += $w * 0.50;
1770
        $this->pdf->line($x, $y, $x, $y + 7.7);
1771
        $texto = 'VR DA B. DE CALC. AFRMM';
1772
        $aFont = $this->formatPadrao;
1773
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1774
        $texto = $this->getTagValue($this->aquav, "vPrest");
1775
        $aFont = $this->formatNegrito;
1776
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1777
        $x += $w * 0.17;
1778
        $this->pdf->line($x, $y, $x, $y + 7.7);
1779
        $texto = 'VALOR DO AFRMM';
1780
        $aFont = $this->formatPadrao;
1781
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1782
        $texto = $this->getTagValue($this->aquav, "vAFRMM");
1783
        $aFont = $this->formatNegrito;
1784
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1785
        $x += $w * 0.12;
1786
        $this->pdf->line($x, $y, $x, $y + 7.7);
1787
        $texto = 'TIPO DE NAVEGAÇÃO';
1788
        $aFont = $this->formatPadrao;
1789
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1790
        $texto = $this->getTagValue($this->aquav, "tpNav");
1791
        switch ($texto) {
1792
            case '0':
1793
                $texto = 'INTERIOR';
1794
                break;
1795
            case '1':
1796
                $texto = 'CABOTAGEM';
1797
                break;
1798
        }
1799
        $aFont = $this->formatNegrito;
1800
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1801
        $x += $w * 0.14;
1802
        $this->pdf->line($x, $y, $x, $y + 7.7);
1803
        $texto = 'DIREÇÃO';
1804
        $aFont = $this->formatPadrao;
1805
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1806
        $texto = $this->getTagValue($this->aquav, "direc");
1807
        switch ($texto) {
1808
            case 'N':
1809
                $texto = 'NORTE';
1810
                break;
1811
            case 'L':
1812
                $texto = 'LESTE';
1813
                break;
1814
            case 'S':
1815
                $texto = 'SUL';
1816
                break;
1817
            case 'O':
1818
                $texto = 'OESTE';
1819
                break;
1820
        }
1821
        $aFont = $this->formatNegrito;
1822
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1823
        $y += 8;
1824
        $this->pdf->line(208, $y, 1, $y);
1825
        $x = 1;
1826
        $texto = 'IDENTIFICAÇÃO DOS CONTEINERS';
1827
        $aFont = $this->formatPadrao;
1828
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1829
        if ($this->infNF->item(0) !== null && $this->infNF->item(0)->getElementsByTagName('infUnidCarga') !== null) {
1830
            $texto = $this->infNF
1831
                ->item(0)
1832
                ->getElementsByTagName('infUnidCarga')
1833
                ->item(0)
1834
                ->getElementsByTagName('idUnidCarga')
1835
                ->item(0)->nodeValue;
1836
        } elseif ($this->infNFe->item(0) !== null
1837
            && $this->infNFe->item(0)->getElementsByTagName('infUnidCarga') !== null
1838
        ) {
1839
            $texto = $this->infNFe
1840
                ->item(0)
1841
                ->getElementsByTagName('infUnidCarga')
1842
                ->item(0)
1843
                ->getElementsByTagName('idUnidCarga')
1844
                ->item(0)
1845
                ->nodeValue;
1846
        } elseif ($this->infOutros->item(0) !== null
1847
            && $this->infOutros->item(0)->getElementsByTagName('infUnidCarga') !== null
1848
        ) {
1849
            $texto = $this->infOutros
1850
                ->item(0)
1851
                ->getElementsByTagName('infUnidCarga')
1852
                ->item(0)
1853
                ->getElementsByTagName('idUnidCarga')
1854
                ->item(0)
1855
                ->nodeValue;
1856
        } else {
1857
            $texto = '';
1858
        }
1859
        $aFont = $this->formatNegrito;
1860
        $this->pdf->textBox($x, $y + 3, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1861
        $x += $w * 0.50;
1862
        $this->pdf->line($x, $y, $x, $y + 7.7);
1863
        $texto = 'IDENTIFICAÇÃO DAS BALSAS';
1864
        $aFont = $this->formatPadrao;
1865
        $this->pdf->textBox($x, $y, $w * 0.23, $h, $texto, $aFont, 'T', 'L', 0, '');
1866
        $texto = '';
1867
        if ($this->getTagValue($this->aquav, "balsa") !== '') {
1868
            foreach ($this->aquav->getElementsByTagName('balsa') as $k => $d) {
1869
                if ($k == 0) {
1870
                    $texto = $this->aquav
1871
                        ->getElementsByTagName('balsa')
1872
                        ->item($k)
1873
                        ->getElementsByTagName('xBalsa')
1874
                        ->item(0)
1875
                        ->nodeValue;
1876
                } else {
1877
                    $texto = $texto
1878
                        . ' / '
1879
                        . $this->aquav
1880
                            ->getElementsByTagName('balsa')
1881
                            ->item($k)
1882
                            ->getElementsByTagName('xBalsa')
1883
                            ->item(0)
1884
                            ->nodeValue;
1885
                }
1886
            }
1887
        }
1888
        $aFont = $this->formatNegrito;
1889
        $this->pdf->textBox($x, $y + 3, $w * 0.50, $h, $texto, $aFont, 'T', 'L', 0, '');
1890
    }
1891
1892
    /**
1893
     * modalFerr
1894
     * Monta o campo com os dados do remetente na DACTE. ( retrato  e paisagem  )
1895
     *
1896
     * @param  number $x Posição horizontal canto esquerdo
1897
     * @param  number $y Posição vertical canto superior
1898
     * @return number Posição vertical final
1899
     */
1900
    protected function modalFerr($x = 0, $y = 0)
1901
    {
1902
        $oldX = $x;
1903
        $oldY = $y;
1904
        if ($this->orientacao == 'P') {
1905
            $maxW = $this->wPrint;
1906
        } else {
1907
            $maxW = $this->wPrint - $this->wCanhoto;
1908
        }
1909
        $w = $maxW;
1910
        $h = 19.6;
1911
        $texto = 'DADOS ESPECÍFICOS DO MODAL FERROVIÁRIO';
1912
        $aFont = $this->formatPadrao;
1913
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
1914
        $y += 3.4;
1915
        $this->pdf->line($x, $y, $w + 1, $y);
1916
        $texto = 'DCL';
1917
        $aFont = array(
1918
            'font' => $this->fontePadrao,
1919
            'size' => 7,
1920
            'style' => 'B');
1921
        $this->pdf->textBox($x, $y, $w * 0.25, $h, $texto, $aFont, 'T', 'C', 0, '');
1922
        $this->pdf->line($x + 49.6, $y, $x + 49.6, $y + 3.5);
1923
        $texto = 'VAGÕES';
1924
        $aFont = array(
1925
            'font' => $this->fontePadrao,
1926
            'size' => 7,
1927
            'style' => 'B');
1928
        $this->pdf->textBox($x + 50, $y, $w * 0.5, $h, $texto, $aFont, 'T', 'C', 0, '');
1929
        $y += 3.4;
1930
        $this->pdf->line($x, $y, $w + 1, $y);
1931
        // DCL
1932
        $texto = 'ID TREM';
1933
        $aFont = array(
1934
            'font' => $this->fontePadrao,
1935
            'size' => 6,
1936
            'style' => '');
1937
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1938
        $texto = $this->getTagValue($this->ferrov, "idTrem");
1939
        $aFont = array(
1940
            'font' => $this->fontePadrao,
1941
            'size' => 6,
1942
            'style' => 'B');
1943
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1944
        $x += $w * 0.06;
1945
        $y1 = $y + 12.5;
1946
        $this->pdf->line($x, $y, $x, $y1);
1947
        $texto = 'NUM';
1948
        $aFont = array(
1949
            'font' => $this->fontePadrao,
1950
            'size' => 6,
1951
            'style' => '');
1952
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1953
        $texto = $this->getTagValue($this->rem, "nDoc");
1954
        $aFont = array(
1955
            'font' => $this->fontePadrao,
1956
            'size' => 6,
1957
            'style' => 'B');
1958
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1959
        $x += $w * 0.06;
1960
        $this->pdf->line($x, $y, $x, $y1);
1961
        $texto = 'SÉRIE';
1962
        $aFont = array(
1963
            'font' => $this->fontePadrao,
1964
            'size' => 6,
1965
            'style' => '');
1966
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1967
        $texto = $this->getTagValue($this->rem, "serie");
1968
        $aFont = array(
1969
            'font' => $this->fontePadrao,
1970
            'size' => 6,
1971
            'style' => 'B');
1972
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1973
        $x += $w * 0.06;
1974
        $this->pdf->line($x, $y, $x, $y1);
1975
        $texto = 'EMISSÃO';
1976
        $aFont = array(
1977
            'font' => $this->fontePadrao,
1978
            'size' => 6,
1979
            'style' => '');
1980
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1981
        $texto = $this->pYmd2dmy($this->getTagValue($this->rem, "dEmi"));
1982
        $aFont = array(
1983
            'font' => $this->fontePadrao,
1984
            'size' => 6,
1985
            'style' => 'B');
1986
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1987
        // VAGOES
1988
        $x += $w * 0.06;
1989
        $this->pdf->line($x, $y, $x, $y1);
1990
        $texto = 'NUM';
1991
        $aFont = array(
1992
            'font' => $this->fontePadrao,
1993
            'size' => 6,
1994
            'style' => '');
1995
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
1996
        $texto = $this->getTagValue($this->ferrov, "nVag");
1997
        $aFont = array(
1998
            'font' => $this->fontePadrao,
1999
            'size' => 6,
2000
            'style' => 'B');
2001
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2002
        $x += $w * 0.06;
2003
        $this->pdf->line($x, $y, $x, $y1);
2004
        $texto = 'TIPO';
2005
        $aFont = array(
2006
            'font' => $this->fontePadrao,
2007
            'size' => 6,
2008
            'style' => '');
2009
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2010
        $texto = $this->getTagValue($this->ferrov, "tpVag");
2011
        $aFont = array(
2012
            'font' => $this->fontePadrao,
2013
            'size' => 6,
2014
            'style' => 'B');
2015
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2016
        $x += $w * 0.06;
2017
        $this->pdf->line($x, $y, $x, $y1);
2018
        $texto = 'CAPACIDADE';
2019
        $aFont = array(
2020
            'font' => $this->fontePadrao,
2021
            'size' => 6,
2022
            'style' => '');
2023
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2024
        $texto = $this->getTagValue($this->ferrov, "cap");
2025
        $aFont = array(
2026
            'font' => $this->fontePadrao,
2027
            'size' => 6,
2028
            'style' => 'B');
2029
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2030
        $x += $w * 0.08;
2031
        $this->pdf->line($x, $y, $x, $y1);
2032
        $texto = 'PESO REAL/TON';
2033
        $aFont = array(
2034
            'font' => $this->fontePadrao,
2035
            'size' => 6,
2036
            'style' => '');
2037
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2038
        $texto = $this->getTagValue($this->ferrov, "pesoR");
2039
        $aFont = array(
2040
            'font' => $this->fontePadrao,
2041
            'size' => 6,
2042
            'style' => 'B');
2043
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2044
        $x += $w * 0.09;
2045
        $this->pdf->line($x, $y, $x, $y1);
2046
        $texto = 'PESO BRUTO/TON';
2047
        $aFont = array(
2048
            'font' => $this->fontePadrao,
2049
            'size' => 6,
2050
            'style' => '');
2051
        $this->pdf->textBox($x, $y, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2052
        $texto = $this->getTagValue($this->ferrov, "pesoBC");
2053
        $aFont = array(
2054
            'font' => $this->fontePadrao,
2055
            'size' => 6,
2056
            'style' => 'B');
2057
        $this->pdf->textBox($x, $y + 3, $w * 0.10, $h, $texto, $aFont, 'T', 'L', 0, '');
2058
        $x += $w * 0.1;
2059
        $this->pdf->line($x, $y, $x, $y1);
2060
        $texto = 'IDENTIFICAÇÃO DOS CONTÊINERES';
2061
        $aFont = array(
2062
            'font' => $this->fontePadrao,
2063
            'size' => 6,
2064
            'style' => '');
2065
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2066
        $texto = $this->getTagValue($this->ferrov, "nCont");
2067
        $aFont = array(
2068
            'font' => $this->fontePadrao,
2069
            'size' => 6,
2070
            'style' => 'B');
2071
        $this->pdf->textBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2072
        // FLUXO
2073
        $x = 1;
2074
        $y += 12.9;
2075
        $h1 = $h * 0.5 + 0.27;
2076
        $wa = round($w * 0.103) + 0.5;
2077
        $texto = 'FLUXO FERROVIARIO';
2078
        $aFont = $this->formatPadrao;
2079
        $this->pdf->textBox($x, $y, $wa, $h1, $texto, $aFont, 'T', 'C', 1, '');
2080
        $texto = $this->getTagValue($this->ferrov, "fluxo");
2081
        $aFont = array(
2082
            'font' => $this->fontePadrao,
2083
            'size' => 7,
2084
            'style' => 'B');
2085
        $this->pdf->textBox($x, $y + 3, $wa, $h1, $texto, $aFont, 'T', 'C', 0, '');
2086
        $y += 10;
2087
        $texto = 'TIPO DE TRÁFEGO';
2088
        $aFont = $this->formatPadrao;
2089
        $this->pdf->textBox($x, $y, $wa, $h1, $texto, $aFont, 'T', 'C', 1, '');
2090
        $texto = $this->convertUnidTrafego($this->getTagValue($this->ferrov, "tpTraf"));
2091
        $aFont = array(
2092
            'font' => $this->fontePadrao,
2093
            'size' => 7,
2094
            'style' => 'B');
2095
        $this->pdf->textBox($x, $y + 3, $wa, $h1, $texto, $aFont, 'T', 'C', 0, '');
2096
        // Novo Box Relativo a Modal Ferroviário
2097
        $x = 22.5;
2098
        $y += -10.2;
2099
        $texto = 'INFORMAÇÕES DAS FERROVIAS ENVOLVIDAS';
2100
        $aFont = $this->formatPadrao;
2101
        $this->pdf->textBox($x, $y, $w - 21.5, $h1 * 2.019, $texto, $aFont, 'T', 'C', 1, '');
2102
        $y += 3.4;
2103
        $this->pdf->line($x, $y, $w + 1, $y);
2104
        $w = $w * 0.2;
2105
        $h = $h * 1.04;
2106
        $texto = 'CÓDIGO INTERNO';
2107
        $aFont = array(
2108
            'font' => $this->fontePadrao,
2109
            'size' => 6,
2110
            'style' => '');
2111
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2112
        $texto = $this->getTagValue($this->ferrov, "cInt");
2113
        $aFont = array(
2114
            'font' => $this->fontePadrao,
2115
            'size' => 6,
2116
            'style' => 'B');
2117
        $this->pdf->textBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2118
        $texto = 'CNPJ';
2119
        $aFont = array(
2120
            'font' => $this->fontePadrao,
2121
            'size' => 6,
2122
            'style' => '');
2123
        $this->pdf->textBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2124
        $texto = $this->getTagValue($this->ferrov, "CNPJ");
2125
        $aFont = array(
2126
            'font' => $this->fontePadrao,
2127
            'size' => 6,
2128
            'style' => 'B');
2129
        $this->pdf->textBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2130
        $x += 50;
2131
        $texto = 'NOME';
2132
        $aFont = array(
2133
            'font' => $this->fontePadrao,
2134
            'size' => 6,
2135
            'style' => '');
2136
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2137
        $texto = $this->getTagValue($this->ferrov, "xNome");
2138
        $aFont = array(
2139
            'font' => $this->fontePadrao,
2140
            'size' => 6,
2141
            'style' => 'B');
2142
        $this->pdf->textBox($x, $y + 3, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2143
        $texto = 'INSCRICAO ESTADUAL';
2144
        $aFont = array(
2145
            'font' => $this->fontePadrao,
2146
            'size' => 6,
2147
            'style' => '');
2148
        $this->pdf->textBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2149
        $texto = $this->getTagValue($this->ferrov, "IE");
2150
        $aFont = array(
2151
            'font' => $this->fontePadrao,
2152
            'size' => 6,
2153
            'style' => 'B');
2154
        $this->pdf->textBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2155
        $x += 50;
2156
        $texto = 'PARTICIPAÇÃO OUTRA FERROVIA';
2157
        $aFont = array(
2158
            'font' => $this->fontePadrao,
2159
            'size' => 6,
2160
            'style' => '');
2161
        $this->pdf->textBox($x, $y + 6, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2162
        $texto = '';
2163
        $aFont = array(
2164
            'font' => $this->fontePadrao,
2165
            'size' => 6,
2166
            'style' => 'B');
2167
        $this->pdf->textBox($x, $y + 9, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2168
    }
2169
2170
    /**
2171
     * canhoto
2172
     * Monta o campo com os dados do remetente na DACTE.
2173
     *
2174
     * @param  number $x Posição horizontal canto esquerdo
2175
     * @param  number $y Posição vertical canto superior
2176
     * @return number Posição vertical final
2177
     */
2178
    protected function canhoto($x = 0, $y = 0)
2179
    {
2180
        $this->pdf->dashedHLine($x, $y+2, $this->wPrint, 0.1, 80);
2181
        $y = $y + 2;
2182
        $oldX = $x;
2183
        $oldY = $y;
2184
        if ($this->orientacao == 'P') {
2185
            $maxW = $this->wPrint;
2186
        } else {
2187
            $maxW = $this->wPrint - $this->wCanhoto;
2188
        }
2189
        $w = $maxW - 1;
2190
        $h = 20;
2191
        $y = $y + 1;
2192
        $texto = 'DECLARO QUE RECEBI OS VOLUMES DESTE CONHECIMENTO EM PERFEITO ESTADO ';
2193
        $texto .= 'PELO QUE DOU POR CUMPRIDO O PRESENTE CONTRATO DE TRANSPORTE';
2194
        $aFont = $this->formatPadrao;
2195
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2196
        $y += 3.4;
2197
        $this->pdf->line($x, $y, $w + 1, $y); // LINHA ABAICO DO TEXTO DECLARO QUE RECEBI...
2198
2199
        $texto = 'NOME';
2200
        $aFont = array(
2201
            'font' => $this->fontePadrao,
2202
            'size' => 6,
2203
            'style' => '');
2204
        $this->pdf->textBox($x, $y, $w * 0.25, $h, $texto, $aFont, 'T', 'L', 0, '');
2205
        $x += $w * 0.25;
2206
2207
        $this->pdf->line($x, $y, $x, $y + 16.5);
2208
2209
        $texto = 'ASSINATURA / CARIMBO';
2210
        $aFont = array(
2211
            'font' => $this->fontePadrao,
2212
            'size' => 6,
2213
            'style' => '');
2214
        $this->pdf->textBox($x, $y, $w * 0.25, $h - 3.4, $texto, $aFont, 'B', 'C', 0, '');
2215
        $x += $w * 0.25;
2216
2217
        $this->pdf->line($x, $y, $x, $y + 16.5);
2218
2219
        $texto = 'TÉRMINO DA PRESTAÇÃO - DATA/HORA' . "\r\n" . "\r\n" . "\r\n". "\r\n";
2220
        $texto .= ' INÍCIO DA PRESTAÇÃO - DATA/HORA';
2221
        $aFont = array(
2222
            'font' => $this->fontePadrao,
2223
            'size' => 6,
2224
            'style' => '');
2225
        $this->pdf->textBox($x + 10, $y, $w * 0.25, $h - 3.4, $texto, $aFont, 'T', 'C', 0, '');
2226
        $x = $oldX;
2227
        $y = $y + 5;
2228
2229
        $this->pdf->line($x, $y+3, $w * 0.255, $y+3); // LINHA HORIZONTAL ACIMA DO RG ABAIXO DO NOME
2230
2231
        $texto = 'RG';
2232
        $aFont = array(
2233
            'font' => $this->fontePadrao,
2234
            'size' => 6,
2235
            'style' => '');
2236
        $this->pdf->textBox($x, $y+3, $w * 0.33, $h, $texto, $aFont, 'T', 'L', 0, '');
2237
        $x += $w * 0.85;
2238
2239
        $this->pdf->line($x, $y + 11.5, $x, $y - 5); // LINHA VERTICAL PROXIMO AO CT-E
2240
2241
        $texto = "CT-E OS";
2242
        $aFont = $this->formatNegrito;
2243
        $this->pdf->textBox($x, $y - 5, $w * 0.15, $h, $texto, $aFont, 'T', 'C', 0, '');
2244
        $texto = "\r\n Nº. DOCUMENTO  " . $this->getTagValue($this->ide, "nCT") . " \n";
2245
        $texto .= "\r\n SÉRIE  " . $this->getTagValue($this->ide, "serie");
2246
        $aFont = array(
2247
            'font' => $this->fontePadrao,
2248
            'size' => 6,
2249
            'style' => '');
2250
        $this->pdf->textBox($x, $y - 8, $w * 0.15, $h, $texto, $aFont, 'C', 'C', 0, '');
2251
        $x = $oldX;
2252
    }
2253
2254
    /**
2255
     * dadosAdic
2256
     * Coloca o grupo de dados adicionais da DACTE.
2257
     *
2258
     * @param  number $x Posição horizontal canto esquerdo
2259
     * @param  number $y Posição vertical canto superior
2260
     * @param  number $h altura do campo
2261
     * @return number Posição vertical final
2262
     */
2263
    protected function dadosAdic($x, $y, $pag, $h)
2264
    {
2265
        $oldX = $x;
2266
        //###########################################################################
2267
        //DADOS ADICIONAIS DACTE
2268
        if ($this->orientacao == 'P') {
2269
            $w = $this->wPrint;
2270
        } else {
2271
            $w = $this->wPrint - $this->wCanhoto;
2272
        }
2273
        //INFORMAÇÕES COMPLEMENTARES
2274
        $texto = "USO EXCLUSIVO DO EMISSOR DO CT-E";
2275
        $y += 3;
2276
        $w = $this->wAdic;
2277
        $h = 20; //mudar
2278
        $aFont = array(
2279
            'font' => $this->fontePadrao,
2280
            'size' => 6,
2281
            'style' => '');
2282
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2283
        //$this->pdf->line($x, $y + 3, $w * 1.385, $y + 3);
2284
        $this->pdf->line($x, $y + 3, $w * 1.385, $y + 3);
2285
        //o texto com os dados adicionais foi obtido na função xxxxxx
2286
        //e carregado em uma propriedade privada da classe
2287
        //$this->wAdic com a largura do campo
2288
        //$this->textoAdic com o texto completo do campo
2289
        $y += 1;
2290
        $aFont = $this->formatPadrao;
2291
        $this->pdf->textBox($x, $y + 3, $w - 2, $h - 3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
2292
        //RESERVADO AO FISCO
2293
        $texto = "RESERVADO AO FISCO";
2294
        $x += $w;
2295
        $y -= 1;
2296
        if ($this->orientacao == 'P') {
2297
            $w = $this->wPrint - $w;
2298
        } else {
2299
            $w = $this->wPrint - $w - $this->wCanhoto;
2300
        }
2301
        $aFont = array(
2302
            'font' => $this->fontePadrao,
2303
            'size' => 6,
2304
            'style' => '');
2305
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'C', 1, '');
2306
        //inserir texto informando caso de contingência
2307
        //1 – Normal – emissão normal;
2308
        //2 – Contingência FS – emissão em contingência com impressão do DACTE em Formulário de Segurança;
2309
        //3 – Contingência SCAN – emissão em contingência  – SCAN;
2310
        //4 – Contingência DPEC - emissão em contingência com envio da Declaração Prévia de
2311
        //Emissão em Contingência – DPEC;
2312
        //5 – Contingência FS-DA - emissão em contingência com impressão do DACTE em Formulário de
2313
        //Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA).
2314
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
2315
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
2316
        $texto = '';
2317
        switch ($this->tpEmis) {
2318
            case 2:
2319
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
2320
                break;
2321
            case 3:
2322
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
2323
                break;
2324
            case 4:
2325
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
2326
                break;
2327
            case 5:
2328
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
2329
                break;
2330
        }
2331
        $y += 2;
2332
        $aFont = $this->formatPadrao;
2333
        $this->pdf->textBox($x, $y + 2, $w - 2, $h - 3, $texto, $aFont, 'T', 'L', 0, '', false);
2334
        return $y + $h;
2335
    }
2336
2337
    /**
2338
     * formatCNPJCPF
2339
     * Formata campo CnpjCpf contida na CTe
2340
     *
2341
     * @param  string $field campo cnpjCpf da CT-e
2342
     * @return string
2343
     */
2344
    protected function formatCNPJCPF($field)
2345
    {
2346
        if (!isset($field)) {
2347
            return '';
2348
        }
2349
        $cnpj = !empty($field->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2350
            $field->getElementsByTagName("CNPJ")->item(0)->nodeValue : "";
2351
        if ($cnpj != "" && $cnpj != "00000000000000") {
2352
            $cnpj = $this->formatField($cnpj, '###.###.###/####-##');
2353
        } else {
2354
            $cnpj = !empty($field->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2355
                $this->formatField($field->getElementsByTagName("CPF")->item(0)->nodeValue, '###.###.###.###-##') : '';
2356
        }
2357
        return $cnpj;
2358
    }
2359
2360
    /**
2361
     * formatFone
2362
     * Formata campo fone contida na CTe
2363
     *
2364
     * @param  string $field campo fone da CT-e
2365
     * @return string
2366
     */
2367
    protected function formatFone($field)
2368
    {
2369
        try {
2370
            $fone = !empty($field->getElementsByTagName("fone")->item(0)->nodeValue) ?
2371
            $field->getElementsByTagName("fone")->item(0)->nodeValue : '';
2372
            $foneLen = strlen($fone);
2373
            if ($foneLen > 0) {
2374
                $fone2 = substr($fone, 0, $foneLen - 4);
2375
                $fone1 = substr($fone, 0, $foneLen - 8);
2376
                $fone = '(' . $fone1 . ') ' . substr($fone2, -4) . '-' . substr($fone, -4);
2377
            } else {
2378
                $fone = '';
2379
            }
2380
            return $fone;
2381
        } catch (Exception $exc) {
2382
            return '';
2383
        }
2384
    }
2385
2386
    /**
2387
     * unidade
2388
     * Converte a imformação de peso contida na CTe
2389
     *
2390
     * @param  string $c unidade de trafego extraida da CTe
2391
     * @return string
2392
     */
2393
    protected function unidade($c = '')
2394
    {
2395
        switch ($c) {
2396
            case '00':
2397
                $r = 'M3';
2398
                break;
2399
            case '01':
2400
                $r = 'KG';
2401
                break;
2402
            case '02':
2403
                $r = 'TON';
2404
                break;
2405
            case '03':
2406
                $r = 'UN';
2407
                break;
2408
            case '04':
2409
                $r = 'LT';
2410
                break;
2411
            case '05':
2412
                $r = 'MMBTU';
2413
                break;
2414
            default:
2415
                $r = '';
2416
        }
2417
        return $r;
2418
    }
2419
2420
    /**
2421
     * convertUnidTrafego
2422
     * Converte a imformação de peso contida na CTe
2423
     *
2424
     * @param  string $U Informação de trafego extraida da CTe
2425
     * @return string
2426
     */
2427
    protected function convertUnidTrafego($U = '')
2428
    {
2429
        if ($U) {
2430
            switch ($U) {
2431
                case '0':
2432
                    $stringU = 'Próprio';
2433
                    break;
2434
                case '1':
2435
                    $stringU = 'Mútuo';
2436
                    break;
2437
                case '2':
2438
                    $stringU = 'Rodoferroviário';
2439
                    break;
2440
                case '3':
2441
                    $stringU = 'Rodoviário';
2442
                    break;
2443
            }
2444
            return $stringU;
2445
        }
2446
    }
2447
2448
    /**
2449
     * multiUniPeso
2450
     * Fornece a imformação multiplicação de peso contida na CTe
2451
     *
2452
     * @param  interger $U Informação de peso extraida da CTe
2453
     * @return interger
2454
     */
2455
    protected function multiUniPeso($U = '')
2456
    {
2457
        if ($U === "01") {
2458
            // tonelada
2459
            //return 1000;
2460
            return 1;
2461
        }
2462
        return 1; // M3, KG, Unidade, litros, mmbtu
2463
    }
2464
2465
    protected function qrCodeDacteOs($y = 0)
2466
    {
2467
        $margemInterna = $this->margemInterna;
2468
        $barcode = new Barcode();
2469
        $bobj = $barcode->getBarcodeObj(
2470
            'QRCODE,M',
2471
            $this->qrCodMDFe,
2472
            -4,
2473
            -4,
2474
            'black',
2475
            array(-1, -1, -1, -1)
2476
        )->setBackgroundColor('white');
2477
        $qrcode = $bobj->getPngData();
2478
        $wQr = 36;
2479
        $hQr = 36;
2480
        $yQr = ($y + $margemInterna);
2481
        if ($this->orientacao == 'P') {
2482
            $xQr = 170;
2483
        } else {
2484
            $xQr = 250;
2485
        }
2486
        // prepare a base64 encoded "data url"
2487
        $pic = 'data://text/plain;base64,' . base64_encode($qrcode);
2488
        $this->pdf->image($pic, $xQr, $yQr, $wQr, $hQr, 'PNG');
2489
    }
2490
    
2491
    /**
2492
     * Add the credits to the integrator in the footer message
2493
     * @param string $message
2494
     */
2495
    public function creditsIntegratorFooter($message = '')
2496
    {
2497
        $this->creditos = trim($message);
2498
    }
2499
}
2500