@pisell/pisellos 2.2.193 → 2.2.195
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/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -0
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +79 -26
- package/dist/modules/Order/utils/manualProductDiscount.js +1 -1
- package/dist/modules/SalesSummary/index.d.ts +0 -25
- package/dist/modules/SalesSummary/types.d.ts +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +2 -25
- package/dist/modules/SalesSummary/utils.js +528 -159
- package/dist/server/index.js +2 -2
- package/dist/server/modules/products/index.js +4 -4
- package/dist/solution/BaseSales/index.js +39 -14
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -0
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +60 -6
- package/lib/modules/Order/utils/manualProductDiscount.js +1 -1
- package/lib/modules/SalesSummary/index.d.ts +0 -25
- package/lib/modules/SalesSummary/types.d.ts +1 -0
- package/lib/modules/SalesSummary/utils.d.ts +2 -25
- package/lib/modules/SalesSummary/utils.js +419 -89
- package/lib/server/index.js +2 -2
- package/lib/server/modules/products/index.js +0 -4
- package/lib/solution/BaseSales/index.js +47 -10
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -1647,14 +1647,14 @@ var Server = /*#__PURE__*/function () {
|
|
|
1647
1647
|
_context20.next = 3;
|
|
1648
1648
|
break;
|
|
1649
1649
|
}
|
|
1650
|
-
this.
|
|
1650
|
+
this.logInfo('setupProductsQuotationPriceBridge: Products 模块未注册');
|
|
1651
1651
|
return _context20.abrupt("return");
|
|
1652
1652
|
case 3:
|
|
1653
1653
|
if (this.schedule) {
|
|
1654
1654
|
_context20.next = 6;
|
|
1655
1655
|
break;
|
|
1656
1656
|
}
|
|
1657
|
-
this.
|
|
1657
|
+
this.logInfo('setupProductsQuotationPriceBridge: Schedule 模块未注册');
|
|
1658
1658
|
return _context20.abrupt("return");
|
|
1659
1659
|
case 6:
|
|
1660
1660
|
_context20.prev = 6;
|
|
@@ -2048,10 +2048,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2048
2048
|
this.productDataSource.run({
|
|
2049
2049
|
pubsub: {
|
|
2050
2050
|
callback: function callback(res) {
|
|
2051
|
-
console.log('sse_products_callback', res)
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
});
|
|
2051
|
+
// console.log('sse_products_callback', res)
|
|
2052
|
+
// this.logInfo('sse_products_callback: 收到同步消息', {
|
|
2053
|
+
// data: res?.data,
|
|
2054
|
+
// });
|
|
2055
2055
|
if (!(res !== null && res !== void 0 && res.data)) return;
|
|
2056
2056
|
var data = res.data;
|
|
2057
2057
|
var channelKey = data.module || 'product';
|
|
@@ -37,6 +37,31 @@ export * from "./types";
|
|
|
37
37
|
import { QuotationModule } from "../../modules/Quotation";
|
|
38
38
|
import { transformBaseProductToOrderProduct as _transformBaseProductToOrderProduct } from "./utils/transformBaseProductToOrderProduct";
|
|
39
39
|
import { calculateBaseSalesProductBookingPrice } from "./utils/quotationPrice";
|
|
40
|
+
function isBaseSalesManualProductDiscountProduct(product) {
|
|
41
|
+
var _product$metadata, _product$metadata2;
|
|
42
|
+
return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_manual_discount) === true || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === 1 || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
|
|
43
|
+
return (item === null || item === void 0 ? void 0 : item.type) === 'product';
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function getBaseSalesProductUid(product) {
|
|
47
|
+
var _product$metadata3;
|
|
48
|
+
var uid = (product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
|
|
49
|
+
if (uid === undefined || uid === null || uid === '') return null;
|
|
50
|
+
return String(uid);
|
|
51
|
+
}
|
|
52
|
+
function preserveManualProductDiscountProducts(previousProducts, nextProducts) {
|
|
53
|
+
var previousByUid = new Map();
|
|
54
|
+
(previousProducts || []).forEach(function (product, index) {
|
|
55
|
+
var uid = getBaseSalesProductUid(product);
|
|
56
|
+
if (uid) previousByUid.set(uid, product);
|
|
57
|
+
previousByUid.set("__index__:".concat(index), product);
|
|
58
|
+
});
|
|
59
|
+
return (nextProducts || []).map(function (product, index) {
|
|
60
|
+
var uid = getBaseSalesProductUid(product);
|
|
61
|
+
var previous = (uid ? previousByUid.get(uid) : undefined) || previousByUid.get("__index__:".concat(index));
|
|
62
|
+
return previous && isBaseSalesManualProductDiscountProduct(previous) ? previous : product;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
40
65
|
export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
41
66
|
_inherits(BaseSalesImpl, _BaseModule);
|
|
42
67
|
var _super = _createSuper(BaseSalesImpl);
|
|
@@ -342,7 +367,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
342
367
|
_product$num,
|
|
343
368
|
_ref8,
|
|
344
369
|
_product$quantity,
|
|
345
|
-
_product$
|
|
370
|
+
_product$metadata4;
|
|
346
371
|
if (!authoritativeProduct) return product;
|
|
347
372
|
var selectedBundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
348
373
|
var authoritativeBundles = this.getAuthoritativeBundleItems(authoritativeProduct);
|
|
@@ -373,7 +398,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
373
398
|
});
|
|
374
399
|
}(),
|
|
375
400
|
product_bundle: productBundle,
|
|
376
|
-
metadata: (_product$
|
|
401
|
+
metadata: (_product$metadata4 = product.metadata) !== null && _product$metadata4 !== void 0 ? _product$metadata4 : authoritativeProduct.metadata
|
|
377
402
|
});
|
|
378
403
|
}
|
|
379
404
|
}, {
|
|
@@ -1180,7 +1205,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1180
1205
|
value: function () {
|
|
1181
1206
|
var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
|
|
1182
1207
|
var _this$getOrderIdentit, _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _discountModule$getDi, _discountModule$getOr, _discountModule$getDi2;
|
|
1183
|
-
var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result, _iterator, _step, _product$
|
|
1208
|
+
var tempOrder, orderStore, discountModule, rulesModule, orderId, customerId, currentDiscountList, originalDiscountList, hasManualDiscountSelection, discountAction, discountConfigCacheKey, preparedDiscountList, _discountModule$setOr, nextDiscountList, shouldSkipAutoApplyFetchedDiscounts, _summary, _tempOrder$holder, _tempOrder$holder2, _orderStore$summary, holders, result, _iterator, _step, _product$metadata5, _tempOrder$_extend3, _product$metadata$sou, _product$metadata6, _product$metadata7, _product$original_pri, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice, summary;
|
|
1184
1209
|
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
1185
1210
|
while (1) switch (_context12.prev = _context12.next) {
|
|
1186
1211
|
case 0:
|
|
@@ -1291,7 +1316,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1291
1316
|
discountList: nextDiscountList
|
|
1292
1317
|
};
|
|
1293
1318
|
if (result.productList) {
|
|
1294
|
-
tempOrder.products = result.productList;
|
|
1319
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
1295
1320
|
}
|
|
1296
1321
|
_iterator = _createForOfIteratorHelper(tempOrder.products || []);
|
|
1297
1322
|
_context12.prev = 45;
|
|
@@ -1302,9 +1327,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1302
1327
|
break;
|
|
1303
1328
|
}
|
|
1304
1329
|
product = _step.value;
|
|
1305
|
-
productUid = (_product$
|
|
1330
|
+
productUid = (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number;
|
|
1306
1331
|
runtimeOrigin = productUid ? (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3.productsByUid) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3[productUid]) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.origin : undefined;
|
|
1307
|
-
if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (
|
|
1332
|
+
if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
|
|
1308
1333
|
_context12.next = 53;
|
|
1309
1334
|
break;
|
|
1310
1335
|
}
|
|
@@ -1314,7 +1339,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1314
1339
|
return sum + Number(pd.amount || 0);
|
|
1315
1340
|
}, 0);
|
|
1316
1341
|
optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
|
|
1317
|
-
sourcePrice = (_product$metadata$sou = (_product$
|
|
1342
|
+
sourcePrice = (_product$metadata$sou = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : '0';
|
|
1318
1343
|
newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1319
1344
|
newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1320
1345
|
if (product.metadata) {
|
|
@@ -1427,7 +1452,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1427
1452
|
orderTotalAmount: Number(((_orderStore$summary2 = orderStore.summary) === null || _orderStore$summary2 === void 0 ? void 0 : _orderStore$summary2.total_amount) || 0)
|
|
1428
1453
|
}) || result;
|
|
1429
1454
|
if (result.productList) {
|
|
1430
|
-
tempOrder.products = result.productList;
|
|
1455
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
1431
1456
|
}
|
|
1432
1457
|
if (!result.discountList) {
|
|
1433
1458
|
_context13.next = 23;
|
|
@@ -1525,7 +1550,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1525
1550
|
key: "setDiscountSelected",
|
|
1526
1551
|
value: function () {
|
|
1527
1552
|
var _setDiscountSelected = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
|
|
1528
|
-
var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$
|
|
1553
|
+
var _tempOrder$holder5, list, updated, tempOrder, orderStore, discountModule, rulesModule, holders, nextDiscountList, _tempOrder$holder6, result, beforeSelectedIds, _iterator2, _step2, d, selectedResourceIds, _iterator3, _step3, _product$metadata8, _tempOrder$_extend4, _product$metadata$sou2, _product$metadata9, _product$metadata10, _product$original_pri2, product, productUid, runtimeOrigin, totalPerUnitDiscount, optionSum, sourcePrice, newSourceSellingPrice, newMainSellingPrice;
|
|
1529
1554
|
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1530
1555
|
while (1) switch (_context15.prev = _context15.next) {
|
|
1531
1556
|
case 0:
|
|
@@ -1569,7 +1594,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1569
1594
|
discountList: updated
|
|
1570
1595
|
};
|
|
1571
1596
|
if (result !== null && result !== void 0 && result.productList) {
|
|
1572
|
-
tempOrder.products = result.productList;
|
|
1597
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
1573
1598
|
}
|
|
1574
1599
|
if (result !== null && result !== void 0 && result.discountList) {
|
|
1575
1600
|
nextDiscountList = result.discountList;
|
|
@@ -1610,9 +1635,9 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1610
1635
|
break;
|
|
1611
1636
|
}
|
|
1612
1637
|
product = _step3.value;
|
|
1613
|
-
productUid = (_product$
|
|
1638
|
+
productUid = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number;
|
|
1614
1639
|
runtimeOrigin = productUid ? (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4.productsByUid) === null || _tempOrder$_extend4 === void 0 || (_tempOrder$_extend4 = _tempOrder$_extend4[productUid]) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.origin : undefined;
|
|
1615
|
-
if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || (
|
|
1640
|
+
if (!(runtimeOrigin !== null && runtimeOrigin !== void 0 && runtimeOrigin.isManualDiscount || isBaseSalesManualProductDiscountProduct(product))) {
|
|
1616
1641
|
_context15.next = 25;
|
|
1617
1642
|
break;
|
|
1618
1643
|
}
|
|
@@ -1630,7 +1655,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1630
1655
|
return sum + (pd.amount || 0);
|
|
1631
1656
|
}, 0); // TODO 这块逻辑需要拿掉
|
|
1632
1657
|
optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
|
|
1633
|
-
sourcePrice = (_product$metadata$sou2 = (_product$
|
|
1658
|
+
sourcePrice = (_product$metadata$sou2 = (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.source_product_price) !== null && _product$metadata$sou2 !== void 0 ? _product$metadata$sou2 : ((_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
|
|
1634
1659
|
newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
1635
1660
|
newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1636
1661
|
if (product.metadata) {
|
|
@@ -1717,7 +1742,7 @@ export var BaseSalesImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1717
1742
|
orderStore = this.store.order.store || {};
|
|
1718
1743
|
discountModule = orderStore.discount;
|
|
1719
1744
|
if (result.productList) {
|
|
1720
|
-
tempOrder.products = result.productList;
|
|
1745
|
+
tempOrder.products = preserveManualProductDiscountProducts(tempOrder.products, result.productList);
|
|
1721
1746
|
}
|
|
1722
1747
|
if (!result.discountList) {
|
|
1723
1748
|
_context16.next = 14;
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 6 | 3 | 5 | 4;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|
|
@@ -279,7 +279,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
279
279
|
* 获取当前的客户搜索条件
|
|
280
280
|
* @returns 当前搜索条件
|
|
281
281
|
*/
|
|
282
|
-
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "
|
|
282
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
|
|
283
283
|
/**
|
|
284
284
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
285
285
|
* @returns 客户状态
|
|
@@ -88,6 +88,7 @@ function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
88
88
|
);
|
|
89
89
|
const originExtend = (_c = (_b = product.metadata) == null ? void 0 : _b.origin) == null ? void 0 : _c._extend;
|
|
90
90
|
const productOptionString = (0, import_orderLineDisplay.buildProductOptionStringFromOrderLine)(product);
|
|
91
|
+
const discountList = product.discount_list || [];
|
|
91
92
|
const other = {
|
|
92
93
|
product_id: resolvedId,
|
|
93
94
|
product_variant_id: product.product_variant_id ?? 0,
|
|
@@ -135,6 +136,7 @@ function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
135
136
|
...productOptionString ? { product_option_string: productOptionString } : {},
|
|
136
137
|
note: product.note,
|
|
137
138
|
order_detail_id: product.order_detail_id ?? null,
|
|
139
|
+
discount_list: discountList,
|
|
138
140
|
new: 0,
|
|
139
141
|
autoClose: true,
|
|
140
142
|
_extend: extend
|
|
@@ -141,6 +141,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
141
141
|
private calculatePaymentTotal;
|
|
142
142
|
private normalizePaymentSource;
|
|
143
143
|
private updateTempOrderPaymentStatus;
|
|
144
|
+
private shouldKeepPaymentStatusAfterAmountRecalc;
|
|
144
145
|
private resolveWalletPassUseValue;
|
|
145
146
|
private capVoucherPaymentsByRemainingAmount;
|
|
146
147
|
private calculatePaidPaymentSummary;
|
|
@@ -45,6 +45,25 @@ var import_Rules = require("../Rules");
|
|
|
45
45
|
var import_types2 = require("../Rules/types");
|
|
46
46
|
var import_decimal = __toESM(require("decimal.js"));
|
|
47
47
|
var import_lodash_es = require("lodash-es");
|
|
48
|
+
function normalizeDiscountListSignature(discountList) {
|
|
49
|
+
return (discountList || []).map((item) => ({
|
|
50
|
+
type: (item == null ? void 0 : item.type) ?? "",
|
|
51
|
+
discount_id: (item == null ? void 0 : item.discount_id) ?? null,
|
|
52
|
+
order_discount_id: (item == null ? void 0 : item.order_discount_id) ?? null,
|
|
53
|
+
amount: new import_decimal.default(Number(item == null ? void 0 : item.amount) || 0).toFixed(2)
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
function isSameDiscountList(left, right) {
|
|
57
|
+
if (!Array.isArray(left) || !Array.isArray(right))
|
|
58
|
+
return false;
|
|
59
|
+
return JSON.stringify(normalizeDiscountListSignature(left)) === JSON.stringify(
|
|
60
|
+
normalizeDiscountListSignature(right)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function isManualProductDiscountProduct(product) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
|
|
66
|
+
}
|
|
48
67
|
var OrderModule = class extends import_BaseModule.BaseModule {
|
|
49
68
|
constructor(name, version) {
|
|
50
69
|
super(name || "order", version);
|
|
@@ -104,12 +123,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
104
123
|
}
|
|
105
124
|
applyProductDiscountPrices(products) {
|
|
106
125
|
return (products || []).map((product) => {
|
|
107
|
-
var _a, _b
|
|
108
|
-
if ((
|
|
126
|
+
var _a, _b;
|
|
127
|
+
if (isManualProductDiscountProduct(product))
|
|
128
|
+
return product;
|
|
129
|
+
const discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
|
|
130
|
+
const hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== void 0 && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every((discount) => (discount == null ? void 0 : discount.order_discount_id) !== void 0 && (discount == null ? void 0 : discount.order_discount_id) !== null);
|
|
131
|
+
if (hasOnlyPersistedDiscountSnapshots) {
|
|
109
132
|
return product;
|
|
133
|
+
}
|
|
110
134
|
const totalPerUnitDiscount = (0, import_utils.resolveEffectivePerUnitDiscount)(product);
|
|
111
135
|
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
|
|
112
|
-
const sourcePrice = ((
|
|
136
|
+
const sourcePrice = ((_a = product.metadata) == null ? void 0 : _a.source_product_price) ?? (((_b = product.metadata) == null ? void 0 : _b.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
|
|
113
137
|
const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
|
|
114
138
|
const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
115
139
|
if (product.metadata) {
|
|
@@ -326,6 +350,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
326
350
|
(result.productList || []).map((product, index) => {
|
|
327
351
|
const uid = (0, import_utils.getOrderProductLineUid)(product);
|
|
328
352
|
const previous = (uid ? previousProductsByUid.get(uid) : void 0) ?? previousProductsByUid.get(`__index__:${index}`);
|
|
353
|
+
if (isManualProductDiscountProduct(previous)) {
|
|
354
|
+
return previous;
|
|
355
|
+
}
|
|
329
356
|
const mergedProduct = previous ? (0, import_utils.mergeOrderProductDisplayFields)(previous, product) : product;
|
|
330
357
|
return {
|
|
331
358
|
...mergedProduct,
|
|
@@ -618,6 +645,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
618
645
|
return normalized;
|
|
619
646
|
}
|
|
620
647
|
updateTempOrderPaymentStatus(tempOrder) {
|
|
648
|
+
if (this.shouldKeepPaymentStatusAfterAmountRecalc(tempOrder.payment_status)) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
621
651
|
const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
|
|
622
652
|
const targetAmount = this.getPaymentTargetAmount();
|
|
623
653
|
if (targetAmount.lte(0)) {
|
|
@@ -630,6 +660,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
630
660
|
}
|
|
631
661
|
tempOrder.payment_status = paymentTotal.gte(targetAmount) ? "paid" : "partially_paid";
|
|
632
662
|
}
|
|
663
|
+
shouldKeepPaymentStatusAfterAmountRecalc(paymentStatus) {
|
|
664
|
+
const normalizedStatus = String(paymentStatus || "").trim().toLowerCase();
|
|
665
|
+
return normalizedStatus === "refunded" || normalizedStatus === "partially_refunded";
|
|
666
|
+
}
|
|
633
667
|
resolveWalletPassUseValue(payment, amount) {
|
|
634
668
|
const usageUnit = payment.wallet_pass_usage_unit && typeof payment.wallet_pass_usage_unit === "object" ? payment.wallet_pass_usage_unit : null;
|
|
635
669
|
if (!usageUnit)
|
|
@@ -1484,9 +1518,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1484
1518
|
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1485
1519
|
normalizedProduct.discount_list
|
|
1486
1520
|
);
|
|
1521
|
+
const nextNum = (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num);
|
|
1522
|
+
const targetIsManualProductDiscount = isManualProductDiscountProduct(targetProduct);
|
|
1523
|
+
const nextDiscountList = targetIsManualProductDiscount ? (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1524
|
+
(0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
|
|
1525
|
+
targetProduct.discount_list,
|
|
1526
|
+
nextNum
|
|
1527
|
+
)
|
|
1528
|
+
) : normalizedProduct.discount_list;
|
|
1487
1529
|
tempOrder.products[matchedIndex] = {
|
|
1488
1530
|
...targetProduct,
|
|
1489
1531
|
...normalizedProduct,
|
|
1532
|
+
discount_list: nextDiscountList,
|
|
1490
1533
|
metadata: {
|
|
1491
1534
|
...targetProduct.metadata || {},
|
|
1492
1535
|
...normalizedProduct.metadata || {},
|
|
@@ -1497,9 +1540,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1497
1540
|
...normalizedProduct.product_sku || { option: [] },
|
|
1498
1541
|
option: (0, import_utils.getProductSkuOptions)(normalizedProduct)
|
|
1499
1542
|
},
|
|
1543
|
+
...targetIsManualProductDiscount ? {
|
|
1544
|
+
selling_price: targetProduct.selling_price,
|
|
1545
|
+
original_price: targetProduct.original_price,
|
|
1546
|
+
payment_price: targetProduct.payment_price,
|
|
1547
|
+
metadata: {
|
|
1548
|
+
...normalizedProduct.metadata || {},
|
|
1549
|
+
...targetProduct.metadata || {},
|
|
1550
|
+
unique_identification_number: targetUid
|
|
1551
|
+
}
|
|
1552
|
+
} : {},
|
|
1500
1553
|
note: targetProduct.note,
|
|
1501
1554
|
order_detail_id: targetProduct.order_detail_id,
|
|
1502
|
-
num:
|
|
1555
|
+
num: nextNum
|
|
1503
1556
|
};
|
|
1504
1557
|
this.captureProductRuntime(
|
|
1505
1558
|
tempOrder,
|
|
@@ -1603,7 +1656,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1603
1656
|
const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
|
|
1604
1657
|
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;
|
|
1605
1658
|
const isPersistedOrderLine = targetProduct.order_detail_id !== void 0 && targetProduct.order_detail_id !== null;
|
|
1606
|
-
const
|
|
1659
|
+
const callerChangesDiscountList = Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
1660
|
+
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;
|
|
1607
1661
|
if (isPersistedOrderLine && !callerUpdatesManualPrice) {
|
|
1608
1662
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
1609
1663
|
nextProduct.original_price = targetProduct.original_price;
|
|
@@ -1613,7 +1667,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1613
1667
|
source_product_price: (_i = targetProduct.metadata) == null ? void 0 : _i.source_product_price,
|
|
1614
1668
|
main_product_selling_price: (_j = targetProduct.metadata) == null ? void 0 : _j.main_product_selling_price,
|
|
1615
1669
|
main_product_original_price: (_k = targetProduct.metadata) == null ? void 0 : _k.main_product_original_price,
|
|
1616
|
-
price_schema_version: (_l = targetProduct.metadata) == null ? void 0 : _l.price_schema_version
|
|
1670
|
+
price_schema_version: ((_l = targetProduct.metadata) == null ? void 0 : _l.price_schema_version) ?? 2
|
|
1617
1671
|
};
|
|
1618
1672
|
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
1619
1673
|
const existedMeta = nextProduct.metadata || {};
|
|
@@ -167,7 +167,7 @@ function buildManualProductDiscountItem(params) {
|
|
|
167
167
|
const diff = origin.minus(selling);
|
|
168
168
|
const quantity = resolveSafeProductNum(params.quantity);
|
|
169
169
|
return {
|
|
170
|
-
amount: diff.
|
|
170
|
+
amount: diff.toDecimalPlaces(2).toNumber(),
|
|
171
171
|
type: "product",
|
|
172
172
|
discount: {
|
|
173
173
|
message: params.message ?? "",
|
|
@@ -43,30 +43,5 @@ export declare class SalesSummaryModule extends BaseModule implements Module, Sa
|
|
|
43
43
|
rounding_amount: string;
|
|
44
44
|
pay_service_charge_amount: string;
|
|
45
45
|
is_price_include_tax?: number | undefined;
|
|
46
|
-
} | {
|
|
47
|
-
tax_title: string;
|
|
48
|
-
tax_rate: number | undefined;
|
|
49
|
-
product_quantity: number;
|
|
50
|
-
product_original_amount: string;
|
|
51
|
-
product_amount: string;
|
|
52
|
-
product_expect_amount: string;
|
|
53
|
-
product_tax_fee: string;
|
|
54
|
-
shipping_fee: string;
|
|
55
|
-
shipping_tax_fee: string;
|
|
56
|
-
tax_fee: string;
|
|
57
|
-
surcharge_fee: string;
|
|
58
|
-
surcharges: any;
|
|
59
|
-
discount_amount: string;
|
|
60
|
-
deposit_amount: string;
|
|
61
|
-
deposit: import("./types").DepositInfo | undefined;
|
|
62
|
-
expect_amount: string;
|
|
63
|
-
total_amount: string;
|
|
64
|
-
total_refund_amount: string;
|
|
65
|
-
customer_paid_amount: string;
|
|
66
|
-
order_paid_amount: string;
|
|
67
|
-
amount_gap: string;
|
|
68
|
-
rounding_amount: string;
|
|
69
|
-
pay_service_charge_amount: string;
|
|
70
|
-
is_price_include_tax: number;
|
|
71
46
|
}>;
|
|
72
47
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SalesSummaryData, SalesSummaryProduct } from './types';
|
|
2
2
|
export declare function createEmptySalesSummary(): SalesSummaryData;
|
|
3
3
|
export declare function calculateSalesSummary(params: {
|
|
4
4
|
products: SalesSummaryProduct[];
|
|
@@ -8,27 +8,4 @@ export declare function calculateSalesSummary(params: {
|
|
|
8
8
|
scheduleById?: Record<string, any>;
|
|
9
9
|
isInScheduleByDate?: any;
|
|
10
10
|
shopDiscount?: string | number;
|
|
11
|
-
}): SalesSummaryData
|
|
12
|
-
product_quantity: number;
|
|
13
|
-
product_original_amount: string;
|
|
14
|
-
product_amount: string;
|
|
15
|
-
product_expect_amount: string;
|
|
16
|
-
product_tax_fee: string;
|
|
17
|
-
shipping_fee: string;
|
|
18
|
-
shipping_tax_fee: string;
|
|
19
|
-
tax_fee: string;
|
|
20
|
-
surcharge_fee: string;
|
|
21
|
-
surcharges: any;
|
|
22
|
-
discount_amount: string;
|
|
23
|
-
deposit_amount: string;
|
|
24
|
-
deposit: DepositInfo | undefined;
|
|
25
|
-
expect_amount: string;
|
|
26
|
-
total_amount: string;
|
|
27
|
-
total_refund_amount: string;
|
|
28
|
-
customer_paid_amount: string;
|
|
29
|
-
order_paid_amount: string;
|
|
30
|
-
amount_gap: string;
|
|
31
|
-
rounding_amount: string;
|
|
32
|
-
pay_service_charge_amount: string;
|
|
33
|
-
is_price_include_tax: number;
|
|
34
|
-
};
|
|
11
|
+
}): SalesSummaryData;
|