# HG changeset patch # User Michiel Broek # Date 1541627559 -3600 # Node ID 75b9227fb98c05a86e599f317a505abd3a85ed53 # Parent f3adf543f698cf9479e5b9039708bad775b9992d Added beginning of recipe print. diff -r f3adf543f698 -r 75b9227fb98c www/includes/db_recipes.php --- a/www/includes/db_recipes.php Wed Nov 07 16:25:05 2018 +0100 +++ b/www/includes/db_recipes.php Wed Nov 07 22:52:39 2018 +0100 @@ -32,7 +32,7 @@ $sql .= "', st_letter='" . mysqli_real_escape_string($connect, $_POST['st_letter']); $sql .= "', st_guide='" . mysqli_real_escape_string($connect, $_POST['st_guide']); $sql .= "', st_type='" . mysqli_real_escape_string($connect, $_POST['st_type']); - $sql .= "', st_category='" . mysqli_real_escape_string($connect, $_POST['st_categpry']); + $sql .= "', st_category='" . mysqli_real_escape_string($connect, $_POST['st_category']); $sql .= "', st_category_number='" . $_POST['st_category_number']; $sql .= "', st_og_min='" . $_POST['st_og_min']; $sql .= "', st_og_max='" . $_POST['st_og_max']; diff -r f3adf543f698 -r 75b9227fb98c www/rec_print.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/rec_print.php Wed Nov 07 22:52:39 2018 +0100 @@ -0,0 +1,200 @@ +ProcessingTable) + $this->TableHeader(); + } + + function TableHeader() { + $this->SetFont('Helvetica','B',9); + $this->SetX($this->TableX); + $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); + 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 TableGlobal($row,$prop) { + /* 2 Columns */ + $vul = $this->w - $this->rMargin - $this->lMargin - 170; + $cMargin=$this->cMargin; + $this->cMargin=$prop['padding']; + $this->TableX=$this->lMargin; + $this->HeaderColor=$prop['HeaderColor']; + $this->TotalColor=$prop['TotalColor']; + $this->RowColors=array($prop['color1'],$prop['color2']); + $this->SetFont('Helvetica','B',11); + $this->SetX($this->TableX); + $this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]); + $this->Cell(0, 6, 'Recept overzicht',0,0,'C',true); + $this->Ln(); + + $this->SetFont('Helvetica','',9); + $this->SetFillColor($this->RowColors[0][0],$this->RowColors[0][1],$this->RowColors[0][2]); + + $this->SetX($this->TableX); + $this->Cell(35,5,'Type',0,0,'L',true); + $this->Cell(25,5,$row['type'],0,0,'L',true); + $this->Cell(25,5,'',0,0,'L',true); + $this->Cell($vul,5,'',0,0,'L',false); + $this->Cell(35,5,'Batch grootte',0,0,'L',true); + $this->Cell(25,5,$row['batch_size'].' liter',0,0,'L',true); + $this->Cell(25,5,'',0,0,'L',true); + $this->Ln(); + + $this->SetX($this->TableX); + $this->Cell(35,5,'Kooktijd',0,0,'L',true); + $this->Cell(25,5,$row['boil_time'].' minuten',0,0,'L',true); + $this->Cell(25,5,'',0,0,'L',true); + $this->Cell($vul,5,'',0,0,'L',false); + $this->Cell(35,5,'Brouwzaal rendement',0,0,'L',true); + $this->Cell(25,5,$row['efficiency'].' %',0,0,'L',true); + $this->Cell(25,5,'',0,0,'L',true); + $this->Ln(); + + $this->SetX($this->TableX); + $this->Cell(35,5,'Start SG',0,0,'L',true); + $this->Cell(25,5,sprintf("%.3f",$row['est_og']),0,0,'L',true); + $this->Cell(25,5,'('.sprintf("%.3f",$row['st_og_min']).' - '.sprintf("%.3f",$row['st_og_max']).')',0,0,'L',true); + $this->Cell($vul,5,'',0,0,'L',false); + $this->Cell(35,5,'Eind SG',0,0,'L',true); + $this->Cell(25,5,sprintf("%.3f",$row['est_fg']),0,0,'L',true); + $this->Cell(25,5,'('.sprintf("%.3f",$row['st_fg_min']).' - '.sprintf("%.3f",$row['st_fg_max']).')',0,0,'L',true); + $this->Ln(); + + $this->SetX($this->TableX); + $this->Cell(35,5,'Geschat alcohol',0,0,'L',true); + $this->Cell(25,5,sprintf("%.1f",$row['est_abv']).'%',0,0,'L',true); + $this->Cell(25,5,'('.sprintf("%.1f",$row['st_abv_min']).' - '.sprintf("%.1f",$row['st_abv_max']).'%)',0,0,'L',true); + $this->Cell($vul,5,'',0,0,'L',false); + $this->Cell(35,5,'CO2',0,0,'L',true); + $this->Cell(25,5,sprintf("%.1f",$row['est_carb']).'%',0,0,'L',true); + $this->Cell(25,5,'('.sprintf("%.1f",$row['st_carb_min']).' - '.sprintf("%.1f",$row['st_carb_max']).'%)',0,0,'L',true); + $this->Ln(); + + $this->SetX($this->TableX); + $this->Cell(35,5,'Kleur ('.$row['color_method'].')',0,0,'L',true); + $this->Cell(25,5,$row['est_color'].' EBC',0,0,'L',true); + $this->Cell(25,5,'('.$row['st_color_min'].' - '.$row['st_color_max'].' EBC)',0,0,'L',true); + $this->Cell($vul,5,'',0,0,'L',false); + $this->Cell(35,5,'Bitterheid ('.$row['ibu_method'].')',0,0,'L',true); + $this->Cell(25,5,sprintf("%.0f",$row['est_ibu']).' IBU',0,0,'L',true); + $this->Cell(25,5,'('.$row['st_ibu_min'].' - '.$row['st_ibu_max'].' IBU)',0,0,'L',true); + $this->Ln(); + + $this->cMargin=$cMargin; + } + + function TableFermentables($row,$prop) { + $vul = $this->w - $this->rMargin - $this->lMargin - 130; + $this->AddCol($vul,'Grondstof','L'); + $this->AddCol( 30,'Leverancier','L'); + $this->AddCol( 15,'EBC','R'); + $this->AddCol( 15,'Moment','L'); + $this->AddCol( 20,'Kg','R'); + $this->AddCol( 15,'Procent','R'); + $this->AddCol( 15,'Opbr.','R'); + $this->AddCol( 20,'Prijs','R'); + + $cMargin=$this->cMargin; + $this->cMargin=$prop['padding']; + $this->TableX=$this->lMargin; + $this->TableHeader(); + $this->ColorIndex=0; + $this->ProcessingTable=true; + + $this->SetFont('Helvetica','',9); + $this->SetFillColor($this->RowColors[0][0],$this->RowColors[0][1],$this->RowColors[0][2]); + + $arr = json_decode($row['json_fermentables'], true); + foreach($arr as $item) { //foreach element in $arr + $name = $item['f_name']; + $supplier = $item['f_supplier']; + $amount = floatval($item['f_amount']); + $costkg = floatval($item['f_cost']); + $yield = floatval($item['f_yield']); + $color = floatval($item['f_color']); + $percent = floatval($item['f_percentage']); + if ($item['f_added'] == "Boil") + $add = "Koken"; + else if ($item['f_added'] == "Mash") + $add = "Maisch"; + else + $add = $item['f_added']; + $cost = $amount * $costkg; + $this->Cell($vul,5,$name,0,0,'L',true); + $this->Cell(30,5,$supplier,0,0,'L',true); + $this->Cell(15,5,sprintf("%.0f",$color),0,0,'R',true); + $this->Cell(15,5,$add,0,0,'L',true); + $this->Cell(20,5,sprintf("%8.3f",$amount),0,0,'R',true); + $this->Cell(15,5,sprintf("%.1f%%",$percent),0,0,'R',true); + $this->Cell(15,5,sprintf("%.1f%%",$yield),0,0,'R',true); + $this->Cell(20,5,sprintf("%8.3f",$cost).EURO,0,0,'R',true); + $this->Ln(); + } + + $this->ProcessingTable=false; + $this->cMargin=$cMargin; + $this->aCols=array(); + } +} + + + +class PDF extends PDF_MySQL_Table { + function Header() { + global $row; + $this->Image('images/logo.png',10,6,30); + // Title + $this->SetFont('Helvetica','B',18); + $this->SetX(45); + $this->Cell(0,8,$row['name'],1,1,'L'); + $this->Ln(20); + // Ensure table header is printed + parent::Header(); + } +} + + +/* + * Generate PDF from recipe data + */ +$pdf = new PDF(); +$pdf->AddPage(); +$prop = array('HeaderColor'=>array(255,150,100), 'color1'=>array(210,245,255), + 'color2'=>array(255,255,210), 'TotalColor'=>array(255,150,100), 'padding'=>2); +$pdf->TableGlobal($row,$prop); +$pdf->Ln(10); +$pdf->TableFermentables($row,$prop); + +//$pdf->SetFont('Helvetica','',10); +//$pdf->Cell(0,10,'Receptje '.$record,0,1,'C'); + +$pdf->Output();