sahab-utils 1.2.2 → 1.2.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/constants/types.ts +23 -0
- package/package.json +1 -1
- package/ts/calcs.ts +27 -6
package/constants/types.ts
CHANGED
|
@@ -745,3 +745,26 @@ export type PaymentConfigs = {
|
|
|
745
745
|
priority: number;
|
|
746
746
|
}[];
|
|
747
747
|
};
|
|
748
|
+
|
|
749
|
+
export type Slot = {
|
|
750
|
+
id: string;
|
|
751
|
+
time: number;
|
|
752
|
+
selected: boolean;
|
|
753
|
+
reserved: boolean;
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
export type Statement = {
|
|
757
|
+
numberOfOrders: number;
|
|
758
|
+
completedOrders: number;
|
|
759
|
+
ratedOrders: number;
|
|
760
|
+
cancelledOrders: number;
|
|
761
|
+
cashOrders: number;
|
|
762
|
+
creditOrders: number;
|
|
763
|
+
applePayPayments: number;
|
|
764
|
+
expiredOrders: number;
|
|
765
|
+
confirmedOrders: number;
|
|
766
|
+
lateOrders: number;
|
|
767
|
+
ordersTotal: number;
|
|
768
|
+
orders: Order[];
|
|
769
|
+
statmentDate?: Date | string;
|
|
770
|
+
};
|
package/package.json
CHANGED
package/ts/calcs.ts
CHANGED
|
@@ -35,9 +35,19 @@ export function getSahabDiscountsAmount(order: Order) {
|
|
|
35
35
|
discounts += 0.05 * orderTotal;
|
|
36
36
|
} else if (order?.promoCode?.amount && order?.promoCode?.amount > 0 && !order?.promoCode?.createdByProvider) {
|
|
37
37
|
if (order?.promoCode?.isPercentage) {
|
|
38
|
-
|
|
38
|
+
const amount = (preventNaN(order?.promoCode?.amount) / 100) * orderTotal;
|
|
39
|
+
if (order?.promoCode?.maxAmount && order?.promoCode?.maxAmount > 0) {
|
|
40
|
+
discounts += Math.min(amount, order?.promoCode?.maxAmount);
|
|
41
|
+
} else {
|
|
42
|
+
discounts += amount;
|
|
43
|
+
}
|
|
39
44
|
} else {
|
|
40
|
-
|
|
45
|
+
const amount = preventNaN(order?.promoCode?.amount);
|
|
46
|
+
if (order?.promoCode?.maxAmount && order?.promoCode?.maxAmount > 0) {
|
|
47
|
+
discounts += Math.min(amount, order?.promoCode?.maxAmount);
|
|
48
|
+
} else {
|
|
49
|
+
discounts += amount;
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
53
|
|
|
@@ -77,9 +87,20 @@ export function getProviderDiscountsAmount(order: Order) {
|
|
|
77
87
|
discounts += 0.05 * orderTotal;
|
|
78
88
|
} else if (order?.promoCode?.amount && order?.promoCode?.amount > 0 && order?.promoCode?.createdByProvider) {
|
|
79
89
|
if (order?.promoCode?.isPercentage) {
|
|
80
|
-
|
|
90
|
+
const amount = (preventNaN(order?.promoCode?.amount) / 100) * orderTotal;
|
|
91
|
+
if (order?.promoCode?.maxAmount && order?.promoCode?.maxAmount > 0) {
|
|
92
|
+
discounts += Math.min(amount, order?.promoCode?.maxAmount);
|
|
93
|
+
} else {
|
|
94
|
+
discounts += amount;
|
|
95
|
+
}
|
|
81
96
|
} else {
|
|
82
|
-
|
|
97
|
+
const amount = preventNaN(order?.promoCode?.amount);
|
|
98
|
+
|
|
99
|
+
if (order?.promoCode?.maxAmount && order?.promoCode?.maxAmount > 0) {
|
|
100
|
+
discounts += Math.min(amount, order?.promoCode?.maxAmount);
|
|
101
|
+
} else {
|
|
102
|
+
discounts += amount;
|
|
103
|
+
}
|
|
83
104
|
}
|
|
84
105
|
}
|
|
85
106
|
|
|
@@ -231,7 +252,7 @@ export function calculateDiscountAmount(order: Order) {
|
|
|
231
252
|
|
|
232
253
|
if (sahabDiscounts.length) {
|
|
233
254
|
sahabDiscounts.forEach((discount) => {
|
|
234
|
-
if (discount
|
|
255
|
+
if (discount?.isPercentage) {
|
|
235
256
|
discounts += (preventNaN(discount?.amount ?? 0) / 100) * (service?.price?.price ?? 0);
|
|
236
257
|
} else {
|
|
237
258
|
discounts += preventNaN(discount?.amount ?? 0);
|
|
@@ -253,7 +274,7 @@ export function getServiceTotal(providedService: ProvidedService | ProvidedAddon
|
|
|
253
274
|
|
|
254
275
|
if (sahabDiscounts.length) {
|
|
255
276
|
sahabDiscounts.forEach((discount) => {
|
|
256
|
-
if (discount
|
|
277
|
+
if (discount?.isPercentage) {
|
|
257
278
|
total -= (preventNaN(discount?.amount ?? 0) / 100) * (providedService?.price?.price ?? 0);
|
|
258
279
|
} else {
|
|
259
280
|
total -= preventNaN(discount?.amount ?? 0);
|