--- a/www/js/inv_yeasts.js Thu Jan 24 20:54:45 2019 +0100 +++ b/www/js/inv_yeasts.js Fri Jan 25 13:33:10 2019 +0100 @@ -46,9 +46,25 @@ var dataRecord = {}; - function calcTotal(cost, inventory) { + function calcTotal() { - $('#totval').val(cost * (inventory / 1000)); + $('#totval').val(dataRecord.cost * dataRecord.inventory); + if (dataRecord.form == 0) { // Liquid + $("#pmpt_cost").html('Prijs per pak:'); + $("#pmpt_inventory").html('Voorraad pak(ken):'); + $("#pmpt_cells").html('Biljoen cellen per pak:'); + $("#inventory").jqxNumberInput({ decimalDigits: 0, spinButtonsStep: 1 }); + } else if (dataRecord.form == 1) { // Dry + $("#pmpt_cost").html('Prijs per kg:'); + $("#pmpt_inventory").html('Voorraad gram:'); + $("#pmpt_cells").html('Biljoen cellen per gram:'); + $("#inventory").jqxNumberInput({ decimalDigits: 1, spinButtonsStep: 0.5 }); + } else { + $("#pmpt_cost").html('Prijs per liter:'); + $("#pmpt_inventory").html('Voorraad ml:'); + $("#pmpt_cells").html('Biljoen cellen per ml:'); + $("#inventory").jqxNumberInput({ decimalDigits: 1, spinButtonsStep: 0.5 }); + } } var url = "includes/db_inventory_yeasts.php"; @@ -154,7 +170,7 @@ autoDropDownHeight: true }); $("#notes").jqxInput({ theme: theme, width: 800, height: 120 }); - $("#best_for").jqxInput({ theme: theme, width: 320, height: 50 }); + $("#best_for").jqxInput({ theme: theme, width: 320, height: 75 }); $("#inventory").jqxNumberInput( Spin1dec1 ); $("#production_date").jqxDateTimeInput( Dateopts ); $("#min_temperature").jqxNumberInput( YeastT ); @@ -168,13 +184,14 @@ height: 23, autoDropDownHeight: true }); - $("#attenuation").jqxNumberInput( Perc1dec1 ); + $("#attenuation").jqxNumberInput( Perc1dec5 ); $("#max_reuse").jqxNumberInput( PosInt ); $("#max_reuse").jqxNumberInput({ max: 10 }); $("#cost").jqxNumberInput( Spin2dec1 ); $("#tht_date").jqxDateTimeInput( Dateopts ); $("#totval").jqxNumberInput( Spin2dec1 ); $("#totval").jqxNumberInput({ width: 90, readOnly: true, spinButtons: false }); + $("#cells").jqxNumberInput( Spin1dec1 ); var dataAdapter = new $.jqx.dataAdapter(source); var editrow = -1; @@ -212,6 +229,7 @@ $("#cost").val(0); $("#production_date").val(''); $("#tht_date").val(''); + $("#cells").val(1); $("#popupWindow").jqxWindow('open'); }); }, @@ -219,22 +237,33 @@ filtermode: 'excel', columns: [ { text: 'Laboratorium', datafield: 'laboratory', width: 150 }, - { text: 'Product ID', datafield: 'product_id', width: 120 }, - { text: 'Gist naam', datafield: 'name' }, - { text: 'Type', datafield: 'type', align: 'center', cellsalign: 'center', width: 90, + { text: 'Product ID', datafield: 'product_id', width: 120, menu: false }, + { text: 'Gist naam', datafield: 'name', menu: false }, + { text: 'Type', datafield: 'type', align: 'center', cellsalign: 'center', menu: false, width: 110, cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { return "<div style='margin: 4px;' class='jqx-center-align'>" + YeastTypeData[value].nl + "</div>"; } }, - { text: 'Vorm', datafield: 'form', align: 'center', cellsalign: 'center', width: 90, + { text: 'Vorm', datafield: 'form', align: 'center', cellsalign: 'center', menu: false, width: 110, cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { return "<div style='margin: 4px;' class='jqx-center-align'>" + YeastFormData[value].nl + "</div>"; } }, - { text: 'Vergistingsgraad', datafield: 'attenuation', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'p0' }, - { text: 'Voor. gr/ml', datafield: 'inventory', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, - { text: 'Prijs kg/l', datafield: 'cost', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'c2' }, - { text: 'Wijzig', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () { + { text: 'SVG', datafield: 'attenuation', width: 80, align: 'right', cellsalign: 'right', menu: false, cellsformat: 'p1' }, + { text: 'Voorraad', datafield: 'inventory', width: 100, align: 'right', menu: false, cellsalign: 'right', + cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { + if (value == 0) + return "<div style='margin: 4px;' class='jqx-right-align'></div>"; + if ((rowdata.form == 0) && (value > 1)) + return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value,"f0")+" pakken</div>"; + if (rowdata.form == 0) + return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value,"f0")+" pak</div>"; + if (rowdata.form == 1) + return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value * 1000,"f1")+" gram</div>"; + return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value * 1000,"f1")+" ml</div>"; + } + }, + { text: 'Wijzig', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', menu: false, cellsrenderer: function () { return "Wijzig"; }, buttonclick: function (row) { // open the popup window when the user clicks a button. @@ -254,11 +283,15 @@ $("#notes").val(dataRecord.notes); $("#best_for").val(dataRecord.best_for); $("#max_reuse").val(dataRecord.max_reuse); - $("#inventory").val(dataRecord.inventory); + if (dataRecord.form == 0) + $("#inventory").val(dataRecord.inventory); + else + $("#inventory").val(dataRecord.inventory * 1000); $("#cost").val(dataRecord.cost); $("#production_date").val(dataRecord.production_date); $("#tht_date").val(dataRecord.tht_date); - calcTotal(dataRecord.cost, dataRecord.inventory); + $("#cells").val(dataRecord.cells); + calcTotal(); // show the popup window. $("#popupWindow").jqxWindow('open'); } @@ -266,13 +299,23 @@ ] }); + $('#popupWindow').on('open', function (event) { calcTotal(); }); $("#cost").on('change', function (event) { dataRecord.cost = parseFloat(event.args.value); - calcTotal(dataRecord.cost, dataRecord.inventory); + calcTotal(); }); $("#inventory").on('change', function (event) { - dataRecord.inventory = parseFloat(event.args.value); - calcTotal(dataRecord.cost, dataRecord.inventory); + if (dataRecord.form == 0) + dataRecord.inventory = parseFloat(event.args.value); + else + dataRecord.inventory = parseFloat(event.args.value) / 1000.0; + calcTotal(); + }); + $("#form").on('select', function (event) { + if (event.args) { + dataRecord.form = event.args.index; + calcTotal(); + } }); // initialize the popup window and buttons. @@ -309,6 +352,10 @@ if (editrow >= 0) { rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); } + if (dataRecord.form == 0) + var n_inventory = parseFloat($("#inventory").jqxNumberInput('decimal')); + else + var n_inventory = parseFloat($("#inventory").jqxNumberInput('decimal')) / 1000.0; var row = { record: rowID, name: $("#name").val(), @@ -323,10 +370,11 @@ notes: $("#notes").val(), best_for: $("#best_for").val(), max_reuse: parseInt($("#max_reuse").jqxNumberInput('decimal')), - inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), + inventory: n_inventory, cost: parseFloat($("#cost").jqxNumberInput('decimal')), production_date: $("#production_date").val(), - tht_date: $("#tht_date").val() + tht_date: $("#tht_date").val(), + cells: parseFloat($("#cells").jqxNumberInput('decimal')) }; if (editrow >= 0) { $('#jqxgrid').jqxGrid('updaterow', rowID, row);