www/inv_instock.php

changeset 77
a9f8de2d7b2b
parent 33
2ee6ad5d6f14
child 78
f35a38e8c16f
equal deleted inserted replaced
76:804d45bdaa86 77:a9f8de2d7b2b
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 page_header('Hoofdmenu', NULL); 3 require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php');
4 ?> 4
5 5 define('EURO', chr(128) );
6 <div id="MainPanel"> 6
7 <div id="ContentPanel"></div> 7 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
8 <pre> 8
9 <?php 9 class PDF_MySQL_Table extends FPDF
10 $mysqli = new mysqli(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); 10 {
11 $result = $mysqli->query("SELECT name,inventory,cost FROM inventory_fermentables WHERE inventory > 0"); 11 protected $ProcessingTable=false;
12 $tot_fermentables = 0.0; 12 protected $aCols=array();
13 printf("Vergistbaar ingredient Voorraad Prijs/kg Waarde\n"); 13 protected $TableX;
14 printf("------------------------------------------------------------ ---------- -------- --------\n"); 14 protected $HeaderColor;
15 while($row = $result->fetch_array(MYSQLI_ASSOC)) { 15 protected $RowColors;
16 $value = $row['inventory'] * $row['cost']; 16 protected $TotalColor;
17 $tot_fermentables += $value; 17 protected $ColorIndex;
18 // printf("%-60s %10.5f kg %8.2f %8.2f \n", $row['name'], $row['inventory'], $row['cost'], $value); 18
19 function Header() {
20 // Print the table header if necessary
21 if ($this->ProcessingTable)
22 $this->TableHeader();
23 }
24
25 function TableHeader() {
26 $this->SetFont('Helvetica','B',9);
27 $this->SetX($this->TableX);
28 $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
29 foreach($this->aCols as $col)
30 $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true);
31 $this->Ln();
32 }
33
34 function CalcWidths($width, $align) {
35 // Compute the widths of the columns
36 $TableWidth=0;
37 foreach($this->aCols as $i=>$col) {
38 $w=$col['w'];
39 if($w==-1)
40 $w=$width/count($this->aCols);
41 elseif(substr($w,-1)=='%')
42 $w=$w/100*$width;
43 $this->aCols[$i]['w']=$w;
44 $TableWidth+=$w;
45 }
46 // Compute the abscissa of the table
47 if($align=='C')
48 $this->TableX=max(($this->w-$TableWidth)/2,0);
49 elseif($align=='R')
50 $this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
51 else
52 $this->TableX=$this->lMargin;
53 }
54
55 function AddCol($width=-1, $caption='', $align='L') {
56 $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align);
57 }
58
59 function TableFermentables($link,$prop) {
60 $this->AddCol(100,'Vergistbaar ingredient','L');
61 $this->AddCol( 28,'Voorraad','R');
62 $this->AddCol( 20, 'Prijs/kg', 'R');
63 $this->AddCol( 20, 'Waarde', 'R');
64 $prop['width']=$this->w-$this->lMargin-$this->rMargin;
65 $prop['align']='L';
66 $cMargin=$this->cMargin;
67 $this->cMargin=$prop['padding'];
68 $this->HeaderColor=$prop['HeaderColor'];
69 $this->TotalColor=$prop['TotalColor'];
70 $this->RowColors=array($prop['color1'],$prop['color2']);
71 $this->CalcWidths($prop['width'],$prop['align']);
72 $this->TableHeader();
73 $this->SetFont('Helvetica','',9);
74 $this->ColorIndex=0;
75 $this->ProcessingTable=true;
76
77 $result = mysqli_query($link, "SELECT name,inventory,cost FROM inventory_fermentables WHERE inventory > 0");
78 $tot_fermentables = 0.0;
79
80 while($row=mysqli_fetch_array($result)) {
81 $value = $row['inventory'] * $row['cost'];
82 $tot_fermentables += $value;
83
84 $this->SetX($this->TableX);
85 $ci=$this->ColorIndex;
86 $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
87 $this->Cell(100,5,$row['name'],0,0,'L',true);
88 $this->Cell(28,5,sprintf("%10.3f kg",$row['inventory']),0,0,'R',true);
89 $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
90 $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);
91 $this->Ln();
92 $this->ColorIndex=1-$ci;
93 }
94
95 $this->SetX($this->TableX);
96 $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]);
97 $this->Cell(148,5,'Totaal',0,0,'L',true);
98 $this->Cell(20,5,sprintf("%8.2f ",$tot_fermentables).EURO,0,0,'R',true);
99 $this->Ln();
100
101 $this->ProcessingTable=false;
102 $this->cMargin=$cMargin;
103 $this->aCols=array();
104 }
105
106 function TableHops($link,$prop) {
107 $this->AddCol(100,'Hoppen','L');
108 $this->AddCol( 28,'Voorraad','R');
109 $this->AddCol( 20, 'Prijs/kg', 'R');
110 $this->AddCol( 20, 'Waarde', 'R');
111 $prop['width']=$this->w-$this->lMargin-$this->rMargin;
112 $prop['align']='L';
113 $cMargin=$this->cMargin;
114 $this->cMargin=$prop['padding'];
115 $this->CalcWidths($prop['width'],$prop['align']);
116 $this->TableHeader();
117 $this->SetFont('Helvetica','',9);
118 $this->ColorIndex=0;
119 $this->ProcessingTable=true;
120
121 $result = mysqli_query($link, "SELECT name,form,origin,inventory,cost FROM inventory_hops WHERE inventory > 0");
122 $tot_hops = 0.0;
123
124 while($row=mysqli_fetch_array($result)) {
125 $value = $row['inventory'] * $row['cost'];
126 $tot_hops += $value;
127 $hop = $row['form'] . " " . $row['origin'] . " - " . $row['name'];
128 $stock = floatval($row['inventory']) * 1000.0;
129
130 $this->SetX($this->TableX);
131 $ci=$this->ColorIndex;
132 $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
133 $this->Cell(100,5,$hop,0,0,'L',true);
134 $this->Cell(28,5,sprintf("%10.1f gr",$stock),0,0,'R',true);
135 $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
136 $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);
137 $this->Ln();
138 $this->ColorIndex=1-$ci;
139 }
140
141 $this->SetX($this->TableX);
142 $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]);
143 $this->Cell(148,5,'Totaal',0,0,'L',true);
144 $this->Cell(20,5,sprintf("%8.2f ",$tot_hops).EURO,0,0,'R',true);
145 $this->Ln();
146
147 $this->ProcessingTable=false;
148 $this->cMargin=$cMargin;
149 $this->aCols=array();
150 }
151
152 function TableYeasts($link,$prop) {
153 $this->AddCol( 30,'Laboratorium','L');
154 $this->AddCol( 20,'Product','L');
155 $this->AddCol( 70,'Gist','L');
156 $this->AddCol( 28,'Voorraad','R');
157 $this->AddCol( 20, 'Prijs/kg', 'R');
158 $this->AddCol( 20, 'Waarde', 'R');
159 $prop['width']=$this->w-$this->lMargin-$this->rMargin;
160 $prop['align']='L';
161 $cMargin=$this->cMargin;
162 $this->cMargin=$prop['padding'];
163 $this->CalcWidths($prop['width'],$prop['align']);
164 $this->TableHeader();
165 $this->SetFont('Helvetica','',9);
166 $this->ColorIndex=0;
167 $this->ProcessingTable=true;
168
169 $result = mysqli_query($link, "SELECT name,laboratory,product_id,form,inventory,cost FROM inventory_yeasts WHERE inventory > 0");
170 $tot_yeasts = 0.0;
171
172 while($row=mysqli_fetch_array($result)) {
173 $value = $row['inventory'] * $row['cost'];
174 $tot_yeasts += $value;
175 $stock = floatval($row['inventory']) * 1000.0;
176 ($row['form'] == 'Dry') ? $amount = "gr" : $amount = "ml";
177
178 $this->SetX($this->TableX);
179 $ci=$this->ColorIndex;
180 $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
181 $this->Cell(30,5,$row['laboratory'],0,0,'L',true);
182 $this->Cell(20,5,$row['product_id'],0,0,'L',true);
183 $this->Cell(70,5,$row['name'],0,0,'L',true);
184 $this->Cell(28,5,sprintf("%10.1f ",$stock).$amount,0,0,'R',true);
185 $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
186 $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);
187 $this->Ln();
188 $this->ColorIndex=1-$ci;
189 }
190
191 $this->SetX($this->TableX);
192 $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]);
193 $this->Cell(168,5,'Totaal',0,0,'L',true);
194 $this->Cell(20,5,sprintf("%8.2f ",$tot_yeasts).EURO,0,0,'R',true);
195 $this->Ln();
196
197 $this->ProcessingTable=false;
198 $this->cMargin=$cMargin;
199 $this->aCols=array();
200 }
201
202 function TableMiscs($link,$prop) {
203 $this->AddCol( 30,'Type','L');
204 $this->AddCol( 70,'Ingredient','L');
205 $this->AddCol( 28,'Voorraad','R');
206 $this->AddCol( 20, 'Prijs/kg', 'R');
207 $this->AddCol( 20, 'Waarde', 'R');
208 $prop['width']=$this->w-$this->lMargin-$this->rMargin;
209 $prop['align']='L';
210 $cMargin=$this->cMargin;
211 $this->cMargin=$prop['padding'];
212 $this->CalcWidths($prop['width'],$prop['align']);
213 $this->TableHeader();
214 $this->SetFont('Helvetica','',9);
215 $this->ColorIndex=0;
216 $this->ProcessingTable=true;
217
218 $result = mysqli_query($link, "SELECT name,type,amount_is_weight,inventory,cost FROM inventory_miscs WHERE inventory > 0");
219 $tot_miscs = 0.0;
220
221 while($row=mysqli_fetch_array($result)) {
222 $value = $row['inventory'] * $row['cost'];
223 $tot_miscs += $value;
224 $stock = floatval($row['inventory']) * 1000.0;
225 ($row['amount_is_weight']) ? $amount = "gr" : $amount = "ml";
226
227 $this->SetX($this->TableX);
228 $ci=$this->ColorIndex;
229 $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
230 $this->Cell(30,5,$row['type'],0,0,'L',true);
231 $this->Cell(70,5,$row['name'],0,0,'L',true);
232 $this->Cell(28,5,sprintf("%10.1f ",$stock).$amount,0,0,'R',true);
233 $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true);
234 $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true);
235 $this->Ln();
236 $this->ColorIndex=1-$ci;
237 }
238
239 $this->SetX($this->TableX);
240 $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]);
241 $this->Cell(168,5,'Totaal',0,0,'L',true);
242 $this->Cell(20,5,sprintf("%8.2f ",$tot_miscs).EURO,0,0,'R',true);
243 $this->Ln();
244
245 $this->ProcessingTable=false;
246 $this->cMargin=$cMargin;
247 $this->aCols=array();
248 }
19 } 249 }
20 printf(" --------\n"); 250
21 printf("Totaal %8.2f\n\n", $tot_fermentables); 251
22 252
23 $tot_hops = 0.0; 253 class PDF extends PDF_MySQL_Table {
24 $result = $mysqli->query("SELECT name,form,origin,inventory,cost FROM inventory_hops WHERE inventory > 0"); 254 function Header() {
25 printf("Hoppen Voorraad Prijs/kg Waarde\n"); 255 // Title
26 printf("------------------------------------------------------------ ---------- -------- --------\n"); 256 $this->SetFont('Helvetica','',18);
27 while($row = $result->fetch_array(MYSQLI_ASSOC)) { 257 $this->Cell(0,6,'Inventaris',0,1,'C');
28 $value = $row['inventory'] * $row['cost']; 258 $this->Ln(10);
29 $tot_hops += $value; 259 // Ensure table header is printed
30 $hop = $row['form'] . " " . $row['origin'] . " - " . $row['name']; 260 parent::Header();
31 $stock = floatval($row['inventory']) * 1000.0; 261 }
32 // printf("%-60s %10.1f gr %8.2f %8.2f \n", $hop, $stock, $row['cost'], $value);
33 } 262 }
34 printf(" --------\n"); 263
35 printf("Totaal %8.2f\n\n", $tot_hops ); 264
36 265 $pdf = new PDF();
37 $tot_yeasts = 0.0; 266 $pdf->AddPage();
38 $result = $mysqli->query("SELECT name,laboratory,product_id,form,inventory,cost FROM inventory_yeasts WHERE inventory > 0"); 267 $prop = array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255),
39 printf("Gisten Voorraad Prijs/kg Waarde\n"); 268 'color2'=>array(255,255,210), 'TotalColor'=>array(255,150,100), 'padding'=>2);
40 printf("------------------------------------------------------------ ---------- -------- --------\n"); 269 $pdf->TableFermentables($link,$prop);
41 while($row = $result->fetch_array(MYSQLI_ASSOC)) { 270 $pdf->Ln(10);
42 $value = $row['inventory'] * $row['cost']; 271 $pdf->TableHops($link,$prop);
43 $yeast = $row['laboratory'] . " " .$row['product_id'] . " - " . $row['name']; 272 $pdf->AddPage();
44 $tot_yeasts += $value; 273 $pdf->TableYeasts($link,$prop);
45 $stock = floatval($row['inventory']) * 1000.0; 274 $pdf->Ln(10);
46 ($row['form'] == 'Dry') ? $amount = "gr" : $amount = "ml"; 275 $pdf->TableMiscs($link,$prop);
47 // printf("%-60s %10.1f %s %8.2f %8.2f \n", $yeast, $stock, $amount, $row['cost'], $value); 276 $pdf->Output();
48 }
49 printf(" --------\n");
50 printf("Totaal %8.2f\n\n", $tot_yeasts );
51
52 $tot_miscs = 0.0;
53 $result = $mysqli->query("SELECT name,type,amount_is_weight,inventory,cost FROM inventory_miscs WHERE inventory > 0");
54 printf("Diverse ingredienten Voorraad Prijs/kg Waarde\n");
55 printf("------------------------------------------------------------ ---------- -------- --------\n");
56 while($row = $result->fetch_array(MYSQLI_ASSOC)) {
57 $value = $row['inventory'] * $row['cost'];
58 $misc = $row['type'] . " " . $row['name'];
59 $tot_miscs += $value;
60 $stock = floatval($row['inventory']) * 1000.0;
61 ($row['amount_is_weight']) ? $amount = "gr" : $amount = "ml";
62 printf("%-60s %10.1f %s %8.2f %8.2f \n", $misc, $stock, $amount, $row['cost'], $value);
63 }
64 printf(" --------\n");
65 printf("Totaal %8.2f\n\n", $tot_miscs );
66 ?>
67 </pre>
68 </div>
69
70 <?php
71 page_footer();
72 ?>

mercurial