@pisell/pisellos 2.2.261 → 2.2.263
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/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
- package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
- package/dist/model/strategy/adapter/index.d.ts +4 -0
- package/dist/model/strategy/adapter/index.js +5 -1
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
- package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
- package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
- package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
- package/dist/model/strategy/adapter/promotion/examples.js +0 -99
- package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/dist/model/strategy/adapter/promotion/index.js +1 -1
- package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
- package/dist/model/strategy/adapter/promotion/type.js +0 -45
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -10
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
- package/dist/modules/Discount/index.d.ts +5 -2
- package/dist/modules/Discount/index.js +30 -7
- package/dist/modules/Discount/types.d.ts +4 -0
- package/dist/modules/Order/index.d.ts +14 -2
- package/dist/modules/Order/index.js +1035 -736
- package/dist/modules/Order/types.d.ts +16 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
- package/dist/modules/Order/utils.d.ts +4 -3
- package/dist/modules/Order/utils.js +54 -61
- package/dist/modules/Product/types.d.ts +22 -0
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +4 -2
- package/dist/modules/ProductList/types.d.ts +2 -0
- package/dist/modules/Rules/index.d.ts +2 -9
- package/dist/modules/Rules/index.js +69 -43
- package/dist/modules/Rules/types.d.ts +10 -1
- package/dist/server/index.d.ts +55 -0
- package/dist/server/index.js +1173 -753
- package/dist/server/modules/order/index.d.ts +10 -4
- package/dist/server/modules/order/index.js +404 -399
- package/dist/server/modules/order/types.d.ts +4 -0
- package/dist/server/modules/products/index.d.ts +31 -8
- package/dist/server/modules/products/index.js +549 -390
- package/dist/server/modules/products/types.d.ts +18 -0
- package/dist/solution/BaseSales/index.d.ts +21 -1
- package/dist/solution/BaseSales/index.js +1136 -789
- package/dist/solution/BaseSales/types.d.ts +6 -1
- package/dist/solution/BaseSales/types.js +1 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
- package/dist/solution/BaseSales/utils/cartPromotion.js +48 -81
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +59 -25
- package/dist/solution/BookingTicket/types.d.ts +2 -0
- package/dist/solution/ScanOrder/index.js +20 -31
- package/dist/solution/ShopDiscount/index.js +15 -14
- package/dist/solution/VenueBooking/index.js +19 -30
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
- package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
- package/lib/model/strategy/adapter/index.d.ts +4 -0
- package/lib/model/strategy/adapter/index.js +13 -2
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
- package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
- package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
- package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
- package/lib/model/strategy/adapter/promotion/examples.js +0 -91
- package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +0 -51
- package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
- package/lib/model/strategy/adapter/promotion/type.js +0 -2
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
- package/lib/modules/Discount/index.d.ts +5 -2
- package/lib/modules/Discount/index.js +23 -3
- package/lib/modules/Discount/types.d.ts +4 -0
- package/lib/modules/Order/index.d.ts +14 -2
- package/lib/modules/Order/index.js +326 -60
- package/lib/modules/Order/types.d.ts +16 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
- package/lib/modules/Order/utils.d.ts +4 -3
- package/lib/modules/Order/utils.js +22 -23
- package/lib/modules/Product/types.d.ts +22 -0
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +4 -2
- package/lib/modules/ProductList/types.d.ts +2 -0
- package/lib/modules/Rules/index.d.ts +2 -9
- package/lib/modules/Rules/index.js +61 -29
- package/lib/modules/Rules/types.d.ts +10 -1
- package/lib/server/index.d.ts +55 -0
- package/lib/server/index.js +332 -34
- package/lib/server/modules/order/index.d.ts +10 -4
- package/lib/server/modules/order/index.js +198 -139
- package/lib/server/modules/order/types.d.ts +4 -0
- package/lib/server/modules/products/index.d.ts +31 -8
- package/lib/server/modules/products/index.js +134 -35
- package/lib/server/modules/products/types.d.ts +18 -0
- package/lib/solution/BaseSales/index.d.ts +21 -1
- package/lib/solution/BaseSales/index.js +313 -72
- package/lib/solution/BaseSales/types.d.ts +6 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
- package/lib/solution/BaseSales/utils/cartPromotion.js +29 -60
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +33 -8
- package/lib/solution/BookingTicket/types.d.ts +2 -0
- package/lib/solution/ScanOrder/index.js +0 -8
- package/lib/solution/ShopDiscount/index.js +2 -1
- package/lib/solution/VenueBooking/index.js +0 -8
- package/package.json +1 -1
|
@@ -41,6 +41,7 @@ var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion
|
|
|
41
41
|
var import_utils3 = require("../../solution/ScanOrder/utils");
|
|
42
42
|
var import_manualProductDiscount = require("./utils/manualProductDiscount");
|
|
43
43
|
var import_bundleDiscountHydration = require("./utils/bundleDiscountHydration");
|
|
44
|
+
var import_orderCollectionIdentity = require("./utils/orderCollectionIdentity");
|
|
44
45
|
var import_Discount = require("../Discount");
|
|
45
46
|
var import_Rules = require("../Rules");
|
|
46
47
|
var import_types2 = require("../Rules/types");
|
|
@@ -107,7 +108,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
107
108
|
this.draftPersistEnabled = true;
|
|
108
109
|
}
|
|
109
110
|
collectHydratedEditDiscounts(products) {
|
|
110
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
111
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
111
112
|
const discountMap = /* @__PURE__ */ new Map();
|
|
112
113
|
for (const product of (0, import_bundleDiscountHydration.expandHydratedProductsForDiscountCollection)(products)) {
|
|
113
114
|
for (const item of (product == null ? void 0 : product.discount_list) || []) {
|
|
@@ -137,6 +138,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
137
138
|
existed.amount = Number(existed.amount || 0) + amount;
|
|
138
139
|
existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
|
|
139
140
|
existed.balance = String(Number(existed.balance || 0) + amount);
|
|
141
|
+
const productIds = Array.isArray((_f = existed.limited_relation_product_data) == null ? void 0 : _f.product_ids) ? existed.limited_relation_product_data.product_ids : [];
|
|
142
|
+
if ((product == null ? void 0 : product.product_id) !== void 0 && (product == null ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
|
|
143
|
+
existed.limited_relation_product_data = {
|
|
144
|
+
...existed.limited_relation_product_data || {},
|
|
145
|
+
product_ids: [...productIds, product.product_id]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
140
148
|
existed.applicableProductDetails = [
|
|
141
149
|
...existed.applicableProductDetails || [],
|
|
142
150
|
detail
|
|
@@ -153,9 +161,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
153
161
|
encoded: "",
|
|
154
162
|
code: "",
|
|
155
163
|
tag: type,
|
|
156
|
-
product_id: ((
|
|
164
|
+
product_id: ((_g = item == null ? void 0 : item.discount) == null ? void 0 : _g.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
|
|
157
165
|
relation_type: "",
|
|
158
|
-
par_value: String(((
|
|
166
|
+
par_value: String(((_h = item == null ? void 0 : item.discount) == null ? void 0 : _h.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
|
|
159
167
|
used_par_value: String((item == null ? void 0 : item.amount) ?? "0"),
|
|
160
168
|
limit_status: "enable",
|
|
161
169
|
limited_relation_product_data: {
|
|
@@ -185,8 +193,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
185
193
|
discount: {
|
|
186
194
|
...(item == null ? void 0 : item.discount) || {},
|
|
187
195
|
resource_id: key,
|
|
188
|
-
discount_product_id: ((
|
|
189
|
-
discount_calculation_mode: ((
|
|
196
|
+
discount_product_id: ((_i = item == null ? void 0 : item.discount) == null ? void 0 : _i.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
|
|
197
|
+
discount_calculation_mode: ((_j = item == null ? void 0 : item.discount) == null ? void 0 : _j.discount_calculation_mode) ?? "item_level"
|
|
190
198
|
},
|
|
191
199
|
applicableProductDetails: [detail],
|
|
192
200
|
appliedProductDetails: [detail]
|
|
@@ -301,6 +309,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
301
309
|
if (!this.store.summary) {
|
|
302
310
|
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
303
311
|
}
|
|
312
|
+
if (!Array.isArray(this.store.availableWalletIds)) {
|
|
313
|
+
this.store.availableWalletIds = [];
|
|
314
|
+
}
|
|
304
315
|
this.request = this.core.getPlugin("request");
|
|
305
316
|
const appPlugin = this.core.getPlugin("app");
|
|
306
317
|
if (!appPlugin) {
|
|
@@ -428,19 +439,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
428
439
|
async loadDiscountConfig(params) {
|
|
429
440
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
430
441
|
const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
|
|
431
|
-
const
|
|
442
|
+
const prepareConfigResult = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
432
443
|
customer_id: params.customerId,
|
|
433
444
|
action: params.action || (orderId ? "edit" : "create"),
|
|
434
445
|
with_good_pass: 1,
|
|
435
446
|
with_discount_card: 1,
|
|
436
447
|
with_wallet_pass_holder: 1,
|
|
448
|
+
with_available_wallet_flag: 1,
|
|
449
|
+
with_available_wallet_pass_flag: 1,
|
|
437
450
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
438
451
|
...orderId ? { order_id: orderId } : {}
|
|
439
452
|
}));
|
|
453
|
+
const discountList = prepareConfigResult == null ? void 0 : prepareConfigResult.discountList;
|
|
454
|
+
this.store.availableWalletIds = (prepareConfigResult == null ? void 0 : prepareConfigResult.availableWalletIds) || [];
|
|
440
455
|
if (discountList) {
|
|
441
|
-
const
|
|
456
|
+
const currentDiscountList = ((_c = this.store.discount) == null ? void 0 : _c.getDiscountList()) || [];
|
|
457
|
+
const currentEditDiscounts = currentDiscountList.filter((discount) => discount == null ? void 0 : discount.isEditMode);
|
|
458
|
+
const currentScanDiscounts = currentDiscountList.filter((discount) => discount == null ? void 0 : discount.isScan);
|
|
459
|
+
const currentScanDiscountIds = new Set(
|
|
460
|
+
currentScanDiscounts.map((discount) => discount == null ? void 0 : discount.id)
|
|
461
|
+
);
|
|
442
462
|
const runtimeDiscountIds = /* @__PURE__ */ new Set();
|
|
443
463
|
const runtimeDiscounts = discountList.filter((discount) => {
|
|
464
|
+
if (currentScanDiscountIds.has(discount == null ? void 0 : discount.id))
|
|
465
|
+
return false;
|
|
444
466
|
if (runtimeDiscountIds.has(discount == null ? void 0 : discount.id))
|
|
445
467
|
return false;
|
|
446
468
|
runtimeDiscountIds.add(discount == null ? void 0 : discount.id);
|
|
@@ -448,6 +470,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
448
470
|
});
|
|
449
471
|
const mergedDiscountList = [
|
|
450
472
|
...currentEditDiscounts,
|
|
473
|
+
...currentScanDiscounts,
|
|
451
474
|
...runtimeDiscounts
|
|
452
475
|
];
|
|
453
476
|
await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(mergedDiscountList));
|
|
@@ -462,6 +485,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
462
485
|
var _a;
|
|
463
486
|
return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
464
487
|
}
|
|
488
|
+
getAvailableWalletIds() {
|
|
489
|
+
return Array.isArray(this.store.availableWalletIds) ? [...this.store.availableWalletIds] : [];
|
|
490
|
+
}
|
|
491
|
+
async syncScannedDiscountsToOriginalDiscountList(discountList) {
|
|
492
|
+
var _a, _b, _c, _d;
|
|
493
|
+
const scanDiscounts = (discountList || []).filter((discount) => discount == null ? void 0 : discount.isScan);
|
|
494
|
+
if (!scanDiscounts.length)
|
|
495
|
+
return;
|
|
496
|
+
const scanDiscountIds = new Set(scanDiscounts.map((discount) => discount == null ? void 0 : discount.id));
|
|
497
|
+
const originalDiscounts = ((_b = (_a = this.store.discount) == null ? void 0 : _a.getOriginalDiscountList) == null ? void 0 : _b.call(_a)) || [];
|
|
498
|
+
const nextOriginalDiscounts = [
|
|
499
|
+
...scanDiscounts,
|
|
500
|
+
...originalDiscounts.filter((discount) => !scanDiscountIds.has(discount == null ? void 0 : discount.id))
|
|
501
|
+
];
|
|
502
|
+
await ((_d = (_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList) == null ? void 0 : _d.call(_c, nextOriginalDiscounts));
|
|
503
|
+
}
|
|
465
504
|
async ensureEditDiscountConfigForProductChange(tempOrder) {
|
|
466
505
|
var _a, _b, _c, _d, _e, _f;
|
|
467
506
|
const orderId = tempOrder.order_id;
|
|
@@ -510,6 +549,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
510
549
|
}));
|
|
511
550
|
const currentSelected = this.getDiscountList().filter((n) => n.isSelected);
|
|
512
551
|
if (currentSelected.length && currentSelected.some((n) => withScanList.some((m) => m.id === n.id))) {
|
|
552
|
+
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
513
553
|
return {
|
|
514
554
|
type: "clientCalc",
|
|
515
555
|
isAvailable: true,
|
|
@@ -530,6 +570,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
530
570
|
if (isAvailable && newDiscountList) {
|
|
531
571
|
(_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
|
|
532
572
|
this.applyDiscount();
|
|
573
|
+
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
533
574
|
}
|
|
534
575
|
return {
|
|
535
576
|
type: "clientCalc",
|
|
@@ -539,8 +580,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
539
580
|
unavailableReason
|
|
540
581
|
};
|
|
541
582
|
}
|
|
542
|
-
applyDiscount() {
|
|
543
|
-
var _a, _b, _c
|
|
583
|
+
applyDiscount(options) {
|
|
584
|
+
var _a, _b, _c;
|
|
544
585
|
const tempOrder = this.store.tempOrder;
|
|
545
586
|
if (!tempOrder)
|
|
546
587
|
return;
|
|
@@ -553,13 +594,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
553
594
|
const rulesModule = this.store.rules;
|
|
554
595
|
if (!rulesModule)
|
|
555
596
|
return;
|
|
556
|
-
const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record) || [];
|
|
557
597
|
const result = rulesModule.calcDiscount({
|
|
558
598
|
productList: tempOrder.products,
|
|
559
599
|
discountList,
|
|
560
|
-
holders,
|
|
600
|
+
holders: [],
|
|
561
601
|
isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
|
|
562
|
-
orderTotalAmount: Number(((
|
|
602
|
+
orderTotalAmount: Number(((_b = this.store.summary) == null ? void 0 : _b.total_amount) || 0)
|
|
603
|
+
}, {
|
|
604
|
+
reapplyBookingDiscountProductUids: options == null ? void 0 : options.reapplyBookingDiscountProductUids
|
|
563
605
|
});
|
|
564
606
|
if (result == null ? void 0 : result.productList) {
|
|
565
607
|
const previousProductsByUid = (0, import_utils.indexOrderProductsByUid)(tempOrder.products);
|
|
@@ -588,7 +630,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
588
630
|
result.productList || tempOrder.products,
|
|
589
631
|
result.discountList
|
|
590
632
|
);
|
|
591
|
-
(
|
|
633
|
+
(_c = this.store.discount) == null ? void 0 : _c.setDiscountList(result.discountList);
|
|
592
634
|
}
|
|
593
635
|
this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
|
|
594
636
|
(product) => this.productHasCustomerBoundDiscount(product)
|
|
@@ -871,6 +913,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
871
913
|
return sum.plus(this.calculatePaymentEffectiveAmount(payment));
|
|
872
914
|
}, new import_decimal.default(0));
|
|
873
915
|
}
|
|
916
|
+
calculateOrderPaidPaymentTotal(payments) {
|
|
917
|
+
return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
|
|
918
|
+
includeVoided: false
|
|
919
|
+
}).reduce((sum, payment) => {
|
|
920
|
+
if (!isPaidPaymentRecord(payment))
|
|
921
|
+
return sum;
|
|
922
|
+
return sum.plus(this.calculatePaymentGapAmount(payment));
|
|
923
|
+
}, new import_decimal.default(0));
|
|
924
|
+
}
|
|
874
925
|
getDepositAmount(tempOrder, summary) {
|
|
875
926
|
return new import_decimal.default(summary.deposit_amount || tempOrder.deposit_amount || "0.00");
|
|
876
927
|
}
|
|
@@ -961,7 +1012,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
961
1012
|
const paymentList = payments || tempOrder.payments || [];
|
|
962
1013
|
const refundAmount = this.getSummaryRefundAmount(summary);
|
|
963
1014
|
const netPaidAmount = import_decimal.default.max(
|
|
964
|
-
this.
|
|
1015
|
+
this.calculateOrderPaidPaymentTotal(paymentList).minus(refundAmount),
|
|
965
1016
|
0
|
|
966
1017
|
);
|
|
967
1018
|
const depositAmount = this.getDepositAmount(tempOrder, summary);
|
|
@@ -990,11 +1041,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
990
1041
|
const isDepositPayment = paymentRecord.type === "deposit" || paymentRecord.order_payment_type === "deposit";
|
|
991
1042
|
if (!isDepositPayment)
|
|
992
1043
|
return sum;
|
|
993
|
-
|
|
994
|
-
return sum.plus(this.calculatePaymentGapAmount(paymentRecord));
|
|
995
|
-
}
|
|
996
|
-
const rounding = new import_decimal.default(paymentRecord.rounding_amount || 0);
|
|
997
|
-
return sum.plus(new import_decimal.default(paymentRecord.amount || 0).minus(rounding));
|
|
1044
|
+
return sum.plus(this.calculatePaymentGapAmount(paymentRecord));
|
|
998
1045
|
}, new import_decimal.default(0));
|
|
999
1046
|
}
|
|
1000
1047
|
resolveNextOrderPaymentType(tempOrder) {
|
|
@@ -1027,8 +1074,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1027
1074
|
updateTempOrderPaymentStatus(tempOrder, options) {
|
|
1028
1075
|
const summary = (options == null ? void 0 : options.summary) || this.store.summary || (0, import_utils.createEmptySummary)();
|
|
1029
1076
|
const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
|
|
1077
|
+
const orderPaymentTotal = this.calculateOrderPaidPaymentTotal(tempOrder.payments || []);
|
|
1030
1078
|
const refundAmount = this.getSummaryRefundAmount(summary);
|
|
1031
|
-
const netPaymentTotal = import_decimal.default.max(
|
|
1079
|
+
const netPaymentTotal = import_decimal.default.max(orderPaymentTotal.minus(refundAmount), 0);
|
|
1032
1080
|
const targetAmount = this.calculatePaymentTargetAmount(
|
|
1033
1081
|
tempOrder,
|
|
1034
1082
|
summary,
|
|
@@ -1097,7 +1145,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1097
1145
|
}
|
|
1098
1146
|
capVoucherPaymentsByRemainingAmount(params) {
|
|
1099
1147
|
const targetAmount = this.getPaymentTargetAmount();
|
|
1100
|
-
const nonVoucherTotal = this.
|
|
1148
|
+
const nonVoucherTotal = this.calculateOrderPaidPaymentTotal(params.nonVoucherPayments);
|
|
1101
1149
|
if (targetAmount.lte(0))
|
|
1102
1150
|
return [];
|
|
1103
1151
|
let remainingAmount = import_decimal.default.max(
|
|
@@ -1140,7 +1188,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1140
1188
|
return summary;
|
|
1141
1189
|
return {
|
|
1142
1190
|
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
1143
|
-
orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord
|
|
1191
|
+
orderPaidAmount: summary.orderPaidAmount.plus(this.calculatePaymentOrderAmount(paymentRecord)),
|
|
1144
1192
|
gapPaidAmount: summary.gapPaidAmount.plus(this.calculatePaymentGapAmount(paymentRecord)),
|
|
1145
1193
|
payServiceChargeAmount: summary.payServiceChargeAmount.plus(this.calculatePaymentServiceFee(paymentRecord)),
|
|
1146
1194
|
roundingAmount: summary.roundingAmount.plus(this.calculatePaymentRoundingAmount(paymentRecord))
|
|
@@ -1165,11 +1213,30 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1165
1213
|
return new import_decimal.default(payment.amount || 0).times(percentage).plus(fixedAmount);
|
|
1166
1214
|
}
|
|
1167
1215
|
calculatePaymentGapAmount(payment) {
|
|
1168
|
-
if (payment.origin_amount
|
|
1169
|
-
|
|
1216
|
+
if (payment.origin_amount !== void 0 && payment.origin_amount !== null && payment.origin_amount !== "") {
|
|
1217
|
+
const rounding2 = new import_decimal.default(payment.rounding_amount || 0);
|
|
1218
|
+
return new import_decimal.default(payment.origin_amount || 0).minus(rounding2);
|
|
1170
1219
|
}
|
|
1171
1220
|
const rounding = new import_decimal.default(payment.rounding_amount || 0);
|
|
1172
|
-
|
|
1221
|
+
const amount = new import_decimal.default(payment.amount || 0);
|
|
1222
|
+
const serviceFee = this.calculatePaymentServiceFee(payment);
|
|
1223
|
+
if (serviceFee.lte(0))
|
|
1224
|
+
return amount.minus(rounding);
|
|
1225
|
+
if (!hasSyncedOrderPaymentRecord(payment))
|
|
1226
|
+
return new import_decimal.default(0);
|
|
1227
|
+
return import_decimal.default.max(amount.minus(serviceFee), 0).minus(rounding);
|
|
1228
|
+
}
|
|
1229
|
+
calculatePaymentOrderAmount(payment) {
|
|
1230
|
+
if (payment.origin_amount !== void 0 && payment.origin_amount !== null && payment.origin_amount !== "") {
|
|
1231
|
+
return new import_decimal.default(payment.origin_amount || 0);
|
|
1232
|
+
}
|
|
1233
|
+
const amount = new import_decimal.default(payment.amount || 0);
|
|
1234
|
+
const serviceFee = this.calculatePaymentServiceFee(payment);
|
|
1235
|
+
if (serviceFee.lte(0))
|
|
1236
|
+
return amount;
|
|
1237
|
+
if (!hasSyncedOrderPaymentRecord(payment))
|
|
1238
|
+
return new import_decimal.default(0);
|
|
1239
|
+
return import_decimal.default.max(amount.minus(serviceFee), 0);
|
|
1173
1240
|
}
|
|
1174
1241
|
calculatePaymentRoundingAmount(payment) {
|
|
1175
1242
|
if (payment.rounding_amount === void 0 || payment.rounding_amount === null || payment.rounding_amount === "") {
|
|
@@ -1480,6 +1547,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1480
1547
|
}
|
|
1481
1548
|
restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
|
|
1482
1549
|
const currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
|
|
1550
|
+
const manualDepositOverride = this.getManualDepositOverride(tempOrder);
|
|
1483
1551
|
if (currentFingerprint !== snapshot.productFingerprint) {
|
|
1484
1552
|
const currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
|
|
1485
1553
|
const snapshotStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(
|
|
@@ -1488,11 +1556,24 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1488
1556
|
if (currentStructuralFingerprint !== snapshotStructuralFingerprint)
|
|
1489
1557
|
return null;
|
|
1490
1558
|
}
|
|
1491
|
-
|
|
1559
|
+
let summary = {
|
|
1492
1560
|
...(0, import_utils.createEmptySummary)(),
|
|
1493
1561
|
...(0, import_lodash_es.cloneDeep)(snapshot.summary || {})
|
|
1494
1562
|
};
|
|
1495
|
-
|
|
1563
|
+
const shouldUseManualDepositOverride = Boolean(
|
|
1564
|
+
manualDepositOverride && manualDepositOverride.productStructuralFingerprint === this.buildOrderProductsStructuralFingerprint(tempOrder.products)
|
|
1565
|
+
);
|
|
1566
|
+
if (shouldUseManualDepositOverride) {
|
|
1567
|
+
summary = this.applyDepositAmountToSummary(
|
|
1568
|
+
tempOrder,
|
|
1569
|
+
summary,
|
|
1570
|
+
manualDepositOverride.amount
|
|
1571
|
+
);
|
|
1572
|
+
} else if (manualDepositOverride) {
|
|
1573
|
+
this.clearManualDepositOverride(tempOrder);
|
|
1574
|
+
}
|
|
1575
|
+
const isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
|
|
1576
|
+
if (!isPayableAmountUnchanged)
|
|
1496
1577
|
return null;
|
|
1497
1578
|
if (Array.isArray(snapshot.products)) {
|
|
1498
1579
|
tempOrder.products = (0, import_lodash_es.cloneDeep)(snapshot.products);
|
|
@@ -1503,7 +1584,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1503
1584
|
tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
|
|
1504
1585
|
tempOrder.deposit_amount = summary.deposit_amount || "0.00";
|
|
1505
1586
|
tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
|
|
1587
|
+
const previousSummary = this.store.summary;
|
|
1506
1588
|
this.store.summary = summary;
|
|
1589
|
+
this.updateTempOrderPaymentStatus(tempOrder, {
|
|
1590
|
+
previousSummary,
|
|
1591
|
+
summary
|
|
1592
|
+
});
|
|
1507
1593
|
return summary;
|
|
1508
1594
|
}
|
|
1509
1595
|
clearPersistedAmountFieldsForFullRecalc(products) {
|
|
@@ -2192,6 +2278,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2192
2278
|
const type = (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag);
|
|
2193
2279
|
return type === "good_pass" || type === "discount_card" || type === "product_discount_card";
|
|
2194
2280
|
}
|
|
2281
|
+
shouldKeepCustomerBoundDiscountAfterCustomerChange(discount) {
|
|
2282
|
+
return Boolean((discount == null ? void 0 : discount.isScan) || (discount == null ? void 0 : discount.isEditMode));
|
|
2283
|
+
}
|
|
2195
2284
|
productHasCustomerBoundDiscount(product) {
|
|
2196
2285
|
if (((product == null ? void 0 : product.discount_list) || []).some((discount) => this.isCustomerBoundDiscount(discount))) {
|
|
2197
2286
|
return true;
|
|
@@ -2247,12 +2336,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2247
2336
|
const currentDiscounts = ((_a = discountModule.getDiscountList) == null ? void 0 : _a.call(discountModule)) || [];
|
|
2248
2337
|
const currentOriginalDiscounts = ((_b = discountModule.getOriginalDiscountList) == null ? void 0 : _b.call(discountModule)) || [];
|
|
2249
2338
|
const nextDiscounts = currentDiscounts.filter((discount) => {
|
|
2250
|
-
if (discount
|
|
2339
|
+
if (this.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount))
|
|
2251
2340
|
return true;
|
|
2252
2341
|
return !this.isCustomerBoundDiscount(discount);
|
|
2253
2342
|
});
|
|
2254
2343
|
const nextOriginalDiscounts = currentOriginalDiscounts.filter((discount) => {
|
|
2255
|
-
if (discount
|
|
2344
|
+
if (this.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount))
|
|
2256
2345
|
return true;
|
|
2257
2346
|
return !this.isCustomerBoundDiscount(discount);
|
|
2258
2347
|
});
|
|
@@ -2323,6 +2412,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2323
2412
|
}
|
|
2324
2413
|
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
2325
2414
|
if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
|
|
2415
|
+
this.store.availableWalletIds = [];
|
|
2326
2416
|
(0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
2327
2417
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2328
2418
|
this.applyDiscount();
|
|
@@ -2362,6 +2452,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2362
2452
|
tempOrder.customer = null;
|
|
2363
2453
|
if (tempOrder._extend)
|
|
2364
2454
|
delete tempOrder._extend.customerSnapshot;
|
|
2455
|
+
this.store.availableWalletIds = [];
|
|
2365
2456
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2366
2457
|
this.persistTempOrder();
|
|
2367
2458
|
this.saveDraftInBackground();
|
|
@@ -2728,12 +2819,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2728
2819
|
const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
|
|
2729
2820
|
const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
|
|
2730
2821
|
const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex((item) => {
|
|
2822
|
+
var _a2;
|
|
2731
2823
|
if (this.hasGoodPassDiscount(item))
|
|
2732
2824
|
return false;
|
|
2733
2825
|
if (this.hasOrderProductLineNote(item))
|
|
2734
2826
|
return false;
|
|
2735
2827
|
if (item.order_detail_id !== void 0 && item.order_detail_id !== null)
|
|
2736
2828
|
return false;
|
|
2829
|
+
if ((_a2 = item.metadata) == null ? void 0 : _a2.is_edit_for_runtime)
|
|
2830
|
+
return false;
|
|
2737
2831
|
if (item.product_id !== productToAdd.product_id)
|
|
2738
2832
|
return false;
|
|
2739
2833
|
if (item.product_variant_id !== productToAdd.product_variant_id)
|
|
@@ -2964,6 +3058,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2964
3058
|
return bundle;
|
|
2965
3059
|
return {
|
|
2966
3060
|
...bundle,
|
|
3061
|
+
...(bundle.cover === void 0 || bundle.cover === null || bundle.cover === "") && previous.cover !== void 0 && previous.cover !== null && previous.cover !== "" ? { cover: previous.cover } : {},
|
|
2967
3062
|
price: previous.price,
|
|
2968
3063
|
custom_price: previous.custom_price,
|
|
2969
3064
|
bundle_payment_price: previous.bundle_payment_price,
|
|
@@ -2974,7 +3069,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2974
3069
|
});
|
|
2975
3070
|
}
|
|
2976
3071
|
applyOrderProductUpdateToTempOrder(tempOrder, params) {
|
|
2977
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
3072
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
2978
3073
|
const {
|
|
2979
3074
|
product_id,
|
|
2980
3075
|
product_variant_id,
|
|
@@ -3038,9 +3133,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3038
3133
|
nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
|
|
3039
3134
|
const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
|
|
3040
3135
|
const callerUpdatesMainMeta = ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.main_product_selling_price) !== void 0 || ((_d = updates == null ? void 0 : updates.metadata) == null ? void 0 : _d.main_product_original_price) !== void 0 || ((_e = updates == null ? void 0 : updates.metadata) == null ? void 0 : _e.source_product_price) !== void 0;
|
|
3136
|
+
const callerUpdatesSourcePrice = ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.source_product_price) !== void 0;
|
|
3137
|
+
const callerUpdatesMainSellingPrice = ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.main_product_selling_price) !== void 0;
|
|
3138
|
+
const callerUpdatesMainOriginalPrice = ((_h = updates == null ? void 0 : updates.metadata) == null ? void 0 : _h.main_product_original_price) !== void 0;
|
|
3139
|
+
const previousLineFingerprint = (0, import_utils3.buildProductLineFingerprint)(
|
|
3140
|
+
(0, import_utils.getProductSkuOptions)(targetProduct),
|
|
3141
|
+
targetProduct.product_bundle
|
|
3142
|
+
);
|
|
3143
|
+
const nextLineFingerprint = (0, import_utils3.buildProductLineFingerprint)(
|
|
3144
|
+
(0, import_utils.getProductSkuOptions)(nextProduct),
|
|
3145
|
+
nextProduct.product_bundle
|
|
3146
|
+
);
|
|
3147
|
+
const callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
|
|
3148
|
+
const callerChangesLineConfiguration = callerChangesVariant || previousLineFingerprint !== nextLineFingerprint;
|
|
3041
3149
|
const isPersistedOrderLine = targetProduct.order_detail_id !== void 0 && targetProduct.order_detail_id !== null;
|
|
3042
3150
|
const callerChangesDiscountList = Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
3043
|
-
const callerUpdatesManualPrice = ((
|
|
3151
|
+
const callerUpdatesManualPrice = ((_i = updates == null ? void 0 : updates.metadata) == null ? void 0 : _i.price_override) !== void 0 || ((_j = updates == null ? void 0 : updates.metadata) == null ? void 0 : _j.is_manual_discount) !== void 0 || ((_k = updates == null ? void 0 : updates.metadata) == null ? void 0 : _k.product_discount_reason) !== void 0 || callerChangesDiscountList;
|
|
3044
3152
|
const callerAllowsBookingReprice = (() => {
|
|
3045
3153
|
if (params.allow_booking_reprice !== true || !booking || !callerUpdatesTopPrice || !callerUpdatesMainMeta) {
|
|
3046
3154
|
return false;
|
|
@@ -3055,21 +3163,69 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3055
3163
|
};
|
|
3056
3164
|
return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
|
|
3057
3165
|
})();
|
|
3058
|
-
if (isPersistedOrderLine && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
3166
|
+
if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
3059
3167
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
3060
3168
|
nextProduct.original_price = targetProduct.original_price;
|
|
3061
3169
|
nextProduct.payment_price = targetProduct.payment_price;
|
|
3062
3170
|
nextProduct.metadata = {
|
|
3063
3171
|
...nextProduct.metadata || {},
|
|
3064
|
-
source_product_price: (
|
|
3065
|
-
main_product_selling_price: (
|
|
3066
|
-
main_product_original_price: (
|
|
3067
|
-
price_schema_version: ((
|
|
3172
|
+
source_product_price: (_l = targetProduct.metadata) == null ? void 0 : _l.source_product_price,
|
|
3173
|
+
main_product_selling_price: (_m = targetProduct.metadata) == null ? void 0 : _m.main_product_selling_price,
|
|
3174
|
+
main_product_original_price: (_n = targetProduct.metadata) == null ? void 0 : _n.main_product_original_price,
|
|
3175
|
+
price_schema_version: ((_o = targetProduct.metadata) == null ? void 0 : _o.price_schema_version) ?? 2
|
|
3068
3176
|
};
|
|
3069
3177
|
nextProduct.product_bundle = this.preservePersistedBundlePriceFields(
|
|
3070
3178
|
targetProduct.product_bundle,
|
|
3071
3179
|
nextProduct.product_bundle
|
|
3072
3180
|
);
|
|
3181
|
+
} else if (callerChangesLineConfiguration && callerUpdatesSourcePrice && (!callerUpdatesMainSellingPrice || !callerUpdatesMainOriginalPrice)) {
|
|
3182
|
+
const previousMainOriginal = new import_decimal.default(
|
|
3183
|
+
Number((_p = targetProduct.metadata) == null ? void 0 : _p.main_product_original_price) || 0
|
|
3184
|
+
);
|
|
3185
|
+
const previousMainSelling = new import_decimal.default(
|
|
3186
|
+
Number((_q = targetProduct.metadata) == null ? void 0 : _q.main_product_selling_price) || previousMainOriginal.toNumber()
|
|
3187
|
+
);
|
|
3188
|
+
const preservedDiscount = previousMainOriginal.minus(previousMainSelling);
|
|
3189
|
+
const nextMainOriginal = new import_decimal.default(
|
|
3190
|
+
Number(updates.metadata.source_product_price) || 0
|
|
3191
|
+
).plus((0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(nextProduct)));
|
|
3192
|
+
nextProduct.metadata = {
|
|
3193
|
+
...nextProduct.metadata || {},
|
|
3194
|
+
source_product_price: String(updates.metadata.source_product_price),
|
|
3195
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : nextMainOriginal.toDecimalPlaces(2).toFixed(2),
|
|
3196
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
3197
|
+
price_schema_version: 2
|
|
3198
|
+
};
|
|
3199
|
+
} else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3200
|
+
const existedMeta = nextProduct.metadata || {};
|
|
3201
|
+
nextProduct.metadata = { ...existedMeta };
|
|
3202
|
+
delete nextProduct.metadata.source_product_price;
|
|
3203
|
+
delete nextProduct.metadata.main_product_selling_price;
|
|
3204
|
+
delete nextProduct.metadata.main_product_original_price;
|
|
3205
|
+
delete nextProduct.metadata.price_schema_version;
|
|
3206
|
+
} else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3207
|
+
const previousOptionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(targetProduct));
|
|
3208
|
+
const nextOptionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(nextProduct));
|
|
3209
|
+
const previousMainOriginal = new import_decimal.default(
|
|
3210
|
+
Number(
|
|
3211
|
+
((_r = targetProduct.metadata) == null ? void 0 : _r.main_product_original_price) ?? targetProduct.original_price ?? 0
|
|
3212
|
+
) || 0
|
|
3213
|
+
);
|
|
3214
|
+
const previousMainSelling = new import_decimal.default(
|
|
3215
|
+
Number(
|
|
3216
|
+
((_s = targetProduct.metadata) == null ? void 0 : _s.main_product_selling_price) ?? targetProduct.selling_price ?? previousMainOriginal.toNumber()
|
|
3217
|
+
) || 0
|
|
3218
|
+
);
|
|
3219
|
+
const preservedDiscount = previousMainOriginal.minus(previousMainSelling);
|
|
3220
|
+
const previousSource = ((_t = targetProduct.metadata) == null ? void 0 : _t.source_product_price) != null ? new import_decimal.default(Number(targetProduct.metadata.source_product_price) || 0) : previousMainOriginal.minus(previousOptionSum);
|
|
3221
|
+
const nextMainOriginal = previousSource.plus(nextOptionSum);
|
|
3222
|
+
nextProduct.metadata = {
|
|
3223
|
+
...nextProduct.metadata || {},
|
|
3224
|
+
source_product_price: previousSource.toDecimalPlaces(2).toFixed(2),
|
|
3225
|
+
main_product_original_price: nextMainOriginal.toDecimalPlaces(2).toFixed(2),
|
|
3226
|
+
main_product_selling_price: nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
3227
|
+
price_schema_version: 2
|
|
3228
|
+
};
|
|
3073
3229
|
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3074
3230
|
const existedMeta = nextProduct.metadata || {};
|
|
3075
3231
|
nextProduct.metadata = { ...existedMeta };
|
|
@@ -3085,7 +3241,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3085
3241
|
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
3086
3242
|
normalizedProduct.discount_list
|
|
3087
3243
|
);
|
|
3088
|
-
const preservedBookingUid = nextProduct.booking_uid || ((
|
|
3244
|
+
const preservedBookingUid = nextProduct.booking_uid || ((_u = nextProduct.metadata) == null ? void 0 : _u.booking_uid) || targetProduct.booking_uid || ((_v = targetProduct.metadata) == null ? void 0 : _v.booking_uid);
|
|
3089
3245
|
if (!booking && preservedBookingUid) {
|
|
3090
3246
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
3091
3247
|
normalizedProduct.metadata = {
|
|
@@ -3095,7 +3251,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3095
3251
|
}
|
|
3096
3252
|
if (booking) {
|
|
3097
3253
|
const productUid = String(
|
|
3098
|
-
((
|
|
3254
|
+
((_w = normalizedProduct.metadata) == null ? void 0 : _w.unique_identification_number) || ((_x = targetProduct.metadata) == null ? void 0 : _x.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
|
|
3099
3255
|
);
|
|
3100
3256
|
normalizedProduct.metadata = {
|
|
3101
3257
|
...normalizedProduct.metadata || {},
|
|
@@ -3126,14 +3282,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3126
3282
|
tempOrder,
|
|
3127
3283
|
updates,
|
|
3128
3284
|
tempOrder.products[productIndex],
|
|
3129
|
-
(
|
|
3285
|
+
(_y = tempOrder.products[productIndex].metadata) == null ? void 0 : _y.unique_identification_number
|
|
3130
3286
|
);
|
|
3287
|
+
return (_z = tempOrder.products[productIndex].metadata) == null ? void 0 : _z.unique_identification_number;
|
|
3131
3288
|
}
|
|
3132
3289
|
async updateOrderProduct(params) {
|
|
3133
3290
|
const tempOrder = this.ensureTempOrder();
|
|
3134
|
-
this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3291
|
+
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3135
3292
|
await this.applyPromotion();
|
|
3136
|
-
this.applyDiscount(
|
|
3293
|
+
this.applyDiscount({
|
|
3294
|
+
reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : void 0
|
|
3295
|
+
});
|
|
3137
3296
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3138
3297
|
await this.recalculateSummary({ createIfMissing: true });
|
|
3139
3298
|
this.persistTempOrder();
|
|
@@ -3147,10 +3306,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3147
3306
|
if (!paramsList.length) {
|
|
3148
3307
|
return tempOrder.products;
|
|
3149
3308
|
}
|
|
3150
|
-
paramsList.
|
|
3151
|
-
this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3309
|
+
const reapplyBookingDiscountProductUids = paramsList.reduce((acc, params) => {
|
|
3310
|
+
const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3311
|
+
if (params.allow_booking_discount_reapply && updatedProductUid) {
|
|
3312
|
+
acc.push(String(updatedProductUid));
|
|
3313
|
+
}
|
|
3314
|
+
return acc;
|
|
3315
|
+
}, []);
|
|
3316
|
+
await this.finalizeAfterProductsMutation(tempOrder, {
|
|
3317
|
+
reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : void 0
|
|
3152
3318
|
});
|
|
3153
|
-
await this.finalizeAfterProductsMutation(tempOrder);
|
|
3154
3319
|
this.logInfo("updateOrderProduct success", {
|
|
3155
3320
|
paramsList
|
|
3156
3321
|
});
|
|
@@ -3259,10 +3424,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3259
3424
|
* @example
|
|
3260
3425
|
* await this.finalizeAfterProductsMutation(tempOrder);
|
|
3261
3426
|
*/
|
|
3262
|
-
async finalizeAfterProductsMutation(tempOrder) {
|
|
3427
|
+
async finalizeAfterProductsMutation(tempOrder, options) {
|
|
3263
3428
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
3264
3429
|
await this.applyPromotion();
|
|
3265
|
-
this.applyDiscount(
|
|
3430
|
+
this.applyDiscount({
|
|
3431
|
+
reapplyBookingDiscountProductUids: options == null ? void 0 : options.reapplyBookingDiscountProductUids
|
|
3432
|
+
});
|
|
3266
3433
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3267
3434
|
await this.recalculateSummary({ createIfMissing: true });
|
|
3268
3435
|
this.persistTempOrder();
|
|
@@ -3599,8 +3766,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3599
3766
|
const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
|
|
3600
3767
|
const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
|
|
3601
3768
|
const completion = this.getPaymentCompletion(effectivePayments);
|
|
3602
|
-
const
|
|
3603
|
-
const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" :
|
|
3769
|
+
const orderPaidPaymentTotal = this.calculateOrderPaidPaymentTotal(effectivePayments);
|
|
3770
|
+
const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" : orderPaidPaymentTotal.gt(0) ? "partially_paid" : "payment_processing";
|
|
3604
3771
|
tempOrder.payments = effectivePayments;
|
|
3605
3772
|
tempOrder.payment_status = paymentStatus;
|
|
3606
3773
|
this.persistTempOrder();
|
|
@@ -3940,8 +4107,36 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3940
4107
|
*/
|
|
3941
4108
|
async hydrateTempOrderFromRecord(record, options) {
|
|
3942
4109
|
var _a, _b, _c;
|
|
3943
|
-
const
|
|
3944
|
-
const
|
|
4110
|
+
const sourceRaw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
4111
|
+
const identityReadySource = this.seedAnonymousBookingUidsFromProducts(
|
|
4112
|
+
sourceRaw
|
|
4113
|
+
);
|
|
4114
|
+
const normalizedCollections = (0, import_orderCollectionIdentity.normalizeOrderCollections)(identityReadySource);
|
|
4115
|
+
const raw = normalizedCollections.order;
|
|
4116
|
+
const hasIdentityChanges = Object.values(normalizedCollections.stats).some(
|
|
4117
|
+
(stats) => stats.backfilledUidCount > 0 || stats.collapsedDuplicateCount > 0 || stats.uidConflictCount > 0 || stats.anonymousRowCount > 0
|
|
4118
|
+
);
|
|
4119
|
+
if (hasIdentityChanges) {
|
|
4120
|
+
const identityLogMetadata = {
|
|
4121
|
+
collections: normalizedCollections.stats,
|
|
4122
|
+
uidRemapCount: normalizedCollections.uidRemaps.length
|
|
4123
|
+
};
|
|
4124
|
+
const hasIdentityWarnings = Object.values(normalizedCollections.stats).some(
|
|
4125
|
+
(stats) => stats.uidConflictCount > 0 || stats.anonymousRowCount > 0
|
|
4126
|
+
);
|
|
4127
|
+
if (hasIdentityWarnings) {
|
|
4128
|
+
this.logWarning(
|
|
4129
|
+
"Normalized hydrated order collection identities",
|
|
4130
|
+
identityLogMetadata
|
|
4131
|
+
);
|
|
4132
|
+
} else {
|
|
4133
|
+
this.logInfo(
|
|
4134
|
+
"Normalized hydrated order collection identities",
|
|
4135
|
+
identityLogMetadata
|
|
4136
|
+
);
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
|
|
3945
4140
|
const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
|
|
3946
4141
|
const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
|
|
3947
4142
|
this.store.tempOrder = nextTempOrder;
|
|
@@ -3955,23 +4150,35 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3955
4150
|
originalSalesSnapshot: {
|
|
3956
4151
|
summary: (0, import_lodash_es.cloneDeep)(this.store.summary),
|
|
3957
4152
|
products: (0, import_lodash_es.cloneDeep)(nextTempOrder.products || []),
|
|
4153
|
+
bookings: (0, import_lodash_es.cloneDeep)(nextTempOrder.bookings || []),
|
|
3958
4154
|
payments: (0, import_lodash_es.cloneDeep)(nextTempOrder.payments || []),
|
|
3959
4155
|
surcharges: (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []),
|
|
3960
4156
|
shop_discount: nextTempOrder.shop_discount || "0.00",
|
|
3961
4157
|
productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
|
|
3962
4158
|
}
|
|
3963
4159
|
};
|
|
3964
|
-
this.store.lastOrderInfo =
|
|
4160
|
+
this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
|
|
3965
4161
|
const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
|
|
3966
4162
|
const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
|
|
3967
|
-
const
|
|
4163
|
+
const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
|
|
4164
|
+
const hydratedDiscountIds = new Set(
|
|
4165
|
+
hydratedEditDiscounts.map((discount) => discount == null ? void 0 : discount.id)
|
|
4166
|
+
);
|
|
4167
|
+
const retainedScanDiscounts = currentScanDiscounts.filter(
|
|
4168
|
+
(discount) => !hydratedDiscountIds.has(discount == null ? void 0 : discount.id)
|
|
4169
|
+
);
|
|
4170
|
+
const nextDiscounts = [
|
|
4171
|
+
...hydratedEditDiscounts,
|
|
4172
|
+
...retainedScanDiscounts
|
|
4173
|
+
];
|
|
4174
|
+
const shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
|
|
3968
4175
|
if (!shouldSkipEmptyDiscountSync) {
|
|
3969
4176
|
OrderModule.populateSavedAmounts(
|
|
3970
4177
|
nextTempOrder.products,
|
|
3971
|
-
|
|
4178
|
+
nextDiscounts
|
|
3972
4179
|
);
|
|
3973
|
-
await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(
|
|
3974
|
-
await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(
|
|
4180
|
+
await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(nextDiscounts));
|
|
4181
|
+
await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(nextDiscounts));
|
|
3975
4182
|
}
|
|
3976
4183
|
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
3977
4184
|
await this.recalculateSummary({ createIfMissing: false });
|
|
@@ -4003,6 +4210,64 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4003
4210
|
}
|
|
4004
4211
|
return next;
|
|
4005
4212
|
}
|
|
4213
|
+
/**
|
|
4214
|
+
* 匿名 booking 没有服务端行 ID 时,商品侧已有的 booking_uid 就是唯一可用的强引用。
|
|
4215
|
+
* 在统一规范化生成 UUID 前先复用它;已落库 booking 仍按 schedule_event_id 派生稳定 UID。
|
|
4216
|
+
*/
|
|
4217
|
+
seedAnonymousBookingUidsFromProducts(raw) {
|
|
4218
|
+
var _a, _b;
|
|
4219
|
+
if (!raw || typeof raw !== "object")
|
|
4220
|
+
return {};
|
|
4221
|
+
if (!Array.isArray(raw.bookings) || !Array.isArray(raw.products))
|
|
4222
|
+
return raw;
|
|
4223
|
+
const bookingUidsByProductUid = /* @__PURE__ */ new Map();
|
|
4224
|
+
for (const product of raw.products) {
|
|
4225
|
+
const productUid = (0, import_orderCollectionIdentity.getOrderCollectionUid)("product", product);
|
|
4226
|
+
const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.booking_uid);
|
|
4227
|
+
if (!productUid || bookingUid === void 0 || bookingUid === null || bookingUid === "") {
|
|
4228
|
+
continue;
|
|
4229
|
+
}
|
|
4230
|
+
const candidates = bookingUidsByProductUid.get(productUid) || /* @__PURE__ */ new Set();
|
|
4231
|
+
candidates.add(String(bookingUid));
|
|
4232
|
+
bookingUidsByProductUid.set(productUid, candidates);
|
|
4233
|
+
}
|
|
4234
|
+
if (bookingUidsByProductUid.size === 0)
|
|
4235
|
+
return raw;
|
|
4236
|
+
const anonymousBookingCountByProductUid = /* @__PURE__ */ new Map();
|
|
4237
|
+
for (const booking of raw.bookings) {
|
|
4238
|
+
if ((0, import_orderCollectionIdentity.getOrderCollectionPersistentId)("booking", booking) || (0, import_orderCollectionIdentity.getOrderCollectionUid)("booking", booking)) {
|
|
4239
|
+
continue;
|
|
4240
|
+
}
|
|
4241
|
+
const productUid = (booking == null ? void 0 : booking.product_uid) || ((_b = booking == null ? void 0 : booking.metadata) == null ? void 0 : _b.product_uid);
|
|
4242
|
+
if (productUid === void 0 || productUid === null || productUid === "")
|
|
4243
|
+
continue;
|
|
4244
|
+
const key = String(productUid);
|
|
4245
|
+
anonymousBookingCountByProductUid.set(
|
|
4246
|
+
key,
|
|
4247
|
+
(anonymousBookingCountByProductUid.get(key) || 0) + 1
|
|
4248
|
+
);
|
|
4249
|
+
}
|
|
4250
|
+
return {
|
|
4251
|
+
...raw,
|
|
4252
|
+
bookings: raw.bookings.map((booking) => {
|
|
4253
|
+
var _a2;
|
|
4254
|
+
if ((0, import_orderCollectionIdentity.getOrderCollectionPersistentId)("booking", booking) || (0, import_orderCollectionIdentity.getOrderCollectionUid)("booking", booking)) {
|
|
4255
|
+
return booking;
|
|
4256
|
+
}
|
|
4257
|
+
const productUid = (booking == null ? void 0 : booking.product_uid) || ((_a2 = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a2.product_uid);
|
|
4258
|
+
if (productUid === void 0 || productUid === null || productUid === "") {
|
|
4259
|
+
return booking;
|
|
4260
|
+
}
|
|
4261
|
+
const productUidKey = String(productUid);
|
|
4262
|
+
if (anonymousBookingCountByProductUid.get(productUidKey) !== 1) {
|
|
4263
|
+
return booking;
|
|
4264
|
+
}
|
|
4265
|
+
const bookingUidCandidates = bookingUidsByProductUid.get(productUidKey);
|
|
4266
|
+
const bookingUid = (bookingUidCandidates == null ? void 0 : bookingUidCandidates.size) === 1 ? [...bookingUidCandidates][0] : null;
|
|
4267
|
+
return bookingUid ? (0, import_orderCollectionIdentity.setOrderCollectionUid)("booking", booking, bookingUid) : booking;
|
|
4268
|
+
})
|
|
4269
|
+
};
|
|
4270
|
+
}
|
|
4006
4271
|
normalizeTempOrderForRuntime(raw, options) {
|
|
4007
4272
|
var _a, _b;
|
|
4008
4273
|
const nextTempOrder = {
|
|
@@ -4028,7 +4293,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4028
4293
|
nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
|
|
4029
4294
|
nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
|
|
4030
4295
|
const rawProducts = Array.isArray(raw.products) ? raw.products : [];
|
|
4031
|
-
nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
|
|
4296
|
+
nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map((p) => this.normalizeHydratedOrderProduct(p, { makeEditMark: options == null ? void 0 : options.makeEditMark })) : [];
|
|
4032
4297
|
nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map((b) => {
|
|
4033
4298
|
const booking = this.normalizeHydratedBookingHolder(b || {});
|
|
4034
4299
|
return {
|
|
@@ -4117,9 +4382,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4117
4382
|
if (!product.metadata || typeof product.metadata !== "object") {
|
|
4118
4383
|
product.metadata = {};
|
|
4119
4384
|
}
|
|
4120
|
-
const linkedBookingUid = String(
|
|
4121
|
-
product.booking_uid || product.metadata.booking_uid || bookingUid
|
|
4122
|
-
);
|
|
4385
|
+
const linkedBookingUid = String(bookingUid);
|
|
4123
4386
|
product.booking_uid = linkedBookingUid;
|
|
4124
4387
|
product.metadata.booking_uid = linkedBookingUid;
|
|
4125
4388
|
});
|
|
@@ -4174,7 +4437,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4174
4437
|
normalized.id = optionItem.id;
|
|
4175
4438
|
return normalized;
|
|
4176
4439
|
}
|
|
4177
|
-
normalizeHydratedOrderProduct(product) {
|
|
4440
|
+
normalizeHydratedOrderProduct(product, options) {
|
|
4178
4441
|
let row = { ...product || {} };
|
|
4179
4442
|
if (row.num === void 0 && row.product_quantity !== void 0) {
|
|
4180
4443
|
row.num = row.product_quantity;
|
|
@@ -4201,6 +4464,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4201
4464
|
if (!existingIdentity) {
|
|
4202
4465
|
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
4203
4466
|
}
|
|
4467
|
+
if (options == null ? void 0 : options.makeEditMark) {
|
|
4468
|
+
row.metadata.is_edit_for_runtime = true;
|
|
4469
|
+
}
|
|
4204
4470
|
const normalized = (0, import_utils3.normalizeOrderProduct)(row);
|
|
4205
4471
|
normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
4206
4472
|
normalized.discount_list
|