Completed
Push — master ( 5bdcba...189d26 )
by Roberto
04:56 queued 02:29
created

Danfe::pSizeExtraTextoFatura()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 12
rs 9.9666
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->pAnfavea($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->pSizeExtraTextoFatura());
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
        $i = 1;
679
        $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...
680
        $hUsado = $hCabecItens;
681
        $w2 = round($w*0.28, 0);
682
        $hDispo = $hDispo1;
683
        $totPag = 1;
684
        while ($i < $this->det->length) {
685
            $texto = $this->pDescricaoProduto($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->pCanhoto($x, $y);
707
            }
708
        } else {
709
            for ($i = 1; $i <= $this->qCanhoto; $i++) {
710
                $this->pCanhoto($x, $y);
711
                $x = 25 * $i;
712
            }
713
        }
714
        //coloca o cabeçalho
715
        $y = $this->pCabecalhoDANFE($x, $y, $pag, $totPag);
716
        //coloca os dados do destinatário
717
        $y = $this->pDestinatarioDANFE($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->pFaturaDANFE($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->pImpostoDANFE($x, $y+1);
744
        //coloca os dados do trasnporte
745
        $y = $this->pTransporteDANFE($x, $y+1);
746
        //itens da DANFE
747
        $nInicial = 0;
748
749
        $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo1, $pag, $totPag, $hCabecItens);
750
751
        //coloca os dados do ISSQN
752
        if ($linhaISSQN == 1) {
753
            $y = $this->pIssqnDANFE($x, $y+4);
754
        } else {
755
            $y += 4;
756
        }
757
        //coloca os dados adicionais da NFe
758
        $y = $this->pDadosAdicionaisDANFE($x, $y, $hdadosadic);
759
        //coloca o rodapé da página
760
        if ($this->orientacao == 'P') {
761
            $this->pRodape($xInic, $y-1);
762
        } else {
763
            $this->pRodape($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->pCabecalhoDANFE($x, $y, $n, $totPag);
781
            //coloca os itens na página adicional
782
            $y = $this->pItensDANFE($x, $y+1, $nInicial, $hDispo2, $n, $totPag, $hCabecItens);
783
            //coloca o rodapé da página
784
            if ($this->orientacao == 'P') {
785
                $this->pRodape($xInic, $y + 4);
786
            } else {
787
                $this->pRodape($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 pAnfavea($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 pNotaCancelada()
964
    {
965
        if (!isset($this->nfeProc)) {
966
            return false;
967
        }
968
        $cStat = $this->getTagValue($this->nfeProc, "cStat");
969
        return $cStat == '101' ||
970
                $cStat == '151' ||
971
                $cStat == '135' ||
972
                $cStat == '155' ||
973
                $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...
974
    }
975
976
    protected function pNotaDPEC()
977
    {
978
        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...
979
    }
980
981
    protected function pNotaDenegada()
982
    {
983
        if (!isset($this->nfeProc)) {
984
            return false;
985
        }
986
        //NÃO ERA NECESSÁRIO ESSA FUNÇÃO POIS SÓ SE USA
987
        //1 VEZ NO ARQUIVO INTEIRO
988
        $cStat = $this->getTagValue($this->nfeProc, "cStat");
989
        return $cStat == '110' ||
990
               $cStat == '301' ||
991
               $cStat == '302' ||
992
               $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...
993
    }
994
995
    /**
996
     *cabecalhoDANFE
997
     * Monta o cabelhalho da DANFE (retrato e paisagem)
998
     *
999
     * @param  number $x      Posição horizontal inicial, canto esquerdo
1000
     * @param  number $y      Posição vertical inicial, canto superior
1001
     * @param  number $pag    Número da Página
1002
     * @param  number $totPag Total de páginas
1003
     * @return number Posição vertical final
1004
     */
1005
    protected function pCabecalhoDANFE($x = 0, $y = 0, $pag = '1', $totPag = '1')
1006
    {
1007
        $oldX = $x;
1008
        $oldY = $y;
1009
        if ($this->orientacao == 'P') {
1010
              $maxW = $this->wPrint;
1011
        } else {
1012
            if ($pag == 1) { // primeira página
1013
                $maxW = $this->wPrint - $this->wCanhoto;
1014
            } else { // páginas seguintes
1015
                $maxW = $this->wPrint;
1016
            }
1017
        }
1018
        //####################################################################################
1019
        //coluna esquerda identificação do emitente
1020
        $w = round($maxW*0.41, 0);
1021
        if ($this->orientacao == 'P') {
1022
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
1023
        } else {
1024
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1025
        }
1026
        $w1 = $w;
1027
        $h=32;
1028
        $oldY += $h;
1029
        $this->pdf->textBox($x, $y, $w, $h);
1030
        $texto = 'IDENTIFICAÇÃO DO EMITENTE';
1031
        $this->pdf->textBox($x, $y, $w, 5, $texto, $aFont, 'T', 'C', 0, '');
1032
        //estabelecer o alinhamento
1033
        //pode ser left L, center C, right R, full logo L
1034
        //se for left separar 1/3 da largura para o tamanho da imagem
1035
        //os outros 2/3 serão usados para os dados do emitente
1036
        //se for center separar 1/2 da altura para o logo e 1/2 para os dados
1037
        //se for right separa 2/3 para os dados e o terço seguinte para o logo
1038
        //se não houver logo centraliza dos dados do emitente
1039
        // coloca o logo
1040
        if (!empty($this->logomarca)) {
1041
            $logoInfo = getimagesize($this->logomarca);
1042
            $type = strtolower(explode('/', $logoInfo['mime'])[1]);
1043
            if ($type == 'png') {
1044
                $this->logomarca = $this->imagePNGtoJPG($this->logomarca);
1045
                $type == 'jpg';
1046
            }
1047
            //largura da imagem em mm
1048
            $logoWmm = ($logoInfo[0]/72)*25.4;
1049
            //altura da imagem em mm
1050
            $logoHmm = ($logoInfo[1]/72)*25.4;
1051
            if ($this->logoAlign=='L') {
1052
                $nImgW = round($w/3, 0);
1053
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1054
                $xImg = $x+1;
1055
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1056
                //estabelecer posições do texto
1057
                $x1 = round($xImg + $nImgW +1, 0);
1058
                $y1 = round($h/3+$y, 0);
1059
                $tw = round(2*$w/3, 0);
1060
            } elseif ($this->logoAlign=='C') {
1061
                $nImgH = round($h/3, 0);
1062
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1063
                $xImg = round(($w-$nImgW)/2+$x, 0);
1064
                $yImg = $y+3;
1065
                $x1 = $x;
1066
                $y1 = round($yImg + $nImgH + 1, 0);
1067
                $tw = $w;
1068
            } elseif ($this->logoAlign=='R') {
1069
                $nImgW = round($w/3, 0);
1070
                $nImgH = round($logoHmm * ($nImgW/$logoWmm), 0);
1071
                $xImg = round($x+($w-(1+$nImgW)), 0);
1072
                $yImg = round(($h-$nImgH)/2, 0)+$y;
1073
                $x1 = $x;
1074
                $y1 = round($h/3+$y, 0);
1075
                $tw = round(2*$w/3, 0);
1076
            } elseif ($this->logoAlign=='F') {
1077
                $nImgH = round($h-5, 0);
1078
                $nImgW = round($logoWmm * ($nImgH/$logoHmm), 0);
1079
                $xImg = round(($w-$nImgW)/2+$x, 0);
1080
                $yImg = $y+3;
1081
                $x1 = $x;
1082
                $y1 = round($yImg + $nImgH + 1, 0);
1083
                $tw = $w;
1084
            }
1085
            $type = (substr($this->logomarca, 0, 7) === 'data://') ? 'jpg' : null;
1086
            $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...
1087
        } else {
1088
            $x1 = $x;
1089
            $y1 = round($h/3+$y, 0);
1090
            $tw = $w;
1091
        }
1092
        // monta as informações apenas se diferente de full logo
1093
        if ($this->logoAlign !== 'F') {
1094
            //Nome emitente
1095
            $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1096
            $texto = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue;
1097
            $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...
1098
            //endereço
1099
            $y1 = $y1+5;
1100
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1101
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1102
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1103
                 : '';
1104
            $lgr = $this->getTagValue($this->enderEmit, "xLgr");
1105
            $nro = $this->getTagValue($this->enderEmit, "nro");
1106
            $cpl = $this->getTagValue($this->enderEmit, "xCpl", " - ");
1107
            $bairro = $this->getTagValue($this->enderEmit, "xBairro");
1108
            $CEP = $this->getTagValue($this->enderEmit, "CEP");
1109
            $CEP = $this->pFormat($CEP, "#####-###");
1110
            $mun = $this->getTagValue($this->enderEmit, "xMun");
1111
            $UF = $this->getTagValue($this->enderEmit, "UF");
1112
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1113
                    . $CEP . "\n" . $mun . " - " . $UF . " "
1114
                    . "Fone/Fax: " . $fone;
1115
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1116
        }
1117
1118
        //####################################################################################
1119
        //coluna central Danfe
1120
        $x += $w;
1121
        $w=round($maxW * 0.17, 0);//35;
1122
        $w2 = $w;
1123
        $h = 32;
1124
        $this->pdf->textBox($x, $y, $w, $h);
1125
1126
        if (! $this->pNotaCancelada()) {
1127
            // A PRINCIPIO NÃO PRECISAVA, POIS A NFE ESTÁ AUTORIZADA,
1128
            // SÓ SE RETIRA O DANFE PARA NOTAS NÃO AUTORIZADAS
1129
            $texto = "DANFE";
1130
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
1131
            $this->pdf->textBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1132
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1133
            $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1134
            $h = 20;
1135
            $this->pdf->textBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1136
        }
1137
1138
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1139
        $texto = '0 - ENTRADA';
1140
        $y1 = $y + 14;
1141
        $h = 8;
1142
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1143
        $texto = '1 - SAÍDA';
1144
        $y1 = $y + 17;
1145
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1146
        //tipo de nF
1147
        $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1148
        $y1 = $y + 13;
1149
        $h = 7;
1150
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1151
        $this->pdf->textBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1152
        //numero da NF
1153
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1154
        $y1 = $y + 20;
1155
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1156
        $numNF = $this->pFormat($numNF, "###.###.###");
1157
        $texto = "Nº. " . $numNF;
1158
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1159
        //Série
1160
        $y1 = $y + 23;
1161
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1162
        $texto = "Série " . $serie;
1163
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1164
        //numero paginas
1165
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I'];
1166
        $y1 = $y + 26;
1167
        $texto = "Folha " . $pag . "/" . $totPag;
1168
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1169
1170
        //####################################################################################
1171
        //coluna codigo de barras
1172
        $x += $w;
1173
        $w = ($maxW-$w1-$w2);//85;
1174
        $w3 = $w;
1175
        $h = 32;
1176
        $this->pdf->textBox($x, $y, $w, $h);
1177
        $this->pdf->SetFillColor(0, 0, 0);
1178
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1179
        $bW = 75;
1180
        $bH = 12;
1181
        //codigo de barras
1182
        $this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1183
        //linhas divisorias
1184
        $this->pdf->Line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1185
        $this->pdf->Line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1186
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1187
        $y1 = $y+4+$bH;
1188
        $h = 7;
1189
        $texto = 'CHAVE DE ACESSO';
1190
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1191
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1192
        $y1 = $y+8+$bH;
1193
        $texto = $this->pFormat($chave_acesso, $this->formatoChave);
1194
        $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1195
        $y1 = $y+12+$bH;
1196
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1197
        $chaveContingencia="";
1198
        if ($this->pNotaDPEC()) {
1199
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1200
        } else {
1201
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1202
        }
1203
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1204
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1205
            $chaveContingencia = $this->pGeraChaveAdicionalDeContingencia();
1206
            $this->pdf->SetFillColor(0, 0, 0);
1207
            //codigo de barras
1208
            $this->pdf->Code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1209
        } else {
1210
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1211
            $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1212
            $y1 = $y+16+$bH;
1213
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1214
            $this->pdf->textBox(
1215
                $x+2,
1216
                $y1,
1217
                $w-2,
1218
                $h,
1219
                $texto,
1220
                $aFont,
1221
                'T',
1222
                'C',
1223
                0,
1224
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1225
            );
1226
        }
1227
1228
        //####################################################################################
1229
        //Dados da NF do cabeçalho
1230
        //natureza da operação
1231
        $texto = 'NATUREZA DA OPERAÇÃO';
1232
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1233
        $w = $w1+$w2;
1234
        $y = $oldY;
1235
        $oldY += $h;
1236
        $x = $oldX;
1237
        $h = 7;
1238
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1239
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1240
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1241
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1242
        $x += $w;
1243
        $w = $w3;
1244
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1245
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1246
        $this->pdf->textBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1247
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1248
        // testada antes de tentar obter a informação.
1249
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1250
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1251
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1252
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1253
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1254
            $texto = $this->pFormat($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1255
            $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...
1256
        } else {
1257
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1258
            if ($this->pNotaDPEC()) {
1259
                $texto = $this->numero_registro_dpec;
1260
                $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...
1261
            } else {
1262
                if (isset($this->nfeProc)) {
1263
                    $texto = ! empty($this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue) ?
1264
                            $this->nfeProc->getElementsByTagName("nProt")->item(0)->nodeValue : '';
1265
                    $tsHora = $this->pConvertTime($this->nfeProc->getElementsByTagName("dhRecbto")->item(0)->nodeValue);
1266
                    if ($texto != '') {
1267
                        $texto .= "  -  " . date('d/m/Y H:i:s', $tsHora);
1268
                    }
1269
                    $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...
1270
                } else {
1271
                    $texto = '';
1272
                    $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...
1273
                }
1274
            }
1275
        }
1276
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1277
        //####################################################################################
1278
        //INSCRIÇÃO ESTADUAL
1279
        $w = round($maxW * 0.333, 0);
1280
        $y += $h;
1281
        $oldY += $h;
1282
        $x = $oldX;
1283
        $texto = 'INSCRIÇÃO ESTADUAL';
1284
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1285
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1286
        $texto = $this->getTagValue($this->emit, "IE");
1287
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1288
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1289
        //INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.
1290
        $x += $w;
1291
        $texto = 'INSCRIÇÃO ESTADUAL DO SUBST. TRIBUT.';
1292
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1293
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1294
        $texto = ! empty($this->emit->getElementsByTagName("IEST")->item(0)->nodeValue)
1295
             ? $this->emit->getElementsByTagName("IEST")->item(0)->nodeValue
1296
             : '';
1297
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1298
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1299
        //CNPJ
1300
        $x += $w;
1301
        $w = ($maxW-(2*$w));
1302
        $texto = 'CNPJ / CPF';
1303
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1304
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1305
        //Pegando valor do CPF/CNPJ
1306
        if (! empty($this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1307
            $texto = $this->pFormat(
1308
                $this->emit->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1309
                "###.###.###/####-##"
1310
            );
1311
        } else {
1312
            $texto = ! empty($this->emit->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1313
                $this->pFormat(
1314
                    $this->emit->getElementsByTagName("CPF")->item(0)->nodeValue,
1315
                    "###.###.###-##"
1316
                ) : '';
1317
        }
1318
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1319
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1320
1321
        //####################################################################################
1322
        //Indicação de NF Homologação, cancelamento e falta de protocolo
1323
        $tpAmb = $this->ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
1324
        //indicar cancelamento
1325
        if ($this->pNotaCancelada()) {
1326
            //101 Cancelamento
1327
            $x = 10;
1328
            $y = $this->hPrint-130;
1329
            $h = 25;
1330
            $w = $maxW-(2*$x);
1331
            $this->pdf->SetTextColor(90, 90, 90);
1332
            $texto = "NFe CANCELADA";
1333
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1334
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1335
            $this->pdf->SetTextColor(0, 0, 0);
1336
        }
1337
1338
        if ($this->pNotaDPEC() || $this->tpEmis == 4) {
1339
            //DPEC
1340
            $x = 10;
1341
            $y = $this->hPrint-130;
1342
            $h = 25;
1343
            $w = $maxW-(2*$x);
1344
            $this->pdf->SetTextColor(200, 200, 200);
1345
            $texto = "DANFE impresso em contingência -\n".
1346
                     "DPEC regularmente recebido pela Receita\n".
1347
                     "Federal do Brasil";
1348
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1349
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1350
            $this->pdf->SetTextColor(0, 0, 0);
1351
        }
1352
        if ($this->pNotaDenegada()) {
1353
            //110 301 302 Denegada
1354
            $x = 10;
1355
            $y = $this->hPrint-130;
1356
            $h = 25;
1357
            $w = $maxW-(2*$x);
1358
            $this->pdf->SetTextColor(90, 90, 90);
1359
            $texto = "NFe USO DENEGADO";
1360
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1361
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1362
            $y += $h;
1363
            $h = 5;
1364
            $w = $maxW-(2*$x);
1365
            if (isset($this->infProt)) {
1366
                $xMotivo = $this->infProt->getElementsByTagName("xMotivo")->item(0)->nodeValue;
1367
            } else {
1368
                $xMotivo = '';
1369
            }
1370
            $texto = "SEM VALOR FISCAL\n".$xMotivo;
1371
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1372
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1373
            $this->pdf->SetTextColor(0, 0, 0);
1374
        }
1375
        //indicar sem valor
1376
        if ($tpAmb != 1) {
1377
            $x = 10;
1378
            if ($this->orientacao == 'P') {
1379
                $y = round($this->hPrint*2/3, 0);
1380
            } else {
1381
                $y = round($this->hPrint/2, 0);
1382
            }
1383
            $h = 5;
1384
            $w = $maxW-(2*$x);
1385
            $this->pdf->SetTextColor(90, 90, 90);
1386
            $texto = "SEM VALOR FISCAL";
1387
            $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1388
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1389
            $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1390
            $texto = "AMBIENTE DE HOMOLOGAÇÃO";
1391
            $this->pdf->textBox($x, $y+14, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1392
            $this->pdf->SetTextColor(0, 0, 0);
1393
        } else {
1394
            $x = 10;
1395
            if ($this->orientacao == 'P') {
1396
                $y = round($this->hPrint*2/3, 0);
1397
            } else {
1398
                $y = round($this->hPrint/2, 0);
1399
            }//fim orientacao
1400
            $h = 5;
1401
            $w = $maxW-(2*$x);
1402
            $this->pdf->SetTextColor(90, 90, 90);
1403
            //indicar FALTA DO PROTOCOLO se NFe não for em contingência
1404
            if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1405
                //Contingência
1406
                $texto = "DANFE Emitido em Contingência";
1407
                $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1408
                $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1409
                $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1410
                $texto = "devido à problemas técnicos";
1411
                $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1412
            } else {
1413
                if (!isset($this->nfeProc)) {
1414
                    if (!$this->pNotaDPEC()) {
1415
                        $texto = "SEM VALOR FISCAL";
1416
                        $aFont = ['font'=>$this->fontePadrao, 'size'=>48, 'style'=>'B'];
1417
                        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1418
                    }
1419
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>30, 'style'=>'B'];
1420
                    $texto = "FALTA PROTOCOLO DE APROVAÇÃO DA SEFAZ";
1421
                    if (!$this->pNotaDPEC()) {
1422
                        $this->pdf->textBox($x, $y+12, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1423
                    } else {
1424
                        $this->pdf->textBox($x, $y+25, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1425
                    }
1426
                }//fim nefProc
1427
            }//fim tpEmis
1428
            $this->pdf->SetTextColor(0, 0, 0);
1429
        }
1430
        return $oldY;
1431
    } //fim cabecalhoDANFE
1432
1433
    /**
1434
     * destinatarioDANFE
1435
     * Monta o campo com os dados do destinatário na DANFE. (retrato e paisagem)
1436
     *
1437
     * @name   destinatarioDANFE
1438
     * @param  number $x Posição horizontal canto esquerdo
1439
     * @param  number $y Posição vertical canto superior
1440
     * @return number Posição vertical final
1441
     */
1442
    protected function pDestinatarioDANFE($x = 0, $y = 0)
1443
    {
1444
        //####################################################################################
1445
        //DESTINATÁRIO / REMETENTE
1446
        $oldX = $x;
1447
        $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...
1448
        if ($this->orientacao == 'P') {
1449
            $maxW = $this->wPrint;
1450
        } else {
1451
            $maxW = $this->wPrint - $this->wCanhoto;
1452
        }
1453
        $w = $maxW;
1454
        $h = 7;
1455
        $texto = 'DESTINATÁRIO / REMETENTE';
1456
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1457
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1458
        //NOME / RAZÃO SOCIAL
1459
        $w = round($maxW*0.61, 0);
1460
        $w1 = $w;
1461
        $y += 3;
1462
        $texto = 'NOME / RAZÃO SOCIAL';
1463
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1464
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1465
        $texto = $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue;
1466
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1467
        if ($this->orientacao == 'P') {
1468
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1469
        } else {
1470
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 1, '');
1471
        }
1472
        //CNPJ / CPF
1473
        $x += $w;
1474
        $w = round($maxW*0.23, 0);
1475
        $w2 = $w;
1476
        $texto = 'CNPJ / CPF';
1477
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1478
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1479
        //Pegando valor do CPF/CNPJ
1480
        if (! empty($this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue)) {
1481
            $texto = $this->pFormat(
1482
                $this->dest->getElementsByTagName("CNPJ")->item(0)->nodeValue,
1483
                "###.###.###/####-##"
1484
            );
1485
        } else {
1486
            $texto = ! empty($this->dest->getElementsByTagName("CPF")->item(0)->nodeValue) ?
1487
                    $this->pFormat(
1488
                        $this->dest->getElementsByTagName("CPF")->item(0)->nodeValue,
1489
                        "###.###.###-##"
1490
                    ) : '';
1491
        }
1492
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1493
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1494
        //DATA DA EMISSÃO
1495
        $x += $w;
1496
        $w = $maxW-($w1+$w2);
1497
        $wx = $w;
1498
        $texto = 'DATA DA EMISSÃO';
1499
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1500
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1501
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
1502
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
1503
        if ($dEmi == '') {
1504
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
1505
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
1506
            $aDemi = explode('T', $dEmi);
1507
            $dEmi = $aDemi[0];
1508
        }
1509
        $texto = $this->pYmd2dmy($dEmi);
1510
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1511
        if ($this->orientacao == 'P') {
1512
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1513
        } else {
1514
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 1, '');
1515
        }
1516
        //ENDEREÇO
1517
        $w = round($maxW*0.47, 0);
1518
        $w1 = $w;
1519
        $y += $h;
1520
        $x = $oldX;
1521
        $texto = 'ENDEREÇO';
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("xLgr")->item(0)->nodeValue;
1525
        $texto .= ', ' . $this->dest->getElementsByTagName("nro")->item(0)->nodeValue;
1526
        $texto .= $this->getTagValue($this->dest, "xCpl", " - ");
1527
1528
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1529
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '', true);
1530
        //BAIRRO / DISTRITO
1531
        $x += $w;
1532
        $w = round($maxW*0.21, 0);
1533
        $w2 = $w;
1534
        $texto = 'BAIRRO / DISTRITO';
1535
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1536
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1537
        $texto = $this->dest->getElementsByTagName("xBairro")->item(0)->nodeValue;
1538
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1539
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1540
        //CEP
1541
        $x += $w;
1542
        $w = $maxW-$w1-$w2-$wx;
1543
        $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...
1544
        $texto = 'CEP';
1545
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1546
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1547
        $texto = ! empty($this->dest->getElementsByTagName("CEP")->item(0)->nodeValue) ?
1548
                $this->dest->getElementsByTagName("CEP")->item(0)->nodeValue : '';
1549
        $texto = $this->pFormat($texto, "#####-###");
1550
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1551
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1552
        //DATA DA SAÍDA
1553
        $x += $w;
1554
        $w = $wx;
1555
        $texto = 'DATA DA SAÍDA/ENTRADA';
1556
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1557
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1558
        $dSaiEnt = ! empty($this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue) ?
1559
                $this->ide->getElementsByTagName("dSaiEnt")->item(0)->nodeValue : '';
1560
        if ($dSaiEnt == '') {
1561
            $dSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1562
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1563
            $aDsaient = explode('T', $dSaiEnt);
1564
            $dSaiEnt = $aDsaient[0];
1565
        }
1566
        $texto = $this->pYmd2dmy($dSaiEnt);
1567
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1568
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1569
        //MUNICÍPIO
1570
        $w = $w1;
1571
        $y += $h;
1572
        $x = $oldX;
1573
        $texto = 'MUNICÍPIO';
1574
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1575
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1576
        $texto = $this->dest->getElementsByTagName("xMun")->item(0)->nodeValue;
1577
        if (strtoupper(trim($texto)) == "EXTERIOR" && $this->dest->getElementsByTagName("xPais")->length > 0) {
1578
            $texto .= " - " .  $this->dest->getElementsByTagName("xPais")->item(0)->nodeValue;
1579
        }
1580
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1581
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
1582
        //UF
1583
        $x += $w;
1584
        $w = 8;
1585
        $texto = 'UF';
1586
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1587
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1588
        $texto = $this->dest->getElementsByTagName("UF")->item(0)->nodeValue;
1589
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1590
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1591
        //FONE / FAX
1592
        $x += $w;
1593
        $w = round(($maxW -$w1-$wx-8)/2, 0);
1594
        $w3 = $w;
1595
        $texto = 'FONE / FAX';
1596
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1597
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1598
        $texto = ! empty($this->dest->getElementsByTagName("fone")->item(0)->nodeValue) ?
1599
                $this->dest->getElementsByTagName("fone")->item(0)->nodeValue : '';
1600
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1601
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1602
        //INSCRIÇÃO ESTADUAL
1603
        $x += $w;
1604
        $w = $maxW -$w1-$wx-8-$w3;
1605
        $texto = 'INSCRIÇÃO ESTADUAL';
1606
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1607
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1608
        $IE = $this->dest->getElementsByTagName("IE");
1609
        $texto = ($IE && $IE->length > 0) ? $IE->item(0)->nodeValue : '';
1610
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1611
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1612
        //HORA DA SAÍDA
1613
        $x += $w;
1614
        $w = $wx;
1615
        $texto = 'HORA DA SAÍDA/ENTRADA';
1616
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1617
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1618
        $hSaiEnt = ! empty($this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue) ?
1619
                $this->ide->getElementsByTagName("hSaiEnt")->item(0)->nodeValue : '';
1620
        if ($hSaiEnt == '') {
1621
            $dhSaiEnt = ! empty($this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue) ?
1622
                    $this->ide->getElementsByTagName("dhSaiEnt")->item(0)->nodeValue : '';
1623
            $tsDhSaiEnt = $this->pConvertTime($dhSaiEnt);
1624
            if ($tsDhSaiEnt != '') {
1625
                $hSaiEnt = date('H:i:s', $tsDhSaiEnt);
1626
            }
1627
        }
1628
        $texto = $hSaiEnt;
1629
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1630
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1631
        return ($y + $h);
1632
    } //fim da função destinatarioDANFE
1633
1634
     /**
1635
     * pGetTextoFatura
1636
     * Gera a String do Texto da Fatura
1637
      *
1638
     * @name   getTextoFatura
1639
     * @return uma String com o texto ou "";
1640
     */
1641
    protected function pGetTextoFatura()
1642
    {
1643
        if (isset($this->cobr)) {
1644
            $fat = $this->cobr->getElementsByTagName("fat")->item(0);
1645
            if (isset($fat)) {
1646
                if (!empty($this->getTagValue($this->ide, "indPag"))) {
1647
                    $textoIndPag = "";
1648
                    $indPag = $this->getTagValue($this->ide, "indPag");
1649
                    if ($indPag === "0") {
1650
                        $textoIndPag = "Pagamento à Vista - ";
1651
                    } elseif ($indPag === "1") {
1652
                        $textoIndPag = "Pagamento à Prazo - ";
1653
                    }
1654
                    $nFat = $this->getTagValue($fat, "nFat", "Fatura: ");
1655
                    $vOrig = $this->getTagValue($fat, "vOrig", " Valor Original: ");
1656
                    $vDesc = $this->getTagValue($fat, "vDesc", " Desconto: ");
1657
                    $vLiq = $this->getTagValue($fat, "vLiq", " Valor Líquido: ");
1658
                    $texto = $textoIndPag . $nFat . $vOrig . $vDesc . $vLiq;
1659
                    return $texto;
1660
                } else {
1661
                    $pag = $this->dom->getElementsByTagName("pag");
1662
                    if ($tPag = $this->getTagValue($pag->item(0), "tPag")) {
1663
                        return $this->tipoPag($tPag);
1664
                    }
1665
                }
1666
            }
1667
        }
1668
        return "";
1669
    } //fim getTextoFatura
1670
1671
     /**
1672
     * pSizeExtraTextoFatura
1673
     * Calcula o espaço ocupado pelo texto da fatura. Este espaço só é utilizado quando não houver duplicata.
1674
      *
1675
     * @name   pSizeExtraTextoFatura
1676
     * @return integer
1677
     */
1678
    protected function pSizeExtraTextoFatura()
1679
    {
1680
        $textoFatura = $this->pGetTextoFatura();
1681
        //verificar se existem duplicatas
1682
        if ($this->dup->length == 0 && $textoFatura !== "") {
1683
            return 10;
1684
        }
1685
        return 0;
1686
    }
1687
1688
    /**
1689
     * faturaDANFE
1690
     * Monta o campo de duplicatas da DANFE (retrato e paisagem)
1691
     *
1692
     * @name   faturaDANFE
1693
     * @param  number $x Posição horizontal canto esquerdo
1694
     * @param  number $y Posição vertical canto superior
1695
     * @return number Posição vertical final
1696
     */
1697
    protected function pFaturaDANFE($x, $y)
1698
    {
1699
        $linha = 1;
1700
        $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...
1701
        $oldx = $x;
1702
        $textoFatura = $this->pGetTextoFatura();
1703
        //verificar se existem duplicatas
1704
        if ($this->dup->length > 0 || $textoFatura !== "") {
1705
            //#####################################################################
1706
            //FATURA / DUPLICATA
1707
            $texto = "FATURA / DUPLICATA";
1708
            if ($this->orientacao == 'P') {
1709
                $w = $this->wPrint;
1710
            } else {
1711
                $w = 271;
1712
            }
1713
            $h = 8;
1714
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1715
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1716
            $y += 3;
1717
            $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...
1718
            $dupcont = 0;
1719
            $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...
1720
            if ($textoFatura !== "" && $this->exibirTextoFatura) {
1721
                $myH=6;
1722
                $myW = $this->wPrint;
1723
                if ($this->orientacao == 'L') {
1724
                    $myW -= $this->wCanhoto;
1725
                }
1726
                $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1727
                $this->pdf->textBox($x, $y, $myW, $myH, $textoFatura, $aFont, 'C', 'L', 1, '');
1728
                $y+=$myH+1;
1729
            }
1730
            if ($this->orientacao == 'P') {
1731
                $w = round($this->wPrint/7.018, 0)-1;
1732
            } else {
1733
                $w = 28;
1734
            }
1735
            $increm = 1;
1736
            foreach ($this->dup as $k => $d) {
1737
                $nDup = ! empty($this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue) ?
1738
                        $this->dup->item($k)->getElementsByTagName('nDup')->item(0)->nodeValue : '';
1739
                $dDup = ! empty($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) ?
1740
                        $this->pYmd2dmy($this->dup->item($k)->getElementsByTagName('dVenc')->item(0)->nodeValue) : '';
1741
                $vDup = ! empty($this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue) ?
1742
                        'R$ ' . number_format(
1743
                            $this->dup->item($k)->getElementsByTagName('vDup')->item(0)->nodeValue,
1744
                            2,
1745
                            ",",
1746
                            "."
1747
                        ) : '';
1748
                $h = 8;
1749
                $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...
1750
                if ($nDup!='0' && $nDup!='') {
1751
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1752
                    $this->pdf->textBox($x, $y, $w, $h, 'Num.', $aFont, 'T', 'L', 1, '');
1753
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1754
                    $this->pdf->textBox($x, $y, $w, $h, $nDup, $aFont, 'T', 'R', 0, '');
1755
                } else {
1756
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1757
                    $this->pdf->textBox($x, $y, $w, $h, ($dupcont+1)."", $aFont, 'T', 'L', 1, '');
1758
                }
1759
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1760
                $this->pdf->textBox($x, $y, $w, $h, 'Venc.', $aFont, 'C', 'L', 0, '');
1761
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1762
                $this->pdf->textBox($x, $y, $w, $h, $dDup, $aFont, 'C', 'R', 0, '');
1763
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1764
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1765
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1766
                $this->pdf->textBox($x, $y, $w, $h, $vDup, $aFont, 'B', 'R', 0, '');
1767
                $x += $w+$increm;
1768
                $dupcont += 1;
1769
                if ($this->orientacao == 'P') {
1770
                    $maxDupCont = 6;
1771
                } else {
1772
                    $maxDupCont = 8;
1773
                }
1774
                if ($dupcont > $maxDupCont) {
1775
                    $y += 9;
1776
                    $x = $oldx;
1777
                    $dupcont = 0;
1778
                    $linha += 1;
1779
                }
1780
                if ($linha == 5) {
1781
                    $linha = 4;
1782
                    break;
1783
                }
1784
            }
1785
            if ($dupcont == 0) {
1786
                $y -= 9;
1787
                $linha--;
1788
            }
1789
            return ($y+$h);
1790
        } else {
1791
            $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...
1792
            return ($y-2);
1793
        }
1794
    } //fim da função faturaDANFE
1795
1796
    /**
1797
     * pagamentoDANFE
1798
     * Monta o campo de pagamentos da DANFE (retrato e paisagem) (foi baseada na faturaDANFE)
1799
     *
1800
     * @name   pagamentoDANFE
1801
     * @param  number $x Posição horizontal canto esquerdo
1802
     * @param  number $y Posição vertical canto superior
1803
     * @return number Posição vertical final
1804
     */
1805
    protected function pagamentoDANFE($x, $y)
1806
    {
1807
        $linha = 1;
1808
        $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...
1809
        $oldx = $x;
1810
        //verificar se existem cobranças definidas
1811
        if (isset($this->detPag) && $this->detPag->length > 0) {
1812
            //#####################################################################
1813
            //Tipo de pagamento
1814
            $texto = "PAGAMENTO";
1815
            if ($this->orientacao == 'P') {
1816
                $w = $this->wPrint;
1817
            } else {
1818
                $w = 271;
1819
            }
1820
            $h = 8;
1821
            $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1822
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1823
            $y += 3;
1824
            $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...
1825
            $dupcont = 0;
1826
            if ($this->orientacao == 'P') {
1827
                $w = round($this->wPrint/7.018, 0)-1;
1828
            } else {
1829
                $w = 28;
1830
            }
1831
            if ($this->orientacao == 'P') {
1832
                $maxDupCont = 6;
1833
            } else {
1834
                $maxDupCont = 8;
1835
            }
1836
            $increm = 1;
1837
            $formaPagamento = ['01'=>'Dinheiro','02'=>'Cheque','03'=>'Cartão de Crédito',
1838
                                    '04'=>'Cartão de Débito','05'=>'Crédito Loja','10'=>'Vale Alimentação',
1839
                                    '11'=>'Vale Refeição','12'=>'Vale Presente','13'=>'Vale Combustível',
1840
                                    '14'=>'Duplicata Mercantil','15'=>'Boleto','90'=>'Sem pagamento','99'=>'Outros'];
1841
            $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...
1842
                              '06'=>'Elo','07'=>'Hipercard','08'=>'Aura','09'=>'Cabal','99'=>'Outros'];
1843
            foreach ($this->detPag as $k => $d) {
1844
                $fPag = !empty($this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue)
1845
                    ? $this->detPag->item($k)->getElementsByTagName('tPag')->item(0)->nodeValue : '0';
1846
                $vPag = ! empty($this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue)
1847
                    ? 'R$ ' . number_format(
1848
                        $this->detPag->item($k)->getElementsByTagName('vPag')->item(0)->nodeValue,
1849
                        2,
1850
                        ",",
1851
                        "."
1852
                    ) : '';
1853
                $h = 6;
1854
                $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...
1855
                if (isset($formaPagamento[$fPag])) {
1856
                    /*Exibir Item sem pagamento ou outros?*/
1857
                    if ($fPag=='90' || $fPag=='99') {
1858
                        continue;
1859
                    }
1860
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1861
                    $this->pdf->textBox($x, $y, $w, $h, 'Forma', $aFont, 'T', 'L', 1, '');
1862
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1863
                    $this->pdf->textBox($x, $y, $w, $h, $formaPagamento[$fPag], $aFont, 'T', 'R', 0, '');
1864
                } else {
1865
                    $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
1866
                    $this->pdf->textBox($x, $y, $w, $h, "Forma ".$fPag." não encontrado", $aFont, 'T', 'L', 1, '');
1867
                }
1868
                $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1869
                $this->pdf->textBox($x, $y, $w, $h, 'Valor', $aFont, 'B', 'L', 0, '');
1870
                $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1871
                $this->pdf->textBox($x, $y, $w, $h, $vPag, $aFont, 'B', 'R', 0, '');
1872
                $x += $w+$increm;
1873
                $dupcont += 1;
1874
1875
                if ($dupcont>$maxDupCont) {
1876
                    $y += 9;
1877
                    $x = $oldx;
1878
                    $dupcont = 0;
1879
                    $linha += 1;
1880
                }
1881
                if ($linha == 5) {
1882
                    $linha = 4;
1883
                    break;
1884
                }
1885
            }
1886
            if ($dupcont == 0) {
1887
                $y -= 9;
1888
                $linha--;
1889
            }
1890
            return ($y+$h);
1891
        } else {
1892
            $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...
1893
            return ($y-2);
1894
        }
1895
    } //fim da função pagamentoDANFE
1896
    
1897
    /**
1898
     * impostoDanfeHelper
1899
     * Auxilia a montagem dos campos de impostos e totais da DANFE
1900
     *
1901
     * @name   impostoDanfeHelper
1902
     * @param  float $x Posição horizontal canto esquerdo
1903
     * @param  float $y Posição vertical canto superior
1904
     * @param  float $w Largura do campo
1905
     * @param  float $h Altura do campo
1906
     * @param  float $h Título do campo
1907
     * @param  float $h Valor do imposto
1908
     * @return float Sugestão do $x do próximo imposto
1909
     */
1910
    protected function pImpostoDanfeHelper($x, $y, $w, $h, $titulo, $campoImposto)
1911
    {
1912
        $valorImposto = '0, 00';
1913
        $the_field = $this->ICMSTot->getElementsByTagName($campoImposto)->item(0);
1914
        if (isset($the_field)) {
1915
            $the_value = $the_field->nodeValue;
1916
            if (!empty($the_value)) {
1917
                $valorImposto = number_format($the_value, 2, ",", ".");
1918
            }
1919
        }
1920
1921
        $fontTitulo = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1922
        $fontValor = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1923
        $this->pdf->textBox($x, $y, $w, $h, $titulo, $fontTitulo, 'T', 'L', 1, '');
1924
        $this->pdf->textBox($x, $y, $w, $h, $valorImposto, $fontValor, 'B', 'R', 0, '');
1925
1926
        $next_x = $x + $w;
1927
        return $next_x;
1928
    }
1929
1930
    /**
1931
     * impostoDANFE
1932
     * Monta o campo de impostos e totais da DANFE (retrato e paisagem)
1933
     *
1934
     * @param  number $x Posição horizontal canto esquerdo
1935
     * @param  number $y Posição vertical canto superior
1936
     * @return number Posição vertical final
1937
     */
1938
    protected function pImpostoDANFE($x, $y)
1939
    {
1940
        $x_inicial = $x;
1941
        //#####################################################################
1942
1943
1944
        $campos_por_linha = 9;
1945
        if (!$this->exibirPIS) {
1946
            $campos_por_linha--;
1947
        }
1948
        if (!$this->exibirIcmsInterestadual) {
1949
            $campos_por_linha -= 2;
1950
        }
1951
1952
        if ($this->orientacao == 'P') {
1953
            $maxW = $this->wPrint;
1954
            $title_size = 31;
1955
        } else {
1956
            $maxW = $this->wPrint - $this->wCanhoto;
1957
            $title_size = 40;
1958
        }
1959
        $w = $maxW / $campos_por_linha;
1960
1961
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
1962
        $texto = "CÁLCULO DO IMPOSTO";
1963
        $this->pdf->textBox($x, $y, $title_size, 8, $texto, $aFont, 'T', 'L', 0, '');
1964
        $y += 3;
1965
        $h = 7;
1966
1967
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. DO ICMS", "vBC");
1968
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS", "vICMS");
1969
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "BASE DE CÁLC. ICMS S.T.", "vBCST");
1970
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO ICMS SUBST.", "vST");
1971
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. IMP. IMPORTAÇÃO", "vII");
1972
1973
        if ($this->exibirIcmsInterestadual) {
1974
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF REMET.", "vICMSUFRemet");
1975
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. FCP UF DEST.", "vFCPUFDest");
1976
        }
1977
1978
        if ($this->exibirPIS) {
1979
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO PIS", "vPIS");
1980
        }
1981
1982
        $x = $this->pImpostoDanfeHelper($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...
1983
1984
        //
1985
1986
        $y += $h;
1987
        $x = $x_inicial;
1988
1989
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO FRETE", "vFrete");
1990
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DO SEGURO", "vSeg");
1991
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "DESCONTO", "vDesc");
1992
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "OUTRAS DESPESAS", "vOutro");
1993
        $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR TOTAL IPI", "vIPI");
1994
1995
        if ($this->exibirIcmsInterestadual) {
1996
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. ICMS UF DEST.", "vICMSUFDest");
1997
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "V. TOT. TRIB.", "vTotTrib");
1998
        }
1999
2000
        if ($this->exibirPIS) {
2001
            $x = $this->pImpostoDanfeHelper($x, $y, $w, $h, "VALOR DA COFINS", "vCOFINS");
2002
        }
2003
        $x = $this->pImpostoDanfeHelper($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...
2004
2005
        return ($y+$h);
2006
    } //fim impostoDANFE
2007
2008
    /**
2009
     * transporteDANFE
2010
     * Monta o campo de transportes da DANFE (retrato e paisagem)
2011
     *
2012
     * @name   transporteDANFE
2013
     * @param  float $x Posição horizontal canto esquerdo
2014
     * @param  float $y Posição vertical canto superior
2015
     * @return float Posição vertical final
2016
     */
2017
    protected function pTransporteDANFE($x, $y)
2018
    {
2019
        $oldX = $x;
2020
        if ($this->orientacao == 'P') {
2021
            $maxW = $this->wPrint;
2022
        } else {
2023
            $maxW = $this->wPrint - $this->wCanhoto;
2024
        }
2025
        //#####################################################################
2026
        //TRANSPORTADOR / VOLUMES TRANSPORTADOS
2027
        $texto = "TRANSPORTADOR / VOLUMES TRANSPORTADOS";
2028
        $w = $maxW;
2029
        $h = 7;
2030
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2031
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2032
        //NOME / RAZÃO SOCIAL
2033
        $w1 = $maxW*0.29;
2034
        $y += 3;
2035
        $texto = 'NOME / RAZÃO SOCIAL';
2036
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2037
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2038
        if (isset($this->transporta)) {
2039
            $texto = ! empty($this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue) ?
2040
                    $this->transporta->getElementsByTagName("xNome")->item(0)->nodeValue : '';
2041
        } else {
2042
            $texto = '';
2043
        }
2044
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2045
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2046
        //FRETE POR CONTA
2047
        $x += $w1;
2048
        $w2 = $maxW*0.15;
2049
        $texto = 'FRETE';
2050
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2051
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2052
        $tipoFrete = ! empty($this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue) ?
2053
                $this->transp->getElementsByTagName("modFrete")->item(0)->nodeValue : '0';
2054
        switch ($tipoFrete) {
2055
            case 0:
2056
                $texto = "0-Por conta do Rem";
2057
                break;
2058
            case 1:
2059
                $texto = "1-Por conta do Dest";
2060
                break;
2061
            case 2:
2062
                $texto = "2-Por conta de Terceiros";
2063
                break;
2064
            case 3:
2065
                $texto = "3-Próprio por conta do Rem";
2066
                break;
2067
            case 4:
2068
                $texto = "4-Próprio por conta do Dest";
2069
                break;
2070
            case 9:
2071
                $texto = "9-Sem Transporte";
2072
                break;
2073
        }
2074
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2075
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 1, '');
2076
        //CÓDIGO ANTT
2077
        $x += $w2;
2078
        $texto = 'CÓDIGO ANTT';
2079
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2080
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2081
        if (isset($this->veicTransp)) {
2082
            $texto = ! empty($this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue) ?
2083
                    $this->veicTransp->getElementsByTagName("RNTC")->item(0)->nodeValue : '';
2084
        } else {
2085
            $texto = '';
2086
        }
2087
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2088
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2089
        //PLACA DO VEÍC
2090
        $x += $w2;
2091
        $texto = 'PLACA DO VEÍCULO';
2092
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2093
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2094
        if (isset($this->veicTransp)) {
2095
            $texto = ! empty($this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue) ?
2096
                    $this->veicTransp->getElementsByTagName("placa")->item(0)->nodeValue : '';
2097
        } elseif (isset($this->reboque)) {
2098
            $texto = ! empty($this->reboque->getElementsByTagName("placa")->item(0)->nodeValue) ?
2099
                    $this->reboque->getElementsByTagName("placa")->item(0)->nodeValue : '';
2100
        } else {
2101
            $texto = '';
2102
        }
2103
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2104
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2105
        //UF
2106
        $x += $w2;
2107
        $w3 = round($maxW*0.04, 0);
2108
        $texto = 'UF';
2109
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2110
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2111
        if (isset($this->veicTransp)) {
2112
            $texto = ! empty($this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue) ?
2113
                    $this->veicTransp->getElementsByTagName("UF")->item(0)->nodeValue : '';
2114
        } elseif (isset($this->reboque)) {
2115
            $texto = ! empty($this->reboque->getElementsByTagName("UF")->item(0)->nodeValue) ?
2116
                    $this->reboque->getElementsByTagName("UF")->item(0)->nodeValue : '';
2117
        } else {
2118
            $texto = '';
2119
        }
2120
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2121
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2122
        //CNPJ / CPF
2123
        $x += $w3;
2124
        $w = $maxW-($w1+3*$w2+$w3);
2125
        $texto = 'CNPJ / CPF';
2126
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2127
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2128
        if (isset($this->transporta)) {
2129
            $texto = ! empty($this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue) ?
2130
                    $this->pFormat(
2131
                        $this->transporta->getElementsByTagName("CNPJ")->item(0)->nodeValue,
2132
                        "##.###.###/####-##"
2133
                    ) : '';
2134
            if ($texto == '') {
2135
                $texto = ! empty($this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue) ?
2136
                        $this->pFormat(
2137
                            $this->transporta->getElementsByTagName("CPF")->item(0)->nodeValue,
2138
                            "###.###.###-##"
2139
                        ) : '';
2140
            }
2141
        } else {
2142
            $texto = '';
2143
        }
2144
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2145
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2146
        //#####################################################################
2147
        //ENDEREÇO
2148
        $y += $h;
2149
        $x = $oldX;
2150
        $h = 7;
2151
        $w1 = $maxW*0.44;
2152
        $texto = 'ENDEREÇO';
2153
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2154
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2155
        if (isset($this->transporta)) {
2156
            $texto = ! empty($this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue) ?
2157
                    $this->transporta->getElementsByTagName("xEnder")->item(0)->nodeValue : '';
2158
        } else {
2159
            $texto = '';
2160
        }
2161
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2162
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'L', 0, '');
2163
        //MUNICÍPIO
2164
        $x += $w1;
2165
        $w2 = round($maxW*0.30, 0);
2166
        $texto = 'MUNICÍPIO';
2167
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2168
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2169
        if (isset($this->transporta)) {
2170
            $texto = ! empty($this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue) ?
2171
                    $this->transporta->getElementsByTagName("xMun")->item(0)->nodeValue : '';
2172
        } else {
2173
            $texto = '';
2174
        }
2175
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2176
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2177
        //UF
2178
        $x += $w2;
2179
        $w3 = round($maxW*0.04, 0);
2180
        $texto = 'UF';
2181
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2182
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2183
        if (isset($this->transporta)) {
2184
            $texto = ! empty($this->transporta->getElementsByTagName("UF")->item(0)->nodeValue) ?
2185
                    $this->transporta->getElementsByTagName("UF")->item(0)->nodeValue : '';
2186
        } else {
2187
            $texto = '';
2188
        }
2189
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2190
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'C', 0, '');
2191
        //INSCRIÇÃO ESTADUAL
