Completed
Pull Request — master (#259)
by Roberto
02:22
created

Danfe::notaDPEC()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace NFePHP\DA\NFe;
4
5
use InvalidArgumentException;
6
use NFePHP\DA\Legacy\Dom;
7
use NFePHP\DA\Legacy\Pdf;
8
use NFePHP\DA\Legacy\Common;
9
10
class Danfe extends Common
11
{
12
    const FPDF_FONTPATH = 'font/';
13
    const SIT_CANCELADA = 1;
14
    const SIT_DENEGADA = 2;
15
    const SIT_DPEC = 3;
16
    const SIT_NONE = 0;
17
18
    /**
19
     * alinhamento padrão do logo (C-Center)
20
     *
21
     * @var string
22
     */
23
    public $logoAlign = 'C';
24
    /**
25
     * Posição
26
     * @var float
27
     */
28
    public $yDados = 0;
29
    /**
30
     * Situação
31
     * @var integer
32
     */
33
    public $situacaoExterna = 0;
34
    /**
35
     * Numero DPEC
36
     *
37
     * @var string
38
     */
39
    public $numero_registro_dpec = '';
40
    /**
41
     * quantidade de canhotos a serem montados, geralmente 1 ou 2
42
     *
43
     * @var integer
44
     */
45
    public $qCanhoto = 1;
46
47
    //###########################################################
48
    // INÍCIO ATRIBUTOS DE PARÂMETROS DE EXIBIÇÃO
49
    //###########################################################
50
51
    /**
52
     * Parâmetro para exibir ou ocultar os valores do PIS/COFINS.
53
     * @var boolean
54
     */
55
    public $exibirPIS = true;
56
    /**
57
     * Parâmetro para exibir ou ocultar os valores do ICMS Interestadual e Valor Total dos Impostos.
58
     * @var boolean
59
     */
60
    public $exibirIcmsInterestadual = true;
61
    /**
62
     * Parâmetro para exibir ou ocultar o texto sobre valor aproximado dos tributos.
63
     * @var boolean
64
     */
65
    public $exibirValorTributos = true;
66
    /**
67
     * Parâmetro para exibir ou ocultar o texto adicional sobre a forma de pagamento
68
     * e as informações de fatura/duplicata.
69
     * @var boolean
70
     */
71
    public $exibirTextoFatura = false;
72
    /**
73
     * Parâmetro do controle se deve concatenar automaticamente informações complementares
74
     * na descrição do produto, como por exemplo, informações sobre impostos.
75
     * @var boolean
76
     */
77
    public $descProdInfoComplemento = true;
78
    /**
79
     * Parâmetro do controle se deve gerar quebras de linha com "\n" a partir de ";" na descrição do produto.
80
     * @var boolean
81
     */
82
    public $descProdQuebraLinha = true;
83
84
    //###########################################################
85
    //PROPRIEDADES DA CLASSE
86
    //###########################################################
87
88
    /**
89
     * objeto fpdf()
90
     * @var object
91
     */
92
    protected $pdf;
93
    /**
94
     * XML NFe
95
     * @var string
96
     */
97
    protected $xml;
98
    /**
99
     * path para logomarca em jpg
100
     * @var string
101
     */
102
    protected $logomarca = '';
103
    /**
104
     * mesagens de erro
105
     * @var string
106
     */
107
    protected $errMsg = '';
108
    /**
109
     * status de erro true um erro ocorreu false sem erros
110
     * @var boolean
111
     */
112
    protected $errStatus = false;
113
    /**
114
     * orientação da DANFE
115
     * P-Retrato ou L-Paisagem
116
     * @var string
117
     */
118
    protected $orientacao = 'P';
119
    /**
120
     * formato do papel
121
     * @var string
122
     */
123
    protected $papel = 'A4';
124
    /**
125
     * destino do arquivo pdf
126
     * I-borwser, S-retorna o arquivo, D-força download, F-salva em arquivo local
127
     * @var string
128
     */
129
    protected $destino = 'I';
130
    /**
131
     * diretorio para salvar o pdf com a opção de destino = F
132
     * @var string
133
     */
134
    protected $pdfDir = '';
135
    /**
136
     * Nome da Fonte para gerar o DANFE
137
     * @var string
138
     */
139
    protected $fontePadrao = 'Times';
140
    /**
141
     * versão
142
     * @var string
143
     */
144
    protected $version = '2.2.8';
145
    /**
146
     * Texto
147
     * @var string
148
     */
149
    protected $textoAdic = '';
150
    /**
151
     * Largura
152
     * @var float
153
     */
154
    protected $wAdic = 0;
155
    /**
156
     * largura imprimivel, em milímetros
157
     * @var float
158
     */
159
    protected $wPrint;
160
    /**
161
     * Comprimento (altura) imprimivel, em milímetros
162
     * @var float
163
     */
164
    protected $hPrint;
165
    /**
166
     * largura do canhoto (25mm) apenas para a formatação paisagem
167
     * @var float
168
     */
169
    protected $wCanhoto = 25;
170
    /**
171
     * Formato chave
172
     * @var string
173
     */
174
    protected $formatoChave = "#### #### #### #### #### #### #### #### #### #### ####";
175
    /**
176
     * quantidade de itens já processados na montagem do DANFE
177
     * @var integer
178
     */
179
    protected $qtdeItensProc;
180
181
    /**
182
     * Document
183
     * @var DOMDocument
184
     */
185
    protected $dom;
186
    /**
187
     * Node
188
     * @var DOMNode
189
     */
190
    protected $infNFe;
191
    /**
192
     * Node
193
     * @var DOMNode
194
     */
195
    protected $ide;
196
    /**
197
     * Node
198
     * @var DOMNode
199
     */
200
    protected $entrega;
201
    /**
202
     * Node
203
     * @var DOMNode
204
     */
205
    protected $retirada;
206
    /**
207
     * Node
208
     * @var DOMNode
209
     */
210
    protected $emit;
211
    /**
212
     * Node
213
     * @var DOMNode
214
     */
215
    protected $dest;
216
    /**
217
     * Node
218
     * @var DOMNode
219
     */
220
    protected $enderEmit;
221
    /**
222
     * Node
223
     * @var DOMNode
224
     */
225
    protected $enderDest;
226
    /**
227
     * Node
228
     * @var DOMNode
229
     */
230
    protected $det;
231
    /**
232
     * Node
233
     * @var DOMNode
234
     */
235
    protected $cobr;
236
    /**
237
     * Node
238
     * @var DOMNode
239
     */
240
    protected $dup;
241
    /**
242
     * Node
243
     * @var DOMNode
244
     */
245
    protected $ICMSTot;
246
    /**
247
     * Node
248
     * @var DOMNode
249
     */
250
    protected $ISSQNtot;
251
    /**
252
     * Node
253
     * @var DOMNode
254
     */
255
    protected $transp;
256
    /**
257
     * Node
258
     * @var DOMNode
259
     */
260
    protected $transporta;
261
    /**
262
     * Node
263
     * @var DOMNode
264
     */
265
    protected $veicTransp;
266
    /**
267
     * Node reboque
268
     * @var DOMNode
269
     */
270
    protected $reboque;
271
    /**
272
     * Node infAdic
273
     * @var DOMNode
274
     */
275
    protected $infAdic;
276
    /**
277
     * Tipo de emissão
278
     * @var integer
279
     */
280
    protected $tpEmis;
281
    /**
282
     * Node infProt
283
     * @var DOMNode
284
     */
285
    protected $infProt;
286
    /**
287
     * 1-Retrato/ 2-Paisagem
288
     * @var integer
289
     */
290
    protected $tpImp;
291
    /**
292
     * Node compra
293
     * @var DOMNode
294
     */
295
    protected $compra;
296
    /**
297
     * ativa ou desativa o modo de debug
298
     * @var integer
299
     */
300
    protected $debugMode = 2;
301
    /**
302
     * Creditos para integrador
303
     * @var string
304
     */
305
    protected $creditos = '';
306
307
    /**
308
     * __construct
309
     *
310
     * @name  __construct
311
     * @param string  $docXML      Conteúdo XML da NF-e (com ou sem a tag nfeProc)
312
     * @param string  $sOrientacao (Opcional) Orientação da impressão P-retrato L-Paisagem
313
     * @param string  $sPapel      Tamanho do papel (Ex. A4)
314
     * @param string  $sPathLogo   Caminho para o arquivo do logo
315
     * @param string  $sDestino    Estabelece a direção do envio do documento PDF I-browser D-browser com download S-
316
     * @param string  $sDirPDF     Caminho para o diretorio de armazenamento dos arquivos PDF
317
     * @param string  $fonteDANFE  Nome da fonte alternativa do DAnfe
318
     * @param integer $mododebug   0-Não 1-Sim e 2-nada (2 default)
319
     */
320
    public function __construct(
321
        $docXML = '',
322
        $sOrientacao = '',
323
        $sPapel = '',
324
        $sPathLogo = '',
325
        $sDestino = 'I',
326
        $sDirPDF = '',
327
        $fonteDANFE = '',
328
        $mododebug = 2
329
    ) {
330
        //set_time_limit(1800);
331
        if (is_numeric($mododebug)) {
332
            $this->debugMode = $mododebug;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mododebug can also be of type double or string. However, the property $debugMode is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
333
        }
334
        if ($mododebug == 1) {
335
            //ativar modo debug
336
            error_reporting(E_ALL);
337
            ini_set('display_errors', 'On');
338
        }
339
        if ($mododebug == 0) {
340
            //desativar modo debug
341
            error_reporting(0);
342
            ini_set('display_errors', 'Off');
343
        }
344
        $this->orientacao   = $sOrientacao;
345
        $this->papel        = $sPapel;
346
        $this->pdf          = '';
0 ignored issues
show
Documentation Bug introduced by
It seems like '' of type string is incompatible with the declared type object of property $pdf.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
347
        $this->xml          = $docXML;
348
        $this->logomarca    = $sPathLogo;
349
        $this->destino      = $sDestino;
350
        $this->pdfDir       = $sDirPDF;
351
        // verifica se foi passa a fonte a ser usada
352
        if (empty($fonteDANFE)) {
353
            $this->fontePadrao = 'Times';
354
        } else {
355
            $this->fontePadrao = $fonteDANFE;
356
        }
357
        //se for passado o xml
358
        if (! empty($this->xml)) {
359
            $this->dom = new Dom();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \NFePHP\DA\Legacy\Dom() of type object<NFePHP\DA\Legacy\Dom> is incompatible with the declared type object<NFePHP\DA\NFe\DOMDocument> of property $dom.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
360
            $this->dom->loadXML($this->xml);
361
            $this->nfeProc    = $this->dom->getElementsByTagName("nfeProc")->item(0);
0 ignored issues
show
Bug introduced by
The property nfeProc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
362
            $this->infNFe     = $this->dom->getElementsByTagName("infNFe")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('infNFe')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infNFe.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
363
            $this->ide        = $this->dom->getElementsByTagName("ide")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('ide')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ide.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
364
            $this->entrega    = $this->dom->getElementsByTagName("entrega")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('entrega')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $entrega.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
365
            $this->retirada   = $this->dom->getElementsByTagName("retirada")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...me('retirada')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $retirada.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
366
            $this->emit       = $this->dom->getElementsByTagName("emit")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('emit')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $emit.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
367
            $this->dest       = $this->dom->getElementsByTagName("dest")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('dest')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $dest.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
368
            $this->enderEmit  = $this->dom->getElementsByTagName("enderEmit")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...e('enderEmit')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $enderEmit.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
369
            $this->enderDest  = $this->dom->getElementsByTagName("enderDest")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...e('enderDest')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $enderDest.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
370
            $this->det        = $this->dom->getElementsByTagName("det");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('det') of type object<DOMNodeList> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $det.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
371
            $this->cobr       = $this->dom->getElementsByTagName("cobr")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('cobr')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $cobr.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
372
            $this->dup        = $this->dom->getElementsByTagName('dup');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsByTagName('dup') of type object<DOMNodeList> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $dup.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
373
            $this->ICMSTot    = $this->dom->getElementsByTagName("ICMSTot")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('ICMSTot')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ICMSTot.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
374
            $this->ISSQNtot   = $this->dom->getElementsByTagName("ISSQNtot")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...me('ISSQNtot')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $ISSQNtot.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
375
            $this->transp     = $this->dom->getElementsByTagName("transp")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('transp')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $transp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
376
            $this->transporta = $this->dom->getElementsByTagName("transporta")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...('transporta')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $transporta.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
377
            $this->veicTransp = $this->dom->getElementsByTagName("veicTransp")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...('veicTransp')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $veicTransp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
378
            $this->reboque    = $this->dom->getElementsByTagName("reboque")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('reboque')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $reboque.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
379
            $this->infAdic    = $this->dom->getElementsByTagName("infAdic")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('infAdic')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infAdic.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
380
            $this->compra     = $this->dom->getElementsByTagName("compra")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...Name('compra')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $compra.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
381
            $this->tpEmis     = $this->getTagValue($this->ide, "tpEmis");
0 ignored issues
show
Documentation Bug introduced by
The property $tpEmis was declared of type integer, but $this->getTagValue($this->ide, 'tpEmis') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
382
            $this->tpImp      = $this->getTagValue($this->ide, "tpImp");
0 ignored issues
show
Documentation Bug introduced by
The property $tpImp was declared of type integer, but $this->getTagValue($this->ide, 'tpImp') is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
383
            $this->infProt    = $this->dom->getElementsByTagName("infProt")->item(0);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->dom->getElementsB...ame('infProt')->item(0) of type object<DOMNode> is incompatible with the declared type object<NFePHP\DA\NFe\DOMNode> of property $infProt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
384
            //valida se o XML é uma NF-e modelo 55, pois não pode ser 65 (NFC-e)
385
            if ($this->getTagValue($this->ide, "mod") != '55') {
386
                throw new InvalidArgumentException("O xml do DANFE deve ser uma NF-e modelo 55");
387
            }
388
        }
389
    }
390
391
    /**
392
     * Add the credits to the integrator in the footer message
393
     * @param string $message
394
     */
395
    public function creditsIntegratorFooter($message = '')
396
    {
397
        $this->creditos = trim($message);
398
    }
399
    
400
    /**
401
     * monta
402
     *
403
     * @name   monta
404
     * @param  string $orientacao
405
     * @param  string $papel
406
     * @param  string $logoAlign
407
     * @return string
408
     */
409
    public function monta(
410
        $orientacao = '',
411
        $papel = 'A4',
412
        $logoAlign = 'C',
413
        $situacaoExterna = self::SIT_NONE,
414
        $classPdf = false,
415
        $dpecNumReg = '',
416
        $margSup = 2,
417
        $margEsq = 2,
418
        $margInf = 2
419
    ) {
420
        return $this->montaDANFE(
421
            $orientacao,
422
            $papel,
423
            $logoAlign,
424
            $situacaoExterna,
425
            $classPdf,
426
            $dpecNumReg,
427
            $margSup,
428
            $margEsq,
429
            $margInf
430
        );
431
    }
432
433
    /**
434
     * printDocument
435
     *
436
     * @param  string $nome
437
     * @param  string $destino
438
     * @param  string $printer
439
     * @return object pdf
440
     */
441
    public function printDocument($nome = '', $destino = 'I', $printer = '')
0 ignored issues
show
Unused Code introduced by
The parameter $printer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
442
    {
443
        $arq = $this->pdf->output($nome, $destino);
444
        if ($destino == 'S') {
445
            //aqui pode entrar a rotina de impressão direta
446
        }
447
        return $arq;
448
    }
449
450
    /**
451
     * montaDANFE
452
     * Monta a DANFE conforme as informações fornecidas para a classe durante sua
453
     * construção. Constroi DANFEs com até 3 páginas podendo conter até 56 itens.
454
     * A definição de margens e posições iniciais para a impressão são estabelecidas
455
     * pelo conteúdo da funçao e podem ser modificados.
456
     *
457
     * @param  string $orientacao (Opcional) Estabelece a orientação da impressão
458
     *  (ex. P-retrato), se nada for fornecido será usado o padrão da NFe
459
     * @param  string $papel      (Opcional) Estabelece o tamanho do papel (ex. A4)
460
     * @return string O ID da NFe numero de 44 digitos extraido do arquivo XML
461
     */
462
    public function montaDANFE(
463
        $orientacao = '',
464
        $papel = 'A4',
465
        $logoAlign = 'C',
466
        $situacaoExterna = self::SIT_NONE,
467
        $classPdf = false,
468
        $depecNumReg = '',
469
        $margSup = 2,
470
        $margEsq = 2,
471
        $margInf = 2
472
    ) {
473
        //se a orientação estiver em branco utilizar o padrão estabelecido na NF
474
        if ($orientacao == '') {
475
            if ($this->tpImp == '1') {
476
                $orientacao = 'P';
477
            } else {
478
                $orientacao = 'L';
479
            }
480
        }
481
        $this->orientacao = $orientacao;
482
        $this->papel = $papel;
483
        $this->logoAlign = $logoAlign;
484
        $this->situacao_externa = $situacaoExterna;
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
485
        $this->numero_registro_dpec = $depecNumReg;
486
        //instancia a classe pdf
487
        if ($classPdf) {
488
            $this->pdf = $classPdf;
0 ignored issues
show
Documentation Bug introduced by
It seems like $classPdf of type boolean is incompatible with the declared type object of property $pdf.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
489
        } else {
490
            $this->pdf = new Pdf($this->orientacao, 'mm', $this->papel);
491
        }
492
        //margens do PDF, em milímetros. Obs.: a margem direita é sempre igual à
493
        //margem esquerda. A margem inferior *não* existe na FPDF, é definida aqui
494
        //apenas para controle se necessário ser maior do que a margem superior
495
        // posição inicial do conteúdo, a partir do canto superior esquerdo da página
496
        $xInic = $margEsq;
497
        $yInic = $margSup;
498
        if ($this->orientacao == 'P') {
499
            if ($papel == 'A4') {
500
                $maxW = 210;
501
                $maxH = 297;
502
            }
503
        } else {
504
            if ($papel == 'A4') {
505
                $maxH = 210;
506
                $maxW = 297;
507
                //se paisagem multiplica a largura do canhoto pela quantidade de canhotos
508
                $this->wCanhoto *= $this->qCanhoto;
509
            }
510
        }
511
        //total inicial de paginas
512
        $totPag = 1;
0 ignored issues
show
Unused Code introduced by
$totPag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
513
        //largura imprimivel em mm: largura da folha menos as margens esq/direita
514
        $this->wPrint = $maxW-($margEsq*2);
0 ignored issues
show
Bug introduced by
The variable $maxW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation Bug introduced by
The property $wPrint was declared of type double, but $maxW - $margEsq * 2 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
515
        //comprimento (altura) imprimivel em mm: altura da folha menos as margens
516
        //superior e inferior
517
        $this->hPrint = $maxH-$margSup-$margInf;
0 ignored issues
show
Bug introduced by
The variable $maxH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation Bug introduced by
The property $hPrint was declared of type double, but $maxH - $margSup - $margInf is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
518
        // estabelece contagem de paginas
519
        $this->pdf->aliasNbPages();
520
        // fixa as margens
521
        $this->pdf->setMargins($margEsq, $margSup);
522
        $this->pdf->setDrawColor(0, 0, 0);
523
        $this->pdf->setFillColor(255, 255, 255);
524
        // inicia o documento
525
        $this->pdf->open();
526
        // adiciona a primeira página
527
        $this->pdf->addPage($this->orientacao, $this->papel);
528
        $this->pdf->setLineWidth(0.1);
529
        $this->pdf->setTextColor(0, 0, 0);
530
531
        //##################################################################
532
        // CALCULO DO NUMERO DE PAGINAS A SEREM IMPRESSAS
533
        //##################################################################
534
        //Verificando quantas linhas serão usadas para impressão das duplicatas
535
        $linhasDup = 0;
536
        if (($this->dup->length > 0) && ($this->dup->length <= 7)) {
537
            $linhasDup = 1;
538
        } elseif (($this->dup->length > 7) && ($this->dup->length <= 14)) {
539
            $linhasDup = 2;
540
        } elseif (($this->dup->length > 14) && ($this->dup->length <= 21)) {
541
            $linhasDup = 3;
542
        } elseif ($this->dup->length > 21) {
543
            // chinnonsantos 11/05/2016: Limite máximo de impressão de duplicatas na NFe,
544
            // só vai ser exibito as 21 primeiras duplicatas (parcelas de pagamento),
545
            // se não oculpa espaço d+, cada linha comporta até 7 duplicatas.
546
            $linhasDup = 3;
547
        }
548
        //verifica se será impressa a linha dos serviços ISSQN
549
        $linhaISSQN = 0;
550
        if ((isset($this->ISSQNtot)) && ($this->getTagValue($this->ISSQNtot, 'vServ') > 0)) {
551
            $linhaISSQN = 1;
552
        }
553
        //calcular a altura necessária para os dados adicionais
554
        if ($this->orientacao == 'P') {
555
            $this->wAdic = round($this->wPrint*0.66, 0);
556
        } else {
557
            $this->wAdic = round(($this->wPrint-$this->wCanhoto)*0.5, 0);
558
        }
559
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
560
        $this->textoAdic = '';
561
        if (isset($this->retirada)) {
562
            $txRetCNPJ = $this->getTagValue($this->retirada, "CNPJ");
563
            $txRetxLgr = $this->getTagValue($this->retirada, "xLgr");
564
            $txRetnro = $this->getTagValue($this->retirada, "nro");
565
            $txRetxCpl = $this->getTagValue($this->retirada, "xCpl", " - ");
566
            $txRetxBairro = $this->getTagValue($this->retirada, "xBairro");
567
            $txRetxMun = $this->getTagValue($this->retirada, "xMun");
568
            $txRetUF = $this->getTagValue($this->retirada, "UF");
569
            $this->textoAdic .= "LOCAL DE RETIRADA : ".
570
                    $txRetCNPJ.
571
                    '-' .
572
                    $txRetxLgr .
573
                    ', ' .
574
                    $txRetnro .
575
                    ' ' .
576
                    $txRetxCpl .
577
                    ' - ' .
578
                    $txRetxBairro .
579
                    ' ' .
580
                    $txRetxMun .
581
                    ' - ' .
582
                    $txRetUF .
583
                    "\r\n";
584
        }
585
        //dados do local de entrega da mercadoria
586
        if (isset($this->entrega)) {
587
            $txRetCNPJ = $this->getTagValue($this->entrega, "CNPJ");
588
            $txRetxLgr = $this->getTagValue($this->entrega, "xLgr");
589
            $txRetnro = $this->getTagValue($this->entrega, "nro");
590
            $txRetxCpl = $this->getTagValue($this->entrega, "xCpl", " - ");
591
            $txRetxBairro = $this->getTagValue($this->entrega, "xBairro");
592
            $txRetxMun = $this->getTagValue($this->entrega, "xMun");
593
            $txRetUF = $this->getTagValue($this->entrega, "UF");
594
            if ($this->textoAdic != '') {
595
                $this->textoAdic .= ". \r\n";
596
            }
597
            $this->textoAdic .= "LOCAL DE ENTREGA : ".$txRetCNPJ.'-'.$txRetxLgr.', '.$txRetnro.' '.$txRetxCpl.
598
               ' - '.$txRetxBairro.' '.$txRetxMun.' - '.$txRetUF."\r\n";
599
        }
600
        //informações adicionais
601
        $this->textoAdic .= $this->geraInformacoesDasNotasReferenciadas();
602
        if (isset($this->infAdic)) {
603
            $i = 0;
604
            if ($this->textoAdic != '') {
605
                $this->textoAdic .= ". \r\n";
606
            }
607
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infCpl")) ?
608
                'Inf. Contribuinte: ' .
609
                $this->anfaveaDANFE($this->getTagValue($this->infAdic, "infCpl")) : '';
610
            $infPedido = $this->geraInformacoesDaTagCompra();
611
            if ($infPedido != "") {
612
                $this->textoAdic .= $infPedido;
613
            }
614
            $this->textoAdic .= $this->getTagValue($this->dest, "email", ' Email do Destinatário: ');
615
            $this->textoAdic .= ! empty($this->getTagValue($this->infAdic, "infAdFisco")) ?
616
                "\r\n Inf. fisco: " .
617
                $this->getTagValue($this->infAdic, "infAdFisco") : '';
618
            $obsCont = $this->infAdic->getElementsByTagName("obsCont");
619
            if (isset($obsCont)) {
620
                foreach ($obsCont as $obs) {
621
                    $campo =  $obsCont->item($i)->getAttribute("xCampo");
622
                    $xTexto = ! empty($obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue) ?
623
                        $obsCont->item($i)->getElementsByTagName("xTexto")->item(0)->nodeValue : '';
624
                    $this->textoAdic .= "\r\n" . $campo . ':  ' . trim($xTexto);
625
                    $i++;
626
                }
627
            }
628
        }
629
        //INCLUSO pela NT 2013.003 Lei da Transparência
630
        //verificar se a informação sobre o valor aproximado dos tributos
631
        //já se encontra no campo de informações adicionais
632
        if ($this->exibirValorTributos) {
633
            $flagVTT = strpos(strtolower(trim($this->textoAdic)), 'valor');
634
            $flagVTT = $flagVTT || strpos(strtolower(trim($this->textoAdic)), 'vl');
635
            $flagVTT = $flagVTT && strpos(strtolower(trim($this->textoAdic)), 'aprox');
636
            $flagVTT = $flagVTT && (strpos(strtolower(trim($this->textoAdic)), 'trib') ||
637
                    strpos(strtolower(trim($this->textoAdic)), 'imp'));
638
            $vTotTrib = $this->getTagValue($this->ICMSTot, 'vTotTrib');
639
            if ($vTotTrib != '' && !$flagVTT) {
640
                $this->textoAdic .= "\n Valor Aproximado dos Tributos : R$ " . number_format($vTotTrib, 2, ",", ".");
641
            }
642
        }
643
        //fim da alteração NT 2013.003 Lei da Transparência
644
        $this->textoAdic = str_replace(";", "\n", $this->textoAdic);
645
        $alinhas = explode("\n", $this->textoAdic);
646
        $numlinhasdados = 0;
647
        foreach ($alinhas as $linha) {
648
            $numlinhasdados += $this->pdf->getNumLines($linha, $this->wAdic, $fontProduto);
649
        }
650
        $hdadosadic = round(($numlinhasdados+3) * $this->pdf->fontSize, 0);
651
        if ($hdadosadic < 10) {
652
            $hdadosadic = 10;
653
        }
654
        //altura disponivel para os campos da DANFE
655
        $hcabecalho = 47;//para cabeçalho
656
        $hdestinatario = 25;//para destinatario
657
        $hduplicatas = 12;//para cada grupo de 7 duplicatas
658
        $himposto = 18;// para imposto
659
        $htransporte = 25;// para transporte
660
        $hissqn = 11;// para issqn
661
        $hfooter = 5;// para rodape
662
        $hCabecItens = 4;//cabeçalho dos itens
663
        //alturas disponiveis para os dados
664
        $hDispo1 = $this->hPrint - 10 - ($hcabecalho +
665
            $hdestinatario + ($linhasDup * $hduplicatas) + $himposto + $htransporte +
666
            ($linhaISSQN * $hissqn) + $hdadosadic + $hfooter + $hCabecItens +
667
            $this->sizeExtraTextoFatura());
668
        if ($this->orientacao == 'P') {
669
            $hDispo1 -= 24 * $this->qCanhoto;//para canhoto
670
            $w = $this->wPrint;
671
        } else {
672
            $hcanhoto = $this->hPrint;//para canhoto
0 ignored issues
show
Unused Code introduced by
$hcanhoto is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
673
            $w = $this->wPrint - $this->wCanhoto;
674
        }
675
        $hDispo2 = $this->hPrint - 10 - ($hcabecalho + $hfooter + $hCabecItens)-4;
676
        //Contagem da altura ocupada para impressão dos itens
677
        $fontProduto = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
678
        $numlinhas = 0;
0 ignored issues
show
Unused Code introduced by
$numlinhas is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
679
        $hUsado = $hCabecItens;
680
        $w2 = round($w*0.28, 0);
681
        $hDispo = $hDispo1;
682
        $totPag = 1;
683
        $i = 0;
684
        while ($i < $this->det->length) {
685
            $texto = $this->descricaoProduto($this->det->item($i));
686
            $numlinhas = $this->pdf->getNumLines($texto, $w2, $fontProduto);
687
            $hUsado += round(($numlinhas * $this->pdf->fontSize) + ($numlinhas * 0.5), 2);
688
            if ($hUsado > $hDispo) {
689
                $totPag++;
690
                $hDispo = $hDispo2;
691
                $hUsado = $hCabecItens;
692
                // Remove canhoto para páginas secundárias em modo paisagem ('L')
693
                $w2 = round($this->wPrint*0.28, 0);
694
                $i--; // decrementa para readicionar o item que não coube nessa pagina na outra.
695
            }
696
            $i++;
697
        } //fim da soma das areas de itens usadas
698
        $qtdeItens = $i; //controle da quantidade de itens no DANFE
699
        //montagem da primeira página
700
        $pag = 1;
701
        $x = $xInic;
702
        $y = $yInic;
703
        //coloca o(s) canhoto(s) da NFe
704
        if ($this->orientacao == 'P') {
705
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
706
                $y = $this->canhoto($x, $y);
707
            }
708
        } else {
709
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
710
                $this->canhoto($x, $y);
711
                $x = 25 * $i;
712
            }
713
        }
714
        //coloca o cabeçalho
715
        $y = $this->cabecalhoDANFE($x, $y, $pag, $totPag);
716
        //coloca os dados do destinatário
717
        $y = $this->destinatarioDANFE($x, $y+1);
718
        
719
        
720
        //Verifica as formas de pagamento da nota fiscal
721
        $formaPag = [];
722
        if (isset($this->detPag) && $this->detPag->length > 0) {
723
            foreach ($this->detPag as $k => $d) {
724
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue) ?
0 ignored issues
show
Bug introduced by
The property detPag does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
725
                    $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
726
                $formaPag[$fPag] = $fPag;
727
            }
728
        }
