|
1 <?php |
|
2 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); |
|
3 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/formulas.php'); |
|
4 require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php'); |
|
5 |
|
6 |
|
7 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); |
|
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 |
|
16 setlocale ( LC_ALL, 'nl_NL.UTF-8'); |
|
17 |
|
18 date_default_timezone_set('Europe/Amsterdam'); |
|
19 $prdate = date(DATE_RFC2822); |
|
20 |
|
21 class PDF_MySQL_Table extends FPDF |
|
22 { |
|
23 protected $ProcessingTable=false; |
|
24 protected $aCols=array(); |
|
25 protected $TableX; |
|
26 |
|
27 function Header() { |
|
28 // Print the table header if necessary |
|
29 if ($this->ProcessingTable) |
|
30 $this->TableHeader(); |
|
31 } |
|
32 |
|
33 function TableHeader() { |
|
34 $this->SetFont('Helvetica','B',9); |
|
35 $this->SetX($this->TableX); |
|
36 $this->SetFillColor(255,150,100); |
|
37 foreach($this->aCols as $col) |
|
38 $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true); |
|
39 $this->Ln(); |
|
40 } |
|
41 |
|
42 function AddCol($width=-1, $caption='', $align='L') { |
|
43 $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align); |
|
44 } |
|
45 |
|
46 function TableTotals() { |
|
47 |
|
48 global $link; |
|
49 |
|
50 $vul = $this->w - $this->rMargin - $this->lMargin - 128; |
|
51 $this->AddCol(18,'Code','L'); |
|
52 $this->AddCol($vul,'Naam','L'); |
|
53 $this->AddCol(30,'Bier stijl','L'); |
|
54 $this->AddCol(20,'Max extract','R'); |
|
55 $this->AddCol(20,'Maish eff.','R'); |
|
56 $this->AddCol(20,'Spoel eff.','R'); |
|
57 $this->AddCol(20,'Kook eff.','R'); |
|
58 |
|
59 $cMargin=$this->cMargin; |
|
60 $this->cMargin=2; |
|
61 $this->TableX=$this->lMargin; |
|
62 $this->TableHeader(); |
|
63 $this->ProcessingTable=true; |
|
64 |
|
65 $this->SetFont('Helvetica','',9); |
|
66 $this->SetFillColor(210,245,255); |
|
67 |
|
68 $result = mysqli_query($link, "SELECT * FROM products WHERE package_date AND type='2' ORDER BY code"); |
|
69 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { |
|
70 /* |
|
71 * Data is not always available, try to calculate the mssing pieces. |
|
72 */ |
|
73 $mvol = 0; |
|
74 $msugars = 0; // mash sugars |
|
75 $ssugars = 0; |
|
76 $arr = json_decode($row['json_mashs'], true); |
|
77 foreach($arr as $item) { |
|
78 if ($item['step_type'] == 0) |
|
79 $mvol += $item['step_infuse_amount']; |
|
80 } |
|
81 |
|
82 $ferms = json_decode($row['json_fermentables'], true); |
|
83 foreach($ferms as $item) { |
|
84 if ($item['f_added'] == 0) { |
|
85 $d = $item['f_amount'] * ($item['f_yield'] / 100) * (1 - $item['f_moisture'] / 100); |
|
86 $ssugars += $item['f_amount']; |
|
87 $mvol += $item['f_amount'] * $item['f_moisture'] / 100; |
|
88 $msugars += $d; |
|
89 } |
|
90 } |
|
91 $sugardensity = 1.611; |
|
92 $v = $msugars / $sugardensity + $mvol; |
|
93 $plato = 1000 * $msugars / ($v * 10); // deg. Plato |
|
94 $mash_efficiency = floatval($row['brew_mash_efficiency']); |
|
95 $mash_sg = floatval($row['brew_mash_sg']); |
|
96 if (($mash_efficiency == 0) && ($mash_sg > 1)) { |
|
97 $mash_efficiency = 100 * sg_to_plato($mash_sg) / $plato; |
|
98 } |
|
99 $mash_extract = 100 * $msugars / $ssugars; |
|
100 $preboil_sg = floatval($row['brew_preboil_sg']); |
|
101 $preboil_volume = floatval($row['brew_preboil_volume']); |
|
102 $est_preboil_plato = sg_to_plato($preboil_sg) * ($preboil_volume / 1.04) * $preboil_sg * 10 / 1000; |
|
103 $preboil_efficiency = floatval($row['brew_preboil_efficiency']); |
|
104 if (($msugars > 0) && ($preboil_efficiency == 0)) |
|
105 $preboil_efficiency = $est_preboil_plato / $msugars * 100; |
|
106 if ($preboil_efficiency < 0) |
|
107 $preboil_efficiency = 0; |
|
108 $aboil_efficiency = floatval($row['brew_aboil_efficiency']); |
|
109 |
|
110 $name = iconv('UTF-8','windows-1252',$row['name']); |
|
111 $st_name = iconv('UTF-8','windows-1252',$row['st_name']); |
|
112 $this->SetX($this->TableX); |
|
113 $this->Cell(18,5,$row['code'],0,0,'L',true); |
|
114 $this->Cell($vul,5,$name,0,0,'L',true); |
|
115 $this->Cell(30,5,$st_name,0,0,'L',true); |
|
116 $this->Cell(20,5,sprintf("%.1f",$mash_extract).'%',0,0,'R',true); |
|
117 $this->Cell(20,5,sprintf("%.1f",$mash_efficiency).'%',0,0,'R',true); |
|
118 $this->Cell(20,5,sprintf("%.1f",$preboil_efficiency).'%',0,0,'R',true); |
|
119 $this->Cell(20,5,sprintf("%.1f",$aboil_efficiency).'%',0,0,'R',true); |
|
120 $this->Ln(); |
|
121 } |
|
122 $this->ProcessingTable=false; |
|
123 $this->cMargin=$cMargin; |
|
124 $this->aCols=array(); |
|
125 $this->Ln(); |
|
126 } |
|
127 } |
|
128 |
|
129 |
|
130 |
|
131 class PDF extends PDF_MySQL_Table { |
|
132 function Header() { |
|
133 global $prdate; |
|
134 global $my_brewery_name; |
|
135 $this->Image('images/logo.png',10,10,30); |
|
136 // Title |
|
137 $this->SetFont('Helvetica','B',18); |
|
138 $this->SetX(45); |
|
139 $this->Cell(0,8,"Efficientie ".$my_brewery_name,0,1,'L'); |
|
140 $this->Ln(1); |
|
141 $this->SetFont('Helvetica','',10); |
|
142 $this->SetX(45); |
|
143 $this->Cell(17,5,'Datum:',0,0,'L'); |
|
144 $this->Cell(0,5,$prdate,0,1,'L'); |
|
145 $this->Ln(20); |
|
146 // Ensure table header is printed |
|
147 parent::Header(); |
|
148 } |
|
149 } |
|
150 |
|
151 |
|
152 |
|
153 /* |
|
154 * Generate PDF |
|
155 */ |
|
156 $pdf = new PDF(); |
|
157 $pdf->AddPage(); |
|
158 $pdf->TableTotals(); |
|
159 $pdf->Output(); |