lazywait-calcs 1.8.7 → 1.8.9
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 +42 -10
- package/lib/cjs/types/Calcs.d.ts.map +1 -1
- package/lib/esm/Calcs.js +42 -10
- package/lib/esm/types/Calcs.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/cjs/Calcs.js
CHANGED
|
@@ -11,6 +11,8 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
12
|
function ItemTotal(order_item, branch_vat, order_taxes, order_discounts, order_items_count = 1) {
|
|
13
13
|
var _a, _b;
|
|
14
|
+
if (!order_item)
|
|
15
|
+
return 0;
|
|
14
16
|
let total = 0;
|
|
15
17
|
const vat = branch_vat ? 1 + branch_vat / 100 : 1;
|
|
16
18
|
if ((order_item.price || order_item.price === 0) && order_item.quantity) {
|
|
@@ -57,6 +59,8 @@ function Subtotal(order_items) {
|
|
|
57
59
|
}
|
|
58
60
|
exports.Subtotal = Subtotal;
|
|
59
61
|
function calcItem(order_item) {
|
|
62
|
+
if (!order_item)
|
|
63
|
+
return 0;
|
|
60
64
|
let result = order_item.price || 0;
|
|
61
65
|
((order_item === null || order_item === void 0 ? void 0 : order_item.addons) || []).forEach((addon) => {
|
|
62
66
|
if ((addon === null || addon === void 0 ? void 0 : addon.price) && (addon === null || addon === void 0 ? void 0 : addon.quantity)) {
|
|
@@ -171,6 +175,8 @@ function DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_v
|
|
|
171
175
|
exports.DiscountsWithVat = DiscountsWithVat;
|
|
172
176
|
function ItemVat(order_item, branch_vat) {
|
|
173
177
|
var _a, _b;
|
|
178
|
+
if (!order_item)
|
|
179
|
+
return 0;
|
|
174
180
|
const vat = branch_vat ? branch_vat / 100 : 1;
|
|
175
181
|
let addons = 0;
|
|
176
182
|
((_a = order_item === null || order_item === void 0 ? void 0 : order_item.addons) !== null && _a !== void 0 ? _a : []).forEach((addon) => {
|
|
@@ -192,14 +198,16 @@ function ItemVat(order_item, branch_vat) {
|
|
|
192
198
|
}
|
|
193
199
|
exports.ItemVat = ItemVat;
|
|
194
200
|
function Vat(order_items, order_discounts, order_taxes, order_deliveries, loyalty_amount, branch_vat) {
|
|
195
|
-
if (
|
|
201
|
+
if (!order_items || !Array.isArray(order_items))
|
|
202
|
+
return 0;
|
|
203
|
+
if (branch_vat && order_items.some((o) => !(o === null || o === void 0 ? void 0 : o.not_taxable))) {
|
|
196
204
|
const discount = DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_vat);
|
|
197
205
|
// Other charges for taxable items
|
|
198
|
-
const other_charges = Number(OtherCharges(order_items.filter((i) => !i.not_taxable), order_discounts, order_taxes, loyalty_amount, branch_vat));
|
|
206
|
+
const other_charges = Number(OtherCharges(order_items.filter((i) => !(i === null || i === void 0 ? void 0 : i.not_taxable)), order_discounts, order_taxes, loyalty_amount, branch_vat));
|
|
199
207
|
// Order delivery
|
|
200
208
|
const deliveries = Deliveries(order_deliveries || []);
|
|
201
209
|
// subtotal of items with vat
|
|
202
|
-
let sub_total = (0, sum_1.default)(order_items.filter((i) => !i.not_taxable).map(calcItem));
|
|
210
|
+
let sub_total = (0, sum_1.default)(order_items.filter((i) => !(i === null || i === void 0 ? void 0 : i.not_taxable)).map(calcItem));
|
|
203
211
|
// VAT amount
|
|
204
212
|
const vat = (branch_vat / 100) * (sub_total + other_charges + deliveries - discount);
|
|
205
213
|
return vat >= 0 ? vat : 0;
|
|
@@ -219,11 +227,11 @@ function Deliveries(order_deliveries) {
|
|
|
219
227
|
let sum = 0;
|
|
220
228
|
if (order_deliveries) {
|
|
221
229
|
order_deliveries.forEach((d) => {
|
|
222
|
-
if (d.delivery_type === 'RADIUS') {
|
|
223
|
-
sum += (d.delivery_fee || 0) * (d.delivery_radius || 1);
|
|
230
|
+
if ((d === null || d === void 0 ? void 0 : d.delivery_type) === 'RADIUS') {
|
|
231
|
+
sum += ((d === null || d === void 0 ? void 0 : d.delivery_fee) || 0) * ((d === null || d === void 0 ? void 0 : d.delivery_radius) || 1);
|
|
224
232
|
}
|
|
225
233
|
else {
|
|
226
|
-
sum += d.delivery_fee || 0;
|
|
234
|
+
sum += (d === null || d === void 0 ? void 0 : d.delivery_fee) || 0;
|
|
227
235
|
}
|
|
228
236
|
});
|
|
229
237
|
}
|
|
@@ -231,6 +239,8 @@ function Deliveries(order_deliveries) {
|
|
|
231
239
|
}
|
|
232
240
|
exports.Deliveries = Deliveries;
|
|
233
241
|
function OtherCharges(order_items, order_discounts, order_taxes, loyalty_amount, branch_vat) {
|
|
242
|
+
if (!order_items || !Array.isArray(order_items))
|
|
243
|
+
return 0;
|
|
234
244
|
const sub = Subtotal(order_items);
|
|
235
245
|
const discounts = Number(Discounts(order_discounts, order_items, loyalty_amount, branch_vat));
|
|
236
246
|
let other_charges = 0;
|
|
@@ -298,6 +308,8 @@ function OtherCharges(order_items, order_discounts, order_taxes, loyalty_amount,
|
|
|
298
308
|
}
|
|
299
309
|
exports.OtherCharges = OtherCharges;
|
|
300
310
|
function printedOrderTaxes(order_items, order_discounts, order_taxes, loyalty_amount, branch_vat, isVoidOrRefund = false) {
|
|
311
|
+
if (!order_items || !Array.isArray(order_items))
|
|
312
|
+
return [];
|
|
301
313
|
let taxes = [];
|
|
302
314
|
const multiplier = isVoidOrRefund ? -1 : 1;
|
|
303
315
|
const sub = Subtotal(order_items);
|
|
@@ -320,9 +332,11 @@ function printedOrderTaxes(order_items, order_discounts, order_taxes, loyalty_am
|
|
|
320
332
|
}
|
|
321
333
|
});
|
|
322
334
|
}
|
|
323
|
-
const order_items_count = (0, sum_1.default)((order_items !== null && order_items !== void 0 ? order_items : []).map((i) => i.quantity));
|
|
335
|
+
const order_items_count = (0, sum_1.default)((order_items !== null && order_items !== void 0 ? order_items : []).map((i) => (i === null || i === void 0 ? void 0 : i.quantity) || 0));
|
|
324
336
|
const item_taxes = (order_items !== null && order_items !== void 0 ? order_items : []).reduce((list, order_item) => {
|
|
325
337
|
var _a;
|
|
338
|
+
if (!order_item)
|
|
339
|
+
return list;
|
|
326
340
|
const addons_amount = calcItemAddons(order_item);
|
|
327
341
|
(_a = order_item === null || order_item === void 0 ? void 0 : order_item.taxes) === null || _a === void 0 ? void 0 : _a.forEach((tax) => {
|
|
328
342
|
let _discounts = calcItemDiscounts(order_item, order_discounts, order_items_count);
|
|
@@ -358,6 +372,8 @@ function printedOrderTaxes(order_items, order_discounts, order_taxes, loyalty_am
|
|
|
358
372
|
}
|
|
359
373
|
exports.printedOrderTaxes = printedOrderTaxes;
|
|
360
374
|
function Total(order_items, order_discounts, order_taxes, order_deliveries, loyalty_amount, branch_vat) {
|
|
375
|
+
if (!order_items || !Array.isArray(order_items))
|
|
376
|
+
return 0;
|
|
361
377
|
const sub = Number(Subtotal(order_items));
|
|
362
378
|
const discounts = Number(Discounts(order_discounts !== null && order_discounts !== void 0 ? order_discounts : [], order_items !== null && order_items !== void 0 ? order_items : [], loyalty_amount !== null && loyalty_amount !== void 0 ? loyalty_amount : 0, branch_vat !== null && branch_vat !== void 0 ? branch_vat : 0));
|
|
363
379
|
const other_charges = Number(OtherCharges(order_items !== null && order_items !== void 0 ? order_items : [], order_discounts !== null && order_discounts !== void 0 ? order_discounts : [], order_taxes !== null && order_taxes !== void 0 ? order_taxes : [], loyalty_amount !== null && loyalty_amount !== void 0 ? loyalty_amount : 0, branch_vat !== null && branch_vat !== void 0 ? branch_vat : 0));
|
|
@@ -371,6 +387,8 @@ function Total(order_items, order_discounts, order_taxes, order_deliveries, loya
|
|
|
371
387
|
exports.Total = Total;
|
|
372
388
|
function calcPaymentBalanceDue(invoice, branch) {
|
|
373
389
|
var _a, _b, _c;
|
|
390
|
+
if (!invoice)
|
|
391
|
+
return 0;
|
|
374
392
|
let due = ((_a = invoice === null || invoice === void 0 ? void 0 : invoice.total) !== null && _a !== void 0 ? _a : 0) - ((_b = invoice === null || invoice === void 0 ? void 0 : invoice.received_amount) !== null && _b !== void 0 ? _b : 0);
|
|
375
393
|
if ((branch === null || branch === void 0 ? void 0 : branch.payment_methods) && branch.payment_methods.length) {
|
|
376
394
|
(_c = branch === null || branch === void 0 ? void 0 : branch.payment_methods) !== null && _c !== void 0 ? _c : [].forEach((payment) => {
|
|
@@ -381,6 +399,8 @@ function calcPaymentBalanceDue(invoice, branch) {
|
|
|
381
399
|
}
|
|
382
400
|
exports.calcPaymentBalanceDue = calcPaymentBalanceDue;
|
|
383
401
|
function calPaymentTotal(info) {
|
|
402
|
+
if (!info || !info.payments)
|
|
403
|
+
return {};
|
|
384
404
|
let groupByPaymnets = (0, map_1.default)(info.payments, (p) => ({
|
|
385
405
|
name_lan_p: p.name_lan_p,
|
|
386
406
|
name_lan_s: p.name_lan_s,
|
|
@@ -409,6 +429,8 @@ function calcClosingCashBalance(closing, opening_start_cash) {
|
|
|
409
429
|
exports.calcClosingCashBalance = calcClosingCashBalance;
|
|
410
430
|
function calcItemDiscounts(item, order_discounts, order_items_count) {
|
|
411
431
|
var _a, _b;
|
|
432
|
+
if (!item)
|
|
433
|
+
return 0;
|
|
412
434
|
let discounts = 0;
|
|
413
435
|
let addons = 0;
|
|
414
436
|
(_a = item === null || item === void 0 ? void 0 : item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
|
|
@@ -437,6 +459,8 @@ function calcItemDiscounts(item, order_discounts, order_items_count) {
|
|
|
437
459
|
exports.calcItemDiscounts = calcItemDiscounts;
|
|
438
460
|
function calcItemAddons(item) {
|
|
439
461
|
var _a;
|
|
462
|
+
if (!item)
|
|
463
|
+
return 0;
|
|
440
464
|
let addons = 0;
|
|
441
465
|
(_a = item === null || item === void 0 ? void 0 : item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
|
|
442
466
|
if (addon.price && addon.quantity) {
|
|
@@ -447,22 +471,30 @@ function calcItemAddons(item) {
|
|
|
447
471
|
}
|
|
448
472
|
exports.calcItemAddons = calcItemAddons;
|
|
449
473
|
function getInvoicesDiffrence(openning, invoices) {
|
|
474
|
+
if (!openning || !invoices || !Array.isArray(invoices))
|
|
475
|
+
return [];
|
|
450
476
|
const openningTime = (0, moment_1.default)((0, utils_1.convertToDate)(openning.cashier_opening_date));
|
|
451
477
|
return invoices.filter((invoice) => {
|
|
478
|
+
if (!invoice)
|
|
479
|
+
return false;
|
|
452
480
|
const invoiceDate = (0, moment_1.default)((0, utils_1.convertToDate)(invoice.order_date));
|
|
453
481
|
return invoiceDate.isBefore(openningTime);
|
|
454
482
|
});
|
|
455
483
|
}
|
|
456
484
|
exports.getInvoicesDiffrence = getInvoicesDiffrence;
|
|
457
485
|
function getActiveInvoices(invoices) {
|
|
458
|
-
|
|
486
|
+
if (!invoices || !Array.isArray(invoices))
|
|
487
|
+
return [];
|
|
488
|
+
const list = invoices.filter((invoice) => { var _a; return invoice && ((_a = invoice.order_payments) === null || _a === void 0 ? void 0 : _a.length) === 0; });
|
|
459
489
|
return list;
|
|
460
490
|
}
|
|
461
491
|
exports.getActiveInvoices = getActiveInvoices;
|
|
462
492
|
function calcRefundedLoyaltyAmount(order, canceled_items) {
|
|
463
493
|
var _a, _b;
|
|
464
|
-
|
|
465
|
-
|
|
494
|
+
if (!order || !canceled_items)
|
|
495
|
+
return 0;
|
|
496
|
+
const items_count = (0, sum_1.default)(((_a = order === null || order === void 0 ? void 0 : order.order_items) === null || _a === void 0 ? void 0 : _a.map((o) => (o === null || o === void 0 ? void 0 : o.quantity) || 0)) || [0]) + (0, sum_1.default)(((_b = order === null || order === void 0 ? void 0 : order.canceled_items) === null || _b === void 0 ? void 0 : _b.map((o) => (o === null || o === void 0 ? void 0 : o.quantity) || 0)) || [0]);
|
|
497
|
+
const canceled_items_count = (0, sum_1.default)((canceled_items === null || canceled_items === void 0 ? void 0 : canceled_items.map((o) => (o === null || o === void 0 ? void 0 : o.quantity) || 0)) || [0]);
|
|
466
498
|
return (((order === null || order === void 0 ? void 0 : order.loyalty_amount) || 0) / items_count) * canceled_items_count;
|
|
467
499
|
}
|
|
468
500
|
exports.calcRefundedLoyaltyAmount = calcRefundedLoyaltyAmount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calcs.d.ts","sourceRoot":"","sources":["../../../src/Calcs.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,MAAM,EACN,cAAc,EACd,cAAc,
|
|
1
|
+
{"version":3,"file":"Calcs.d.ts","sourceRoot":"","sources":["../../../src/Calcs.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,MAAM,EACN,cAAc,EACd,cAAc,EACd,KAAK,EACL,aAAa,EACb,aAAa,EACb,SAAS,EACT,QAAQ,EAER,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,MAAM,SAAS,CAAC;AAGjB,wBAAgB,SAAS,CACxB,UAAU,EAAE,SAAS,EACrB,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,WAAW,CAAC,EAAE,QAAQ,EAAE,EACxB,eAAe,CAAC,EAAE,aAAa,EAAE,EACjC,iBAAiB,SAAI,UAmDrB;AAED,wBAAgB,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,UAKvD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,SAAS,UAe7C;AAED,wBAAgB,SAAS,CACxB,eAAe,EAAE,aAAa,EAAE,GAAG,IAAI,EACvC,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,EAC/B,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,UA8CzB;AAED,wBAAgB,gBAAgB,CAC/B,eAAe,EAAE,aAAa,EAAE,GAAG,IAAI,EACvC,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,EAC/B,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,UAgDzB;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,UAsBv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AAE,OAAO,CAAC,cAAc,CAAC,EAAE,kBAAkB,EAAE,MAAM,GAAG,SAAS,UAM9G;AAED,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,SAAS,GAAG,cAAc,EAChC,eAAe,EAAE,aAAa,EAAE,GAAG,kBAAkB,EAAE,GAAG,SAAS,EACnE,iBAAiB,EAAE,MAAM,UA6BzB;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,cAAc,UAU9D;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,WAS/E;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,KAAK,EAAE,WAIlD;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,UAMzF;AAED,wBAAgB,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,UAK1D;AAED,wBAAgB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,UAK7D"}
|
package/lib/esm/Calcs.js
CHANGED
|
@@ -4,6 +4,8 @@ import _sum from 'lodash/sum';
|
|
|
4
4
|
import moment from 'moment';
|
|
5
5
|
import { convertToDate, preventNaN, toFixedFloat } from './utils';
|
|
6
6
|
export function ItemTotal(order_item, branch_vat, order_taxes, order_discounts, order_items_count = 1) {
|
|
7
|
+
if (!order_item)
|
|
8
|
+
return 0;
|
|
7
9
|
let total = 0;
|
|
8
10
|
const vat = branch_vat ? 1 + branch_vat / 100 : 1;
|
|
9
11
|
if ((order_item.price || order_item.price === 0) && order_item.quantity) {
|
|
@@ -48,6 +50,8 @@ export function Subtotal(order_items) {
|
|
|
48
50
|
return 0;
|
|
49
51
|
}
|
|
50
52
|
export function calcItem(order_item) {
|
|
53
|
+
if (!order_item)
|
|
54
|
+
return 0;
|
|
51
55
|
let result = order_item.price || 0;
|
|
52
56
|
(order_item?.addons || []).forEach((addon) => {
|
|
53
57
|
if (addon?.price && addon?.quantity) {
|
|
@@ -156,6 +160,8 @@ export function DiscountsWithVat(order_discounts, order_items, loyalty_amount, b
|
|
|
156
160
|
return discounts;
|
|
157
161
|
}
|
|
158
162
|
export function ItemVat(order_item, branch_vat) {
|
|
163
|
+
if (!order_item)
|
|
164
|
+
return 0;
|
|
159
165
|
const vat = branch_vat ? branch_vat / 100 : 1;
|
|
160
166
|
let addons = 0;
|
|
161
167
|
(order_item?.addons ?? []).forEach((addon) => {
|
|
@@ -176,14 +182,16 @@ export function ItemVat(order_item, branch_vat) {
|
|
|
176
182
|
return order_item?.not_taxable ? 0 : price * vat;
|
|
177
183
|
}
|
|
178
184
|
export function Vat(order_items, order_discounts, order_taxes, order_deliveries, loyalty_amount, branch_vat) {
|
|
179
|
-
if (
|
|
185
|
+
if (!order_items || !Array.isArray(order_items))
|
|
186
|
+
return 0;
|
|
187
|
+
if (branch_vat && order_items.some((o) => !o?.not_taxable)) {
|
|
180
188
|
const discount = DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_vat);
|
|
181
189
|
// Other charges for taxable items
|
|
182
|
-
const other_charges = Number(OtherCharges(order_items.filter((i) => !i
|
|
190
|
+
const other_charges = Number(OtherCharges(order_items.filter((i) => !i?.not_taxable), order_discounts, order_taxes, loyalty_amount, branch_vat));
|
|
183
191
|
// Order delivery
|
|
184
192
|
const deliveries = Deliveries(order_deliveries || []);
|
|
185
193
|
// subtotal of items with vat
|
|
186
|
-
let sub_total = _sum(order_items.filter((i) => !i
|
|
194
|
+
let sub_total = _sum(order_items.filter((i) => !i?.not_taxable).map(calcItem));
|
|
187
195
|
// VAT amount
|
|
188
196
|
const vat = (branch_vat / 100) * (sub_total + other_charges + deliveries - discount);
|
|
189
197
|
return vat >= 0 ? vat : 0;
|
|
@@ -200,17 +208,19 @@ export function Deliveries(order_deliveries) {
|
|
|
200
208
|
let sum = 0;
|
|
201
209
|
if (order_deliveries) {
|
|
202
210
|
order_deliveries.forEach((d) => {
|
|
203
|
-
if (d
|
|
204
|
-
sum += (d
|
|
211
|
+
if (d?.delivery_type === 'RADIUS') {
|
|
212
|
+
sum += (d?.delivery_fee || 0) * (d?.delivery_radius || 1);
|
|
205
213
|
}
|
|
206
214
|
else {
|
|
207
|
-
sum += d
|
|
215
|
+
sum += d?.delivery_fee || 0;
|
|
208
216
|
}
|
|
209
217
|
});
|
|
210
218
|
}
|
|
211
219
|
return sum;
|
|
212
220
|
}
|
|
213
221
|
export function OtherCharges(order_items, order_discounts, order_taxes, loyalty_amount, branch_vat) {
|
|
222
|
+
if (!order_items || !Array.isArray(order_items))
|
|
223
|
+
return 0;
|
|
214
224
|
const sub = Subtotal(order_items);
|
|
215
225
|
const discounts = Number(Discounts(order_discounts, order_items, loyalty_amount, branch_vat));
|
|
216
226
|
let other_charges = 0;
|
|
@@ -276,6 +286,8 @@ export function OtherCharges(order_items, order_discounts, order_taxes, loyalty_
|
|
|
276
286
|
return other_charges;
|
|
277
287
|
}
|
|
278
288
|
export function printedOrderTaxes(order_items, order_discounts, order_taxes, loyalty_amount, branch_vat, isVoidOrRefund = false) {
|
|
289
|
+
if (!order_items || !Array.isArray(order_items))
|
|
290
|
+
return [];
|
|
279
291
|
let taxes = [];
|
|
280
292
|
const multiplier = isVoidOrRefund ? -1 : 1;
|
|
281
293
|
const sub = Subtotal(order_items);
|
|
@@ -298,8 +310,10 @@ export function printedOrderTaxes(order_items, order_discounts, order_taxes, loy
|
|
|
298
310
|
}
|
|
299
311
|
});
|
|
300
312
|
}
|
|
301
|
-
const order_items_count = _sum((order_items ?? []).map((i) => i
|
|
313
|
+
const order_items_count = _sum((order_items ?? []).map((i) => i?.quantity || 0));
|
|
302
314
|
const item_taxes = (order_items ?? []).reduce((list, order_item) => {
|
|
315
|
+
if (!order_item)
|
|
316
|
+
return list;
|
|
303
317
|
const addons_amount = calcItemAddons(order_item);
|
|
304
318
|
order_item?.taxes?.forEach((tax) => {
|
|
305
319
|
let _discounts = calcItemDiscounts(order_item, order_discounts, order_items_count);
|
|
@@ -334,6 +348,8 @@ export function printedOrderTaxes(order_items, order_discounts, order_taxes, loy
|
|
|
334
348
|
return _concat(taxes, item_taxes);
|
|
335
349
|
}
|
|
336
350
|
export function Total(order_items, order_discounts, order_taxes, order_deliveries, loyalty_amount, branch_vat) {
|
|
351
|
+
if (!order_items || !Array.isArray(order_items))
|
|
352
|
+
return 0;
|
|
337
353
|
const sub = Number(Subtotal(order_items));
|
|
338
354
|
const discounts = Number(Discounts(order_discounts ?? [], order_items ?? [], loyalty_amount ?? 0, branch_vat ?? 0));
|
|
339
355
|
const other_charges = Number(OtherCharges(order_items ?? [], order_discounts ?? [], order_taxes ?? [], loyalty_amount ?? 0, branch_vat ?? 0));
|
|
@@ -345,6 +361,8 @@ export function Total(order_items, order_discounts, order_taxes, order_deliverie
|
|
|
345
361
|
return total;
|
|
346
362
|
}
|
|
347
363
|
export function calcPaymentBalanceDue(invoice, branch) {
|
|
364
|
+
if (!invoice)
|
|
365
|
+
return 0;
|
|
348
366
|
let due = (invoice?.total ?? 0) - (invoice?.received_amount ?? 0);
|
|
349
367
|
if (branch?.payment_methods && branch.payment_methods.length) {
|
|
350
368
|
branch?.payment_methods ??
|
|
@@ -355,6 +373,8 @@ export function calcPaymentBalanceDue(invoice, branch) {
|
|
|
355
373
|
return due > 0 ? due : 0;
|
|
356
374
|
}
|
|
357
375
|
export function calPaymentTotal(info) {
|
|
376
|
+
if (!info || !info.payments)
|
|
377
|
+
return {};
|
|
358
378
|
let groupByPaymnets = _map(info.payments, (p) => ({
|
|
359
379
|
name_lan_p: p.name_lan_p,
|
|
360
380
|
name_lan_s: p.name_lan_s,
|
|
@@ -380,6 +400,8 @@ export function calcClosingCashBalance(closing, opening_start_cash) {
|
|
|
380
400
|
(preventNaN(closing.closing_cash_add || 0) - preventNaN(closing.closing_cash_remove || 0)));
|
|
381
401
|
}
|
|
382
402
|
export function calcItemDiscounts(item, order_discounts, order_items_count) {
|
|
403
|
+
if (!item)
|
|
404
|
+
return 0;
|
|
383
405
|
let discounts = 0;
|
|
384
406
|
let addons = 0;
|
|
385
407
|
item?.addons?.forEach((addon) => {
|
|
@@ -406,6 +428,8 @@ export function calcItemDiscounts(item, order_discounts, order_items_count) {
|
|
|
406
428
|
return discounts;
|
|
407
429
|
}
|
|
408
430
|
export function calcItemAddons(item) {
|
|
431
|
+
if (!item)
|
|
432
|
+
return 0;
|
|
409
433
|
let addons = 0;
|
|
410
434
|
item?.addons?.forEach((addon) => {
|
|
411
435
|
if (addon.price && addon.quantity) {
|
|
@@ -415,19 +439,27 @@ export function calcItemAddons(item) {
|
|
|
415
439
|
return addons;
|
|
416
440
|
}
|
|
417
441
|
export function getInvoicesDiffrence(openning, invoices) {
|
|
442
|
+
if (!openning || !invoices || !Array.isArray(invoices))
|
|
443
|
+
return [];
|
|
418
444
|
const openningTime = moment(convertToDate(openning.cashier_opening_date));
|
|
419
445
|
return invoices.filter((invoice) => {
|
|
446
|
+
if (!invoice)
|
|
447
|
+
return false;
|
|
420
448
|
const invoiceDate = moment(convertToDate(invoice.order_date));
|
|
421
449
|
return invoiceDate.isBefore(openningTime);
|
|
422
450
|
});
|
|
423
451
|
}
|
|
424
452
|
export function getActiveInvoices(invoices) {
|
|
425
|
-
|
|
453
|
+
if (!invoices || !Array.isArray(invoices))
|
|
454
|
+
return [];
|
|
455
|
+
const list = invoices.filter((invoice) => invoice && invoice.order_payments?.length === 0);
|
|
426
456
|
return list;
|
|
427
457
|
}
|
|
428
458
|
export function calcRefundedLoyaltyAmount(order, canceled_items) {
|
|
429
|
-
|
|
430
|
-
|
|
459
|
+
if (!order || !canceled_items)
|
|
460
|
+
return 0;
|
|
461
|
+
const items_count = _sum(order?.order_items?.map((o) => o?.quantity || 0) || [0]) + _sum(order?.canceled_items?.map((o) => o?.quantity || 0) || [0]);
|
|
462
|
+
const canceled_items_count = _sum(canceled_items?.map((o) => o?.quantity || 0) || [0]);
|
|
431
463
|
return ((order?.loyalty_amount || 0) / items_count) * canceled_items_count;
|
|
432
464
|
}
|
|
433
465
|
export function WithVat(price, branch_vat) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calcs.d.ts","sourceRoot":"","sources":["../../../src/Calcs.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,MAAM,EACN,cAAc,EACd,cAAc,
|
|
1
|
+
{"version":3,"file":"Calcs.d.ts","sourceRoot":"","sources":["../../../src/Calcs.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,MAAM,EACN,cAAc,EACd,cAAc,EACd,KAAK,EACL,aAAa,EACb,aAAa,EACb,SAAS,EACT,QAAQ,EAER,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,MAAM,SAAS,CAAC;AAGjB,wBAAgB,SAAS,CACxB,UAAU,EAAE,SAAS,EACrB,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,WAAW,CAAC,EAAE,QAAQ,EAAE,EACxB,eAAe,CAAC,EAAE,aAAa,EAAE,EACjC,iBAAiB,SAAI,UAmDrB;AAED,wBAAgB,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,UAKvD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,SAAS,UAe7C;AAED,wBAAgB,SAAS,CACxB,eAAe,EAAE,aAAa,EAAE,GAAG,IAAI,EACvC,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,EAC/B,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,UA8CzB;AAED,wBAAgB,gBAAgB,CAC/B,eAAe,EAAE,aAAa,EAAE,GAAG,IAAI,EACvC,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,EAC/B,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,UAAU,EAAE,MAAM,GAAG,IAAI,UAgDzB;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,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