www/import/from_brouwhulp.php

Sat, 08 Dec 2018 17:11:38 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 08 Dec 2018 17:11:38 +0100
changeset 131
71f1ca48c551
parent 126
9999b3ce98cb
child 136
bcc4583fd013
permissions
-rw-r--r--

When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.

11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 <?php
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 /*
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * Import inventory from brouwhulp
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 */
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 require("../config.php");
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 require("../version.php");
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 require("../includes/formulas.php");
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 echo "Start adding data from brouwhulp\n";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 $db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 if (! $db) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 }
77
a9f8de2d7b2b Fixed most charset problems. Added fpdf library. Added inventory pdf creation.
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
16 mysqli_set_charset($db, "utf8" );
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 $brouwhulp = '/home/mbroek/Documents/brouwhulp';
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
19 $pCara = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
20 $pSugar = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
21 $efficiency = 75;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
22 $batch_size = 20;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
23 $colorw = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
24 $f_sugars = 0;
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
89
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
26 function get_miscs_cost($miscname) {
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
27 global $db;
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
28
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
29 if ($result = mysqli_query($db, "SELECT cost FROM inventory_miscs WHERE name='$miscname'")) {
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
30 if ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
31 return floatval($row['cost']);
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
32 }
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
33 }
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
34 return 0.0;
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
35 }
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
36
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
37
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
38
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 function do_fermentables()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 echo " Start adding fermentables to the database\n";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 $sql = "TRUNCATE TABLE inventory_fermentables;";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 $myfermentables = simplexml_load_file($brouwhulp . '/fermentables.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 foreach ($myfermentables->FERMENTABLE as $fermentable) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 $sql = "INSERT INTO inventory_fermentables SET name='" . mysqli_real_escape_string($db, $fermentable->NAME);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 $sql .= "', type='" . $fermentable->TYPE;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 if ($fermentable->YIELD)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
55 $sql .= "', yield='" . floatval($fermentable->YIELD);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 if ($fermentable->COLOR) {
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
57 $srm = floatval($fermentable->COLOR);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 $ebc = srm_to_ebc($srm);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 $sql .= "', color='" . $ebc;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 ($fermentable->ADD_AFTER_BOIL == "TRUE") ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 $sql .= "', origin='" . mysqli_real_escape_string($db, $fermentable->ORIGIN);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 $sql .= "', supplier='" . mysqli_real_escape_string($db, $fermentable->SUPPLIER);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 $sql .= "', notes='" . mysqli_real_escape_string($db, $fermentable->NOTES);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 if ($fermentable->COARSE_FINE_DIFF)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
66 $sql .= "', coarse_fine_diff='" . floatval($fermentable->COARSE_FINE_DIFF);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 if ($fermentable->MOISTURE)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
68 $sql .= "', moisture='" . floatval($fermentable->MOISTURE);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 if ($fermentable->DIASTATIC_POWER)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
70 $sql .= "', diastatic_power='" . floatval($fermentable->DIASTATIC_POWER);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 if ($fermentable->PROTEIN)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
72 $sql .= "', protein='" . floatval($fermentable->PROTEIN);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 if ($fermentable->MAX_IN_BATCH)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
74 $sql .= "', max_in_batch='" . floatval($fermentable->MAX_IN_BATCH);
21
acb2d8098f19 Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
75 ($fermentable->RECOMMEND_MASH == "TRUE") ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 if ($fermentable->IBU_GAL_PER_LB)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
77 $sql .= "', ibu_gal_per_lb='" . floatval($fermentable->IBU_GAL_PER_LB);
21
acb2d8098f19 Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
78 ($fermentable->ALWAYS_ON_STOCK == "TRUE") ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 if ($fermentable->INVENTORY)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
80 $sql .= "', inventory='" . floatval($fermentable->INVENTORY);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 if ($fermentable->COST)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
82 $sql .= "', cost='" . floatval($fermentable->COST);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 /*
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 * These are not beerxml standard:
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 */
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 if ($fermentable->DI_pH)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
87 $sql .= "', di_ph='" . floatval($fermentable->DI_pH);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 if ($fermentable->{'ACID_TO_pH_5.7'})
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
89 $sql .= "', acid_to_ph_57='" . floatval($fermentable->{'ACID_TO_pH_5.7'});
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 $sql .= "', graintype='" . $fermentable->GRAINTYPE;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 $sql .= "';";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 function do_hops()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 echo " Start adding hops to the database\n";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 $sql = "TRUNCATE TABLE inventory_hops;";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 $myhops = simplexml_load_file($brouwhulp . '/hops.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 foreach ($myhops->HOP as $hop) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 $sql = "INSERT INTO inventory_hops SET name='" . mysqli_real_escape_string($db, $hop->NAME);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 if ($hop->ALPHA)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
115 $sql .= "', alpha='" . floatval($hop->ALPHA);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 if ($hop->BETA)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
117 $sql .= "', beta='" . floatval($hop->BETA);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 if ($hop->HUMULENE)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
119 $sql .= "', humulene='" . floatval($hop->HUMULENE);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 if ($hop->CARYOPHYLLENE)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
121 $sql .= "', caryophyllene='" . floatval($hop->CARYOPHYLLENE);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 if ($hop->COHUMULONE)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
123 $sql .= "', cohumulone='" . floatval($hop->COHUMULONE);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 if ($hop->MYCRENE)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
125 $sql .= "', myrcene='" . floatval($hop->MYCRENE);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 if ($hop->HSI)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
127 $sql .= "', hsi='" . floatval($hop->HSI);
69
ca25fdce3b85 Improved hop selection dropdown
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
128 $sql .= "', useat='Boil"; // brouwhulp says Aroma always :)
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 $sql .= "', type='" . $hop->TYPE;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 $sql .= "', form='" . $hop->FORM;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 $sql .= "', notes='" . mysqli_real_escape_string($db, $hop->NOTES);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 $sql .= "', origin='" . mysqli_real_escape_string($db, $hop->ORIGIN);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 $sql .= "', substitutes='" . mysqli_real_escape_string($db, $hop->SUBSTITUTES);
21
acb2d8098f19 Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
134 ($hop->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 if ($hop->INVENTORY)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
136 $sql .= "', inventory='" . floatval($hop->INVENTORY) / 1000.0;
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 if ($hop->COST)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
138 $sql .= "', cost='" . floatval($hop->COST);
13
b8c3ca152984 Added hops inventory
Michiel Broek <mbroek@mbse.eu>
parents: 11
diff changeset
139 if ($hop->TOTAL_OIL)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
140 $sql .= "', total_oil='" . floatval($hop->TOTAL_OIL);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 $sql .= "';";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 function do_yeasts()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 echo " Start adding yeasts to the database\n";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 $sql = "TRUNCATE TABLE inventory_yeasts;";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 $yeasts = simplexml_load_file($brouwhulp . '/yeasts.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 foreach ($yeasts->YEAST as $yeast) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 $sql = "INSERT INTO inventory_yeasts SET name='" . mysqli_real_escape_string($db, $yeast->NAME);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 $sql .= "', type='" . $yeast->TYPE;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 $sql .= "', form='" . $yeast->FORM;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 $sql .= "', laboratory='" . mysqli_real_escape_string($db, $yeast->LABORATORY);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 $sql .= "', product_id='" . mysqli_real_escape_string($db, $yeast->PRODUCT_ID);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 if ($yeast->MIN_TEMPERATURE)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
171 $sql .= "', min_temperature='" . floatval($yeast->MIN_TEMPERATURE);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 if ($yeast->MAX_TEMPERATURE)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
173 $sql .= "', max_temperature='" . floatval($yeast->MAX_TEMPERATURE);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 $sql .= "', flocculation='" . $yeast->FLOCCULATION;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 if ($yeast->ATTENUATION)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
176 $sql .= "', attenuation='" . floatval($yeast->ATTENUATION);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 $sql .= "', notes='" . mysqli_real_escape_string($db, $yeast->NOTES);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 $sql .= "', best_for='" . mysqli_real_escape_string($db, $yeast->BEST_FOR);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 if ($yeast->MAX_REUSE)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 $sql .= "', max_reuse='" . $yeast->MAX_REUSE;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 if ($yeast->INVENTORY)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
182 $sql .= "', inventory='" . floatval($yeast->INVENTORY) / 1000.0;
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 if ($yeast->COST)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
184 $sql .= "', cost='" . floatval($yeast->COST) * 1000.0;
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 if ($yeast->CULTURE_DATE) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 $date = substr($yeast->CULTURE_DATE, 6, 4) . '-' . substr($yeast->CULTURE_DATE, 3, 2) . '-' . substr($yeast->CULTURE_DATE, 0, 2);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 $sql .= "', production_date='" . $date;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 $sql .= "';";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 function do_waters()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 echo " Start adding waters to the database\n";
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
203 $sql = "TRUNCATE TABLE profile_water;";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 }
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
207 $sql = "TRUNCATE TABLE inventory_waters;";
15
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
208 if (! $result = mysqli_query($db, $sql)) {
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
209 printf("Error: %s\n", mysqli_error($db));
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
210 }
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 $waters = simplexml_load_file($brouwhulp . '/waters.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 foreach ($waters->WATER as $water) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215
15
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
216 if (($water->NAME == "Gedemineraliseerd water") || ($water->NAME == "Cristalline") || ($water->NAME == "Montille (Delhaize)") ||
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
217 ($water->NAME == "Spa Reine") || ($water->NAME == "Velsen") || ($water->NAME == "Zutphen") ||
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
218 ($water->NAME == "Aurele Bronwater (Colruyt)")) {
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
219 $sql = "INSERT INTO inventory_waters SET name='" . mysqli_real_escape_string($db, $water->NAME);
15
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
220 } else {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
221 $sql = "INSERT INTO profile_water SET name='" . mysqli_real_escape_string($db, $water->NAME);
15
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
222 }
ccbe79db80b8 Waters import and home page
Michiel Broek <mbroek@mbse.eu>
parents: 13
diff changeset
223
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 if ($water->NOTES)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 $sql .= "', notes='" . mysqli_real_escape_string($db, $water->NOTES);
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
226 $sql .= "', calcium='" . floatval($water->CALCIUM);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
227 $sql .= "', bicarbonate='" . floatval($water->BICARBONATE);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
228 $sql .= "', sulfate='" . floatval($water->SULFATE);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
229 $sql .= "', chloride='" . floatval($water->CHLORIDE);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
230 $sql .= "', sodium='" . floatval($water->SODIUM);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
231 $sql .= "', magnesium='" . floatval($water->MAGNESIUM);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
232 $sql .= "', ph='" . floatval($water->PH);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 if ($water->TOTAL_ALKALINITY)
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
234 $sql .= "', total_alkalinity='" . floatval($water->TOTAL_ALKALINITY);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 $sql .= "';";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 function do_miscs()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 echo " Start adding miscs to the database\n";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 $sql = "TRUNCATE TABLE inventory_miscs;";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 $miscs = simplexml_load_file($brouwhulp . '/miscs.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 foreach ($miscs->MISC as $misc) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 $sql = "INSERT INTO inventory_miscs SET name='" . mysqli_real_escape_string($db, $misc->NAME);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 if ($misc->NOTES)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260 $sql .= "', notes='" . mysqli_real_escape_string($db, $misc->NOTES);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 $sql .= "', type='" . $misc->TYPE;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262 $sql .= "', use_use='" . $misc->USE;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 $sql .= "', time='" . $misc->TIME;
21
acb2d8098f19 Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
264 ($misc->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='1" : $sql .= "', amount_is_weight='0";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 if ($misc->USE_FOR)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 $sql .= "', use_for='" . mysqli_real_escape_string($db, $misc->USE_FOR);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 if ($misc->ALWAYS_ON_STOCK)
21
acb2d8098f19 Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
268 ($misc->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 if ($misc->INVENTORY)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
270 $sql .= "', inventory='" . floatval($misc->INVENTORY) / 1000.0;
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 if ($misc->COST)
32
8bb369f32ef9 Fixed floating precision problems and also got the SRM to EBC conversion right.
Michiel Broek <mbroek@mbse.eu>
parents: 30
diff changeset
272 $sql .= "', cost='" . floatval($misc->COST);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 $sql .= "';";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 function do_equipments()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 echo " Start adding equipments to the database\n";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 $sql = "TRUNCATE TABLE inventory_equipments;";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 $equipments = simplexml_load_file($brouwhulp . '/equipments.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 foreach ($equipments->EQUIPMENT as $equipment) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 $sql = "INSERT INTO inventory_equipments SET name='" . mysqli_real_escape_string($db, $equipment->NAME);
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
297 $sql .= "', boil_size='" . floatval($equipment->BOIL_SIZE);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
298 $sql .= "', batch_size='" . floatval($equipment->BATCH_SIZE);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
299 $sql .= "', tun_volume='" . floatval($equipment->TUN_VOLUME);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
300 $sql .= "', tun_weight='" . floatval($equipment->TUN_WEIGHT);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
301 $sql .= "', tun_specific_heat='" . floatval($equipment->TUN_SPECIFIC_HEAT);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
302 $sql .= "', tun_material='" . mysqli_real_escape_string($db, $equipment->TUN_MATERIAL);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
303 $sql .= "', tun_height='" . floatval($equipment->TUN_HEIGHT);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
304 $sql .= "', top_up_water='" . floatval($equipment->TOP_UP_WATER);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
305 $sql .= "', trub_chiller_loss='" . floatval($equipment->TRUB_CHILLER_LOSS);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 /*
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 * Brouwhulp uses a percentage for the evaporation rate. This is wrong
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 * but was made so because the beerxml standard requires this. What we
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 * do is calculate the actual evaporation and store that.
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 * This is what we use. Brouwhulp calculates this on the fly.
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 */
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
312 $sql .= "', evap_rate='" . (floatval($equipment->EVAP_RATE) * floatval($equipment->BOIL_SIZE)) / 100.0;
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
313 $sql .= "', boil_time='" . floatval($equipment->BOIL_TIME);
21
acb2d8098f19 Added inventory miscs and water sources.
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
314 ($equipment->CALC_BOIL_VOLUME == 'TRUE') ? $sql .= "', calc_boil_volume='1" : $sql .= "', calc_boil_volume='0";
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
315 $sql .= "', top_up_kettle='" . floatval($equipment->TOP_UP_KETTLE);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
316 $sql .= "', hop_utilization='" . floatval($equipment->HOP_UTILIZATION);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 if ($equipment->NOTES)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 $sql .= "', notes='" . mysqli_real_escape_string($db, $equipment->NOTES);
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
319 $sql .= "', lauter_volume='" . floatval($equipment->LAUTER_VOLUME);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
320 $sql .= "', lauter_height='" . floatval($equipment->LAUTER_HEIGHT);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
321 $sql .= "', lauter_deadspace='" . floatval($equipment->LAUTER_DEADSPACE);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
322 $sql .= "', kettle_volume='" . floatval($equipment->KETTLE_VOLUME);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
323 $sql .= "', kettle_height='" . floatval($equipment->KETTLE_HEIGHT);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
324 $sql .= "', mash_volume='" . floatval($equipment->MASH_VOLUME);
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
325 $sql .= "', efficiency='" . floatval($equipment->EFFICIENCY);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 $sql .= "';";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 function do_styles()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 echo " Start adding styles to the database\n";
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
340 $sql = "TRUNCATE TABLE profile_styles;";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 $styles = simplexml_load_file($brouwhulp . '/styles.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 foreach ($styles->STYLE as $style) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
349 $sql = "INSERT INTO profile_styles SET name='" . mysqli_real_escape_string($db, $style->NAME);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 if ($style->NOTES)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 $sql .= "', notes='" . mysqli_real_escape_string($db, $style->NOTES);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 if ($style->CATEGORY)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353 $sql .= "', category='" . mysqli_real_escape_string($db, $style->CATEGORY);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 if ($style->CATEGORY_NUMBER)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355 $sql .= "', category_number='" . $style->CATEGORY_NUMBER;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 if ($style->STYLE_LETTER)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 $sql .= "', style_letter='" . mysqli_real_escape_string($db, $style->STYLE_LETTER);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 if ($style->STYLE_GUIDE)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 $sql .= "', style_guide='" . mysqli_real_escape_string($db, $style->STYLE_GUIDE);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360 $sql .= "', type='" . $style->TYPE;
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
361 $sql .= "', og_min='" . floatval($style->OG_MIN);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
362 $sql .= "', og_max='" . floatval($style->OG_MAX);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
363 $sql .= "', fg_min='" . floatval($style->FG_MIN);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
364 $sql .= "', fg_max='" . floatval($style->FG_MAX);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
365 $sql .= "', ibu_min='" . floatval($style->IBU_MIN);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
366 $sql .= "', ibu_max='" . floatval($style->IBU_MAX);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
367 $sql .= "', color_min='" . floatval($style->COLOR_MIN);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
368 $sql .= "', color_max='" . floatval($style->COLOR_MAX);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
369 $sql .= "', carb_min='" . floatval($style->CARB_MIN);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
370 $sql .= "', carb_max='" . floatval($style->CARB_MAX);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
371 $sql .= "', abv_min='" . floatval($style->ABV_MIN);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
372 $sql .= "', abv_max='" . floatval($style->ABV_MAX);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
373 if ($style->PROFILE)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374 $sql .= "', profile='" . mysqli_real_escape_string($db, $style->PROFILE);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375 if ($style->INGREDIENTS)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 $sql .= "', ingredients='" . mysqli_real_escape_string($db, $style->INGREDIENTS);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
377 if ($style->EXAMPLES)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 $sql .= "', examples='" . mysqli_real_escape_string($db, $style->EXAMPLES);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 $sql .= "';";
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 function do_mash()
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391 global $brouwhulp, $db;
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 echo " Start adding mash profiles to the database\n";
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
394 $sql = "TRUNCATE TABLE profile_mash;";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 if (! $result = mysqli_query($db, $sql)) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 printf("Error: %s\n", mysqli_error($db));
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 $mashes = simplexml_load_file($brouwhulp . '/mashs.xml');
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 foreach ($mashes->MASH as $mash) {
45
95251bedfab4 Moved three inventory tables and screens to profiles
Michiel Broek <mbroek@mbse.eu>
parents: 38
diff changeset
402 $sql = "INSERT INTO profile_mash SET name='" . mysqli_real_escape_string($db, $mash->NAME);
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 if ($mash->NOTES)
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 $sql .= "', notes='" . mysqli_real_escape_string($db, $mash->NOTES);
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 /*
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
407 * Put the steps in a json array
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 */
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 if ($mash->MASH_STEPS) {
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
410 $steps = "[";
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
411 $comma = FALSE;
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 foreach ($mash->MASH_STEPS->MASH_STEP as $step) {
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
414 if ($comma)
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
415 $steps .= ',';
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
416 $comma = TRUE;
38
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 35
diff changeset
417 $steps .= '{"step_name":"' . mysqli_real_escape_string($db, $step->NAME) . '"';
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
418 if ($step->TYPE) {
38
b7d44c98d609 Initial setup for mash steps editing.
Michiel Broek <mbroek@mbse.eu>
parents: 35
diff changeset
419 $steps .= ',"step_type":"' . $step->TYPE . '"';
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
420 }
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
421 if ($step->STEP_TEMP) {
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
422 $steps .= ',"step_temp":"' . floatval($step->STEP_TEMP) . '"';
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
423 }
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
424 if ($step->STEP_TIME) {
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
425 $steps .= ',"step_time":"' . floatval($step->STEP_TIME) . '"';
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 }
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
427 if ($step->RAMP_TIME) {
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
428 $steps .= ',"ramp_time":"' . floatval($step->RAMP_TIME) . '"';
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
429 }
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
430 if ($step->END_TEMP) {
118
07daa505d309 Improved float precision for databases import.
Michiel Broek <mbroek@mbse.eu>
parents: 114
diff changeset
431 $steps .= ',"end_temp":"' . floatval($step->END_TEMP) . '"';
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
432 }
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
433 $steps .= "}";
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 }
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
435 $steps .= ']';
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
436 $sql .= "', steps='" . $steps;
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
437 }
35
d6314a95021c Enabled mash
Michiel Broek <mbroek@mbse.eu>
parents: 32
diff changeset
438 $sql .= "';";
23
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
439 if (! $result = mysqli_query($db, $sql)) {
4b157d7a1cee Added first part of mash profiles. Steps are in the database but not in the web ui.
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
440 printf("Error: %s\n", mysqli_error($db));
11
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443 }
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445
d341f0a91a91 Added fermentable inventory
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
447 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
448 * Return recipe ingredients as json functions.
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
449 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
450 function recipe_style($recipe)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
451 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
452 global $db;
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
453
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
454 if ($recipe->STYLE->NAME)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
455 $sql = "', st_name='" . mysqli_real_escape_string($db, $recipe->STYLE->NAME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
456 if ($recipe->STYLE->STYLE_LETTER)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
457 $sql .= "', st_letter='" . mysqli_real_escape_string($db, $recipe->STYLE->STYLE_LETTER);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
458 if ($recipe->STYLE->STYLE_GUIDE) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
459 if ($recipe->STYLE->STYLE_GUIDE == "Biertypengids Derek Walsh") {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
460 $sql .= "', st_guide='BKG 2015";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
461 } else if ($recipe->STYLE->STYLE_GUIDE == "BKG Biertypen") {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
462 $sql .= "', st_guide='BKG 2015";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
463 } else {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
464 $sql .= "', st_guide='" . mysqli_real_escape_string($db, $recipe->STYLE->STYLE_GUIDE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
465 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
466 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
467 if ($recipe->STYLE->CATEGORY)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
468 $sql .= "', st_category='" . mysqli_real_escape_string($db, $recipe->STYLE->CATEGORY);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
469 if ($recipe->STYLE->CATEGORY_NUMBER)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
470 $sql .= "', st_category_number='" . floatval($recipe->STYLE->CATEGORY_NUMBER);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
471 if ($recipe->STYLE->TYPE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
472 $sql .= "', st_type='" . mysqli_real_escape_string($db, $recipe->STYLE->TYPE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
473 if ($recipe->STYLE->OG_MIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
474 $sql .= "', st_og_min='" . floatval($recipe->STYLE->OG_MIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
475 if ($recipe->STYLE->OG_MAX)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
476 $sql .= "', st_og_max='" . floatval($recipe->STYLE->OG_MAX);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
477 if ($recipe->STYLE->FG_MIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
478 $sql .= "', st_fg_min='" . floatval($recipe->STYLE->FG_MIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
479 if ($recipe->STYLE->FG_MAX)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
480 $sql .= "', st_fg_max='" . floatval($recipe->STYLE->FG_MAX);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
481 if ($recipe->STYLE->IBU_MIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
482 $sql .= "', st_ibu_min='" . floatval($recipe->STYLE->IBU_MIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
483 if ($recipe->STYLE->IBU_MAX)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
484 $sql .= "', st_ibu_max='" . floatval($recipe->STYLE->IBU_MAX);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
485 if ($recipe->STYLE->COLOR_MIN) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
486 $srm = floatval($recipe->STYLE->COLOR_MIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
487 $sql .= "', st_color_min='" . srm_to_ebc($srm);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
488 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
489 if ($recipe->STYLE->COLOR_MAX) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
490 $srm = floatval($recipe->STYLE->COLOR_MAX);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
491 $sql .= "', st_color_max='" . srm_to_ebc($srm);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
492 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
493 if ($recipe->STYLE->CARB_MIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
494 $sql .= "', st_carb_min='" . floatval($recipe->STYLE->CARB_MIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
495 if ($recipe->STYLE->CARB_MAX)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
496 $sql .= "', st_carb_max='" . floatval($recipe->STYLE->CARB_MAX);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
497 if ($recipe->STYLE->ABV_MIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
498 $sql .= "', st_abv_min='" . floatval($recipe->STYLE->ABV_MIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
499 if ($recipe->STYLE->ABV_MAX)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
500 $sql .= "', st_abv_max='" . floatval($recipe->STYLE->ABV_MAX);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
501 return $sql;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
502 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
503
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
504 function recipe_fermentables($recipe)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
505 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
506 global $db;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
507 global $pCara;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
508 global $pSugar;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
509 global $batch_size;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
510 global $efficiency;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
511 global $colorw;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
512 global $f_sugars;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
513
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
514 $fermentables = "[";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
515 $comma = FALSE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
516 foreach ($recipe->FERMENTABLES->FERMENTABLE as $fermentable) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
517 if ($comma)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
518 $fermentables .= ',';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
519 $comma = TRUE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
520 $fermentables .= '{"f_name":"' . mysqli_real_escape_string($db, $fermentable->NAME) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
521 $fermentables .= ',"f_origin":"' . mysqli_real_escape_string($db, $fermentable->ORIGIN) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
522 $fermentables .= ',"f_supplier":"' . mysqli_real_escape_string($db, $fermentable->SUPPLIER) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
523 $famount = floatval($fermentable->AMOUNT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
524 $fermentables .= ',"f_amount":' . $famount;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
525 $fermentables .= ',"f_cost":' . floatval($fermentable->COST);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
526 $ftype = mysqli_real_escape_string($db, $fermentable->TYPE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
527 $fermentables .= ',"f_type":"' . $ftype . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
528 $fyield = floatval($fermentable->YIELD);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
529 $fermentables .= ',"f_yield":' . $fyield;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
530 if ($fermentable->COLOR) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
531 $srm = floatval($fermentable->COLOR);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
532 $ebc = srm_to_ebc($srm);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
533 } else {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
534 $srm = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
535 $ebc = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
536 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
537 $colorw += ($famount * $srm / $batch_size) * 8.34436; /* Kleurwerking */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
538 $fermentables .= ',"f_color":' . $ebc;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
539 if ($fermentable->COARSE_FINE_DIFF)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
540 $fermentables .= ',"f_coarse_fine_diff":' . floatval($fermentable->COARSE_FINE_DIFF);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
541 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
542 $fermentables .= ',"f_coarse_fine_diff":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
543 if ($fermentable->MOISTURE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
544 $fmoisture = floatval($fermentable->MOISTURE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
545 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
546 $fmoisture = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
547 $fermentables .= ',"f_moisture":' . $fmoisture;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
548 if ($fermentable->DIASTATIC_POWER)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
549 $fermentables .= ',"f_diastatic_power":' . floatval($fermentable->DIASTATIC_POWER);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
550 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
551 $fermentables .= ',"f_diastatic_power":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
552 if ($fermentable->PROTEIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
553 $fermentables .= ',"f_protein":' . floatval($fermentable->PROTEIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
554 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
555 $fermentables .= ',"f_protein":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
556 if ($fermentable->MAX_IN_BATCH)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
557 $fermentables .= ',"f_max_in_batch":' . floatval($fermentable->MAX_IN_BATCH);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
558 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
559 $fermentables .= ',"f_max_in_batch":100.0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
560 $fgraintype = mysqli_real_escape_string($db, $fermentable->GRAINTYPE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
561 if ($fermentable->GRAINTYPE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
562 $fgraintype = mysqli_real_escape_string($db, $fermentable->GRAINTYPE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
563 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
564 $fgraintype = "Base";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
565 $fermentables .= ',"f_graintype":"' . $fgraintype . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
566 if ($fermentable->ADDED)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
567 $fadded = mysqli_real_escape_string($db, $fermentable->ADDED);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
568 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
569 $fadded = "Mash";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
570 $fermentables .= ',"f_added":"'.$fadded.'"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
571 ($fermentable->ADD_AFTER_BOIL== "TRUE") ? $fermentables .= ',"f_add_after_boil":true' : $fermentables .= ',"f_add_after_boil":false';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
572 ($fermentable->RECOMMEND_MASH== "TRUE") ? $fermentables .= ',"f_recommend_mash":true' : $fermentables .= ',"f_recommend_mash":false';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
573 if ($fermentable->DISSOLVED_PROTEIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
574 $fermentables .= ',"f_dissolved_protein":' . floatval($fermentable->DISSOLVED_PROTEIN);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
575 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
576 $fermentables .= ',"f_dissolved_protein":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
577 ($fermentable->ADJUST_TO_TOTAL_100 == "TRUE") ? $fermentables .= ',"f_adjust_to_total_100":true' : $fermentables .= ',"f_adjust_to_total_100":false';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
578 $percent = floatval($fermentable->PERCENTAGE);
126
9999b3ce98cb Row editors are now per cell. Added fermentable percentages editor.
Michiel Broek <mbroek@mbse.eu>
parents: 121
diff changeset
579 $fermentables .= ',"f_percentage":' . round($percent * 10) / 10.0;
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
580 if ($fermentable->DI_pH)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
581 $fermentables .= ',"f_di_ph":' . floatval($fermentable->DI_pH);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
582 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
583 $fermentables .= ',"f_di_ph":0.0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
584 $fermentables .= "}";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
585 /* Sugars */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
586 $d = $famount * ($fyield / 100) * (1 - $fmoisture / 100);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
587 if ($fadded == "Mash")
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
588 $d = floatval($efficiency) / 100 * $d;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
589 $f_sugars += $d;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
590 if ($fgraintype == "Crystal")
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
591 $pCara += $percent;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
592 if ($ftype == "Sugar")
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
593 $pSugar += $percent;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
594 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
595 $fermentables .= ']';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
596 return $fermentables;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
597 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
598
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
599 function recipe_hops($recipe)
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
600 {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
601 global $db;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
602
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
603 $hops = "[";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
604 $comma = FALSE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
605 foreach ($recipe->HOPS->HOP as $hop) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
606 if ($comma)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
607 $hops .= ',';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
608 $comma = TRUE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
609 $hops .= '{"h_name":"' . mysqli_real_escape_string($db, $hop->NAME) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
610 $hops .= ',"h_amount":' . floatval($hop->AMOUNT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
611 $hops .= ',"h_cost":' . floatval($hop->COST);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
612 $hops .= ',"h_type":"' . mysqli_real_escape_string($db, $hop->TYPE) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
613 $hops .= ',"h_form":"' . mysqli_real_escape_string($db, $hop->FORM) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
614 $hops .= ',"h_useat":"' . mysqli_real_escape_string($db, $hop->USE) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
615 if ($hop->TIME)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
616 $hops .= ',"h_time":' . floatval($hop->TIME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
617 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
618 $hops .= ',"h_time":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
619 $hops .= ',"h_alpha":' . floatval($hop->ALPHA);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
620 $hops .= ',"h_beta":' . floatval($hop->BETA);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
621 $hops .= ',"h_hsi":' . floatval($hop->HSI);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
622 $hops .= ',"h_humulene":' . floatval($hop->HUMULENE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
623 $hops .= ',"h_carophyllene":' . floatval($hop->CAROPHYLLENE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
624 $hops .= ',"h_cohumulone":' . floatval($hop->COHUMULONE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
625 $hops .= ',"h_myrcene":' . floatval($hop->MYRCENE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
626 if ($hop->TOTAL_OIL)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
627 $hops .= ',"h_total_oil":' . floatval($hop->TOTAL_OIL);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
628 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
629 $hops .= ',"h_total_oil":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
630 if ($hop->ORIGIN)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
631 $hops .= ',"h_origin":"' . mysqli_real_escape_string($db, $hop->ORIGIN) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
632 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
633 $hops .= ',"h_origin":""';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
634 $hops .= "}";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
635 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
636 $hops .= ']';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
637 return $hops;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
638 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
639
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
640 function recipe_miscs($recipe)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
641 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
642 global $db;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
643
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
644 $miscs = "[";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
645 $comma = FALSE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
646 foreach ($recipe->MISCS->MISC as $misc) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
647 if ($comma)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
648 $miscs .= ',';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
649 $comma = TRUE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
650 $mname = mysqli_real_escape_string($db, $misc->NAME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
651 $miscs .= '{"m_name":"' . $mname . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
652 $miscs .= ',"m_amount":' . floatval($misc->AMOUNT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
653 if ($misc->COST) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
654 $miscs .= ',"m_cost":' . floatval($misc->COST);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
655 } else {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
656 /* Brouwhulp bug, added water agents have no cost field. */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
657 if ($misc->TYPE == "Water agent") {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
658 $miscs .= ',"m_cost":'. get_miscs_cost($mname);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
659 } else {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
660 $miscs .= ',"m_cost":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
661 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
662 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
663 $miscs .= ',"m_type":"' . mysqli_real_escape_string($db, $misc->TYPE) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
664 $miscs .= ',"m_use_use":"' . mysqli_real_escape_string($db, $misc->USE) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
665 ($misc->AMOUNT_IS_WEIGHT== "TRUE") ? $miscs .= ',"m_amount_is_weight":true' : $miscs.= ',"m_amount_is_weight":false';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
666 if ($misc->TIME)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
667 $miscs .= ',"m_time":' . floatval($misc->TIME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
668 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
669 $miscs .= ',"m_time":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
670 $miscs .= "}";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
671 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
672 $miscs .= ']';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
673 return $miscs;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
674 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
675
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
676 function recipe_yeasts($recipe)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
677 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
678 global $db;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
679
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
680 $yeasts = "[";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
681 $comma = FALSE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
682 foreach ($recipe->YEASTS->YEAST as $yeast) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
683 if ($comma)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
684 $yeasts .= ',';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
685 $comma = TRUE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
686 $yeasts .= '{"y_name":"' . mysqli_real_escape_string($db, $yeast->NAME) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
687 $yeasts .= ',"y_amount":' . floatval($yeast->AMOUNT);
131
71f1ca48c551 When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.
Michiel Broek <mbroek@mbse.eu>
parents: 126
diff changeset
688 if ($yeast->COST) {
71f1ca48c551 When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.
Michiel Broek <mbroek@mbse.eu>
parents: 126
diff changeset
689 if (($yeast->FORM == "Liquid") && ($yeast->AMOUNT == "0.0588")) { // Packs
71f1ca48c551 When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.
Michiel Broek <mbroek@mbse.eu>
parents: 126
diff changeset
690 $yeasts .= ',"y_cost":' . floatval($yeast->COST) / 58.8;
71f1ca48c551 When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.
Michiel Broek <mbroek@mbse.eu>
parents: 126
diff changeset
691 } else {
71f1ca48c551 When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.
Michiel Broek <mbroek@mbse.eu>
parents: 126
diff changeset
692 $yeasts .= ',"y_cost":' . floatval($yeast->COST);
71f1ca48c551 When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.
Michiel Broek <mbroek@mbse.eu>
parents: 126
diff changeset
693 }
71f1ca48c551 When importing recipes with liquid yeast divide the cost by the pack volume. Don't allow alpha editing of hops in a recipe. Fix hop use time when the hop is used when not boiling and set the fixed time.
Michiel Broek <mbroek@mbse.eu>
parents: 126
diff changeset
694 } else
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
695 $yeasts .= ',"y_cost":0';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
696 $yeasts .= ',"y_laboratory":"' . mysqli_real_escape_string($db, $yeast->LABORATORY) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
697 $yeasts .= ',"y_product_id":"' . mysqli_real_escape_string($db, $yeast->PRODUCT_ID) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
698 $yeasts .= ',"y_type":"' . mysqli_real_escape_string($db, $yeast->TYPE) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
699 $yeasts .= ',"y_form":"' . mysqli_real_escape_string($db, $yeast->FORM) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
700 ($yeast->AMOUNT_IS_WEIGHT== "TRUE") ? $yeasts .= ',"y_amount_is_weight":true' : $yeasts.= ',"y_amount_is_weight":false';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
701 if ($yeast->ADD_TO_SECONDARY=="FALSE") {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
702 $yeasts .= ',"y_use":"Primary"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
703 $svg = floatval($yeast->ATTENUATION);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
704 } else if ($yeast->PRODUCT_ID=="F2") {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
705 $yeasts .= ',"y_use":"Bottle"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
706 } else {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
707 $yeasts .= ',"y_use":"Secondary"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
708 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
709 $yeasts .= ',"y_min_temperature":' . floatval($yeast->MIN_TEMPERATURE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
710 $yeasts .= ',"y_max_temperature":' . floatval($yeast->MAX_TEMPERATURE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
711 $yeasts .= ',"y_attenuation":' . floatval($yeast->ATTENUATION);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
712 $yeasts .= "}";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
713 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
714 $yeasts .= ']';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
715 return $yeasts;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
716 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
717
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
718 function recipe_waters($recipe, $db)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
719 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
720 $waters = "[";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
721 $comma = FALSE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
722 foreach ($recipe->WATERS->WATER as $water) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
723 if ($comma)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
724 $waters .= ',';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
725 $comma = TRUE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
726 $waters .= '{"w_name":"' . mysqli_real_escape_string($db, $water->NAME) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
727 $waters .= ',"w_amount":' . floatval($water->AMOUNT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
728 if ($water->CALCIUM)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
729 $waters .= ',"w_calcium":' . floatval($water->CALCIUM);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
730 if ($water->SULFATE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
731 $waters .= ',"w_sulfate":' . floatval($water->SULFATE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
732 if ($water->CHLORIDE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
733 $waters .= ',"w_chloride":' . floatval($water->CHLORIDE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
734 if ($water->SODIUM)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
735 $waters .= ',"w_sodium":' . floatval($water->SODIUM);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
736 if ($water->MAGNESIUM)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
737 $waters .= ',"w_magnesium":' . floatval($water->MAGNESIUM);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
738 if ($water->PH)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
739 $waters .= ',"w_ph":' . floatval($water->PH);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
740 if ($water->TOTAL_ALKALINITY)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
741 $waters .= ',"w_total_alkalinity":' . floatval($water->TOTAL_ALKALINITY);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
742 if ($water->COST)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
743 $waters .= ',"w_cost":' . floatval($water->COST);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
744 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
745 $waters .= ',"w_cost":0.00';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
746 $waters .= "}";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
747 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
748 $waters .= ']';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
749 return $waters;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
750 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
751
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
752 function recipe_mash_steps($recipe)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
753 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
754 global $db;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
755
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
756 $steps = '[';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
757 $comma = FALSE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
758 foreach ($recipe->MASH->MASH_STEPS->MASH_STEP as $step) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
759 if ($comma)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
760 $steps .= ',';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
761 $comma = TRUE;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
762 $steps .= '{"step_name":"' . mysqli_real_escape_string($db, $step->NAME) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
763 if ($step->TYPE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
764 $steps .= ',"step_type":"' . $step->TYPE . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
765 if ($step->INFUSE_AMOUNT)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
766 $steps .= ',"step_infuse_amount":"' . floatval($step->INFUSE_AMOUNT) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
767 if ($step->STEP_TEMP)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
768 $steps .= ',"step_temp":"' . floatval($step->STEP_TEMP) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
769 if ($step->STEP_TIME)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
770 $steps .= ',"step_time":"' . floatval($step->STEP_TIME) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
771 if ($step->RAMP_TIME)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
772 $steps .= ',"ramp_time":"' . floatval($step->RAMP_TIME) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
773 if ($step->END_TEMP)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
774 $steps .= ',"end_temp":"' . floatval($step->END_TEMP) . '"';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
775 $steps .= "}";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
776 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
777 $steps .= ']';
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
778 return $steps;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
779 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
780
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
781
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
782
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
783 function do_recipes()
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
784 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
785 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $colorw, $f_sugars;
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
786 $len_fermentables = 0;
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
787 $len_hops = 0;
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
788 $len_miscs = 0;
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
789 $len_yeasts = 0;
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
790 $len_waters = 0;
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
791 $len_mash = 0;
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
792
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
793 echo " Start adding recipes to the database\n";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
794 $sql = "TRUNCATE TABLE recipes;";
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
795 if (! $result = mysqli_query($db, $sql)) {
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
796 printf("Error: %s\n", mysqli_error($db));
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
797 }
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
798
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
799 $recipes = simplexml_load_file($brouwhulp . '/recipes.xml');
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
800
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
801 foreach ($recipes->RECIPE as $recipe) {
86
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
802 $f_sugars = 0;
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
803 $efficiency = 75;
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
804 $batch_size = 20;
94
295c3af2a421 Include boil_size field in the recipes table. Calculate pre-boil SG. Use that in the IBU calculation.
Michiel Broek <mbroek@mbse.eu>
parents: 89
diff changeset
805 $boil_size = 22;
87
7f1d0abe5571 OG and FG are now calculated from the grist. The printed report has a summary an notes section at the end. The formulas are in the global formulas script.
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
806 $pCara = 0;
7f1d0abe5571 OG and FG are now calculated from the grist. The printed report has a summary an notes section at the end. The formulas are in the global formulas script.
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
807 $pSugar = 0;
7f1d0abe5571 OG and FG are now calculated from the grist. The printed report has a summary an notes section at the end. The formulas are in the global formulas script.
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
808 $svg = 77;
89
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
809 $colorw = 0;
105
d06ddc4d1af0 Added uuid and locked fields to the recipes table.
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
810 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
86
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
811
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
812 $sql = "INSERT INTO recipes SET uuid='" . $uuid;
105
d06ddc4d1af0 Added uuid and locked fields to the recipes table.
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
813 $sql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
d06ddc4d1af0 Added uuid and locked fields to the recipes table.
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
814 $sql .= "', locked='0";
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
815 if ($recipe->NOTES)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
816 $sql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES);
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
817 else
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
818 $sql .= "', notes='";
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
819 if ($recipe->TYPE)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
820 $sql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE);
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
821 else
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
822 $sql .= "', type='";
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
823 if ($recipe->BATCH_SIZE)
86
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
824 $batch_size = floatval($recipe->BATCH_SIZE);
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
825 $sql .= "', batch_size='" . $batch_size;
94
295c3af2a421 Include boil_size field in the recipes table. Calculate pre-boil SG. Use that in the IBU calculation.
Michiel Broek <mbroek@mbse.eu>
parents: 89
diff changeset
826 if ($recipe->BOIL_SIZE)
295c3af2a421 Include boil_size field in the recipes table. Calculate pre-boil SG. Use that in the IBU calculation.
Michiel Broek <mbroek@mbse.eu>
parents: 89
diff changeset
827 $boil_size = floatval($recipe->BOIL_SIZE);
295c3af2a421 Include boil_size field in the recipes table. Calculate pre-boil SG. Use that in the IBU calculation.
Michiel Broek <mbroek@mbse.eu>
parents: 89
diff changeset
828 $sql .= "', boil_size='" . $boil_size;
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
829 if ($recipe->BOIL_TIME)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
830 $sql .= "', boil_time='" . floatval($recipe->BOIL_TIME);
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
831 else
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
832 $sql .= "', boil_time='90";
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
833 if ($recipe->EFFICIENCY)
86
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
834 $efficiency = floatval($recipe->EFFICIENCY);
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
835 $sql .= "', efficiency='" . $efficiency;
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
836 /* Don't use $recipe->EST_OG but recalculate it */
87
7f1d0abe5571 OG and FG are now calculated from the grist. The printed report has a summary an notes section at the end. The formulas are in the global formulas script.
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
837 /* Don't use $recipe->EST_FG but recalculate it */
89
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
838 /* Don't use $recipe->EST_COLOR but recalculate it */
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
839 if ($recipe->COLOR_METHOD)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
840 $sql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
841 if ($recipe->IBU)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
842 $sql .= "', est_ibu='" . floatval($recipe->IBU);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
843 if ($recipe->IBU_METHOD)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
844 $sql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD);
102
679ddf512b65 Added est_carb field import in the recipes.
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
845 if ($recipe->CARBONATION)
679ddf512b65 Added est_carb field import in the recipes.
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
846 $sql .= "', est_carb='" . floatval($recipe->CARBONATION);
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
847
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
848 if ($recipe->STYLE) {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
849 $sql .= recipe_style($recipe);
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
850 }
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
851
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
852 /*
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
853 * Put the fermentables in a json array
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
854 */
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
855 if ($recipe->FERMENTABLES) {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
856 $fermentables = recipe_fermentables($recipe);
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
857 $sql .= "', json_fermentables='" . $fermentables;
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
858 if (strlen($fermentables) > $len_fermentables)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
859 $len_fermentables = strlen($fermentables);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
860 }
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
861
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
862 /*
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
863 * Put the hops in a json array
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
864 */
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
865 if ($recipe->HOPS) {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
866 $hops = recipe_hops($recipe);
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
867 $sql .= "', json_hops='" . $hops;
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
868 if (strlen($hops) > $len_hops)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
869 $len_hops = strlen($hops);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
870 }
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
871
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
872 /*
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
873 * Put the miscs in a json array
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
874 */
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
875 if ($recipe->MISCS) {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
876 $miscs = recipe_miscs($recipe);
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
877 $sql .= "', json_miscs='" . $miscs;
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
878 if (strlen($miscs) > $len_miscs)
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
879 $len_miscs = strlen($miscs);
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
880 }
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
881
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
882 /*
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
883 * Put the yeasts in a json array
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
884 */
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
885 if ($recipe->YEASTS) {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
886 $yeasts = recipe_yeasts($recipe);
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
887 $sql .= "', json_yeasts='" . $yeasts;
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
888 if (strlen($yeasts) > $len_yeasts)
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
889 $len_yeasts = strlen($yeasts);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
890 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
891
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
892 /*
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
893 * Put the waters in a json array
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
894 */
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
895 if ($recipe->WATERS) {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
896 $waters = recipe_waters($recipe, $db);
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
897 $sql .= "', json_waters='" . $waters;
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
898 if (strlen($waters) > $len_waters)
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
899 $len_waters = strlen($waters);
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
900 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
901
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
902 /*
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
903 * Put the mash in a json array
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
904 */
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
905 if ($recipe->MASH) {
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
906 $sql .= "',mash_sparge_temp='" . floatval($recipe->MASH->SPARGE_TEMP);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
907 $sql .= "',mash_ph='" . floatval($recipe->MASH->PH);
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
908 if ($recipe->MASH->NAME)
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
909 $sql .= "',mash_name='" . mysqli_real_escape_string($db, $recipe->MASH->NAME);
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
910
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
911 if ($recipe->MASH->MASH_STEPS) {
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
912 $steps = recipe_mash_steps($recipe);
51
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
913 $sql .= "', json_mashs='" . $steps;
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
914 if (strlen($steps) > $len_mash)
7224109adfe1 More recipe editor changes
Michiel Broek <mbroek@mbse.eu>
parents: 50
diff changeset
915 $len_mash = strlen($steps);
49
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
916 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
917 }
4d27a7fb1265 Finisched recipe import. Added recipe retrieve script.
Michiel Broek <mbroek@mbse.eu>
parents: 48
diff changeset
918
86
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
919 /*
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
920 * Added the calculated values
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
921 * OG, FG, color, IBU
e977a505ea8c With recipe import calculate the OG
Michiel Broek <mbroek@mbse.eu>
parents: 77
diff changeset
922 */
96
107c12c3e49d Renamed estimate_og() to estimate_sg() formula. Updated the formulas in javascript. The calcFermenter() function now only calculates the gravities. The colors still need to be added. When a recept is loaded in the editor, all tabs are selected once to load all subgrid data. Ugly and slow but it at least it works.
Michiel Broek <mbroek@mbse.eu>
parents: 94
diff changeset
923 $og = estimate_sg($f_sugars, $batch_size);
87
7f1d0abe5571 OG and FG are now calculated from the grist. The printed report has a summary an notes section at the end. The formulas are in the global formulas script.
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
924 $sql .= "', est_og='" . floatval($og);
7f1d0abe5571 OG and FG are now calculated from the grist. The printed report has a summary an notes section at the end. The formulas are in the global formulas script.
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
925 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og);
7f1d0abe5571 OG and FG are now calculated from the grist. The printed report has a summary an notes section at the end. The formulas are in the global formulas script.
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
926 $sql .= "', est_fg='" . floatval($fg);
88
0a39cbdcf085 Added ABV clculation.
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
927 $abv = abvol($og, $fg);
0a39cbdcf085 Added ABV clculation.
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
928 $sql .= "', est_abv='" . floatval($abv);
89
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
929 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw);
082c23b26055 Missing Water agent costs from Brouwhulp import are now added from the imported miscs database. The printed recipe report now calculates the beer color from the ingredients. Also set during recipes import. This will later allow to set the color method for each recipe individually.
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
930 $sql .= "', est_color='" . floatval($color);
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
931 $sql .= "';";
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
932 if (! $result = mysqli_query($db, $sql)) {
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
933 printf("Error: %s\n", mysqli_error($db));
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
934 }
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
935 }
64
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
936 // echo "Fermentables: " . $len_fermentables . PHP_EOL;
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
937 // echo "Hops: " . $len_hops . PHP_EOL;
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
938 // echo "Miscs: " . $len_miscs . PHP_EOL;
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
939 // echo "Yeasts: " . $len_yeasts . PHP_EOL;
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
940 // echo "Waters: " . $len_waters . PHP_EOL;
5d5fc6f7cbfe Improved recipes import. Finished inventory_suppliers.
Michiel Broek <mbroek@mbse.eu>
parents: 61
diff changeset
941 // echo "Mash: " . $len_mash . PHP_EOL;
48
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
942 }
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
943
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
944
bdd1ec9b9c06 Start recipes import and menus.
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
945
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
946 function do_brews()
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
947 {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
948 global $brouwhulp, $db, $efficiency, $batch_size, $pCara, $pSugar, $colorw, $f_sugars;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
949 $len_fermentables = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
950 $len_hops = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
951 $len_miscs = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
952 $len_yeasts = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
953 $len_waters = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
954 $len_mash = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
955
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
956 echo " Start adding brews to the database\n";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
957 $psql = "TRUNCATE TABLE prod_main;";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
958 if (! $presult = mysqli_query($db, $psql)) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
959 printf("Error: %s\n", mysqli_error($db));
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
960 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
961 $rsql = "TRUNCATE TABLE prod_recipes;";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
962 if (! $rresult = mysqli_query($db, $rsql)) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
963 printf("Error: %s\n", mysqli_error($db));
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
964 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
965
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
966 date_default_timezone_set('Europe/Amsterdam');
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
967 $recipes = simplexml_load_file($brouwhulp . '/brews.xml');
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
968
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
969 foreach ($recipes->RECIPE as $recipe) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
970 $f_sugars = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
971 $efficiency = 75;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
972 $batch_size = 20;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
973 $boil_size = 22;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
974 $pCara = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
975 $pSugar = 0;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
976 $svg = 77;
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
977 $colorw = 0;
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
978 $stage = "Plan"; // Default value.
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
979 $uuid = str_replace("\n", "", file_get_contents('/proc/sys/kernel/random/uuid'));
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
980
119
ae5e8d740173 Renamed some fields in prod_main to prevent ambigous names with the join. Delete product also deletes the corresponding recipe. Fixed equipment load and save. Read data from the product main joined with prod_recipes completed. The brewday page is now almost complete, the calculations must be added.
Michiel Broek <mbroek@mbse.eu>
parents: 118
diff changeset
981 $psql = "INSERT INTO prod_main SET puuid='" . $uuid; // So we can link the records.
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
982 $rsql = "INSERT INTO prod_recipes SET uuid='" . $uuid;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
983
119
ae5e8d740173 Renamed some fields in prod_main to prevent ambigous names with the join. Delete product also deletes the corresponding recipe. Fixed equipment load and save. Read data from the product main joined with prod_recipes completed. The brewday page is now almost complete, the calculations must be added.
Michiel Broek <mbroek@mbse.eu>
parents: 118
diff changeset
984 $psql .= "', pname='" . mysqli_real_escape_string($db, $recipe->NAME);
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
985 $rsql .= "', name='" . mysqli_real_escape_string($db, $recipe->NAME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
986
111
8c4ba91adf58 Basic screens for brew products.
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
987 if ($recipe->NOTES) {
8c4ba91adf58 Basic screens for brew products.
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
988 $rsql .= "', notes='" . mysqli_real_escape_string($db, $recipe->NOTES); // Duplicate the notes
119
ae5e8d740173 Renamed some fields in prod_main to prevent ambigous names with the join. Delete product also deletes the corresponding recipe. Fixed equipment load and save. Read data from the product main joined with prod_recipes completed. The brewday page is now almost complete, the calculations must be added.
Michiel Broek <mbroek@mbse.eu>
parents: 118
diff changeset
989 $psql .= "', pnotes='" . mysqli_real_escape_string($db, $recipe->NOTES);
111
8c4ba91adf58 Basic screens for brew products.
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
990 } else {
8c4ba91adf58 Basic screens for brew products.
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
991 $rsql .= "', notes='";
119
ae5e8d740173 Renamed some fields in prod_main to prevent ambigous names with the join. Delete product also deletes the corresponding recipe. Fixed equipment load and save. Read data from the product main joined with prod_recipes completed. The brewday page is now almost complete, the calculations must be added.
Michiel Broek <mbroek@mbse.eu>
parents: 118
diff changeset
992 $psql .= "', pnotes='";
111
8c4ba91adf58 Basic screens for brew products.
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
993 }
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
994 if ($recipe->TYPE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
995 $rsql .= "', type='" . mysqli_real_escape_string($db, $recipe->TYPE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
996 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
997 $rsql .= "', type='";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
998 if ($recipe->BATCH_SIZE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
999 $batch_size = floatval($recipe->BATCH_SIZE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1000 $rsql .= "', batch_size='" . $batch_size;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1001 if ($recipe->BOIL_SIZE)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1002 $boil_size = floatval($recipe->BOIL_SIZE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1003 $rsql .= "', boil_size='" . $boil_size;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1004 if ($recipe->BOIL_TIME)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1005 $rsql .= "', boil_time='" . floatval($recipe->BOIL_TIME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1006 else
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1007 $rsql .= "', boil_time='90";
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1008 if ($recipe->EFFICIENCY)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1009 $efficiency = floatval($recipe->EFFICIENCY);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1010 $rsql .= "', efficiency='" . $efficiency;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1011 /* Don't use $recipe->EST_OG but recalculate it */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1012 /* Don't use $recipe->EST_FG but recalculate it */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1013 /* Don't use $recipe->EST_COLOR but recalculate it */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1014 if ($recipe->COLOR_METHOD)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1015 $rsql .= "', color_method='" . mysqli_real_escape_string($db, $recipe->COLOR_METHOD);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1016 if ($recipe->IBU)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1017 $rsql .= "', est_ibu='" . floatval($recipe->IBU);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1018 if ($recipe->IBU_METHOD)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1019 $rsql .= "', ibu_method='" . mysqli_real_escape_string($db, $recipe->IBU_METHOD);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1020 if ($recipe->CARBONATION)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1021 $rsql .= "', est_carb='" . floatval($recipe->CARBONATION);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1022
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1023 if ($recipe->STYLE) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1024 $rsql .= recipe_style($recipe);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1025 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1026
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1027 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1028 * Put the fermentables in a json array
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1029 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1030 if ($recipe->FERMENTABLES) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1031 $fermentables = recipe_fermentables($recipe);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1032 $rsql .= "', json_fermentables='" . $fermentables;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1033 if (strlen($fermentables) > $len_fermentables)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1034 $len_fermentables = strlen($fermentables);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1035 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1036
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1037 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1038 * Put the hops in a json array
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1039 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1040 if ($recipe->HOPS) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1041 $hops = recipe_hops($recipe);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1042 $rsql .= "', json_hops='" . $hops;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1043 if (strlen($hops) > $len_hops)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1044 $len_hops = strlen($hops);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1045 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1046
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1047 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1048 * Put the miscs in a json array
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1049 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1050 if ($recipe->MISCS) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1051 $miscs = recipe_miscs($recipe);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1052 $rsql .= "', json_miscs='" . $miscs;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1053 if (strlen($miscs) > $len_miscs)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1054 $len_miscs = strlen($miscs);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1055 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1056
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1057 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1058 * Put the yeasts in a json array
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1059 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1060 if ($recipe->YEASTS) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1061 $yeasts = recipe_yeasts($recipe);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1062 $rsql .= "', json_yeasts='" . $yeasts;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1063 if (strlen($yeasts) > $len_yeasts)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1064 $len_yeasts = strlen($yeasts);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1065 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1066
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1067 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1068 * Put the waters in a json array
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1069 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1070 if ($recipe->WATERS) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1071 $waters = recipe_waters($recipe, $db);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1072 $rsql .= "', json_waters='" . $waters;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1073 if (strlen($waters) > $len_waters)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1074 $len_waters = strlen($waters);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1075 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1076
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1077 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1078 * Put the mash in a json array
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1079 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1080 if ($recipe->MASH) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1081 $rsql .= "',mash_sparge_temp='" . floatval($recipe->MASH->SPARGE_TEMP);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1082 $rsql .= "',mash_ph='" . floatval($recipe->MASH->PH);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1083 if ($recipe->MASH->NAME)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1084 $rsql .= "',mash_name='" . mysqli_real_escape_string($db, $recipe->MASH->NAME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1085
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1086 if ($recipe->MASH->MASH_STEPS) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1087 $steps = recipe_mash_steps($recipe);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1088 $rsql .= "', json_mashs='" . $steps;
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1089 if (strlen($steps) > $len_mash)
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1090 $len_mash = strlen($steps);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1091 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1092 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1093
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1094 /*
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1095 * Added the calculated values
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1096 * OG, FG, color, IBU
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1097 */
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1098 $og = estimate_sg($f_sugars, $batch_size);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1099 $rsql .= "', est_og='" . floatval($og);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1100 $fg = estimate_fg($pSugar, $pCara, 0, 0, 0, $svg, $og);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1101 $rsql .= "', est_fg='" . floatval($fg);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1102 $abv = abvol($og, $fg);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1103 $rsql .= "', est_abv='" . floatval($abv);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1104 $color = kw_to_ebc(mysqli_real_escape_string($db, $recipe->COLOR_METHOD), $colorw);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1105 $rsql .= "', est_color='" . floatval($color);
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1106 $psql .= "', code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1107
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1108 /*
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1109 * Update external logfiles
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1110 */
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1111 $sql = "UPDATE log_brews SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1112 $sql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1113 if (! $result = mysqli_query($db, $sql)) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1114 printf("Error: %s\n", mysqli_error($db));
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1115 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1116 $count = mysqli_affected_rows($db);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1117 if ($count > 0) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1118 $psql .= "', log_brew='1";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1119 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1120 $sql = "UPDATE log_fermentation SET product_uuid='".$uuid."', product_name='".mysqli_real_escape_string($db, $recipe->NAME);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1121 $sql .= "' WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1122 if (! $result = mysqli_query($db, $sql)) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1123 printf("Error: %s\n", mysqli_error($db));
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1124 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1125 $count = mysqli_affected_rows($db);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1126 if ($count > 0) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1127 $psql .= "', log_fermentation='1";
114
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1128 } else {
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1129 // See if there really are no records
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1130 $sql = "SELECT product_code FROM log_fermentation WHERE product_code='".$recipe->NR_RECIPE."';";
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1131 $count = mysqli_affected_rows($db);
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1132 if ($count > 0) {
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1133 $psql .= "', log_fermentation='1";
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1134 }
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1135 }
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1136
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1137 /*
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1138 * If no external fermentation log is found, check for an internal one.
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1139 */
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1140 if (($count == 0) && $recipe->FERM_MEASUREMENTS) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1141 $lsql = "DELETE FROM log_fermentation WHERE product_code='".mysqli_real_escape_string($db, $recipe->NR_RECIPE)."';";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1142 if (! $lresult = mysqli_query($db, $lsql)) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1143 printf("Error: %s\n", mysqli_error($db));
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1144 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1145 foreach ($recipe->FERM_MEASUREMENTS->FERM_MEASUREMENT as $measurement) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1146 $dt = substr($measurement->DATE_TIME, 6, 4).substr($measurement->DATE_TIME,2,4).substr($measurement->DATE_TIME,0,2);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1147 $dt .= ' '.substr($measurement->DATE_TIME, 11,8);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1148 $lsql = "INSERT INTO log_fermentation SET product_uuid='".$uuid;
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1149 $lsql .= "', product_code='" . mysqli_real_escape_string($db, $recipe->NR_RECIPE);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1150 $lsql .= "', product_name='" . mysqli_real_escape_string($db, $recipe->NAME);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1151 $lsql .= "', datetime='" . $dt;
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1152 $lsql .= "', temperature_air='" . floatval($measurement->TEMP_SENSOR_1);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1153 $lsql .= "', temperature_beer='" . floatval($measurement->TEMP_SENSOR_2);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1154 $lsql .= "';";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1155 if (! $lresult = mysqli_query($db, $lsql)) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1156 printf("Error: %s\n", mysqli_error($db));
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1157 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1158 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1159 $psql .= "', log_fermentation='1";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1160 }
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1161
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1162 if ($recipe->EQUIPMENT) {
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1163 $psql .= "', eq_name='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NAME);
111
8c4ba91adf58 Basic screens for brew products.
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
1164 $psql .= "', eq_notes='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->NOTES);
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1165 $psql .= "', eq_boil_size='" . floatval($recipe->EQUIPMENT->BOIL_SIZE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1166 $psql .= "', eq_batch_size='" . floatval($recipe->EQUIPMENT->BATCH_SIZE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1167 $psql .= "', eq_tun_volume='" . floatval($recipe->EQUIPMENT->TUN_VOLUME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1168 $psql .= "', eq_tun_weight='" . floatval($recipe->EQUIPMENT->TUN_WEIGHT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1169 $psql .= "', eq_tun_specific_heat='" . floatval($recipe->EQUIPMENT->TUN_SPECIFIC_HEAT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1170 $psql .= "', eq_tun_material='" . mysqli_real_escape_string($db, $recipe->EQUIPMENT->TUN_MATERIAL);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1171 $psql .= "', eq_tun_height='" . floatval($recipe->EQUIPMENT->TUN_HEIGHT);
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1172 if ($recipe->EQUIPMENT->TOP_UP_WATER)
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1173 $psql .= "', eq_top_up_water='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER);
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1174 $psql .= "', eq_trub_chiller_loss='" . floatval($recipe->EQUIPMENT->TRUB_CHILLER_LOSS);
114
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1175 /*
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1176 * Brouwhulp uses a percentage for the evaporation rate. This is wrong
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1177 * but was made so because the beerxml standard requires this. What we
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1178 * do is calculate the actual evaporation and store that.
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1179 * This is what we use. Brouwhulp calculates this on the fly.
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1180 */
4935e86b2775 Small fixes for prject import from Brouwhulp. Fixes for poduct database read/write. New menu entries. Equipment select in product editor. Started brewday editor. Added conditions on some buttons and edit fields. Screen layout changes.
Michiel Broek <mbroek@mbse.eu>
parents: 111
diff changeset
1181 $psql .= "', eq_evap_rate='" . (floatval($recipe->EQUIPMENT->EVAP_RATE) * floatval($recipe->EQUIPMENT->BOIL_SIZE)) / 100;
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1182 $psql .= "', eq_boil_time='" . floatval($recipe->EQUIPMENT->BOIL_TIME);
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1183 ($recipe->EQUIPMENT->CALC_BOIL_VOLUME == 'TRUE') ? $psql .= "', eq_calc_boil_volume='1" : $psql .= "', eq_calc_boil_volume='0";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1184 if ($recipe->EQUIPMENT->TOP_UP_KETTLE)
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1185 $psql .= "', eq_top_up_kettle='" . floatval($recipe->EQUIPMENT->TOP_UP_KETTLE);
106
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1186 $psql .= "', eq_hop_utilization='" . floatval($recipe->EQUIPMENT->HOP_UTILIZATION);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1187 $psql .= "', eq_lauter_volume='" . floatval($recipe->EQUIPMENT->LAUTER_VOLUME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1188 $psql .= "', eq_lauter_height='" . floatval($recipe->EQUIPMENT->LAUTER_HEIGHT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1189 $psql .= "', eq_lauter_deadspace='" . floatval($recipe->EQUIPMENT->LAUTER_DEADSPACE);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1190 $psql .= "', eq_kettle_volume='" . floatval($recipe->EQUIPMENT->KETTLE_VOLUME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1191 $psql .= "', eq_kettle_height='" . floatval($recipe->EQUIPMENT->KETTLE_HEIGHT);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1192 $psql .= "', eq_mash_volume='" . floatval($recipe->EQUIPMENT->MASH_VOLUME);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1193 $psql .= "', eq_efficiency='" . floatval($recipe->EQUIPMENT->EFFICIENCY);
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1194 }
c64d979613ab Prepare for production brews databases
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
1195
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1196 if (($recipe->DATE) && (! $recipe->TIME_STARTED) && (! $recipe->TIME_ENDED)) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1197 /* We have a plan date but haven't brewed yet, use current date */
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1198 $psql .= "', birth='" . date("Y-m-d");
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1199 $stage = "Wait";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1200 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1201
107
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1202 if (($recipe->DATE) && ($recipe->TIME_STARTED) && ($recipe->TIME_ENDED)) {
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1203 /* We have brew data */
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1204 $stage = "Primary"; // Need to think about during a brew...
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1205 $brewdate = substr($recipe->DATE, 6, 4).substr($recipe->DATE,2,4).substr($recipe->DATE,0,2);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1206 $psql .= "', birth='" . $brewdate;
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1207 $date_start = $brewdate.' '.$recipe->TIME_STARTED;
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1208 $date_end = $brewdate.' '.$recipe->TIME_ENDED;
107
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1209 $psql .= "', brew_date_start='" . $date_start;
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1210
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1211 if ($recipe->PH_ADJUSTED)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1212 $psql .= "', brew_mash_ph='" . floatval($recipe->PH_ADJUSTED);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1213 if (floatval($recipe->SG_END_MASH) != 1.0)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1214 $psql .= "', brew_mash_sg='" . floatval($recipe->SG_END_MASH);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1215 if ($recipe->MASH->SPARGE_TEMP)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1216 $psql .= "', brew_sparge_temperature='" . floatval($recipe->MASH->SPARGE_TEMP);
121
875aeb365e1c Added sparge pH during import. Added several calculations. Added calculated estimates to the brewday screen.
Michiel Broek <mbroek@mbse.eu>
parents: 119
diff changeset
1217 if ($recipe->MASH->PH)
875aeb365e1c Added sparge pH during import. Added several calculations. Added calculated estimates to the brewday screen.
Michiel Broek <mbroek@mbse.eu>
parents: 119
diff changeset
1218 $psql .= "', brew_sparge_ph='" . floatval($recipe->MASH->PH);
107
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1219 if ($recipe->VOLUME_HLT)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1220 $psql .= "', brew_sparge_volume='" . floatval($recipe->VOLUME_HLT);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1221 if ($recipe->VOLUME_BEFORE_BOIL)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1222 $psql .= "', brew_preboil_volume='" . floatval($recipe->VOLUME_BEFORE_BOIL);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1223 if (floatval($recipe->OG_BEFORE_BOIL) != 1.0)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1224 $psql .= "', brew_preboil_sg='" . floatval($recipe->OG_BEFORE_BOIL);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1225 if ($recipe->PH_BEFORE_BOIL)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1226 $psql .= "', brew_preboil_ph='" . floatval($recipe->PH_BEFORE_BOIL);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1227 if ($recipe->VOLUME_AFTER_BOIL)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1228 $psql .= "', brew_aboil_volume='" . floatval($recipe->VOLUME_AFTER_BOIL);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1229 $psql .= "', brew_aboil_sg='" . floatval($recipe->OG);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1230 if ($recipe->PH_AFTER_BOIL)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1231 $psql .= "', brew_aboil_ph='" . floatval($recipe->PH_AFTER_BOIL);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1232 if ($recipe->ACTUAL_EFFICIENCY)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1233 $psql .= "', brew_aboil_efficiency='" . floatval($recipe->ACTUAL_EFFICIENCY);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1234 $psql .= "', brew_whirlpool2='" . floatval($recipe->WHIRLPOOL_TIME);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1235 $psql .= "', brew_cooling_method='" . mysqli_real_escape_string($db, $recipe->COOLING_METHOD);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1236 $psql .= "', brew_cooling_time='" . floatval($recipe->COOLING_TIME);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1237 $psql .= "', brew_cooling_to='" . floatval($recipe->COOLING_TO);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1238 if ($recipe->VOLUME_FERMENTER)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1239 $psql .= "', brew_fermenter_volume='" . floatval($recipe->VOLUME_FERMENTER);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1240 if ($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY)
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1241 $psql .= "', brew_fermenter_extrawater='" . floatval($recipe->EQUIPMENT->TOP_UP_WATER_BREWDAY);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1242 $psql .= "', brew_fermenter_sg='" . floatval($recipe->OG_FERMENTER);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1243 $psql .= "', brew_fermenter_ibu='" . floatval($recipe->IBU);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1244 $psql .= "', brew_aeration_type='" . mysqli_real_escape_string($db, $recipe->AERATION_TYPE);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1245 if ($recipe->AERATION_TYPE != "None") {
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1246 $psql .= "', brew_aeration_speed='" . floatval($recipe->AERATION_SPEED);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1247 $psql .= "', brew_aeration_time='" . floatval($recipe->AERATION_TIME);
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1248 }
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1249 $psql .= "', brew_date_end='" . $date_end;
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1250 }
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1251
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1252 if ($recipe->PRIMARY_AGE) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1253 /* PRIMARY_TEMP is the average of START_TEMP_PRIMARY MAX_TEMP_PRIMARY END_TEMP_PRIMARY */
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1254 $pdate = new DateTime($brewdate);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1255 $pdate->modify("+".floatval($recipe->PRIMARY_AGE)." days");
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1256 $psql .= "', primary_start_temp='" . floatval($recipe->START_TEMP_PRIMARY);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1257 $psql .= "', primary_max_temp='" . floatval($recipe->MAX_TEMP_PRIMARY);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1258 $psql .= "', primary_end_temp='" . floatval($recipe->END_TEMP_PRIMARY);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1259 $psql .= "', primary_end_sg='" . floatval($recipe->SG_END_PRIMARY);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1260 $psql .= "', primary_end_date='" . $pdate->format("Y-m-d");
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1261 $stage = "Secondary";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1262
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1263 if ($recipe->SECONDARY_AGE) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1264 $sdate = new DateTime($brewdate);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1265 $sdate->modify("+".floatval($recipe->SECONDARY_AGE)." days");
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1266 $psql .= "', secondary_temp='" . floatval($recipe->SECONDARY_TEMP);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1267 $psql .= "', secondary_end_date='" . $sdate->format("Y-m-d");
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1268 $stage = "Tertiary";
107
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1269
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1270 if ($recipe->TERTIARY_TEMP) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1271 $psql .= "', tertiary_temp='" . floatval($recipe->TERTIARY_TEMP);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1272 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1273 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1274 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1275
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1276 if ($recipe->DATE_BOTTLING && ($recipe->AMOUNT_BOTTLING || $recipe->AMOUNT_KEGGED) &&
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1277 ($recipe->AMOUNT_PRIMING || $recipe->AMOUNT_PRIMING_KEGS)) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1278 $bdate = substr($recipe->DATE_BOTTLING, 6, 4).substr($recipe->DATE_BOTTLING,2,4).substr($recipe->DATE_BOTTLING,0,2);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1279 $psql .= "', package_date='" . $bdate;
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1280 $stage = "Package";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1281 $dStart = new DateTime($bdate);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1282 $dEnd = new DateTime('');
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1283 $dDiff = $dStart->diff($dEnd);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1284 $age = floatval($dDiff->days);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1285 if ($age == 0) // Package day
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1286 $stage = "Package";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1287 else if ($age < 14) // Carbonation period
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1288 $stage = "Carbonation";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1289 else if ($age < 42) // Mature, fixed 6 weeks
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1290 $stage = "Mature";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1291 else // Ready for tasting.
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1292 $stage = "Taste";
107
8b4fdadf320c Added brewday data
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1293
108
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1294 if ($recipe->AMOUNT_BOTTLING && $recipe->AMOUNT_PRIMING) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1295 $psql .= "', bottle_amount='" . floatval($recipe->AMOUNT_BOTTLING);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1296 $psql .= "', bottle_carbonation='" . floatval($recipe->CARBONATION);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1297 $psql .= "', bottle_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_BOTTLES);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1298 $psql .= "', bottle_priming_amount='" . floatval($recipe->AMOUNT_PRIMING);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1299 $psql .= "', bottle_carbonation_temp='" . floatval($recipe->CARBONATION_TEMP);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1300 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1301 if ($recipe->AMOUNT_KEGGED && $recipe->AMOUNT_PRIMING_KEGS) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1302 $psql .= "', keg_amount='" . floatval($recipe->AMOUNT_KEGGED);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1303 $psql .= "', keg_carbonation='" . floatval($recipe->CARBONATION); // Lijkt wel hetzelfde als bottles
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1304 $psql .= "', keg_priming_sugar='" . mysqli_real_escape_string($db, $recipe->PRIMING_SUGAR_KEGS);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1305 $psql .= "', keg_priming_amount='" . floatval($recipe->AMOUNT_PRIMING_KEGS);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1306 $psql .= "', keg_carbonation_temp='" . floatval($recipe->KEG_CARB_TEMP);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1307 ($recipe->FORCED_CARB_KEGS == 'TRUE') ? $psql .= "', keg_forced_carb='1" : $psql .= "', keg_forced_carb='0";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1308 $psql .= "', keg_pressure='" . floatval($recipe->KEG_PRESSURE);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1309 $psql .= "', keg_priming_factor='" . floatval($recipe->KEG_PRIMING_FACTOR);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1310 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1311 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1312
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1313 if ($recipe->TASTE_NOTES && $recipe->TASTING_RATE && $recipe->TASTE_DATE) {
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1314 $stage = "Ready"; // Ready if tasted.
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1315 $psql .= "', taste_notes='" . mysqli_real_escape_string($db, $recipe->TASTE_NOTES);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1316 $psql .= "', taste_rate='" . floatval($recipe->TASTING_RATE);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1317 $tdate = substr($recipe->TASTE_DATE, 6, 4).substr($recipe->TASTE_DATE,2,4).substr($recipe->TASTE_DATE,0,2);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1318 $psql .= "', taste_date='" . $tdate;
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1319 $psql .= "', taste_color='" . mysqli_real_escape_string($db, $recipe->TASTE_COLOR);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1320 $psql .= "', taste_transparency='" . mysqli_real_escape_string($db, $recipe->TASTE_TRANSPARENCY);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1321 $psql .= "', taste_head='" . mysqli_real_escape_string($db, $recipe->TASTE_HEAD);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1322 $psql .= "', taste_aroma='" . mysqli_real_escape_string($db, $recipe->TASTE_AROMA);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1323 $psql .= "', taste_taste='" . mysqli_real_escape_string($db, $recipe->TASTE_TASTE);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1324 $psql .= "', taste_mouthfeel='" . mysqli_real_escape_string($db, $recipe->TASTE_MOUTHFEEL);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1325 $psql .= "', taste_aftertaste='" . mysqli_real_escape_string($db, $recipe->TASTE_AFTERTASTE);
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1326 }
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1327
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107
diff changeset
1328 ($recipe->INVENTORY_REDUCED == 'TRUE') ? $psql .= "', inventory_reduced='1" : $psql .= "', inventory_reduced='0";
a466373bc23f Finished brews import
Michiel Broek <mbroek@mbse.eu>
parents: 107