729
        //caso tenha boleto imprimir fatura
730
        if ($this->dup->length > 0) {
731
            $y = $this->faturaDANFE($x, $y+1);
732
        } else {
733
            //Se somente tiver a forma de pagamento sem pagamento ou outros não imprimir nada
734
            if (count($formaPag)=='1' && (isset($formaPag[90]) || isset($formaPag[99]))) {
735
                $y = $y;
0 ignored issues
show
Bug introduced by
Why assign $y to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
736
            } else {
737
                //caso tenha mais de uma forma de pagamento ou seja diferente de boleto exibe a
738
                //forma de pagamento e o valor
739
                $y = $this->pagamentoDANFE($x, $y+1);
740
            }
741
        }
742
        //coloca os dados dos impostos e totais da NFe
743
        $y = $this->impostoDANFE($x, $y+1);
744
        //coloca os dados do trasnporte
745
        $y = $this->transporteDANFE($x, $y+1);
746
        //itens da DANFE
747
        $nInicial = 0;
748
749
        $y = $this->itensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
750
751
        //coloca os dados do ISSQN
752
        if ($linhaISSQN == 1) {
753
            $y = $this->issqnDANFE($x, $y+4);
754
        } else {
755
            $y += 4;
756
        }
757
        //coloca os dados adicionais da NFe
