@pisell/pisellos 2.2.309 → 2.2.311
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
- package/dist/modules/BookingContext/index.js +4 -4
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
- package/dist/modules/Customer/index.js +6 -3
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/availability.d.ts +7 -0
- package/dist/modules/Discount/availability.js +49 -0
- package/dist/modules/Discount/entitlementPass.d.ts +34 -0
- package/dist/modules/Discount/entitlementPass.js +147 -0
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +37 -151
- package/dist/modules/Discount/types.d.ts +36 -5
- package/dist/modules/OpenData/index.d.ts +1 -1
- package/dist/modules/OpenData/index.js +21 -12
- package/dist/modules/Order/index.d.ts +32 -4
- package/dist/modules/Order/index.js +733 -373
- package/dist/modules/Order/types.d.ts +17 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
- package/dist/modules/Order/utils.d.ts +19 -5
- package/dist/modules/Order/utils.js +306 -86
- package/dist/modules/Payment/index.d.ts +0 -5
- package/dist/modules/Payment/index.js +35 -85
- package/dist/modules/Payment/types.d.ts +21 -1
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Payment/walletpass.d.ts +1 -1
- package/dist/modules/Payment/walletpass.js +80 -47
- package/dist/modules/ProductList/index.js +18 -5
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +480 -186
- package/dist/modules/Rules/types.d.ts +4 -0
- package/dist/server/index.js +8 -5
- package/dist/server/modules/floor-plan/index.js +34 -3
- package/dist/server/modules/order/index.js +6 -0
- package/dist/server/modules/order/types.d.ts +12 -0
- package/dist/server/modules/payment/index.d.ts +25 -6
- package/dist/server/modules/payment/index.js +660 -133
- package/dist/server/utils/small-ticket.d.ts +8 -5
- package/dist/server/utils/small-ticket.js +1269 -199
- package/dist/solution/BaseSales/index.d.ts +11 -2
- package/dist/solution/BaseSales/index.js +1463 -1173
- package/dist/solution/BaseSales/types.d.ts +7 -3
- package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
- package/dist/solution/BookingTicket/index.d.ts +11 -2
- package/dist/solution/BookingTicket/index.js +663 -542
- package/dist/solution/BookingTicket/types.d.ts +5 -1
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +99 -42
- package/dist/solution/ShopDiscount/utils.d.ts +4 -2
- package/dist/solution/ShopDiscount/utils.js +43 -23
- package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/dist/solution/UnifiedBookingSales/index.js +5 -5
- package/dist/utils/os-private-payload.d.ts +5 -0
- package/dist/utils/os-private-payload.js +17 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
- package/lib/modules/BookingContext/index.js +3 -3
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
- package/lib/modules/Customer/index.js +5 -1
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/availability.d.ts +7 -0
- package/lib/modules/Discount/availability.js +43 -0
- package/lib/modules/Discount/entitlementPass.d.ts +34 -0
- package/lib/modules/Discount/entitlementPass.js +141 -0
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +23 -129
- package/lib/modules/Discount/types.d.ts +36 -5
- package/lib/modules/OpenData/index.d.ts +1 -1
- package/lib/modules/OpenData/index.js +11 -2
- package/lib/modules/Order/index.d.ts +32 -4
- package/lib/modules/Order/index.js +341 -71
- package/lib/modules/Order/types.d.ts +17 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
- package/lib/modules/Order/utils.d.ts +19 -5
- package/lib/modules/Order/utils.js +215 -13
- package/lib/modules/Payment/index.d.ts +0 -5
- package/lib/modules/Payment/index.js +3 -28
- package/lib/modules/Payment/types.d.ts +21 -1
- package/lib/modules/Payment/types.js +1 -0
- package/lib/modules/Payment/walletpass.d.ts +1 -1
- package/lib/modules/Payment/walletpass.js +29 -9
- package/lib/modules/ProductList/index.js +14 -1
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +357 -110
- package/lib/modules/Rules/types.d.ts +4 -0
- package/lib/server/index.js +8 -5
- package/lib/server/modules/floor-plan/index.js +29 -1
- package/lib/server/modules/order/index.js +6 -0
- package/lib/server/modules/order/types.d.ts +12 -0
- package/lib/server/modules/payment/index.d.ts +25 -6
- package/lib/server/modules/payment/index.js +350 -78
- package/lib/server/utils/small-ticket.d.ts +8 -5
- package/lib/server/utils/small-ticket.js +1009 -121
- package/lib/solution/BaseSales/index.d.ts +11 -2
- package/lib/solution/BaseSales/index.js +164 -30
- package/lib/solution/BaseSales/types.d.ts +7 -3
- package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
- package/lib/solution/BookingTicket/index.d.ts +11 -2
- package/lib/solution/BookingTicket/index.js +103 -41
- package/lib/solution/BookingTicket/types.d.ts +5 -1
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +55 -9
- package/lib/solution/ShopDiscount/utils.d.ts +4 -2
- package/lib/solution/ShopDiscount/utils.js +42 -25
- package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/lib/solution/UnifiedBookingSales/index.js +5 -5
- package/lib/utils/os-private-payload.d.ts +5 -0
- package/lib/utils/os-private-payload.js +22 -0
- package/package.json +1 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
var _excluded = ["isMarkup"];
|
|
1
2
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
3
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
4
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
4
5
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
6
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
7
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
8
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
9
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
10
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
11
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
15
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
16
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -17,15 +21,31 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
17
21
|
import dayjs from 'dayjs';
|
|
18
22
|
import Decimal from 'decimal.js';
|
|
19
23
|
var DEFAULT_LOCALES = ['en', 'zh_CN'];
|
|
24
|
+
var SERVICE_TYPE_LABEL_KEYS = {
|
|
25
|
+
takeaway: 'takeAway',
|
|
26
|
+
pick_up: 'pickUp',
|
|
27
|
+
table_service: 'tableService',
|
|
28
|
+
delivery: 'delivery',
|
|
29
|
+
room_service: 'roomService',
|
|
30
|
+
dine_in: 'dineIn',
|
|
31
|
+
delivery_by_uber: 'deliveryByUber',
|
|
32
|
+
delivery_by_panda: 'deliveryByPanda',
|
|
33
|
+
delivery_by_merchant: 'deliveryByMerchant'
|
|
34
|
+
};
|
|
20
35
|
var LABELS = {
|
|
21
36
|
en: {
|
|
22
37
|
contactName: 'Contact name',
|
|
23
38
|
contactMobile: 'Contact Mobile',
|
|
24
39
|
email: 'email',
|
|
25
|
-
dineIn: 'Dine
|
|
26
|
-
takeAway: '
|
|
40
|
+
dineIn: 'Dine in',
|
|
41
|
+
takeAway: 'Takeaway',
|
|
27
42
|
delivery: 'Delivery',
|
|
28
|
-
pickUp: '
|
|
43
|
+
pickUp: 'Pickup',
|
|
44
|
+
tableService: 'Table Service',
|
|
45
|
+
roomService: 'Room Service',
|
|
46
|
+
deliveryByUber: 'Uber Eats Delivery',
|
|
47
|
+
deliveryByPanda: 'HungryPanda Delivery',
|
|
48
|
+
deliveryByMerchant: 'Merchant Delivery',
|
|
29
49
|
shopService: 'Dine-in',
|
|
30
50
|
pickUpTime: 'Pick-up time',
|
|
31
51
|
asap: 'ASAP',
|
|
@@ -35,13 +55,21 @@ var LABELS = {
|
|
|
35
55
|
eftpos: 'Eftpos',
|
|
36
56
|
wallet: 'Wallet',
|
|
37
57
|
giftCard: 'Gift card',
|
|
58
|
+
pointCard: 'Point card',
|
|
38
59
|
balance: 'Balance',
|
|
60
|
+
validity: 'Validity',
|
|
39
61
|
remainingAmount: 'Remaining amount',
|
|
40
62
|
redeemPoints: 'Redeem points',
|
|
41
|
-
remainingPoints: '
|
|
63
|
+
remainingPoints: 'Points balance',
|
|
64
|
+
entitlementRemaining: 'Remaining',
|
|
42
65
|
table: 'Table',
|
|
66
|
+
bookingId: 'Booking ID',
|
|
67
|
+
bookingDateTime: 'Date & time',
|
|
68
|
+
bookingResource: 'Resource',
|
|
69
|
+
bookingHolder: 'Holder',
|
|
43
70
|
orderDiscount: 'Order discount',
|
|
44
71
|
manualDiscount: 'Manual discount',
|
|
72
|
+
manualMarkup: 'Manual markup',
|
|
45
73
|
payProcessingFee: 'Pay processing fee',
|
|
46
74
|
surchargeIncluded: 'Surcharge(Included)',
|
|
47
75
|
rounding: 'Rounding',
|
|
@@ -57,7 +85,12 @@ var LABELS = {
|
|
|
57
85
|
dineIn: '堂食',
|
|
58
86
|
takeAway: '外带',
|
|
59
87
|
delivery: '配送',
|
|
60
|
-
pickUp: '
|
|
88
|
+
pickUp: '自取',
|
|
89
|
+
tableService: '送餐到桌',
|
|
90
|
+
roomService: '客房服务',
|
|
91
|
+
deliveryByUber: 'Uber 配送',
|
|
92
|
+
deliveryByPanda: '熊猫外卖配送',
|
|
93
|
+
deliveryByMerchant: '商家配送',
|
|
61
94
|
shopService: '堂食',
|
|
62
95
|
pickUpTime: '取餐时间',
|
|
63
96
|
asap: '尽快',
|
|
@@ -67,13 +100,21 @@ var LABELS = {
|
|
|
67
100
|
eftpos: '刷卡支付',
|
|
68
101
|
wallet: '钱包支付',
|
|
69
102
|
giftCard: '礼品卡',
|
|
103
|
+
pointCard: '积分卡',
|
|
70
104
|
balance: '余额',
|
|
105
|
+
validity: '有效期',
|
|
71
106
|
remainingAmount: '剩余金额',
|
|
72
107
|
redeemPoints: '本次使用积分',
|
|
73
|
-
remainingPoints: '
|
|
108
|
+
remainingPoints: '积分余额',
|
|
109
|
+
entitlementRemaining: '剩余次数',
|
|
74
110
|
table: '桌台',
|
|
111
|
+
bookingId: '预约编号',
|
|
112
|
+
bookingDateTime: '日期和时间',
|
|
113
|
+
bookingResource: '资源',
|
|
114
|
+
bookingHolder: '预约人',
|
|
75
115
|
orderDiscount: '整单折扣',
|
|
76
116
|
manualDiscount: '手动折扣',
|
|
117
|
+
manualMarkup: '手动加价',
|
|
77
118
|
payProcessingFee: '支付手续费',
|
|
78
119
|
surchargeIncluded: '手续费(已含)',
|
|
79
120
|
rounding: '抹零',
|
|
@@ -90,6 +131,11 @@ var LABELS = {
|
|
|
90
131
|
takeAway: '外帶',
|
|
91
132
|
delivery: '配送',
|
|
92
133
|
pickUp: '自取',
|
|
134
|
+
tableService: '送餐到桌',
|
|
135
|
+
roomService: '客房服務',
|
|
136
|
+
deliveryByUber: 'Uber 配送',
|
|
137
|
+
deliveryByPanda: '熊貓外賣配送',
|
|
138
|
+
deliveryByMerchant: '商家配送',
|
|
93
139
|
shopService: '堂食',
|
|
94
140
|
pickUpTime: '取餐時間',
|
|
95
141
|
asap: '盡快',
|
|
@@ -99,13 +145,21 @@ var LABELS = {
|
|
|
99
145
|
eftpos: '刷卡支付',
|
|
100
146
|
wallet: '錢包支付',
|
|
101
147
|
giftCard: '禮品卡',
|
|
148
|
+
pointCard: '積分卡',
|
|
102
149
|
balance: '餘額',
|
|
150
|
+
validity: '有效期',
|
|
103
151
|
remainingAmount: '剩餘金額',
|
|
104
152
|
redeemPoints: '本次使用積分',
|
|
105
|
-
remainingPoints: '
|
|
153
|
+
remainingPoints: '積分餘額',
|
|
154
|
+
entitlementRemaining: '剩餘次數',
|
|
106
155
|
table: '桌台',
|
|
156
|
+
bookingId: '預約編號',
|
|
157
|
+
bookingDateTime: '日期和時間',
|
|
158
|
+
bookingResource: '資源',
|
|
159
|
+
bookingHolder: '預約人',
|
|
107
160
|
orderDiscount: '整單折扣',
|
|
108
161
|
manualDiscount: '手動折扣',
|
|
162
|
+
manualMarkup: '手動加價',
|
|
109
163
|
payProcessingFee: '支付手續費',
|
|
110
164
|
surchargeIncluded: '手續費(已含)',
|
|
111
165
|
rounding: '抹零',
|
|
@@ -122,6 +176,11 @@ var LABELS = {
|
|
|
122
176
|
takeAway: 'テイクアウト',
|
|
123
177
|
delivery: '配達',
|
|
124
178
|
pickUp: '受け取り',
|
|
179
|
+
tableService: 'テーブルサービス',
|
|
180
|
+
roomService: 'ルームサービス',
|
|
181
|
+
deliveryByUber: 'Uber Eats 配達',
|
|
182
|
+
deliveryByPanda: 'HungryPanda 配達',
|
|
183
|
+
deliveryByMerchant: '店舗による配達',
|
|
125
184
|
shopService: '店内飲食',
|
|
126
185
|
pickUpTime: '受取時間',
|
|
127
186
|
asap: 'できるだけ早く',
|
|
@@ -129,13 +188,21 @@ var LABELS = {
|
|
|
129
188
|
eftpos: 'カード',
|
|
130
189
|
wallet: 'ウォレット',
|
|
131
190
|
giftCard: 'ギフトカード',
|
|
191
|
+
pointCard: 'ポイントカード',
|
|
132
192
|
balance: '残高',
|
|
193
|
+
validity: '有効期限',
|
|
133
194
|
remainingAmount: '残高',
|
|
134
195
|
redeemPoints: '利用ポイント',
|
|
135
|
-
remainingPoints: '
|
|
196
|
+
remainingPoints: 'ポイント残高',
|
|
197
|
+
entitlementRemaining: '残り回数',
|
|
136
198
|
table: 'テーブル',
|
|
199
|
+
bookingId: '予約ID',
|
|
200
|
+
bookingDateTime: '日時',
|
|
201
|
+
bookingResource: 'リソース',
|
|
202
|
+
bookingHolder: '予約者',
|
|
137
203
|
orderDiscount: '注文割引',
|
|
138
204
|
manualDiscount: '手動割引',
|
|
205
|
+
manualMarkup: '手動値上げ',
|
|
139
206
|
payProcessingFee: '決済手数料',
|
|
140
207
|
rounding: '端数調整',
|
|
141
208
|
gross: '総重量',
|
|
@@ -153,6 +220,11 @@ var LABELS = {
|
|
|
153
220
|
takeAway: 'Para levar',
|
|
154
221
|
delivery: 'Entrega',
|
|
155
222
|
pickUp: 'Recolha',
|
|
223
|
+
tableService: 'Serviço à mesa',
|
|
224
|
+
roomService: 'Serviço de quarto',
|
|
225
|
+
deliveryByUber: 'Entrega pela Uber Eats',
|
|
226
|
+
deliveryByPanda: 'Entrega pela HungryPanda',
|
|
227
|
+
deliveryByMerchant: 'Entrega pelo comerciante',
|
|
156
228
|
shopService: 'Consumo no local',
|
|
157
229
|
pickUpTime: 'Hora de recolha',
|
|
158
230
|
asap: 'Assim que possível',
|
|
@@ -160,13 +232,21 @@ var LABELS = {
|
|
|
160
232
|
eftpos: 'Cartão',
|
|
161
233
|
wallet: 'Carteira',
|
|
162
234
|
giftCard: 'Cartão-presente',
|
|
235
|
+
pointCard: 'Cartão de pontos',
|
|
163
236
|
balance: 'Saldo',
|
|
237
|
+
validity: 'Validade',
|
|
164
238
|
remainingAmount: 'Saldo restante',
|
|
165
239
|
redeemPoints: 'Pontos utilizados',
|
|
166
|
-
remainingPoints: '
|
|
240
|
+
remainingPoints: 'Saldo de pontos',
|
|
241
|
+
entitlementRemaining: 'Utilizações restantes',
|
|
167
242
|
table: 'Mesa',
|
|
243
|
+
bookingId: 'ID da reserva',
|
|
244
|
+
bookingDateTime: 'Data e hora',
|
|
245
|
+
bookingResource: 'Recurso',
|
|
246
|
+
bookingHolder: 'Titular',
|
|
168
247
|
orderDiscount: 'Desconto do pedido',
|
|
169
248
|
manualDiscount: 'Desconto manual',
|
|
249
|
+
manualMarkup: 'Acréscimo manual',
|
|
170
250
|
payProcessingFee: 'Taxa de processamento',
|
|
171
251
|
rounding: 'Arredondamento',
|
|
172
252
|
gross: 'Peso bruto',
|
|
@@ -250,14 +330,14 @@ function buildLocaleData(params) {
|
|
|
250
330
|
});
|
|
251
331
|
}
|
|
252
332
|
function buildBaseData(params) {
|
|
253
|
-
var _order$metadata;
|
|
333
|
+
var _financials$amountGap, _order$metadata;
|
|
254
334
|
var order = params.order,
|
|
255
335
|
shopInfo = params.shopInfo,
|
|
256
336
|
locale = params.locale,
|
|
257
337
|
currencySymbol = params.currencySymbol,
|
|
258
338
|
financials = params.financials;
|
|
259
339
|
var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
260
|
-
return _objectSpread(
|
|
340
|
+
return _objectSpread({
|
|
261
341
|
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
262
342
|
note: stringify(order.note),
|
|
263
343
|
shop_order_number: stringify(order.shop_order_number),
|
|
@@ -268,10 +348,8 @@ function buildBaseData(params) {
|
|
|
268
348
|
original_payment_status: financials.paymentStatus,
|
|
269
349
|
payment_status: financials.paymentStatus,
|
|
270
350
|
total_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
271
|
-
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
272
|
-
|
|
273
|
-
amount_gap: formatMoney(financials.amountGap, currencySymbol)
|
|
274
|
-
} : {}), {}, {
|
|
351
|
+
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol),
|
|
352
|
+
amount_gap: formatCalculatedMoney((_financials$amountGap = financials.amountGap) !== null && _financials$amountGap !== void 0 ? _financials$amountGap : 0, currencySymbol),
|
|
275
353
|
is_repeat: 0,
|
|
276
354
|
buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
|
|
277
355
|
order_no: orderNumber,
|
|
@@ -282,8 +360,10 @@ function buildBaseData(params) {
|
|
|
282
360
|
}
|
|
283
361
|
function buildProducts(order, locale, productMap) {
|
|
284
362
|
var products = Array.isArray(order.products) ? order.products : [];
|
|
285
|
-
|
|
363
|
+
var allergyByProductUid = buildProductAllergyMap(order, locale);
|
|
364
|
+
return products.map(function (rawProduct) {
|
|
286
365
|
var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
|
|
366
|
+
var product = restoreReceiptDiscountHierarchy(rawProduct);
|
|
287
367
|
var quantity = toNumber((_ref = (_ref2 = (_product$product_quan = product.product_quantity) !== null && _product$product_quan !== void 0 ? _product$product_quan : product.quantity) !== null && _ref2 !== void 0 ? _ref2 : product.num) !== null && _ref !== void 0 ? _ref : 1, 1);
|
|
288
368
|
var originalPrice = (_ref3 = (_ref4 = (_ref5 = (_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product.selling_price) !== null && _ref5 !== void 0 ? _ref5 : product.payment_price) !== null && _ref4 !== void 0 ? _ref4 : product.price) !== null && _ref3 !== void 0 ? _ref3 : 0;
|
|
289
369
|
var sellingPrice = (_ref6 = (_ref7 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.payment_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : originalPrice;
|
|
@@ -322,16 +402,25 @@ function buildProducts(order, locale, productMap) {
|
|
|
322
402
|
originalPrice: originalPrice
|
|
323
403
|
});
|
|
324
404
|
var productNote = resolveProductNote(product, locale);
|
|
405
|
+
var allergy = isPresentId(productUid) ? allergyByProductUid.get(String(productUid).trim()) || '' : '';
|
|
325
406
|
var basePrice = resolveProductBasePrice(product);
|
|
326
|
-
|
|
407
|
+
var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
|
|
408
|
+
var shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
|
|
409
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
327
410
|
product_title: productTitle,
|
|
328
411
|
product_quantity: quantity,
|
|
329
412
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
413
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
|
|
330
414
|
original_price: formatMoney(originalPrice, currencySymbol)
|
|
331
|
-
},
|
|
332
|
-
base_price:
|
|
415
|
+
}, shouldIncludeBasePrice ? {
|
|
416
|
+
base_price: formatCalculatedMoney(basePrice !== null && basePrice !== void 0 ? basePrice : 0, currencySymbol)
|
|
417
|
+
} : {}), {}, {
|
|
418
|
+
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol)
|
|
419
|
+
}, options.length ? {
|
|
420
|
+
options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
|
|
421
|
+
} : {}), resolvedCombinations.length ? {
|
|
422
|
+
package_items_total_price: sumCombinationTotals(resolvedCombinations, currencySymbol)
|
|
333
423
|
} : {}), {}, {
|
|
334
|
-
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
335
424
|
extension_list: extensionList
|
|
336
425
|
}, isPresentId(productUid) ? {
|
|
337
426
|
product_uid: productUid
|
|
@@ -339,19 +428,109 @@ function buildProducts(order, locale, productMap) {
|
|
|
339
428
|
booking_uid: bookingUid
|
|
340
429
|
} : {}), productNote ? {
|
|
341
430
|
product_note: productNote
|
|
431
|
+
} : {}), allergy ? {
|
|
432
|
+
allergy: allergy
|
|
342
433
|
} : {}), options.length ? {
|
|
343
434
|
options: options
|
|
344
435
|
} : {}), resolvedVariant ? {
|
|
345
436
|
variant: resolvedVariant
|
|
346
|
-
} : {}),
|
|
347
|
-
combinations:
|
|
348
|
-
} : combinations.length ? {
|
|
349
|
-
combinations: combinations
|
|
437
|
+
} : {}), resolvedCombinations.length ? {
|
|
438
|
+
combinations: resolvedCombinations
|
|
350
439
|
} : {});
|
|
351
440
|
});
|
|
352
441
|
}
|
|
442
|
+
var RECEIPT_BUNDLE_MAP_ID_KEY = 'custom_product_bundle_map_id';
|
|
443
|
+
function restoreReceiptDiscountHierarchy(source) {
|
|
444
|
+
if (!source || _typeof(source) !== 'object' || Array.isArray(source)) {
|
|
445
|
+
return source;
|
|
446
|
+
}
|
|
447
|
+
var childKey = Array.isArray(source.combinations) && source.combinations.length ? 'combinations' : Array.isArray(source.product_bundle) && source.product_bundle.length ? 'product_bundle' : null;
|
|
448
|
+
if (!childKey) return _objectSpread({}, source);
|
|
449
|
+
var children = source[childKey].map(function (child) {
|
|
450
|
+
return child && _typeof(child) === 'object' && !Array.isArray(child) ? restoreReceiptDiscountHierarchy(child) : child;
|
|
451
|
+
});
|
|
452
|
+
var restored = _objectSpread(_objectSpread({}, source), {}, _defineProperty({}, childKey, children));
|
|
453
|
+
if (!Array.isArray(source.discount_list) || !source.discount_list.length) {
|
|
454
|
+
return restored;
|
|
455
|
+
}
|
|
456
|
+
var descendantsByMapId = new Map();
|
|
457
|
+
indexReceiptDiscountTargets(children, descendantsByMapId);
|
|
458
|
+
if (!descendantsByMapId.size) return restored;
|
|
459
|
+
var ownDiscounts = [];
|
|
460
|
+
var _iterator = _createForOfIteratorHelper(source.discount_list),
|
|
461
|
+
_step;
|
|
462
|
+
try {
|
|
463
|
+
var _loop = function _loop() {
|
|
464
|
+
var discount = _step.value;
|
|
465
|
+
var mapId = getReceiptDiscountBundleMapId(discount);
|
|
466
|
+
var target = mapId ? descendantsByMapId.get(mapId) : undefined;
|
|
467
|
+
if (!target) {
|
|
468
|
+
ownDiscounts.push(discount);
|
|
469
|
+
return 1; // continue
|
|
470
|
+
}
|
|
471
|
+
var targetDiscounts = Array.isArray(target.discount_list) ? target.discount_list : [];
|
|
472
|
+
if (!targetDiscounts.some(function (item) {
|
|
473
|
+
return isSameReceiptDiscount(item, discount);
|
|
474
|
+
})) {
|
|
475
|
+
target.discount_list = [].concat(_toConsumableArray(targetDiscounts), [discount]);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
479
|
+
if (_loop()) continue;
|
|
480
|
+
}
|
|
481
|
+
} catch (err) {
|
|
482
|
+
_iterator.e(err);
|
|
483
|
+
} finally {
|
|
484
|
+
_iterator.f();
|
|
485
|
+
}
|
|
486
|
+
restored.discount_list = ownDiscounts;
|
|
487
|
+
return restored;
|
|
488
|
+
}
|
|
489
|
+
function indexReceiptDiscountTargets(nodes, targets) {
|
|
490
|
+
var _iterator2 = _createForOfIteratorHelper(nodes),
|
|
491
|
+
_step2;
|
|
492
|
+
try {
|
|
493
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
494
|
+
var node = _step2.value;
|
|
495
|
+
if (!node || _typeof(node) !== 'object' || Array.isArray(node)) continue;
|
|
496
|
+
var mapId = getReceiptBundleMapId(node);
|
|
497
|
+
if (mapId && !targets.has(mapId)) targets.set(mapId, node);
|
|
498
|
+
var children = Array.isArray(node.combinations) && node.combinations.length ? node.combinations : Array.isArray(node.product_bundle) ? node.product_bundle : [];
|
|
499
|
+
indexReceiptDiscountTargets(children, targets);
|
|
500
|
+
}
|
|
501
|
+
} catch (err) {
|
|
502
|
+
_iterator2.e(err);
|
|
503
|
+
} finally {
|
|
504
|
+
_iterator2.f();
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
function normalizeReceiptId(value) {
|
|
508
|
+
if (value === undefined || value === null) return null;
|
|
509
|
+
var normalized = String(value).trim();
|
|
510
|
+
return normalized ? normalized : null;
|
|
511
|
+
}
|
|
512
|
+
function getReceiptBundleMapId(node) {
|
|
513
|
+
var _node$metadata$RECEIP, _node$metadata;
|
|
514
|
+
return normalizeReceiptId((_node$metadata$RECEIP = (_node$metadata = node.metadata) === null || _node$metadata === void 0 ? void 0 : _node$metadata[RECEIPT_BUNDLE_MAP_ID_KEY]) !== null && _node$metadata$RECEIP !== void 0 ? _node$metadata$RECEIP : node._id);
|
|
515
|
+
}
|
|
516
|
+
function getReceiptDiscountBundleMapId(discount) {
|
|
517
|
+
var _discount$metadata;
|
|
518
|
+
return normalizeReceiptId(discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata[RECEIPT_BUNDLE_MAP_ID_KEY]);
|
|
519
|
+
}
|
|
520
|
+
function isSameReceiptDiscount(left, right) {
|
|
521
|
+
var _ref8, _left$discount$resour, _left$discount, _ref9, _right$discount$resou, _right$discount, _ref10, _ref11, _left$amount, _ref12, _ref13, _right$amount;
|
|
522
|
+
var leftOrderDiscountId = normalizeReceiptId(left === null || left === void 0 ? void 0 : left.order_discount_id);
|
|
523
|
+
var rightOrderDiscountId = normalizeReceiptId(right === null || right === void 0 ? void 0 : right.order_discount_id);
|
|
524
|
+
if (leftOrderDiscountId && rightOrderDiscountId) {
|
|
525
|
+
return leftOrderDiscountId === rightOrderDiscountId;
|
|
526
|
+
}
|
|
527
|
+
var leftResourceId = normalizeReceiptId((_ref8 = (_left$discount$resour = left === null || left === void 0 || (_left$discount = left.discount) === null || _left$discount === void 0 ? void 0 : _left$discount.resource_id) !== null && _left$discount$resour !== void 0 ? _left$discount$resour : left === null || left === void 0 ? void 0 : left.resource_id) !== null && _ref8 !== void 0 ? _ref8 : left === null || left === void 0 ? void 0 : left.discount_id);
|
|
528
|
+
var rightResourceId = normalizeReceiptId((_ref9 = (_right$discount$resou = right === null || right === void 0 || (_right$discount = right.discount) === null || _right$discount === void 0 ? void 0 : _right$discount.resource_id) !== null && _right$discount$resou !== void 0 ? _right$discount$resou : right === null || right === void 0 ? void 0 : right.resource_id) !== null && _ref9 !== void 0 ? _ref9 : right === null || right === void 0 ? void 0 : right.discount_id);
|
|
529
|
+
if (!leftResourceId || !rightResourceId) return false;
|
|
530
|
+
return leftResourceId === rightResourceId && getReceiptDiscountBundleMapId(left) === getReceiptDiscountBundleMapId(right) && String((_ref10 = (_ref11 = (_left$amount = left === null || left === void 0 ? void 0 : left.amount) !== null && _left$amount !== void 0 ? _left$amount : left === null || left === void 0 ? void 0 : left.value) !== null && _ref11 !== void 0 ? _ref11 : left === null || left === void 0 ? void 0 : left.discount_amount) !== null && _ref10 !== void 0 ? _ref10 : '') === String((_ref12 = (_ref13 = (_right$amount = right === null || right === void 0 ? void 0 : right.amount) !== null && _right$amount !== void 0 ? _right$amount : right === null || right === void 0 ? void 0 : right.value) !== null && _ref13 !== void 0 ? _ref13 : right === null || right === void 0 ? void 0 : right.discount_amount) !== null && _ref12 !== void 0 ? _ref12 : '');
|
|
531
|
+
}
|
|
353
532
|
function resolveProductBasePrice(product) {
|
|
354
|
-
var _product$product_vari, _product$_origin, _product$_origin2;
|
|
533
|
+
var _product$product_vari, _ref14, _ref15, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
|
|
355
534
|
var metadata = product.metadata || {};
|
|
356
535
|
var origin = product._origin || metadata.origin || {};
|
|
357
536
|
var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
|
|
@@ -359,23 +538,67 @@ function resolveProductBasePrice(product) {
|
|
|
359
538
|
return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
|
|
360
539
|
}) : undefined;
|
|
361
540
|
var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
|
|
362
|
-
|
|
541
|
+
var quantity = toNumber((_ref14 = (_ref15 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref15 !== void 0 ? _ref15 : product.num) !== null && _ref14 !== void 0 ? _ref14 : 1, 1);
|
|
542
|
+
var hasEntitlementPass = normalizeArray(product.discount_list).some(function (discount) {
|
|
543
|
+
return getProductWalletDiscountType(discount) === 'entitlement_pass';
|
|
544
|
+
});
|
|
545
|
+
var hasOptions = normalizeArray(product.options).length > 0 || normalizeArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option).length > 0;
|
|
546
|
+
var hasCombinations = normalizeArray(product.combinations).length > 0 || normalizeArray(product.product_bundle).length > 0 || normalizeArray(product.bundle).length > 0;
|
|
547
|
+
var aggregateSourcePrice = firstPresentValue(metadata.source_product_price, product.price);
|
|
548
|
+
var originalPrice = product.original_price;
|
|
549
|
+
// 部分旧 entitlement 商品把 source/price 持久化成了整行总价,但
|
|
550
|
+
// original_price 仍是单件价。仅在等式能明确证明该口径时做窄幅回退。
|
|
551
|
+
var useOriginalPriceAsLegacyUnitPrice = hasEntitlementPass && quantity > 1 && !hasOptions && !hasCombinations && isNumericAmount(aggregateSourcePrice) && isNumericAmount(originalPrice) && new Decimal(aggregateSourcePrice).eq(new Decimal(originalPrice).mul(quantity));
|
|
552
|
+
return firstPresentValue(useOriginalPriceAsLegacyUnitPrice ? originalPrice : undefined, metadata.source_product_price, variant === null || variant === void 0 ? void 0 : variant.price, (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.price, (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
|
|
363
553
|
}
|
|
364
554
|
function normalizeProductDiscounts(params) {
|
|
365
555
|
var product = params.product,
|
|
366
556
|
locale = params.locale,
|
|
367
557
|
currencySymbol = params.currencySymbol,
|
|
368
558
|
quantity = params.quantity;
|
|
369
|
-
|
|
370
|
-
var
|
|
559
|
+
var rows = normalizeArray(product.discount_list).filter(function (discount) {
|
|
560
|
+
var _ref16, _discount$amount;
|
|
561
|
+
var amount = (_ref16 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref16 !== void 0 ? _ref16 : discount.discount_amount;
|
|
562
|
+
return isNonZero(amount);
|
|
563
|
+
}).map(function (discount) {
|
|
564
|
+
var _ref17, _discount$amount2;
|
|
371
565
|
var title = resolveDiscountTitleWithPercent(discount, locale);
|
|
372
|
-
var amount = (
|
|
373
|
-
var
|
|
566
|
+
var amount = (_ref17 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
|
|
567
|
+
var isMarkup = isManualMarkup(discount);
|
|
568
|
+
var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
|
|
569
|
+
var isEntitlementPass = getProductWalletDiscountType(discount) === 'entitlement_pass';
|
|
570
|
+
var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount || isEntitlementPass ? 1 : quantity);
|
|
571
|
+
var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
|
|
374
572
|
return {
|
|
375
573
|
item: title,
|
|
376
|
-
value: formattedAmount
|
|
574
|
+
value: formattedAmount,
|
|
575
|
+
isMarkup: isMarkup
|
|
377
576
|
};
|
|
378
577
|
});
|
|
578
|
+
return rows.sort(function (left, right) {
|
|
579
|
+
return Number(right.isMarkup) - Number(left.isMarkup);
|
|
580
|
+
}).map(function (_ref18) {
|
|
581
|
+
var _isMarkup = _ref18.isMarkup,
|
|
582
|
+
row = _objectWithoutProperties(_ref18, _excluded);
|
|
583
|
+
return row;
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
function isManualMarkup(discount) {
|
|
587
|
+
var _discount$discount, _ref19, _discount$amount3;
|
|
588
|
+
if (discount.type !== 'product') return false;
|
|
589
|
+
if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
|
|
590
|
+
var amount = (_ref19 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref19 !== void 0 ? _ref19 : discount.discount_amount;
|
|
591
|
+
return new Decimal(toMoneyNumber(amount)).isNegative();
|
|
592
|
+
}
|
|
593
|
+
function hasProductDiscount(product) {
|
|
594
|
+
var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
595
|
+
var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
|
|
596
|
+
var _ref20, _discount$amount4;
|
|
597
|
+
return isNonZero((_ref20 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref20 !== void 0 ? _ref20 : discount.discount_amount);
|
|
598
|
+
});
|
|
599
|
+
return hasDiscountListAmount || extensionList.some(function (row) {
|
|
600
|
+
return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
|
|
601
|
+
});
|
|
379
602
|
}
|
|
380
603
|
function buildProductExtensionList(params) {
|
|
381
604
|
var product = params.product,
|
|
@@ -442,10 +665,13 @@ function buildProductQuantityPriceText(params) {
|
|
|
442
665
|
return "".concat(quantity, " @ ").concat(currencySymbol).concat(stringify(price), " EACH");
|
|
443
666
|
}
|
|
444
667
|
function resolveDiscountTitleWithPercent(discount, locale) {
|
|
445
|
-
var _discount$
|
|
668
|
+
var _discount$discount2, _discount$discount$di, _discount$discount3;
|
|
446
669
|
var title = resolveDiscountTitle(discount, locale);
|
|
447
|
-
|
|
448
|
-
|
|
670
|
+
if (getProductWalletDiscountType(discount) === 'entitlement_pass') {
|
|
671
|
+
return title;
|
|
672
|
+
}
|
|
673
|
+
var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
|
|
674
|
+
var cardType = (_discount$discount$di = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.discount_card_type) !== null && _discount$discount$di !== void 0 ? _discount$discount$di : 'percent';
|
|
449
675
|
var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
|
|
450
676
|
if (percentRaw === undefined || percentRaw === null) return title;
|
|
451
677
|
if (cardType !== 'percent') return title;
|
|
@@ -453,10 +679,12 @@ function resolveDiscountTitleWithPercent(discount, locale) {
|
|
|
453
679
|
return "".concat(title, " (").concat(percent, "%)");
|
|
454
680
|
}
|
|
455
681
|
function resolveDiscountTitle(discount, locale) {
|
|
456
|
-
var
|
|
457
|
-
var title = getLocalizedValue((
|
|
682
|
+
var _ref21, _ref22, _ref23, _ref24, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
|
|
683
|
+
var title = getLocalizedValue((_ref21 = (_ref22 = (_ref23 = (_ref24 = (_discount$discount$na = (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.title) !== null && _ref24 !== void 0 ? _ref24 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref23 !== void 0 ? _ref23 : discount.name) !== null && _ref22 !== void 0 ? _ref22 : discount.title) !== null && _ref21 !== void 0 ? _ref21 : discount.message, locale);
|
|
458
684
|
if (title) return title;
|
|
459
|
-
if (discount.type === 'product')
|
|
685
|
+
if (discount.type === 'product') {
|
|
686
|
+
return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
|
|
687
|
+
}
|
|
460
688
|
return '';
|
|
461
689
|
}
|
|
462
690
|
function resolveProductTitle(params) {
|
|
@@ -472,16 +700,17 @@ function resolveProductTitle(params) {
|
|
|
472
700
|
return getProductTitleSource(fallbackProduct, locale);
|
|
473
701
|
}
|
|
474
702
|
function normalizeProductOptions(params) {
|
|
475
|
-
var _product$
|
|
703
|
+
var _product$product_sku2;
|
|
476
704
|
var product = params.product,
|
|
477
705
|
locale = params.locale,
|
|
478
706
|
currencySymbol = params.currencySymbol,
|
|
479
707
|
parentProduct = params.parentProduct;
|
|
480
|
-
var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$
|
|
708
|
+
var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku2 = product.product_sku) === null || _product$product_sku2 === void 0 ? void 0 : _product$product_sku2.option) ? product.product_sku.option : [];
|
|
481
709
|
return rawOptions.map(function (option) {
|
|
482
|
-
var
|
|
483
|
-
var price = (
|
|
484
|
-
var
|
|
710
|
+
var _ref25, _option$original_pric, _ref26, _option$num, _ref27, _option$value;
|
|
711
|
+
var price = (_ref25 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref25 !== void 0 ? _ref25 : option.price;
|
|
712
|
+
var quantity = toNumber((_ref26 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
|
|
713
|
+
var value = (_ref27 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref27 !== void 0 ? _ref27 : option.item;
|
|
485
714
|
var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
|
|
486
715
|
option: option,
|
|
487
716
|
parentProduct: parentProduct,
|
|
@@ -490,10 +719,12 @@ function normalizeProductOptions(params) {
|
|
|
490
719
|
return _objectSpread(_objectSpread(_objectSpread({
|
|
491
720
|
name: name
|
|
492
721
|
}, option.num !== undefined || option.quantity !== undefined ? {
|
|
493
|
-
num:
|
|
722
|
+
num: quantity
|
|
494
723
|
} : {}), price !== undefined && price !== null && price !== '' ? {
|
|
495
724
|
price: formatMoney(price, currencySymbol)
|
|
496
|
-
} : {}),
|
|
725
|
+
} : {}), {}, {
|
|
726
|
+
total_price: formatCalculatedMoney(new Decimal(toMoneyNumber(price !== null && price !== void 0 ? price : 0)).mul(quantity), currencySymbol)
|
|
727
|
+
}, value !== undefined && value !== null && value !== '' ? {
|
|
497
728
|
value: getLocalizedValue(value, locale)
|
|
498
729
|
} : {});
|
|
499
730
|
});
|
|
@@ -506,7 +737,7 @@ function normalizeProductCombinations(params) {
|
|
|
506
737
|
parentProduct = params.parentProduct;
|
|
507
738
|
var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
508
739
|
return bundles.map(function (bundle) {
|
|
509
|
-
var
|
|
740
|
+
var _ref28, _bundle$num;
|
|
510
741
|
var combinationsOptions = normalizeProductOptions({
|
|
511
742
|
product: {},
|
|
512
743
|
locale: locale,
|
|
@@ -521,59 +752,166 @@ function normalizeProductCombinations(params) {
|
|
|
521
752
|
parentProduct: parentProduct
|
|
522
753
|
});
|
|
523
754
|
var productNote = resolveProductNote(bundle, locale);
|
|
524
|
-
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale) : [];
|
|
525
|
-
|
|
755
|
+
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
|
|
756
|
+
var quantity = toNumber((_ref28 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref28 !== void 0 ? _ref28 : 1, 1);
|
|
757
|
+
var formattedPrice = formatBundlePrice(bundle, currencySymbol);
|
|
758
|
+
var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
|
|
759
|
+
var explicitBasePrice = resolveCombinationBasePrice(bundle);
|
|
760
|
+
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
761
|
+
var extensionList = buildProductExtensionList({
|
|
762
|
+
product: bundle,
|
|
763
|
+
locale: locale,
|
|
764
|
+
currencySymbol: currencySymbol,
|
|
765
|
+
quantity: quantity,
|
|
766
|
+
originalPrice: formattedPrice
|
|
767
|
+
});
|
|
768
|
+
var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
|
|
769
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
526
770
|
product_title: baseTitle,
|
|
527
|
-
product_quantity:
|
|
528
|
-
price:
|
|
771
|
+
product_quantity: quantity,
|
|
772
|
+
price: formattedPrice,
|
|
773
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol)
|
|
774
|
+
}, shouldIncludeBasePrice ? {
|
|
775
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
776
|
+
} : {}), {}, {
|
|
529
777
|
combinations_options: combinationsOptions
|
|
530
|
-
},
|
|
778
|
+
}, combinationsOptions.length ? {
|
|
779
|
+
options_total_price: optionsTotal
|
|
780
|
+
} : {}), nestedCombinations.length ? {
|
|
781
|
+
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
782
|
+
} : {}), productNote ? {
|
|
531
783
|
product_note: productNote
|
|
784
|
+
} : {}), extensionList.length ? {
|
|
785
|
+
extension_list: extensionList
|
|
532
786
|
} : {}), nestedCombinations.length ? {
|
|
533
787
|
combinations: nestedCombinations
|
|
534
788
|
} : {});
|
|
535
789
|
});
|
|
536
790
|
}
|
|
537
|
-
function normalizeExistingCombinations(combinations, locale) {
|
|
791
|
+
function normalizeExistingCombinations(combinations, locale, currencySymbol) {
|
|
538
792
|
return combinations.map(function (combination) {
|
|
793
|
+
var _ref29, _ref30, _combination$product_, _firstPresentValue;
|
|
539
794
|
if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
|
|
540
795
|
return combination;
|
|
541
796
|
}
|
|
542
797
|
var productNote = resolveProductNote(combination, locale);
|
|
543
|
-
var
|
|
798
|
+
var rawOptions = Array.isArray(combination.combinations_options) ? combination.combinations_options : Array.isArray(combination.options) ? combination.options : [];
|
|
799
|
+
var normalizedOptions = normalizeProductOptions({
|
|
800
|
+
product: {},
|
|
801
|
+
locale: locale,
|
|
802
|
+
currencySymbol: currencySymbol,
|
|
803
|
+
options: rawOptions
|
|
804
|
+
});
|
|
805
|
+
var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
|
|
806
|
+
var productTitle = getBundleProductTitleSource(combination, locale);
|
|
544
807
|
var snapshot = _objectSpread({}, combination);
|
|
808
|
+
delete snapshot.product_title;
|
|
545
809
|
delete snapshot.product_note;
|
|
546
810
|
delete snapshot.note;
|
|
547
|
-
|
|
811
|
+
delete snapshot.combinations;
|
|
812
|
+
delete snapshot.discount_list;
|
|
813
|
+
var quantity = toNumber((_ref29 = (_ref30 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref30 !== void 0 ? _ref30 : combination.quantity) !== null && _ref29 !== void 0 ? _ref29 : 1, 1);
|
|
814
|
+
var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
|
|
815
|
+
var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
|
|
816
|
+
return option.total_price;
|
|
817
|
+
}));
|
|
818
|
+
var explicitBasePrice = resolveCombinationBasePrice(combination, true);
|
|
819
|
+
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
820
|
+
var extensionList = buildProductExtensionList({
|
|
821
|
+
product: combination,
|
|
822
|
+
locale: locale,
|
|
823
|
+
currencySymbol: currencySymbol,
|
|
824
|
+
quantity: quantity,
|
|
825
|
+
originalPrice: unitPrice
|
|
826
|
+
});
|
|
827
|
+
var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
|
|
828
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), productTitle ? {
|
|
829
|
+
product_title: productTitle
|
|
830
|
+
} : {}), {}, {
|
|
831
|
+
product_quantity: quantity,
|
|
832
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
|
|
833
|
+
}, shouldIncludeBasePrice ? {
|
|
834
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
835
|
+
} : {}), Array.isArray(combination.combinations_options) ? {
|
|
836
|
+
combinations_options: normalizedOptions
|
|
837
|
+
} : Array.isArray(combination.options) ? {
|
|
838
|
+
options: normalizedOptions
|
|
839
|
+
} : {}), normalizedOptions.length ? {
|
|
840
|
+
options_total_price: formatCalculatedMoney(optionsAmount, currencySymbol)
|
|
841
|
+
} : {}), nestedCombinations.length ? {
|
|
842
|
+
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
843
|
+
} : {}), productNote ? {
|
|
548
844
|
product_note: productNote
|
|
549
|
-
} : {}),
|
|
845
|
+
} : {}), extensionList.length ? {
|
|
846
|
+
extension_list: extensionList
|
|
847
|
+
} : {}), nestedCombinations.length ? {
|
|
550
848
|
combinations: nestedCombinations
|
|
551
849
|
} : {});
|
|
552
850
|
});
|
|
553
851
|
}
|
|
852
|
+
function sumMoneyValues(values) {
|
|
853
|
+
return values.reduce(function (sum, value) {
|
|
854
|
+
return sum.plus(toMoneyNumber(value));
|
|
855
|
+
}, new Decimal(0));
|
|
856
|
+
}
|
|
857
|
+
function resolveCombinationBasePrice(combination) {
|
|
858
|
+
var _combination$metadata;
|
|
859
|
+
var preferOriginalPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
860
|
+
var fallbackPrices = preferOriginalPrice ? [combination.original_price, combination.product_price, combination.price] : [combination.price, combination.original_price, combination.product_price];
|
|
861
|
+
return firstPresentValue.apply(void 0, [combination.base_price, (_combination$metadata = combination.metadata) === null || _combination$metadata === void 0 ? void 0 : _combination$metadata.source_product_price].concat(fallbackPrices));
|
|
862
|
+
}
|
|
863
|
+
function sumNormalizedOptionTotals(options, currencySymbol) {
|
|
864
|
+
return formatCalculatedMoney(sumMoneyValues(options.map(function (option) {
|
|
865
|
+
return option.total_price;
|
|
866
|
+
})), currencySymbol);
|
|
867
|
+
}
|
|
868
|
+
function sumCombinationTotals(combinations, currencySymbol) {
|
|
869
|
+
return formatCalculatedMoney(sumMoneyValues(combinations.map(function (combination) {
|
|
870
|
+
return combination.total_selling_price;
|
|
871
|
+
})), currencySymbol);
|
|
872
|
+
}
|
|
554
873
|
function resolveProductNote(product, locale) {
|
|
555
874
|
var productNote = getLocalizedValue(product.product_note, locale).trim();
|
|
556
875
|
if (productNote) return productNote;
|
|
557
876
|
return getLocalizedValue(product.note, locale).trim();
|
|
558
877
|
}
|
|
878
|
+
function buildProductAllergyMap(order, locale) {
|
|
879
|
+
var allergyByProductUid = new Map();
|
|
880
|
+
for (var _i = 0, _normalizeArray = normalizeArray(order.notes); _i < _normalizeArray.length; _i++) {
|
|
881
|
+
var _note$content, _relation$target_uuid;
|
|
882
|
+
var note = _normalizeArray[_i];
|
|
883
|
+
if (!note || _typeof(note) !== 'object' || Array.isArray(note) || String(note.note_type || '').trim() !== 'allergy') {
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
var content = getLocalizedValue((_note$content = note.content) === null || _note$content === void 0 ? void 0 : _note$content.text, locale).trim();
|
|
887
|
+
if (!content) continue;
|
|
888
|
+
var relation = normalizeArray(note.note_relations).find(function (item) {
|
|
889
|
+
return item && _typeof(item) === 'object' && !Array.isArray(item) && item.relation_type === 'about' && item.target_type === 'order_detail' && Number(item.is_primary) === 1;
|
|
890
|
+
});
|
|
891
|
+
var productUid = String((_relation$target_uuid = relation === null || relation === void 0 ? void 0 : relation.target_uuid) !== null && _relation$target_uuid !== void 0 ? _relation$target_uuid : '').trim();
|
|
892
|
+
if (!productUid || allergyByProductUid.has(productUid)) continue;
|
|
893
|
+
allergyByProductUid.set(productUid, content);
|
|
894
|
+
}
|
|
895
|
+
return allergyByProductUid;
|
|
896
|
+
}
|
|
559
897
|
function resolveBundleProductTitle(params) {
|
|
560
|
-
var
|
|
898
|
+
var _ref31, _ref32, _bundle$bundle_produc;
|
|
561
899
|
var bundle = params.bundle,
|
|
562
900
|
productMap = params.productMap,
|
|
563
901
|
locale = params.locale,
|
|
564
902
|
parentProduct = params.parentProduct;
|
|
565
|
-
var ownTitle =
|
|
903
|
+
var ownTitle = getBundleProductTitleSource(bundle, locale);
|
|
566
904
|
if (ownTitle) return ownTitle;
|
|
567
905
|
var parentBundleItem = resolveBundleItemFromParentProduct({
|
|
568
906
|
bundle: bundle,
|
|
569
907
|
parentProduct: parentProduct
|
|
570
908
|
});
|
|
571
|
-
var parentBundleTitle = parentBundleItem ?
|
|
909
|
+
var parentBundleTitle = parentBundleItem ? getBundleProductTitleSource(parentBundleItem, locale) : '';
|
|
572
910
|
if (parentBundleTitle) return parentBundleTitle;
|
|
573
|
-
var productId = (
|
|
911
|
+
var productId = (_ref31 = (_ref32 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref32 !== void 0 ? _ref32 : bundle.product_id) !== null && _ref31 !== void 0 ? _ref31 : bundle.id;
|
|
574
912
|
var fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
575
913
|
if (!fallbackProduct) return '';
|
|
576
|
-
return
|
|
914
|
+
return getBundleProductTitleSource(fallbackProduct, locale);
|
|
577
915
|
}
|
|
578
916
|
function resolveProductFromMap(productId, productMap) {
|
|
579
917
|
if (productId === undefined || productId === null || productId === '') return null;
|
|
@@ -622,10 +960,10 @@ function resolveVariantTextFromSkuKey(params) {
|
|
|
622
960
|
}
|
|
623
961
|
function resolveVariantTextFromNameMap(params) {
|
|
624
962
|
if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
|
|
625
|
-
return Object.entries(params.nameMap).map(function (
|
|
626
|
-
var
|
|
627
|
-
groupPositionId =
|
|
628
|
-
value =
|
|
963
|
+
return Object.entries(params.nameMap).map(function (_ref33) {
|
|
964
|
+
var _ref34 = _slicedToArray(_ref33, 2),
|
|
965
|
+
groupPositionId = _ref34[0],
|
|
966
|
+
value = _ref34[1];
|
|
629
967
|
var group = resolveVariantGroup(params.parentProduct, groupPositionId);
|
|
630
968
|
if (!group) return '';
|
|
631
969
|
var groupName = getLocalizedValue(group.name, params.locale);
|
|
@@ -656,15 +994,19 @@ function resolveVariantItem(group, itemPositionId) {
|
|
|
656
994
|
}
|
|
657
995
|
function getProductTitleSource(source, locale) {
|
|
658
996
|
if (!source || _typeof(source) !== 'object') return '';
|
|
659
|
-
return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
|
|
997
|
+
return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name_i18n, locale) || resolveTitleValue(source.name, locale);
|
|
998
|
+
}
|
|
999
|
+
function getBundleProductTitleSource(source, locale) {
|
|
1000
|
+
if (!source || _typeof(source) !== 'object') return '';
|
|
1001
|
+
return resolveTitleValue(source.bundle_title, locale) || resolveTitleValue(source.trans_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
|
|
660
1002
|
}
|
|
661
1003
|
function resolveTitleValue(value, locale) {
|
|
662
|
-
var
|
|
1004
|
+
var _ref35, _ref36, _ref37, _ref38, _value$locale;
|
|
663
1005
|
if (value === undefined || value === null) return '';
|
|
664
1006
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
665
1007
|
var dashedLocale = locale.replace('_', '-');
|
|
666
1008
|
var underscoredLocale = locale.replace('-', '_');
|
|
667
|
-
return stringify((
|
|
1009
|
+
return stringify((_ref35 = (_ref36 = (_ref37 = (_ref38 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref38 !== void 0 ? _ref38 : value[underscoredLocale]) !== null && _ref37 !== void 0 ? _ref37 : value.original) !== null && _ref36 !== void 0 ? _ref36 : value.auto) !== null && _ref35 !== void 0 ? _ref35 : '');
|
|
668
1010
|
}
|
|
669
1011
|
function resolveOptionTitleFromParentProduct(params) {
|
|
670
1012
|
var option = params.option,
|
|
@@ -682,17 +1024,17 @@ function flattenOptionItems(parentProduct) {
|
|
|
682
1024
|
return optionGroups.flatMap(function (group) {
|
|
683
1025
|
var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
|
|
684
1026
|
return items.map(function (item) {
|
|
685
|
-
var
|
|
1027
|
+
var _ref39, _item$option_group_id;
|
|
686
1028
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
687
|
-
option_group_id: (
|
|
1029
|
+
option_group_id: (_ref39 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref39 !== void 0 ? _ref39 : group.option_group_id
|
|
688
1030
|
});
|
|
689
1031
|
});
|
|
690
1032
|
});
|
|
691
1033
|
}
|
|
692
1034
|
function isOptionItemMatch(option, item) {
|
|
693
|
-
var
|
|
694
|
-
var optionItemId = (
|
|
695
|
-
var itemId = (
|
|
1035
|
+
var _ref40, _option$option_group_, _ref41, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
|
|
1036
|
+
var optionItemId = (_ref40 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref40 !== void 0 ? _ref40 : option.id;
|
|
1037
|
+
var itemId = (_ref41 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref41 !== void 0 ? _ref41 : item.id;
|
|
696
1038
|
if (!isSameId(optionItemId, itemId)) return false;
|
|
697
1039
|
var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
|
|
698
1040
|
var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
|
|
@@ -702,16 +1044,16 @@ function isOptionItemMatch(option, item) {
|
|
|
702
1044
|
return true;
|
|
703
1045
|
}
|
|
704
1046
|
function resolveBundleItemFromParentProduct(params) {
|
|
705
|
-
var
|
|
1047
|
+
var _ref42, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref44, _bundle$bundle_produc2;
|
|
706
1048
|
var bundle = params.bundle,
|
|
707
1049
|
parentProduct = params.parentProduct;
|
|
708
1050
|
if (!parentProduct) return null;
|
|
709
1051
|
var bundleItems = flattenBundleItems(parentProduct);
|
|
710
|
-
var bundleVariantId = (
|
|
1052
|
+
var bundleVariantId = (_ref42 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref42 !== void 0 ? _ref42 : bundle.product_variant_id;
|
|
711
1053
|
if (isNonZeroId(bundleVariantId)) {
|
|
712
1054
|
var matchedByVariant = bundleItems.find(function (item) {
|
|
713
|
-
var
|
|
714
|
-
return isSameId((
|
|
1055
|
+
var _ref43, _item$bundle_variant_;
|
|
1056
|
+
return isSameId((_ref43 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref43 !== void 0 ? _ref43 : item.product_variant_id, bundleVariantId);
|
|
715
1057
|
});
|
|
716
1058
|
if (matchedByVariant) return matchedByVariant;
|
|
717
1059
|
}
|
|
@@ -724,18 +1066,18 @@ function resolveBundleItemFromParentProduct(params) {
|
|
|
724
1066
|
if (matchedByBundleId) return matchedByBundleId;
|
|
725
1067
|
}
|
|
726
1068
|
var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
|
|
727
|
-
var bundleProductId = (
|
|
1069
|
+
var bundleProductId = (_ref44 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref44 !== void 0 ? _ref44 : bundle.product_id;
|
|
728
1070
|
if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
|
|
729
1071
|
var matchedByGroupAndProduct = bundleItems.find(function (item) {
|
|
730
|
-
var _item$group_id,
|
|
731
|
-
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((
|
|
1072
|
+
var _item$group_id, _ref45, _item$bundle_product_;
|
|
1073
|
+
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref45 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref45 !== void 0 ? _ref45 : item.product_id, bundleProductId);
|
|
732
1074
|
});
|
|
733
1075
|
if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
|
|
734
1076
|
}
|
|
735
1077
|
if (isPresentId(bundleProductId)) {
|
|
736
1078
|
return bundleItems.find(function (item) {
|
|
737
|
-
var
|
|
738
|
-
return isSameId((
|
|
1079
|
+
var _ref46, _item$bundle_product_2;
|
|
1080
|
+
return isSameId((_ref46 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref46 !== void 0 ? _ref46 : item.product_id, bundleProductId);
|
|
739
1081
|
}) || null;
|
|
740
1082
|
}
|
|
741
1083
|
return null;
|
|
@@ -745,9 +1087,9 @@ function flattenBundleItems(parentProduct) {
|
|
|
745
1087
|
return bundleGroups.flatMap(function (group) {
|
|
746
1088
|
var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
|
|
747
1089
|
return items.map(function (item) {
|
|
748
|
-
var
|
|
1090
|
+
var _ref47, _item$group_id2;
|
|
749
1091
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
750
|
-
group_id: (
|
|
1092
|
+
group_id: (_ref47 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref47 !== void 0 ? _ref47 : group.group_id
|
|
751
1093
|
});
|
|
752
1094
|
});
|
|
753
1095
|
});
|
|
@@ -771,8 +1113,8 @@ function isSameId(left, right) {
|
|
|
771
1113
|
return String(left) === String(right);
|
|
772
1114
|
}
|
|
773
1115
|
function formatBundlePrice(bundle, currencySymbol) {
|
|
774
|
-
var
|
|
775
|
-
var value = (
|
|
1116
|
+
var _ref48, _ref49, _bundle$bundle_sellin;
|
|
1117
|
+
var value = (_ref48 = (_ref49 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref49 !== void 0 ? _ref49 : bundle.price) !== null && _ref48 !== void 0 ? _ref48 : 0;
|
|
776
1118
|
var amount = new Decimal(toMoneyNumber(value));
|
|
777
1119
|
// 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
|
|
778
1120
|
var isNegative = bundle.price_type === 'markdown';
|
|
@@ -780,7 +1122,7 @@ function formatBundlePrice(bundle, currencySymbol) {
|
|
|
780
1122
|
return formatMoney(amount, currencySymbol);
|
|
781
1123
|
}
|
|
782
1124
|
function buildFees(params) {
|
|
783
|
-
var
|
|
1125
|
+
var _firstPresentValue2, _firstPresentValue3;
|
|
784
1126
|
var order = params.order,
|
|
785
1127
|
shopInfo = params.shopInfo,
|
|
786
1128
|
locale = params.locale,
|
|
@@ -789,10 +1131,10 @@ function buildFees(params) {
|
|
|
789
1131
|
currencySymbol = params.currencySymbol,
|
|
790
1132
|
financials = params.financials;
|
|
791
1133
|
var fees = [];
|
|
792
|
-
for (var
|
|
793
|
-
var
|
|
794
|
-
var surcharge =
|
|
795
|
-
var value = (
|
|
1134
|
+
for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
|
|
1135
|
+
var _ref50, _surcharge$amount;
|
|
1136
|
+
var surcharge = _normalizeArray2[_i2];
|
|
1137
|
+
var value = (_ref50 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref50 !== void 0 ? _ref50 : surcharge.total_amount;
|
|
796
1138
|
if (!isNonZero(value)) continue;
|
|
797
1139
|
fees.push({
|
|
798
1140
|
item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
|
|
@@ -815,12 +1157,6 @@ function buildFees(params) {
|
|
|
815
1157
|
});
|
|
816
1158
|
var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
|
|
817
1159
|
var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
|
|
818
|
-
if (isNonZero(roundingAmount)) {
|
|
819
|
-
fees.push({
|
|
820
|
-
item: label(locale, 'rounding'),
|
|
821
|
-
value: formatMoney(roundingAmount, currencySymbol)
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
1160
|
var payProcessingFee = financials.payProcessingFee;
|
|
825
1161
|
if (isNonZero(payProcessingFee)) {
|
|
826
1162
|
fees.push({
|
|
@@ -829,14 +1165,16 @@ function buildFees(params) {
|
|
|
829
1165
|
});
|
|
830
1166
|
}
|
|
831
1167
|
var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
|
|
832
|
-
var productOriginalAmount = (
|
|
1168
|
+
var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
|
|
833
1169
|
var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
1170
|
+
var itemDiscountAmount = new Decimal(toMoneyNumber(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0)).minus(toMoneyNumber(productOriginalAmount));
|
|
834
1171
|
return {
|
|
835
1172
|
fees: fees,
|
|
836
1173
|
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
837
|
-
total_amount: formatMoney((
|
|
1174
|
+
total_amount: formatMoney((_firstPresentValue3 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0, currencySymbol),
|
|
838
1175
|
original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
|
|
839
1176
|
product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
|
|
1177
|
+
item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol),
|
|
840
1178
|
expect_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
841
1179
|
product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
|
|
842
1180
|
return sum + product.product_quantity;
|
|
@@ -861,15 +1199,15 @@ function buildFees(params) {
|
|
|
861
1199
|
};
|
|
862
1200
|
}
|
|
863
1201
|
function resolveReceiptFinancials(order, summary) {
|
|
864
|
-
var
|
|
865
|
-
var totalAmount = (
|
|
1202
|
+
var _firstPresentValue4, _firstPresentValue5, _firstPresentValue6, _firstPresentValue7;
|
|
1203
|
+
var totalAmount = (_firstPresentValue4 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
|
|
866
1204
|
var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
|
|
867
1205
|
var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
|
|
868
|
-
var orderPaidAmount = (
|
|
869
|
-
var totalRefundAmount = (
|
|
1206
|
+
var orderPaidAmount = (_firstPresentValue5 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
|
|
1207
|
+
var totalRefundAmount = (_firstPresentValue6 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
|
|
870
1208
|
var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
|
|
871
1209
|
var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
|
|
872
|
-
var customerPaidAmount = (
|
|
1210
|
+
var customerPaidAmount = (_firstPresentValue7 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
|
|
873
1211
|
var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
|
|
874
1212
|
return {
|
|
875
1213
|
totalAmount: totalAmount,
|
|
@@ -898,9 +1236,9 @@ function resolveTaxTitle(params) {
|
|
|
898
1236
|
}
|
|
899
1237
|
function calculateProductOriginalAmount(order) {
|
|
900
1238
|
return normalizeArray(order.products).reduce(function (total, product) {
|
|
901
|
-
var
|
|
902
|
-
var quantity = toNumber((
|
|
903
|
-
var originalPrice = (
|
|
1239
|
+
var _ref51, _ref52, _product$product_quan3, _ref53, _ref54, _ref55, _product$original_pri2;
|
|
1240
|
+
var quantity = toNumber((_ref51 = (_ref52 = (_product$product_quan3 = product.product_quantity) !== null && _product$product_quan3 !== void 0 ? _product$product_quan3 : product.quantity) !== null && _ref52 !== void 0 ? _ref52 : product.num) !== null && _ref51 !== void 0 ? _ref51 : 1, 1);
|
|
1241
|
+
var originalPrice = (_ref53 = (_ref54 = (_ref55 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref55 !== void 0 ? _ref55 : product.payment_price) !== null && _ref54 !== void 0 ? _ref54 : product.price) !== null && _ref53 !== void 0 ? _ref53 : 0;
|
|
904
1242
|
return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
|
|
905
1243
|
}, new Decimal(0));
|
|
906
1244
|
}
|
|
@@ -925,15 +1263,13 @@ function normalizeCustomerDisplayValue(value) {
|
|
|
925
1263
|
}
|
|
926
1264
|
function buildDelivery(order, locale) {
|
|
927
1265
|
var _order$metadata2, _order$metadata3, _order$metadata4, _order$metadata5, _order$metadata6, _order$metadata7, _order$metadata8, _order$metadata9, _order$metadata10, _order$metadata11, _order$metadata12;
|
|
928
|
-
var
|
|
929
|
-
var
|
|
930
|
-
var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType, order);
|
|
1266
|
+
var serviceType = stringify((_order$metadata2 = order.metadata) === null || _order$metadata2 === void 0 || (_order$metadata2 = _order$metadata2.shop_service_data) === null || _order$metadata2 === void 0 ? void 0 : _order$metadata2.service_type).trim();
|
|
1267
|
+
var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
|
|
931
1268
|
if (!serviceTypeLabelKey) return [];
|
|
932
1269
|
var items = [{
|
|
933
|
-
item:
|
|
934
|
-
value:
|
|
935
|
-
size: 2
|
|
936
|
-
align: 'left'
|
|
1270
|
+
item: label(locale, serviceTypeLabelKey),
|
|
1271
|
+
value: '',
|
|
1272
|
+
size: 2
|
|
937
1273
|
}];
|
|
938
1274
|
var handoverTime = firstPresentValue(order.handover_time, order.handover_at, order.pickup_time, order.pickup_at, order.scheduled_pickup_time, order.delivery_time, order.delivery_at, order.scheduled_delivery_time, order.fulfillment_time, order.fulfillment_at, (_order$metadata3 = order.metadata) === null || _order$metadata3 === void 0 ? void 0 : _order$metadata3.handover_time, (_order$metadata4 = order.metadata) === null || _order$metadata4 === void 0 ? void 0 : _order$metadata4.handover_at, (_order$metadata5 = order.metadata) === null || _order$metadata5 === void 0 ? void 0 : _order$metadata5.pickup_time, (_order$metadata6 = order.metadata) === null || _order$metadata6 === void 0 ? void 0 : _order$metadata6.pickup_at, (_order$metadata7 = order.metadata) === null || _order$metadata7 === void 0 ? void 0 : _order$metadata7.scheduled_pickup_time, (_order$metadata8 = order.metadata) === null || _order$metadata8 === void 0 ? void 0 : _order$metadata8.delivery_time, (_order$metadata9 = order.metadata) === null || _order$metadata9 === void 0 ? void 0 : _order$metadata9.delivery_at, (_order$metadata10 = order.metadata) === null || _order$metadata10 === void 0 ? void 0 : _order$metadata10.scheduled_delivery_time, (_order$metadata11 = order.metadata) === null || _order$metadata11 === void 0 ? void 0 : _order$metadata11.fulfillment_time, (_order$metadata12 = order.metadata) === null || _order$metadata12 === void 0 ? void 0 : _order$metadata12.fulfillment_at);
|
|
939
1275
|
if (isPresentId(handoverTime)) {
|
|
@@ -945,30 +1281,140 @@ function buildDelivery(order, locale) {
|
|
|
945
1281
|
return items;
|
|
946
1282
|
}
|
|
947
1283
|
function buildAppointment(order, locale) {
|
|
948
|
-
var _order$metadata13, _order$metadata14, _order$form_data;
|
|
949
|
-
var
|
|
1284
|
+
var _order$metadata13, _order$metadata14, _order$metadata15, _order$form_data;
|
|
1285
|
+
var parentScheduleId = (_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.appointment_booking_parent_schedule_id;
|
|
1286
|
+
var bookings = sortBookings(normalizeArray(order.bookings).filter(function (booking) {
|
|
1287
|
+
return isReceiptAppointmentBooking(booking, parentScheduleId);
|
|
1288
|
+
}));
|
|
950
1289
|
if (bookings.length) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
product_uid: productUid
|
|
960
|
-
} : {}), isPresentId(bookingUid) ? {
|
|
961
|
-
booking_uid: bookingUid
|
|
962
|
-
} : {});
|
|
1290
|
+
var allResources = normalizeArray(order.resources || order.resource_list);
|
|
1291
|
+
return bookings.flatMap(function (booking) {
|
|
1292
|
+
return buildAppointmentRows({
|
|
1293
|
+
booking: booking,
|
|
1294
|
+
allResources: allResources,
|
|
1295
|
+
bookingCount: bookings.length,
|
|
1296
|
+
locale: locale
|
|
1297
|
+
});
|
|
963
1298
|
});
|
|
964
1299
|
}
|
|
965
|
-
var tableName = order.table_name || ((_order$
|
|
1300
|
+
var tableName = order.table_name || ((_order$metadata14 = order.metadata) === null || _order$metadata14 === void 0 ? void 0 : _order$metadata14.table_name) || ((_order$metadata15 = order.metadata) === null || _order$metadata15 === void 0 || (_order$metadata15 = _order$metadata15.table) === null || _order$metadata15 === void 0 ? void 0 : _order$metadata15.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
|
|
966
1301
|
if (!tableName) return [];
|
|
967
1302
|
return [{
|
|
968
1303
|
item: label(locale, 'table'),
|
|
969
1304
|
value: getLocalizedValue(tableName, locale)
|
|
970
1305
|
}];
|
|
971
1306
|
}
|
|
1307
|
+
function isReceiptAppointmentBooking(booking, parentScheduleId) {
|
|
1308
|
+
if (!booking || _typeof(booking) !== 'object' || Array.isArray(booking)) {
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
if (isPresentId(parentScheduleId) && isSameId(booking.schedule_event_id, parentScheduleId)) {
|
|
1312
|
+
return false;
|
|
1313
|
+
}
|
|
1314
|
+
var parentId = booking.parent_id;
|
|
1315
|
+
if (parentId === undefined || parentId === null || parentId === '') {
|
|
1316
|
+
return true;
|
|
1317
|
+
}
|
|
1318
|
+
return Number(parentId) !== 0;
|
|
1319
|
+
}
|
|
1320
|
+
function buildAppointmentRows(params) {
|
|
1321
|
+
var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
|
|
1322
|
+
var booking = params.booking,
|
|
1323
|
+
allResources = params.allResources,
|
|
1324
|
+
bookingCount = params.bookingCount,
|
|
1325
|
+
locale = params.locale;
|
|
1326
|
+
var productUid = stringify(firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid)).trim();
|
|
1327
|
+
var bookingUid = stringify(firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid)).trim();
|
|
1328
|
+
var association = {
|
|
1329
|
+
product_uid: productUid,
|
|
1330
|
+
booking_uid: bookingUid
|
|
1331
|
+
};
|
|
1332
|
+
var bookingId = stringify(firstPresentValue(booking.booking_id, booking.schedule_event_id, bookingUid)).trim();
|
|
1333
|
+
var bookingTime = formatBookingRange(booking, locale);
|
|
1334
|
+
var resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
|
|
1335
|
+
var holder = getLocalizedValue((_booking$holder$name = (_booking$holder = booking.holder) === null || _booking$holder === void 0 ? void 0 : _booking$holder.name) !== null && _booking$holder$name !== void 0 ? _booking$holder$name : (_booking$metadata3 = booking.metadata) === null || _booking$metadata3 === void 0 || (_booking$metadata3 = _booking$metadata3.holder) === null || _booking$metadata3 === void 0 ? void 0 : _booking$metadata3.name, locale).trim();
|
|
1336
|
+
return [_objectSpread({
|
|
1337
|
+
item: label(locale, 'bookingId'),
|
|
1338
|
+
value: bookingId
|
|
1339
|
+
}, association), _objectSpread({
|
|
1340
|
+
item: label(locale, 'bookingDateTime'),
|
|
1341
|
+
value: bookingTime
|
|
1342
|
+
}, association), _objectSpread({
|
|
1343
|
+
item: label(locale, 'bookingResource'),
|
|
1344
|
+
value: resourceText
|
|
1345
|
+
}, association), _objectSpread({
|
|
1346
|
+
item: label(locale, 'bookingHolder'),
|
|
1347
|
+
value: holder
|
|
1348
|
+
}, association)].filter(function (row) {
|
|
1349
|
+
return Boolean(row.value);
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
function formatBookingRange(booking, locale) {
|
|
1353
|
+
var startDate = stringify(booking.start_date);
|
|
1354
|
+
var startTime = stringify(booking.start_time);
|
|
1355
|
+
var endDate = stringify(booking.end_date || startDate);
|
|
1356
|
+
var endTime = stringify(booking.end_time);
|
|
1357
|
+
var start = firstValidBookingDate(booking.start_at, booking.start_datetime, booking.start_date_time, "".concat(startDate, " ").concat(startTime).trim());
|
|
1358
|
+
var end = firstValidBookingDate(booking.end_at, booking.end_datetime, booking.end_date_time, endTime ? "".concat(endDate, " ").concat(endTime).trim() : '');
|
|
1359
|
+
if (!start) {
|
|
1360
|
+
return [startDate, startTime, endTime ? "- ".concat(endDate, " ").concat(endTime) : ''].filter(Boolean).join(' ');
|
|
1361
|
+
}
|
|
1362
|
+
var dateFormat = locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD';
|
|
1363
|
+
var startText = start.format("".concat(dateFormat, " HH:mm"));
|
|
1364
|
+
if (!end) return startText;
|
|
1365
|
+
return "".concat(startText, " - ").concat(end.isSame(start, 'day') ? end.format('HH:mm') : end.format("".concat(dateFormat, " HH:mm")));
|
|
1366
|
+
}
|
|
1367
|
+
function firstValidBookingDate() {
|
|
1368
|
+
for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1369
|
+
values[_key2] = arguments[_key2];
|
|
1370
|
+
}
|
|
1371
|
+
for (var _i3 = 0, _values = values; _i3 < _values.length; _i3++) {
|
|
1372
|
+
var value = _values[_i3];
|
|
1373
|
+
if (!isPresentId(value)) continue;
|
|
1374
|
+
var parsed = dayjs(value);
|
|
1375
|
+
if (parsed.isValid()) return parsed;
|
|
1376
|
+
}
|
|
1377
|
+
return null;
|
|
1378
|
+
}
|
|
1379
|
+
function resolveBookingResourcesForReceipt(booking, allResources, bookingCount) {
|
|
1380
|
+
var _booking$metadata4;
|
|
1381
|
+
var embedded = normalizeArray(booking.resources).filter(function (resource) {
|
|
1382
|
+
return Boolean(resource) && _typeof(resource) === 'object' && !Array.isArray(resource);
|
|
1383
|
+
});
|
|
1384
|
+
var resourceIds = new Set([booking.resource_id, booking.relation_id].concat(_toConsumableArray(normalizeArray(booking.resource_ids)), _toConsumableArray(normalizeArray((_booking$metadata4 = booking.metadata) === null || _booking$metadata4 === void 0 ? void 0 : _booking$metadata4.resource_ids))).map(function (value) {
|
|
1385
|
+
return stringify(value).trim();
|
|
1386
|
+
}).filter(Boolean));
|
|
1387
|
+
var _iterator3 = _createForOfIteratorHelper(embedded),
|
|
1388
|
+
_step3;
|
|
1389
|
+
try {
|
|
1390
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1391
|
+
var _ref57, _resource$id2;
|
|
1392
|
+
var resource = _step3.value;
|
|
1393
|
+
var id = stringify((_ref57 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref57 !== void 0 ? _ref57 : resource.relation_id).trim();
|
|
1394
|
+
if (id) resourceIds.add(id);
|
|
1395
|
+
}
|
|
1396
|
+
} catch (err) {
|
|
1397
|
+
_iterator3.e(err);
|
|
1398
|
+
} finally {
|
|
1399
|
+
_iterator3.f();
|
|
1400
|
+
}
|
|
1401
|
+
if (resourceIds.size) {
|
|
1402
|
+
var matched = allResources.filter(function (resource) {
|
|
1403
|
+
var _ref56, _resource$id;
|
|
1404
|
+
return resourceIds.has(stringify((_ref56 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref56 !== void 0 ? _ref56 : resource.relation_id).trim());
|
|
1405
|
+
});
|
|
1406
|
+
if (matched.length) return matched;
|
|
1407
|
+
}
|
|
1408
|
+
if (embedded.length) return embedded;
|
|
1409
|
+
if (bookingCount === 1 && allResources.length) return allResources;
|
|
1410
|
+
return [];
|
|
1411
|
+
}
|
|
1412
|
+
function formatBookingResources(resources, locale) {
|
|
1413
|
+
return resources.map(function (resource) {
|
|
1414
|
+
var _resource$metadata, _resource$metadata2, _resource$metadata3, _resource$metadata4;
|
|
1415
|
+
return [getLocalizedValue(resource.form_title || ((_resource$metadata = resource.metadata) === null || _resource$metadata === void 0 ? void 0 : _resource$metadata.form_name) || resource.relation_form_name || ((_resource$metadata2 = resource.metadata) === null || _resource$metadata2 === void 0 ? void 0 : _resource$metadata2.relation_form_name), locale), getLocalizedValue(resource.title || resource.name || resource.main_field || ((_resource$metadata3 = resource.metadata) === null || _resource$metadata3 === void 0 ? void 0 : _resource$metadata3.main_field) || ((_resource$metadata4 = resource.metadata) === null || _resource$metadata4 === void 0 ? void 0 : _resource$metadata4.resource_name), locale)].filter(Boolean).join(' ');
|
|
1416
|
+
}).filter(Boolean).join(', ');
|
|
1417
|
+
}
|
|
972
1418
|
function sortBookings(bookings) {
|
|
973
1419
|
return bookings.map(function (booking, index) {
|
|
974
1420
|
return {
|
|
@@ -980,23 +1426,23 @@ function sortBookings(bookings) {
|
|
|
980
1426
|
var leftStart = bookingStartTimestamp(left.booking);
|
|
981
1427
|
var rightStart = bookingStartTimestamp(right.booking);
|
|
982
1428
|
if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
|
|
983
|
-
for (var
|
|
1429
|
+
for (var _i4 = 0, _arr = ['booking_id', 'schedule_event_id']; _i4 < _arr.length; _i4++) {
|
|
984
1430
|
var _left$booking, _right$booking;
|
|
985
|
-
var field = _arr[
|
|
1431
|
+
var field = _arr[_i4];
|
|
986
1432
|
var fieldOrder = compareOptionalValues((_left$booking = left.booking) === null || _left$booking === void 0 ? void 0 : _left$booking[field], (_right$booking = right.booking) === null || _right$booking === void 0 ? void 0 : _right$booking[field]);
|
|
987
1433
|
if (fieldOrder !== 0) return fieldOrder;
|
|
988
1434
|
}
|
|
989
1435
|
var bookingUidOrder = compareOptionalValues(firstPresentValue((_left$booking2 = left.booking) === null || _left$booking2 === void 0 || (_left$booking2 = _left$booking2.metadata) === null || _left$booking2 === void 0 ? void 0 : _left$booking2.unique_identification_number, (_left$booking3 = left.booking) === null || _left$booking3 === void 0 ? void 0 : _left$booking3.booking_uid), firstPresentValue((_right$booking2 = right.booking) === null || _right$booking2 === void 0 || (_right$booking2 = _right$booking2.metadata) === null || _right$booking2 === void 0 ? void 0 : _right$booking2.unique_identification_number, (_right$booking3 = right.booking) === null || _right$booking3 === void 0 ? void 0 : _right$booking3.booking_uid));
|
|
990
1436
|
return bookingUidOrder || left.index - right.index;
|
|
991
|
-
}).map(function (
|
|
992
|
-
var booking =
|
|
1437
|
+
}).map(function (_ref58) {
|
|
1438
|
+
var booking = _ref58.booking;
|
|
993
1439
|
return booking;
|
|
994
1440
|
});
|
|
995
1441
|
}
|
|
996
1442
|
function bookingStartTimestamp(booking) {
|
|
997
1443
|
var startValues = [booking === null || booking === void 0 ? void 0 : booking.start_at, booking === null || booking === void 0 ? void 0 : booking.start_datetime, booking === null || booking === void 0 ? void 0 : booking.booking_time, isPresentId(booking === null || booking === void 0 ? void 0 : booking.start_date) ? "".concat(booking.start_date, " ").concat(stringify(booking.start_time)).trim() : undefined];
|
|
998
|
-
for (var
|
|
999
|
-
var startValue = _startValues[
|
|
1444
|
+
for (var _i5 = 0, _startValues = startValues; _i5 < _startValues.length; _i5++) {
|
|
1445
|
+
var startValue = _startValues[_i5];
|
|
1000
1446
|
if (!isPresentId(startValue)) continue;
|
|
1001
1447
|
var timestamp = dayjs(startValue).valueOf();
|
|
1002
1448
|
if (Number.isFinite(timestamp)) return timestamp;
|
|
@@ -1032,7 +1478,9 @@ function buildPaymentData(params) {
|
|
|
1032
1478
|
payment: payment,
|
|
1033
1479
|
locale: params.locale,
|
|
1034
1480
|
currencySymbol: params.currencySymbol,
|
|
1035
|
-
includeFundRecordBalance: false
|
|
1481
|
+
includeFundRecordBalance: false,
|
|
1482
|
+
includeFundRecordUsage: true,
|
|
1483
|
+
includePaymentAmount: true
|
|
1036
1484
|
});
|
|
1037
1485
|
});
|
|
1038
1486
|
}
|
|
@@ -1049,8 +1497,8 @@ function buildRefundData(params) {
|
|
|
1049
1497
|
result.set(identity, candidate);
|
|
1050
1498
|
}
|
|
1051
1499
|
return result;
|
|
1052
|
-
}, new Map()).values()).filter(function (
|
|
1053
|
-
var refund =
|
|
1500
|
+
}, new Map()).values()).filter(function (_ref59) {
|
|
1501
|
+
var refund = _ref59.refund;
|
|
1054
1502
|
return isPrintableRefund(refund);
|
|
1055
1503
|
}).sort(function (left, right) {
|
|
1056
1504
|
var leftTime = refundTimestamp(left.refund);
|
|
@@ -1058,12 +1506,12 @@ function buildRefundData(params) {
|
|
|
1058
1506
|
if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
|
|
1059
1507
|
return left.index - right.index;
|
|
1060
1508
|
});
|
|
1061
|
-
return refunds.map(function (
|
|
1062
|
-
var
|
|
1063
|
-
var refund =
|
|
1509
|
+
return refunds.map(function (_ref60) {
|
|
1510
|
+
var _firstPresentValue8;
|
|
1511
|
+
var refund = _ref60.refund;
|
|
1064
1512
|
var payment = resolveRefundPayment(refund, payments);
|
|
1065
1513
|
var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
|
|
1066
|
-
var amount = (
|
|
1514
|
+
var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
|
|
1067
1515
|
var items = [{
|
|
1068
1516
|
item: methodName,
|
|
1069
1517
|
value: formatNegativeMoney(amount, params.currencySymbol)
|
|
@@ -1120,32 +1568,556 @@ function resolveRefundPayment(refund, payments) {
|
|
|
1120
1568
|
return matchedPayment || refund;
|
|
1121
1569
|
}
|
|
1122
1570
|
function buildWallets(params) {
|
|
1123
|
-
var
|
|
1571
|
+
var virtualCurrencySnapshots = collectVirtualCurrencySnapshots(params.order);
|
|
1572
|
+
var displayedWalletPayments = normalizeArray(params.order.payments).filter(function (payment) {
|
|
1124
1573
|
return isPrintablePayment(payment) && !!getFundRecord(payment);
|
|
1125
|
-
})
|
|
1574
|
+
});
|
|
1575
|
+
var paymentWallets = displayedWalletPayments.map(function (payment) {
|
|
1576
|
+
var virtualCurrencySnapshot = findVirtualCurrencySnapshotForPayment(payment, virtualCurrencySnapshots.byId);
|
|
1126
1577
|
return buildPaymentItems({
|
|
1127
1578
|
payment: payment,
|
|
1128
1579
|
locale: params.locale,
|
|
1129
1580
|
currencySymbol: params.currencySymbol,
|
|
1130
|
-
includeFundRecordBalance: true
|
|
1581
|
+
includeFundRecordBalance: true,
|
|
1582
|
+
includeFundRecordUsage: false,
|
|
1583
|
+
includePaymentAmount: false,
|
|
1584
|
+
virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
|
|
1585
|
+
});
|
|
1586
|
+
});
|
|
1587
|
+
var displayedWalletAssetIdentities = collectDisplayedWalletAssetIdentities(displayedWalletPayments);
|
|
1588
|
+
var voucherWallets = buildVoucherAssets(_objectSpread(_objectSpread({}, params), {}, {
|
|
1589
|
+
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1590
|
+
}));
|
|
1591
|
+
var productDiscountWallets = buildProductDiscountAssets(_objectSpread(_objectSpread({}, params), {}, {
|
|
1592
|
+
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1593
|
+
}));
|
|
1594
|
+
return [].concat(_toConsumableArray(paymentWallets), voucherWallets, productDiscountWallets, _toConsumableArray(buildPointCardSnapshotAssets({
|
|
1595
|
+
order: params.order,
|
|
1596
|
+
locale: params.locale,
|
|
1597
|
+
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1598
|
+
})), _toConsumableArray(buildVirtualCurrencySnapshotAssets({
|
|
1599
|
+
snapshots: virtualCurrencySnapshots.items,
|
|
1600
|
+
order: params.order,
|
|
1601
|
+
locale: params.locale,
|
|
1602
|
+
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1603
|
+
})));
|
|
1604
|
+
}
|
|
1605
|
+
function collectDisplayedWalletAssetIdentities(payments) {
|
|
1606
|
+
var identities = [];
|
|
1607
|
+
payments.forEach(function (payment) {
|
|
1608
|
+
var fundRecord = getFundRecord(payment);
|
|
1609
|
+
var ids = Array.from(new Set([fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id].map(function (value) {
|
|
1610
|
+
return normalizeWalletPassId(value);
|
|
1611
|
+
}).filter(function (value) {
|
|
1612
|
+
return !!value;
|
|
1613
|
+
})));
|
|
1614
|
+
var codes = normalizeWalletAssetCodes(fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.encoded);
|
|
1615
|
+
if (!ids.length) {
|
|
1616
|
+
registerWalletAssetIdentity(identities, {
|
|
1617
|
+
id: null,
|
|
1618
|
+
codes: codes
|
|
1619
|
+
});
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1622
|
+
ids.forEach(function (id) {
|
|
1623
|
+
registerWalletAssetIdentity(identities, {
|
|
1624
|
+
id: id,
|
|
1625
|
+
codes: codes
|
|
1626
|
+
});
|
|
1131
1627
|
});
|
|
1132
1628
|
});
|
|
1133
|
-
return
|
|
1629
|
+
return identities;
|
|
1630
|
+
}
|
|
1631
|
+
var PRODUCT_WALLET_DISCOUNT_TYPES = new Set(['good_pass', 'discount_card', 'product_discount_card', 'entitlement_pass']);
|
|
1632
|
+
function buildProductDiscountAssets(params) {
|
|
1633
|
+
var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1634
|
+
return collectProductWalletDiscountAssets(params.order).flatMap(function (asset) {
|
|
1635
|
+
var _getProductWalletDisc;
|
|
1636
|
+
if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
|
|
1637
|
+
id: asset.id,
|
|
1638
|
+
codes: asset.codes
|
|
1639
|
+
})) return [];
|
|
1640
|
+
var name = getProductWalletDiscountName(asset, params.locale);
|
|
1641
|
+
var assetTime = (_getProductWalletDisc = getProductWalletDiscountTime(asset)) !== null && _getProductWalletDisc !== void 0 ? _getProductWalletDisc : fallbackAssetTime;
|
|
1642
|
+
var timeRow = isPresentId(assetTime) ? {
|
|
1643
|
+
item: formatDateTime(assetTime, params.locale),
|
|
1644
|
+
value: ''
|
|
1645
|
+
} : null;
|
|
1646
|
+
if (asset.type === 'entitlement_pass') {
|
|
1647
|
+
var remaining = getProductEntitlementBalance(asset);
|
|
1648
|
+
return [[{
|
|
1649
|
+
item: name,
|
|
1650
|
+
value: ''
|
|
1651
|
+
}].concat(_toConsumableArray(remaining ? [{
|
|
1652
|
+
item: label(params.locale, 'entitlementRemaining'),
|
|
1653
|
+
value: formatEntitlementUses(remaining, params.locale)
|
|
1654
|
+
}] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1655
|
+
}
|
|
1656
|
+
var percent = getProductWalletDiscountPercent(asset);
|
|
1657
|
+
if (percent) {
|
|
1658
|
+
return [[{
|
|
1659
|
+
item: appendPercentToVoucherName(name, percent),
|
|
1660
|
+
value: formatVoucherDiscount(percent, params.locale)
|
|
1661
|
+
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1662
|
+
}
|
|
1663
|
+
var balance = getProductWalletMoneyBalance(asset);
|
|
1664
|
+
return [[{
|
|
1665
|
+
item: name,
|
|
1666
|
+
value: ''
|
|
1667
|
+
}].concat(_toConsumableArray(balance ? [{
|
|
1668
|
+
item: label(params.locale, 'balance'),
|
|
1669
|
+
value: formatMoney(balance, params.currencySymbol)
|
|
1670
|
+
}] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
function collectProductWalletDiscountAssets(order) {
|
|
1674
|
+
var assets = [];
|
|
1675
|
+
var assetsById = new Map();
|
|
1676
|
+
normalizeArray(order.products).forEach(function (rawProduct) {
|
|
1677
|
+
if (!rawProduct || _typeof(rawProduct) !== 'object') return;
|
|
1678
|
+
visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById);
|
|
1679
|
+
});
|
|
1680
|
+
return assets;
|
|
1681
|
+
}
|
|
1682
|
+
function visitProductWalletDiscounts(product, assets, assetsById) {
|
|
1683
|
+
normalizeArray(product.discount_list).forEach(function (record) {
|
|
1684
|
+
if (!record || _typeof(record) !== 'object' || Array.isArray(record)) return;
|
|
1685
|
+
var type = getProductWalletDiscountType(record);
|
|
1686
|
+
if (!type) return;
|
|
1687
|
+
var id = getProductWalletDiscountAssetId(record);
|
|
1688
|
+
if (!id) return;
|
|
1689
|
+
var codes = getProductWalletDiscountCodes(record);
|
|
1690
|
+
var existing = assetsById.get(id);
|
|
1691
|
+
if (existing) {
|
|
1692
|
+
existing.records.push(record);
|
|
1693
|
+
existing.codes = Array.from(new Set([].concat(_toConsumableArray(existing.codes), codes)));
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
var asset = {
|
|
1697
|
+
id: id,
|
|
1698
|
+
type: type,
|
|
1699
|
+
codes: codes,
|
|
1700
|
+
records: [record]
|
|
1701
|
+
};
|
|
1702
|
+
assetsById.set(id, asset);
|
|
1703
|
+
assets.push(asset);
|
|
1704
|
+
});
|
|
1705
|
+
for (var _i6 = 0, _arr2 = ['combinations', 'product_bundle', 'bundle']; _i6 < _arr2.length; _i6++) {
|
|
1706
|
+
var childKey = _arr2[_i6];
|
|
1707
|
+
normalizeArray(product[childKey]).forEach(function (child) {
|
|
1708
|
+
if (!child || _typeof(child) !== 'object' || Array.isArray(child)) return;
|
|
1709
|
+
visitProductWalletDiscounts(child, assets, assetsById);
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
function getProductWalletDiscountType(record) {
|
|
1714
|
+
for (var _i7 = 0, _arr3 = [record.tag, record.type, (_record$discount = record.discount) === null || _record$discount === void 0 ? void 0 : _record$discount.tag, (_record$discount2 = record.discount) === null || _record$discount2 === void 0 ? void 0 : _record$discount2.type]; _i7 < _arr3.length; _i7++) {
|
|
1715
|
+
var _record$discount, _record$discount2;
|
|
1716
|
+
var value = _arr3[_i7];
|
|
1717
|
+
var type = stringify(value).trim().toLowerCase();
|
|
1718
|
+
if (PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
|
|
1719
|
+
}
|
|
1720
|
+
return null;
|
|
1721
|
+
}
|
|
1722
|
+
function getProductWalletDiscountAssetId(record) {
|
|
1723
|
+
for (var _i8 = 0, _arr4 = [(_record$discount3 = record.discount) === null || _record$discount3 === void 0 ? void 0 : _record$discount3.resource_id, record.resource_id, record.id, record.discount_id]; _i8 < _arr4.length; _i8++) {
|
|
1724
|
+
var _record$discount3;
|
|
1725
|
+
var value = _arr4[_i8];
|
|
1726
|
+
var id = normalizeWalletPassId(value);
|
|
1727
|
+
if (id && id !== '0') return id;
|
|
1728
|
+
}
|
|
1729
|
+
return null;
|
|
1730
|
+
}
|
|
1731
|
+
function getProductWalletDiscountCodes(record) {
|
|
1732
|
+
var _record$discount4, _record$discount5;
|
|
1733
|
+
return normalizeWalletAssetCodes(record.code, record.encoded, (_record$discount4 = record.discount) === null || _record$discount4 === void 0 ? void 0 : _record$discount4.code, (_record$discount5 = record.discount) === null || _record$discount5 === void 0 ? void 0 : _record$discount5.encoded);
|
|
1734
|
+
}
|
|
1735
|
+
function getProductWalletDiscountName(asset, locale) {
|
|
1736
|
+
var _iterator4 = _createForOfIteratorHelper(asset.records),
|
|
1737
|
+
_step4;
|
|
1738
|
+
try {
|
|
1739
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1740
|
+
var record = _step4.value;
|
|
1741
|
+
for (var _i9 = 0, _arr5 = [(_record$discount6 = record.discount) === null || _record$discount6 === void 0 ? void 0 : _record$discount6.title, (_record$discount7 = record.discount) === null || _record$discount7 === void 0 ? void 0 : _record$discount7.name, (_record$discount8 = record.discount) === null || _record$discount8 === void 0 ? void 0 : _record$discount8.message, record.product_name, record.format_title, record.title, record.name, record.message]; _i9 < _arr5.length; _i9++) {
|
|
1742
|
+
var _record$discount6, _record$discount7, _record$discount8;
|
|
1743
|
+
var value = _arr5[_i9];
|
|
1744
|
+
var name = getLocalizedValue(value, locale).trim();
|
|
1745
|
+
if (name) return name;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
} catch (err) {
|
|
1749
|
+
_iterator4.e(err);
|
|
1750
|
+
} finally {
|
|
1751
|
+
_iterator4.f();
|
|
1752
|
+
}
|
|
1753
|
+
return asset.codes[0] || label(locale, 'giftCard');
|
|
1754
|
+
}
|
|
1755
|
+
function getProductWalletDiscountTime(asset) {
|
|
1756
|
+
for (var _i10 = 0, _arr6 = ['updated_at', 'created_at', 'collection_time']; _i10 < _arr6.length; _i10++) {
|
|
1757
|
+
var field = _arr6[_i10];
|
|
1758
|
+
var _iterator5 = _createForOfIteratorHelper(asset.records),
|
|
1759
|
+
_step5;
|
|
1760
|
+
try {
|
|
1761
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1762
|
+
var _record$discount9;
|
|
1763
|
+
var record = _step5.value;
|
|
1764
|
+
var value = firstPresentValue(record[field], (_record$discount9 = record.discount) === null || _record$discount9 === void 0 ? void 0 : _record$discount9[field]);
|
|
1765
|
+
if (isPresentId(value)) return value;
|
|
1766
|
+
}
|
|
1767
|
+
} catch (err) {
|
|
1768
|
+
_iterator5.e(err);
|
|
1769
|
+
} finally {
|
|
1770
|
+
_iterator5.f();
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
return undefined;
|
|
1774
|
+
}
|
|
1775
|
+
function getProductEntitlementBalance(asset) {
|
|
1776
|
+
var _iterator6 = _createForOfIteratorHelper(asset.records),
|
|
1777
|
+
_step6;
|
|
1778
|
+
try {
|
|
1779
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1780
|
+
var record = _step6.value;
|
|
1781
|
+
var balance = getProductDiscountEntitlementBalance(record);
|
|
1782
|
+
if (balance) return balance;
|
|
1783
|
+
}
|
|
1784
|
+
} catch (err) {
|
|
1785
|
+
_iterator6.e(err);
|
|
1786
|
+
} finally {
|
|
1787
|
+
_iterator6.f();
|
|
1788
|
+
}
|
|
1789
|
+
return null;
|
|
1790
|
+
}
|
|
1791
|
+
function getProductDiscountEntitlementBalance(record) {
|
|
1792
|
+
var _record$metadata, _record$discount10, _record$discount11;
|
|
1793
|
+
return getEntitlementBalance((_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata.balance, record.balance, (_record$discount10 = record.discount) === null || _record$discount10 === void 0 || (_record$discount10 = _record$discount10.metadata) === null || _record$discount10 === void 0 ? void 0 : _record$discount10.balance, (_record$discount11 = record.discount) === null || _record$discount11 === void 0 ? void 0 : _record$discount11.balance);
|
|
1794
|
+
}
|
|
1795
|
+
function getEntitlementBalance() {
|
|
1796
|
+
for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1797
|
+
values[_key3] = arguments[_key3];
|
|
1798
|
+
}
|
|
1799
|
+
for (var _i11 = 0, _values2 = values; _i11 < _values2.length; _i11++) {
|
|
1800
|
+
var value = _values2[_i11];
|
|
1801
|
+
if (!isNumericAmount(value)) continue;
|
|
1802
|
+
var balance = new Decimal(value);
|
|
1803
|
+
if (balance.isFinite() && balance.isInteger() && balance.gte(0)) {
|
|
1804
|
+
return balance;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return null;
|
|
1808
|
+
}
|
|
1809
|
+
function formatEntitlementUses(value, locale) {
|
|
1810
|
+
var count = value.toFixed(0);
|
|
1811
|
+
switch (normalizeLocaleKey(locale)) {
|
|
1812
|
+
case 'zh_CN':
|
|
1813
|
+
case 'zh_HK':
|
|
1814
|
+
return "".concat(count, "\u6B21");
|
|
1815
|
+
case 'ja':
|
|
1816
|
+
return "".concat(count, "\u56DE");
|
|
1817
|
+
case 'pt':
|
|
1818
|
+
return "".concat(count, " ").concat(value.eq(1) ? 'utilização' : 'utilizações');
|
|
1819
|
+
default:
|
|
1820
|
+
return "".concat(count, " ").concat(value.eq(1) ? 'use' : 'uses');
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
function getProductWalletDiscountPercent(asset) {
|
|
1824
|
+
if (asset.type !== 'discount_card' && asset.type !== 'product_discount_card') return null;
|
|
1825
|
+
var _iterator7 = _createForOfIteratorHelper(asset.records),
|
|
1826
|
+
_step7;
|
|
1827
|
+
try {
|
|
1828
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1829
|
+
var _record$metadata2, _record$discount12, _record$discount13, _record$discount14;
|
|
1830
|
+
var record = _step7.value;
|
|
1831
|
+
var discountType = stringify(firstPresentValue(record.discount_card_type, (_record$metadata2 = record.metadata) === null || _record$metadata2 === void 0 ? void 0 : _record$metadata2.discount_card_type, (_record$discount12 = record.discount) === null || _record$discount12 === void 0 ? void 0 : _record$discount12.discount_card_type, (_record$discount13 = record.discount) === null || _record$discount13 === void 0 || (_record$discount13 = _record$discount13.metadata) === null || _record$discount13 === void 0 ? void 0 : _record$discount13.discount_card_type)).trim().toLowerCase();
|
|
1832
|
+
if (discountType && discountType !== 'percent' && discountType !== 'percentage') continue;
|
|
1833
|
+
var candidates = [record.percent, (_record$discount14 = record.discount) === null || _record$discount14 === void 0 ? void 0 : _record$discount14.percent];
|
|
1834
|
+
if (discountType === 'percent' || discountType === 'percentage') {
|
|
1835
|
+
var _record$discount15;
|
|
1836
|
+
candidates.push(record.par_value, (_record$discount15 = record.discount) === null || _record$discount15 === void 0 ? void 0 : _record$discount15.par_value);
|
|
1837
|
+
}
|
|
1838
|
+
for (var _i12 = 0, _candidates = candidates; _i12 < _candidates.length; _i12++) {
|
|
1839
|
+
var value = _candidates[_i12];
|
|
1840
|
+
if (!isNumericAmount(value)) continue;
|
|
1841
|
+
var percent = new Decimal(value);
|
|
1842
|
+
if (percent.isFinite() && percent.gt(0) && percent.lte(100)) {
|
|
1843
|
+
return percent;
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
} catch (err) {
|
|
1848
|
+
_iterator7.e(err);
|
|
1849
|
+
} finally {
|
|
1850
|
+
_iterator7.f();
|
|
1851
|
+
}
|
|
1852
|
+
return null;
|
|
1853
|
+
}
|
|
1854
|
+
function getProductWalletMoneyBalance(asset) {
|
|
1855
|
+
var _iterator8 = _createForOfIteratorHelper(asset.records),
|
|
1856
|
+
_step8;
|
|
1857
|
+
try {
|
|
1858
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1859
|
+
var record = _step8.value;
|
|
1860
|
+
for (var _i13 = 0, _arr7 = [(_record$metadata3 = record.metadata) === null || _record$metadata3 === void 0 ? void 0 : _record$metadata3.balance, record.balance, (_record$discount16 = record.discount) === null || _record$discount16 === void 0 || (_record$discount16 = _record$discount16.metadata) === null || _record$discount16 === void 0 ? void 0 : _record$discount16.balance, (_record$discount17 = record.discount) === null || _record$discount17 === void 0 ? void 0 : _record$discount17.balance]; _i13 < _arr7.length; _i13++) {
|
|
1861
|
+
var _record$metadata3, _record$discount16, _record$discount17;
|
|
1862
|
+
var value = _arr7[_i13];
|
|
1863
|
+
if (!isNumericAmount(value)) continue;
|
|
1864
|
+
return Decimal.max(new Decimal(value), 0);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
} catch (err) {
|
|
1868
|
+
_iterator8.e(err);
|
|
1869
|
+
} finally {
|
|
1870
|
+
_iterator8.f();
|
|
1871
|
+
}
|
|
1872
|
+
var _iterator9 = _createForOfIteratorHelper(asset.records),
|
|
1873
|
+
_step9;
|
|
1874
|
+
try {
|
|
1875
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
1876
|
+
var _record$discount18, _record$discount19;
|
|
1877
|
+
var _record = _step9.value;
|
|
1878
|
+
var parValue = firstPresentValue(_record.par_value, (_record$discount18 = _record.discount) === null || _record$discount18 === void 0 ? void 0 : _record$discount18.par_value);
|
|
1879
|
+
var usedParValue = firstPresentValue(_record.used_par_value, (_record$discount19 = _record.discount) === null || _record$discount19 === void 0 ? void 0 : _record$discount19.used_par_value);
|
|
1880
|
+
if (!isNumericAmount(parValue) || !isNumericAmount(usedParValue)) continue;
|
|
1881
|
+
return Decimal.max(new Decimal(parValue).minus(new Decimal(usedParValue)), 0);
|
|
1882
|
+
}
|
|
1883
|
+
} catch (err) {
|
|
1884
|
+
_iterator9.e(err);
|
|
1885
|
+
} finally {
|
|
1886
|
+
_iterator9.f();
|
|
1887
|
+
}
|
|
1888
|
+
return null;
|
|
1889
|
+
}
|
|
1890
|
+
function buildPointCardSnapshotAssets(params) {
|
|
1891
|
+
var _params$order$order_m;
|
|
1892
|
+
var snapshots = (_params$order$order_m = params.order.order_meta_list) === null || _params$order$order_m === void 0 ? void 0 : _params$order$order_m.point_cards_snapshot;
|
|
1893
|
+
if (!Array.isArray(snapshots)) return [];
|
|
1894
|
+
var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1895
|
+
return snapshots.flatMap(function (snapshot) {
|
|
1896
|
+
if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
|
|
1897
|
+
var pointCard = snapshot;
|
|
1898
|
+
if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
|
|
1899
|
+
var assetId = normalizeWalletPassId(pointCard.id);
|
|
1900
|
+
if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
|
|
1901
|
+
id: assetId,
|
|
1902
|
+
codes: []
|
|
1903
|
+
})) return [];
|
|
1904
|
+
var rows = [{
|
|
1905
|
+
item: appendMaskedCardCode(stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'), pointCard.code),
|
|
1906
|
+
value: ''
|
|
1907
|
+
}];
|
|
1908
|
+
var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
|
|
1909
|
+
if (remainingPoints) {
|
|
1910
|
+
rows.push({
|
|
1911
|
+
item: label(params.locale, 'remainingPoints'),
|
|
1912
|
+
value: trimDecimal(remainingPoints)
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
if (isPresentId(snapshotTime)) {
|
|
1916
|
+
rows.push({
|
|
1917
|
+
item: formatDateTime(snapshotTime, params.locale),
|
|
1918
|
+
value: ''
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
return [rows];
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
function collectVirtualCurrencySnapshots(order) {
|
|
1925
|
+
var _order$order_meta_lis;
|
|
1926
|
+
var items = [];
|
|
1927
|
+
var byId = new Map();
|
|
1928
|
+
var snapshots = (_order$order_meta_lis = order.order_meta_list) === null || _order$order_meta_lis === void 0 ? void 0 : _order$order_meta_lis.virtual_currency_snapshot;
|
|
1929
|
+
if (!Array.isArray(snapshots)) return {
|
|
1930
|
+
items: items,
|
|
1931
|
+
byId: byId
|
|
1932
|
+
};
|
|
1933
|
+
snapshots.forEach(function (snapshot) {
|
|
1934
|
+
if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return;
|
|
1935
|
+
var virtualCurrency = snapshot;
|
|
1936
|
+
if (stringify(virtualCurrency.tag).trim().toLowerCase() !== 'virtual_currency') return;
|
|
1937
|
+
var id = normalizeWalletPassId(virtualCurrency.id);
|
|
1938
|
+
if (!id || byId.has(id)) return;
|
|
1939
|
+
byId.set(id, virtualCurrency);
|
|
1940
|
+
items.push(virtualCurrency);
|
|
1941
|
+
});
|
|
1942
|
+
return {
|
|
1943
|
+
items: items,
|
|
1944
|
+
byId: byId
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
|
|
1948
|
+
var fundRecord = getFundRecord(payment);
|
|
1949
|
+
for (var _i14 = 0, _arr8 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i14 < _arr8.length; _i14++) {
|
|
1950
|
+
var value = _arr8[_i14];
|
|
1951
|
+
var id = normalizeWalletPassId(value);
|
|
1952
|
+
if (!id) continue;
|
|
1953
|
+
var snapshot = snapshotsById.get(id);
|
|
1954
|
+
if (snapshot) return snapshot;
|
|
1955
|
+
}
|
|
1956
|
+
return undefined;
|
|
1957
|
+
}
|
|
1958
|
+
function buildVirtualCurrencySnapshotAssets(params) {
|
|
1959
|
+
var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1960
|
+
return params.snapshots.flatMap(function (virtualCurrency) {
|
|
1961
|
+
var assetId = normalizeWalletPassId(virtualCurrency.id);
|
|
1962
|
+
if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
|
|
1963
|
+
id: assetId,
|
|
1964
|
+
codes: []
|
|
1965
|
+
})) return [];
|
|
1966
|
+
var rows = [{
|
|
1967
|
+
item: stringify(virtualCurrency.product_name).trim(),
|
|
1968
|
+
value: ''
|
|
1969
|
+
}];
|
|
1970
|
+
var balance = getVirtualCurrencySnapshotBalance(virtualCurrency);
|
|
1971
|
+
if (balance) {
|
|
1972
|
+
rows.push({
|
|
1973
|
+
item: label(params.locale, 'balance'),
|
|
1974
|
+
value: formatVirtualCurrencyBalance(balance, getVirtualCurrencySnapshotUnit(virtualCurrency, params.locale))
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
if (isPresentId(snapshotTime)) {
|
|
1978
|
+
rows.push({
|
|
1979
|
+
item: formatDateTime(snapshotTime, params.locale),
|
|
1980
|
+
value: ''
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
return [rows];
|
|
1984
|
+
});
|
|
1985
|
+
}
|
|
1986
|
+
function getVirtualCurrencySnapshotBalance(snapshot) {
|
|
1987
|
+
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
1988
|
+
return null;
|
|
1989
|
+
}
|
|
1990
|
+
return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
|
|
1991
|
+
}
|
|
1992
|
+
function getVirtualCurrencySnapshotUnit(snapshot, locale) {
|
|
1993
|
+
return getNonEmptyLocalizedValue(snapshot.name, locale);
|
|
1994
|
+
}
|
|
1995
|
+
function getNonEmptyLocalizedValue(value, locale) {
|
|
1996
|
+
if (value === undefined || value === null) return '';
|
|
1997
|
+
if (_typeof(value) !== 'object' || Array.isArray(value)) return stringify(value).trim();
|
|
1998
|
+
var dashedLocale = locale.replace('_', '-');
|
|
1999
|
+
var underscoredLocale = locale.replace('-', '_');
|
|
2000
|
+
for (var _i15 = 0, _arr9 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i15 < _arr9.length; _i15++) {
|
|
2001
|
+
var candidate = _arr9[_i15];
|
|
2002
|
+
var text = stringify(candidate).trim();
|
|
2003
|
+
if (text) return text;
|
|
2004
|
+
}
|
|
2005
|
+
return '';
|
|
2006
|
+
}
|
|
2007
|
+
function formatVirtualCurrencyBalance(value, unit) {
|
|
2008
|
+
var amount = trimDecimal(value);
|
|
2009
|
+
var normalizedUnit = unit.trim();
|
|
2010
|
+
return normalizedUnit ? "".concat(amount, " ").concat(normalizedUnit) : amount;
|
|
2011
|
+
}
|
|
2012
|
+
function normalizeWalletPassId(value) {
|
|
2013
|
+
if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
|
|
2014
|
+
if (typeof value !== 'string') return null;
|
|
2015
|
+
return value.trim() || null;
|
|
2016
|
+
}
|
|
2017
|
+
function firstNormalizedWalletAssetId() {
|
|
2018
|
+
for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
2019
|
+
values[_key4] = arguments[_key4];
|
|
2020
|
+
}
|
|
2021
|
+
for (var _i16 = 0, _values3 = values; _i16 < _values3.length; _i16++) {
|
|
2022
|
+
var value = _values3[_i16];
|
|
2023
|
+
var id = normalizeWalletPassId(value);
|
|
2024
|
+
if (id) return id;
|
|
2025
|
+
}
|
|
2026
|
+
return null;
|
|
2027
|
+
}
|
|
2028
|
+
function normalizeWalletAssetCodes() {
|
|
2029
|
+
for (var _len5 = arguments.length, values = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
2030
|
+
values[_key5] = arguments[_key5];
|
|
2031
|
+
}
|
|
2032
|
+
return Array.from(new Set(values.map(function (value) {
|
|
2033
|
+
return normalizeWalletPassId(value);
|
|
2034
|
+
}).filter(function (value) {
|
|
2035
|
+
return !!value;
|
|
2036
|
+
})));
|
|
2037
|
+
}
|
|
2038
|
+
function registerWalletAssetIdentity(identities, candidate) {
|
|
2039
|
+
if (!candidate.id && !candidate.codes.length) return;
|
|
2040
|
+
var existing = identities.find(function (identity) {
|
|
2041
|
+
return isSameWalletAssetIdentity(identity, candidate);
|
|
2042
|
+
});
|
|
2043
|
+
if (existing) {
|
|
2044
|
+
mergeWalletAssetIdentity(existing, candidate);
|
|
2045
|
+
return;
|
|
2046
|
+
}
|
|
2047
|
+
identities.push({
|
|
2048
|
+
id: candidate.id,
|
|
2049
|
+
codes: _toConsumableArray(candidate.codes)
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
function claimWalletAssetIdentity(identities, candidate) {
|
|
2053
|
+
if (!candidate.id && !candidate.codes.length) return true;
|
|
2054
|
+
var existing = identities.find(function (identity) {
|
|
2055
|
+
return isSameWalletAssetIdentity(identity, candidate);
|
|
2056
|
+
});
|
|
2057
|
+
if (existing) {
|
|
2058
|
+
mergeWalletAssetIdentity(existing, candidate);
|
|
2059
|
+
return false;
|
|
2060
|
+
}
|
|
2061
|
+
identities.push({
|
|
2062
|
+
id: candidate.id,
|
|
2063
|
+
codes: _toConsumableArray(candidate.codes)
|
|
2064
|
+
});
|
|
2065
|
+
return true;
|
|
2066
|
+
}
|
|
2067
|
+
function isSameWalletAssetIdentity(left, right) {
|
|
2068
|
+
if (left.id && right.id) return left.id === right.id;
|
|
2069
|
+
return left.codes.some(function (code) {
|
|
2070
|
+
return right.codes.includes(code);
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
function mergeWalletAssetIdentity(target, source) {
|
|
2074
|
+
if (!target.id && source.id) target.id = source.id;
|
|
2075
|
+
target.codes = Array.from(new Set([].concat(_toConsumableArray(target.codes), _toConsumableArray(source.codes))));
|
|
2076
|
+
}
|
|
2077
|
+
function getPointCardSnapshotRemainingPoints(snapshot) {
|
|
2078
|
+
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
2079
|
+
return null;
|
|
2080
|
+
}
|
|
2081
|
+
return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
|
|
1134
2082
|
}
|
|
1135
2083
|
function buildVoucherAssets(params) {
|
|
1136
|
-
var
|
|
1137
|
-
return normalizeArray(params.order.vouchers).flatMap(function (voucher
|
|
2084
|
+
var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
2085
|
+
return normalizeArray(params.order.vouchers).flatMap(function (voucher) {
|
|
1138
2086
|
if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
|
|
1139
|
-
|
|
1140
|
-
if (seenVoucherKeys.has(voucherKey)) return [];
|
|
1141
|
-
seenVoucherKeys.add(voucherKey);
|
|
2087
|
+
if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
|
|
1142
2088
|
var name = getVoucherAssetName(voucher, params.locale);
|
|
2089
|
+
var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
|
|
2090
|
+
var timeRow = isPresentId(assetTime) ? {
|
|
2091
|
+
item: formatDateTime(assetTime, params.locale),
|
|
2092
|
+
value: ''
|
|
2093
|
+
} : null;
|
|
2094
|
+
if (isEntitlementVoucher(voucher)) {
|
|
2095
|
+
var _voucher$metadata;
|
|
2096
|
+
var remaining = getEntitlementBalance((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.balance, voucher.balance);
|
|
2097
|
+
return [[{
|
|
2098
|
+
item: name,
|
|
2099
|
+
value: ''
|
|
2100
|
+
}].concat(_toConsumableArray(remaining ? [{
|
|
2101
|
+
item: label(params.locale, 'entitlementRemaining'),
|
|
2102
|
+
value: formatEntitlementUses(remaining, params.locale)
|
|
2103
|
+
}] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
|
|
2104
|
+
}
|
|
2105
|
+
if (isTicketVoucher(voucher)) {
|
|
2106
|
+
var validity = getVoucherValidity(voucher, params.locale);
|
|
2107
|
+
return [[{
|
|
2108
|
+
item: name,
|
|
2109
|
+
value: ''
|
|
2110
|
+
}].concat(_toConsumableArray(validity ? [{
|
|
2111
|
+
item: label(params.locale, 'validity'),
|
|
2112
|
+
value: validity
|
|
2113
|
+
}] : []))];
|
|
2114
|
+
}
|
|
1143
2115
|
var percent = getVoucherDiscountPercent(voucher);
|
|
1144
2116
|
if (percent) {
|
|
1145
2117
|
return [[{
|
|
1146
2118
|
item: appendPercentToVoucherName(name, percent),
|
|
1147
2119
|
value: formatVoucherDiscount(percent, params.locale)
|
|
1148
|
-
}]];
|
|
2120
|
+
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1149
2121
|
}
|
|
1150
2122
|
var balance = getVoucherBalance(voucher);
|
|
1151
2123
|
return [[{
|
|
@@ -1154,19 +2126,105 @@ function buildVoucherAssets(params) {
|
|
|
1154
2126
|
}, {
|
|
1155
2127
|
item: label(params.locale, 'balance'),
|
|
1156
2128
|
value: formatMoney(balance, params.currencySymbol)
|
|
1157
|
-
}]];
|
|
2129
|
+
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1158
2130
|
});
|
|
1159
2131
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
return
|
|
2132
|
+
var TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
|
|
2133
|
+
function isEntitlementVoucher(voucher) {
|
|
2134
|
+
return [voucher.tag, voucher.type].some(function (value) {
|
|
2135
|
+
return stringify(value).trim().toLowerCase() === 'entitlement_pass';
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
2138
|
+
function isTicketVoucher(voucher) {
|
|
2139
|
+
return TICKET_VOUCHER_TAGS.has(stringify(voucher.tag).trim().toLowerCase());
|
|
2140
|
+
}
|
|
2141
|
+
function getVoucherValidity(voucher, locale) {
|
|
2142
|
+
var _voucher$metadata2, _voucher$metadata3, _voucher$metadata4, _voucher$metadata5, _voucher$metadata6, _voucher$metadata7, _voucher$metadata8, _voucher$metadata9, _voucher$metadata10, _voucher$metadata11, _voucher$start_time, _voucher$metadata12, _voucher$end_time, _voucher$metadata13;
|
|
2143
|
+
var availableTime = firstPresentValue(voucher.available_time, voucher.avaliable_time, (_voucher$metadata2 = voucher.metadata) === null || _voucher$metadata2 === void 0 ? void 0 : _voucher$metadata2.available_time, (_voucher$metadata3 = voucher.metadata) === null || _voucher$metadata3 === void 0 ? void 0 : _voucher$metadata3.avaliable_time);
|
|
2144
|
+
var availableTimeText = formatVoucherAvailableTime(availableTime, locale);
|
|
2145
|
+
if (availableTimeText) return availableTimeText;
|
|
2146
|
+
var startDate = firstPresentValue(voucher.valid_from, voucher.start_at, voucher.start_date_time, voucher.start_date, (_voucher$metadata4 = voucher.metadata) === null || _voucher$metadata4 === void 0 ? void 0 : _voucher$metadata4.valid_from, (_voucher$metadata5 = voucher.metadata) === null || _voucher$metadata5 === void 0 ? void 0 : _voucher$metadata5.start_at, (_voucher$metadata6 = voucher.metadata) === null || _voucher$metadata6 === void 0 ? void 0 : _voucher$metadata6.start_date);
|
|
2147
|
+
var endDate = firstPresentValue(voucher.valid_to, voucher.end_at, voucher.end_date_time, voucher.expire_date, voucher.end_date, voucher.expire_time, (_voucher$metadata7 = voucher.metadata) === null || _voucher$metadata7 === void 0 ? void 0 : _voucher$metadata7.valid_to, (_voucher$metadata8 = voucher.metadata) === null || _voucher$metadata8 === void 0 ? void 0 : _voucher$metadata8.end_at, (_voucher$metadata9 = voucher.metadata) === null || _voucher$metadata9 === void 0 ? void 0 : _voucher$metadata9.expire_date, (_voucher$metadata10 = voucher.metadata) === null || _voucher$metadata10 === void 0 ? void 0 : _voucher$metadata10.end_date, (_voucher$metadata11 = voucher.metadata) === null || _voucher$metadata11 === void 0 ? void 0 : _voucher$metadata11.expire_time);
|
|
2148
|
+
return formatVoucherValidityRange(startDate, endDate, locale, {
|
|
2149
|
+
startTime: (_voucher$start_time = voucher.start_time) !== null && _voucher$start_time !== void 0 ? _voucher$start_time : (_voucher$metadata12 = voucher.metadata) === null || _voucher$metadata12 === void 0 ? void 0 : _voucher$metadata12.start_time,
|
|
2150
|
+
endTime: (_voucher$end_time = voucher.end_time) !== null && _voucher$end_time !== void 0 ? _voucher$end_time : (_voucher$metadata13 = voucher.metadata) === null || _voucher$metadata13 === void 0 ? void 0 : _voucher$metadata13.end_time
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
function formatVoucherAvailableTime(value, locale) {
|
|
2154
|
+
if (!isPresentId(value)) return '';
|
|
2155
|
+
if (Array.isArray(value)) {
|
|
2156
|
+
return value.map(function (item) {
|
|
2157
|
+
return formatVoucherAvailableTime(item, locale);
|
|
2158
|
+
}).filter(Boolean).join(', ');
|
|
2159
|
+
}
|
|
2160
|
+
if (_typeof(value) !== 'object') return stringify(value).trim();
|
|
2161
|
+
var start = firstPresentValue(value.start, value.start_at, value.start_date_time, value.start_date);
|
|
2162
|
+
var end = firstPresentValue(value.end, value.end_at, value.end_date_time, value.expire_time, value.expire_date, value.end_date);
|
|
2163
|
+
if (isPresentId(start) || isPresentId(end)) {
|
|
2164
|
+
return formatVoucherValidityRange(start, end, locale, {
|
|
2165
|
+
startTime: value.start_time,
|
|
2166
|
+
endTime: value.end_time
|
|
2167
|
+
});
|
|
2168
|
+
}
|
|
2169
|
+
return getLocalizedValue(value, locale).trim();
|
|
2170
|
+
}
|
|
2171
|
+
function formatVoucherValidityRange(startValue, endValue, locale) {
|
|
2172
|
+
var times = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2173
|
+
var start = combineVoucherDateAndTime(startValue, times.startTime);
|
|
2174
|
+
var end = combineVoucherDateAndTime(endValue, times.endTime);
|
|
2175
|
+
var startPart = formatVoucherValidityDate(start, locale);
|
|
2176
|
+
var endPart = formatVoucherValidityDate(end, locale);
|
|
2177
|
+
if (startPart.text && endPart.text) {
|
|
2178
|
+
var parsedStart = dayjs(start);
|
|
2179
|
+
var parsedEnd = dayjs(end);
|
|
2180
|
+
var sameDay = parsedStart.isValid() && parsedEnd.isValid() && parsedStart.isSame(parsedEnd, 'day');
|
|
2181
|
+
if (sameDay && startPart.time && endPart.time) {
|
|
2182
|
+
return "".concat(startPart.time, " - ").concat(endPart.time, " ").concat(startPart.date);
|
|
2183
|
+
}
|
|
2184
|
+
return "".concat(startPart.text, " - ").concat(endPart.text);
|
|
2185
|
+
}
|
|
2186
|
+
return startPart.text || endPart.text;
|
|
2187
|
+
}
|
|
2188
|
+
function combineVoucherDateAndTime(dateValue, timeValue) {
|
|
2189
|
+
if (!isPresentId(dateValue) || !isPresentId(timeValue)) return dateValue;
|
|
2190
|
+
var dateText = stringify(dateValue).trim();
|
|
2191
|
+
if (/\d{1,2}:\d{2}/.test(dateText)) return dateValue;
|
|
2192
|
+
return "".concat(dateText, " ").concat(stringify(timeValue).trim());
|
|
2193
|
+
}
|
|
2194
|
+
function formatVoucherValidityDate(value, locale) {
|
|
2195
|
+
if (!isPresentId(value)) return {
|
|
2196
|
+
date: '',
|
|
2197
|
+
time: '',
|
|
2198
|
+
text: ''
|
|
2199
|
+
};
|
|
2200
|
+
var source = stringify(value).trim();
|
|
2201
|
+
var parsed = dayjs(source);
|
|
2202
|
+
if (!parsed.isValid()) return {
|
|
2203
|
+
date: '',
|
|
2204
|
+
time: '',
|
|
2205
|
+
text: source
|
|
2206
|
+
};
|
|
2207
|
+
var hasTime = /\d{1,2}:\d{2}/.test(source);
|
|
2208
|
+
var date = parsed.format(locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD');
|
|
2209
|
+
var time = hasTime ? parsed.format(/\d{1,2}:\d{2}:\d{2}/.test(source) ? 'HH:mm:ss' : 'HH:mm') : '';
|
|
2210
|
+
return {
|
|
2211
|
+
date: date,
|
|
2212
|
+
time: time,
|
|
2213
|
+
text: time ? "".concat(time, " ").concat(date) : date
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
function getVoucherAssetIdentity(voucher) {
|
|
2217
|
+
return {
|
|
2218
|
+
id: firstNormalizedWalletAssetId(voucher.voucher_id, voucher.id),
|
|
2219
|
+
codes: normalizeWalletAssetCodes(voucher.code, voucher.encoded)
|
|
2220
|
+
};
|
|
1163
2221
|
}
|
|
1164
2222
|
function getVoucherAssetName(voucher, locale) {
|
|
1165
2223
|
return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
|
|
1166
2224
|
}
|
|
1167
2225
|
function getVoucherDiscountPercent(voucher) {
|
|
1168
|
-
var _voucher$
|
|
1169
|
-
var discountType = stringify(((_voucher$
|
|
2226
|
+
var _voucher$metadata14;
|
|
2227
|
+
var discountType = stringify(((_voucher$metadata14 = voucher.metadata) === null || _voucher$metadata14 === void 0 ? void 0 : _voucher$metadata14.discount_card_type) || voucher.discount_card_type).toLowerCase();
|
|
1170
2228
|
if (discountType !== 'percent' && discountType !== 'percentage') return null;
|
|
1171
2229
|
var percent = new Decimal(toMoneyNumber(voucher.par_value));
|
|
1172
2230
|
if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
|
|
@@ -1186,6 +2244,12 @@ function formatVoucherDiscount(percent, locale) {
|
|
|
1186
2244
|
return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
|
|
1187
2245
|
}
|
|
1188
2246
|
function getVoucherBalance(voucher) {
|
|
2247
|
+
for (var _i17 = 0, _arr10 = [(_voucher$metadata15 = voucher.metadata) === null || _voucher$metadata15 === void 0 ? void 0 : _voucher$metadata15.balance, voucher.balance]; _i17 < _arr10.length; _i17++) {
|
|
2248
|
+
var _voucher$metadata15;
|
|
2249
|
+
var value = _arr10[_i17];
|
|
2250
|
+
if (!isNumericAmount(value)) continue;
|
|
2251
|
+
return Decimal.max(new Decimal(value), 0);
|
|
2252
|
+
}
|
|
1189
2253
|
var parValue = new Decimal(toMoneyNumber(voucher.par_value));
|
|
1190
2254
|
var usedParValue = new Decimal(toMoneyNumber(voucher.used_par_value));
|
|
1191
2255
|
return Decimal.max(parValue.minus(usedParValue), 0);
|
|
@@ -1194,11 +2258,14 @@ function buildPaymentItems(params) {
|
|
|
1194
2258
|
var payment = params.payment,
|
|
1195
2259
|
locale = params.locale,
|
|
1196
2260
|
currencySymbol = params.currencySymbol,
|
|
1197
|
-
includeFundRecordBalance = params.includeFundRecordBalance
|
|
2261
|
+
includeFundRecordBalance = params.includeFundRecordBalance,
|
|
2262
|
+
includeFundRecordUsage = params.includeFundRecordUsage,
|
|
2263
|
+
includePaymentAmount = params.includePaymentAmount,
|
|
2264
|
+
virtualCurrencyUnit = params.virtualCurrencyUnit;
|
|
1198
2265
|
var serviceFee = getPaymentServiceFee(payment);
|
|
1199
2266
|
var items = [{
|
|
1200
2267
|
item: paymentMethodName(payment, locale),
|
|
1201
|
-
value: formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol)
|
|
2268
|
+
value: includePaymentAmount ? formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol) : ''
|
|
1202
2269
|
}];
|
|
1203
2270
|
items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
|
|
1204
2271
|
payment: payment,
|
|
@@ -1218,11 +2285,13 @@ function buildPaymentItems(params) {
|
|
|
1218
2285
|
fundRecord: fundRecord,
|
|
1219
2286
|
locale: locale,
|
|
1220
2287
|
currencySymbol: currencySymbol,
|
|
1221
|
-
includeBalance: includeFundRecordBalance
|
|
2288
|
+
includeBalance: includeFundRecordBalance,
|
|
2289
|
+
includeUsage: includeFundRecordUsage,
|
|
2290
|
+
virtualCurrencyUnit: virtualCurrencyUnit
|
|
1222
2291
|
})));
|
|
1223
2292
|
} else {
|
|
1224
|
-
var
|
|
1225
|
-
var remainingAmount = (
|
|
2293
|
+
var _ref61, _payment$remaining_am, _payment$metadata;
|
|
2294
|
+
var remainingAmount = (_ref61 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref61 !== void 0 ? _ref61 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
|
|
1226
2295
|
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
1227
2296
|
items.push({
|
|
1228
2297
|
item: label(locale, 'remainingAmount'),
|
|
@@ -1282,16 +2351,20 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1282
2351
|
fundRecord = params.fundRecord,
|
|
1283
2352
|
locale = params.locale,
|
|
1284
2353
|
currencySymbol = params.currencySymbol,
|
|
1285
|
-
includeBalance = params.includeBalance
|
|
2354
|
+
includeBalance = params.includeBalance,
|
|
2355
|
+
includeUsage = params.includeUsage,
|
|
2356
|
+
virtualCurrencyUnit = params.virtualCurrencyUnit;
|
|
1286
2357
|
var items = [];
|
|
1287
2358
|
var usingBeforeValue = fundRecord.using_before_value;
|
|
1288
2359
|
var usingAfterValue = fundRecord.using_after_value;
|
|
1289
2360
|
if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
|
|
1290
2361
|
var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
2362
|
+
if (includeUsage) {
|
|
2363
|
+
items.push({
|
|
2364
|
+
item: label(locale, 'redeemPoints'),
|
|
2365
|
+
value: trimDecimal(usedPoints)
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
1295
2368
|
if (includeBalance) {
|
|
1296
2369
|
items.push({
|
|
1297
2370
|
item: label(locale, 'remainingPoints'),
|
|
@@ -1301,8 +2374,16 @@ function buildFundRecordPaymentItems(params) {
|
|
|
1301
2374
|
return items;
|
|
1302
2375
|
}
|
|
1303
2376
|
if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
|
|
2377
|
+
if (virtualCurrencyUnit !== undefined) {
|
|
2378
|
+
if (!isNumericAmount(usingAfterValue)) return items;
|
|
2379
|
+
items.push({
|
|
2380
|
+
item: label(locale, 'balance'),
|
|
2381
|
+
value: formatVirtualCurrencyBalance(new Decimal(usingAfterValue), virtualCurrencyUnit)
|
|
2382
|
+
});
|
|
2383
|
+
return items;
|
|
2384
|
+
}
|
|
1304
2385
|
items.push({
|
|
1305
|
-
item: label(locale, '
|
|
2386
|
+
item: label(locale, 'balance'),
|
|
1306
2387
|
value: formatMoney(usingAfterValue, currencySymbol)
|
|
1307
2388
|
});
|
|
1308
2389
|
}
|
|
@@ -1321,9 +2402,14 @@ function isPointCardPayment(payment) {
|
|
|
1321
2402
|
return code === 'POINTCARD' || type === 'point_card';
|
|
1322
2403
|
}
|
|
1323
2404
|
function maskMachineCode(code) {
|
|
1324
|
-
var text = stringify(code);
|
|
1325
|
-
if (text
|
|
1326
|
-
|
|
2405
|
+
var text = stringify(code).trim();
|
|
2406
|
+
if (!text) return '';
|
|
2407
|
+
if (text.length <= 6) return '*'.repeat(text.length);
|
|
2408
|
+
return "".concat(text.slice(0, 2), "****").concat(text.slice(-4));
|
|
2409
|
+
}
|
|
2410
|
+
function appendMaskedCardCode(name, code) {
|
|
2411
|
+
var maskedCode = maskMachineCode(code);
|
|
2412
|
+
return maskedCode ? "".concat(name, "(").concat(maskedCode, ")") : name;
|
|
1327
2413
|
}
|
|
1328
2414
|
function trimDecimal(value) {
|
|
1329
2415
|
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
|
|
@@ -1332,16 +2418,13 @@ function getFundRecordPaymentName(payment, locale) {
|
|
|
1332
2418
|
var fundRecord = getFundRecord(payment);
|
|
1333
2419
|
if (!fundRecord) return '';
|
|
1334
2420
|
var name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
|
|
1335
|
-
|
|
1336
|
-
if (!name && !code) return '';
|
|
1337
|
-
if (!code) return name;
|
|
2421
|
+
if (!name && !maskMachineCode(fundRecord.code)) return '';
|
|
1338
2422
|
var fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
|
|
1339
|
-
return
|
|
2423
|
+
return appendMaskedCardCode(name || fallbackName, fundRecord.code);
|
|
1340
2424
|
}
|
|
1341
2425
|
function appendMachineCodeToName(name, payment) {
|
|
1342
2426
|
var fundRecord = getFundRecord(payment);
|
|
1343
|
-
|
|
1344
|
-
return "".concat(name, "(").concat(maskMachineCode(fundRecord.code), ")");
|
|
2427
|
+
return appendMaskedCardCode(name, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code);
|
|
1345
2428
|
}
|
|
1346
2429
|
function paymentMethodName(payment, locale) {
|
|
1347
2430
|
var fundRecordName = getFundRecordPaymentName(payment, locale);
|
|
@@ -1373,33 +2456,15 @@ function label(locale, key) {
|
|
|
1373
2456
|
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
1374
2457
|
}
|
|
1375
2458
|
function getLocalizedValue(value, locale) {
|
|
1376
|
-
var
|
|
2459
|
+
var _ref62, _ref63, _ref64, _ref65, _ref66, _ref67, _value$locale2;
|
|
1377
2460
|
if (value === undefined || value === null) return '';
|
|
1378
2461
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
1379
2462
|
var dashedLocale = locale.replace('_', '-');
|
|
1380
2463
|
var underscoredLocale = locale.replace('-', '_');
|
|
1381
|
-
return stringify((
|
|
1382
|
-
}
|
|
1383
|
-
function resolveServiceTypeLabelKey(serviceType, order) {
|
|
1384
|
-
var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
1385
|
-
if (['', 'nil', 'none', 'unknown'].includes(normalized)) return null;
|
|
1386
|
-
if (['pickup', 'pick_up', 'self_pickup'].includes(normalized)) return 'pickUp';
|
|
1387
|
-
if (['delivery', 'shipping', 'local_delivery'].includes(normalized)) return 'delivery';
|
|
1388
|
-
if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
|
|
1389
|
-
if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
|
|
1390
|
-
if (['shop_service', 'shop_server'].includes(normalized)) {
|
|
1391
|
-
return resolveShopServiceLabelKey(order);
|
|
1392
|
-
}
|
|
1393
|
-
return null;
|
|
2464
|
+
return stringify((_ref62 = (_ref63 = (_ref64 = (_ref65 = (_ref66 = (_ref67 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref67 !== void 0 ? _ref67 : value[underscoredLocale]) !== null && _ref66 !== void 0 ? _ref66 : value.original) !== null && _ref65 !== void 0 ? _ref65 : value.auto) !== null && _ref64 !== void 0 ? _ref64 : value.default) !== null && _ref63 !== void 0 ? _ref63 : value.en) !== null && _ref62 !== void 0 ? _ref62 : '');
|
|
1394
2465
|
}
|
|
1395
|
-
function
|
|
1396
|
-
|
|
1397
|
-
var rawShopServiceType = firstPresentValue((_order$metadata15 = order.metadata) === null || _order$metadata15 === void 0 || (_order$metadata15 = _order$metadata15.shop_service_type) === null || _order$metadata15 === void 0 ? void 0 : _order$metadata15.server_type, (_order$shop_service_t = order.shop_service_type) === null || _order$shop_service_t === void 0 ? void 0 : _order$shop_service_t.server_type, typeof order.shop_service_type === 'string' ? order.shop_service_type : undefined);
|
|
1398
|
-
if (!isPresentId(rawShopServiceType)) return 'dineIn';
|
|
1399
|
-
var normalized = stringify(rawShopServiceType).trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
1400
|
-
if (['takeaway', 'take_away'].includes(normalized)) return 'takeAway';
|
|
1401
|
-
if (['dine_in', 'dinein'].includes(normalized)) return 'dineIn';
|
|
1402
|
-
return null;
|
|
2466
|
+
function resolveServiceTypeLabelKey(serviceType) {
|
|
2467
|
+
return SERVICE_TYPE_LABEL_KEYS[serviceType] || null;
|
|
1403
2468
|
}
|
|
1404
2469
|
function normalizeBooleanFlag(value) {
|
|
1405
2470
|
if (value === true || value === 1 || stringify(value).trim() === '1') return 1;
|
|
@@ -1420,6 +2485,11 @@ function formatMoney(value, currencySymbol) {
|
|
|
1420
2485
|
var amount = new Decimal(toMoneyNumber(value));
|
|
1421
2486
|
return "".concat(currencySymbol).concat(amount.toFixed(2));
|
|
1422
2487
|
}
|
|
2488
|
+
function formatCalculatedMoney(value, currencySymbol) {
|
|
2489
|
+
var amount = new Decimal(toMoneyNumber(value));
|
|
2490
|
+
var sign = amount.isNegative() ? '-' : '';
|
|
2491
|
+
return "".concat(sign).concat(currencySymbol).concat(amount.abs().toFixed(2));
|
|
2492
|
+
}
|
|
1423
2493
|
function formatNegativeMoney(value, currencySymbol) {
|
|
1424
2494
|
var amount = new Decimal(toMoneyNumber(value)).abs();
|
|
1425
2495
|
return "-".concat(currencySymbol).concat(amount.toFixed(2));
|