@pisell/pisellos 2.2.263 → 2.2.264
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/index.d.ts +0 -4
- package/dist/model/strategy/adapter/index.js +1 -5
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
- package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/dist/model/strategy/adapter/promotion/examples.js +99 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/dist/model/strategy/adapter/promotion/type.js +45 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +10 -16
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -2
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +1 -32
- package/dist/modules/Discount/index.d.ts +2 -5
- package/dist/modules/Discount/index.js +7 -30
- package/dist/modules/Discount/types.d.ts +0 -4
- package/dist/modules/Order/index.d.ts +2 -14
- package/dist/modules/Order/index.js +736 -1035
- package/dist/modules/Order/types.d.ts +0 -16
- package/dist/modules/Order/utils.d.ts +3 -4
- package/dist/modules/Order/utils.js +61 -54
- package/dist/modules/Product/types.d.ts +0 -22
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -4
- package/dist/modules/ProductList/types.d.ts +0 -2
- package/dist/modules/Rules/index.d.ts +9 -2
- package/dist/modules/Rules/index.js +43 -69
- package/dist/modules/Rules/types.d.ts +1 -10
- package/dist/server/index.d.ts +0 -55
- package/dist/server/index.js +753 -1173
- package/dist/server/modules/order/index.d.ts +4 -10
- package/dist/server/modules/order/index.js +399 -404
- package/dist/server/modules/order/types.d.ts +0 -4
- package/dist/server/modules/products/index.d.ts +8 -31
- package/dist/server/modules/products/index.js +390 -549
- package/dist/server/modules/products/types.d.ts +0 -18
- package/dist/solution/BaseSales/index.d.ts +1 -21
- package/dist/solution/BaseSales/index.js +789 -1136
- package/dist/solution/BaseSales/types.d.ts +1 -6
- package/dist/solution/BaseSales/types.js +1 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/dist/solution/BaseSales/utils/cartPromotion.js +97 -50
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +8 -6
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -14
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +25 -59
- package/dist/solution/BookingTicket/types.d.ts +0 -2
- package/dist/solution/ScanOrder/index.js +31 -20
- package/dist/solution/ShopDiscount/index.js +14 -15
- package/dist/solution/VenueBooking/index.js +30 -19
- package/lib/model/strategy/adapter/index.d.ts +0 -4
- package/lib/model/strategy/adapter/index.js +2 -13
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/lib/model/strategy/adapter/promotion/examples.js +91 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +51 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/lib/model/strategy/adapter/promotion/type.js +2 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -5
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -1
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +2 -23
- package/lib/modules/Discount/index.d.ts +2 -5
- package/lib/modules/Discount/index.js +3 -23
- package/lib/modules/Discount/types.d.ts +0 -4
- package/lib/modules/Order/index.d.ts +2 -14
- package/lib/modules/Order/index.js +60 -326
- package/lib/modules/Order/types.d.ts +0 -16
- package/lib/modules/Order/utils.d.ts +3 -4
- package/lib/modules/Order/utils.js +23 -22
- package/lib/modules/Product/types.d.ts +0 -22
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -4
- package/lib/modules/ProductList/types.d.ts +0 -2
- package/lib/modules/Rules/index.d.ts +9 -2
- package/lib/modules/Rules/index.js +29 -61
- package/lib/modules/Rules/types.d.ts +1 -10
- package/lib/server/index.d.ts +0 -55
- package/lib/server/index.js +34 -332
- package/lib/server/modules/order/index.d.ts +4 -10
- package/lib/server/modules/order/index.js +139 -198
- package/lib/server/modules/order/types.d.ts +0 -4
- package/lib/server/modules/products/index.d.ts +8 -31
- package/lib/server/modules/products/index.js +35 -134
- package/lib/server/modules/products/types.d.ts +0 -18
- package/lib/solution/BaseSales/index.d.ts +1 -21
- package/lib/solution/BaseSales/index.js +72 -313
- package/lib/solution/BaseSales/types.d.ts +1 -6
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/lib/solution/BaseSales/utils/cartPromotion.js +64 -25
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +5 -4
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +0 -8
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +8 -33
- package/lib/solution/BookingTicket/types.d.ts +0 -2
- package/lib/solution/ScanOrder/index.js +8 -0
- package/lib/solution/ShopDiscount/index.js +1 -2
- package/lib/solution/VenueBooking/index.js +8 -0
- package/package.json +1 -1
- package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
- package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -167
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -780
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
- package/dist/model/strategy/adapter/dataVariant/examples.js +0 -277
- package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
- package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -148
- package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
- package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +0 -53
- package/dist/modules/Order/utils/orderCollectionIdentity.js +0 -405
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -50
- package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -149
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -89
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -583
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
- package/lib/model/strategy/adapter/dataVariant/examples.js +0 -293
- package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
- package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -148
- package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
- package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +0 -53
- package/lib/modules/Order/utils/orderCollectionIdentity.js +0 -415
|
@@ -41,7 +41,6 @@ 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");
|
|
45
44
|
var import_Discount = require("../Discount");
|
|
46
45
|
var import_Rules = require("../Rules");
|
|
47
46
|
var import_types2 = require("../Rules/types");
|
|
@@ -108,7 +107,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
108
107
|
this.draftPersistEnabled = true;
|
|
109
108
|
}
|
|
110
109
|
collectHydratedEditDiscounts(products) {
|
|
111
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
110
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
112
111
|
const discountMap = /* @__PURE__ */ new Map();
|
|
113
112
|
for (const product of (0, import_bundleDiscountHydration.expandHydratedProductsForDiscountCollection)(products)) {
|
|
114
113
|
for (const item of (product == null ? void 0 : product.discount_list) || []) {
|
|
@@ -138,13 +137,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
138
137
|
existed.amount = Number(existed.amount || 0) + amount;
|
|
139
138
|
existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
|
|
140
139
|
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
|
-
}
|
|
148
140
|
existed.applicableProductDetails = [
|
|
149
141
|
...existed.applicableProductDetails || [],
|
|
150
142
|
detail
|
|
@@ -161,9 +153,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
161
153
|
encoded: "",
|
|
162
154
|
code: "",
|
|
163
155
|
tag: type,
|
|
164
|
-
product_id: ((
|
|
156
|
+
product_id: ((_f = item == null ? void 0 : item.discount) == null ? void 0 : _f.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
|
|
165
157
|
relation_type: "",
|
|
166
|
-
par_value: String(((
|
|
158
|
+
par_value: String(((_g = item == null ? void 0 : item.discount) == null ? void 0 : _g.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
|
|
167
159
|
used_par_value: String((item == null ? void 0 : item.amount) ?? "0"),
|
|
168
160
|
limit_status: "enable",
|
|
169
161
|
limited_relation_product_data: {
|
|
@@ -193,8 +185,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
193
185
|
discount: {
|
|
194
186
|
...(item == null ? void 0 : item.discount) || {},
|
|
195
187
|
resource_id: key,
|
|
196
|
-
discount_product_id: ((
|
|
197
|
-
discount_calculation_mode: ((
|
|
188
|
+
discount_product_id: ((_h = item == null ? void 0 : item.discount) == null ? void 0 : _h.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
|
|
189
|
+
discount_calculation_mode: ((_i = item == null ? void 0 : item.discount) == null ? void 0 : _i.discount_calculation_mode) ?? "item_level"
|
|
198
190
|
},
|
|
199
191
|
applicableProductDetails: [detail],
|
|
200
192
|
appliedProductDetails: [detail]
|
|
@@ -309,9 +301,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
309
301
|
if (!this.store.summary) {
|
|
310
302
|
this.store.summary = (0, import_utils.createEmptySummary)();
|
|
311
303
|
}
|
|
312
|
-
if (!Array.isArray(this.store.availableWalletIds)) {
|
|
313
|
-
this.store.availableWalletIds = [];
|
|
314
|
-
}
|
|
315
304
|
this.request = this.core.getPlugin("request");
|
|
316
305
|
const appPlugin = this.core.getPlugin("app");
|
|
317
306
|
if (!appPlugin) {
|
|
@@ -439,30 +428,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
439
428
|
async loadDiscountConfig(params) {
|
|
440
429
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
441
430
|
const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
|
|
442
|
-
const
|
|
431
|
+
const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
|
|
443
432
|
customer_id: params.customerId,
|
|
444
433
|
action: params.action || (orderId ? "edit" : "create"),
|
|
445
434
|
with_good_pass: 1,
|
|
446
435
|
with_discount_card: 1,
|
|
447
436
|
with_wallet_pass_holder: 1,
|
|
448
|
-
with_available_wallet_flag: 1,
|
|
449
|
-
with_available_wallet_pass_flag: 1,
|
|
450
437
|
request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
451
438
|
...orderId ? { order_id: orderId } : {}
|
|
452
439
|
}));
|
|
453
|
-
const discountList = prepareConfigResult == null ? void 0 : prepareConfigResult.discountList;
|
|
454
|
-
this.store.availableWalletIds = (prepareConfigResult == null ? void 0 : prepareConfigResult.availableWalletIds) || [];
|
|
455
440
|
if (discountList) {
|
|
456
|
-
const
|
|
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
|
-
);
|
|
441
|
+
const currentEditDiscounts = (((_c = this.store.discount) == null ? void 0 : _c.getDiscountList()) || []).filter((discount) => discount == null ? void 0 : discount.isEditMode);
|
|
462
442
|
const runtimeDiscountIds = /* @__PURE__ */ new Set();
|
|
463
443
|
const runtimeDiscounts = discountList.filter((discount) => {
|
|
464
|
-
if (currentScanDiscountIds.has(discount == null ? void 0 : discount.id))
|
|
465
|
-
return false;
|
|
466
444
|
if (runtimeDiscountIds.has(discount == null ? void 0 : discount.id))
|
|
467
445
|
return false;
|
|
468
446
|
runtimeDiscountIds.add(discount == null ? void 0 : discount.id);
|
|
@@ -470,7 +448,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
470
448
|
});
|
|
471
449
|
const mergedDiscountList = [
|
|
472
450
|
...currentEditDiscounts,
|
|
473
|
-
...currentScanDiscounts,
|
|
474
451
|
...runtimeDiscounts
|
|
475
452
|
];
|
|
476
453
|
await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(mergedDiscountList));
|
|
@@ -485,22 +462,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
485
462
|
var _a;
|
|
486
463
|
return ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
|
|
487
464
|
}
|
|
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
|
-
}
|
|
504
465
|
async ensureEditDiscountConfigForProductChange(tempOrder) {
|
|
505
466
|
var _a, _b, _c, _d, _e, _f;
|
|
506
467
|
const orderId = tempOrder.order_id;
|
|
@@ -549,7 +510,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
549
510
|
}));
|
|
550
511
|
const currentSelected = this.getDiscountList().filter((n) => n.isSelected);
|
|
551
512
|
if (currentSelected.length && currentSelected.some((n) => withScanList.some((m) => m.id === n.id))) {
|
|
552
|
-
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
553
513
|
return {
|
|
554
514
|
type: "clientCalc",
|
|
555
515
|
isAvailable: true,
|
|
@@ -570,7 +530,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
570
530
|
if (isAvailable && newDiscountList) {
|
|
571
531
|
(_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
|
|
572
532
|
this.applyDiscount();
|
|
573
|
-
await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
|
|
574
533
|
}
|
|
575
534
|
return {
|
|
576
535
|
type: "clientCalc",
|
|
@@ -580,8 +539,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
580
539
|
unavailableReason
|
|
581
540
|
};
|
|
582
541
|
}
|
|
583
|
-
applyDiscount(
|
|
584
|
-
var _a, _b, _c;
|
|
542
|
+
applyDiscount() {
|
|
543
|
+
var _a, _b, _c, _d;
|
|
585
544
|
const tempOrder = this.store.tempOrder;
|
|
586
545
|
if (!tempOrder)
|
|
587
546
|
return;
|
|
@@ -594,14 +553,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
594
553
|
const rulesModule = this.store.rules;
|
|
595
554
|
if (!rulesModule)
|
|
596
555
|
return;
|
|
556
|
+
const holders = ((_b = tempOrder.holder) == null ? void 0 : _b.form_record) || [];
|
|
597
557
|
const result = rulesModule.calcDiscount({
|
|
598
558
|
productList: tempOrder.products,
|
|
599
559
|
discountList,
|
|
600
|
-
holders
|
|
560
|
+
holders,
|
|
601
561
|
isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
|
|
602
|
-
orderTotalAmount: Number(((
|
|
603
|
-
}, {
|
|
604
|
-
reapplyBookingDiscountProductUids: options == null ? void 0 : options.reapplyBookingDiscountProductUids
|
|
562
|
+
orderTotalAmount: Number(((_c = this.store.summary) == null ? void 0 : _c.total_amount) || 0)
|
|
605
563
|
});
|
|
606
564
|
if (result == null ? void 0 : result.productList) {
|
|
607
565
|
const previousProductsByUid = (0, import_utils.indexOrderProductsByUid)(tempOrder.products);
|
|
@@ -630,7 +588,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
630
588
|
result.productList || tempOrder.products,
|
|
631
589
|
result.discountList
|
|
632
590
|
);
|
|
633
|
-
(
|
|
591
|
+
(_d = this.store.discount) == null ? void 0 : _d.setDiscountList(result.discountList);
|
|
634
592
|
}
|
|
635
593
|
this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
|
|
636
594
|
(product) => this.productHasCustomerBoundDiscount(product)
|
|
@@ -913,15 +871,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
913
871
|
return sum.plus(this.calculatePaymentEffectiveAmount(payment));
|
|
914
872
|
}, new import_decimal.default(0));
|
|
915
873
|
}
|
|
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
|
-
}
|
|
925
874
|
getDepositAmount(tempOrder, summary) {
|
|
926
875
|
return new import_decimal.default(summary.deposit_amount || tempOrder.deposit_amount || "0.00");
|
|
927
876
|
}
|
|
@@ -1012,7 +961,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1012
961
|
const paymentList = payments || tempOrder.payments || [];
|
|
1013
962
|
const refundAmount = this.getSummaryRefundAmount(summary);
|
|
1014
963
|
const netPaidAmount = import_decimal.default.max(
|
|
1015
|
-
this.
|
|
964
|
+
this.calculatePaymentTotal(paymentList).minus(refundAmount),
|
|
1016
965
|
0
|
|
1017
966
|
);
|
|
1018
967
|
const depositAmount = this.getDepositAmount(tempOrder, summary);
|
|
@@ -1041,7 +990,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1041
990
|
const isDepositPayment = paymentRecord.type === "deposit" || paymentRecord.order_payment_type === "deposit";
|
|
1042
991
|
if (!isDepositPayment)
|
|
1043
992
|
return sum;
|
|
1044
|
-
|
|
993
|
+
if (paymentRecord.origin_amount !== void 0 && paymentRecord.origin_amount !== null && paymentRecord.origin_amount !== "") {
|
|
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));
|
|
1045
998
|
}, new import_decimal.default(0));
|
|
1046
999
|
}
|
|
1047
1000
|
resolveNextOrderPaymentType(tempOrder) {
|
|
@@ -1074,9 +1027,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1074
1027
|
updateTempOrderPaymentStatus(tempOrder, options) {
|
|
1075
1028
|
const summary = (options == null ? void 0 : options.summary) || this.store.summary || (0, import_utils.createEmptySummary)();
|
|
1076
1029
|
const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
|
|
1077
|
-
const orderPaymentTotal = this.calculateOrderPaidPaymentTotal(tempOrder.payments || []);
|
|
1078
1030
|
const refundAmount = this.getSummaryRefundAmount(summary);
|
|
1079
|
-
const netPaymentTotal = import_decimal.default.max(
|
|
1031
|
+
const netPaymentTotal = import_decimal.default.max(paymentTotal.minus(refundAmount), 0);
|
|
1080
1032
|
const targetAmount = this.calculatePaymentTargetAmount(
|
|
1081
1033
|
tempOrder,
|
|
1082
1034
|
summary,
|
|
@@ -1145,7 +1097,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1145
1097
|
}
|
|
1146
1098
|
capVoucherPaymentsByRemainingAmount(params) {
|
|
1147
1099
|
const targetAmount = this.getPaymentTargetAmount();
|
|
1148
|
-
const nonVoucherTotal = this.
|
|
1100
|
+
const nonVoucherTotal = this.calculatePaymentTotal(params.nonVoucherPayments);
|
|
1149
1101
|
if (targetAmount.lte(0))
|
|
1150
1102
|
return [];
|
|
1151
1103
|
let remainingAmount = import_decimal.default.max(
|
|
@@ -1188,7 +1140,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1188
1140
|
return summary;
|
|
1189
1141
|
return {
|
|
1190
1142
|
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
1191
|
-
orderPaidAmount: summary.orderPaidAmount.plus(
|
|
1143
|
+
orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
|
|
1192
1144
|
gapPaidAmount: summary.gapPaidAmount.plus(this.calculatePaymentGapAmount(paymentRecord)),
|
|
1193
1145
|
payServiceChargeAmount: summary.payServiceChargeAmount.plus(this.calculatePaymentServiceFee(paymentRecord)),
|
|
1194
1146
|
roundingAmount: summary.roundingAmount.plus(this.calculatePaymentRoundingAmount(paymentRecord))
|
|
@@ -1213,30 +1165,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1213
1165
|
return new import_decimal.default(payment.amount || 0).times(percentage).plus(fixedAmount);
|
|
1214
1166
|
}
|
|
1215
1167
|
calculatePaymentGapAmount(payment) {
|
|
1216
|
-
if (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);
|
|
1219
|
-
}
|
|
1220
|
-
const rounding = new import_decimal.default(payment.rounding_amount || 0);
|
|
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))
|
|
1168
|
+
if (payment.origin_amount === void 0 || payment.origin_amount === null || payment.origin_amount === "") {
|
|
1226
1169
|
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
1170
|
}
|
|
1233
|
-
const
|
|
1234
|
-
|
|
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);
|
|
1171
|
+
const rounding = new import_decimal.default(payment.rounding_amount || 0);
|
|
1172
|
+
return new import_decimal.default(payment.origin_amount || 0).minus(rounding);
|
|
1240
1173
|
}
|
|
1241
1174
|
calculatePaymentRoundingAmount(payment) {
|
|
1242
1175
|
if (payment.rounding_amount === void 0 || payment.rounding_amount === null || payment.rounding_amount === "") {
|
|
@@ -1547,7 +1480,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1547
1480
|
}
|
|
1548
1481
|
restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
|
|
1549
1482
|
const currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
|
|
1550
|
-
const manualDepositOverride = this.getManualDepositOverride(tempOrder);
|
|
1551
1483
|
if (currentFingerprint !== snapshot.productFingerprint) {
|
|
1552
1484
|
const currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
|
|
1553
1485
|
const snapshotStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(
|
|
@@ -1556,24 +1488,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1556
1488
|
if (currentStructuralFingerprint !== snapshotStructuralFingerprint)
|
|
1557
1489
|
return null;
|
|
1558
1490
|
}
|
|
1559
|
-
|
|
1491
|
+
const summary = {
|
|
1560
1492
|
...(0, import_utils.createEmptySummary)(),
|
|
1561
1493
|
...(0, import_lodash_es.cloneDeep)(snapshot.summary || {})
|
|
1562
1494
|
};
|
|
1563
|
-
|
|
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)
|
|
1495
|
+
if (!this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary))
|
|
1577
1496
|
return null;
|
|
1578
1497
|
if (Array.isArray(snapshot.products)) {
|
|
1579
1498
|
tempOrder.products = (0, import_lodash_es.cloneDeep)(snapshot.products);
|
|
@@ -1584,12 +1503,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1584
1503
|
tempOrder.surcharge_fee = summary.surcharge_fee || tempOrder.surcharge_fee;
|
|
1585
1504
|
tempOrder.deposit_amount = summary.deposit_amount || "0.00";
|
|
1586
1505
|
tempOrder.is_deposit = summary.deposit_amount !== "0.00" ? 1 : 0;
|
|
1587
|
-
const previousSummary = this.store.summary;
|
|
1588
1506
|
this.store.summary = summary;
|
|
1589
|
-
this.updateTempOrderPaymentStatus(tempOrder, {
|
|
1590
|
-
previousSummary,
|
|
1591
|
-
summary
|
|
1592
|
-
});
|
|
1593
1507
|
return summary;
|
|
1594
1508
|
}
|
|
1595
1509
|
clearPersistedAmountFieldsForFullRecalc(products) {
|
|
@@ -2278,9 +2192,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2278
2192
|
const type = (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag);
|
|
2279
2193
|
return type === "good_pass" || type === "discount_card" || type === "product_discount_card";
|
|
2280
2194
|
}
|
|
2281
|
-
shouldKeepCustomerBoundDiscountAfterCustomerChange(discount) {
|
|
2282
|
-
return Boolean((discount == null ? void 0 : discount.isScan) || (discount == null ? void 0 : discount.isEditMode));
|
|
2283
|
-
}
|
|
2284
2195
|
productHasCustomerBoundDiscount(product) {
|
|
2285
2196
|
if (((product == null ? void 0 : product.discount_list) || []).some((discount) => this.isCustomerBoundDiscount(discount))) {
|
|
2286
2197
|
return true;
|
|
@@ -2336,12 +2247,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2336
2247
|
const currentDiscounts = ((_a = discountModule.getDiscountList) == null ? void 0 : _a.call(discountModule)) || [];
|
|
2337
2248
|
const currentOriginalDiscounts = ((_b = discountModule.getOriginalDiscountList) == null ? void 0 : _b.call(discountModule)) || [];
|
|
2338
2249
|
const nextDiscounts = currentDiscounts.filter((discount) => {
|
|
2339
|
-
if (
|
|
2250
|
+
if (discount == null ? void 0 : discount.isEditMode)
|
|
2340
2251
|
return true;
|
|
2341
2252
|
return !this.isCustomerBoundDiscount(discount);
|
|
2342
2253
|
});
|
|
2343
2254
|
const nextOriginalDiscounts = currentOriginalDiscounts.filter((discount) => {
|
|
2344
|
-
if (
|
|
2255
|
+
if (discount == null ? void 0 : discount.isEditMode)
|
|
2345
2256
|
return true;
|
|
2346
2257
|
return !this.isCustomerBoundDiscount(discount);
|
|
2347
2258
|
});
|
|
@@ -2412,7 +2323,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2412
2323
|
}
|
|
2413
2324
|
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
2414
2325
|
if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
|
|
2415
|
-
this.store.availableWalletIds = [];
|
|
2416
2326
|
(0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
2417
2327
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2418
2328
|
this.applyDiscount();
|
|
@@ -2452,7 +2362,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2452
2362
|
tempOrder.customer = null;
|
|
2453
2363
|
if (tempOrder._extend)
|
|
2454
2364
|
delete tempOrder._extend.customerSnapshot;
|
|
2455
|
-
this.store.availableWalletIds = [];
|
|
2456
2365
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2457
2366
|
this.persistTempOrder();
|
|
2458
2367
|
this.saveDraftInBackground();
|
|
@@ -2819,15 +2728,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2819
2728
|
const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
|
|
2820
2729
|
const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
|
|
2821
2730
|
const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex((item) => {
|
|
2822
|
-
var _a2;
|
|
2823
2731
|
if (this.hasGoodPassDiscount(item))
|
|
2824
2732
|
return false;
|
|
2825
2733
|
if (this.hasOrderProductLineNote(item))
|
|
2826
2734
|
return false;
|
|
2827
2735
|
if (item.order_detail_id !== void 0 && item.order_detail_id !== null)
|
|
2828
2736
|
return false;
|
|
2829
|
-
if ((_a2 = item.metadata) == null ? void 0 : _a2.is_edit_for_runtime)
|
|
2830
|
-
return false;
|
|
2831
2737
|
if (item.product_id !== productToAdd.product_id)
|
|
2832
2738
|
return false;
|
|
2833
2739
|
if (item.product_variant_id !== productToAdd.product_variant_id)
|
|
@@ -3058,7 +2964,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3058
2964
|
return bundle;
|
|
3059
2965
|
return {
|
|
3060
2966
|
...bundle,
|
|
3061
|
-
...(bundle.cover === void 0 || bundle.cover === null || bundle.cover === "") && previous.cover !== void 0 && previous.cover !== null && previous.cover !== "" ? { cover: previous.cover } : {},
|
|
3062
2967
|
price: previous.price,
|
|
3063
2968
|
custom_price: previous.custom_price,
|
|
3064
2969
|
bundle_payment_price: previous.bundle_payment_price,
|
|
@@ -3069,7 +2974,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3069
2974
|
});
|
|
3070
2975
|
}
|
|
3071
2976
|
applyOrderProductUpdateToTempOrder(tempOrder, params) {
|
|
3072
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q
|
|
2977
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
3073
2978
|
const {
|
|
3074
2979
|
product_id,
|
|
3075
2980
|
product_variant_id,
|
|
@@ -3133,22 +3038,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3133
3038
|
nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
|
|
3134
3039
|
const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
|
|
3135
3040
|
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;
|
|
3149
3041
|
const isPersistedOrderLine = targetProduct.order_detail_id !== void 0 && targetProduct.order_detail_id !== null;
|
|
3150
3042
|
const callerChangesDiscountList = Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
3151
|
-
const callerUpdatesManualPrice = ((
|
|
3043
|
+
const callerUpdatesManualPrice = ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.price_override) !== void 0 || ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.is_manual_discount) !== void 0 || ((_h = updates == null ? void 0 : updates.metadata) == null ? void 0 : _h.product_discount_reason) !== void 0 || callerChangesDiscountList;
|
|
3152
3044
|
const callerAllowsBookingReprice = (() => {
|
|
3153
3045
|
if (params.allow_booking_reprice !== true || !booking || !callerUpdatesTopPrice || !callerUpdatesMainMeta) {
|
|
3154
3046
|
return false;
|
|
@@ -3163,69 +3055,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3163
3055
|
};
|
|
3164
3056
|
return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
|
|
3165
3057
|
})();
|
|
3166
|
-
if (isPersistedOrderLine && !
|
|
3058
|
+
if (isPersistedOrderLine && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
3167
3059
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
3168
3060
|
nextProduct.original_price = targetProduct.original_price;
|
|
3169
3061
|
nextProduct.payment_price = targetProduct.payment_price;
|
|
3170
3062
|
nextProduct.metadata = {
|
|
3171
3063
|
...nextProduct.metadata || {},
|
|
3172
|
-
source_product_price: (
|
|
3173
|
-
main_product_selling_price: (
|
|
3174
|
-
main_product_original_price: (
|
|
3175
|
-
price_schema_version: ((
|
|
3064
|
+
source_product_price: (_i = targetProduct.metadata) == null ? void 0 : _i.source_product_price,
|
|
3065
|
+
main_product_selling_price: (_j = targetProduct.metadata) == null ? void 0 : _j.main_product_selling_price,
|
|
3066
|
+
main_product_original_price: (_k = targetProduct.metadata) == null ? void 0 : _k.main_product_original_price,
|
|
3067
|
+
price_schema_version: ((_l = targetProduct.metadata) == null ? void 0 : _l.price_schema_version) ?? 2
|
|
3176
3068
|
};
|
|
3177
3069
|
nextProduct.product_bundle = this.preservePersistedBundlePriceFields(
|
|
3178
3070
|
targetProduct.product_bundle,
|
|
3179
3071
|
nextProduct.product_bundle
|
|
3180
3072
|
);
|
|
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
|
-
};
|
|
3229
3073
|
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
3230
3074
|
const existedMeta = nextProduct.metadata || {};
|
|
3231
3075
|
nextProduct.metadata = { ...existedMeta };
|
|
@@ -3241,7 +3085,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3241
3085
|
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
3242
3086
|
normalizedProduct.discount_list
|
|
3243
3087
|
);
|
|
3244
|
-
const preservedBookingUid = nextProduct.booking_uid || ((
|
|
3088
|
+
const preservedBookingUid = nextProduct.booking_uid || ((_m = nextProduct.metadata) == null ? void 0 : _m.booking_uid) || targetProduct.booking_uid || ((_n = targetProduct.metadata) == null ? void 0 : _n.booking_uid);
|
|
3245
3089
|
if (!booking && preservedBookingUid) {
|
|
3246
3090
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
3247
3091
|
normalizedProduct.metadata = {
|
|
@@ -3251,7 +3095,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3251
3095
|
}
|
|
3252
3096
|
if (booking) {
|
|
3253
3097
|
const productUid = String(
|
|
3254
|
-
((
|
|
3098
|
+
((_o = normalizedProduct.metadata) == null ? void 0 : _o.unique_identification_number) || ((_p = targetProduct.metadata) == null ? void 0 : _p.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
|
|
3255
3099
|
);
|
|
3256
3100
|
normalizedProduct.metadata = {
|
|
3257
3101
|
...normalizedProduct.metadata || {},
|
|
@@ -3282,17 +3126,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3282
3126
|
tempOrder,
|
|
3283
3127
|
updates,
|
|
3284
3128
|
tempOrder.products[productIndex],
|
|
3285
|
-
(
|
|
3129
|
+
(_q = tempOrder.products[productIndex].metadata) == null ? void 0 : _q.unique_identification_number
|
|
3286
3130
|
);
|
|
3287
|
-
return (_z = tempOrder.products[productIndex].metadata) == null ? void 0 : _z.unique_identification_number;
|
|
3288
3131
|
}
|
|
3289
3132
|
async updateOrderProduct(params) {
|
|
3290
3133
|
const tempOrder = this.ensureTempOrder();
|
|
3291
|
-
|
|
3134
|
+
this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3292
3135
|
await this.applyPromotion();
|
|
3293
|
-
this.applyDiscount(
|
|
3294
|
-
reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : void 0
|
|
3295
|
-
});
|
|
3136
|
+
this.applyDiscount();
|
|
3296
3137
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3297
3138
|
await this.recalculateSummary({ createIfMissing: true });
|
|
3298
3139
|
this.persistTempOrder();
|
|
@@ -3306,16 +3147,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3306
3147
|
if (!paramsList.length) {
|
|
3307
3148
|
return tempOrder.products;
|
|
3308
3149
|
}
|
|
3309
|
-
|
|
3310
|
-
|
|
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
|
|
3150
|
+
paramsList.forEach((params) => {
|
|
3151
|
+
this.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3318
3152
|
});
|
|
3153
|
+
await this.finalizeAfterProductsMutation(tempOrder);
|
|
3319
3154
|
this.logInfo("updateOrderProduct success", {
|
|
3320
3155
|
paramsList
|
|
3321
3156
|
});
|
|
@@ -3424,12 +3259,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3424
3259
|
* @example
|
|
3425
3260
|
* await this.finalizeAfterProductsMutation(tempOrder);
|
|
3426
3261
|
*/
|
|
3427
|
-
async finalizeAfterProductsMutation(tempOrder
|
|
3262
|
+
async finalizeAfterProductsMutation(tempOrder) {
|
|
3428
3263
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
3429
3264
|
await this.applyPromotion();
|
|
3430
|
-
this.applyDiscount(
|
|
3431
|
-
reapplyBookingDiscountProductUids: options == null ? void 0 : options.reapplyBookingDiscountProductUids
|
|
3432
|
-
});
|
|
3265
|
+
this.applyDiscount();
|
|
3433
3266
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
3434
3267
|
await this.recalculateSummary({ createIfMissing: true });
|
|
3435
3268
|
this.persistTempOrder();
|
|
@@ -3766,8 +3599,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
3766
3599
|
const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
|
|
3767
3600
|
const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
|
|
3768
3601
|
const completion = this.getPaymentCompletion(effectivePayments);
|
|
3769
|
-
const
|
|
3770
|
-
const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" :
|
|
3602
|
+
const paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
|
|
3603
|
+
const paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || "paid" : paidPaymentTotal.gt(0) ? "partially_paid" : "payment_processing";
|
|
3771
3604
|
tempOrder.payments = effectivePayments;
|
|
3772
3605
|
tempOrder.payment_status = paymentStatus;
|
|
3773
3606
|
this.persistTempOrder();
|
|
@@ -4107,36 +3940,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4107
3940
|
*/
|
|
4108
3941
|
async hydrateTempOrderFromRecord(record, options) {
|
|
4109
3942
|
var _a, _b, _c;
|
|
4110
|
-
const
|
|
4111
|
-
const
|
|
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 });
|
|
3943
|
+
const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
|
|
3944
|
+
const nextTempOrder = this.normalizeTempOrderForRuntime(raw);
|
|
4140
3945
|
const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
|
|
4141
3946
|
const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
|
|
4142
3947
|
this.store.tempOrder = nextTempOrder;
|
|
@@ -4150,35 +3955,23 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4150
3955
|
originalSalesSnapshot: {
|
|
4151
3956
|
summary: (0, import_lodash_es.cloneDeep)(this.store.summary),
|
|
4152
3957
|
products: (0, import_lodash_es.cloneDeep)(nextTempOrder.products || []),
|
|
4153
|
-
bookings: (0, import_lodash_es.cloneDeep)(nextTempOrder.bookings || []),
|
|
4154
3958
|
payments: (0, import_lodash_es.cloneDeep)(nextTempOrder.payments || []),
|
|
4155
3959
|
surcharges: (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []),
|
|
4156
3960
|
shop_discount: nextTempOrder.shop_discount || "0.00",
|
|
4157
3961
|
productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
|
|
4158
3962
|
}
|
|
4159
3963
|
};
|
|
4160
|
-
this.store.lastOrderInfo =
|
|
3964
|
+
this.store.lastOrderInfo = raw.lastOrderInfo || raw;
|
|
4161
3965
|
const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
|
|
4162
3966
|
const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
|
|
4163
|
-
const
|
|
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;
|
|
3967
|
+
const shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
|
|
4175
3968
|
if (!shouldSkipEmptyDiscountSync) {
|
|
4176
3969
|
OrderModule.populateSavedAmounts(
|
|
4177
3970
|
nextTempOrder.products,
|
|
4178
|
-
|
|
3971
|
+
hydratedEditDiscounts
|
|
4179
3972
|
);
|
|
4180
|
-
await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(
|
|
4181
|
-
await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(
|
|
3973
|
+
await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(hydratedEditDiscounts));
|
|
3974
|
+
await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(hydratedEditDiscounts));
|
|
4182
3975
|
}
|
|
4183
3976
|
if (options == null ? void 0 : options.recalcOnHydrate) {
|
|
4184
3977
|
await this.recalculateSummary({ createIfMissing: false });
|
|
@@ -4210,64 +4003,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4210
4003
|
}
|
|
4211
4004
|
return next;
|
|
4212
4005
|
}
|
|
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
|
-
}
|
|
4271
4006
|
normalizeTempOrderForRuntime(raw, options) {
|
|
4272
4007
|
var _a, _b;
|
|
4273
4008
|
const nextTempOrder = {
|
|
@@ -4293,7 +4028,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4293
4028
|
nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
|
|
4294
4029
|
nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
|
|
4295
4030
|
const rawProducts = Array.isArray(raw.products) ? raw.products : [];
|
|
4296
|
-
nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map((p) => this.normalizeHydratedOrderProduct(p
|
|
4031
|
+
nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
|
|
4297
4032
|
nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map((b) => {
|
|
4298
4033
|
const booking = this.normalizeHydratedBookingHolder(b || {});
|
|
4299
4034
|
return {
|
|
@@ -4382,7 +4117,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4382
4117
|
if (!product.metadata || typeof product.metadata !== "object") {
|
|
4383
4118
|
product.metadata = {};
|
|
4384
4119
|
}
|
|
4385
|
-
const linkedBookingUid = String(
|
|
4120
|
+
const linkedBookingUid = String(
|
|
4121
|
+
product.booking_uid || product.metadata.booking_uid || bookingUid
|
|
4122
|
+
);
|
|
4386
4123
|
product.booking_uid = linkedBookingUid;
|
|
4387
4124
|
product.metadata.booking_uid = linkedBookingUid;
|
|
4388
4125
|
});
|
|
@@ -4437,7 +4174,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4437
4174
|
normalized.id = optionItem.id;
|
|
4438
4175
|
return normalized;
|
|
4439
4176
|
}
|
|
4440
|
-
normalizeHydratedOrderProduct(product
|
|
4177
|
+
normalizeHydratedOrderProduct(product) {
|
|
4441
4178
|
let row = { ...product || {} };
|
|
4442
4179
|
if (row.num === void 0 && row.product_quantity !== void 0) {
|
|
4443
4180
|
row.num = row.product_quantity;
|
|
@@ -4464,9 +4201,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
4464
4201
|
if (!existingIdentity) {
|
|
4465
4202
|
row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
4466
4203
|
}
|
|
4467
|
-
if (options == null ? void 0 : options.makeEditMark) {
|
|
4468
|
-
row.metadata.is_edit_for_runtime = true;
|
|
4469
|
-
}
|
|
4470
4204
|
const normalized = (0, import_utils3.normalizeOrderProduct)(row);
|
|
4471
4205
|
normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
4472
4206
|
normalized.discount_list
|