www/prod_r_totals.php

changeset 452
4dbfa131d173
equal deleted inserted replaced
451:259c97782bf8 452:4dbfa131d173
1 <?php
2 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php');
3 require_once($_SERVER['DOCUMENT_ROOT'].'/includes/formulas.php');
4 require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php');
5
6
7 $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME);
8 if (! $link) {
9 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
10 }
11 if (! mysqli_set_charset($link, "utf8" )) {
12 echo "error";
13 return 1;
14 }
15
16 setlocale ( LC_ALL, 'nl_NL.UTF-8');
17
18 date_default_timezone_set('Europe/Amsterdam');
19 $prdate = date(DATE_RFC2822);
20
21 class PDF_MySQL_Table extends FPDF
22 {
23 protected $ProcessingTable=false;
24 protected $aCols=array();
25 protected $TableX;
26
27 function Header() {
28 // Print the table header if necessary
29 if ($this->ProcessingTable)
30 $this->TableHeader();
31 }
32
33 function TableHeader() {
34 $this->SetFont('Helvetica','B',9);
35 $this->SetX($this->TableX);
36 $this->SetFillColor(255,150,100);
37 foreach($this->aCols as $col)
38 $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true);
39 $this->Ln();
40 }
41
42 function AddCol($width=-1, $caption='', $align='L') {
43 $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align);
44 }
45
46 function TableTotals() {
47
48 global $link;
49
50 $vul = ($this->w - $this->rMargin - $this->lMargin - 130) / 2;
51 $this->Ln();
52 $this->AddCol(15,'Nummer','C');
53 $this->AddCol(10,'Jaar','C');
54 $this->AddCol(35,'Brouw sessies','R');
55 $this->AddCol(35,'Brouw volume','R');
56 $this->AddCol(35,'Gemiddeld volume','R');
57
58 $total = $tvolume = $regel = 0;
59 $cMargin=$this->cMargin;
60 $this->cMargin=2;
61 $this->TableX=$this->lMargin+$vul;
62 $this->TableHeader();
63 $this->ProcessingTable=true;
64
65 $this->SetFont('Helvetica','',9);
66 $this->SetFillColor(210,245,255);
67
68 $result = mysqli_query($link, "SELECT DISTINCT YEAR(package_date) FROM products WHERE package_date ORDER BY package_date");
69 while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
70
71 $regel++;
72 $year = $row['YEAR(package_date)'];
73 $this->SetX($this->TableX);
74
75 $brews = 0;
76 $packaged = 0;
77
78 $result2 = mysqli_query($link, "SELECT package_volume FROM products WHERE package_date AND YEAR(package_date) = '".$year."'");
79 while ($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC)) {
80 $brews++;
81 $total++;
82 $packaged += floatval($row2['package_volume']);
83 $tvolume += floatval($row2['package_volume']);
84 }
85 $average = $packaged / $brews;
86 $this->Cell(15,5,$regel,0,0,'C',true);
87 $this->Cell(10,5,$year,0,0,'C',true);
88 $this->Cell(35,5,$brews,0,0,'R',true);
89 $this->Cell(35,5,sprintf("%.1f",$packaged).' L',0,0,'R',true);
90 $this->Cell(35,5,sprintf("%.1f",$average).' L',0,0,'R',true);
91 $this->Ln();
92 }
93 $this->Cell($vul+25,5,'',0,0,'L',false);
94 $this->Cell(35,5,$total,0,0,'R',true);
95 $this->Cell(35,5,sprintf("%.1f",$tvolume).' L',0,0,'R',true);
96 $this->ProcessingTable=false;
97 $this->cMargin=$cMargin;
98 $this->aCols=array();
99 $this->Ln();
100 }
101 }
102
103
104
105 class PDF extends PDF_MySQL_Table {
106 function Header() {
107 global $prdate;
108 global $my_brewery_name;
109 $this->Image('images/logo.png',10,10,30);
110 // Title
111 $this->SetFont('Helvetica','B',18);
112 $this->SetX(45);
113 $this->Cell(0,8,"Jaarproductie ".$my_brewery_name,0,1,'L');
114 $this->Ln(1);
115 $this->SetFont('Helvetica','',10);
116 $this->SetX(45);
117 $this->Cell(17,5,'Datum:',0,0,'L');
118 $this->Cell(0,5,$prdate,0,1,'L');
119 $this->Ln(20);
120 // Ensure table header is printed
121 parent::Header();
122 }
123 }
124
125
126
127 /*
128 * Generate PDF
129 */
130 $pdf = new PDF();
131 $pdf->AddPage();
132 $pdf->TableTotals();
133 $pdf->Output();

mercurial