1 <?php |
1 <?php |
2 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); |
2 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); |
|
3 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/formulas.php'); |
3 require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php'); |
4 require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php'); |
4 |
5 |
5 define('EURO', chr(128) ); |
|
6 |
6 |
7 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); |
7 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); |
8 //mysqli_set_charset($link, "utf8" ); |
8 if (! $link) { |
|
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); |
|
10 } |
|
11 if (! mysqli_set_charset($link, "utf8" )) { |
|
12 echo "error"; |
|
13 return 1; |
|
14 } |
|
15 |
9 setlocale ( LC_ALL, 'nl_NL.UTF-8'); |
16 setlocale ( LC_ALL, 'nl_NL.UTF-8'); |
10 $record = $_GET["record"]; |
17 $record = $_GET["record"]; |
11 $result = mysqli_query($link, "SELECT * FROM recipes WHERE record='".$record."'"); |
18 $result = mysqli_query($link, "SELECT * FROM recipes WHERE record='".$record."'"); |
12 $row = mysqli_fetch_array($result); |
19 $row = mysqli_fetch_array($result); |
|
20 |
|
21 $total_fermentables = 0.0; |
|
22 $cost_fermentables = 0.0; |
|
23 $total_hops = 0.0; |
|
24 $cost_hops = 0.0; |
|
25 $cost_yeasts = 0.0; |
|
26 $cost_miscs = 0.0; |
13 |
27 |
14 |
28 |
15 class PDF_MySQL_Table extends FPDF |
29 class PDF_MySQL_Table extends FPDF |
16 { |
30 { |
17 protected $ProcessingTable=false; |
31 protected $ProcessingTable=false; |
18 protected $aCols=array(); |
32 protected $aCols=array(); |
19 protected $TableX; |
33 protected $TableX; |
20 protected $HeaderColor; |
|
21 protected $RowColors; |
|
22 protected $TotalColor; |
|
23 protected $ColorIndex; |
|
24 |
34 |
25 function Header() { |
35 function Header() { |
26 // Print the table header if necessary |
36 // Print the table header if necessary |
27 if ($this->ProcessingTable) |
37 if ($this->ProcessingTable) |
28 $this->TableHeader(); |
38 $this->TableHeader(); |
29 } |
39 } |
30 |
40 |
31 function TableHeader() { |
41 function TableHeader() { |
32 $this->SetFont('Helvetica','B',9); |
42 $this->SetFont('Helvetica','B',9); |
33 $this->SetX($this->TableX); |
43 $this->SetX($this->TableX); |
34 $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); |
44 $this->SetFillColor(255,150,100); |
35 foreach($this->aCols as $col) |
45 foreach($this->aCols as $col) |
36 $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true); |
46 $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true); |
37 $this->Ln(); |
47 $this->Ln(); |
38 } |
48 } |
39 |
49 |
40 function AddCol($width=-1, $caption='', $align='L') { |
50 function AddCol($width=-1, $caption='', $align='L') { |
41 $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align); |
51 $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align); |
42 } |
52 } |
43 |
53 |
44 function TableGlobal($row,$prop) { |
54 function TableGlobal($row) { |
45 /* 2 Columns */ |
55 /* 2 Columns */ |
46 $vul = $this->w - $this->rMargin - $this->lMargin - 170; |
56 $vul = $this->w - $this->rMargin - $this->lMargin - 170; |
47 $cMargin=$this->cMargin; |
57 $cMargin=$this->cMargin; |
48 $this->cMargin=$prop['padding']; |
58 $this->cMargin=2; |
49 $this->TableX=$this->lMargin; |
59 $this->TableX=$this->lMargin; |
50 $this->HeaderColor=$prop['HeaderColor']; |
60 $this->SetFont('Helvetica','B',9); |
51 $this->TotalColor=$prop['TotalColor']; |
61 $this->SetX($this->TableX); |
52 $this->RowColors=array($prop['color1'],$prop['color2']); |
62 $this->SetFillColor(255,150,100); |
53 $this->SetFont('Helvetica','B',11); |
63 $this->Cell(0, 5, 'Recept overzicht',0,0,'C',true); |
54 $this->SetX($this->TableX); |
|
55 $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); |
|
56 $this->Cell(0, 6, 'Recept overzicht',0,0,'C',true); |
|
57 $this->Ln(); |
64 $this->Ln(); |
58 |
65 |
59 $this->SetFont('Helvetica','',9); |
66 $this->SetFont('Helvetica','',9); |
60 $this->SetFillColor($this->RowColors[0][0],$this->RowColors[0][1],$this->RowColors[0][2]); |
67 $this->SetFillColor(210,245,255); |
61 |
68 |
62 $this->SetX($this->TableX); |
69 $this->SetX($this->TableX); |
63 $this->Cell(35,5,'Type',0,0,'L',true); |
70 $this->Cell(35,5,'Type',0,0,'L',true); |
64 $this->Cell(25,5,$row['type'],0,0,'L',true); |
71 $this->Cell(25,5,$row['type'],0,0,'L',true); |
65 $this->Cell(25,5,'',0,0,'L',true); |
72 $this->Cell(25,5,'',0,0,'L',true); |
99 $this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true); |
106 $this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true); |
100 $this->Ln(); |
107 $this->Ln(); |
101 |
108 |
102 $this->SetX($this->TableX); |
109 $this->SetX($this->TableX); |
103 $this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true); |
110 $this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true); |
|
111 $beercolor = ebc_to_color($row['est_color']); |
|
112 $this->SetFillColor($beercolor[0],$beercolor[1],$beercolor[2]); |
104 $this->Cell(25,5,$row['est_color'].' EBC',0,0,'L',true); |
113 $this->Cell(25,5,$row['est_color'].' EBC',0,0,'L',true); |
105 $this->Cell(25,5,'('.$row['st_color_min'].' - '.$row['st_color_max'].' EBC)',0,0,'L',true); |
114 $this->Cell(25,5,'('.$row['st_color_min'].' - '.$row['st_color_max'].' EBC)',0,0,'L',true); |
|
115 $this->SetFillColor(210,245,255); |
106 $this->Cell($vul,5,'',0,0,'L',false); |
116 $this->Cell($vul,5,'',0,0,'L',false); |
107 $this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true); |
117 $this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true); |
108 $this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true); |
118 $this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true); |
109 $this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true); |
119 $this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true); |
110 $this->Ln(); |
120 $this->Ln(); |
111 |
121 |
112 $this->cMargin=$cMargin; |
122 $this->cMargin=$cMargin; |
113 } |
123 } |
114 |
124 |
115 function TableFermentables($row,$prop) { |
125 function TableFermentables($row) { |
116 $vul = $this->w - $this->rMargin - $this->lMargin - 130; |
126 global $cost_fermentables; |
|
127 global $total_fermentables; |
|
128 $vul = $this->w - $this->rMargin - $this->lMargin - 130; |
117 $this->AddCol($vul,'Grondstof','L'); |
129 $this->AddCol($vul,'Grondstof','L'); |
118 $this->AddCol( 30,'Leverancier','L'); |
130 $this->AddCol(30,'Leverancier','L'); |
119 $this->AddCol( 15,'EBC','R'); |
131 $this->AddCol(15,'EBC','R'); |
120 $this->AddCol( 15,'Moment','L'); |
132 $this->AddCol(15,'Moment','L'); |
121 $this->AddCol( 20,'Kg','R'); |
133 $this->AddCol(20,'Kg','R'); |
122 $this->AddCol( 15,'Procent','R'); |
134 $this->AddCol(15,'Procent','R'); |
123 $this->AddCol( 15,'Opbr.','R'); |
135 $this->AddCol(15,'Opbr.','R'); |
124 $this->AddCol( 20,'Prijs','R'); |
136 $this->AddCol(20,'Prijs','R'); |
125 |
137 |
126 $cMargin=$this->cMargin; |
138 $cMargin=$this->cMargin; |
127 $this->cMargin=$prop['padding']; |
139 $this->cMargin=2; |
128 $this->TableX=$this->lMargin; |
140 $this->TableX=$this->lMargin; |
129 $this->TableHeader(); |
141 $this->TableHeader(); |
130 $this->ColorIndex=0; |
|
131 $this->ProcessingTable=true; |
142 $this->ProcessingTable=true; |
132 |
143 |
133 $this->SetFont('Helvetica','',9); |
144 $this->SetFont('Helvetica','',9); |
134 $this->SetFillColor($this->RowColors[0][0],$this->RowColors[0][1],$this->RowColors[0][2]); |
145 $this->SetFillColor(250, 195, 65); |
135 |
146 |
136 $arr = json_decode($row['json_fermentables'], true); |
147 $arr = json_decode($row['json_fermentables'], true); |
137 foreach($arr as $item) { //foreach element in $arr |
148 foreach($arr as $item) { //foreach element in $arr |
138 $name = $item['f_name']; |
149 $name = iconv('UTF-8','windows-1252',$item['f_name']); |
139 $supplier = $item['f_supplier']; |
150 $supplier = iconv('UTF-8','windows-1252',$item['f_supplier']); |
140 $amount = floatval($item['f_amount']); |
151 $amount = floatval($item['f_amount']); |
141 $costkg = floatval($item['f_cost']); |
152 $costkg = floatval($item['f_cost']); |
142 $yield = floatval($item['f_yield']); |
153 $yield = floatval($item['f_yield']); |
143 $color = floatval($item['f_color']); |
154 $color = floatval($item['f_color']); |
144 $percent = floatval($item['f_percentage']); |
155 $percent = floatval($item['f_percentage']); |
158 $this->Cell(15,5,sprintf("%.1f%%",$yield),0,0,'R',true); |
171 $this->Cell(15,5,sprintf("%.1f%%",$yield),0,0,'R',true); |
159 $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); |
172 $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); |
160 $this->Ln(); |
173 $this->Ln(); |
161 } |
174 } |
162 |
175 |
|
176 $this->SetFillColor(210,245,255); |
|
177 $this->Cell($vul+60,5,'',0,0,'L',false); |
|
178 $this->Cell(20,5,sprintf("%8.3f",$total_fermentables),0,0,'R',true); |
|
179 $this->Cell(30,5,'',0,0,'L',false); |
|
180 $this->Cell(20,5,sprintf("%8.3f",$cost_fermentables).EURO,0,0,'R',true); |
|
181 $this->Ln(); |
163 $this->ProcessingTable=false; |
182 $this->ProcessingTable=false; |
164 $this->cMargin=$cMargin; |
183 $this->cMargin=$cMargin; |
165 $this->aCols=array(); |
184 $this->aCols=array(); |
|
185 } |
|
186 |
|
187 function TableHops($row) { |
|
188 global $total_hops; |
|
189 global $cost_hops; |
|
190 $vul = $this->w - $this->rMargin - $this->lMargin - 135; |
|
191 $this->AddCol($vul,'Hop','L'); |
|
192 $this->AddCol(35,'Land','L'); |
|
193 $this->AddCol(15,'Soort','L'); |
|
194 $this->AddCol(20,'Moment','L'); |
|
195 $this->AddCol(15,'Alpha','R'); |
|
196 $this->AddCol(12,'IBU','R'); |
|
197 $this->AddCol(18,'Gram','R'); |
|
198 $this->AddCol(20,'Prijs','R'); |
|
199 |
|
200 $cMargin=$this->cMargin; |
|
201 $this->cMargin=2; |
|
202 $this->TableX=$this->lMargin; |
|
203 $this->TableHeader(); |
|
204 $this->ProcessingTable=true; |
|
205 |
|
206 $this->SetFont('Helvetica','',9); |
|
207 $this->SetFillColor(100, 250, 65); |
|
208 |
|
209 $arr = json_decode($row['json_hops'], true); |
|
210 foreach($arr as $item) { //foreach element in $arr |
|
211 $name = iconv('UTF-8','windows-1252',$item['h_name']); |
|
212 $origin = iconv('UTF-8','windows-1252',$item['h_origin']); |
|
213 $useat = iconv('UTF-8','windows-1252',$item['h_useat']); |
|
214 $form = iconv('UTF-8','windows-1252',$item['h_form']); |
|
215 $amount = floatval($item['h_amount']) * 1000; |
|
216 $mass = $amount; |
|
217 $costkg = floatval($item['h_cost']); |
|
218 $time = floatval($item['h_time']); |
|
219 $alpha = floatval($item['h_alpha']); |
|
220 |
|
221 $cost = ($amount * $costkg) / 1000; |
|
222 $cost_hops += $cost; |
|
223 $total_hops += $amount; |
|
224 |
|
225 $fmoment = 1.0; |
|
226 $moment = "Kook@".$time; |
|
227 if (($useat == "Dry Hop") || ($useat == "Dry hop")) { |
|
228 $fmoment = 0.0; |
|
229 $moment = "Dry-hop"; |
|
230 } else if ($useat == "Whirlpool") { |
|
231 $fmoment = 0.0; |
|
232 $moment = "Whirlpool"; |
|
233 } else if ($useat == "Mash") { |
|
234 $fmoment = 0.7; // Brouwhulp |
|
235 $moment = "Maischen"; |
|
236 } else if (($useat == "First Wort") || ($useat == "First wort")) { |
|
237 $fmoment = 1.1; // Brouwhulp, Louis, Ozzie |
|
238 $moment = "First wort"; |
|
239 } else if ($useat == "Aroma") { |
|
240 $fmoment = 0.0; // Brouwhulp 1.0 redeneert vlamuit. |
|
241 $moment = "Vlamuit"; |
|
242 } |
|
243 |
|
244 $pfactor = 1.0; |
|
245 if ($form == "Pellet") { |
|
246 $pfactor = 1.1; |
|
247 } |
|
248 |
|
249 /* Tinseth only for now */ |
|
250 $AddedAlphaAcids = (($alpha / 100) * $mass * 1000) / floatval($row['batch_size']); |
|
251 $Bigness_factor = 1.65 * pow( 0.000125, floatval($row['est_og']) - 1); |
|
252 $BoilTime_factor = ((1 - exp(-0.04 * $time)) / 4.15); |
|
253 $utiisation = $Bigness_factor * $BoilTime_factor; |
|
254 $ibu = (round($utiisation * $AddedAlphaAcids * $fmoment * $pfactor * 10) / 10.0); |
|
255 |
|
256 $this->Cell($vul,5,$name,0,0,'L',true); |
|
257 $this->Cell(35,5,$origin,0,0,'L',true); |
|
258 $this->Cell(15,5,$form,0,0,'L',true); |
|
259 $this->Cell(20,5,$moment,0,0,'L',true); |
|
260 $this->Cell(15,5,sprintf("%.1f%%",$alpha),0,0,'R',true); |
|
261 $this->Cell(12,5,sprintf("%.1f",$ibu),0,0,'R',true); |
|
262 $this->Cell(18,5,sprintf("%.1f",$amount),0,0,'R',true); |
|
263 $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); |
|
264 $this->Ln(); |
|
265 } |
|
266 |
|
267 $this->SetFillColor(210,245,255); |
|
268 $this->Cell($vul+97,5,'',0,0,'L',false); |
|
269 $this->Cell(18,5,sprintf("%.1f",$total_hops),0,0,'R',true); |
|
270 $this->Cell(20,5,sprintf("%8.3f",$cost_hops).EURO,0,0,'R',true); |
|
271 $this->Ln(); |
|
272 $this->ProcessingTable=false; |
|
273 $this->cMargin=$cMargin; |
|
274 $this->aCols=array(); |
|
275 } |
|
276 |
|
277 function TableYeasts($row) { |
|
278 global $cost_yeasts; |
|
279 $vul = $this->w - $this->rMargin - $this->lMargin - 140; |
|
280 $this->AddCol(27,'Laboratorium','L'); |
|
281 $this->AddCol(18,'Product','L'); |
|
282 $this->AddCol($vul,'Gist','L'); |
|
283 $this->AddCol(20,'Gebruik','L'); |
|
284 $this->AddCol(15,'Attn','R'); |
|
285 $this->AddCol(22,'Vorm','L'); |
|
286 $this->AddCol(18,'Gram','R'); |
|
287 $this->AddCol(20,'Prijs','R'); |
|
288 |
|
289 $cMargin=$this->cMargin; |
|
290 $this->cMargin=2; |
|
291 $this->TableX=$this->lMargin; |
|
292 $this->TableHeader(); |
|
293 $this->ProcessingTable=true; |
|
294 |
|
295 $this->SetFont('Helvetica','',9); |
|
296 $this->SetFillColor(175, 175, 255); |
|
297 $svg = 70; /* Conservative SVG% as default */ |
|
298 |
|
299 $arr = json_decode($row['json_yeasts'], true); |
|
300 foreach($arr as $item) { //foreach element in $arr |
|
301 $name = iconv('UTF-8','windows-1252',$item['y_name']); |
|
302 $laboratory = iconv('UTF-8','windows-1252',$item['y_laboratory']); |
|
303 $product_id = iconv('UTF-8','windows-1252',$item['y_product_id']); |
|
304 $form = iconv('UTF-8','windows-1252',$item['y_form']); |
|
305 $use = iconv('UTF-8','windows-1252',$item['y_use']); |
|
306 $amount = floatval($item['y_amount']) * 1000; |
|
307 $costg = floatval($item['y_cost']); |
|
308 $attenuation = floatval($item['y_attenuation']); |
|
309 $cost = $amount * $costg; |
|
310 $cost_yeasts += $cost; |
|
311 |
|
312 if ($use == "Primary") { |
|
313 $svg = $attenuation; |
|
314 $gebruik = 'Hoofdgist'; |
|
315 } else if ($use == "Bottle") |
|
316 $gebruik = 'Bottelgist'; |
|
317 else |
|
318 $gebruik = $use; |
|
319 |
|
320 if ($form == "Liquid") |
|
321 $vorm = 'Vloeibaar'; |
|
322 else if ($form == "Dry") |
|
323 $vorm = 'Droog'; |
|
324 else if ($form == "Slant") |
|
325 $vorm = 'Schuine buis'; |
|
326 else if ($form == "Culture") |
|
327 $vorm = 'Slurry'; |
|
328 else if ($form == "Frozen") |
|
329 $vorm = 'Ingevroren'; |
|
330 else if ($form == "Bottel") |
|
331 $vorm = 'Depot'; |
|
332 else |
|
333 $vorm = $form; |
|
334 |
|
335 $this->Cell(27,5,$laboratory,0,0,'L',true); |
|
336 $this->Cell(18,5,$product_id,0,0,'L',true); |
|
337 $this->Cell($vul,5,$name,0,0,'L',true); |
|
338 $this->Cell(20,5,$gebruik,0,0,'L',true); |
|
339 $this->Cell(15,5,sprintf("%.1f%%",$attenuation),0,0,'R',true); |
|
340 $this->Cell(22,5,$vorm,0,0,'L',true); |
|
341 $this->Cell(18,5,sprintf("%.1f",$amount),0,0,'R',true); |
|
342 $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); |
|
343 $this->Ln(); |
|
344 } |
|
345 |
|
346 $this->SetFillColor(210,245,255); |
|
347 $this->Cell($vul+120,5,'',0,0,'L',false); |
|
348 $this->Cell(20,5,sprintf("%8.3f",$cost_yeasts).EURO,0,0,'R',true); |
|
349 $this->Ln(); |
|
350 |
|
351 $og = floatval($row['est_og']); |
|
352 $fg = $og - ($svg * ($og - 1.0)) / 100; |
|
353 $this->Cell(0,5,'FG: '.sprintf("%5.3f",$fg),0,0,'L',false); |
|
354 $this->Ln(); |
|
355 $this->ProcessingTable=false; |
|
356 $this->cMargin=$cMargin; |
|
357 $this->aCols=array(); |
|
358 } |
|
359 |
|
360 /* |
|
361 MiscColor:= RGBtoColor(240, 250, 65); |
|
362 WaterAgentColor:= RGBtoColor(240, 140, 130); |
|
363 FiningColor:= RGBtoColor(95, 180, 25); |
|
364 WaterColor:= RGBtoColor(120, 255, 250); |
|
365 */ |
|
366 function TableMiscs($row) { |
|
367 global $cost_miscs; |
|
368 $vul = $this->w - $this->rMargin - $this->lMargin - 135; |
166 } |
369 } |
167 } |
370 } |
168 |
371 |
169 |
372 |
170 |
373 |