--- a/www/inv_instock.php Thu Oct 04 22:50:40 2018 +0200 +++ b/www/inv_instock.php Tue Nov 06 22:55:55 2018 +0100 @@ -1,72 +1,276 @@ <?php require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); -page_header('Hoofdmenu', NULL); -?> +require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php'); + +define('EURO', chr(128) ); + +$link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); + +class PDF_MySQL_Table extends FPDF +{ + protected $ProcessingTable=false; + protected $aCols=array(); + protected $TableX; + protected $HeaderColor; + protected $RowColors; + protected $TotalColor; + protected $ColorIndex; + + function Header() { + // Print the table header if necessary + if ($this->ProcessingTable) + $this->TableHeader(); + } + + function TableHeader() { + $this->SetFont('Helvetica','B',9); + $this->SetX($this->TableX); + $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); + foreach($this->aCols as $col) + $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true); + $this->Ln(); + } + + function CalcWidths($width, $align) { + // Compute the widths of the columns + $TableWidth=0; + foreach($this->aCols as $i=>$col) { + $w=$col['w']; + if($w==-1) + $w=$width/count($this->aCols); + elseif(substr($w,-1)=='%') + $w=$w/100*$width; + $this->aCols[$i]['w']=$w; + $TableWidth+=$w; + } + // Compute the abscissa of the table + if($align=='C') + $this->TableX=max(($this->w-$TableWidth)/2,0); + elseif($align=='R') + $this->TableX=max($this->w-$this->rMargin-$TableWidth,0); + else + $this->TableX=$this->lMargin; + } + + function AddCol($width=-1, $caption='', $align='L') { + $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align); + } - <div id="MainPanel"> - <div id="ContentPanel"></div> - <pre> -<?php -$mysqli = new mysqli(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); -$result = $mysqli->query("SELECT name,inventory,cost FROM inventory_fermentables WHERE inventory > 0"); -$tot_fermentables = 0.0; -printf("Vergistbaar ingredient Voorraad Prijs/kg Waarde\n"); -printf("------------------------------------------------------------ ---------- -------- --------\n"); -while($row = $result->fetch_array(MYSQLI_ASSOC)) { - $value = $row['inventory'] * $row['cost']; - $tot_fermentables += $value; -// printf("%-60s %10.5f kg %8.2f %8.2f \n", $row['name'], $row['inventory'], $row['cost'], $value); -} -printf(" --------\n"); -printf("Totaal %8.2f\n\n", $tot_fermentables); + function TableFermentables($link,$prop) { + $this->AddCol(100,'Vergistbaar ingredient','L'); + $this->AddCol( 28,'Voorraad','R'); + $this->AddCol( 20, 'Prijs/kg', 'R'); + $this->AddCol( 20, 'Waarde', 'R'); + $prop['width']=$this->w-$this->lMargin-$this->rMargin; + $prop['align']='L'; + $cMargin=$this->cMargin; + $this->cMargin=$prop['padding']; + $this->HeaderColor=$prop['HeaderColor']; + $this->TotalColor=$prop['TotalColor']; + $this->RowColors=array($prop['color1'],$prop['color2']); + $this->CalcWidths($prop['width'],$prop['align']); + $this->TableHeader(); + $this->SetFont('Helvetica','',9); + $this->ColorIndex=0; + $this->ProcessingTable=true; + + $result = mysqli_query($link, "SELECT name,inventory,cost FROM inventory_fermentables WHERE inventory > 0"); + $tot_fermentables = 0.0; + + while($row=mysqli_fetch_array($result)) { + $value = $row['inventory'] * $row['cost']; + $tot_fermentables += $value; -$tot_hops = 0.0; -$result = $mysqli->query("SELECT name,form,origin,inventory,cost FROM inventory_hops WHERE inventory > 0"); -printf("Hoppen Voorraad Prijs/kg Waarde\n"); -printf("------------------------------------------------------------ ---------- -------- --------\n"); -while($row = $result->fetch_array(MYSQLI_ASSOC)) { - $value = $row['inventory'] * $row['cost']; - $tot_hops += $value; - $hop = $row['form'] . " " . $row['origin'] . " - " . $row['name']; - $stock = floatval($row['inventory']) * 1000.0; -// printf("%-60s %10.1f gr %8.2f %8.2f \n", $hop, $stock, $row['cost'], $value); -} -printf(" --------\n"); -printf("Totaal %8.2f\n\n", $tot_hops ); + $this->SetX($this->TableX); + $ci=$this->ColorIndex; + $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); + $this->Cell(100,5,$row['name'],0,0,'L',true); + $this->Cell(28,5,sprintf("%10.3f kg",$row['inventory']),0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true); + $this->Ln(); + $this->ColorIndex=1-$ci; + } + + $this->SetX($this->TableX); + $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]); + $this->Cell(148,5,'Totaal',0,0,'L',true); + $this->Cell(20,5,sprintf("%8.2f ",$tot_fermentables).EURO,0,0,'R',true); + $this->Ln(); + + $this->ProcessingTable=false; + $this->cMargin=$cMargin; + $this->aCols=array(); + } + + function TableHops($link,$prop) { + $this->AddCol(100,'Hoppen','L'); + $this->AddCol( 28,'Voorraad','R'); + $this->AddCol( 20, 'Prijs/kg', 'R'); + $this->AddCol( 20, 'Waarde', 'R'); + $prop['width']=$this->w-$this->lMargin-$this->rMargin; + $prop['align']='L'; + $cMargin=$this->cMargin; + $this->cMargin=$prop['padding']; + $this->CalcWidths($prop['width'],$prop['align']); + $this->TableHeader(); + $this->SetFont('Helvetica','',9); + $this->ColorIndex=0; + $this->ProcessingTable=true; + + $result = mysqli_query($link, "SELECT name,form,origin,inventory,cost FROM inventory_hops WHERE inventory > 0"); + $tot_hops = 0.0; + + while($row=mysqli_fetch_array($result)) { + $value = $row['inventory'] * $row['cost']; + $tot_hops += $value; + $hop = $row['form'] . " " . $row['origin'] . " - " . $row['name']; + $stock = floatval($row['inventory']) * 1000.0; -$tot_yeasts = 0.0; -$result = $mysqli->query("SELECT name,laboratory,product_id,form,inventory,cost FROM inventory_yeasts WHERE inventory > 0"); -printf("Gisten Voorraad Prijs/kg Waarde\n"); -printf("------------------------------------------------------------ ---------- -------- --------\n"); -while($row = $result->fetch_array(MYSQLI_ASSOC)) { - $value = $row['inventory'] * $row['cost']; - $yeast = $row['laboratory'] . " " .$row['product_id'] . " - " . $row['name']; - $tot_yeasts += $value; - $stock = floatval($row['inventory']) * 1000.0; - ($row['form'] == 'Dry') ? $amount = "gr" : $amount = "ml"; -// printf("%-60s %10.1f %s %8.2f %8.2f \n", $yeast, $stock, $amount, $row['cost'], $value); -} -printf(" --------\n"); -printf("Totaal %8.2f\n\n", $tot_yeasts ); + $this->SetX($this->TableX); + $ci=$this->ColorIndex; + $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); + $this->Cell(100,5,$hop,0,0,'L',true); + $this->Cell(28,5,sprintf("%10.1f gr",$stock),0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true); + $this->Ln(); + $this->ColorIndex=1-$ci; + } + + $this->SetX($this->TableX); + $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]); + $this->Cell(148,5,'Totaal',0,0,'L',true); + $this->Cell(20,5,sprintf("%8.2f ",$tot_hops).EURO,0,0,'R',true); + $this->Ln(); + + $this->ProcessingTable=false; + $this->cMargin=$cMargin; + $this->aCols=array(); + } + + function TableYeasts($link,$prop) { + $this->AddCol( 30,'Laboratorium','L'); + $this->AddCol( 20,'Product','L'); + $this->AddCol( 70,'Gist','L'); + $this->AddCol( 28,'Voorraad','R'); + $this->AddCol( 20, 'Prijs/kg', 'R'); + $this->AddCol( 20, 'Waarde', 'R'); + $prop['width']=$this->w-$this->lMargin-$this->rMargin; + $prop['align']='L'; + $cMargin=$this->cMargin; + $this->cMargin=$prop['padding']; + $this->CalcWidths($prop['width'],$prop['align']); + $this->TableHeader(); + $this->SetFont('Helvetica','',9); + $this->ColorIndex=0; + $this->ProcessingTable=true; + + $result = mysqli_query($link, "SELECT name,laboratory,product_id,form,inventory,cost FROM inventory_yeasts WHERE inventory > 0"); + $tot_yeasts = 0.0; + + while($row=mysqli_fetch_array($result)) { + $value = $row['inventory'] * $row['cost']; + $tot_yeasts += $value; + $stock = floatval($row['inventory']) * 1000.0; + ($row['form'] == 'Dry') ? $amount = "gr" : $amount = "ml"; + + $this->SetX($this->TableX); + $ci=$this->ColorIndex; + $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); + $this->Cell(30,5,$row['laboratory'],0,0,'L',true); + $this->Cell(20,5,$row['product_id'],0,0,'L',true); + $this->Cell(70,5,$row['name'],0,0,'L',true); + $this->Cell(28,5,sprintf("%10.1f ",$stock).$amount,0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true); + $this->Ln(); + $this->ColorIndex=1-$ci; + } + + $this->SetX($this->TableX); + $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]); + $this->Cell(168,5,'Totaal',0,0,'L',true); + $this->Cell(20,5,sprintf("%8.2f ",$tot_yeasts).EURO,0,0,'R',true); + $this->Ln(); + + $this->ProcessingTable=false; + $this->cMargin=$cMargin; + $this->aCols=array(); + } -$tot_miscs = 0.0; -$result = $mysqli->query("SELECT name,type,amount_is_weight,inventory,cost FROM inventory_miscs WHERE inventory > 0"); -printf("Diverse ingredienten Voorraad Prijs/kg Waarde\n"); -printf("------------------------------------------------------------ ---------- -------- --------\n"); -while($row = $result->fetch_array(MYSQLI_ASSOC)) { - $value = $row['inventory'] * $row['cost']; - $misc = $row['type'] . " " . $row['name']; - $tot_miscs += $value; - $stock = floatval($row['inventory']) * 1000.0; - ($row['amount_is_weight']) ? $amount = "gr" : $amount = "ml"; - printf("%-60s %10.1f %s %8.2f %8.2f \n", $misc, $stock, $amount, $row['cost'], $value); + function TableMiscs($link,$prop) { + $this->AddCol( 30,'Type','L'); + $this->AddCol( 70,'Ingredient','L'); + $this->AddCol( 28,'Voorraad','R'); + $this->AddCol( 20, 'Prijs/kg', 'R'); + $this->AddCol( 20, 'Waarde', 'R'); + $prop['width']=$this->w-$this->lMargin-$this->rMargin; + $prop['align']='L'; + $cMargin=$this->cMargin; + $this->cMargin=$prop['padding']; + $this->CalcWidths($prop['width'],$prop['align']); + $this->TableHeader(); + $this->SetFont('Helvetica','',9); + $this->ColorIndex=0; + $this->ProcessingTable=true; + + $result = mysqli_query($link, "SELECT name,type,amount_is_weight,inventory,cost FROM inventory_miscs WHERE inventory > 0"); + $tot_miscs = 0.0; + + while($row=mysqli_fetch_array($result)) { + $value = $row['inventory'] * $row['cost']; + $tot_miscs += $value; + $stock = floatval($row['inventory']) * 1000.0; + ($row['amount_is_weight']) ? $amount = "gr" : $amount = "ml"; + + $this->SetX($this->TableX); + $ci=$this->ColorIndex; + $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); + $this->Cell(30,5,$row['type'],0,0,'L',true); + $this->Cell(70,5,$row['name'],0,0,'L',true); + $this->Cell(28,5,sprintf("%10.1f ",$stock).$amount,0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$row['cost']).EURO,0,0,'R',true); + $this->Cell(20,5,sprintf("%8.2f ",$value).EURO,0,0,'R',true); + $this->Ln(); + $this->ColorIndex=1-$ci; + } + + $this->SetX($this->TableX); + $this->SetFillColor($this->TotalColor[0],$this->TotalColor[1],$this->TotalColor[2]); + $this->Cell(168,5,'Totaal',0,0,'L',true); + $this->Cell(20,5,sprintf("%8.2f ",$tot_miscs).EURO,0,0,'R',true); + $this->Ln(); + + $this->ProcessingTable=false; + $this->cMargin=$cMargin; + $this->aCols=array(); + } } -printf(" --------\n"); -printf("Totaal %8.2f\n\n", $tot_miscs ); -?> - </pre> - </div> + + + +class PDF extends PDF_MySQL_Table { + function Header() { + // Title + $this->SetFont('Helvetica','',18); + $this->Cell(0,6,'Inventaris',0,1,'C'); + $this->Ln(10); + // Ensure table header is printed + parent::Header(); + } +} -<?php -page_footer(); -?> + +$pdf = new PDF(); +$pdf->AddPage(); +$prop = array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255), + 'color2'=>array(255,255,210), 'TotalColor'=>array(255,150,100), 'padding'=>2); +$pdf->TableFermentables($link,$prop); +$pdf->Ln(10); +$pdf->TableHops($link,$prop); +$pdf->AddPage(); +$pdf->TableYeasts($link,$prop); +$pdf->Ln(10); +$pdf->TableMiscs($link,$prop); +$pdf->Output();