2192
        $x += $w3;
2193
        $w = $maxW-($w1+$w2+$w3);
2194
        $texto = 'INSCRIÇÃO ESTADUAL';
2195
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2196
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2197
        $texto = '';
2198
        if (isset($this->transporta)) {
2199
            if (! empty($this->transporta->getElementsByTagName("IE")->item(0)->nodeValue)) {
2200
                $texto = $this->transporta->getElementsByTagName("IE")->item(0)->nodeValue;
2201
            }
2202
        }
2203
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2204
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
2205
        //Tratar Multiplos volumes
2206
        $volumes = $this->transp->getElementsByTagName('vol');
2207
        $quantidade = 0;
2208
        $especie = '';
2209
        $marca = '';
2210
        $numero = '';
2211
        $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...
2212
        $pesoBruto=0;
2213
        $pesoLiquido=0;
2214
        foreach ($volumes as $volume) {
2215
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2216
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2217
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2218
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2219
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2220
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2221
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2222
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2223
            if ($texto != $especie && $especie != '') {
2224
                //tem várias especies
2225
                $especie = 'VARIAS';
2226
            } else {
2227
                $especie = $texto;
2228
            }
2229
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2230
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2231
            if ($texto != $marca && $marca != '') {
2232
                //tem várias especies
2233
                $marca = 'VARIAS';
2234
            } else {
2235
                $marca = $texto;
2236
            }
2237
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2238
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2239
            if ($texto != $numero && $numero != '') {
2240
                //tem várias especies
2241
                $numero = 'VARIOS';
2242
            } else {
2243
                $numero = $texto;
2244
            }
2245
        }
