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