Completed
Push — master ( 420ed5...551514 )
by Roberto
04:46 queued 02:22
created

Danfe::pAnfavea()   F

Complexity

Conditions 36
Paths > 20000

Size

Total Lines 139

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1332

Importance

Changes 0
Metric Value
cc 36
nc 2519426
nop 1
dl 0
loc 139
ccs 0
cts 133
cp 0
crap 1332
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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

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

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

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

class Id
{
    public $id;

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

}

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

$account_id = false;

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

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

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

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

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

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

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

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

$answer = 42;

$correct = false;

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

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

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

$answer = 42;

$correct = false;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

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

$answer = 42;

$correct = false;

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

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

$answer = 42;

$correct = false;

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

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

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

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

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

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

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

class MyClass { }

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

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

class MyClass {
    public $foo;
}

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

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

This assignement can be removed without consequences.

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

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

Let’s take a look at an example:

class Author {
    private $name;

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

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

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

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

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

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

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

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

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

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

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

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

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

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

Let’s take a look at an example:

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

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

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

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

Available Fixes

  1. Check for existence of the variable explicitly:

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

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

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1129
            //endereço
1130
            $y1 = $y1+5;
1131
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1132
            $fone = ! empty($this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue)
1133
                 ? $this->enderEmit->getElementsByTagName("fone")->item(0)->nodeValue
1134
                 : '';
1135
            $lgr = $this->getTagValue($this->enderEmit, "xLgr");
1136
            $nro = $this->getTagValue($this->enderEmit, "nro");
1137
            $cpl = $this->getTagValue($this->enderEmit, "xCpl", " - ");
1138
            $bairro = $this->getTagValue($this->enderEmit, "xBairro");
1139
            $CEP = $this->getTagValue($this->enderEmit, "CEP");
1140
            $CEP = $this->formatField($CEP, "#####-###");
1141
            $mun = $this->getTagValue($this->enderEmit, "xMun");
1142
            $UF = $this->getTagValue($this->enderEmit, "UF");
1143
            $texto = $lgr . ", " . $nro . $cpl . "\n" . $bairro . " - "
1144
                    . $CEP . "\n" . $mun . " - " . $UF . " "
1145
                    . "Fone/Fax: " . $fone;
1146
            $this->pdf->textBox($x1, $y1, $tw, 8, $texto, $aFont, 'T', 'C', 0, '');
1147
        }
1148
1149
        //####################################################################################
1150
        //coluna central Danfe
1151
        $x += $w;
1152
        $w=round($maxW * 0.17, 0);//35;
1153
        $w2 = $w;
1154
        $h = 32;
1155
        $this->pdf->textBox($x, $y, $w, $h);
1156
  
1157
        $texto = "DANFE";
1158
        $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
1159
        $this->pdf->textBox($x, $y+1, $w, $h, $texto, $aFont, 'T', 'C', 0, '');
1160
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1161
        $texto = 'Documento Auxiliar da Nota Fiscal Eletrônica';
1162
        $h = 20;
1163
        $this->pdf->textBox($x, $y+6, $w, $h, $texto, $aFont, 'T', 'C', 0, '', false);
1164
        
1165
1166
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1167
        $texto = '0 - ENTRADA';
1168
        $y1 = $y + 14;
1169
        $h = 8;
1170
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1171
        $texto = '1 - SAÍDA';
1172
        $y1 = $y + 17;
1173
        $this->pdf->textBox($x+2, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1174
        //tipo de nF
1175
        $aFont = ['font'=>$this->fontePadrao, 'size'=>12, 'style'=>'B'];
1176
        $y1 = $y + 13;
1177
        $h = 7;
1178
        $texto = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
1179
        $this->pdf->textBox($x+27, $y1, 5, $h, $texto, $aFont, 'C', 'C', 1, '');
1180
        //numero da NF
1181
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1182
        $y1 = $y + 20;
1183
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
1184
        $numNF = $this->formatField($numNF, "###.###.###");
1185
        $texto = "Nº. " . $numNF;
1186
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1187
        //Série
1188
        $y1 = $y + 23;
1189
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
1190
        $texto = "Série " . $serie;
1191
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1192
        //numero paginas
1193
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'I'];
1194
        $y1 = $y + 26;
1195
        $texto = "Folha " . $pag . "/" . $totPag;
1196
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'C', 'C', 0, '');
1197
1198
        //####################################################################################
1199
        //coluna codigo de barras
1200
        $x += $w;
1201
        $w = ($maxW-$w1-$w2);//85;
1202
        $w3 = $w;
1203
        $h = 32;
1204
        $this->pdf->textBox($x, $y, $w, $h);
1205
        $this->pdf->SetFillColor(0, 0, 0);
1206
        $chave_acesso = str_replace('NFe', '', $this->infNFe->getAttribute("Id"));
1207
        $bW = 75;
1208
        $bH = 12;
1209
        //codigo de barras
1210
        $this->pdf->Code128($x+(($w-$bW)/2), $y+2, $chave_acesso, $bW, $bH);
1211
        //linhas divisorias
1212
        $this->pdf->line($x, $y+4+$bH, $x+$w, $y+4+$bH);
1213
        $this->pdf->line($x, $y+12+$bH, $x+$w, $y+12+$bH);
1214
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1215
        $y1 = $y+4+$bH;
1216
        $h = 7;
1217
        $texto = 'CHAVE DE ACESSO';
1218
        $this->pdf->textBox($x, $y1, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
1219
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1220
        $y1 = $y+8+$bH;
1221
        $texto = $this->formatField($chave_acesso, $this->formatoChave);
1222
        $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1223
        $y1 = $y+12+$bH;
1224
        $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>''];
1225
        $chaveContingencia="";
1226
        if ($this->pNotaDPEC()) {
1227
            $cabecalhoProtoAutorizacao = 'NÚMERO DE REGISTRO DPEC';
1228
        } else {
1229
            $cabecalhoProtoAutorizacao = 'PROTOCOLO DE AUTORIZAÇÃO DE USO';
1230
        }
1231
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1232
            $cabecalhoProtoAutorizacao = "DADOS DA NF-E";
1233
            $chaveContingencia = $this->pGeraChaveAdicionalDeContingencia();
1234
            $this->pdf->setFillColor(0, 0, 0);
1235
            //codigo de barras
1236
            $this->pdf->code128($x+11, $y1+1, $chaveContingencia, $bW*.9, $bH/2);
1237
        } else {
1238
            $texto = 'Consulta de autenticidade no portal nacional da NF-e';
1239
            $this->pdf->textBox($x+2, $y1, $w-2, $h, $texto, $aFont, 'T', 'C', 0, '');
1240
            $y1 = $y+16+$bH;
1241
            $texto = 'www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora';
1242
            $this->pdf->textBox(
1243
                $x+2,
1244
                $y1,
1245
                $w-2,
1246
                $h,
1247
                $texto,
1248
                $aFont,
1249
                'T',
1250
                'C',
1251
                0,
1252
                'http://www.nfe.fazenda.gov.br/portal ou no site da Sefaz Autorizadora'
1253
            );
1254
        }
1255
1256
        //####################################################################################
1257
        //Dados da NF do cabeçalho
1258
        //natureza da operação
1259
        $texto = 'NATUREZA DA OPERAÇÃO';
1260
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1261
        $w = $w1+$w2;
1262
        $y = $oldY;
1263
        $oldY += $h;
1264
        $x = $oldX;
1265
        $h = 7;
1266
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
1267
        $texto = $this->ide->getElementsByTagName("natOp")->item(0)->nodeValue;
1268
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1269
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'C', 0, '');
1270
        $x += $w;
1271
        $w = $w3;
1272
        //PROTOCOLO DE AUTORIZAÇÃO DE USO ou DADOS da NF-E
1273
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
1274
        $this->pdf->textBox($x, $y, $w, $h, $cabecalhoProtoAutorizacao, $aFont, 'T', 'L', 1, '');