2246
2247
        //#####################################################################
2248
        //QUANTIDADE
2249
        $y += $h;
2250
        $x = $oldX;
2251
        $h = 7;
2252
        $w1 = round($maxW*0.10, 0);
2253
        $texto = 'QUANTIDADE';
2254
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2255
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2256
        if (!empty($quantidade)) {
2257
            $texto = $quantidade;
2258
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2259
            $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2260
        }
2261
        //ESPÉCIE
2262
        $x += $w1;
2263
        $w2 = round($maxW*0.17, 0);
2264
        $texto = 'ESPÉCIE';
2265
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2266
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2267
        $texto = $especie;
2268
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2269
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2270
        //MARCA
2271
        $x += $w2;
2272
        $texto = 'MARCA';
2273
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2274
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2275
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2276
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2277
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2278
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2279
        //NUMERAÇÃO
2280
        $x += $w2;
2281
        $texto = 'NUMERAÇÃO';
2282
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2283
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2284
        $texto = $numero;
2285
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2286
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2287
        //PESO BRUTO
2288
        $x += $w2;
2289
        $w3 = round($maxW*0.20, 0);
2290
        $texto = 'PESO BRUTO';
2291
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2292
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2293
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2294
            $texto = number_format($pesoBruto, 3, ",", ".");
