|
1 /***************************************************************************** |
|
2 * Copyright (C) 2019 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of BMS |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * BrewCloud is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 |
|
24 $(document).ready(function () { |
|
25 |
|
26 $('#divide_type').jqxDropDownList({ |
|
27 theme: theme, |
|
28 source: SplitAdapter, |
|
29 valueMember: 'id', |
|
30 displayMember: 'nl', |
|
31 width: 180, |
|
32 height: 23, |
|
33 autoDropDownHeight: true |
|
34 }); |
|
35 |
|
36 // Calculate the volume in the main batch. |
|
37 function calcLeftover() { |
|
38 rows = $('#splitGrid').jqxGrid('getrows'); |
|
39 leftover = Round(available, 1); |
|
40 for (i = 0; i < rows.length; i++) { |
|
41 row = rows[i]; |
|
42 leftover -= row.split_size; |
|
43 //console.log('i:' + i + ' split_size:' + row.split_size); |
|
44 } |
|
45 $('#leftover').val(leftover); |
|
46 //console.log('calcLeftover():' + leftover); |
|
47 } |
|
48 |
|
49 // Calculate available volume but ignore the current row. |
|
50 function calcRoom(r) { |
|
51 var rows, row, i, vol = 0; |
|
52 |
|
53 rows = $('#splitGrid').jqxGrid('getrows'); |
|
54 for (i = 0; i < rows.length; i++) { |
|
55 row = rows[i]; |
|
56 if (i != r) |
|
57 vol += row.split_size; |
|
58 } |
|
59 maxvolume = Round(available - minvolume - vol, 1); |
|
60 console.log('calcRoom(' + r + '):' + vol + ' room:' + maxvolume); |
|
61 } |
|
62 |
|
63 var dataRecord = {}, |
|
64 i, |
|
65 available = 0, |
|
66 leftover = 0, |
|
67 minvolume = 0, |
|
68 maxvolume = 0, |
|
69 url = 'includes/db_product.php', |
|
70 |
|
71 // Prepare the data |
|
72 source = { |
|
73 datatype: 'json', |
|
74 cache: false, |
|
75 datafields: [ |
|
76 // From prod_main |
|
77 { name: 'record', type: 'number' }, |
|
78 { name: 'uuid', type: 'string' }, |
|
79 { name: 'name', type: 'string' }, |
|
80 { name: 'code', type: 'string' }, |
|
81 { name: 'birth', type: 'string' }, |
|
82 { name: 'stage', type: 'int' }, |
|
83 { name: 'notes', type: 'string' }, |
|
84 { name: 'log_brew', type: 'int' }, |
|
85 { name: 'log_fermentation', type: 'int' }, |
|
86 { name: 'inventory_reduced', type: 'int' }, |
|
87 { name: 'locked', type: 'int' }, |
|
88 { name: 'eq_name', type: 'string' }, |
|
89 { name: 'eq_boil_size', type: 'float' }, |
|
90 { name: 'eq_batch_size', type: 'float' }, |
|
91 { name: 'eq_tun_volume', type: 'float' }, |
|
92 { name: 'eq_tun_weight', type: 'float' }, |
|
93 { name: 'eq_tun_specific_heat', type: 'float' }, |
|
94 { name: 'eq_tun_material', type: 'int' }, |
|
95 { name: 'eq_tun_height', type: 'float' }, |
|
96 { name: 'eq_top_up_water', type: 'float' }, |
|
97 { name: 'eq_trub_chiller_loss', type: 'float' }, |
|
98 { name: 'eq_evap_rate', type: 'float' }, |
|
99 { name: 'eq_boil_time', type: 'float' }, |
|
100 { name: 'eq_calc_boil_volume', type: 'int' }, |
|
101 { name: 'eq_top_up_kettle', type: 'float' }, |
|
102 { name: 'eq_hop_utilization', type: 'float' }, |
|
103 { name: 'eq_notes', type: 'string' }, |
|
104 { name: 'eq_lauter_volume', type: 'float' }, |
|
105 { name: 'eq_lauter_height', type: 'float' }, |
|
106 { name: 'eq_lauter_deadspace', type: 'float' }, |
|
107 { name: 'eq_kettle_volume', type: 'float' }, |
|
108 { name: 'eq_kettle_height', type: 'float' }, |
|
109 { name: 'eq_mash_volume', type: 'float' }, |
|
110 { name: 'eq_mash_max', type: 'float' }, |
|
111 { name: 'eq_efficiency', type: 'float' }, |
|
112 { name: 'brew_date_start', type: 'string' }, |
|
113 { name: 'brew_mash_ph', type: 'float' }, |
|
114 { name: 'brew_mash_sg', type: 'float' }, |
|
115 { name: 'brew_mash_efficiency', type: 'float' }, |
|
116 { name: 'brew_sparge_est', type: 'float' }, |
|
117 { name: 'brew_sparge_ph', type: 'float' }, |
|
118 { name: 'brew_preboil_volume', type: 'float' }, |
|
119 { name: 'brew_preboil_sg', type: 'float' }, |
|
120 { name: 'brew_preboil_ph', type: 'float' }, |
|
121 { name: 'brew_preboil_efficiency', type: 'float' }, |
|
122 { name: 'brew_aboil_volume', type: 'float' }, |
|
123 { name: 'brew_aboil_sg', type: 'float' }, |
|
124 { name: 'brew_aboil_ph', type: 'float' }, |
|
125 { name: 'brew_aboil_efficiency', type: 'float' }, |
|
126 { name: 'brew_cooling_method', type: 'int' }, |
|
127 { name: 'brew_cooling_time', type: 'float' }, |
|
128 { name: 'brew_cooling_to', type: 'float' }, |
|
129 { name: 'brew_whirlpool9', type: 'float' }, |
|
130 { name: 'brew_whirlpool7', type: 'float' }, |
|
131 { name: 'brew_whirlpool6', type: 'float' }, |
|
132 { name: 'brew_whirlpool2', type: 'float' }, |
|
133 { name: 'brew_fermenter_volume', type: 'float' }, |
|
134 { name: 'brew_fermenter_extrawater', type: 'float' }, |
|
135 { name: 'brew_fermenter_tcloss', type: 'float' }, |
|
136 { name: 'brew_aeration_time', type: 'float' }, |
|
137 { name: 'brew_aeration_speed', type: 'float' }, |
|
138 { name: 'brew_aeration_type', type: 'int' }, |
|
139 { name: 'brew_fermenter_sg', type: 'float' }, |
|
140 { name: 'brew_fermenter_ibu', type: 'float' }, |
|
141 { name: 'brew_fermenter_color', type: 'float' }, |
|
142 { name: 'brew_date_end', type: 'string' }, |
|
143 { name: 'og', type: 'float' }, |
|
144 { name: 'fg', type: 'float' }, |
|
145 { name: 'primary_start_temp', type: 'float' }, |
|
146 { name: 'primary_max_temp', type: 'float' }, |
|
147 { name: 'primary_end_temp', type: 'float' }, |
|
148 { name: 'primary_end_sg', type: 'float' }, |
|
149 { name: 'primary_end_date', type: 'string' }, |
|
150 { name: 'secondary_temp', type: 'float' }, |
|
151 { name: 'secondary_end_sg', type: 'float' }, |
|
152 { name: 'secondary_end_date', type: 'string' }, |
|
153 { name: 'tertiary_temp', type: 'float' }, |
|
154 { name: 'package_date', type: 'string' }, |
|
155 { name: 'package_volume', type: 'float' }, |
|
156 { name: 'package_infuse_amount', type: 'float' }, |
|
157 { name: 'package_infuse_abv', type: 'float' }, |
|
158 { name: 'package_infuse_notes', type: 'string' }, |
|
159 { name: 'package_abv', type: 'float' }, |
|
160 { name: 'package_ph', type: 'float' }, |
|
161 { name: 'bottle_amount', type: 'float' }, |
|
162 { name: 'bottle_carbonation', type: 'float' }, |
|
163 { name: 'bottle_priming_water', type: 'float' }, |
|
164 { name: 'bottle_priming_amount', type: 'float' }, |
|
165 { name: 'bottle_carbonation_temp', type: 'float' }, |
|
166 { name: 'keg_amount', type: 'float' }, |
|
167 { name: 'keg_carbonation', type: 'float' }, |
|
168 { name: 'keg_priming_water', type: 'float' }, |
|
169 { name: 'keg_priming_amount', type: 'float' }, |
|
170 { name: 'keg_carbonation_temp', type: 'float' }, |
|
171 { name: 'keg_forced_carb', type: 'int' }, |
|
172 { name: 'keg_pressure', type: 'float' }, |
|
173 { name: 'taste_notes', type: 'string' }, |
|
174 { name: 'taste_rate', type: 'float' }, |
|
175 { name: 'taste_date', type: 'string' }, |
|
176 { name: 'taste_color', type: 'string' }, |
|
177 { name: 'taste_transparency', type: 'string' }, |
|
178 { name: 'taste_head', type: 'string' }, |
|
179 { name: 'taste_aroma', type: 'string' }, |
|
180 { name: 'taste_taste', type: 'string' }, |
|
181 { name: 'taste_mouthfeel', type: 'string' }, |
|
182 { name: 'taste_aftertaste', type: 'string' }, |
|
183 { name: 'st_name', type: 'string' }, |
|
184 { name: 'st_letter', type: 'string' }, |
|
185 { name: 'st_guide', type: 'string' }, |
|
186 { name: 'st_category', type: 'string' }, |
|
187 { name: 'st_category_number', type: 'float' }, |
|
188 { name: 'st_type', type: 'int' }, |
|
189 { name: 'st_og_min', type: 'float' }, |
|
190 { name: 'st_og_max', type: 'float' }, |
|
191 { name: 'st_fg_min', type: 'float' }, |
|
192 { name: 'st_fg_max', type: 'float' }, |
|
193 { name: 'st_ibu_min', type: 'float' }, |
|
194 { name: 'st_ibu_max', type: 'float' }, |
|
195 { name: 'st_color_min', type: 'float' }, |
|
196 { name: 'st_color_max', type: 'float' }, |
|
197 { name: 'st_carb_min', type: 'float' }, |
|
198 { name: 'st_carb_max', type: 'float' }, |
|
199 { name: 'st_abv_min', type: 'float' }, |
|
200 { name: 'st_abv_max', type: 'float' }, |
|
201 { name: 'type', type: 'int' }, |
|
202 { name: 'batch_size', type: 'float' }, |
|
203 { name: 'boil_size', type: 'float' }, |
|
204 { name: 'boil_time', type: 'float' }, |
|
205 { name: 'efficiency', type: 'float' }, |
|
206 { name: 'est_og', type: 'float' }, |
|
207 { name: 'est_fg', type: 'float' }, |
|
208 { name: 'est_abv', type: 'float' }, |
|
209 { name: 'est_color', type: 'float' }, |
|
210 { name: 'color_method', type: 'int' }, |
|
211 { name: 'est_ibu', type: 'float' }, |
|
212 { name: 'ibu_method', type: 'int' }, |
|
213 { name: 'est_carb', type: 'float' }, |
|
214 { name: 'sparge_temp', type: 'float' }, |
|
215 { name: 'sparge_ph', type: 'float' }, |
|
216 { name: 'sparge_volume', type: 'float' }, |
|
217 { name: 'sparge_source', type: 'int' }, |
|
218 { name: 'sparge_acid_type', type: 'int' }, |
|
219 { name: 'sparge_acid_perc', type: 'float' }, |
|
220 { name: 'sparge_acid_amount', type: 'float' }, |
|
221 { name: 'mash_ph', type: 'float' }, |
|
222 { name: 'mash_name', type: 'string' }, |
|
223 { name: 'calc_acid', type: 'int' }, |
|
224 { name: 'w1_name', type: 'string' }, |
|
225 { name: 'w1_amount', type: 'float' }, |
|
226 { name: 'w1_calcium', type: 'float' }, |
|
227 { name: 'w1_sulfate', type: 'float' }, |
|
228 { name: 'w1_chloride', type: 'float' }, |
|
229 { name: 'w1_sodium', type: 'float' }, |
|
230 { name: 'w1_magnesium', type: 'float' }, |
|
231 { name: 'w1_total_alkalinity', type: 'float' }, |
|
232 { name: 'w1_ph', type: 'float' }, |
|
233 { name: 'w1_cost', type: 'float' }, |
|
234 { name: 'w2_name', type: 'string' }, |
|
235 { name: 'w2_amount', type: 'float' }, |
|
236 { name: 'w2_calcium', type: 'float' }, |
|
237 { name: 'w2_sulfate', type: 'float' }, |
|
238 { name: 'w2_chloride', type: 'float' }, |
|
239 { name: 'w2_sodium', type: 'float' }, |
|
240 { name: 'w2_magnesium', type: 'float' }, |
|
241 { name: 'w2_total_alkalinity', type: 'float' }, |
|
242 { name: 'w2_ph', type: 'float' }, |
|
243 { name: 'w2_cost', type: 'float' }, |
|
244 { name: 'wg_amount', type: 'float' }, |
|
245 { name: 'wg_calcium', type: 'float' }, |
|
246 { name: 'wg_sulfate', type: 'float' }, |
|
247 { name: 'wg_chloride', type: 'float' }, |
|
248 { name: 'wg_sodium', type: 'float' }, |
|
249 { name: 'wg_magnesium', type: 'float' }, |
|
250 { name: 'wg_total_alkalinity', type: 'float' }, |
|
251 { name: 'wg_ph', type: 'float' }, |
|
252 { name: 'wb_calcium', type: 'float' }, |
|
253 { name: 'wb_sulfate', type: 'float' }, |
|
254 { name: 'wb_chloride', type: 'float' }, |
|
255 { name: 'wb_sodium', type: 'float' }, |
|
256 { name: 'wb_magnesium', type: 'float' }, |
|
257 { name: 'wb_total_alkalinity', type: 'float' }, |
|
258 { name: 'wb_ph', type: 'float' }, |
|
259 { name: 'wa_acid_name', type: 'int' }, |
|
260 { name: 'wa_acid_perc', type: 'int' }, |
|
261 { name: 'wa_base_name', type: 'int' }, |
|
262 { name: 'starter_enable', type: 'int' }, |
|
263 { name: 'starter_type', type: 'int' }, |
|
264 { name: 'starter_sg', type: 'float' }, |
|
265 { name: 'starter_viability', type: 'int' }, |
|
266 { name: 'starter_viability', type: 'int' }, |
|
267 { name: 'prop1_type', type: 'int' }, |
|
268 { name: 'prop1_volume', type: 'float' }, |
|
269 { name: 'prop2_type', type: 'int' }, |
|
270 { name: 'prop2_volume', type: 'float' }, |
|
271 { name: 'prop3_type', type: 'int' }, |
|
272 { name: 'prop3_volume', type: 'float' }, |
|
273 { name: 'prop4_type', type: 'int' }, |
|
274 { name: 'prop4_volume', type: 'float' }, |
|
275 { name: 'divide_type', type: 'int' }, |
|
276 { name: 'divide_size', type: 'float' }, |
|
277 { name: 'divide_parts', type: 'int' }, |
|
278 { name: 'fermentables', type: 'string' }, |
|
279 { name: 'hops', type: 'string' }, |
|
280 { name: 'miscs', type: 'string' }, |
|
281 { name: 'yeasts', type: 'string' }, |
|
282 { name: 'mashs', type: 'string' } |
|
283 ], |
|
284 id: 'record', |
|
285 url: url + '?record=' + my_record |
|
286 }, |
|
287 |
|
288 // Load data and select one record. |
|
289 dataAdapter = new $.jqx.dataAdapter(source, { |
|
290 loadComplete: function() { |
|
291 var records = dataAdapter.records; |
|
292 dataRecord = records[0]; |
|
293 // Hidden record uuid |
|
294 $('#name').val(dataRecord.name); |
|
295 $('#code').val(dataRecord.code); |
|
296 $('#stage').val(StageData[dataRecord.stage].nl); |
|
297 // Disable stages that are already done. |
|
298 for (i = 0; i < SplitData.length; i++) { |
|
299 console.log('i:' + i + ' ok:' + SplitData[i].ok + ' stage:' + dataRecord.stage); |
|
300 if (SplitData[i].ok < dataRecord.stage) |
|
301 $("#divide_type").jqxDropDownList('disableAt', i); |
|
302 } |
|
303 }, |
|
304 loadError: function(jqXHR, status, error) { |
|
305 }, |
|
306 beforeLoadComplete: function(records) { |
|
307 $('#jqxLoader').jqxLoader('open'); |
|
308 } |
|
309 }); |
|
310 |
|
311 durl = 'includes/db_divides.php', |
|
312 |
|
313 // Prepare the data |
|
314 dividerec = { |
|
315 datatype: 'json', |
|
316 cache: false, |
|
317 datafields: [ |
|
318 // From prod_main |
|
319 { name: 'record', type: 'number' }, |
|
320 { name: 'divide_from', type: 'string' }, |
|
321 { name: 'divide_type', type: 'int' }, |
|
322 { name: 'divide_size', type: 'float' }, |
|
323 { name: 'name', type: 'string' }, |
|
324 { name: 'code', type: 'string' } |
|
325 ], |
|
326 id: 'record', |
|
327 url: durl + '?record=' + my_record |
|
328 }; |
|
329 |
|
330 var editSplit = function(data) { |
|
331 var splitSource = { |
|
332 datatype: 'local', |
|
333 cache: false, |
|
334 async: false, |
|
335 datafields: [ |
|
336 { name: 'split_code', type: 'string' }, |
|
337 { name: 'split_name', type: 'string' }, |
|
338 { name: 'split_size', type: 'float' } |
|
339 ], |
|
340 addrow: function(rowid, rowdata, position, commit) { |
|
341 console.log('split addrow ' + rowid); |
|
342 commit(true); |
|
343 }, |
|
344 deleterow: function(rowid, commit) { |
|
345 console.log('split deleterow ' + rowid); |
|
346 commit(true); |
|
347 } |
|
348 }, |
|
349 splitAdapter = new $.jqx.dataAdapter(splitSource, {}); |
|
350 $('#splitGrid').jqxGrid({ |
|
351 width: 1240, |
|
352 height: 375, |
|
353 source: splitAdapter, |
|
354 editable: true, |
|
355 enabletooltips: true, |
|
356 selectionmode: 'singlecell', |
|
357 editmode: 'click', |
|
358 theme: theme, |
|
359 showtoolbar: true, |
|
360 rendertoolbar: function(toolbar) { |
|
361 var container = $('<div style="overflow: hidden; position: relative; margin: 5px;"></div>'); |
|
362 toolbar.append(container); |
|
363 container.append('<input style="float: left; margin-left: 165px;" id="saddrowbutton" type="button" value="Nieuwe splitsing" />'); |
|
364 container.append('<input style="float: left; margin-left: 565px;" id="sdeleterowbutton" type="button" value="Verwijder splitsing" />'); |
|
365 $('#saddrowbutton').jqxButton({ template: 'primary', theme: theme, disabled: true, height: 27, width: 150 }); |
|
366 $('#saddrowbutton').on('click', function() { |
|
367 var row = {}, rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount; |
|
368 row['split_code'] = dataRecord.code + '-' + (rowscount + 1); |
|
369 row['split_name'] = dataRecord.name + ' ' + (rowscount + 1); |
|
370 row['split_size'] = 0; |
|
371 $('#splitGrid').jqxGrid('addrow', null, row); |
|
372 $('#sdeleterowbutton').jqxButton({ disabled: false }); // Enable delete |
|
373 $('#divide_type').jqxDropDownList({ disabled: true }); // Disable dropdown |
|
374 }); |
|
375 // Delete last added split |
|
376 $('#sdeleterowbutton').jqxButton({ template: 'danger', theme: theme, disabled: true, height: 27, width: 150 }); |
|
377 $('#sdeleterowbutton').on('click', function() { |
|
378 var rowscount, id, row; |
|
379 rowscount = $('#splitGrid').jqxGrid('getdatainformation').rowscount; |
|
380 id = $('#splitGrid').jqxGrid('getrowid', rowscount - 1); |
|
381 // First, give back this batch volume. |
|
382 row = $('#splitGrid').jqxGrid('getrowdata', id); |
|
383 leftover += row.split_size; |
|
384 if (leftover > available) |
|
385 leftover = available; |
|
386 $('#leftover').val(leftover); |
|
387 // Then delete the row. |
|
388 $('#splitGrid').jqxGrid('deleterow', id); |
|
389 if (rowscount == 1) { |
|
390 $('#sdeleterowbutton').jqxButton({ disabled: true }); // No more rows |
|
391 $('#divide_type').jqxDropDownList({ disabled: false }); |
|
392 } |
|
393 }); |
|
394 }, |
|
395 columns: [ |
|
396 { text: 'Splits code', datafield: 'split_code', width: 120, editable: false }, |
|
397 { text: 'Splits naam', datafield: 'split_name' }, |
|
398 { text: 'Splits volume', datafield: 'split_size', width: 120, align: 'right', cellsalign: 'right', cellsformat: 'f1', columntype: 'numberinput', |
|
399 validation: function (cell, value) { |
|
400 if (value < 0 || value > maxvolume) { |
|
401 return { result: false, message: 'Volume should be between 0 and ' + maxvolume + ' liter' }; |
|
402 } |
|
403 return true; |
|
404 }, |
|
405 createeditor: function (row, cellvalue, editor) { |
|
406 editor.jqxNumberInput({ decimalDigits: 1, digits: 3 }); |
|
407 } |
|
408 } |
|
409 ] |
|
410 }); |
|
411 $('#splitGrid').on('cellbeginedit', function (event) { |
|
412 var args = event.args; |
|
413 calcRoom(args.rowindex); // Make maxvolume available. |
|
414 }); |
|
415 $('#splitGrid').on('cellvaluechanged', function (event) { |
|
416 var args = event.args; |
|
417 //console.log("cellvaluechanged, Column: " + args.datafield + ", Row: " + (1 + args.rowindex) + ", Value: " + args.value); |
|
418 calcLeftover(); |
|
419 }); |
|
420 }; |
|
421 |
|
422 dataAdapter.dataBind(); |
|
423 editSplit(dataRecord); |
|
424 |
|
425 // initialize the input fields. |
|
426 $('#name').jqxTooltip({ content: 'De naam voor dit product.' }); |
|
427 $('#name').jqxInput({ theme: theme, width: 640, height: 23 }); |
|
428 $('#code').jqxTooltip({ content: 'Product code nummer.' }); |
|
429 $('#code').jqxInput({ theme: theme, width: 100, height: 23 }); |
|
430 $('#stage').jqxTooltip({ content: 'De productie fase van dit product.' }); |
|
431 $('#stage').jqxInput({ theme: theme, width: 100, height: 23 }); |
|
432 $('#available').jqxNumberInput(Show1dec); |
|
433 $('#leftover').jqxNumberInput(Show1dec); |
|
434 $('#divide_type').val(0); |
|
435 $('#divide_type').on('change', function(event) { |
|
436 var index = event.args.index; |
|
437 console.log('divide_type:' + index); |
|
438 dataRecord.divide_type = index; |
|
439 switch (index) { |
|
440 case 0: |
|
441 available = 0; |
|
442 break; |
|
443 case 1: |
|
444 available = dataRecord.boil_size; |
|
445 break; |
|
446 case 2: |
|
447 available = dataRecord.batch_size; |
|
448 break; |
|
449 case 3: |
|
450 available = dataRecord.brew_fermenter_volume; |
|
451 break; |
|
452 case 4: |
|
453 case 5: |
|
454 available = Round(dataRecord.brew_fermenter_volume * 0.92, 1); // Estimate volume without yeast trub |
|
455 break; |
|
456 case 6: |
|
457 available = dataRecord.package_volume; |
|
458 break; |
|
459 } |
|
460 leftover = available; |
|
461 minvolume = Round(0.1 * available, 1); |
|
462 $('#available').val(available); |
|
463 $('#leftover').val(leftover); |
|
464 if (index != 0) { |
|
465 $('#saddrowbutton').jqxButton({ disabled: false }); |
|
466 } else { |
|
467 $('#saddrowbutton').jqxButton({ disabled: true }); |
|
468 } |
|
469 }); |
|
470 |
|
471 $('#Cancel').jqxButton({ template: 'primary', width: '80px', theme: theme }); |
|
472 $('#Cancel').bind('click', function() { |
|
473 window.location.href = my_return; |
|
474 }); |
|
475 |
|
476 $('#Save').jqxButton({ template: 'success', width: '80px', theme: theme }); |
|
477 $('#Save').bind('click', function() { |
|
478 var rows, row, i, div, data; |
|
479 if (leftover != available) { |
|
480 console.log('Save and there are splits'); |
|
481 |
|
482 // Record 0, the master data |
|
483 div = {}; |
|
484 div.divide_from = dataRecord.uuid; |
|
485 div.divide_type = dataRecord.divide_type; |
|
486 div.divide_size = leftover; |
|
487 div.divide_part = 0; |
|
488 div.name = dataRecord.name; |
|
489 div.code = dataRecord.code; |
|
490 data = 'insert=true&' + $.param(div); |
|
491 $.ajax({ |
|
492 dataType: 'json', |
|
493 url: durl, |
|
494 cache: false, |
|
495 data: data, |
|
496 type: "POST", |
|
497 success: function (data, status, xhr) { |
|
498 console.log('insert divides: 0'); |
|
499 }, |
|
500 error: function(jqXHR, textStatus, errorThrown) { |
|
501 console.log('insert divides: ' + textStatus); |
|
502 } |
|
503 }); |
|
504 |
|
505 rows = $('#splitGrid').jqxGrid('getrows'); |
|
506 for (i = 0; i < rows.length; i++) { |
|
507 row = rows[i]; |
|
508 console.log('split ' + i); |
|
509 div = {}; |
|
510 div.divide_from = dataRecord.uuid; |
|
511 div.divide_type = dataRecord.divide_type; |
|
512 div.divide_size = row.split_size; |
|
513 div.divide_part = i + 1; |
|
514 div.name = row.split_name; |
|
515 div.code = row.split_code; |
|
516 data = 'insert=true&' + $.param(div); |
|
517 $.ajax({ |
|
518 dataType: 'json', |
|
519 url: durl, |
|
520 cache: false, |
|
521 data: data, |
|
522 type: "POST", |
|
523 success: function (data, status, xhr) { |
|
524 console.log('insert divides: ' + i); |
|
525 }, |
|
526 error: function(jqXHR, textStatus, errorThrown) { |
|
527 console.log('insert divides: ' + textStatus); |
|
528 } |
|
529 }); |
|
530 } |
|
531 |
|
532 div = {}; |
|
533 div.record = dataRecord.record; |
|
534 div.divide_type = dataRecord.divide_type; |
|
535 div.divide_size = leftover; |
|
536 div.divide_parts = i; |
|
537 data = 'splitit=true&' + $.param(div); |
|
538 $.ajax({ |
|
539 dataType: 'json', |
|
540 url: url, |
|
541 cache: false, |
|
542 data: data, |
|
543 type: "POST", |
|
544 success: function (data, status, xhr) { |
|
545 console.log('updated products'); |
|
546 }, |
|
547 error: function(jqXHR, textStatus, errorThrown) { |
|
548 console.log('updated products: ' + textStatus); |
|
549 } |
|
550 }); |
|
551 } |
|
552 window.location.href = my_return; |
|
553 }); |
|
554 |
|
555 }); |