lazywait-calcs 1.0.0 → 1.0.2
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 +433 -0
- package/lib/cjs/index.js +7 -0
- package/lib/cjs/types/Calcs.d.ts +43 -0
- package/lib/cjs/types/Calcs.d.ts.map +1 -0
- package/lib/cjs/types/index.d.ts +3 -0
- package/lib/cjs/types/index.d.ts.map +1 -0
- package/lib/cjs/types/types.d.ts +767 -0
- package/lib/cjs/types/types.d.ts.map +1 -0
- package/lib/cjs/types/utils.d.ts +7 -0
- package/lib/cjs/types/utils.d.ts.map +1 -0
- package/lib/cjs/types.js +2 -0
- package/lib/cjs/utils.js +48 -0
- package/lib/esm/Calcs.js +417 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/types/Calcs.d.ts +43 -0
- package/lib/esm/types/Calcs.d.ts.map +1 -0
- package/lib/esm/types/index.d.ts +3 -0
- package/lib/esm/types/index.d.ts.map +1 -0
- package/lib/esm/types/types.d.ts +767 -0
- package/lib/esm/types/types.d.ts.map +1 -0
- package/lib/esm/types/utils.d.ts +7 -0
- package/lib/esm/types/utils.d.ts.map +1 -0
- package/lib/esm/types.js +1 -0
- package/lib/esm/utils.js +40 -0
- package/package.json +10 -2
package/lib/cjs/Calcs.js
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
function ItemTotal(order_item, branch_vat, order_taxes, order_discounts, order_items_count = 1) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
let total = 0;
|
|
12
|
+
const vat = branch_vat ? 1 + branch_vat / 100 : 1;
|
|
13
|
+
if (order_item.price && order_item.quantity) {
|
|
14
|
+
let price = order_item.price;
|
|
15
|
+
(_a = order_item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
|
|
16
|
+
if (addon.price && addon.quantity) {
|
|
17
|
+
price += addon.price * addon.quantity;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const discounts = calcItemDiscounts(order_item, order_discounts, order_items_count);
|
|
21
|
+
price -= discounts;
|
|
22
|
+
let item_tax = lodash_1.default.sum((_b = order_item.taxes) === null || _b === void 0 ? void 0 : _b.map((tax) => {
|
|
23
|
+
return tax.isPercent ? ((tax.amount || 0) / 100) * price : tax.amount || 0;
|
|
24
|
+
}));
|
|
25
|
+
if (order_taxes) {
|
|
26
|
+
price += lodash_1.default.sum((order_taxes === null || order_taxes === void 0 ? void 0 : order_taxes.map((_tax) => {
|
|
27
|
+
return _tax.isPercent ? ((_tax.amount || 0) / 100) * price : (_tax.amount || 0) / order_items_count;
|
|
28
|
+
})) || [0]);
|
|
29
|
+
}
|
|
30
|
+
if (order_item.not_taxable) {
|
|
31
|
+
total = price * order_item.quantity;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
total = (price + item_tax) * order_item.quantity * vat;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return total;
|
|
38
|
+
}
|
|
39
|
+
function Subtotal(order_items) {
|
|
40
|
+
if (order_items && order_items.length) {
|
|
41
|
+
return lodash_1.default.sum(order_items.map(calcItem));
|
|
42
|
+
}
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
function calcItem(order_item) {
|
|
46
|
+
var _a;
|
|
47
|
+
let result = 0;
|
|
48
|
+
(_a = order_item === null || order_item === void 0 ? void 0 : order_item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
|
|
49
|
+
if (addon.price && addon.quantity) {
|
|
50
|
+
result += addon.price * addon.quantity;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (order_item.price && order_item.quantity) {
|
|
54
|
+
return (result + order_item.price) * order_item.quantity;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function Discounts(order_discounts, order_items, loyalty_amount, branch_vat) {
|
|
59
|
+
let discounts = 0;
|
|
60
|
+
const subtotal = Subtotal(order_items);
|
|
61
|
+
if (order_discounts) {
|
|
62
|
+
order_discounts.forEach((discount) => {
|
|
63
|
+
if (discount.amount) {
|
|
64
|
+
let is_percentage = discount.is_percentage || false;
|
|
65
|
+
let is_spendAtleast = discount.spends_at_least || false;
|
|
66
|
+
let amount = 0;
|
|
67
|
+
if (is_percentage)
|
|
68
|
+
amount = (subtotal * discount.amount) / 100;
|
|
69
|
+
else if (is_spendAtleast && subtotal >= discount.spends_at_least_amount) {
|
|
70
|
+
amount = discount.amount;
|
|
71
|
+
}
|
|
72
|
+
else if (is_spendAtleast && subtotal < discount.spends_at_least_amount) {
|
|
73
|
+
null;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
amount = discount.amount;
|
|
77
|
+
}
|
|
78
|
+
discounts += amount;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
order_items === null || order_items === void 0 ? void 0 : order_items.forEach((order_item) => {
|
|
83
|
+
var _a;
|
|
84
|
+
(_a = order_item === null || order_item === void 0 ? void 0 : order_item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
|
|
85
|
+
var _a;
|
|
86
|
+
if (discount.is_percentage && discount.amount) {
|
|
87
|
+
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; });
|
|
88
|
+
const addons_total = lodash_1.default.sum(addons_arr);
|
|
89
|
+
discounts += (order_item.price + (addons_total || 0)) * order_item.quantity * (discount.amount / 100);
|
|
90
|
+
}
|
|
91
|
+
else if (discount.amount) {
|
|
92
|
+
discounts += discount.amount * order_item.quantity;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
if (loyalty_amount) {
|
|
97
|
+
if (branch_vat) {
|
|
98
|
+
const vat = 1 + branch_vat / 100;
|
|
99
|
+
discounts += loyalty_amount / vat;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
discounts += loyalty_amount;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return discounts;
|
|
106
|
+
}
|
|
107
|
+
function DiscountsWithVat(order_discounts, order_items, loyalty_amount, branch_vat) {
|
|
108
|
+
let discounts = 0;
|
|
109
|
+
const subtotal = Subtotal(order_items);
|
|
110
|
+
if (order_discounts) {
|
|
111
|
+
order_discounts.forEach((discount) => {
|
|
112
|
+
if (discount.amount) {
|
|
113
|
+
let is_percentage = discount.is_percentage || false;
|
|
114
|
+
let is_spendAtleast = discount.spends_at_least || false;
|
|
115
|
+
let amount = 0;
|
|
116
|
+
if (is_percentage)
|
|
117
|
+
amount = (subtotal * discount.amount) / 100;
|
|
118
|
+
else if (is_spendAtleast && subtotal >= discount.spends_at_least_amount) {
|
|
119
|
+
amount = discount.amount;
|
|
120
|
+
}
|
|
121
|
+
else if (is_spendAtleast && subtotal < discount.spends_at_least_amount) {
|
|
122
|
+
null;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
amount = discount.amount;
|
|
126
|
+
}
|
|
127
|
+
discounts += amount;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
order_items === null || order_items === void 0 ? void 0 : order_items.forEach((order_item) => {
|
|
132
|
+
var _a;
|
|
133
|
+
(_a = order_item === null || order_item === void 0 ? void 0 : order_item.discounts) === null || _a === void 0 ? void 0 : _a.forEach((discount) => {
|
|
134
|
+
var _a;
|
|
135
|
+
if (!order_item.not_taxable) {
|
|
136
|
+
if (discount.is_percentage && discount.amount) {
|
|
137
|
+
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) => (a.price || 0) * (a.quantity || 0));
|
|
138
|
+
const addons_total = lodash_1.default.sum(addons_arr);
|
|
139
|
+
discounts += (order_item.price + (addons_total || 0)) * order_item.quantity * (discount.amount / 100);
|
|
140
|
+
}
|
|
141
|
+
else if (discount.amount) {
|
|
142
|
+
discounts += discount.amount * order_item.quantity;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
if (loyalty_amount) {
|
|
148
|
+
if (branch_vat) {
|
|
149
|
+
const vat = 1 + branch_vat / 100;
|
|
150
|
+
discounts += loyalty_amount / vat;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
discounts += loyalty_amount;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return discounts;
|
|
157
|
+
}
|
|
158
|
+
function ItemVat(order_item, branch_vat) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
const vat = branch_vat ? branch_vat / 100 : 1;
|
|
161
|
+
let addons = 0;
|
|
162
|
+
(_a = order_item === null || order_item === void 0 ? void 0 : order_item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
|
|
163
|
+
if (addon.price && addon.quantity) {
|
|
164
|
+
addons += (0, utils_1.toFixedFloat)(addon.price * addon.quantity);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
let discounts = 0;
|
|
168
|
+
(_b = order_item.discounts) === null || _b === void 0 ? void 0 : _b.forEach((discount) => {
|
|
169
|
+
if (discount.is_percentage && discount.amount) {
|
|
170
|
+
discounts += (0, utils_1.toFixedFloat)((order_item.price + addons) * order_item.quantity * (discount.amount / 100));
|
|
171
|
+
}
|
|
172
|
+
else if (discount.amount) {
|
|
173
|
+
discounts += (0, utils_1.toFixedFloat)(discount.amount * order_item.quantity);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const price = order_item.price + addons - discounts;
|
|
177
|
+
return order_item.not_taxable ? 0 : (0, utils_1.toFixedFloat)(price * vat);
|
|
178
|
+
}
|
|
179
|
+
function Vat(order, order_items, loyalty_amount, branch_vat) {
|
|
180
|
+
if (branch_vat && order_items.some((o) => !o.not_taxable)) {
|
|
181
|
+
const discount = DiscountsWithVat((order === null || order === void 0 ? void 0 : order.order_discounts) || [], order_items, (order === null || order === void 0 ? void 0 : order.loyalty_amount) || 0, branch_vat);
|
|
182
|
+
// Other charges for taxable items
|
|
183
|
+
const other_charges = Number(OtherCharges(order_items.filter((i) => !i.not_taxable), order, loyalty_amount, branch_vat));
|
|
184
|
+
// Order delivery
|
|
185
|
+
const deliveries = Deliveries((order === null || order === void 0 ? void 0 : order.order_deliveries) || []);
|
|
186
|
+
// subtotal of items with vat
|
|
187
|
+
let sub_total = lodash_1.default.sum(order_items.filter((i) => !i.not_taxable).map(calcItem));
|
|
188
|
+
// VAT amount
|
|
189
|
+
const vat = ((branch_vat || 0) / 100) * (sub_total + other_charges + deliveries - discount);
|
|
190
|
+
return vat >= 0 ? vat : 0;
|
|
191
|
+
}
|
|
192
|
+
return 0;
|
|
193
|
+
}
|
|
194
|
+
function TaxableAmount(order_items) {
|
|
195
|
+
return lodash_1.default.sum((order_items || []).filter((i) => !i.not_taxable).map(calcItem));
|
|
196
|
+
}
|
|
197
|
+
function NonTaxableAmount(order_items) {
|
|
198
|
+
return lodash_1.default.sum((order_items || []).filter((i) => i.not_taxable).map(calcItem));
|
|
199
|
+
}
|
|
200
|
+
function Deliveries(order_deliveries) {
|
|
201
|
+
let sum = 0;
|
|
202
|
+
if (order_deliveries) {
|
|
203
|
+
(order_deliveries || []).forEach((d) => {
|
|
204
|
+
if (d.delivery_type === 'RADIUS') {
|
|
205
|
+
sum += (d.delivery_fee || 0) * (d.delivery_radius || 1);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
sum += d.delivery_fee || 0;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return sum;
|
|
213
|
+
}
|
|
214
|
+
function OtherCharges(order_items, order, loyalty_amount, branch_vat) {
|
|
215
|
+
const sub = Subtotal(order_items);
|
|
216
|
+
const discounts = Number(Discounts((order === null || order === void 0 ? void 0 : order.order_deliveries) || [], order_items, loyalty_amount, branch_vat));
|
|
217
|
+
let other_charges = 0;
|
|
218
|
+
if (order === null || order === void 0 ? void 0 : order.order_taxes) {
|
|
219
|
+
other_charges = (order === null || order === void 0 ? void 0 : order.order_taxes)
|
|
220
|
+
? lodash_1.default.sum(order === null || order === void 0 ? void 0 : order.order_taxes.map((tax) => {
|
|
221
|
+
if (tax.amount) {
|
|
222
|
+
let result = tax.isPercent ? (tax.amount / 100) * (sub - discounts) : tax.amount;
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
return 0;
|
|
226
|
+
}))
|
|
227
|
+
: 0;
|
|
228
|
+
}
|
|
229
|
+
order_items.forEach((order_item) => {
|
|
230
|
+
var _a, _b, _c;
|
|
231
|
+
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)));
|
|
232
|
+
const price = (order_item.price + addons_total) * order_item.quantity;
|
|
233
|
+
let _discounts = 0;
|
|
234
|
+
(_b = order_item === null || order_item === void 0 ? void 0 : order_item.discounts) === null || _b === void 0 ? void 0 : _b.forEach((discount) => {
|
|
235
|
+
if (discount.is_percentage && discount.amount) {
|
|
236
|
+
_discounts += price * (discount.amount / 100);
|
|
237
|
+
}
|
|
238
|
+
else if (discount.amount) {
|
|
239
|
+
_discounts += discount.amount * order_item.quantity;
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
const order_items_count = lodash_1.default.sum(order_items.map((i) => i.quantity));
|
|
243
|
+
order === null || order === void 0 ? void 0 : order.order_discounts.forEach((discount) => {
|
|
244
|
+
if (discount.is_percentage && discount.amount) {
|
|
245
|
+
_discounts += price * (discount.amount / 100);
|
|
246
|
+
}
|
|
247
|
+
else if (discount.amount) {
|
|
248
|
+
_discounts += (discount.amount / order_items_count) * order_item.quantity;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
(_c = order_item === null || order_item === void 0 ? void 0 : order_item.taxes) === null || _c === void 0 ? void 0 : _c.forEach((tax) => {
|
|
252
|
+
if (tax.isPercent && tax.amount) {
|
|
253
|
+
let temp = price - _discounts;
|
|
254
|
+
if (temp < 0) {
|
|
255
|
+
temp = 0;
|
|
256
|
+
}
|
|
257
|
+
other_charges += temp * (tax.amount / 100);
|
|
258
|
+
}
|
|
259
|
+
else if (tax.amount) {
|
|
260
|
+
other_charges += tax.amount * ((order_item === null || order_item === void 0 ? void 0 : order_item.quantity) || 0);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
return other_charges;
|
|
265
|
+
}
|
|
266
|
+
function printedOrderTaxes(order, loyalty_amount, branch_vat) {
|
|
267
|
+
let taxes = [];
|
|
268
|
+
if (order) {
|
|
269
|
+
const sub = Subtotal(order.order_items);
|
|
270
|
+
const discounts = Number(Discounts((order === null || order === void 0 ? void 0 : order.order_discounts) || [], order.order_items, loyalty_amount, branch_vat));
|
|
271
|
+
if (order && order.order_taxes) {
|
|
272
|
+
order.order_taxes.forEach((tax) => {
|
|
273
|
+
if (tax.amount) {
|
|
274
|
+
taxes.push({
|
|
275
|
+
tax_id: tax.tax_id || '',
|
|
276
|
+
name_lan_p: tax.name_lan_p || '',
|
|
277
|
+
name_lan_s: tax.name_lan_s || '',
|
|
278
|
+
isPercent: tax.isPercent,
|
|
279
|
+
amount: tax.amount,
|
|
280
|
+
total: tax.isPercent ? (tax.amount / 100) * (sub - discounts) : tax.amount,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
const order_items_count = lodash_1.default.sum(order.order_items.map((i) => i.quantity));
|
|
286
|
+
const item_taxes = order.order_items.reduce((list, order_item) => {
|
|
287
|
+
var _a;
|
|
288
|
+
const addons_amount = calcItemAddons(order_item);
|
|
289
|
+
(_a = order_item === null || order_item === void 0 ? void 0 : order_item.taxes) === null || _a === void 0 ? void 0 : _a.forEach((tax) => {
|
|
290
|
+
let _discounts = calcItemDiscounts(order_item, order.order_discounts, order_items_count);
|
|
291
|
+
if (tax.tax_id) {
|
|
292
|
+
let charge = 0;
|
|
293
|
+
if (tax.isPercent && tax.amount) {
|
|
294
|
+
charge = ((tax.amount || 0) / 100) * (order_item.price + addons_amount - _discounts) * order_item.quantity;
|
|
295
|
+
}
|
|
296
|
+
else if (tax.amount) {
|
|
297
|
+
charge = (tax.amount || 0) * order_item.quantity;
|
|
298
|
+
}
|
|
299
|
+
if (!list.some((t) => t.tax_id === tax.tax_id)) {
|
|
300
|
+
list.push({
|
|
301
|
+
tax_id: tax.tax_id,
|
|
302
|
+
name_lan_p: tax.name_lan_p || '',
|
|
303
|
+
name_lan_s: tax.name_lan_s,
|
|
304
|
+
isPercent: tax.isPercent,
|
|
305
|
+
amount: tax.amount || 0,
|
|
306
|
+
total: charge,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
list = list.map((t) => (t.tax_id !== tax.tax_id ? t : Object.assign(Object.assign({}, t), { total: t.total + charge })));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
return list;
|
|
315
|
+
}, []);
|
|
316
|
+
return lodash_1.default.concat(taxes, item_taxes);
|
|
317
|
+
}
|
|
318
|
+
return taxes;
|
|
319
|
+
}
|
|
320
|
+
function Total(order, order_items, loyalty_amount, branch_vat) {
|
|
321
|
+
const sub = Number(Subtotal(order_items));
|
|
322
|
+
const discounts = Number(Discounts((order === null || order === void 0 ? void 0 : order.order_discounts) || [], order_items, loyalty_amount, branch_vat));
|
|
323
|
+
const other_charges = Number(OtherCharges(order_items, order, loyalty_amount, branch_vat));
|
|
324
|
+
const vat = Number(Vat(order, order_items, loyalty_amount, branch_vat));
|
|
325
|
+
const deliveries = Number(Deliveries((order === null || order === void 0 ? void 0 : order.order_deliveries) || []));
|
|
326
|
+
const total = (0, utils_1.toFixedFloat)(sub - discounts + other_charges + vat + deliveries);
|
|
327
|
+
if (total < 0)
|
|
328
|
+
return 0;
|
|
329
|
+
return total;
|
|
330
|
+
}
|
|
331
|
+
function calcPaymentBalanceDue(invoice, branch) {
|
|
332
|
+
let due = (invoice.total || 0) - (invoice.received_amount || 0);
|
|
333
|
+
if (branch && branch.payment_methods) {
|
|
334
|
+
branch.payment_methods.forEach((payment) => {
|
|
335
|
+
due -= payment.payment_amount || 0;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return due > 0 ? due : 0;
|
|
339
|
+
}
|
|
340
|
+
function calPaymentTotal(info) {
|
|
341
|
+
let groupByPaymnets = lodash_1.default.map(info.payments, (p) => ({
|
|
342
|
+
name_lan_p: p.name_lan_p,
|
|
343
|
+
name_lan_s: p.name_lan_s,
|
|
344
|
+
amount: p.payment_amount,
|
|
345
|
+
}));
|
|
346
|
+
groupByPaymnets = groupByPaymnets.reduce(function (result, acc) {
|
|
347
|
+
if (acc.name_lan_p !== 'CASH_ADD' && acc.name_lan_p !== 'CASH_REMOVE') {
|
|
348
|
+
result[acc.name_lan_p] = result[acc.name_lan_p] || [];
|
|
349
|
+
var val = (0, utils_1.toFixedFloat)(result[acc.name_lan_p].payment_amount) || 0;
|
|
350
|
+
result[acc.name_lan_p] = {
|
|
351
|
+
name_lan_p: acc.name_lan_p,
|
|
352
|
+
name_lan_s: acc.name_lan_s,
|
|
353
|
+
payment_amount: val + (0, utils_1.toFixedFloat)(acc.amount),
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
return result;
|
|
357
|
+
}, {});
|
|
358
|
+
return groupByPaymnets;
|
|
359
|
+
}
|
|
360
|
+
function calcClosingCashBalance(closing, opening_start_cash) {
|
|
361
|
+
return ((0, utils_1.preventNaN)(closing.closing_cash_sales || 0) +
|
|
362
|
+
(0, utils_1.preventNaN)(opening_start_cash || 0) +
|
|
363
|
+
((0, utils_1.preventNaN)(closing.closing_cash_add || 0) - (0, utils_1.preventNaN)(closing.closing_cash_remove || 0)));
|
|
364
|
+
}
|
|
365
|
+
function calcItemDiscounts(item, order_discounts, order_items_count) {
|
|
366
|
+
var _a, _b;
|
|
367
|
+
let discounts = 0;
|
|
368
|
+
let addons = 0;
|
|
369
|
+
(_a = item === null || item === void 0 ? void 0 : item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
|
|
370
|
+
if (addon.price && addon.quantity) {
|
|
371
|
+
addons += addon.price * addon.quantity;
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
(_b = item.discounts) === null || _b === void 0 ? void 0 : _b.forEach((discount) => {
|
|
375
|
+
if (discount.is_percentage && discount.amount) {
|
|
376
|
+
discounts += (item.price + addons) * (discount.amount / 100);
|
|
377
|
+
}
|
|
378
|
+
else if (discount.amount) {
|
|
379
|
+
discounts += discount.amount;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
order_discounts === null || order_discounts === void 0 ? void 0 : order_discounts.forEach((discount) => {
|
|
383
|
+
if (discount.is_percentage && discount.amount) {
|
|
384
|
+
discounts += (item.price + addons) * (discount.amount / 100);
|
|
385
|
+
}
|
|
386
|
+
else if (discount.amount) {
|
|
387
|
+
discounts += discount.amount / order_items_count;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
return discounts;
|
|
391
|
+
}
|
|
392
|
+
function calcItemAddons(item) {
|
|
393
|
+
var _a;
|
|
394
|
+
let addons = 0;
|
|
395
|
+
(_a = item === null || item === void 0 ? void 0 : item.addons) === null || _a === void 0 ? void 0 : _a.forEach((addon) => {
|
|
396
|
+
if (addon.price && addon.quantity) {
|
|
397
|
+
addons += addon.price * addon.quantity;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
return addons;
|
|
401
|
+
}
|
|
402
|
+
function getInvoicesDiffrence(openning, invoices) {
|
|
403
|
+
const now = (0, moment_1.default)();
|
|
404
|
+
const openningTime = (0, moment_1.default)((0, utils_1.convertToDate)(openning.cashier_opening_date));
|
|
405
|
+
const orders = invoices.map((invoice) => {
|
|
406
|
+
const invoiceDate = (0, moment_1.default)((0, utils_1.convertToDate)(invoice.order_date));
|
|
407
|
+
if (!invoiceDate.isBetween(openningTime, now)) {
|
|
408
|
+
return invoice;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return orders;
|
|
412
|
+
}
|
|
413
|
+
exports.default = {
|
|
414
|
+
ItemTotal,
|
|
415
|
+
Subtotal,
|
|
416
|
+
calcItem,
|
|
417
|
+
Discounts,
|
|
418
|
+
DiscountsWithVat,
|
|
419
|
+
ItemVat,
|
|
420
|
+
Vat,
|
|
421
|
+
TaxableAmount,
|
|
422
|
+
NonTaxableAmount,
|
|
423
|
+
Deliveries,
|
|
424
|
+
OtherCharges,
|
|
425
|
+
printedOrderTaxes,
|
|
426
|
+
Total,
|
|
427
|
+
calcPaymentBalanceDue,
|
|
428
|
+
calPaymentTotal,
|
|
429
|
+
calcClosingCashBalance,
|
|
430
|
+
calcItemDiscounts,
|
|
431
|
+
calcItemAddons,
|
|
432
|
+
getInvoicesDiffrence,
|
|
433
|
+
};
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Calcs_1 = __importDefault(require("./Calcs"));
|
|
7
|
+
exports.default = Calcs_1.default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Branch, CashierClosing, Order, OrderDiscount, OrderItem, OrderTax, PrintedTax, CashierOpening, OrderDelivery } from './types';
|
|
2
|
+
declare function ItemTotal(order_item: OrderItem, branch_vat: number | null, order_taxes?: OrderTax[], order_discounts?: OrderDiscount[], order_items_count?: number): number;
|
|
3
|
+
declare function Subtotal(order_items: OrderItem[] | null): number;
|
|
4
|
+
declare function calcItem(order_item: OrderItem): number;
|
|
5
|
+
declare function Discounts(order_discounts: OrderDiscount[] | null, order_items: OrderItem[] | null, loyalty_amount: number | null, branch_vat: number | null): number;
|
|
6
|
+
declare function DiscountsWithVat(order_discounts: OrderDiscount[] | null, order_items: OrderItem[] | null, loyalty_amount: number | null, branch_vat: number | null): number;
|
|
7
|
+
declare function ItemVat(order_item: OrderItem, branch_vat: number | null): number;
|
|
8
|
+
declare function Vat(order: Order | null, order_items: OrderItem[], loyalty_amount: number | null, branch_vat: number | null): number;
|
|
9
|
+
declare function TaxableAmount(order_items: OrderItem[] | null): number;
|
|
10
|
+
declare function NonTaxableAmount(order_items: OrderItem[] | null): number;
|
|
11
|
+
declare function Deliveries(order_deliveries: OrderDelivery[] | null): number;
|
|
12
|
+
declare function OtherCharges(order_items: OrderItem[], order: Order | null, loyalty_amount: number | null, branch_vat: number | null): number;
|
|
13
|
+
declare function printedOrderTaxes(order: Order | null, loyalty_amount: number | null, branch_vat: number | null): PrintedTax[];
|
|
14
|
+
declare function Total(order: Order | null, order_items: OrderItem[], loyalty_amount: number | null, branch_vat: number | null): number;
|
|
15
|
+
declare function calcPaymentBalanceDue(invoice: Order, branch: Branch): number;
|
|
16
|
+
declare function calPaymentTotal(info: any): any;
|
|
17
|
+
declare function calcClosingCashBalance(closing: Partial<CashierClosing>, opening_start_cash: number | undefined): number;
|
|
18
|
+
declare function calcItemDiscounts(item: OrderItem, order_discounts: OrderDiscount[] | undefined, order_items_count: number): number;
|
|
19
|
+
declare function calcItemAddons(item: OrderItem): number;
|
|
20
|
+
declare function getInvoicesDiffrence(openning: CashierOpening, invoices: Order[]): (Order | undefined)[];
|
|
21
|
+
declare const _default: {
|
|
22
|
+
ItemTotal: typeof ItemTotal;
|
|
23
|
+
Subtotal: typeof Subtotal;
|
|
24
|
+
calcItem: typeof calcItem;
|
|
25
|
+
Discounts: typeof Discounts;
|
|
26
|
+
DiscountsWithVat: typeof DiscountsWithVat;
|
|
27
|
+
ItemVat: typeof ItemVat;
|
|
28
|
+
Vat: typeof Vat;
|
|
29
|
+
TaxableAmount: typeof TaxableAmount;
|
|
30
|
+
NonTaxableAmount: typeof NonTaxableAmount;
|
|
31
|
+
Deliveries: typeof Deliveries;
|
|
32
|
+
OtherCharges: typeof OtherCharges;
|
|
33
|
+
printedOrderTaxes: typeof printedOrderTaxes;
|
|
34
|
+
Total: typeof Total;
|
|
35
|
+
calcPaymentBalanceDue: typeof calcPaymentBalanceDue;
|
|
36
|
+
calPaymentTotal: typeof calPaymentTotal;
|
|
37
|
+
calcClosingCashBalance: typeof calcClosingCashBalance;
|
|
38
|
+
calcItemDiscounts: typeof calcItemDiscounts;
|
|
39
|
+
calcItemAddons: typeof calcItemAddons;
|
|
40
|
+
getInvoicesDiffrence: typeof getInvoicesDiffrence;
|
|
41
|
+
};
|
|
42
|
+
export default _default;
|
|
43
|
+
//# sourceMappingURL=Calcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Calcs.d.ts","sourceRoot":"","sources":["../../../src/Calcs.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAiB,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGtJ,iBAAS,SAAS,CACjB,UAAU,EAAE,SAAS,EACrB,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,WAAW,CAAC,EAAE,QAAQ,EAAE,EACxB,eAAe,CAAC,EAAE,aAAa,EAAE,EACjC,iBAAiB,SAAI,UAqCrB;AAED,iBAAS,QAAQ,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,IAAI,UAKhD;AAED,iBAAS,QAAQ,CAAC,UAAU,E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