1275
        // algumas NFe podem estar sem o protocolo de uso portanto sua existencia deve ser
1276
        // testada antes de tentar obter a informação.
1277
        // NOTA : DANFE sem protocolo deve existir somente no caso de contingência !!!
1278
        // Além disso, existem várias NFes em contingência que eu recebo com protocolo de autorização.
1279
        // Na minha opinião, deveríamos mostra-lo, mas o  manual  da NFe v4.01 diz outra coisa...
1280
        if (($this->tpEmis == 2 || $this->tpEmis == 5) && !$this->pNotaDPEC()) {
1281
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
1282
            $texto = $this->formatField($chaveContingencia, "#### #### #### #### #### #### #### #### ####");
1283
            $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

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

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

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

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

Loading history...
1284
        } else {
1285
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
1286
            if ($this->pNotaDPEC()) {
1287
                $texto = $this->numero_registro_dpec;
1288
                $cStat = '';
0 ignored issues
show
Unused Code introduced by
$cStat is not used, you could remove the assignment.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
2271
        $pesoBruto=0;
2272
        $pesoLiquido=0;
2273
        foreach ($volumes as $volume) {
2274
            $quantidade += ! empty($volume->getElementsByTagName("qVol")->item(0)->nodeValue) ?
2275
                    $volume->getElementsByTagName("qVol")->item(0)->nodeValue : 0;
2276
            $pesoBruto += ! empty($volume->getElementsByTagName("pesoB")->item(0)->nodeValue) ?
2277
                    $volume->getElementsByTagName("pesoB")->item(0)->nodeValue : 0;
2278
            $pesoLiquido += ! empty($volume->getElementsByTagName("pesoL")->item(0)->nodeValue) ?
2279
                    $volume->getElementsByTagName("pesoL")->item(0)->nodeValue : 0;
2280
            $texto = ! empty($this->transp->getElementsByTagName("esp")->item(0)->nodeValue) ?
2281
                    $this->transp->getElementsByTagName("esp")->item(0)->nodeValue : '';
2282
            if ($texto != $especie && $especie != '') {
2283
                //tem várias especies
2284
                $especie = 'VARIAS';
2285
            } else {
2286
                $especie = $texto;
2287
            }
2288
            $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2289
                    $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2290
            if ($texto != $marca && $marca != '') {
2291
                //tem várias especies
2292
                $marca = 'VARIAS';
2293
            } else {
2294
                $marca = $texto;
2295
            }
2296
            $texto = ! empty($this->transp->getElementsByTagName("nVol")->item(0)->nodeValue) ?
2297
                    $this->transp->getElementsByTagName("nVol")->item(0)->nodeValue : '';
2298
            if ($texto != $numero && $numero != '') {
2299
                //tem várias especies
2300
                $numero = 'VARIOS';
2301
            } else {
2302
                $numero = $texto;
2303
            }
2304
        }
2305
2306
        //#####################################################################
2307
        //QUANTIDADE
2308
        $y += $h;
2309
        $x = $oldX;
2310
        $h = 7;
2311
        $w1 = round($maxW*0.10, 0);
2312
        $texto = 'QUANTIDADE';
2313
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2314
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'L', 1, '');
2315
        if (!empty($quantidade)) {
2316
            $texto = $quantidade;
2317
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2318
            $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'B', 'C', 0, '');
2319
        }
2320
        //ESPÉCIE
2321
        $x += $w1;
2322
        $w2 = round($maxW*0.17, 0);
2323
        $texto = 'ESPÉCIE';
2324
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2325
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2326
        $texto = $especie;
2327
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2328
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2329
        //MARCA
2330
        $x += $w2;
2331
        $texto = 'MARCA';
2332
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2333
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2334
        $texto = ! empty($this->transp->getElementsByTagName("marca")->item(0)->nodeValue) ?
2335
                $this->transp->getElementsByTagName("marca")->item(0)->nodeValue : '';
2336
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2337
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2338
        //NUMERAÇÃO
2339
        $x += $w2;
2340
        $texto = 'NUMERAÇÃO';
2341
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2342
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'T', 'L', 1, '');
2343
        $texto = $numero;
2344
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2345
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'B', 'C', 0, '');
2346
        //PESO BRUTO
2347
        $x += $w2;
2348
        $w3 = round($maxW*0.20, 0);
2349
        $texto = 'PESO BRUTO';
2350
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2351
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'L', 1, '');
2352
        if (is_numeric($pesoBruto) && $pesoBruto > 0) {
2353
            $texto = number_format($pesoBruto, 3, ",", ".");
2354
        } else {
2355
            $texto = '';
2356
        }
2357
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2358
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'B', 'R', 0, '');
2359
        //PESO LÍQUIDO
2360
        $x += $w3;
2361
        $w = $maxW -($w1+3*$w2+$w3);
2362
        $texto = 'PESO LÍQUIDO';
2363
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2364
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2365
        if (is_numeric($pesoLiquido) && $pesoLiquido > 0) {
2366
            $texto = number_format($pesoLiquido, 3, ",", ".");
2367
        } else {
2368
            $texto = '';
2369
        }
2370
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2371
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2372
        return ($y+$h);
2373
    } //fim transporteDANFE
2374
2375
2376
2377
    protected function descricaoProdutoHelper($origem, $campo, $formato)
2378
    {
2379
        $valor_original = $origem->getElementsByTagName($campo)->item(0);
2380
        if (!isset($valor_original)) {
2381
            return "";
2382
        }
2383
        $valor_original = $valor_original->nodeValue;
2384
        $valor = ! empty($valor_original) ? number_format($valor_original, 2, ",", ".") : '';
2385
2386
        if ($valor != "") {
2387
            return sprintf($formato, $valor);
2388
        }
2389
        return "";
2390
    }
2391
2392
    /**
2393
     * descricaoProduto
2394
     * Monta a string de descrição de cada Produto
2395
     *
2396
     * @name   descricaoProduto
2397
     * @param  DOMNode itemProd
2398
     * @return string descricao do produto
2399
     */
2400
    protected function descricaoProduto($itemProd)
2401
    {
2402
        $prod = $itemProd->getElementsByTagName('prod')->item(0);
2403
        $ICMS = $itemProd->getElementsByTagName("ICMS")->item(0);
2404
        $ICMSUFDest = $itemProd->getElementsByTagName("ICMSUFDest")->item(0);
2405
        $impostos = '';
2406
2407
        if (!empty($ICMS)) {
2408
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCP", " BcFcp=%s");
2409
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCP", " pFcp=%s%%");
2410
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCP", " vFcp=%s");
2411
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pRedBC", " pRedBC=%s%%");
2412
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pMVAST", " IVA/MVA=%s%%");
2413
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pICMSST", " pIcmsSt=%s%%");
2414
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCST", " BcIcmsSt=%s");
2415
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSST", " vIcmsSt=%s");
2416
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCFCPST", " BcFcpSt=%s");
2417
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pFCPST", " pFcpSt=%s%%");
2418
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vFCPST", " vFcpSt=%s");
2419
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vBCSTRet", " vBcStRet=%s");
2420
            $impostos .= $this->descricaoProdutoHelper($ICMS, "pST", " pSt=%s");
2421
            $impostos .= $this->descricaoProdutoHelper($ICMS, "vICMSSTRet", " vIcmsStRet=%s");
2422
        }
2423
        if (!empty($ICMSUFDest)) {
2424
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pFCPUFDest", " pFCPUFDest=%s%%");
2425
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSUFDest", " pICMSUFDest=%s%%");
2426
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "pICMSInterPart", " pICMSInterPart=%s%%");
2427
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vFCPUFDest", " vFCPUFDest=%s");
2428
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFDest", " vICMSUFDest=%s");
2429
            $impostos .= $this->descricaoProdutoHelper($ICMSUFDest, "vICMSUFRemet", " vICMSUFRemet=%s");
2430
        }
2431
        $infAdProd = ! empty($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue)
