@pisell/pisellos 2.3.128 → 2.3.129

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.
Files changed (88) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  4. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  5. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  6. package/dist/modules/Customer/index.js +6 -3
  7. package/dist/modules/Customer/types.d.ts +2 -0
  8. package/dist/modules/Discount/availability.d.ts +7 -0
  9. package/dist/modules/Discount/availability.js +49 -0
  10. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  11. package/dist/modules/Discount/entitlementPass.js +147 -0
  12. package/dist/modules/Discount/index.d.ts +2 -2
  13. package/dist/modules/Discount/index.js +37 -151
  14. package/dist/modules/Discount/types.d.ts +36 -5
  15. package/dist/modules/Order/index.d.ts +6 -0
  16. package/dist/modules/Order/index.js +443 -235
  17. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  18. package/dist/modules/Order/utils.d.ts +1 -1
  19. package/dist/modules/Order/utils.js +101 -60
  20. package/dist/modules/Payment/types.d.ts +21 -1
  21. package/dist/modules/Payment/types.js +2 -0
  22. package/dist/modules/Payment/walletpass.d.ts +1 -1
  23. package/dist/modules/Payment/walletpass.js +80 -47
  24. package/dist/modules/Rules/index.d.ts +2 -2
  25. package/dist/modules/Rules/index.js +480 -186
  26. package/dist/modules/Rules/types.d.ts +4 -0
  27. package/dist/server/modules/order/types.d.ts +2 -0
  28. package/dist/solution/BaseSales/index.d.ts +1 -0
  29. package/dist/solution/BaseSales/index.js +5 -2
  30. package/dist/solution/BaseSales/types.d.ts +2 -2
  31. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  32. package/dist/solution/BookingTicket/index.d.ts +1 -2
  33. package/dist/solution/BookingTicket/index.js +60 -63
  34. package/dist/solution/BookingTicket/types.d.ts +5 -1
  35. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  36. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  37. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  38. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  39. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  40. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  41. package/dist/solution/ShopDiscount/index.js +99 -42
  42. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  43. package/dist/solution/ShopDiscount/utils.js +43 -23
  44. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  45. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  46. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  47. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  48. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  49. package/lib/modules/Customer/index.js +5 -1
  50. package/lib/modules/Customer/types.d.ts +2 -0
  51. package/lib/modules/Discount/availability.d.ts +7 -0
  52. package/lib/modules/Discount/availability.js +43 -0
  53. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  54. package/lib/modules/Discount/entitlementPass.js +141 -0
  55. package/lib/modules/Discount/index.d.ts +2 -2
  56. package/lib/modules/Discount/index.js +23 -129
  57. package/lib/modules/Discount/types.d.ts +36 -5
  58. package/lib/modules/Order/index.d.ts +6 -0
  59. package/lib/modules/Order/index.js +213 -40
  60. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  61. package/lib/modules/Order/utils.d.ts +1 -1
  62. package/lib/modules/Order/utils.js +39 -3
  63. package/lib/modules/Payment/types.d.ts +21 -1
  64. package/lib/modules/Payment/types.js +1 -0
  65. package/lib/modules/Payment/walletpass.d.ts +1 -1
  66. package/lib/modules/Payment/walletpass.js +29 -9
  67. package/lib/modules/Rules/index.d.ts +2 -2
  68. package/lib/modules/Rules/index.js +357 -110
  69. package/lib/modules/Rules/types.d.ts +4 -0
  70. package/lib/server/modules/order/types.d.ts +2 -0
  71. package/lib/solution/BaseSales/index.d.ts +1 -0
  72. package/lib/solution/BaseSales/index.js +5 -2
  73. package/lib/solution/BaseSales/types.d.ts +2 -2
  74. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  75. package/lib/solution/BookingTicket/index.d.ts +1 -2
  76. package/lib/solution/BookingTicket/index.js +36 -33
  77. package/lib/solution/BookingTicket/types.d.ts +5 -1
  78. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  79. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  80. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  81. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  82. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  83. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  84. package/lib/solution/ShopDiscount/index.js +55 -9
  85. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  86. package/lib/solution/ShopDiscount/utils.js +42 -25
  87. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  88. package/package.json +1 -1
@@ -6,13 +6,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
6
  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; }
7
7
  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); } }
8
8
  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); }); }; }
9
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
10
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
9
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
14
- 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); }
15
- 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; }
16
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
11
  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); } }
18
12
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -25,6 +19,12 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
25
19
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
20
  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; } }
27
21
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
23
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+ 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); }
25
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
26
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
27
+ 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; }
28
28
  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; }
29
29
  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; }
30
30
  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; }
@@ -36,6 +36,7 @@ import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationFo
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import { getWeighedProductPriceFingerprint, resolveWeighedSourcePrice, withOriginalBundleOptionPrices } from "./utils/weighedProduct";
38
38
  import dayjs from 'dayjs';
39
+ import { getDiscountLifecycleReason } from "../Discount/availability";
39
40
  import { stripOsPrivatePayloadFields } from "../../utils/os-private-payload";
40
41
  import { buildSalesNoteText, decodeSalesNotesSnapshot, getSalesNotePolicy } from "./salesNotes";
41
42
  import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
@@ -49,6 +50,7 @@ import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from
49
50
  import { applyTempOrderSettlementState, getSelectedSettlementSnapshot, getSettlementKey, getTempOrderSettlementKey, getTempOrderSettlementSnapshot, isVirtualSettlementOrder, normalizeVirtualSettlementOrderProduct, normalizeVirtualSettlementProducts, OrderSettlementConflictError, releaseTempOrderSettlementState, VirtualCurrencyAssetNotFoundError, VirtualCurrencyBalanceError } from "./utils/virtualSettlement";
50
51
  import { DiscountModule } from "../Discount";
51
52
  import { RulesModule } from "../Rules";
53
+ import { isEntitlementPass, isFullCoveragePass } from "../Discount/entitlementPass";
52
54
  import { UnavailableReason } from "../Rules/types";
53
55
  import Decimal from 'decimal.js';
54
56
  import { cloneDeep } from 'lodash-es';
@@ -72,9 +74,26 @@ function isManualProductDiscountProduct(product) {
72
74
  return (item === null || item === void 0 ? void 0 : item.type) === 'product';
73
75
  });
74
76
  }
77
+ function syncReducedEntitlementPassUsageCount(discountList, previousQuantity, nextQuantity) {
78
+ if (!Array.isArray(discountList)) return discountList;
79
+ var previousCount = getSafeProductNum(previousQuantity);
80
+ var nextCount = getSafeProductNum(nextQuantity);
81
+ if (nextCount >= previousCount) return discountList;
82
+ return discountList.map(function (discount) {
83
+ var _discount$metadata$nu, _discount$metadata;
84
+ if (!isEntitlementPass(discount)) return discount;
85
+ var rawUsageCount = Number((_discount$metadata$nu = discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.num) !== null && _discount$metadata$nu !== void 0 ? _discount$metadata$nu : previousCount);
86
+ var usageCount = Number.isFinite(rawUsageCount) ? Math.max(Math.floor(rawUsageCount), 0) : previousCount;
87
+ return _objectSpread(_objectSpread({}, discount), {}, {
88
+ metadata: _objectSpread(_objectSpread({}, (discount === null || discount === void 0 ? void 0 : discount.metadata) || {}), {}, {
89
+ num: Math.min(usageCount, nextCount)
90
+ })
91
+ });
92
+ });
93
+ }
75
94
  var ORDER_PAYMENT_STATUS_PAID = 'paid';
76
95
  var ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
77
- var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
96
+ var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['entitlement_pass', 'good_pass', 'product_discount_card', 'discount_card']);
78
97
  function isCustomerPromotionDiscount(discount) {
79
98
  return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(String((discount === null || discount === void 0 ? void 0 : discount.tag) || (discount === null || discount === void 0 ? void 0 : discount.type) || '').toLowerCase());
80
99
  }
@@ -109,6 +128,27 @@ function getVoucherPaymentLifecycleKey(payment) {
109
128
  if (!isVoucherPaymentRecord(payment)) return null;
110
129
  return "".concat(String(payment.voucher_id), "::").concat(String(payment.status || ''));
111
130
  }
131
+ function getDiscountIdentityKey(discount) {
132
+ var id = discount === null || discount === void 0 ? void 0 : discount.id;
133
+ if (id === undefined || id === null || id === '') return null;
134
+ return String(id);
135
+ }
136
+ function mergeCommittedEntitlementWithRuntime(committed, runtime) {
137
+ var _committed$committedA, _runtime$id, _runtime$isDisabled, _runtime$isSelected;
138
+ var committedAppliedProductDetails = (_committed$committedA = committed.committedAppliedProductDetails) !== null && _committed$committedA !== void 0 && _committed$committedA.length ? committed.committedAppliedProductDetails : committed.appliedProductDetails || [];
139
+ return _objectSpread(_objectSpread(_objectSpread({}, committed), runtime), {}, {
140
+ id: (_runtime$id = runtime.id) !== null && _runtime$id !== void 0 ? _runtime$id : committed.id,
141
+ tag: runtime.tag || committed.tag,
142
+ type: runtime.type || committed.type,
143
+ isEditMode: false,
144
+ isDisabled: (_runtime$isDisabled = runtime.isDisabled) !== null && _runtime$isDisabled !== void 0 ? _runtime$isDisabled : false,
145
+ isSelected: (_runtime$isSelected = runtime.isSelected) !== null && _runtime$isSelected !== void 0 ? _runtime$isSelected : committed.isSelected,
146
+ isUsed: committed.isUsed || runtime.isUsed,
147
+ committedAppliedProductDetails: _toConsumableArray(committedAppliedProductDetails),
148
+ applicableProductDetails: [].concat(_toConsumableArray(committed.applicableProductDetails || []), _toConsumableArray(runtime.applicableProductDetails || [])),
149
+ appliedProductDetails: [].concat(_toConsumableArray(committedAppliedProductDetails), _toConsumableArray(runtime.appliedProductDetails || []))
150
+ });
151
+ }
112
152
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
113
153
  _inherits(OrderModule, _BaseModule);
114
154
  var _super = _createSuper(OrderModule);
@@ -173,7 +213,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
173
213
  _step2;