758
        $y = $this->dadosAdicionaisDANFE($x, $y, $hdadosadic);
759
        //coloca o rodapé da página
760
        if ($this->orientacao == 'P') {
761
            $this->rodape($xInic, $y-1);
762
        } else {
763
            $this->rodape($xInic, $this->hPrint + 1);
764
        }
765
766
        //loop para páginas seguintes
767
        for ($n = 2; $n <= $totPag; $n++) {
768
            // fixa as margens
769
            $this->pdf->setMargins($margEsq, $margSup);
770
            //adiciona nova página
771
            $this->pdf->addPage($this->orientacao, $this->papel);
772
            //ajusta espessura das linhas
773
            $this->pdf->setLineWidth(0.1);
774
            //seta a cor do texto para petro
775
            $this->pdf->setTextColor(0, 0, 0);
776
            // posição inicial do relatorio
777
            $x = $xInic;
778
            $y = $yInic;
779
            //coloca o cabeçalho na página adicional
780
            $y = $this->cabecalhoDANFE($x, $y, $n, $totPag);
781
            //coloca os itens na página adicional
782
            $y = $this->itensDANFE($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
783
            //coloca o rodapé da página
784
            if ($this->orientacao == 'P') {
785
                $this->rodape($xInic, $y + 4);
786
            } else {
787
                $this->rodape($xInic, $this->hPrint + 4);
788
            }
789
            //se estiver na última página e ainda restar itens para inserir, adiciona mais uma página
790
            if ($n == $totPag && $this->qtdeItensProc < $qtdeItens) {
791
                $totPag++;
792
            }
793
        }
794
        //retorna o ID na NFe
795
        if ($classPdf!==false) {
796
            $aR = [
797
                'id'=>str_replace('NFe', '', $this->infNFe->getAttribute("Id")),
798
                'classe_PDF'=>$this->pdf
799
            ];
800
            return $aR;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $aR; (array) is incompatible with the return type documented by NFePHP\DA\NFe\Danfe::montaDANFE of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
801
        } else {
802
            return str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
803
        }
804
    }//fim da função montaDANFE
805
806
    /**
807
     * anfavea
808
     * Função para transformar o campo cdata do padrão ANFAVEA para
809
     * texto imprimível
810
     *
811
     * @param  string $cdata campo CDATA
812
     * @return string conteúdo do campo CDATA como string
813
     */
814
    protected function anfaveaDANFE($cdata = '')
815
    {
816
        if ($cdata == '') {
817
            return '';
818
        }
819
        //remove qualquer texto antes ou depois da tag CDATA
820
        $cdata = str_replace('<![CDATA[', '<CDATA>', $cdata);
821
        $cdata = str_replace(']]>', '</CDATA>', $cdata);
822
        $cdata = preg_replace('/\s\s+/', ' ', $cdata);
823
        $cdata = str_replace("> <", "><", $cdata);
824
        $len = strlen($cdata);
825
        $startPos = strpos($cdata, '<');
826
        if ($startPos === false) {
827
            return $cdata;
828
        }
829
        for ($x=$len; $x>0; $x--) {
830
            if (substr($cdata, $x, 1) == '>') {
831
                $endPos = $x;
832
                break;
833
            }
834
        }
835
        if ($startPos > 0) {
836
            $parte1 = substr($cdata, 0, $startPos);
837
        } else {
838
            $parte1 = '';
839
        }
840
        $parte2 = substr($cdata, $startPos, $endPos-$startPos+1);
0 ignored issues
show
Bug introduced by
The variable $endPos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
841
        if ($endPos < $len) {
842
            $parte3 = substr($cdata, $endPos + 1, $len - $endPos - 1);
843
        } else {
844
            $parte3 = '';
845
        }
846
        $texto = trim($parte1).' '.trim($parte3);
847
        if (strpos($parte2, '<CDATA>') === false) {
848
            $cdata = '<CDATA>'.$parte2.'</CDATA>';
849
        } else {
850
            $cdata = $parte2;
851
        }
852
        //Retira a tag <FONTE IBPT> (caso existir) pois não é uma estrutura válida XML
853
        $cdata = str_replace('<FONTE IBPT>', '', $cdata);
854
        //carrega o xml CDATA em um objeto DOM
855
        $dom = new Dom();
856
        $dom->loadXML($cdata, LIBXML_NOBLANKS | LIBXML_NOEMPTYTAG);
857
        //$xml = $dom->saveXML();
858
        //grupo CDATA infADprod
859
        $id = $dom->getElementsByTagName('id')->item(0);
860
        $div = $dom->getElementsByTagName('div')->item(0);
861
        $entg = $dom->getElementsByTagName('entg')->item(0);
862
        $dest = $dom->getElementsByTagName('dest')->item(0);
863
        $ctl = $dom->getElementsByTagName('ctl')->item(0);
864
        $ref = $dom->getElementsByTagName('ref')->item(0);
865
        if (isset($id)) {
866
            if ($id->hasAttributes()) {
867
                foreach ($id->attributes as $attr) {
868
                    $name = $attr->nodeName;
869
                    $value = $attr->nodeValue;
870
                    $texto .= " $name : $value";
871
                }
872
            }
873
        }
874
        if (isset($div)) {
875
            if ($div->hasAttributes()) {
876
                foreach ($div->attributes as $attr) {
877
                    $name = $attr->nodeName;
878
                    $value = $attr->nodeValue;
879
                    $texto .= " $name : $value";
880
                }
881
            }
882
        }
883
        if (isset($entg)) {
884
            if ($entg->hasAttributes()) {
885
                foreach ($entg->attributes as $attr) {
886
                    $name = $attr->nodeName;
887
                    $value = $attr->nodeValue;
888
                    $texto .= " $name : $value";
889
                }
890
            }
891
        }
892
        if (isset($dest)) {
893
            if ($dest->hasAttributes()) {
894
                foreach ($dest->attributes as $attr) {
895
                    $name = $attr->nodeName;
896
                    $value = $attr->nodeValue;
897
                    $texto .= " $name : $value";
898
                }
899
            }
900
        }
901
        if (isset($ctl)) {
902
            if ($ctl->hasAttributes()) {
903
                foreach ($ctl->attributes as $attr) {
904
                    $name = $attr->nodeName;
905
                    $value = $attr->nodeValue;
906
                    $texto .= " $name : $value";
907
                }
908
            }
909
        }
910
        if (isset($ref)) {
911
            if ($ref->hasAttributes()) {
912
                foreach ($ref->attributes as $attr) {
913
                    $name = $attr->nodeName;
914
                    $value = $attr->nodeValue;
915
                    $texto .= " $name : $value";
916
                }
917
            }
918
        }
919
        //grupo CADATA infCpl
920
        $t = $dom->getElementsByTagName('transmissor')->item(0);
921
        $r = $dom->getElementsByTagName('receptor')->item(0);
922
        $versao = ! empty($dom->getElementsByTagName('versao')->item(0)->nodeValue) ?
923
            'Versao:'.$dom->getElementsByTagName('versao')->item(0)->nodeValue.' ' : '';
924
        $especieNF = ! empty($dom->getElementsByTagName('especieNF')->item(0)->nodeValue) ?
925
            'Especie:'.$dom->getElementsByTagName('especieNF')->item(0)->nodeValue.' ' : '';
926
        $fabEntrega = ! empty($dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue) ?
927
            'Entrega:'.$dom->getElementsByTagName('fabEntrega')->item(0)->nodeValue.' ' : '';
928
        $dca = ! empty($dom->getElementsByTagName('dca')->item(0)->nodeValue) ?
929
            'dca:'.$dom->getElementsByTagName('dca')->item(0)->nodeValue.' ' : '';
930
        $texto .= "".$versao.$especieNF.$fabEntrega.$dca;
931
        if (isset($t)) {
932
            if ($t->hasAttributes()) {
933
                $texto .= " Transmissor ";
934
                foreach ($t->attributes as $attr) {
935
                    $name = $attr->nodeName;
936
                    $value = $attr->nodeValue;
937
                    $texto .= " $name : $value";
938
                }
939
            }
940
        }
941
        if (isset($r)) {
942
            if ($r->hasAttributes()) {
943
                $texto .= " Receptor ";
944
                foreach ($r->attributes as $attr) {
945
                    $name = $attr->nodeName;
946
                    $value = $attr->nodeValue;
947
                    $texto .= " $name : $value";
948
                }
949
            }
950
        }
951
        return $texto;
952
    }
953
954
    /**
955
     * Dados brutos do PDF
956
     * @return string
957
     */
958
    public function render()
959
    {
960
        return $this->pdf->getPdf();
961
    }
962
963
    protected function statusNFe()
964
    {
965
        if (!isset($this->nfeProc)) {
966
            return ['status' => false, 'message' => 'NFe NÃO PROTOCOLADA'];
967
        }
968
        if ($this->getTagValue($this->ide, "tpAmb") == '2') {
969
            return ['status' => false, 'message' => 'NFe EMITIDA EM HOMOLOGAÇÃO'];
970
        }
971
        $cStat = $this->getTagValue($this->nfeProc, "cStat");
972
        if ($cStat == '101'
973
            || $cStat == '151'
974
            || $cStat == '135'
975
            || $cStat == '155'
976
            || $this->situacao_externa == self::SIT_CANCELADA
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
977
        ) {
978
            return ['status' => false, 'message' => 'NFe CANCELADA'];
979
        }
980
        
981
        if ($cStat == '110' ||
982
               $cStat == '301' ||
983
               $cStat == '302' ||
984
               $this->situacao_externa == self::SIT_DENEGADA
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
985
        ) {
986
            return ['status' => false, 'message' => 'NFe DENEGADA'];
987
        }
988
    }
989
990
    /*
991
    protected function pNotaCancelada()
992
    {
993
        if (!isset($this->nfeProc)) {
994
            return false;
995
        }
996
        $cStat = $this->getTagValue($this->nfeProc, "cStat");
997
        return $cStat == '101' ||
998
                $cStat == '151' ||
999
                $cStat == '135' ||
1000
                $cStat == '155' ||
1001
                $this->situacao_externa == self::SIT_CANCELADA;
1002
    }
1003
     *
1004
     */
1005
1006
    protected function notaDPEC()
1007
    {
1008
        return $this->situacao_externa == self::SIT_DPEC && $this->numero_registro_dpec != '';
0 ignored issues
show
Bug introduced by
The property situacao_externa does not seem to exist. Did you mean situacaoExterna?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1009
    }
1010
1011
    /*
1012
    protected function pNotaDenegada()
1013
    {
1014
        if (!isset($this->nfeProc)) {
1015
            return false;
1016
        }
1017
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
1018
        //1 VEZ NO ARQUIVO INTEIRO
1019
        $cStat = $this->getTagValue($this->nfeProc, "cStat");
1020
        return $cStat == '110' ||
1021
               $cStat == '301' ||
1022
               $cStat == '302' ||
1023
               $this->situacao_externa == self::SIT_DENEGADA;
1024
    }*/
1025
1026
    /**
1027
     *cabecalhoDANFE
1028
     * Monta o cabelhalho da DANFE (retrato e paisagem)
1029
     *
1030
     * @param  number $x      Posição horizontal inicial, canto esquerdo
1031
     * @param  number $y      Posição vertical inicial, canto superior
1032
     * @param  number $pag    Número da Página
1033
     * @param  number $totPag Total de páginas
1034
     * @return number Posição vertical final
1035
     */
1036
    protected function cabecalhoDANFE($x = 0, $y = 0, $pag = '1', $totPag = '1')