2432
            ? substr(
2433
                $this->anfaveaDANFE($itemProd->getElementsByTagName('infAdProd')->item(0)->nodeValue),
2434
                0,
2435
                500
2436
            )
2437
            : '';
2438
        if (! empty($infAdProd)) {
2439
            $infAdProd = trim($infAdProd);
2440
            $infAdProd .= ' ';
2441
        }
2442
        $loteTxt ='';
2443
        $rastro = $prod->getElementsByTagName("med");
2444
        if (!isset($rastro)) {
2445
            $rastro = $prod->getElementsByTagName("rastro");
2446
        }
2447
        if (isset($rastro)) {
2448
            $i = 0;
2449
            while ($i < $rastro->length) {
2450
                $loteTxt .= $this->getTagValue($rastro->item($i), 'nLote', ' Lote: ');
2451
                $loteTxt .= $this->getTagValue($rastro->item($i), 'qLote', ' Quant: ');
2452
                $loteTxt .= $this->simpleGetDate($rastro->item($i), 'dFab', ' Fab: ');
2453
                $loteTxt .= $this->simpleGetDate($rastro->item($i), 'dVal', ' Val: ');
2454
                $loteTxt .= $this->getTagValue($rastro->item($i), 'vPMC', ' PMC: ');
2455
                $i++;
2456
            }
2457
            if ($loteTxt != '') {
2458
                $loteTxt.= ' ';
2459
            }
2460
        }
2461
        //NT2013.006 FCI
2462
        $nFCI = (! empty($itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue)) ?
2463
                ' FCI:'.$itemProd->getElementsByTagName('nFCI')->item(0)->nodeValue : '';
2464
        $tmp_ad=$infAdProd . ($this->descProdInfoComplemento ? $loteTxt . $impostos . $nFCI : '');
2465
        $texto = $prod->getElementsByTagName("xProd")->item(0)->nodeValue . (strlen($tmp_ad)!=0?"\n    ".$tmp_ad:'');
2466
        //decodifica os caracteres html no xml
2467
        $texto = html_entity_decode($texto);
2468
        if ($this->descProdQuebraLinha) {
2469
            $texto = str_replace(";", "\n", $texto);
2470
        }
2471
        return $texto;
2472
    }
2473
2474
    /**
2475
     * itensDANFE
2476
     * Monta o campo de itens da DANFE (retrato e paisagem)
2477
     *
2478
     * @name   itensDANFE
2479
     * @param  float $x       Posição horizontal canto esquerdo
2480
     * @param  float $y       Posição vertical canto superior
2481
     * @param  float $nInicio Número do item inicial
2482
     * @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...
2483
     * @param  float $hmax    Altura máxima do campo de itens em mm
2484
     * @return float Posição vertical final
2485
     */
2486
    protected function itensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0, $hCabecItens = 7)
