@pisell/pisellos 2.2.196 → 2.2.198
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/modules/Order/index.d.ts +16 -0
- package/dist/modules/Order/index.js +1176 -563
- package/dist/modules/Payment/walletpass.js +14 -7
- package/dist/modules/SalesSummary/utils.js +344 -133
- package/dist/server/index.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +0 -49
- package/lib/modules/Order/index.d.ts +16 -0
- package/lib/modules/Order/index.js +468 -13
- package/lib/modules/Payment/walletpass.js +7 -3
- package/lib/modules/SalesSummary/utils.js +255 -42
- package/lib/server/index.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -107,6 +107,7 @@ function buildSurchargeServiceItems(products) {
|
|
|
107
107
|
const quantity = getSafeNum(product.num);
|
|
108
108
|
const unitTotal = getUnitPaymentTotal(product);
|
|
109
109
|
const options = (0, import_utils2.getProductSkuOptions)(product);
|
|
110
|
+
const persistedSurchargeFee = getPersistedMainSurchargeFee(product);
|
|
110
111
|
return {
|
|
111
112
|
id: product.product_id,
|
|
112
113
|
num: quantity,
|
|
@@ -125,7 +126,10 @@ function buildSurchargeServiceItems(products) {
|
|
|
125
126
|
option: options,
|
|
126
127
|
options,
|
|
127
128
|
relation_details: [],
|
|
128
|
-
metadata:
|
|
129
|
+
metadata: {
|
|
130
|
+
...product.metadata || {},
|
|
131
|
+
__persisted_surcharge_fee: persistedSurchargeFee == null ? void 0 : persistedSurchargeFee.toFixed(2)
|
|
132
|
+
},
|
|
129
133
|
start_date: ((_a = product.metadata) == null ? void 0 : _a.start_date) || "",
|
|
130
134
|
start_time: ((_b = product.metadata) == null ? void 0 : _b.start_time) || ""
|
|
131
135
|
};
|
|
@@ -133,10 +137,11 @@ function buildSurchargeServiceItems(products) {
|
|
|
133
137
|
}
|
|
134
138
|
function getRelationSurchargeIds(item) {
|
|
135
139
|
var _a;
|
|
136
|
-
const ids =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
const ids = [
|
|
141
|
+
...Array.isArray(item == null ? void 0 : item.relation_surcharge_ids) ? item.relation_surcharge_ids : [],
|
|
142
|
+
...Array.isArray((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.relation_surcharge_ids) ? item.metadata.relation_surcharge_ids : []
|
|
143
|
+
];
|
|
144
|
+
return [...new Set(ids.filter((id) => id !== void 0 && id !== null && id !== ""))];
|
|
140
145
|
}
|
|
141
146
|
function getSurchargeConfigId(config) {
|
|
142
147
|
return (config == null ? void 0 : config.id) ?? (config == null ? void 0 : config.surcharge_id);
|
|
@@ -169,6 +174,50 @@ function getBundleProductId(bundle) {
|
|
|
169
174
|
return null;
|
|
170
175
|
return parsed;
|
|
171
176
|
}
|
|
177
|
+
function getPersistedMainSurchargeFee(product) {
|
|
178
|
+
var _a;
|
|
179
|
+
if ((product == null ? void 0 : product.order_detail_id) === void 0 || (product == null ? void 0 : product.order_detail_id) === null)
|
|
180
|
+
return null;
|
|
181
|
+
const value = (product == null ? void 0 : product.surcharge_fee) ?? (product == null ? void 0 : product.main_product_attached_bundle_surcharge_fee) ?? ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.main_product_attached_bundle_surcharge_fee);
|
|
182
|
+
if (value === void 0 || value === null || value === "")
|
|
183
|
+
return null;
|
|
184
|
+
return toDecimal(value);
|
|
185
|
+
}
|
|
186
|
+
function getPersistedSourceSurchargeFee(sourceItem) {
|
|
187
|
+
var _a;
|
|
188
|
+
const value = (_a = sourceItem == null ? void 0 : sourceItem.metadata) == null ? void 0 : _a.__persisted_surcharge_fee;
|
|
189
|
+
if (value === void 0 || value === null || value === "")
|
|
190
|
+
return null;
|
|
191
|
+
return toDecimal(value);
|
|
192
|
+
}
|
|
193
|
+
function getPersistedSurchargeRemainder(item, sourceItem) {
|
|
194
|
+
var _a, _b;
|
|
195
|
+
const value = ((_a = sourceItem == null ? void 0 : sourceItem.metadata) == null ? void 0 : _a.surcharge_rounding_remainder) ?? (item == null ? void 0 : item.surcharge_rounding_remainder) ?? ((_b = item == null ? void 0 : item.metadata) == null ? void 0 : _b.surcharge_rounding_remainder);
|
|
196
|
+
if (value === void 0 || value === null || value === "")
|
|
197
|
+
return null;
|
|
198
|
+
return toDecimal(value);
|
|
199
|
+
}
|
|
200
|
+
function getPersistedQuantity(item, fallbackQuantity) {
|
|
201
|
+
const isPersistedLine = (item == null ? void 0 : item.order_detail_id) !== void 0 && (item == null ? void 0 : item.order_detail_id) !== null;
|
|
202
|
+
if (!isPersistedLine)
|
|
203
|
+
return new import_decimal.default(0);
|
|
204
|
+
const value = (item == null ? void 0 : item.product_quantity) ?? (item == null ? void 0 : item.quantity);
|
|
205
|
+
const parsed = new import_decimal.default(value || 0);
|
|
206
|
+
if (parsed.lte(0))
|
|
207
|
+
return import_decimal.default.min(fallbackQuantity, 1);
|
|
208
|
+
return import_decimal.default.min(fallbackQuantity, parsed);
|
|
209
|
+
}
|
|
210
|
+
function getPersistedBundleSurchargeFee(bundle, product) {
|
|
211
|
+
var _a;
|
|
212
|
+
if ((bundle == null ? void 0 : bundle.order_detail_id) === void 0 && (product == null ? void 0 : product.order_detail_id) === void 0)
|
|
213
|
+
return null;
|
|
214
|
+
if ((bundle == null ? void 0 : bundle.order_detail_id) === null && (product == null ? void 0 : product.order_detail_id) === null)
|
|
215
|
+
return null;
|
|
216
|
+
const value = (bundle == null ? void 0 : bundle.surcharge_fee) ?? ((_a = bundle == null ? void 0 : bundle.metadata) == null ? void 0 : _a.surcharge_fee);
|
|
217
|
+
if (value === void 0 || value === null || value === "")
|
|
218
|
+
return null;
|
|
219
|
+
return toDecimal(value);
|
|
220
|
+
}
|
|
172
221
|
function createSurchargeAllocationNodes(products, sourceItems) {
|
|
173
222
|
var _a;
|
|
174
223
|
const nodes = [];
|
|
@@ -188,7 +237,10 @@ function createSurchargeAllocationNodes(products, sourceItems) {
|
|
|
188
237
|
productId: getBundleProductId(bundle),
|
|
189
238
|
unitAmount: getBundleSurchargeUnitAmount(bundle),
|
|
190
239
|
quantity: new import_decimal.default(getSafeNum((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity))).times(productQuantity),
|
|
191
|
-
|
|
240
|
+
persistedQuantity: getPersistedQuantity(bundle, new import_decimal.default(getSafeNum((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity))).times(productQuantity)),
|
|
241
|
+
relationSurchargeIds: getRelationSurchargeIds(sourceBundle).length ? getRelationSurchargeIds(sourceBundle) : getRelationSurchargeIds(bundle),
|
|
242
|
+
persistedUnitSurchargeFee: getPersistedBundleSurchargeFee(bundle, product),
|
|
243
|
+
persistedSurchargeRemainder: getPersistedSurchargeRemainder(bundle, sourceBundle)
|
|
192
244
|
});
|
|
193
245
|
}
|
|
194
246
|
nodes.push({
|
|
@@ -198,7 +250,10 @@ function createSurchargeAllocationNodes(products, sourceItems) {
|
|
|
198
250
|
productId: product.product_id ?? null,
|
|
199
251
|
unitAmount: getMainSurchargeUnitAmount(product),
|
|
200
252
|
quantity: productQuantity,
|
|
201
|
-
|
|
253
|
+
persistedQuantity: getPersistedQuantity(product, productQuantity),
|
|
254
|
+
relationSurchargeIds: getRelationSurchargeIds(sourceItem).length ? getRelationSurchargeIds(sourceItem) : getRelationSurchargeIds(product),
|
|
255
|
+
persistedUnitSurchargeFee: getPersistedSourceSurchargeFee(sourceItem) ?? getPersistedMainSurchargeFee(product),
|
|
256
|
+
persistedSurchargeRemainder: getPersistedSurchargeRemainder(product, sourceItem)
|
|
202
257
|
});
|
|
203
258
|
}
|
|
204
259
|
return nodes;
|
|
@@ -221,6 +276,17 @@ function resetProductSurchargeFields(products) {
|
|
|
221
276
|
}
|
|
222
277
|
}
|
|
223
278
|
}
|
|
279
|
+
function getPersistedSurchargeIds(nodes) {
|
|
280
|
+
const ids = /* @__PURE__ */ new Set();
|
|
281
|
+
for (const node of nodes) {
|
|
282
|
+
if (!node.persistedUnitSurchargeFee || node.persistedUnitSurchargeFee.lte(0))
|
|
283
|
+
continue;
|
|
284
|
+
for (const surchargeId of node.relationSurchargeIds) {
|
|
285
|
+
ids.add(surchargeId);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return ids;
|
|
289
|
+
}
|
|
224
290
|
function buildSurchargeQuantityTotals(nodes) {
|
|
225
291
|
const totals = /* @__PURE__ */ new Map();
|
|
226
292
|
for (const node of nodes) {
|
|
@@ -261,6 +327,24 @@ function getBackendSurchargeState(stateMap, surchargeId, config) {
|
|
|
261
327
|
}
|
|
262
328
|
return state;
|
|
263
329
|
}
|
|
330
|
+
function buildSurchargeResultItem(config, surchargeId, amount, index) {
|
|
331
|
+
const name = (config == null ? void 0 : config.name) || (config == null ? void 0 : config.label) || {};
|
|
332
|
+
return {
|
|
333
|
+
key: `custom_surcharge_${index}`,
|
|
334
|
+
label: name,
|
|
335
|
+
name,
|
|
336
|
+
value: amount.toNumber(),
|
|
337
|
+
surcharge_id: surchargeId,
|
|
338
|
+
description: config == null ? void 0 : config.description,
|
|
339
|
+
type: "default",
|
|
340
|
+
fixed: config == null ? void 0 : config.fixed,
|
|
341
|
+
amount: amount.toNumber(),
|
|
342
|
+
percentage: config == null ? void 0 : config.percentage,
|
|
343
|
+
metadata: {
|
|
344
|
+
open_product: config == null ? void 0 : config.open_product
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
264
348
|
function applySurchargeNodeResult(node, params) {
|
|
265
349
|
const { unitSurchargeFee, roundingRemainder, surchargeIds } = params;
|
|
266
350
|
if (node.kind === "main") {
|
|
@@ -290,16 +374,64 @@ function calculateBackendProductSurcharges(params) {
|
|
|
290
374
|
node.relationSurchargeIds = fallbackAllProductSurchargeIds;
|
|
291
375
|
}
|
|
292
376
|
}
|
|
377
|
+
const persistedSurchargeIds = getPersistedSurchargeIds(nodes);
|
|
293
378
|
const quantityTotals = buildSurchargeQuantityTotals(nodes);
|
|
294
379
|
const stateMap = /* @__PURE__ */ new Map();
|
|
295
380
|
for (const node of nodes) {
|
|
296
381
|
let unitSurchargeFee = new import_decimal.default(0);
|
|
297
382
|
let roundingRemainder = new import_decimal.default(0);
|
|
298
383
|
const appliedSurchargeIds = [];
|
|
384
|
+
let persistedRemainderApplied = false;
|
|
299
385
|
for (const surchargeId of node.relationSurchargeIds) {
|
|
300
386
|
const config = configById.get(surchargeId);
|
|
301
387
|
const totalQuantity = quantityTotals.get(surchargeId) || new import_decimal.default(0);
|
|
302
|
-
if (
|
|
388
|
+
if (totalQuantity.lte(0))
|
|
389
|
+
continue;
|
|
390
|
+
const persistedUnitSurchargeFee = node.persistedUnitSurchargeFee;
|
|
391
|
+
if (persistedUnitSurchargeFee && persistedUnitSurchargeFee.gt(0)) {
|
|
392
|
+
const persistedQuantity = import_decimal.default.min(node.persistedQuantity, node.quantity);
|
|
393
|
+
const deltaQuantity = import_decimal.default.max(node.quantity.minus(persistedQuantity), 0);
|
|
394
|
+
const state2 = getBackendSurchargeState(
|
|
395
|
+
stateMap,
|
|
396
|
+
surchargeId,
|
|
397
|
+
config || { surcharge_id: surchargeId }
|
|
398
|
+
);
|
|
399
|
+
const persistedSurchargeRemainder = !persistedRemainderApplied && node.persistedSurchargeRemainder ? node.persistedSurchargeRemainder : new import_decimal.default(0);
|
|
400
|
+
state2.amount = bcAdd(
|
|
401
|
+
bcAdd(
|
|
402
|
+
state2.amount,
|
|
403
|
+
bcMul(persistedUnitSurchargeFee, persistedQuantity, 2),
|
|
404
|
+
2
|
|
405
|
+
),
|
|
406
|
+
persistedSurchargeRemainder,
|
|
407
|
+
2
|
|
408
|
+
);
|
|
409
|
+
const fixed2 = new import_decimal.default((config == null ? void 0 : config.fixed) || 0);
|
|
410
|
+
if (fixed2.gt(0))
|
|
411
|
+
state2.fixedIncluded = true;
|
|
412
|
+
let nodeTotalSurcharge = bcAdd(
|
|
413
|
+
bcMul(persistedUnitSurchargeFee, persistedQuantity, 2),
|
|
414
|
+
persistedSurchargeRemainder,
|
|
415
|
+
2
|
|
416
|
+
);
|
|
417
|
+
if (config && deltaQuantity.gt(0)) {
|
|
418
|
+
const percentage2 = new import_decimal.default(config.percentage || 0);
|
|
419
|
+
const deltaUnitPercentageFee = import_decimal.default.max(0, bcMul(node.unitAmount, percentage2, 2));
|
|
420
|
+
const deltaSurcharge = bcMul(deltaQuantity, deltaUnitPercentageFee, 2);
|
|
421
|
+
state2.amount = bcAdd(state2.amount, deltaSurcharge, 2);
|
|
422
|
+
nodeTotalSurcharge = bcAdd(nodeTotalSurcharge, deltaSurcharge, 2);
|
|
423
|
+
}
|
|
424
|
+
if (node.quantity.gt(0)) {
|
|
425
|
+
unitSurchargeFee = bcAdd(unitSurchargeFee, bcDiv(nodeTotalSurcharge, node.quantity, 2), 2);
|
|
426
|
+
}
|
|
427
|
+
if (!persistedSurchargeRemainder.eq(0)) {
|
|
428
|
+
roundingRemainder = bcAdd(roundingRemainder, persistedSurchargeRemainder, 2);
|
|
429
|
+
persistedRemainderApplied = true;
|
|
430
|
+
}
|
|
431
|
+
appliedSurchargeIds.push(surchargeId);
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (!config)
|
|
303
435
|
continue;
|
|
304
436
|
const percentage = new import_decimal.default(config.percentage || 0);
|
|
305
437
|
const fixed = new import_decimal.default(config.fixed || 0);
|
|
@@ -307,7 +439,7 @@ function calculateBackendProductSurcharges(params) {
|
|
|
307
439
|
const percentageTotalFee = bcMul(node.quantity, unitPercentageFee, 2);
|
|
308
440
|
let unitFixedFee = new import_decimal.default(0);
|
|
309
441
|
let fixedRemainder = new import_decimal.default(0);
|
|
310
|
-
if (fixed.gt(0)) {
|
|
442
|
+
if (fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
|
|
311
443
|
unitFixedFee = bcDiv(fixed, totalQuantity, 2);
|
|
312
444
|
const distributedFixed = bcMul(unitFixedFee, totalQuantity, 2);
|
|
313
445
|
fixedRemainder = bcSub(fixed, distributedFixed, 2);
|
|
@@ -328,7 +460,7 @@ function calculateBackendProductSurcharges(params) {
|
|
|
328
460
|
6
|
|
329
461
|
);
|
|
330
462
|
state.calculatedQuantity = bcAdd(state.calculatedQuantity, node.quantity, 6);
|
|
331
|
-
if (!state.fixedIncluded && fixed.gt(0)) {
|
|
463
|
+
if (!state.fixedIncluded && fixed.gt(0) && !persistedSurchargeIds.has(surchargeId)) {
|
|
332
464
|
state.amount = bcAdd(state.amount, fixed, 2);
|
|
333
465
|
state.fixedIncluded = true;
|
|
334
466
|
}
|
|
@@ -351,31 +483,25 @@ function calculateBackendProductSurcharges(params) {
|
|
|
351
483
|
surchargeIds: appliedSurchargeIds
|
|
352
484
|
});
|
|
353
485
|
}
|
|
354
|
-
|
|
486
|
+
const result = (surchargeList || []).reduce((items, config, index) => {
|
|
355
487
|
const surchargeId = getSurchargeConfigId(config);
|
|
356
488
|
if (surchargeId === void 0)
|
|
357
|
-
return
|
|
489
|
+
return items;
|
|
358
490
|
const state = stateMap.get(surchargeId);
|
|
359
491
|
if (!state || state.amount.lte(0))
|
|
360
|
-
return
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
key: `custom_surcharge_${index}`,
|
|
364
|
-
label: name,
|
|
365
|
-
name,
|
|
366
|
-
value: state.amount.toNumber(),
|
|
367
|
-
surcharge_id: surchargeId,
|
|
368
|
-
description: config.description,
|
|
369
|
-
type: "default",
|
|
370
|
-
fixed: config.fixed,
|
|
371
|
-
amount: state.amount.toNumber(),
|
|
372
|
-
percentage: config.percentage,
|
|
373
|
-
metadata: {
|
|
374
|
-
open_product: config.open_product
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
return result;
|
|
492
|
+
return items;
|
|
493
|
+
items.push(buildSurchargeResultItem(config, surchargeId, state.amount, index));
|
|
494
|
+
return items;
|
|
378
495
|
}, []);
|
|
496
|
+
const includedIds = new Set(
|
|
497
|
+
result.map((item) => item == null ? void 0 : item.surcharge_id).filter((id) => id !== void 0)
|
|
498
|
+
);
|
|
499
|
+
for (const [surchargeId, state] of stateMap.entries()) {
|
|
500
|
+
if (includedIds.has(surchargeId) || state.amount.lte(0))
|
|
501
|
+
continue;
|
|
502
|
+
result.push(buildSurchargeResultItem(state.config, surchargeId, state.amount, result.length));
|
|
503
|
+
}
|
|
504
|
+
return result;
|
|
379
505
|
}
|
|
380
506
|
function getProductDepositData(product) {
|
|
381
507
|
var _a, _b, _c;
|
|
@@ -508,6 +634,15 @@ function getPersistedTaxRemainder(item, parentProduct) {
|
|
|
508
634
|
return null;
|
|
509
635
|
return getExplicitTaxRemainder(item);
|
|
510
636
|
}
|
|
637
|
+
function getPersistedMainTaxFee(product) {
|
|
638
|
+
var _a;
|
|
639
|
+
if ((product == null ? void 0 : product.order_detail_id) === void 0 || (product == null ? void 0 : product.order_detail_id) === null)
|
|
640
|
+
return null;
|
|
641
|
+
const value = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.main_product_attached_bundle_tax_fee) ?? (product == null ? void 0 : product.main_product_attached_bundle_tax_fee) ?? (product == null ? void 0 : product.tax_fee);
|
|
642
|
+
if (value === void 0 || value === null || value === "")
|
|
643
|
+
return null;
|
|
644
|
+
return toDecimal(value);
|
|
645
|
+
}
|
|
511
646
|
function writeTaxRemainder(item, roundingRemainder) {
|
|
512
647
|
item.tax_fee_rounding_remainder = roundingRemainder.toNumber();
|
|
513
648
|
if (item.metadata && typeof item.metadata === "object") {
|
|
@@ -517,15 +652,24 @@ function writeTaxRemainder(item, roundingRemainder) {
|
|
|
517
652
|
function resetTaxRemainderFields(products) {
|
|
518
653
|
for (const product of products) {
|
|
519
654
|
const productRemainder = getPersistedTaxRemainder(product);
|
|
520
|
-
|
|
655
|
+
if (productRemainder !== null) {
|
|
656
|
+
product.tax_fee_rounding_remainder = productRemainder.toNumber();
|
|
657
|
+
} else {
|
|
658
|
+
delete product.tax_fee_rounding_remainder;
|
|
659
|
+
}
|
|
521
660
|
product.original_tax_fee_rounding_remainder = 0;
|
|
522
661
|
for (const bundle of product.product_bundle || []) {
|
|
523
662
|
const bundleRemainder = getPersistedTaxRemainder(bundle, product);
|
|
524
663
|
bundle.metadata = {
|
|
525
|
-
...bundle.metadata || {}
|
|
526
|
-
tax_fee_rounding_remainder: (bundleRemainder == null ? void 0 : bundleRemainder.toFixed(2)) ?? "0.00"
|
|
664
|
+
...bundle.metadata || {}
|
|
527
665
|
};
|
|
528
|
-
|
|
666
|
+
if (bundleRemainder !== null) {
|
|
667
|
+
bundle.metadata.tax_fee_rounding_remainder = bundleRemainder.toFixed(2);
|
|
668
|
+
bundle.tax_fee_rounding_remainder = bundleRemainder.toNumber();
|
|
669
|
+
} else {
|
|
670
|
+
delete bundle.metadata.tax_fee_rounding_remainder;
|
|
671
|
+
delete bundle.tax_fee_rounding_remainder;
|
|
672
|
+
}
|
|
529
673
|
bundle.original_tax_fee_rounding_remainder = 0;
|
|
530
674
|
}
|
|
531
675
|
}
|
|
@@ -617,17 +761,22 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
617
761
|
isChargeTax: product.is_charge_tax ?? 0
|
|
618
762
|
});
|
|
619
763
|
const mainTaxRounded = toBackendTaxFee(mainTaxPrecise);
|
|
620
|
-
product.main_product_attached_bundle_tax_fee = mainTaxRounded.toFixed(2);
|
|
621
764
|
const persistedMainRemainder = getPersistedTaxRemainder(product);
|
|
622
|
-
const
|
|
765
|
+
const persistedMainTaxFee = getPersistedMainTaxFee(product);
|
|
766
|
+
const persistedQuantity = getPersistedQuantity(product, quantity);
|
|
767
|
+
const deltaQuantity = import_decimal.default.max(quantity.minus(persistedQuantity), 0);
|
|
768
|
+
const shouldUsePersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gte(quantity);
|
|
769
|
+
const shouldSplitPersistedMainTax = persistedMainTaxFee && persistedMainTaxFee.gt(0) && persistedQuantity.gt(0) && deltaQuantity.gt(0);
|
|
770
|
+
const mainRemainder = shouldUsePersistedMainTax || shouldSplitPersistedMainTax ? new import_decimal.default(0) : persistedMainRemainder ?? applyBackendTaxRemainder({
|
|
623
771
|
target: product,
|
|
624
772
|
rawTax: mainTaxPrecise,
|
|
625
773
|
formattedTax: mainTaxRounded,
|
|
626
774
|
quantity,
|
|
627
775
|
state: taxRemainderState
|
|
628
776
|
});
|
|
629
|
-
if (persistedMainRemainder)
|
|
777
|
+
if (persistedMainRemainder && !shouldSplitPersistedMainTax) {
|
|
630
778
|
writeTaxRemainder(product, persistedMainRemainder);
|
|
779
|
+
}
|
|
631
780
|
const originalTotal = getUnitOriginalTotal(product);
|
|
632
781
|
const originalTaxableBase = originalTotal.lte(0) ? surchargeFee : originalTotal.plus(surchargeFee);
|
|
633
782
|
const originalTaxPrecise = calculateSingleItemTax({
|
|
@@ -637,18 +786,71 @@ function calculateProductsTax(products, taxRate, isPriceIncludeTax) {
|
|
|
637
786
|
isChargeTax: product.is_charge_tax ?? 0
|
|
638
787
|
});
|
|
639
788
|
const originalTaxRounded = toAmountFormat(originalTaxPrecise);
|
|
640
|
-
|
|
789
|
+
const effectiveMainUnitTax = shouldUsePersistedMainTax ? persistedMainTaxFee : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)).div(quantity).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP) : mainTaxRounded;
|
|
790
|
+
productUnitTax = productUnitTax.plus(effectiveMainUnitTax);
|
|
641
791
|
productUnitOriginTax = productUnitOriginTax.plus(originalTaxRounded);
|
|
792
|
+
product.main_product_attached_bundle_tax_fee = effectiveMainUnitTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
|
|
642
793
|
product.tax_fee = productUnitTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toFixed(2);
|
|
643
794
|
product.original_tax_fee = productUnitOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
644
|
-
totalTax = totalTax.plus(
|
|
795
|
+
totalTax = totalTax.plus(
|
|
796
|
+
shouldUsePersistedMainTax ? persistedMainTaxFee.times(quantity).plus(persistedMainRemainder || 0) : shouldSplitPersistedMainTax ? persistedMainTaxFee.times(persistedQuantity).plus(mainTaxRounded.times(deltaQuantity)) : mainTaxRounded.times(quantity).plus(mainRemainder)
|
|
797
|
+
);
|
|
645
798
|
totalOriginTax = totalOriginTax.plus(originalTaxRounded.times(quantity));
|
|
799
|
+
if (product.tax_fee_rounding_remainder === void 0) {
|
|
800
|
+
product.tax_fee_rounding_remainder = 0;
|
|
801
|
+
}
|
|
646
802
|
}
|
|
647
803
|
return {
|
|
648
804
|
tax: totalTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP),
|
|
649
805
|
originTax: totalOriginTax.toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP)
|
|
650
806
|
};
|
|
651
807
|
}
|
|
808
|
+
function applyShopDiscountToSurchargeBase(products, productAmount, shopDiscountAmount) {
|
|
809
|
+
if (productAmount.lte(0) || shopDiscountAmount.lte(0))
|
|
810
|
+
return () => {
|
|
811
|
+
};
|
|
812
|
+
const effectiveDiscount = import_decimal.default.min(productAmount, shopDiscountAmount);
|
|
813
|
+
if (effectiveDiscount.lte(0))
|
|
814
|
+
return () => {
|
|
815
|
+
};
|
|
816
|
+
const snapshots = products.map((product) => {
|
|
817
|
+
var _a;
|
|
818
|
+
return {
|
|
819
|
+
product,
|
|
820
|
+
metadata: product.metadata,
|
|
821
|
+
attachedBundleSellingPrice: (_a = product.metadata) == null ? void 0 : _a.main_product_attached_bundle_selling_price
|
|
822
|
+
};
|
|
823
|
+
});
|
|
824
|
+
let allocatedDiscount = new import_decimal.default(0);
|
|
825
|
+
products.forEach((product, index) => {
|
|
826
|
+
const quantity = new import_decimal.default(getSafeNum(product.num));
|
|
827
|
+
const lineAmount = getUnitPaymentTotal(product).times(quantity);
|
|
828
|
+
const lineDiscount = index === products.length - 1 ? effectiveDiscount.minus(allocatedDiscount) : toAmountFormat(lineAmount.div(productAmount).times(effectiveDiscount));
|
|
829
|
+
allocatedDiscount = allocatedDiscount.plus(lineDiscount);
|
|
830
|
+
const unitDiscount = quantity.lte(0) ? new import_decimal.default(0) : lineDiscount.div(quantity);
|
|
831
|
+
const currentBase = getMainSurchargeUnitAmount(product);
|
|
832
|
+
const adjustedBase = import_decimal.default.max(currentBase.minus(unitDiscount), 0);
|
|
833
|
+
product.metadata = {
|
|
834
|
+
...product.metadata || {},
|
|
835
|
+
main_product_attached_bundle_selling_price: adjustedBase.toFixed(2)
|
|
836
|
+
};
|
|
837
|
+
});
|
|
838
|
+
return () => {
|
|
839
|
+
for (const snapshot of snapshots) {
|
|
840
|
+
if (!snapshot.metadata) {
|
|
841
|
+
delete snapshot.product.metadata;
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
snapshot.product.metadata = {
|
|
845
|
+
...snapshot.product.metadata,
|
|
846
|
+
main_product_attached_bundle_selling_price: snapshot.attachedBundleSellingPrice
|
|
847
|
+
};
|
|
848
|
+
if (snapshot.attachedBundleSellingPrice === void 0) {
|
|
849
|
+
delete snapshot.product.metadata.main_product_attached_bundle_selling_price;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
}
|
|
652
854
|
function createEmptySalesSummary() {
|
|
653
855
|
return {
|
|
654
856
|
product_quantity: 0,
|
|
@@ -700,6 +902,17 @@ function calculateSalesSummary(params) {
|
|
|
700
902
|
(sum, item) => sum.plus(getUnitPaymentTotal(item).times(getSafeNum(item.num))),
|
|
701
903
|
new import_decimal.default(0)
|
|
702
904
|
);
|
|
905
|
+
const shopDiscountAmount = import_decimal.default.max(new import_decimal.default(Number(shopDiscount) || 0), 0);
|
|
906
|
+
const hasPersistedSurchargeSnapshot = summaryProducts.some((product) => {
|
|
907
|
+
var _a;
|
|
908
|
+
return (_a = getPersistedMainSurchargeFee(product)) == null ? void 0 : _a.gt(0);
|
|
909
|
+
});
|
|
910
|
+
const restoreSurchargeBase = hasPersistedSurchargeSnapshot ? () => {
|
|
911
|
+
} : applyShopDiscountToSurchargeBase(
|
|
912
|
+
summaryProducts,
|
|
913
|
+
productAmount,
|
|
914
|
+
shopDiscountAmount
|
|
915
|
+
);
|
|
703
916
|
const surchargeServiceItems = buildSurchargeServiceItems(summaryProducts);
|
|
704
917
|
(0, import_utils.getSurcharge)(
|
|
705
918
|
{
|
|
@@ -720,6 +933,7 @@ function calculateSalesSummary(params) {
|
|
|
720
933
|
sourceItems: surchargeServiceItems,
|
|
721
934
|
surchargeList
|
|
722
935
|
});
|
|
936
|
+
restoreSurchargeBase();
|
|
723
937
|
const surchargeAmount = new import_decimal.default(
|
|
724
938
|
(0, import_utils.getSurchargeAmount)(
|
|
725
939
|
{ bookingDetail: null, bookingId: void 0 },
|
|
@@ -738,9 +952,8 @@ function calculateSalesSummary(params) {
|
|
|
738
952
|
new import_decimal.default(0)
|
|
739
953
|
);
|
|
740
954
|
}
|
|
741
|
-
const
|
|
742
|
-
const
|
|
743
|
-
const totalAmount = isPriceIncludeTax === 1 ? preTaxExpectAmount : preTaxExpectAmount.plus(productTaxFee);
|
|
955
|
+
const orderAmountBeforeDiscount = productAmount.plus(surchargeAmount).plus(isPriceIncludeTax === 1 ? 0 : productTaxFee);
|
|
956
|
+
const totalAmount = import_decimal.default.max(0, orderAmountBeforeDiscount.minus(shopDiscountAmount));
|
|
744
957
|
const deposit = calculateProductsDeposit(summaryProducts);
|
|
745
958
|
return {
|
|
746
959
|
product_quantity: productQuantity,
|
package/lib/server/index.js
CHANGED
|
@@ -511,7 +511,7 @@ var Server = class {
|
|
|
511
511
|
});
|
|
512
512
|
const fresh = (response == null ? void 0 : response.data) ?? response;
|
|
513
513
|
if (!fresh || typeof fresh !== "object" || fresh.order_id == null) {
|
|
514
|
-
this.
|
|
514
|
+
this.logInfo("handleOrderSalesDetail: 后端返回订单为空", {
|
|
515
515
|
lookup,
|
|
516
516
|
backendPath
|
|
517
517
|
});
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 | 2 | 1 | 6 | 3 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 6 | 3 | 4 | 5;
|
|
315
315
|
}[]>;
|
|
316
316
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
317
317
|
private getScheduleDataByIds;
|