2295
        } else {
2296
            $texto = '';
2297
        }
2298
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2299
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2300
        //PESO LÍQUIDO
2301
        $x += $w3;
2302
        $w = $maxW -($w1+3*$w2+$w3);
2303
        $texto = 'PESO LÍQUIDO';
2304
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2305
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2306
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2307
            $texto = number_format($pesoLiquido, 3, ",", ".");
2308
        } else {
2309
            $texto = '';
2310
        }
2311
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2312
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2313
        return ($y+$h);
2314
    } //fim transporteDANFE
2315
2316
2317
2318
    protected function pDescricaoProdutoHelper($origem, $campo, $formato)
2319
    {
2320
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2321
        if (!isset($valor_original)) {
2322
            return "";
2323
        }
2324
        $valor_original = $valor_original->nodeValue;
2325
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2326
2327
        if ($valor != "") {
2328
            return sprintf($formato, $valor);
2329
        }
2330
        return "";
2331
    }
2332
2333
    /**
2334
     * descricaoProduto
2335
     * Monta a string de descrição de cada Produto
2336
     *
2337
     * @name   descricaoProduto
2338
     * @param  DOMNode itemProd
2339
     * @return string descricao do produto
2340
     */
2341
    protected function pDescricaoProduto($itemProd)
2342
    {
2343
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2344
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2345
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2346
        $impostos = '';
2347
2348
        if (!empty($ICMS)) {
2349
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2350
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2351
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2352
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2353
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2354
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2355
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2356
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2357
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2358
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2359
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2360
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vBCSTRet", " vBcStRet=%s");
2361
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "pST", " pSt=%s");
2362
            $impostos .= $this->pDescricaoProdutoHelper($ICMS, "vICMSSTRet", " vIcmsStRet=%s");
2363
        }
