Sun, 23 May 2021 16:41:35 +0200
Fermentables, hops, miscs and yeast now have tests against the added moment with the brewing stage. Added to inventory edit rows, delete rows, and pick choices for the moment to add or edit. Some more popups to explain certain blocks.
626 | 1 | <?php |
2 | require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); | |
3 | require_once($_SERVER['DOCUMENT_ROOT'].'/includes/constants.php'); | |
4 | require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php'); | |
5 | ||
6 | define('EURO', chr(128) ); | |
7 | ||
8 | $link = mysqli_connect(DBASE_HOST,DBASE_USER,DBASE_PASS,DBASE_NAME); | |
9 | if (! $link) { | |
10 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
11 | } | |
12 | if (! mysqli_set_charset($link, "utf8" )) { | |
13 | echo "error"; | |
14 | return 1; | |
15 | } | |
16 | ||
17 | setlocale ( LC_ALL, 'nl_NL.UTF-8'); | |
18 | date_default_timezone_set('Europe/Amsterdam'); | |
19 | $prdate = date(DATE_RFC2822); | |
20 | ||
21 | $sql = "SELECT brewery_name,my_yeastlab FROM profile_setup WHERE record = '1';"; | |
22 | $result = mysqli_query($link, $sql); | |
23 | if ($row=mysqli_fetch_array($result)) { | |
24 | $my_brewery = iconv('UTF-8','windows-1252',$row['brewery_name']); | |
25 | $my_lab = $row['my_yeastlab']; | |
26 | } else { | |
27 | $my_brewery = $my_lab = ''; | |
28 | } | |
29 | ||
30 | ||
31 | class PDF_MySQL_Table extends FPDF | |
32 | { | |
33 | protected $ProcessingTable=false; | |
34 | protected $aCols=array(); | |
35 | protected $TableX; | |
36 | protected $HeaderColor; | |
37 | protected $RowColors; | |
38 | protected $TotalColor; | |
39 | protected $ColorIndex; | |
40 | ||
41 | function Header() { | |
42 | // Print the table header if necessary | |
43 | if ($this->ProcessingTable) | |
44 | $this->TableHeader(); | |
45 | } | |
46 | ||
47 | function TableHeader() { | |
48 | $this->SetFont('Helvetica','B',9); | |
49 | $this->SetX($this->TableX); | |
50 | $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); | |
51 | foreach($this->aCols as $col) | |
52 | $this->Cell($col['w'],5,$col['c'],0,0,$col['a'],true); | |
53 | $this->Ln(); | |
54 | } | |
55 | ||
56 | function CalcWidths($width, $align) { | |
57 | // Compute the widths of the columns | |
58 | $TableWidth=0; | |
59 | foreach($this->aCols as $i=>$col) { | |
60 | $w=$col['w']; | |
61 | if($w==-1) | |
62 | $w=$width/count($this->aCols); | |
63 | elseif(substr($w,-1)=='%') | |
64 | $w=$w/100*$width; | |
65 | $this->aCols[$i]['w']=$w; | |
66 | $TableWidth+=$w; | |
67 | } | |
68 | // Compute the abscissa of the table | |
69 | if($align=='C') | |
70 | $this->TableX=max(($this->w-$TableWidth)/2,0); | |
71 | elseif($align=='R') | |
72 | $this->TableX=max($this->w-$this->rMargin-$TableWidth,0); | |
73 | else | |
74 | $this->TableX=$this->lMargin; | |
75 | } | |
76 | ||
77 | function AddCol($width=-1, $caption='', $align='L') { | |
78 | $this->aCols[]=array('c'=>$caption,'w'=>$width,'a'=>$align); | |
79 | } | |
80 | ||
81 | function TableYeasts($link,$prop) { | |
82 | global $yeasttype; | |
83 | global $yeastform; | |
84 | global $my_lab; | |
630
ffe0416614b3
Added short_desc to the yeast inventory database for short remarks in the yeastlab pdf list
Michiel Broek <mbroek@mbse.eu>
parents:
626
diff
changeset
|
85 | $this->AddCol( 60,'Gist','L'); |
ffe0416614b3
Added short_desc to the yeast inventory database for short remarks in the yeastlab pdf list
Michiel Broek <mbroek@mbse.eu>
parents:
626
diff
changeset
|
86 | $this->AddCol( 50,'Omschrijving','L'); |
626 | 87 | $this->AddCol( 18,'Soort','L'); |
88 | $this->AddCol( 18,'Vorm','L'); | |
89 | $this->AddCol( 20,'Voorraad','R'); | |
90 | $this->AddCol( 25,'Datum','L'); | |
91 | $prop['width']=$this->w-$this->lMargin-$this->rMargin; | |
92 | $prop['align']='L'; | |
93 | $cMargin=$this->cMargin; | |
94 | $this->cMargin=$prop['padding']; | |
95 | $this->HeaderColor=$prop['HeaderColor']; | |
96 | $this->TotalColor=$prop['TotalColor']; | |
97 | $this->RowColors=array($prop['color1'],$prop['color2']); | |
98 | $this->CalcWidths($prop['width'],$prop['align']); | |
99 | $this->TableHeader(); | |
100 | $this->SetFont('Helvetica','',9); | |
101 | $this->ColorIndex=0; | |
102 | $this->ProcessingTable=true; | |
103 | ||
630
ffe0416614b3
Added short_desc to the yeast inventory database for short remarks in the yeastlab pdf list
Michiel Broek <mbroek@mbse.eu>
parents:
626
diff
changeset
|
104 | $sql = "SELECT name,type,form,inventory,production_date,short_desc FROM inventory_yeasts "; |
626 | 105 | $sql .= "WHERE inventory > 0 AND laboratory = '".$my_lab."' ORDER BY product_id"; |
106 | $result = mysqli_query($link, $sql); | |
107 | ||
108 | while ($row=mysqli_fetch_array($result)) { | |
109 | if ($row['form'] == 0) | |
110 | $stock = floatval($row['inventory']); | |
111 | else | |
112 | $stock = floatval($row['inventory']) * 1000.0; | |
113 | $form = array( 'pak', 'gr', 'ml', 'ml', 'ml', 'ml', 'gr' ); | |
114 | ||
115 | $this->SetX($this->TableX); | |
116 | $ci=$this->ColorIndex; | |
117 | $this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]); | |
630
ffe0416614b3
Added short_desc to the yeast inventory database for short remarks in the yeastlab pdf list
Michiel Broek <mbroek@mbse.eu>
parents:
626
diff
changeset
|
118 | $this->Cell(60,5,iconv('UTF-8','windows-1252',$row['name']),0,0,'L',true); |
ffe0416614b3
Added short_desc to the yeast inventory database for short remarks in the yeastlab pdf list
Michiel Broek <mbroek@mbse.eu>
parents:
626
diff
changeset
|
119 | $this->Cell(50,5,iconv('UTF-8','windows-1252',$row['short_desc']),0,0,'L',true); |
626 | 120 | $this->Cell(18,5,iconv('UTF-8','windows-1252',$yeasttype[$row['type']]),0,0,'L',true); |
121 | $this->Cell(18,5,iconv('UTF-8','windows-1252',$yeastform[$row['form']]),0,0,'L',true); | |
122 | $this->Cell(20,5,sprintf("%10.1f ",$stock).$form[$row['form']],0,0,'R',true); | |
123 | $this->Cell(25,5,$row['production_date'],0,0,'L',true); | |
124 | $this->Ln(); | |
125 | $this->ColorIndex=1-$ci; | |
126 | } | |
127 | ||
128 | $this->ProcessingTable=false; | |
129 | $this->cMargin=$cMargin; | |
130 | $this->aCols=array(); | |
131 | } | |
132 | } | |
133 | ||
134 | ||
135 | ||
136 | class PDF extends PDF_MySQL_Table { | |
137 | function Header() { | |
138 | global $prdate; | |
139 | global $my_brewery; | |
140 | $this->Image('images/logo.png',10,6,30); | |
141 | // Title | |
142 | $this->SetFont('Helvetica','',18); | |
143 | $this->SetX(45); | |
144 | $this->Cell(0,10,'Gistbank van '.$my_brewery,0,1,'L'); | |
145 | $this->Ln(1); | |
146 | $this->SetFont('Helvetica','',10); | |
147 | $this->SetX(45); | |
148 | $this->Cell(17,5,'Datum:',0,0,'L'); | |
149 | $this->Cell(0,5,$prdate,0,1,'L'); | |
150 | $this->Ln(18); | |
151 | // Ensure table header is printed | |
152 | parent::Header(); | |
153 | } | |
154 | } | |
155 | ||
156 | ||
157 | $pdf = new PDF(); | |
158 | $pdf->AddPage(); | |
159 | $prop = array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255), | |
160 | 'color2'=>array(255,255,210), 'TotalColor'=>array(255,150,100), 'padding'=>2); | |
161 | $pdf->TableYeasts($link,$prop); | |
162 | $pdf->Output(); |