Sun, 12 Aug 2018 21:24:33 +0200
Added fermentable inventory
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/import/from_brouwhulp.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,461 @@ +<?php +/* + * Import inventory from brouwhulp + */ + +require("../config.php"); +require("../version.php"); +require("../includes/formulas.php"); + +echo "Start adding data from brouwhulp\n"; + +$db = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); +if (! $db) { + die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); +} + +$brouwhulp = '/home/mbroek/Documents/brouwhulp'; + + +function do_fermentables() +{ + global $brouwhulp, $db; + + echo " Start adding fermentables to the database\n"; + $sql = "TRUNCATE TABLE inventory_fermentables;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + $myfermentables = simplexml_load_file($brouwhulp . '/fermentables.xml'); + + foreach ($myfermentables->FERMENTABLE as $fermentable) { + + $sql = "INSERT INTO inventory_fermentables SET name='" . mysqli_real_escape_string($db, $fermentable->NAME); + $sql .= "', type='" . $fermentable->TYPE; + if ($fermentable->YIELD) + $sql .= "', yield='" . $fermentable->YIELD; + if ($fermentable->COLOR) { + $srm = $fermentable->COLOR; + $ebc = srm_to_ebc($srm); + if ($ebc < 0) + $ebc = 0; + $nsrm = ebc_to_srm($ebc); + echo 'SRM '.$srm.' EBC '.$ebc.' back '.$nsrm.PHP_EOL; + $sql .= "', color='" . $ebc; + } + ($fermentable->ADD_AFTER_BOIL == "TRUE") ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; + $sql .= "', origin='" . mysqli_real_escape_string($db, $fermentable->ORIGIN); + $sql .= "', supplier='" . mysqli_real_escape_string($db, $fermentable->SUPPLIER); + $sql .= "', notes='" . mysqli_real_escape_string($db, $fermentable->NOTES); + if ($fermentable->COARSE_FINE_DIFF) + $sql .= "', coarse_fine_diff='" . $fermentable->COARSE_FINE_DIFF; + if ($fermentable->MOISTURE) + $sql .= "', moisture='" . $fermentable->MOISTURE; + if ($fermentable->DIASTATIC_POWER) + $sql .= "', diastatic_power='" . $fermentable->DIASTATIC_POWER; + if ($fermentable->PROTEIN) + $sql .= "', protein='" . $fermentable->PROTEIN; + if ($fermentable->MAX_IN_BATCH) + $sql .= "', max_in_batch='" . $fermentable->MAX_IN_BATCH; + ($fermentable->RECOMMEND_MASH == "TRUE") ? $sql .= "', recommend_mash='Y" : $sql .= "', recommend_mash='N"; + if ($fermentable->IBU_GAL_PER_LB) + $sql .= "', ibu_gal_per_lb='" . $fermentable->IBU_GAL_PER_LB; + ($fermentable->ALWAYS_ON_STOCK == "TRUE") ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($fermentable->INVENTORY) + $sql .= "', inventory='" . $fermentable->INVENTORY; + if ($fermentable->COST) + $sql .= "', cost='" . $fermentable->COST; + /* + * These are not beerxml standard: + */ + if ($fermentable->DI_pH) + $sql .= "', di_ph='" . $fermentable->DI_pH; + if ($fermentable->{'ACID_TO_pH_5.7'}) + $sql .= "', acid_to_ph_57='" . $fermentable->{'ACID_TO_pH_5.7'}; + $sql .= "', graintype='" . $fermentable->GRAINTYPE; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + +function do_hops() +{ + global $brouwhulp, $db; + + echo " Start adding hops to the database\n"; + $sql = "TRUNCATE TABLE inventory_hops;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $myhops = simplexml_load_file($brouwhulp . '/hops.xml'); + + foreach ($myhops->HOP as $hop) { + + $sql = "INSERT INTO inventory_hops SET name='" . mysqli_real_escape_string($db, $hop->NAME); + if ($hop->ALPHA) + $sql .= "', alpha='" . $hop->ALPHA; + if ($hop->BETA) + $sql .= "', beta='" . $hop->BETA; + if ($hop->HUMULENE) + $sql .= "', humulene='" . $hop->HUMULENE; + if ($hop->CARYOPHYLLENE) + $sql .= "', caryophyllene='" . $hop->CARYOPHYLLENE; + if ($hop->COHUMULONE) + $sql .= "', cohumulone='" . $hop->COHUMULONE; + if ($hop->MYCRENE) + $sql .= "', myrcene='" . $hop->MYCRENE; + if ($hop->HSI) + $sql .= "', hsi='" . $hop->HSI; + $sql .= "', useat='" . $hop->USE; + $sql .= "', type='" . $hop->TYPE; + $sql .= "', form='" . $hop->FORM; + $sql .= "', notes='" . mysqli_real_escape_string($db, $hop->NOTES); + $sql .= "', origin='" . mysqli_real_escape_string($db, $hop->ORIGIN); + $sql .= "', substitutes='" . mysqli_real_escape_string($db, $hop->SUBSTITUTES); + ($hop->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($hop->INVENTORY) + $sql .= "', inventory='" . $hop->INVENTORY; + if ($hop->COST) + $sql .= "', cost='" . $hop->COST; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } + +} + + + +function do_yeasts() +{ + global $brouwhulp, $db; + + echo " Start adding yeasts to the database\n"; + $sql = "TRUNCATE TABLE inventory_yeasts;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $yeasts = simplexml_load_file($brouwhulp . '/yeasts.xml'); + + foreach ($yeasts->YEAST as $yeast) { + + $sql = "INSERT INTO inventory_yeasts SET name='" . mysqli_real_escape_string($db, $yeast->NAME); + $sql .= "', type='" . $yeast->TYPE; + $sql .= "', form='" . $yeast->FORM; + if ($yeast->AMOUNT) + $sql .= "', amount='" . $yeast->AMOUNT; + ($yeast->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='Y" : $sql .= "', amount_is_weight='N"; + $sql .= "', laboratory='" . mysqli_real_escape_string($db, $yeast->LABORATORY); + $sql .= "', product_id='" . mysqli_real_escape_string($db, $yeast->PRODUCT_ID); + if ($yeast->MIN_TEMPERATURE) + $sql .= "', min_temperature='" . $yeast->MIN_TEMPERATURE; + if ($yeast->MAX_TEMPERATURE) + $sql .= "', max_temperature='" . $yeast->MAX_TEMPERATURE; + $sql .= "', flocculation='" . $yeast->FLOCCULATION; + if ($yeast->ATTENUATION) + $sql .= "', attenuation='" . $yeast->ATTENUATION; + $sql .= "', notes='" . mysqli_real_escape_string($db, $yeast->NOTES); + $sql .= "', best_for='" . mysqli_real_escape_string($db, $yeast->BEST_FOR); + if ($yeast->TIMES_CULTURED) + $sql .= "', times_cultured='" . $yeast->TIMES_CULTURED; + if ($yeast->MAX_REUSE) + $sql .= "', max_reuse='" . $yeast->MAX_REUSE; + if ($yeast->INVENTORY) + $sql .= "', inventory='" . $yeast->INVENTORY; + if ($yeast->COST) + $sql .= "', cost='" . $yeast->COST; + if ($yeast->CULTURE_DATE) { + $date = substr($yeast->CULTURE_DATE, 6, 4) . '-' . substr($yeast->CULTURE_DATE, 3, 2) . '-' . substr($yeast->CULTURE_DATE, 0, 2); + $sql .= "', production_date='" . $date; + } + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_waters() +{ + global $brouwhulp, $db; + + echo " Start adding waters to the database\n"; + $sql = "TRUNCATE TABLE inventory_water_profiles;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $waters = simplexml_load_file($brouwhulp . '/waters.xml'); + + foreach ($waters->WATER as $water) { + + $sql = "INSERT INTO inventory_water_profiles SET name='" . mysqli_real_escape_string($db, $water->NAME); + ($water->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($water->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $water->NOTES); + $sql .= "', calcium='" . $water->CALCIUM; + $sql .= "', bicarbonate='" . $water->BICARBONATE; + $sql .= "', sulfate='" . $water->SULFATE; + $sql .= "', chloride='" . $water->CHLORIDE; + $sql .= "', sodium='" . $water->SODIUM; + $sql .= "', magnesium='" . $water->MAGNESIUM; + $sql .= "', ph='" . $water->PH; + if ($water->TOTAL_ALKALINITY) + $sql .= "', total_alkalinity='" . $water->TOTAL_ALKALINITY; + ($water->DEFAULT_WATER == 'TRUE') ? $sql .= "', default_water='Y" : $sql .= "', default_water='N"; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_miscs() +{ + global $brouwhulp, $db; + + echo " Start adding miscs to the database\n"; + $sql = "TRUNCATE TABLE inventory_miscs;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $miscs = simplexml_load_file($brouwhulp . '/miscs.xml'); + + foreach ($miscs->MISC as $misc) { + + $sql = "INSERT INTO inventory_miscs SET name='" . mysqli_real_escape_string($db, $misc->NAME); + if ($misc->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $misc->NOTES); + $sql .= "', type='" . $misc->TYPE; + $sql .= "', use_use='" . $misc->USE; + $sql .= "', time='" . $misc->TIME; + $sql .= "', amount='" . $misc->AMOUNT; + ($misc->AMOUNT_IS_WEIGHT == 'TRUE') ? $sql .= "', amount_is_weight='Y" : $sql .= "', amount_is_weight='N"; + if ($misc->USE_FOR) + $sql .= "', use_for='" . mysqli_real_escape_string($db, $misc->USE_FOR); + if ($misc->ALWAYS_ON_STOCK) + ($misc->ALWAYS_ON_STOCK == 'TRUE') ? $sql .= "', always_on_stock='Y" : $sql .= "', always_on_stock='N"; + if ($misc->INVENTORY) + $sql .= "', inventory='" . $misc->INVENTORY; + if ($misc->COST) + $sql .= "', cost='" . $misc->COST; + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_equipments() +{ + global $brouwhulp, $db; + + echo " Start adding equipments to the database\n"; + $sql = "TRUNCATE TABLE inventory_equipments;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $equipments = simplexml_load_file($brouwhulp . '/equipments.xml'); + + foreach ($equipments->EQUIPMENT as $equipment) { + + $sql = "INSERT INTO inventory_equipments SET name='" . mysqli_real_escape_string($db, $equipment->NAME); + $sql .= "', boil_size='" . $equipment->BOIL_SIZE; + $sql .= "', batch_size='" . $equipment->BATCH_SIZE; + $sql .= "', tun_volume='" . $equipment->TUN_VOLUME; + $sql .= "', tun_weight='" . $equipment->TUN_WEIGHT; + $sql .= "', tun_specific_heat='" . $equipment->TUN_SPECIFIC_HEAT; + $sql .= "', top_up_water='" . $equipment->TOP_UP_WATER; + $sql .= "', trub_chiller_loss='" . $equipment->TRUB_CHILLER_LOSS; + /* + * Brouwhulp uses a percentage for the evaporation rate. This is wrong + * but was made so because the beerxml standard requires this. What we + * do is calculate the actual evaporation and store that. + * This is what we use. Brouwhulp calculates this on the fly. + */ + $sql .= "', evap_rate='" . ($equipment->EVAP_RATE * $equipment->BOIL_SIZE) / 100.0; + $sql .= "', boil_time='" . $equipment->BOIL_TIME; + ($equipment->CALC_BOIL_VOLUME == 'TRUE') ? $sql .= "', calc_boil_volume='Y" : $sql .= "', calc_boil_volume='N"; + $sql .= "', lauter_deadspace='" . $equipment->LAUTER_DEADSPACE; + $sql .= "', top_up_kettle='" . $equipment->TOP_UP_KETTLE; + $sql .= "', hop_utilization='" . $equipment->HOP_UTILIZATION; + if ($equipment->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $equipment->NOTES); + $sql .= "', lauter_volume='" . $equipment->LAUTER_VOLUME; + $sql .= "', kettle_volume='" . $equipment->KETTLE_VOLUME; + if ($equipment->TUN_MATERIAL) + $sql .= "', tun_material='" . mysqli_real_escape_string($db, $equipment->TUN_MATERIAL); + $sql .= "', tun_height='" . $equipment->TUN_HEIGHT; + $sql .= "', kettle_height='" . $equipment->KETTLE_HEIGHT; + $sql .= "', lauter_height='" . $equipment->LAUTER_HEIGHT; + $sql .= "', mash_volume='" . $equipment->MASH_VOLUME; + $sql .= "', efficiency='" . $equipment->EFFICIENCY; + + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_styles() +{ + global $brouwhulp, $db; + + echo " Start adding styles to the database\n"; + $sql = "TRUNCATE TABLE inventory_styles;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $styles = simplexml_load_file($brouwhulp . '/styles.xml'); + + foreach ($styles->STYLE as $style) { + + $sql = "INSERT INTO inventory_styles SET name='" . mysqli_real_escape_string($db, $style->NAME); + if ($style->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $style->NOTES); + if ($style->CATEGORY) + $sql .= "', category='" . mysqli_real_escape_string($db, $style->CATEGORY); + if ($style->CATEGORY_NUMBER) + $sql .= "', category_number='" . $style->CATEGORY_NUMBER; + if ($style->STYLE_LETTER) + $sql .= "', style_letter='" . mysqli_real_escape_string($db, $style->STYLE_LETTER); + if ($style->STYLE_GUIDE) + $sql .= "', style_guide='" . mysqli_real_escape_string($db, $style->STYLE_GUIDE); + $sql .= "', type='" . $style->TYPE; + $sql .= "', og_min='" . $style->OG_MIN; + $sql .= "', og_max='" . $style->OG_MAX; + $sql .= "', fg_min='" . $style->FG_MIN; + $sql .= "', fg_max='" . $style->FG_MAX; + $sql .= "', ibu_min='" . $style->IBU_MIN; + $sql .= "', ibu_max='" . $style->IBU_MAX; + $sql .= "', color_min='" . $style->COLOR_MIN; + $sql .= "', color_max='" . $style->COLOR_MAX; + $sql .= "', carb_min='" . $style->CARB_MIN; + $sql .= "', carb_max='" . $style->CARB_MAX; + $sql .= "', abv_min='" . $style->ABV_MIN; + $sql .= "', abv_max='" . $style->ABV_MAX; + if ($style->PROFILE) + $sql .= "', profile='" . mysqli_real_escape_string($db, $style->PROFILE); + if ($style->INGREDIENTS) + $sql .= "', ingredients='" . mysqli_real_escape_string($db, $style->INGREDIENTS); + if ($style->EXAMPLES) + $sql .= "', examples='" . mysqli_real_escape_string($db, $style->EXAMPLES); + + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } +} + + + +function do_mash() +{ + global $brouwhulp, $db; + + echo " Start adding mash profiles to the database\n"; + $sql = "TRUNCATE TABLE inventory_mash_steps;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + $sql = "TRUNCATE TABLE inventory_mash_profiles;"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + + $mashes = simplexml_load_file($brouwhulp . '/mashs.xml'); + + foreach ($mashes->MASH as $mash) { + $sql = "INSERT INTO inventory_mash_profiles SET name='" . mysqli_real_escape_string($db, $mash->NAME); + if ($mash->NOTES) + $sql .= "', notes='" . mysqli_real_escape_string($db, $mash->NOTES); + if ($mash->GRAIN_TEMP) + $sql .= "', grain_temp='" . $mash->GRAIN_TEMP; + if ($mash->TUN_TEMP) + $sql .= "', tun_temp='" . $mash->TUN_TEMP; + if ($mash->SPARGE_TEMP) + $sql .= "', sparge_temp='" . $mash->SPARGE_TEMP; + if ($mash->PH) + $sql .= "', ph='" . $mash->PH; + if ($mash->TUN_WEIGHT) + $sql .= "', tun_weight='" . $mash->TUN_WEIGHT; + if ($mash->TUN_SPECIFIX_HEAT) + $sql .= "', tun_specific_heat='" . $mash->TUN_SPECIFIC_HEAT; + ($mash->EQUIP_ADJUST == 'TRUE') ? $sql .= "', equip_adjust='Y" : $sql .= "', equip_adjust='N"; + $sql .= "';"; + /* + * Store the record and get the record number that is created. + * Store that as a reference in the steps. + */ + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + $record = mysqli_insert_id($db); + + /* + * Put the steps in a different table with a reference to the profile. + */ + if ($mash->MASH_STEPS) { + foreach ($mash->MASH_STEPS->MASH_STEP as $step) { + + $sql = "INSERT INTO inventory_mash_steps SET name='" . mysqli_real_escape_string($db, $step->NAME); + $sql .= "', rec_mash_profile='" . $record; + if ($step->TYPE) + $sql .= "', type='" . $step->TYPE; + if ($step->INFUSE_AMOUNT) + $sql .= "', infuse_amount='" . $step->INFUSE_AMOUNT; + if ($step->STEP_TEMP) + $sql .= "', step_temp='" . $step->STEP_TEMP; + if ($step->STEP_TIME) + $sql .= "', step_time='" . $step->STEP_TIME; + if ($step->RAMP_TIME) + $sql .= "', ramp_time='" . $step->RAMP_TIME; + if ($step->END_TEMP) + $sql .= "', end_temp='" . $step->END_TEMP; + if ($step->DESCRIPTION) + $sql .= "', description='" . mysqli_real_escape_string($db, $step->DESCRIPTION); + $sql .= "';"; + if (! $result = mysqli_query($db, $sql)) { + printf("Error: %s\n", mysqli_error($db)); + } + } + } + } +} + + + +do_fermentables(); +//do_hops(); +//do_yeasts(); +//do_waters(); +//do_miscs(); +//do_equipments(); +//do_styles(); +//do_mash(); + +mysqli_close($db); + +echo "Finished adding data\n"; + + +?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/includes/db_inventory_fermentables.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,121 @@ +<?php + +require($_SERVER['DOCUMENT_ROOT']."/config.php"); +require($_SERVER['DOCUMENT_ROOT']."/version.php"); + + +#Connect to the database +$connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); +if (! $connect) { + die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); +} + +// get data and store in a json array +$query = "SELECT * FROM inventory_fermentables"; +if (isset($_GET['insert'])) { + // INSERT COMMAND + $sql = "INSERT INTO `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); + $sql .= "', type='" . $_GET['type']; + $sql .= "', yield='" . $_GET['yield']; + $sql .= "', color='" . ebc_to_srm($_GET['color']); + ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; + $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); + $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); + $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); + $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; + $sql .= "', moisture='" . $_GET['moisture']; + $sql .= "', diastatic_power='" . $_GET['diastatic_power']; + $sql .= "', protein='" . $_GET['protein']; + $sql .= "', max_in_batch='" . $_GET['max_in_batch']; + ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; + $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; + ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; + $sql .= "', di_ph='" . $_GET['di_ph']; + $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; + $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); + $sql .= "', inventory='" . $_GET['inventory']; + $sql .= "', cost='" . $_GET['cost']; + $sql .= "', production_date='" . $_GET['production_date']; + $sql .= "', tht_date='" . $_GET['tht_date']; + $sql .= "', supplier_rec='" . $_GET['supplier_rec']; + $sql .= "';"; + error_log("\"$sql\""); + $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); + error_log("result " . $result); + echo $result; + +} else if (isset($_GET['update'])) { + // UPDATE COMMAND + $sql = "UPDATE `inventory_fermentables` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); + $sql .= "', type='" . $_GET['type']; + $sql .= "', yield='" . $_GET['yield']; + $sql .= "', color='" . ebc_to_srm($_GET['color']); + ($_GET['add_after_boil'] == 'true') ? $sql .= "', add_after_boil='1" : $sql .= "', add_after_boil='0"; + $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); + $sql .= "', supplier='" . mysqli_real_escape_string($connect, $_GET['supplier']); + $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); + $sql .= "', coarse_fine_diff='" . $_GET['coarse_fine_diff']; + $sql .= "', moisture='" . $_GET['moisture']; + $sql .= "', diastatic_power='" . $_GET['diastatic_power']; + $sql .= "', protein='" . $_GET['protein']; + $sql .= "', max_in_batch='" . $_GET['max_in_batch']; + ($_GET['recommend_mash'] == 'true') ? $sql .= "', recommend_mash='1" : $sql .= "', recommend_mash='0"; + $sql .= "', ibu_gal_per_lb='" . $_GET['ibu_gal_per_lb']; + ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; + $sql .= "', di_ph='" . $_GET['di_ph']; + $sql .= "', acid_to_ph_57='" . $_GET['acid_to_ph_57']; + $sql .= "', graintype='" . mysqli_real_escape_string($connect, $_GET['graintype']); + $sql .= "', inventory='" . $_GET['inventory']; + $sql .= "', cost='" . $_GET['cost']; + $sql .= "', production_date='" . $_GET['production_date']; + $sql .= "', tht_date='" . $_GET['tht_date']; + $sql .= "', supplier_rec='" . $_GET['supplier_rec']; + $sql .= "' WHERE record='" . $_GET['record'] . "';"; + error_log("\"$sql\""); + $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); + error_log("result " . $result); + echo $result; + +} else if (isset($_GET['delete'])) { + // DELETE COMMAND + $sql = "DELETE FROM `inventory_fermentables` WHERE record='".$_GET['record']."';"; + error_log("\"$sql\""); + $result = mysqli_query($connect, $sql) or die("SQL Error 1: " . mysqli_error($connect)); + error_log("result " . $result); + echo $result; + +} else { + // SELECT COMMAND + $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); + while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { + $fermentables[] = array( + 'record' => $row['record'], + 'name' => $row['name'], + 'type' => $row['type'], + 'yield' => $row['yield'], + 'color' => $row['color'], + 'add_after_boil' => $row['add_after_boil'], + 'origin' => $row['origin'], + 'supplier' => $row['supplier'], + 'notes' => $row['notes'], + 'coarse_fine_diff' => $row['coarse_fine_diff'], + 'moisture' => $row['moisture'], + 'diastatic_power' => $row['diastatic_power'], + 'protein' => $row['protein'], + 'max_in_batch' => $row['max_in_batch'], + 'recommend_mash' => $row['recommend_mash'], + 'ibu_gal_per_lb' => $row['ibu_gal_per_lb'], + 'always_on_stock' => $row['always_on_stock'], + 'di_ph' => $row['di_ph'], + 'acid_to_ph_57' => $row['acid_to_ph_57'], + 'graintype' => $row['graintype'], + 'inventory' => $row['inventory'], + 'cost' => $row['cost'], + 'production_date' => $row['production_date'], + 'tht_date' => $row['tht_date'], + 'supplier_rec' => $row['supplier_rec'] + ); + } + echo json_encode($fermentables); +} +?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/includes/formulas.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,22 @@ +<?php + + +function ebc_to_srm($ebc) +{ + // Srm = -1.32303E-12*Ebc4-0.00000000291515*Ebc3+0.00000818515*Ebc2+0.372038*Ebc+0.596351 + return -1.32303E-12 * pow($ebc, 4) - 0.00000000291515 * pow($ebc, 3) + 0.00000818515 * pow($ebc, 2) + 0.372038 * $ebc + 0.596351; + // return $ebc * 0.508; +} + + +function srm_to_ebc($srm) +{ + // EBC = 0.000000000176506*Srm4+ 0.000000154529*Srm3-0.000159428*Srm2+2.68837*Srm-1.6004 + // + // Formule van Adrie Otten. brouwhulp. + $ebc = 0.000000000176506 * pow($srm, 4) + 0.000000154529 * pow($srm, 3) - 0.000159428 * pow($srm, 2) + 2.68837 * $srm - 1.6004; + return round($ebc); +} + + +?>
--- a/www/includes/global.inc.php Sat Aug 11 22:49:44 2018 +0200 +++ b/www/includes/global.inc.php Sun Aug 12 21:24:33 2018 +0200 @@ -26,9 +26,14 @@ * * energyblue of ui-redmond */ -#$my_style = 'mbse-dark'; -$my_style = 'ui-redmond'; -$my_style = 'android'; +//$my_style = 'ui-redmond'; +//$my_style = 'black'; +//$my_style = 'dark'; +//$my_style = 'metrodark'; +$my_style = 'ui-darkness'; +//$my_style = 'ui-start'; +//$my_style = 'ui-sunny'; +//$my_style = 'android'; require_once($_SERVER['DOCUMENT_ROOT'].'/config.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/version.php'); @@ -36,101 +41,127 @@ function page_header($title, $loadjs) { global $my_style; + global $my_version; +?> +<!DOCTYPE html> +<html lang=nl-NL> + <head> + <meta http-equiv="content-type" content="text/html; charset=utf-8" /> + <title>BMS v<?php echo $my_version;?> - <?php echo $title;?></title> + <link type="text/css" href="css/style.css" rel="stylesheet" media="all" /> + <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" /> + <link type="text/css" href="jqwidgets/styles/jqx.<?php echo $my_style; ?>.css" rel="stylesheet" /> + <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" /> + <script> + var theme = "<?php echo $my_style; ?>"; + </script> + <script src="js/jquery-1.11.1.min.js"></script> + <script src="jqwidgets/jqxcore.js"></script> + <script src="jqwidgets/jqxwindow.js"></script> + <script src="jqwidgets/jqxmenu.js"></script> + <script src="jqwidgets/jqxwindow.js"></script> + <script src="jqwidgets/jqxdata.js"></script> + <script src="jqwidgets/jqxbuttons.js"></script> + <script src="jqwidgets/jqxscrollbar.js"></script> + <script src="jqwidgets/jqxgrid.js"></script> + <script src="jqwidgets/jqxgrid.pager.js"></script> + <script src="jqwidgets/jqxgrid.filter.js"></script> + <script src="jqwidgets/jqxgrid.selection.js"></script> + <script src="jqwidgets/jqxnumberinput.js"></script> + <script src="jqwidgets/jqxlistbox.js"></script> + <script src="jqwidgets/jqxdropdownlist.js"></script> + <script src="jqwidgets/jqxdropdownbutton.js"></script> + <script src="jqwidgets/jqxinput.js"></script> + <script src="jqwidgets/jqxeditor.js"></script> + <script src="jqwidgets/jqxtooltip.js"></script> + <script src="jqwidgets/jqxcheckbox.js"></script> + <script src="jqwidgets/jqxdatetimeinput.js"></script> + <script src="jqwidgets/jqxcalendar.js"></script> + <script src="jqwidgets/globalization/globalize.js"></script> + <script src="js/global.js"></script> +<?php +if (strlen($loadjs)) + echo ' <script src="js/'.$loadjs.'.js"></script>'.PHP_EOL; +?> + </head> - $outstr = '<!DOCTYPE html>'.PHP_EOL; - $outstr .= '<html lang=nl-NL>'.PHP_EOL; - $outstr .= ' <head>'.PHP_EOL; - $outstr .= ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'.PHP_EOL; - $outstr .= ' <title>BMS v'.$my_version.' - ' . $title . '</title>'.PHP_EOL; - $outstr .= ' <link type="text/css" href="css/style.css" rel="stylesheet" media="all" />'.PHP_EOL; - $outstr .= ' <link type="text/css" href="jqwidgets/styles/jqx.base.css" rel="stylesheet" />'.PHP_EOL; - $outstr .= ' <link type="text/css" href="jqwidgets/styles/jqx.'.$my_style.'.css" rel="stylesheet" />'.PHP_EOL; - $outstr .= ' <meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1 minimum-scale=1" />'.PHP_EOL; - $outstr .= ' <script>'.PHP_EOL; - $outstr .= ' var theme = "'.$my_style.'";'.PHP_EOL; - $outstr .= ' </script>'.PHP_EOL; - $outstr .= ' <script src="js/jquery-1.11.1.min.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxcore.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxwindow.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxmenu.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxwindow.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxdata.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxbuttons.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxscrollbar.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxgrid.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxgrid.pager.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxgrid.filter.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxgrid.selection.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxnumberinput.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxlistbox.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxdropdownlist.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxdropdownbutton.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxinput.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxeditor.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxtooltip.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxcheckbox.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxdatetimeinput.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/jqxcalendar.js"></script>'.PHP_EOL; - $outstr .= ' <script src="jqwidgets/globalization/globalize.js"></script>'.PHP_EOL; - $outstr .= ' <script src="js/global.js"></script>'.PHP_EOL; - if (strlen($loadjs)) - $outstr .= ' <script src="js/'.$loadjs.'.js"></script>'.PHP_EOL; - $outstr .= ' </head>'.PHP_EOL; - $outstr .= ' <body class="default">'.PHP_EOL; - $outstr .= ' <div id="jqxWidget">'.PHP_EOL; + <body class="default"> + <div id="jqxWidget"> - /* - * Menu - */ - $outstr .= ' <div id="jqxMenu">'.PHP_EOL; - $outstr .= ' <ul>'.PHP_EOL; - $outstr .= ' <li><a href="#Home">Home</a></li>'.PHP_EOL; - $outstr .= ' <li>Monitoren'.PHP_EOL; - $outstr .= ' <ul>'.PHP_EOL; - $outstr .= ' <li><a href="monitor.php">Probeersel</a></li>'.PHP_EOL; - $outstr .= ' </ul>'.PHP_EOL; - $outstr .= ' </li>'.PHP_EOL; // Monitoren - $outstr .= ' <li>Inventaris'.PHP_EOL; - $outstr .= ' <ul>'.PHP_EOL; - $outstr .= ' <li><a href="inv_suppliers.php">Leveranciers</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_fermentables.php">Vergistbare producten</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_hops.php">Hoppen</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_yeasts.php">Gist</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_waters.php">Water profielen</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_miscs.php">Diverse ingredienetn</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_mashs.php">Maisch profielen</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_equipments.php">Brouw apparatuur</a></li>'.PHP_EOL; - $outstr .= ' <li><a href="inv_styles.php">Bier stijlen</a></li>'.PHP_EOL; - $outstr .= ' </ul>'.PHP_EOL; - $outstr .= ' </li>'.PHP_EOL; // Inventaris - $outstr .= ' <li>About'.PHP_EOL; - $outstr .= ' <ul>'.PHP_EOL; - $outstr .= ' <li><a href="#aboutWindow">Informatie</a></li>'.PHP_EOL; - $outstr .= ' </ul>'.PHP_EOL; - $outstr .= ' </li>'.PHP_EOL; - $outstr .= ' </ul>'.PHP_EOL; - $outstr .= ' </div>'.PHP_EOL; + <!-- Menu --> + <div id="jqxMenu"> + <ul> + <li><a href="#Home">Home</a></li> + <li>Monitoren + <ul> + <li>Systemen</li> + <li>Klimaatkasten</li> + <li><a href="monitor.php">Probeersel</a></li> + </ul> + </li> + <li>Inventaris + <ul> + <li><a href="inv_suppliers.php">Leveranciers</a></li> + <li><a href="inv_fermentables.php">Vergistbare producten</a></li> + <li><a href="inv_hops.php">Hoppen</a></li> + <li><a href="inv_yeasts.php">Gist</a></li> + <li><a href="inv_waters.php">Water profielen</a></li> + <li><a href="inv_miscs.php">Diverse ingredienetn</a></li> + <li><a href="inv_mashs.php">Maisch profielen</a></li> + <li><a href="inv_equipments.php">Brouw apparatuur</a></li> + <li><a href="inv_styles.php">Bier stijlen</a></li> + </ul> + </li> + <li>Over + <ul> + <li><a href="#aboutWindow">Informatie</a></li> + </ul> + </li> + </ul> + </div> <!-- End menu --> - $outstr .= ' <div id="aboutWindow">'.PHP_EOL; - $outstr .= ' <div>'.PHP_EOL; - $outstr .= ' About BrewCloud'.PHP_EOL; - $outstr .= ' </div>'.PHP_EOL; - $outstr .= ' <div>'.PHP_EOL; - $outstr .= ' The about text comes here'.PHP_EOL; - $outstr .= ' </div>'.PHP_EOL; - $outstr .= ' </div>'.PHP_EOL; + <div id="aboutWindow"> + <div> + Over BMS + </div> + <div> + The about text comes here + </div> + </div> + +<?php +} + - return $outstr; +function confirm_delete() { +?> + <div id="eventWindow"> + <div> + Bevestig verwijderen + </div> + <div> + <div> + Klik "OK" om dit record definitief te verwijderen.<br> + Druk "Cancel" om te sluiten zonder dit record te verwijderen. + </div> + <div> + <div style="float: right; margin-top: 15px; margin-bottom: 10px;"> + <input type="button" id="delOk" value="OK" style="margin-right: 15px" /> + <input type="button" id="delCancel" value="Cancel" style="margin-right: 65px" /> + </div> + </div> + </div> + </div> + +<?php } function page_footer() { - - $outstr = ' </div> <!-- jqxWidget -->'.PHP_EOL; - $outstr .= ' </body>'.PHP_EOL; - $outstr .= '</html>'.PHP_EOL; - - return $outstr; +?> + </div> <!-- jqxWidget --> + </body> +</html> +<?php } - - +?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/index.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,32 @@ +<?php +/***************************************************************************** + * Copyright (C) 2018 + * + * Michiel Broek <mbroek at mbse dot eu> + * + * This file is part of Brewery Management System + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * BrewCloud is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ThermFerm; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + +require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); + +$outstr = page_header('Hoofdmenu', NULL); + + +$outstr .= page_footer(); + +echo $outstr; +?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/inv_fermentables.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,104 @@ +<?php +require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); +page_header('Vergistbare producten', 'inv_fermentables'); +?> + + <div id="jqxgrid"></div> + <div style="margin-top: 30px;"> + <div id="cellbegineditevent"></div> + <div style="margin-top: 10px;" id="cellendeditevent"></div> + </div> + + <!-- Popup editor window. --> + <div id="popupWindow"> + <div>Wijzig vergistbaar product</div> + <div style="overflow: hidden;"> + <table> + <tr> + <td align="right" style="vertical-align: top;">Product naam:</td> + <td align="left" style="vertical-align: top;"><input id="name" /></td> + <td align="right" style="vertical-align: top;">Type:</td> + <td align="left"><div id="type"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Opbrengst:</td> + <td align="left"><div id="yield"></div></td> + <td align="right" style="vertical-align: top;">Kleur:</td> + <td align="left"><div id="color"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Add after boil:</td> + <td align="left"><div id="add_after_boil"></div></td> + <td align="right" style="vertical-align: top;">Grof/fijn verschil:</td> + <td align="left"><div id="coarse_fine_diff"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Herkomst:</td> + <td align="left" style="vertical-align: top;"><input id="origin" /></td> + <td align="right" style="vertical-align: top;">Moisture:</td> + <td align="left"><div id="moisture"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Leverancier:</td> + <td align="left" style="vertical-align: top;"><input id="supplier" /></td> + <td align="right" style="vertical-align: top;">Diastatic Power:</td> + <td align="left"><div id="diastatic_power"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">protein:</td> + <td align="left"><div id="protein"></div></td> + <td align="right" style="vertical-align: top;">max_in_batch:</td> + <td align="left"><div id="max_in_batch"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">recommend_mash:</td> + <td align="left"><div id="recommend_mash"></div></td> + <td align="right" style="vertical-align: top;">ibu_gal_per_lb:</td> + <td align="left"><div id="ibu_gal_per_lb"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">always_on_stock:</td> + <td align="left"><div id="always_on_stock"></div></td> + <td align="right" style="vertical-align: top;">di_ph:</td> + <td align="left"><div id="di_ph"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">acid_to_ph_57:</td> + <td align="left"><div id="acid_to_ph_57"></div></td> + <td align="right" style="vertical-align: top;">graintype:</td> + <td align="left" style="vertical-align: top;"><input id="graintype" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">supplier_rec:</td> + <td align="left" colspan="3"><div id="supplier_rec"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Opmerkingen:</td> + <td align="left" colspan="3"><textarea id="notes"></textarea></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Voorraad:</td> + <td align="left"><div id="inventory"></div></td> + <td align="right" style="vertical-align: top;">Prijs:</td> + <td align="left"><div id="cost"></div></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Productie datum:</td> + <td align="left" style="vertical-align: top;"><div id="production_date"></div></td> + <td align="right" style="vertical-align: top;">Gebruik voor datum:</td> + <td align="left" style="vertical-align: top;"><div id="tht_date"></div></td> + </tr> + <tr> + <td style="padding-top: 10px;" align="right"><input type="button" id="Delete" value="Delete" /></td> + <td align="right"></td> + <td align="right"></td> + <td style="padding-top: 10px;" align="right"><input style="margin-right: 5px;" type="button" id="Save" value="Save" /><input id="Cancel" type="button" value="Cancel" /></td> + </tr> + </table> + </div> + </div> + +<?php +confirm_delete(); +page_footer(); +?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/inv_suppliers.php Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,67 @@ +<?php +require_once($_SERVER['DOCUMENT_ROOT'].'/includes/global.inc.php'); +page_header('Leveranciers', 'inv_suppliers'); +?> + + <div id="jqxgrid"></div> + <div style="margin-top: 30px;"> + <div id="cellbegineditevent"></div> + <div style="margin-top: 10px;" id="cellendeditevent"></div> + </div> + + <!-- Popup editor window. --> + <div id="popupWindow"> + <div>Wijzig leverancier.</div> + <div style="overflow: hidden;"> + <table> + <tr> + <td align="right" style="vertical-align: top;">Leverancier naam:</td> + <td align="left" colspan="3" style="vertical-align: top;"><input id="name" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Adres:</td> + <td align="left" style="vertical-align: top;"><input id="address" /></td> + <td align="right" style="vertical-align: top;">Postcode:</td> + <td align="left" style="vertical-align: top;"><input id="zip" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Plaats:</td> + <td align="left" colspan="3" style="vertical-align: top;"><input id="city" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Land:</td> + <td align="left" colspan="3" style="vertical-align: top;"><input id="country" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Website:</td> + <td align="left" colspan="3" style="vertical-align: top;"><input id="website" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Email:</td> + <td align="left" colspan="3" style="vertical-align: top;"><input id="email" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Telefoon:</td> + <td align="left" colspan="3" style="vertical-align: top;"><input id="phone" /></td> + </tr> + <tr> + <td align="right" style="vertical-align: top;">Opmerkingen:</td> + <td align="left" colspan="3"><textarea id="notes"></textarea></td> + </tr> + <tr> + <td style="padding-top: 10px;" align="right"><input type="button" id="Delete" value="Delete" /></td> + <td align="right"></td> + <td align="right"></td> + <td style="padding-top: 10px;" align="right"> + <input style="margin-right: 5px;" type="button" id="Save" value="Save" /> + <input id="Cancel" type="button" value="Cancel" /> + </td> + </tr> + </table> + </div> + </div> + +<?php +confirm_delete(); +page_footer(); +?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/js/inv_fermentables.js Sun Aug 12 21:24:33 2018 +0200 @@ -0,0 +1,341 @@ +/***************************************************************************** + * Copyright (C) 2014-2018 + * + * Michiel Broek <mbroek at mbse dot eu> + * + * This file is part of BrewCloud + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * BrewCloud is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ThermFerm; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + + +function createDelElements() { + $('#eventWindow').jqxWindow({ + theme: theme, + position: { x: 490, y: 210 }, + width: 300, + height: 145, + resizable: false, + isModal: true, + modalOpacity: 0.4, + okButton: $('#delOk'), + cancelButton: $('#delCancel'), + initContent: function () { + $('#delOk').jqxButton({ width: '65px', theme: theme }); + $('#delCancel').jqxButton({ width: '65px', theme: theme }); + $('#delCancel').focus(); + } + }); + $('#eventWindow').jqxWindow('hide'); +} + + +$(document).ready(function () { + var url = "includes/db_inventory_fermentables.php"; + // prepare the data + var source = { + datatype: "json", + cache: false, + datafields: [ + { name: 'record', type: 'number' }, + { name: 'name', type: 'string' }, + { name: 'type', type: 'string' }, + { name: 'yield', type: 'float' }, + { name: 'color', type: 'float' }, + { name: 'add_after_boil', type: 'bool' }, + { name: 'origin', type: 'string' }, + { name: 'supplier', type: 'string' }, + { name: 'notes', type: 'string' }, + { name: 'coarse_fine_diff', type: 'float' }, + { name: 'moisture', type: 'float' }, + { name: 'diastatic_power', type: 'float' }, + { name: 'protein', type: 'float' }, + { name: 'max_in_batch', type: 'float' }, + { name: 'recommend_mash', type: 'bool' }, + { name: 'ibu_gal_per_lb', type: 'float' }, + { name: 'always_on_stock', type: 'bool' }, + { name: 'di_ph', type: 'float' }, + { name: 'acid_to_ph_57', type: 'float' }, + { name: 'graintype', type: 'string' }, + { name: 'inventory', type: 'float' }, + { name: 'cost', type: 'float' }, + { name: 'production_date', type: 'string' }, + { name: 'tht_date', type: 'string' }, + { name: 'supplier_rec', type: 'float' } + ], + id: 'record', + url: url, + deleterow: function (rowid, commit) { + // synchronize with the server - send delete command + var data = "delete=true&" + $.param({ record: rowid }); + $.ajax({ + dataType: 'json', + url: url, + cache: false, + data: data, + success: function (data, status, xhr) { + // delete command is executed. + commit(true); + }, + error: function (jqXHR, textStatus, errorThrown) { + commit(false); + } + }); + }, + addrow: function (rowid, rowdata, position, commit) { + var data = "insert=true&" + $.param(rowdata); + $.ajax({ + dataType: 'json', + url: url, + cache: false, + data: data, + success: function (data, status, xhr) { + commit(true); + }, + error: function(jqXHR, textStatus, errorThrown) { + commit(false); + } + }); + }, + updaterow: function (rowid, rowdata, commit) { + var data = "update=true&" + $.param(rowdata); + $.ajax({ + dataType: 'json', + url: url, + cache: false, + data: data, + success: function (data, status, xhr) { + // update command is executed. + commit(true); + }, + error: function(jqXHR, textStatus, errorThrown) { + commit(false); + } + }); + } + }; + var srcType = [ "Grain", "Sugar", "Extract", "Dry Extract", "Adjunct" ]; + // initialize the input fields. + $("#name").jqxInput({ theme: theme, width: 250, height: 23 }); + $("#type").jqxDropDownList({ theme: theme, source: srcType, width: 90, height: 23, dropDownHeight: 130 }); + $("#yield").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#color").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#add_after_boil").jqxCheckBox({ theme: theme, width: 120, height: 23 }); + $("#origin").jqxInput({ theme: theme, width: 250, height: 23 }); + $("#supplier").jqxInput({ theme: theme, width: 250, height: 23 }); + $("#notes").jqxInput({ theme: theme, width: 640, height: 48 }); + $("#coarse_fine_diff").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#moisture").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#diastatic_power").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#protein").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#max_in_batch").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#recommend_mash").jqxCheckBox({ theme: theme, width: 120, height: 23 }); + $("#ibu_gal_per_lb").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#always_on_stock").jqxCheckBox({ theme: theme, width: 120, height: 23 }); + $("#di_ph").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#acid_to_ph_57").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + + $("#graintype").jqxInput({ theme: theme, width: 250, height: 23 }); + + $("#inventory").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + $("#production_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); + + $("#cost").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 2, spinButtons: true }); + $("#tht_date").jqxDateTimeInput({ theme: theme, width: 100, height: 23, formatString: 'yyyy-MM-dd' }); + $("#supplier_rec").jqxNumberInput({ inputMode: 'simple', spinMode: 'simple', theme: theme, width: 70, height: 23, min: 0, decimalDigits: 1, spinButtons: true }); + // supplier_rec + var dataAdapter = new $.jqx.dataAdapter(source); + var editrow = -1; + // initialize jqxGrid + $("#jqxgrid").jqxGrid({ + width: 1280, + height: 630, + source: dataAdapter, + theme: theme, + showstatusbar: true, + localization: getLocalization(), + renderstatusbar: function (statusbar) { + var container = $("<div style='overflow: hidden; position: relative; margin: 5px;'></div>"); + var addButton = $("<div style='float: right; margin-right: 15px;'><img style='position: relative; margin-top: 2px;' src='images/add.png'/><span style='margin-left: 4px; position: relative; top: -3px;'>Add</span></div>"); + container.append(addButton); + statusbar.append(container); + addButton.jqxButton({ width: 60, height: 20 }); + // add new row. + addButton.click(function (event) { + editrow = -1; + $("#popupWindow").jqxWindow({ position: { x: 230, y: 10 } }); + $("#name").val(''); + $("#type").val('Grain'); + $("#origin").val(''); + $("#supplier").val(''); + $("#notes").val(''); + $("#coarse_fine_diff").val(''); + $("#moisture").val(''); + $("#diastatic_power").val(''); + $("#protein").val(''); + $("#max_in_batch").val(''); + $("#recommend_mash").val(''); + $("#ibu_gal_per_lb").val(''); + $("#always_on_stock").val(''); + $("#di_ph").val(''); + $("#acid_to_ph_57").val(''); + $("#graintype").val(''); + $("#inventory").val(''); + $("#cost").val(''); + $("#production_date").val(''); + $("#tht_date").val(''); + $("#supplier_rec").val(''); + $("#popupWindow").jqxWindow('open'); + }); + }, + filterable: true, + filtermode: 'excel', + columns: [ + { text: 'Vergistbaar product', datafield: 'name', width: 250 }, + { text: 'Soort', datafield: 'type', width: 90 }, + { text: 'Herkomst', datafield: 'origin', width: 150 }, + { text: 'Producent', datafield: 'supplier', width: 150 }, + { text: 'Kleur', datafield: 'color', width: 70, cellsalign: 'right' }, + { text: 'Opbrengst', datafield: 'yield', width: 70, cellsalign: 'right' }, + { text: 'Inv.', datafield: 'inventory', width: 70, cellsalign: 'right' }, + { text: 'Prijs', datafield: 'cost', width: 70, cellsalign: 'right', cellsformat: 'c2' }, + { text: 'Edit', datafield: 'Edit', width: 120, columntype: 'button', cellsrenderer: function () { + return "Edit"; + }, buttonclick: function (row) { + // open the popup window when the user clicks a button. + editrow = row; + $("#popupWindow").jqxWindow({ position: { x: 230, y: 10 } }); + // get the clicked row's data and initialize the input fields. + var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); + $("#name").val(dataRecord.name); + $("#type").val(dataRecord.type); + $("#yield").val(dataRecord.yield); + $("#color").val(dataRecord.color); + $("#add_after_boil").val(dataRecord.add_after_boil); + $("#origin").val(dataRecord.origin); + $("#supplier").val(dataRecord.supplier); + $("#notes").val(dataRecord.notes); + $("#coarse_fine_diff").val(dataRecord.coarse_fine_diff); + $("#moisture").val(dataRecord.moisture); + $("#diastatic_power").val(dataRecord.diastatic_power); + $("#protein").val(dataRecord.protein); + $("#max_in_batch").val(dataRecord.max_in_batch); + $("#recommend_mash").val(dataRecord.recommend_mash); + $("#ibu_gal_per_lb").val(dataRecord.ibu_gal_per_lb); + $("#always_on_stock").val(dataRecord.always_on_stock); + $("#di_ph").val(dataRecord.di_ph); + $("#acid_to_ph_57").val(dataRecord.acid_to_ph_57); + $("#graintype").val(dataRecord.graintype); + $("#inventory").val(dataRecord.inventory); + $("#cost").val(dataRecord.cost); + $("#production_date").val(dataRecord.production_date); + $("#tht_date").val(dataRecord.tht_date); + $("#supplier_rec").val(dataRecord.supplier_rec); + // show the popup window. + $("#popupWindow").jqxWindow('open'); + } + } + ] + }); + // initialize the popup window and buttons. + $("#popupWindow").jqxWindow({ + width: 860, resizable: false, theme: theme, isModal: true, autoOpen: false, cancelButton: $("#Cancel"), modalOpacity: 0.40 + }); + $("#popupWindow").on('open', function () { + $("#name").jqxInput('selectAll'); + }); + $("#Delete").jqxButton({ theme: theme }); + $("#Delete").click(function () { + if (editrow >= 0) { + // Open a popup to confirm this action. + $('#eventWindow').jqxWindow('open'); + $("#delOk").click(function () { + var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); + $("#jqxgrid").jqxGrid('deleterow', rowID); + }); + } + $("#popupWindow").jqxWindow('hide'); + }); + $("#Cancel").jqxButton({ theme: theme }); + $("#Save").jqxButton({ theme: theme }); + // update the edited row when the user clicks the 'Save' button. + $("#Save").click(function () { + if (editrow >= 0) { + var rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); + var row = { + record: rowID, + name: $("#name").val(), + type: $("#type").val(), + yield: parseFloat($("#yield").jqxNumberInput('decimal')), + color: parseFloat($("#color").jqxNumberInput('decimal')), + add_after_boil: $("#add_after_boil").val(), + origin: $("#origin").val(), + supplier: $("#supplier").val(), + notes: $("#notes").val(), + coarse_fine_diff: parseFloat($("#coarse_fine_diff").jqxNumberInput('decimal')), + moisture: parseFloat($("#moisture").jqxNumberInput('decimal')), + diastatic_power: parseFloat($("#diastatic_power").jqxNumberInput('decimal')), + protein: parseFloat($("#protein").jqxNumberInput('decimal')), + max_in_batch: parseFloat($("#max_in_batch").jqxNumberInput('decimal')), + recommend_mash: $("#recommend_mash").val(), + ibu_gal_per_lb: parseFloat($("#ibu_gal_per_lb").jqxNumberInput('decimal')), + always_on_stock: $("#always_on_stock").val(), + di_ph: parseFloat($("#di_ph").jqxNumberInput('decimal')), + acid_to_ph_57: parseFloat($("#acid_to_ph_57").jqxNumberInput('decimal')), + graintype: $("#graintype").val(), + inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), + cost: parseFloat($("#cost").jqxNumberInput('decimal')), + production_date: $("#production_date").val(), + tht_date: $("#tht_date").val(), + supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')) + }; + $('#jqxgrid').jqxGrid('updaterow', rowID, row); + $("#popupWindow").jqxWindow('hide'); + } else { + // Insert a record + var newrow = { + record: -1, + name: $("#name").val(), + type: $("#type").val(), + yield: parseFloat($("#yield").jqxNumberInput('decimal')), + color: parseFloat($("#color").jqxNumberInput('decimal')), + add_after_boil: $("#add_after_boil").val(), + origin: $("#origin").val(), + supplier: $("#supplier").val(), + notes: $("#notes").val(), + coarse_fine_diff: parseFloat($("#coarse_fine_diff").jqxNumberInput('decimal')), + moisture: parseFloat($("#moisture").jqxNumberInput('decimal')), + diastatic_power: parseFloat($("#diastatic_power").jqxNumberInput('decimal')), + protein: parseFloat($("#protein").jqxNumberInput('decimal')), + max_in_batch: parseFloat($("#max_in_batch").jqxNumberInput('decimal')), + recommend_mash: $("#recommend_mash").val(), + ibu_gal_per_lb: parseFloat($("#ibu_gal_per_lb").jqxNumberInput('decimal')), + always_on_stock: $("#always_on_stock").val(), + di_ph: parseFloat($("#di_ph").jqxNumberInput('decimal')), + acid_to_ph_57: parseFloat($("#acid_to_ph_57").jqxNumberInput('decimal')), + graintype: $("#graintype").val(), + inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), + cost: parseFloat($("#cost").jqxNumberInput('decimal')), + production_date: $("#production_date").val(), + tht_date: $("#tht_date").val(), + supplier_rec: parseFloat($("#supplier_rec").jqxNumberInput('decimal')) + }; + $('#jqxgrid').jqxGrid('addrow', null, newrow); + $("#popupWindow").jqxWindow('hide'); + } + }); + createDelElements(); +}); +
--- a/www/js/inv_suppliers.js Sat Aug 11 22:49:44 2018 +0200 +++ b/www/js/inv_suppliers.js Sun Aug 12 21:24:33 2018 +0200 @@ -21,18 +21,20 @@ *****************************************************************************/ + function createDelElements() { $('#eventWindow').jqxWindow({ theme: theme, - position: { x: 355, y: 210 }, - width: 270, + position: { x: 490, y: 210 }, + width: 300, + height: 145, resizable: false, isModal: true, modalOpacity: 0.4, okButton: $('#delOk'), cancelButton: $('#delCancel'), initContent: function () { - $('#delOk').jqxButton({ width: '65px', theme: theme }); + $('#delOk').jqxButton({ width: '65px', theme: theme }); $('#delCancel').jqxButton({ width: '65px', theme: theme }); $('#delCancel').focus(); } @@ -41,6 +43,7 @@ } + $(document).ready(function () { var url = "includes/db_inventory_suppliers.php"; // prepare the data @@ -125,7 +128,8 @@ var editrow = -1; // initialize jqxGrid $("#jqxgrid").jqxGrid({ - width: 980, + width: 1280, + height: 630, source: dataAdapter, theme: theme, showstatusbar: true, @@ -138,7 +142,7 @@ // add new row. addButton.click(function (event) { editrow = -1; - $("#popupWindow").jqxWindow({ position: { x: 80, y: 10 } }); + $("#popupWindow").jqxWindow({ position: { x: 230, y: 10 } }); $("#name").val(''); $("#address").val(''); $("#city").val(''); @@ -154,16 +158,17 @@ filterable: true, filtermode: 'excel', columns: [ - { text: 'Supplier Name', datafield: 'name', width: 250 }, - { text: 'City', datafield: 'city', width: 250 }, - { text: 'Country', datafield: 'country', width: 250 }, - { text: 'Phone', datafield: 'phone', width: 100 }, - { text: 'Edit', datafield: 'Edit', columntype: 'button', cellsrenderer: function () { + { text: 'Leverancier naam', datafield: 'name', width: 250 }, + { text: 'Adres', datafield: 'address', width: 300 }, + { text: 'Plaats', datafield: 'city', width: 250 }, + { text: 'Land', datafield: 'country', width: 250 }, + { text: 'Telefoon', datafield: 'phone', width: 100 }, + { text: 'Wijzig', datafield: 'Edit', columntype: 'button', cellsrenderer: function () { return "Edit"; }, buttonclick: function (row) { // open the popup window when the user clicks a button. editrow = row; - $("#popupWindow").jqxWindow({ position: { x: 80, y: 10 } }); + $("#popupWindow").jqxWindow({ position: { x: 230, y: 10 } }); // get the clicked row's data and initialize the input fields. var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow); $("#name").val(dataRecord.name);