Fri, 14 Aug 2020 11:38:58 +0200
Fixed recipe upload style category number default. Changed default style guid to BKG 2019.
454 | 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 - 151; | |
51 | $this->AddCol(16,'Code','L'); | |
52 | $this->AddCol($vul,'Naam','L'); | |
53 | $this->AddCol(35,'Gist','L'); | |
54 | $this->AddCol(20,'Hoofdgisting','R'); | |
55 | $this->AddCol(20,'Nagisten','R'); | |
56 | $this->AddCol(20,'Lageren','R'); | |
57 | $this->AddCol(10,'Duur','R'); | |
58 | $this->AddCol(10,'OG','R'); | |
59 | $this->AddCol(10,'FG','R'); | |
60 | $this->AddCol(12,'SVG','R'); | |
61 | ||
62 | $cMargin=$this->cMargin; | |
63 | $this->cMargin=2; | |
64 | $this->TableX=$this->lMargin; | |
65 | $this->TableHeader(); | |
66 | $this->ProcessingTable=true; | |
67 | ||
68 | $this->SetFont('Helvetica','',9); | |
69 | $this->SetFillColor(210,245,255); | |
70 | ||
71 | $result = mysqli_query($link, "SELECT * FROM products WHERE package_date AND type='2' ORDER BY json_yeasts"); | |
72 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
73 | /* | |
74 | * Data is not always available, try to calculate the mssing pieces. | |
75 | */ | |
76 | $y_name = $y_lab = $y_product = ''; | |
77 | $yeasts = json_decode($row['json_yeasts'], true); | |
78 | foreach($yeasts as $item) { | |
79 | if ($item['y_use'] == 0) { | |
80 | $y_name = iconv('UTF-8','windows-1252',$item['y_name']); | |
81 | $y_lab = iconv('UTF-8','windows-1252',$item['y_laboratory']); | |
82 | $y_product = iconv('UTF-8','windows-1252',$item['y_product_id']); | |
83 | break; | |
84 | } | |
85 | } | |
86 | ||
87 | // name,brew_date_end,primary_end_date,secondary_end_date,package_date | |
88 | $d1 = new DateTime($row['brew_date_end']); | |
89 | $d2 = new DateTime($row['primary_end_date']); | |
90 | $d3 = new DateTime($row['secondary_end_date']); | |
91 | $d4 = new DateTime($row['package_date']); | |
92 | ||
93 | $diff = $d2->diff($d1); | |
94 | $primary_days = $diff->days; | |
95 | $diff = $d3->diff($d2); | |
96 | $secondary_days = $diff->days; | |
97 | $diff = $d4->diff($d3); | |
98 | $tertiary_days = $diff->days; | |
99 | $diff = $d4->diff($d1); | |
100 | $total_days = $diff->days; | |
101 | ||
102 | $og = floatval($row['brew_fermenter_sg']); | |
103 | $fg = floatval($row['fg']); | |
655
f4e00869f39f
Calculate the svg using Brew by the Numbers, Micahel L. Hall.
Michiel Broek <mbroek@mbse.eu>
parents:
454
diff
changeset
|
104 | $svg = calc_svg($og, $fg); |
454 | 105 | |
106 | $name = iconv('UTF-8','windows-1252',$row['name']); | |
107 | $this->SetX($this->TableX); | |
108 | $this->Cell(16,5,$row['code'],0,0,'L',true); | |
109 | $this->Cell($vul,5,$name,0,0,'L',true); | |
110 | $this->Cell(35,5,$y_lab.' '.$y_product,0,0,'L',true); | |
111 | $this->Cell(13,5,sprintf("%.1f",$row['primary_end_temp']).DEG,0,0,'R',true); | |
112 | $this->Cell( 7,5,sprintf("%d",$primary_days),0,0,'R',true); | |
113 | $this->Cell(13,5,sprintf("%.1f",$row['secondary_temp']).DEG,0,0,'R',true); | |
114 | $this->Cell( 7,5,sprintf("%d",$secondary_days),0,0,'R',true); | |
115 | $this->Cell(13,5,sprintf("%.1f",$row['tertiary_temp']).DEG,0,0,'R',true); | |
116 | $this->Cell( 7,5,sprintf("%d",$tertiary_days),0,0,'R',true); | |
117 | $this->Cell(10,5,sprintf("%d",$total_days),0,0,'R',true); | |
118 | $this->Cell(10,5,sprintf("%.3f",$og),0,0,'R',true); | |
119 | $this->Cell(10,5,sprintf("%.3f",$fg),0,0,'R',true); | |
120 | $this->Cell(12,5,sprintf("%.1f",$svg).'%',0,0,'R',true); | |
121 | $this->Ln(); | |
122 | } | |
123 | $this->ProcessingTable=false; | |
124 | $this->cMargin=$cMargin; | |
125 | $this->aCols=array(); | |
126 | $this->Ln(); | |
127 | } | |
128 | } | |
129 | ||
130 | ||
131 | ||
132 | class PDF extends PDF_MySQL_Table { | |
133 | function Header() { | |
134 | global $prdate; | |
135 | global $my_brewery_name; | |
136 | $this->Image('images/logo.png',10,10,30); | |
137 | // Title | |
138 | $this->SetFont('Helvetica','B',18); | |
139 | $this->SetX(45); | |
140 | $this->Cell(0,8,"Vergisting ".$my_brewery_name,0,1,'L'); | |
141 | $this->Ln(1); | |
142 | $this->SetFont('Helvetica','',10); | |
143 | $this->SetX(45); | |
144 | $this->Cell(17,5,'Datum:',0,0,'L'); | |
145 | $this->Cell(0,5,$prdate,0,1,'L'); | |
146 | $this->Ln(20); | |
147 | // Ensure table header is printed | |
148 | parent::Header(); | |
149 | } | |
150 | } | |
151 | ||
152 | ||
153 | ||
154 | /* | |
155 | * Generate PDF | |
156 | */ | |
157 | $pdf = new PDF(); | |
158 | $pdf->AddPage(); | |
159 | $pdf->TableTotals(); | |
160 | $pdf->Output(); |