2364
        if (!empty($ICMSUFDest)) {
2365
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2366
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2367
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2368
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2369
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2370
            $impostos .= $this->pDescricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2371
        }
2372
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue) ?
2373
                substr($this->pAnfavea($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue), 0, 500) : '';
2374
        if (! empty($infAdProd)) {
2375
            $infAdProd = trim($infAdProd);
2376
            $infAdProd .= ' ';
2377
        }
2378
        $loteTxt ='';
2379
        $rastro = $prod->getElementsByTagName("med");
2380
        if (!isset($rastro)) {
2381
            $rastro = $prod->getElementsByTagName("rastro");
2382
        }
2383
        if (isset($rastro)) {
2384
            $i = 0;
2385
            while ($i < $rastro->length) {
2386
                $loteTxt .= $this->getTagValue($rastro->item($i), 'nLote', ' Lote: ');
2387
                $loteTxt .= $this->getTagValue($rastro->item($i), 'qLote', ' Quant: ');
2388
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dFab', ' Fab: ');
2389
                $loteTxt .= $this->pSimpleGetDate($rastro->item($i), 'dVal', ' Val: ');
2390
                $loteTxt .= $this->getTagValue($rastro->item($i), 'vPMC', ' PMC: ');
2391
                $i++;
2392
            }
2393
            if ($loteTxt != '') {
2394
                $loteTxt.= ' ';
2395
            }
2396
        }