2487
    {
2488
        $oldX = $x;
2489
        $oldY = $y;
2490
        $totItens = $this->det->length;
2491
        //#####################################################################
2492
        //DADOS DOS PRODUTOS / SERVIÇOS
2493
        $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
2494
        if ($this->orientacao == 'P') {
2495
            $w = $this->wPrint;
2496
        } else {
2497
            if ($nInicio < 2) { // primeira página
2498
                $w = $this->wPrint - $this->wCanhoto;
2499
            } else { // páginas seguintes
2500
                $w = $this->wPrint;
2501
            }
2502
        }
2503
        $h = 4;
2504
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2505
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2506
        $y += 3;
2507
        //desenha a caixa dos dados dos itens da NF
2508
        $hmax += 1;
2509
        $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...
2510
        $this->pdf->textBox($x, $y, $w, $hmax);
2511
        //##################################################################################
2512
        // cabecalho LOOP COM OS DADOS DOS PRODUTOS
2513
        //CÓDIGO PRODUTO
2514
        $texto = "CÓDIGO PRODUTO";
2515
        $w1 = round($w*0.09, 0);
2516
        $h = 4;
2517
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2518
        $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2519
        $this->pdf->line($x+$w1, $y, $x+$w1, $y+$hmax);
2520
        //DESCRIÇÃO DO PRODUTO / SERVIÇO
2521
        $x += $w1;
2522
        $w2 = round($w*0.28, 0);
2523
        $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
2524
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2525
        $this->pdf->textBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2526
        $this->pdf->line($x+$w2, $y, $x+$w2, $y+$hmax);
2527
        //NCM/SH
2528
        $x += $w2;
2529
        $w3 = round($w*0.06, 0);
2530
        $texto = 'NCM/SH';
2531
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2532
        $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2533
        $this->pdf->line($x+$w3, $y, $x+$w3, $y+$hmax);
2534
        //O/CST ou O/CSOSN
2535
        $x += $w3;
2536
        $w4 = round($w*0.05, 0);
2537
        $texto = 'O/CSOSN';//Regime do Simples CRT = 1 ou CRT = 2
2538
        if ($this->getTagValue($this->emit, 'CRT') == '3') {
2539
             $texto = 'O/CST';//Regime Normal
2540
        }
2541
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2542
        $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2543
        $this->pdf->line($x+$w4, $y, $x+$w4, $y+$hmax);
2544
        //CFOP
2545
        $x += $w4;
2546
        $w5 = round($w*0.04, 0);
2547
        $texto = 'CFOP';
2548
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2549
        $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2550
        $this->pdf->line($x+$w5, $y, $x+$w5, $y+$hmax);
2551
        //UN
2552
        $x += $w5;
2553
        $w6 = round($w*0.03, 0);
2554
        $texto = 'UN';
2555
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2556
        $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2557
        $this->pdf->line($x+$w6, $y, $x+$w6, $y+$hmax);
2558
        //QUANT
2559
        $x += $w6;
2560
        $w7 = round($w*0.07, 0);
2561
        $texto = 'QUANT';
2562
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2563
        $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2564
        $this->pdf->line($x+$w7, $y, $x+$w7, $y+$hmax);
2565
        //VALOR UNIT
2566
        $x += $w7;
2567
        $w8 = round($w*0.06, 0);
2568
        $texto = 'VALOR UNIT';
2569
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2570
        $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2571
        $this->pdf->line($x+$w8, $y, $x+$w8, $y+$hmax);
2572
        //VALOR TOTAL
2573
        $x += $w8;
2574
        $w9 = round($w*0.06, 0);
2575
        $texto = 'VALOR TOTAL';
2576
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2577
        $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2578
        $this->pdf->line($x+$w9, $y, $x+$w9, $y+$hmax);
2579
        //B.CÁLC ICMS
2580
        $x += $w9;
2581
        $w10 = round($w*0.06, 0);
2582
        $texto = 'B.CÁLC ICMS';
2583
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2584
        $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2585
        $this->pdf->line($x+$w10, $y, $x+$w10, $y+$hmax);
2586
        //VALOR ICMS
2587
        $x += $w10;
2588
        $w11 = round($w*0.06, 0);
2589
        $texto = 'VALOR ICMS';
2590
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2591
        $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2592
        $this->pdf->line($x+$w11, $y, $x+$w11, $y+$hmax);
2593
        //VALOR IPI
2594
        $x += $w11;
2595
        $w12 = round($w*0.05, 0);
2596
        $texto = 'VALOR IPI';
2597
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2598
        $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2599
        $this->pdf->line($x+$w12, $y, $x+$w12, $y+$hmax);
2600
        //ALÍQ. ICMS
2601
        $x += $w12;
2602
        $w13 = round($w*0.035, 0);
2603
        $texto = 'ALÍQ. ICMS';
2604
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2605
        $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2606
        $this->pdf->line($x+$w13, $y, $x+$w13, $y+$hmax);
2607
        //ALÍQ. IPI
2608
        $x += $w13;
2609
        $w14 = $w-($w1+$w2+$w3+$w4+$w5+$w6+$w7+$w8+$w9+$w10+$w11+$w12+$w13);
2610
        $texto = 'ALÍQ. IPI';
2611
        $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
2612
        $this->pdf->line($oldX, $y+$h+1, $oldX + $w, $y+$h+1);
2613
        $y += 5;
2614
        //##################################################################################
2615
        // LOOP COM OS DADOS DOS PRODUTOS
2616
        $i = 0;
2617
        $hUsado = $hCabecItens;
2618
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2619
        foreach ($this->det as $d) {
2620
            if ($i >= $nInicio) {
2621
                $thisItem = $this->det->item($i);
2622
                //carrega as tags do item
2623
                $prod = $thisItem->getElementsByTagName("prod")->item(0);
2624
                $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
2625
                $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
2626
                $IPI  = $imposto->getElementsByTagName("IPI")->item(0);
2627
                $textoProduto = trim($this->descricaoProduto($thisItem));
2628
2629
                $linhaDescr = $this->pdf->getNumLines($textoProduto, $w2, $aFont);
2630
                $h = round(($linhaDescr * $this->pdf->fontSize)+ ($linhaDescr * 0.5), 2);
2631
                $hUsado += $h;
2632
2633
                $diffH = $hmax - $hUsado;
2634
2635
                if ($pag != $totpag) {
2636
                    if (1 > $diffH && $i < $totItens) {
2637
                        //ultrapassa a capacidade para uma única página
2638
                        //o restante dos dados serão usados nas proximas paginas
2639
                        $nInicio = $i;
2640
                        break;
2641
                    }
2642
                }
2643
                $y_linha=$y+$h;
2644
                // linha entre itens
2645
                $this->pdf->dashedHLine($oldX, $y_linha, $w, 0.1, 120);
2646
                //corrige o x
2647
                $x=$oldX;
2648
                //codigo do produto
2649
                $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
2650
                $this->pdf->textBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
2651
                $x += $w1;
2652
                //DESCRIÇÃO
2653
                if ($this->orientacao == 'P') {
2654
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2655
                } else {
2656
                    $this->pdf->textBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
2657
                }
2658
                $x += $w2;
2659
                //NCM
2660
                $texto = ! empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ?
2661
                        $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
2662
                $this->pdf->textBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
2663
                $x += $w3;
2664
                //CST
2665
                if (isset($ICMS)) {
2666
                    $origem =  $this->getTagValue($ICMS, "orig");
2667
                    $cst =  $this->getTagValue($ICMS, "CST");
2668
                    $csosn =  $this->getTagValue($ICMS, "CSOSN");
2669
                    $texto = $origem.$cst.$csosn;
2670
                    $this->pdf->textBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
2671
                }
2672
                //CFOP
2673
                $x += $w4;
2674
                $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
2675
                $this->pdf->textBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
2676
                //Unidade
2677
                $x += $w5;
2678
                $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
2679
                $this->pdf->textBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
2680
                $x += $w6;
2681
                if ($this->orientacao == 'P') {
2682
                    $alinhamento = 'R';
2683
                } else {
2684
                    $alinhamento = 'R';
2685
                }
2686
                // QTDADE
2687
                $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
2688
                $this->pdf->textBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2689
                $x += $w7;
2690
                // Valor Unitário
2691
                $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
2692
                $this->pdf->textBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2693
                $x += $w8;
2694
                // Valor do Produto
2695
                $texto = "";
2696
                if (is_numeric($prod->getElementsByTagName("vProd")->item(0)->nodeValue)) {
2697
                    $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
2698
                }
2699
                $this->pdf->textBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2700
                //Valor da Base de calculo
2701
                $x += $w9;
2702
                if (isset($ICMS)) {
2703
                    $texto = ! empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ?
2704
                            number_format(
2705
                                $ICMS->getElementsByTagName("vBC")->item(0)->nodeValue,
2706
                                2,
2707
                                ",",
2708
                                "."
2709
                            ) : '0, 00';
2710
                    $this->pdf->textBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2711
                }
2712
                //Valor do ICMS
2713
                $x += $w10;
2714
                if (isset($ICMS)) {
2715
                    $texto = ! empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ?
2716
                            number_format(
2717
                                $ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue,
2718
                                2,
2719
                                ",",
2720
                                "."
2721
                            ) : '0, 00';
2722
                    $this->pdf->textBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2723
                }
2724
                //Valor do IPI
2725
                $x += $w11;
2726
                if (isset($IPI)) {
2727
                    $texto = ! empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ?
2728
                            number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") :'';
2729
                } else {
2730
                    $texto = '';
2731
                }
2732
                $this->pdf->textBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
2733
                // %ICMS
2734
                $x += $w12;
2735
                if (isset($ICMS)) {
2736
                    $texto = ! empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ?
2737
                            number_format(
2738
                                $ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue,
2739
                                2,
2740
                                ",",
2741
                                "."
2742
                            ) : '0, 00';
2743
                    $this->pdf->textBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
2744
                }
2745
                //%IPI
2746
                $x += $w13;
2747
                if (isset($IPI)) {
2748
                    $texto = ! empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ?
2749
                            number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
2750
                } else {
2751
                    $texto = '';
2752
                }
2753
                $this->pdf->textBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
2754
2755
2756
                // Dados do Veiculo Somente para veiculo 0 Km
2757
                $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2758
                // Tag somente é gerada para veiculo 0k, e só é permitido um veiculo por NF-e por conta do detran
2759
                // Verifica se a Tag existe
2760
                if (!empty($veicProd)) {
2761
                    $this->dadosItenVeiculoDANFE($oldX, $y, $nInicio, $h, $prod);
2762
                }
2763
2764
2765
                $y += $h;
2766
                $i++;
2767
                //incrementa o controle dos itens processados.
2768
                $this->qtdeItensProc++;
2769
            } else {
2770
                $i++;
2771
            }
2772
        }
2773
        return $oldY+$hmax;
2774
    }
2775
2776
2777
    /**
2778
     * dadosItenVeiculoDANFE
2779
     * Coloca os dados do veiculo abaixo do item da NFe. (retrato e paisagem)
2780
     *
2781
     * @param float  $x    Posição horizontal
2782
     *                     canto esquerdo
2783
     * @param float  $y    Posição vertical
2784
     *                     canto superior
2785
     * @param        $nInicio
2786
     * @param float  $h    altura do campo
2787
     * @param object $prod Contendo todos os dados do item
2788
     */
2789
2790
    protected function dadosItenVeiculoDANFE($x, $y, &$nInicio, $h, $prod)
