www/inv_instock.php

Fri, 30 Nov 2018 17:40:39 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 30 Nov 2018 17:40:39 +0100
changeset 116
ac993ef43b13
parent 82
7af1d472475a
child 209
dc30801e6961
permissions
-rw-r--r--

Removed all calculations from the equipemnts database script and added missing fields. Added missing fields to the inventory equipemnts edit screen. Added conditional batch size calculation to the equipments editor. Added specific heat settings to the equipments editor.

<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php');

define('EURO', chr(128) );

$link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
if (! $link) {
	die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
if (! mysqli_set_charset($link, "utf8" )) {
	echo "error";
	return 1;
}

setlocale ( LC_ALL, 'nl_NL.UTF-8');

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);
	}

	function TableFermentables($link,$prop) {
		$this->AddCol( 30,'Leverancier','L');
		$this->AddCol( 90,'Vergistbaar ingredient','L');
		$this->AddCol( 30,'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,supplier,inventory,cost FROM inventory_fermentables WHERE inventory > 0 ORDER BY supplier,name");
		$tot_fermentables = 0.0;

		while($row=mysqli_fetch_array($result)) {
			$value = $row['inventory'] * $row['cost'];
			$tot_fermentables += $value;

			$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,iconv('UTF-8','windows-1252',$row['supplier']),0,0,'L',true);
			$this->Cell(90,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
			$this->Cell(30,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(170,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( 30,'Land','L');
		$this->AddCol( 75,'Hoppen','L');
		$this->AddCol( 15,'Soort','L');
		$this->AddCol( 30,'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 ORDER BY origin,name");
		$tot_hops = 0.0;

		while($row=mysqli_fetch_array($result)) {
			$value = $row['inventory'] * $row['cost'];
			$tot_hops += $value;
			$stock = floatval($row['inventory']) * 1000.0;

			$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,iconv('UTF-8','windows-1252',$row['origin']),0,0,'L',true);
			$this->Cell(75,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
			$this->Cell(15,5,iconv('UTF-8','windows-1252',$row['form']),0,0,'L',true);
			$this->Cell(30,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(170,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( 30,'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 ORDER BY laboratory,product_id");
		$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,iconv('UTF-8','windows-1252',$row['laboratory']),0,0,'L',true);
			$this->Cell(20,5,iconv('UTF-8','windows-1252',$row['product_id']),0,0,'L',true);
			$this->Cell(70,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
			$this->Cell(30,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(170,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();
	}

	function TableMiscs($link,$prop) {
		$this->AddCol( 30,'Type','L');
		$this->AddCol( 90,'Ingredient','L');
		$this->AddCol( 30,'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 ORDER BY type,name");
		$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,iconv('UTF-8','windows-1252',$row['type']),0,0,'L',true);
			$this->Cell(90,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true);
			$this->Cell(30,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(170,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();
	}
}



class PDF extends PDF_MySQL_Table {
	function Header() {
		$this->Image('images/logo.png',10,6,30);
		// Title
		$this->SetFont('Helvetica','',18);
		$this->Cell(0,10,'Inventaris',0,1,'C');
		$this->Ln(20);
		// Ensure table header is printed
		parent::Header();
	}
}


$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();

mercurial