2397
        //NT2013.006 FCI
2398
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2399
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2400
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2401
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2402
        //decodifica os caracteres html no xml
2403
        $texto = html_entity_decode($texto);
2404
        if ($this->descProdQuebraLinha) {
2405
            $texto = str_replace(";", "\n", $texto);
2406
        }
2407
        return $texto;
2408
    }
2409
2410
    /**
2411
     * itensDANFE
2412
     * Monta o campo de itens da DANFE (retrato e paisagem)
2413
     *
2414
     * @name   itensDANFE
2415
     * @param  float $x       Posição horizontal canto esquerdo
2416
     * @param  float $y       Posição vertical canto superior
2417
     * @param  float $nInicio Número do item inicial
2418
     * @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...
2419
     * @param  float $hmax    Altura máxima do campo de itens em mm
2420
     * @return float Posição vertical final
2421
     */
2422
    protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2423
    {
2424
        $oldX = $x;
2425
        $oldY = $y;
2426
        $totItens = $this->det->length;
2427
        //#####################################################################
2428
        //DADOS DOS PRODUTOS / SERVIÇOS
2429
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2430
        if ($this->orientacao == 'P') {
2431
            $w = $this->wPrint;
2432
        } else {
2433
            if ($nInicio < 2) { // primeira página
2434
                $w = $this->wPrint - $this->wCanhoto;
2435
            } else { // páginas seguintes
2436
                $w = $this->wPrint;
2437
            }
2438
        }
2439
        $h = 4;
2440
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2441
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2442
        $y += 3;
2443
        //desenha a caixa dos dados dos itens da NF
2444
        $hmax += 1;
2445
        $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...
2446
        $this->pdf->textBox($x, $y, $w, $hmax);
2447
        //##################################################################################
2448
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2449
        //CÓDIGO PRODUTO
2450
        $texto = "CÓDIGO PRODUTO";
2451
        $w1 = round($w*0.09, 0);
2452
        $h = 4;
2453
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2454
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2455
        $this->pdf->Line($x+$w1, $y, $x+$w1, $y+$hmax);
2456
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2457
        $x += $w1;
2458
        $w2 = round($w*0.28, 0);
2459
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2460
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2461
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2462
        $this->pdf->Line($x+$w2, $y, $x+$w2, $y+$hmax);
2463
        //NCM/SH
2464
        $x += $w2;
2465
        $w3 = round($w*0.06, 0);
2466
        $texto = 'NCM/SH';
2467
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2468
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2469
        $this->pdf->Line($x+$w3, $y, $x+$w3, $y+$hmax);
2470
        //O/CST ou O/CSOSN
2471
        $x += $w3;
2472
        $w4 = round($w*0.05, 0);
2473
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2474
        if ($this->getTagValue($this->emit, 'CRT') == '3') {
2475
             $texto = 'O/CST';//Regime Normal
2476
        }
2477
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2478
        $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2479
        $this->pdf->Line($x+$w4, $y, $x+$w4, $y+$hmax);
2480
        //CFOP
2481
        $x += $w4;
2482
        $w5 = round($w*0.04, 0);
2483
        $texto = 'CFOP';
2484
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2485
        $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2486
        $this->pdf->Line($x+$w5, $y, $x+$w5, $y+$hmax);
2487
        //UN
2488
        $x += $w5;
2489
        $w6 = round($w*0.03, 0);
2490
        $texto = 'UN';
2491
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2492
        $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2493
        $this->pdf->Line($x+$w6, $y, $x+$w6, $y+$hmax);
2494
        //QUANT
2495
        $x += $w6;
2496
        $w7 = round($w*0.07, 0);
2497
        $texto = 'QUANT';
2498
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2499
        $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2500
        $this->pdf->Line($x+$w7, $y, $x+$w7, $y+$hmax);
2501
        //VALOR UNIT
2502
        $x += $w7;
2503
        $w8 = round($w*0.06, 0);
2504
        $texto = 'VALOR UNIT';
2505
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2506
        $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2507
        $this->pdf->Line($x+$w8, $y, $x+$w8, $y+$hmax);
2508
        //VALOR TOTAL
2509
        $x += $w8;
2510
        $w9 = round($w*0.06, 0);
2511
        $texto = 'VALOR TOTAL';
2512
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2513
        $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2514
        $this->pdf->Line($x+$w9, $y, $x+$w9, $y+$hmax);
2515
        //B.CÁLC ICMS
2516
        $x += $w9;
2517
        $w10 = round($w*0.06, 0);
2518
        $texto = 'B.CÁLC ICMS';
2519
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2520
        $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2521
        $this->pdf->Line($x+$w10, $y, $x+$w10, $y+$hmax);
2522
        //VALOR ICMS
2523
        $x += $w10;
2524
        $w11 = round($w*0.06, 0);
2525
        $texto = 'VALOR ICMS';
2526
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2527
        $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2528
        $this->pdf->Line($x+$w11, $y, $x+$w11, $y+$hmax);
2529
        //VALOR IPI
2530
        $x += $w11;
2531
        $w12 = round($w*0.05, 0);
2532
        $texto = 'VALOR IPI';
2533
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2534
        $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2535
        $this->pdf->Line($x+$w12, $y, $x+$w12, $y+$hmax);
2536
        //ALÍQ. ICMS
2537
        $x += $w12;
2538
        $w13 = round($w*0.035, 0);
2539
        $texto = 'ALÍQ. ICMS';
2540
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2541
        $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2542
        $this->pdf->Line($x+$w13, $y, $x+$w13, $y+$hmax);
2543
        //ALÍQ. IPI
2544
        $x += $w13;
2545
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2546
        $texto = 'ALÍQ. IPI';
2547
        $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2548
        $this->pdf->Line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2549
        $y += 5;
2550
        //##################################################################################
2551
        // LOOP COM OS DADOS DOS PRODUTOS
2552
        $i = 0;
2553
        $hUsado = $hCabecItens;
2554
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2555
        foreach ($this->det as $d) {
2556
            if ($i >= $nInicio) {
2557
                $thisItem = $this->det->item($i);
2558
                //carrega as tags do item
2559
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2560
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2561
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2562
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2563
                $textoProduto = trim($this->pDescricaoProduto($thisItem));
2564
2565
                $linhaDescr = $this->pdf->getNumLines($textoProduto, $w2, $aFont);
2566
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2567
                $hUsado += $h;
2568
2569
                $diffH = $hmax - $hUsado;
2570
2571
                if ($pag != $totpag) {
2572
                    if (1 > $diffH && $i < $totItens) {
2573
                        //ultrapassa a capacidade para uma única página
2574
                        //o restante dos dados serão usados nas proximas paginas
2575
                        $nInicio = $i;
2576
                        break;
2577
                    }
2578
                }
2579
                $y_linha=$y+$h;
2580
                // linha entre itens
2581
                $this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120);
2582
                //corrige o x
2583
                $x=$oldX;
2584
                //codigo do produto
2585
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2586
                $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2587
                $x += $w1;
2588
                //DESCRIÇÃO
2589
                if ($this->orientacao == 'P') {
2590
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2591
                } else {
2592
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2593
                }
2594
                $x += $w2;
2595
                //NCM
2596
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2597
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2598
                $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2599
                $x += $w3;
2600
                //CST
2601
                if (isset($ICMS)) {
2602
                    $origem =  $this->getTagValue($ICMS, "orig");
2603
                    $cst =  $this->getTagValue($ICMS, "CST");
2604
                    $csosn =  $this->getTagValue($ICMS, "CSOSN");
2605
                    $texto = $origem.$cst.$csosn;
2606
                    $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2607
                }
2608
                //CFOP
2609
                $x += $w4;
2610
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2611
                $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2612
                //Unidade
2613
                $x += $w5;
2614
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2615
                $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2616
                $x += $w6;
2617
                if ($this->orientacao == 'P') {
2618
                    $alinhamento = 'R';
2619
                } else {
2620
                    $alinhamento = 'R';
2621
                }
2622
                // QTDADE
2623
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2624
                $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2625
                $x += $w7;
2626
                // Valor Unitário
2627
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2628
                $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2629
                $x += $w8;
2630
                // Valor do Produto
2631
                $texto = "";
2632
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2633
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2634
                }
2635
                $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2636
                //Valor da Base de calculo
2637
                $x += $w9;
2638
                if (isset($ICMS)) {
2639
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2640
                            number_format(
2641
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2642
                                2,
2643
                                ",",
2644
                                "."
2645
                            ) : '0, 00';
2646
                    $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2647
                }
2648
                //Valor do ICMS
2649
                $x += $w10;
2650
                if (isset($ICMS)) {
2651
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2652
                            number_format(
2653
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2654
                                2,
2655
                                ",",
2656
                                "."
2657
                            ) : '0, 00';
2658
                    $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2659
                }
2660
                //Valor do IPI
2661
                $x += $w11;
2662
                if (isset($IPI)) {
2663
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2664
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2665
                } else {
2666
                    $texto = '';
2667
                }
2668
                $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2669
                // %ICMS
2670
                $x += $w12;
2671
                if (isset($ICMS)) {
2672
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2673
                            number_format(
2674
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2675
                                2,
2676
                                ",",
2677
                                "."
2678
                            ) : '0, 00';
2679
                    $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2680
                }
2681
                //%IPI
2682
                $x += $w13;
2683
                if (isset($IPI)) {
2684
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2685
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2686
                } else {
2687
                    $texto = '';
2688
                }
2689
                $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2690
2691
2692
                // Dados do Veiculo Somente para veiculo 0 Km
2693
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2694
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2695
                // Verifica se a Tag existe
2696
                if (!empty($veicProd)) {
2697
                    $this->pDadosItenVeiculoDANFE($oldX, $y, $nInicio, $h, $prod);
2698
                }
2699
2700
2701
                $y += $h;
2702
                $i++;
2703
                //incrementa o controle dos itens processados.
2704
                $this->qtdeItensProc++;
2705
            } else {
2706
                $i++;
2707
            }
