@pisell/pisellos 2.3.128 → 2.3.130
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 +0 -9
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
- package/dist/modules/Customer/index.js +6 -3
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/availability.d.ts +7 -0
- package/dist/modules/Discount/availability.js +49 -0
- package/dist/modules/Discount/entitlementPass.d.ts +34 -0
- package/dist/modules/Discount/entitlementPass.js +147 -0
- package/dist/modules/Discount/index.d.ts +2 -2
- package/dist/modules/Discount/index.js +37 -151
- package/dist/modules/Discount/types.d.ts +36 -5
- package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
- package/dist/modules/FulfillmentTiming/index.js +407 -0
- package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
- package/dist/modules/FulfillmentTiming/types.js +1 -0
- package/dist/modules/OpenData/types.d.ts +6 -0
- package/dist/modules/Order/index.d.ts +12 -0
- package/dist/modules/Order/index.js +498 -247
- package/dist/modules/Order/pickupTiming.d.ts +46 -0
- package/dist/modules/Order/pickupTiming.js +53 -0
- package/dist/modules/Order/types.d.ts +5 -1
- package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
- package/dist/modules/Order/utils.d.ts +1 -1
- package/dist/modules/Order/utils.js +117 -66
- package/dist/modules/Payment/index.js +9 -10
- package/dist/modules/Payment/types.d.ts +21 -1
- package/dist/modules/Payment/types.js +2 -0
- package/dist/modules/Payment/walletpass.d.ts +1 -1
- package/dist/modules/Payment/walletpass.js +80 -47
- package/dist/modules/Rules/index.d.ts +2 -2
- package/dist/modules/Rules/index.js +480 -186
- package/dist/modules/Rules/types.d.ts +4 -0
- package/dist/modules/Schedule/index.d.ts +8 -0
- package/dist/modules/Schedule/index.js +141 -39
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/plugins/request.d.ts +7 -0
- package/dist/server/modules/order/types.d.ts +2 -0
- package/dist/server/utils/small-ticket.d.ts +1 -85
- package/dist/server/utils/small-ticket.js +2 -2542
- package/dist/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/dist/shared/payment/loadPaymentMethods.js +66 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/dist/shared/receipt/loadCustomerInvoiceLayout.js +142 -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 +25 -0
- package/dist/solution/BaseSales/index.js +1226 -1040
- package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/dist/solution/BaseSales/pickupTiming.js +589 -0
- package/dist/solution/BaseSales/types.d.ts +2 -2
- package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +4 -5
- package/dist/solution/BookingTicket/index.js +60 -63
- package/dist/solution/BookingTicket/types.d.ts +5 -1
- package/dist/solution/BookingTicket/utils/cartView.js +3 -1
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
- package/dist/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/dist/solution/OrderInvoicePreview/index.js +269 -0
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +99 -42
- package/dist/solution/ShopDiscount/utils.d.ts +4 -2
- package/dist/solution/ShopDiscount/utils.js +43 -23
- package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/dist/solution/UnifiedBookingSales/index.js +874 -709
- 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/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
- package/lib/modules/Customer/index.js +5 -1
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/availability.d.ts +7 -0
- package/lib/modules/Discount/availability.js +43 -0
- package/lib/modules/Discount/entitlementPass.d.ts +34 -0
- package/lib/modules/Discount/entitlementPass.js +141 -0
- package/lib/modules/Discount/index.d.ts +2 -2
- package/lib/modules/Discount/index.js +23 -129
- package/lib/modules/Discount/types.d.ts +36 -5
- package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
- package/lib/modules/FulfillmentTiming/index.js +359 -0
- package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
- package/lib/modules/FulfillmentTiming/types.js +5 -0
- package/lib/modules/OpenData/types.d.ts +6 -0
- package/lib/modules/Order/index.d.ts +12 -0
- package/lib/modules/Order/index.js +252 -48
- package/lib/modules/Order/pickupTiming.d.ts +46 -0
- package/lib/modules/Order/pickupTiming.js +61 -0
- package/lib/modules/Order/types.d.ts +5 -1
- package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
- package/lib/modules/Order/utils.d.ts +1 -1
- package/lib/modules/Order/utils.js +51 -7
- package/lib/modules/Payment/index.js +3 -4
- package/lib/modules/Payment/types.d.ts +21 -1
- package/lib/modules/Payment/types.js +1 -0
- package/lib/modules/Payment/walletpass.d.ts +1 -1
- package/lib/modules/Payment/walletpass.js +29 -9
- package/lib/modules/Rules/index.d.ts +2 -2
- package/lib/modules/Rules/index.js +357 -110
- package/lib/modules/Rules/types.d.ts +4 -0
- package/lib/modules/Schedule/index.d.ts +8 -0
- package/lib/modules/Schedule/index.js +68 -12
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +11 -0
- package/lib/plugins/request.d.ts +7 -0
- package/lib/server/modules/order/types.d.ts +2 -0
- package/lib/server/utils/small-ticket.d.ts +1 -85
- package/lib/server/utils/small-ticket.js +9 -2305
- package/lib/shared/payment/loadPaymentMethods.d.ts +9 -0
- package/lib/shared/payment/loadPaymentMethods.js +40 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.d.ts +22 -0
- package/lib/shared/receipt/loadCustomerInvoiceLayout.js +86 -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 +25 -0
- package/lib/solution/BaseSales/index.js +102 -3
- package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/lib/solution/BaseSales/pickupTiming.js +269 -0
- package/lib/solution/BaseSales/types.d.ts +2 -2
- package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +4 -5
- package/lib/solution/BookingTicket/index.js +36 -33
- package/lib/solution/BookingTicket/types.d.ts +5 -1
- package/lib/solution/BookingTicket/utils/cartView.js +3 -1
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
- package/lib/solution/OrderInvoicePreview/index.d.ts +56 -0
- package/lib/solution/OrderInvoicePreview/index.js +192 -0
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +55 -9
- package/lib/solution/ShopDiscount/utils.d.ts +4 -2
- package/lib/solution/ShopDiscount/utils.js +42 -25
- package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/lib/solution/UnifiedBookingSales/index.js +132 -48
- package/lib/solution/index.d.ts +1 -0
- package/lib/solution/index.js +11 -0
- package/package.json +1 -1
|
@@ -17,7 +17,8 @@ export var searchWalletPass = /*#__PURE__*/function () {
|
|
|
17
17
|
// 翻译识别码名称 0:不翻译 1:翻译
|
|
18
18
|
relation_product: 1,
|
|
19
19
|
// 组装关联商品: 0不处理 1处理
|
|
20
|
-
|
|
20
|
+
with_franchisor_data: 1,
|
|
21
|
+
with: ['customer', 'franchiseeWalletPass:shop_id,source_shop_id,product_id,use'],
|
|
21
22
|
tags: ['point_card',
|
|
22
23
|
// 积分卡
|
|
23
24
|
'gift_card',
|
|
@@ -28,6 +29,8 @@ export var searchWalletPass = /*#__PURE__*/function () {
|
|
|
28
29
|
// 折扣卡
|
|
29
30
|
'good_pass',
|
|
30
31
|
// 商品券
|
|
32
|
+
'entitlement_pass',
|
|
33
|
+
// 月卡 / 年卡 / 多次使用卡
|
|
31
34
|
'session_ticket',
|
|
32
35
|
// 场次票
|
|
33
36
|
'appointment_ticket' // 预约类门票
|
|
@@ -74,14 +77,15 @@ export var searchWallet = /*#__PURE__*/function () {
|
|
|
74
77
|
case 0:
|
|
75
78
|
params = {
|
|
76
79
|
code: code,
|
|
77
|
-
with_customer: 1
|
|
80
|
+
with_customer: 1,
|
|
81
|
+
with_franchisor_data: 1
|
|
78
82
|
};
|
|
79
83
|
_context2.prev = 1;
|
|
80
84
|
_context2.next = 4;
|
|
81
85
|
return request === null || request === void 0 ? void 0 : request.post('/wallet/detail/search', params);
|
|
82
86
|
case 4:
|
|
83
87
|
res = _context2.sent;
|
|
84
|
-
if (!((res === null || res === void 0 ? void 0 : res.code)
|
|
88
|
+
if (!((res === null || res === void 0 ? void 0 : res.status) === true && (res === null || res === void 0 ? void 0 : res.code) === 200 && !!(res !== null && res !== void 0 && res.data))) {
|
|
85
89
|
_context2.next = 7;
|
|
86
90
|
break;
|
|
87
91
|
}
|
|
@@ -90,7 +94,7 @@ export var searchWallet = /*#__PURE__*/function () {
|
|
|
90
94
|
response: res
|
|
91
95
|
});
|
|
92
96
|
case 7:
|
|
93
|
-
throw new Error('没有找到对应的识别码');
|
|
97
|
+
throw new Error((res === null || res === void 0 ? void 0 : res.message) || '没有找到对应的识别码');
|
|
94
98
|
case 10:
|
|
95
99
|
_context2.prev = 10;
|
|
96
100
|
_context2.t0 = _context2["catch"](1);
|
|
@@ -6,6 +6,12 @@ export interface GlobalScanFormattedResult {
|
|
|
6
6
|
searchType: GlobalScanSearchType;
|
|
7
7
|
data: any;
|
|
8
8
|
scanCode: string;
|
|
9
|
+
/** Wallet / Wallet Pass 来源客户 ID;跨店时必须先解析为当前店客户。 */
|
|
10
|
+
customerId?: string | number;
|
|
11
|
+
/** 仅 Wallet 返回;true 时禁止直接使用响应内的来源客户。 */
|
|
12
|
+
isCrossShopWallet?: boolean;
|
|
13
|
+
/** 总店 Wallet Pass 未共享给当前子店。 */
|
|
14
|
+
isWalletPassUnavailableAtStore?: boolean;
|
|
9
15
|
}
|
|
10
16
|
interface RawScanSearchResult {
|
|
11
17
|
searchType?: GlobalScanSearchType;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
1
7
|
/**
|
|
2
8
|
* 全局扫码搜索结果格式化(对齐 ticketBooking `formatScanGlobal`)。
|
|
3
9
|
*/
|
|
@@ -27,16 +33,23 @@ export function formatGlobalScanResult(raw, scanCode) {
|
|
|
27
33
|
return {
|
|
28
34
|
searchType: searchType,
|
|
29
35
|
data: resultData === null || resultData === void 0 ? void 0 : resultData.customer,
|
|
30
|
-
scanCode: scanCode
|
|
36
|
+
scanCode: scanCode,
|
|
37
|
+
customerId: resultData === null || resultData === void 0 ? void 0 : resultData.customer_id,
|
|
38
|
+
isCrossShopWallet: (resultData === null || resultData === void 0 ? void 0 : resultData.is_cross_shop_wallet) === true || Number(resultData === null || resultData === void 0 ? void 0 : resultData.is_cross_shop_wallet) === 1
|
|
31
39
|
};
|
|
32
40
|
}
|
|
33
41
|
if (searchType === 'walletPass') {
|
|
34
|
-
var
|
|
35
|
-
|
|
42
|
+
var _firstResult$franchis, _ref2, _ref3, _firstResult$customer, _firstResult$holder, _firstResult$customer2, _firstResult$customer3;
|
|
43
|
+
var firstResult = resultData === null || resultData === void 0 ? void 0 : resultData[0];
|
|
44
|
+
var isWalletPassUnavailableAtStore = (firstResult === null || firstResult === void 0 ? void 0 : firstResult.is_franchisor_pass) === 1 && (firstResult === null || firstResult === void 0 || (_firstResult$franchis = firstResult.franchisee_wallet_pass) === null || _firstResult$franchis === void 0 ? void 0 : _firstResult$franchis.use) !== 'enabled';
|
|
45
|
+
return _objectSpread({
|
|
36
46
|
searchType: searchType,
|
|
37
|
-
data:
|
|
38
|
-
scanCode: scanCode
|
|
39
|
-
|
|
47
|
+
data: firstResult === null || firstResult === void 0 ? void 0 : firstResult.customer,
|
|
48
|
+
scanCode: scanCode,
|
|
49
|
+
customerId: (_ref2 = (_ref3 = (_firstResult$customer = firstResult === null || firstResult === void 0 ? void 0 : firstResult.customer_id) !== null && _firstResult$customer !== void 0 ? _firstResult$customer : firstResult === null || firstResult === void 0 || (_firstResult$holder = firstResult.holder) === null || _firstResult$holder === void 0 ? void 0 : _firstResult$holder.customer_id) !== null && _ref3 !== void 0 ? _ref3 : firstResult === null || firstResult === void 0 || (_firstResult$customer2 = firstResult.customer) === null || _firstResult$customer2 === void 0 ? void 0 : _firstResult$customer2.id) !== null && _ref2 !== void 0 ? _ref2 : firstResult === null || firstResult === void 0 || (_firstResult$customer3 = firstResult.customer) === null || _firstResult$customer3 === void 0 ? void 0 : _firstResult$customer3.customer_id
|
|
50
|
+
}, isWalletPassUnavailableAtStore ? {
|
|
51
|
+
isWalletPassUnavailableAtStore: true
|
|
52
|
+
} : {});
|
|
40
53
|
}
|
|
41
54
|
if (searchType === 'product' || searchType === 'local_product') {
|
|
42
55
|
return {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Module, ModuleOptions, PisellCore } from '../../types';
|
|
2
|
+
import { BaseModule } from '../../modules/BaseModule';
|
|
3
|
+
import type { InvoiceLayoutConfig } from '../../modules/OpenData';
|
|
4
|
+
import { type SmallTicketData } from '../../shared/receipt/small-ticket';
|
|
5
|
+
export interface OrderInvoicePreviewInput {
|
|
6
|
+
orderId: string | number;
|
|
7
|
+
tenantId: string | number;
|
|
8
|
+
shopId: string | number;
|
|
9
|
+
/** Changes on login/logout, without exposing credentials in state or cache keys. */
|
|
10
|
+
identity: string;
|
|
11
|
+
businessCode: string;
|
|
12
|
+
channel: string;
|
|
13
|
+
locale: string;
|
|
14
|
+
sourceRevision: string;
|
|
15
|
+
shop?: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
export interface OrderInvoicePreviewResult {
|
|
18
|
+
identity: string;
|
|
19
|
+
sourceRevision: string;
|
|
20
|
+
generatedAt: string;
|
|
21
|
+
locale: string;
|
|
22
|
+
orderId: string | number;
|
|
23
|
+
source: Record<string, any>;
|
|
24
|
+
shop: Record<string, any>;
|
|
25
|
+
layout: InvoiceLayoutConfig;
|
|
26
|
+
smallTicketData: SmallTicketData;
|
|
27
|
+
}
|
|
28
|
+
export interface OrderInvoicePreviewState {
|
|
29
|
+
status: 'idle' | 'loading' | 'ready' | 'error';
|
|
30
|
+
result: OrderInvoicePreviewResult | null;
|
|
31
|
+
error: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** Read-only, page-owned solution. No Order, Schedule, quotation or payment modules. */
|
|
34
|
+
export declare class OrderInvoicePreviewImpl extends BaseModule implements Module {
|
|
35
|
+
isSolution: boolean;
|
|
36
|
+
private request;
|
|
37
|
+
private state;
|
|
38
|
+
private listeners;
|
|
39
|
+
private generation;
|
|
40
|
+
private disposed;
|
|
41
|
+
private input?;
|
|
42
|
+
private activeKey;
|
|
43
|
+
private pending?;
|
|
44
|
+
private snapshotCache;
|
|
45
|
+
constructor(name?: string);
|
|
46
|
+
initialize(core: PisellCore, _options: ModuleOptions): void;
|
|
47
|
+
getState: () => OrderInvoicePreviewState;
|
|
48
|
+
subscribe: (listener: () => void) => (() => void);
|
|
49
|
+
private publish;
|
|
50
|
+
private getScope;
|
|
51
|
+
private loadContext;
|
|
52
|
+
private loadSource;
|
|
53
|
+
prepare(input: OrderInvoicePreviewInput): Promise<OrderInvoicePreviewResult>;
|
|
54
|
+
retry(): Promise<OrderInvoicePreviewResult>;
|
|
55
|
+
destroy(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
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); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
15
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
17
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
18
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
19
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
21
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
22
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
23
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
24
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
25
|
+
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; }
|
|
26
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
27
|
+
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); }
|
|
28
|
+
import { BaseModule } from "../../modules/BaseModule";
|
|
29
|
+
import { loadCustomerInvoiceLayout } from "../../shared/receipt/loadCustomerInvoiceLayout";
|
|
30
|
+
import { buildSmallTicketData } from "../../shared/receipt/small-ticket";
|
|
31
|
+
import { loadSalesOrderSnapshot } from "../../shared/sales/loadSalesOrderSnapshot";
|
|
32
|
+
import { loadPaymentMethods, withPaymentMethodNames } from "../../shared/payment/loadPaymentMethods";
|
|
33
|
+
// Page-runtime cache shared by preview instances, scoped to host, shop and identity.
|
|
34
|
+
var contextCaches = new WeakMap();
|
|
35
|
+
/** Read-only, page-owned solution. No Order, Schedule, quotation or payment modules. */
|
|
36
|
+
export var OrderInvoicePreviewImpl = /*#__PURE__*/function (_BaseModule) {
|
|
37
|
+
_inherits(OrderInvoicePreviewImpl, _BaseModule);
|
|
38
|
+
var _super = _createSuper(OrderInvoicePreviewImpl);
|
|
39
|
+
function OrderInvoicePreviewImpl() {
|
|
40
|
+
var _this;
|
|
41
|
+
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'orderInvoicePreview';
|
|
42
|
+
_classCallCheck(this, OrderInvoicePreviewImpl);
|
|
43
|
+
_this = _super.call(this, name);
|
|
44
|
+
_defineProperty(_assertThisInitialized(_this), "isSolution", true);
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "request", void 0);
|
|
46
|
+
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
47
|
+
status: 'idle',
|
|
48
|
+
result: null,
|
|
49
|
+
error: null
|
|
50
|
+
});
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "listeners", new Set());
|
|
52
|
+
_defineProperty(_assertThisInitialized(_this), "generation", 0);
|
|
53
|
+
_defineProperty(_assertThisInitialized(_this), "disposed", false);
|
|
54
|
+
_defineProperty(_assertThisInitialized(_this), "input", void 0);
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "activeKey", '');
|
|
56
|
+
_defineProperty(_assertThisInitialized(_this), "pending", void 0);
|
|
57
|
+
_defineProperty(_assertThisInitialized(_this), "snapshotCache", new Map());
|
|
58
|
+
_defineProperty(_assertThisInitialized(_this), "getState", function () {
|
|
59
|
+
return _this.state;
|
|
60
|
+
});
|
|
61
|
+
_defineProperty(_assertThisInitialized(_this), "subscribe", function (listener) {
|
|
62
|
+
_this.listeners.add(listener);
|
|
63
|
+
return function () {
|
|
64
|
+
_this.listeners.delete(listener);
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return _this;
|
|
68
|
+
}
|
|
69
|
+
_createClass(OrderInvoicePreviewImpl, [{
|
|
70
|
+
key: "initialize",
|
|
71
|
+
value: function initialize(core, _options) {
|
|
72
|
+
this.core = core;
|
|
73
|
+
var request = core.getPlugin('request');
|
|
74
|
+
if (!request) throw new Error('OrderInvoicePreview requires request plugin');
|
|
75
|
+
this.request = request;
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "publish",
|
|
79
|
+
value: function publish(state) {
|
|
80
|
+
this.state = state;
|
|
81
|
+
this.listeners.forEach(function (listener) {
|
|
82
|
+
return listener();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "getScope",
|
|
87
|
+
value: function getScope(input) {
|
|
88
|
+
return JSON.stringify([input.tenantId, input.shopId, input.identity, input.businessCode, input.channel]);
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "loadContext",
|
|
92
|
+
value: function loadContext(input) {
|
|
93
|
+
var cache = contextCaches.get(this.request);
|
|
94
|
+
if (!cache) {
|
|
95
|
+
cache = new Map();
|
|
96
|
+
contextCaches.set(this.request, cache);
|
|
97
|
+
}
|
|
98
|
+
var key = JSON.stringify([input.tenantId, input.shopId, input.identity, input.locale]);
|
|
99
|
+
var cached = cache.get(key);
|
|
100
|
+
if (cached) return cached;
|
|
101
|
+
var task = Promise.all([this.request.get('/shop/show', {}, {
|
|
102
|
+
manualErrorHandling: true,
|
|
103
|
+
skipErrorHandler: true
|
|
104
|
+
}), loadPaymentMethods(this.request, {
|
|
105
|
+
transport: 'remote',
|
|
106
|
+
filterPaymentMethods: false
|
|
107
|
+
})]).then(function (_ref) {
|
|
108
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
109
|
+
response = _ref2[0],
|
|
110
|
+
methods = _ref2[1];
|
|
111
|
+
var shop = response === null || response === void 0 ? void 0 : response.data;
|
|
112
|
+
if (!shop || _typeof(shop) !== 'object' || Array.isArray(shop)) throw new Error('Invoice shop information is unavailable');
|
|
113
|
+
if (String(shop.id) !== String(input.shopId)) throw new Error('Invoice shop identity mismatch');
|
|
114
|
+
return {
|
|
115
|
+
shop: shop,
|
|
116
|
+
methods: methods
|
|
117
|
+
};
|
|
118
|
+
}).catch(function (error) {
|
|
119
|
+
if (cache.get(key) === task) cache.delete(key);
|
|
120
|
+
throw error;
|
|
121
|
+
});
|
|
122
|
+
cache.set(key, task);
|
|
123
|
+
return task;
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
key: "loadSource",
|
|
127
|
+
value: function loadSource(input) {
|
|
128
|
+
var _this2 = this;
|
|
129
|
+
var key = JSON.stringify([this.getScope(input), input.orderId, input.sourceRevision]);
|
|
130
|
+
var cached = this.snapshotCache.get(key);
|
|
131
|
+
if (cached) return cached;
|
|
132
|
+
var task = loadSalesOrderSnapshot(this.request, {
|
|
133
|
+
lookup: input.orderId,
|
|
134
|
+
transport: 'remote'
|
|
135
|
+
}).then(function (response) {
|
|
136
|
+
if ((response === null || response === void 0 ? void 0 : response.code) !== 200 || !response.data || _typeof(response.data) !== 'object' || Array.isArray(response.data)) {
|
|
137
|
+
throw new Error((response === null || response === void 0 ? void 0 : response.message) || 'Invoice order is unavailable');
|
|
138
|
+
}
|
|
139
|
+
var source = response.data;
|
|
140
|
+
if (source.order_id != null && String(source.order_id) !== String(input.orderId)) {
|
|
141
|
+
throw new Error('Invoice order identity mismatch');
|
|
142
|
+
}
|
|
143
|
+
return source;
|
|
144
|
+
}).catch(function (error) {
|
|
145
|
+
if (_this2.snapshotCache.get(key) === task) _this2.snapshotCache.delete(key);
|
|
146
|
+
throw error;
|
|
147
|
+
});
|
|
148
|
+
this.snapshotCache.set(key, task);
|
|
149
|
+
return task;
|
|
150
|
+
}
|
|
151
|
+
}, {
|
|
152
|
+
key: "prepare",
|
|
153
|
+
value: function prepare(input) {
|
|
154
|
+
var _this$core$getPlugin,
|
|
155
|
+
_this$core$getPlugin$,
|
|
156
|
+
_this$core$getPlugin$2,
|
|
157
|
+
_this3 = this;
|
|
158
|
+
if (this.disposed) return Promise.reject(new Error('Invoice preview disposed'));
|
|
159
|
+
var currentShop = (_this$core$getPlugin = this.core.getPlugin('app')) === null || _this$core$getPlugin === void 0 || (_this$core$getPlugin$ = _this$core$getPlugin.getData) === null || _this$core$getPlugin$ === void 0 || (_this$core$getPlugin$2 = _this$core$getPlugin$.call(_this$core$getPlugin)) === null || _this$core$getPlugin$2 === void 0 ? void 0 : _this$core$getPlugin$2('shop_id');
|
|
160
|
+
if (currentShop != null && String(currentShop) !== String(input.shopId)) {
|
|
161
|
+
return Promise.reject(new Error('Invoice shop changed'));
|
|
162
|
+
}
|
|
163
|
+
var key = JSON.stringify([this.getScope(input), input.orderId, input.sourceRevision, input.locale]);
|
|
164
|
+
if (key === this.activeKey) {
|
|
165
|
+
if (this.pending) return this.pending;
|
|
166
|
+
if (this.state.status === 'ready' && this.state.result) return Promise.resolve(this.state.result);
|
|
167
|
+
}
|
|
168
|
+
if (this.input && this.getScope(this.input) !== this.getScope(input)) this.snapshotCache.clear();
|
|
169
|
+
this.input = input;
|
|
170
|
+
this.activeKey = key;
|
|
171
|
+
var generation = ++this.generation;
|
|
172
|
+
this.publish({
|
|
173
|
+
status: 'loading',
|
|
174
|
+
result: null,
|
|
175
|
+
error: null
|
|
176
|
+
});
|
|
177
|
+
var task = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
178
|
+
var _this3$core$getPlugin, _this3$core$getPlugin2, _coreData$core;
|
|
179
|
+
var _yield$Promise$all, _yield$Promise$all2, snapshot, context, layout, source, getData, coreData, shop, requestedLocale, locale, result;
|
|
180
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
181
|
+
while (1) switch (_context.prev = _context.next) {
|
|
182
|
+
case 0:
|
|
183
|
+
_context.next = 2;
|
|
184
|
+
return Promise.all([_this3.loadSource(input), _this3.loadContext(input), loadCustomerInvoiceLayout(_this3.request, input)]);
|
|
185
|
+
case 2:
|
|
186
|
+
_yield$Promise$all = _context.sent;
|
|
187
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
|
|
188
|
+
snapshot = _yield$Promise$all2[0];
|
|
189
|
+
context = _yield$Promise$all2[1];
|
|
190
|
+
layout = _yield$Promise$all2[2];
|
|
191
|
+
source = withPaymentMethodNames(snapshot, context.methods);
|
|
192
|
+
getData = (_this3$core$getPlugin = _this3.core.getPlugin('app')) === null || _this3$core$getPlugin === void 0 || (_this3$core$getPlugin2 = _this3$core$getPlugin.getData) === null || _this3$core$getPlugin2 === void 0 ? void 0 : _this3$core$getPlugin2.call(_this3$core$getPlugin);
|
|
193
|
+
if (!((getData === null || getData === void 0 ? void 0 : getData('shop_id')) != null && String(getData('shop_id')) !== String(input.shopId))) {
|
|
194
|
+
_context.next = 11;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
throw new Error('Invoice shop changed');
|
|
198
|
+
case 11:
|
|
199
|
+
coreData = getData === null || getData === void 0 ? void 0 : getData('core');
|
|
200
|
+
shop = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, (coreData === null || coreData === void 0 || (_coreData$core = coreData.core) === null || _coreData$core === void 0 ? void 0 : _coreData$core.shop) || (coreData === null || coreData === void 0 ? void 0 : coreData.shop) || {}), (getData === null || getData === void 0 ? void 0 : getData('shop_info')) || {}), input.shop), context.shop), getData !== null && getData !== void 0 && getData('tax_country_code') ? {
|
|
201
|
+
tax_country_code: getData('tax_country_code')
|
|
202
|
+
} : {});
|
|
203
|
+
if (!(generation !== _this3.generation || _this3.disposed)) {
|
|
204
|
+
_context.next = 15;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
throw new Error('Invoice request superseded');
|
|
208
|
+
case 15:
|
|
209
|
+
requestedLocale = input.locale.toLowerCase().replace(/_/g, '-');
|
|
210
|
+
locale = requestedLocale.startsWith('zh-tw') || requestedLocale.startsWith('zh-hk') ? 'zh_HK' : requestedLocale.startsWith('zh') ? 'zh_CN' : requestedLocale.startsWith('ja') ? 'ja' : requestedLocale.startsWith('pt') ? 'pt' : 'en';
|
|
211
|
+
result = {
|
|
212
|
+
identity: key,
|
|
213
|
+
orderId: input.orderId,
|
|
214
|
+
sourceRevision: input.sourceRevision,
|
|
215
|
+
generatedAt: new Date().toISOString(),
|
|
216
|
+
locale: locale,
|
|
217
|
+
source: source,
|
|
218
|
+
shop: shop,
|
|
219
|
+
layout: layout,
|
|
220
|
+
smallTicketData: buildSmallTicketData({
|
|
221
|
+
order: source,
|
|
222
|
+
shopInfo: shop,
|
|
223
|
+
locales: [locale]
|
|
224
|
+
})
|
|
225
|
+
};
|
|
226
|
+
_this3.publish({
|
|
227
|
+
status: 'ready',
|
|
228
|
+
result: result,
|
|
229
|
+
error: null
|
|
230
|
+
});
|
|
231
|
+
return _context.abrupt("return", result);
|
|
232
|
+
case 20:
|
|
233
|
+
case "end":
|
|
234
|
+
return _context.stop();
|
|
235
|
+
}
|
|
236
|
+
}, _callee);
|
|
237
|
+
}))().catch(function (error) {
|
|
238
|
+
if (generation === _this3.generation && !_this3.disposed) {
|
|
239
|
+
_this3.publish({
|
|
240
|
+
status: 'error',
|
|
241
|
+
result: null,
|
|
242
|
+
error: error instanceof Error ? error.message : String(error)
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
throw error;
|
|
246
|
+
}).finally(function () {
|
|
247
|
+
if (_this3.pending === task) _this3.pending = undefined;
|
|
248
|
+
});
|
|
249
|
+
this.pending = task;
|
|
250
|
+
return task;
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
key: "retry",
|
|
254
|
+
value: function retry() {
|
|
255
|
+
if (!this.input) return Promise.reject(new Error('Invoice input is missing'));
|
|
256
|
+
return this.prepare(this.input);
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "destroy",
|
|
260
|
+
value: function destroy() {
|
|
261
|
+
this.disposed = true;
|
|
262
|
+
this.generation++;
|
|
263
|
+
this.listeners.clear();
|
|
264
|
+
this.snapshotCache.clear();
|
|
265
|
+
if (this.core.getModule(this.name) === this) _get(_getPrototypeOf(OrderInvoicePreviewImpl.prototype), "destroy", this).call(this);
|
|
266
|
+
}
|
|
267
|
+
}]);
|
|
268
|
+
return OrderInvoicePreviewImpl;
|
|
269
|
+
}(BaseModule);
|
|
@@ -43,6 +43,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
43
43
|
batchSearchByProductIds(productIds: number[]): Promise<Discount[]>;
|
|
44
44
|
scanCode(code: string, customerId?: number): Promise<{
|
|
45
45
|
isAvailable: boolean;
|
|
46
|
+
isAccepted?: boolean;
|
|
46
47
|
productList: Record<string, any>[];
|
|
47
48
|
discountList: Discount[];
|
|
48
49
|
type: "server" | "clientCalc";
|
|
@@ -62,6 +63,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
62
63
|
action?: 'create' | 'edit';
|
|
63
64
|
with_good_pass?: 0 | 1;
|
|
64
65
|
with_discount_card?: 0 | 1;
|
|
66
|
+
with_entitlement_pass?: 0 | 1;
|
|
65
67
|
}): Promise<void>;
|
|
66
68
|
}
|
|
67
69
|
export default ShopDiscountImpl;
|