2791
    {
2792
        $oldX = $x;
2793
        $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...
2794
2795
        if ($this->orientacao == 'P') {
2796
            $w = $this->wPrint;
2797
        } else {
2798
            if ($nInicio < 2) { // primeira página
2799
                $w = $this->wPrint - $this->wCanhoto;
2800
            } else { // páginas seguintes
2801
                $w = $this->wPrint;
2802
            }
2803
        }
2804
2805
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
2806
2807
        $w1 = round($w*0.09, 0);
2808
2809
        // Tabela Renavam Combustivel
2810
        $renavamCombustivel = [
2811
            1=>'ALCOOL',
2812
            2=>'GASOLINA',
2813
            3=>'DIESEL',
2814
            4=>'GASOGENIO',
2815
            5=>'GAS METANO',
2816
            6=>'ELETRICO/FONTE INTERNA',
2817
            7=>'ELETRICO/FONTE EXTERNA',
2818
            8=>'GASOL/GAS NATURAL COMBUSTIVEL',
2819
            9=>'ALCOOL/GAS NATURAL COMBUSTIVEL',
2820
            10=>'DIESEL/GAS NATURAL COMBUSTIVEL',
2821
            11=>'VIDE/CAMPO/OBSERVACAO',
2822
            12=>'ALCOOL/GAS NATURAL VEICULAR',
2823
            13=>'GASOLINA/GAS NATURAL VEICULAR',
2824
            14=>'DIESEL/GAS NATURAL VEICULAR',
2825
            15=>'GAS NATURAL VEICULAR',
2826
            16=>'ALCOOL/GASOLINA',
2827
            17=>'GASOLINA/ALCOOL/GAS NATURAL',
2828
            18=>'GASOLINA/ELETRICO'
2829
        ];
2830
2831
        $renavamEspecie = [
2832
            1=>'PASSAGEIRO',
2833
            2=>'CARGA',
2834
            3=>'MISTO',
2835
            4=>'CORRIDA',
2836
            5=>'TRACAO',
2837
            6=>'ESPECIAL',
2838
            7=>'COLECAO'
2839
        ];
2840
2841
        $renavamTiposVeiculos = [
2842
            1=>'BICICLETA',
2843
            2=>'CICLOMOTOR',
2844
            3=>'MOTONETA',
2845
            4=>'MOTOCICLETA',
2846
            5=>'TRICICLO',
2847
            6=>'AUTOMOVEL',
2848
            7=>'MICROONIBUS',
2849
            8=>'ONIBUS',
2850
            9=>'BONDE',
2851
            10=>'REBOQUE',
2852
            11=>'SEMI-REBOQUE',
2853
            12=>'CHARRETE',
2854
            13=>'CAMIONETA',
2855
            14=>'CAMINHAO',
2856
            15=>'CARROCA',
2857
            16=>'CARRO DE MAO',
2858
            17=>'CAMINHAO TRATOR',
2859
            18=>'TRATOR DE RODAS',
2860
            19=>'TRATOR DE ESTEIRAS',
2861
            20=>'TRATOR MISTO',
2862
            21=>'QUADRICICLO',
2863
            22=>'CHASSI/PLATAFORMA',
2864
            23=>'CAMINHONETE',
2865
            24=>'SIDE-CAR',
2866
            25=>'UTILITARIO',
2867
            26=>'MOTOR-CASA'
2868
        ];
2869
2870
        $renavamTipoPintura = [
2871
            'F'=>'FOSCA',
2872
            'S'=>'SÓLIDA',
2873
            'P'=>'PEROLIZADA',
2874
            'M'=>'METALICA',
2875
        ];
2876
2877
        $veicProd = $prod->getElementsByTagName("veicProd")->item(0);
2878
2879
        $veiculoChassi = $veicProd->getElementsByTagName("chassi")->item(0)->nodeValue;
2880
        $veiculoCor = $veicProd->getElementsByTagName("xCor")->item(0)->nodeValue;
2881
        $veiculoCilindrada = $veicProd->getElementsByTagName("cilin")->item(0)->nodeValue;
2882
        $veiculoCmkg = $veicProd->getElementsByTagName("CMT")->item(0)->nodeValue;
2883
        $veiculoTipo = $veicProd->getElementsByTagName("tpVeic")->item(0)->nodeValue;
2884
2885
        $veiculoMotor = $veicProd->getElementsByTagName("nMotor")->item(0)->nodeValue;
2886
        $veiculoRenavam = $veicProd->getElementsByTagName("cMod")->item(0)->nodeValue;
2887
        $veiculoHp = $veicProd->getElementsByTagName("pot")->item(0)->nodeValue;
2888
        $veiculoPlaca = ''; //$veiculo->getElementsByTagName("CMT")->item(0)->nodeValue;
2889
        $veiculoTipoPintura = $veicProd->getElementsByTagName("tpPint")->item(0)->nodeValue;
2890
2891
        $veiculoMarcaModelo = $prod->getElementsByTagName("xProd")->item(0)->nodeValue;
2892
        $veiculoEspecie = $veicProd->getElementsByTagName("espVeic")->item(0)->nodeValue;
2893
        $veiculoCombustivel = $veicProd->getElementsByTagName("tpComb")->item(0)->nodeValue;
2894
        $veiculoSerial = $veicProd->getElementsByTagName("nSerie")->item(0)->nodeValue;
2895
        $veiculoFabricacao = $veicProd->getElementsByTagName("anoFab")->item(0)->nodeValue;
2896
        $veiculoModelo = $veicProd->getElementsByTagName("anoMod")->item(0)->nodeValue;
2897
2898
        $veiculoDistancia = $veicProd->getElementsByTagName("dist")->item(0)->nodeValue;
2899
2900
        $x = $oldX;
2901
2902
        $yVeic = $y + $h;
2903
        $texto = 'Chassi: ............: ' . $veiculoChassi;
2904
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2905
        $yVeic += $h;
2906
        $texto = 'Cor...................: ' . $veiculoCor;
2907
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2908
        $yVeic += $h;
2909
        $texto = 'Cilindrada........: ' . $veiculoCilindrada;
2910
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2911
        $yVeic += $h;
2912
        $texto = 'Cmkg...............: ' . $veiculoCmkg;
2913
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2914
        $yVeic += $h;
2915
        $texto = 'Tipo.................: ' . $renavamTiposVeiculos[intval($veiculoTipo)];
2916
        $this->pdf->textBox($x, $yVeic, $w1+40, $h, $texto, $aFont, 'T', 'L', 0, '');
2917
        $yVeic = $y + $h;
2918
        $xVeic = $x + 65;
2919
        $texto = 'Nº Motor: .........: ' . $veiculoMotor;
2920
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2921
        $yVeic += $h;
2922
        $texto = 'Renavam...........: ' . $veiculoRenavam;
2923
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2924
        $yVeic += $h;
2925
        $texto = 'HP.....................: ' . $veiculoHp;
2926
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2927
        $yVeic += $h;
2928
        $texto = 'Placa.................: ' . $veiculoPlaca;
2929
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2930
        $yVeic += $h;
2931
        $texto = 'Tipo Pintura......: ' . $renavamTipoPintura[$veiculoTipoPintura];
2932
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2933
        $yVeic = $y + $h;
2934
        $xVeic = $xVeic + 55;
2935
        $texto = 'Marca / Modelo.....: ' . $veiculoMarcaModelo;
2936
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2937
        $yVeic += $h;
2938
        $texto = 'Especie..................: ' . $renavamEspecie[intval($veiculoEspecie)];
2939
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2940
        $yVeic += $h;
2941
        $texto = 'Combustivel..........: ' . $renavamCombustivel[intval($veiculoCombustivel)];
2942
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2943
        $yVeic += $h;
2944
        $texto = 'Serial.....................: ' . $veiculoSerial;
2945
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2946
        $yVeic += $h;
2947
        $texto = 'Ano Fab/Mod........: '. $veiculoFabricacao . '/' . $veiculoModelo;
2948
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2949
        $yVeic += $h;
2950
        $texto = 'Distancia Entre Eixos(mm)..: '. $veiculoDistancia;
2951
        $this->pdf->textBox($xVeic, $yVeic, $w1+50, $h, $texto, $aFont, 'T', 'L', 0, '');
2952
    }
2953
2954
    /**
2955
     * issqnDANFE
2956
     * Monta o campo de serviços do DANFE
2957
     *
2958
     * @name   issqnDANFE (retrato e paisagem)
2959
     * @param  float $x Posição horizontal canto esquerdo
2960
     * @param  float $y Posição vertical canto superior
2961
     * @return float Posição vertical final
2962
     */
2963
    protected function issqnDANFE($x, $y)
2964
    {
2965
        $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...
2966
        //#####################################################################
2967
        //CÁLCULO DO ISSQN
2968
        $texto = "CÁLCULO DO ISSQN";
2969
        $w = $this->wPrint;
2970
        $h = 7;
2971
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
2972
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
2973
        //INSCRIÇÃO MUNICIPAL
2974
        $y += 3;
2975
        $w = round($this->wPrint*0.23, 0);
2976
        $texto = 'INSCRIÇÃO MUNICIPAL';
2977
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2978
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2979
        //inscrição municipal
2980
        $texto = ! empty($this->emit->getElementsByTagName("IM")->item(0)->nodeValue) ?
2981
                $this->emit->getElementsByTagName("IM")->item(0)->nodeValue : '';
2982
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2983
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'L', 0, '');
2984
        //VALOR TOTAL DOS SERVIÇOS
