diff -r 259c97782bf8 -r 4dbfa131d173 www/prod_r_totals.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/prod_r_totals.php Fri Aug 23 22:26:13 2019 +0200 @@ -0,0 +1,133 @@ +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();