www/js/inv_yeasts.js

changeset 201
f9b7e3f6be7c
parent 200
7b2f11652d67
child 245
3649c3d31d15
equal deleted inserted replaced
200:7b2f11652d67 201:f9b7e3f6be7c
44 44
45 $(document).ready(function () { 45 $(document).ready(function () {
46 46
47 var dataRecord = {}; 47 var dataRecord = {};
48 48
49 function calcTotal(cost, inventory) { 49 function calcTotal() {
50 50
51 $('#totval').val(cost * (inventory / 1000)); 51 $('#totval').val(dataRecord.cost * dataRecord.inventory);
52 if (dataRecord.form == 0) { // Liquid
53 $("#pmpt_cost").html('Prijs per pak:');
54 $("#pmpt_inventory").html('Voorraad pak(ken):');
55 $("#pmpt_cells").html('Biljoen cellen per pak:');
56 $("#inventory").jqxNumberInput({ decimalDigits: 0, spinButtonsStep: 1 });
57 } else if (dataRecord.form == 1) { // Dry
58 $("#pmpt_cost").html('Prijs per kg:');
59 $("#pmpt_inventory").html('Voorraad gram:');
60 $("#pmpt_cells").html('Biljoen cellen per gram:');
61 $("#inventory").jqxNumberInput({ decimalDigits: 1, spinButtonsStep: 0.5 });
62 } else {
63 $("#pmpt_cost").html('Prijs per liter:');
64 $("#pmpt_inventory").html('Voorraad ml:');
65 $("#pmpt_cells").html('Biljoen cellen per ml:');
66 $("#inventory").jqxNumberInput({ decimalDigits: 1, spinButtonsStep: 0.5 });
67 }
52 } 68 }
53 69
54 var url = "includes/db_inventory_yeasts.php"; 70 var url = "includes/db_inventory_yeasts.php";
55 // prepare the data 71 // prepare the data
56 var source = { 72 var source = {
152 width: 180, 168 width: 180,
153 height: 23, 169 height: 23,
154 autoDropDownHeight: true 170 autoDropDownHeight: true
155 }); 171 });
156 $("#notes").jqxInput({ theme: theme, width: 800, height: 120 }); 172 $("#notes").jqxInput({ theme: theme, width: 800, height: 120 });
157 $("#best_for").jqxInput({ theme: theme, width: 320, height: 50 }); 173 $("#best_for").jqxInput({ theme: theme, width: 320, height: 75 });
158 $("#inventory").jqxNumberInput( Spin1dec1 ); 174 $("#inventory").jqxNumberInput( Spin1dec1 );
159 $("#production_date").jqxDateTimeInput( Dateopts ); 175 $("#production_date").jqxDateTimeInput( Dateopts );
160 $("#min_temperature").jqxNumberInput( YeastT ); 176 $("#min_temperature").jqxNumberInput( YeastT );
161 $("#max_temperature").jqxNumberInput( YeastT ); 177 $("#max_temperature").jqxNumberInput( YeastT );
162 $("#flocculation").jqxDropDownList({ 178 $("#flocculation").jqxDropDownList({
166 displayMember: 'nl', 182 displayMember: 'nl',
167 width: 180, 183 width: 180,
168 height: 23, 184 height: 23,
169 autoDropDownHeight: true 185 autoDropDownHeight: true
170 }); 186 });
171 $("#attenuation").jqxNumberInput( Perc1dec1 ); 187 $("#attenuation").jqxNumberInput( Perc1dec5 );
172 $("#max_reuse").jqxNumberInput( PosInt ); 188 $("#max_reuse").jqxNumberInput( PosInt );
173 $("#max_reuse").jqxNumberInput({ max: 10 }); 189 $("#max_reuse").jqxNumberInput({ max: 10 });
174 $("#cost").jqxNumberInput( Spin2dec1 ); 190 $("#cost").jqxNumberInput( Spin2dec1 );
175 $("#tht_date").jqxDateTimeInput( Dateopts ); 191 $("#tht_date").jqxDateTimeInput( Dateopts );
176 $("#totval").jqxNumberInput( Spin2dec1 ); 192 $("#totval").jqxNumberInput( Spin2dec1 );
177 $("#totval").jqxNumberInput({ width: 90, readOnly: true, spinButtons: false }); 193 $("#totval").jqxNumberInput({ width: 90, readOnly: true, spinButtons: false });
194 $("#cells").jqxNumberInput( Spin1dec1 );
178 195
179 var dataAdapter = new $.jqx.dataAdapter(source); 196 var dataAdapter = new $.jqx.dataAdapter(source);
180 var editrow = -1; 197 var editrow = -1;
181 // initialize jqxGrid 198 // initialize jqxGrid
182 $("#jqxgrid").jqxGrid({ 199 $("#jqxgrid").jqxGrid({
210 $("#max_reuse").val(10); 227 $("#max_reuse").val(10);
211 $("#inventory").val(0); 228 $("#inventory").val(0);
212 $("#cost").val(0); 229 $("#cost").val(0);
213 $("#production_date").val(''); 230 $("#production_date").val('');
214 $("#tht_date").val(''); 231 $("#tht_date").val('');
232 $("#cells").val(1);
215 $("#popupWindow").jqxWindow('open'); 233 $("#popupWindow").jqxWindow('open');
216 }); 234 });
217 }, 235 },
218 filterable: true, 236 filterable: true,
219 filtermode: 'excel', 237 filtermode: 'excel',
220 columns: [ 238 columns: [
221 { text: 'Laboratorium', datafield: 'laboratory', width: 150 }, 239 { text: 'Laboratorium', datafield: 'laboratory', width: 150 },
222 { text: 'Product ID', datafield: 'product_id', width: 120 }, 240 { text: 'Product ID', datafield: 'product_id', width: 120, menu: false },
223 { text: 'Gist naam', datafield: 'name' }, 241 { text: 'Gist naam', datafield: 'name', menu: false },
224 { text: 'Type', datafield: 'type', align: 'center', cellsalign: 'center', width: 90, 242 { text: 'Type', datafield: 'type', align: 'center', cellsalign: 'center', menu: false, width: 110,
225 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { 243 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
226 return "<div style='margin: 4px;' class='jqx-center-align'>" + YeastTypeData[value].nl + "</div>"; 244 return "<div style='margin: 4px;' class='jqx-center-align'>" + YeastTypeData[value].nl + "</div>";
227 } 245 }
228 }, 246 },
229 { text: 'Vorm', datafield: 'form', align: 'center', cellsalign: 'center', width: 90, 247 { text: 'Vorm', datafield: 'form', align: 'center', cellsalign: 'center', menu: false, width: 110,
230 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) { 248 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
231 return "<div style='margin: 4px;' class='jqx-center-align'>" + YeastFormData[value].nl + "</div>"; 249 return "<div style='margin: 4px;' class='jqx-center-align'>" + YeastFormData[value].nl + "</div>";
232 } 250 }
233 }, 251 },
234 { text: 'Vergistingsgraad', datafield: 'attenuation', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'p0' }, 252 { text: 'SVG', datafield: 'attenuation', width: 80, align: 'right', cellsalign: 'right', menu: false, cellsformat: 'p1' },
235 { text: 'Voor. gr/ml', datafield: 'inventory', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'f1' }, 253 { text: 'Voorraad', datafield: 'inventory', width: 100, align: 'right', menu: false, cellsalign: 'right',
236 { text: 'Prijs kg/l', datafield: 'cost', width: 100, align: 'right', cellsalign: 'right', cellsformat: 'c2' }, 254 cellsrenderer: function (index, datafield, value, defaultvalue, column, rowdata) {
237 { text: 'Wijzig', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', cellsrenderer: function () { 255 if (value == 0)
256 return "<div style='margin: 4px;' class='jqx-right-align'></div>";
257 if ((rowdata.form == 0) && (value > 1))
258 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value,"f0")+" pakken</div>";
259 if (rowdata.form == 0)
260 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value,"f0")+" pak</div>";
261 if (rowdata.form == 1)
262 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value * 1000,"f1")+" gram</div>";
263 return "<div style='margin: 4px;' class='jqx-right-align'>"+dataAdapter.formatNumber(value * 1000,"f1")+" ml</div>";
264 }
265 },
266 { text: 'Wijzig', datafield: 'Edit', columntype: 'button', width: 100, align: 'center', menu: false, cellsrenderer: function () {
238 return "Wijzig"; 267 return "Wijzig";
239 }, buttonclick: function (row) { 268 }, buttonclick: function (row) {
240 // open the popup window when the user clicks a button. 269 // open the popup window when the user clicks a button.
241 editrow = row; 270 editrow = row;
242 $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } }); 271 $("#popupWindow").jqxWindow({ position: { x: 110, y: 30 } });
252 $("#flocculation").val(dataRecord.flocculation); 281 $("#flocculation").val(dataRecord.flocculation);
253 $("#attenuation").val(dataRecord.attenuation); 282 $("#attenuation").val(dataRecord.attenuation);
254 $("#notes").val(dataRecord.notes); 283 $("#notes").val(dataRecord.notes);
255 $("#best_for").val(dataRecord.best_for); 284 $("#best_for").val(dataRecord.best_for);
256 $("#max_reuse").val(dataRecord.max_reuse); 285 $("#max_reuse").val(dataRecord.max_reuse);
257 $("#inventory").val(dataRecord.inventory); 286 if (dataRecord.form == 0)
287 $("#inventory").val(dataRecord.inventory);
288 else
289 $("#inventory").val(dataRecord.inventory * 1000);
258 $("#cost").val(dataRecord.cost); 290 $("#cost").val(dataRecord.cost);
259 $("#production_date").val(dataRecord.production_date); 291 $("#production_date").val(dataRecord.production_date);
260 $("#tht_date").val(dataRecord.tht_date); 292 $("#tht_date").val(dataRecord.tht_date);
261 calcTotal(dataRecord.cost, dataRecord.inventory); 293 $("#cells").val(dataRecord.cells);
294 calcTotal();
262 // show the popup window. 295 // show the popup window.
263 $("#popupWindow").jqxWindow('open'); 296 $("#popupWindow").jqxWindow('open');
264 } 297 }
265 } 298 }
266 ] 299 ]
267 }); 300 });
268 301
302 $('#popupWindow').on('open', function (event) { calcTotal(); });
269 $("#cost").on('change', function (event) { 303 $("#cost").on('change', function (event) {
270 dataRecord.cost = parseFloat(event.args.value); 304 dataRecord.cost = parseFloat(event.args.value);
271 calcTotal(dataRecord.cost, dataRecord.inventory); 305 calcTotal();
272 }); 306 });
273 $("#inventory").on('change', function (event) { 307 $("#inventory").on('change', function (event) {
274 dataRecord.inventory = parseFloat(event.args.value); 308 if (dataRecord.form == 0)
275 calcTotal(dataRecord.cost, dataRecord.inventory); 309 dataRecord.inventory = parseFloat(event.args.value);
310 else
311 dataRecord.inventory = parseFloat(event.args.value) / 1000.0;
312 calcTotal();
313 });
314 $("#form").on('select', function (event) {
315 if (event.args) {
316 dataRecord.form = event.args.index;
317 calcTotal();
318 }
276 }); 319 });
277 320
278 // initialize the popup window and buttons. 321 // initialize the popup window and buttons.
279 $("#popupWindow").jqxWindow({ 322 $("#popupWindow").jqxWindow({
280 width: 1050, 323 width: 1050,
307 $("#Save").click(function () { 350 $("#Save").click(function () {
308 var rowID = -1; 351 var rowID = -1;
309 if (editrow >= 0) { 352 if (editrow >= 0) {
310 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow); 353 rowID = $('#jqxgrid').jqxGrid('getrowid', editrow);
311 } 354 }
355 if (dataRecord.form == 0)
356 var n_inventory = parseFloat($("#inventory").jqxNumberInput('decimal'));
357 else
358 var n_inventory = parseFloat($("#inventory").jqxNumberInput('decimal')) / 1000.0;
312 var row = { 359 var row = {
313 record: rowID, 360 record: rowID,
314 name: $("#name").val(), 361 name: $("#name").val(),
315 type: $("#type").val(), 362 type: $("#type").val(),
316 form: $("#form").val(), 363 form: $("#form").val(),
321 flocculation: $("#flocculation").val(), 368 flocculation: $("#flocculation").val(),
322 attenuation: parseFloat($("#attenuation").jqxNumberInput('decimal')), 369 attenuation: parseFloat($("#attenuation").jqxNumberInput('decimal')),
323 notes: $("#notes").val(), 370 notes: $("#notes").val(),
324 best_for: $("#best_for").val(), 371 best_for: $("#best_for").val(),
325 max_reuse: parseInt($("#max_reuse").jqxNumberInput('decimal')), 372 max_reuse: parseInt($("#max_reuse").jqxNumberInput('decimal')),
326 inventory: parseFloat($("#inventory").jqxNumberInput('decimal')), 373 inventory: n_inventory,
327 cost: parseFloat($("#cost").jqxNumberInput('decimal')), 374 cost: parseFloat($("#cost").jqxNumberInput('decimal')),
328 production_date: $("#production_date").val(), 375 production_date: $("#production_date").val(),
329 tht_date: $("#tht_date").val() 376 tht_date: $("#tht_date").val(),
377 cells: parseFloat($("#cells").jqxNumberInput('decimal'))
330 }; 378 };
331 if (editrow >= 0) { 379 if (editrow >= 0) {
332 $('#jqxgrid').jqxGrid('updaterow', rowID, row); 380 $('#jqxgrid').jqxGrid('updaterow', rowID, row);
333 } else { 381 } else {
334 $('#jqxgrid').jqxGrid('addrow', null, row); 382 $('#jqxgrid').jqxGrid('addrow', null, row);

mercurial