www/prod_r_totals.php

Sat, 25 Sep 2021 10:42:54 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 25 Sep 2021 10:42:54 +0200
changeset 778
e64fd38c469c
parent 452
4dbfa131d173
permissions
-rw-r--r--

If during styles import the CATEGORY_NUMBER is empty, insert 0 in the database instead.

<?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 - 130) / 2;
		$this->Ln();
		$this->AddCol(15,'Nummer','C');
		$this->AddCol(10,'Jaar','C');
		$this->AddCol(35,'Brouw sessies','R');
		$this->AddCol(35,'Brouw volume','R');
		$this->AddCol(35,'Gemiddeld volume','R');

		$total = $tvolume = $regel = 0;
		$cMargin=$this->cMargin;
                $this->cMargin=2;
                $this->TableX=$this->lMargin+$vul;
		$this->TableHeader();
                $this->ProcessingTable=true;

		$this->SetFont('Helvetica','',9);
                $this->SetFillColor(210,245,255);

		$result = mysqli_query($link, "SELECT DISTINCT YEAR(package_date) FROM products WHERE package_date ORDER BY package_date");
		while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {

			$regel++;
			$year = $row['YEAR(package_date)'];
			$this->SetX($this->TableX);

			$brews = 0;
			$packaged = 0;

			$result2 = mysqli_query($link, "SELECT package_volume FROM products WHERE package_date AND YEAR(package_date) = '".$year."'");
			while ($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC)) {
				$brews++;
				$total++;
				$packaged += floatval($row2['package_volume']);
				$tvolume += floatval($row2['package_volume']);
			}
			$average = $packaged / $brews;
			$this->Cell(15,5,$regel,0,0,'C',true);
			$this->Cell(10,5,$year,0,0,'C',true);
			$this->Cell(35,5,$brews,0,0,'R',true);
			$this->Cell(35,5,sprintf("%.1f",$packaged).' L',0,0,'R',true);
			$this->Cell(35,5,sprintf("%.1f",$average).' L',0,0,'R',true);
			$this->Ln();
		}
		$this->Cell($vul+25,5,'',0,0,'L',false);
		$this->Cell(35,5,$total,0,0,'R',true);
                $this->Cell(35,5,sprintf("%.1f",$tvolume).' L',0,0,'R',true);
		$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,"Jaarproductie ".$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