1037
    {
1038
        $oldX = $x;
1039
        $oldY = $y;
1040
        if ($this->orientacao == 'P') {
1041
              $maxW = $this->wPrint;
1042
        } else {
1043
            if ($pag == 1) { // primeira página
1044
                $maxW = $this->wPrint - $this->wCanhoto;
1045
            } else { // páginas seguintes
1046
                $maxW = $this->wPrint;
1047
            }
1048
        }
1049
        //####################################################################################
1050
        //coluna esquerda identificação do emitente
1051
        $w = round($maxW*0.41, 0);
1052
        if ($this->orientacao == 'P') {
1053
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
1054
        } else {
1055
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1056
        }
1057
        $w1 = $w;
1058
        $h=32;
1059
        $oldY += $h;
1060
        $this->pdf->textBox($x, $y, $w, $h);
1061
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
1062
        $this->pdf->textBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
1063
        //estabelecer o alinhamento
1064
        //pode ser left L, center C, right R, full logo L
1065
        //se for left separar 1/3 da largura para o tamanho da imagem
1066
        //os outros 2/3 serão usados para os dados do emitente
1067
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
1068
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
1069
        //se não houver logo centraliza dos dados do emitente
1070
        // coloca o logo
1071
        if (!empty($this->logomarca)) {
1072
            $logoInfo = getimagesize($this->logomarca);
1073
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
1074
            if ($type == 'png') {
1075
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
1076
                $type == 'jpg';
1077
            }
1078
            //largura da imagem em mm
1079
            $logoWmm = ($logoInfo[0]/72)*25.4;
1080
            //altura da imagem em mm
1081
            $logoHmm = ($logoInfo[1]/72)*25.4;
1082
            if ($this->logoAlign=='L') {
1083
                $nImgW = round($w/3, 0);
1084
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1085
                $xImg = $x+1;
1086
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1087
                //estabelecer posições do texto
1088
                $x1 = round($xImg + $nImgW +1, 0);
1089
                $y1 = round($h/3+$y, 0);
1090
                $tw = round(2*$w/3, 0);
1091
            } elseif ($this->logoAlign=='C') {
1092
                $nImgH = round($h/3, 0);
1093
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1094
                $xImg = round(($w-$nImgW)/2+$x, 0);
1095
                $yImg = $y+3;
1096
                $x1 = $x;
1097
                $y1 = round($yImg + $nImgH + 1, 0);
1098
                $tw = $w;
1099
            } elseif ($this->logoAlign=='R') {
1100
                $nImgW = round($w/3, 0);
1101
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1102
                $xImg = round($x+($w-(1+$nImgW)), 0);
1103
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1104
                $x1 = $x;
1105
                $y1 = round($h/3+$y, 0);
1106
                $tw = round(2*$w/3, 0);
1107
            } elseif ($this->logoAlign=='F') {
1108
                $nImgH = round($h-5, 0);
1109
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1110
                $xImg = round(($w-$nImgW)/2+$x, 0);
1111
                $yImg = $y+3;
1112
                $x1 = $x;
1113
                $y1 = round($yImg + $nImgH + 1, 0);
1114
                $tw = $w;
1115
            }
1116
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
1117
            $this->pdf->Image($this->logomarca, $xImg, $yImg, $nImgW, $nImgH, $type);
0 ignored issues
show
Bug introduced by
The variable $xImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $yImg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgW does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $nImgH does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1118
        } else {
1119
            $x1 = $x;
1120
            $y1 = round($h/3+$y, 0);
1121
            $tw = $w;
1122
        }
1123
        // monta as informações apenas se diferente de full logo
1124
        if ($this->logoAlign !== 'F') {
1125
            //Nome emitente
1126
            $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1127
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
1128
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
0 ignored issues
show
Bug introduced by
The variable $x1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $y1 does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $tw does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1129
            //endereço
1130
            $y1 = $y1+5;
1131
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1132
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1133
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1134
                 : '';
1135
            $lgr = $this->getTagValue($this->enderEmit, "xLgr");
1136
            $nro = $this->getTagValue($this->enderEmit, "nro");
1137
            $cpl = $this->getTagValue($this->enderEmit, "xCpl", " - ");
1138
            $bairro = $this->getTagValue($this->enderEmit, "xBairro");
1139
            $CEP = $this->getTagValue($this->enderEmit, "CEP");
1140
            $CEP = $this->formatField($CEP, "#####-###");
1141
            $mun = $this->getTagValue($this->enderEmit, "xMun");
1142
            $UF = $this->getTagValue($this->enderEmit, "UF");
1143
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1144
                    . $CEP . "\n" . $mun . " - " . $UF . " "
1145
                    . "Fone/Fax: " . $fone;
1146
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1147
        }
1148
1149
        //####################################################################################
1150
        //coluna central Danfe
1151
        $x += $w;
1152
        $w=round($maxW * 0.17, 0);//35;
1153
        $w2 = $w;
1154
        $h = 32;
1155
        $this->pdf->textBox($x, $y, $w, $h);
1156
  
1157
        $texto = "DANFE";
1158
        $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
1159
        $this->pdf->textBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1160
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1161
        $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1162
        $h = 20;
1163
        $this->pdf->textBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1164
        
1165
1166
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1167
        $texto = '0 - ENTRADA';
1168
        $y1 = $y + 14;
1169
        $h = 8;
1170
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1171
        $texto = '1 - SAÍDA';
1172
        $y1 = $y + 17;
1173
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1174
        //tipo de nF
1175
        $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1176
        $y1 = $y + 13;
1177
        $h = 7;
1178
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1179
        $this->pdf->textBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1180
        //numero da NF
1181
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1182
        $y1 = $y + 20;
1183
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1184
        $numNF = $this->formatField($numNF, "###.###.###");
1185
        $texto = "Nº. " . $numNF;
1186
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1187
        //Série
1188
        $y1 = $y + 23;
1189
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1190
        $texto = "Série " . $serie;
1191
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1192
        //numero paginas
1193
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I'];
1194
        $y1 = $y + 26;
1195
        $texto = "Folha " . $pag . "/" . $totPag;
1196
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1197
1198
        //####################################################################################
1199
        //coluna codigo de barras
1200
        $x += $w;
1201
        $w = ($maxW-$w1-$w2);//85;
1202
        $w3 = $w;
1203
        $h = 32;
1204
        $this->pdf->textBox($x, $y, $w, $h);
1205
        $this->pdf->SetFillColor(0, 0, 0);
1206
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1207
        $bW = 75;
1208
        $bH = 12;
1209
        //codigo de barras
1210
        $this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1211
        //linhas divisorias
1212
        $this->pdf->line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1213
        $this->pdf->line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1214
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1215
        $y1 = $y+4+$bH;
1216
        $h = 7;
1217
        $texto = 'CHAVE DE ACESSO';
1218
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1219
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1220
        $y1 = $y+8+$bH;
1221
        $texto = $this->formatField($chave_acesso, $this->formatoChave);
1222
        $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1223
        $y1 = $y+12+$bH;
1224
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1225
        $chaveContingencia="";
1226
        if ($this->pNotaDPEC()) {
0 ignored issues
show
Bug introduced by
The method pNotaDPEC() does not exist on NFePHP\DA\NFe\Danfe. Did you maybe mean notaDPEC()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1227
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1228
        } else {
1229
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1230
        }
1231
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
0 ignored issues
show
Bug introduced by
The method pNotaDPEC() does not exist on NFePHP\DA\NFe\Danfe. Did you maybe mean notaDPEC()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1232
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1233
            $chaveContingencia = $this->geraChaveAdicionalDeContingencia();
1234
            $this->pdf->setFillColor(0, 0, 0);
1235
            //codigo de barras
1236
            $this->pdf->code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1237
        } else {
1238
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1239
            $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1240
            $y1 = $y+16+$bH;
1241
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1242
            $this->pdf->textBox(
1243
                $x+2,
1244
                $y1,
1245
                $w-2,
1246
                $h,
1247
                $texto,
1248
                $aFont,
1249
                'T',
1250
                'C',
1251
                0,
1252
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1253
            );
1254
        }
1255
1256
        //####################################################################################
1257
        //Dados da NF do cabeçalho
1258
        //natureza da operação
1259
        $texto = 'NATUREZA DA OPERAÇÃO';
1260
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1261
        $w = $w1+$w2;
1262
        $y = $oldY;
1263
        $oldY += $h;
1264
        $x = $oldX;
1265
        $h = 7;
1266
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1267
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1268
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1269
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1270
        $x += $w;
1271
        $w = $w3;
1272
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1273
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1274
        $this->pdf->textBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1275
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1276
        // testada antes de tentar obter a informação.
1277
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1278
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1279
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1280
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
0 ignored issues
show
Bug introduced by
The method pNotaDPEC() does not exist on NFePHP\DA\NFe\Danfe. Did you maybe mean notaDPEC()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1281
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1282
            $texto = $this->formatField($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1283
            $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1284
        } else {
1285
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1286
            if ($this->pNotaDPEC()) {
0 ignored issues
show
Bug introduced by
The method pNotaDPEC() does not exist on NFePHP\DA\NFe\Danfe. Did you maybe mean notaDPEC()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1287
                $texto = $this->numero_registro_dpec;
1288
                $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1289
            } else {
1290
                if (isset($this->nfeProc)) {
1291
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
1292
                            $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
1293
                    $tsHora = $this->convertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue);
1294
                    if ($texto != '') {
1295
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1296
                    }
1297
                    $cStat = $this->nfeProc->getElementsByTagName("cStat")->item(0)->nodeValue;
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1298
                } else {
1299
                    $texto = '';
1300
                    $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1301
                }
1302
            }
1303
        }
1304
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1305
        //####################################################################################
1306
        //INSCRIÇÃO ESTADUAL
1307
        $w = round($maxW * 0.333, 0);
1308
        $y += $h;
1309
        $oldY += $h;
1310
        $x = $oldX;
1311
        $texto = 'INSCRIÇÃO ESTADUAL';
1312
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1313
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1314
        $texto = $this->getTagValue($this->emit, "IE");
1315
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1316
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1317
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1318
        $x += $w;
1319
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1320
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1321
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1322
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1323
             ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1324
             : '';
1325
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1326
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1327
        //CNPJ
1328
        $x += $w;
1329
        $w = ($maxW-(2*$w));
1330
        $texto = 'CNPJ / CPF';
1331
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1332
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1333
        //Pegando valor do CPF/CNPJ
1334
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1335
            $texto = $this->formatField(
1336
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1337
                "###.###.###/####-##"
1338
            );
1339
        } else {
1340
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1341
                $this->formatField(
1342
                    $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1343
                    "###.###.###-##"
1344
                ) : '';
1345
        }
1346
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1347
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1348
1349
        //####################################################################################
1350
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1351
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
0 ignored issues
show
Unused Code introduced by
$tpAmb is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1352
        //indicar cancelamento
1353
        $resp = $this->statusNFe();
1354
        if (!$resp['status']) {
1355
            $x = 10;
1356
            $y = $this->hPrint-130;
1357
            $h = 25;
1358
            $w = $maxW-(2*$x);
1359
            $this->pdf->setTextColor(90, 90, 90);
1360
            $texto = $resp['message'];
1361
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1362
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1363
            $y += $h;
1364
            $h = 5;
1365
            $w = $maxW-(2*$x);
1366
            if (isset($this->infProt) && $resp['status']) {
1367
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1368
            } else {
1369
                $xMotivo = '';
1370
            }
1371
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1372
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1373
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1374
            $this->pdf->setTextColor(0, 0, 0);
1375
        }
1376
        
1377
        /*
1378
        if ($this->pNotaCancelada()) {
1379
            //101 Cancelamento
1380
            $x = 10;
1381
            $y = $this->hPrint-130;
1382
            $h = 25;
1383
            $w = $maxW-(2*$x);
1384
            $this->pdf->SetTextColor(90, 90, 90);
1385
            $texto = "NFe CANCELADA";
1386
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1387
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1388
            $this->pdf->SetTextColor(0, 0, 0);
1389
        }*/
1390
1391
        if ($this->pNotaDPEC() || $this->tpEmis == 4) {
0 ignored issues
show
Bug introduced by
The method pNotaDPEC() does not exist on NFePHP\DA\NFe\Danfe. Did you maybe mean notaDPEC()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1392
            //DPEC
1393
            $x = 10;
1394
            $y = $this->hPrint-130;
1395
            $h = 25;
1396
            $w = $maxW-(2*$x);
1397
            $this->pdf->SetTextColor(200, 200, 200);
1398
            $texto = "DANFE impresso em contingência -\n".
1399
                     "DPEC regularmente recebido pela Receita\n".
1400
                     "Federal do Brasil";
1401
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1402
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1403
            $this->pdf->SetTextColor(0, 0, 0);
1404
        }
1405
        /*
1406
        if ($this->pNotaDenegada()) {
1407
            //110 301 302 Denegada
1408
            $x = 10;
1409
            $y = $this->hPrint-130;
1410
            $h = 25;
1411
            $w = $maxW-(2*$x);
1412
            $this->pdf->SetTextColor(90, 90, 90);
1413
            $texto = "NFe USO DENEGADO";
1414
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1415
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1416
            $y += $h;
1417
            $h = 5;
1418
            $w = $maxW-(2*$x);
1419
            if (isset($this->infProt)) {
1420
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1421
            } else {
1422
                $xMotivo = '';
1423
            }
1424
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1425
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1426
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1427
            $this->pdf->SetTextColor(0, 0, 0);
1428
        }
1429
         *
1430
         */
1431
        //indicar sem valor
1432
        /*
1433
        if ($tpAmb != 1) {
1434
            $x = 10;
1435
            if ($this->orientacao == 'P') {
1436
                $y = round($this->hPrint*2/3, 0);
1437
            } else {
1438
                $y = round($this->hPrint/2, 0);
1439
            }
1440
            $h = 5;
1441
            $w = $maxW-(2*$x);
1442
            $this->pdf->SetTextColor(90, 90, 90);
1443
            $texto = "SEM VALOR FISCAL";
1444
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1445
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1446
            $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1447
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1448
            $this->pdf->textBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1449
            $this->pdf->SetTextColor(0, 0, 0);
1450
        } else {
1451
            $x = 10;
1452
            if ($this->orientacao == 'P') {
1453
                $y = round($this->hPrint*2/3, 0);
1454
            } else {
1455
                $y = round($this->hPrint/2, 0);
1456
            }//fim orientacao
1457
            $h = 5;
1458
            $w = $maxW-(2*$x);
1459
            $this->pdf->SetTextColor(90, 90, 90);
1460
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1461
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1462
                //Contingência
1463
                $texto = "DANFE Emitido em Contingência";
1464
                $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1465
                $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1466
                $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1467
                $texto = "devido à problemas técnicos";
1468
                $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1469
            } else {
1470
                if (!isset($this->nfeProc)) {
1471
                    if (!$this->pNotaDPEC()) {
1472
                        $texto = "SEM VALOR FISCAL";
1473
                        $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1474
                        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1475
                    }
1476
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1477
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1478
                    if (!$this->pNotaDPEC()) {
1479
                        $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1480
                    } else {
1481
                        $this->pdf->textBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1482
                    }
1483
                }//fim nefProc
1484
            }//fim tpEmis
1485
            $this->pdf->SetTextColor(0, 0, 0);
1486
        }
1487
         *
1488
         */
1489
        return $oldY;
1490
    } //fim cabecalhoDANFE
