@pisell/pisellos 2.2.323 → 2.2.324
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/inventory/index.d.ts +92 -0
- package/dist/inventory/index.js +509 -0
- package/dist/modules/BookingContext/index.d.ts +2 -2
- package/dist/modules/BookingContext/index.js +55 -25
- package/dist/modules/BookingContext/types.d.ts +2 -0
- package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
- package/dist/modules/BookingContext/utils/index.d.ts +1 -0
- package/dist/modules/BookingContext/utils/index.js +1 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +20 -1
- package/dist/modules/BookingContext/utils/productExtend.js +122 -29
- package/dist/modules/Date/index.d.ts +1 -1
- package/dist/modules/Date/index.js +60 -14
- package/dist/modules/Date/types.d.ts +5 -0
- package/dist/modules/Discount/index.js +1 -0
- package/dist/modules/OpenData/index.d.ts +1 -0
- package/dist/modules/OpenData/index.js +1 -0
- package/dist/modules/OpenData/salesSettings.d.ts +32 -0
- package/dist/modules/OpenData/salesSettings.js +80 -0
- package/dist/modules/OpenData/types.d.ts +16 -0
- package/dist/modules/OpenData/utils.d.ts +1 -1
- package/dist/modules/OpenData/utils.js +3 -2
- package/dist/modules/Order/index.d.ts +54 -11
- package/dist/modules/Order/index.js +2699 -1411
- package/dist/modules/Order/types.d.ts +43 -5
- package/dist/modules/Order/types.js +4 -0
- package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/dist/modules/Order/unpaidAmountGap.js +72 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
- package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
- package/dist/modules/Order/utils.d.ts +3 -1
- package/dist/modules/Order/utils.js +6 -2
- package/dist/modules/ProductList/clientDataVariants.js +6 -2
- package/dist/modules/ProductList/index.d.ts +2 -0
- package/dist/modules/ProductList/index.js +161 -51
- package/dist/modules/ResourcePlanner/planner.js +58 -2
- package/dist/modules/ResourcePlanner/types.d.ts +13 -0
- package/dist/modules/Rules/index.d.ts +2 -0
- package/dist/modules/Rules/index.js +58 -39
- package/dist/modules/Schedule/index.d.ts +7 -1
- package/dist/modules/Schedule/index.js +155 -39
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/modules/bookingReadValidation.d.ts +6 -0
- package/dist/modules/bookingReadValidation.js +72 -0
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +1312 -1154
- package/dist/server/modules/order/index.js +2 -1
- package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/dist/shared/receipt/small-ticket.d.ts +4 -0
- package/dist/shared/receipt/small-ticket.js +70 -12
- package/dist/solution/BaseSales/index.d.ts +39 -5
- package/dist/solution/BaseSales/index.js +1828 -1462
- package/dist/solution/BaseSales/types.d.ts +1 -0
- package/dist/solution/BaseSales/types.js +1 -0
- package/dist/solution/BookingByStep/index.d.ts +17 -3
- package/dist/solution/BookingByStep/index.js +676 -361
- package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/dist/solution/BookingByStep/utils/resources.js +117 -76
- package/dist/solution/BookingTicket/index.d.ts +15 -3
- package/dist/solution/BookingTicket/index.js +249 -135
- package/dist/solution/BookingTicket/types.d.ts +14 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +39 -11
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +88 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/dist/solution/OrderInvoicePreview/index.js +14 -8
- package/dist/solution/ScanOrder/index.d.ts +2 -0
- package/dist/solution/ScanOrder/index.js +166 -67
- package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/dist/solution/ScanOrder/menuAvailability.js +363 -0
- package/dist/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
- package/dist/solution/UnifiedBookingSales/catalogQueryBatch.js +202 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +96 -4
- package/dist/solution/UnifiedBookingSales/index.js +3374 -1177
- package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
- package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
- package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
- package/dist/solution/UnifiedBookingSales/types.d.ts +71 -2
- package/dist/solution/UnifiedBookingSales/types.js +7 -1
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +283 -0
- package/dist/utils/platform.d.ts +2 -0
- package/dist/utils/platform.js +6 -0
- package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
- package/dist/utils/pos-receipt-auto-print.js +14 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +12 -0
- package/lib/inventory/index.d.ts +92 -0
- package/lib/inventory/index.js +287 -0
- package/lib/modules/BookingContext/index.d.ts +2 -2
- package/lib/modules/BookingContext/index.js +42 -10
- package/lib/modules/BookingContext/types.d.ts +2 -0
- package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
- package/lib/modules/BookingContext/utils/index.d.ts +1 -0
- package/lib/modules/BookingContext/utils/index.js +11 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +20 -1
- package/lib/modules/BookingContext/utils/productExtend.js +96 -7
- package/lib/modules/Date/index.d.ts +1 -1
- package/lib/modules/Date/index.js +28 -5
- package/lib/modules/Date/types.d.ts +5 -0
- package/lib/modules/Discount/index.js +1 -0
- package/lib/modules/OpenData/index.d.ts +1 -0
- package/lib/modules/OpenData/index.js +12 -0
- package/lib/modules/OpenData/salesSettings.d.ts +32 -0
- package/lib/modules/OpenData/salesSettings.js +70 -0
- package/lib/modules/OpenData/types.d.ts +16 -0
- package/lib/modules/OpenData/utils.d.ts +1 -1
- package/lib/modules/OpenData/utils.js +3 -2
- package/lib/modules/Order/index.d.ts +54 -11
- package/lib/modules/Order/index.js +659 -80
- package/lib/modules/Order/types.d.ts +43 -5
- package/lib/modules/Order/types.js +2 -0
- package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/lib/modules/Order/unpaidAmountGap.js +60 -0
- package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
- package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
- package/lib/modules/Order/utils.d.ts +3 -1
- package/lib/modules/Order/utils.js +6 -2
- package/lib/modules/ProductList/clientDataVariants.js +6 -2
- package/lib/modules/ProductList/index.d.ts +2 -0
- package/lib/modules/ProductList/index.js +74 -0
- package/lib/modules/ResourcePlanner/planner.js +52 -1
- package/lib/modules/ResourcePlanner/types.d.ts +13 -0
- package/lib/modules/Rules/index.d.ts +2 -0
- package/lib/modules/Rules/index.js +25 -9
- package/lib/modules/Schedule/index.d.ts +7 -1
- package/lib/modules/Schedule/index.js +68 -4
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/modules/bookingReadValidation.d.ts +6 -0
- package/lib/modules/bookingReadValidation.js +56 -0
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +5 -0
- package/lib/server/index.js +124 -16
- package/lib/server/modules/order/index.js +2 -1
- package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/lib/shared/receipt/small-ticket.d.ts +4 -0
- package/lib/shared/receipt/small-ticket.js +63 -8
- package/lib/solution/BaseSales/index.d.ts +39 -5
- package/lib/solution/BaseSales/index.js +212 -18
- package/lib/solution/BaseSales/types.d.ts +1 -0
- package/lib/solution/BaseSales/types.js +1 -0
- package/lib/solution/BookingByStep/index.d.ts +17 -3
- package/lib/solution/BookingByStep/index.js +222 -14
- package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/lib/solution/BookingByStep/utils/resources.js +25 -15
- package/lib/solution/BookingTicket/index.d.ts +15 -3
- package/lib/solution/BookingTicket/index.js +47 -4
- package/lib/solution/BookingTicket/types.d.ts +14 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +37 -6
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +54 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/lib/solution/OrderInvoicePreview/index.js +7 -1
- package/lib/solution/ScanOrder/index.d.ts +2 -0
- package/lib/solution/ScanOrder/index.js +72 -2
- package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/lib/solution/ScanOrder/menuAvailability.js +203 -0
- package/lib/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
- package/lib/solution/UnifiedBookingSales/catalogQueryBatch.js +109 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +96 -4
- package/lib/solution/UnifiedBookingSales/index.js +1316 -73
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
- package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +71 -2
- package/lib/solution/UnifiedBookingSales/types.js +4 -1
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +155 -0
- package/lib/utils/platform.d.ts +2 -0
- package/lib/utils/platform.js +7 -0
- package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
- package/lib/utils/pos-receipt-auto-print.js +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.salesGuardError = exports.InventoryController = void 0;
|
|
7
|
+
/** Optional, instance-scoped sales inventory. Never stored in ProductData or order payloads. */
|
|
8
|
+
|
|
9
|
+
const salesGuardError = message => Object.assign(new Error(message), {
|
|
10
|
+
code: 'SALES_GUARD_REJECTED'
|
|
11
|
+
});
|
|
12
|
+
exports.salesGuardError = salesGuardError;
|
|
13
|
+
const cancelled = () => Object.assign(new Error('Inventory request cancelled'), {
|
|
14
|
+
name: 'AbortError'
|
|
15
|
+
});
|
|
16
|
+
const variantIdentity = (productId, variantId) => JSON.stringify([String(productId), String(variantId ?? 0)]);
|
|
17
|
+
class InventoryController {
|
|
18
|
+
identity = Symbol('sales-inventory-instance');
|
|
19
|
+
scopeKey;
|
|
20
|
+
entries = new Map();
|
|
21
|
+
lastQuantities = new Map();
|
|
22
|
+
products = new Map();
|
|
23
|
+
keys = new Map();
|
|
24
|
+
catalogProducts = new Map();
|
|
25
|
+
listeners = new Set();
|
|
26
|
+
revision = 0;
|
|
27
|
+
state = 'stale';
|
|
28
|
+
pending;
|
|
29
|
+
disposed = false;
|
|
30
|
+
constructor(source) {
|
|
31
|
+
this.source = source;
|
|
32
|
+
this.scopeKey = source.scopeKey;
|
|
33
|
+
}
|
|
34
|
+
getRevision = () => this.revision;
|
|
35
|
+
subscribe = listener => {
|
|
36
|
+
this.listeners.add(listener);
|
|
37
|
+
return () => {
|
|
38
|
+
this.listeners.delete(listener);
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
publish() {
|
|
42
|
+
this.revision += 1;
|
|
43
|
+
this.listeners.forEach(listener => {
|
|
44
|
+
try {
|
|
45
|
+
listener();
|
|
46
|
+
} catch {/* A view cannot interrupt a stock update. */}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
assertCurrent(signal) {
|
|
50
|
+
if (this.disposed || signal?.aborted) throw cancelled();
|
|
51
|
+
this.source.assertCurrent();
|
|
52
|
+
}
|
|
53
|
+
activate() {
|
|
54
|
+
this.disposed = false;
|
|
55
|
+
}
|
|
56
|
+
dispose() {
|
|
57
|
+
this.disposed = true;
|
|
58
|
+
this.invalidate();
|
|
59
|
+
}
|
|
60
|
+
invalidate() {
|
|
61
|
+
this.pending?.controller.abort();
|
|
62
|
+
this.pending = undefined;
|
|
63
|
+
this.state = 'stale';
|
|
64
|
+
this.publish();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Catalog replaces identities; partial detail only merges its variants, never its prices. */
|
|
68
|
+
registerProducts(products, complete = false) {
|
|
69
|
+
this.assertCurrent();
|
|
70
|
+
let changed = false;
|
|
71
|
+
for (const product of products) {
|
|
72
|
+
const id = String(product.id ?? product.product_id);
|
|
73
|
+
if (complete && this.catalogProducts.get(id) === product) continue;
|
|
74
|
+
if (complete) this.catalogProducts.set(id, product);
|
|
75
|
+
const previous = this.products.get(id);
|
|
76
|
+
if (complete) for (const variantId of previous?.keys() || []) this.keys.delete(variantIdentity(id, variantId));
|
|
77
|
+
const variants = complete ? new Map() : new Map(previous);
|
|
78
|
+
const list = product.variant?.length ? product.variant : [{
|
|
79
|
+
id: 0,
|
|
80
|
+
code: product.code
|
|
81
|
+
}];
|
|
82
|
+
for (const variant of list) {
|
|
83
|
+
const variantId = String(variant.id ?? variant.product_variant_id ?? 0);
|
|
84
|
+
const key = this.source.keyOf(product, variant) ?? previous?.get(variantId);
|
|
85
|
+
variants.set(variantId, key);
|
|
86
|
+
this.keys.set(variantIdentity(id, variantId), key);
|
|
87
|
+
}
|
|
88
|
+
if (!previous || previous.size !== variants.size || [...variants].some(([id, key]) => previous.get(id) !== key)) changed = true;
|
|
89
|
+
this.products.set(id, variants);
|
|
90
|
+
}
|
|
91
|
+
if (changed) this.publish();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Consumers share I/O; cancelling one detail does not cancel another consumer. */
|
|
95
|
+
async refresh(context) {
|
|
96
|
+
this.assertCurrent(context.signal);
|
|
97
|
+
if (context.force) this.invalidate();
|
|
98
|
+
let read = this.pending;
|
|
99
|
+
if (!read) {
|
|
100
|
+
read = {
|
|
101
|
+
controller: new AbortController(),
|
|
102
|
+
consumers: 0,
|
|
103
|
+
promise: Promise.resolve()
|
|
104
|
+
};
|
|
105
|
+
const current = read;
|
|
106
|
+
this.pending = current;
|
|
107
|
+
this.state = 'loading';
|
|
108
|
+
this.publish();
|
|
109
|
+
current.promise = (async () => {
|
|
110
|
+
try {
|
|
111
|
+
const entries = await this.source.read({
|
|
112
|
+
reason: context.reason,
|
|
113
|
+
signal: current.controller.signal
|
|
114
|
+
});
|
|
115
|
+
this.assertCurrent(current.controller.signal);
|
|
116
|
+
if (this.pending !== current) throw cancelled();
|
|
117
|
+
this.entries = entries;
|
|
118
|
+
for (const [key, stock] of entries) if (stock.quantity !== null && Number.isSafeInteger(stock.quantity) && stock.quantity >= 0) this.lastQuantities.set(key, stock.quantity);
|
|
119
|
+
this.state = 'ready';
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (this.pending !== current || current.controller.signal.aborted) throw cancelled();
|
|
122
|
+
this.state = 'error';
|
|
123
|
+
throw error;
|
|
124
|
+
} finally {
|
|
125
|
+
if (this.pending === current) {
|
|
126
|
+
this.pending = undefined;
|
|
127
|
+
this.publish();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
})();
|
|
131
|
+
}
|
|
132
|
+
read.consumers += 1;
|
|
133
|
+
try {
|
|
134
|
+
if (!context.signal) await read.promise;else await new Promise((resolve, reject) => {
|
|
135
|
+
const signal = context.signal;
|
|
136
|
+
const abort = () => reject(cancelled());
|
|
137
|
+
signal.addEventListener('abort', abort, {
|
|
138
|
+
once: true
|
|
139
|
+
});
|
|
140
|
+
read.promise.then(resolve, reject).finally(() => signal.removeEventListener('abort', abort));
|
|
141
|
+
if (signal.aborted) abort();
|
|
142
|
+
});
|
|
143
|
+
this.assertCurrent(context.signal);
|
|
144
|
+
} finally {
|
|
145
|
+
read.consumers -= 1;
|
|
146
|
+
if (this.pending === read && read.consumers === 0) this.invalidate();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
availabilityForKey(key) {
|
|
150
|
+
const stock = key ? this.entries.get(key) : undefined;
|
|
151
|
+
const quantity = key ? this.lastQuantities.get(key) : undefined;
|
|
152
|
+
if (this.state !== 'ready') return {
|
|
153
|
+
status: this.state,
|
|
154
|
+
quantity,
|
|
155
|
+
message: this.source.message('unavailable')
|
|
156
|
+
};
|
|
157
|
+
if (!stock) return {
|
|
158
|
+
status: 'unmapped',
|
|
159
|
+
quantity,
|
|
160
|
+
message: this.source.message('unmapped')
|
|
161
|
+
};
|
|
162
|
+
if (stock.quantity === null || !Number.isSafeInteger(stock.quantity) || stock.quantity < 0) return {
|
|
163
|
+
status: 'error',
|
|
164
|
+
quantity,
|
|
165
|
+
message: stock.message || this.source.message('unavailable')
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
status: 'ready',
|
|
169
|
+
quantity: stock.quantity
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
availability(product, variantId) {
|
|
173
|
+
const id = product.id ?? product.product_id;
|
|
174
|
+
if (variantId !== undefined && variantId !== null) return this.availabilityForKey(this.keys.get(variantIdentity(id, variantId)));
|
|
175
|
+
const keys = [...new Set(this.products.get(String(id))?.values() || [])];
|
|
176
|
+
const states = keys.map(key => this.availabilityForKey(key));
|
|
177
|
+
if (!states.length) return this.availabilityForKey();
|
|
178
|
+
// Unmapped variants are not offered by this source. Exclude even their last
|
|
179
|
+
// known quantities, while preserving errors on variants that are configured.
|
|
180
|
+
const mappedStates = states.filter(entry => entry.status !== 'unmapped');
|
|
181
|
+
if (!mappedStates.length) return {
|
|
182
|
+
status: 'unmapped',
|
|
183
|
+
message: this.source.message('unmapped')
|
|
184
|
+
};
|
|
185
|
+
const quantity = mappedStates.every(entry => entry.quantity !== undefined) ? mappedStates.reduce((sum, entry) => sum + entry.quantity, 0) : undefined;
|
|
186
|
+
const failed = mappedStates.find(entry => entry.status !== 'ready');
|
|
187
|
+
if (quantity !== undefined && !Number.isSafeInteger(quantity)) return {
|
|
188
|
+
status: 'error',
|
|
189
|
+
message: this.source.message('unavailable')
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
status: failed?.status || 'ready',
|
|
193
|
+
quantity,
|
|
194
|
+
message: failed?.message
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
keyForLine(item) {
|
|
198
|
+
return this.keys.get(variantIdentity(item.product_id, item.product_variant_id ?? item.product_sku?.product_variant_id));
|
|
199
|
+
}
|
|
200
|
+
/** Advisory UI limit only. The serialized cart guard remains authoritative. */
|
|
201
|
+
selectionAvailability(product, variantId, items, editingItem) {
|
|
202
|
+
const identity = variantIdentity(product.id ?? product.product_id, variantId);
|
|
203
|
+
const key = this.keys.get(identity);
|
|
204
|
+
let availability = this.availabilityForKey(key);
|
|
205
|
+
let reserved = 0;
|
|
206
|
+
let retainedQuantity = 0;
|
|
207
|
+
for (const item of items) {
|
|
208
|
+
const matches = key ? this.keyForLine(item) === key : variantIdentity(item.product_id, item.product_variant_id ?? item.product_sku?.product_variant_id) === identity;
|
|
209
|
+
if (!matches) continue;
|
|
210
|
+
const count = Number(item.num ?? item.quantity);
|
|
211
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
212
|
+
availability = {
|
|
213
|
+
...availability,
|
|
214
|
+
status: 'error',
|
|
215
|
+
message: this.source.message('unavailable')
|
|
216
|
+
};
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (item === editingItem) retainedQuantity = count;else reserved += count;
|
|
220
|
+
}
|
|
221
|
+
if (!Number.isSafeInteger(reserved)) {
|
|
222
|
+
availability = {
|
|
223
|
+
...availability,
|
|
224
|
+
status: 'error',
|
|
225
|
+
message: this.source.message('unavailable')
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const availableQuantity = availability.status === 'ready' ? Math.max(0, availability.quantity - reserved) : 0;
|
|
229
|
+
return {
|
|
230
|
+
availability,
|
|
231
|
+
availableQuantity,
|
|
232
|
+
retainedQuantity,
|
|
233
|
+
maxQuantity: Math.max(availableQuantity, retainedQuantity)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
totals(items) {
|
|
237
|
+
const totals = new Map();
|
|
238
|
+
for (const item of items) {
|
|
239
|
+
const key = this.keyForLine(item);
|
|
240
|
+
const identity = key ? JSON.stringify(['inventory', key]) : variantIdentity(item.product_id, item.product_variant_id);
|
|
241
|
+
const quantity = Number(item.num ?? item.quantity);
|
|
242
|
+
if (!Number.isSafeInteger(quantity) || quantity < 0) throw salesGuardError(this.source.message('unavailable'));
|
|
243
|
+
if (!quantity) continue;
|
|
244
|
+
const total = (totals.get(identity)?.quantity || 0) + quantity;
|
|
245
|
+
if (!Number.isSafeInteger(total)) throw salesGuardError(this.source.message('unavailable'));
|
|
246
|
+
totals.set(identity, {
|
|
247
|
+
key,
|
|
248
|
+
quantity: total
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return totals;
|
|
252
|
+
}
|
|
253
|
+
validate(proposed, current = [], allowReductions = true) {
|
|
254
|
+
this.assertCurrent();
|
|
255
|
+
const previous = this.totals(current);
|
|
256
|
+
for (const [identity, {
|
|
257
|
+
key,
|
|
258
|
+
quantity
|
|
259
|
+
}] of this.totals(proposed)) {
|
|
260
|
+
if (allowReductions && quantity <= (previous.get(identity)?.quantity || 0)) continue;
|
|
261
|
+
const stock = this.availabilityForKey(key);
|
|
262
|
+
if (stock.status !== 'ready') throw salesGuardError(stock.message || this.source.message('unavailable'));
|
|
263
|
+
if (quantity > stock.quantity) throw salesGuardError(this.source.message('insufficient', {
|
|
264
|
+
key: key,
|
|
265
|
+
quantity: stock.quantity
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
freezeCheckout(items) {
|
|
270
|
+
if (!items.length || items.some(item => Number(item.num ?? item.quantity) <= 0)) {
|
|
271
|
+
throw salesGuardError(this.source.message('unavailable'));
|
|
272
|
+
}
|
|
273
|
+
this.validate(items, [], false);
|
|
274
|
+
return Object.freeze({
|
|
275
|
+
scopeKey: this.scopeKey,
|
|
276
|
+
revision: this.revision,
|
|
277
|
+
lines: Object.freeze(items.map((item, index) => Object.freeze({
|
|
278
|
+
lineId: String(item.metadata?.unique_identification_number ?? item.unique_identification_number ?? item.order_detail_id ?? index),
|
|
279
|
+
productId: item.product_id,
|
|
280
|
+
variantId: item.product_variant_id ?? item.product_sku?.product_variant_id ?? 0,
|
|
281
|
+
quantity: Number(item.num ?? item.quantity),
|
|
282
|
+
inventoryKey: this.keyForLine(item)
|
|
283
|
+
})))
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
exports.InventoryController = InventoryController;
|
|
@@ -12,7 +12,7 @@ export * from './utils';
|
|
|
12
12
|
export declare function __clearBookingContextSharedCacheForTest(): void;
|
|
13
13
|
/** 稳定序列化 config 查询参数,用于判断是否与上次 loadBookingConfig 一致。 */
|
|
14
14
|
export declare function buildBookingConfigQueryKey(params?: LoadBookingConfigParams): string;
|
|
15
|
-
/** 稳定序列化资源列表查询(date + bookingIds
|
|
15
|
+
/** 稳定序列化资源列表查询(date + bookingIds + resourceIds)。 */
|
|
16
16
|
export declare function buildBookingResourcesQueryKey(params?: LoadBookingResourcesParams): string;
|
|
17
17
|
export declare class BookingContextModule extends BaseModule implements Module, BookingContextModuleAPI {
|
|
18
18
|
protected defaultName: string;
|
|
@@ -22,7 +22,7 @@ export declare class BookingContextModule extends BaseModule implements Module,
|
|
|
22
22
|
private otherParams;
|
|
23
23
|
/** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
|
|
24
24
|
private lastConfigQueryKey;
|
|
25
|
-
/** 上次成功 loadResources 的 query key
|
|
25
|
+
/** 上次成功 loadResources 的 query key(接口合同 + 日期/预约/资源范围)。 */
|
|
26
26
|
private lastResourcesQueryKey;
|
|
27
27
|
constructor(name?: string, version?: string);
|
|
28
28
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
@@ -190,12 +190,38 @@ function resolveBookingConfigRequest(platform, params = {}) {
|
|
|
190
190
|
key: `${endpoint}:${JSON.stringify(sortedQuery)}`
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
|
+
function normalizeBookingResourceIds(ids) {
|
|
194
|
+
return [...new Set((ids || []).map(id => String(id).trim()).filter(Boolean))].sort();
|
|
195
|
+
}
|
|
193
196
|
|
|
194
|
-
/** 稳定序列化资源列表查询(date + bookingIds
|
|
197
|
+
/** 稳定序列化资源列表查询(date + bookingIds + resourceIds)。 */
|
|
195
198
|
function buildBookingResourcesQueryKey(params = {}) {
|
|
196
199
|
const date = toScheduleQueryDate(params.date);
|
|
197
200
|
const ids = (params.bookingIds || []).filter(id => typeof id === 'number' && Number.isFinite(id)).sort((a, b) => a - b);
|
|
198
|
-
|
|
201
|
+
const resourceIds = normalizeBookingResourceIds(params.resourceIds);
|
|
202
|
+
return `${date}|${ids.join(',')}${resourceIds.length ? `|resources:${JSON.stringify(resourceIds)}` : ''}`;
|
|
203
|
+
}
|
|
204
|
+
function resolveBookingResourcesRequest(platform, params) {
|
|
205
|
+
const date = toScheduleQueryDate(params.date);
|
|
206
|
+
const isCustomerPlatform = (0, _platform.isCustomerUserPlatform)(platform);
|
|
207
|
+
const resourceIds = normalizeBookingResourceIds(params.resourceIds);
|
|
208
|
+
return {
|
|
209
|
+
// The customer endpoint uses the same inclusive date range as DateModule.
|
|
210
|
+
// Keep the public date contract and the staff endpoint's existing query.
|
|
211
|
+
query: isCustomerPlatform ? {
|
|
212
|
+
start_date: date,
|
|
213
|
+
end_date: date,
|
|
214
|
+
...(resourceIds.length ? {
|
|
215
|
+
resource_ids: resourceIds
|
|
216
|
+
} : {})
|
|
217
|
+
} : {
|
|
218
|
+
date
|
|
219
|
+
},
|
|
220
|
+
key: `${isCustomerPlatform ? 'customer' : 'staff'}:${buildBookingResourcesQueryKey({
|
|
221
|
+
...params,
|
|
222
|
+
date
|
|
223
|
+
})}`
|
|
224
|
+
};
|
|
199
225
|
}
|
|
200
226
|
class BookingContextModule extends _BaseModule.BaseModule {
|
|
201
227
|
defaultName = 'bookingContext';
|
|
@@ -207,7 +233,7 @@ class BookingContextModule extends _BaseModule.BaseModule {
|
|
|
207
233
|
otherParams = {};
|
|
208
234
|
/** 上次成功 loadBookingConfig 的 query key;命中则不再请求。 */
|
|
209
235
|
lastConfigQueryKey = null;
|
|
210
|
-
/** 上次成功 loadResources 的 query key
|
|
236
|
+
/** 上次成功 loadResources 的 query key(接口合同 + 日期/预约/资源范围)。 */
|
|
211
237
|
lastResourcesQueryKey = null;
|
|
212
238
|
constructor(name, version) {
|
|
213
239
|
super(name, version);
|
|
@@ -277,9 +303,13 @@ class BookingContextModule extends _BaseModule.BaseModule {
|
|
|
277
303
|
}
|
|
278
304
|
async loadResources(params = {}, options = {}) {
|
|
279
305
|
const date = toScheduleQueryDate(params.date ?? this.store.date);
|
|
280
|
-
const
|
|
306
|
+
const {
|
|
307
|
+
query,
|
|
308
|
+
key: resourcesKey
|
|
309
|
+
} = resolveBookingResourcesRequest(this.otherParams?.platform, {
|
|
281
310
|
date,
|
|
282
|
-
bookingIds: params.bookingIds
|
|
311
|
+
bookingIds: params.bookingIds,
|
|
312
|
+
resourceIds: params.resourceIds
|
|
283
313
|
});
|
|
284
314
|
if (!options.forceRefresh && this.lastResourcesQueryKey === resourcesKey) {
|
|
285
315
|
return this.getResourcesOrigin();
|
|
@@ -295,9 +325,7 @@ class BookingContextModule extends _BaseModule.BaseModule {
|
|
|
295
325
|
if (!pending) {
|
|
296
326
|
const requestPromise = (async () => {
|
|
297
327
|
try {
|
|
298
|
-
const res = await this.request.get('/schedule/resource/list',
|
|
299
|
-
date
|
|
300
|
-
}, RESOURCE_LIST_CACHE);
|
|
328
|
+
const res = await this.request.get('/schedule/resource/list', query, RESOURCE_LIST_CACHE);
|
|
301
329
|
const {
|
|
302
330
|
list
|
|
303
331
|
} = (0, _formatResourceList.formatResourceListAndMap)(res?.data, params.bookingIds || []);
|
|
@@ -323,7 +351,9 @@ class BookingContextModule extends _BaseModule.BaseModule {
|
|
|
323
351
|
const configKey = resolveBookingConfigRequest(this.otherParams?.platform, params.bookingConfigParams).key;
|
|
324
352
|
const dateInput = params.date ?? this.store.date ?? (0, _dayjs.default)();
|
|
325
353
|
const queryDate = toScheduleQueryDate(dateInput);
|
|
326
|
-
const
|
|
354
|
+
const {
|
|
355
|
+
key: resourcesKey
|
|
356
|
+
} = resolveBookingResourcesRequest(this.otherParams?.platform, {
|
|
327
357
|
date: queryDate,
|
|
328
358
|
bookingIds: params.bookingIds
|
|
329
359
|
});
|
|
@@ -339,7 +369,9 @@ class BookingContextModule extends _BaseModule.BaseModule {
|
|
|
339
369
|
return this.getState();
|
|
340
370
|
}
|
|
341
371
|
const configKey = resolveBookingConfigRequest(this.otherParams?.platform, params.bookingConfigParams).key;
|
|
342
|
-
const
|
|
372
|
+
const {
|
|
373
|
+
key: resourcesKey
|
|
374
|
+
} = resolveBookingResourcesRequest(this.otherParams?.platform, {
|
|
343
375
|
date: queryDate,
|
|
344
376
|
bookingIds: params.bookingIds
|
|
345
377
|
});
|
|
@@ -22,6 +22,8 @@ export interface LoadBookingConfigParams {
|
|
|
22
22
|
export interface LoadBookingResourcesParams {
|
|
23
23
|
/** 查询日期,`YYYY-MM-DD`;缺省用 store 内已 set 的 date,再缺省为当天。 */
|
|
24
24
|
date?: string;
|
|
25
|
+
/** 用户端查询的资源 ID;PC/H5 资源接口需要显式范围才会返回对应实体。 */
|
|
26
|
+
resourceIds?: Array<number | string>;
|
|
25
27
|
/** 编辑态排除容量占用用的 booking id 列表。 */
|
|
26
28
|
bookingIds?: number[];
|
|
27
29
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import type { BookingCalcContext } from './productExtend';
|
|
3
|
+
export declare function isManualBookingProduct(product: any): boolean;
|
|
4
|
+
export declare function getCalendarBookingRange(product: any, ctx?: BookingCalcContext): {
|
|
5
|
+
startAt: string;
|
|
6
|
+
endAt: string;
|
|
7
|
+
duration: number;
|
|
8
|
+
startDate: dayjs.Dayjs;
|
|
9
|
+
endDate: dayjs.Dayjs;
|
|
10
|
+
} | undefined;
|
|
11
|
+
/** A prepared calendar cache is reused after SKU input; no availability-driven replacement is allowed. */
|
|
12
|
+
export declare function prepareCalendarBookingCacheItem(cacheItem: any, ctx: BookingCalcContext): any;
|
|
13
|
+
export declare function calendarBookingEntryKey(ctx: BookingCalcContext): string;
|
|
14
|
+
export declare function calendarBookingNeedsInput(cacheItem: any): boolean;
|
|
15
|
+
export declare function calendarBookingPreparationKey(cacheItem: any, ctx: BookingCalcContext): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.calendarBookingEntryKey = calendarBookingEntryKey;
|
|
7
|
+
exports.calendarBookingNeedsInput = calendarBookingNeedsInput;
|
|
8
|
+
exports.calendarBookingPreparationKey = calendarBookingPreparationKey;
|
|
9
|
+
exports.getCalendarBookingRange = getCalendarBookingRange;
|
|
10
|
+
exports.isManualBookingProduct = isManualBookingProduct;
|
|
11
|
+
exports.prepareCalendarBookingCacheItem = prepareCalendarBookingCacheItem;
|
|
12
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
13
|
+
var _localClock = require("../../ResourcePlanner/localClock");
|
|
14
|
+
var _serviceTimes = require("./serviceTimes");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function isManualBookingProduct(product) {
|
|
17
|
+
return !(0, _serviceTimes.isBookingProduct)(product) && Boolean(product?.extension_type === 'product_appointment' || product?.product_resource?.resources?.some(group => Number(group.status) === 1) || ['custom', 'package'].includes(product?.capacity?.type));
|
|
18
|
+
}
|
|
19
|
+
function getCalendarBookingRange(product, ctx) {
|
|
20
|
+
const range = ctx?.bookingTimeRangeFromCalendar;
|
|
21
|
+
if (!range || ctx?.platform !== 'pos' || (0, _serviceTimes.isMultiDayProduct)(product) || product?.duration_type === 'days' || product?.flexible?.duration?.type === 'days' || product?._extend?.sub_type === 'days' || !(0, _serviceTimes.isBookingProduct)(product) && !isManualBookingProduct(product)) return undefined;
|
|
22
|
+
try {
|
|
23
|
+
const offset = (0, _localClock.captureRuntimeOffsetMinutes)();
|
|
24
|
+
const normalize = text => {
|
|
25
|
+
const scalar = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(text));
|
|
26
|
+
const inputOffset = (0, _localClock.extractFixedOffsetMinutes)(text) ?? offset;
|
|
27
|
+
return (0, _localClock.formatLocalDateTime)(scalar + (offset - inputOffset) * 60000, offset);
|
|
28
|
+
};
|
|
29
|
+
const startAt = normalize(range.startAt);
|
|
30
|
+
const endAt = normalize(range.endAt);
|
|
31
|
+
const start = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(startAt));
|
|
32
|
+
const end = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(endAt));
|
|
33
|
+
const duration = (end - start) / 60000;
|
|
34
|
+
if (!Number.isInteger(duration) || duration <= 0 || start % 60000 || end % 60000) throw new Error();
|
|
35
|
+
return {
|
|
36
|
+
startAt,
|
|
37
|
+
endAt,
|
|
38
|
+
duration,
|
|
39
|
+
startDate: (0, _dayjs.default)(startAt.slice(0, 19)),
|
|
40
|
+
endDate: (0, _dayjs.default)(endAt.slice(0, 19))
|
|
41
|
+
};
|
|
42
|
+
} catch {
|
|
43
|
+
throw Object.assign(new Error('Calendar booking requires valid complete start/end times.'), {
|
|
44
|
+
code: 'INVALID_TARGET_FILTER'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A prepared calendar cache is reused after SKU input; no availability-driven replacement is allowed. */
|
|
50
|
+
function prepareCalendarBookingCacheItem(cacheItem, ctx) {
|
|
51
|
+
let range = getCalendarBookingRange(cacheItem, ctx);
|
|
52
|
+
if (!range) return cacheItem;
|
|
53
|
+
const resource = {};
|
|
54
|
+
const forms = (cacheItem.product_resource?.resources || []).filter(group => Number(group.status) === 1);
|
|
55
|
+
const entry = Number(ctx.resourceIdFromCalendar);
|
|
56
|
+
const preserveInput = cacheItem._data?.calendarBookingEntryKey === calendarBookingEntryKey(ctx);
|
|
57
|
+
let inputInvalid = false;
|
|
58
|
+
if (preserveInput) {
|
|
59
|
+
const ext = cacheItem._extend || {};
|
|
60
|
+
try {
|
|
61
|
+
if (!(ext.start_date ?? ext.startDate) || !(ext.end_date ?? ext.endDate) || !ext.start_time || !ext.end_time) throw new Error('Incomplete calendar input.');
|
|
62
|
+
range = getCalendarBookingRange(cacheItem, {
|
|
63
|
+
...ctx,
|
|
64
|
+
bookingTimeRangeFromCalendar: {
|
|
65
|
+
startAt: `${(0, _dayjs.default)(ext.start_date ?? ext.startDate).format('YYYY-MM-DD')}T${ext.start_time}:00`,
|
|
66
|
+
endAt: `${(0, _dayjs.default)(ext.end_date ?? ext.endDate).format('YYYY-MM-DD')}T${ext.end_time}:00`
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} catch {
|
|
70
|
+
range = undefined;
|
|
71
|
+
inputInvalid = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const form of forms) {
|
|
75
|
+
const ids = [...(form.optional_resource || []), ...(form.default_resource || [])];
|
|
76
|
+
const linked = ids.some(id => String(id) === String(entry));
|
|
77
|
+
const origin = ctx.resourcesOriginMap?.[entry];
|
|
78
|
+
const chosen = cacheItem._extend?.resource?.[String(form.id)];
|
|
79
|
+
const hasChosen = preserveInput && chosen !== undefined;
|
|
80
|
+
const validChosen = hasChosen && Array.isArray(chosen) && new Set(chosen.map(row => String(row.relation_id))).size === chosen.length && chosen.every(row => (row.form_id == null || String(row.form_id) === String(form.id)) && (Number(row.relation_id) === 0 || ids.some(id => String(id) === String(row.relation_id)) && ctx.resourcesOriginMap?.[row.relation_id] && (ctx.resourcesOriginMap[row.relation_id].form_id == null || String(ctx.resourcesOriginMap[row.relation_id].form_id) === String(form.id))));
|
|
81
|
+
if (hasChosen && !validChosen) inputInvalid = true;
|
|
82
|
+
if (hasChosen) {
|
|
83
|
+
resource[String(form.id)] = validChosen ? chosen : [];
|
|
84
|
+
} else if (linked && origin && (origin.form_id == null || String(origin.form_id) === String(form.id))) {
|
|
85
|
+
resource[String(form.id)] = [{
|
|
86
|
+
relation_type: origin.relation_type || 'form',
|
|
87
|
+
form_id: form.id,
|
|
88
|
+
relation_id: entry,
|
|
89
|
+
like_status: 'common',
|
|
90
|
+
metadata: {
|
|
91
|
+
form_name: form.title,
|
|
92
|
+
resource_name: origin.main_field
|
|
93
|
+
}
|
|
94
|
+
}];
|
|
95
|
+
} else {
|
|
96
|
+
resource[String(form.id)] = [];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...cacheItem,
|
|
101
|
+
...(isManualBookingProduct(cacheItem) && range ? {
|
|
102
|
+
duration: {
|
|
103
|
+
type: 'minutes',
|
|
104
|
+
value: range.duration
|
|
105
|
+
}
|
|
106
|
+
} : {}),
|
|
107
|
+
_data: {
|
|
108
|
+
...cacheItem._data,
|
|
109
|
+
calendarBookingInputInvalid: inputInvalid
|
|
110
|
+
},
|
|
111
|
+
_extend: {
|
|
112
|
+
...cacheItem._extend,
|
|
113
|
+
...(range ? {
|
|
114
|
+
startDate: range.startDate,
|
|
115
|
+
start_date: range.startDate,
|
|
116
|
+
start_time: range.startAt.slice(11, 16),
|
|
117
|
+
endDate: range.endDate,
|
|
118
|
+
end_date: range.endDate,
|
|
119
|
+
end_time: range.endAt.slice(11, 16),
|
|
120
|
+
duration: range.duration
|
|
121
|
+
} : {}),
|
|
122
|
+
resource
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function calendarBookingEntryKey(ctx) {
|
|
127
|
+
return JSON.stringify([ctx.bookingTimeRangeFromCalendar, ctx.resourceIdFromCalendar]);
|
|
128
|
+
}
|
|
129
|
+
function calendarBookingNeedsInput(cacheItem) {
|
|
130
|
+
if (cacheItem._data?.calendarBookingInputInvalid) return true;
|
|
131
|
+
const capacity = cacheItem.capacity;
|
|
132
|
+
if (capacity?.type === 'custom' && (!Array.isArray(capacity.custom) || !capacity.custom.length || capacity.custom.some(item => !Number.isFinite(Number(item.min)) || item.max == null || Number(item.min) !== Number(item.max)))) return true;
|
|
133
|
+
const groups = cacheItem.product_resource?.resources;
|
|
134
|
+
if (groups != null && !Array.isArray(groups)) return true;
|
|
135
|
+
const seen = new Set();
|
|
136
|
+
return (groups || []).some(group => {
|
|
137
|
+
if (Number(group.status) === 0) return false;
|
|
138
|
+
if (group.id == null || seen.has(String(group.id))) return true;
|
|
139
|
+
seen.add(String(group.id));
|
|
140
|
+
const rule = group.select_type;
|
|
141
|
+
if (Number(group.status) !== 1 || !rule || !['single', 'multiple'].includes(rule.type)) return true;
|
|
142
|
+
const min = Number(rule.min ?? (rule.type === 'single' ? 1 : NaN));
|
|
143
|
+
const max = Number(rule.max ?? (rule.type === 'single' ? 1 : NaN));
|
|
144
|
+
const rows = cacheItem._extend?.resource?.[String(group.id)];
|
|
145
|
+
const required = group.required ?? true;
|
|
146
|
+
const minimum = Math.max(required ? 1 : 0, min);
|
|
147
|
+
return !Number.isInteger(min) || !Number.isInteger(max) || min < 0 || max < minimum || !Array.isArray(rows) || rows.length < minimum || rows.length > max;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function calendarBookingPreparationKey(cacheItem, ctx) {
|
|
151
|
+
const identities = rows => (rows || []).map(row => [row.group_id ?? row.option_group_id ?? row.bundle_group_id, row.product_option_item_id ?? row.option_group_item_id ?? row.id, row._bundle_product_id ?? row.bundle_product_id, row.product_variant_id ?? row.bundle_variant_id, row.quantity ?? row.num ?? 1, identities(row.option)]).sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
152
|
+
const sku = cacheItem._extend?.other || {};
|
|
153
|
+
const ext = cacheItem._extend || {};
|
|
154
|
+
const dateKey = value => value == null || value === '' ? null : (0, _dayjs.default)(value).format('YYYY-MM-DD');
|
|
155
|
+
return JSON.stringify([ctx.bookingTimeRangeFromCalendar, ctx.resourceIdFromCalendar, cacheItem.capacity, cacheItem.product_resource, sku.product_variant_id ?? sku.variant_id, identities(sku.option), identities(sku.bundle), dateKey(ext.start_date ?? ext.startDate), ext.start_time, dateKey(ext.end_date ?? ext.endDate), ext.end_time, Object.entries(ext.resource || {}).map(([formId, rows]) => [formId, Array.isArray(rows) ? rows.map(row => [row.form_id, row.relation_id]) : null])]);
|
|
156
|
+
}
|
|
@@ -6,6 +6,7 @@ export * from './resources';
|
|
|
6
6
|
export * from './resourceSelection';
|
|
7
7
|
export * from './resourceErrors';
|
|
8
8
|
export * from './productExtend';
|
|
9
|
+
export * from './calendarBooking';
|
|
9
10
|
export * from './cacheItemToBookingInput';
|
|
10
11
|
export * from './buildCacheItemFromOrderLine';
|
|
11
12
|
export * from './buildNormalProductCacheItemFromOrderLine';
|
|
@@ -91,6 +91,17 @@ Object.keys(_productExtend).forEach(function (key) {
|
|
|
91
91
|
}
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
+
var _calendarBooking = require("./calendarBooking");
|
|
95
|
+
Object.keys(_calendarBooking).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _calendarBooking[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _calendarBooking[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
94
105
|
var _cacheItemToBookingInput = require("./cacheItemToBookingInput");
|
|
95
106
|
Object.keys(_cacheItemToBookingInput).forEach(function (key) {
|
|
96
107
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -7,13 +7,27 @@ import { TimeSlicesResult, TimeSlice, DurationSlice } from './timeSlices';
|
|
|
7
7
|
* 让 OS 这层完全可在 Node 单测下运行(dayjs 在 Node 也是纯函数)。
|
|
8
8
|
*/
|
|
9
9
|
export interface BookingCalcContext {
|
|
10
|
+
/** Real runtime platform, injected by BookingTicket rather than inferred from sales channel. */
|
|
11
|
+
platform?: string;
|
|
12
|
+
bookingTimeRangeFromCalendar?: {
|
|
13
|
+
startAt: string;
|
|
14
|
+
endAt: string;
|
|
15
|
+
};
|
|
10
16
|
/** Sales channel; remembered duration starts are accepted only by POS. */
|
|
11
17
|
channel?: string;
|
|
12
|
-
/**
|
|
18
|
+
/** Current in-memory order session, supplied by the owning Order module. */
|
|
19
|
+
orderSessionId?: string;
|
|
20
|
+
/** Rejects a session while an order replacement or hydration is pending. */
|
|
21
|
+
isOrderSessionCurrent?: (sessionId: string) => boolean;
|
|
22
|
+
/** Legacy start-only preference, or an exact interval owned by the current order session. */
|
|
13
23
|
rememberedTime?: {
|
|
14
24
|
businessDate: string;
|
|
15
25
|
startAt: string;
|
|
26
|
+
endAt?: string;
|
|
27
|
+
orderSessionId?: string;
|
|
16
28
|
};
|
|
29
|
+
/** An expired memory restarts from the current entry time, without following cart bookings. */
|
|
30
|
+
useCurrentTimeAfterRememberedExpiry?: boolean;
|
|
17
31
|
/** 来自 `/core/board/management/config` 的整套配置;常用路径见 sliceTimeSlices / appointmentTimingPreference。 */
|
|
18
32
|
bookingConfig?: any;
|
|
19
33
|
/** 资源 origin map(id → resource origin)。 */
|
|
@@ -24,6 +38,10 @@ export interface BookingCalcContext {
|
|
|
24
38
|
date?: any;
|
|
25
39
|
/** 上一个服务行(getServiceStartTimeAndEndTime 拼接续接 start_time 用)。可缺省。 */
|
|
26
40
|
previousService?: any;
|
|
41
|
+
/** UBS-only default-time policy. Other solutions retain their existing Board behavior. */
|
|
42
|
+
resolveDefaultBookingStart?: (cacheItem: any, fallback: string) => string | undefined;
|
|
43
|
+
/** Explicit holder context supplied before the cache item has received its holder snapshot. */
|
|
44
|
+
holderIds?: unknown;
|
|
27
45
|
/** 日历选中的资源 id(替代 info2 sessionStorage.serviceParams.resource_id)。 */
|
|
28
46
|
resourceIdFromCalendar?: number;
|
|
29
47
|
/** 资源自动分派开关(替代 info2 localStorage 'resource-auto-allocation');默认全开。 */
|
|
@@ -58,6 +76,7 @@ export declare function getServiceStartTimeAndEndTime(params: {
|
|
|
58
76
|
cacheItem: any;
|
|
59
77
|
timeObj: TimeSlicesResult;
|
|
60
78
|
ctx: BookingCalcContext;
|
|
79
|
+
defaultBookingStartFallback?: string;
|
|
61
80
|
}): any;
|
|
62
81
|
/**
|
|
63
82
|
* 综合:把 cacheItem 拼装出完整的 _extend / _data(资源 / 容量 / timeObj),并标记 autoClose。
|