2985
        $x += $w;
2986
        $texto = 'VALOR TOTAL DOS SERVIÇOS';
2987
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
2988
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
2989
        if (isset($this->ISSQNtot)) {
2990
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue) ?
2991
                    $this->ISSQNtot->getElementsByTagName("vServ")->item(0)->nodeValue : '';
2992
            $texto = number_format($texto, 2, ",", ".");
2993
        } else {
2994
            $texto = '';
2995
        }
2996
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
2997
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
2998
        //BASE DE CÁLCULO DO ISSQN
2999
        $x += $w;
3000
        $texto = 'BASE DE CÁLCULO DO ISSQN';
3001
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3002
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3003
        if (isset($this->ISSQNtot)) {
3004
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue) ?
3005
                    $this->ISSQNtot->getElementsByTagName("vBC")->item(0)->nodeValue : '';
3006
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3007
        } else {
3008
            $texto = '';
3009
        }
3010
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3011
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3012
        //VALOR TOTAL DO ISSQN
3013
        $x += $w;
3014
        if ($this->orientacao == 'P') {
3015
            $w = $this->wPrint - (3 * $w);
3016
        } else {
3017
            $w = $this->wPrint - (3 * $w)-$this->wCanhoto;
3018
        }
3019
        $texto = 'VALOR TOTAL DO ISSQN';
3020
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3021
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3022
        if (isset($this->ISSQNtot)) {
3023
            $texto = ! empty($this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue) ?
3024
                    $this->ISSQNtot->getElementsByTagName("vISS")->item(0)->nodeValue : '';
3025
            $texto = ! empty($texto) ? number_format($texto, 2, ",", ".") : '';
3026
        } else {
3027
            $texto = '';
3028
        }
3029
        $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3030
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'B', 'R', 0, '');
3031
        return ($y+$h+1);
3032
    }
3033
3034
    /**
3035
     *dadosAdicionaisDANFE
3036
     * Coloca o grupo de dados adicionais da NFe. (retrato e paisagem)
3037
     *
3038
     * @name   dadosAdicionaisDANFE
3039
     * @param  float $x Posição horizontal canto esquerdo
3040
     * @param  float $y Posição vertical canto superior
3041
     * @param  float $h altura do campo
3042
     * @return float Posição vertical final (eixo Y)
3043
     */
3044
    protected function dadosAdicionaisDANFE($x, $y, $h)
3045
    {
3046
        //##################################################################################
3047
        //DADOS ADICIONAIS
3048
        $texto = "DADOS ADICIONAIS";
3049
        if ($this->orientacao == 'P') {
3050
              $w = $this->wPrint;
3051
        } else {
3052
              $w = $this->wPrint-$this->wCanhoto;
3053
        }
3054
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>'B'];
3055
        $this->pdf->textBox($x, $y, $w, 8, $texto, $aFont, 'T', 'L', 0, '');
3056
        //INFORMAÇÕES COMPLEMENTARES
3057
        $texto = "INFORMAÇÕES COMPLEMENTARES";
3058
        $y += 3;
3059
        $w = $this->wAdic;
3060
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3061
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3062
        //o texto com os dados adicionais foi obtido na função montaDANFE
3063
        //e carregado em uma propriedade privada da classe
3064
        //$this->wAdic com a largura do campo
3065
        //$this->textoAdic com o texto completo do campo
3066
        $y += 1;
3067
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3068
        $this->pdf->textBox($x, $y+2, $w-2, $h-3, $this->textoAdic, $aFont, 'T', 'L', 0, '', false);
3069
        //RESERVADO AO FISCO
3070
        $texto = "RESERVADO AO FISCO";
3071
        $x += $w;
3072
        $y -= 1;
3073
        if ($this->orientacao == 'P') {
3074
            $w = $this->wPrint-$w;
3075
        } else {
3076
            $w = $this->wPrint-$w-$this->wCanhoto;
3077
        }
3078
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'B'];
3079
        $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 1, '');
3080
        //inserir texto informando caso de contingência
3081
        // 1 - Normal - emissão normal;
3082
        // 2 - Contingência FS - emissão em contingência com impressão do DANFE em Formulário de Segurança;
3083
        // 3 - Contingência SCAN - emissão em contingência no Sistema de Contingência do Ambiente Nacional;
3084
        // 4 - Contingência DPEC - emissão em contingência com envio da Declaração
3085
        //     Prévia de Emissão em Contingência;
3086
        // 5 - Contingência FS-DA - emissão em contingência com impressão do DANFE em Formulário de
3087
        //     Segurança para Impressão de Documento Auxiliar de Documento Fiscal Eletrônico (FS-DA);
3088
        // 6 - Contingência SVC-AN
3089
        // 7 - Contingência SVC-RS
3090
        $xJust = $this->getTagValue($this->ide, 'xJust', 'Justificativa: ');
3091
        $dhCont = $this->getTagValue($this->ide, 'dhCont', ' Entrada em contingência : ');
3092
        $texto = '';
3093
        switch ($this->tpEmis) {
3094
            case 2:
3095
                $texto = 'CONTINGÊNCIA FS' . $dhCont . $xJust;
3096
                break;
3097
            case 3:
3098
                $texto = 'CONTINGÊNCIA SCAN' . $dhCont . $xJust;
3099
                break;
3100
            case 4:
3101
                $texto = 'CONTINGÊNCIA DPEC' . $dhCont . $xJust;
3102
                break;
3103
            case 5:
3104
                $texto = 'CONTINGÊNCIA FSDA' . $dhCont . $xJust;
3105
                break;
3106
            case 6:
3107
                $texto = 'CONTINGÊNCIA SVC-AN' . $dhCont . $xJust;
3108
                break;
3109
            case 7:
3110
                $texto = 'CONTINGÊNCIA SVC-RS' . $dhCont . $xJust;
3111
                break;
3112
        }
3113
        $y += 2;
3114
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3115
        $this->pdf->textBox($x, $y, $w-2, $h-3, $texto, $aFont, 'T', 'L', 0, '', false);
3116
        return $y+$h;
3117
    }
3118
3119
    /**
3120
     * rodape
3121
     * Monta o rodapé no final da DANFE com a data/hora de impressão e informações
3122
     * sobre a API NfePHP
3123
     *
3124
     * @name   rodape
3125
     * @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...
3126
     * @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...
3127
     * @return void
3128
     */
3129
    protected function rodape($x, $y)
3130
    {
3131
        if ($this->orientacao == 'P') {
3132
              $w = $this->wPrint;
3133
        } else {
3134
              $w = $this->wPrint-$this->wCanhoto;
3135
              $x = $this->wCanhoto;
3136
        }
3137
        $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>'I'];
3138
        $texto = "Impresso em ". date('d/m/Y') . " as " . date('H:i:s');
3139
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'L', false);
3140
        $texto = $this->creditos .  "  Powered by NFePHP";
3141
        $this->pdf->textBox($x, $y, $w, 0, $texto, $aFont, 'T', 'R', false, '');
3142
    }
3143
3144
    /**
3145
     * pCcanhotoDANFE
3146
     * Monta o canhoto da DANFE (retrato e paisagem)
3147
     *
3148
     * @name   canhotoDANFE
3149
     * @param  number $x Posição horizontal canto esquerdo
3150
     * @param  number $y Posição vertical canto superior
3151
     * @return number Posição vertical final
3152
     *
3153
     * TODO 21/07/14 fmertins: quando orientação L-paisagem, o canhoto está sendo gerado incorretamente
3154
     */
3155
    protected function canhoto($x, $y)