1491
1492
    /**
1493
     * destinatarioDANFE
1494
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1495
     *
1496
     * @name   destinatarioDANFE
1497
     * @param  number $x Posição horizontal canto esquerdo
1498
     * @param  number $y Posição vertical canto superior
1499
     * @return number Posição vertical final
1500
     */
1501
    protected function destinatarioDANFE($x = 0, $y = 0)
1502
    {
1503
        //####################################################################################
1504
        //DESTINATÁRIO / REMETENTE
1505
        $oldX = $x;
1506
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1507
        if ($this->orientacao == 'P') {
1508
            $maxW = $this->wPrint;
1509
        } else {
1510
            $maxW = $this->wPrint - $this->wCanhoto;
1511
        }
1512
        $w = $maxW;
1513
        $h = 7;
1514
        $texto = 'DESTINATÁRIO / REMETENTE';
1515
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1516
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1517
        //NOME / RAZÃO SOCIAL
1518
        $w = round($maxW*0.61, 0);
1519
        $w1 = $w;
1520
        $y += 3;
1521
        $texto = 'NOME / RAZÃO SOCIAL';
1522
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1523
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1524
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1525
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1526
        if ($this->orientacao == 'P') {
1527
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1528
        } else {
1529
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1530
        }
1531
        //CNPJ / CPF
1532
        $x += $w;
1533
        $w = round($maxW*0.23, 0);
1534
        $w2 = $w;
1535
        $texto = 'CNPJ / CPF';
1536
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1537
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1538
        //Pegando valor do CPF/CNPJ
1539
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1540
            $texto = $this->formatField(
1541
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1542
                "###.###.###/####-##"
1543
            );
1544
        } else {
1545
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1546
                    $this->formatField(
1547
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1548
                        "###.###.###-##"
1549
                    ) : '';
1550
        }
1551
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1552
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1553
        //DATA DA EMISSÃO
1554
        $x += $w;
1555
        $w = $maxW-($w1+$w2);
1556
        $wx = $w;
1557
        $texto = 'DATA DA EMISSÃO';
1558
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1559
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1560
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1561
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1562
        if ($dEmi == '') {
1563
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1564
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1565
            $aDemi = explode('T', $dEmi);
1566
            $dEmi = $aDemi[0];
1567
        }
1568
        $texto = $this->ymdTodmy($dEmi);
1569
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1570
        if ($this->orientacao == 'P') {
1571
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1572
        } else {
1573
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1574
        }
1575
        //ENDEREÇO
1576
        $w = round($maxW*0.47, 0);
1577
        $w1 = $w;
1578
        $y += $h;
1579
        $x = $oldX;
1580
        $texto = 'ENDEREÇO';
1581
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1582
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1583
        $texto = $this->dest->getElementsByTagName("xLgr")->item(0)->nodeValue;
1584
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1585
        $texto .= $this->getTagValue($this->dest, "xCpl", " - ");
1586
1587
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1588
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1589
        //BAIRRO / DISTRITO
1590
        $x += $w;
1591
        $w = round($maxW*0.21, 0);
1592
        $w2 = $w;
1593
        $texto = 'BAIRRO / DISTRITO';
1594
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1595
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1596
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1597
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1598
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1599
        //CEP
1600
        $x += $w;
1601
        $w = $maxW-$w1-$w2-$wx;
1602
        $w2 = $w;
0 ignored issues
show
Unused Code introduced by
$w2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1603
        $texto = 'CEP';
1604
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1605
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1606
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1607
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1608
        $texto = $this->formatField($texto, "#####-###");
1609
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1610
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1611
        //DATA DA SAÍDA
1612
        $x += $w;
1613
        $w = $wx;
1614
        $texto = 'DATA DA SAÍDA/ENTRADA';
1615
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1616
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1617
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1618
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1619
        if ($dSaiEnt == '') {
1620
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1621
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1622
            $aDsaient = explode('T', $dSaiEnt);
1623
            $dSaiEnt = $aDsaient[0];
1624
        }
1625
        $texto = $this->ymdTodmy($dSaiEnt);
1626
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1627
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1628
        //MUNICÍPIO
1629
        $w = $w1;
1630
        $y += $h;
1631
        $x = $oldX;
1632
        $texto = 'MUNICÍPIO';
1633
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1634
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1635
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1636
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1637
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1638
        }
1639
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1640
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1641
        //UF
1642
        $x += $w;
1643
        $w = 8;
1644
        $texto = 'UF';
1645
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1646
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1647
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1648
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1649
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1650
        //FONE / FAX
1651
        $x += $w;
1652
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1653
        $w3 = $w;
1654
        $texto = 'FONE / FAX';
1655
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1656
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1657
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1658
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1659
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1660
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1661
        //INSCRIÇÃO ESTADUAL
1662
        $x += $w;
1663
        $w = $maxW -$w1-$wx-8-$w3;
1664
        $texto = 'INSCRIÇÃO ESTADUAL';
1665
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1666
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1667
        $IE = $this->dest->getElementsByTagName("IE");
1668
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1669
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1670
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1671
        //HORA DA SAÍDA
1672
        $x += $w;
1673
        $w = $wx;
1674
        $texto = 'HORA DA SAÍDA/ENTRADA';
1675
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1676
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1677
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1678
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1679
        if ($hSaiEnt == '') {
1680
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1681
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1682
            $tsDhSaiEnt = $this->convertTime($dhSaiEnt);
1683
            if ($tsDhSaiEnt != '') {
1684
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1685
            }
1686
        }
1687
        $texto = $hSaiEnt;
1688
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1689
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1690
        return ($y + $h);
1691
    } //fim da função destinatarioDANFE
1692
1693
     /**
1694
     * getTextoFatura
1695
     * Gera a String do Texto da Fatura
1696
      *
1697
     * @name   getTextoFatura
1698
     * @return uma String com o texto ou "";
1699
     */
1700
    protected function getTextoFatura()
1701
    {
1702
        if (isset($this->cobr)) {
1703
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1704
            if (isset($fat)) {
1705
                if (!empty($this->getTagValue($this->ide, "indPag"))) {
1706
                    $textoIndPag = "";
1707
                    $indPag = $this->getTagValue($this->ide, "indPag");
1708
                    if ($indPag === "0") {
1709
                        $textoIndPag = "Pagamento à Vista - ";
1710
                    } elseif ($indPag === "1") {
1711
                        $textoIndPag = "Pagamento à Prazo - ";
1712
                    }
1713
                    $nFat = $this->getTagValue($fat, "nFat", "Fatura: ");
1714
                    $vOrig = $this->getTagValue($fat, "vOrig", " Valor Original: ");
1715
                    $vDesc = $this->getTagValue($fat, "vDesc", " Desconto: ");
1716
                    $vLiq = $this->getTagValue($fat, "vLiq", " Valor Líquido: ");
1717
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1718
                    return $texto;
1719
                } else {
1720
                    $pag = $this->dom->getElementsByTagName("pag");
1721
                    if ($tPag = $this->getTagValue($pag->item(0), "tPag")) {
1722
                        return $this->tipoPag($tPag);
1723
                    }
1724
                }
1725
            }
1726
        }
1727
        return "";
1728
    }
1729
1730
     /**
1731
     * sizeExtraTextoFatura
1732
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1733
      *
1734
     * @name   sizeExtraTextoFatura
1735
     * @return integer
1736
     */
1737
    protected function sizeExtraTextoFatura()
1738
    {
1739
        $textoFatura = $this->getTextoFatura();
1740
        //verificar se existem duplicatas
1741
        if ($this->dup->length == 0 && $textoFatura !== "") {
1742
            return 10;
1743
        }
1744
        return 0;
1745
    }
1746
1747
    /**
1748
     * faturaDANFE
1749
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1750
     *
1751
     * @name   faturaDANFE
1752
     * @param  number $x Posição horizontal canto esquerdo
1753
     * @param  number $y Posição vertical canto superior
1754
     * @return number Posição vertical final
1755
     */
1756
    protected function faturaDANFE($x, $y)
1757
    {
1758
        $linha = 1;
1759
        $h = 8+3;
0 ignored issues
show
Unused Code introduced by
$h is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1760
        $oldx = $x;
1761
        $textoFatura = $this->getTextoFatura();
1762
        //verificar se existem duplicatas
1763
        if ($this->dup->length > 0 || $textoFatura !== "") {
1764
            //#####################################################################
1765
            //FATURA / DUPLICATA
1766
            $texto = "FATURA / DUPLICATA";
1767
            if ($this->orientacao == 'P') {
1768
                $w = $this->wPrint;
1769
            } else {
1770
                $w = 271;
1771
            }
1772
            $h = 8;
1773
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1774
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1775
            $y += 3;
1776
            $dups = "";
0 ignored issues
show
Unused Code introduced by
$dups is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1777
            $dupcont = 0;
1778
            $nFat = $this->dup->length;
0 ignored issues
show
Unused Code introduced by
$nFat is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1779
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1780
                $myH=6;
1781
                $myW = $this->wPrint;
1782
                if ($this->orientacao == 'L') {
1783
                    $myW -= $this->wCanhoto;
1784
                }
1785
                $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1786
                $this->pdf->textBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1787
                $y+=$myH+1;
1788
            }
1789
            if ($this->orientacao == 'P') {
1790
                $w = round($this->wPrint/7.018, 0)-1;
1791
            } else {
1792
                $w = 28;
1793
            }
1794
            $increm = 1;
1795
            foreach ($this->dup as $k => $d) {
1796
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1797
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1798
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1799
                        $this->ymdTodmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1800
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1801
                        'R$ ' . number_format(
1802
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1803
                            2,
1804
                            ",",
1805
                            "."
1806
                        ) : '';
1807
                $h = 8;
1808
                $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1809
                if ($nDup!='0' && $nDup!='') {
1810
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1811
                    $this->pdf->textBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1812
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1813
                    $this->pdf->textBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1814
                } else {
1815
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1816
                    $this->pdf->textBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1817
                }
1818
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1819
                $this->pdf->textBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1820
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1821
                $this->pdf->textBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1822
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1823
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1824
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1825
                $this->pdf->textBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1826
                $x += $w+$increm;
1827
                $dupcont += 1;
1828
                if ($this->orientacao == 'P') {
1829
                    $maxDupCont = 6;
1830
                } else {
1831
                    $maxDupCont = 8;
1832
                }
1833
                if ($dupcont > $maxDupCont) {
1834
                    $y += 9;
1835
                    $x = $oldx;
1836
                    $dupcont = 0;
1837
                    $linha += 1;
1838
                }
1839
                if ($linha == 5) {
1840
                    $linha = 4;
1841
                    break;
1842
                }
1843
            }
1844
            if ($dupcont == 0) {
1845
                $y -= 9;
1846
                $linha--;
1847
            }
1848
            return ($y+$h);
1849
        } else {
1850
            $linha = 0;
0 ignored issues
show
Unused Code introduced by
$linha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1851
            return ($y-2);
1852
        }
1853
    } //fim da função faturaDANFE
1854
1855
    /**
1856
     * pagamentoDANFE
1857
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na faturaDANFE)
1858
     *
1859
     * @name   pagamentoDANFE
1860
     * @param  number $x Posição horizontal canto esquerdo
1861
     * @param  number $y Posição vertical canto superior
1862
     * @return number Posição vertical final
1863
     */
1864
    protected function pagamentoDANFE($x, $y)