2708
        }
2709
        return $oldY+$hmax;
2710
    }
2711
2712
2713
    /**
2714
     * pDadosItenVeiculoDANFE
2715
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2716
     *
2717
     * @param float  $x    Posição horizontal
2718
     *                     canto esquerdo
2719
     * @param float  $y    Posição vertical
2720
     *                     canto superior
2721
     * @param        $nInicio
2722
     * @param float  $h    altura do campo
2723
     * @param object $prod Contendo todos os dados do item
2724
     */
2725
2726
    protected function pDadosItenVeiculoDANFE($x, $y, &$nInicio, $h, $prod)
2727
    {
2728
        $oldX = $x;
2729
        $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...
2730
2731
        if ($this->orientacao == 'P') {
2732
            $w = $this->wPrint;
2733
        } else {
2734
            if ($nInicio < 2) { // primeira página
2735
                $w = $this->wPrint - $this->wCanhoto;
2736
            } else { // páginas seguintes
2737
                $w = $this->wPrint;
2738
            }
2739
        }
2740
2741
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2742
2743
        $w1 = round($w*0.09, 0);
2744
2745
        // Tabela Renavam Combustivel
2746
        $renavamCombustivel = [
2747
            1=>'ALCOOL',
2748
            2=>'GASOLINA',
2749
            3=>'DIESEL',
2750
            4=>'GASOGENIO',
2751
            5=>'GAS METANO',
2752
            6=>'ELETRICO/FONTE INTERNA',
2753
            7=>'ELETRICO/FONTE EXTERNA',
2754
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
2755
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
2756
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
2757
            11=>'VIDE/CAMPO/OBSERVACAO',
2758
            12=>'ALCOOL/GAS NATURAL VEICULAR',
2759
            13=>'GASOLINA/GAS NATURAL VEICULAR',
2760
            14=>'DIESEL/GAS NATURAL VEICULAR',
2761
            15=>'GAS NATURAL VEICULAR',
2762
            16=>'ALCOOL/GASOLINA',
2763
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
2764
            18=>'GASOLINA/ELETRICO'
2765
        ];
2766
2767
        $renavamEspecie = [
2768
            1=>'PASSAGEIRO',
2769
            2=>'CARGA',
2770
            3=>'MISTO',
2771
            4=>'CORRIDA',
2772
            5=>'TRACAO',
2773
            6=>'ESPECIAL',
2774
            7=>'COLECAO'
2775
        ];
2776
2777
        $renavamTiposVeiculos = [
2778
            1=>'BICICLETA',
2779
            2=>'CICLOMOTOR',
2780
            3=>'MOTONETA',
2781
            4=>'MOTOCICLETA',
2782
            5=>'TRICICLO',
2783
            6=>'AUTOMOVEL',
2784
            7=>'MICROONIBUS',
2785
            8=>'ONIBUS',
2786
            9=>'BONDE',
2787
            10=>'REBOQUE',
2788
            11=>'SEMI-REBOQUE',
2789
            12=>'CHARRETE',
2790
            13=>'CAMIONETA',
2791
            14=>'CAMINHAO',
2792
            15=>'CARROCA',
2793
            16=>'CARRO DE MAO',
2794
            17=>'CAMINHAO TRATOR',
2795
            18=>'TRATOR DE RODAS',
2796
            19=>'TRATOR DE ESTEIRAS',
2797
            20=>'TRATOR MISTO',
2798
            21=>'QUADRICICLO',
2799
            22=>'CHASSI/PLATAFORMA',
2800
            23=>'CAMINHONETE',
2801
            24=>'SIDE-CAR',
2802
            25=>'UTILITARIO',
2803
            26=>'MOTOR-CASA'
2804
        ];
2805
2806
        $renavamTipoPintura = [
2807
            'F'=>'FOSCA',
2808
            'S'=>'SÓLIDA',
2809
            'P'=>'PEROLIZADA',
2810
            'M'=>'METALICA',
2811
        ];
2812
2813
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2814
2815
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
2816
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
2817
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
2818
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
2819
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
2820
2821
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
2822
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
2823
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
2824
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
2825
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2826
2827
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2828
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2829
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2830
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2831
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2832
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2833
2834
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2835
2836
        $x = $oldX;
2837
2838
        $yVeic = $y + $h;
2839
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2840
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2841
        $yVeic += $h;
2842
        $texto = 'Cor...................: ' . $veiculoCor;
2843
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2844
        $yVeic += $h;
2845
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2846
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2847
        $yVeic += $h;
2848
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2849
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2850
        $yVeic += $h;
2851
        $texto = 'Tipo.................: ' . $renavamTiposVeiculos[intval($veiculoTipo)];
2852
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2853
        $yVeic = $y + $h;
2854
        $xVeic = $x + 65;
2855
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2856
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2857
        $yVeic += $h;
2858
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2859
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2860
        $yVeic += $h;
2861
        $texto = 'HP.....................: ' . $veiculoHp;
2862
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2863
        $yVeic += $h;
2864
        $texto = 'Placa.................: ' . $veiculoPlaca;
2865
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2866
        $yVeic += $h;
2867
        $texto = 'Tipo Pintura......: ' . $renavamTipoPintura[$veiculoTipoPintura];
2868
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2869
        $yVeic = $y + $h;
2870
        $xVeic = $xVeic + 55;
2871
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2872
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2873
        $yVeic += $h;
2874
        $texto = 'Especie..................: ' . $renavamEspecie[intval($veiculoEspecie)];
2875
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2876
        $yVeic += $h;
2877
        $texto = 'Combustivel..........: ' . $renavamCombustivel[intval($veiculoCombustivel)];
2878
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2879
        $yVeic += $h;
2880
        $texto = 'Serial.....................: ' . $veiculoSerial;
2881
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2882
        $yVeic += $h;
2883
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2884
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2885
        $yVeic += $h;
2886
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2887
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2888
    }
2889
2890
    /**
2891
     * issqnDANFE
2892
     * Monta o campo de serviços do DANFE
2893
     *
2894
     * @name   issqnDANFE (retrato e paisagem)
2895
     * @param  float $x Posição horizontal canto esquerdo
2896
     * @param  float $y Posição vertical canto superior
2897
     * @return float Posição vertical final
2898
     */
2899
    protected function pIssqnDANFE($x, $y)
2900
    {
2901
        $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...
2902
        //#####################################################################
2903
        //CÁLCULO DO ISSQN
2904
        $texto = "CÁLCULO DO ISSQN";
2905
        $w = $this->wPrint;
2906
        $h = 7;
2907
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2908
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2909
        //INSCRIÇÃO MUNICIPAL
2910
        $y += 3;
2911
        $w = round($this->wPrint*0.23, 0);
2912
        $texto = 'INSCRIÇÃO MUNICIPAL';
2913
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2914
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2915
        //inscrição municipal
2916
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2917
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2918
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2919
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2920
        //VALOR TOTAL DOS SERVIÇOS
2921
        $x += $w;
2922
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2923
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2924
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2925
        if (isset($this->ISSQNtot)) {
2926
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2927
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2928
            $texto = number_format($texto, 2, ",", ".");
2929
        } else {
2930
            $texto = '';
2931
        }
2932
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2933
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2934
        //BASE DE CÁLCULO DO ISSQN
2935
        $x += $w;
2936
        $texto = 'BASE DE CÁLCULO DO ISSQN';
2937
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2938
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2939
        if (isset($this->ISSQNtot)) {
2940
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2941
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
2942
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2943
        } else {
2944
            $texto = '';
2945
        }
2946
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2947
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2948
        //VALOR TOTAL DO ISSQN
2949
        $x += $w;
2950
        if ($this->orientacao == 'P') {
2951
            $w = $this->wPrint - (3 * $w);
2952
        } else {
2953
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
2954
        }
2955
        $texto = 'VALOR TOTAL DO ISSQN';
2956
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2957
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2958
        if (isset($this->ISSQNtot)) {
2959
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
2960
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
2961
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
2962
        } else {
2963
            $texto = '';
2964
        }
2965
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2966
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2967
        return ($y+$h+1);
2968
    }
2969
2970
    /**
2971
     *dadosAdicionaisDANFE
2972
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
2973
     *
2974
     * @name   dadosAdicionaisDANFE
2975
     * @param  float $x Posição horizontal canto esquerdo
2976
     * @param  float $y Posição vertical canto superior
2977
     * @param  float $h altura do campo
2978
     * @return float Posição vertical final (eixo Y)
2979
     */
2980
    protected function pDadosAdicionaisDANFE($x, $y, $h)