3156
    {
3157
        $oldX = $x;
3158
        $oldY = $y;
3159
        //#################################################################################
3160
        //canhoto
3161
        //identificação do tipo de nf entrada ou saida
3162
        $tpNF = $this->ide->getElementsByTagName('tpNF')->item(0)->nodeValue;
3163
        if ($tpNF == '0') {
3164
            //NFe de Entrada
3165
            $emitente = '';
3166
            $emitente .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3167
            $emitente .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3168
            $emitente .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " - ";
3169
            $emitente .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3170
            $emitente .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3171
            $emitente .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3172
            $emitente .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . "";
3173
            $destinatario = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3174
        } else {
3175
            //NFe de Saída
3176
            $emitente = $this->emit->getElementsByTagName("xNome")->item(0)->nodeValue . " ";
3177
            $destinatario = '';
3178
            $destinatario .= $this->dest->getElementsByTagName("xNome")->item(0)->nodeValue . " - ";
3179
            $destinatario .= $this->enderDest->getElementsByTagName("xLgr")->item(0)->nodeValue . ", ";
3180
            $destinatario .= $this->enderDest->getElementsByTagName("nro")->item(0)->nodeValue . " ";
3181
            $destinatario .= $this->getTagValue($this->enderDest, "xCpl", " - ", " ");
3182
            $destinatario .= $this->enderDest->getElementsByTagName("xBairro")->item(0)->nodeValue . " ";
3183
            $destinatario .= $this->enderDest->getElementsByTagName("xMun")->item(0)->nodeValue . "-";
3184
            $destinatario .= $this->enderDest->getElementsByTagName("UF")->item(0)->nodeValue . " ";
3185
        }
3186
        //identificação do sistema emissor
3187
        //linha separadora do canhoto
3188
        if ($this->orientacao == 'P') {
3189
            $w = round($this->wPrint * 0.81, 0);
3190
        } else {
3191
            //linha separadora do canhoto - 238
3192
            //posicao altura
3193
            $y = $this->wPrint-85;
3194
            //altura
3195
            $w = $this->wPrint-85-24;
3196
        }
3197
        $h = 10;
3198
        //desenha caixa
3199
        $texto = '';
3200
        $aFont = ['font'=>$this->fontePadrao, 'size'=>7, 'style'=>''];
3201
        $aFontSmall = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3202
        if ($this->orientacao == 'P') {
3203
            $this->pdf->textBox($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3204
        } else {
3205
            $this->pdf->textBox90($x, $y, $w, $h, $texto, $aFont, 'C', 'L', 1, '', false);
3206
        }
3207
        $numNF = str_pad($this->ide->getElementsByTagName('nNF')->item(0)->nodeValue, 9, "0", STR_PAD_LEFT);
3208
        $serie = str_pad($this->ide->getElementsByTagName('serie')->item(0)->nodeValue, 3, "0", STR_PAD_LEFT);
3209
        $texto = "RECEBEMOS DE ";
3210
        $texto .= $emitente;
3211
        $texto .= " OS PRODUTOS E/OU SERVIÇOS CONSTANTES DA NOTA FISCAL ELETRÔNICA INDICADA ";
3212
        if ($this->orientacao == 'P') {
3213
            $texto .= "ABAIXO";
3214
        } else {
3215
            $texto .= "AO LADO";
3216
        }
3217
        $texto .= ". EMISSÃO: ";
3218
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3219
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3220
        if ($dEmi == '') {
3221
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3222
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3223
            $aDemi = explode('T', $dEmi);
3224
            $dEmi = $aDemi[0];
3225
        }
3226
        $texto .= $this->ymdTodmy($dEmi) ." ";
3227
        $texto .= "VALOR TOTAL: R$ ";
3228
        $texto .= number_format($this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue, 2, ",", ".") . " ";
3229
        $texto .= "DESTINATÁRIO: ";
3230
        $texto .= $destinatario;
3231
        if ($this->orientacao == 'P') {
3232
            $this->pdf->textBox($x, $y, $w-1, $h, $texto, $aFont, 'C', 'L', 0, '', false);
3233
            $x1 = $x + $w;
3234
            $w1 = $this->wPrint - $w;
3235
            $texto = "NF-e";
3236
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3237
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3238
            $texto = "Nº. " . $this->formatField($numNF, "###.###.###") . " \n";
3239
            $texto .= "Série $serie";
3240
            $aFont = ['font'=>$this->fontePadrao, 'size'=>10, 'style'=>'B'];
3241
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3242
            //DATA DE RECEBIMENTO
3243
            $texto = "DATA DE RECEBIMENTO";
3244
            $y += $h;
3245
            $w2 = round($this->wPrint*0.17, 0); //35;
3246
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3247
            $this->pdf->textBox($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3248
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3249
            $x += $w2;
3250
            $w3 = $w-$w2;
3251
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3252
            $this->pdf->textBox($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3253
            $x = $oldX;
3254
            $y += 9;
3255
            $this->pdf->dashedHLine($x, $y, $this->wPrint, 0.1, 80);
3256
            $y += 2;
3257
            return $y;
3258
        } else {
3259
            $x--;
3260
            $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...
3261
            //NUMERO DA NOTA FISCAL LOGO NFE
3262
            $w1 = 18;
3263
            $x1 = $oldX;
3264
            $y = $oldY;
3265
            $texto = "NF-e";
3266
            $aFont = ['font'=>$this->fontePadrao, 'size'=>14, 'style'=>'B'];
3267
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'T', 'C', 0, '');
3268
            $texto = "Nº.\n" . $this->formatField($numNF, "###.###.###") . " \n";
3269
            $texto .= "Série $serie";
3270
            $aFont = ['font'=>$this->fontePadrao, 'size'=>8, 'style'=>'B'];
3271
            $this->pdf->textBox($x1, $y, $w1, 18, $texto, $aFont, 'C', 'C', 1, '');
3272
            //DATA DO RECEBIMENTO
3273
            $texto = "DATA DO RECEBIMENTO";
3274
            $y = $this->wPrint-85;
3275
            $x = 12;
3276
            $w2 = round($this->wPrint*0.17, 0); //35;
3277
            $aFont = ['font'=>$this->fontePadrao, 'size'=>6, 'style'=>''];
3278
            $this->pdf->textBox90($x, $y, $w2, 8, $texto, $aFont, 'T', 'L', 1, '');
3279
            //IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR
3280
            $y -= $w2;
3281
            $w3 = $w-$w2;
3282
            $texto = "IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR";
3283
            $aFont = ['font'=>$this->fontePadrao, 'size'=>5.7, 'style'=>''];
3284
            $x = $this->pdf->textBox90($x, $y, $w3, 8, $texto, $aFont, 'T', 'L', 1, '');
3285
            $this->pdf->DashedVLine(23, $oldY, 0.1, $this->wPrint-20, 67);
3286
            return $x;
3287
        }
3288
    }
3289
3290
    /**
3291
     * geraInformacoesDaTagCompra
3292
     * Devolve uma string contendo informação sobre as tag <compra><xNEmp>, <xPed> e <xCont> ou string vazia.
3293
     * Aviso: Esta função não leva em consideração dados na tag xPed do item.
3294
     *
3295
     * @name   pGeraInformacoesDaTagCompra
3296
     * @return string com as informacoes dos pedidos.
3297
     */
3298
    protected function geraInformacoesDaTagCompra()
3299
    {
3300
        $saida = "";
3301
        if (isset($this->compra)) {
3302
            if (! empty($this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue)) {
3303
                $saida .= " Nota de Empenho: " . $this->compra->getElementsByTagName("xNEmp")->item(0)->nodeValue;
3304
            }
3305
            if (! empty($this->compra->getElementsByTagName("xPed")->item(0)->nodeValue)) {
3306
                $saida .= " Pedido: " . $this->compra->getElementsByTagName("xPed")->item(0)->nodeValue;
3307
            }
3308
            if (! empty($this->compra->getElementsByTagName("xCont")->item(0)->nodeValue)) {
3309
                $saida .= " Contrato: " . $this->compra->getElementsByTagName("xCont")->item(0)->nodeValue;
3310
            }
3311
        }
3312
        return $saida;
3313
    }
3314
3315
    /**
3316
     * pGeraChaveAdicionalDeContingencia
3317
     *
3318
     * @name   pGeraChaveAdicionalDeContingencia
3319
     * @return string chave
3320
     */
3321
    protected function pGeraChaveAdicionalDeContingencia()
3322
    {
3323
        //cUF tpEmis CNPJ vNF ICMSp ICMSs DD  DV
3324
        // Quantidade de caracteres  02   01      14  14    01    01  02 01
3325
        $forma  = "%02d%d%s%014d%01d%01d%02d";
3326
        $cUF    = $this->ide->getElementsByTagName('cUF')->item(0)->nodeValue;
3327
        $CNPJ   = "00000000000000" . $this->emit->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3328
        $CNPJ   = substr($CNPJ, -14);
3329
        $vNF    = $this->ICMSTot->getElementsByTagName("vNF")->item(0)->nodeValue * 100;
3330
        $vICMS  = $this->ICMSTot->getElementsByTagName("vICMS")->item(0)->nodeValue;
3331
        if ($vICMS > 0) {
3332
            $vICMS = 1;
3333
        }
3334
        $icmss  = $this->ICMSTot->getElementsByTagName("vBC")->item(0)->nodeValue;
3335
        if ($icmss > 0) {
3336
            $icmss = 1;
3337
        }
3338
        $dEmi = ! empty($this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue) ?
3339
                $this->ide->getElementsByTagName("dEmi")->item(0)->nodeValue : '';
3340
        if ($dEmi == '') {
3341
            $dEmi = ! empty($this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue) ?
3342
                    $this->ide->getElementsByTagName("dhEmi")->item(0)->nodeValue : '';
3343
            $aDemi = explode('T', $dEmi);
3344
            $dEmi = $aDemi[0];
3345
        }
3346
        $dd  = $dEmi;
3347
        $rpos = strrpos($dd, '-');
3348
        $dd  = substr($dd, $rpos +1);
3349
        $chave = sprintf($forma, $cUF, $this->tpEmis, $CNPJ, $vNF, $vICMS, $icmss, $dd);
3350
        $chave = $chave . $this->modulo11($chave);
3351
        return $chave;
3352
    }
3353
3354
    /**
3355
     *  geraInformacoesDasNotasReferenciadas
3356
     * Devolve uma string contendo informação sobre as notas referenciadas. Suporta N notas, eletrônicas ou não
3357
     * Exemplo: NFe Ref.: série: 01 número: 01 emit: 11.111.111/0001-01
3358
     * em 10/2010 [0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000]
3359
     *
3360
     * @return string Informacoes a serem adicionadas no rodapé sobre notas referenciadas.
3361
     */
3362
    protected function geraInformacoesDasNotasReferenciadas()
3363
    {
3364
        $formaNfeRef = "\r\nNFe Ref.: série:%d número:%d emit:%s em %s [%s]";
3365
        $formaCTeRef = "\r\nCTe Ref.: série:%d número:%d emit:%s em %s [%s]";
3366
        $formaNfRef = "\r\nNF  Ref.: série:%d numero:%d emit:%s em %s modelo: %d";
3367
        $formaECFRef = "\r\nECF Ref.: modelo: %s ECF:%d COO:%d";
3368
        $formaNfpRef = "\r\nNFP Ref.: série:%d número:%d emit:%s em %s modelo: %d IE:%s";
3369
        $saida='';
3370
        $nfRefs = $this->ide->getElementsByTagName('NFref');
3371
        if (0 === $nfRefs->length) {
3372
            return $saida;
3373
        }
3374
        if ($nfRefs->length > 2) {
3375
            return 'Existem mais de 2 NF/NFe/ECF/NFP/CTe referenciadas, não serão exibidas na DANFE.';
3376
        }
3377
        foreach ($nfRefs as $nfRef) {
3378
            if (empty($nfRef)) {
3379
                continue;
3380
            }
3381
            $refNFe = $nfRef->getElementsByTagName('refNFe');
3382
            foreach ($refNFe as $chave_acessoRef) {
3383
                $chave_acesso = $chave_acessoRef->nodeValue;
3384
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3385
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3386
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3387
                $serie  = substr($chave_acesso, 22, 3);
3388
                $numero = substr($chave_acesso, 25, 9);
3389
                $saida .= sprintf($formaNfeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3390
            }
3391
            $refNF = $nfRef->getElementsByTagName('refNF');
3392
            foreach ($refNF as $umaRefNFe) {
3393
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3394
                $cnpj = $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue;
3395
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3396
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3397
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3398
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3399
                $cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3400
                $saida .= sprintf($formaNfRef, $serie, $numero, $cnpj, $data, $mod);
3401
            }
3402
            $refCTe = $nfRef->getElementsByTagName('refCTe');
3403
            foreach ($refCTe as $chave_acessoRef) {
3404
                $chave_acesso = $chave_acessoRef->nodeValue;
3405
                $chave_acessoF = $this->formatField($chave_acesso, $this->formatoChave);
3406
                $data = substr($chave_acesso, 4, 2)."/20".substr($chave_acesso, 2, 2);
3407
                $cnpj = $this->formatField(substr($chave_acesso, 6, 14), "##.###.###/####-##");
3408
                $serie  = substr($chave_acesso, 22, 3);
3409
                $numero = substr($chave_acesso, 25, 9);
3410
                $saida .= sprintf($formaCTeRef, $serie, $numero, $cnpj, $data, $chave_acessoF);
3411
            }
3412
            $refECF = $nfRef->getElementsByTagName('refECF');
3413
            foreach ($refECF as $umaRefNFe) {
3414
                $mod    = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3415
                $nECF   = $umaRefNFe->getElementsByTagName('nECF')->item(0)->nodeValue;
3416
                $nCOO   = $umaRefNFe->getElementsByTagName('nCOO')->item(0)->nodeValue;
3417
                $saida .= sprintf($formaECFRef, $mod, $nECF, $nCOO);
3418
            }
3419
            $refNFP = $nfRef->getElementsByTagName('refNFP');
3420
            foreach ($refNFP as $umaRefNFe) {
3421
                $data = $umaRefNFe->getElementsByTagName('AAMM')->item(0)->nodeValue;
3422
                $cnpj = ! empty($umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue) ?
3423
                    $umaRefNFe->getElementsByTagName('CNPJ')->item(0)->nodeValue :
3424
                    '';
3425
                $cpf = ! empty($umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue) ?
3426
                        $umaRefNFe->getElementsByTagName('CPF')->item(0)->nodeValue : '';
3427
                $mod = $umaRefNFe->getElementsByTagName('mod')->item(0)->nodeValue;
3428
                $serie = $umaRefNFe->getElementsByTagName('serie')->item(0)->nodeValue;
3429
                $numero = $umaRefNFe->getElementsByTagName('nNF')->item(0)->nodeValue;
3430
                $ie = $umaRefNFe->getElementsByTagName('IE')->item(0)->nodeValue;
3431
                $data = substr($data, 2, 2) . "/20" . substr($data, 0, 2);
3432
                if ($cnpj == '') {
3433
                    $cpf_cnpj = $this->formatField($cpf, "###.###.###-##");
3434
                } else {
3435
                    $cpf_cnpj = $this->formatField($cnpj, "##.###.###/####-##");
3436
                }
3437
                $saida .= sprintf($formaNfpRef, $serie, $numero, $cpf_cnpj, $data, $mod, $ie);
3438
            }
3439
        }
3440
        return $saida;
3441
    }
3442
    
3443
    private function imagePNGtoJPG($original)
3444
    {
3445
        $image = imagecreatefrompng($original);
3446
        ob_start();
3447
        imagejpeg($image, null, 100);
3448
        imagedestroy($image);
3449
        $stringdata = ob_get_contents(); // read from buffer
3450
        ob_end_clean();
3451
        return 'data://text/plain;base64,'.base64_encode($stringdata);
3452
    }
3453
}
3454