1865
    {
1866
        $linha = 1;
1867
        $h = 8+3;
0 ignored issues
show
Unused Code introduced by
$h is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1868
        $oldx = $x;
1869
        //verificar se existem cobranças definidas
1870
        if (isset($this->detPag) && $this->detPag->length > 0) {
1871
            //#####################################################################
1872
            //Tipo de pagamento
1873
            $texto = "PAGAMENTO";
1874
            if ($this->orientacao == 'P') {
1875
                $w = $this->wPrint;
1876
            } else {
1877
                $w = 271;
1878
            }
1879
            $h = 8;
1880
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1881
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1882
            $y += 3;
1883
            $dups = "";
0 ignored issues
show
Unused Code introduced by
$dups is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1884
            $dupcont = 0;
1885
            if ($this->orientacao == 'P') {
1886
                $w = round($this->wPrint/7.018, 0)-1;
1887
            } else {
1888
                $w = 28;
1889
            }
1890
            if ($this->orientacao == 'P') {
1891
                $maxDupCont = 6;
1892
            } else {
1893
                $maxDupCont = 8;
1894
            }
1895
            $increm = 1;
1896
            $formaPagamento = ['01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1897
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1898
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1899
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros'];
1900
            $bandeira = ['01'=>'Visa','02'=>'Mastercard','03'=>'American','04'=>'Sorocred','05'=>'Diners',
0 ignored issues
show
Unused Code introduced by
$bandeira is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1901
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros'];
1902
            foreach ($this->detPag as $k => $d) {
1903
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1904
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1905
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1906
                    ? 'R$ ' . number_format(
1907
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1908
                        2,
1909
                        ",",
1910
                        "."
1911
                    ) : '';
1912
                $h = 6;
1913
                $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1914
                if (isset($formaPagamento[$fPag])) {
1915
                    /*Exibir Item sem pagamento ou outros?*/
1916
                    if ($fPag=='90' || $fPag=='99') {
1917
                        continue;
1918
                    }
1919
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1920
                    $this->pdf->textBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1921
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1922
                    $this->pdf->textBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1923
                } else {
1924
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
1925
                    $this->pdf->textBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1926
                }
1927
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1928
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1929
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1930
                $this->pdf->textBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1931
                $x += $w+$increm;
1932
                $dupcont += 1;
1933
1934
                if ($dupcont>$maxDupCont) {
1935
                    $y += 9;
1936
                    $x = $oldx;
1937
                    $dupcont = 0;
1938
                    $linha += 1;
1939
                }
1940
                if ($linha == 5) {
1941
                    $linha = 4;
1942
                    break;
1943
                }
1944
            }
1945
            if ($dupcont == 0) {
1946
                $y -= 9;
1947
                $linha--;
1948
            }
1949
            return ($y+$h);
1950
        } else {
1951
            $linha = 0;
0 ignored issues
show
Unused Code introduced by
$linha is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1952
            return ($y-2);
1953
        }
1954
    } //fim da função pagamentoDANFE
1955
    
1956
    /**
1957
     * impostoDanfeHelper
1958
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1959
     *
1960
     * @name   impostoDanfeHelper
1961
     * @param  float $x Posição horizontal canto esquerdo
1962
     * @param  float $y Posição vertical canto superior
1963
     * @param  float $w Largura do campo
1964
     * @param  float $h Altura do campo
1965
     * @param  float $h Título do campo
1966
     * @param  float $h Valor do imposto
1967
     * @return float Sugestão do $x do próximo imposto
1968
     */
1969
    protected function impostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1970
    {
1971
        $valorImposto = '0, 00';
1972
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1973
        if (isset($the_field)) {
1974
            $the_value = $the_field->nodeValue;
1975
            if (!empty($the_value)) {
1976
                $valorImposto = number_format($the_value, 2, ",", ".");
1977
            }
1978
        }
1979
1980
        $fontTitulo = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1981
        $fontValor = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1982
        $this->pdf->textBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1983
        $this->pdf->textBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1984
1985
        $next_x = $x + $w;
1986
        return $next_x;
1987
    }
1988
1989
    /**
1990
     * impostoDANFE
1991
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1992
     *
1993
     * @param  number $x Posição horizontal canto esquerdo
1994
     * @param  number $y Posição vertical canto superior
1995
     * @return number Posição vertical final
1996
     */
1997
    protected function impostoDANFE($x, $y)
1998
    {
1999
        $x_inicial = $x;
2000
        //#####################################################################
2001
2002
2003
        $campos_por_linha = 9;
2004
        if (!$this->exibirPIS) {
2005
            $campos_por_linha--;
2006
        }
2007
        if (!$this->exibirIcmsInterestadual) {
2008
            $campos_por_linha -= 2;
2009
        }
2010
2011
        if ($this->orientacao == 'P') {
2012
            $maxW = $this->wPrint;
2013
            $title_size = 31;
2014
        } else {
2015
            $maxW = $this->wPrint - $this->wCanhoto;
2016
            $title_size = 40;
2017
        }
2018
        $w = $maxW / $campos_por_linha;
2019
2020
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2021
        $texto = "CÁLCULO DO IMPOSTO";
2022
        $this->pdf->textBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
2023
        $y += 3;
2024
        $h = 7;
2025
2026
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
2027
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
2028
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
2029
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
2030
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
2031
2032
        if ($this->exibirIcmsInterestadual) {
2033
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
2034
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
2035
        }
2036
2037
        if ($this->exibirPIS) {
2038
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
2039
        }
2040
2041
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. TOTAL PRODUTOS", "vProd");
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2042
2043
        //
2044
2045
        $y += $h;
2046
        $x = $x_inicial;
2047
2048
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
2049
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
2050
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
2051
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
2052
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
2053
2054
        if ($this->exibirIcmsInterestadual) {
2055
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
2056
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
2057
        }
2058
2059
        if ($this->exibirPIS) {
2060
            $x = $this->impostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2061
        }
2062
        $x = $this->impostoDanfeHelper($x, $y, $w, $h, "V. TOTAL DA NOTA", "vNF");
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2063
2064
        return ($y+$h);
2065
    } //fim impostoDANFE
2066
2067
    /**
2068
     * transporteDANFE
2069
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2070
     *
2071
     * @name   transporteDANFE
2072
     * @param  float $x Posição horizontal canto esquerdo
2073
     * @param  float $y Posição vertical canto superior
2074
     * @return float Posição vertical final
2075
     */
2076
    protected function transporteDANFE($x, $y)
2077
    {
2078
        $oldX = $x;
2079
        if ($this->orientacao == 'P') {
2080
            $maxW = $this->wPrint;
2081
        } else {
2082
            $maxW = $this->wPrint - $this->wCanhoto;
2083
        }
2084
        //#####################################################################
2085
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2086
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2087
        $w = $maxW;
2088
        $h = 7;
2089
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2090
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2091
        //NOME / RAZÃO SOCIAL
2092
        $w1 = $maxW*0.29;
2093
        $y += 3;
2094
        $texto = 'NOME / RAZÃO SOCIAL';
2095
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2096
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2097
        if (isset($this->transporta)) {
2098
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
2099
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
2100
        } else {
2101
            $texto = '';
2102
        }
2103
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2104
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2105
        //FRETE POR CONTA
2106
        $x += $w1;
2107
        $w2 = $maxW*0.15;
2108
        $texto = 'FRETE';
2109
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2110
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2111
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
2112
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
2113
        switch ($tipoFrete) {
2114
            case 0:
2115
                $texto = "0-Por conta do Rem";
2116
                break;
2117
            case 1:
2118
                $texto = "1-Por conta do Dest";
2119
                break;
2120
            case 2:
2121
                $texto = "2-Por conta de Terceiros";
2122
                break;
2123
            case 3:
2124
                $texto = "3-Próprio por conta do Rem";
2125
                break;
2126
            case 4:
2127
                $texto = "4-Próprio por conta do Dest";
2128
                break;
2129
            case 9:
2130
                $texto = "9-Sem Transporte";
2131
                break;
2132
        }
2133
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2134
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2135
        //CÓDIGO ANTT
2136
        $x += $w2;
2137
        $texto = 'CÓDIGO ANTT';
2138
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2139
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2140
        if (isset($this->veicTransp)) {
2141
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
2142
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
2143
        } else {
2144
            $texto = '';
2145
        }
2146
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2147
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2148
        //PLACA DO VEÍC
2149
        $x += $w2;
2150
        $texto = 'PLACA DO VEÍCULO';
2151
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2152
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2153
        if (isset($this->veicTransp)) {
2154
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
2155
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
2156
        } elseif (isset($this->reboque)) {
2157
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
2158
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
2159
        } else {
2160
            $texto = '';
2161
        }
2162
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2163
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2164
        //UF
2165
        $x += $w2;
2166
        $w3 = round($maxW*0.04, 0);
2167
        $texto = 'UF';
2168
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2169
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2170
        if (isset($this->veicTransp)) {
2171
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2172
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2173
        } elseif (isset($this->reboque)) {
2174
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2175
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2176
        } else {
2177
            $texto = '';
2178
        }
2179
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2180
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2181
        //CNPJ / CPF
2182
        $x += $w3;
2183
        $w = $maxW-($w1+3*$w2+$w3);
2184
        $texto = 'CNPJ / CPF';
2185
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2186
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2187
        if (isset($this->transporta)) {
2188
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2189
                    $this->formatField(
2190
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2191
                        "##.###.###/####-##"
2192
                    ) : '';
2193
            if ($texto == '') {
2194
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2195
                        $this->formatField(
2196
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2197
                            "###.###.###-##"
2198
                        ) : '';
2199
            }
2200
        } else {
2201
            $texto = '';
2202
        }
2203
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2204
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2205
        //#####################################################################
2206
        //ENDEREÇO
2207
        $y += $h;
2208
        $x = $oldX;
2209
        $h = 7;
2210
        $w1 = $maxW*0.44;
2211
        $texto = 'ENDEREÇO';
2212
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2213
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2214
        if (isset($this->transporta)) {
2215
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2216
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2217
        } else {
2218
            $texto = '';
2219
        }
2220
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2221
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2222
        //MUNICÍPIO
2223
        $x += $w1;
2224
        $w2 = round($maxW*0.30, 0);
2225
        $texto = 'MUNICÍPIO';
2226
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2227
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2228
        if (isset($this->transporta)) {
2229
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2230
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2231
        } else {
2232
            $texto = '';
2233
        }
2234
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2235
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2236
        //UF
2237
        $x += $w2;
2238
        $w3 = round($maxW*0.04, 0);
2239
        $texto = 'UF';
2240
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2241
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2242
        if (isset($this->transporta)) {
2243
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2244
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2245
        } else {
2246
            $texto = '';
2247
        }
2248
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2249
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2250
        //INSCRIÇÃO ESTADUAL
2251
        $x += $w3;
2252
        $w = $maxW-($w1+$w2+$w3);
2253
        $texto = 'INSCRIÇÃO ESTADUAL';
2254
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2255
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2256
        $texto = '';
2257
        if (isset($this->transporta)) {
2258
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2259
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2260
            }
2261
        }
2262
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2263
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2264
        //Tratar Multiplos volumes
2265
        $volumes = $this->transp->getElementsByTagName('vol');
2266
        $quantidade = 0;
2267
        $especie = '';
2268
        $marca = '';
2269
        $numero = '';
2270
        $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2271
        $pesoBruto=0;
2272
        $pesoLiquido=0;
2273
        foreach ($volumes as $volume) {
2274
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2275
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2276
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2277
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2278
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2279
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2280
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2281
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2282
            if ($texto != $especie && $especie != '') {
2283
                //tem várias especies
2284
                $especie = 'VARIAS';
2285
            } else {
2286
                $especie = $texto;
2287
            }
2288
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2289
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2290
            if ($texto != $marca && $marca != '') {
2291
                //tem várias especies
2292
                $marca = 'VARIAS';
2293
            } else {
2294
                $marca = $texto;
2295
            }
2296
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2297
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2298
            if ($texto != $numero && $numero != '') {
2299
                //tem várias especies
2300
                $numero = 'VARIOS';
2301
            } else {
2302
                $numero = $texto;
2303
            }
2304
        }
2305
2306
        //#####################################################################
2307
        //QUANTIDADE
2308
        $y += $h;
2309
        $x = $oldX;
2310
        $h = 7;
2311
        $w1 = round($maxW*0.10, 0);
2312
        $texto = 'QUANTIDADE';
2313
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2314
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2315
        if (!empty($quantidade)) {
2316
            $texto = $quantidade;
2317
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2318
            $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2319
        }
2320
        //ESPÉCIE
2321
        $x += $w1;
2322
        $w2 = round($maxW*0.17, 0);
2323
        $texto = 'ESPÉCIE';
2324
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2325
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2326
        $texto = $especie;
2327
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2328
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2329
        //MARCA
2330
        $x += $w2;
2331
        $texto = 'MARCA';
2332
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2333
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2334
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2335
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2336
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2337
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2338
        //NUMERAÇÃO
2339
        $x += $w2;
2340
        $texto = 'NUMERAÇÃO';
2341
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2342
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2343
        $texto = $numero;
2344
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2345
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2346
        //PESO BRUTO
2347
        $x += $w2;
2348
        $w3 = round($maxW*0.20, 0);
2349
        $texto = 'PESO BRUTO';
2350
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2351
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2352
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2353
            $texto = number_format($pesoBruto, 3, ",", ".");
2354
        } else {
2355
            $texto = '';
2356
        }
2357
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2358
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2359
        //PESO LÍQUIDO
2360
        $x += $w3;
2361
        $w = $maxW -($w1+3*$w2+$w3);
2362
        $texto = 'PESO LÍQUIDO';
2363
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2364
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2365
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2366
            $texto = number_format($pesoLiquido, 3, ",", ".");
2367
        } else {
2368
            $texto = '';
2369
        }
2370
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2371
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2372
        return ($y+$h);
2373
    } //fim transporteDANFE
2374
2375
2376
2377
    protected function descricaoProdutoHelper($origem, $campo, $formato)
2378
    {
2379
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2380
        if (!isset($valor_original)) {
2381
            return "";
2382
        }
2383
        $valor_original = $valor_original->nodeValue;
2384
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2385
2386
        if ($valor != "") {
2387
            return sprintf($formato, $valor);
2388
        }
2389
        return "";
2390
    }
2391
2392
    /**
2393
     * descricaoProduto
2394
     * Monta a string de descrição de cada Produto
2395
     *
2396
     * @name   descricaoProduto
2397
     * @param  DOMNode itemProd
2398
     * @return string descricao do produto
2399
     */
2400
    protected function descricaoProduto($itemProd)
2401
    {
2402
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2403
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2404
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2405
        $impostos = '';
2406
2407
        if (!empty($ICMS)) {
2408
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2409
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2410
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2411
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2412
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2413
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2414
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2415
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2416
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2417
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2418
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2419
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCSTRet", " vBcStRet=%s");
2420
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pST", " pSt=%s");
2421
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSSTRet", " vIcmsStRet=%s");
2422
        }
2423
        if (!empty($ICMSUFDest)) {
2424
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2425
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2426
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2427
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2428
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2429
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2430
        }
2431
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue)
2432
            ? substr(
2433
                $this->anfaveaDANFE($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue),
2434
                0,
2435
                500
2436
            )
2437
            : '';
2438
        if (! empty($infAdProd)) {
2439
            $infAdProd = trim($infAdProd);
2440
            $infAdProd .= ' ';
2441
        }
2442
        $loteTxt ='';
2443
        $rastro = $prod->getElementsByTagName("med");
0 ignored issues
show
Unused Code introduced by
$rastro is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2444
        if (!empty($prod->getElementsByTagName("rastro"))) {
2445
            $rastro = $prod->getElementsByTagName("rastro");
2446
            $i = 0;
2447
            while ($i < $rastro->length) {
2448
                $loteTxt .= $this->getTagValue($rastro->item($i), 'nLote', ' Lote: ');
2449
                $loteTxt .= $this->getTagValue($rastro->item($i), 'qLote', ' Quant: ');
2450
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dFab', ' Fab: ');
2451
                $loteTxt .= $this->getTagDate($rastro->item($i), 'dVal', ' Val: ');
2452
                $loteTxt .= $this->getTagValue($rastro->item($i), 'vPMC', ' PMC: ');
2453
                $i++;
2454
            }
2455
            if ($loteTxt != '') {
2456
                $loteTxt.= ' ';
2457
            }
2458
        }
2459
        //NT2013.006 FCI
2460
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2461
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2462
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2463
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2464
        //decodifica os caracteres html no xml
2465
        $texto = html_entity_decode($texto);
2466
        if ($this->descProdQuebraLinha) {
2467
            $texto = str_replace(";", "\n", $texto);
2468
        }
2469
        return $texto;
2470
    }
2471
2472
    /**
2473
     * itensDANFE
2474
     * Monta o campo de itens da DANFE (retrato e paisagem)
2475
     *
2476
     * @name   itensDANFE
2477
     * @param  float $x       Posição horizontal canto esquerdo
2478
     * @param  float $y       Posição vertical canto superior
2479
     * @param  float $nInicio Número do item inicial
2480
     * @param  float $max     Número do item final
0 ignored issues
show
Bug introduced by
There is no parameter named $max. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2481
     * @param  float $hmax    Altura máxima do campo de itens em mm
2482
     * @return float Posição vertical final
2483
     */
