jqgrid_utils 1.31.0 → 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.
@@ -16,6 +16,111 @@ 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
+
19
124
  /**
20
125
  * Syncron Alias grid_ratio_on
21
126
  @alias module:Jqgrid_utils
package/jqgrid_utils.js CHANGED
@@ -15,6 +15,111 @@ 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
+
18
123
  /**
19
124
  * Syncron Alias grid_ratio_on
20
125
  @alias module:Jqgrid_utils
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.31.0"
32
+
33
+ "version": "1.33.0"
34
+
33
35
  }