@pisell/pisellos 0.10.53 → 0.10.55
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/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/BusinessAvailability/index.d.ts +30 -0
- package/dist/modules/BusinessAvailability/index.js +204 -0
- package/dist/modules/OpenData/index.js +1 -1
- package/dist/modules/OpenData/types.d.ts +2 -0
- package/dist/modules/Order/index.d.ts +5 -2
- package/dist/modules/Order/index.js +320 -247
- package/dist/modules/Order/types.d.ts +8 -0
- package/dist/modules/Payment/index.js +9 -10
- package/dist/plugins/request.d.ts +3 -0
- package/dist/server/utils/small-ticket.d.ts +1 -85
- package/dist/server/utils/small-ticket.js +2 -2576
- package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/dist/shared/payment/loadPaymentMethods.js +66 -0
- package/dist/shared/receipt/small-ticket.d.ts +85 -0
- package/dist/shared/receipt/small-ticket.js +2576 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/dist/shared/sales/loadSalesOrderSnapshot.js +21 -0
- package/dist/solution/BaseSales/index.d.ts +4 -15
- package/dist/solution/BaseSales/index.js +131 -86
- package/dist/solution/BaseSales/types.d.ts +11 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +41 -13
- package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/dist/solution/OrderInvoicePreview/index.js +269 -0
- package/dist/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
- package/dist/solution/UnifiedBookingSales/businessAvailability.js +292 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +11 -0
- package/dist/solution/UnifiedBookingSales/index.js +154 -75
- package/dist/solution/UnifiedBookingSales/types.d.ts +2 -0
- package/dist/solution/index.d.ts +1 -0
- package/dist/solution/index.js +2 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +21 -1
- package/lib/modules/BusinessAvailability/index.d.ts +30 -0
- package/lib/modules/BusinessAvailability/index.js +146 -0
- package/lib/modules/OpenData/index.js +1 -1
- package/lib/modules/OpenData/types.d.ts +2 -0
- package/lib/modules/Order/index.d.ts +5 -2
- package/lib/modules/Order/index.js +67 -13
- package/lib/modules/Order/types.d.ts +8 -0
- package/lib/modules/Payment/index.js +3 -4
- package/lib/plugins/request.d.ts +3 -0
- package/lib/server/utils/small-ticket.d.ts +1 -85
- package/lib/server/utils/small-ticket.js +9 -2335
- package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/lib/shared/payment/loadPaymentMethods.js +40 -0
- package/lib/shared/receipt/small-ticket.d.ts +85 -0
- package/lib/shared/receipt/small-ticket.js +2342 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.d.ts +9 -0
- package/lib/shared/sales/loadSalesOrderSnapshot.js +22 -0
- package/lib/solution/BaseSales/index.d.ts +4 -15
- package/lib/solution/BaseSales/index.js +45 -24
- package/lib/solution/BaseSales/types.d.ts +11 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +37 -4
- package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/lib/solution/OrderInvoicePreview/index.js +194 -0
- package/lib/solution/UnifiedBookingSales/businessAvailability.d.ts +27 -0
- package/lib/solution/UnifiedBookingSales/businessAvailability.js +138 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +11 -0
- package/lib/solution/UnifiedBookingSales/index.js +54 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +2 -0
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +11 -0
- package/package.json +1 -1
|
@@ -1,2576 +1,2 @@
|
|
|
1
|
-
|
|
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."); }
|
|
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; } }
|
|
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; }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
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."); }
|
|
10
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
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); }
|
|
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; }
|
|
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; }
|
|
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
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
19
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
21
|
-
import dayjs from 'dayjs';
|
|
22
|
-
import Decimal from 'decimal.js';
|
|
23
|
-
import { isFulfillmentTimingBooking } from "../../modules/Order/pickupTiming";
|
|
24
|
-
var DEFAULT_LOCALES = ['en', 'zh_CN'];
|
|
25
|
-
var SERVICE_TYPE_LABEL_KEYS = {
|
|
26
|
-
takeaway: 'takeAway',
|
|
27
|
-
pick_up: 'pickUp',
|
|
28
|
-
table_service: 'tableService',
|
|
29
|
-
delivery: 'delivery',
|
|
30
|
-
room_service: 'roomService',
|
|
31
|
-
dine_in: 'dineIn',
|
|
32
|
-
delivery_by_uber: 'deliveryByUber',
|
|
33
|
-
delivery_by_panda: 'deliveryByPanda',
|
|
34
|
-
delivery_by_merchant: 'deliveryByMerchant'
|
|
35
|
-
};
|
|
36
|
-
var LABELS = {
|
|
37
|
-
en: {
|
|
38
|
-
contactName: 'Contact name',
|
|
39
|
-
contactMobile: 'Contact Mobile',
|
|
40
|
-
email: 'email',
|
|
41
|
-
dineIn: 'Dine in',
|
|
42
|
-
takeAway: 'Takeaway',
|
|
43
|
-
delivery: 'Delivery',
|
|
44
|
-
pickUp: 'Pickup',
|
|
45
|
-
tableService: 'Table Service',
|
|
46
|
-
roomService: 'Room Service',
|
|
47
|
-
deliveryByUber: 'Uber Eats Delivery',
|
|
48
|
-
deliveryByPanda: 'HungryPanda Delivery',
|
|
49
|
-
deliveryByMerchant: 'Merchant Delivery',
|
|
50
|
-
shopService: 'Dine-in',
|
|
51
|
-
pickUpTime: 'Pick-up time',
|
|
52
|
-
asap: 'ASAP',
|
|
53
|
-
cash: 'Cash',
|
|
54
|
-
cashReceived: 'Cash received',
|
|
55
|
-
changeDue: 'Change due',
|
|
56
|
-
eftpos: 'Eftpos',
|
|
57
|
-
wallet: 'Wallet',
|
|
58
|
-
giftCard: 'Gift card',
|
|
59
|
-
pointCard: 'Point card',
|
|
60
|
-
balance: 'Balance',
|
|
61
|
-
validity: 'Validity',
|
|
62
|
-
remainingAmount: 'Remaining amount',
|
|
63
|
-
redeemPoints: 'Redeem points',
|
|
64
|
-
remainingPoints: 'Points balance',
|
|
65
|
-
entitlementRemaining: 'Remaining',
|
|
66
|
-
table: 'Table',
|
|
67
|
-
bookingId: 'Booking ID',
|
|
68
|
-
bookingDateTime: 'Date & time',
|
|
69
|
-
bookingResource: 'Resource',
|
|
70
|
-
bookingHolder: 'Holder',
|
|
71
|
-
orderDiscount: 'Order discount',
|
|
72
|
-
manualDiscount: 'Manual discount',
|
|
73
|
-
manualMarkup: 'Manual markup',
|
|
74
|
-
payProcessingFee: 'Pay processing fee',
|
|
75
|
-
surchargeIncluded: 'Surcharge(Included)',
|
|
76
|
-
rounding: 'Rounding',
|
|
77
|
-
gross: 'Gross',
|
|
78
|
-
tare: 'Tare',
|
|
79
|
-
handoverTime: 'Handover time',
|
|
80
|
-
refund: 'Refund'
|
|
81
|
-
},
|
|
82
|
-
zh_CN: {
|
|
83
|
-
contactName: '联系人姓名',
|
|
84
|
-
contactMobile: '联系电话',
|
|
85
|
-
email: '邮箱',
|
|
86
|
-
dineIn: '堂食',
|
|
87
|
-
takeAway: '外带',
|
|
88
|
-
delivery: '配送',
|
|
89
|
-
pickUp: '自取',
|
|
90
|
-
tableService: '送餐到桌',
|
|
91
|
-
roomService: '客房服务',
|
|
92
|
-
deliveryByUber: 'Uber 配送',
|
|
93
|
-
deliveryByPanda: '熊猫外卖配送',
|
|
94
|
-
deliveryByMerchant: '商家配送',
|
|
95
|
-
shopService: '堂食',
|
|
96
|
-
pickUpTime: '取餐时间',
|
|
97
|
-
asap: '尽快',
|
|
98
|
-
cash: '现金支付',
|
|
99
|
-
cashReceived: '收取现金',
|
|
100
|
-
changeDue: '找零',
|
|
101
|
-
eftpos: '刷卡支付',
|
|
102
|
-
wallet: '钱包支付',
|
|
103
|
-
giftCard: '礼品卡',
|
|
104
|
-
pointCard: '积分卡',
|
|
105
|
-
balance: '余额',
|
|
106
|
-
validity: '有效期',
|
|
107
|
-
remainingAmount: '剩余金额',
|
|
108
|
-
redeemPoints: '本次使用积分',
|
|
109
|
-
remainingPoints: '积分余额',
|
|
110
|
-
entitlementRemaining: '剩余次数',
|
|
111
|
-
table: '桌台',
|
|
112
|
-
bookingId: '预约编号',
|
|
113
|
-
bookingDateTime: '日期和时间',
|
|
114
|
-
bookingResource: '资源',
|
|
115
|
-
bookingHolder: '预约人',
|
|
116
|
-
orderDiscount: '整单折扣',
|
|
117
|
-
manualDiscount: '手动折扣',
|
|
118
|
-
manualMarkup: '手动加价',
|
|
119
|
-
payProcessingFee: '支付手续费',
|
|
120
|
-
surchargeIncluded: '手续费(已含)',
|
|
121
|
-
rounding: '抹零',
|
|
122
|
-
gross: '重量',
|
|
123
|
-
tare: '去皮',
|
|
124
|
-
handoverTime: '交付时间',
|
|
125
|
-
refund: '退款'
|
|
126
|
-
},
|
|
127
|
-
zh_HK: {
|
|
128
|
-
contactName: '聯絡人姓名',
|
|
129
|
-
contactMobile: '聯絡電話',
|
|
130
|
-
email: '電郵',
|
|
131
|
-
dineIn: '堂食',
|
|
132
|
-
takeAway: '外帶',
|
|
133
|
-
delivery: '配送',
|
|
134
|
-
pickUp: '自取',
|
|
135
|
-
tableService: '送餐到桌',
|
|
136
|
-
roomService: '客房服務',
|
|
137
|
-
deliveryByUber: 'Uber 配送',
|
|
138
|
-
deliveryByPanda: '熊貓外賣配送',
|
|
139
|
-
deliveryByMerchant: '商家配送',
|
|
140
|
-
shopService: '堂食',
|
|
141
|
-
pickUpTime: '取餐時間',
|
|
142
|
-
asap: '盡快',
|
|
143
|
-
cash: '現金支付',
|
|
144
|
-
cashReceived: '收取現金',
|
|
145
|
-
changeDue: '找零',
|
|
146
|
-
eftpos: '刷卡支付',
|
|
147
|
-
wallet: '錢包支付',
|
|
148
|
-
giftCard: '禮品卡',
|
|
149
|
-
pointCard: '積分卡',
|
|
150
|
-
balance: '餘額',
|
|
151
|
-
validity: '有效期',
|
|
152
|
-
remainingAmount: '剩餘金額',
|
|
153
|
-
redeemPoints: '本次使用積分',
|
|
154
|
-
remainingPoints: '積分餘額',
|
|
155
|
-
entitlementRemaining: '剩餘次數',
|
|
156
|
-
table: '桌台',
|
|
157
|
-
bookingId: '預約編號',
|
|
158
|
-
bookingDateTime: '日期和時間',
|
|
159
|
-
bookingResource: '資源',
|
|
160
|
-
bookingHolder: '預約人',
|
|
161
|
-
orderDiscount: '整單折扣',
|
|
162
|
-
manualDiscount: '手動折扣',
|
|
163
|
-
manualMarkup: '手動加價',
|
|
164
|
-
payProcessingFee: '支付手續費',
|
|
165
|
-
surchargeIncluded: '手續費(已含)',
|
|
166
|
-
rounding: '抹零',
|
|
167
|
-
gross: '重量',
|
|
168
|
-
tare: '去皮',
|
|
169
|
-
handoverTime: '交付時間',
|
|
170
|
-
refund: '退款'
|
|
171
|
-
},
|
|
172
|
-
ja: {
|
|
173
|
-
contactName: '連絡先名',
|
|
174
|
-
contactMobile: '連絡先電話',
|
|
175
|
-
email: 'メール',
|
|
176
|
-
dineIn: '店内飲食',
|
|
177
|
-
takeAway: 'テイクアウト',
|
|
178
|
-
delivery: '配達',
|
|
179
|
-
pickUp: '受け取り',
|
|
180
|
-
tableService: 'テーブルサービス',
|
|
181
|
-
roomService: 'ルームサービス',
|
|
182
|
-
deliveryByUber: 'Uber Eats 配達',
|
|
183
|
-
deliveryByPanda: 'HungryPanda 配達',
|
|
184
|
-
deliveryByMerchant: '店舗による配達',
|
|
185
|
-
shopService: '店内飲食',
|
|
186
|
-
pickUpTime: '受取時間',
|
|
187
|
-
asap: 'できるだけ早く',
|
|
188
|
-
cash: '現金',
|
|
189
|
-
eftpos: 'カード',
|
|
190
|
-
wallet: 'ウォレット',
|
|
191
|
-
giftCard: 'ギフトカード',
|
|
192
|
-
pointCard: 'ポイントカード',
|
|
193
|
-
balance: '残高',
|
|
194
|
-
validity: '有効期限',
|
|
195
|
-
remainingAmount: '残高',
|
|
196
|
-
redeemPoints: '利用ポイント',
|
|
197
|
-
remainingPoints: 'ポイント残高',
|
|
198
|
-
entitlementRemaining: '残り回数',
|
|
199
|
-
table: 'テーブル',
|
|
200
|
-
bookingId: '予約ID',
|
|
201
|
-
bookingDateTime: '日時',
|
|
202
|
-
bookingResource: 'リソース',
|
|
203
|
-
bookingHolder: '予約者',
|
|
204
|
-
orderDiscount: '注文割引',
|
|
205
|
-
manualDiscount: '手動割引',
|
|
206
|
-
manualMarkup: '手動値上げ',
|
|
207
|
-
payProcessingFee: '決済手数料',
|
|
208
|
-
rounding: '端数調整',
|
|
209
|
-
gross: '総重量',
|
|
210
|
-
tare: '風袋',
|
|
211
|
-
handoverTime: '受け渡し時間',
|
|
212
|
-
refund: '返金',
|
|
213
|
-
cashReceived: 'お預かり',
|
|
214
|
-
changeDue: 'お釣り'
|
|
215
|
-
},
|
|
216
|
-
pt: {
|
|
217
|
-
contactName: 'Nome de contato',
|
|
218
|
-
contactMobile: 'Celular de contato',
|
|
219
|
-
email: 'e-mail',
|
|
220
|
-
dineIn: 'Consumo no local',
|
|
221
|
-
takeAway: 'Para levar',
|
|
222
|
-
delivery: 'Entrega',
|
|
223
|
-
pickUp: 'Recolha',
|
|
224
|
-
tableService: 'Serviço à mesa',
|
|
225
|
-
roomService: 'Serviço de quarto',
|
|
226
|
-
deliveryByUber: 'Entrega pela Uber Eats',
|
|
227
|
-
deliveryByPanda: 'Entrega pela HungryPanda',
|
|
228
|
-
deliveryByMerchant: 'Entrega pelo comerciante',
|
|
229
|
-
shopService: 'Consumo no local',
|
|
230
|
-
pickUpTime: 'Hora de recolha',
|
|
231
|
-
asap: 'Assim que possível',
|
|
232
|
-
cash: 'Dinheiro',
|
|
233
|
-
eftpos: 'Cartão',
|
|
234
|
-
wallet: 'Carteira',
|
|
235
|
-
giftCard: 'Cartão-presente',
|
|
236
|
-
pointCard: 'Cartão de pontos',
|
|
237
|
-
balance: 'Saldo',
|
|
238
|
-
validity: 'Validade',
|
|
239
|
-
remainingAmount: 'Saldo restante',
|
|
240
|
-
redeemPoints: 'Pontos utilizados',
|
|
241
|
-
remainingPoints: 'Saldo de pontos',
|
|
242
|
-
entitlementRemaining: 'Utilizações restantes',
|
|
243
|
-
table: 'Mesa',
|
|
244
|
-
bookingId: 'ID da reserva',
|
|
245
|
-
bookingDateTime: 'Data e hora',
|
|
246
|
-
bookingResource: 'Recurso',
|
|
247
|
-
bookingHolder: 'Titular',
|
|
248
|
-
orderDiscount: 'Desconto do pedido',
|
|
249
|
-
manualDiscount: 'Desconto manual',
|
|
250
|
-
manualMarkup: 'Acréscimo manual',
|
|
251
|
-
payProcessingFee: 'Taxa de processamento',
|
|
252
|
-
rounding: 'Arredondamento',
|
|
253
|
-
gross: 'Peso bruto',
|
|
254
|
-
tare: 'Tara',
|
|
255
|
-
handoverTime: 'Hora de entrega',
|
|
256
|
-
refund: 'Reembolso',
|
|
257
|
-
cashReceived: 'Dinheiro recebido',
|
|
258
|
-
changeDue: 'Troco'
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
export function buildSmallTicketData(params) {
|
|
262
|
-
var order = params.order || {};
|
|
263
|
-
var shopInfo = params.shopInfo || {};
|
|
264
|
-
var locales = resolveLocales(shopInfo, params.locales);
|
|
265
|
-
var productMap = params.productMap || {};
|
|
266
|
-
return locales.reduce(function (data, locale) {
|
|
267
|
-
data[locale] = buildLocaleData({
|
|
268
|
-
order: order,
|
|
269
|
-
shopInfo: shopInfo,
|
|
270
|
-
locale: locale,
|
|
271
|
-
productMap: productMap
|
|
272
|
-
});
|
|
273
|
-
return data;
|
|
274
|
-
}, {});
|
|
275
|
-
}
|
|
276
|
-
export function hasSmallTicketData(value) {
|
|
277
|
-
return !!value && _typeof(value) === 'object' && Object.keys(value).length > 0;
|
|
278
|
-
}
|
|
279
|
-
function buildLocaleData(params) {
|
|
280
|
-
var order = params.order,
|
|
281
|
-
shopInfo = params.shopInfo,
|
|
282
|
-
locale = params.locale,
|
|
283
|
-
productMap = params.productMap;
|
|
284
|
-
var products = buildProducts(order, locale, productMap);
|
|
285
|
-
var summary = getSummary(order);
|
|
286
|
-
var currencySymbol = getCurrencySymbol(order, shopInfo);
|
|
287
|
-
var financials = resolveReceiptFinancials(order, summary);
|
|
288
|
-
var delivery = buildDelivery(order, locale);
|
|
289
|
-
return _objectSpread(_objectSpread({
|
|
290
|
-
base_data: buildBaseData({
|
|
291
|
-
order: order,
|
|
292
|
-
shopInfo: shopInfo,
|
|
293
|
-
locale: locale,
|
|
294
|
-
currencySymbol: currencySymbol,
|
|
295
|
-
financials: financials
|
|
296
|
-
}),
|
|
297
|
-
products: products,
|
|
298
|
-
fees: buildFees({
|
|
299
|
-
order: order,
|
|
300
|
-
shopInfo: shopInfo,
|
|
301
|
-
locale: locale,
|
|
302
|
-
products: products,
|
|
303
|
-
summary: summary,
|
|
304
|
-
currencySymbol: currencySymbol,
|
|
305
|
-
financials: financials
|
|
306
|
-
}),
|
|
307
|
-
customer: buildCustomer(order, locale),
|
|
308
|
-
appointment: buildAppointment(order, locale)
|
|
309
|
-
}, delivery.length ? {
|
|
310
|
-
delivery: delivery
|
|
311
|
-
} : {}), {}, {
|
|
312
|
-
resources: buildResources(order, locale),
|
|
313
|
-
payment_data: buildPaymentData({
|
|
314
|
-
order: order,
|
|
315
|
-
locale: locale,
|
|
316
|
-
currencySymbol: currencySymbol
|
|
317
|
-
}),
|
|
318
|
-
wallets: buildWallets({
|
|
319
|
-
order: order,
|
|
320
|
-
locale: locale,
|
|
321
|
-
currencySymbol: currencySymbol
|
|
322
|
-
}),
|
|
323
|
-
tickets: Array.isArray(order.tickets) ? order.tickets : [],
|
|
324
|
-
source_shop: [],
|
|
325
|
-
refund_data: buildRefundData({
|
|
326
|
-
order: order,
|
|
327
|
-
locale: locale,
|
|
328
|
-
currencySymbol: currencySymbol
|
|
329
|
-
}),
|
|
330
|
-
expend_data: []
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
function buildBaseData(params) {
|
|
334
|
-
var _financials$amountGap, _order$metadata;
|
|
335
|
-
var order = params.order,
|
|
336
|
-
shopInfo = params.shopInfo,
|
|
337
|
-
locale = params.locale,
|
|
338
|
-
currencySymbol = params.currencySymbol,
|
|
339
|
-
financials = params.financials;
|
|
340
|
-
var orderNumber = stringify(order.buzzer || order.shop_full_order_number);
|
|
341
|
-
return _objectSpread({
|
|
342
|
-
shop_name: stringify(shopInfo.name || order.shop_name),
|
|
343
|
-
note: stringify(order.note),
|
|
344
|
-
shop_order_number: stringify(order.shop_order_number),
|
|
345
|
-
order_number: orderNumber,
|
|
346
|
-
shop_tax_number: stringify(shopInfo.tax_number || order.shop_tax_number),
|
|
347
|
-
shop_phone: stringify(shopInfo.phone || order.shop_phone),
|
|
348
|
-
shop_address: stringify(shopInfo.receipt_address || shopInfo.address || buildShopAddress(shopInfo) || order.shop_address),
|
|
349
|
-
original_payment_status: financials.paymentStatus,
|
|
350
|
-
payment_status: financials.paymentStatus,
|
|
351
|
-
total_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
352
|
-
has_pay: formatMoney(financials.netPaymentApplied, currencySymbol),
|
|
353
|
-
amount_gap: formatCalculatedMoney((_financials$amountGap = financials.amountGap) !== null && _financials$amountGap !== void 0 ? _financials$amountGap : 0, currencySymbol),
|
|
354
|
-
is_repeat: 0,
|
|
355
|
-
buzzer: stringify(order.buzzer || order.pickup_number || ((_order$metadata = order.metadata) === null || _order$metadata === void 0 ? void 0 : _order$metadata.buzzer)),
|
|
356
|
-
order_no: orderNumber,
|
|
357
|
-
order_time: formatDateTime(order.created_at || order.sales_time || new Date(), locale)
|
|
358
|
-
}, isPresentId(order.updated_at) ? {
|
|
359
|
-
updated_at: formatDateTime(order.updated_at, locale)
|
|
360
|
-
} : {});
|
|
361
|
-
}
|
|
362
|
-
function buildProducts(order, locale, productMap) {
|
|
363
|
-
var products = Array.isArray(order.products) ? order.products : [];
|
|
364
|
-
var allergyByProductUid = buildProductAllergyMap(order, locale);
|
|
365
|
-
return products.map(function (rawProduct) {
|
|
366
|
-
var _ref, _ref2, _product$product_quan, _ref3, _ref4, _ref5, _product$original_pri, _ref6, _ref7, _product$selling_pric, _product$product_id, _product$metadata, _product$metadata2;
|
|
367
|
-
var product = restoreReceiptDiscountHierarchy(rawProduct);
|
|
368
|
-
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);
|
|
369
|
-
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;
|
|
370
|
-
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;
|
|
371
|
-
var productTitle = resolveProductTitle({
|
|
372
|
-
product: product,
|
|
373
|
-
productMap: productMap,
|
|
374
|
-
locale: locale
|
|
375
|
-
});
|
|
376
|
-
var parentProduct = resolveProductFromMap((_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product.id, productMap);
|
|
377
|
-
var currencySymbol = getCurrencySymbol(order, null);
|
|
378
|
-
var options = normalizeProductOptions({
|
|
379
|
-
product: product,
|
|
380
|
-
locale: locale,
|
|
381
|
-
currencySymbol: currencySymbol,
|
|
382
|
-
parentProduct: parentProduct
|
|
383
|
-
});
|
|
384
|
-
var combinations = normalizeProductCombinations({
|
|
385
|
-
product: product,
|
|
386
|
-
productMap: productMap,
|
|
387
|
-
locale: locale,
|
|
388
|
-
currencySymbol: currencySymbol,
|
|
389
|
-
parentProduct: parentProduct
|
|
390
|
-
});
|
|
391
|
-
var resolvedVariant = resolveProductVariantText({
|
|
392
|
-
product: product,
|
|
393
|
-
parentProduct: parentProduct,
|
|
394
|
-
locale: locale
|
|
395
|
-
});
|
|
396
|
-
var productUid = firstPresentValue((_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number, product.unique_identification_number);
|
|
397
|
-
var bookingUid = firstPresentValue(product.booking_uid, (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.booking_uid);
|
|
398
|
-
var extensionList = buildProductExtensionList({
|
|
399
|
-
product: product,
|
|
400
|
-
locale: locale,
|
|
401
|
-
currencySymbol: currencySymbol,
|
|
402
|
-
quantity: quantity,
|
|
403
|
-
originalPrice: originalPrice
|
|
404
|
-
});
|
|
405
|
-
var productNote = resolveProductNote(product, locale);
|
|
406
|
-
var allergy = isPresentId(productUid) ? allergyByProductUid.get(String(productUid).trim()) || '' : '';
|
|
407
|
-
var basePrice = resolveProductBasePrice(product);
|
|
408
|
-
var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
|
|
409
|
-
var shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
|
|
410
|
-
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
411
|
-
product_title: productTitle,
|
|
412
|
-
product_quantity: quantity,
|
|
413
|
-
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
414
|
-
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
|
|
415
|
-
original_price: formatMoney(originalPrice, currencySymbol)
|
|
416
|
-
}, shouldIncludeBasePrice ? {
|
|
417
|
-
base_price: formatCalculatedMoney(basePrice !== null && basePrice !== void 0 ? basePrice : 0, currencySymbol)
|
|
418
|
-
} : {}), {}, {
|
|
419
|
-
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol)
|
|
420
|
-
}, options.length ? {
|
|
421
|
-
options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
|
|
422
|
-
} : {}), resolvedCombinations.length ? {
|
|
423
|
-
package_items_total_price: sumCombinationTotals(resolvedCombinations, currencySymbol)
|
|
424
|
-
} : {}), {}, {
|
|
425
|
-
extension_list: extensionList
|
|
426
|
-
}, isPresentId(productUid) ? {
|
|
427
|
-
product_uid: productUid
|
|
428
|
-
} : {}), isPresentId(bookingUid) ? {
|
|
429
|
-
booking_uid: bookingUid
|
|
430
|
-
} : {}), productNote ? {
|
|
431
|
-
product_note: productNote
|
|
432
|
-
} : {}), allergy ? {
|
|
433
|
-
allergy: allergy
|
|
434
|
-
} : {}), options.length ? {
|
|
435
|
-
options: options
|
|
436
|
-
} : {}), resolvedVariant ? {
|
|
437
|
-
variant: resolvedVariant
|
|
438
|
-
} : {}), resolvedCombinations.length ? {
|
|
439
|
-
combinations: resolvedCombinations
|
|
440
|
-
} : {});
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
var RECEIPT_BUNDLE_MAP_ID_KEY = 'custom_product_bundle_map_id';
|
|
444
|
-
function restoreReceiptDiscountHierarchy(source) {
|
|
445
|
-
if (!source || _typeof(source) !== 'object' || Array.isArray(source)) {
|
|
446
|
-
return source;
|
|
447
|
-
}
|
|
448
|
-
var childKey = Array.isArray(source.combinations) && source.combinations.length ? 'combinations' : Array.isArray(source.product_bundle) && source.product_bundle.length ? 'product_bundle' : null;
|
|
449
|
-
if (!childKey) return _objectSpread({}, source);
|
|
450
|
-
var children = source[childKey].map(function (child) {
|
|
451
|
-
return child && _typeof(child) === 'object' && !Array.isArray(child) ? restoreReceiptDiscountHierarchy(child) : child;
|
|
452
|
-
});
|
|
453
|
-
var restored = _objectSpread(_objectSpread({}, source), {}, _defineProperty({}, childKey, children));
|
|
454
|
-
if (!Array.isArray(source.discount_list) || !source.discount_list.length) {
|
|
455
|
-
return restored;
|
|
456
|
-
}
|
|
457
|
-
var descendantsByMapId = new Map();
|
|
458
|
-
indexReceiptDiscountTargets(children, descendantsByMapId);
|
|
459
|
-
if (!descendantsByMapId.size) return restored;
|
|
460
|
-
var ownDiscounts = [];
|
|
461
|
-
var _iterator = _createForOfIteratorHelper(source.discount_list),
|
|
462
|
-
_step;
|
|
463
|
-
try {
|
|
464
|
-
var _loop = function _loop() {
|
|
465
|
-
var discount = _step.value;
|
|
466
|
-
var mapId = getReceiptDiscountBundleMapId(discount);
|
|
467
|
-
var target = mapId ? descendantsByMapId.get(mapId) : undefined;
|
|
468
|
-
if (!target) {
|
|
469
|
-
ownDiscounts.push(discount);
|
|
470
|
-
return 1; // continue
|
|
471
|
-
}
|
|
472
|
-
var targetDiscounts = Array.isArray(target.discount_list) ? target.discount_list : [];
|
|
473
|
-
if (!targetDiscounts.some(function (item) {
|
|
474
|
-
return isSameReceiptDiscount(item, discount);
|
|
475
|
-
})) {
|
|
476
|
-
target.discount_list = [].concat(_toConsumableArray(targetDiscounts), [discount]);
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
480
|
-
if (_loop()) continue;
|
|
481
|
-
}
|
|
482
|
-
} catch (err) {
|
|
483
|
-
_iterator.e(err);
|
|
484
|
-
} finally {
|
|
485
|
-
_iterator.f();
|
|
486
|
-
}
|
|
487
|
-
restored.discount_list = ownDiscounts;
|
|
488
|
-
return restored;
|
|
489
|
-
}
|
|
490
|
-
function indexReceiptDiscountTargets(nodes, targets) {
|
|
491
|
-
var _iterator2 = _createForOfIteratorHelper(nodes),
|
|
492
|
-
_step2;
|
|
493
|
-
try {
|
|
494
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
495
|
-
var node = _step2.value;
|
|
496
|
-
if (!node || _typeof(node) !== 'object' || Array.isArray(node)) continue;
|
|
497
|
-
var mapId = getReceiptBundleMapId(node);
|
|
498
|
-
if (mapId && !targets.has(mapId)) targets.set(mapId, node);
|
|
499
|
-
var children = Array.isArray(node.combinations) && node.combinations.length ? node.combinations : Array.isArray(node.product_bundle) ? node.product_bundle : [];
|
|
500
|
-
indexReceiptDiscountTargets(children, targets);
|
|
501
|
-
}
|
|
502
|
-
} catch (err) {
|
|
503
|
-
_iterator2.e(err);
|
|
504
|
-
} finally {
|
|
505
|
-
_iterator2.f();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
function normalizeReceiptId(value) {
|
|
509
|
-
if (value === undefined || value === null) return null;
|
|
510
|
-
var normalized = String(value).trim();
|
|
511
|
-
return normalized ? normalized : null;
|
|
512
|
-
}
|
|
513
|
-
function getReceiptBundleMapId(node) {
|
|
514
|
-
var _node$metadata$RECEIP, _node$metadata;
|
|
515
|
-
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);
|
|
516
|
-
}
|
|
517
|
-
function getReceiptDiscountBundleMapId(discount) {
|
|
518
|
-
var _discount$metadata;
|
|
519
|
-
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]);
|
|
520
|
-
}
|
|
521
|
-
function isSameReceiptDiscount(left, right) {
|
|
522
|
-
var _ref8, _left$discount$resour, _left$discount, _ref9, _right$discount$resou, _right$discount, _ref10, _ref11, _left$amount, _ref12, _ref13, _right$amount;
|
|
523
|
-
var leftOrderDiscountId = normalizeReceiptId(left === null || left === void 0 ? void 0 : left.order_discount_id);
|
|
524
|
-
var rightOrderDiscountId = normalizeReceiptId(right === null || right === void 0 ? void 0 : right.order_discount_id);
|
|
525
|
-
if (leftOrderDiscountId && rightOrderDiscountId) {
|
|
526
|
-
return leftOrderDiscountId === rightOrderDiscountId;
|
|
527
|
-
}
|
|
528
|
-
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);
|
|
529
|
-
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);
|
|
530
|
-
if (!leftResourceId || !rightResourceId) return false;
|
|
531
|
-
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 : '');
|
|
532
|
-
}
|
|
533
|
-
function resolveProductBasePrice(product) {
|
|
534
|
-
var _product$product_vari, _ref14, _ref15, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
|
|
535
|
-
var metadata = product.metadata || {};
|
|
536
|
-
var origin = product._origin || metadata.origin || {};
|
|
537
|
-
var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
|
|
538
|
-
var variant = Array.isArray(origin.variant) && isPresentId(variantId) ? origin.variant.find(function (item) {
|
|
539
|
-
return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
|
|
540
|
-
}) : undefined;
|
|
541
|
-
var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
|
|
542
|
-
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);
|
|
543
|
-
var hasEntitlementPass = normalizeArray(product.discount_list).some(function (discount) {
|
|
544
|
-
return getProductWalletDiscountType(discount) === 'entitlement_pass';
|
|
545
|
-
});
|
|
546
|
-
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;
|
|
547
|
-
var hasCombinations = normalizeArray(product.combinations).length > 0 || normalizeArray(product.product_bundle).length > 0 || normalizeArray(product.bundle).length > 0;
|
|
548
|
-
var aggregateSourcePrice = firstPresentValue(metadata.source_product_price, product.price);
|
|
549
|
-
var originalPrice = product.original_price;
|
|
550
|
-
// 部分旧 entitlement 商品把 source/price 持久化成了整行总价,但
|
|
551
|
-
// original_price 仍是单件价。仅在等式能明确证明该口径时做窄幅回退。
|
|
552
|
-
var useOriginalPriceAsLegacyUnitPrice = hasEntitlementPass && quantity > 1 && !hasOptions && !hasCombinations && isNumericAmount(aggregateSourcePrice) && isNumericAmount(originalPrice) && new Decimal(aggregateSourcePrice).eq(new Decimal(originalPrice).mul(quantity));
|
|
553
|
-
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);
|
|
554
|
-
}
|
|
555
|
-
function normalizeProductDiscounts(params) {
|
|
556
|
-
var product = params.product,
|
|
557
|
-
locale = params.locale,
|
|
558
|
-
currencySymbol = params.currencySymbol,
|
|
559
|
-
quantity = params.quantity;
|
|
560
|
-
var rows = normalizeArray(product.discount_list).filter(function (discount) {
|
|
561
|
-
var _ref16, _discount$amount;
|
|
562
|
-
var amount = (_ref16 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref16 !== void 0 ? _ref16 : discount.discount_amount;
|
|
563
|
-
return isNonZero(amount);
|
|
564
|
-
}).map(function (discount) {
|
|
565
|
-
var _ref17, _discount$amount2;
|
|
566
|
-
var title = resolveDiscountTitleWithPercent(discount, locale);
|
|
567
|
-
var amount = (_ref17 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
|
|
568
|
-
var isMarkup = isManualMarkup(discount);
|
|
569
|
-
var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
|
|
570
|
-
var isEntitlementPass = getProductWalletDiscountType(discount) === 'entitlement_pass';
|
|
571
|
-
var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount || isEntitlementPass ? 1 : quantity);
|
|
572
|
-
var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
|
|
573
|
-
return {
|
|
574
|
-
item: title,
|
|
575
|
-
value: formattedAmount,
|
|
576
|
-
isMarkup: isMarkup
|
|
577
|
-
};
|
|
578
|
-
});
|
|
579
|
-
return rows.sort(function (left, right) {
|
|
580
|
-
return Number(right.isMarkup) - Number(left.isMarkup);
|
|
581
|
-
}).map(function (_ref18) {
|
|
582
|
-
var _isMarkup = _ref18.isMarkup,
|
|
583
|
-
row = _objectWithoutProperties(_ref18, _excluded);
|
|
584
|
-
return row;
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
function isManualMarkup(discount) {
|
|
588
|
-
var _discount$discount, _ref19, _discount$amount3;
|
|
589
|
-
if (discount.type !== 'product') return false;
|
|
590
|
-
if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
|
|
591
|
-
var amount = (_ref19 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref19 !== void 0 ? _ref19 : discount.discount_amount;
|
|
592
|
-
return new Decimal(toMoneyNumber(amount)).isNegative();
|
|
593
|
-
}
|
|
594
|
-
function hasProductDiscount(product) {
|
|
595
|
-
var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
596
|
-
var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
|
|
597
|
-
var _ref20, _discount$amount4;
|
|
598
|
-
return isNonZero((_ref20 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref20 !== void 0 ? _ref20 : discount.discount_amount);
|
|
599
|
-
});
|
|
600
|
-
return hasDiscountListAmount || extensionList.some(function (row) {
|
|
601
|
-
return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
function buildProductExtensionList(params) {
|
|
605
|
-
var product = params.product,
|
|
606
|
-
locale = params.locale,
|
|
607
|
-
currencySymbol = params.currencySymbol,
|
|
608
|
-
quantity = params.quantity,
|
|
609
|
-
originalPrice = params.originalPrice;
|
|
610
|
-
var discountList = normalizeProductDiscounts({
|
|
611
|
-
product: product,
|
|
612
|
-
locale: locale,
|
|
613
|
-
currencySymbol: currencySymbol,
|
|
614
|
-
quantity: quantity
|
|
615
|
-
});
|
|
616
|
-
var extensionList = [].concat(_toConsumableArray(buildProductOpenWeightRows({
|
|
617
|
-
product: product,
|
|
618
|
-
locale: locale,
|
|
619
|
-
currencySymbol: currencySymbol
|
|
620
|
-
})), _toConsumableArray(quantity > 1 ? [{
|
|
621
|
-
item: buildProductQuantityPriceText({
|
|
622
|
-
quantity: quantity,
|
|
623
|
-
currencySymbol: currencySymbol,
|
|
624
|
-
price: originalPrice
|
|
625
|
-
}),
|
|
626
|
-
value: ''
|
|
627
|
-
}] : []));
|
|
628
|
-
var productExtensionList = extensionList.length ? extensionList : normalizeArray(product.extension_list);
|
|
629
|
-
return [].concat(_toConsumableArray(productExtensionList), _toConsumableArray(discountList));
|
|
630
|
-
}
|
|
631
|
-
function buildProductOpenWeightRows(params) {
|
|
632
|
-
var _productSku$unit, _productSku$net_weigh, _productSku$unit_pric;
|
|
633
|
-
var product = params.product,
|
|
634
|
-
locale = params.locale,
|
|
635
|
-
currencySymbol = params.currencySymbol;
|
|
636
|
-
var productSku = product.product_sku || {};
|
|
637
|
-
if (productSku.open_sold_weight != 1) return [];
|
|
638
|
-
var unit = (_productSku$unit = productSku.unit) !== null && _productSku$unit !== void 0 ? _productSku$unit : '';
|
|
639
|
-
var manualFlag = productSku.weight_source === 'manual' ? '(M) ' : '';
|
|
640
|
-
var hasTare = toNumber(productSku.tare_weight, 0) > 0;
|
|
641
|
-
var rows = [];
|
|
642
|
-
if (hasTare) {
|
|
643
|
-
var _productSku$weight;
|
|
644
|
-
rows.push({
|
|
645
|
-
item: "".concat(manualFlag).concat(label(locale, 'gross'), ": ").concat((_productSku$weight = productSku.weight) !== null && _productSku$weight !== void 0 ? _productSku$weight : 0).concat(unit),
|
|
646
|
-
value: ''
|
|
647
|
-
});
|
|
648
|
-
rows.push({
|
|
649
|
-
item: "".concat(label(locale, 'tare'), ": ").concat(productSku.tare_weight).concat(unit),
|
|
650
|
-
value: ''
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
var netWeight = (_productSku$net_weigh = productSku.net_weight) !== null && _productSku$net_weigh !== void 0 ? _productSku$net_weigh : 0;
|
|
654
|
-
var unitPrice = (_productSku$unit_pric = productSku.unit_price) !== null && _productSku$unit_pric !== void 0 ? _productSku$unit_pric : 0;
|
|
655
|
-
var netItem = "".concat(netWeight, " ").concat(unit, " NET @ ").concat(currencySymbol).concat(unitPrice, "/").concat(unit);
|
|
656
|
-
rows.push({
|
|
657
|
-
item: hasTare ? netItem : "".concat(manualFlag).concat(netItem),
|
|
658
|
-
value: ''
|
|
659
|
-
});
|
|
660
|
-
return rows;
|
|
661
|
-
}
|
|
662
|
-
function buildProductQuantityPriceText(params) {
|
|
663
|
-
var quantity = params.quantity,
|
|
664
|
-
currencySymbol = params.currencySymbol,
|
|
665
|
-
price = params.price;
|
|
666
|
-
return "".concat(quantity, " @ ").concat(currencySymbol).concat(stringify(price), " EACH");
|
|
667
|
-
}
|
|
668
|
-
function resolveDiscountTitleWithPercent(discount, locale) {
|
|
669
|
-
var _discount$discount2, _discount$discount$di, _discount$discount3;
|
|
670
|
-
var title = resolveDiscountTitle(discount, locale);
|
|
671
|
-
if (getProductWalletDiscountType(discount) === 'entitlement_pass') {
|
|
672
|
-
return title;
|
|
673
|
-
}
|
|
674
|
-
var percentRaw = (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.percent;
|
|
675
|
-
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';
|
|
676
|
-
var percent = percentRaw !== undefined && percentRaw !== null ? Math.trunc(Number(percentRaw)) : NaN;
|
|
677
|
-
if (percentRaw === undefined || percentRaw === null) return title;
|
|
678
|
-
if (cardType !== 'percent') return title;
|
|
679
|
-
if (Number.isNaN(percent)) return title;
|
|
680
|
-
return "".concat(title, " (").concat(percent, "%)");
|
|
681
|
-
}
|
|
682
|
-
function resolveDiscountTitle(discount, locale) {
|
|
683
|
-
var _ref21, _ref22, _ref23, _ref24, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
|
|
684
|
-
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);
|
|
685
|
-
if (title) return title;
|
|
686
|
-
if (discount.type === 'product') {
|
|
687
|
-
return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
|
|
688
|
-
}
|
|
689
|
-
return '';
|
|
690
|
-
}
|
|
691
|
-
function resolveProductTitle(params) {
|
|
692
|
-
var _product$product_id2;
|
|
693
|
-
var product = params.product,
|
|
694
|
-
productMap = params.productMap,
|
|
695
|
-
locale = params.locale;
|
|
696
|
-
var ownTitle = getProductTitleSource(product, locale);
|
|
697
|
-
if (ownTitle) return ownTitle;
|
|
698
|
-
var productId = (_product$product_id2 = product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : product.id;
|
|
699
|
-
var fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
700
|
-
if (!fallbackProduct) return ownTitle || '';
|
|
701
|
-
return getProductTitleSource(fallbackProduct, locale);
|
|
702
|
-
}
|
|
703
|
-
function normalizeProductOptions(params) {
|
|
704
|
-
var _product$product_sku2;
|
|
705
|
-
var product = params.product,
|
|
706
|
-
locale = params.locale,
|
|
707
|
-
currencySymbol = params.currencySymbol,
|
|
708
|
-
parentProduct = params.parentProduct;
|
|
709
|
-
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 : [];
|
|
710
|
-
return rawOptions.map(function (option) {
|
|
711
|
-
var _ref25, _option$original_pric, _ref26, _option$num, _ref27, _option$value;
|
|
712
|
-
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;
|
|
713
|
-
var quantity = toNumber((_ref26 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
|
|
714
|
-
var value = (_ref27 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref27 !== void 0 ? _ref27 : option.item;
|
|
715
|
-
var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
|
|
716
|
-
option: option,
|
|
717
|
-
parentProduct: parentProduct,
|
|
718
|
-
locale: locale
|
|
719
|
-
});
|
|
720
|
-
return _objectSpread(_objectSpread(_objectSpread({
|
|
721
|
-
name: name
|
|
722
|
-
}, option.num !== undefined || option.quantity !== undefined ? {
|
|
723
|
-
num: quantity
|
|
724
|
-
} : {}), price !== undefined && price !== null && price !== '' ? {
|
|
725
|
-
price: formatMoney(price, currencySymbol)
|
|
726
|
-
} : {}), {}, {
|
|
727
|
-
total_price: formatCalculatedMoney(new Decimal(toMoneyNumber(price !== null && price !== void 0 ? price : 0)).mul(quantity), currencySymbol)
|
|
728
|
-
}, value !== undefined && value !== null && value !== '' ? {
|
|
729
|
-
value: getLocalizedValue(value, locale)
|
|
730
|
-
} : {});
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
function normalizeProductCombinations(params) {
|
|
734
|
-
var product = params.product,
|
|
735
|
-
productMap = params.productMap,
|
|
736
|
-
locale = params.locale,
|
|
737
|
-
currencySymbol = params.currencySymbol,
|
|
738
|
-
parentProduct = params.parentProduct;
|
|
739
|
-
var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
740
|
-
return bundles.map(function (bundle) {
|
|
741
|
-
var _ref28, _bundle$num;
|
|
742
|
-
var combinationsOptions = normalizeProductOptions({
|
|
743
|
-
product: {},
|
|
744
|
-
locale: locale,
|
|
745
|
-
currencySymbol: currencySymbol,
|
|
746
|
-
options: Array.isArray(bundle.option) ? bundle.option : [],
|
|
747
|
-
parentProduct: parentProduct
|
|
748
|
-
});
|
|
749
|
-
var baseTitle = resolveBundleProductTitle({
|
|
750
|
-
bundle: bundle,
|
|
751
|
-
productMap: productMap,
|
|
752
|
-
locale: locale,
|
|
753
|
-
parentProduct: parentProduct
|
|
754
|
-
});
|
|
755
|
-
var productNote = resolveProductNote(bundle, locale);
|
|
756
|
-
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
|
|
757
|
-
var quantity = toNumber((_ref28 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref28 !== void 0 ? _ref28 : 1, 1);
|
|
758
|
-
var formattedPrice = formatBundlePrice(bundle, currencySymbol);
|
|
759
|
-
var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
|
|
760
|
-
var explicitBasePrice = resolveCombinationBasePrice(bundle);
|
|
761
|
-
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
762
|
-
var extensionList = buildProductExtensionList({
|
|
763
|
-
product: bundle,
|
|
764
|
-
locale: locale,
|
|
765
|
-
currencySymbol: currencySymbol,
|
|
766
|
-
quantity: quantity,
|
|
767
|
-
originalPrice: formattedPrice
|
|
768
|
-
});
|
|
769
|
-
var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle, extensionList);
|
|
770
|
-
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
771
|
-
product_title: baseTitle,
|
|
772
|
-
product_quantity: quantity,
|
|
773
|
-
price: formattedPrice,
|
|
774
|
-
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol)
|
|
775
|
-
}, shouldIncludeBasePrice ? {
|
|
776
|
-
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
777
|
-
} : {}), {}, {
|
|
778
|
-
combinations_options: combinationsOptions
|
|
779
|
-
}, combinationsOptions.length ? {
|
|
780
|
-
options_total_price: optionsTotal
|
|
781
|
-
} : {}), nestedCombinations.length ? {
|
|
782
|
-
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
783
|
-
} : {}), productNote ? {
|
|
784
|
-
product_note: productNote
|
|
785
|
-
} : {}), extensionList.length ? {
|
|
786
|
-
extension_list: extensionList
|
|
787
|
-
} : {}), nestedCombinations.length ? {
|
|
788
|
-
combinations: nestedCombinations
|
|
789
|
-
} : {});
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
function normalizeExistingCombinations(combinations, locale, currencySymbol) {
|
|
793
|
-
return combinations.map(function (combination) {
|
|
794
|
-
var _ref29, _ref30, _combination$product_, _firstPresentValue;
|
|
795
|
-
if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
|
|
796
|
-
return combination;
|
|
797
|
-
}
|
|
798
|
-
var productNote = resolveProductNote(combination, locale);
|
|
799
|
-
var rawOptions = Array.isArray(combination.combinations_options) ? combination.combinations_options : Array.isArray(combination.options) ? combination.options : [];
|
|
800
|
-
var normalizedOptions = normalizeProductOptions({
|
|
801
|
-
product: {},
|
|
802
|
-
locale: locale,
|
|
803
|
-
currencySymbol: currencySymbol,
|
|
804
|
-
options: rawOptions
|
|
805
|
-
});
|
|
806
|
-
var nestedCombinations = Array.isArray(combination.combinations) ? normalizeExistingCombinations(combination.combinations, locale, currencySymbol) : [];
|
|
807
|
-
var productTitle = getBundleProductTitleSource(combination, locale);
|
|
808
|
-
var snapshot = _objectSpread({}, combination);
|
|
809
|
-
delete snapshot.product_title;
|
|
810
|
-
delete snapshot.product_note;
|
|
811
|
-
delete snapshot.note;
|
|
812
|
-
delete snapshot.combinations;
|
|
813
|
-
delete snapshot.discount_list;
|
|
814
|
-
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);
|
|
815
|
-
var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
|
|
816
|
-
var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
|
|
817
|
-
return option.total_price;
|
|
818
|
-
}));
|
|
819
|
-
var explicitBasePrice = resolveCombinationBasePrice(combination, true);
|
|
820
|
-
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
821
|
-
var extensionList = buildProductExtensionList({
|
|
822
|
-
product: combination,
|
|
823
|
-
locale: locale,
|
|
824
|
-
currencySymbol: currencySymbol,
|
|
825
|
-
quantity: quantity,
|
|
826
|
-
originalPrice: unitPrice
|
|
827
|
-
});
|
|
828
|
-
var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, extensionList);
|
|
829
|
-
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), productTitle ? {
|
|
830
|
-
product_title: productTitle
|
|
831
|
-
} : {}), {}, {
|
|
832
|
-
product_quantity: quantity,
|
|
833
|
-
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
|
|
834
|
-
}, shouldIncludeBasePrice ? {
|
|
835
|
-
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
836
|
-
} : {}), Array.isArray(combination.combinations_options) ? {
|
|
837
|
-
combinations_options: normalizedOptions
|
|
838
|
-
} : Array.isArray(combination.options) ? {
|
|
839
|
-
options: normalizedOptions
|
|
840
|
-
} : {}), normalizedOptions.length ? {
|
|
841
|
-
options_total_price: formatCalculatedMoney(optionsAmount, currencySymbol)
|
|
842
|
-
} : {}), nestedCombinations.length ? {
|
|
843
|
-
package_items_total_price: sumCombinationTotals(nestedCombinations, currencySymbol)
|
|
844
|
-
} : {}), productNote ? {
|
|
845
|
-
product_note: productNote
|
|
846
|
-
} : {}), extensionList.length ? {
|
|
847
|
-
extension_list: extensionList
|
|
848
|
-
} : {}), nestedCombinations.length ? {
|
|
849
|
-
combinations: nestedCombinations
|
|
850
|
-
} : {});
|
|
851
|
-
});
|
|
852
|
-
}
|
|
853
|
-
function sumMoneyValues(values) {
|
|
854
|
-
return values.reduce(function (sum, value) {
|
|
855
|
-
return sum.plus(toMoneyNumber(value));
|
|
856
|
-
}, new Decimal(0));
|
|
857
|
-
}
|
|
858
|
-
function resolveCombinationBasePrice(combination) {
|
|
859
|
-
var _combination$metadata;
|
|
860
|
-
var preferOriginalPrice = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
861
|
-
var fallbackPrices = preferOriginalPrice ? [combination.original_price, combination.product_price, combination.price] : [combination.price, combination.original_price, combination.product_price];
|
|
862
|
-
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));
|
|
863
|
-
}
|
|
864
|
-
function sumNormalizedOptionTotals(options, currencySymbol) {
|
|
865
|
-
return formatCalculatedMoney(sumMoneyValues(options.map(function (option) {
|
|
866
|
-
return option.total_price;
|
|
867
|
-
})), currencySymbol);
|
|
868
|
-
}
|
|
869
|
-
function sumCombinationTotals(combinations, currencySymbol) {
|
|
870
|
-
return formatCalculatedMoney(sumMoneyValues(combinations.map(function (combination) {
|
|
871
|
-
return combination.total_selling_price;
|
|
872
|
-
})), currencySymbol);
|
|
873
|
-
}
|
|
874
|
-
function resolveProductNote(product, locale) {
|
|
875
|
-
var productNote = getLocalizedValue(product.product_note, locale).trim();
|
|
876
|
-
if (productNote) return productNote;
|
|
877
|
-
return getLocalizedValue(product.note, locale).trim();
|
|
878
|
-
}
|
|
879
|
-
function buildProductAllergyMap(order, locale) {
|
|
880
|
-
var allergyByProductUid = new Map();
|
|
881
|
-
for (var _i = 0, _normalizeArray = normalizeArray(order.notes); _i < _normalizeArray.length; _i++) {
|
|
882
|
-
var _note$content, _relation$target_uuid;
|
|
883
|
-
var note = _normalizeArray[_i];
|
|
884
|
-
if (!note || _typeof(note) !== 'object' || Array.isArray(note) || String(note.note_type || '').trim() !== 'allergy') {
|
|
885
|
-
continue;
|
|
886
|
-
}
|
|
887
|
-
var content = getLocalizedValue((_note$content = note.content) === null || _note$content === void 0 ? void 0 : _note$content.text, locale).trim();
|
|
888
|
-
if (!content) continue;
|
|
889
|
-
var relation = normalizeArray(note.note_relations).find(function (item) {
|
|
890
|
-
return item && _typeof(item) === 'object' && !Array.isArray(item) && item.relation_type === 'about' && item.target_type === 'order_detail' && Number(item.is_primary) === 1;
|
|
891
|
-
});
|
|
892
|
-
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();
|
|
893
|
-
if (!productUid || allergyByProductUid.has(productUid)) continue;
|
|
894
|
-
allergyByProductUid.set(productUid, content);
|
|
895
|
-
}
|
|
896
|
-
return allergyByProductUid;
|
|
897
|
-
}
|
|
898
|
-
function resolveBundleProductTitle(params) {
|
|
899
|
-
var _ref31, _ref32, _bundle$bundle_produc;
|
|
900
|
-
var bundle = params.bundle,
|
|
901
|
-
productMap = params.productMap,
|
|
902
|
-
locale = params.locale,
|
|
903
|
-
parentProduct = params.parentProduct;
|
|
904
|
-
var ownTitle = getBundleProductTitleSource(bundle, locale);
|
|
905
|
-
if (ownTitle) return ownTitle;
|
|
906
|
-
var parentBundleItem = resolveBundleItemFromParentProduct({
|
|
907
|
-
bundle: bundle,
|
|
908
|
-
parentProduct: parentProduct
|
|
909
|
-
});
|
|
910
|
-
var parentBundleTitle = parentBundleItem ? getBundleProductTitleSource(parentBundleItem, locale) : '';
|
|
911
|
-
if (parentBundleTitle) return parentBundleTitle;
|
|
912
|
-
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;
|
|
913
|
-
var fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
914
|
-
if (!fallbackProduct) return '';
|
|
915
|
-
return getBundleProductTitleSource(fallbackProduct, locale);
|
|
916
|
-
}
|
|
917
|
-
function resolveProductFromMap(productId, productMap) {
|
|
918
|
-
if (productId === undefined || productId === null || productId === '') return null;
|
|
919
|
-
return productMap[productId] || productMap[String(productId)] || null;
|
|
920
|
-
}
|
|
921
|
-
function resolveProductVariantText(params) {
|
|
922
|
-
var _product$product_vari2;
|
|
923
|
-
var product = params.product,
|
|
924
|
-
parentProduct = params.parentProduct,
|
|
925
|
-
locale = params.locale;
|
|
926
|
-
if (product.variant) return getLocalizedValue(product.variant, locale);
|
|
927
|
-
if (!parentProduct) return '';
|
|
928
|
-
var productVariantId = (_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : product.variant_id;
|
|
929
|
-
if (!isNonZeroId(productVariantId)) return '';
|
|
930
|
-
var matchedVariant = normalizeArray(parentProduct.variant).find(function (variant) {
|
|
931
|
-
return isSameId(variant.id, productVariantId);
|
|
932
|
-
});
|
|
933
|
-
if (!matchedVariant) return '';
|
|
934
|
-
var resolvedFromSkuKey = resolveVariantTextFromSkuKey({
|
|
935
|
-
skuKey: matchedVariant.sku_key,
|
|
936
|
-
parentProduct: parentProduct,
|
|
937
|
-
locale: locale
|
|
938
|
-
});
|
|
939
|
-
if (resolvedFromSkuKey) return resolvedFromSkuKey;
|
|
940
|
-
return resolveVariantTextFromNameMap({
|
|
941
|
-
nameMap: matchedVariant.name || matchedVariant.title,
|
|
942
|
-
parentProduct: parentProduct,
|
|
943
|
-
locale: locale
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
function resolveVariantTextFromSkuKey(params) {
|
|
947
|
-
var skuKey = stringify(params.skuKey);
|
|
948
|
-
if (!skuKey) return '';
|
|
949
|
-
return skuKey.split('_').map(function (item) {
|
|
950
|
-
var _item$split = item.split(':'),
|
|
951
|
-
_item$split2 = _slicedToArray(_item$split, 2),
|
|
952
|
-
groupPositionId = _item$split2[0],
|
|
953
|
-
itemPositionId = _item$split2[1];
|
|
954
|
-
return resolveVariantTextItem({
|
|
955
|
-
parentProduct: params.parentProduct,
|
|
956
|
-
groupPositionId: groupPositionId,
|
|
957
|
-
itemPositionId: itemPositionId,
|
|
958
|
-
locale: params.locale
|
|
959
|
-
});
|
|
960
|
-
}).filter(Boolean).join(',');
|
|
961
|
-
}
|
|
962
|
-
function resolveVariantTextFromNameMap(params) {
|
|
963
|
-
if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
|
|
964
|
-
return Object.entries(params.nameMap).map(function (_ref33) {
|
|
965
|
-
var _ref34 = _slicedToArray(_ref33, 2),
|
|
966
|
-
groupPositionId = _ref34[0],
|
|
967
|
-
value = _ref34[1];
|
|
968
|
-
var group = resolveVariantGroup(params.parentProduct, groupPositionId);
|
|
969
|
-
if (!group) return '';
|
|
970
|
-
var groupName = getLocalizedValue(group.name, params.locale);
|
|
971
|
-
var itemName = getLocalizedValue(value, params.locale);
|
|
972
|
-
if (!groupName || !itemName) return '';
|
|
973
|
-
return "".concat(groupName, ":").concat(itemName);
|
|
974
|
-
}).filter(Boolean).join(',');
|
|
975
|
-
}
|
|
976
|
-
function resolveVariantTextItem(params) {
|
|
977
|
-
var group = resolveVariantGroup(params.parentProduct, params.groupPositionId);
|
|
978
|
-
var item = resolveVariantItem(group, params.itemPositionId);
|
|
979
|
-
if (!group || !item) return '';
|
|
980
|
-
var groupName = getLocalizedValue(group.name, params.locale);
|
|
981
|
-
var itemName = getLocalizedValue(item.name, params.locale);
|
|
982
|
-
if (!groupName || !itemName) return '';
|
|
983
|
-
return "".concat(groupName, ":").concat(itemName);
|
|
984
|
-
}
|
|
985
|
-
function resolveVariantGroup(parentProduct, groupPositionId) {
|
|
986
|
-
return normalizeArray(parentProduct.variant_group).find(function (group) {
|
|
987
|
-
return isSameId(group.position_id, groupPositionId) || isSameId(group.id, groupPositionId);
|
|
988
|
-
}) || null;
|
|
989
|
-
}
|
|
990
|
-
function resolveVariantItem(group, itemPositionId) {
|
|
991
|
-
if (!group) return null;
|
|
992
|
-
return normalizeArray(group.variant_item).find(function (item) {
|
|
993
|
-
return isSameId(item.position_id, itemPositionId) || isSameId(item.id, itemPositionId);
|
|
994
|
-
}) || null;
|
|
995
|
-
}
|
|
996
|
-
function getProductTitleSource(source, locale) {
|
|
997
|
-
if (!source || _typeof(source) !== 'object') return '';
|
|
998
|
-
return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title_i18n, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
|
|
999
|
-
}
|
|
1000
|
-
function getBundleProductTitleSource(source, locale) {
|
|
1001
|
-
if (!source || _typeof(source) !== 'object') return '';
|
|
1002
|
-
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);
|
|
1003
|
-
}
|
|
1004
|
-
function resolveTitleValue(value, locale) {
|
|
1005
|
-
var _ref35, _ref36, _ref37, _ref38, _value$locale;
|
|
1006
|
-
if (value === undefined || value === null) return '';
|
|
1007
|
-
if (_typeof(value) !== 'object') return stringify(value);
|
|
1008
|
-
var dashedLocale = locale.replace('_', '-');
|
|
1009
|
-
var underscoredLocale = locale.replace('-', '_');
|
|
1010
|
-
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 : '');
|
|
1011
|
-
}
|
|
1012
|
-
function resolveOptionTitleFromParentProduct(params) {
|
|
1013
|
-
var option = params.option,
|
|
1014
|
-
parentProduct = params.parentProduct,
|
|
1015
|
-
locale = params.locale;
|
|
1016
|
-
if (!parentProduct) return '';
|
|
1017
|
-
var optionItems = flattenOptionItems(parentProduct);
|
|
1018
|
-
var matchedOption = optionItems.find(function (item) {
|
|
1019
|
-
return isOptionItemMatch(option, item);
|
|
1020
|
-
});
|
|
1021
|
-
return getProductTitleSource(matchedOption, locale);
|
|
1022
|
-
}
|
|
1023
|
-
function flattenOptionItems(parentProduct) {
|
|
1024
|
-
var optionGroups = Array.isArray(parentProduct.option_group) ? parentProduct.option_group : [];
|
|
1025
|
-
return optionGroups.flatMap(function (group) {
|
|
1026
|
-
var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
|
|
1027
|
-
return items.map(function (item) {
|
|
1028
|
-
var _ref39, _item$option_group_id;
|
|
1029
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
1030
|
-
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
|
|
1031
|
-
});
|
|
1032
|
-
});
|
|
1033
|
-
});
|
|
1034
|
-
}
|
|
1035
|
-
function isOptionItemMatch(option, item) {
|
|
1036
|
-
var _ref40, _option$option_group_, _ref41, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
|
|
1037
|
-
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;
|
|
1038
|
-
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;
|
|
1039
|
-
if (!isSameId(optionItemId, itemId)) return false;
|
|
1040
|
-
var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
|
|
1041
|
-
var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
|
|
1042
|
-
if (isPresentId(optionGroupId) && isPresentId(itemGroupId)) {
|
|
1043
|
-
return isSameId(optionGroupId, itemGroupId);
|
|
1044
|
-
}
|
|
1045
|
-
return true;
|
|
1046
|
-
}
|
|
1047
|
-
function resolveBundleItemFromParentProduct(params) {
|
|
1048
|
-
var _ref42, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref44, _bundle$bundle_produc2;
|
|
1049
|
-
var bundle = params.bundle,
|
|
1050
|
-
parentProduct = params.parentProduct;
|
|
1051
|
-
if (!parentProduct) return null;
|
|
1052
|
-
var bundleItems = flattenBundleItems(parentProduct);
|
|
1053
|
-
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;
|
|
1054
|
-
if (isNonZeroId(bundleVariantId)) {
|
|
1055
|
-
var matchedByVariant = bundleItems.find(function (item) {
|
|
1056
|
-
var _ref43, _item$bundle_variant_;
|
|
1057
|
-
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);
|
|
1058
|
-
});
|
|
1059
|
-
if (matchedByVariant) return matchedByVariant;
|
|
1060
|
-
}
|
|
1061
|
-
var bundleId = (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id;
|
|
1062
|
-
if (isPresentId(bundleId)) {
|
|
1063
|
-
var matchedByBundleId = bundleItems.find(function (item) {
|
|
1064
|
-
var _item$id;
|
|
1065
|
-
return isSameId((_item$id = item.id) !== null && _item$id !== void 0 ? _item$id : item.bundle_id, bundleId);
|
|
1066
|
-
});
|
|
1067
|
-
if (matchedByBundleId) return matchedByBundleId;
|
|
1068
|
-
}
|
|
1069
|
-
var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
|
|
1070
|
-
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;
|
|
1071
|
-
if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
|
|
1072
|
-
var matchedByGroupAndProduct = bundleItems.find(function (item) {
|
|
1073
|
-
var _item$group_id, _ref45, _item$bundle_product_;
|
|
1074
|
-
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);
|
|
1075
|
-
});
|
|
1076
|
-
if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
|
|
1077
|
-
}
|
|
1078
|
-
if (isPresentId(bundleProductId)) {
|
|
1079
|
-
return bundleItems.find(function (item) {
|
|
1080
|
-
var _ref46, _item$bundle_product_2;
|
|
1081
|
-
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);
|
|
1082
|
-
}) || null;
|
|
1083
|
-
}
|
|
1084
|
-
return null;
|
|
1085
|
-
}
|
|
1086
|
-
function flattenBundleItems(parentProduct) {
|
|
1087
|
-
var bundleGroups = Array.isArray(parentProduct.bundle_group) ? parentProduct.bundle_group : [];
|
|
1088
|
-
return bundleGroups.flatMap(function (group) {
|
|
1089
|
-
var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
|
|
1090
|
-
return items.map(function (item) {
|
|
1091
|
-
var _ref47, _item$group_id2;
|
|
1092
|
-
return _objectSpread(_objectSpread({}, item), {}, {
|
|
1093
|
-
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
|
|
1094
|
-
});
|
|
1095
|
-
});
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
|
-
function isNonZeroId(value) {
|
|
1099
|
-
return isPresentId(value) && String(value) !== '0';
|
|
1100
|
-
}
|
|
1101
|
-
function isPresentId(value) {
|
|
1102
|
-
return value !== undefined && value !== null && value !== '';
|
|
1103
|
-
}
|
|
1104
|
-
function firstPresentValue() {
|
|
1105
|
-
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1106
|
-
values[_key] = arguments[_key];
|
|
1107
|
-
}
|
|
1108
|
-
return values.find(function (value) {
|
|
1109
|
-
return isPresentId(value);
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
function isSameId(left, right) {
|
|
1113
|
-
if (!isPresentId(left) || !isPresentId(right)) return false;
|
|
1114
|
-
return String(left) === String(right);
|
|
1115
|
-
}
|
|
1116
|
-
function formatBundlePrice(bundle, currencySymbol) {
|
|
1117
|
-
var _ref48, _ref49, _bundle$bundle_sellin;
|
|
1118
|
-
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;
|
|
1119
|
-
var amount = new Decimal(toMoneyNumber(value));
|
|
1120
|
-
// 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
|
|
1121
|
-
var isNegative = bundle.price_type === 'markdown';
|
|
1122
|
-
if (isNegative) return "-".concat(currencySymbol).concat(amount.abs().toFixed(2));
|
|
1123
|
-
return formatMoney(amount, currencySymbol);
|
|
1124
|
-
}
|
|
1125
|
-
function buildFees(params) {
|
|
1126
|
-
var _firstPresentValue2, _firstPresentValue3;
|
|
1127
|
-
var order = params.order,
|
|
1128
|
-
shopInfo = params.shopInfo,
|
|
1129
|
-
locale = params.locale,
|
|
1130
|
-
products = params.products,
|
|
1131
|
-
summary = params.summary,
|
|
1132
|
-
currencySymbol = params.currencySymbol,
|
|
1133
|
-
financials = params.financials;
|
|
1134
|
-
var fees = [];
|
|
1135
|
-
for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
|
|
1136
|
-
var _ref50, _surcharge$amount;
|
|
1137
|
-
var surcharge = _normalizeArray2[_i2];
|
|
1138
|
-
var value = (_ref50 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref50 !== void 0 ? _ref50 : surcharge.total_amount;
|
|
1139
|
-
if (!isNonZero(value)) continue;
|
|
1140
|
-
fees.push({
|
|
1141
|
-
item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
|
|
1142
|
-
value: formatMoney(value, currencySymbol)
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
|
-
var discountAmount = firstPresentValue(order.shop_discount, summary.discount_amount, order.discount_amount);
|
|
1146
|
-
if (isNonZero(discountAmount)) {
|
|
1147
|
-
fees.push({
|
|
1148
|
-
item: label(locale, 'orderDiscount'),
|
|
1149
|
-
value: formatNegativeMoney(discountAmount, currencySymbol)
|
|
1150
|
-
});
|
|
1151
|
-
}
|
|
1152
|
-
var taxFee = firstPresentValue(summary.tax_fee, order.tax_fee);
|
|
1153
|
-
var taxTitle = resolveTaxTitle({
|
|
1154
|
-
summary: summary,
|
|
1155
|
-
order: order,
|
|
1156
|
-
shopInfo: shopInfo,
|
|
1157
|
-
locale: locale
|
|
1158
|
-
});
|
|
1159
|
-
var isPriceIncludeTax = firstPresentValue(summary.is_price_include_tax, order.is_price_include_tax, shopInfo.is_price_include_tax);
|
|
1160
|
-
var roundingAmount = firstPresentValue(summary.rounding_amount, order.rounding_amount);
|
|
1161
|
-
var payProcessingFee = financials.payProcessingFee;
|
|
1162
|
-
if (isNonZero(payProcessingFee)) {
|
|
1163
|
-
fees.push({
|
|
1164
|
-
item: label(locale, 'payProcessingFee'),
|
|
1165
|
-
value: formatMoney(payProcessingFee, currencySymbol)
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
var productExpectAmount = firstPresentValue(summary.product_expect_amount, summary.product_amount, order.product_expect_amount);
|
|
1169
|
-
var productOriginalAmount = (_firstPresentValue2 = firstPresentValue(summary.product_original_amount, order.product_original_amount)) !== null && _firstPresentValue2 !== void 0 ? _firstPresentValue2 : calculateProductOriginalAmount(order);
|
|
1170
|
-
var totalSavingsAmount = new Decimal(toMoneyNumber(productOriginalAmount)).minus(toMoneyNumber(productExpectAmount)).plus(toMoneyNumber(discountAmount));
|
|
1171
|
-
var itemDiscountAmount = new Decimal(toMoneyNumber(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0)).minus(toMoneyNumber(productOriginalAmount));
|
|
1172
|
-
return {
|
|
1173
|
-
fees: fees,
|
|
1174
|
-
countFee: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
1175
|
-
total_amount: formatMoney((_firstPresentValue3 = firstPresentValue(summary.total_amount, order.total_amount)) !== null && _firstPresentValue3 !== void 0 ? _firstPresentValue3 : 0, currencySymbol),
|
|
1176
|
-
original_item_amount: formatMoney(productOriginalAmount, currencySymbol),
|
|
1177
|
-
product_expect_amount: formatMoney(productExpectAmount !== null && productExpectAmount !== void 0 ? productExpectAmount : 0, currencySymbol),
|
|
1178
|
-
item_discount_amount: formatCalculatedMoney(itemDiscountAmount, currencySymbol),
|
|
1179
|
-
expect_amount: formatMoney(financials.totalAmount, currencySymbol),
|
|
1180
|
-
product_quantity: toNumber(firstPresentValue(summary.product_quantity, products.reduce(function (sum, product) {
|
|
1181
|
-
return sum + product.product_quantity;
|
|
1182
|
-
}, 0)), 0),
|
|
1183
|
-
has_pay: formatMoney(financials.orderPaidAmount, currencySymbol),
|
|
1184
|
-
payment_method: '',
|
|
1185
|
-
tax_title: taxTitle,
|
|
1186
|
-
total_refund_amount: formatMoney(financials.totalRefundAmount, currencySymbol),
|
|
1187
|
-
customer_paid_amount: formatMoney(financials.customerPaidAmount, currencySymbol),
|
|
1188
|
-
net_payment_applied: formatMoney(financials.netPaymentApplied, currencySymbol)
|
|
1189
|
-
}, isPresentId(roundingAmount) ? {
|
|
1190
|
-
rounding_amount: formatMoney(roundingAmount, currencySymbol)
|
|
1191
|
-
} : {}), isNonZero(totalSavingsAmount) ? {
|
|
1192
|
-
order_total_discount: formatMoney(totalSavingsAmount, currencySymbol)
|
|
1193
|
-
} : {}), financials.hasPayProcessingFee ? {
|
|
1194
|
-
pay_processing_fee: formatMoney(payProcessingFee, currencySymbol)
|
|
1195
|
-
} : {}), isPresentId(taxFee) ? {
|
|
1196
|
-
tax_fee: formatMoney(taxFee, currencySymbol)
|
|
1197
|
-
} : {}), isPresentId(isPriceIncludeTax) ? {
|
|
1198
|
-
is_price_include_tax: normalizeBooleanFlag(isPriceIncludeTax)
|
|
1199
|
-
} : {})
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
function resolveReceiptFinancials(order, summary) {
|
|
1203
|
-
var _firstPresentValue4, _firstPresentValue5, _firstPresentValue6, _firstPresentValue7;
|
|
1204
|
-
var totalAmount = (_firstPresentValue4 = firstPresentValue(summary.expect_amount, order.expect_amount, summary.total_amount, order.total_amount)) !== null && _firstPresentValue4 !== void 0 ? _firstPresentValue4 : 0;
|
|
1205
|
-
var rawPayProcessingFee = firstPresentValue(summary.pay_service_charge_amount, order.pay_service_charge_amount);
|
|
1206
|
-
var payProcessingFee = rawPayProcessingFee !== null && rawPayProcessingFee !== void 0 ? rawPayProcessingFee : 0;
|
|
1207
|
-
var orderPaidAmount = (_firstPresentValue5 = firstPresentValue(summary.order_paid_amount, order.order_paid_amount, sumAppliedPayments(order.payments))) !== null && _firstPresentValue5 !== void 0 ? _firstPresentValue5 : 0;
|
|
1208
|
-
var totalRefundAmount = (_firstPresentValue6 = firstPresentValue(summary.total_refund_amount, order.total_refund_amount)) !== null && _firstPresentValue6 !== void 0 ? _firstPresentValue6 : 0;
|
|
1209
|
-
var netPaymentApplied = Decimal.max(new Decimal(toMoneyNumber(orderPaidAmount)).minus(toMoneyNumber(totalRefundAmount)), 0);
|
|
1210
|
-
var fallbackCustomerPaidAmount = Decimal.max(sumCustomerPaidPayments(order.payments), new Decimal(toMoneyNumber(orderPaidAmount)).plus(toMoneyNumber(payProcessingFee)));
|
|
1211
|
-
var customerPaidAmount = (_firstPresentValue7 = firstPresentValue(summary.customer_paid_amount, order.customer_paid_amount, fallbackCustomerPaidAmount)) !== null && _firstPresentValue7 !== void 0 ? _firstPresentValue7 : 0;
|
|
1212
|
-
var amountGap = firstPresentValue(summary.amount_gap, order.amount_gap);
|
|
1213
|
-
return {
|
|
1214
|
-
totalAmount: totalAmount,
|
|
1215
|
-
orderPaidAmount: orderPaidAmount,
|
|
1216
|
-
payProcessingFee: payProcessingFee,
|
|
1217
|
-
customerPaidAmount: customerPaidAmount,
|
|
1218
|
-
totalRefundAmount: totalRefundAmount,
|
|
1219
|
-
netPaymentApplied: netPaymentApplied,
|
|
1220
|
-
amountGap: amountGap,
|
|
1221
|
-
paymentStatus: resolveReceiptPaymentStatus({
|
|
1222
|
-
order: order,
|
|
1223
|
-
summary: summary
|
|
1224
|
-
}),
|
|
1225
|
-
hasPayProcessingFee: isPresentId(rawPayProcessingFee)
|
|
1226
|
-
};
|
|
1227
|
-
}
|
|
1228
|
-
function resolveReceiptPaymentStatus(params) {
|
|
1229
|
-
return [params.order.payment_status, params.summary.payment_status, params.order.original_payment_status].map(function (status) {
|
|
1230
|
-
return stringify(status).trim();
|
|
1231
|
-
}).find(Boolean) || '';
|
|
1232
|
-
}
|
|
1233
|
-
function resolveTaxTitle(params) {
|
|
1234
|
-
return [params.summary.tax_title, params.order.tax_title, params.shopInfo.tax_title].map(function (title) {
|
|
1235
|
-
return getLocalizedValue(title, params.locale).trim();
|
|
1236
|
-
}).find(Boolean) || 'Tax';
|
|
1237
|
-
}
|
|
1238
|
-
function calculateProductOriginalAmount(order) {
|
|
1239
|
-
return normalizeArray(order.products).reduce(function (total, product) {
|
|
1240
|
-
var _ref51, _ref52, _product$product_quan3, _ref53, _ref54, _ref55, _product$original_pri2;
|
|
1241
|
-
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);
|
|
1242
|
-
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;
|
|
1243
|
-
return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
|
|
1244
|
-
}, new Decimal(0));
|
|
1245
|
-
}
|
|
1246
|
-
function buildCustomer(order, locale) {
|
|
1247
|
-
var _order$customer, _order$customer2, _order$customer3, _order$customer4;
|
|
1248
|
-
return [{
|
|
1249
|
-
item: label(locale, 'contactName'),
|
|
1250
|
-
value: normalizeCustomerDisplayValue(order.customer_name || ((_order$customer = order.customer) === null || _order$customer === void 0 ? void 0 : _order$customer.name) || ((_order$customer2 = order.customer) === null || _order$customer2 === void 0 ? void 0 : _order$customer2.display_name))
|
|
1251
|
-
}, {
|
|
1252
|
-
item: label(locale, 'contactMobile'),
|
|
1253
|
-
value: stringify(order.phone || ((_order$customer3 = order.customer) === null || _order$customer3 === void 0 ? void 0 : _order$customer3.phone))
|
|
1254
|
-
}, {
|
|
1255
|
-
item: label(locale, 'email'),
|
|
1256
|
-
value: stringify(order.email || ((_order$customer4 = order.customer) === null || _order$customer4 === void 0 ? void 0 : _order$customer4.email))
|
|
1257
|
-
}];
|
|
1258
|
-
}
|
|
1259
|
-
function normalizeCustomerDisplayValue(value) {
|
|
1260
|
-
var text = stringify(value).trim();
|
|
1261
|
-
if (!text) return 'Walk-In';
|
|
1262
|
-
if (text.toLowerCase() === 'select a customer') return 'Walk-In';
|
|
1263
|
-
return text;
|
|
1264
|
-
}
|
|
1265
|
-
function buildDelivery(order, locale) {
|
|
1266
|
-
var _order$metadata2, _order$metadata3, _order$metadata4, _order$metadata5, _order$metadata6, _order$metadata7, _order$metadata8, _order$metadata9, _order$metadata10, _order$metadata11, _order$metadata12;
|
|
1267
|
-
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();
|
|
1268
|
-
var serviceTypeLabelKey = resolveServiceTypeLabelKey(serviceType);
|
|
1269
|
-
if (!serviceTypeLabelKey) return [];
|
|
1270
|
-
var items = [{
|
|
1271
|
-
item: label(locale, serviceTypeLabelKey),
|
|
1272
|
-
value: '',
|
|
1273
|
-
size: 2
|
|
1274
|
-
}];
|
|
1275
|
-
if (serviceType === 'pick_up') {
|
|
1276
|
-
var pickupTime = formatPickupBookingStart(order.bookings, locale);
|
|
1277
|
-
if (pickupTime) {
|
|
1278
|
-
items.push({
|
|
1279
|
-
item: pickupTime,
|
|
1280
|
-
value: '',
|
|
1281
|
-
size: 2
|
|
1282
|
-
});
|
|
1283
|
-
return items;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
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);
|
|
1287
|
-
if (isPresentId(handoverTime)) {
|
|
1288
|
-
items.push({
|
|
1289
|
-
item: label(locale, 'handoverTime'),
|
|
1290
|
-
value: formatDateTime(handoverTime, locale)
|
|
1291
|
-
});
|
|
1292
|
-
}
|
|
1293
|
-
return items;
|
|
1294
|
-
}
|
|
1295
|
-
function formatPickupBookingStart(bookings, locale) {
|
|
1296
|
-
var booking = normalizeArray(bookings).find(isFulfillmentTimingBooking);
|
|
1297
|
-
var date = stringify(booking === null || booking === void 0 ? void 0 : booking.start_date).trim();
|
|
1298
|
-
var time = stringify(booking === null || booking === void 0 ? void 0 : booking.start_time).trim();
|
|
1299
|
-
if (!/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/.test(date) || !/^([01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(time)) {
|
|
1300
|
-
return '';
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
// Validate only the calendar date in UTC; display the stored shop-local
|
|
1304
|
-
// fields verbatim so the printing device's timezone cannot shift pickup.
|
|
1305
|
-
var calendarDate = new Date("".concat(date, "T00:00:00.000Z"));
|
|
1306
|
-
if (!Number.isFinite(calendarDate.getTime()) || calendarDate.toISOString().slice(0, 10) !== date) {
|
|
1307
|
-
return '';
|
|
1308
|
-
}
|
|
1309
|
-
var _date$split = date.split('-'),
|
|
1310
|
-
_date$split2 = _slicedToArray(_date$split, 3),
|
|
1311
|
-
year = _date$split2[0],
|
|
1312
|
-
month = _date$split2[1],
|
|
1313
|
-
day = _date$split2[2];
|
|
1314
|
-
var dateText = locale === 'en' ? "".concat(day, "/").concat(month, "/").concat(year) : "".concat(year, "/").concat(month, "/").concat(day);
|
|
1315
|
-
return "".concat(time.slice(0, 5), " ").concat(dateText);
|
|
1316
|
-
}
|
|
1317
|
-
function buildAppointment(order, locale) {
|
|
1318
|
-
var _order$metadata13, _order$metadata14, _order$metadata15, _order$form_data;
|
|
1319
|
-
var parentScheduleId = (_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.appointment_booking_parent_schedule_id;
|
|
1320
|
-
var bookings = sortBookings(normalizeArray(order.bookings).filter(function (booking) {
|
|
1321
|
-
return !isFulfillmentTimingBooking(booking) && isReceiptAppointmentBooking(booking, parentScheduleId);
|
|
1322
|
-
}));
|
|
1323
|
-
if (bookings.length) {
|
|
1324
|
-
var allResources = normalizeArray(order.resources || order.resource_list);
|
|
1325
|
-
return bookings.flatMap(function (booking) {
|
|
1326
|
-
return buildAppointmentRows({
|
|
1327
|
-
booking: booking,
|
|
1328
|
-
allResources: allResources,
|
|
1329
|
-
bookingCount: bookings.length,
|
|
1330
|
-
locale: locale
|
|
1331
|
-
});
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
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);
|
|
1335
|
-
if (!tableName) return [];
|
|
1336
|
-
return [{
|
|
1337
|
-
item: label(locale, 'table'),
|
|
1338
|
-
value: getLocalizedValue(tableName, locale)
|
|
1339
|
-
}];
|
|
1340
|
-
}
|
|
1341
|
-
function isReceiptAppointmentBooking(booking, parentScheduleId) {
|
|
1342
|
-
if (!booking || _typeof(booking) !== 'object' || Array.isArray(booking)) {
|
|
1343
|
-
return false;
|
|
1344
|
-
}
|
|
1345
|
-
if (isPresentId(parentScheduleId) && isSameId(booking.schedule_event_id, parentScheduleId)) {
|
|
1346
|
-
return false;
|
|
1347
|
-
}
|
|
1348
|
-
var parentId = booking.parent_id;
|
|
1349
|
-
if (parentId === undefined || parentId === null || parentId === '') {
|
|
1350
|
-
return true;
|
|
1351
|
-
}
|
|
1352
|
-
return Number(parentId) !== 0;
|
|
1353
|
-
}
|
|
1354
|
-
function buildAppointmentRows(params) {
|
|
1355
|
-
var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
|
|
1356
|
-
var booking = params.booking,
|
|
1357
|
-
allResources = params.allResources,
|
|
1358
|
-
bookingCount = params.bookingCount,
|
|
1359
|
-
locale = params.locale;
|
|
1360
|
-
var productUid = stringify(firstPresentValue(booking.product_uid, (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid)).trim();
|
|
1361
|
-
var bookingUid = stringify(firstPresentValue((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.unique_identification_number, booking.booking_uid)).trim();
|
|
1362
|
-
var association = {
|
|
1363
|
-
product_uid: productUid,
|
|
1364
|
-
booking_uid: bookingUid
|
|
1365
|
-
};
|
|
1366
|
-
var bookingId = stringify(firstPresentValue(booking.booking_id, booking.schedule_event_id, bookingUid)).trim();
|
|
1367
|
-
var bookingTime = formatBookingRange(booking, locale);
|
|
1368
|
-
var resourceText = formatBookingResources(resolveBookingResourcesForReceipt(booking, allResources, bookingCount), locale);
|
|
1369
|
-
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();
|
|
1370
|
-
return [_objectSpread({
|
|
1371
|
-
item: label(locale, 'bookingId'),
|
|
1372
|
-
value: bookingId
|
|
1373
|
-
}, association), _objectSpread({
|
|
1374
|
-
item: label(locale, 'bookingDateTime'),
|
|
1375
|
-
value: bookingTime
|
|
1376
|
-
}, association), _objectSpread({
|
|
1377
|
-
item: label(locale, 'bookingResource'),
|
|
1378
|
-
value: resourceText
|
|
1379
|
-
}, association), _objectSpread({
|
|
1380
|
-
item: label(locale, 'bookingHolder'),
|
|
1381
|
-
value: holder
|
|
1382
|
-
}, association)].filter(function (row) {
|
|
1383
|
-
return Boolean(row.value);
|
|
1384
|
-
});
|
|
1385
|
-
}
|
|
1386
|
-
function formatBookingRange(booking, locale) {
|
|
1387
|
-
var startDate = stringify(booking.start_date);
|
|
1388
|
-
var startTime = stringify(booking.start_time);
|
|
1389
|
-
var endDate = stringify(booking.end_date || startDate);
|
|
1390
|
-
var endTime = stringify(booking.end_time);
|
|
1391
|
-
var start = firstValidBookingDate(booking.start_at, booking.start_datetime, booking.start_date_time, "".concat(startDate, " ").concat(startTime).trim());
|
|
1392
|
-
var end = firstValidBookingDate(booking.end_at, booking.end_datetime, booking.end_date_time, endTime ? "".concat(endDate, " ").concat(endTime).trim() : '');
|
|
1393
|
-
if (!start) {
|
|
1394
|
-
return [startDate, startTime, endTime ? "- ".concat(endDate, " ").concat(endTime) : ''].filter(Boolean).join(' ');
|
|
1395
|
-
}
|
|
1396
|
-
var dateFormat = locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD';
|
|
1397
|
-
var startText = start.format("".concat(dateFormat, " HH:mm"));
|
|
1398
|
-
if (!end) return startText;
|
|
1399
|
-
return "".concat(startText, " - ").concat(end.isSame(start, 'day') ? end.format('HH:mm') : end.format("".concat(dateFormat, " HH:mm")));
|
|
1400
|
-
}
|
|
1401
|
-
function firstValidBookingDate() {
|
|
1402
|
-
for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1403
|
-
values[_key2] = arguments[_key2];
|
|
1404
|
-
}
|
|
1405
|
-
for (var _i3 = 0, _values = values; _i3 < _values.length; _i3++) {
|
|
1406
|
-
var value = _values[_i3];
|
|
1407
|
-
if (!isPresentId(value)) continue;
|
|
1408
|
-
var parsed = dayjs(value);
|
|
1409
|
-
if (parsed.isValid()) return parsed;
|
|
1410
|
-
}
|
|
1411
|
-
return null;
|
|
1412
|
-
}
|
|
1413
|
-
function resolveBookingResourcesForReceipt(booking, allResources, bookingCount) {
|
|
1414
|
-
var _booking$metadata4;
|
|
1415
|
-
var embedded = normalizeArray(booking.resources).filter(function (resource) {
|
|
1416
|
-
return Boolean(resource) && _typeof(resource) === 'object' && !Array.isArray(resource);
|
|
1417
|
-
});
|
|
1418
|
-
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) {
|
|
1419
|
-
return stringify(value).trim();
|
|
1420
|
-
}).filter(Boolean));
|
|
1421
|
-
var _iterator3 = _createForOfIteratorHelper(embedded),
|
|
1422
|
-
_step3;
|
|
1423
|
-
try {
|
|
1424
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1425
|
-
var _ref57, _resource$id2;
|
|
1426
|
-
var resource = _step3.value;
|
|
1427
|
-
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();
|
|
1428
|
-
if (id) resourceIds.add(id);
|
|
1429
|
-
}
|
|
1430
|
-
} catch (err) {
|
|
1431
|
-
_iterator3.e(err);
|
|
1432
|
-
} finally {
|
|
1433
|
-
_iterator3.f();
|
|
1434
|
-
}
|
|
1435
|
-
if (resourceIds.size) {
|
|
1436
|
-
var matched = allResources.filter(function (resource) {
|
|
1437
|
-
var _ref56, _resource$id;
|
|
1438
|
-
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());
|
|
1439
|
-
});
|
|
1440
|
-
if (matched.length) return matched;
|
|
1441
|
-
}
|
|
1442
|
-
if (embedded.length) return embedded;
|
|
1443
|
-
if (bookingCount === 1 && allResources.length) return allResources;
|
|
1444
|
-
return [];
|
|
1445
|
-
}
|
|
1446
|
-
function formatBookingResources(resources, locale) {
|
|
1447
|
-
return resources.map(function (resource) {
|
|
1448
|
-
var _resource$metadata, _resource$metadata2, _resource$metadata3, _resource$metadata4;
|
|
1449
|
-
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(' ');
|
|
1450
|
-
}).filter(Boolean).join(', ');
|
|
1451
|
-
}
|
|
1452
|
-
function sortBookings(bookings) {
|
|
1453
|
-
return bookings.map(function (booking, index) {
|
|
1454
|
-
return {
|
|
1455
|
-
booking: booking,
|
|
1456
|
-
index: index
|
|
1457
|
-
};
|
|
1458
|
-
}).sort(function (left, right) {
|
|
1459
|
-
var _left$booking2, _left$booking3, _right$booking2, _right$booking3;
|
|
1460
|
-
var leftStart = bookingStartTimestamp(left.booking);
|
|
1461
|
-
var rightStart = bookingStartTimestamp(right.booking);
|
|
1462
|
-
if (leftStart !== rightStart) return leftStart < rightStart ? -1 : 1;
|
|
1463
|
-
for (var _i4 = 0, _arr = ['booking_id', 'schedule_event_id']; _i4 < _arr.length; _i4++) {
|
|
1464
|
-
var _left$booking, _right$booking;
|
|
1465
|
-
var field = _arr[_i4];
|
|
1466
|
-
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]);
|
|
1467
|
-
if (fieldOrder !== 0) return fieldOrder;
|
|
1468
|
-
}
|
|
1469
|
-
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));
|
|
1470
|
-
return bookingUidOrder || left.index - right.index;
|
|
1471
|
-
}).map(function (_ref58) {
|
|
1472
|
-
var booking = _ref58.booking;
|
|
1473
|
-
return booking;
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
function bookingStartTimestamp(booking) {
|
|
1477
|
-
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];
|
|
1478
|
-
for (var _i5 = 0, _startValues = startValues; _i5 < _startValues.length; _i5++) {
|
|
1479
|
-
var startValue = _startValues[_i5];
|
|
1480
|
-
if (!isPresentId(startValue)) continue;
|
|
1481
|
-
var timestamp = dayjs(startValue).valueOf();
|
|
1482
|
-
if (Number.isFinite(timestamp)) return timestamp;
|
|
1483
|
-
}
|
|
1484
|
-
return Number.POSITIVE_INFINITY;
|
|
1485
|
-
}
|
|
1486
|
-
function compareOptionalValues(left, right) {
|
|
1487
|
-
var hasLeft = isPresentId(left);
|
|
1488
|
-
var hasRight = isPresentId(right);
|
|
1489
|
-
if (!hasLeft && !hasRight) return 0;
|
|
1490
|
-
if (!hasLeft) return 1;
|
|
1491
|
-
if (!hasRight) return -1;
|
|
1492
|
-
return String(left).localeCompare(String(right), undefined, {
|
|
1493
|
-
numeric: true
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
function buildResources(order, locale) {
|
|
1497
|
-
return normalizeArray(order.resources || order.resource_list).map(function (resource) {
|
|
1498
|
-
return {
|
|
1499
|
-
id: resource.id || resource.resource_id || '',
|
|
1500
|
-
code: '',
|
|
1501
|
-
title: getLocalizedValue(resource.title || resource.name, locale),
|
|
1502
|
-
form_title: getLocalizedValue(resource.form_title || resource.type || '', locale)
|
|
1503
|
-
};
|
|
1504
|
-
});
|
|
1505
|
-
}
|
|
1506
|
-
function buildPaymentData(params) {
|
|
1507
|
-
var payments = normalizeArray(params.order.payments);
|
|
1508
|
-
return payments.filter(function (payment) {
|
|
1509
|
-
return isPrintablePayment(payment);
|
|
1510
|
-
}).map(function (payment) {
|
|
1511
|
-
return buildPaymentItems({
|
|
1512
|
-
payment: payment,
|
|
1513
|
-
locale: params.locale,
|
|
1514
|
-
currencySymbol: params.currencySymbol,
|
|
1515
|
-
includeFundRecordBalance: false,
|
|
1516
|
-
includeFundRecordUsage: true,
|
|
1517
|
-
includePaymentAmount: true
|
|
1518
|
-
});
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1521
|
-
function buildRefundData(params) {
|
|
1522
|
-
var payments = normalizeArray(params.order.payments);
|
|
1523
|
-
var refunds = Array.from(normalizeArray(params.order.refunds).reduce(function (result, refund, index) {
|
|
1524
|
-
var identity = refundIdentity(refund, index);
|
|
1525
|
-
var candidate = {
|
|
1526
|
-
refund: refund,
|
|
1527
|
-
index: index
|
|
1528
|
-
};
|
|
1529
|
-
var existing = result.get(identity);
|
|
1530
|
-
if (!existing || shouldPreferRefundCandidate(candidate, existing)) {
|
|
1531
|
-
result.set(identity, candidate);
|
|
1532
|
-
}
|
|
1533
|
-
return result;
|
|
1534
|
-
}, new Map()).values()).filter(function (_ref59) {
|
|
1535
|
-
var refund = _ref59.refund;
|
|
1536
|
-
return isPrintableRefund(refund);
|
|
1537
|
-
}).sort(function (left, right) {
|
|
1538
|
-
var leftTime = refundTimestamp(left.refund);
|
|
1539
|
-
var rightTime = refundTimestamp(right.refund);
|
|
1540
|
-
if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
|
|
1541
|
-
return left.index - right.index;
|
|
1542
|
-
});
|
|
1543
|
-
return refunds.map(function (_ref60) {
|
|
1544
|
-
var _firstPresentValue8;
|
|
1545
|
-
var refund = _ref60.refund;
|
|
1546
|
-
var payment = resolveRefundPayment(refund, payments);
|
|
1547
|
-
var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
|
|
1548
|
-
var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
|
|
1549
|
-
var items = [{
|
|
1550
|
-
item: methodName,
|
|
1551
|
-
value: formatNegativeMoney(amount, params.currencySymbol)
|
|
1552
|
-
}];
|
|
1553
|
-
var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
|
|
1554
|
-
if (isPresentId(occurredAt)) {
|
|
1555
|
-
items.push({
|
|
1556
|
-
item: formatDateTime(occurredAt, params.locale),
|
|
1557
|
-
value: ''
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
return items;
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
function refundIdentity(refund, index) {
|
|
1564
|
-
if (isPresentId(refund.order_refund_id)) return "refund-id:".concat(refund.order_refund_id);
|
|
1565
|
-
if (isPresentId(refund.refund_number)) return "refund-number:".concat(refund.refund_number);
|
|
1566
|
-
return "refund-index:".concat(index);
|
|
1567
|
-
}
|
|
1568
|
-
function shouldPreferRefundCandidate(candidate, existing) {
|
|
1569
|
-
var candidatePrintable = isPrintableRefund(candidate.refund);
|
|
1570
|
-
var existingPrintable = isPrintableRefund(existing.refund);
|
|
1571
|
-
if (candidatePrintable !== existingPrintable) return candidatePrintable;
|
|
1572
|
-
var candidateTime = refundFreshnessTimestamp(candidate.refund);
|
|
1573
|
-
var existingTime = refundFreshnessTimestamp(existing.refund);
|
|
1574
|
-
if (candidateTime !== existingTime) return candidateTime > existingTime;
|
|
1575
|
-
return candidate.index > existing.index;
|
|
1576
|
-
}
|
|
1577
|
-
function refundFreshnessTimestamp(refund) {
|
|
1578
|
-
var timestampValue = firstPresentValue(refund.updated_at, refund.refunded_at, refund.refund_time, refund.created_at);
|
|
1579
|
-
if (!isPresentId(timestampValue)) return Number.NEGATIVE_INFINITY;
|
|
1580
|
-
var timestamp = dayjs(timestampValue).valueOf();
|
|
1581
|
-
return Number.isFinite(timestamp) ? timestamp : Number.NEGATIVE_INFINITY;
|
|
1582
|
-
}
|
|
1583
|
-
function refundTimestamp(refund) {
|
|
1584
|
-
var occurredAt = firstPresentValue(refund.refund_time, refund.refunded_at, refund.created_at, refund.updated_at);
|
|
1585
|
-
if (!isPresentId(occurredAt)) return Number.POSITIVE_INFINITY;
|
|
1586
|
-
var timestamp = dayjs(occurredAt).valueOf();
|
|
1587
|
-
return Number.isFinite(timestamp) ? timestamp : Number.POSITIVE_INFINITY;
|
|
1588
|
-
}
|
|
1589
|
-
function isPrintableRefund(refund) {
|
|
1590
|
-
var status = stringify(refund.status).trim().toLowerCase();
|
|
1591
|
-
if (!status) return true;
|
|
1592
|
-
return !['pending', 'payment_pending', 'payment_processing', 'refund_processing', 'processing', 'failed', 'error', 'cancelled', 'canceled', 'voided'].includes(status);
|
|
1593
|
-
}
|
|
1594
|
-
function resolveRefundPayment(refund, payments) {
|
|
1595
|
-
if (refund.payment && _typeof(refund.payment) === 'object' && !Array.isArray(refund.payment)) {
|
|
1596
|
-
return refund.payment;
|
|
1597
|
-
}
|
|
1598
|
-
var orderPaymentId = firstPresentValue(refund.order_payment_id, refund.payment_id);
|
|
1599
|
-
var matchedPayment = payments.find(function (payment) {
|
|
1600
|
-
return isSameId(firstPresentValue(payment.order_payment_id, payment.id), orderPaymentId);
|
|
1601
|
-
});
|
|
1602
|
-
return matchedPayment || refund;
|
|
1603
|
-
}
|
|
1604
|
-
function buildWallets(params) {
|
|
1605
|
-
var virtualCurrencySnapshots = collectVirtualCurrencySnapshots(params.order);
|
|
1606
|
-
var displayedWalletPayments = normalizeArray(params.order.payments).filter(function (payment) {
|
|
1607
|
-
return isPrintablePayment(payment) && !!getFundRecord(payment);
|
|
1608
|
-
});
|
|
1609
|
-
var paymentWallets = displayedWalletPayments.map(function (payment) {
|
|
1610
|
-
var virtualCurrencySnapshot = findVirtualCurrencySnapshotForPayment(payment, virtualCurrencySnapshots.byId);
|
|
1611
|
-
return buildPaymentItems({
|
|
1612
|
-
payment: payment,
|
|
1613
|
-
locale: params.locale,
|
|
1614
|
-
currencySymbol: params.currencySymbol,
|
|
1615
|
-
includeFundRecordBalance: true,
|
|
1616
|
-
includeFundRecordUsage: false,
|
|
1617
|
-
includePaymentAmount: false,
|
|
1618
|
-
virtualCurrencyUnit: virtualCurrencySnapshot ? getVirtualCurrencySnapshotUnit(virtualCurrencySnapshot, params.locale) : undefined
|
|
1619
|
-
});
|
|
1620
|
-
});
|
|
1621
|
-
var displayedWalletAssetIdentities = collectDisplayedWalletAssetIdentities(displayedWalletPayments);
|
|
1622
|
-
var voucherWallets = buildVoucherAssets(_objectSpread(_objectSpread({}, params), {}, {
|
|
1623
|
-
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1624
|
-
}));
|
|
1625
|
-
var productDiscountWallets = buildProductDiscountAssets(_objectSpread(_objectSpread({}, params), {}, {
|
|
1626
|
-
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1627
|
-
}));
|
|
1628
|
-
return [].concat(_toConsumableArray(paymentWallets), voucherWallets, productDiscountWallets, _toConsumableArray(buildPointCardSnapshotAssets({
|
|
1629
|
-
order: params.order,
|
|
1630
|
-
locale: params.locale,
|
|
1631
|
-
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1632
|
-
})), _toConsumableArray(buildVirtualCurrencySnapshotAssets({
|
|
1633
|
-
snapshots: virtualCurrencySnapshots.items,
|
|
1634
|
-
order: params.order,
|
|
1635
|
-
locale: params.locale,
|
|
1636
|
-
displayedWalletAssetIdentities: displayedWalletAssetIdentities
|
|
1637
|
-
})));
|
|
1638
|
-
}
|
|
1639
|
-
function collectDisplayedWalletAssetIdentities(payments) {
|
|
1640
|
-
var identities = [];
|
|
1641
|
-
payments.forEach(function (payment) {
|
|
1642
|
-
var fundRecord = getFundRecord(payment);
|
|
1643
|
-
var ids = Array.from(new Set([fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id].map(function (value) {
|
|
1644
|
-
return normalizeWalletPassId(value);
|
|
1645
|
-
}).filter(function (value) {
|
|
1646
|
-
return !!value;
|
|
1647
|
-
})));
|
|
1648
|
-
var codes = normalizeWalletAssetCodes(fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.encoded);
|
|
1649
|
-
if (!ids.length) {
|
|
1650
|
-
registerWalletAssetIdentity(identities, {
|
|
1651
|
-
id: null,
|
|
1652
|
-
codes: codes
|
|
1653
|
-
});
|
|
1654
|
-
return;
|
|
1655
|
-
}
|
|
1656
|
-
ids.forEach(function (id) {
|
|
1657
|
-
registerWalletAssetIdentity(identities, {
|
|
1658
|
-
id: id,
|
|
1659
|
-
codes: codes
|
|
1660
|
-
});
|
|
1661
|
-
});
|
|
1662
|
-
});
|
|
1663
|
-
return identities;
|
|
1664
|
-
}
|
|
1665
|
-
var PRODUCT_WALLET_DISCOUNT_TYPES = new Set(['good_pass', 'discount_card', 'product_discount_card', 'entitlement_pass']);
|
|
1666
|
-
function buildProductDiscountAssets(params) {
|
|
1667
|
-
var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1668
|
-
return collectProductWalletDiscountAssets(params.order).flatMap(function (asset) {
|
|
1669
|
-
var _getProductWalletDisc;
|
|
1670
|
-
if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
|
|
1671
|
-
id: asset.id,
|
|
1672
|
-
codes: asset.codes
|
|
1673
|
-
})) return [];
|
|
1674
|
-
var name = getProductWalletDiscountName(asset, params.locale);
|
|
1675
|
-
var assetTime = (_getProductWalletDisc = getProductWalletDiscountTime(asset)) !== null && _getProductWalletDisc !== void 0 ? _getProductWalletDisc : fallbackAssetTime;
|
|
1676
|
-
var timeRow = isPresentId(assetTime) ? {
|
|
1677
|
-
item: formatDateTime(assetTime, params.locale),
|
|
1678
|
-
value: ''
|
|
1679
|
-
} : null;
|
|
1680
|
-
if (asset.type === 'entitlement_pass') {
|
|
1681
|
-
var remaining = getProductEntitlementBalance(asset);
|
|
1682
|
-
return [[{
|
|
1683
|
-
item: name,
|
|
1684
|
-
value: ''
|
|
1685
|
-
}].concat(_toConsumableArray(remaining ? [{
|
|
1686
|
-
item: label(params.locale, 'entitlementRemaining'),
|
|
1687
|
-
value: formatEntitlementUses(remaining, params.locale)
|
|
1688
|
-
}] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1689
|
-
}
|
|
1690
|
-
var percent = getProductWalletDiscountPercent(asset);
|
|
1691
|
-
if (percent) {
|
|
1692
|
-
return [[{
|
|
1693
|
-
item: appendPercentToVoucherName(name, percent),
|
|
1694
|
-
value: formatVoucherDiscount(percent, params.locale)
|
|
1695
|
-
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1696
|
-
}
|
|
1697
|
-
var balance = getProductWalletMoneyBalance(asset);
|
|
1698
|
-
return [[{
|
|
1699
|
-
item: name,
|
|
1700
|
-
value: ''
|
|
1701
|
-
}].concat(_toConsumableArray(balance ? [{
|
|
1702
|
-
item: label(params.locale, 'balance'),
|
|
1703
|
-
value: formatMoney(balance, params.currencySymbol)
|
|
1704
|
-
}] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
|
|
1705
|
-
});
|
|
1706
|
-
}
|
|
1707
|
-
function collectProductWalletDiscountAssets(order) {
|
|
1708
|
-
var assets = [];
|
|
1709
|
-
var assetsById = new Map();
|
|
1710
|
-
normalizeArray(order.products).forEach(function (rawProduct) {
|
|
1711
|
-
if (!rawProduct || _typeof(rawProduct) !== 'object') return;
|
|
1712
|
-
visitProductWalletDiscounts(restoreReceiptDiscountHierarchy(rawProduct), assets, assetsById);
|
|
1713
|
-
});
|
|
1714
|
-
return assets;
|
|
1715
|
-
}
|
|
1716
|
-
function visitProductWalletDiscounts(product, assets, assetsById) {
|
|
1717
|
-
normalizeArray(product.discount_list).forEach(function (record) {
|
|
1718
|
-
if (!record || _typeof(record) !== 'object' || Array.isArray(record)) return;
|
|
1719
|
-
var type = getProductWalletDiscountType(record);
|
|
1720
|
-
if (!type) return;
|
|
1721
|
-
var id = getProductWalletDiscountAssetId(record);
|
|
1722
|
-
if (!id) return;
|
|
1723
|
-
var codes = getProductWalletDiscountCodes(record);
|
|
1724
|
-
var existing = assetsById.get(id);
|
|
1725
|
-
if (existing) {
|
|
1726
|
-
existing.records.push(record);
|
|
1727
|
-
existing.codes = Array.from(new Set([].concat(_toConsumableArray(existing.codes), codes)));
|
|
1728
|
-
return;
|
|
1729
|
-
}
|
|
1730
|
-
var asset = {
|
|
1731
|
-
id: id,
|
|
1732
|
-
type: type,
|
|
1733
|
-
codes: codes,
|
|
1734
|
-
records: [record]
|
|
1735
|
-
};
|
|
1736
|
-
assetsById.set(id, asset);
|
|
1737
|
-
assets.push(asset);
|
|
1738
|
-
});
|
|
1739
|
-
for (var _i6 = 0, _arr2 = ['combinations', 'product_bundle', 'bundle']; _i6 < _arr2.length; _i6++) {
|
|
1740
|
-
var childKey = _arr2[_i6];
|
|
1741
|
-
normalizeArray(product[childKey]).forEach(function (child) {
|
|
1742
|
-
if (!child || _typeof(child) !== 'object' || Array.isArray(child)) return;
|
|
1743
|
-
visitProductWalletDiscounts(child, assets, assetsById);
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
function getProductWalletDiscountType(record) {
|
|
1748
|
-
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++) {
|
|
1749
|
-
var _record$discount, _record$discount2;
|
|
1750
|
-
var value = _arr3[_i7];
|
|
1751
|
-
var type = stringify(value).trim().toLowerCase();
|
|
1752
|
-
if (PRODUCT_WALLET_DISCOUNT_TYPES.has(type)) return type;
|
|
1753
|
-
}
|
|
1754
|
-
return null;
|
|
1755
|
-
}
|
|
1756
|
-
function getProductWalletDiscountAssetId(record) {
|
|
1757
|
-
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++) {
|
|
1758
|
-
var _record$discount3;
|
|
1759
|
-
var value = _arr4[_i8];
|
|
1760
|
-
var id = normalizeWalletPassId(value);
|
|
1761
|
-
if (id && id !== '0') return id;
|
|
1762
|
-
}
|
|
1763
|
-
return null;
|
|
1764
|
-
}
|
|
1765
|
-
function getProductWalletDiscountCodes(record) {
|
|
1766
|
-
var _record$discount4, _record$discount5;
|
|
1767
|
-
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);
|
|
1768
|
-
}
|
|
1769
|
-
function getProductWalletDiscountName(asset, locale) {
|
|
1770
|
-
var _iterator4 = _createForOfIteratorHelper(asset.records),
|
|
1771
|
-
_step4;
|
|
1772
|
-
try {
|
|
1773
|
-
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1774
|
-
var record = _step4.value;
|
|
1775
|
-
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++) {
|
|
1776
|
-
var _record$discount6, _record$discount7, _record$discount8;
|
|
1777
|
-
var value = _arr5[_i9];
|
|
1778
|
-
var name = getLocalizedValue(value, locale).trim();
|
|
1779
|
-
if (name) return name;
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
} catch (err) {
|
|
1783
|
-
_iterator4.e(err);
|
|
1784
|
-
} finally {
|
|
1785
|
-
_iterator4.f();
|
|
1786
|
-
}
|
|
1787
|
-
return asset.codes[0] || label(locale, 'giftCard');
|
|
1788
|
-
}
|
|
1789
|
-
function getProductWalletDiscountTime(asset) {
|
|
1790
|
-
for (var _i10 = 0, _arr6 = ['updated_at', 'created_at', 'collection_time']; _i10 < _arr6.length; _i10++) {
|
|
1791
|
-
var field = _arr6[_i10];
|
|
1792
|
-
var _iterator5 = _createForOfIteratorHelper(asset.records),
|
|
1793
|
-
_step5;
|
|
1794
|
-
try {
|
|
1795
|
-
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1796
|
-
var _record$discount9;
|
|
1797
|
-
var record = _step5.value;
|
|
1798
|
-
var value = firstPresentValue(record[field], (_record$discount9 = record.discount) === null || _record$discount9 === void 0 ? void 0 : _record$discount9[field]);
|
|
1799
|
-
if (isPresentId(value)) return value;
|
|
1800
|
-
}
|
|
1801
|
-
} catch (err) {
|
|
1802
|
-
_iterator5.e(err);
|
|
1803
|
-
} finally {
|
|
1804
|
-
_iterator5.f();
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
return undefined;
|
|
1808
|
-
}
|
|
1809
|
-
function getProductEntitlementBalance(asset) {
|
|
1810
|
-
var _iterator6 = _createForOfIteratorHelper(asset.records),
|
|
1811
|
-
_step6;
|
|
1812
|
-
try {
|
|
1813
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1814
|
-
var record = _step6.value;
|
|
1815
|
-
var balance = getProductDiscountEntitlementBalance(record);
|
|
1816
|
-
if (balance) return balance;
|
|
1817
|
-
}
|
|
1818
|
-
} catch (err) {
|
|
1819
|
-
_iterator6.e(err);
|
|
1820
|
-
} finally {
|
|
1821
|
-
_iterator6.f();
|
|
1822
|
-
}
|
|
1823
|
-
return null;
|
|
1824
|
-
}
|
|
1825
|
-
function getProductDiscountEntitlementBalance(record) {
|
|
1826
|
-
var _record$metadata, _record$discount10, _record$discount11;
|
|
1827
|
-
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);
|
|
1828
|
-
}
|
|
1829
|
-
function getEntitlementBalance() {
|
|
1830
|
-
for (var _len3 = arguments.length, values = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1831
|
-
values[_key3] = arguments[_key3];
|
|
1832
|
-
}
|
|
1833
|
-
for (var _i11 = 0, _values2 = values; _i11 < _values2.length; _i11++) {
|
|
1834
|
-
var value = _values2[_i11];
|
|
1835
|
-
if (!isNumericAmount(value)) continue;
|
|
1836
|
-
var balance = new Decimal(value);
|
|
1837
|
-
if (balance.isFinite() && balance.isInteger() && balance.gte(0)) {
|
|
1838
|
-
return balance;
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
return null;
|
|
1842
|
-
}
|
|
1843
|
-
function formatEntitlementUses(value, locale) {
|
|
1844
|
-
var count = value.toFixed(0);
|
|
1845
|
-
switch (normalizeLocaleKey(locale)) {
|
|
1846
|
-
case 'zh_CN':
|
|
1847
|
-
case 'zh_HK':
|
|
1848
|
-
return "".concat(count, "\u6B21");
|
|
1849
|
-
case 'ja':
|
|
1850
|
-
return "".concat(count, "\u56DE");
|
|
1851
|
-
case 'pt':
|
|
1852
|
-
return "".concat(count, " ").concat(value.eq(1) ? 'utilização' : 'utilizações');
|
|
1853
|
-
default:
|
|
1854
|
-
return "".concat(count, " ").concat(value.eq(1) ? 'use' : 'uses');
|
|
1855
|
-
}
|
|
1856
|
-
}
|
|
1857
|
-
function getProductWalletDiscountPercent(asset) {
|
|
1858
|
-
if (asset.type !== 'discount_card' && asset.type !== 'product_discount_card') return null;
|
|
1859
|
-
var _iterator7 = _createForOfIteratorHelper(asset.records),
|
|
1860
|
-
_step7;
|
|
1861
|
-
try {
|
|
1862
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1863
|
-
var _record$metadata2, _record$discount12, _record$discount13, _record$discount14;
|
|
1864
|
-
var record = _step7.value;
|
|
1865
|
-
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();
|
|
1866
|
-
if (discountType && discountType !== 'percent' && discountType !== 'percentage') continue;
|
|
1867
|
-
var candidates = [record.percent, (_record$discount14 = record.discount) === null || _record$discount14 === void 0 ? void 0 : _record$discount14.percent];
|
|
1868
|
-
if (discountType === 'percent' || discountType === 'percentage') {
|
|
1869
|
-
var _record$discount15;
|
|
1870
|
-
candidates.push(record.par_value, (_record$discount15 = record.discount) === null || _record$discount15 === void 0 ? void 0 : _record$discount15.par_value);
|
|
1871
|
-
}
|
|
1872
|
-
for (var _i12 = 0, _candidates = candidates; _i12 < _candidates.length; _i12++) {
|
|
1873
|
-
var value = _candidates[_i12];
|
|
1874
|
-
if (!isNumericAmount(value)) continue;
|
|
1875
|
-
var percent = new Decimal(value);
|
|
1876
|
-
if (percent.isFinite() && percent.gt(0) && percent.lte(100)) {
|
|
1877
|
-
return percent;
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
} catch (err) {
|
|
1882
|
-
_iterator7.e(err);
|
|
1883
|
-
} finally {
|
|
1884
|
-
_iterator7.f();
|
|
1885
|
-
}
|
|
1886
|
-
return null;
|
|
1887
|
-
}
|
|
1888
|
-
function getProductWalletMoneyBalance(asset) {
|
|
1889
|
-
var _iterator8 = _createForOfIteratorHelper(asset.records),
|
|
1890
|
-
_step8;
|
|
1891
|
-
try {
|
|
1892
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1893
|
-
var record = _step8.value;
|
|
1894
|
-
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++) {
|
|
1895
|
-
var _record$metadata3, _record$discount16, _record$discount17;
|
|
1896
|
-
var value = _arr7[_i13];
|
|
1897
|
-
if (!isNumericAmount(value)) continue;
|
|
1898
|
-
return Decimal.max(new Decimal(value), 0);
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
} catch (err) {
|
|
1902
|
-
_iterator8.e(err);
|
|
1903
|
-
} finally {
|
|
1904
|
-
_iterator8.f();
|
|
1905
|
-
}
|
|
1906
|
-
var _iterator9 = _createForOfIteratorHelper(asset.records),
|
|
1907
|
-
_step9;
|
|
1908
|
-
try {
|
|
1909
|
-
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
1910
|
-
var _record$discount18, _record$discount19;
|
|
1911
|
-
var _record = _step9.value;
|
|
1912
|
-
var parValue = firstPresentValue(_record.par_value, (_record$discount18 = _record.discount) === null || _record$discount18 === void 0 ? void 0 : _record$discount18.par_value);
|
|
1913
|
-
var usedParValue = firstPresentValue(_record.used_par_value, (_record$discount19 = _record.discount) === null || _record$discount19 === void 0 ? void 0 : _record$discount19.used_par_value);
|
|
1914
|
-
if (!isNumericAmount(parValue) || !isNumericAmount(usedParValue)) continue;
|
|
1915
|
-
return Decimal.max(new Decimal(parValue).minus(new Decimal(usedParValue)), 0);
|
|
1916
|
-
}
|
|
1917
|
-
} catch (err) {
|
|
1918
|
-
_iterator9.e(err);
|
|
1919
|
-
} finally {
|
|
1920
|
-
_iterator9.f();
|
|
1921
|
-
}
|
|
1922
|
-
return null;
|
|
1923
|
-
}
|
|
1924
|
-
function buildPointCardSnapshotAssets(params) {
|
|
1925
|
-
var _params$order$order_m;
|
|
1926
|
-
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;
|
|
1927
|
-
if (!Array.isArray(snapshots)) return [];
|
|
1928
|
-
var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1929
|
-
return snapshots.flatMap(function (snapshot) {
|
|
1930
|
-
if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
|
|
1931
|
-
var pointCard = snapshot;
|
|
1932
|
-
if (stringify(pointCard.tag).trim().toLowerCase() !== 'point_card') return [];
|
|
1933
|
-
var assetId = normalizeWalletPassId(pointCard.id);
|
|
1934
|
-
if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
|
|
1935
|
-
id: assetId,
|
|
1936
|
-
codes: []
|
|
1937
|
-
})) return [];
|
|
1938
|
-
var rows = [{
|
|
1939
|
-
item: appendMaskedCardCode(stringify(pointCard.product_name).trim() || label(params.locale, 'pointCard'), pointCard.code),
|
|
1940
|
-
value: ''
|
|
1941
|
-
}];
|
|
1942
|
-
var remainingPoints = getPointCardSnapshotRemainingPoints(pointCard);
|
|
1943
|
-
if (remainingPoints) {
|
|
1944
|
-
rows.push({
|
|
1945
|
-
item: label(params.locale, 'remainingPoints'),
|
|
1946
|
-
value: trimDecimal(remainingPoints)
|
|
1947
|
-
});
|
|
1948
|
-
}
|
|
1949
|
-
if (isPresentId(snapshotTime)) {
|
|
1950
|
-
rows.push({
|
|
1951
|
-
item: formatDateTime(snapshotTime, params.locale),
|
|
1952
|
-
value: ''
|
|
1953
|
-
});
|
|
1954
|
-
}
|
|
1955
|
-
return [rows];
|
|
1956
|
-
});
|
|
1957
|
-
}
|
|
1958
|
-
function collectVirtualCurrencySnapshots(order) {
|
|
1959
|
-
var _order$order_meta_lis;
|
|
1960
|
-
var items = [];
|
|
1961
|
-
var byId = new Map();
|
|
1962
|
-
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;
|
|
1963
|
-
if (!Array.isArray(snapshots)) return {
|
|
1964
|
-
items: items,
|
|
1965
|
-
byId: byId
|
|
1966
|
-
};
|
|
1967
|
-
snapshots.forEach(function (snapshot) {
|
|
1968
|
-
if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return;
|
|
1969
|
-
var virtualCurrency = snapshot;
|
|
1970
|
-
if (stringify(virtualCurrency.tag).trim().toLowerCase() !== 'virtual_currency') return;
|
|
1971
|
-
var id = normalizeWalletPassId(virtualCurrency.id);
|
|
1972
|
-
if (!id || byId.has(id)) return;
|
|
1973
|
-
byId.set(id, virtualCurrency);
|
|
1974
|
-
items.push(virtualCurrency);
|
|
1975
|
-
});
|
|
1976
|
-
return {
|
|
1977
|
-
items: items,
|
|
1978
|
-
byId: byId
|
|
1979
|
-
};
|
|
1980
|
-
}
|
|
1981
|
-
function findVirtualCurrencySnapshotForPayment(payment, snapshotsById) {
|
|
1982
|
-
var fundRecord = getFundRecord(payment);
|
|
1983
|
-
for (var _i14 = 0, _arr8 = [fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.voucher_id, payment.voucher_id]; _i14 < _arr8.length; _i14++) {
|
|
1984
|
-
var value = _arr8[_i14];
|
|
1985
|
-
var id = normalizeWalletPassId(value);
|
|
1986
|
-
if (!id) continue;
|
|
1987
|
-
var snapshot = snapshotsById.get(id);
|
|
1988
|
-
if (snapshot) return snapshot;
|
|
1989
|
-
}
|
|
1990
|
-
return undefined;
|
|
1991
|
-
}
|
|
1992
|
-
function buildVirtualCurrencySnapshotAssets(params) {
|
|
1993
|
-
var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1994
|
-
return params.snapshots.flatMap(function (virtualCurrency) {
|
|
1995
|
-
var assetId = normalizeWalletPassId(virtualCurrency.id);
|
|
1996
|
-
if (!assetId || !claimWalletAssetIdentity(params.displayedWalletAssetIdentities, {
|
|
1997
|
-
id: assetId,
|
|
1998
|
-
codes: []
|
|
1999
|
-
})) return [];
|
|
2000
|
-
var rows = [{
|
|
2001
|
-
item: stringify(virtualCurrency.product_name).trim(),
|
|
2002
|
-
value: ''
|
|
2003
|
-
}];
|
|
2004
|
-
var balance = getVirtualCurrencySnapshotBalance(virtualCurrency);
|
|
2005
|
-
if (balance) {
|
|
2006
|
-
rows.push({
|
|
2007
|
-
item: label(params.locale, 'balance'),
|
|
2008
|
-
value: formatVirtualCurrencyBalance(balance, getVirtualCurrencySnapshotUnit(virtualCurrency, params.locale))
|
|
2009
|
-
});
|
|
2010
|
-
}
|
|
2011
|
-
if (isPresentId(snapshotTime)) {
|
|
2012
|
-
rows.push({
|
|
2013
|
-
item: formatDateTime(snapshotTime, params.locale),
|
|
2014
|
-
value: ''
|
|
2015
|
-
});
|
|
2016
|
-
}
|
|
2017
|
-
return [rows];
|
|
2018
|
-
});
|
|
2019
|
-
}
|
|
2020
|
-
function getVirtualCurrencySnapshotBalance(snapshot) {
|
|
2021
|
-
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
2022
|
-
return null;
|
|
2023
|
-
}
|
|
2024
|
-
return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
|
|
2025
|
-
}
|
|
2026
|
-
function getVirtualCurrencySnapshotUnit(snapshot, locale) {
|
|
2027
|
-
return getNonEmptyLocalizedValue(snapshot.name, locale);
|
|
2028
|
-
}
|
|
2029
|
-
function getNonEmptyLocalizedValue(value, locale) {
|
|
2030
|
-
if (value === undefined || value === null) return '';
|
|
2031
|
-
if (_typeof(value) !== 'object' || Array.isArray(value)) return stringify(value).trim();
|
|
2032
|
-
var dashedLocale = locale.replace('_', '-');
|
|
2033
|
-
var underscoredLocale = locale.replace('-', '_');
|
|
2034
|
-
for (var _i15 = 0, _arr9 = [value[locale], value[dashedLocale], value[underscoredLocale], value.original, value.auto, value.default, value.en]; _i15 < _arr9.length; _i15++) {
|
|
2035
|
-
var candidate = _arr9[_i15];
|
|
2036
|
-
var text = stringify(candidate).trim();
|
|
2037
|
-
if (text) return text;
|
|
2038
|
-
}
|
|
2039
|
-
return '';
|
|
2040
|
-
}
|
|
2041
|
-
function formatVirtualCurrencyBalance(value, unit) {
|
|
2042
|
-
var amount = trimDecimal(value);
|
|
2043
|
-
var normalizedUnit = unit.trim();
|
|
2044
|
-
return normalizedUnit ? "".concat(amount, " ").concat(normalizedUnit) : amount;
|
|
2045
|
-
}
|
|
2046
|
-
function normalizeWalletPassId(value) {
|
|
2047
|
-
if (typeof value === 'number') return Number.isFinite(value) ? String(value) : null;
|
|
2048
|
-
if (typeof value !== 'string') return null;
|
|
2049
|
-
return value.trim() || null;
|
|
2050
|
-
}
|
|
2051
|
-
function firstNormalizedWalletAssetId() {
|
|
2052
|
-
for (var _len4 = arguments.length, values = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
2053
|
-
values[_key4] = arguments[_key4];
|
|
2054
|
-
}
|
|
2055
|
-
for (var _i16 = 0, _values3 = values; _i16 < _values3.length; _i16++) {
|
|
2056
|
-
var value = _values3[_i16];
|
|
2057
|
-
var id = normalizeWalletPassId(value);
|
|
2058
|
-
if (id) return id;
|
|
2059
|
-
}
|
|
2060
|
-
return null;
|
|
2061
|
-
}
|
|
2062
|
-
function normalizeWalletAssetCodes() {
|
|
2063
|
-
for (var _len5 = arguments.length, values = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
2064
|
-
values[_key5] = arguments[_key5];
|
|
2065
|
-
}
|
|
2066
|
-
return Array.from(new Set(values.map(function (value) {
|
|
2067
|
-
return normalizeWalletPassId(value);
|
|
2068
|
-
}).filter(function (value) {
|
|
2069
|
-
return !!value;
|
|
2070
|
-
})));
|
|
2071
|
-
}
|
|
2072
|
-
function registerWalletAssetIdentity(identities, candidate) {
|
|
2073
|
-
if (!candidate.id && !candidate.codes.length) return;
|
|
2074
|
-
var existing = identities.find(function (identity) {
|
|
2075
|
-
return isSameWalletAssetIdentity(identity, candidate);
|
|
2076
|
-
});
|
|
2077
|
-
if (existing) {
|
|
2078
|
-
mergeWalletAssetIdentity(existing, candidate);
|
|
2079
|
-
return;
|
|
2080
|
-
}
|
|
2081
|
-
identities.push({
|
|
2082
|
-
id: candidate.id,
|
|
2083
|
-
codes: _toConsumableArray(candidate.codes)
|
|
2084
|
-
});
|
|
2085
|
-
}
|
|
2086
|
-
function claimWalletAssetIdentity(identities, candidate) {
|
|
2087
|
-
if (!candidate.id && !candidate.codes.length) return true;
|
|
2088
|
-
var existing = identities.find(function (identity) {
|
|
2089
|
-
return isSameWalletAssetIdentity(identity, candidate);
|
|
2090
|
-
});
|
|
2091
|
-
if (existing) {
|
|
2092
|
-
mergeWalletAssetIdentity(existing, candidate);
|
|
2093
|
-
return false;
|
|
2094
|
-
}
|
|
2095
|
-
identities.push({
|
|
2096
|
-
id: candidate.id,
|
|
2097
|
-
codes: _toConsumableArray(candidate.codes)
|
|
2098
|
-
});
|
|
2099
|
-
return true;
|
|
2100
|
-
}
|
|
2101
|
-
function isSameWalletAssetIdentity(left, right) {
|
|
2102
|
-
if (left.id && right.id) return left.id === right.id;
|
|
2103
|
-
return left.codes.some(function (code) {
|
|
2104
|
-
return right.codes.includes(code);
|
|
2105
|
-
});
|
|
2106
|
-
}
|
|
2107
|
-
function mergeWalletAssetIdentity(target, source) {
|
|
2108
|
-
if (!target.id && source.id) target.id = source.id;
|
|
2109
|
-
target.codes = Array.from(new Set([].concat(_toConsumableArray(target.codes), _toConsumableArray(source.codes))));
|
|
2110
|
-
}
|
|
2111
|
-
function getPointCardSnapshotRemainingPoints(snapshot) {
|
|
2112
|
-
if (!isNumericAmount(snapshot.par_value) || !isNumericAmount(snapshot.used_par_value)) {
|
|
2113
|
-
return null;
|
|
2114
|
-
}
|
|
2115
|
-
return Decimal.max(new Decimal(snapshot.par_value).minus(new Decimal(snapshot.used_par_value)), 0);
|
|
2116
|
-
}
|
|
2117
|
-
function buildVoucherAssets(params) {
|
|
2118
|
-
var fallbackAssetTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
2119
|
-
return normalizeArray(params.order.vouchers).flatMap(function (voucher) {
|
|
2120
|
-
if (!voucher || _typeof(voucher) !== 'object' || Array.isArray(voucher)) return [];
|
|
2121
|
-
if (!claimWalletAssetIdentity(params.displayedWalletAssetIdentities, getVoucherAssetIdentity(voucher))) return [];
|
|
2122
|
-
var name = getVoucherAssetName(voucher, params.locale);
|
|
2123
|
-
var assetTime = firstPresentValue(voucher.updated_at, voucher.created_at, voucher.collection_time, fallbackAssetTime);
|
|
2124
|
-
var timeRow = isPresentId(assetTime) ? {
|
|
2125
|
-
item: formatDateTime(assetTime, params.locale),
|
|
2126
|
-
value: ''
|
|
2127
|
-
} : null;
|
|
2128
|
-
if (isEntitlementVoucher(voucher)) {
|
|
2129
|
-
var _voucher$metadata;
|
|
2130
|
-
var remaining = getEntitlementBalance((_voucher$metadata = voucher.metadata) === null || _voucher$metadata === void 0 ? void 0 : _voucher$metadata.balance, voucher.balance);
|
|
2131
|
-
return [[{
|
|
2132
|
-
item: name,
|
|
2133
|
-
value: ''
|
|
2134
|
-
}].concat(_toConsumableArray(remaining ? [{
|
|
2135
|
-
item: label(params.locale, 'entitlementRemaining'),
|
|
2136
|
-
value: formatEntitlementUses(remaining, params.locale)
|
|
2137
|
-
}] : []), _toConsumableArray(timeRow ? [timeRow] : []))];
|
|
2138
|
-
}
|
|
2139
|
-
if (isTicketVoucher(voucher)) {
|
|
2140
|
-
var validity = getVoucherValidity(voucher, params.locale);
|
|
2141
|
-
return [[{
|
|
2142
|
-
item: name,
|
|
2143
|
-
value: ''
|
|
2144
|
-
}].concat(_toConsumableArray(validity ? [{
|
|
2145
|
-
item: label(params.locale, 'validity'),
|
|
2146
|
-
value: validity
|
|
2147
|
-
}] : []))];
|
|
2148
|
-
}
|
|
2149
|
-
var percent = getVoucherDiscountPercent(voucher);
|
|
2150
|
-
if (percent) {
|
|
2151
|
-
return [[{
|
|
2152
|
-
item: appendPercentToVoucherName(name, percent),
|
|
2153
|
-
value: formatVoucherDiscount(percent, params.locale)
|
|
2154
|
-
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
2155
|
-
}
|
|
2156
|
-
var balance = getVoucherBalance(voucher);
|
|
2157
|
-
return [[{
|
|
2158
|
-
item: name,
|
|
2159
|
-
value: ''
|
|
2160
|
-
}, {
|
|
2161
|
-
item: label(params.locale, 'balance'),
|
|
2162
|
-
value: formatMoney(balance, params.currencySymbol)
|
|
2163
|
-
}].concat(_toConsumableArray(timeRow ? [timeRow] : []))];
|
|
2164
|
-
});
|
|
2165
|
-
}
|
|
2166
|
-
var TICKET_VOUCHER_TAGS = new Set(['ticket', 'product_package_ticket', 'appointment_ticket', 'session_ticket']);
|
|
2167
|
-
function isEntitlementVoucher(voucher) {
|
|
2168
|
-
return [voucher.tag, voucher.type].some(function (value) {
|
|
2169
|
-
return stringify(value).trim().toLowerCase() === 'entitlement_pass';
|
|
2170
|
-
});
|
|
2171
|
-
}
|
|
2172
|
-
function isTicketVoucher(voucher) {
|
|
2173
|
-
return TICKET_VOUCHER_TAGS.has(stringify(voucher.tag).trim().toLowerCase());
|
|
2174
|
-
}
|
|
2175
|
-
function getVoucherValidity(voucher, locale) {
|
|
2176
|
-
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;
|
|
2177
|
-
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);
|
|
2178
|
-
var availableTimeText = formatVoucherAvailableTime(availableTime, locale);
|
|
2179
|
-
if (availableTimeText) return availableTimeText;
|
|
2180
|
-
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);
|
|
2181
|
-
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);
|
|
2182
|
-
return formatVoucherValidityRange(startDate, endDate, locale, {
|
|
2183
|
-
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,
|
|
2184
|
-
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
|
|
2185
|
-
});
|
|
2186
|
-
}
|
|
2187
|
-
function formatVoucherAvailableTime(value, locale) {
|
|
2188
|
-
if (!isPresentId(value)) return '';
|
|
2189
|
-
if (Array.isArray(value)) {
|
|
2190
|
-
return value.map(function (item) {
|
|
2191
|
-
return formatVoucherAvailableTime(item, locale);
|
|
2192
|
-
}).filter(Boolean).join(', ');
|
|
2193
|
-
}
|
|
2194
|
-
if (_typeof(value) !== 'object') return stringify(value).trim();
|
|
2195
|
-
var start = firstPresentValue(value.start, value.start_at, value.start_date_time, value.start_date);
|
|
2196
|
-
var end = firstPresentValue(value.end, value.end_at, value.end_date_time, value.expire_time, value.expire_date, value.end_date);
|
|
2197
|
-
if (isPresentId(start) || isPresentId(end)) {
|
|
2198
|
-
return formatVoucherValidityRange(start, end, locale, {
|
|
2199
|
-
startTime: value.start_time,
|
|
2200
|
-
endTime: value.end_time
|
|
2201
|
-
});
|
|
2202
|
-
}
|
|
2203
|
-
return getLocalizedValue(value, locale).trim();
|
|
2204
|
-
}
|
|
2205
|
-
function formatVoucherValidityRange(startValue, endValue, locale) {
|
|
2206
|
-
var times = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
2207
|
-
var start = combineVoucherDateAndTime(startValue, times.startTime);
|
|
2208
|
-
var end = combineVoucherDateAndTime(endValue, times.endTime);
|
|
2209
|
-
var startPart = formatVoucherValidityDate(start, locale);
|
|
2210
|
-
var endPart = formatVoucherValidityDate(end, locale);
|
|
2211
|
-
if (startPart.text && endPart.text) {
|
|
2212
|
-
var parsedStart = dayjs(start);
|
|
2213
|
-
var parsedEnd = dayjs(end);
|
|
2214
|
-
var sameDay = parsedStart.isValid() && parsedEnd.isValid() && parsedStart.isSame(parsedEnd, 'day');
|
|
2215
|
-
if (sameDay && startPart.time && endPart.time) {
|
|
2216
|
-
return "".concat(startPart.time, " - ").concat(endPart.time, " ").concat(startPart.date);
|
|
2217
|
-
}
|
|
2218
|
-
return "".concat(startPart.text, " - ").concat(endPart.text);
|
|
2219
|
-
}
|
|
2220
|
-
return startPart.text || endPart.text;
|
|
2221
|
-
}
|
|
2222
|
-
function combineVoucherDateAndTime(dateValue, timeValue) {
|
|
2223
|
-
if (!isPresentId(dateValue) || !isPresentId(timeValue)) return dateValue;
|
|
2224
|
-
var dateText = stringify(dateValue).trim();
|
|
2225
|
-
if (/\d{1,2}:\d{2}/.test(dateText)) return dateValue;
|
|
2226
|
-
return "".concat(dateText, " ").concat(stringify(timeValue).trim());
|
|
2227
|
-
}
|
|
2228
|
-
function formatVoucherValidityDate(value, locale) {
|
|
2229
|
-
if (!isPresentId(value)) return {
|
|
2230
|
-
date: '',
|
|
2231
|
-
time: '',
|
|
2232
|
-
text: ''
|
|
2233
|
-
};
|
|
2234
|
-
var source = stringify(value).trim();
|
|
2235
|
-
var parsed = dayjs(source);
|
|
2236
|
-
if (!parsed.isValid()) return {
|
|
2237
|
-
date: '',
|
|
2238
|
-
time: '',
|
|
2239
|
-
text: source
|
|
2240
|
-
};
|
|
2241
|
-
var hasTime = /\d{1,2}:\d{2}/.test(source);
|
|
2242
|
-
var date = parsed.format(locale === 'en' ? 'DD/MM/YYYY' : 'YYYY/MM/DD');
|
|
2243
|
-
var time = hasTime ? parsed.format(/\d{1,2}:\d{2}:\d{2}/.test(source) ? 'HH:mm:ss' : 'HH:mm') : '';
|
|
2244
|
-
return {
|
|
2245
|
-
date: date,
|
|
2246
|
-
time: time,
|
|
2247
|
-
text: time ? "".concat(time, " ").concat(date) : date
|
|
2248
|
-
};
|
|
2249
|
-
}
|
|
2250
|
-
function getVoucherAssetIdentity(voucher) {
|
|
2251
|
-
return {
|
|
2252
|
-
id: firstNormalizedWalletAssetId(voucher.voucher_id, voucher.id),
|
|
2253
|
-
codes: normalizeWalletAssetCodes(voucher.code, voucher.encoded)
|
|
2254
|
-
};
|
|
2255
|
-
}
|
|
2256
|
-
function getVoucherAssetName(voucher, locale) {
|
|
2257
|
-
return getLocalizedValue(voucher.product_name || voucher.name || voucher.title, locale) || stringify(voucher.encoded || voucher.code || label(locale, 'giftCard'));
|
|
2258
|
-
}
|
|
2259
|
-
function getVoucherDiscountPercent(voucher) {
|
|
2260
|
-
var _voucher$metadata14;
|
|
2261
|
-
var discountType = stringify(((_voucher$metadata14 = voucher.metadata) === null || _voucher$metadata14 === void 0 ? void 0 : _voucher$metadata14.discount_card_type) || voucher.discount_card_type).toLowerCase();
|
|
2262
|
-
if (discountType !== 'percent' && discountType !== 'percentage') return null;
|
|
2263
|
-
var percent = new Decimal(toMoneyNumber(voucher.par_value));
|
|
2264
|
-
if (!percent.isFinite() || percent.lte(0) || percent.gt(100)) return null;
|
|
2265
|
-
return percent;
|
|
2266
|
-
}
|
|
2267
|
-
function appendPercentToVoucherName(name, percent) {
|
|
2268
|
-
if (/\d+(?:\.\d+)?\s*(?:%|折)|\boff\b/i.test(name)) return name;
|
|
2269
|
-
var separator = /^(?:[\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u3005\u3007\u3021-\u3029\u3038-\u303B\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FD-\u30FF\u31F0-\u31FF\u32D0-\u32FE\u3300-\u3357\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFA6D\uFA70-\uFAD9\uFF66-\uFF6F\uFF71-\uFF9D]|\uD81B[\uDFE2\uDFE3\uDFF0\uDFF1]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD32\uDD50-\uDD52\uDD55\uDD64-\uDD67]|\uD83C\uDE00|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883\uD885-\uD887][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF39\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0\uDFF0-\uDFFF]|\uD87B[\uDC00-\uDE5D]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A\uDF50-\uDFFF]|\uD888[\uDC00-\uDFAF])/.test(name) ? '' : ' ';
|
|
2270
|
-
return "".concat(trimDecimal(percent), "%").concat(separator).concat(name);
|
|
2271
|
-
}
|
|
2272
|
-
function formatVoucherDiscount(percent, locale) {
|
|
2273
|
-
var normalizedLocale = normalizeLocaleKey(locale);
|
|
2274
|
-
if (normalizedLocale === 'zh_CN' || normalizedLocale === 'zh_HK') {
|
|
2275
|
-
return "".concat(trimDecimal(percent), "% OFF");
|
|
2276
|
-
}
|
|
2277
|
-
if (normalizedLocale === 'pt') return "Desconto ".concat(trimDecimal(percent), "%");
|
|
2278
|
-
return normalizedLocale === 'en' ? "Discount ".concat(trimDecimal(percent), "% OFF") : "".concat(trimDecimal(percent), "% OFF");
|
|
2279
|
-
}
|
|
2280
|
-
function getVoucherBalance(voucher) {
|
|
2281
|
-
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++) {
|
|
2282
|
-
var _voucher$metadata15;
|
|
2283
|
-
var value = _arr10[_i17];
|
|
2284
|
-
if (!isNumericAmount(value)) continue;
|
|
2285
|
-
return Decimal.max(new Decimal(value), 0);
|
|
2286
|
-
}
|
|
2287
|
-
var parValue = new Decimal(toMoneyNumber(voucher.par_value));
|
|
2288
|
-
var usedParValue = new Decimal(toMoneyNumber(voucher.used_par_value));
|
|
2289
|
-
return Decimal.max(parValue.minus(usedParValue), 0);
|
|
2290
|
-
}
|
|
2291
|
-
function buildPaymentItems(params) {
|
|
2292
|
-
var payment = params.payment,
|
|
2293
|
-
locale = params.locale,
|
|
2294
|
-
currencySymbol = params.currencySymbol,
|
|
2295
|
-
includeFundRecordBalance = params.includeFundRecordBalance,
|
|
2296
|
-
includeFundRecordUsage = params.includeFundRecordUsage,
|
|
2297
|
-
includePaymentAmount = params.includePaymentAmount,
|
|
2298
|
-
virtualCurrencyUnit = params.virtualCurrencyUnit;
|
|
2299
|
-
var serviceFee = getPaymentServiceFee(payment);
|
|
2300
|
-
var items = [{
|
|
2301
|
-
item: paymentMethodName(payment, locale),
|
|
2302
|
-
value: includePaymentAmount ? formatMoney(resolveReceiptPaymentAmount(payment, serviceFee), currencySymbol) : ''
|
|
2303
|
-
}];
|
|
2304
|
-
items.push.apply(items, _toConsumableArray(buildCashChangePaymentItems({
|
|
2305
|
-
payment: payment,
|
|
2306
|
-
locale: locale,
|
|
2307
|
-
currencySymbol: currencySymbol
|
|
2308
|
-
})));
|
|
2309
|
-
if (serviceFee.gt(0)) {
|
|
2310
|
-
items.push({
|
|
2311
|
-
item: label(locale, 'surchargeIncluded'),
|
|
2312
|
-
value: formatMoney(serviceFee, currencySymbol)
|
|
2313
|
-
});
|
|
2314
|
-
}
|
|
2315
|
-
var fundRecord = getFundRecord(payment);
|
|
2316
|
-
if (fundRecord) {
|
|
2317
|
-
items.push.apply(items, _toConsumableArray(buildFundRecordPaymentItems({
|
|
2318
|
-
payment: payment,
|
|
2319
|
-
fundRecord: fundRecord,
|
|
2320
|
-
locale: locale,
|
|
2321
|
-
currencySymbol: currencySymbol,
|
|
2322
|
-
includeBalance: includeFundRecordBalance,
|
|
2323
|
-
includeUsage: includeFundRecordUsage,
|
|
2324
|
-
virtualCurrencyUnit: virtualCurrencyUnit
|
|
2325
|
-
})));
|
|
2326
|
-
} else {
|
|
2327
|
-
var _ref61, _payment$remaining_am, _payment$metadata;
|
|
2328
|
-
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;
|
|
2329
|
-
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
2330
|
-
items.push({
|
|
2331
|
-
item: label(locale, 'remainingAmount'),
|
|
2332
|
-
value: formatMoney(remainingAmount, currencySymbol)
|
|
2333
|
-
});
|
|
2334
|
-
}
|
|
2335
|
-
}
|
|
2336
|
-
items.push({
|
|
2337
|
-
item: formatDateTime(payment.paid_at || payment.created_at || payment.updated_at || new Date(), locale),
|
|
2338
|
-
value: ''
|
|
2339
|
-
});
|
|
2340
|
-
return items;
|
|
2341
|
-
}
|
|
2342
|
-
function getPaymentServiceFee(payment) {
|
|
2343
|
-
return new Decimal(toMoneyNumber(payment.service_fee));
|
|
2344
|
-
}
|
|
2345
|
-
function resolveReceiptPaymentAmount(payment, serviceFee) {
|
|
2346
|
-
var _payment$amount;
|
|
2347
|
-
var amount = new Decimal(toMoneyNumber((_payment$amount = payment.amount) !== null && _payment$amount !== void 0 ? _payment$amount : payment.origin_amount));
|
|
2348
|
-
var hasAmount = payment.amount !== undefined && payment.amount !== null && payment.amount !== '';
|
|
2349
|
-
var hasOriginAmount = payment.origin_amount !== undefined && payment.origin_amount !== null && payment.origin_amount !== '';
|
|
2350
|
-
if (!hasAmount || !hasOriginAmount || serviceFee.lte(0)) return amount;
|
|
2351
|
-
var originAmount = new Decimal(toMoneyNumber(payment.origin_amount));
|
|
2352
|
-
return amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
|
|
2353
|
-
}
|
|
2354
|
-
function buildCashChangePaymentItems(params) {
|
|
2355
|
-
var payment = params.payment,
|
|
2356
|
-
locale = params.locale,
|
|
2357
|
-
currencySymbol = params.currencySymbol;
|
|
2358
|
-
if (!shouldDisplayCashChange(payment)) return [];
|
|
2359
|
-
return [{
|
|
2360
|
-
item: label(locale, 'cashReceived'),
|
|
2361
|
-
value: formatMoney(payment.metadata.actual_paid_amount, currencySymbol)
|
|
2362
|
-
}, {
|
|
2363
|
-
item: label(locale, 'changeDue'),
|
|
2364
|
-
value: formatMoney(payment.metadata.change_given_amount, currencySymbol)
|
|
2365
|
-
}];
|
|
2366
|
-
}
|
|
2367
|
-
function shouldDisplayCashChange(payment) {
|
|
2368
|
-
var _payment$code, _payment$metadata2, _payment$metadata3;
|
|
2369
|
-
if (stringify(payment.status).toLowerCase() !== 'paid') return false;
|
|
2370
|
-
var paymentMethod = stringify((_payment$code = payment.code) !== null && _payment$code !== void 0 ? _payment$code : payment.payment_method).toUpperCase();
|
|
2371
|
-
if (paymentMethod !== 'CASHMANUAL') return false;
|
|
2372
|
-
var actualPaidAmount = (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.actual_paid_amount;
|
|
2373
|
-
var changeGivenAmount = (_payment$metadata3 = payment.metadata) === null || _payment$metadata3 === void 0 ? void 0 : _payment$metadata3.change_given_amount;
|
|
2374
|
-
if (!isNumericAmount(actualPaidAmount) || !isNumericAmount(changeGivenAmount)) return false;
|
|
2375
|
-
return new Decimal(changeGivenAmount).toDecimalPlaces(2).gt(0);
|
|
2376
|
-
}
|
|
2377
|
-
function isNumericAmount(value) {
|
|
2378
|
-
if (typeof value === 'number') return Number.isFinite(value);
|
|
2379
|
-
if (typeof value !== 'string') return false;
|
|
2380
|
-
var normalized = value.trim();
|
|
2381
|
-
return normalized !== '' && /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(normalized);
|
|
2382
|
-
}
|
|
2383
|
-
function buildFundRecordPaymentItems(params) {
|
|
2384
|
-
var payment = params.payment,
|
|
2385
|
-
fundRecord = params.fundRecord,
|
|
2386
|
-
locale = params.locale,
|
|
2387
|
-
currencySymbol = params.currencySymbol,
|
|
2388
|
-
includeBalance = params.includeBalance,
|
|
2389
|
-
includeUsage = params.includeUsage,
|
|
2390
|
-
virtualCurrencyUnit = params.virtualCurrencyUnit;
|
|
2391
|
-
var items = [];
|
|
2392
|
-
var usingBeforeValue = fundRecord.using_before_value;
|
|
2393
|
-
var usingAfterValue = fundRecord.using_after_value;
|
|
2394
|
-
if (isPointCardPayment(payment) && usingBeforeValue !== undefined && usingAfterValue !== undefined) {
|
|
2395
|
-
var usedPoints = new Decimal(toMoneyNumber(usingBeforeValue)).minus(toMoneyNumber(usingAfterValue));
|
|
2396
|
-
if (includeUsage) {
|
|
2397
|
-
items.push({
|
|
2398
|
-
item: label(locale, 'redeemPoints'),
|
|
2399
|
-
value: trimDecimal(usedPoints)
|
|
2400
|
-
});
|
|
2401
|
-
}
|
|
2402
|
-
if (includeBalance) {
|
|
2403
|
-
items.push({
|
|
2404
|
-
item: label(locale, 'remainingPoints'),
|
|
2405
|
-
value: trimDecimal(new Decimal(toMoneyNumber(usingAfterValue)))
|
|
2406
|
-
});
|
|
2407
|
-
}
|
|
2408
|
-
return items;
|
|
2409
|
-
}
|
|
2410
|
-
if (includeBalance && usingAfterValue !== undefined && usingAfterValue !== null) {
|
|
2411
|
-
if (virtualCurrencyUnit !== undefined) {
|
|
2412
|
-
if (!isNumericAmount(usingAfterValue)) return items;
|
|
2413
|
-
items.push({
|
|
2414
|
-
item: label(locale, 'balance'),
|
|
2415
|
-
value: formatVirtualCurrencyBalance(new Decimal(usingAfterValue), virtualCurrencyUnit)
|
|
2416
|
-
});
|
|
2417
|
-
return items;
|
|
2418
|
-
}
|
|
2419
|
-
items.push({
|
|
2420
|
-
item: label(locale, 'balance'),
|
|
2421
|
-
value: formatMoney(usingAfterValue, currencySymbol)
|
|
2422
|
-
});
|
|
2423
|
-
}
|
|
2424
|
-
return items;
|
|
2425
|
-
}
|
|
2426
|
-
function getFundRecord(payment) {
|
|
2427
|
-
var fundRecord = payment.fund_record;
|
|
2428
|
-
if (!fundRecord || _typeof(fundRecord) !== 'object' || Array.isArray(fundRecord)) return null;
|
|
2429
|
-
if (!fundRecord.voucher_id && !fundRecord.code) return null;
|
|
2430
|
-
return fundRecord;
|
|
2431
|
-
}
|
|
2432
|
-
function isPointCardPayment(payment) {
|
|
2433
|
-
var _payment$fund_record;
|
|
2434
|
-
var code = stringify(payment.code || payment.payment_method).toUpperCase();
|
|
2435
|
-
var type = stringify(payment.type || ((_payment$fund_record = payment.fund_record) === null || _payment$fund_record === void 0 ? void 0 : _payment$fund_record.tag)).toLowerCase();
|
|
2436
|
-
return code === 'POINTCARD' || type === 'point_card';
|
|
2437
|
-
}
|
|
2438
|
-
function maskMachineCode(code) {
|
|
2439
|
-
var text = stringify(code).trim();
|
|
2440
|
-
if (!text) return '';
|
|
2441
|
-
if (text.length <= 6) return '*'.repeat(text.length);
|
|
2442
|
-
return "".concat(text.slice(0, 2), "****").concat(text.slice(-4));
|
|
2443
|
-
}
|
|
2444
|
-
function appendMaskedCardCode(name, code) {
|
|
2445
|
-
var maskedCode = maskMachineCode(code);
|
|
2446
|
-
return maskedCode ? "".concat(name, "(").concat(maskedCode, ")") : name;
|
|
2447
|
-
}
|
|
2448
|
-
function trimDecimal(value) {
|
|
2449
|
-
return value.toDecimalPlaces(2).toFixed(2).replace(/\.?0+$/, '');
|
|
2450
|
-
}
|
|
2451
|
-
function getFundRecordPaymentName(payment, locale) {
|
|
2452
|
-
var fundRecord = getFundRecord(payment);
|
|
2453
|
-
if (!fundRecord) return '';
|
|
2454
|
-
var name = getLocalizedValue(fundRecord.wallet_pass_name, locale);
|
|
2455
|
-
if (!name && !maskMachineCode(fundRecord.code)) return '';
|
|
2456
|
-
var fallbackName = getLocalizedValue(payment.name || payment.title || payment.payment_method_name || payment.method_name || payment.code, locale);
|
|
2457
|
-
return appendMaskedCardCode(name || fallbackName, fundRecord.code);
|
|
2458
|
-
}
|
|
2459
|
-
function appendMachineCodeToName(name, payment) {
|
|
2460
|
-
var fundRecord = getFundRecord(payment);
|
|
2461
|
-
return appendMaskedCardCode(name, fundRecord === null || fundRecord === void 0 ? void 0 : fundRecord.code);
|
|
2462
|
-
}
|
|
2463
|
-
function paymentMethodName(payment, locale) {
|
|
2464
|
-
var fundRecordName = getFundRecordPaymentName(payment, locale);
|
|
2465
|
-
if (fundRecordName) return fundRecordName;
|
|
2466
|
-
var raw = payment.name || payment.title || payment.payment_method_name || payment.method_name;
|
|
2467
|
-
if (raw) return appendMachineCodeToName(getLocalizedValue(raw, locale), payment);
|
|
2468
|
-
var code = stringify(payment.code || payment.type || payment.payment_method || payment.method).toLowerCase();
|
|
2469
|
-
if (code.includes('cash')) return label(locale, 'cash');
|
|
2470
|
-
if (code.includes('eftpos') || code.includes('card')) return label(locale, 'eftpos');
|
|
2471
|
-
if (code.includes('wallet')) return label(locale, 'wallet');
|
|
2472
|
-
if (code.includes('gift')) return label(locale, 'giftCard');
|
|
2473
|
-
return stringify(payment.code || payment.type || payment.payment_method || payment.method);
|
|
2474
|
-
}
|
|
2475
|
-
function getSummary(order) {
|
|
2476
|
-
return order.summary && _typeof(order.summary) === 'object' ? order.summary : order;
|
|
2477
|
-
}
|
|
2478
|
-
function getCurrencySymbol(order, shopInfo) {
|
|
2479
|
-
return stringify(order.currency_symbol || (shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.currency_symbol) || order.shop_symbol || '$') || '$';
|
|
2480
|
-
}
|
|
2481
|
-
function resolveLocales(shopInfo, locales) {
|
|
2482
|
-
var preferred = [].concat(_toConsumableArray(locales || []), [shopInfo.primary_locale], DEFAULT_LOCALES).filter(Boolean);
|
|
2483
|
-
return Array.from(new Set(preferred.map(normalizeLocaleKey)));
|
|
2484
|
-
}
|
|
2485
|
-
function normalizeLocaleKey(locale) {
|
|
2486
|
-
return locale.replace('-', '_');
|
|
2487
|
-
}
|
|
2488
|
-
function label(locale, key) {
|
|
2489
|
-
var _LABELS$locale;
|
|
2490
|
-
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
2491
|
-
}
|
|
2492
|
-
function getLocalizedValue(value, locale) {
|
|
2493
|
-
var _ref62, _ref63, _ref64, _ref65, _ref66, _ref67, _value$locale2;
|
|
2494
|
-
if (value === undefined || value === null) return '';
|
|
2495
|
-
if (_typeof(value) !== 'object') return stringify(value);
|
|
2496
|
-
var dashedLocale = locale.replace('_', '-');
|
|
2497
|
-
var underscoredLocale = locale.replace('-', '_');
|
|
2498
|
-
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 : '');
|
|
2499
|
-
}
|
|
2500
|
-
function resolveServiceTypeLabelKey(serviceType) {
|
|
2501
|
-
return SERVICE_TYPE_LABEL_KEYS[serviceType] || null;
|
|
2502
|
-
}
|
|
2503
|
-
function normalizeBooleanFlag(value) {
|
|
2504
|
-
if (value === true || value === 1 || stringify(value).trim() === '1') return 1;
|
|
2505
|
-
return 0;
|
|
2506
|
-
}
|
|
2507
|
-
function buildShopAddress(shopInfo) {
|
|
2508
|
-
return [shopInfo.address_street, shopInfo.address_detail, shopInfo.city, shopInfo.province, shopInfo.country, shopInfo.zip].filter(Boolean).join(', ');
|
|
2509
|
-
}
|
|
2510
|
-
function formatDateTime(value, locale) {
|
|
2511
|
-
var date = dayjs(value);
|
|
2512
|
-
if (!date.isValid()) return stringify(value);
|
|
2513
|
-
if (locale === 'en') return date.format('HH:mm:ss DD/MM/YYYY');
|
|
2514
|
-
return date.format('YYYY/MM/DD HH:mm:ss');
|
|
2515
|
-
}
|
|
2516
|
-
function formatMoney(value, currencySymbol) {
|
|
2517
|
-
if (value instanceof Decimal) return "".concat(currencySymbol).concat(value.toFixed(2));
|
|
2518
|
-
if (typeof value === 'string' && value.trim().startsWith(currencySymbol)) return value;
|
|
2519
|
-
var amount = new Decimal(toMoneyNumber(value));
|
|
2520
|
-
return "".concat(currencySymbol).concat(amount.toFixed(2));
|
|
2521
|
-
}
|
|
2522
|
-
function formatCalculatedMoney(value, currencySymbol) {
|
|
2523
|
-
var amount = new Decimal(toMoneyNumber(value));
|
|
2524
|
-
var sign = amount.isNegative() ? '-' : '';
|
|
2525
|
-
return "".concat(sign).concat(currencySymbol).concat(amount.abs().toFixed(2));
|
|
2526
|
-
}
|
|
2527
|
-
function formatNegativeMoney(value, currencySymbol) {
|
|
2528
|
-
var amount = new Decimal(toMoneyNumber(value)).abs();
|
|
2529
|
-
return "-".concat(currencySymbol).concat(amount.toFixed(2));
|
|
2530
|
-
}
|
|
2531
|
-
function sumAppliedPayments(payments) {
|
|
2532
|
-
return normalizeArray(payments).filter(function (payment) {
|
|
2533
|
-
return isPrintablePayment(payment);
|
|
2534
|
-
}).reduce(function (sum, payment) {
|
|
2535
|
-
if (isPresentId(payment.origin_amount)) {
|
|
2536
|
-
return sum.plus(toMoneyNumber(payment.origin_amount));
|
|
2537
|
-
}
|
|
2538
|
-
var amount = new Decimal(toMoneyNumber(payment.amount));
|
|
2539
|
-
var serviceFee = Decimal.max(toMoneyNumber(payment.service_fee), 0);
|
|
2540
|
-
return sum.plus(Decimal.max(amount.minus(serviceFee), 0));
|
|
2541
|
-
}, new Decimal(0));
|
|
2542
|
-
}
|
|
2543
|
-
function sumCustomerPaidPayments(payments) {
|
|
2544
|
-
return normalizeArray(payments).filter(function (payment) {
|
|
2545
|
-
return isPrintablePayment(payment);
|
|
2546
|
-
}).reduce(function (sum, payment) {
|
|
2547
|
-
var _payment$amount2;
|
|
2548
|
-
return sum.plus(toMoneyNumber((_payment$amount2 = payment.amount) !== null && _payment$amount2 !== void 0 ? _payment$amount2 : payment.origin_amount));
|
|
2549
|
-
}, new Decimal(0));
|
|
2550
|
-
}
|
|
2551
|
-
function isPrintablePayment(payment) {
|
|
2552
|
-
var status = stringify(payment.status).toLowerCase();
|
|
2553
|
-
if (!status) return true;
|
|
2554
|
-
return ['paid', 'success', 'succeeded', 'completed', 'partially_refunded', 'refunded'].includes(status);
|
|
2555
|
-
}
|
|
2556
|
-
function normalizeArray(value) {
|
|
2557
|
-
return Array.isArray(value) ? value : [];
|
|
2558
|
-
}
|
|
2559
|
-
function isNonZero(value) {
|
|
2560
|
-
return !new Decimal(toMoneyNumber(value)).isZero();
|
|
2561
|
-
}
|
|
2562
|
-
function toMoneyNumber(value) {
|
|
2563
|
-
if (value instanceof Decimal) return value.toString();
|
|
2564
|
-
if (typeof value === 'number') return Number.isFinite(value) ? value : 0;
|
|
2565
|
-
if (typeof value !== 'string') return 0;
|
|
2566
|
-
var normalized = value.replace(/[^\d.-]/g, '');
|
|
2567
|
-
return normalized || 0;
|
|
2568
|
-
}
|
|
2569
|
-
function toNumber(value, fallback) {
|
|
2570
|
-
var numberValue = Number(value);
|
|
2571
|
-
return Number.isFinite(numberValue) ? numberValue : fallback;
|
|
2572
|
-
}
|
|
2573
|
-
function stringify(value) {
|
|
2574
|
-
if (value === undefined || value === null) return '';
|
|
2575
|
-
return String(value);
|
|
2576
|
-
}
|
|
1
|
+
// Compatibility entry for POS Server and existing native receipt consumers.
|
|
2
|
+
export * from "../../shared/receipt/small-ticket";
|