Wed, 18 Mar 2020 19:46:15 +0100
Limit debug ProtoDeficit error messages. If the need for a yeast starter changes, make sure the screen is updated. Another set of extra debug logs. Fixed try yeast starter. Several dropdown lists changed the action from change to select. This should fix te too early calculations while the data was not yet loaded.
<?php require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/includes/constants.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'); date_default_timezone_set('Europe/Amsterdam'); $prdate = date(DATE_RFC2822); $sql = "SELECT brewery_name,my_yeastlab FROM profile_setup WHERE record = '1';"; $result = mysqli_query($link, $sql); if ($row=mysqli_fetch_array($result)) { $my_brewery = iconv('UTF-8','windows-1252',$row['brewery_name']); $my_lab = $row['my_yeastlab']; } else { $my_brewery = $my_lab = ''; } 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 TableYeasts($link,$prop) { global $yeasttype; global $yeastform; global $my_lab; $this->AddCol( 60,'Gist','L'); $this->AddCol( 50,'Omschrijving','L'); $this->AddCol( 18,'Soort','L'); $this->AddCol( 18,'Vorm','L'); $this->AddCol( 20,'Voorraad','R'); $this->AddCol( 25,'Datum','L'); $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; $sql = "SELECT name,type,form,inventory,production_date,short_desc FROM inventory_yeasts "; $sql .= "WHERE inventory > 0 AND laboratory = '".$my_lab."' ORDER BY product_id"; $result = mysqli_query($link, $sql); while ($row=mysqli_fetch_array($result)) { if ($row['form'] == 0) $stock = floatval($row['inventory']); else $stock = floatval($row['inventory']) * 1000.0; $form = array( 'pak', 'gr', 'ml', 'ml', 'ml', 'ml', 'gr' ); $this->SetX($this->TableX); $ci=$this->ColorIndex; $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); $this->Cell(60,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true); $this->Cell(50,5,iconv('UTF-8','windows-1252',$row['short_desc']),0,0,'L',true); $this->Cell(18,5,iconv('UTF-8','windows-1252',$yeasttype[$row['type']]),0,0,'L',true); $this->Cell(18,5,iconv('UTF-8','windows-1252',$yeastform[$row['form']]),0,0,'L',true); $this->Cell(20,5,sprintf("%10.1f ",$stock).$form[$row['form']],0,0,'R',true); $this->Cell(25,5,$row['production_date'],0,0,'L',true); $this->Ln(); $this->ColorIndex=1-$ci; } $this->ProcessingTable=false; $this->cMargin=$cMargin; $this->aCols=array(); } } class PDF extends PDF_MySQL_Table { function Header() { global $prdate; global $my_brewery; $this->Image('images/logo.png',10,6,30); // Title $this->SetFont('Helvetica','',18); $this->SetX(45); $this->Cell(0,10,'Gistbank van '.$my_brewery,0,1,'L'); $this->Ln(1); $this->SetFont('Helvetica','',10); $this->SetX(45); $this->Cell(17,5,'Datum:',0,0,'L'); $this->Cell(0,5,$prdate,0,1,'L'); $this->Ln(18); // 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->TableYeasts($link,$prop); $pdf->Output();