|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NFePHP\DA\NFe\Traits; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Bloco itens da NFe |
|
7
|
|
|
*/ |
|
8
|
|
|
trait TraitBlocoIII |
|
9
|
|
|
{ |
|
10
|
|
|
protected function blocoIII($y) |
|
11
|
|
|
{ |
|
12
|
|
|
if ($this->flagResume) { |
|
|
|
|
|
|
13
|
|
|
return $y; |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
$matrix = [0.12, $this->descPercent, 0.08, 0.09, 0.156, 0.156]; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
//$aFont = ['font'=> $this->fontePadrao, 'size' => 7, 'style' => '']; |
|
19
|
|
|
//$this->pdf->textBox($this->margem, $y, $this->wPrint, $this->bloco3H, '', $aFont, 'T', 'C', true, '', false); |
|
20
|
|
|
|
|
21
|
|
|
$fsize = 7; |
|
22
|
|
|
if ($this->paperwidth < 70) { |
|
|
|
|
|
|
23
|
|
|
$fsize = 5; |
|
24
|
|
|
} |
|
25
|
|
|
$aFont = ['font'=> $this->fontePadrao, 'size' => $fsize, 'style' => '']; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
$texto = "Código"; |
|
28
|
|
|
$x = $this->margem; |
|
|
|
|
|
|
29
|
|
|
$this->pdf->textBox($x, $y, ($this->wPrint * $matrix[0]), 3, $texto, $aFont, 'T', 'L', false, '', true); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
$texto = "Descrição"; |
|
32
|
|
|
$x1 = $x + ($this->wPrint * $matrix[0]); |
|
33
|
|
|
$this->pdf->textBox($x1, $y, ($this->wPrint * $matrix[1]), 3, $texto, $aFont, 'T', 'L', false, '', true); |
|
34
|
|
|
|
|
35
|
|
|
$texto = "Qtde"; |
|
36
|
|
|
$x2 = $x1 + ($this->wPrint * $matrix[1]); |
|
37
|
|
|
$this->pdf->textBox($x2, $y, ($this->wPrint * $matrix[2]), 3, $texto, $aFont, 'T', 'C', false, '', true); |
|
38
|
|
|
|
|
39
|
|
|
$texto = "UN"; |
|
40
|
|
|
$x3 = $x2 + ($this->wPrint * $matrix[2]); |
|
41
|
|
|
$this->pdf->textBox($x3, $y, ($this->wPrint * $matrix[3]), 3, $texto, $aFont, 'T', 'C', false, '', true); |
|
42
|
|
|
|
|
43
|
|
|
$texto = "Vl Unit"; |
|
44
|
|
|
$x4 = $x3 + ($this->wPrint * $matrix[3]); |
|
45
|
|
|
$this->pdf->textBox($x4, $y, ($this->wPrint * $matrix[4]), 3, $texto, $aFont, 'T', 'C', false, '', true); |
|
46
|
|
|
|
|
47
|
|
|
$texto = "Vl Total"; |
|
48
|
|
|
$x5 = $x4 + ($this->wPrint * $matrix[4]); |
|
49
|
|
|
$y1 = $this->pdf->textBox($x5, $y, ($this->wPrint * $matrix[5]), 3, $texto, $aFont, 'T', 'R', false, '', true); |
|
50
|
|
|
|
|
51
|
|
|
$y2 = $y + $y1; |
|
52
|
|
|
if ($this->det->length == 0) { |
|
|
|
|
|
|
53
|
|
|
} else { |
|
54
|
|
|
foreach ($this->itens as $item) { |
|
|
|
|
|
|
55
|
|
|
$it = (object) $item; |
|
56
|
|
|
$this->pdf->textBox( |
|
57
|
|
|
$x, |
|
58
|
|
|
$y2, |
|
59
|
|
|
($this->wPrint * $matrix[0]), |
|
60
|
|
|
$it->height, |
|
61
|
|
|
$it->codigo, |
|
62
|
|
|
$aFont, |
|
63
|
|
|
'T', |
|
64
|
|
|
'L', |
|
65
|
|
|
false, |
|
66
|
|
|
'', |
|
67
|
|
|
true |
|
68
|
|
|
); |
|
69
|
|
|
$this->pdf->textBox( |
|
70
|
|
|
$x1, |
|
71
|
|
|
$y2, |
|
72
|
|
|
($this->wPrint * $matrix[1]), |
|
73
|
|
|
$it->height, |
|
74
|
|
|
$it->desc, |
|
75
|
|
|
$aFont, |
|
76
|
|
|
'T', |
|
77
|
|
|
'L', |
|
78
|
|
|
false, |
|
79
|
|
|
'', |
|
80
|
|
|
false |
|
81
|
|
|
); |
|
82
|
|
|
$this->pdf->textBox( |
|
83
|
|
|
$x2, |
|
84
|
|
|
$y2, |
|
85
|
|
|
($this->wPrint * $matrix[2]), |
|
86
|
|
|
$it->height, |
|
87
|
|
|
$it->qtd, |
|
88
|
|
|
$aFont, |
|
89
|
|
|
'T', |
|
90
|
|
|
'R', |
|
91
|
|
|
false, |
|
92
|
|
|
'', |
|
93
|
|
|
true |
|
94
|
|
|
); |
|
95
|
|
|
$this->pdf->textBox( |
|
96
|
|
|
$x3, |
|
97
|
|
|
$y2, |
|
98
|
|
|
($this->wPrint * $matrix[3]), |
|
99
|
|
|
$it->height, |
|
100
|
|
|
$it->un, |
|
101
|
|
|
$aFont, |
|
102
|
|
|
'T', |
|
103
|
|
|
'C', |
|
104
|
|
|
false, |
|
105
|
|
|
'', |
|
106
|
|
|
true |
|
107
|
|
|
); |
|
108
|
|
|
$this->pdf->textBox( |
|
109
|
|
|
$x4, |
|
110
|
|
|
$y2, |
|
111
|
|
|
($this->wPrint * $matrix[4]), |
|
112
|
|
|
$it->height, |
|
113
|
|
|
$it->vunit, |
|
114
|
|
|
$aFont, |
|
115
|
|
|
'T', |
|
116
|
|
|
'R', |
|
117
|
|
|
false, |
|
118
|
|
|
'', |
|
119
|
|
|
true |
|
120
|
|
|
); |
|
121
|
|
|
$this->pdf->textBox( |
|
122
|
|
|
$x5, |
|
123
|
|
|
$y2, |
|
124
|
|
|
($this->wPrint * $matrix[5]), |
|
125
|
|
|
$it->height, |
|
126
|
|
|
$it->valor, |
|
127
|
|
|
$aFont, |
|
128
|
|
|
'T', |
|
129
|
|
|
'R', |
|
130
|
|
|
false, |
|
131
|
|
|
'', |
|
132
|
|
|
true |
|
133
|
|
|
); |
|
134
|
|
|
$y2 += $it->height; |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
$this->pdf->dashedHLine($this->margem, $this->bloco3H+$y, $this->wPrint, 0.1, 30); |
|
|
|
|
|
|
138
|
|
|
return $this->bloco3H + $y; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
protected function calculateHeightItens($descriptionWidth) |
|
142
|
|
|
{ |
|
143
|
|
|
if ($this->flagResume) { |
|
144
|
|
|
return 0; |
|
145
|
|
|
} |
|
146
|
|
|
$fsize = 7; |
|
147
|
|
|
if ($this->paperwidth < 70) { |
|
148
|
|
|
$fsize = 5; |
|
149
|
|
|
} |
|
150
|
|
|
$hfont = (imagefontheight($fsize)/72)*15; |
|
151
|
|
|
$aFont = ['font'=> $this->fontePadrao, 'size' => $fsize, 'style' => '']; |
|
|
|
|
|
|
152
|
|
|
$htot = 0; |
|
153
|
|
|
if ($this->det->length == 0) { |
|
154
|
|
|
} else { |
|
155
|
|
|
foreach ($this->det as $item) { |
|
156
|
|
|
$prod = $item->getElementsByTagName("prod")->item(0); |
|
157
|
|
|
$cProd = $this->getTagValue($prod, "cProd"); |
|
|
|
|
|
|
158
|
|
|
$xProd = substr($this->getTagValue($prod, "xProd"), 1, 45); |
|
|
|
|
|
|
159
|
|
|
$qCom = number_format($this->getTagValue($prod, "qCom"), 2, ",", "."); |
|
|
|
|
|
|
160
|
|
|
$uCom = $this->getTagValue($prod, "uCom"); |
|
|
|
|
|
|
161
|
|
|
$vUnCom = number_format($this->getTagValue($prod, "vUnCom"), 2, ",", "."); |
|
|
|
|
|
|
162
|
|
|
$vProd = number_format($this->getTagValue($prod, "vProd"), 2, ",", "."); |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
$tempPDF = new \NFePHP\DA\Legacy\Pdf(); // cria uma instancia temporaria da class pdf |
|
165
|
|
|
$tempPDF->setFont($this->fontePadrao, '', $fsize); // seta a font do PDF |
|
166
|
|
|
|
|
167
|
|
|
$n = $tempPDF->wordWrap($xProd, $descriptionWidth); |
|
|
|
|
|
|
168
|
|
|
$limit = 45; |
|
169
|
|
|
while ($n > 2) { |
|
170
|
|
|
$limit -= 1; |
|
171
|
|
|
$xProd = substr($this->getTagValue($prod, "xProd"), 0, $limit); |
|
|
|
|
|
|
172
|
|
|
$p = $xProd; |
|
173
|
|
|
$n = $tempPDF->wordWrap($p, $descriptionWidth); |
|
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
$h = ($hfont * $n); |
|
176
|
|
|
$this->itens[] = [ |
|
177
|
|
|
"codigo" => $cProd, |
|
178
|
|
|
"desc" => $xProd, |
|
179
|
|
|
"qtd" => $qCom, |
|
180
|
|
|
"un" => $uCom, |
|
181
|
|
|
"vunit" => $vUnCom, |
|
182
|
|
|
"valor" => $vProd, |
|
183
|
|
|
"height" => $h |
|
184
|
|
|
]; |
|
185
|
|
|
$htot += $h; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
return $htot+2; |
|
189
|
|
|
} |
|
190
|
|
|
} |
|
191
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: