www/inv_instock.php

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

mercurial