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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sahab-utils",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "This package containts types and utils fuctions",
5
5
  "main": "index.ts",
6
6
  "scripts": {
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
- discounts += (preventNaN(order?.promoCode?.amount) / 100) * orderTotal;
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
- discounts += preventNaN(order?.promoCode?.amount);
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
- discounts += (preventNaN(order?.promoCode?.amount) / 100) * orderTotal;
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
- discounts += preventNaN(order?.promoCode?.amount);
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.isPercentage) {
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.isPercentage) {
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);