2484
    protected function itensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2485
    {
2486
        $oldX = $x;
2487
        $oldY = $y;
2488
        $totItens = $this->det->length;
2489
        //#####################################################################
2490
        //DADOS DOS PRODUTOS / SERVIÇOS
2491
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2492
        if ($this->orientacao == 'P') {
2493
            $w = $this->wPrint;
2494
        } else {
2495
            if ($nInicio < 2) { // primeira página
2496
                $w = $this->wPrint - $this->wCanhoto;
2497
            } else { // páginas seguintes
2498
                $w = $this->wPrint;
2499
            }
2500
        }
2501
        $h = 4;
2502
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2503
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2504
        $y += 3;
2505
        //desenha a caixa dos dados dos itens da NF
2506
        $hmax += 1;
2507
        $texto = '';
0 ignored issues
show
Unused Code introduced by
$texto is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2508
        $this->pdf->textBox($x, $y, $w, $hmax);
2509
        //##################################################################################
2510
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2511
        //CÓDIGO PRODUTO
2512
        $texto = "CÓDIGO PRODUTO";
2513
        $w1 = round($w*0.09, 0);
2514
        $h = 4;
2515
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2516
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2517
        $this->pdf->line($x+$w1, $y, $x+$w1, $y+$hmax);
2518
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2519
        $x += $w1;
2520
        $w2 = round($w*0.28, 0);
2521
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2522
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2523
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2524
        $this->pdf->line($x+$w2, $y, $x+$w2, $y+$hmax);
2525
        //NCM/SH
2526
        $x += $w2;
2527
        $w3 = round($w*0.06, 0);
2528
        $texto = 'NCM/SH';
2529
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2530
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2531
        $this->pdf->line($x+$w3, $y, $x+$w3, $y+$hmax);
2532
        //O/CST ou O/CSOSN
2533
        $x += $w3;
2534
        $w4 = round($w*0.05, 0);
2535
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2536
        if ($this->getTagValue($this->emit, 'CRT') == '3') {
2537
             $texto = 'O/CST';//Regime Normal
2538
        }
2539
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2540
        $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2541
        $this->pdf->line($x+$w4, $y, $x+$w4, $y+$hmax);
2542
        //CFOP
2543
        $x += $w4;
2544
        $w5 = round($w*0.04, 0);
2545
        $texto = 'CFOP';
2546
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2547
        $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2548
        $this->pdf->line($x+$w5, $y, $x+$w5, $y+$hmax);
2549
        //UN
2550
        $x += $w5;
2551
        $w6 = round($w*0.03, 0);
2552
        $texto = 'UN';
2553
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2554
        $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2555
        $this->pdf->line($x+$w6, $y, $x+$w6, $y+$hmax);
2556
        //QUANT
2557
        $x += $w6;
2558
        $w7 = round($w*0.07, 0);
2559
        $texto = 'QUANT';
2560
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2561
        $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2562
        $this->pdf->line($x+$w7, $y, $x+$w7, $y+$hmax);
2563
        //VALOR UNIT
2564
        $x += $w7;
2565
        $w8 = round($w*0.06, 0);
2566
        $texto = 'VALOR UNIT';
2567
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2568
        $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2569
        $this->pdf->line($x+$w8, $y, $x+$w8, $y+$hmax);
2570
        //VALOR TOTAL
2571
        $x += $w8;
2572
        $w9 = round($w*0.06, 0);
2573
        $texto = 'VALOR TOTAL';
2574
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2575
        $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2576
        $this->pdf->line($x+$w9, $y, $x+$w9, $y+$hmax);
2577
        //B.CÁLC ICMS
2578
        $x += $w9;
2579
        $w10 = round($w*0.06, 0);
2580
        $texto = 'B.CÁLC ICMS';
2581
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2582
        $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2583
        $this->pdf->line($x+$w10, $y, $x+$w10, $y+$hmax);
2584
        //VALOR ICMS
2585
        $x += $w10;
2586
        $w11 = round($w*0.06, 0);
2587
        $texto = 'VALOR ICMS';
2588
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2589
        $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2590
        $this->pdf->line($x+$w11, $y, $x+$w11, $y+$hmax);
2591
        //VALOR IPI
2592
        $x += $w11;
2593
        $w12 = round($w*0.05, 0);
2594
        $texto = 'VALOR IPI';
2595
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2596
        $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2597
        $this->pdf->line($x+$w12, $y, $x+$w12, $y+$hmax);
2598
        //ALÍQ. ICMS
2599
        $x += $w12;
2600
        $w13 = round($w*0.035, 0);
2601
        $texto = 'ALÍQ. ICMS';
2602
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2603
        $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2604
        $this->pdf->line($x+$w13, $y, $x+$w13, $y+$hmax);
2605
        //ALÍQ. IPI
2606
        $x += $w13;
2607
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2608
        $texto = 'ALÍQ. IPI';
2609
        $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2610
        $this->pdf->line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2611
        $y += 5;
2612
        //##################################################################################
2613
        // LOOP COM OS DADOS DOS PRODUTOS
2614
        $i = 0;
2615
        $hUsado = $hCabecItens;
2616
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2617
        foreach ($this->det as $d) {
2618
            if ($i >= $nInicio) {
2619
                $thisItem = $this->det->item($i);
2620
                //carrega as tags do item
2621
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2622
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2623
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2624
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2625
                $textoProduto = trim($this->descricaoProduto($thisItem));
2626
2627
                $linhaDescr = $this->pdf->getNumLines($textoProduto, $w2, $aFont);
2628
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2629
                $hUsado += $h;
2630
2631
                $diffH = $hmax - $hUsado;
2632
2633
                if ($pag != $totpag) {
2634
                    if (1 > $diffH && $i < $totItens) {
2635
                        //ultrapassa a capacidade para uma única página
2636
                        //o restante dos dados serão usados nas proximas paginas
2637
                        $nInicio = $i;
2638
                        break;
2639
                    }
2640
                }
2641
                $y_linha=$y+$h;
2642
                // linha entre itens
2643
                $this->pdf->dashedHLine($oldX, $y_linha, $w, 0.1, 120);
2644
                //corrige o x
2645
                $x=$oldX;
2646
                //codigo do produto
2647
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2648
                $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2649
                $x += $w1;
2650
                //DESCRIÇÃO
2651
                if ($this->orientacao == 'P') {
2652
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2653
                } else {
2654
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2655
                }
2656
                $x += $w2;
2657
                //NCM
2658
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2659
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2660
                $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2661
                $x += $w3;
2662
                //CST
2663
                if (isset($ICMS)) {
2664
                    $origem =  $this->getTagValue($ICMS, "orig");
2665
                    $cst =  $this->getTagValue($ICMS, "CST");
2666
                    $csosn =  $this->getTagValue($ICMS, "CSOSN");
2667
                    $texto = $origem.$cst.$csosn;
2668
                    $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2669
                }
2670
                //CFOP
2671
                $x += $w4;
2672
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2673
                $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2674
                //Unidade
2675
                $x += $w5;
2676
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2677
                $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2678
                $x += $w6;
2679
                if ($this->orientacao == 'P') {
2680
                    $alinhamento = 'R';
2681
                } else {
2682
                    $alinhamento = 'R';
2683
                }
2684
                // QTDADE
2685
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2686
                $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2687
                $x += $w7;
2688
                // Valor Unitário
2689
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2690
                $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2691
                $x += $w8;
2692
                // Valor do Produto
2693
                $texto = "";
2694
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2695
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2696
                }
2697
                $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2698
                //Valor da Base de calculo
2699
                $x += $w9;
2700
                if (isset($ICMS)) {
2701
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2702
                            number_format(
2703
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2704
                                2,
2705
                                ",",
2706
                                "."
2707
                            ) : '0, 00';
2708
                    $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2709
                }
2710
                //Valor do ICMS
2711
                $x += $w10;
2712
                if (isset($ICMS)) {
2713
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2714
                            number_format(
2715
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2716
                                2,
2717
                                ",",
2718
                                "."
2719
                            ) : '0, 00';
2720
                    $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2721
                }
2722
                //Valor do IPI
2723
                $x += $w11;
2724
                if (isset($IPI)) {
2725
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2726
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2727
                } else {
2728
                    $texto = '';
2729
                }
2730
                $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2731
                // %ICMS
2732
                $x += $w12;
2733
                if (isset($ICMS)) {
2734
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2735
                            number_format(
2736
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2737
                                2,
2738
                                ",",
2739
                                "."
2740
                            ) : '0, 00';
2741
                    $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2742
                }
2743
                //%IPI
2744
                $x += $w13;
2745
                if (isset($IPI)) {
2746
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2747
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2748
                } else {
2749
                    $texto = '';
2750
                }
2751
                $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2752
2753
2754
                // Dados do Veiculo Somente para veiculo 0 Km
2755
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2756
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2757
                // Verifica se a Tag existe
2758
                if (!empty($veicProd)) {
2759
                    $this->dadosItenVeiculoDANFE($oldX, $y, $nInicio, $h, $prod);
2760
                }
2761
2762
2763
                $y += $h;
2764
                $i++;
2765
                //incrementa o controle dos itens processados.
2766
                $this->qtdeItensProc++;
2767
            } else {
2768
                $i++;
2769
            }
2770
        }
2771
        return $oldY+$hmax;
2772
    }
2773
2774
2775
    /**
2776
     * dadosItenVeiculoDANFE
2777
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2778
     *
2779
     * @param float  $x    Posição horizontal
2780
     *                     canto esquerdo
2781
     * @param float  $y    Posição vertical
2782
     *                     canto superior
2783
     * @param        $nInicio
2784
     * @param float  $h    altura do campo
2785
     * @param object $prod Contendo todos os dados do item
2786
     */
2787
2788
    protected function dadosItenVeiculoDANFE($x, $y, &$nInicio, $h, $prod)
2789
    {
2790
        $oldX = $x;
2791
        $oldY = $y;
0 ignored issues
show
Unused Code introduced by
$oldY is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2792
2793
        if ($this->orientacao == 'P') {
2794
            $w = $this->wPrint;
2795
        } else {
2796
            if ($nInicio < 2) { // primeira página
2797
                $w = $this->wPrint - $this->wCanhoto;
2798
            } else { // páginas seguintes
2799
                $w = $this->wPrint;
2800
            }
2801
        }
2802
2803
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2804
2805
        $w1 = round($w*0.09, 0);
2806
2807
        // Tabela Renavam Combustivel
2808
        $renavamCombustivel = [
2809
            1=>'ALCOOL',
2810
            2=>'GASOLINA',
2811
            3=>'DIESEL',
2812
            4=>'GASOGENIO',
2813
            5=>'GAS METANO',
2814
            6=>'ELETRICO/FONTE INTERNA',
2815
            7=>'ELETRICO/FONTE EXTERNA',
2816
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
2817
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
2818
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
2819
            11=>'VIDE/CAMPO/OBSERVACAO',
2820
            12=>'ALCOOL/GAS NATURAL VEICULAR',
2821
            13=>'GASOLINA/GAS NATURAL VEICULAR',
2822
            14=>'DIESEL/GAS NATURAL VEICULAR',
2823
            15=>'GAS NATURAL VEICULAR',
2824
            16=>'ALCOOL/GASOLINA',
2825
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
2826
            18=>'GASOLINA/ELETRICO'
2827
        ];
2828
2829
        $renavamEspecie = [
2830
            1=>'PASSAGEIRO',
2831
            2=>'CARGA',
2832
            3=>'MISTO',
2833
            4=>'CORRIDA',
2834
            5=>'TRACAO',
2835
            6=>'ESPECIAL',
2836
            7=>'COLECAO'
2837
        ];
2838
2839
        $renavamTiposVeiculos = [
2840
            1=>'BICICLETA',
2841
            2=>'CICLOMOTOR',
2842
            3=>'MOTONETA',
2843
            4=>'MOTOCICLETA',
2844
            5=>'TRICICLO',
2845
            6=>'AUTOMOVEL',
2846
            7=>'MICROONIBUS',
2847
            8=>'ONIBUS',
2848
            9=>'BONDE',
2849
            10=>'REBOQUE',
2850
            11=>'SEMI-REBOQUE',
2851
            12=>'CHARRETE',
2852
            13=>'CAMIONETA',
2853
            14=>'CAMINHAO',
2854
            15=>'CARROCA',
2855
            16=>'CARRO DE MAO',
2856
            17=>'CAMINHAO TRATOR',
2857
            18=>'TRATOR DE RODAS',
2858
            19=>'TRATOR DE ESTEIRAS',
2859
            20=>'TRATOR MISTO',
2860
            21=>'QUADRICICLO',
2861
            22=>'CHASSI/PLATAFORMA',
2862
            23=>'CAMINHONETE',
2863
            24=>'SIDE-CAR',
2864
            25=>'UTILITARIO',
2865
            26=>'MOTOR-CASA'
2866
        ];
2867
2868
        $renavamTipoPintura = [
0 ignored issues
show
Unused Code introduced by
$renavamTipoPintura is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2869
            'F'=>'FOSCA',
2870
            'S'=>'SÓLIDA',
2871
            'P'=>'PEROLIZADA',
2872
            'M'=>'METALICA',
2873
        ];
2874
2875
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2876
2877
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
2878
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
2879
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
2880
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
2881
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
2882
2883
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
2884
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
2885
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
2886
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
2887
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2888
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2889
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2890
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2891
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2892
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2893
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2894
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2895
2896
        $x = $oldX;
2897
2898
        $yVeic = $y + $h;
2899
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2900
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2901
        $yVeic += $h;
2902
        $texto = 'Cor...................: ' . $veiculoCor;
2903
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2904
        $yVeic += $h;
2905
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2906
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2907
        $yVeic += $h;
2908
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2909
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2910
        $yVeic += $h;
2911
        $texto = 'Tipo.................: ' . ($renavamTiposVeiculos[intval($veiculoTipo)] ?? $veiculoTipo);
2912
         $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2913
        $yVeic = $y + $h;
2914
        $xVeic = $x + 65;
2915
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2916
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2917
        $yVeic += $h;
2918
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2919
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2920
        $yVeic += $h;
2921
        $texto = 'HP.....................: ' . $veiculoHp;
2922
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2923
        $yVeic += $h;
2924
        $texto = 'Placa.................: ' . $veiculoPlaca;
2925
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2926
        $yVeic += $h;
2927
        $texto = 'Tipo Pintura......: ' . ($renavamEspecie[intval($veiculoTipoPintura)] ?? $veiculoTipoPintura);
2928
        $this->pTextBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
0 ignored issues
show
Bug introduced by
The method pTextBox() does not seem to exist on object<NFePHP\DA\NFe\Danfe>.

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...
2929
        $yVeic = $y + $h;
2930
        $xVeic = $xVeic + 55;
2931
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2932
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2933
        $yVeic += $h;
2934
        $texto = 'Especie..................: ' . ($renavamEspecie[intval($veiculoEspecie)] ?? $veiculoEspecie);
2935
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2936
        $yVeic += $h;
2937
        $texto = 'Combustivel..........: ' . ($renavamCombustivel[intval($veiculoCombustivel)] ?? $veiculoCombustivel);
2938
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2939
        $yVeic += $h;
2940
        $texto = 'Serial.....................: ' . $veiculoSerial;
2941
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2942
        $yVeic += $h;
2943
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2944
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2945
        $yVeic += $h;
2946
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2947
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2948
    }
