lazywait-calcs 1.0.3 → 1.0.4

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/lib/cjs/Calcs.js CHANGED
@@ -8,19 +8,19 @@ const lodash_1 = __importDefault(require("lodash"));
8
8
  const moment_1 = __importDefault(require("moment"));
9
9
  const utils_1 = require("./utils");
10
10
  function ItemTotal(order_item, branch_vat, order_taxes, order_discounts, order_items_count = 1) {
11
- var _a, _b;
11
+ var _a;
12
12
  let total = 0;
13
13
  const vat = branch_vat ? 1 + branch_vat / 100 : 1;
14
14
  if (order_item.price && order_item.quantity) {
15
15
  let price = order_item.price;
16
- (_a = order_item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
16
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.addons) || []).forEach((addon) => {
17
17
  if (addon.price && addon.quantity) {
18
18
  price += addon.price * addon.quantity;
19
19
  }
20
20
  });
21
21
  const discounts = calcItemDiscounts(order_item, order_discounts, order_items_count);
22
22
  price -= discounts;
23
- let item_tax = lodash_1.default.sum((_b = order_item.taxes) === null || _b === void 0 ? void 0 : _b.map((tax) => {
23
+ let item_tax = lodash_1.default.sum((_a = order_item.taxes) === null || _a === void 0 ? void 0 : _a.map((tax) => {
24
24
  return tax.isPercent ? ((tax.amount || 0) / 100) * price : tax.amount || 0;
25
25
  }));
26
26
  if (order_taxes) {
@@ -46,9 +46,8 @@ function Subtotal(order_items) {
46
46
  }
47
47
  exports.Subtotal = Subtotal;
48
48
  function calcItem(order_item) {
49
- var _a;
50
49
  let result = 0;
51
- (_a = order_item === null || order_item === void 0 ? void 0 : order_item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
50
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.addons) || []).forEach((addon) => {
52
51
  if (addon.price && addon.quantity) {
53
52
  result += addon.price * addon.quantity;
54
53
  }
@@ -84,8 +83,7 @@ function Discounts(order_discounts, order_items, loyalty_amount, branch_vat) {
84
83
  });
85
84
  }
86
85
  order_items === null || order_items === void 0 ? void 0 : order_items.forEach((order_item) => {
87
- var _a;
88
- (_a = order_item === null || order_item === void 0 ? void 0 : order_item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
86
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.discounts) || []).forEach((discount) => {
89
87
  var _a;
90
88
  if (discount.is_percentage && discount.amount) {
91
89
  const addons_arr = (_a = order_item === null || order_item === void 0 ? void 0 : order_item.addons) === null || _a === void 0 ? void 0 : _a.map((a) => { var _a; return ((_a = a.price) !== null && _a !== void 0 ? _a : 0) * a.quantity || 0; });
@@ -133,9 +131,8 @@ function DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_v
133
131
  }
134
132
  });
135
133
  }
136
- order_items === null || order_items === void 0 ? void 0 : order_items.forEach((order_item) => {
137
- var _a;
138
- (_a = order_item === null || order_item === void 0 ? void 0 : order_item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
134
+ (order_items || []).forEach((order_item) => {
135
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.discounts) || []).forEach((discount) => {
139
136
  var _a;
140
137
  if (!order_item.not_taxable) {
141
138
  if (discount.is_percentage && discount.amount) {
@@ -162,16 +159,15 @@ function DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_v
162
159
  }
163
160
  exports.DiscountsWithVat = DiscountsWithVat;
164
161
  function ItemVat(order_item, branch_vat) {
165
- var _a, _b;
166
162
  const vat = branch_vat ? branch_vat / 100 : 1;
167
163
  let addons = 0;
168
- (_a = order_item === null || order_item === void 0 ? void 0 : order_item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
164
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.addons) || []).forEach((addon) => {
169
165
  if (addon.price && addon.quantity) {
170
166
  addons += (0, utils_1.toFixedFloat)(addon.price * addon.quantity);
171
167
  }
172
168
  });
173
169
  let discounts = 0;
174
- (_b = order_item.discounts) === null || _b === void 0 ? void 0 : _b.forEach((discount) => {
170
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.discounts) || []).forEach((discount) => {
175
171
  if (discount.is_percentage && discount.amount) {
176
172
  discounts += (0, utils_1.toFixedFloat)((order_item.price + addons) * order_item.quantity * (discount.amount / 100));
177
173
  }
@@ -237,12 +233,12 @@ function OtherCharges(order_items, order, loyalty_amount, branch_vat) {
237
233
  }))
238
234
  : 0;
239
235
  }
240
- order_items.forEach((order_item) => {
241
- var _a, _b, _c;
236
+ (order_items || []).forEach((order_item) => {
237
+ var _a;
242
238
  const addons_total = lodash_1.default.sum((_a = order_item === null || order_item === void 0 ? void 0 : order_item.addons) === null || _a === void 0 ? void 0 : _a.map((a) => (a.price || 0) * (a.quantity || 0)));
243
239
  const price = (order_item.price + addons_total) * order_item.quantity;
244
240
  let _discounts = 0;
245
- (_b = order_item === null || order_item === void 0 ? void 0 : order_item.discounts) === null || _b === void 0 ? void 0 : _b.forEach((discount) => {
241
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.discounts) || []).forEach((discount) => {
246
242
  if (discount.is_percentage && discount.amount) {
247
243
  _discounts += price * (discount.amount / 100);
248
244
  }
@@ -251,7 +247,7 @@ function OtherCharges(order_items, order, loyalty_amount, branch_vat) {
251
247
  }
252
248
  });
253
249
  const order_items_count = lodash_1.default.sum(order_items.map((i) => i.quantity));
254
- order === null || order === void 0 ? void 0 : order.order_discounts.forEach((discount) => {
250
+ ((order === null || order === void 0 ? void 0 : order.order_discounts) || []).forEach((discount) => {
255
251
  if (discount.is_percentage && discount.amount) {
256
252
  _discounts += price * (discount.amount / 100);
257
253
  }
@@ -259,7 +255,7 @@ function OtherCharges(order_items, order, loyalty_amount, branch_vat) {
259
255
  _discounts += (discount.amount / order_items_count) * order_item.quantity;
260
256
  }
261
257
  });
262
- (_c = order_item === null || order_item === void 0 ? void 0 : order_item.taxes) === null || _c === void 0 ? void 0 : _c.forEach((tax) => {
258
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.taxes) || []).forEach((tax) => {
263
259
  if (tax.isPercent && tax.amount) {
264
260
  let temp = price - _discounts;
265
261
  if (temp < 0) {
@@ -281,7 +277,7 @@ function printedOrderTaxes(order, loyalty_amount, branch_vat) {
281
277
  const sub = Subtotal(order.order_items);
282
278
  const discounts = Number(Discounts((order === null || order === void 0 ? void 0 : order.order_discounts) || [], order.order_items, loyalty_amount, branch_vat));
283
279
  if (order && order.order_taxes) {
284
- order.order_taxes.forEach((tax) => {
280
+ ((order === null || order === void 0 ? void 0 : order.order_taxes) || []).forEach((tax) => {
285
281
  if (tax.amount) {
286
282
  taxes.push({
287
283
  tax_id: tax.tax_id || '',
@@ -296,9 +292,8 @@ function printedOrderTaxes(order, loyalty_amount, branch_vat) {
296
292
  }
297
293
  const order_items_count = lodash_1.default.sum(order.order_items.map((i) => i.quantity));
298
294
  const item_taxes = order.order_items.reduce((list, order_item) => {
299
- var _a;
300
295
  const addons_amount = calcItemAddons(order_item);
301
- (_a = order_item === null || order_item === void 0 ? void 0 : order_item.taxes) === null || _a === void 0 ? void 0 : _a.forEach((tax) => {
296
+ ((order_item === null || order_item === void 0 ? void 0 : order_item.taxes) || []).forEach((tax) => {
302
297
  let _discounts = calcItemDiscounts(order_item, order.order_discounts, order_items_count);
303
298
  if (tax.tax_id) {
304
299
  let charge = 0;
@@ -380,15 +375,14 @@ function calcClosingCashBalance(closing, opening_start_cash) {
380
375
  }
381
376
  exports.calcClosingCashBalance = calcClosingCashBalance;
382
377
  function calcItemDiscounts(item, order_discounts, order_items_count) {
383
- var _a, _b;
384
378
  let discounts = 0;
385
379
  let addons = 0;
386
- (_a = item === null || item === void 0 ? void 0 : item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
380
+ ((item === null || item === void 0 ? void 0 : item.addons) || []).forEach((addon) => {
387
381
  if (addon.price && addon.quantity) {
388
382
  addons += addon.price * addon.quantity;
389
383
  }
390
384
  });
391
- (_b = item.discounts) === null || _b === void 0 ? void 0 : _b.forEach((discount) => {
385
+ ((item === null || item === void 0 ? void 0 : item.discounts) || []).forEach((discount) => {
392
386
  if (discount.is_percentage && discount.amount) {
393
387
  discounts += (item.price + addons) * (discount.amount / 100);
394
388
  }
@@ -396,7 +390,7 @@ function calcItemDiscounts(item, order_discounts, order_items_count) {
396
390
  discounts += discount.amount;
397
391
  }
398
392
  });
399
- order_discounts === null || order_discounts === void 0 ? void 0 : order_discounts.forEach((discount) => {
393
+ (order_discounts || []).forEach((discount) => {
400
394
  if (discount.is_percentage && discount.amount) {
401
395
  discounts += (item.price + addons) * (discount.amount / 100);
402
396
  }
@@ -408,9 +402,8 @@ function calcItemDiscounts(item, order_discounts, order_items_count) {
408
402
  }
409
403
  exports.calcItemDiscounts = calcItemDiscounts;
410
404
  function calcItemAddons(item) {
411
- var _a;
412
405
  let addons = 0;
413
- (_a = item === null || item === void 0 ? void 0 : item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
406
+ ((item === null || item === void 0 ? void 0 : item.addons) || []).forEach((addon) => {
414
407
  if (addon.price && addon.quantity) {
415
408
  addons += addon.price * addon.quantity;
416
409
  }
package/lib/esm/Calcs.js CHANGED
@@ -6,7 +6,7 @@ function ItemTotal(order_item, branch_vat, order_taxes, order_discounts, order_i
6
6
  const vat = branch_vat ? 1 + branch_vat / 100 : 1;
7
7
  if (order_item.price && order_item.quantity) {
8
8
  let price = order_item.price;
9
- order_item.addons?.forEach((addon) => {
9
+ (order_item?.addons || []).forEach((addon) => {
10
10
  if (addon.price && addon.quantity) {
11
11
  price += addon.price * addon.quantity;
12
12
  }
@@ -38,7 +38,7 @@ function Subtotal(order_items) {
38
38
  }
39
39
  function calcItem(order_item) {
40
40
  let result = 0;
41
- order_item?.addons?.forEach((addon) => {
41
+ (order_item?.addons || []).forEach((addon) => {
42
42
  if (addon.price && addon.quantity) {
43
43
  result += addon.price * addon.quantity;
44
44
  }
@@ -73,7 +73,7 @@ function Discounts(order_discounts, order_items, loyalty_amount, branch_vat) {
73
73
  });
74
74
  }
75
75
  order_items?.forEach((order_item) => {
76
- order_item?.discounts?.forEach((discount) => {
76
+ (order_item?.discounts || []).forEach((discount) => {
77
77
  if (discount.is_percentage && discount.amount) {
78
78
  const addons_arr = order_item?.addons?.map((a) => (a.price ?? 0) * a.quantity || 0);
79
79
  const addons_total = _.sum(addons_arr);
@@ -119,8 +119,8 @@ function DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_v
119
119
  }
120
120
  });
121
121
  }
122
- order_items?.forEach((order_item) => {
123
- order_item?.discounts?.forEach((discount) => {
122
+ (order_items || []).forEach((order_item) => {
123
+ (order_item?.discounts || []).forEach((discount) => {
124
124
  if (!order_item.not_taxable) {
125
125
  if (discount.is_percentage && discount.amount) {
126
126
  const addons_arr = order_item?.addons?.map((a) => (a.price || 0) * (a.quantity || 0));
@@ -147,13 +147,13 @@ function DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_v
147
147
  function ItemVat(order_item, branch_vat) {
148
148
  const vat = branch_vat ? branch_vat / 100 : 1;
149
149
  let addons = 0;
150
- order_item?.addons?.forEach((addon) => {
150
+ (order_item?.addons || []).forEach((addon) => {
151
151
  if (addon.price && addon.quantity) {
152
152
  addons += toFixedFloat(addon.price * addon.quantity);
153
153
  }
154
154
  });
155
155
  let discounts = 0;
156
- order_item.discounts?.forEach((discount) => {
156
+ (order_item?.discounts || []).forEach((discount) => {
157
157
  if (discount.is_percentage && discount.amount) {
158
158
  discounts += toFixedFloat((order_item.price + addons) * order_item.quantity * (discount.amount / 100));
159
159
  }
@@ -214,11 +214,11 @@ function OtherCharges(order_items, order, loyalty_amount, branch_vat) {
214
214
  }))
215
215
  : 0;
216
216
  }
217
- order_items.forEach((order_item) => {
217
+ (order_items || []).forEach((order_item) => {
218
218
  const addons_total = _.sum(order_item?.addons?.map((a) => (a.price || 0) * (a.quantity || 0)));
219
219
  const price = (order_item.price + addons_total) * order_item.quantity;
220
220
  let _discounts = 0;
221
- order_item?.discounts?.forEach((discount) => {
221
+ (order_item?.discounts || []).forEach((discount) => {
222
222
  if (discount.is_percentage && discount.amount) {
223
223
  _discounts += price * (discount.amount / 100);
224
224
  }
@@ -227,7 +227,7 @@ function OtherCharges(order_items, order, loyalty_amount, branch_vat) {
227
227
  }
228
228
  });
229
229
  const order_items_count = _.sum(order_items.map((i) => i.quantity));
230
- order?.order_discounts.forEach((discount) => {
230
+ (order?.order_discounts || []).forEach((discount) => {
231
231
  if (discount.is_percentage && discount.amount) {
232
232
  _discounts += price * (discount.amount / 100);
233
233
  }
@@ -235,7 +235,7 @@ function OtherCharges(order_items, order, loyalty_amount, branch_vat) {
235
235
  _discounts += (discount.amount / order_items_count) * order_item.quantity;
236
236
  }
237
237
  });
238
- order_item?.taxes?.forEach((tax) => {
238
+ (order_item?.taxes || []).forEach((tax) => {
239
239
  if (tax.isPercent && tax.amount) {
240
240
  let temp = price - _discounts;
241
241
  if (temp < 0) {
@@ -256,7 +256,7 @@ function printedOrderTaxes(order, loyalty_amount, branch_vat) {
256
256
  const sub = Subtotal(order.order_items);
257
257
  const discounts = Number(Discounts(order?.order_discounts || [], order.order_items, loyalty_amount, branch_vat));
258
258
  if (order && order.order_taxes) {
259
- order.order_taxes.forEach((tax) => {
259
+ (order?.order_taxes || []).forEach((tax) => {
260
260
  if (tax.amount) {
261
261
  taxes.push({
262
262
  tax_id: tax.tax_id || '',
@@ -272,7 +272,7 @@ function printedOrderTaxes(order, loyalty_amount, branch_vat) {
272
272
  const order_items_count = _.sum(order.order_items.map((i) => i.quantity));
273
273
  const item_taxes = order.order_items.reduce((list, order_item) => {
274
274
  const addons_amount = calcItemAddons(order_item);
275
- order_item?.taxes?.forEach((tax) => {
275
+ (order_item?.taxes || []).forEach((tax) => {
276
276
  let _discounts = calcItemDiscounts(order_item, order.order_discounts, order_items_count);
277
277
  if (tax.tax_id) {
278
278
  let charge = 0;
@@ -351,12 +351,12 @@ function calcClosingCashBalance(closing, opening_start_cash) {
351
351
  function calcItemDiscounts(item, order_discounts, order_items_count) {
352
352
  let discounts = 0;
353
353
  let addons = 0;
354
- item?.addons?.forEach((addon) => {
354
+ (item?.addons || []).forEach((addon) => {
355
355
  if (addon.price && addon.quantity) {
356
356
  addons += addon.price * addon.quantity;
357
357
  }
358
358
  });
359
- item.discounts?.forEach((discount) => {
359
+ (item?.discounts || []).forEach((discount) => {
360
360
  if (discount.is_percentage && discount.amount) {
361
361
  discounts += (item.price + addons) * (discount.amount / 100);
362
362
  }
@@ -364,7 +364,7 @@ function calcItemDiscounts(item, order_discounts, order_items_count) {
364
364
  discounts += discount.amount;
365
365
  }
366
366
  });
367
- order_discounts?.forEach((discount) => {
367
+ (order_discounts || []).forEach((discount) => {
368
368
  if (discount.is_percentage && discount.amount) {
369
369
  discounts += (item.price + addons) * (discount.amount / 100);
370
370
  }
@@ -376,7 +376,7 @@ function calcItemDiscounts(item, order_discounts, order_items_count) {
376
376
  }
377
377
  function calcItemAddons(item) {
378
378
  let addons = 0;
379
- item?.addons?.forEach((addon) => {
379
+ (item?.addons || []).forEach((addon) => {
380
380
  if (addon.price && addon.quantity) {
381
381
  addons += addon.price * addon.quantity;
382
382
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lazywait-calcs",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "An npm package for all calculations needed in LazyWait projects.",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "repository": "https://github.com/CloudAppsLLC/Calcs.git",