174
214
  try {
175
215
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
176
- var _item$type2, _ref, _ref2, _item$discount$resour, _item$discount, _item$discount$title, _item$discount2, _item$discount3, _item$discount$fixed_, _item$discount4, _item$discount5, _item$amount, _ref3, _item$discount$origin, _item$discount6, _ref4, _ref5, _item$metadata$num, _item$metadata, _ref6, _ref7, _item$metadata$num2, _item$metadata2, _ref8, _item$discount$discou, _item$discount7, _item$amount2, _item$amount3, _product$product_id, _product$is_charge_ta, _ref9, _product$original_pri, _ref10, _item$discount$discou2, _item$discount8, _item$discount$discou3, _item$discount9;
216
+ var _item$type2, _ref, _ref2, _item$discount$resour, _item$discount, _item$discount$title, _item$discount2, _item$metadata, _item$discount3, _item$discount4, _item$discount$fixed_, _item$discount5, _item$discount6, _item$amount, _ref3, _item$discount$origin, _item$discount7, _ref4, _ref5, _item$metadata$num, _item$metadata2, _item$discount$produc, _item$discount8, _ref6, _ref7, _item$metadata$num2, _item$metadata3, _item$discount9, _ref8, _item$discount$discou, _item$discount10, _item$amount2, _item$amount3, _product$product_id, _product$is_charge_ta, _ref9, _product$original_pri, _ref10, _item$discount$discou2, _item$discount11, _item$discount$discou3, _item$discount12;
177
217
  var item = _step2.value;
178
218
  var type = (_item$type2 = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type2 !== void 0 ? _item$type2 : item === null || item === void 0 ? void 0 : item.tag;
179
219
  if (!type || type === 'product') continue;
@@ -184,22 +224,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
184
224
  var key = Number.isFinite(id) ? id : String(resourceId);
185
225
  var title = (_item$discount$title = item === null || item === void 0 || (_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.title) !== null && _item$discount$title !== void 0 ? _item$discount$title : {};
186
226
  var amount = Number((item === null || item === void 0 ? void 0 : item.amount) || 0);
187
- var discountCardType = item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.discount_card_type;
188
- var parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? (_item$discount$fixed_ = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.fixed_amount) !== null && _item$discount$fixed_ !== void 0 ? _item$discount$fixed_ : item === null || item === void 0 ? void 0 : item.amount : item === null || item === void 0 || (_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.percent : '0';
227
+ var encoded = (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.encoded) || (item === null || item === void 0 ? void 0 : item.encoded) || (item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.encoded) || '';
228
+ var discountCardType = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.discount_card_type;
229
+ var parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? (_item$discount$fixed_ = item === null || item === void 0 || (_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.fixed_amount) !== null && _item$discount$fixed_ !== void 0 ? _item$discount$fixed_ : item === null || item === void 0 ? void 0 : item.amount : item === null || item === void 0 || (_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.percent : '0';
189
230
  var detail = {
190
231
  amount: String((_item$amount = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount !== void 0 ? _item$amount : '0'),
191
232
  type: type,
192
233
  resource_id: key,
193
234
  title: title,
194
- original_amount: String((_ref3 = (_item$discount$origin = item === null || item === void 0 || (_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.original_amount) !== null && _item$discount$origin !== void 0 ? _item$discount$origin : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref3 !== void 0 ? _ref3 : '0'),
195
- num: Number((_ref4 = (_ref5 = (_item$metadata$num = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.num) !== null && _item$metadata$num !== void 0 ? _item$metadata$num : product === null || product === void 0 ? void 0 : product.num) !== null && _ref5 !== void 0 ? _ref5 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref4 !== void 0 ? _ref4 : 1) || 1,
235
+ original_amount: String((_ref3 = (_item$discount$origin = item === null || item === void 0 || (_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.original_amount) !== null && _item$discount$origin !== void 0 ? _item$discount$origin : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref3 !== void 0 ? _ref3 : '0'),
236
+ num: Number((_ref4 = (_ref5 = (_item$metadata$num = item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.num) !== null && _item$metadata$num !== void 0 ? _item$metadata$num : product === null || product === void 0 ? void 0 : product.num) !== null && _ref5 !== void 0 ? _ref5 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref4 !== void 0 ? _ref4 : 1) || 1,
196
237
  metadata: item === null || item === void 0 ? void 0 : item.metadata,
197
- discount: item === null || item === void 0 ? void 0 : item.discount,
198
- _num: Number((_ref6 = (_ref7 = (_item$metadata$num2 = item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.num) !== null && _item$metadata$num2 !== void 0 ? _item$metadata$num2 : product === null || product === void 0 ? void 0 : product.num) !== null && _ref7 !== void 0 ? _ref7 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref6 !== void 0 ? _ref6 : 1) || 1
238
+ discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
239
+ product_id: (_item$discount$produc = item === null || item === void 0 || (_item$discount8 = item.discount) === null || _item$discount8 === void 0 ? void 0 : _item$discount8.product_id) !== null && _item$discount$produc !== void 0 ? _item$discount$produc : product === null || product === void 0 ? void 0 : product.product_id
240
+ }),
241
+ _num: Number((_ref6 = (_ref7 = (_item$metadata$num2 = item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.num) !== null && _item$metadata$num2 !== void 0 ? _item$metadata$num2 : product === null || product === void 0 ? void 0 : product.num) !== null && _ref7 !== void 0 ? _ref7 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref6 !== void 0 ? _ref6 : 1) || 1
199
242
  };
200
243
  var existed = discountMap.get(key);
201
244
  if (existed) {
202
245
  var _existed$limited_rela;
246
+ if (!existed.encoded && encoded) {
247
+ existed.encoded = encoded;
248
+ existed.metadata = _objectSpread(_objectSpread({}, existed.metadata), {}, {
249
+ encoded: encoded
250
+ });
251
+ }
203
252
  existed.amount = Number(existed.amount || 0) + amount;
204
253
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
205
254
  if (!isDiscountCard) {
@@ -218,10 +267,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
218
267
  discountMap.set(key, {
219
268
  id: key,
220
269
  product_name: '',
221
- encoded: '',
222
- code: '',
270
+ encoded: encoded,
271
+ code: (item === null || item === void 0 ? void 0 : item.code) || (item === null || item === void 0 || (_item$discount9 = item.discount) === null || _item$discount9 === void 0 ? void 0 : _item$discount9.code) || '',
272
+ metadata: {
273
+ encoded: encoded
274
+ },
223
275
  tag: type,
224
- product_id: (_ref8 = (_item$discount$discou = item === null || item === void 0 || (_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.discount_product_id) !== null && _item$discount$discou !== void 0 ? _item$discount$discou : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
276
+ product_id: (_ref8 = (_item$discount$discou = item === null || item === void 0 || (_item$discount10 = item.discount) === null || _item$discount10 === void 0 ? void 0 : _item$discount10.discount_product_id) !== null && _item$discount$discou !== void 0 ? _item$discount$discou : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
225
277
  relation_type: '',
226
278
  par_value: String(parValue !== null && parValue !== void 0 ? parValue : '0'),
227
279
  used_par_value: String((_item$amount2 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount2 !== void 0 ? _item$amount2 : '0'),
@@ -254,8 +306,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
254
306
  amount: amount,
255
307
  discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
256
308
  resource_id: key,
257
- discount_product_id: (_ref10 = (_item$discount$discou2 = item === null || item === void 0 || (_item$discount8 = item.discount) === null || _item$discount8 === void 0 ? void 0 : _item$discount8.discount_product_id) !== null && _item$discount$discou2 !== void 0 ? _item$discount$discou2 : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
258
- discount_calculation_mode: (_item$discount$discou3 = item === null || item === void 0 || (_item$discount9 = item.discount) === null || _item$discount9 === void 0 ? void 0 : _item$discount9.discount_calculation_mode) !== null && _item$discount$discou3 !== void 0 ? _item$discount$discou3 : 'item_level'
309
+ discount_product_id: (_ref10 = (_item$discount$discou2 = item === null || item === void 0 || (_item$discount11 = item.discount) === null || _item$discount11 === void 0 ? void 0 : _item$discount11.discount_product_id) !== null && _item$discount$discou2 !== void 0 ? _item$discount$discou2 : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
310
+ discount_calculation_mode: (_item$discount$discou3 = item === null || item === void 0 || (_item$discount12 = item.discount) === null || _item$discount12 === void 0 ? void 0 : _item$discount12.discount_calculation_mode) !== null && _item$discount$discou3 !== void 0 ? _item$discount$discou3 : 'item_level'
259
311
  }),
260
312
  applicableProductDetails: [detail],
261
313
  appliedProductDetails: [detail]
@@ -559,7 +611,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
559
611
  }, {
560
612
  key: "createDefaultRulesHooks",
561
613
  value: function createDefaultRulesHooks() {
562
- return createDefaultOrderRulesHooks();
614
+ var _this2 = this;
615
+ return createDefaultOrderRulesHooks(function () {
616
+ var _this2$store$tempOrde;
617
+ return ((_this2$store$tempOrde = _this2.store.tempOrder) === null || _this2$store$tempOrde === void 0 ? void 0 : _this2$store$tempOrde.bookings) || [];
618
+ });
563
619
  }
564
620
 
565
621
  /**
@@ -581,9 +637,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
581
637
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
582
638
  var _this$store$tempOrder,
583
639
  _this$store$discount,
584
- _this2 = this,
640
+ _this3 = this,
585
641
  _this$store$tempOrder2;
586
- var orderId, requestEpoch, requestOrderIdentityKey, prepareConfigResult, isCurrentRequest, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentEditDiscounts, currentScanDiscounts, currentScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, mergedDiscountList;
642
+ var orderId, requestEpoch, requestOrderIdentityKey, prepareConfigResult, isCurrentRequest, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentCommittedDiscounts, currentScanDiscounts, currentScanDiscountById, committedDiscountById, mergedCommittedDiscountIds, refreshedScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, retainedCommittedDiscounts, retainedScanDiscounts, mergedDiscountList;
587
643
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
588
644
  while (1) switch (_context3.prev = _context3.next) {
589
645
  case 0:
@@ -599,6 +655,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
599
655
  with_wallet_pass_holder: 1,
600
656
  with_available_wallet_flag: 1,
601
657
  with_available_wallet_pass_flag: 1,
658
+ with_entitlement_pass: 1,
659
+ filter_order_wallet_pass_usage: 0,
602
660
  with_virtual_currency: 1,
603
661
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
604
662
  }, orderId ? {
@@ -607,8 +665,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
607
665
  case 5:
608
666
  prepareConfigResult = _context3.sent;
609
667
  isCurrentRequest = function isCurrentRequest() {
610
- var _this2$store$tempOrde, _this2$store$tempOrde2;
611
- return requestEpoch === _this2.customerWalletPrepareConfigEpoch && _this2.getDiscountConfigOrderIdentityKey(_this2.store.tempOrder) === requestOrderIdentityKey && String((_this2$store$tempOrde = (_this2$store$tempOrde2 = _this2.store.tempOrder) === null || _this2$store$tempOrde2 === void 0 ? void 0 : _this2$store$tempOrde2.customer_id) !== null && _this2$store$tempOrde !== void 0 ? _this2$store$tempOrde : '') === String(params.customerId);
668
+ var _this3$store$tempOrde, _this3$store$tempOrde2;
669
+ return requestEpoch === _this3.customerWalletPrepareConfigEpoch && _this3.getDiscountConfigOrderIdentityKey(_this3.store.tempOrder) === requestOrderIdentityKey && String((_this3$store$tempOrde = (_this3$store$tempOrde2 = _this3.store.tempOrder) === null || _this3$store$tempOrde2 === void 0 ? void 0 : _this3$store$tempOrde2.customer_id) !== null && _this3$store$tempOrde !== void 0 ? _this3$store$tempOrde : '') === String(params.customerId);
612
670
  };
613
671
  if (isCurrentRequest()) {
614
672
  _context3.next = 9;
@@ -626,56 +684,101 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
626
684
  });
627
685
  }
628
686
  if (!discountList) {
629
- _context3.next = 27;
687
+ _context3.next = 32;
630
688
  break;
631
689
  }
632
690
  currentDiscountList = ((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || [];
633
- currentEditDiscounts = currentDiscountList.filter(function (discount) {
634
- return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
691
+ currentCommittedDiscounts = currentDiscountList.filter(function (discount) {
692
+ var _discount$committedAp;
693
+ return (discount === null || discount === void 0 ? void 0 : discount.isEditMode) || (discount === null || discount === void 0 || (_discount$committedAp = discount.committedAppliedProductDetails) === null || _discount$committedAp === void 0 ? void 0 : _discount$committedAp.length);
635
694
  });
636
695
  currentScanDiscounts = currentDiscountList.filter(function (discount) {
637
696
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
638
697
  });
639
- currentScanDiscountIds = new Set(currentScanDiscounts.map(function (discount) {
640
- return discount === null || discount === void 0 ? void 0 : discount.id;
698
+ currentScanDiscountById = new Map(currentScanDiscounts.flatMap(function (discount) {
699
+ var id = getDiscountIdentityKey(discount);
700
+ return id === null ? [] : [[id, discount]];
701
+ }));
702
+ committedDiscountById = new Map(currentCommittedDiscounts.flatMap(function (discount) {
703
+ var id = getDiscountIdentityKey(discount);
704
+ return id === null ? [] : [[id, discount]];
641
705
  }));
706
+ mergedCommittedDiscountIds = new Set();
707
+ refreshedScanDiscountIds = new Set();
642
708
  runtimeDiscountIds = new Set();
643
- runtimeDiscounts = discountList.filter(function (discount) {
644
- if (currentScanDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
645
- if (runtimeDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
646
- runtimeDiscountIds.add(discount === null || discount === void 0 ? void 0 : discount.id);
647
- return true;
709
+ runtimeDiscounts = discountList.flatMap(function (discount) {
710
+ var id = getDiscountIdentityKey(discount);
711
+ if (id === null) return [discount];
712
+ if (runtimeDiscountIds.has(id)) return [];
713
+ runtimeDiscountIds.add(id);
714
+ var currentScanDiscount = currentScanDiscountById.get(id);
715
+ if (currentScanDiscount && (!isEntitlementPass(currentScanDiscount) || !isEntitlementPass(discount))) {
716
+ return [];
717
+ }
718
+ var committedDiscount = committedDiscountById.get(id);
719
+ var nextDiscount = discount;
720
+ if (committedDiscount && isEntitlementPass(committedDiscount) && isEntitlementPass(discount)) {
721
+ mergedCommittedDiscountIds.add(id);
722
+ nextDiscount = mergeCommittedEntitlementWithRuntime(committedDiscount, discount);
723
+ }
724
+ if (currentScanDiscount) {
725
+ var _currentScanDiscount$, _currentScanDiscount$2;
726
+ refreshedScanDiscountIds.add(id);
727
+ nextDiscount = _objectSpread(_objectSpread({}, nextDiscount), {}, {
728
+ isScan: true,
729
+ isSelected: (_currentScanDiscount$ = currentScanDiscount.isSelected) !== null && _currentScanDiscount$ !== void 0 ? _currentScanDiscount$ : nextDiscount.isSelected,
730
+ isManualSelect: (_currentScanDiscount$2 = currentScanDiscount.isManualSelect) !== null && _currentScanDiscount$2 !== void 0 ? _currentScanDiscount$2 : nextDiscount.isManualSelect
731
+ });
732
+ }
733
+ return [nextDiscount];
734
+ });
735
+ retainedCommittedDiscounts = currentCommittedDiscounts.filter(function (discount) {
736
+ var id = getDiscountIdentityKey(discount);
737
+ return id === null || !mergedCommittedDiscountIds.has(id);
738
+ }).map(function (discount) {
739
+ var _discount$committedAp2;
740
+ return (_discount$committedAp2 = discount.committedAppliedProductDetails) !== null && _discount$committedAp2 !== void 0 && _discount$committedAp2.length ? _objectSpread(_objectSpread({}, discount), {}, {
741
+ isEditMode: true,
742
+ isDisabled: true,
743
+ isSelected: true,
744
+ isUsed: true,
745
+ appliedProductDetails: _toConsumableArray(discount.committedAppliedProductDetails)
746
+ }) : discount;
648
747
  });
649
- mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(currentScanDiscounts), _toConsumableArray(runtimeDiscounts));
748
+ retainedScanDiscounts = currentScanDiscounts.filter(function (discount) {
749
+ var id = getDiscountIdentityKey(discount);
750
+ return id === null || !refreshedScanDiscountIds.has(id);
751
+ });
752
+ mergedDiscountList = [].concat(_toConsumableArray(retainedCommittedDiscounts), _toConsumableArray(retainedScanDiscounts), _toConsumableArray(runtimeDiscounts));
650
753
  if (isCurrentRequest()) {
651
- _context3.next = 21;
754
+ _context3.next = 26;
652
755
  break;
653
756
  }
654
757
  return _context3.abrupt("return", this.getDiscountList());
655
- case 21:
656
- _context3.next = 23;
758
+ case 26:
759
+ _context3.next = 28;
657
760
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
658
- case 23:
761
+ case 28:
659
762
  if (isCurrentRequest()) {
660
- _context3.next = 25;
763
+ _context3.next = 30;
661
764
  break;
662
765
  }
663
766
  return _context3.abrupt("return", this.getDiscountList());
664
- case 25:
665
- _context3.next = 27;
767
+ case 30:
768
+ _context3.next = 32;
666
769
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
667
- case 27:
770
+ case 32:
668
771
  if (isCurrentRequest()) {
669
- _context3.next = 29;
772
+ _context3.next = 34;
670
773
  break;
671
774
  }
672
775
  return _context3.abrupt("return", this.getDiscountList());
673
- case 29:
776
+ case 34:
674
777
  if (params.apply !== false && (_this$store$tempOrder2 = this.store.tempOrder) !== null && _this$store$tempOrder2 !== void 0 && (_this$store$tempOrder2 = _this$store$tempOrder2.products) !== null && _this$store$tempOrder2 !== void 0 && _this$store$tempOrder2.length) {
675
778
  this.applyDiscount();
676
779
  }
677
780
  return _context3.abrupt("return", this.getDiscountList());
678
- case 31:
781
+ case 36:
679
782
  case "end":
680
783
  return _context3.stop();
681
784
  }
@@ -795,7 +898,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
795
898
  value: function () {
796
899
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
797
900
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
798
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref16, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
901
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref16, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, scannedIds, evaluatedScannedDiscounts, shouldRetainForLater, normalizedNewDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13, retainedDiscounts;
799
902
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
800
903
  while (1) switch (_context6.prev = _context6.next) {
801
904
  case 0:
@@ -898,46 +1001,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
898
1001
  isAvailable: false,
899
1002
  discountList: this.getDiscountList()
900
1003
  }, isAvailable = _ref16.isAvailable, newDiscountList = _ref16.discountList, evaluatedDiscountList = _ref16.evaluatedDiscountList, unavailableReason = _ref16.unavailableReason;
901
- shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
1004
+ scannedIds = new Set(withScanList.map(function (discount) {
1005
+ return String(discount.id);
1006
+ }));
1007
+ evaluatedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(function (discount) {
1008
+ return scannedIds.has(String(discount.id)) && isCustomerPromotionDiscount(discount) && !getDiscountLifecycleReason(discount);
1009
+ });
1010
+ shouldRetainForLater = !isAvailable && evaluatedScannedDiscounts.length > 0;
902
1011
  normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
903
- retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
904
1012
  resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
905
1013
  if (!(isAvailable && normalizedNewDiscountList)) {
906
- _context6.next = 36;
1014
+ _context6.next = 37;
907
1015
  break;
908
1016
  }
909
- _context6.next = 30;
1017
+ _context6.next = 31;
910
1018
  return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
911
- case 30:
912
- this.applyDiscount();
913
- _context6.next = 33;
1019
+ case 31:
1020
+ // 实际写回商品时沿用扫码试算的优先级,避免旧商品行的选卡覆盖本次扫码。
1021
+ this.applyDiscount({
1022
+ preferredEntitlementPassIds: withScanList.filter(function (discount) {
1023
+ return isEntitlementPass(discount);
1024
+ }).map(function (discount) {
1025
+ return discount.id;
1026
+ })
1027
+ });
1028
+ _context6.next = 34;
914
1029
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
915
- case 33:
1030
+ case 34:
916
1031
  resolvedDiscountList = this.getDiscountList();
917
- _context6.next = 42;
1032
+ _context6.next = 45;
918
1033
  break;
919
- case 36:
920
- if (!(shouldRetainForLater && retainedDiscountList)) {
921
- _context6.next = 42;
1034
+ case 37:
1035
+ if (!shouldRetainForLater) {
1036
+ _context6.next = 45;
922
1037
  break;
923
1038
  }
924
- _context6.next = 39;
925
- return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
926
- case 39:
927
- _context6.next = 41;
1039
+ // 只合并本次识别的卡券;不把试算产生的其他选券状态写回订单。
1040
+ retainedDiscounts = new Map(this.getDiscountList().map(function (discount) {
1041
+ return [String(discount.id), discount];
1042
+ }));
1043
+ evaluatedScannedDiscounts.forEach(function (discount) {
1044
+ retainedDiscounts.set(String(discount.id), _objectSpread(_objectSpread({}, discount), {}, {
1045
+ isScan: true,
1046
+ isAvailable: false,
1047
+ isSelected: false,
1048
+ reasonCode: discount.reasonCode || 'product_not_applicable',
1049
+ appliedProductDetails: [],
1050
+ savedAmount: 0
1051
+ }));
1052
+ });
1053
+ _context6.next = 42;
1054
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(_toConsumableArray(retainedDiscounts.values()));
1055
+ case 42:
1056
+ _context6.next = 44;
928
1057
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
929
- case 41:
1058
+ case 44:
930
1059
  resolvedDiscountList = this.getDiscountList();
931
- case 42:
1060
+ case 45:
932
1061
  return _context6.abrupt("return", {
933
1062
  type: 'clientCalc',
934
1063
  isAvailable: isAvailable || false,
935
1064
  isAccepted: Boolean(isAvailable || shouldRetainForLater),
936
1065
  discountList: resolvedDiscountList,
937
- scannedDiscountList: resultDiscountList,
1066
+ scannedDiscountList: evaluatedScannedDiscounts,
938
1067
  unavailableReason: unavailableReason
939
1068
  });
940
- case 43:
1069
+ case 46:
941
1070
  case "end":
942
1071
  return _context6.stop();
943
1072
  }
@@ -953,7 +1082,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
953
1082
  value: function applyDiscount(options) {
954
1083
  var _this$store$discount16,
955
1084
  _this$store$summary2,
956
- _this3 = this;
1085
+ _this4 = this;
957
1086
  var tempOrder = this.store.tempOrder;
958
1087
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
959
1088
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
@@ -985,7 +1114,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
985
1114
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
986
1115
  }, {
987
1116
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
988
- reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids
1117
+ reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids,
1118
+ preferredEntitlementPassIds: options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds
989
1119
  });
990
1120
  if (result !== null && result !== void 0 && result.productList) {
991
1121
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
@@ -1010,7 +1140,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1010
1140
  (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || _this$store$discount17.setDiscountList(result.discountList);
1011
1141
  }
1012
1142
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
1013
- return _this3.productHasCustomerBoundDiscount(product);
1143
+ return _this4.productHasCustomerBoundDiscount(product);
1014
1144
  });
1015
1145
  }
1016
1146
 
@@ -1073,7 +1203,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1073
1203
  var _evaluatePromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1074
1204
  var _this$promotionEvalua,
1075
1205
  _this$promotionEvalua2,
1076
- _this4 = this;
1206
+ _this5 = this;
1077
1207
  var tempOrder, strategyConfigs, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
1078
1208
  return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1079
1209
  while (1) switch (_context9.prev = _context9.next) {
@@ -1232,7 +1362,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1232
1362
  case 6:
1233
1363
  _context7.prev = 6;
1234
1364
  _context7.next = 9;
1235
- return _this4.giftSelectResolver({
1365
+ return _this5.giftSelectResolver({
1236
1366
  strategyId: addAction.strategyId,
1237
1367
  strategyName: addAction.strategyName,
1238
1368
  giftCount: addAction.giftCount,
@@ -1267,7 +1397,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1267
1397
  _context7.next = 26;
1268
1398
  break;
1269
1399
  }
1270
- linked = _this4.createLinkedProductAndBooking({
1400
+ linked = _this5.createLinkedProductAndBooking({
1271
1401
  product: gp,
1272
1402
  booking: booking
1273
1403
  });
@@ -1597,12 +1727,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1597
1727
  }, {
1598
1728
  key: "rememberPointCardSnapshotCodeCandidates",
1599
1729
  value: function rememberPointCardSnapshotCodeCandidates(value) {
1600
- var _this5 = this;
1730
+ var _this6 = this;
1601
1731
  collectPointCardSnapshotCodeCandidates(value).forEach(function (_ref18) {
1602
1732
  var id = _ref18.id,
1603
1733
  code = _ref18.code;
1604
- if (!_this5.pointCardSnapshotCodeCandidates.has(id)) {
1605
- _this5.pointCardSnapshotCodeCandidates.set(id, code);
1734
+ if (!_this6.pointCardSnapshotCodeCandidates.has(id)) {
1735
+ _this6.pointCardSnapshotCodeCandidates.set(id, code);
1606
1736
  }
1607
1737
  });
1608
1738
  }
@@ -1809,23 +1939,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1809
1939
  }, {
1810
1940
  key: "calculatePaymentTotal",
1811
1941
  value: function calculatePaymentTotal(payments) {
1812
- var _this6 = this;
1942
+ var _this7 = this;
1813
1943
  return mapPaymentItemsToOrderPayments(payments, {
1814
1944
  includeVoided: false
1815
1945
  }).reduce(function (sum, payment) {
1816
1946
  if (!isPaidPaymentRecord(payment)) return sum;
1817
- return sum.plus(_this6.calculatePaymentEffectiveAmount(payment));
1947
+ return sum.plus(_this7.calculatePaymentEffectiveAmount(payment));
1818
1948
  }, new Decimal(0));
1819
1949
  }
1820
1950
  }, {
1821
1951
  key: "calculateOrderPaidPaymentTotal",
1822
1952
  value: function calculateOrderPaidPaymentTotal(payments) {
1823
- var _this7 = this;
1953
+ var _this8 = this;
1824
1954
  return mapPaymentItemsToOrderPayments(payments, {
1825
1955
  includeVoided: false
1826
1956
  }).reduce(function (sum, payment) {
1827
1957
  if (!isPaidPaymentRecord(payment)) return sum;
1828
- return sum.plus(_this7.calculatePaymentGapAmount(payment));
1958
+ return sum.plus(_this8.calculatePaymentGapAmount(payment));
1829
1959
  }, new Decimal(0));
1830
1960
  }
1831
1961
  }, {
@@ -1961,13 +2091,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1961
2091
  }, {
1962
2092
  key: "calculateDepositPaidAmount",
1963
2093
  value: function calculateDepositPaidAmount(payments) {
1964
- var _this8 = this;
2094
+ var _this9 = this;
1965
2095
  return (payments || []).reduce(function (sum, payment) {
1966
2096
  var paymentRecord = payment;
1967
2097
  if (!isPaidPaymentRecord(paymentRecord)) return sum;
1968
2098
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1969
2099
  if (!isDepositPayment) return sum;
1970
- return sum.plus(_this8.calculatePaymentGapAmount(paymentRecord));
2100
+ return sum.plus(_this9.calculatePaymentGapAmount(paymentRecord));
1971
2101
  }, new Decimal(0));
1972
2102
  }
1973
2103
  }, {
@@ -2004,17 +2134,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2004
2134
  }, {
2005
2135
  key: "getPaymentNumberDevicePrefixSync",
2006
2136
  value: function getPaymentNumberDevicePrefixSync() {
2007
- var _this9 = this;
2137
+ var _this10 = this;
2008
2138
  return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
2009
- return _this9.getPaymentNumberAppData(key);
2139
+ return _this10.getPaymentNumberAppData(key);
2010
2140
  });
2011
2141
  }
2012
2142
  }, {
2013
2143
  key: "getPaymentNumberDevicePrefixAsync",
2014
2144
  value: function getPaymentNumberDevicePrefixAsync() {
2015
- var _this10 = this;
2145
+ var _this11 = this;
2016
2146
  return resolvePaymentNumberDevicePrefix(function (key) {
2017
- return _this10.getPaymentNumberAppData(key);
2147
+ return _this11.getPaymentNumberAppData(key);
2018
2148
  });
2019
2149
  }
2020
2150
  }, {
@@ -2144,16 +2274,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2144
2274
  }, {
2145
2275
  key: "calculatePaidPaymentSummary",
2146
2276
  value: function calculatePaidPaymentSummary(payments) {
2147
- var _this11 = this;
2277
+ var _this12 = this;
2148
2278
  return (payments || []).reduce(function (summary, payment) {
2149
2279
  var paymentRecord = payment;
2150
2280
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
2151
2281
  return {
2152
2282
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
2153
- orderPaidAmount: summary.orderPaidAmount.plus(_this11.calculatePaymentOrderAmount(paymentRecord)),
2154
- gapPaidAmount: summary.gapPaidAmount.plus(_this11.calculatePaymentGapAmount(paymentRecord)),
2155
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this11.calculatePaymentServiceFee(paymentRecord)),
2156
- roundingAmount: summary.roundingAmount.plus(_this11.calculatePaymentRoundingAmount(paymentRecord))
2283
+ orderPaidAmount: summary.orderPaidAmount.plus(_this12.calculatePaymentOrderAmount(paymentRecord)),
2284
+ gapPaidAmount: summary.gapPaidAmount.plus(_this12.calculatePaymentGapAmount(paymentRecord)),
2285
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this12.calculatePaymentServiceFee(paymentRecord)),
2286
+ roundingAmount: summary.roundingAmount.plus(_this12.calculatePaymentRoundingAmount(paymentRecord))
2157
2287
  };
2158
2288
  }, {
2159
2289
  customerPaidAmount: new Decimal(0),
@@ -2360,15 +2490,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2360
2490
  }, {
2361
2491
  key: "normalizeFingerprintValue",
2362
2492
  value: function normalizeFingerprintValue(value) {
2363
- var _this12 = this;
2493
+ var _this13 = this;
2364
2494
  if (Array.isArray(value)) {
2365
2495
  return value.map(function (item) {
2366
- return _this12.normalizeFingerprintValue(item);
2496
+ return _this13.normalizeFingerprintValue(item);
2367
2497
  });
2368
2498
  }
2369
2499
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
2370
2500
  return Object.keys(value).sort().reduce(function (result, key) {
2371
- result[key] = _this12.normalizeFingerprintValue(value[key]);
2501
+ result[key] = _this13.normalizeFingerprintValue(value[key]);
2372
2502
  return result;
2373
2503
  }, {});
2374
2504
  }
@@ -2383,14 +2513,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2383
2513
  _sku$barcode,
2384
2514
  _ref26,
2385
2515
  _sku$variant_id,
2386
- _this13 = this;
2516
+ _this14 = this;
2387
2517
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2388
2518
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2389
2519
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2390
2520
  var _discount$type;
2391
2521
  return (_discount$type = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type !== void 0 ? _discount$type : discount === null || discount === void 0 ? void 0 : discount.tag;
2392
2522
  });
2393
- var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
2523
+ var fullCoveragePassType = discountTypes.find(function (type) {
2524
+ return ['entitlement_pass', 'good_pass'].includes(type);
2525
+ });
2526
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || fullCoveragePassType || 'normal';
2394
2527
  return {
2395
2528
  product_id: (_product$product_id2 = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : null,
2396
2529
  product_variant_id: (_product$product_vari = product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : null,
@@ -2417,7 +2550,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2417
2550
  option_group_id: (_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : null,
2418
2551
  option_group_item_id: (_ref28 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref28 !== void 0 ? _ref28 : null,
2419
2552
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
2420
- add_price: _this13.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
2553
+ add_price: _this14.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
2421
2554
  };
2422
2555
  })
2423
2556
  }),
@@ -2427,8 +2560,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2427
2560
  bundle_product_id: (_ref29 = (_ref30 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref30 !== void 0 ? _ref30 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref29 !== void 0 ? _ref29 : null,
2428
2561
  bundle_variant_id: (_ref31 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref31 !== void 0 ? _ref31 : 0,
2429
2562
  num: getSafeProductNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
2430
- price: _this13.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2431
- bundle_selling_price: _this13.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2563
+ price: _this14.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2564
+ bundle_selling_price: _this14.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2432
2565
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
2433
2566
  price_type_ext: (_bundle$price_type_ex = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : ''
2434
2567
  };
@@ -2438,7 +2571,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2438
2571
  return {
2439
2572
  type: (_ref32 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref32 !== void 0 ? _ref32 : '',
2440
2573
  discount_id: (_ref33 = (_ref34 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref34 !== void 0 ? _ref34 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref33 !== void 0 ? _ref33 : null,
2441
- amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2574
+ amount: _this14.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2442
2575
  };
2443
2576
  }))
2444
2577
  };
@@ -2446,9 +2579,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2446
2579
  }, {
2447
2580
  key: "buildOrderProductsFingerprint",
2448
2581
  value: function buildOrderProductsFingerprint(products) {
2449
- var _this14 = this;
2582
+ var _this15 = this;
2450
2583
  var items = (products || []).map(function (product) {
2451
- return _this14.buildProductFingerprintItem(product);
2584
+ return _this15.buildProductFingerprintItem(product);
2452
2585
  });
2453
2586
  items.sort(function (left, right) {
2454
2587
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2470,14 +2603,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2470
2603
  _sku$barcode2,
2471
2604
  _ref36,
2472
2605
  _sku$variant_id2,
2473
- _this15 = this;
2606
+ _this16 = this;
2474
2607
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2475
2608
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2476
2609
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2477
2610
  var _discount$type3;
2478
2611
  return (_discount$type3 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type3 !== void 0 ? _discount$type3 : discount === null || discount === void 0 ? void 0 : discount.tag;
2479
2612
  });
2480
- var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
2613
+ var fullCoveragePassType = discountTypes.find(function (type) {
2614
+ return ['entitlement_pass', 'good_pass'].includes(type);
2615
+ });
2616
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || fullCoveragePassType || 'normal';
2481
2617
  return {
2482
2618
  product_id: (_product$product_id3 = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id3 !== void 0 ? _product$product_id3 : null,
2483
2619
  product_variant_id: (_product$product_vari2 = product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : null,
@@ -2501,7 +2637,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2501
2637
  option_group_id: (_option$option_group_3 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_3 !== void 0 ? _option$option_group_3 : null,
2502
2638
  option_group_item_id: (_ref38 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref38 !== void 0 ? _ref38 : null,
2503
2639
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
2504
- add_price: _this15.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2640
+ add_price: _this16.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2505
2641
  };
2506
2642
  })
2507
2643
  }),
@@ -2515,14 +2651,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2515
2651
  num: getSafeProductNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
2516
2652
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2517
2653
  price_type_ext: (_bundle$price_type_ex2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : '',
2518
- option: _this15.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2654
+ option: _this16.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2519
2655
  var _ref44, _option$id3, _option$option_group_5, _ref45, _option$option_group_6, _option$num3, _option$add_price3;
2520
2656
  return {
2521
2657
  id: (_ref44 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref44 !== void 0 ? _ref44 : null,
2522
2658
  option_group_id: (_option$option_group_5 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_5 !== void 0 ? _option$option_group_5 : null,
2523
2659
  option_group_item_id: (_ref45 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref45 !== void 0 ? _ref45 : null,
2524
2660
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2525
- add_price: _this15.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2661
+ add_price: _this16.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2526
2662
  };
2527
2663
  }))
2528
2664
  };
@@ -2532,7 +2668,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2532
2668
  return {
2533
2669
  type: (_ref46 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref46 !== void 0 ? _ref46 : '',
2534
2670
  discount_id: (_ref47 = (_ref48 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref48 !== void 0 ? _ref48 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref47 !== void 0 ? _ref47 : null,
2535
- amount: _this15.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2671
+ amount: _this16.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2536
2672
  };
2537
2673
  }))
2538
2674
  };
@@ -2540,9 +2676,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2540
2676
  }, {
2541
2677
  key: "buildOrderProductsStructuralFingerprint",
2542
2678
  value: function buildOrderProductsStructuralFingerprint(products) {
2543
- var _this16 = this;
2679
+ var _this17 = this;
2544
2680
  var items = (products || []).map(function (product) {
2545
- return _this16.buildProductStructuralFingerprintItem(product);
2681
+ return _this17.buildProductStructuralFingerprintItem(product);
2546
2682
  });
2547
2683
  items.sort(function (left, right) {
2548
2684
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2994,9 +3130,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2994
3130
  }, {
2995
3131
  key: "sanitizeTempOrderProducts",
2996
3132
  value: function sanitizeTempOrderProducts(tempOrder) {
2997
- var _this17 = this;
3133
+ var _this18 = this;
2998
3134
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2999
- return _this17.sanitizeOrderProductForTempOrder(_this17.normalizeVirtualSettlementProductIfEnabled(product));
3135
+ return _this18.sanitizeOrderProductForTempOrder(_this18.normalizeVirtualSettlementProductIfEnabled(product));
3000
3136
  });
3001
3137
  this.syncTempOrderSettlementState(tempOrder);
3002
3138
  ensureUniqueProductLineUids(tempOrder);
@@ -3116,7 +3252,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3116
3252
  }, {
3117
3253
  key: "syncLinkedBookingHoldersToProducts",
3118
3254
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
3119
- var _this18 = this;
3255
+ var _this19 = this;
3120
3256
  var bookings = tempOrder.bookings || [];
3121
3257
  var products = tempOrder.products || [];
3122
3258
  if (!bookings.length || !products.length) return;
@@ -3141,7 +3277,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3141
3277
  var bookingUid = product.booking_uid || ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.booking_uid);
3142
3278
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
3143
3279
  if (linkedBooking) {
3144
- _this18.setProductHolderFromBooking(product, linkedBooking);
3280
+ _this19.setProductHolderFromBooking(product, linkedBooking);
3145
3281
  }
3146
3282
  });
3147
3283
  }
@@ -3269,9 +3405,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3269
3405
  }, {
3270
3406
  key: "findBookingIndexByUniqueIdentificationNumber",
3271
3407
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
3272
- var _this19 = this;
3408
+ var _this20 = this;
3273
3409
  return (tempOrder.bookings || []).findIndex(function (booking) {
3274
- return _this19.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3410
+ return _this20.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3275
3411
  });
3276
3412
  }
3277
3413
  }, {
@@ -3279,12 +3415,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3279
3415
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
3280
3416
  var _product$metadata5,
3281
3417
  _product$metadata6,
3282
- _this20 = this;
3418
+ _this21 = this;
3283
3419
  var productUid = (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
3284
3420
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
3285
3421
  if (!productUid && !bookingUid) return;
3286
3422
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
3287
- var currentBookingUid = _this20.getBookingUniqueIdentificationNumber(booking);
3423
+ var currentBookingUid = _this21.getBookingUniqueIdentificationNumber(booking);
3288
3424
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
3289
3425
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
3290
3426
  return true;
@@ -3586,7 +3722,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3586
3722
  }, {
3587
3723
  key: "removeSalesNotesForMissingProductLines",
3588
3724
  value: function removeSalesNotesForMissingProductLines(tempOrder) {
3589
- var _this21 = this;
3725
+ var _this22 = this;
3590
3726
  var state = this.ensureSalesNotesRuntimeState(tempOrder);
3591
3727
  if (!state.loaded || !Array.isArray(tempOrder.notes) || tempOrder.notes.length === 0) {
3592
3728
  return;
@@ -3598,7 +3734,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3598
3734
  return typeof uid === 'string' && uid.length > 0;
3599
3735
  }));
3600
3736
  var nextNotes = tempOrder.notes.filter(function (note) {
3601
- var primary = _this21.getSalesNotePrimaryRelation(note);
3737
+ var primary = _this22.getSalesNotePrimaryRelation(note);
3602
3738
  if (!primary || primary.target_type !== 'order_detail') return true;
3603
3739
  return remainingProductUids.has(primary.target_uuid);
3604
3740
  });
@@ -3610,7 +3746,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3610
3746
  key: "setSalesNoteOnTempOrder",
3611
3747
  value: function setSalesNoteOnTempOrder(tempOrder, input) {
3612
3748
  var _input$target,
3613
- _this22 = this,
3749
+ _this23 = this,
3614
3750
  _tempOrder$shop_order;
3615
3751
  this.ensureSalesNotesLoadedForMutation(tempOrder);
3616
3752
  var note_type = String(input.note_type || '').trim();
@@ -3634,7 +3770,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3634
3770
  var notes = tempOrder.notes || [];
3635
3771
  // 当前 allergy policy 固定同一商品行只保留一条;业务调用方不参与去重规则。
3636
3772
  var existingIndex = policy.uniquePerPrimaryTarget ? notes.findIndex(function (note) {
3637
- var primary = _this22.getSalesNotePrimaryRelation(note);
3773
+ var primary = _this23.getSalesNotePrimaryRelation(note);
3638
3774
  return note.note_type === note_type && (primary === null || primary === void 0 ? void 0 : primary.target_type) === 'order_detail' && primary.target_uuid === target_uuid;
3639
3775
  }) : -1;
3640
3776
  var existing = existingIndex >= 0 ? notes[existingIndex] : null;
@@ -3906,7 +4042,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3906
4042
  value: function isCustomerBoundDiscount(discount) {
3907
4043
  var _discount$type5;
3908
4044
  var type = (_discount$type5 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type5 !== void 0 ? _discount$type5 : discount === null || discount === void 0 ? void 0 : discount.tag;
3909
- return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
4045
+ return type === 'entitlement_pass' || type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
3910
4046
  }
3911
4047
  }, {
3912
4048
  key: "shouldKeepCustomerBoundDiscountAfterCustomerChange",
@@ -3916,15 +4052,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3916
4052
  }, {
3917
4053
  key: "productHasCustomerBoundDiscount",
3918
4054
  value: function productHasCustomerBoundDiscount(product) {
3919
- var _this23 = this;
4055
+ var _this24 = this;
3920
4056
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3921
- return _this23.isCustomerBoundDiscount(discount);
4057
+ return _this24.isCustomerBoundDiscount(discount);
3922
4058
  })) {
3923
4059
  return true;
3924
4060
  }
3925
4061
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3926
4062
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3927
- return _this23.isCustomerBoundDiscount(discount);
4063
+ return _this24.isCustomerBoundDiscount(discount);
3928
4064
  });
3929
4065
  });
3930
4066
  }
@@ -3933,18 +4069,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3933
4069
  value: function shouldSkipDiscountCalculation(tempOrder) {
3934
4070
  var _this$store$discount20,
3935
4071
  _this$store$discount21,
3936
- _this24 = this;
4072
+ _this25 = this;
3937
4073
  if (this.hasActiveCustomerBoundDiscount) return false;
3938
4074
  var discountList = ((_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 || (_this$store$discount21 = _this$store$discount20.getDiscountList) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.call(_this$store$discount20)) || [];
3939
4075
  if (discountList.length > 0) return false;
3940
4076
  return !(tempOrder.products || []).some(function (product) {
3941
- return _this24.productHasCustomerBoundDiscount(product);
4077
+ return _this25.productHasCustomerBoundDiscount(product);
3942
4078
  });
3943
4079
  }
3944
4080
  }, {
3945
4081
  key: "clearCustomerBoundDiscounts",
3946
4082
  value: function clearCustomerBoundDiscounts(tempOrder) {
3947
- var _this25 = this,
4083
+ var _this26 = this,
3948
4084
  _discountModule$getDi,
3949
4085
  _discountModule$getOr,
3950
4086
  _discountModule$setDi,
@@ -3953,7 +4089,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3953
4089
  var filterDiscountList = function filterDiscountList(discountList) {
3954
4090
  if (!Array.isArray(discountList)) return [];
3955
4091
  return discountList.filter(function (discount) {
3956
- var shouldRemove = _this25.isCustomerBoundDiscount(discount);
4092
+ var shouldRemove = _this26.isCustomerBoundDiscount(discount);
3957
4093
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3958
4094
  return !shouldRemove;
3959
4095
  });
@@ -3980,12 +4116,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3980
4116
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3981
4117
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3982
4118
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3983
- if (_this25.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3984
- return !_this25.isCustomerBoundDiscount(discount);
4119
+ if (_this26.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4120
+ return !_this26.isCustomerBoundDiscount(discount);
3985
4121
  });
3986
4122
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3987
- if (_this25.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3988
- return !_this25.isCustomerBoundDiscount(discount);
4123
+ if (_this26.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4124
+ return !_this26.isCustomerBoundDiscount(discount);
3989
4125
  });
3990
4126
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3991
4127
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -4149,10 +4285,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4149
4285
  }, {
4150
4286
  key: "setOrderPayments",
4151
4287
  value: function setOrderPayments(payments) {
4152
- var _this26 = this;
4288
+ var _this27 = this;
4153
4289
  var tempOrder = this.ensureTempOrder();
4154
4290
  tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
4155
- return _this26.normalizePaymentSource(payment, {
4291
+ return _this27.normalizePaymentSource(payment, {
4156
4292
  defaultPaid: false
4157
4293
  });
4158
4294
  }));
@@ -4207,7 +4343,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4207
4343
  }, {
4208
4344
  key: "addOrderPaymentWithDevicePrefix",
4209
4345
  value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
4210
- var _this27 = this;
4346
+ var _this28 = this;
4211
4347
  this.logInfo('addOrderPayment', {
4212
4348
  payment: payment
4213
4349
  });
@@ -4225,7 +4361,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4225
4361
  void this.recalculateSummary({
4226
4362
  createIfMissing: true
4227
4363
  }).catch(function (error) {
4228
- _this27.logError('recalculate summary after addOrderPayment failed', {
4364
+ _this28.logError('recalculate summary after addOrderPayment failed', {
4229
4365
  error: error instanceof Error ? error.message : String(error)
4230
4366
  });
4231
4367
  });
@@ -4338,7 +4474,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4338
4474
  }, {
4339
4475
  key: "applyPaymentLifecycleChange",
4340
4476
  value: function applyPaymentLifecycleChange(tempOrder, options) {
4341
- var _this28 = this;
4477
+ var _this29 = this;
4342
4478
  this.updateTempOrderPaymentStatus(tempOrder);
4343
4479
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
4344
4480
  this.persistTempOrder();
@@ -4348,7 +4484,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4348
4484
  void this.recalculateSummary({
4349
4485
  createIfMissing: true
4350
4486
  }).catch(function (error) {
4351
- _this28.logError("recalculate summary after ".concat(logContext, " failed"), {
4487
+ _this29.logError("recalculate summary after ".concat(logContext, " failed"), {
4352
4488
  error: error instanceof Error ? error.message : String(error)
4353
4489
  });
4354
4490
  });
@@ -4392,7 +4528,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4392
4528
  }, {
4393
4529
  key: "updateVoucherOrderPayments",
4394
4530
  value: function updateVoucherOrderPayments(payments, options) {
4395
- var _this29 = this;
4531
+ var _this30 = this;
4396
4532
  var tempOrder = this.ensureTempOrder();
4397
4533
  var isOrderPaymentType = function isOrderPaymentType(value) {
4398
4534
  return value === 'normal' || value === 'deposit';
@@ -4427,7 +4563,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4427
4563
  });
4428
4564
  };
4429
4565
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
4430
- return _this29.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4566
+ return _this30.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4431
4567
  defaultPaid: false,
4432
4568
  devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
4433
4569
  });
@@ -4480,7 +4616,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4480
4616
  void this.recalculateSummary({
4481
4617
  createIfMissing: true
4482
4618
  }).catch(function (error) {
4483
- _this29.logError('recalculate summary after updateVoucherOrderPayments failed', {
4619
+ _this30.logError('recalculate summary after updateVoucherOrderPayments failed', {
4484
4620
  error: error instanceof Error ? error.message : String(error)
4485
4621
  });
4486
4622
  });
@@ -4538,7 +4674,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4538
4674
  key: "shouldMergeProductToOrder",
4539
4675
  value: function shouldMergeProductToOrder(params) {
4540
4676
  var _this$orderHooks,
4541
- _this30 = this;
4677
+ _this31 = this;
4542
4678
  var onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
4543
4679
  if (!onBeforeMergeProductToOrder) return true;
4544
4680
  var result = onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
@@ -4546,7 +4682,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4546
4682
  }));
4547
4683
  if (result && _typeof(result) === 'object' && typeof result.then === 'function') {
4548
4684
  return Promise.resolve(result).then(function (resolved) {
4549
- return _this30.normalizeShouldMergeProductResult(resolved);
4685
+ return _this31.normalizeShouldMergeProductResult(resolved);
4550
4686
  });
4551
4687
  }
4552
4688
  return this.normalizeShouldMergeProductResult(result);
@@ -4747,7 +4883,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4747
4883
  _metadata,
4748
4884
  _productToAdd$metadat,
4749
4885
  _origin,
4750
- _this31 = this;
4886
+ _this32 = this;
4751
4887
  var linked = booking ? this.createLinkedProductAndBooking({
4752
4888
  product: product,
4753
4889
  booking: booking
@@ -4774,18 +4910,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4774
4910
  }
4775
4911
  normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
4776
4912
  var hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
4913
+ var hasIncomingEntitlementPass = this.hasEntitlementPassDiscount(normalizedIncoming);
4914
+ var isIncomingEntitlementAppend = this.isRuntimeEntitlementAppend(productToAdd, tempOrder);
4915
+ var isIncomingPersistedEntitlementPass = hasIncomingEntitlementPass && this.isPersistedProductLine(normalizedIncoming);
4777
4916
  var hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
4778
4917
  var hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
4779
4918
  var hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
4780
4919
  var isIncomingCustomItem = ((_productToAdd$metadat = productToAdd.metadata) === null || _productToAdd$metadat === void 0 || (_productToAdd$metadat = _productToAdd$metadat.origin) === null || _productToAdd$metadat === void 0 ? void 0 : _productToAdd$metadat.isCustomItem) === true || ((_origin = productToAdd._origin) === null || _origin === void 0 ? void 0 : _origin.isCustomItem) === true;
4781
- var shouldForceNewLine = disableMerge || !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4782
- var matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4783
- var _item$metadata3;
4784
- if (_this31.hasGoodPassDiscount(item)) return false;
4785
- if (_this31.hasOrderProductLineNote(item)) return false;
4786
- if (isManualProductDiscountProduct(item)) return false;
4787
- if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
4788
- if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
4920
+ var shouldForceNewLine = disableMerge || !!booking || hasIncomingGoodPass || isIncomingPersistedEntitlementPass || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4921
+ var matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4922
+ if (_this32.hasGoodPassDiscount(item)) return false;
4923
+ var isRuntimeEntitlementPass = _this32.isRuntimeEntitlementAppend(item, tempOrder);
4924
+ if (isIncomingEntitlementAppend !== isRuntimeEntitlementPass) {
4925
+ return false;
4926
+ }
4927
+ if (isIncomingEntitlementAppend && _this32.isPersistedProductLine(item)) {
4928
+ return false;
4929
+ }
4930
+ var hasExistingProductNote = _this32.hasOrderProductLineNote(item);
4931
+ if ((hasIncomingProductNote || hasExistingProductNote) && (!isRuntimeEntitlementPass || String(normalizedIncoming.note || '').trim() !== String(item.note || '').trim())) {
4932
+ return false;
4933
+ }
4934
+ var hasExistingManualProductDiscount = isManualProductDiscountProduct(item);
4935
+ if (isRuntimeEntitlementPass && !_this32.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
4936
+ return false;
4937
+ }
4938
+ if ((hasIncomingManualProductDiscount || hasExistingManualProductDiscount) && !isRuntimeEntitlementPass) {
4939
+ return false;
4940
+ }
4941
+ if (_this32.isPersistedProductLine(item)) return false;
4789
4942
  if (item.product_id !== productToAdd.product_id) return false;
4790
4943
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
4791
4944
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -4796,7 +4949,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4796
4949
  var commitProductLine = function commitProductLine(shouldMerge) {
4797
4950
  var committedProduct;
4798
4951
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4799
- _this31.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4952
+ _this32.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4800
4953
  if (linked) {
4801
4954
  normalizedIncoming.booking_uid = linked.bookingUid;
4802
4955
  normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
@@ -4814,7 +4967,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4814
4967
  var _targetProduct$metada;
4815
4968
  var targetProduct = matchedProduct;
4816
4969
  var targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4817
- var normalizedProduct = _this31.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4970
+ var normalizedProduct = _this32.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4818
4971
  metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4819
4972
  unique_identification_number: targetUid
4820
4973
  })
@@ -4837,7 +4990,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4837
4990
  order_detail_id: targetProduct.order_detail_id,
4838
4991
  num: nextNum
4839
4992
  });
4840
- _this31.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4993
+ _this32.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4841
4994
  committedProduct = tempOrder.products[matchedIndex];
4842
4995
  if (matchedIndex !== tempOrder.products.length - 1) {
4843
4996
  var mergedProduct = tempOrder.products[matchedIndex];
@@ -4947,7 +5100,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4947
5100
  key: "addProductToOrder",
4948
5101
  value: (function () {
4949
5102
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(product, booking, options) {
4950
- var _this32 = this;
5103
+ var _this33 = this;
4951
5104
  var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref71, _productRecord$num, productRecord, splitCount, i, splitLine, committedProduct, _committedProduct, _committedProduct2;
4952
5105
  return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4953
5106
  while (1) switch (_context25.prev = _context25.next) {
@@ -4976,7 +5129,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4976
5129
  throw new Error('[Order Notes] 商品行缺少 unique_identification_number');
4977
5130
  }
4978
5131
  salesNoteDrafts.forEach(function (draft) {
4979
- _this32.setSalesNoteOnTempOrder(tempOrder, {
5132
+ _this33.setSalesNoteOnTempOrder(tempOrder, {
4980
5133
  note_type: draft.note_type,
4981
5134
  target: {
4982
5135
  target_type: 'order_detail',
@@ -5210,45 +5363,99 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5210
5363
  return addProductsToOrder;
5211
5364
  }())
5212
5365
  }, {
5213
- key: "hasGoodPassDiscount",
5214
- value: function hasGoodPassDiscount(product) {
5366
+ key: "getFullCoveragePassDiscounts",
5367
+ value: function getFullCoveragePassDiscounts(product) {
5215
5368
  var _product$_extend;
5216
- var hasMainGoodPass = (product.discount_list || []).some(function (item) {
5217
- return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
5218
- });
5219
- if (hasMainGoodPass) return true;
5220
- var bundleDiscountList = [];
5369
+ var discountList = _toConsumableArray(product.discount_list || []);
5221
5370
  (product.product_bundle || []).forEach(function (item) {
5222
- bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5371
+ discountList.push.apply(discountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5223
5372
  });
5224
5373
  ((product === null || product === void 0 || (_product$_extend = product._extend) === null || _product$_extend === void 0 || (_product$_extend = _product$_extend.other) === null || _product$_extend === void 0 ? void 0 : _product$_extend.bundle) || []).forEach(function (item) {
5225
- bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5374
+ discountList.push.apply(discountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5226
5375
  });
5227
- return bundleDiscountList.some(function (item) {
5228
- return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
5376
+ return discountList.filter(function (item) {
5377
+ return isFullCoveragePass(item);
5378
+ });
5379
+ }
5380
+ }, {
5381
+ key: "hasEntitlementPassDiscount",
5382
+ value: function hasEntitlementPassDiscount(product) {
5383
+ return this.getFullCoveragePassDiscounts(product).some(function (item) {
5384
+ return isEntitlementPass(item);
5229
5385
  });
5230
5386
  }
5387
+ }, {
5388
+ key: "hasGoodPassDiscount",
5389
+ value: function hasGoodPassDiscount(product) {
5390
+ return this.getFullCoveragePassDiscounts(product).some(function (item) {
5391
+ return !isEntitlementPass(item);
5392
+ });
5393
+ }
5394
+ }, {
5395
+ key: "isPersistedProductLine",
5396
+ value: function isPersistedProductLine(product) {
5397
+ var _product$metadata11;
5398
+ return product.order_detail_id !== undefined && product.order_detail_id !== null && product.order_detail_id !== '' || ((_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.is_edit_for_runtime) === true;
5399
+ }
5400
+ }, {
5401
+ key: "isRuntimeEntitlementAppend",
5402
+ value: function isRuntimeEntitlementAppend(product, tempOrder) {
5403
+ var _product$metadata$uni, _product$metadata12, _tempOrder$_extend10, _product$_origin;
5404
+ if (this.isPersistedProductLine(product)) return false;
5405
+ var uid = (_product$metadata$uni = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product.unique_identification_number;
5406
+ var storedOrigin = uid !== undefined && uid !== null && uid !== '' ? (_tempOrder$_extend10 = tempOrder._extend) === null || _tempOrder$_extend10 === void 0 || (_tempOrder$_extend10 = _tempOrder$_extend10.productsByUid) === null || _tempOrder$_extend10 === void 0 || (_tempOrder$_extend10 = _tempOrder$_extend10[String(uid)]) === null || _tempOrder$_extend10 === void 0 ? void 0 : _tempOrder$_extend10.origin : undefined;
5407
+ return Boolean((product === null || product === void 0 || (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.__entitlementPassRuntimeAppend) === true || (storedOrigin === null || storedOrigin === void 0 ? void 0 : storedOrigin.__entitlementPassRuntimeAppend) === true);
5408
+ }
5409
+ }, {
5410
+ key: "hasSameEntitlementMergePriceConfig",
5411
+ value: function hasSameEntitlementMergePriceConfig(incoming, existing) {
5412
+ var _this34 = this;
5413
+ var buildPriceConfig = function buildPriceConfig(product) {
5414
+ var metadata = product.metadata || {};
5415
+ var bundle = (product.product_bundle || []).map(function (item) {
5416
+ var _ref73, _item$bundle_id, _ref74, _ref75, _item$bundle_product_, _ref76, _item$bundle_variant_, _ref77, _item$price_type, _ref78, _item$price_type_ext;
5417
+ return {
5418
+ bundle_id: (_ref73 = (_item$bundle_id = item.bundle_id) !== null && _item$bundle_id !== void 0 ? _item$bundle_id : item.id) !== null && _ref73 !== void 0 ? _ref73 : null,
5419
+ bundle_product_id: (_ref74 = (_ref75 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref75 !== void 0 ? _ref75 : item.product_id) !== null && _ref74 !== void 0 ? _ref74 : null,
5420
+ bundle_variant_id: (_ref76 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.product_variant_id) !== null && _ref76 !== void 0 ? _ref76 : 0,
5421
+ price_type: (_ref77 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref77 !== void 0 ? _ref77 : '',
5422
+ price_type_ext: (_ref78 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref78 !== void 0 ? _ref78 : ''
5423
+ };
5424
+ }).sort(function (left, right) {
5425
+ return JSON.stringify(left).localeCompare(JSON.stringify(right));
5426
+ });
5427
+ return JSON.stringify({
5428
+ original_price: _this34.normalizeFingerprintMoney(product.original_price),
5429
+ source_product_price: _this34.normalizeFingerprintMoney(metadata.source_product_price),
5430
+ main_product_original_price: _this34.normalizeFingerprintMoney(metadata.main_product_original_price),
5431
+ price_override: _this34.normalizeFingerprintMoney(metadata.price_override),
5432
+ is_manual_discount: Boolean(metadata.is_manual_discount),
5433
+ bundle: bundle
5434
+ });
5435
+ };
5436
+ return buildPriceConfig(incoming) === buildPriceConfig(existing);
5437
+ }
5231
5438
  }, {
5232
5439
  key: "getBundleRuntimeIdentity",
5233
5440
  value: function getBundleRuntimeIdentity(bundle) {
5234
- var _ref73, _bundle$bundle_id2, _ref74, _bundle$bundle_group_2, _ref75, _ref76, _bundle$bundle_produc3, _ref77, _bundle$bundle_varian3;
5441
+ var _ref79, _bundle$bundle_id2, _ref80, _bundle$bundle_group_2, _ref81, _ref82, _bundle$bundle_produc3, _ref83, _bundle$bundle_varian3;
5235
5442
  if (!bundle || _typeof(bundle) !== 'object') return '';
5236
- return [(_ref73 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref73 !== void 0 ? _ref73 : '', (_ref74 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref74 !== void 0 ? _ref74 : '', (_ref75 = (_ref76 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref76 !== void 0 ? _ref76 : bundle.product_id) !== null && _ref75 !== void 0 ? _ref75 : '', (_ref77 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref77 !== void 0 ? _ref77 : 0].join('|');
5443
+ return [(_ref79 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref79 !== void 0 ? _ref79 : '', (_ref80 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref80 !== void 0 ? _ref80 : '', (_ref81 = (_ref82 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref82 !== void 0 ? _ref82 : bundle.product_id) !== null && _ref81 !== void 0 ? _ref81 : '', (_ref83 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref83 !== void 0 ? _ref83 : 0].join('|');
5237
5444
  }
5238
5445
  }, {
5239
5446
  key: "preservePersistedBundlePriceFields",
5240
5447
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
5241
- var _this33 = this;
5448
+ var _this35 = this;
5242
5449
  if (!Array.isArray(nextBundles)) return nextBundles;
5243
5450
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
5244
5451
  var previousByIdentity = new Map();
5245
5452
  previousBundles.forEach(function (bundle) {
5246
- var identity = _this33.getBundleRuntimeIdentity(bundle);
5453
+ var identity = _this35.getBundleRuntimeIdentity(bundle);
5247
5454
  if (identity) previousByIdentity.set(identity, bundle);
5248
5455
  });
5249
5456
  return nextBundles.map(function (bundle, index) {
5250
5457
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
5251
- var previous = previousByIdentity.get(_this33.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
5458
+ var previous = previousByIdentity.get(_this35.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
5252
5459
  if (!previous || _typeof(previous) !== 'object') return bundle;
5253
5460
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
5254
5461
  cover: previous.cover
@@ -5351,10 +5558,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5351
5558
  var weighedSourcePrice = callerChangesWeighing ? resolveWeighedSourcePrice(nextProduct.product_sku) : undefined;
5352
5559
  var hasResolvedWeighedPrice = weighedSourcePrice !== undefined;
5353
5560
  if (hasResolvedWeighedPrice && !callerUpdatesSourcePrice) {
5354
- var _ref78, _targetProduct$metada3, _targetProduct$metada4, _ref79, _targetProduct$metada5, _targetProduct$metada6;
5561
+ var _ref84, _targetProduct$metada3, _targetProduct$metada4, _ref85, _targetProduct$metada5, _targetProduct$metada6;
5355
5562
  var nextMainOriginal = new Decimal(weighedSourcePrice).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
5356
- var previousMainOriginal = new Decimal((_ref78 = (_targetProduct$metada3 = (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_original_price) !== null && _targetProduct$metada3 !== void 0 ? _targetProduct$metada3 : targetProduct.original_price) !== null && _ref78 !== void 0 ? _ref78 : 0);
5357
- var previousMainSelling = new Decimal((_ref79 = (_targetProduct$metada5 = (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.main_product_selling_price) !== null && _targetProduct$metada5 !== void 0 ? _targetProduct$metada5 : targetProduct.selling_price) !== null && _ref79 !== void 0 ? _ref79 : 0);
5563
+ var previousMainOriginal = new Decimal((_ref84 = (_targetProduct$metada3 = (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_original_price) !== null && _targetProduct$metada3 !== void 0 ? _targetProduct$metada3 : targetProduct.original_price) !== null && _ref84 !== void 0 ? _ref84 : 0);
5564
+ var previousMainSelling = new Decimal((_ref85 = (_targetProduct$metada5 = (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.main_product_selling_price) !== null && _targetProduct$metada5 !== void 0 ? _targetProduct$metada5 : targetProduct.selling_price) !== null && _ref85 !== void 0 ? _ref85 : 0);
5358
5565
  // A manual final price remains fixed; other legacy discounts keep their amount
5359
5566
  // until Rules reapplies the currently selected wallet discount below.
5360
5567
  var nextMainSelling = isManualProductDiscountProduct(nextProduct) ? previousMainSelling : nextMainOriginal.minus(previousMainOriginal.minus(previousMainSelling));
@@ -5402,13 +5609,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5402
5609
  delete nextProduct.metadata.main_product_original_price;
5403
5610
  delete nextProduct.metadata.price_schema_version;
5404
5611
  } else if (callerChangesLineConfiguration && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5405
- var _ref80, _targetProduct$metada15, _targetProduct$metada16, _ref81, _targetProduct$metada17, _targetProduct$metada18, _targetProduct$metada19;
5612
+ var _ref86, _targetProduct$metada15, _targetProduct$metada16, _ref87, _targetProduct$metada17, _targetProduct$metada18, _targetProduct$metada19;
5406
5613
  // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
5407
5614
  // 但必须让 original 与 selling 一起随新的 option 金额移动。
5408
5615
  var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
5409
5616
  var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
5410
- var _previousMainOriginal2 = new Decimal(Number((_ref80 = (_targetProduct$metada15 = (_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.main_product_original_price) !== null && _targetProduct$metada15 !== void 0 ? _targetProduct$metada15 : targetProduct.original_price) !== null && _ref80 !== void 0 ? _ref80 : 0) || 0);
5411
- var _previousMainSelling2 = new Decimal(Number((_ref81 = (_targetProduct$metada17 = (_targetProduct$metada18 = targetProduct.metadata) === null || _targetProduct$metada18 === void 0 ? void 0 : _targetProduct$metada18.main_product_selling_price) !== null && _targetProduct$metada17 !== void 0 ? _targetProduct$metada17 : targetProduct.selling_price) !== null && _ref81 !== void 0 ? _ref81 : _previousMainOriginal2.toNumber()) || 0);
5617
+ var _previousMainOriginal2 = new Decimal(Number((_ref86 = (_targetProduct$metada15 = (_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.main_product_original_price) !== null && _targetProduct$metada15 !== void 0 ? _targetProduct$metada15 : targetProduct.original_price) !== null && _ref86 !== void 0 ? _ref86 : 0) || 0);
5618
+ var _previousMainSelling2 = new Decimal(Number((_ref87 = (_targetProduct$metada17 = (_targetProduct$metada18 = targetProduct.metadata) === null || _targetProduct$metada18 === void 0 ? void 0 : _targetProduct$metada18.main_product_selling_price) !== null && _targetProduct$metada17 !== void 0 ? _targetProduct$metada17 : targetProduct.selling_price) !== null && _ref87 !== void 0 ? _ref87 : _previousMainOriginal2.toNumber()) || 0);
5412
5619
  var _preservedDiscount = _previousMainOriginal2.minus(_previousMainSelling2);
5413
5620
  var previousSource = ((_targetProduct$metada19 = targetProduct.metadata) === null || _targetProduct$metada19 === void 0 ? void 0 : _targetProduct$metada19.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal2.minus(previousOptionSum);
5414
5621
  var _nextMainOriginal2 = previousSource.plus(nextOptionSum);
@@ -5458,7 +5665,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5458
5665
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
5459
5666
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
5460
5667
  var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
5461
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
5668
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
5462
5669
  var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata2 = nextProduct.metadata) === null || _nextProduct$metadata2 === void 0 ? void 0 : _nextProduct$metadata2.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada20 = targetProduct.metadata) === null || _targetProduct$metada20 === void 0 ? void 0 : _targetProduct$metada20.booking_uid);
5463
5670
  if (!booking && preservedBookingUid) {
5464
5671
  normalizedProduct.booking_uid = preservedBookingUid;
@@ -5544,7 +5751,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5544
5751
  key: "updateOrderProducts",
5545
5752
  value: function () {
5546
5753
  var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
5547
- var _this34 = this;
5754
+ var _this36 = this;
5548
5755
  var tempOrder, reapplyWeighedDiscountProductUids, reapplyBookingDiscountProductUids;
5549
5756
  return _regeneratorRuntime().wrap(function _callee26$(_context28) {
5550
5757
  while (1) switch (_context28.prev = _context28.next) {
@@ -5558,7 +5765,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5558
5765
  case 3:
5559
5766
  reapplyWeighedDiscountProductUids = [];
5560
5767
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
5561
- var updatedProductUid = _this34.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
5768
+ var updatedProductUid = _this36.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
5562
5769
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
5563
5770
  if (params.allow_booking_discount_reapply && updatedProductUid) {
5564
5771
  acc.push(String(updatedProductUid));
@@ -5591,7 +5798,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5591
5798
  value: function () {
5592
5799
  var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
5593
5800
  var _targetProduct$metada22;
5594
- var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
5801
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, isPersistedOrderLine, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
5595
5802
  return _regeneratorRuntime().wrap(function _callee27$(_context29) {
5596
5803
  while (1) switch (_context29.prev = _context29.next) {
5597
5804
  case 0:
@@ -5629,16 +5836,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5629
5836
  throw new Error('[Order] 目标商品不存在,无法更新数量');
5630
5837
  case 13:
5631
5838
  targetProduct = tempOrder.products[productIndex];
5839
+ isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
5632
5840
  normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
5633
5841
  num: getSafeProductNum(num),
5634
5842
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
5635
5843
  unique_identification_number: ((_targetProduct$metada22 = targetProduct.metadata) === null || _targetProduct$metada22 === void 0 ? void 0 : _targetProduct$metada22.unique_identification_number) || unique_identification_number
5636
5844
  })
5637
5845
  })));
5638
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
5846
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
5639
5847
  settlementSnapshot = getSelectedSettlementSnapshot(normalizedProduct);
5640
5848
  if (!(this.isMultiCurrencySettlementEnabled() && (settlementSnapshot === null || settlementSnapshot === void 0 ? void 0 : settlementSnapshot.settlement_type) === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1)) {
5641
- _context29.next = 26;
5849
+ _context29.next = 27;
5642
5850
  break;
5643
5851
  }
5644
5852
  currencyProductId = Number(settlementSnapshot.currency_product_id);
@@ -5646,11 +5854,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5646
5854
  return Number(item === null || item === void 0 ? void 0 : item.product_id) === currencyProductId;
5647
5855
  });
5648
5856
  if (asset) {
5649
- _context29.next = 22;
5857
+ _context29.next = 23;
5650
5858
  break;
5651
5859
  }
5652
5860
  throw new VirtualCurrencyAssetNotFoundError(currencyProductId);
5653
- case 22:
5861
+ case 23:
5654
5862
  requiredAmount = tempOrder.products.reduce(function (sum, item, index) {
5655
5863
  var current = index === productIndex ? normalizedProduct : item;
5656
5864
  var currentSnapshot = getSelectedSettlementSnapshot(current);
@@ -5658,44 +5866,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5658
5866
  }, new Decimal(0));
5659
5867
  balance = new Decimal(asset.balance || 0);
5660
5868
  if (!balance.lt(requiredAmount)) {
5661
- _context29.next = 26;
5869
+ _context29.next = 27;
5662
5870
  break;
5663
5871
  }
5664
5872
  throw new VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
5665
- case 26:
5873
+ case 27:
5666
5874
  tempOrder.products[productIndex] = normalizedProduct;
5667
5875
  this.prepareVirtualSettlementTempOrder(tempOrder);
5668
5876
  isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
5669
5877
  if (isVirtualSettlement) {
5670
- _context29.next = 35;
5878
+ _context29.next = 36;
5671
5879
  break;
5672
5880
  }
5673
- _context29.next = 32;
5881
+ _context29.next = 33;
5674
5882
  return this.evaluatePromotion();
5675
- case 32:
5883
+ case 33:
5676
5884
  _context29.t0 = _context29.sent;
5677
- _context29.next = 36;
5885
+ _context29.next = 37;
5678
5886
  break;
5679
- case 35:
5680
- _context29.t0 = null;
5681
5887
  case 36:
5888
+ _context29.t0 = null;
5889
+ case 37:
5682
5890
  promotionPayload = _context29.t0;
5683
5891
  if (!isVirtualSettlement) {
5684
5892
  this.applyDiscount();
5685
5893
  }
5686
5894
  this.sanitizeTempOrderProducts(tempOrder);
5687
- _context29.next = 41;
5895
+ _context29.next = 42;
5688
5896
  return this.recalculateSummary({
5689
5897
  createIfMissing: true
5690
5898
  });
5691
- case 41:
5899
+ case 42:
5692
5900
  this.persistTempOrder();
5693
5901
  this.emitPromotionApplied(promotionPayload);
5694
5902
  this.logInfo('updateOrderProductQuantity success', {
5695
5903
  params: params
5696
5904
  });
5697
5905
  return _context29.abrupt("return", tempOrder.products);
5698
- case 45:
5906
+ case 46:
5699
5907
  case "end":
5700
5908
  return _context29.stop();
5701
5909
  }
@@ -5786,7 +5994,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5786
5994
  key: "removeProductsFromOrder",
5787
5995
  value: (function () {
5788
5996
  var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(identities, options) {
5789
- var _this35 = this;
5997
+ var _this37 = this;
5790
5998
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
5791
5999
  return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5792
6000
  while (1) switch (_context32.prev = _context32.next) {
@@ -5851,7 +6059,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5851
6059
  }
5852
6060
  if (productUid !== undefined && productUid !== null && productUid !== '') {
5853
6061
  bookingsBeforeRemove.forEach(function (booking) {
5854
- var bookingUid = _this35.getBookingUniqueIdentificationNumber(booking);
6062
+ var bookingUid = _this37.getBookingUniqueIdentificationNumber(booking);
5855
6063
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
5856
6064
  linkedBookingUidsToRemove.add(bookingUid);
5857
6065
  }
@@ -6066,23 +6274,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6066
6274
  }, {
6067
6275
  key: "buildCurrentSubmitPayloadForLocalPrint",
6068
6276
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
6069
- var _params$cacheId, _this$otherParams5, _ref82, _params$businessCode, _this$otherParams6, _this$otherParams7;
6277
+ var _params$cacheId, _this$otherParams5, _ref88, _params$businessCode, _this$otherParams6, _this$otherParams7;
6070
6278
  var tempOrder = this.ensureTempOrder();
6071
6279
  this.persistTempOrder();
6072
6280
  var payload = buildSubmitPayload({
6073
6281
  tempOrder: tempOrder,
6074
6282
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
6075
6283
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
6076
- businessCode: (_ref82 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref82 !== void 0 ? _ref82 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
6284
+ businessCode: (_ref88 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref88 !== void 0 ? _ref88 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
6077
6285
  channel: params === null || params === void 0 ? void 0 : params.channel,
6078
6286
  type: params === null || params === void 0 ? void 0 : params.type,
6079
6287
  summary: this.store.summary || createEmptySummary(),
6080
6288
  enhance: function enhance(nextPayload) {
6081
- var _ref83, _tempOrder$order_numb, _ref84, _tempOrder$shop_order2, _ref85, _tempOrder$shop_full_;
6289
+ var _ref89, _tempOrder$order_numb, _ref90, _tempOrder$shop_order2, _ref91, _tempOrder$shop_full_;
6082
6290
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
6083
- order_number: (_ref83 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref83 !== void 0 ? _ref83 : null,
6084
- shop_order_number: (_ref84 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref84 !== void 0 ? _ref84 : null,
6085
- shop_full_order_number: (_ref85 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref85 !== void 0 ? _ref85 : null,
6291
+ order_number: (_ref89 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref89 !== void 0 ? _ref89 : null,
6292
+ shop_order_number: (_ref90 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref90 !== void 0 ? _ref90 : null,
6293
+ shop_full_order_number: (_ref91 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref91 !== void 0 ? _ref91 : null,
6086
6294
  small_ticket_data_flag: 1
6087
6295
  });
6088
6296
  }
@@ -6246,7 +6454,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6246
6454
  key: "runSubmitTempOrder",
6247
6455
  value: function () {
6248
6456
  var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
6249
- var _params$cacheId3, _this$otherParams12, _ref86, _ref87, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6457
+ var _params$cacheId3, _this$otherParams12, _ref92, _ref93, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6250
6458
  var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
6251
6459
  return _regeneratorRuntime().wrap(function _callee37$(_context40) {
6252
6460
  while (1) switch (_context40.prev = _context40.next) {
@@ -6313,7 +6521,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6313
6521
  tempOrder: tempOrder,
6314
6522
  cacheId: effectiveCacheId,
6315
6523
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
6316
- businessCode: (_ref86 = (_ref87 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref87 !== void 0 ? _ref87 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref86 !== void 0 ? _ref86 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6524
+ businessCode: (_ref92 = (_ref93 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref93 !== void 0 ? _ref93 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref92 !== void 0 ? _ref92 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6317
6525
  channel: params === null || params === void 0 ? void 0 : params.channel,
6318
6526
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
6319
6527
  summary: latestSummary,
@@ -6483,10 +6691,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6483
6691
  value: function extractSubmitErrorResponse(error) {
6484
6692
  var _error$response,
6485
6693
  _error$response2,
6486
- _this36 = this;
6694
+ _this38 = this;
6487
6695
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
6488
6696
  return candidates.find(function (candidate) {
6489
- return _this36.isSubmitErrorResponse(candidate);
6697
+ return _this38.isSubmitErrorResponse(candidate);
6490
6698
  }) || null;
6491
6699
  }
6492
6700
  }, {
@@ -6514,7 +6722,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6514
6722
  key: "syncPaymentsToOrder",
6515
6723
  value: function () {
6516
6724
  var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
6517
- var _this37 = this,
6725
+ var _this39 = this,
6518
6726
  _params$confirmPendin;
6519
6727
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, enhancePayload, submitParams, submitResult;
6520
6728
  return _regeneratorRuntime().wrap(function _callee39$(_context42) {
@@ -6539,7 +6747,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6539
6747
  case 9:
6540
6748
  devicePrefix = _context42.t0;
6541
6749
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
6542
- return _this37.normalizePaymentSource(payment, {
6750
+ return _this39.normalizePaymentSource(payment, {
6543
6751
  defaultPaid: false,
6544
6752
  devicePrefix: devicePrefix
6545
6753
  });
@@ -6618,7 +6826,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6618
6826
  }, {
6619
6827
  key: "createOrder",
6620
6828
  value: function createOrder(params) {
6621
- var _this38 = this;
6829
+ var _this40 = this;
6622
6830
  var order = _objectSpread({
6623
6831
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
6624
6832
  // 要从外面拿,virtual
@@ -6650,7 +6858,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6650
6858
 
6651
6859
  // 为预约补齐 holder 信息
6652
6860
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
6653
- ensureCartItemOriginHolder(item, _this38.window);
6861
+ ensureCartItemOriginHolder(item, _this40.window);
6654
6862
  }
6655
6863
 
6656
6864
  // 购物车是否为普通商品
@@ -7292,10 +7500,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7292
7500
  _step22;
7293
7501
  try {
7294
7502
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
7295
- var _product$metadata11;
7503
+ var _product$metadata13;
7296
7504
  var product = _step22.value;
7297
7505
  var productUid = getOrderCollectionUid('product', product);
7298
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.booking_uid);
7506
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.booking_uid);
7299
7507
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
7300
7508
  continue;
7301
7509
  }
@@ -7353,7 +7561,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7353
7561
  }, {
7354
7562
  key: "normalizeTempOrderForRuntime",
7355
7563
  value: function normalizeTempOrderForRuntime(raw, options) {
7356
- var _this39 = this,
7564
+ var _this41 = this,
7357
7565
  _raw$_extend;
7358
7566
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
7359
7567
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
@@ -7378,12 +7586,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7378
7586
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
7379
7587
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
7380
7588
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
7381
- return _this39.normalizeHydratedOrderProduct(p, {
7589
+ return _this41.normalizeHydratedOrderProduct(p, {
7382
7590
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
7383
7591
  });
7384
7592
  }) : [];
7385
7593
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
7386
- var booking = _this39.normalizeHydratedBookingHolder(b || {});
7594
+ var booking = _this41.normalizeHydratedBookingHolder(b || {});
7387
7595
  return _objectSpread(_objectSpread({}, booking), {}, {
7388
7596
  is_all: normalizeBookingIsAll(booking),
7389
7597
  sub_type: normalizeBookingSubType(booking)
@@ -7433,15 +7641,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7433
7641
  _step24;
7434
7642
  try {
7435
7643
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
7436
- var _product$metadata12, _ref88, _ref89, _existed$origin, _rawProduct$metadata;
7644
+ var _product$metadata14, _ref94, _ref95, _existed$origin, _rawProduct$metadata;
7437
7645
  var _step24$value = _slicedToArray(_step24.value, 2),
7438
7646
  index = _step24$value[0],
7439
7647
  product = _step24$value[1];
7440
- var uid = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number;
7648
+ var uid = (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number;
7441
7649
  if (!uid) continue;
7442
7650
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
7443
7651
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
7444
- var origin = (_ref88 = (_ref89 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref89 !== void 0 ? _ref89 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref88 !== void 0 ? _ref88 : rawProduct;
7652
+ var origin = (_ref94 = (_ref95 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref95 !== void 0 ? _ref95 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref94 !== void 0 ? _ref94 : rawProduct;
7445
7653
  var originSnapshot = cloneDeep(origin);
7446
7654
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
7447
7655
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -7492,8 +7700,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7492
7700
  var bookingUidByProductUid = new Map();
7493
7701
  var productByUid = new Map();
7494
7702
  (tempOrder.products || []).forEach(function (product) {
7495
- var _product$metadata13;
7496
- var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7703
+ var _product$metadata15;
7704
+ var productUid = (product === null || product === void 0 || (_product$metadata15 = product.metadata) === null || _product$metadata15 === void 0 ? void 0 : _product$metadata15.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7497
7705
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
7498
7706
  productByUid.set(String(productUid), product);
7499
7707
  }
@@ -7514,8 +7722,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7514
7722
  bookingUidByProductUid.set(String(productUid), bookingUid);
7515
7723
  });
7516
7724
  (tempOrder.products || []).forEach(function (product) {
7517
- var _product$metadata14;
7518
- var productUid = (product === null || product === void 0 || (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7725
+ var _product$metadata16;
7726
+ var productUid = (product === null || product === void 0 || (_product$metadata16 = product.metadata) === null || _product$metadata16 === void 0 ? void 0 : _product$metadata16.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7519
7727
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
7520
7728
  var bookingUid = bookingUidByProductUid.get(String(productUid));
7521
7729
  if (!bookingUid) return;
@@ -7570,10 +7778,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7570
7778
  }, {
7571
7779
  key: "normalizeHydratedProductOptionItem",
7572
7780
  value: function normalizeHydratedProductOptionItem(optionItem) {
7573
- var _ref90, _optionItem$num, _ref91, _optionItem$add_price;
7574
- var rawNum = (_ref90 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref90 !== void 0 ? _ref90 : 1;
7781
+ var _ref96, _optionItem$num, _ref97, _optionItem$add_price;
7782
+ var rawNum = (_ref96 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref96 !== void 0 ? _ref96 : 1;
7575
7783
  var parsedNum = Number(rawNum);
7576
- var rawPrice = (_ref91 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref91 !== void 0 ? _ref91 : 0;
7784
+ var rawPrice = (_ref97 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref97 !== void 0 ? _ref97 : 0;
7577
7785
  var parsedPrice = Number(rawPrice);
7578
7786
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
7579
7787
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -7590,7 +7798,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7590
7798
  }, {
7591
7799
  key: "normalizeHydratedOrderProduct",
7592
7800
  value: function normalizeHydratedOrderProduct(product, options) {
7593
- var _this40 = this;
7801
+ var _this42 = this;
7594
7802
  var row = _objectSpread({}, product || {});
7595
7803
  if (row.num === undefined && row.product_quantity !== undefined) {
7596
7804
  row.num = row.product_quantity;
@@ -7598,7 +7806,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7598
7806
  var productSku = ensureProductSku(row);
7599
7807
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
7600
7808
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
7601
- return _this40.normalizeHydratedProductOptionItem(optionItem || {});
7809
+ return _this42.normalizeHydratedProductOptionItem(optionItem || {});
7602
7810
  }))
7603
7811
  });
7604
7812
  delete row["product_".concat('option', "_item")];
@@ -7706,11 +7914,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7706
7914
  targetMap.set(discountKey, (targetMap.get(discountKey) || new Decimal(0)).plus(amount));
7707
7915
  };
7708
7916
  var addProductDiscountAmount = function addProductDiscountAmount(discount, quantity, isPersistedProduct) {
7709
- var _discount$discount3, _discount$metadata;
7917
+ var _discount$discount3, _discount$metadata2;
7710
7918
  var discountKey = ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.resource_id) || discount.id;
7711
7919
  if (discountKey == null) return;
7712
7920
  var qty = Number(quantity) || 1;
7713
- var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
7921
+ var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.product_discount_difference) || 0);
7714
7922
  addDiscountAmount(savedMap, discountKey, amount);
7715
7923
  addDiscountAmount(isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap, discountKey, amount);
7716
7924
  };