www/rec_print.php

changeset 87
7f1d0abe5571
parent 86
e977a505ea8c
child 88
0a39cbdcf085
equal deleted inserted replaced
86:e977a505ea8c 87:7f1d0abe5571
22 $cost_fermentables = 0.0; 22 $cost_fermentables = 0.0;
23 $total_hops = 0.0; 23 $total_hops = 0.0;
24 $cost_hops = 0.0; 24 $cost_hops = 0.0;
25 $cost_yeasts = 0.0; 25 $cost_yeasts = 0.0;
26 $cost_miscs = 0.0; 26 $cost_miscs = 0.0;
27 $pSugar = 0;
28 $pCara = 0;
29 $svg = 77;
27 30
28 31
29 class PDF_MySQL_Table extends FPDF 32 class PDF_MySQL_Table extends FPDF
30 { 33 {
31 protected $ProcessingTable=false; 34 protected $ProcessingTable=false;
82 $this->Cell(25,5,'',0,0,'L',true); 85 $this->Cell(25,5,'',0,0,'L',true);
83 $this->Cell($vul,5,'',0,0,'L',false); 86 $this->Cell($vul,5,'',0,0,'L',false);
84 $this->Cell(35,5,'Brouwzaal rendement',0,0,'L',true); 87 $this->Cell(35,5,'Brouwzaal rendement',0,0,'L',true);
85 $this->Cell(25,5,$row['efficiency'].' %',0,0,'L',true); 88 $this->Cell(25,5,$row['efficiency'].' %',0,0,'L',true);
86 $this->Cell(25,5,'',0,0,'L',true); 89 $this->Cell(25,5,'',0,0,'L',true);
87 $this->Ln();
88
89 $this->SetX($this->TableX);
90 $this->Cell(35,5,'Start SG',0,0,'L',true);
91 $this->Cell(25,5,sprintf("%.3f",$row['est_og']),0,0,'L',true);
92 $this->Cell(25,5,'('.sprintf("%.3f",$row['st_og_min']).' - '.sprintf("%.3f",$row['st_og_max']).')',0,0,'L',true);
93 $this->Cell($vul,5,'',0,0,'L',false);
94 $this->Cell(35,5,'Eind SG',0,0,'L',true);
95 $this->Cell(25,5,sprintf("%.3f",$row['est_fg']),0,0,'L',true);
96 $this->Cell(25,5,'('.sprintf("%.3f",$row['st_fg_min']).' - '.sprintf("%.3f",$row['st_fg_max']).')',0,0,'L',true);
97 $this->Ln();
98
99 $this->SetX($this->TableX);
100 $this->Cell(35,5,'Geschat alcohol',0,0,'L',true);
101 $this->Cell(25,5,sprintf("%.1f",$row['est_abv']).'%',0,0,'L',true);
102 $this->Cell(25,5,'('.sprintf("%.1f",$row['st_abv_min']).' - '.sprintf("%.1f",$row['st_abv_max']).'%)',0,0,'L',true);
103 $this->Cell($vul,5,'',0,0,'L',false);
104 $this->Cell(35,5,'CO2',0,0,'L',true);
105 $this->Cell(25,5,sprintf("%.1f",$row['est_carb']).'%',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);
107 $this->Ln();
108
109 $this->SetX($this->TableX);
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]);
113 $this->Cell(25,5,$row['est_color'].' 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);
116 $this->Cell($vul,5,'',0,0,'L',false);
117 $this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true);
118 $this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true);
119 $this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true);
120 $this->Ln(10); 90 $this->Ln(10);
121 91
122 $this->cMargin=$cMargin; 92 $this->cMargin=$cMargin;
123 } 93 }
124 94
125 function TableFermentables($row) { 95 function TableFermentables($row) {
126 global $cost_fermentables; 96 global $cost_fermentables;
127 global $total_fermentables; 97 global $total_fermentables;
98 global $pSugar;
99 global $pCara;
128 $vul = $this->w - $this->rMargin - $this->lMargin - 132; 100 $vul = $this->w - $this->rMargin - $this->lMargin - 132;
129 $this->AddCol($vul,'Grondstof','L'); 101 $this->AddCol($vul,'Grondstof','L');
130 $this->AddCol(30,'Leverancier','L'); 102 $this->AddCol(30,'Leverancier','L');
131 $this->AddCol(15,'EBC','R'); 103 $this->AddCol(15,'EBC','R');
132 $this->AddCol(17,'Moment','L'); 104 $this->AddCol(17,'Moment','L');
140 $this->TableX=$this->lMargin; 112 $this->TableX=$this->lMargin;
141 $this->TableHeader(); 113 $this->TableHeader();
142 $this->ProcessingTable=true; 114 $this->ProcessingTable=true;
143 115
144 $sugf = 0; 116 $sugf = 0;
145 // $tot = 0;
146 $this->SetFont('Helvetica','',9); 117 $this->SetFont('Helvetica','',9);
147 $this->SetFillColor(250, 195, 65); 118 $this->SetFillColor(250, 195, 65);
148 $arr = json_decode($row['json_fermentables'], true); 119 $arr = json_decode($row['json_fermentables'], true);
149 foreach($arr as $item) { //foreach element in $arr 120 foreach($arr as $item) { //foreach element in $arr
150 $name = iconv('UTF-8','windows-1252',$item['f_name']); 121 $name = iconv('UTF-8','windows-1252',$item['f_name']);
151 $supplier = iconv('UTF-8','windows-1252',$item['f_supplier']); 122 $supplier = iconv('UTF-8','windows-1252',$item['f_supplier']);
152 $added = iconv('UTF-8','windows-1252',$item['f_added']); 123 $added = iconv('UTF-8','windows-1252',$item['f_added']);
124 $type = iconv('UTF-8','windows-1252',$item['f_type']);
125 $graintype = iconv('UTF-8','windows-1252',$item['f_graintype']);
153 $amount = floatval($item['f_amount']); 126 $amount = floatval($item['f_amount']);
154 $costkg = floatval($item['f_cost']); 127 $costkg = floatval($item['f_cost']);
155 $yield = floatval($item['f_yield']); 128 $yield = floatval($item['f_yield']);
156 $moisture = floatval($item['f_moisture']); 129 $moisture = floatval($item['f_moisture']);
157 $color = floatval($item['f_color']); 130 $color = floatval($item['f_color']);
158 $percent = floatval($item['f_percentage']); 131 $percent = floatval($item['f_percentage']);
132
133 if ($type == "Sugar")
134 $pSugar += $percent;
135 if ($graintype == "Crystal")
136 $pCara += $percent;
137
159 $cost = $amount * $costkg; 138 $cost = $amount * $costkg;
160 $cost_fermentables += $cost; 139 $cost_fermentables += $cost;
161 $total_fermentables += $amount; 140 $total_fermentables += $amount;
162 /* Calculate the amount of sugars */ 141 /* Calculate the amount of sugars */
163 $d = $amount * ($yield / 100) * (1 - $moisture / 100); 142 $d = $amount * ($yield / 100) * (1 - $moisture / 100);
164 if ($added == "Mash") 143 if ($added == "Mash")
165 $d = floatval($row['efficiency']) / 100 * $d; 144 $d = floatval($row['efficiency']) / 100 * $d;
166 $sugf += $d; 145 $sugf += $d;
167 // $tot += $amount;
168 //$plato = 100 * $d / $amount;
169 //$this->Cell(0,5,$tot.' sugf: '.$sugf.' d: '.$d.' pt: '.$plato.' moisture: '.$moisture,0,0,'L',false);
170 //$this->Ln();
171 146
172 $this->Cell($vul,5,$name,0,0,'L',true); 147 $this->Cell($vul,5,$name,0,0,'L',true);
173 $this->Cell(30,5,$supplier,0,0,'L',true); 148 $this->Cell(30,5,$supplier,0,0,'L',true);
174 $this->Cell(15,5,sprintf("%.0f",$color),0,0,'R',true); 149 $this->Cell(15,5,sprintf("%.0f",$color),0,0,'R',true);
175 $this->Cell(17,5,added_type_names($added),0,0,'L',true); 150 $this->Cell(17,5,added_type_names($added),0,0,'L',true);
178 $this->Cell(15,5,sprintf("%.1f%%",$yield),0,0,'R',true); 153 $this->Cell(15,5,sprintf("%.1f%%",$yield),0,0,'R',true);
179 $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); 154 $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true);
180 $this->Ln(); 155 $this->Ln();
181 } 156 }
182 157
183 $plato = 100 * $sugf / floatval($row['batch_size']); 158 $row['est_og'] = estimate_og($sugf, floatval($row['batch_size']));
184 $sg = plato_to_sg($plato); 159 $this->SetFillColor(210,245,255);
185 /* Average loops, HansH 5x. Brouwhulp 20x, about 10x is enough so keep 20. */ 160 $this->Cell($vul+62,5,'',0,0,'L',false);
186 for ($i = 0; $i < 20; $i++) {
187 if ($sg > 0)
188 $plato = 100 * $sugf / (floatval($row['batch_size']) * $sg);
189 $sg = plato_to_sg($plato);
190 }
191 $this->SetFillColor(210,245,255);
192 $this->Cell($vul,5,sprintf("%.1f",$plato).' Plato, OG: '.sprintf("%.3f",$sg),0,0,'L',true);
193 $this->Cell(62,5,'',0,0,'L',false);
194 $this->Cell(20,5,sprintf("%8.3f",$total_fermentables),0,0,'R',true); 161 $this->Cell(20,5,sprintf("%8.3f",$total_fermentables),0,0,'R',true);
195 $this->Cell(30,5,'',0,0,'L',false); 162 $this->Cell(30,5,'',0,0,'L',false);
196 $this->Cell(20,5,sprintf("%8.3f",$cost_fermentables).EURO,0,0,'R',true); 163 $this->Cell(20,5,sprintf("%8.3f",$cost_fermentables).EURO,0,0,'R',true);
197 $this->Ln(10); 164 $this->Ln(10);
198 $this->ProcessingTable=false; 165 $this->ProcessingTable=false;
288 $this->aCols=array(); 255 $this->aCols=array();
289 } 256 }
290 257
291 function TableYeasts($row) { 258 function TableYeasts($row) {
292 global $cost_yeasts; 259 global $cost_yeasts;
260 global $svg;
293 $vul = $this->w - $this->rMargin - $this->lMargin - 140; 261 $vul = $this->w - $this->rMargin - $this->lMargin - 140;
294 $this->AddCol(27,'Laboratorium','L'); 262 $this->AddCol(27,'Laboratorium','L');
295 $this->AddCol(18,'Product','L'); 263 $this->AddCol(18,'Product','L');
296 $this->AddCol($vul,'Gist','L'); 264 $this->AddCol($vul,'Gist','L');
297 $this->AddCol(20,'Gebruik','L'); 265 $this->AddCol(20,'Gebruik','L');
306 $this->TableHeader(); 274 $this->TableHeader();
307 $this->ProcessingTable=true; 275 $this->ProcessingTable=true;
308 276
309 $this->SetFont('Helvetica','',9); 277 $this->SetFont('Helvetica','',9);
310 $this->SetFillColor(175, 175, 255); 278 $this->SetFillColor(175, 175, 255);
311 $svg = 70; /* Conservative SVG% as default */
312 279
313 $arr = json_decode($row['json_yeasts'], true); 280 $arr = json_decode($row['json_yeasts'], true);
314 foreach($arr as $item) { //foreach element in $arr 281 foreach($arr as $item) { //foreach element in $arr
315 $name = iconv('UTF-8','windows-1252',$item['y_name']); 282 $name = iconv('UTF-8','windows-1252',$item['y_name']);
316 $laboratory = iconv('UTF-8','windows-1252',$item['y_laboratory']); 283 $laboratory = iconv('UTF-8','windows-1252',$item['y_laboratory']);
338 } 305 }
339 306
340 $this->SetFillColor(210,245,255); 307 $this->SetFillColor(210,245,255);
341 $this->Cell($vul+120,5,'',0,0,'L',false); 308 $this->Cell($vul+120,5,'',0,0,'L',false);
342 $this->Cell(20,5,sprintf("%8.3f",$cost_yeasts).EURO,0,0,'R',true); 309 $this->Cell(20,5,sprintf("%8.3f",$cost_yeasts).EURO,0,0,'R',true);
343 $this->Ln();
344
345 $og = floatval($row['est_og']);
346 $fg = $og - ($svg * ($og - 1.0)) / 100;
347 $this->Cell(0,5,'FG: '.sprintf("%5.3f",$fg),0,0,'L',false);
348 $this->Ln(10); 310 $this->Ln(10);
349 $this->ProcessingTable=false; 311 $this->ProcessingTable=false;
350 $this->cMargin=$cMargin; 312 $this->cMargin=$cMargin;
351 $this->aCols=array(); 313 $this->aCols=array();
352 } 314 }
413 $this->cMargin=$cMargin; 375 $this->cMargin=$cMargin;
414 $this->aCols=array(); 376 $this->aCols=array();
415 } 377 }
416 378
417 // Watercolor $this->SetFillColor(120,255,250); 379 // Watercolor $this->SetFillColor(120,255,250);
380
381 function TableSummary($row) {
382 global $pSugar;
383 global $pCara;
384 global $svg;
385 /* 2 Columns */
386 $vul = $this->w - $this->rMargin - $this->lMargin - 170;
387 $cMargin=$this->cMargin;
388 $this->cMargin=2;
389 $this->TableX=$this->lMargin;
390 $this->SetFont('Helvetica','B',9);
391 $this->SetX($this->TableX);
392 $this->SetFillColor(255,150,100);
393 $this->Cell(0, 5, 'Recept samenvatting',0,0,'C',true);
394 $this->Ln();
395
396 $this->SetFont('Helvetica','',9);
397 $this->SetFillColor(210,245,255);
398
399 $row['est_fg'] = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $row['est_og']);
400
401 $this->SetX($this->TableX);
402 $this->Cell(35,5,'Start SG',0,0,'L',true);
403 $this->Cell(25,5,sprintf("%.3f",$row['est_og']),0,0,'L',true);
404 $this->Cell(25,5,'('.sprintf("%.3f",$row['st_og_min']).' - '.sprintf("%.3f",$row['st_og_max']).')',0,0,'L',true);
405 $this->Cell($vul,5,'',0,0,'L',false);
406 $this->Cell(35,5,'Eind SG',0,0,'L',true);
407 $this->Cell(25,5,sprintf("%.3f",$row['est_fg']),0,0,'L',true);
408 $this->Cell(25,5,'('.sprintf("%.3f",$row['st_fg_min']).' - '.sprintf("%.3f",$row['st_fg_max']).')',0,0,'L',true);
409 $this->Ln();
410
411 $this->SetX($this->TableX);
412 $this->Cell(35,5,'Geschat alcohol',0,0,'L',true);
413 $this->Cell(25,5,sprintf("%.1f",$row['est_abv']).'%',0,0,'L',true);
414 $this->Cell(25,5,'('.sprintf("%.1f",$row['st_abv_min']).' - '.sprintf("%.1f",$row['st_abv_max']).'%)',0,0,'L',true);
415 $this->Cell($vul,5,'',0,0,'L',false);
416 $this->Cell(35,5,'CO2',0,0,'L',true);
417 $this->Cell(25,5,sprintf("%.1f",$row['est_carb']).'%',0,0,'L',true);
418 $this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true);
419 $this->Ln();
420
421 $this->SetX($this->TableX);
422 $this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true);
423 $beercolor = ebc_to_color($row['est_color']);
424 $this->SetFillColor($beercolor[0],$beercolor[1],$beercolor[2]);
425 $this->Cell(25,5,$row['est_color'].' EBC',0,0,'L',true);
426 $this->Cell(25,5,'('.$row['st_color_min'].' - '.$row['st_color_max'].' EBC)',0,0,'L',true);
427 $this->SetFillColor(210,245,255);
428 $this->Cell($vul,5,'',0,0,'L',false);
429 $this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true);
430 $this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true);
431 $this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true);
432 $this->Ln(10);
433 // Kostprijs per liter, calorieren
434 $this->cMargin=$cMargin;
435 }
418 } 436 }
419 437
420 438
421 439
422 class PDF extends PDF_MySQL_Table { 440 class PDF extends PDF_MySQL_Table {
442 $pdf->TableGlobal($row); 460 $pdf->TableGlobal($row);
443 $pdf->TableFermentables($row); 461 $pdf->TableFermentables($row);
444 $pdf->TableHops($row); 462 $pdf->TableHops($row);
445 $pdf->TableYeasts($row); 463 $pdf->TableYeasts($row);
446 $pdf->TableMiscs($row); 464 $pdf->TableMiscs($row);
447 465 $pdf->TableSummary($row);
448 //$pdf->SetFont('Helvetica','',10); 466 if (strlen($row['notes'])) {
449 //$pdf->Cell(0,10,'Receptje '.$record,0,1,'C'); 467 $pdf->SetFillColor(255,150,100);
450 // Disclaimer toeveogen dat dit alleen recept ontwikkeling is. 468 $pdf->Cell(0, 5, 'Recept opmerkingen',0,0,'C',true);
451 // Footer sectie met berekende/geschatte uitkomsten zoals FG, ABV, kostprijs per liter enz. 469 $pdf->Ln();
470 $pdf->SetFillColor(210,245,255);
471 $pdf->MultiCell(0,4,$row['notes'],0,'L',true);
472 }
473 // Disclaimer toevoegen dat dit alleen recept ontwikkeling is. Uitkomsten zoals IBU zijn een berekende schatting.
474 // Footer sectie met berekende/geschatte uitkomsten zoals ABV, kostprijs per liter enz.
452 $pdf->Output(); 475 $pdf->Output();

mercurial