2949
2950
    /**
2951
     * issqnDANFE
2952
     * Monta o campo de serviços do DANFE
2953
     *
2954
     * @name   issqnDANFE (retrato e paisagem)
2955
     * @param  float $x Posição horizontal canto esquerdo
2956
     * @param  float $y Posição vertical canto superior
2957
     * @return float Posição vertical final
2958
     */
2959
    protected function issqnDANFE($x, $y)
2960
    {
2961
        $oldX = $x;
0 ignored issues
show
Unused Code introduced by
$oldX is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2962
        //#####################################################################
2963
        //CÁLCULO DO ISSQN
2964
        $texto = "CÁLCULO DO ISSQN";
2965
        $w = $this->wPrint;
2966
        $h = 7;
2967
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2968
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2969
        //INSCRIÇÃO MUNICIPAL
2970
        $y += 3;
2971
        $w = round($this->wPrint*0.23, 0);
2972
        $texto = 'INSCRIÇÃO MUNICIPAL';
2973
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2974
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2975
        //inscrição municipal
2976
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2977
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2978
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2979
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2980
        //VALOR TOTAL DOS SERVIÇOS
2981
        $x += $w;
2982
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2983
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2984
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2985
        if (isset($this->ISSQNtot)) {
2986
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2987
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2988
            $texto = number_format($texto, 2, ",", ".");
2989
        } else {
2990
            $texto = '';
2991
        }
2992
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2993
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2994
        //BASE DE CÁLCULO DO ISSQN
2995
        $x += $w;
2996
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2997
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2998
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2999
        if (isset($this->ISSQNtot)) {
3000
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
3001
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
3002
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3003
        } else {
3004
            $texto = '';
3005
        }
3006
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3007
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3008
        //VALOR TOTAL DO ISSQN
3009
        $x += $w;
3010
        if ($this->orientacao == 'P') {
3011
            $w = $this->wPrint - (3 * $w);
3012
        } else {
3013
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
3014
        }
3015
        $texto = 'VALOR TOTAL DO ISSQN';
3016
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3017
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3018
        if (isset($this->ISSQNtot)) {
3019
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
3020
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
3021
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3022
        } else {
3023
            $texto = '';
3024
        }
3025
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3026
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3027
        return ($y+$h+1);
3028
    }
3029
3030
    /**
3031
     *dadosAdicionaisDANFE
3032
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
3033
     *
3034
     * @name   dadosAdicionaisDANFE
3035
     * @param  float $x Posição horizontal canto esquerdo
3036
     * @param  float $y Posição vertical canto superior
3037
     * @param  float $h altura do campo
3038
     * @return float Posição vertical final (eixo Y)
3039
     */
3040
    protected function dadosAdicionaisDANFE($x, $y, $h)
3041
    {
3042
        //##################################################################################
3043
        //DADOS ADICIONAIS
3044
        $texto = "DADOS ADICIONAIS";
3045
        if ($this->orientacao == 'P') {
3046
              $w = $this->wPrint;
3047
        } else {
3048
              $w = $this->wPrint-$this->wCanhoto;
3049
        }
3050
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
3051
        $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
3052
        //INFORMAÇÕES COMPLEMENTARES
3053
        $texto = "INFORMAÇÕES COMPLEMENTARES";
3054
        $y += 3;
3055
        $w = $this->wAdic;
3056
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3057
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3058
        //o texto com os dados adicionais foi obtido na função montaDANFE
3059
        //e carregado em uma propriedade privada da classe
3060
        //$this->wAdic com a largura do campo
3061
        //$this->textoAdic com o texto completo do campo
3062
        $y += 1;
3063
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3064
        $this->pdf->textBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3065
        //RESERVADO AO FISCO
3066
        $texto = "RESERVADO AO FISCO";
3067
        $x += $w;
3068
        $y -= 1;
3069
        if ($this->orientacao == 'P') {
3070
            $w = $this->wPrint-$w;
3071
        } else {
3072
            $w = $this->wPrint-$w-$this->wCanhoto;
3073
        }
3074
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3075
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3076
        //inserir texto informando caso de contingência
3077
        // 1 - Normal - emissão normal;
3078
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3079
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3080
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3081
        //     Prévia de Emissão em Contingência;
3082
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3083
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3084
        // 6 - Contingência SVC-AN
3085
        // 7 - Contingência SVC-RS
3086
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
3087
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3088
        $texto = '';
3089
        switch ($this->tpEmis) {
3090
            case 2:
3091
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3092
                break;
3093
            case 3:
3094
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3095
                break;
3096
            case 4:
3097
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3098
                break;
3099
            case 5:
3100
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3101
                break;
3102
            case 6:
3103
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3104
                break;
3105
            case 7:
3106
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3107
                break;
3108
        }
3109
        $y += 2;
3110
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3111
        $this->pdf->textBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3112
        return $y+$h;
3113
    }
3114
3115
    /**
3116
     * rodape
3117
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3118
     * sobre a API NfePHP
3119
     *
3120
     * @name   rodape
3121
     * @param  float $xInic  Posição horizontal canto esquerdo
0 ignored issues
show
Bug introduced by
There is no parameter named $xInic. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
3122
     * @param  float $yFinal Posição vertical final para impressão
0 ignored issues
show
Bug introduced by
There is no parameter named $yFinal. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
3123
     * @return void
3124
     */
3125
    protected function rodape($x, $y)
3126
    {
3127
        if ($this->orientacao == 'P') {
3128
              $w = $this->wPrint;
3129
        } else {
3130
              $w = $this->wPrint-$this->wCanhoto;
3131
              $x = $this->wCanhoto;
3132
        }
3133
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
3134
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
3135
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
3136
        $texto = $this->creditos .  "  Powered by NFePHP®";
3137
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
3138
    }
3139
3140
    /**
3141
     * pCcanhotoDANFE
3142
     * Monta o canhoto da DANFE (retrato e paisagem)
3143
     *
3144
     * @name   canhotoDANFE
3145
     * @param  number $x Posição horizontal canto esquerdo
3146
     * @param  number $y Posição vertical canto superior
3147
     * @return number Posição vertical final
3148
     *
3149
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3150
     */
3151
    protected function canhoto($x, $y)
3152
    {
3153
        $oldX = $x;
3154
        $oldY = $y;
3155
        //#################################################################################
3156
        //canhoto
3157
        //identificação do tipo de nf entrada ou saida
3158
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3159
        if ($tpNF == '0') {
3160
            //NFe de Entrada
3161
            $emitente = '';
3162
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3163
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3164
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3165
            $emitente .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3166
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3167
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3168
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3169
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3170
        } else {
3171
            //NFe de Saída
3172
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3173
            $destinatario = '';
3174
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3175
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3176
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3177
            $destinatario .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3178
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3179
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3180
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3181
        }
3182
        //identificação do sistema emissor
3183
        //linha separadora do canhoto
3184
        if ($this->orientacao == 'P') {
3185
            $w = round($this->wPrint * 0.81, 0);
3186
        } else {
3187
            //linha separadora do canhoto - 238
3188
            //posicao altura
3189
            $y = $this->wPrint-85;
3190
            //altura
3191
            $w = $this->wPrint-85-24;
3192
        }
3193
        $h = 10;
3194
        //desenha caixa
3195
        $texto = '';
3196
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3197
        $aFontSmall = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3198
        if ($this->orientacao == 'P') {
3199
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3200
        } else {
3201
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3202
        }
3203
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3204
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3205
        $texto = "RECEBEMOS DE ";
3206
        $texto .= $emitente;
3207
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3208
        if ($this->orientacao == 'P') {
3209
            $texto .= "ABAIXO";
3210
        } else {
3211
            $texto .= "AO LADO";
3212
        }
3213
        $texto .= ". EMISSÃO: ";
3214
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3215
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3216
        if ($dEmi == '') {
3217
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3218
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3219
            $aDemi = explode('T', $dEmi);
3220
            $dEmi = $aDemi[0];
3221
        }
3222
        $texto .= $this->ymdTodmy($dEmi) ." ";
3223
        $texto .= "VALOR TOTAL: R$ ";
3224
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3225
        $texto .= "DESTINATÁRIO: ";
3226
        $texto .= $destinatario;
3227
        if ($this->orientacao == 'P') {
3228
            $this->pdf->textBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3229
            $x1 = $x + $w;
3230
            $w1 = $this->wPrint - $w;
3231
            $texto = "NF-e";
3232
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3233
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3234
            $texto = "Nº. " . $this->formatField($numNF, "###.###.###") . " \n";
3235
            $texto .= "Série $serie";
3236
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3237
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3238
            //DATA DE RECEBIMENTO
3239
            $texto = "DATA DE RECEBIMENTO";
3240
            $y += $h;
3241
            $w2 = round($this->wPrint*0.17, 0); //35;
3242
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3243
            $this->pdf->textBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3244
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3245
            $x += $w2;
3246
            $w3 = $w-$w2;
3247
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3248
            $this->pdf->textBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3249
            $x = $oldX;
3250
            $y += 9;
3251
            $this->pdf->dashedHLine($x, $y, $this->wPrint, 0.1, 80);
3252
            $y += 2;
3253
            return $y;
3254
        } else {
3255
            $x--;
3256
            $x = $this->pdf->textBox90($x, $y, $w-1, $h, $texto, $aFontSmall, 'C', 'L', 0, '', false);
0 ignored issues
show
Unused Code introduced by
$x is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3257
            //NUMERO DA NOTA FISCAL LOGO NFE
3258
            $w1 = 18;
3259
            $x1 = $oldX;
3260
            $y = $oldY;
3261
            $texto = "NF-e";
3262
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3263
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3264
            $texto = "Nº.\n" . $this->formatField($numNF, "###.###.###") . " \n";
3265
            $texto .= "Série $serie";
3266
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
3267
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3268
            //DATA DO RECEBIMENTO
3269
            $texto = "DATA DO RECEBIMENTO";
3270
            $y = $this->wPrint-85;
3271
            $x = 12;
3272
            $w2 = round($this->wPrint*0.17, 0); //35;
3273
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3274
            $this->pdf->textBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3275
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3276
            $y -= $w2;
3277
            $w3 = $w-$w2;
3278
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3279
            $aFont = ['font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''];
3280
            $x = $this->pdf->textBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3281
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3282
            return $x;
3283
        }
3284
    }
3285
3286
    /**
3287
     * geraInformacoesDaTagCompra
3288
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3289
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3290
     *
3291
     * @name   pGeraInformacoesDaTagCompra
3292
     * @return string com as informacoes dos pedidos.
3293
     */
3294
    protected function geraInformacoesDaTagCompra()
3295
    {
3296
        $saida = "";
3297
        if (isset($this->compra)) {
3298
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3299
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3300
            }
3301
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3302
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3303
            }
3304
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3305
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3306
            }
3307
        }
3308
        return $saida;
3309
    }
3310
3311
    /**
3312
     * geraChaveAdicionalDeContingencia
3313
     *
3314
     * @name   geraChaveAdicionalDeContingencia
3315
     * @return string chave
3316
     */
3317
    protected function geraChaveAdicionalDeContingencia()
3318
    {
3319
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3320
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
3321
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3322
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3323
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3324
        $CNPJ   = substr($CNPJ, -14);
3325
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3326
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3327
        if ($vICMS > 0) {
3328
            $vICMS = 1;
3329
        }
3330
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3331
        if ($icmss > 0) {
3332
            $icmss = 1;
3333
        }
3334
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3335
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3336
        if ($dEmi == '') {
3337
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3338
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3339
            $aDemi = explode('T', $dEmi);
3340
            $dEmi = $aDemi[0];
3341
        }
3342
        $dd  = $dEmi;
3343
        $rpos = strrpos($dd, '-');
3344
        $dd  = substr($dd, $rpos +1);
3345
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3346
        $chave = $chave . $this->modulo11($chave);
3347
        return $chave;
3348
    }
3349
3350
    /**
3351
     *  geraInformacoesDasNotasReferenciadas
3352
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3353
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3354
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3355
     *
3356
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3357
     */
3358
    protected function geraInformacoesDasNotasReferenciadas()
3359
    {
3360
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3361
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3362
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3363
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3364
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3365
        $saida='';
3366
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3367
        if (0 === $nfRefs->length) {
3368
            return $saida;
3369
        }
3370
        if ($nfRefs->length > 2) {
3371
            return 'Existem mais de 2 NF/NFe/ECF/NFP/CTe referenciadas, não serão exibidas na DANFE.';
3372
        }
3373
        foreach ($nfRefs as $nfRef) {
3374
            if (empty($nfRef)) {
3375
                continue;
3376
            }
3377
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3378
            foreach ($refNFe as $chave_acessoRef) {
3379
                $chave_acesso = $chave_acessoRef->nodeValue;
3380
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3381
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3382
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3383
                $serie  = substr($chave_acesso, 22, 3);
3384
                $numero = substr($chave_acesso, 25, 9);
3385
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3386
            }
3387
            $refNF = $nfRef->getElementsByTagName('refNF');
3388
            foreach ($refNF as $umaRefNFe) {
3389
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3390
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3391
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3392
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3393
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3394
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3395
                $cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3396
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3397
            }
3398
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3399
            foreach ($refCTe as $chave_acessoRef) {
3400
                $chave_acesso = $chave_acessoRef->nodeValue;
3401
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3402
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3403
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3404
                $serie  = substr($chave_acesso, 22, 3);
3405
                $numero = substr($chave_acesso, 25, 9);
3406
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3407
            }
3408
            $refECF = $nfRef->getElementsByTagName('refECF');
3409
            foreach ($refECF as $umaRefNFe) {
3410
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3411
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3412
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3413
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3414
            }
3415
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3416
            foreach ($refNFP as $umaRefNFe) {
3417
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3418
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3419
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3420
                    '';
3421
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3422
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3423
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3424
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3425
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3426
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3427
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3428
                if ($cnpj == '') {
3429
                    $cpf_cnpj = $this->formatField($cpf, "###.###.###-##");
3430
                } else {
3431
                    $cpf_cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3432
                }
3433
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3434
            }
3435
        }
3436
        return $saida;
3437
    }
3438
    
3439
    private function imagePNGtoJPG($original)
3440
    {
3441
        $image = imagecreatefrompng($original);
3442
        ob_start();
3443
        imagejpeg($image, null, 100);
3444
        imagedestroy($image);
3445
        $stringdata = ob_get_contents(); // read from buffer
3446
        ob_end_clean();
3447
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3448
    }
3449
}
3450