jqgrid_utils 1.30.3 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,6 +27,14 @@ A module for Jqgrid_utils
27
27
 
28
28
 
29
29
  * [Jqgrid_utils](#module_Jqgrid_utils)
30
+ * [module.exports#_grid_ratio_on()](#exp_module_Jqgrid_utils--module.exports+_grid_ratio_on) ⏏
31
+ * [module.exports#grid_ratio_on(grid, fraction_col, denominator_col, ratio_col)](#exp_module_Jqgrid_utils--module.exports+grid_ratio_on) ⏏
32
+ * [module.exports#_grid_sum_on()](#exp_module_Jqgrid_utils--module.exports+_grid_sum_on) ⏏
33
+ * [module.exports#grid_sum_on(grid, fields)](#exp_module_Jqgrid_utils--module.exports+grid_sum_on) ⏏
34
+ * [module.exports#_grid_avg_on()](#exp_module_Jqgrid_utils--module.exports+_grid_avg_on) ⏏
35
+ * [module.exports#grid_avg_on(grid, fields)](#exp_module_Jqgrid_utils--module.exports+grid_avg_on) ⏏
36
+ * [module.exports#_grid_percent_on()](#exp_module_Jqgrid_utils--module.exports+_grid_percent_on) ⏏
37
+ * [module.exports#grid_percent_on(grid, obj)](#exp_module_Jqgrid_utils--module.exports+grid_percent_on) ⏏
30
38
  * [module.exports#update_row_to_api(_self, api, _ids, row)](#exp_module_Jqgrid_utils--module.exports+update_row_to_api) ⏏
31
39
  * [module.exports#delete_row_to_api(_self, api, rowid, _ids, data)](#exp_module_Jqgrid_utils--module.exports+delete_row_to_api) ⏏
32
40
  * [module.exports#append_seperator_link_column(col_model, url, field_value, base, attr, keys)](#exp_module_Jqgrid_utils--module.exports+append_seperator_link_column) ⏏
@@ -71,6 +79,121 @@ A module for Jqgrid_utils
71
79
  * [module.exports#set_filter(grid, data, fx, append_to)](#exp_module_Jqgrid_utils--module.exports+set_filter) ⏏
72
80
  * [module.exports#_filter()](#exp_module_Jqgrid_utils--module.exports+_filter) ⏏
73
81
 
82
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_ratio_on"></a>
83
+
84
+ ### module.exports#\_grid\_ratio\_on() ⏏
85
+ Syncron Alias grid_ratio_on
86
+
87
+ **Kind**: Exported function
88
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_ratio_on"></a>
89
+
90
+ ### module.exports#grid\_ratio\_on(grid, fraction_col, denominator_col, ratio_col) ⏏
91
+ Get the ratio the columns values together
92
+
93
+ **Kind**: Exported function
94
+
95
+ | Param | Type | Description |
96
+ | --- | --- | --- |
97
+ | grid | <code>object</code> | Grid Object (required) |
98
+ | fraction_col | <code>string</code> | Column/Field Name for value 1 |
99
+ | denominator_col | <code>string</code> | Column/Field Name for value 2 |
100
+ | ratio_col | <code>string</code> | Column/Field Name to the set the target ratio |
101
+
102
+ **Example**
103
+ ```js
104
+ var jqu = new Jqgrid_utils({page:page});
105
+ gridComplete: function()
106
+ {
107
+ jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
108
+ },
109
+ ```
110
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_sum_on"></a>
111
+
112
+ ### module.exports#\_grid\_sum\_on() ⏏
113
+ Syncron Alias grid_sum_on
114
+
115
+ **Kind**: Exported function
116
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_sum_on"></a>
117
+
118
+ ### module.exports#grid\_sum\_on(grid, fields) ⏏
119
+ Sum the columns values together
120
+
121
+ **Kind**: Exported function
122
+
123
+ | Param | Type | Description |
124
+ | --- | --- | --- |
125
+ | grid | <code>object</code> | Grid Object (required) |
126
+ | fields | <code>string</code> | Column/Field Name to sum |
127
+
128
+ **Example**
129
+ ```js
130
+ var jqu = new Jqgrid_utils({page:page});
131
+ gridComplete: function () {
132
+ jqu._jqu._grid_sum_on(this, [
133
+ "qty_icollect",
134
+ "qty_ordered",
135
+ "need_for_qty_ordered",
136
+ "wait_icollect",
137
+ ]);
138
+ },
139
+ ```
140
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_avg_on"></a>
141
+
142
+ ### module.exports#\_grid\_avg\_on() ⏏
143
+ Syncron Alias grid_avg_on
144
+
145
+ **Kind**: Exported function
146
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_avg_on"></a>
147
+
148
+ ### module.exports#grid\_avg\_on(grid, fields) ⏏
149
+ Average the column values together
150
+
151
+ **Kind**: Exported function
152
+
153
+ | Param | Type | Description |
154
+ | --- | --- | --- |
155
+ | grid | <code>object</code> | Grid Object (required) |
156
+ | fields | <code>array</code> | Column/Field Names to where the average of each column should be calculated |
157
+
158
+ **Example**
159
+ ```js
160
+ var jqu = new Jqgrid_utils({page:page});
161
+
162
+ gridComplete: function()
163
+ {
164
+ jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
165
+ },
166
+ ```
167
+ <a name="exp_module_Jqgrid_utils--module.exports+_grid_percent_on"></a>
168
+
169
+ ### module.exports#\_grid\_percent\_on() ⏏
170
+ Syncron Alias grid_percent_on
171
+
172
+ **Kind**: Exported function
173
+ <a name="exp_module_Jqgrid_utils--module.exports+grid_percent_on"></a>
174
+
175
+ ### module.exports#grid\_percent\_on(grid, obj) ⏏
176
+ Percent the columns values together
177
+
178
+ **Kind**: Exported function
179
+
180
+ | Param | Type | Description |
181
+ | --- | --- | --- |
182
+ | grid | <code>object</code> | Grid Object (required) |
183
+ | obj | <code>string</code> | Column/Field Name to sum |
184
+
185
+ **Example**
186
+ ```js
187
+ var jqu = new Jqgrid_utils({page:page});
188
+ gridComplete: function () {
189
+ jqu._jqu._grid_sum_on(this, [
190
+ "qty_icollect",
191
+ "qty_ordered",
192
+ "need_for_qty_ordered",
193
+ "wait_icollect",
194
+ ]);
195
+ },
196
+ ```
74
197
  <a name="exp_module_Jqgrid_utils--module.exports+update_row_to_api"></a>
75
198
 
76
199
  ### module.exports#update\_row\_to\_api(_self, api, _ids, row) ⏏
@@ -16,6 +16,330 @@ module.exports = class Vanilla_website_utils {
16
16
  }
17
17
  }
18
18
 
19
+ /**
20
+ * Syncron Alias grid_sum_on
21
+ @alias module:Jqgrid_utils
22
+ */
23
+ async _grid_substract_on(
24
+ grid,
25
+ minuend = [],
26
+ subtrahend = [],
27
+ difference,
28
+ no_negative = false,
29
+ ) {
30
+ return await this.grid_substract_on(
31
+ grid,
32
+ minuend,
33
+ subtrahend,
34
+ difference,
35
+ no_negative,
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Sum the columns values together
41
+ @alias module:Jqgrid_utils
42
+ @param {object} - Grid Object (required)
43
+ @param {array} - string array list of field_names used as minuend(number from which the other number is subtracted)
44
+ @param {array} - string array list of field_names used as subtrahend(number which is to be subtracted from the minuend)
45
+ @param {string} - string field name for the difference(number which is to be subtracted from the minuend)
46
+ @param {bolen} - true or 1 to not show negative numbers
47
+
48
+ @example
49
+ var jqu = new Jqgrid_utils({page:page});
50
+ gridComplete: function () {
51
+ jqu._jqu._grid_sum_on(this, [
52
+ "qty_icollect",
53
+ "qty_ordered",
54
+ "need_for_qty_ordered",
55
+ "wait_icollect",
56
+ ]);
57
+ },
58
+ */
59
+ async grid_substract_on(
60
+ grid,
61
+ minuend = [],
62
+ subtrahend = [],
63
+ difference,
64
+ no_negative = false,
65
+ ) {
66
+ let $self = jQuery(grid);
67
+ let rows = $self.jqGrid("getGridParam", "data");
68
+ let footer = { invdate: "Total" };
69
+ let _minuend = 0.0;
70
+ let _subtrahend = 0.0;
71
+ for (let i in minuend) {
72
+ let sum = 0;
73
+ for (let r in rows) {
74
+ if (rows[r].hasOwnProperty(minuend[i])) {
75
+ let val = rows[r][minuend[i]];
76
+ if (typeof val === "string") {
77
+ if (is_digit(val)) {
78
+ val = parseFloat(val);
79
+ }
80
+ }
81
+ sum += val;
82
+ }
83
+ }
84
+ if (sum != Math.floor(sum)) {
85
+ sum = sum.toFixed(2);
86
+ }
87
+ footer[minuend[i]] = sum;
88
+ _minuend = sum;
89
+ }
90
+
91
+ for (let i in subtrahend) {
92
+ let sum = 0;
93
+ for (let r in rows) {
94
+ if (rows[r].hasOwnProperty(subtrahend[i])) {
95
+ let val = rows[r][subtrahend[i]];
96
+ if (typeof val === "string") {
97
+ if (is_digit(val)) {
98
+ val = parseFloat(val);
99
+ }
100
+ }
101
+ sum += val;
102
+ }
103
+ }
104
+ if (sum != Math.floor(sum)) {
105
+ sum = sum.toFixed(2);
106
+ }
107
+ footer[subtrahend[i]] = sum;
108
+ _subtrahend = sum;
109
+ }
110
+
111
+ let diff = _minuend - _subtrahend;
112
+ if (no_negative) {
113
+ if (diff < 0) {
114
+ diff = 0;
115
+ }
116
+ }
117
+ footer[difference] = diff;
118
+
119
+ $self.jqGrid("footerData", "set", footer);
120
+
121
+ return footer;
122
+ }
123
+
124
+ /**
125
+ * Syncron Alias grid_ratio_on
126
+ @alias module:Jqgrid_utils
127
+ */
128
+ _grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
129
+ return this.grid_ratio_on(grid, fraction_col, denominator_col, ratio_col);
130
+ }
131
+
132
+ /**
133
+ * Get the ratio the columns values together
134
+ @alias module:Jqgrid_utils
135
+ @param {object} - Grid Object (required)
136
+ @param {string} - Column/Field Name for value 1
137
+ @param {string} - Column/Field Name for value 2
138
+ @param {string} - Column/Field Name to the set the target ratio
139
+ @example
140
+ var jqu = new Jqgrid_utils({page:page});
141
+ gridComplete: function()
142
+ {
143
+ jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
144
+ },
145
+
146
+ */
147
+ async grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
148
+ var allrows = jQuery("#grid").jqGrid("getGridParam", "data");
149
+ let $self = jQuery(grid);
150
+ let rows = $self.jqGrid("getGridParam", "data");
151
+ let footer = {
152
+ invdate: "Total",
153
+ };
154
+ let sum = 0;
155
+ fraction_sum = 0;
156
+ denominator_sum = 0;
157
+ ratio_sum = 0;
158
+ for (let r in rows) {
159
+ if (rows[r].hasOwnProperty(fraction_col)) {
160
+ fraction_sum += rows[r][fraction_col];
161
+ }
162
+ if (rows[r].hasOwnProperty(denominator_col)) {
163
+ denominator_sum += rows[r][denominator_col];
164
+ }
165
+ }
166
+ footer["qc_eta_ratio"] = (fraction_sum / denominator_sum).toFixed(2);
167
+ $self.jqGrid("footerData", "set", footer);
168
+ return footer;
169
+ }
170
+
171
+ /**
172
+ * Syncron Alias grid_sum_on
173
+ @alias module:Jqgrid_utils
174
+ */
175
+ async _grid_sum_on(grid, fields = []) {
176
+ return await this.grid_sum_on(grid, fields);
177
+ }
178
+
179
+ /**
180
+ * Sum the columns values together
181
+ @alias module:Jqgrid_utils
182
+ @param {object} - Grid Object (required)
183
+ @param {string} - Column/Field Name to sum
184
+ @example
185
+ var jqu = new Jqgrid_utils({page:page});
186
+ gridComplete: function () {
187
+ jqu._jqu._grid_sum_on(this, [
188
+ "qty_icollect",
189
+ "qty_ordered",
190
+ "need_for_qty_ordered",
191
+ "wait_icollect",
192
+ ]);
193
+ },
194
+ */
195
+ async grid_sum_on(grid, fields = []) {
196
+ let $self = jQuery(grid);
197
+ let rows = $self.jqGrid("getGridParam", "data");
198
+ let footer = {
199
+ invdate: "Total",
200
+ };
201
+ for (let i in fields) {
202
+ let sum = 0;
203
+ for (let r in rows) {
204
+ if (rows[r].hasOwnProperty(fields[i])) {
205
+ let val = rows[r][fields[i]];
206
+ if (typeof val === "string") {
207
+ if (is_digit(val)) {
208
+ val = parseFloat(val);
209
+ }
210
+ }
211
+ sum += val;
212
+ }
213
+ }
214
+ //let number = new Intl.NumberFormat('en-En', { style: 'currency', currency: 'USD' }).format(sum);
215
+ if (sum != Math.floor(sum)) {
216
+ sum = sum.toFixed(2);
217
+ }
218
+ footer[fields[i]] = sum;
219
+ }
220
+ $self.jqGrid("footerData", "set", footer);
221
+ return footer;
222
+ }
223
+
224
+ /**
225
+ * Syncron Alias grid_avg_on
226
+ @alias module:Jqgrid_utils
227
+ */
228
+ _grid_avg_on(grid, fields = []) {
229
+ return this.grid_avg_on(grid, fields);
230
+ }
231
+
232
+ /**
233
+ * Average the column values together
234
+ @alias module:Jqgrid_utils
235
+ @param {object} - Grid Object (required)
236
+ @param {array} - Column/Field Names to where the average of each column should be calculated
237
+ @example
238
+ var jqu = new Jqgrid_utils({page:page});
239
+
240
+ gridComplete: function()
241
+ {
242
+ jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
243
+ },
244
+
245
+
246
+ */
247
+
248
+ async grid_avg_on(grid, fields = []) {
249
+ let $self = jQuery(grid);
250
+ let rows = $self.jqGrid("getGridParam", "data");
251
+ let count = 0;
252
+ let footer = {
253
+ invdate: "Total",
254
+ };
255
+ for (let i in fields) {
256
+ let sum = 0;
257
+ for (let r in rows) {
258
+ if (rows[r].hasOwnProperty(fields[i])) {
259
+ let val = rows[r][fields[i]];
260
+ if (typeof val === "string") {
261
+ if (is_digit(val)) {
262
+ val = parseFloat(val);
263
+ }
264
+ }
265
+ sum += val;
266
+ count++;
267
+ }
268
+ }
269
+ sum = sum / count;
270
+ if (sum != Math.floor(sum)) {
271
+ sum = sum.toFixed(2);
272
+ }
273
+ footer[fields[i]] = sum;
274
+ }
275
+ $self.jqGrid("footerData", "set", footer);
276
+ return footer;
277
+ }
278
+
279
+ /**
280
+ * Syncron Alias grid_percent_on
281
+ @alias module:Jqgrid_utils
282
+ */
283
+ _grid_percent_on(grid, obj) {
284
+ return grid_percent_on(grid, obj);
285
+ }
286
+
287
+ /**
288
+ * Percent the columns values together
289
+ @alias module:Jqgrid_utils
290
+ @param {object} - Grid Object (required)
291
+ @param {string} - Column/Field Name to sum
292
+ @example
293
+ var jqu = new Jqgrid_utils({page:page});
294
+ gridComplete: function () {
295
+ jqu._jqu._grid_sum_on(this, [
296
+ "qty_icollect",
297
+ "qty_ordered",
298
+ "need_for_qty_ordered",
299
+ "wait_icollect",
300
+ ]);
301
+ },
302
+ */
303
+ async grid_percent_on(grid, obj) {
304
+ let $self = jQuery(grid);
305
+ let rows = $self.jqGrid("getGridParam", "data");
306
+ let footer_sum = {};
307
+ let id = obj["id"] ? obj["id"] : "invate";
308
+ footer[id] = "Total";
309
+ let total = obj["total"];
310
+ let sums = JSON.parse(JSON.stringify(obj["percent"]));
311
+ sums.push(total);
312
+ for (let i in sums) {
313
+ let field = sums[i];
314
+ let sum = 0;
315
+ let _rows = 0;
316
+ for (let r in rows) {
317
+ if (rows[r].hasOwnProperty(field)) {
318
+ let val = rows[r][field];
319
+ if (typeof val === "string") {
320
+ if (is_digit(val)) {
321
+ val = parseFloat(val);
322
+ sum += val;
323
+ _rows++;
324
+ }
325
+ } else {
326
+ sum += val;
327
+ _rows++;
328
+ }
329
+ }
330
+ }
331
+ footer_sum[field] = sum;
332
+ }
333
+
334
+ for (let i in sums) {
335
+ let field = sums[i];
336
+ let percent = footer_sum[field] / (footer_sum[total] / 100);
337
+ percent = percent.toFixed(2);
338
+ footer[field] = percent + "%";
339
+ }
340
+ $self.jqGrid("footerData", "set", footer);
341
+ }
342
+
19
343
  /**
20
344
  * Takes the updated columns data and send it to your API post server
21
345
  * loadComplete: async function() for the old record needs to be called, see example !
package/jqgrid_utils.js CHANGED
@@ -15,6 +15,330 @@ module.exports = class Vanilla_website_utils {
15
15
  }
16
16
  }
17
17
 
18
+ /**
19
+ * Syncron Alias grid_sum_on
20
+ @alias module:Jqgrid_utils
21
+ */
22
+ async _grid_substract_on(
23
+ grid,
24
+ minuend = [],
25
+ subtrahend = [],
26
+ difference,
27
+ no_negative = false,
28
+ ) {
29
+ return await this.grid_substract_on(
30
+ grid,
31
+ minuend,
32
+ subtrahend,
33
+ difference,
34
+ no_negative,
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Sum the columns values together
40
+ @alias module:Jqgrid_utils
41
+ @param {object} - Grid Object (required)
42
+ @param {array} - string array list of field_names used as minuend(number from which the other number is subtracted)
43
+ @param {array} - string array list of field_names used as subtrahend(number which is to be subtracted from the minuend)
44
+ @param {string} - string field name for the difference(number which is to be subtracted from the minuend)
45
+ @param {bolen} - true or 1 to not show negative numbers
46
+
47
+ @example
48
+ var jqu = new Jqgrid_utils({page:page});
49
+ gridComplete: function () {
50
+ jqu._jqu._grid_sum_on(this, [
51
+ "qty_icollect",
52
+ "qty_ordered",
53
+ "need_for_qty_ordered",
54
+ "wait_icollect",
55
+ ]);
56
+ },
57
+ */
58
+ async grid_substract_on(
59
+ grid,
60
+ minuend = [],
61
+ subtrahend = [],
62
+ difference,
63
+ no_negative = false,
64
+ ) {
65
+ let $self = jQuery(grid);
66
+ let rows = $self.jqGrid("getGridParam", "data");
67
+ let footer = { invdate: "Total" };
68
+ let _minuend = 0.0;
69
+ let _subtrahend = 0.0;
70
+ for (let i in minuend) {
71
+ let sum = 0;
72
+ for (let r in rows) {
73
+ if (rows[r].hasOwnProperty(minuend[i])) {
74
+ let val = rows[r][minuend[i]];
75
+ if (typeof val === "string") {
76
+ if (is_digit(val)) {
77
+ val = parseFloat(val);
78
+ }
79
+ }
80
+ sum += val;
81
+ }
82
+ }
83
+ if (sum != Math.floor(sum)) {
84
+ sum = sum.toFixed(2);
85
+ }
86
+ footer[minuend[i]] = sum;
87
+ _minuend = sum;
88
+ }
89
+
90
+ for (let i in subtrahend) {
91
+ let sum = 0;
92
+ for (let r in rows) {
93
+ if (rows[r].hasOwnProperty(subtrahend[i])) {
94
+ let val = rows[r][subtrahend[i]];
95
+ if (typeof val === "string") {
96
+ if (is_digit(val)) {
97
+ val = parseFloat(val);
98
+ }
99
+ }
100
+ sum += val;
101
+ }
102
+ }
103
+ if (sum != Math.floor(sum)) {
104
+ sum = sum.toFixed(2);
105
+ }
106
+ footer[subtrahend[i]] = sum;
107
+ _subtrahend = sum;
108
+ }
109
+
110
+ let diff = _minuend - _subtrahend;
111
+ if (no_negative) {
112
+ if (diff < 0) {
113
+ diff = 0;
114
+ }
115
+ }
116
+ footer[difference] = diff;
117
+
118
+ $self.jqGrid("footerData", "set", footer);
119
+
120
+ return footer;
121
+ }
122
+
123
+ /**
124
+ * Syncron Alias grid_ratio_on
125
+ @alias module:Jqgrid_utils
126
+ */
127
+ _grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
128
+ return this.grid_ratio_on(grid, fraction_col, denominator_col, ratio_col);
129
+ }
130
+
131
+ /**
132
+ * Get the ratio the columns values together
133
+ @alias module:Jqgrid_utils
134
+ @param {object} - Grid Object (required)
135
+ @param {string} - Column/Field Name for value 1
136
+ @param {string} - Column/Field Name for value 2
137
+ @param {string} - Column/Field Name to the set the target ratio
138
+ @example
139
+ var jqu = new Jqgrid_utils({page:page});
140
+ gridComplete: function()
141
+ {
142
+ jqu._grid_ratio_on(this, 'actual_days', 'plan_days', 'qc_eta_ratio');
143
+ },
144
+
145
+ */
146
+ async grid_ratio_on(grid, fraction_col, denominator_col, ratio_col) {
147
+ var allrows = jQuery("#grid").jqGrid("getGridParam", "data");
148
+ let $self = jQuery(grid);
149
+ let rows = $self.jqGrid("getGridParam", "data");
150
+ let footer = {
151
+ invdate: "Total",
152
+ };
153
+ let sum = 0;
154
+ fraction_sum = 0;
155
+ denominator_sum = 0;
156
+ ratio_sum = 0;
157
+ for (let r in rows) {
158
+ if (rows[r].hasOwnProperty(fraction_col)) {
159
+ fraction_sum += rows[r][fraction_col];
160
+ }
161
+ if (rows[r].hasOwnProperty(denominator_col)) {
162
+ denominator_sum += rows[r][denominator_col];
163
+ }
164
+ }
165
+ footer["qc_eta_ratio"] = (fraction_sum / denominator_sum).toFixed(2);
166
+ $self.jqGrid("footerData", "set", footer);
167
+ return footer;
168
+ }
169
+
170
+ /**
171
+ * Syncron Alias grid_sum_on
172
+ @alias module:Jqgrid_utils
173
+ */
174
+ async _grid_sum_on(grid, fields = []) {
175
+ return await this.grid_sum_on(grid, fields);
176
+ }
177
+
178
+ /**
179
+ * Sum the columns values together
180
+ @alias module:Jqgrid_utils
181
+ @param {object} - Grid Object (required)
182
+ @param {string} - Column/Field Name to sum
183
+ @example
184
+ var jqu = new Jqgrid_utils({page:page});
185
+ gridComplete: function () {
186
+ jqu._jqu._grid_sum_on(this, [
187
+ "qty_icollect",
188
+ "qty_ordered",
189
+ "need_for_qty_ordered",
190
+ "wait_icollect",
191
+ ]);
192
+ },
193
+ */
194
+ async grid_sum_on(grid, fields = []) {
195
+ let $self = jQuery(grid);
196
+ let rows = $self.jqGrid("getGridParam", "data");
197
+ let footer = {
198
+ invdate: "Total",
199
+ };
200
+ for (let i in fields) {
201
+ let sum = 0;
202
+ for (let r in rows) {
203
+ if (rows[r].hasOwnProperty(fields[i])) {
204
+ let val = rows[r][fields[i]];
205
+ if (typeof val === "string") {
206
+ if (is_digit(val)) {
207
+ val = parseFloat(val);
208
+ }
209
+ }
210
+ sum += val;
211
+ }
212
+ }
213
+ //let number = new Intl.NumberFormat('en-En', { style: 'currency', currency: 'USD' }).format(sum);
214
+ if (sum != Math.floor(sum)) {
215
+ sum = sum.toFixed(2);
216
+ }
217
+ footer[fields[i]] = sum;
218
+ }
219
+ $self.jqGrid("footerData", "set", footer);
220
+ return footer;
221
+ }
222
+
223
+ /**
224
+ * Syncron Alias grid_avg_on
225
+ @alias module:Jqgrid_utils
226
+ */
227
+ _grid_avg_on(grid, fields = []) {
228
+ return this.grid_avg_on(grid, fields);
229
+ }
230
+
231
+ /**
232
+ * Average the column values together
233
+ @alias module:Jqgrid_utils
234
+ @param {object} - Grid Object (required)
235
+ @param {array} - Column/Field Names to where the average of each column should be calculated
236
+ @example
237
+ var jqu = new Jqgrid_utils({page:page});
238
+
239
+ gridComplete: function()
240
+ {
241
+ jqu._grid_avg_on(this, ['diff_plan_to_actual', 'days_early', 'days_late']);
242
+ },
243
+
244
+
245
+ */
246
+
247
+ async grid_avg_on(grid, fields = []) {
248
+ let $self = jQuery(grid);
249
+ let rows = $self.jqGrid("getGridParam", "data");
250
+ let count = 0;
251
+ let footer = {
252
+ invdate: "Total",
253
+ };
254
+ for (let i in fields) {
255
+ let sum = 0;
256
+ for (let r in rows) {
257
+ if (rows[r].hasOwnProperty(fields[i])) {
258
+ let val = rows[r][fields[i]];
259
+ if (typeof val === "string") {
260
+ if (is_digit(val)) {
261
+ val = parseFloat(val);
262
+ }
263
+ }
264
+ sum += val;
265
+ count++;
266
+ }
267
+ }
268
+ sum = sum / count;
269
+ if (sum != Math.floor(sum)) {
270
+ sum = sum.toFixed(2);
271
+ }
272
+ footer[fields[i]] = sum;
273
+ }
274
+ $self.jqGrid("footerData", "set", footer);
275
+ return footer;
276
+ }
277
+
278
+ /**
279
+ * Syncron Alias grid_percent_on
280
+ @alias module:Jqgrid_utils
281
+ */
282
+ _grid_percent_on(grid, obj) {
283
+ return grid_percent_on(grid, obj);
284
+ }
285
+
286
+ /**
287
+ * Percent the columns values together
288
+ @alias module:Jqgrid_utils
289
+ @param {object} - Grid Object (required)
290
+ @param {string} - Column/Field Name to sum
291
+ @example
292
+ var jqu = new Jqgrid_utils({page:page});
293
+ gridComplete: function () {
294
+ jqu._jqu._grid_sum_on(this, [
295
+ "qty_icollect",
296
+ "qty_ordered",
297
+ "need_for_qty_ordered",
298
+ "wait_icollect",
299
+ ]);
300
+ },
301
+ */
302
+ async grid_percent_on(grid, obj) {
303
+ let $self = jQuery(grid);
304
+ let rows = $self.jqGrid("getGridParam", "data");
305
+ let footer_sum = {};
306
+ let id = obj["id"] ? obj["id"] : "invate";
307
+ footer[id] = "Total";
308
+ let total = obj["total"];
309
+ let sums = JSON.parse(JSON.stringify(obj["percent"]));
310
+ sums.push(total);
311
+ for (let i in sums) {
312
+ let field = sums[i];
313
+ let sum = 0;
314
+ let _rows = 0;
315
+ for (let r in rows) {
316
+ if (rows[r].hasOwnProperty(field)) {
317
+ let val = rows[r][field];
318
+ if (typeof val === "string") {
319
+ if (is_digit(val)) {
320
+ val = parseFloat(val);
321
+ sum += val;
322
+ _rows++;
323
+ }
324
+ } else {
325
+ sum += val;
326
+ _rows++;
327
+ }
328
+ }
329
+ }
330
+ footer_sum[field] = sum;
331
+ }
332
+
333
+ for (let i in sums) {
334
+ let field = sums[i];
335
+ let percent = footer_sum[field] / (footer_sum[total] / 100);
336
+ percent = percent.toFixed(2);
337
+ footer[field] = percent + "%";
338
+ }
339
+ $self.jqGrid("footerData", "set", footer);
340
+ }
341
+
18
342
  /**
19
343
  * Takes the updated columns data and send it to your API post server
20
344
  * loadComplete: async function() for the old record needs to be called, see example !
package/npmignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .tern-port
2
- *~
2
+ *~
3
+ .github
package/package.json CHANGED
@@ -29,5 +29,7 @@
29
29
  {
30
30
  "test": "echo \"Error: no test specified\" && exit 1"
31
31
  },
32
- "version": "1.30.3"
32
+
33
+ "version": "1.33.0"
34
+
33
35
  }