Added yeast performance report.

Sat, 24 Aug 2019 14:17:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 24 Aug 2019 14:17:54 +0200
changeset 454
f05ced2b5124
parent 453
ec4f1d652ed7
child 455
f319a8ab931a

Added yeast performance report.

www/Makefile file | annotate | diff | comparison | revisions
www/includes/global.inc.php file | annotate | diff | comparison | revisions
www/prod_r_yeast.php file | annotate | diff | comparison | revisions
--- a/www/Makefile	Fri Aug 23 23:17:10 2019 +0200
+++ b/www/Makefile	Sat Aug 24 14:17:54 2019 +0200
@@ -14,7 +14,7 @@
 		  prod_archive_code.php prod_archive_date.php prod_archive_name.php prod_beerxml.php \
 		  prod_checklist.php prod_duplicate.php prod_edit.php prod_export.php prod_forum.php \
 		  prod_impbrew.php prod_inprod.php prod_new.php prod_print.php prod_torecipe.php \
-		  prod_r_efficiency.php  prod_r_totals.php \
+		  prod_r_efficiency.php prod_r_yeast.php prod_r_totals.php \
 		  profile_fermentation.php profile_mash.php profile_setup.php profile_styles.php \
 		  profile_water.php \
 		  rec_beerxml.php rec_duplicate.php rec_edit.php rec_export.php rec_forum.php \
--- a/www/includes/global.inc.php	Fri Aug 23 23:17:10 2019 +0200
+++ b/www/includes/global.inc.php	Sat Aug 24 14:17:54 2019 +0200
@@ -253,6 +253,7 @@
         <ul style='width: 200px;'>
          <li><a href="prod_r_totals.php" target="_blank">Totaal productie</a></li>
          <li><a href="prod_r_efficiency.php" target="_blank">Rendementen</a></li>
+         <li><a href="prod_r_yeast.php" target="_blank">Vergisting</a></li>
         </ul>
        </li>
        <li><img style='float: left; margin-right: 7px;' src='images/calendar.png' />Kalender</li>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/www/prod_r_yeast.php	Sat Aug 24 14:17:54 2019 +0200
@@ -0,0 +1,160 @@
+<?php
+require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php');
+require_once($_SERVER['DOCUMENT_ROOT'].'/includes/formulas.php');
+require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php');
+
+
+$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);
+
+class PDF_MySQL_Table extends FPDF
+{
+        protected $ProcessingTable=false;
+        protected $aCols=array();
+        protected $TableX;
+
+        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(255,150,100);
+                foreach($this->aCols as $col)
+                        $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true);
+                $this->Ln();
+        }
+
+        function AddCol($width=-1, $caption='', $align='L') {
+                $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align);
+        }
+
+	function TableTotals() {
+
+		global $link;
+
+		$vul = $this->w - $this->rMargin - $this->lMargin - 151;
+		$this->AddCol(16,'Code','L');
+		$this->AddCol($vul,'Naam','L');
+		$this->AddCol(35,'Gist','L');
+		$this->AddCol(20,'Hoofdgisting','R');
+		$this->AddCol(20,'Nagisten','R');
+		$this->AddCol(20,'Lageren','R');
+		$this->AddCol(10,'Duur','R');
+		$this->AddCol(10,'OG','R');
+		$this->AddCol(10,'FG','R');
+		$this->AddCol(12,'SVG','R');
+
+		$cMargin=$this->cMargin;
+                $this->cMargin=2;
+                $this->TableX=$this->lMargin;
+		$this->TableHeader();
+                $this->ProcessingTable=true;
+
+		$this->SetFont('Helvetica','',9);
+                $this->SetFillColor(210,245,255);
+
+		$result = mysqli_query($link, "SELECT * FROM products WHERE package_date AND type='2' ORDER BY json_yeasts");
+		while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+			/*
+			 * Data is not always available, try to calculate the mssing pieces.
+			 */
+			$y_name = $y_lab = $y_product = '';
+			$yeasts = json_decode($row['json_yeasts'], true);
+			foreach($yeasts as $item) {
+				if ($item['y_use'] == 0) {
+					$y_name = iconv('UTF-8','windows-1252',$item['y_name']);
+					$y_lab = iconv('UTF-8','windows-1252',$item['y_laboratory']);
+					$y_product = iconv('UTF-8','windows-1252',$item['y_product_id']);
+					break;
+				}
+			}
+
+			// name,brew_date_end,primary_end_date,secondary_end_date,package_date
+			$d1 = new DateTime($row['brew_date_end']);
+			$d2 = new DateTime($row['primary_end_date']); 
+			$d3 = new DateTime($row['secondary_end_date']);
+			$d4 = new DateTime($row['package_date']);
+
+			$diff = $d2->diff($d1); 
+			$primary_days = $diff->days;
+			$diff = $d3->diff($d2);
+                        $secondary_days = $diff->days;
+			$diff = $d4->diff($d3);
+                        $tertiary_days = $diff->days;
+			$diff = $d4->diff($d1);
+                        $total_days = $diff->days;
+
+			$og = floatval($row['brew_fermenter_sg']);
+			$fg = floatval($row['fg']);
+			$svg = 100 * ($og - $fg) / ($og - 1);
+
+			$name = iconv('UTF-8','windows-1252',$row['name']);
+			$this->SetX($this->TableX);
+			$this->Cell(16,5,$row['code'],0,0,'L',true);
+			$this->Cell($vul,5,$name,0,0,'L',true);
+			$this->Cell(35,5,$y_lab.' '.$y_product,0,0,'L',true);
+			$this->Cell(13,5,sprintf("%.1f",$row['primary_end_temp']).DEG,0,0,'R',true);
+			$this->Cell( 7,5,sprintf("%d",$primary_days),0,0,'R',true);
+			$this->Cell(13,5,sprintf("%.1f",$row['secondary_temp']).DEG,0,0,'R',true);
+			$this->Cell( 7,5,sprintf("%d",$secondary_days),0,0,'R',true);
+			$this->Cell(13,5,sprintf("%.1f",$row['tertiary_temp']).DEG,0,0,'R',true);
+			$this->Cell( 7,5,sprintf("%d",$tertiary_days),0,0,'R',true);
+			$this->Cell(10,5,sprintf("%d",$total_days),0,0,'R',true);
+			$this->Cell(10,5,sprintf("%.3f",$og),0,0,'R',true);
+			$this->Cell(10,5,sprintf("%.3f",$fg),0,0,'R',true);
+			$this->Cell(12,5,sprintf("%.1f",$svg).'%',0,0,'R',true);
+			$this->Ln();
+		}
+		$this->ProcessingTable=false;
+                $this->cMargin=$cMargin;
+                $this->aCols=array();
+                $this->Ln();
+	}
+}
+
+
+
+class PDF extends PDF_MySQL_Table {
+        function Header() {
+		global $prdate;
+		global $my_brewery_name;
+                $this->Image('images/logo.png',10,10,30);
+                // Title
+                $this->SetFont('Helvetica','B',18);
+                $this->SetX(45);
+                $this->Cell(0,8,"Vergisting ".$my_brewery_name,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(20);
+                // Ensure table header is printed
+                parent::Header();
+        }
+}
+
+
+
+/*
+ * Generate PDF
+ */
+$pdf = new PDF();
+$pdf->AddPage();
+$pdf->TableTotals();
+$pdf->Output();

mercurial