@pisell/pisellos 2.3.74 → 2.3.75
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/core/index.js +6 -10
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +2 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.js +36 -64
- package/dist/modules/Payment/index.js +97 -162
- package/dist/modules/Rules/index.js +1 -4
- package/dist/modules/Schedule/index.js +0 -1
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.js +97 -129
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/order/index.js +2 -4
- package/dist/server/modules/products/index.js +24 -42
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +3 -4
- package/dist/server/modules/schedule/index.js +27 -35
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BaseSales/index.js +38 -41
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.js +0 -2
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -252
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/VenueBooking/index.js +45 -55
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +134 -134
- package/lib/effects/index.js +46 -57
- package/lib/index.js +82 -49
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
- package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
- package/lib/model/strategy/adapter/promotion/examples.js +222 -234
- package/lib/model/strategy/adapter/promotion/index.js +1 -0
- package/lib/model/strategy/adapter/promotion/type.js +243 -36
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +23 -42
- package/lib/modules/BookingContext/index.js +158 -136
- package/lib/modules/BookingContext/types.js +46 -32
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
- package/lib/modules/BookingContext/utils/flexible.js +38 -55
- package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
- package/lib/modules/BookingContext/utils/index.js +124 -41
- package/lib/modules/BookingContext/utils/noResource.js +58 -70
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
- package/lib/modules/BookingContext/utils/productExtend.js +202 -155
- package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
- package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
- package/lib/modules/BookingContext/utils/resources.js +209 -167
- package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
- package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +321 -251
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +70 -78
- package/lib/modules/Cart/utils/changePrice.js +22 -50
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +235 -172
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +122 -127
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.js +70 -76
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.js +1713 -2118
- package/lib/modules/Order/payment-utils.js +77 -120
- package/lib/modules/Order/types.js +88 -35
- package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
- package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
- package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
- package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
- package/lib/modules/Order/utils.js +814 -647
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +532 -399
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +230 -108
- package/lib/modules/Payment/utils.js +52 -51
- package/lib/modules/Payment/walletpass.js +485 -660
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +113 -123
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.js +81 -118
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/ResourcePlanner/index.js +25 -23
- package/lib/modules/ResourcePlanner/localClock.js +54 -119
- package/lib/modules/ResourcePlanner/planner.js +589 -770
- package/lib/modules/ResourcePlanner/types.js +10 -29
- package/lib/modules/Rules/index.js +1218 -959
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +85 -90
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +355 -430
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
- package/lib/modules/Schedule/index.js +100 -114
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -71
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +773 -418
- package/lib/modules/SurchargeList/index.js +46 -60
- package/lib/modules/SurchargeList/types.js +4 -16
- package/lib/modules/index.js +245 -63
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.js +3050 -2665
- package/lib/server/modules/floor-plan/index.js +118 -134
- package/lib/server/modules/floor-plan/types.js +15 -30
- package/lib/server/modules/index.js +106 -68
- package/lib/server/modules/menu/index.js +142 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.js +784 -1002
- package/lib/server/modules/order/types.js +122 -33
- package/lib/server/modules/order/utils/filterBookings.js +219 -194
- package/lib/server/modules/order/utils/filterOrders.js +118 -92
- package/lib/server/modules/payment/index.js +59 -83
- package/lib/server/modules/payment/types.js +4 -16
- package/lib/server/modules/products/index.js +583 -471
- package/lib/server/modules/products/types.js +44 -34
- package/lib/server/modules/quotation/index.js +137 -172
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +220 -186
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +135 -123
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/small-ticket.js +479 -456
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BaseSales/index.js +1186 -1410
- package/lib/solution/BaseSales/types.js +42 -38
- package/lib/solution/BaseSales/utils/cartPromotion.js +642 -498
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
- package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
- package/lib/solution/BaseSales/utils.js +158 -143
- package/lib/solution/BookingByStep/index.js +1527 -1340
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.js +607 -522
- package/lib/solution/BookingTicket/types.js +99 -77
- package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
- package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
- package/lib/solution/BookingTicket/utils/cartView.js +114 -99
- package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
- package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
- package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +228 -156
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.js +328 -324
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +832 -864
- package/lib/solution/ScanOrder/types.js +33 -34
- package/lib/solution/ScanOrder/utils.js +409 -374
- package/lib/solution/ShopDiscount/index.js +226 -232
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +300 -172
- package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
- package/lib/solution/UnifiedBookingSales/types.js +10 -32
- package/lib/solution/VenueBooking/index.js +811 -879
- package/lib/solution/VenueBooking/types.js +19 -39
- package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
- package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +124 -41
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/payment-number.js +26 -46
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,119 +1,92 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";
|
|
28
2
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
__export(small_ticket_exports, {
|
|
32
|
-
buildSmallTicketData: () => buildSmallTicketData,
|
|
33
|
-
hasSmallTicketData: () => hasSmallTicketData
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
34
5
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
|
|
6
|
+
exports.buildSmallTicketData = buildSmallTicketData;
|
|
7
|
+
exports.hasSmallTicketData = hasSmallTicketData;
|
|
8
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
|
+
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
const DEFAULT_LOCALES = ['en', 'zh_CN'];
|
|
12
|
+
const LABELS = {
|
|
40
13
|
en: {
|
|
41
|
-
contactName:
|
|
42
|
-
contactMobile:
|
|
43
|
-
email:
|
|
44
|
-
dineIn:
|
|
45
|
-
takeAway:
|
|
46
|
-
delivery:
|
|
47
|
-
pickUp:
|
|
48
|
-
shopService:
|
|
49
|
-
pickUpTime:
|
|
50
|
-
asap:
|
|
51
|
-
cash:
|
|
52
|
-
eftpos:
|
|
53
|
-
wallet:
|
|
54
|
-
giftCard:
|
|
55
|
-
remainingAmount:
|
|
56
|
-
redeemPoints:
|
|
57
|
-
remainingPoints:
|
|
58
|
-
table:
|
|
59
|
-
orderDiscount:
|
|
60
|
-
manualDiscount:
|
|
61
|
-
payProcessingFee:
|
|
62
|
-
rounding:
|
|
63
|
-
gross:
|
|
64
|
-
tare:
|
|
14
|
+
contactName: 'Contact name',
|
|
15
|
+
contactMobile: 'Contact Mobile',
|
|
16
|
+
email: 'email',
|
|
17
|
+
dineIn: 'Dine-in',
|
|
18
|
+
takeAway: 'Take away',
|
|
19
|
+
delivery: 'Delivery',
|
|
20
|
+
pickUp: 'Pick-up',
|
|
21
|
+
shopService: 'Dine-in',
|
|
22
|
+
pickUpTime: 'Pick-up time',
|
|
23
|
+
asap: 'ASAP',
|
|
24
|
+
cash: 'Cash',
|
|
25
|
+
eftpos: 'Eftpos',
|
|
26
|
+
wallet: 'Wallet',
|
|
27
|
+
giftCard: 'Gift card',
|
|
28
|
+
remainingAmount: 'Remaining amount',
|
|
29
|
+
redeemPoints: 'Redeem points',
|
|
30
|
+
remainingPoints: 'Remaining points',
|
|
31
|
+
table: 'Table',
|
|
32
|
+
orderDiscount: 'Order discount',
|
|
33
|
+
manualDiscount: 'Manual discount',
|
|
34
|
+
payProcessingFee: 'Pay processing fee',
|
|
35
|
+
rounding: 'Rounding',
|
|
36
|
+
gross: 'Gross',
|
|
37
|
+
tare: 'Tare'
|
|
65
38
|
},
|
|
66
39
|
zh_CN: {
|
|
67
|
-
contactName:
|
|
68
|
-
contactMobile:
|
|
69
|
-
email:
|
|
70
|
-
dineIn:
|
|
71
|
-
takeAway:
|
|
72
|
-
delivery:
|
|
73
|
-
pickUp:
|
|
74
|
-
shopService:
|
|
75
|
-
pickUpTime:
|
|
76
|
-
asap:
|
|
77
|
-
cash:
|
|
78
|
-
eftpos:
|
|
79
|
-
wallet:
|
|
80
|
-
giftCard:
|
|
81
|
-
remainingAmount:
|
|
82
|
-
redeemPoints:
|
|
83
|
-
remainingPoints:
|
|
84
|
-
table:
|
|
85
|
-
orderDiscount:
|
|
86
|
-
manualDiscount:
|
|
87
|
-
payProcessingFee:
|
|
88
|
-
rounding:
|
|
89
|
-
gross:
|
|
90
|
-
tare:
|
|
40
|
+
contactName: '联系人姓名',
|
|
41
|
+
contactMobile: '联系电话',
|
|
42
|
+
email: '邮箱',
|
|
43
|
+
dineIn: '堂食',
|
|
44
|
+
takeAway: '外带',
|
|
45
|
+
delivery: '配送',
|
|
46
|
+
pickUp: '自提',
|
|
47
|
+
shopService: '堂食',
|
|
48
|
+
pickUpTime: '取餐时间',
|
|
49
|
+
asap: '尽快',
|
|
50
|
+
cash: '现金支付',
|
|
51
|
+
eftpos: '刷卡支付',
|
|
52
|
+
wallet: '钱包支付',
|
|
53
|
+
giftCard: '礼品卡',
|
|
54
|
+
remainingAmount: '剩余金额',
|
|
55
|
+
redeemPoints: '本次使用积分',
|
|
56
|
+
remainingPoints: '剩余积分',
|
|
57
|
+
table: '桌台',
|
|
58
|
+
orderDiscount: '整单折扣',
|
|
59
|
+
manualDiscount: '手动折扣',
|
|
60
|
+
payProcessingFee: '支付手续费',
|
|
61
|
+
rounding: '抹零',
|
|
62
|
+
gross: '重量',
|
|
63
|
+
tare: '去皮'
|
|
91
64
|
},
|
|
92
65
|
zh_HK: {
|
|
93
|
-
contactName:
|
|
94
|
-
contactMobile:
|
|
95
|
-
email:
|
|
96
|
-
dineIn:
|
|
97
|
-
takeAway:
|
|
98
|
-
delivery:
|
|
99
|
-
pickUp:
|
|
100
|
-
shopService:
|
|
101
|
-
pickUpTime:
|
|
102
|
-
asap:
|
|
103
|
-
cash:
|
|
104
|
-
eftpos:
|
|
105
|
-
wallet:
|
|
106
|
-
giftCard:
|
|
107
|
-
remainingAmount:
|
|
108
|
-
redeemPoints:
|
|
109
|
-
remainingPoints:
|
|
110
|
-
table:
|
|
111
|
-
orderDiscount:
|
|
112
|
-
manualDiscount:
|
|
113
|
-
payProcessingFee:
|
|
114
|
-
rounding:
|
|
115
|
-
gross:
|
|
116
|
-
tare:
|
|
66
|
+
contactName: '聯絡人姓名',
|
|
67
|
+
contactMobile: '聯絡電話',
|
|
68
|
+
email: '電郵',
|
|
69
|
+
dineIn: '堂食',
|
|
70
|
+
takeAway: '外帶',
|
|
71
|
+
delivery: '配送',
|
|
72
|
+
pickUp: '自取',
|
|
73
|
+
shopService: '堂食',
|
|
74
|
+
pickUpTime: '取餐時間',
|
|
75
|
+
asap: '盡快',
|
|
76
|
+
cash: '現金支付',
|
|
77
|
+
eftpos: '刷卡支付',
|
|
78
|
+
wallet: '錢包支付',
|
|
79
|
+
giftCard: '禮品卡',
|
|
80
|
+
remainingAmount: '剩餘金額',
|
|
81
|
+
redeemPoints: '本次使用積分',
|
|
82
|
+
remainingPoints: '剩餘積分',
|
|
83
|
+
table: '桌台',
|
|
84
|
+
orderDiscount: '整單折扣',
|
|
85
|
+
manualDiscount: '手動折扣',
|
|
86
|
+
payProcessingFee: '支付手續費',
|
|
87
|
+
rounding: '抹零',
|
|
88
|
+
gross: '重量',
|
|
89
|
+
tare: '去皮'
|
|
117
90
|
}
|
|
118
91
|
};
|
|
119
92
|
function buildSmallTicketData(params) {
|
|
@@ -122,27 +95,52 @@ function buildSmallTicketData(params) {
|
|
|
122
95
|
const locales = resolveLocales(shopInfo, params.locales);
|
|
123
96
|
const productMap = params.productMap || {};
|
|
124
97
|
return locales.reduce((data, locale) => {
|
|
125
|
-
data[locale] = buildLocaleData({
|
|
98
|
+
data[locale] = buildLocaleData({
|
|
99
|
+
order,
|
|
100
|
+
shopInfo,
|
|
101
|
+
locale,
|
|
102
|
+
productMap
|
|
103
|
+
});
|
|
126
104
|
return data;
|
|
127
105
|
}, {});
|
|
128
106
|
}
|
|
129
107
|
function hasSmallTicketData(value) {
|
|
130
|
-
return !!value && typeof value ===
|
|
108
|
+
return !!value && typeof value === 'object' && Object.keys(value).length > 0;
|
|
131
109
|
}
|
|
132
110
|
function buildLocaleData(params) {
|
|
133
|
-
const {
|
|
111
|
+
const {
|
|
112
|
+
order,
|
|
113
|
+
shopInfo,
|
|
114
|
+
locale,
|
|
115
|
+
productMap
|
|
116
|
+
} = params;
|
|
134
117
|
const products = buildProducts(order, locale, productMap);
|
|
135
118
|
const summary = getSummary(order);
|
|
136
119
|
const currencySymbol = getCurrencySymbol(order, shopInfo);
|
|
137
120
|
return {
|
|
138
|
-
base_data: buildBaseData({
|
|
121
|
+
base_data: buildBaseData({
|
|
122
|
+
order,
|
|
123
|
+
shopInfo,
|
|
124
|
+
locale
|
|
125
|
+
}),
|
|
139
126
|
products,
|
|
140
|
-
fees: buildFees({
|
|
127
|
+
fees: buildFees({
|
|
128
|
+
order,
|
|
129
|
+
shopInfo,
|
|
130
|
+
locale,
|
|
131
|
+
products,
|
|
132
|
+
summary,
|
|
133
|
+
currencySymbol
|
|
134
|
+
}),
|
|
141
135
|
customer: buildCustomer(order, locale),
|
|
142
136
|
appointment: buildAppointment(order, locale),
|
|
143
137
|
// delivery: buildDelivery(order, locale),
|
|
144
138
|
resources: buildResources(order, locale),
|
|
145
|
-
payment_data: buildPaymentData({
|
|
139
|
+
payment_data: buildPaymentData({
|
|
140
|
+
order,
|
|
141
|
+
locale,
|
|
142
|
+
currencySymbol
|
|
143
|
+
}),
|
|
146
144
|
tickets: Array.isArray(order.tickets) ? order.tickets : [],
|
|
147
145
|
source_shop: [],
|
|
148
146
|
refund_data: [],
|
|
@@ -150,11 +148,12 @@ function buildLocaleData(params) {
|
|
|
150
148
|
};
|
|
151
149
|
}
|
|
152
150
|
function buildBaseData(params) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
151
|
+
const {
|
|
152
|
+
order,
|
|
153
|
+
shopInfo,
|
|
154
|
+
locale
|
|
155
|
+
} = params;
|
|
156
|
+
const orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
158
157
|
return {
|
|
159
158
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
160
159
|
note: stringify(order.note),
|
|
@@ -165,18 +164,22 @@ function buildBaseData(params) {
|
|
|
165
164
|
shop_address: stringify(shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
|
|
166
165
|
original_payment_status: stringify(order.payment_status),
|
|
167
166
|
is_repeat: 0,
|
|
168
|
-
buzzer: stringify(order.buzzer || order.pickup_number ||
|
|
167
|
+
buzzer: stringify(order.buzzer || order.pickup_number || order.metadata?.buzzer),
|
|
169
168
|
order_no: orderNumber,
|
|
170
|
-
order_time: formatDateTime(order.created_at || order.sales_time ||
|
|
169
|
+
order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale)
|
|
171
170
|
};
|
|
172
171
|
}
|
|
173
172
|
function buildProducts(order, locale, productMap) {
|
|
174
173
|
const products = Array.isArray(order.products) ? order.products : [];
|
|
175
|
-
return products.map(
|
|
174
|
+
return products.map(product => {
|
|
176
175
|
const quantity = toNumber(product.product_quantity ?? product.quantity ?? product.num ?? 1, 1);
|
|
177
176
|
const originalPrice = product.original_price ?? product.selling_price ?? product.payment_price ?? product.price ?? 0;
|
|
178
177
|
const sellingPrice = product.selling_price ?? product.payment_price ?? product.price ?? originalPrice;
|
|
179
|
-
const productTitle = resolveProductTitle({
|
|
178
|
+
const productTitle = resolveProductTitle({
|
|
179
|
+
product,
|
|
180
|
+
productMap,
|
|
181
|
+
locale
|
|
182
|
+
});
|
|
180
183
|
const parentProduct = resolveProductFromMap(product.product_id ?? product.id, productMap);
|
|
181
184
|
const currencySymbol = getCurrencySymbol(order, null);
|
|
182
185
|
const options = normalizeProductOptions({
|
|
@@ -192,7 +195,11 @@ function buildProducts(order, locale, productMap) {
|
|
|
192
195
|
currencySymbol,
|
|
193
196
|
parentProduct
|
|
194
197
|
});
|
|
195
|
-
const resolvedVariant = resolveProductVariantText({
|
|
198
|
+
const resolvedVariant = resolveProductVariantText({
|
|
199
|
+
product,
|
|
200
|
+
parentProduct,
|
|
201
|
+
locale
|
|
202
|
+
});
|
|
196
203
|
const extensionList = buildProductExtensionList({
|
|
197
204
|
product,
|
|
198
205
|
locale,
|
|
@@ -205,20 +212,33 @@ function buildProducts(order, locale, productMap) {
|
|
|
205
212
|
product_quantity: quantity,
|
|
206
213
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
207
214
|
original_price: formatMoney(originalPrice, currencySymbol),
|
|
208
|
-
total_original_price: formatMoney(new
|
|
215
|
+
total_original_price: formatMoney(new _decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
209
216
|
extension_list: extensionList,
|
|
210
|
-
...options.length ? {
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
...(options.length ? {
|
|
218
|
+
options
|
|
219
|
+
} : {}),
|
|
220
|
+
...(resolvedVariant ? {
|
|
221
|
+
variant: resolvedVariant
|
|
222
|
+
} : {}),
|
|
223
|
+
...(Array.isArray(product.combinations) ? {
|
|
224
|
+
combinations: product.combinations
|
|
225
|
+
} : combinations.length ? {
|
|
226
|
+
combinations
|
|
227
|
+
} : {})
|
|
213
228
|
};
|
|
214
229
|
});
|
|
215
230
|
}
|
|
216
231
|
function normalizeProductDiscounts(params) {
|
|
217
|
-
const {
|
|
218
|
-
|
|
232
|
+
const {
|
|
233
|
+
product,
|
|
234
|
+
locale,
|
|
235
|
+
currencySymbol,
|
|
236
|
+
quantity
|
|
237
|
+
} = params;
|
|
238
|
+
return normalizeArray(product.discount_list).map(discount => {
|
|
219
239
|
const title = resolveDiscountTitleWithPercent(discount, locale);
|
|
220
240
|
const amount = discount.amount ?? discount.value ?? discount.discount_amount;
|
|
221
|
-
const formattedAmount = formatNegativeMoney(new
|
|
241
|
+
const formattedAmount = formatNegativeMoney(new _decimal.default(toMoneyNumber(amount)).mul(quantity), currencySymbol);
|
|
222
242
|
return {
|
|
223
243
|
item: title,
|
|
224
244
|
value: formattedAmount
|
|
@@ -226,35 +246,54 @@ function normalizeProductDiscounts(params) {
|
|
|
226
246
|
});
|
|
227
247
|
}
|
|
228
248
|
function buildProductExtensionList(params) {
|
|
229
|
-
const {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
249
|
+
const {
|
|
250
|
+
product,
|
|
251
|
+
locale,
|
|
252
|
+
currencySymbol,
|
|
253
|
+
quantity,
|
|
254
|
+
originalPrice
|
|
255
|
+
} = params;
|
|
256
|
+
const discountList = normalizeProductDiscounts({
|
|
257
|
+
product,
|
|
258
|
+
locale,
|
|
259
|
+
currencySymbol,
|
|
260
|
+
quantity
|
|
261
|
+
});
|
|
262
|
+
const extensionList = [...buildProductOpenWeightRows({
|
|
263
|
+
product,
|
|
264
|
+
locale,
|
|
265
|
+
currencySymbol
|
|
266
|
+
}), ...(quantity > 1 ? [{
|
|
267
|
+
item: buildProductQuantityPriceText({
|
|
268
|
+
quantity,
|
|
269
|
+
currencySymbol,
|
|
270
|
+
price: originalPrice
|
|
271
|
+
}),
|
|
272
|
+
value: ''
|
|
273
|
+
}] : [])];
|
|
238
274
|
const productExtensionList = extensionList.length ? extensionList : normalizeArray(product.extension_list);
|
|
239
275
|
return [...productExtensionList, ...discountList];
|
|
240
276
|
}
|
|
241
277
|
function buildProductOpenWeightRows(params) {
|
|
242
|
-
const {
|
|
278
|
+
const {
|
|
279
|
+
product,
|
|
280
|
+
locale,
|
|
281
|
+
currencySymbol
|
|
282
|
+
} = params;
|
|
243
283
|
const productSku = product.product_sku || {};
|
|
244
|
-
if (productSku.open_sold_weight != 1)
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
const manualFlag = productSku.weight_source === "manual" ? "(M) " : "";
|
|
284
|
+
if (productSku.open_sold_weight != 1) return [];
|
|
285
|
+
const unit = productSku.unit ?? '';
|
|
286
|
+
const manualFlag = productSku.weight_source === 'manual' ? '(M) ' : '';
|
|
248
287
|
const hasTare = toNumber(productSku.tare_weight, 0) > 0;
|
|
249
288
|
const rows = [];
|
|
250
289
|
if (hasTare) {
|
|
251
290
|
rows.push({
|
|
252
|
-
item: `${manualFlag}${label(locale,
|
|
253
|
-
value:
|
|
291
|
+
item: `${manualFlag}${label(locale, 'gross')}: ${productSku.weight ?? 0}${unit}`,
|
|
292
|
+
value: ''
|
|
254
293
|
});
|
|
255
294
|
rows.push({
|
|
256
|
-
item: `${label(locale,
|
|
257
|
-
value:
|
|
295
|
+
item: `${label(locale, 'tare')}: ${productSku.tare_weight}${unit}`,
|
|
296
|
+
value: ''
|
|
258
297
|
});
|
|
259
298
|
}
|
|
260
299
|
const netWeight = productSku.net_weight ?? 0;
|
|
@@ -262,71 +301,87 @@ function buildProductOpenWeightRows(params) {
|
|
|
262
301
|
const netItem = `${netWeight} ${unit} NET @ ${currencySymbol}${unitPrice}/${unit}`;
|
|
263
302
|
rows.push({
|
|
264
303
|
item: hasTare ? netItem : `${manualFlag}${netItem}`,
|
|
265
|
-
value:
|
|
304
|
+
value: ''
|
|
266
305
|
});
|
|
267
306
|
return rows;
|
|
268
307
|
}
|
|
269
308
|
function buildProductQuantityPriceText(params) {
|
|
270
|
-
const {
|
|
309
|
+
const {
|
|
310
|
+
quantity,
|
|
311
|
+
currencySymbol,
|
|
312
|
+
price
|
|
313
|
+
} = params;
|
|
271
314
|
return `${quantity} @ ${currencySymbol}${stringify(price)} EACH`;
|
|
272
315
|
}
|
|
273
316
|
function resolveDiscountTitleWithPercent(discount, locale) {
|
|
274
|
-
var _a, _b;
|
|
275
317
|
const title = resolveDiscountTitle(discount, locale);
|
|
276
|
-
const percentRaw =
|
|
277
|
-
const cardType =
|
|
278
|
-
const percent = percentRaw !==
|
|
279
|
-
if (percentRaw ===
|
|
280
|
-
|
|
281
|
-
if (
|
|
282
|
-
return title;
|
|
283
|
-
if (Number.isNaN(percent))
|
|
284
|
-
return title;
|
|
318
|
+
const percentRaw = discount.discount?.percent;
|
|
319
|
+
const cardType = discount.discount?.discount_card_type ?? 'percent';
|
|
320
|
+
const percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
|
|
321
|
+
if (percentRaw === undefined || percentRaw === null) return title;
|
|
322
|
+
if (cardType !== 'percent') return title;
|
|
323
|
+
if (Number.isNaN(percent)) return title;
|
|
285
324
|
return `${title} (${percent}%)`;
|
|
286
325
|
}
|
|
287
326
|
function resolveDiscountTitle(discount, locale) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
);
|
|
293
|
-
if (title)
|
|
294
|
-
return title;
|
|
295
|
-
if (discount.type === "product")
|
|
296
|
-
return label(locale, "manualDiscount");
|
|
297
|
-
return "";
|
|
327
|
+
const title = getLocalizedValue(discount.discount?.name ?? discount.discount?.title ?? discount.discount?.message ?? discount.name ?? discount.title ?? discount.message, locale);
|
|
328
|
+
if (title) return title;
|
|
329
|
+
if (discount.type === 'product') return label(locale, 'manualDiscount');
|
|
330
|
+
return '';
|
|
298
331
|
}
|
|
299
332
|
function resolveProductTitle(params) {
|
|
300
|
-
const {
|
|
333
|
+
const {
|
|
334
|
+
product,
|
|
335
|
+
productMap,
|
|
336
|
+
locale
|
|
337
|
+
} = params;
|
|
301
338
|
const ownTitle = getProductTitleSource(product, locale);
|
|
302
|
-
if (ownTitle)
|
|
303
|
-
return ownTitle;
|
|
339
|
+
if (ownTitle) return ownTitle;
|
|
304
340
|
const productId = product.product_id ?? product.id;
|
|
305
341
|
const fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
306
|
-
if (!fallbackProduct)
|
|
307
|
-
return ownTitle || "";
|
|
342
|
+
if (!fallbackProduct) return ownTitle || '';
|
|
308
343
|
return getProductTitleSource(fallbackProduct, locale);
|
|
309
344
|
}
|
|
310
345
|
function normalizeProductOptions(params) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
346
|
+
const {
|
|
347
|
+
product,
|
|
348
|
+
locale,
|
|
349
|
+
currencySymbol,
|
|
350
|
+
parentProduct
|
|
351
|
+
} = params;
|
|
352
|
+
const rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray(product.product_sku?.option) ? product.product_sku.option : [];
|
|
353
|
+
return rawOptions.map(option => {
|
|
315
354
|
const price = option.original_price ?? option.add_price ?? option.price;
|
|
316
355
|
const value = option.value ?? option.option ?? option.item;
|
|
317
|
-
const name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
|
|
356
|
+
const name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
|
|
357
|
+
option,
|
|
358
|
+
parentProduct,
|
|
359
|
+
locale
|
|
360
|
+
});
|
|
318
361
|
return {
|
|
319
362
|
name,
|
|
320
|
-
...option.num !==
|
|
321
|
-
|
|
322
|
-
|
|
363
|
+
...(option.num !== undefined || option.quantity !== undefined ? {
|
|
364
|
+
num: toNumber(option.num ?? option.quantity, 1)
|
|
365
|
+
} : {}),
|
|
366
|
+
...(price !== undefined && price !== null && price !== '' ? {
|
|
367
|
+
price: formatMoney(price, currencySymbol)
|
|
368
|
+
} : {}),
|
|
369
|
+
...(value !== undefined && value !== null && value !== '' ? {
|
|
370
|
+
value: getLocalizedValue(value, locale)
|
|
371
|
+
} : {})
|
|
323
372
|
};
|
|
324
373
|
});
|
|
325
374
|
}
|
|
326
375
|
function normalizeProductCombinations(params) {
|
|
327
|
-
const {
|
|
376
|
+
const {
|
|
377
|
+
product,
|
|
378
|
+
productMap,
|
|
379
|
+
locale,
|
|
380
|
+
currencySymbol,
|
|
381
|
+
parentProduct
|
|
382
|
+
} = params;
|
|
328
383
|
const bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
329
|
-
return bundles.map(
|
|
384
|
+
return bundles.map(bundle => {
|
|
330
385
|
const combinationsOptions = normalizeProductOptions({
|
|
331
386
|
product: {},
|
|
332
387
|
locale,
|
|
@@ -350,44 +405,47 @@ function normalizeProductCombinations(params) {
|
|
|
350
405
|
});
|
|
351
406
|
}
|
|
352
407
|
function resolveBundleProductTitle(params) {
|
|
353
|
-
const {
|
|
408
|
+
const {
|
|
409
|
+
bundle,
|
|
410
|
+
productMap,
|
|
411
|
+
locale,
|
|
412
|
+
parentProduct
|
|
413
|
+
} = params;
|
|
354
414
|
const ownTitle = getProductTitleSource(bundle, locale);
|
|
355
|
-
if (ownTitle)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
415
|
+
if (ownTitle) return ownTitle;
|
|
416
|
+
const parentBundleItem = resolveBundleItemFromParentProduct({
|
|
417
|
+
bundle,
|
|
418
|
+
parentProduct
|
|
419
|
+
});
|
|
420
|
+
const parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
|
|
421
|
+
if (parentBundleTitle) return parentBundleTitle;
|
|
361
422
|
const productId = bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id ?? bundle.id;
|
|
362
423
|
const fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
363
|
-
if (!fallbackProduct)
|
|
364
|
-
return "";
|
|
424
|
+
if (!fallbackProduct) return '';
|
|
365
425
|
return getProductTitleSource(fallbackProduct, locale);
|
|
366
426
|
}
|
|
367
427
|
function resolveProductFromMap(productId, productMap) {
|
|
368
|
-
if (productId ===
|
|
369
|
-
return null;
|
|
428
|
+
if (productId === undefined || productId === null || productId === '') return null;
|
|
370
429
|
return productMap[productId] || productMap[String(productId)] || null;
|
|
371
430
|
}
|
|
372
431
|
function resolveProductVariantText(params) {
|
|
373
|
-
const {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
432
|
+
const {
|
|
433
|
+
product,
|
|
434
|
+
parentProduct,
|
|
435
|
+
locale
|
|
436
|
+
} = params;
|
|
437
|
+
if (product.variant) return getLocalizedValue(product.variant, locale);
|
|
438
|
+
if (!parentProduct) return '';
|
|
378
439
|
const productVariantId = product.product_variant_id ?? product.variant_id;
|
|
379
|
-
if (!isNonZeroId(productVariantId))
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (!matchedVariant)
|
|
383
|
-
return "";
|
|
440
|
+
if (!isNonZeroId(productVariantId)) return '';
|
|
441
|
+
const matchedVariant = normalizeArray(parentProduct.variant).find(variant => isSameId(variant.id, productVariantId));
|
|
442
|
+
if (!matchedVariant) return '';
|
|
384
443
|
const resolvedFromSkuKey = resolveVariantTextFromSkuKey({
|
|
385
444
|
skuKey: matchedVariant.sku_key,
|
|
386
445
|
parentProduct,
|
|
387
446
|
locale
|
|
388
447
|
});
|
|
389
|
-
if (resolvedFromSkuKey)
|
|
390
|
-
return resolvedFromSkuKey;
|
|
448
|
+
if (resolvedFromSkuKey) return resolvedFromSkuKey;
|
|
391
449
|
return resolveVariantTextFromNameMap({
|
|
392
450
|
nameMap: matchedVariant.name || matchedVariant.title,
|
|
393
451
|
parentProduct,
|
|
@@ -396,86 +454,71 @@ function resolveProductVariantText(params) {
|
|
|
396
454
|
}
|
|
397
455
|
function resolveVariantTextFromSkuKey(params) {
|
|
398
456
|
const skuKey = stringify(params.skuKey);
|
|
399
|
-
if (!skuKey)
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
const [groupPositionId, itemPositionId] = item.split(":");
|
|
457
|
+
if (!skuKey) return '';
|
|
458
|
+
return skuKey.split('_').map(item => {
|
|
459
|
+
const [groupPositionId, itemPositionId] = item.split(':');
|
|
403
460
|
return resolveVariantTextItem({
|
|
404
461
|
parentProduct: params.parentProduct,
|
|
405
462
|
groupPositionId,
|
|
406
463
|
itemPositionId,
|
|
407
464
|
locale: params.locale
|
|
408
465
|
});
|
|
409
|
-
}).filter(Boolean).join(
|
|
466
|
+
}).filter(Boolean).join(',');
|
|
410
467
|
}
|
|
411
468
|
function resolveVariantTextFromNameMap(params) {
|
|
412
|
-
if (!params.nameMap || typeof params.nameMap !==
|
|
413
|
-
return "";
|
|
469
|
+
if (!params.nameMap || typeof params.nameMap !== 'object') return '';
|
|
414
470
|
return Object.entries(params.nameMap).map(([groupPositionId, value]) => {
|
|
415
471
|
const group = resolveVariantGroup(params.parentProduct, groupPositionId);
|
|
416
|
-
if (!group)
|
|
417
|
-
return "";
|
|
472
|
+
if (!group) return '';
|
|
418
473
|
const groupName = getLocalizedValue(group.name, params.locale);
|
|
419
474
|
const itemName = getLocalizedValue(value, params.locale);
|
|
420
|
-
if (!groupName || !itemName)
|
|
421
|
-
return "";
|
|
475
|
+
if (!groupName || !itemName) return '';
|
|
422
476
|
return `${groupName}:${itemName}`;
|
|
423
|
-
}).filter(Boolean).join(
|
|
477
|
+
}).filter(Boolean).join(',');
|
|
424
478
|
}
|
|
425
479
|
function resolveVariantTextItem(params) {
|
|
426
480
|
const group = resolveVariantGroup(params.parentProduct, params.groupPositionId);
|
|
427
481
|
const item = resolveVariantItem(group, params.itemPositionId);
|
|
428
|
-
if (!group || !item)
|
|
429
|
-
return "";
|
|
482
|
+
if (!group || !item) return '';
|
|
430
483
|
const groupName = getLocalizedValue(group.name, params.locale);
|
|
431
484
|
const itemName = getLocalizedValue(item.name, params.locale);
|
|
432
|
-
if (!groupName || !itemName)
|
|
433
|
-
return "";
|
|
485
|
+
if (!groupName || !itemName) return '';
|
|
434
486
|
return `${groupName}:${itemName}`;
|
|
435
487
|
}
|
|
436
488
|
function resolveVariantGroup(parentProduct, groupPositionId) {
|
|
437
|
-
return normalizeArray(parentProduct.variant_group).find(
|
|
438
|
-
(group) => isSameId(group.position_id, groupPositionId) || isSameId(group.id, groupPositionId)
|
|
439
|
-
) || null;
|
|
489
|
+
return normalizeArray(parentProduct.variant_group).find(group => isSameId(group.position_id, groupPositionId) || isSameId(group.id, groupPositionId)) || null;
|
|
440
490
|
}
|
|
441
491
|
function resolveVariantItem(group, itemPositionId) {
|
|
442
|
-
if (!group)
|
|
443
|
-
|
|
444
|
-
return normalizeArray(group.variant_item).find(
|
|
445
|
-
(item) => isSameId(item.position_id, itemPositionId) || isSameId(item.id, itemPositionId)
|
|
446
|
-
) || null;
|
|
492
|
+
if (!group) return null;
|
|
493
|
+
return normalizeArray(group.variant_item).find(item => isSameId(item.position_id, itemPositionId) || isSameId(item.id, itemPositionId)) || null;
|
|
447
494
|
}
|
|
448
495
|
function getProductTitleSource(source, locale) {
|
|
449
|
-
if (!source || typeof source !==
|
|
450
|
-
return "";
|
|
496
|
+
if (!source || typeof source !== 'object') return '';
|
|
451
497
|
return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
|
|
452
498
|
}
|
|
453
499
|
function resolveTitleValue(value, locale) {
|
|
454
|
-
if (value ===
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const underscoredLocale = locale.replace("-", "_");
|
|
460
|
-
return stringify(
|
|
461
|
-
value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? ""
|
|
462
|
-
);
|
|
500
|
+
if (value === undefined || value === null) return '';
|
|
501
|
+
if (typeof value !== 'object') return stringify(value);
|
|
502
|
+
const dashedLocale = locale.replace('_', '-');
|
|
503
|
+
const underscoredLocale = locale.replace('-', '_');
|
|
504
|
+
return stringify(value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? '');
|
|
463
505
|
}
|
|
464
506
|
function resolveOptionTitleFromParentProduct(params) {
|
|
465
|
-
const {
|
|
466
|
-
|
|
467
|
-
|
|
507
|
+
const {
|
|
508
|
+
option,
|
|
509
|
+
parentProduct,
|
|
510
|
+
locale
|
|
511
|
+
} = params;
|
|
512
|
+
if (!parentProduct) return '';
|
|
468
513
|
const optionItems = flattenOptionItems(parentProduct);
|
|
469
|
-
const matchedOption = optionItems.find(
|
|
514
|
+
const matchedOption = optionItems.find(item => isOptionItemMatch(option, item));
|
|
470
515
|
return getProductTitleSource(matchedOption, locale);
|
|
471
516
|
}
|
|
472
517
|
function flattenOptionItems(parentProduct) {
|
|
473
518
|
const optionGroups = Array.isArray(parentProduct.option_group) ? parentProduct.option_group : [];
|
|
474
|
-
return optionGroups.flatMap(
|
|
475
|
-
const items = normalizeArray(
|
|
476
|
-
|
|
477
|
-
);
|
|
478
|
-
return items.map((item) => ({
|
|
519
|
+
return optionGroups.flatMap(group => {
|
|
520
|
+
const items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
|
|
521
|
+
return items.map(item => ({
|
|
479
522
|
...item,
|
|
480
523
|
option_group_id: item.option_group_id ?? group.id ?? group.option_group_id
|
|
481
524
|
}));
|
|
@@ -484,8 +527,7 @@ function flattenOptionItems(parentProduct) {
|
|
|
484
527
|
function isOptionItemMatch(option, item) {
|
|
485
528
|
const optionItemId = option.option_group_item_id ?? option.product_option_item_id ?? option.id;
|
|
486
529
|
const itemId = item.option_group_item_id ?? item.product_option_item_id ?? item.id;
|
|
487
|
-
if (!isSameId(optionItemId, itemId))
|
|
488
|
-
return false;
|
|
530
|
+
if (!isSameId(optionItemId, itemId)) return false;
|
|
489
531
|
const optionGroupId = option.option_group_id ?? option.group_id;
|
|
490
532
|
const itemGroupId = item.option_group_id ?? item.group_id;
|
|
491
533
|
if (isPresentId(optionGroupId) && isPresentId(itemGroupId)) {
|
|
@@ -494,86 +536,83 @@ function isOptionItemMatch(option, item) {
|
|
|
494
536
|
return true;
|
|
495
537
|
}
|
|
496
538
|
function resolveBundleItemFromParentProduct(params) {
|
|
497
|
-
const {
|
|
498
|
-
|
|
499
|
-
|
|
539
|
+
const {
|
|
540
|
+
bundle,
|
|
541
|
+
parentProduct
|
|
542
|
+
} = params;
|
|
543
|
+
if (!parentProduct) return null;
|
|
500
544
|
const bundleItems = flattenBundleItems(parentProduct);
|
|
501
545
|
const bundleVariantId = bundle.bundle_variant_id ?? bundle.variant_id ?? bundle.product_variant_id;
|
|
502
546
|
if (isNonZeroId(bundleVariantId)) {
|
|
503
|
-
const matchedByVariant = bundleItems.find(
|
|
504
|
-
|
|
505
|
-
);
|
|
506
|
-
if (matchedByVariant)
|
|
507
|
-
return matchedByVariant;
|
|
547
|
+
const matchedByVariant = bundleItems.find(item => isSameId(item.bundle_variant_id ?? item.variant_id ?? item.product_variant_id, bundleVariantId));
|
|
548
|
+
if (matchedByVariant) return matchedByVariant;
|
|
508
549
|
}
|
|
509
550
|
const bundleId = bundle.bundle_id ?? bundle.id;
|
|
510
551
|
if (isPresentId(bundleId)) {
|
|
511
|
-
const matchedByBundleId = bundleItems.find(
|
|
512
|
-
if (matchedByBundleId)
|
|
513
|
-
return matchedByBundleId;
|
|
552
|
+
const matchedByBundleId = bundleItems.find(item => isSameId(item.id ?? item.bundle_id, bundleId));
|
|
553
|
+
if (matchedByBundleId) return matchedByBundleId;
|
|
514
554
|
}
|
|
515
555
|
const bundleGroupId = bundle.bundle_group_id ?? bundle.group_id;
|
|
516
556
|
const bundleProductId = bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id;
|
|
517
557
|
if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
|
|
518
|
-
const matchedByGroupAndProduct = bundleItems.find(
|
|
519
|
-
|
|
520
|
-
);
|
|
521
|
-
if (matchedByGroupAndProduct)
|
|
522
|
-
return matchedByGroupAndProduct;
|
|
558
|
+
const matchedByGroupAndProduct = bundleItems.find(item => isSameId(item.group_id ?? item.bundle_group_id, bundleGroupId) && isSameId(item.bundle_product_id ?? item._bundle_product_id ?? item.product_id, bundleProductId));
|
|
559
|
+
if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
|
|
523
560
|
}
|
|
524
561
|
if (isPresentId(bundleProductId)) {
|
|
525
|
-
return bundleItems.find(
|
|
526
|
-
(item) => isSameId(item.bundle_product_id ?? item._bundle_product_id ?? item.product_id, bundleProductId)
|
|
527
|
-
) || null;
|
|
562
|
+
return bundleItems.find(item => isSameId(item.bundle_product_id ?? item._bundle_product_id ?? item.product_id, bundleProductId)) || null;
|
|
528
563
|
}
|
|
529
564
|
return null;
|
|
530
565
|
}
|
|
531
566
|
function flattenBundleItems(parentProduct) {
|
|
532
567
|
const bundleGroups = Array.isArray(parentProduct.bundle_group) ? parentProduct.bundle_group : [];
|
|
533
|
-
return bundleGroups.flatMap(
|
|
568
|
+
return bundleGroups.flatMap(group => {
|
|
534
569
|
const items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
|
|
535
|
-
return items.map(
|
|
570
|
+
return items.map(item => ({
|
|
536
571
|
...item,
|
|
537
572
|
group_id: item.group_id ?? group.id ?? group.group_id
|
|
538
573
|
}));
|
|
539
574
|
});
|
|
540
575
|
}
|
|
541
576
|
function isNonZeroId(value) {
|
|
542
|
-
return isPresentId(value) && String(value) !==
|
|
577
|
+
return isPresentId(value) && String(value) !== '0';
|
|
543
578
|
}
|
|
544
579
|
function isPresentId(value) {
|
|
545
|
-
return value !==
|
|
580
|
+
return value !== undefined && value !== null && value !== '';
|
|
546
581
|
}
|
|
547
582
|
function isSameId(left, right) {
|
|
548
|
-
if (!isPresentId(left) || !isPresentId(right))
|
|
549
|
-
return false;
|
|
583
|
+
if (!isPresentId(left) || !isPresentId(right)) return false;
|
|
550
584
|
return String(left) === String(right);
|
|
551
585
|
}
|
|
552
586
|
function buildOptionTitleSuffix(options) {
|
|
553
|
-
const text = options.map(
|
|
587
|
+
const text = options.map(option => {
|
|
554
588
|
const name = stringify(option.name).trim();
|
|
555
|
-
if (!name)
|
|
556
|
-
return "";
|
|
589
|
+
if (!name) return '';
|
|
557
590
|
const quantity = option.num ?? 1;
|
|
558
591
|
return `${name} x ${quantity}`;
|
|
559
|
-
}).filter(Boolean).join(
|
|
560
|
-
return text ? `(${text})` :
|
|
592
|
+
}).filter(Boolean).join(', ');
|
|
593
|
+
return text ? `(${text})` : '';
|
|
561
594
|
}
|
|
562
595
|
function formatBundlePrice(bundle, currencySymbol) {
|
|
563
596
|
const value = bundle.bundle_selling_price ?? bundle.bundle_sum_price ?? bundle.price ?? 0;
|
|
564
|
-
const amount = new
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
597
|
+
const amount = new _decimal.default(toMoneyNumber(value));
|
|
598
|
+
// 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
|
|
599
|
+
const isNegative = bundle.price_type === 'markdown';
|
|
600
|
+
if (isNegative) return `-${currencySymbol}${amount.abs().toFixed(2)}`;
|
|
568
601
|
return formatMoney(amount, currencySymbol);
|
|
569
602
|
}
|
|
570
603
|
function buildFees(params) {
|
|
571
|
-
const {
|
|
604
|
+
const {
|
|
605
|
+
order,
|
|
606
|
+
shopInfo,
|
|
607
|
+
locale,
|
|
608
|
+
products,
|
|
609
|
+
summary,
|
|
610
|
+
currencySymbol
|
|
611
|
+
} = params;
|
|
572
612
|
const fees = [];
|
|
573
613
|
for (const surcharge of normalizeArray(order.surcharges || summary.surcharges)) {
|
|
574
614
|
const value = surcharge.amount ?? surcharge.value ?? surcharge.total_amount;
|
|
575
|
-
if (!isNonZero(value))
|
|
576
|
-
continue;
|
|
615
|
+
if (!isNonZero(value)) continue;
|
|
577
616
|
fees.push({
|
|
578
617
|
item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
|
|
579
618
|
value: formatMoney(value, currencySymbol)
|
|
@@ -582,7 +621,7 @@ function buildFees(params) {
|
|
|
582
621
|
const discountAmount = order.shop_discount ?? summary.discount_amount ?? order.discount_amount;
|
|
583
622
|
if (isNonZero(discountAmount)) {
|
|
584
623
|
fees.push({
|
|
585
|
-
item: label(locale,
|
|
624
|
+
item: label(locale, 'orderDiscount'),
|
|
586
625
|
value: formatNegativeMoney(discountAmount, currencySymbol)
|
|
587
626
|
});
|
|
588
627
|
}
|
|
@@ -596,126 +635,154 @@ function buildFees(params) {
|
|
|
596
635
|
const roundingAmount = summary.rounding_amount || order.rounding_amount;
|
|
597
636
|
if (isNonZero(roundingAmount)) {
|
|
598
637
|
fees.push({
|
|
599
|
-
item: label(locale,
|
|
638
|
+
item: label(locale, 'rounding'),
|
|
600
639
|
value: formatMoney(roundingAmount, currencySymbol)
|
|
601
640
|
});
|
|
602
641
|
}
|
|
603
642
|
const payProcessingFee = summary.pay_service_charge_amount || order.pay_service_charge_amount;
|
|
604
643
|
if (isNonZero(payProcessingFee)) {
|
|
605
644
|
fees.push({
|
|
606
|
-
item: label(locale,
|
|
645
|
+
item: label(locale, 'payProcessingFee'),
|
|
607
646
|
value: formatMoney(payProcessingFee, currencySymbol)
|
|
608
647
|
});
|
|
609
648
|
}
|
|
610
649
|
const productExpectAmount = summary.product_expect_amount || summary.product_amount || order.product_expect_amount;
|
|
611
650
|
const productOriginalAmount = summary.product_original_amount ?? order.product_original_amount ?? productExpectAmount;
|
|
612
|
-
const totalSavingsAmount = new
|
|
651
|
+
const totalSavingsAmount = new _decimal.default(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
613
652
|
return {
|
|
614
653
|
fees,
|
|
615
654
|
countFee: {
|
|
616
655
|
total_amount: formatMoney(summary.total_amount || order.total_amount, currencySymbol),
|
|
617
656
|
product_expect_amount: formatMoney(productExpectAmount, currencySymbol),
|
|
618
657
|
expect_amount: formatMoney(summary.expect_amount || order.expect_amount || summary.total_amount || order.total_amount, currencySymbol),
|
|
619
|
-
product_quantity: toNumber(
|
|
620
|
-
summary.product_quantity || products.reduce((sum, product) => sum + product.product_quantity, 0),
|
|
621
|
-
0
|
|
622
|
-
),
|
|
658
|
+
product_quantity: toNumber(summary.product_quantity || products.reduce((sum, product) => sum + product.product_quantity, 0), 0),
|
|
623
659
|
has_pay: formatMoney(calculateReceiptPaidAmount(order, summary), currencySymbol),
|
|
624
|
-
payment_method:
|
|
660
|
+
payment_method: '',
|
|
625
661
|
tax_title: stringify(summary.tax_title || order.tax_title || shopInfo.tax_title),
|
|
626
662
|
total_refund_amount: formatMoney(summary.total_refund_amount || order.total_refund_amount, currencySymbol),
|
|
627
|
-
...isNonZero(roundingAmount) ? {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
...isNonZero(
|
|
663
|
+
...(isNonZero(roundingAmount) ? {
|
|
664
|
+
rounding_amount: formatMoney(roundingAmount, currencySymbol)
|
|
665
|
+
} : {}),
|
|
666
|
+
...(isNonZero(totalSavingsAmount) ? {
|
|
667
|
+
order_total_discount: formatMoney(totalSavingsAmount, currencySymbol)
|
|
668
|
+
} : {}),
|
|
669
|
+
...(isNonZero(payProcessingFee) ? {
|
|
670
|
+
pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
|
|
671
|
+
} : {}),
|
|
672
|
+
...(isNonZero(taxFee) ? {
|
|
673
|
+
tax_fee: formatMoney(taxFee, currencySymbol)
|
|
674
|
+
} : {})
|
|
631
675
|
}
|
|
632
676
|
};
|
|
633
677
|
}
|
|
634
678
|
function buildCustomer(order, locale) {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
679
|
+
return [{
|
|
680
|
+
item: label(locale, 'contactName'),
|
|
681
|
+
value: normalizeCustomerDisplayValue(order.customer_name || order.customer?.name || order.customer?.display_name)
|
|
682
|
+
}, {
|
|
683
|
+
item: label(locale, 'contactMobile'),
|
|
684
|
+
value: stringify(order.phone || order.customer?.phone)
|
|
685
|
+
}, {
|
|
686
|
+
item: label(locale, 'email'),
|
|
687
|
+
value: stringify(order.email || order.customer?.email)
|
|
688
|
+
}];
|
|
641
689
|
}
|
|
642
690
|
function normalizeCustomerDisplayValue(value) {
|
|
643
691
|
const text = stringify(value).trim();
|
|
644
|
-
if (!text)
|
|
645
|
-
|
|
646
|
-
if (text.toLowerCase() === "select a customer")
|
|
647
|
-
return "Walk-In";
|
|
692
|
+
if (!text) return 'Walk-In';
|
|
693
|
+
if (text.toLowerCase() === 'select a customer') return 'Walk-In';
|
|
648
694
|
return text;
|
|
649
695
|
}
|
|
696
|
+
function buildDelivery(order, locale) {
|
|
697
|
+
const serviceType = stringify(order.metadata?.service_type || order.service_type || order.delivery_type);
|
|
698
|
+
if (!serviceType) return [];
|
|
699
|
+
const serviceTypeLabelKey = serviceTypeToLabelKey(serviceType);
|
|
700
|
+
const items = [{
|
|
701
|
+
item: '',
|
|
702
|
+
value: label(locale, serviceTypeLabelKey),
|
|
703
|
+
size: 2,
|
|
704
|
+
align: 'left'
|
|
705
|
+
}];
|
|
706
|
+
if (serviceType === 'shop_server' || serviceType === 'shop_service') {
|
|
707
|
+
items.push({
|
|
708
|
+
item: label(locale, 'pickUpTime'),
|
|
709
|
+
value: label(locale, 'asap')
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
return items;
|
|
713
|
+
}
|
|
650
714
|
function buildAppointment(order, locale) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
item: label(locale, "table"),
|
|
658
|
-
value: getLocalizedValue(tableName, locale)
|
|
659
|
-
}
|
|
660
|
-
];
|
|
715
|
+
const tableName = order.table_name || order.metadata?.table_name || order.metadata?.table?.name || order.form_data?.table_name;
|
|
716
|
+
if (!tableName) return [];
|
|
717
|
+
return [{
|
|
718
|
+
item: label(locale, 'table'),
|
|
719
|
+
value: getLocalizedValue(tableName, locale)
|
|
720
|
+
}];
|
|
661
721
|
}
|
|
662
722
|
function buildResources(order, locale) {
|
|
663
|
-
return normalizeArray(order.resources || order.resource_list).map(
|
|
664
|
-
id: resource.id || resource.resource_id ||
|
|
665
|
-
code:
|
|
723
|
+
return normalizeArray(order.resources || order.resource_list).map(resource => ({
|
|
724
|
+
id: resource.id || resource.resource_id || '',
|
|
725
|
+
code: '',
|
|
666
726
|
title: getLocalizedValue(resource.title || resource.name, locale),
|
|
667
|
-
form_title: getLocalizedValue(resource.form_title || resource.type ||
|
|
727
|
+
form_title: getLocalizedValue(resource.form_title || resource.type || '', locale)
|
|
668
728
|
}));
|
|
669
729
|
}
|
|
670
730
|
function buildPaymentData(params) {
|
|
671
731
|
const payments = normalizeArray(params.order.payments);
|
|
672
|
-
return payments.filter(
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
value: formatMoney(payment.amount ?? payment.origin_amount, params.currencySymbol)
|
|
678
|
-
}
|
|
679
|
-
];
|
|
732
|
+
return payments.filter(payment => isPrintablePayment(payment)).map(payment => {
|
|
733
|
+
const items = [{
|
|
734
|
+
item: paymentMethodName(payment, params.locale),
|
|
735
|
+
value: formatMoney(payment.amount ?? payment.origin_amount, params.currencySymbol)
|
|
736
|
+
}];
|
|
680
737
|
const fundRecord = getFundRecord(payment);
|
|
681
738
|
if (fundRecord) {
|
|
682
|
-
items.push(...buildFundRecordPaymentItems({
|
|
739
|
+
items.push(...buildFundRecordPaymentItems({
|
|
740
|
+
payment,
|
|
741
|
+
fundRecord,
|
|
742
|
+
locale: params.locale,
|
|
743
|
+
currencySymbol: params.currencySymbol
|
|
744
|
+
}));
|
|
683
745
|
} else {
|
|
684
|
-
const remainingAmount = payment.remaining_amount ?? payment.balance ??
|
|
685
|
-
if (remainingAmount !==
|
|
746
|
+
const remainingAmount = payment.remaining_amount ?? payment.balance ?? payment.metadata?.remaining_amount;
|
|
747
|
+
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
686
748
|
items.push({
|
|
687
|
-
item: label(params.locale,
|
|
749
|
+
item: label(params.locale, 'remainingAmount'),
|
|
688
750
|
value: formatMoney(remainingAmount, params.currencySymbol)
|
|
689
751
|
});
|
|
690
752
|
}
|
|
691
753
|
}
|
|
692
754
|
items.push({
|
|
693
|
-
item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at ||
|
|
694
|
-
value:
|
|
755
|
+
item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), params.locale),
|
|
756
|
+
value: ''
|
|
695
757
|
});
|
|
696
758
|
return items;
|
|
697
759
|
});
|
|
698
760
|
}
|
|
699
761
|
function buildFundRecordPaymentItems(params) {
|
|
700
|
-
const {
|
|
762
|
+
const {
|
|
763
|
+
payment,
|
|
764
|
+
fundRecord,
|
|
765
|
+
locale,
|
|
766
|
+
currencySymbol
|
|
767
|
+
} = params;
|
|
701
768
|
const items = [];
|
|
702
769
|
const usingBeforeValue = fundRecord.using_before_value;
|
|
703
770
|
const usingAfterValue = fundRecord.using_after_value;
|
|
704
|
-
if (isPointCardPayment(payment) && usingBeforeValue !==
|
|
705
|
-
const usedPoints = new
|
|
771
|
+
if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
|
|
772
|
+
const usedPoints = new _decimal.default(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
|
|
706
773
|
items.push({
|
|
707
|
-
item: label(locale,
|
|
774
|
+
item: label(locale, 'redeemPoints'),
|
|
708
775
|
value: trimDecimal(usedPoints)
|
|
709
776
|
});
|
|
710
777
|
items.push({
|
|
711
|
-
item: label(locale,
|
|
712
|
-
value: trimDecimal(new
|
|
778
|
+
item: label(locale, 'remainingPoints'),
|
|
779
|
+
value: trimDecimal(new _decimal.default(toMoneyNumber(usingAfterValue)))
|
|
713
780
|
});
|
|
714
781
|
return items;
|
|
715
782
|
}
|
|
716
|
-
if (usingAfterValue !==
|
|
783
|
+
if (usingAfterValue !== undefined && usingAfterValue !== null) {
|
|
717
784
|
items.push({
|
|
718
|
-
item: label(locale,
|
|
785
|
+
item: label(locale, 'remainingAmount'),
|
|
719
786
|
value: formatMoney(usingAfterValue, currencySymbol)
|
|
720
787
|
});
|
|
721
788
|
}
|
|
@@ -723,169 +790,131 @@ function buildFundRecordPaymentItems(params) {
|
|
|
723
790
|
}
|
|
724
791
|
function getFundRecord(payment) {
|
|
725
792
|
const fundRecord = payment.fund_record;
|
|
726
|
-
if (!fundRecord || typeof fundRecord !==
|
|
727
|
-
|
|
728
|
-
if (!fundRecord.voucher_id && !fundRecord.code)
|
|
729
|
-
return null;
|
|
793
|
+
if (!fundRecord || typeof fundRecord !== 'object' || Array.isArray(fundRecord)) return null;
|
|
794
|
+
if (!fundRecord.voucher_id && !fundRecord.code) return null;
|
|
730
795
|
return fundRecord;
|
|
731
796
|
}
|
|
732
797
|
function isPointCardPayment(payment) {
|
|
733
|
-
var _a;
|
|
734
798
|
const code = stringify(payment.code || payment.payment_method).toUpperCase();
|
|
735
|
-
const type = stringify(payment.type ||
|
|
736
|
-
return code ===
|
|
799
|
+
const type = stringify(payment.type || payment.fund_record?.tag).toLowerCase();
|
|
800
|
+
return code === 'POINTCARD' || type === 'point_card';
|
|
737
801
|
}
|
|
738
802
|
function maskMachineCode(code) {
|
|
739
803
|
const text = stringify(code);
|
|
740
|
-
if (text.length <= 6)
|
|
741
|
-
return text;
|
|
804
|
+
if (text.length <= 6) return text;
|
|
742
805
|
return `${text.slice(0, 2)}**${text.slice(-4)}`;
|
|
743
806
|
}
|
|
744
807
|
function trimDecimal(value) {
|
|
745
|
-
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/,
|
|
808
|
+
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
|
|
746
809
|
}
|
|
747
810
|
function getFundRecordPaymentName(payment, locale) {
|
|
748
811
|
const fundRecord = getFundRecord(payment);
|
|
749
|
-
if (!fundRecord)
|
|
750
|
-
return "";
|
|
812
|
+
if (!fundRecord) return '';
|
|
751
813
|
const name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
|
|
752
814
|
const code = maskMachineCode(fundRecord.code);
|
|
753
|
-
if (!name && !code)
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
return name;
|
|
757
|
-
const fallbackName = getLocalizedValue(
|
|
758
|
-
payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code,
|
|
759
|
-
locale
|
|
760
|
-
);
|
|
815
|
+
if (!name && !code) return '';
|
|
816
|
+
if (!code) return name;
|
|
817
|
+
const fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
|
|
761
818
|
return `${name || fallbackName}(${code})`;
|
|
762
819
|
}
|
|
763
820
|
function appendMachineCodeToName(name, payment) {
|
|
764
821
|
const fundRecord = getFundRecord(payment);
|
|
765
|
-
if (!
|
|
766
|
-
return name;
|
|
822
|
+
if (!fundRecord?.code) return name;
|
|
767
823
|
return `${name}(${maskMachineCode(fundRecord.code)})`;
|
|
768
824
|
}
|
|
769
825
|
function paymentMethodName(payment, locale) {
|
|
770
826
|
const fundRecordName = getFundRecordPaymentName(payment, locale);
|
|
771
|
-
if (fundRecordName)
|
|
772
|
-
return fundRecordName;
|
|
827
|
+
if (fundRecordName) return fundRecordName;
|
|
773
828
|
const raw = payment.name || payment.title || payment.payment_method_name || payment.method_name;
|
|
774
|
-
if (raw)
|
|
775
|
-
return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
|
|
829
|
+
if (raw) return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
|
|
776
830
|
const code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
|
|
777
|
-
if (code.includes(
|
|
778
|
-
|
|
779
|
-
if (code.includes(
|
|
780
|
-
|
|
781
|
-
if (code.includes("wallet"))
|
|
782
|
-
return label(locale, "wallet");
|
|
783
|
-
if (code.includes("gift"))
|
|
784
|
-
return label(locale, "giftCard");
|
|
831
|
+
if (code.includes('cash')) return label(locale, 'cash');
|
|
832
|
+
if (code.includes('eftpos') || code.includes('card')) return label(locale, 'eftpos');
|
|
833
|
+
if (code.includes('wallet')) return label(locale, 'wallet');
|
|
834
|
+
if (code.includes('gift')) return label(locale, 'giftCard');
|
|
785
835
|
return stringify(payment.code || payment.type || payment.payment_method || payment.method);
|
|
786
836
|
}
|
|
787
837
|
function getSummary(order) {
|
|
788
|
-
return order.summary && typeof order.summary ===
|
|
838
|
+
return order.summary && typeof order.summary === 'object' ? order.summary : order;
|
|
789
839
|
}
|
|
790
840
|
function getCurrencySymbol(order, shopInfo) {
|
|
791
|
-
return stringify(order.currency_symbol ||
|
|
841
|
+
return stringify(order.currency_symbol || shopInfo?.currency_symbol || order.shop_symbol || '$') || '$';
|
|
792
842
|
}
|
|
793
843
|
function resolveLocales(shopInfo, locales) {
|
|
794
|
-
const preferred = [
|
|
795
|
-
...locales || [],
|
|
796
|
-
shopInfo.primary_locale,
|
|
797
|
-
...DEFAULT_LOCALES
|
|
798
|
-
].filter(Boolean);
|
|
844
|
+
const preferred = [...(locales || []), shopInfo.primary_locale, ...DEFAULT_LOCALES].filter(Boolean);
|
|
799
845
|
return Array.from(new Set(preferred.map(normalizeLocaleKey)));
|
|
800
846
|
}
|
|
801
847
|
function normalizeLocaleKey(locale) {
|
|
802
|
-
return locale.replace(
|
|
848
|
+
return locale.replace('-', '_');
|
|
803
849
|
}
|
|
804
850
|
function label(locale, key) {
|
|
805
|
-
|
|
806
|
-
return ((_a = LABELS[locale]) == null ? void 0 : _a[key]) || LABELS.en[key] || key;
|
|
851
|
+
return LABELS[locale]?.[key] || LABELS.en[key] || key;
|
|
807
852
|
}
|
|
808
853
|
function getLocalizedValue(value, locale) {
|
|
809
|
-
if (value ===
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
);
|
|
854
|
+
if (value === undefined || value === null) return '';
|
|
855
|
+
if (typeof value !== 'object') return stringify(value);
|
|
856
|
+
const dashedLocale = locale.replace('_', '-');
|
|
857
|
+
const underscoredLocale = locale.replace('-', '_');
|
|
858
|
+
return stringify(value[locale] ?? value[dashedLocale] ?? value[underscoredLocale] ?? value.original ?? value.auto ?? value.default ?? value.en ?? '');
|
|
859
|
+
}
|
|
860
|
+
function serviceTypeToLabelKey(serviceType) {
|
|
861
|
+
const normalized = serviceType.toLowerCase();
|
|
862
|
+
if (normalized.includes('take')) return 'takeAway';
|
|
863
|
+
if (normalized.includes('delivery')) return 'delivery';
|
|
864
|
+
if (normalized.includes('pick')) return 'pickUp';
|
|
865
|
+
if (normalized.includes('shop')) return 'shopService';
|
|
866
|
+
return 'dineIn';
|
|
818
867
|
}
|
|
819
868
|
function buildShopAddress(shopInfo) {
|
|
820
|
-
return [
|
|
821
|
-
shopInfo.address_street,
|
|
822
|
-
shopInfo.address_detail,
|
|
823
|
-
shopInfo.city,
|
|
824
|
-
shopInfo.province,
|
|
825
|
-
shopInfo.country,
|
|
826
|
-
shopInfo.zip
|
|
827
|
-
].filter(Boolean).join(", ");
|
|
869
|
+
return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
|
|
828
870
|
}
|
|
829
871
|
function formatDateTime(value, locale) {
|
|
830
|
-
const date = (0,
|
|
831
|
-
if (!date.isValid())
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
return date.format("HH:mm:ss DD/MM/YYYY");
|
|
835
|
-
return date.format("YYYY/MM/DD HH:mm:ss");
|
|
872
|
+
const date = (0, _dayjs.default)(value);
|
|
873
|
+
if (!date.isValid()) return stringify(value);
|
|
874
|
+
if (locale === 'en') return date.format('HH:mm:ss DD/MM/YYYY');
|
|
875
|
+
return date.format('YYYY/MM/DD HH:mm:ss');
|
|
836
876
|
}
|
|
837
877
|
function formatMoney(value, currencySymbol) {
|
|
838
|
-
if (value instanceof
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
return value;
|
|
842
|
-
const amount = new import_decimal.default(toMoneyNumber(value));
|
|
878
|
+
if (value instanceof _decimal.default) return `${currencySymbol}${value.toFixed(2)}`;
|
|
879
|
+
if (typeof value === 'string' && value.trim().startsWith(currencySymbol)) return value;
|
|
880
|
+
const amount = new _decimal.default(toMoneyNumber(value));
|
|
843
881
|
return `${currencySymbol}${amount.toFixed(2)}`;
|
|
844
882
|
}
|
|
845
883
|
function formatNegativeMoney(value, currencySymbol) {
|
|
846
|
-
const amount = new
|
|
884
|
+
const amount = new _decimal.default(toMoneyNumber(value)).abs();
|
|
847
885
|
return `-${currencySymbol}${amount.toFixed(2)}`;
|
|
848
886
|
}
|
|
849
887
|
function calculateReceiptPaidAmount(order, summary) {
|
|
850
888
|
const paidAmount = sumPayments(order.payments);
|
|
851
|
-
const payProcessingFee = new
|
|
852
|
-
|
|
853
|
-
);
|
|
854
|
-
if (
|
|
855
|
-
return paidAmount;
|
|
856
|
-
const totalAmount = new import_decimal.default(toMoneyNumber(summary.total_amount ?? order.total_amount));
|
|
857
|
-
if (totalAmount.gt(0) && paidAmount.gte(totalAmount))
|
|
858
|
-
return paidAmount;
|
|
889
|
+
const payProcessingFee = new _decimal.default(toMoneyNumber(summary.pay_service_charge_amount ?? order.pay_service_charge_amount));
|
|
890
|
+
if (payProcessingFee.lte(0)) return paidAmount;
|
|
891
|
+
const totalAmount = new _decimal.default(toMoneyNumber(summary.total_amount ?? order.total_amount));
|
|
892
|
+
if (totalAmount.gt(0) && paidAmount.gte(totalAmount)) return paidAmount;
|
|
859
893
|
const paidAmountWithFee = paidAmount.plus(payProcessingFee);
|
|
860
|
-
if (totalAmount.gt(0) && paidAmountWithFee.gt(totalAmount))
|
|
861
|
-
return totalAmount;
|
|
894
|
+
if (totalAmount.gt(0) && paidAmountWithFee.gt(totalAmount)) return totalAmount;
|
|
862
895
|
return paidAmountWithFee;
|
|
863
896
|
}
|
|
864
897
|
function sumPayments(payments) {
|
|
865
|
-
return normalizeArray(payments).filter(
|
|
898
|
+
return normalizeArray(payments).filter(payment => isPrintablePayment(payment)).reduce((sum, payment) => {
|
|
866
899
|
return sum.plus(toMoneyNumber(payment.amount ?? payment.origin_amount));
|
|
867
|
-
}, new
|
|
900
|
+
}, new _decimal.default(0));
|
|
868
901
|
}
|
|
869
902
|
function isPrintablePayment(payment) {
|
|
870
903
|
const status = stringify(payment.status).toLowerCase();
|
|
871
|
-
if (!status)
|
|
872
|
-
|
|
873
|
-
return ["paid", "success", "succeeded", "completed"].includes(status);
|
|
904
|
+
if (!status) return true;
|
|
905
|
+
return ['paid', 'success', 'succeeded', 'completed'].includes(status);
|
|
874
906
|
}
|
|
875
907
|
function normalizeArray(value) {
|
|
876
908
|
return Array.isArray(value) ? value : [];
|
|
877
909
|
}
|
|
878
910
|
function isNonZero(value) {
|
|
879
|
-
return !new
|
|
911
|
+
return !new _decimal.default(toMoneyNumber(value)).isZero();
|
|
880
912
|
}
|
|
881
913
|
function toMoneyNumber(value) {
|
|
882
|
-
if (value instanceof
|
|
883
|
-
|
|
884
|
-
if (typeof value
|
|
885
|
-
|
|
886
|
-
if (typeof value !== "string")
|
|
887
|
-
return 0;
|
|
888
|
-
const normalized = value.replace(/[^\d.-]/g, "");
|
|
914
|
+
if (value instanceof _decimal.default) return value.toString();
|
|
915
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
|
|
916
|
+
if (typeof value !== 'string') return 0;
|
|
917
|
+
const normalized = value.replace(/[^\d.-]/g, '');
|
|
889
918
|
return normalized || 0;
|
|
890
919
|
}
|
|
891
920
|
function toNumber(value, fallback) {
|
|
@@ -893,12 +922,6 @@ function toNumber(value, fallback) {
|
|
|
893
922
|
return Number.isFinite(numberValue) ? numberValue : fallback;
|
|
894
923
|
}
|
|
895
924
|
function stringify(value) {
|
|
896
|
-
if (value ===
|
|
897
|
-
return "";
|
|
925
|
+
if (value === undefined || value === null) return '';
|
|
898
926
|
return String(value);
|
|
899
|
-
}
|
|
900
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
901
|
-
0 && (module.exports = {
|
|
902
|
-
buildSmallTicketData,
|
|
903
|
-
hasSmallTicketData
|
|
904
|
-
});
|
|
927
|
+
}
|