2981
    {
2982
        //##################################################################################
2983
        //DADOS ADICIONAIS
2984
        $texto = "DADOS ADICIONAIS";
2985
        if ($this->orientacao == 'P') {
2986
              $w = $this->wPrint;
2987
        } else {
2988
              $w = $this->wPrint-$this->wCanhoto;
2989
        }
2990
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2991
        $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
2992
        //INFORMAÇÕES COMPLEMENTARES
2993
        $texto = "INFORMAÇÕES COMPLEMENTARES";
2994
        $y += 3;
2995
        $w = $this->wAdic;
2996
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
2997
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2998
        //o texto com os dados adicionais foi obtido na função montaDANFE
2999
        //e carregado em uma propriedade privada da classe
3000
        //$this->wAdic com a largura do campo
3001
        //$this->textoAdic com o texto completo do campo
3002
        $y += 1;
3003
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3004
        $this->pdf->textBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3005
        //RESERVADO AO FISCO
3006
        $texto = "RESERVADO AO FISCO";
3007
        $x += $w;
3008
        $y -= 1;
3009
        if ($this->orientacao == 'P') {
3010
            $w = $this->wPrint-$w;
3011
        } else {
3012
            $w = $this->wPrint-$w-$this->wCanhoto;
3013
        }
3014
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3015
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3016
        //inserir texto informando caso de contingência
3017
        // 1 - Normal - emissão normal;
3018
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3019
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3020
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3021
        //     Prévia de Emissão em Contingência;
3022
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3023
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3024
        // 6 - Contingência SVC-AN
3025
        // 7 - Contingência SVC-RS
3026
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
3027
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3028
        $texto = '';
3029
        switch ($this->tpEmis) {
3030
            case 2:
3031
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3032
                break;
3033
            case 3:
3034
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3035
                break;
3036
            case 4:
3037
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3038
                break;
3039
            case 5:
3040
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3041
                break;
3042
            case 6:
3043
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3044
                break;
3045
            case 7:
3046
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3047
                break;
3048
        }
3049
        $y += 2;
3050
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3051
        $this->pdf->textBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3052
        return $y+$h;
3053
    }
3054
3055
    /**
3056
     * pRodape
3057
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3058
     * sobre a API NfePHP
3059
     *
3060
     * @name   pRodape
3061
     * @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...
3062
     * @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...
3063
     * @return void
3064
     */
3065
    protected function pRodape($x, $y)
3066
    {
3067
        if ($this->orientacao == 'P') {
3068
              $w = $this->wPrint;
3069
        } else {
3070
              $w = $this->wPrint-$this->wCanhoto;
3071
              $x = $this->wCanhoto;
3072
        }
3073
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
3074
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
3075
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
3076
        $texto = $this->creditos .  "  Powered by NFePHP";
3077
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
3078
    }
3079
3080
    /**
3081
     * pCcanhotoDANFE
3082
     * Monta o canhoto da DANFE (retrato e paisagem)
3083
     *
3084
     * @name   canhotoDANFE
3085
     * @param  number $x Posição horizontal canto esquerdo
3086
     * @param  number $y Posição vertical canto superior
3087
     * @return number Posição vertical final
3088
     *
3089
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3090
     */
3091
    protected function pCanhoto($x, $y)
3092
    {
3093
        $oldX = $x;
3094
        $oldY = $y;
3095
        //#################################################################################
3096
        //canhoto
3097
        //identificação do tipo de nf entrada ou saida
3098
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3099
        if ($tpNF == '0') {
3100
            //NFe de Entrada
3101
            $emitente = '';
3102
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3103
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3104
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3105
            $emitente .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3106
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3107
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3108
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3109
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3110
        } else {
3111
            //NFe de Saída
3112
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3113
            $destinatario = '';
3114
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3115
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3116
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3117
            $destinatario .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3118
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3119
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3120
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3121
        }
3122
        //identificação do sistema emissor
3123
        //linha separadora do canhoto
3124
        if ($this->orientacao == 'P') {
3125
            $w = round($this->wPrint * 0.81, 0);
3126
        } else {
3127
            //linha separadora do canhoto - 238
3128
            //posicao altura
3129
            $y = $this->wPrint-85;
3130
            //altura
3131
            $w = $this->wPrint-85-24;
3132
        }
3133
        $h = 10;
3134
        //desenha caixa
3135
        $texto = '';
3136
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3137
        $aFontSmall = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3138
        if ($this->orientacao == 'P') {
3139
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3140
        } else {
3141
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3142
        }
3143
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3144
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3145
        $texto = "RECEBEMOS DE ";
3146
        $texto .= $emitente;
3147
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3148
        if ($this->orientacao == 'P') {
3149
            $texto .= "ABAIXO";
3150
        } else {
3151
            $texto .= "AO LADO";
3152
        }
3153
        $texto .= ". EMISSÃO: ";
3154
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3155
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3156
        if ($dEmi == '') {
3157
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3158
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3159
            $aDemi = explode('T', $dEmi);
3160
            $dEmi = $aDemi[0];
3161
        }
3162
        $texto .= $this->pYmd2dmy($dEmi) ." ";
3163
        $texto .= "VALOR TOTAL: R$ ";
3164
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3165
        $texto .= "DESTINATÁRIO: ";
3166
        $texto .= $destinatario;
3167
        if ($this->orientacao == 'P') {
3168
            $this->pdf->textBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3169
            $x1 = $x + $w;
3170
            $w1 = $this->wPrint - $w;
3171
            $texto = "NF-e";
3172
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3173
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3174
            $texto = "Nº. " . $this->pFormat($numNF, "###.###.###") . " \n";
3175
            $texto .= "Série $serie";
3176
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3177
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3178
            //DATA DE RECEBIMENTO
3179
            $texto = "DATA DE RECEBIMENTO";
3180
            $y += $h;
3181
            $w2 = round($this->wPrint*0.17, 0); //35;
3182
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3183
            $this->pdf->textBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3184
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3185
            $x += $w2;
3186
            $w3 = $w-$w2;
3187
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3188
            $this->pdf->textBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3189
            $x = $oldX;
3190
            $y += 9;
3191
            $this->pdf->DashedHLine($x, $y, $this->wPrint, 0.1, 80);
3192
            $y += 2;
3193
            return $y;
3194
        } else {
3195
            $x--;
3196
            $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...
3197
            //NUMERO DA NOTA FISCAL LOGO NFE
3198
            $w1 = 18;
3199
            $x1 = $oldX;
3200
            $y = $oldY;
3201
            $texto = "NF-e";
3202
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3203
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3204
            $texto = "Nº.\n" . $this->pFormat($numNF, "###.###.###") . " \n";
3205
            $texto .= "Série $serie";
3206
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
3207
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3208
            //DATA DO RECEBIMENTO
3209
            $texto = "DATA DO RECEBIMENTO";
3210
            $y = $this->wPrint-85;
3211
            $x = 12;
3212
            $w2 = round($this->wPrint*0.17, 0); //35;
3213
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3214
            $this->pdf->textBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3215
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3216
            $y -= $w2;
3217
            $w3 = $w-$w2;
3218
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3219
            $aFont = ['font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''];
3220
            $x = $this->pdf->textBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3221
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3222
            return $x;
3223
        }
3224
    }
3225
3226
    /**
3227
     * geraInformacoesDaTagCompra
3228
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3229
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3230
     *
3231
     * @name   pGeraInformacoesDaTagCompra
3232
     * @return string com as informacoes dos pedidos.
3233
     */
3234
    protected function geraInformacoesDaTagCompra()
3235
    {
3236
        $saida = "";
3237
        if (isset($this->compra)) {
3238
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3239
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3240
            }
3241
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3242
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3243
            }
3244
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3245
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3246
            }
3247
        }
3248
        return $saida;
3249
    }
3250
3251
    /**
3252
     * pGeraChaveAdicionalDeContingencia
3253
     *
3254
     * @name   pGeraChaveAdicionalDeContingencia
3255
     * @return string chave
3256
     */
3257
    protected function pGeraChaveAdicionalDeContingencia()
3258
    {
3259
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3260
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
3261
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3262
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3263
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3264
        $CNPJ   = substr($CNPJ, -14);
3265
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3266
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3267
        if ($vICMS > 0) {
3268
            $vICMS = 1;
3269
        }
3270
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3271
        if ($icmss > 0) {
3272
            $icmss = 1;
3273
        }
3274
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3275
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3276
        if ($dEmi == '') {
3277
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3278
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3279
            $aDemi = explode('T', $dEmi);
3280
            $dEmi = $aDemi[0];
3281
        }
3282
        $dd  = $dEmi;
3283
        $rpos = strrpos($dd, '-');
3284
        $dd  = substr($dd, $rpos +1);
3285
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3286
        $chave = $chave . $this->pModulo11($chave);
3287
        return $chave;
3288
    }
3289
3290
    /**
3291
     *  geraInformacoesDasNotasReferenciadas
3292
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3293
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3294
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3295
     *
3296
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3297
     */
3298
    protected function geraInformacoesDasNotasReferenciadas()
3299
    {
3300
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3301
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3302
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3303
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3304
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3305
        $saida='';
3306
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3307
        if (0 === $nfRefs->length) {
3308
            return $saida;
3309
        }
3310
        if ($nfRefs->length > 2) {
3311
            return 'Existem mais de 2 NF/NFe/ECF/NFP/CTe referenciadas, não serão exibidas na DANFE.';
3312
        }
3313
        foreach ($nfRefs as $nfRef) {
3314
            if (empty($nfRef)) {
3315
                continue;
3316
            }
3317
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3318
            foreach ($refNFe as $chave_acessoRef) {
3319
                $chave_acesso = $chave_acessoRef->nodeValue;
3320
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3321
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3322
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3323
                $serie  = substr($chave_acesso, 22, 3);
3324
                $numero = substr($chave_acesso, 25, 9);
3325
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3326
            }
3327
            $refNF = $nfRef->getElementsByTagName('refNF');
3328
            foreach ($refNF as $umaRefNFe) {
3329
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3330
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3331
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3332
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3333
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3334
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3335
                $cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3336
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3337
            }
3338
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3339
            foreach ($refCTe as $chave_acessoRef) {
3340
                $chave_acesso = $chave_acessoRef->nodeValue;
3341
                $chave_acessoF = $this->pFormat($chave_acesso, $this->formatoChave);
3342
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3343
                $cnpj = $this->pFormat(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3344
                $serie  = substr($chave_acesso, 22, 3);
3345
                $numero = substr($chave_acesso, 25, 9);
3346
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3347
            }
3348
            $refECF = $nfRef->getElementsByTagName('refECF');
3349
            foreach ($refECF as $umaRefNFe) {
3350
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3351
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3352
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3353
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3354
            }
3355
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3356
            foreach ($refNFP as $umaRefNFe) {
3357
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3358
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3359
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3360
                    '';
3361
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3362
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3363
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3364
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3365
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3366
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3367
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3368
                if ($cnpj == '') {
3369
                    $cpf_cnpj = $this->pFormat($cpf, "###.###.###-##");
3370
                } else {
3371
                    $cpf_cnpj = $this->pFormat($cnpj, "##.###.###/####-##");
3372
                }
3373
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3374
            }
3375
        }
3376
        return $saida;
3377
    }
3378
    
3379
    private function imagePNGtoJPG($original)
3380
    {
3381
        $image = imagecreatefrompng($original);
3382
        ob_start();
3383
        imagejpeg($image, null, 100);
3384
        imagedestroy($image);
3385
        $stringdata = ob_get_contents(); // read from buffer
3386
        ob_end_clean();
3387
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3388
    }
3389
}
3390