@pisell/pisellos 2.3.123 → 2.3.124

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 (89) hide show
  1. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  3. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  4. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  5. package/dist/modules/Customer/index.js +6 -3
  6. package/dist/modules/Customer/types.d.ts +2 -0
  7. package/dist/modules/Discount/availability.d.ts +7 -0
  8. package/dist/modules/Discount/availability.js +49 -0
  9. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  10. package/dist/modules/Discount/entitlementPass.js +147 -0
  11. package/dist/modules/Discount/index.d.ts +2 -2
  12. package/dist/modules/Discount/index.js +37 -151
  13. package/dist/modules/Discount/types.d.ts +36 -5
  14. package/dist/modules/Order/index.d.ts +7 -1
  15. package/dist/modules/Order/index.js +437 -229
  16. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  17. package/dist/modules/Order/utils.d.ts +1 -1
  18. package/dist/modules/Order/utils.js +101 -60
  19. package/dist/modules/Payment/types.d.ts +21 -1
  20. package/dist/modules/Payment/types.js +2 -0
  21. package/dist/modules/Payment/walletpass.d.ts +1 -1
  22. package/dist/modules/Payment/walletpass.js +80 -47
  23. package/dist/modules/Rules/index.d.ts +2 -2
  24. package/dist/modules/Rules/index.js +480 -186
  25. package/dist/modules/Rules/types.d.ts +4 -0
  26. package/dist/server/modules/order/types.d.ts +2 -0
  27. package/dist/solution/BaseSales/index.d.ts +1 -0
  28. package/dist/solution/BaseSales/index.js +5 -2
  29. package/dist/solution/BaseSales/types.d.ts +2 -2
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  31. package/dist/solution/BookingByStep/index.d.ts +1 -1
  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 +7 -1
  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/BookingByStep/index.d.ts +1 -1
  76. package/lib/solution/BookingTicket/index.d.ts +1 -2
  77. package/lib/solution/BookingTicket/index.js +36 -33
  78. package/lib/solution/BookingTicket/types.d.ts +5 -1
  79. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  80. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  81. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  82. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  83. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  84. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  85. package/lib/solution/ShopDiscount/index.js +55 -9
  86. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  87. package/lib/solution/ShopDiscount/utils.js +42 -25
  88. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  89. 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; }
@@ -35,6 +35,7 @@ import { OrderHooks } from "./types";
35
35
  import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, buildPointCardSnapshotFromWalletPassList, buildVirtualCurrencySnapshotFromList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import dayjs from 'dayjs';
38
+ import { getDiscountLifecycleReason } from "../Discount/availability";
38
39
  import { stripOsPrivatePayloadFields } from "../../utils/os-private-payload";
39
40
  import { buildSalesNoteText, decodeSalesNotesSnapshot, getSalesNotePolicy } from "./salesNotes";
40
41
  import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
@@ -48,6 +49,7 @@ import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from
48
49
  import { applyTempOrderSettlementState, getSelectedSettlementSnapshot, getSettlementKey, getTempOrderSettlementKey, getTempOrderSettlementSnapshot, isVirtualSettlementOrder, normalizeVirtualSettlementOrderProduct, normalizeVirtualSettlementProducts, OrderSettlementConflictError, releaseTempOrderSettlementState, VirtualCurrencyAssetNotFoundError, VirtualCurrencyBalanceError } from "./utils/virtualSettlement";
49
50
  import { DiscountModule } from "../Discount";
50
51
  import { RulesModule } from "../Rules";
52
+ import { isEntitlementPass, isFullCoveragePass } from "../Discount/entitlementPass";
51
53
  import { UnavailableReason } from "../Rules/types";
52
54
  import Decimal from 'decimal.js';
53
55
  import { cloneDeep } from 'lodash-es';
@@ -71,9 +73,26 @@ function isManualProductDiscountProduct(product) {
71
73
  return (item === null || item === void 0 ? void 0 : item.type) === 'product';
72
74
  });
73
75
  }
76
+ function syncReducedEntitlementPassUsageCount(discountList, previousQuantity, nextQuantity) {
77
+ if (!Array.isArray(discountList)) return discountList;
78
+ var previousCount = getSafeProductNum(previousQuantity);
79
+ var nextCount = getSafeProductNum(nextQuantity);
80
+ if (nextCount >= previousCount) return discountList;
81
+ return discountList.map(function (discount) {
82
+ var _discount$metadata$nu, _discount$metadata;
83
+ if (!isEntitlementPass(discount)) return discount;
84
+ 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);
85
+ var usageCount = Number.isFinite(rawUsageCount) ? Math.max(Math.floor(rawUsageCount), 0) : previousCount;
86
+ return _objectSpread(_objectSpread({}, discount), {}, {
87
+ metadata: _objectSpread(_objectSpread({}, (discount === null || discount === void 0 ? void 0 : discount.metadata) || {}), {}, {
88
+ num: Math.min(usageCount, nextCount)
89
+ })
90
+ });
91
+ });
92
+ }
74
93
  var ORDER_PAYMENT_STATUS_PAID = 'paid';
75
94
  var ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
76
- var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
95
+ var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['entitlement_pass', 'good_pass', 'product_discount_card', 'discount_card']);
77
96
  function isCustomerPromotionDiscount(discount) {
78
97
  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());
79
98
  }
@@ -108,6 +127,27 @@ function getVoucherPaymentLifecycleKey(payment) {
108
127
  if (!isVoucherPaymentRecord(payment)) return null;
109
128
  return "".concat(String(payment.voucher_id), "::").concat(String(payment.status || ''));
110
129
  }
130
+ function getDiscountIdentityKey(discount) {
131
+ var id = discount === null || discount === void 0 ? void 0 : discount.id;
132
+ if (id === undefined || id === null || id === '') return null;
133
+ return String(id);
134
+ }
135
+ function mergeCommittedEntitlementWithRuntime(committed, runtime) {
136
+ var _committed$committedA, _runtime$id, _runtime$isDisabled, _runtime$isSelected;
137
+ var committedAppliedProductDetails = (_committed$committedA = committed.committedAppliedProductDetails) !== null && _committed$committedA !== void 0 && _committed$committedA.length ? committed.committedAppliedProductDetails : committed.appliedProductDetails || [];
138
+ return _objectSpread(_objectSpread(_objectSpread({}, committed), runtime), {}, {
139
+ id: (_runtime$id = runtime.id) !== null && _runtime$id !== void 0 ? _runtime$id : committed.id,
140
+ tag: runtime.tag || committed.tag,
141
+ type: runtime.type || committed.type,
142
+ isEditMode: false,
143
+ isDisabled: (_runtime$isDisabled = runtime.isDisabled) !== null && _runtime$isDisabled !== void 0 ? _runtime$isDisabled : false,
144
+ isSelected: (_runtime$isSelected = runtime.isSelected) !== null && _runtime$isSelected !== void 0 ? _runtime$isSelected : committed.isSelected,
145
+ isUsed: committed.isUsed || runtime.isUsed,
146
+ committedAppliedProductDetails: _toConsumableArray(committedAppliedProductDetails),
147
+ applicableProductDetails: [].concat(_toConsumableArray(committed.applicableProductDetails || []), _toConsumableArray(runtime.applicableProductDetails || [])),
148
+ appliedProductDetails: [].concat(_toConsumableArray(committedAppliedProductDetails), _toConsumableArray(runtime.appliedProductDetails || []))
149
+ });
150
+ }
111
151
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
112
152
  _inherits(OrderModule, _BaseModule);
113
153
  var _super = _createSuper(OrderModule);
@@ -170,7 +210,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
170
210
  _step2;
171
211
  try {
172
212
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
173
- 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;
213
+ 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;
174
214
  var item = _step2.value;
175
215
  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;
176
216
  if (!type || type === 'product') continue;
@@ -181,22 +221,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
181
221
  var key = Number.isFinite(id) ? id : String(resourceId);
182
222
  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 : {};
183
223
  var amount = Number((item === null || item === void 0 ? void 0 : item.amount) || 0);
184
- var discountCardType = item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.discount_card_type;
185
- 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';
224
+ 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) || '';
225
+ var discountCardType = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.discount_card_type;
226
+ 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';
186
227
  var detail = {
187
228
  amount: String((_item$amount = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount !== void 0 ? _item$amount : '0'),
188
229
  type: type,
189
230
  resource_id: key,
190
231
  title: title,
191
- 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'),
192
- 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,
232
+ 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'),
233
+ 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,
193
234
  metadata: item === null || item === void 0 ? void 0 : item.metadata,
194
- discount: item === null || item === void 0 ? void 0 : item.discount,
195
- _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
235
+ discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
236
+ 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
237
+ }),
238
+ _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
196
239
  };
197
240
  var existed = discountMap.get(key);
198
241
  if (existed) {
199
242
  var _existed$limited_rela;
243
+ if (!existed.encoded && encoded) {
244
+ existed.encoded = encoded;
245
+ existed.metadata = _objectSpread(_objectSpread({}, existed.metadata), {}, {
246
+ encoded: encoded
247
+ });
248
+ }
200
249
  existed.amount = Number(existed.amount || 0) + amount;
201
250
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
202
251
  if (!isDiscountCard) {
@@ -215,10 +264,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
215
264
  discountMap.set(key, {
216
265
  id: key,
217
266
  product_name: '',
218
- encoded: '',
219
- code: '',
267
+ encoded: encoded,
268
+ 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) || '',
269
+ metadata: {
270
+ encoded: encoded
271
+ },
220
272
  tag: type,
221
- 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,
273
+ 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,
222
274
  relation_type: '',
223
275
  par_value: String(parValue !== null && parValue !== void 0 ? parValue : '0'),
224
276
  used_par_value: String((_item$amount2 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount2 !== void 0 ? _item$amount2 : '0'),
@@ -251,8 +303,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
251
303
  amount: amount,
252
304
  discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
253
305
  resource_id: key,
254
- 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,
255
- 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'
306
+ 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,
307
+ 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'
256
308
  }),
257
309
  applicableProductDetails: [detail],
258
310
  appliedProductDetails: [detail]
@@ -556,7 +608,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
556
608
  }, {
557
609
  key: "createDefaultRulesHooks",
558
610
  value: function createDefaultRulesHooks() {
559
- return createDefaultOrderRulesHooks();
611
+ var _this2 = this;
612
+ return createDefaultOrderRulesHooks(function () {
613
+ var _this2$store$tempOrde;
614
+ return ((_this2$store$tempOrde = _this2.store.tempOrder) === null || _this2$store$tempOrde === void 0 ? void 0 : _this2$store$tempOrde.bookings) || [];
615
+ });
560
616
  }
561
617
 
562
618
  /**
@@ -578,9 +634,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
578
634
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
579
635
  var _this$store$tempOrder,
580
636
  _this$store$discount,
581
- _this2 = this,
637
+ _this3 = this,
582
638
  _this$store$tempOrder2;
583
- var orderId, requestEpoch, requestOrderIdentityKey, prepareConfigResult, isCurrentRequest, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentEditDiscounts, currentScanDiscounts, currentScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, mergedDiscountList;
639
+ 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;
584
640
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
585
641
  while (1) switch (_context3.prev = _context3.next) {
586
642
  case 0:
@@ -596,6 +652,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
596
652
  with_wallet_pass_holder: 1,
597
653
  with_available_wallet_flag: 1,
598
654
  with_available_wallet_pass_flag: 1,
655
+ with_entitlement_pass: 1,
656
+ filter_order_wallet_pass_usage: 0,
599
657
  with_virtual_currency: 1,
600
658
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
601
659
  }, orderId ? {
@@ -604,8 +662,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
604
662
  case 5:
605
663
  prepareConfigResult = _context3.sent;
606
664
  isCurrentRequest = function isCurrentRequest() {
607
- var _this2$store$tempOrde, _this2$store$tempOrde2;
608
- 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);
665
+ var _this3$store$tempOrde, _this3$store$tempOrde2;
666
+ 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);
609
667
  };
610
668
  if (isCurrentRequest()) {
611
669
  _context3.next = 9;
@@ -623,56 +681,101 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
623
681
  });
624
682
  }
625
683
  if (!discountList) {
626
- _context3.next = 27;
684
+ _context3.next = 32;
627
685
  break;
628
686
  }
629
687
  currentDiscountList = ((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || [];
630
- currentEditDiscounts = currentDiscountList.filter(function (discount) {
631
- return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
688
+ currentCommittedDiscounts = currentDiscountList.filter(function (discount) {
689
+ var _discount$committedAp;
690
+ 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);
632
691
  });
633
692
  currentScanDiscounts = currentDiscountList.filter(function (discount) {
634
693
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
635
694
  });
636
- currentScanDiscountIds = new Set(currentScanDiscounts.map(function (discount) {
637
- return discount === null || discount === void 0 ? void 0 : discount.id;
695
+ currentScanDiscountById = new Map(currentScanDiscounts.flatMap(function (discount) {
696
+ var id = getDiscountIdentityKey(discount);
697
+ return id === null ? [] : [[id, discount]];
698
+ }));
699
+ committedDiscountById = new Map(currentCommittedDiscounts.flatMap(function (discount) {
700
+ var id = getDiscountIdentityKey(discount);
701
+ return id === null ? [] : [[id, discount]];
638
702
  }));
703
+ mergedCommittedDiscountIds = new Set();
704
+ refreshedScanDiscountIds = new Set();
639
705
  runtimeDiscountIds = new Set();
640
- runtimeDiscounts = discountList.filter(function (discount) {
641
- if (currentScanDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
642
- if (runtimeDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
643
- runtimeDiscountIds.add(discount === null || discount === void 0 ? void 0 : discount.id);
644
- return true;
706
+ runtimeDiscounts = discountList.flatMap(function (discount) {
707
+ var id = getDiscountIdentityKey(discount);
708
+ if (id === null) return [discount];
709
+ if (runtimeDiscountIds.has(id)) return [];
710
+ runtimeDiscountIds.add(id);
711
+ var currentScanDiscount = currentScanDiscountById.get(id);
712
+ if (currentScanDiscount && (!isEntitlementPass(currentScanDiscount) || !isEntitlementPass(discount))) {
713
+ return [];
714
+ }
715
+ var committedDiscount = committedDiscountById.get(id);
716
+ var nextDiscount = discount;
717
+ if (committedDiscount && isEntitlementPass(committedDiscount) && isEntitlementPass(discount)) {
718
+ mergedCommittedDiscountIds.add(id);
719
+ nextDiscount = mergeCommittedEntitlementWithRuntime(committedDiscount, discount);
720
+ }
721
+ if (currentScanDiscount) {
722
+ var _currentScanDiscount$, _currentScanDiscount$2;
723
+ refreshedScanDiscountIds.add(id);
724
+ nextDiscount = _objectSpread(_objectSpread({}, nextDiscount), {}, {
725
+ isScan: true,
726
+ isSelected: (_currentScanDiscount$ = currentScanDiscount.isSelected) !== null && _currentScanDiscount$ !== void 0 ? _currentScanDiscount$ : nextDiscount.isSelected,
727
+ isManualSelect: (_currentScanDiscount$2 = currentScanDiscount.isManualSelect) !== null && _currentScanDiscount$2 !== void 0 ? _currentScanDiscount$2 : nextDiscount.isManualSelect
728
+ });
729
+ }
730
+ return [nextDiscount];
731
+ });
732
+ retainedCommittedDiscounts = currentCommittedDiscounts.filter(function (discount) {
733
+ var id = getDiscountIdentityKey(discount);
734
+ return id === null || !mergedCommittedDiscountIds.has(id);
735
+ }).map(function (discount) {
736
+ var _discount$committedAp2;
737
+ return (_discount$committedAp2 = discount.committedAppliedProductDetails) !== null && _discount$committedAp2 !== void 0 && _discount$committedAp2.length ? _objectSpread(_objectSpread({}, discount), {}, {
738
+ isEditMode: true,
739
+ isDisabled: true,
740
+ isSelected: true,
741
+ isUsed: true,
742
+ appliedProductDetails: _toConsumableArray(discount.committedAppliedProductDetails)
743
+ }) : discount;
645
744
  });
646
- mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(currentScanDiscounts), _toConsumableArray(runtimeDiscounts));
745
+ retainedScanDiscounts = currentScanDiscounts.filter(function (discount) {
746
+ var id = getDiscountIdentityKey(discount);
747
+ return id === null || !refreshedScanDiscountIds.has(id);
748
+ });
749
+ mergedDiscountList = [].concat(_toConsumableArray(retainedCommittedDiscounts), _toConsumableArray(retainedScanDiscounts), _toConsumableArray(runtimeDiscounts));
647
750
  if (isCurrentRequest()) {
648
- _context3.next = 21;
751
+ _context3.next = 26;
649
752
  break;
650
753
  }
651
754
  return _context3.abrupt("return", this.getDiscountList());
652
- case 21:
653
- _context3.next = 23;
755
+ case 26:
756
+ _context3.next = 28;
654
757
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
655
- case 23:
758
+ case 28:
656
759
  if (isCurrentRequest()) {
657
- _context3.next = 25;
760
+ _context3.next = 30;
658
761
  break;
659
762
  }
660
763
  return _context3.abrupt("return", this.getDiscountList());
661
- case 25:
662
- _context3.next = 27;
764
+ case 30:
765
+ _context3.next = 32;
663
766
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
664
- case 27:
767
+ case 32:
665
768
  if (isCurrentRequest()) {
666
- _context3.next = 29;
769
+ _context3.next = 34;
667
770
  break;
668
771
  }
669
772
  return _context3.abrupt("return", this.getDiscountList());
670
- case 29:
773
+ case 34:
671
774
  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) {
672
775
  this.applyDiscount();
673
776
  }
674
777
  return _context3.abrupt("return", this.getDiscountList());
675
- case 31:
778
+ case 36:
676
779
  case "end":
677
780
  return _context3.stop();
678
781
  }
@@ -792,7 +895,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
792
895
  value: function () {
793
896
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
794
897
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
795
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref16, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
898
+ 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;
796
899
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
797
900
  while (1) switch (_context6.prev = _context6.next) {
798
901
  case 0:
@@ -895,46 +998,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
895
998
  isAvailable: false,
896
999
  discountList: this.getDiscountList()
897
1000
  }, isAvailable = _ref16.isAvailable, newDiscountList = _ref16.discountList, evaluatedDiscountList = _ref16.evaluatedDiscountList, unavailableReason = _ref16.unavailableReason;
898
- shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
1001
+ scannedIds = new Set(withScanList.map(function (discount) {
1002
+ return String(discount.id);
1003
+ }));
1004
+ evaluatedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(function (discount) {
1005
+ return scannedIds.has(String(discount.id)) && isCustomerPromotionDiscount(discount) && !getDiscountLifecycleReason(discount);
1006
+ });
1007
+ shouldRetainForLater = !isAvailable && evaluatedScannedDiscounts.length > 0;
899
1008
  normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
900
- retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
901
1009
  resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
902
1010
  if (!(isAvailable && normalizedNewDiscountList)) {
903
- _context6.next = 36;
1011
+ _context6.next = 37;
904
1012
  break;
905
1013
  }
906
- _context6.next = 30;
1014
+ _context6.next = 31;
907
1015
  return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
908
- case 30:
909
- this.applyDiscount();
910
- _context6.next = 33;
1016
+ case 31:
1017
+ // 实际写回商品时沿用扫码试算的优先级,避免旧商品行的选卡覆盖本次扫码。
1018
+ this.applyDiscount({
1019
+ preferredEntitlementPassIds: withScanList.filter(function (discount) {
1020
+ return isEntitlementPass(discount);
1021
+ }).map(function (discount) {
1022
+ return discount.id;
1023
+ })
1024
+ });
1025
+ _context6.next = 34;
911
1026
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
912
- case 33:
1027
+ case 34:
913
1028
  resolvedDiscountList = this.getDiscountList();
914
- _context6.next = 42;
1029
+ _context6.next = 45;
915
1030
  break;
916
- case 36:
917
- if (!(shouldRetainForLater && retainedDiscountList)) {
918
- _context6.next = 42;
1031
+ case 37:
1032
+ if (!shouldRetainForLater) {
1033
+ _context6.next = 45;
919
1034
  break;
920
1035
  }
921
- _context6.next = 39;
922
- return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
923
- case 39:
924
- _context6.next = 41;
1036
+ // 只合并本次识别的卡券;不把试算产生的其他选券状态写回订单。
1037
+ retainedDiscounts = new Map(this.getDiscountList().map(function (discount) {
1038
+ return [String(discount.id), discount];
1039
+ }));
1040
+ evaluatedScannedDiscounts.forEach(function (discount) {
1041
+ retainedDiscounts.set(String(discount.id), _objectSpread(_objectSpread({}, discount), {}, {
1042
+ isScan: true,
1043
+ isAvailable: false,
1044
+ isSelected: false,
1045
+ reasonCode: discount.reasonCode || 'product_not_applicable',
1046
+ appliedProductDetails: [],
1047
+ savedAmount: 0
1048
+ }));
1049
+ });
1050
+ _context6.next = 42;
1051
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(_toConsumableArray(retainedDiscounts.values()));
1052
+ case 42:
1053
+ _context6.next = 44;
925
1054
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
926
- case 41:
1055
+ case 44:
927
1056
  resolvedDiscountList = this.getDiscountList();
928
- case 42:
1057
+ case 45:
929
1058
  return _context6.abrupt("return", {
930
1059
  type: 'clientCalc',
931
1060
  isAvailable: isAvailable || false,
932
1061
  isAccepted: Boolean(isAvailable || shouldRetainForLater),
933
1062
  discountList: resolvedDiscountList,
934
- scannedDiscountList: resultDiscountList,
1063
+ scannedDiscountList: evaluatedScannedDiscounts,
935
1064
  unavailableReason: unavailableReason
936
1065
  });
937
- case 43:
1066
+ case 46:
938
1067
  case "end":
939
1068
  return _context6.stop();
940
1069
  }
@@ -950,7 +1079,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
950
1079
  value: function applyDiscount(options) {
951
1080
  var _this$store$discount16,
952
1081
  _this$store$summary2,
953
- _this3 = this;
1082
+ _this4 = this;
954
1083
  var tempOrder = this.store.tempOrder;
955
1084
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
956
1085
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
@@ -981,7 +1110,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
981
1110
  },
982
1111
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
983
1112
  }, {
984
- reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
1113
+ reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
1114
+ preferredEntitlementPassIds: options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds
985
1115
  });
986
1116
  if (result !== null && result !== void 0 && result.productList) {
987
1117
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
@@ -1006,7 +1136,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1006
1136
  (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || _this$store$discount17.setDiscountList(result.discountList);
1007
1137
  }
1008
1138
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
1009
- return _this3.productHasCustomerBoundDiscount(product);
1139
+ return _this4.productHasCustomerBoundDiscount(product);
1010
1140
  });
1011
1141
  }
1012
1142
 
@@ -1069,7 +1199,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1069
1199
  var _evaluatePromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1070
1200
  var _this$promotionEvalua,
1071
1201
  _this$promotionEvalua2,
1072
- _this4 = this;
1202
+ _this5 = this;
1073
1203
  var tempOrder, strategyConfigs, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
1074
1204
  return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1075
1205
  while (1) switch (_context9.prev = _context9.next) {
@@ -1228,7 +1358,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1228
1358
  case 6:
1229
1359
  _context7.prev = 6;
1230
1360
  _context7.next = 9;
1231
- return _this4.giftSelectResolver({
1361
+ return _this5.giftSelectResolver({
1232
1362
  strategyId: addAction.strategyId,
1233
1363
  strategyName: addAction.strategyName,
1234
1364
  giftCount: addAction.giftCount,
@@ -1263,7 +1393,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1263
1393
  _context7.next = 26;
1264
1394
  break;
1265
1395
  }
1266
- linked = _this4.createLinkedProductAndBooking({
1396
+ linked = _this5.createLinkedProductAndBooking({
1267
1397
  product: gp,
1268
1398
  booking: booking
1269
1399
  });
@@ -1724,23 +1854,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1724
1854
  }, {
1725
1855
  key: "calculatePaymentTotal",
1726
1856
  value: function calculatePaymentTotal(payments) {
1727
- var _this5 = this;
1857
+ var _this6 = this;
1728
1858
  return mapPaymentItemsToOrderPayments(payments, {
1729
1859
  includeVoided: false
1730
1860
  }).reduce(function (sum, payment) {
1731
1861
  if (!isPaidPaymentRecord(payment)) return sum;
1732
- return sum.plus(_this5.calculatePaymentEffectiveAmount(payment));
1862
+ return sum.plus(_this6.calculatePaymentEffectiveAmount(payment));
1733
1863
  }, new Decimal(0));
1734
1864
  }
1735
1865
  }, {
1736
1866
  key: "calculateOrderPaidPaymentTotal",
1737
1867
  value: function calculateOrderPaidPaymentTotal(payments) {
1738
- var _this6 = this;
1868
+ var _this7 = this;
1739
1869
  return mapPaymentItemsToOrderPayments(payments, {
1740
1870
  includeVoided: false
1741
1871
  }).reduce(function (sum, payment) {
1742
1872
  if (!isPaidPaymentRecord(payment)) return sum;
1743
- return sum.plus(_this6.calculatePaymentGapAmount(payment));
1873
+ return sum.plus(_this7.calculatePaymentGapAmount(payment));
1744
1874
  }, new Decimal(0));
1745
1875
  }
1746
1876
  }, {
@@ -1876,13 +2006,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1876
2006
  }, {
1877
2007
  key: "calculateDepositPaidAmount",
1878
2008
  value: function calculateDepositPaidAmount(payments) {
1879
- var _this7 = this;
2009
+ var _this8 = this;
1880
2010
  return (payments || []).reduce(function (sum, payment) {
1881
2011
  var paymentRecord = payment;
1882
2012
  if (!isPaidPaymentRecord(paymentRecord)) return sum;
1883
2013
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1884
2014
  if (!isDepositPayment) return sum;
1885
- return sum.plus(_this7.calculatePaymentGapAmount(paymentRecord));
2015
+ return sum.plus(_this8.calculatePaymentGapAmount(paymentRecord));
1886
2016
  }, new Decimal(0));
1887
2017
  }
1888
2018
  }, {
@@ -1919,17 +2049,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1919
2049
  }, {
1920
2050
  key: "getPaymentNumberDevicePrefixSync",
1921
2051
  value: function getPaymentNumberDevicePrefixSync() {
1922
- var _this8 = this;
2052
+ var _this9 = this;
1923
2053
  return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1924
- return _this8.getPaymentNumberAppData(key);
2054
+ return _this9.getPaymentNumberAppData(key);
1925
2055
  });
1926
2056
  }
1927
2057
  }, {
1928
2058
  key: "getPaymentNumberDevicePrefixAsync",
1929
2059
  value: function getPaymentNumberDevicePrefixAsync() {
1930
- var _this9 = this;
2060
+ var _this10 = this;
1931
2061
  return resolvePaymentNumberDevicePrefix(function (key) {
1932
- return _this9.getPaymentNumberAppData(key);
2062
+ return _this10.getPaymentNumberAppData(key);
1933
2063
  });
1934
2064
  }
1935
2065
  }, {
@@ -2059,16 +2189,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2059
2189
  }, {
2060
2190
  key: "calculatePaidPaymentSummary",
2061
2191
  value: function calculatePaidPaymentSummary(payments) {
2062
- var _this10 = this;
2192
+ var _this11 = this;
2063
2193
  return (payments || []).reduce(function (summary, payment) {
2064
2194
  var paymentRecord = payment;
2065
2195
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
2066
2196
  return {
2067
2197
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
2068
- orderPaidAmount: summary.orderPaidAmount.plus(_this10.calculatePaymentOrderAmount(paymentRecord)),
2069
- gapPaidAmount: summary.gapPaidAmount.plus(_this10.calculatePaymentGapAmount(paymentRecord)),
2070
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this10.calculatePaymentServiceFee(paymentRecord)),
2071
- roundingAmount: summary.roundingAmount.plus(_this10.calculatePaymentRoundingAmount(paymentRecord))
2198
+ orderPaidAmount: summary.orderPaidAmount.plus(_this11.calculatePaymentOrderAmount(paymentRecord)),
2199
+ gapPaidAmount: summary.gapPaidAmount.plus(_this11.calculatePaymentGapAmount(paymentRecord)),
2200
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this11.calculatePaymentServiceFee(paymentRecord)),
2201
+ roundingAmount: summary.roundingAmount.plus(_this11.calculatePaymentRoundingAmount(paymentRecord))
2072
2202
  };
2073
2203
  }, {
2074
2204
  customerPaidAmount: new Decimal(0),
@@ -2275,15 +2405,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2275
2405
  }, {
2276
2406
  key: "normalizeFingerprintValue",
2277
2407
  value: function normalizeFingerprintValue(value) {
2278
- var _this11 = this;
2408
+ var _this12 = this;
2279
2409
  if (Array.isArray(value)) {
2280
2410
  return value.map(function (item) {
2281
- return _this11.normalizeFingerprintValue(item);
2411
+ return _this12.normalizeFingerprintValue(item);
2282
2412
  });
2283
2413
  }
2284
2414
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
2285
2415
  return Object.keys(value).sort().reduce(function (result, key) {
2286
- result[key] = _this11.normalizeFingerprintValue(value[key]);
2416
+ result[key] = _this12.normalizeFingerprintValue(value[key]);
2287
2417
  return result;
2288
2418
  }, {});
2289
2419
  }
@@ -2298,14 +2428,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2298
2428
  _sku$barcode,
2299
2429
  _ref23,
2300
2430
  _sku$variant_id,
2301
- _this12 = this;
2431
+ _this13 = this;
2302
2432
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2303
2433
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2304
2434
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2305
2435
  var _discount$type;
2306
2436
  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;
2307
2437
  });
2308
- var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
2438
+ var fullCoveragePassType = discountTypes.find(function (type) {
2439
+ return ['entitlement_pass', 'good_pass'].includes(type);
2440
+ });
2441
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || fullCoveragePassType || 'normal';
2309
2442
  return {
2310
2443
  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,
2311
2444
  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,
@@ -2332,7 +2465,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2332
2465
  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,
2333
2466
  option_group_item_id: (_ref25 = (_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 && _ref25 !== void 0 ? _ref25 : null,
2334
2467
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
2335
- add_price: _this12.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)
2468
+ 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)
2336
2469
  };
2337
2470
  })
2338
2471
  }),
@@ -2342,8 +2475,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2342
2475
  bundle_product_id: (_ref26 = (_ref27 = (_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 && _ref27 !== void 0 ? _ref27 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref26 !== void 0 ? _ref26 : null,
2343
2476
  bundle_variant_id: (_ref28 = (_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 && _ref28 !== void 0 ? _ref28 : 0,
2344
2477
  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),
2345
- price: _this12.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2346
- bundle_selling_price: _this12.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2478
+ price: _this13.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2479
+ bundle_selling_price: _this13.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2347
2480
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
2348
2481
  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 : ''
2349
2482
  };
@@ -2353,7 +2486,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2353
2486
  return {
2354
2487
  type: (_ref29 = (_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 && _ref29 !== void 0 ? _ref29 : '',
2355
2488
  discount_id: (_ref30 = (_ref31 = (_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 && _ref31 !== void 0 ? _ref31 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref30 !== void 0 ? _ref30 : null,
2356
- amount: _this12.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2489
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2357
2490
  };
2358
2491
  }))
2359
2492
  };
@@ -2361,9 +2494,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2361
2494
  }, {
2362
2495
  key: "buildOrderProductsFingerprint",
2363
2496
  value: function buildOrderProductsFingerprint(products) {
2364
- var _this13 = this;
2497
+ var _this14 = this;
2365
2498
  var items = (products || []).map(function (product) {
2366
- return _this13.buildProductFingerprintItem(product);
2499
+ return _this14.buildProductFingerprintItem(product);
2367
2500
  });
2368
2501
  items.sort(function (left, right) {
2369
2502
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2385,14 +2518,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2385
2518
  _sku$barcode2,
2386
2519
  _ref33,
2387
2520
  _sku$variant_id2,
2388
- _this14 = this;
2521
+ _this15 = this;
2389
2522
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2390
2523
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2391
2524
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2392
2525
  var _discount$type3;
2393
2526
  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;
2394
2527
  });
2395
- var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
2528
+ var fullCoveragePassType = discountTypes.find(function (type) {
2529
+ return ['entitlement_pass', 'good_pass'].includes(type);
2530
+ });
2531
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || fullCoveragePassType || 'normal';
2396
2532
  return {
2397
2533
  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,
2398
2534
  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,
@@ -2416,7 +2552,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2416
2552
  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,
2417
2553
  option_group_item_id: (_ref35 = (_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 && _ref35 !== void 0 ? _ref35 : null,
2418
2554
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
2419
- add_price: _this14.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)
2555
+ 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)
2420
2556
  };
2421
2557
  })
2422
2558
  }),
@@ -2430,14 +2566,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2430
2566
  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),
2431
2567
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2432
2568
  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 : '',
2433
- option: _this14.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2569
+ option: _this15.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2434
2570
  var _ref41, _option$id3, _option$option_group_5, _ref42, _option$option_group_6, _option$num3, _option$add_price3;
2435
2571
  return {
2436
2572
  id: (_ref41 = (_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 && _ref41 !== void 0 ? _ref41 : null,
2437
2573
  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,
2438
2574
  option_group_item_id: (_ref42 = (_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 && _ref42 !== void 0 ? _ref42 : null,
2439
2575
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2440
- add_price: _this14.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)
2576
+ 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)
2441
2577
  };
2442
2578
  }))
2443
2579
  };
@@ -2447,7 +2583,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2447
2583
  return {
2448
2584
  type: (_ref43 = (_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 && _ref43 !== void 0 ? _ref43 : '',
2449
2585
  discount_id: (_ref44 = (_ref45 = (_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 && _ref45 !== void 0 ? _ref45 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref44 !== void 0 ? _ref44 : null,
2450
- amount: _this14.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2586
+ amount: _this15.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2451
2587
  };
2452
2588
  }))
2453
2589
  };
@@ -2455,9 +2591,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2455
2591
  }, {
2456
2592
  key: "buildOrderProductsStructuralFingerprint",
2457
2593
  value: function buildOrderProductsStructuralFingerprint(products) {
2458
- var _this15 = this;
2594
+ var _this16 = this;
2459
2595
  var items = (products || []).map(function (product) {
2460
- return _this15.buildProductStructuralFingerprintItem(product);
2596
+ return _this16.buildProductStructuralFingerprintItem(product);
2461
2597
  });
2462
2598
  items.sort(function (left, right) {
2463
2599
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2909,9 +3045,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2909
3045
  }, {
2910
3046
  key: "sanitizeTempOrderProducts",
2911
3047
  value: function sanitizeTempOrderProducts(tempOrder) {
2912
- var _this16 = this;
3048
+ var _this17 = this;
2913
3049
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2914
- return _this16.sanitizeOrderProductForTempOrder(_this16.normalizeVirtualSettlementProductIfEnabled(product));
3050
+ return _this17.sanitizeOrderProductForTempOrder(_this17.normalizeVirtualSettlementProductIfEnabled(product));
2915
3051
  });
2916
3052
  this.syncTempOrderSettlementState(tempOrder);
2917
3053
  ensureUniqueProductLineUids(tempOrder);
@@ -3031,7 +3167,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3031
3167
  }, {
3032
3168
  key: "syncLinkedBookingHoldersToProducts",
3033
3169
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
3034
- var _this17 = this;
3170
+ var _this18 = this;
3035
3171
  var bookings = tempOrder.bookings || [];
3036
3172
  var products = tempOrder.products || [];
3037
3173
  if (!bookings.length || !products.length) return;
@@ -3056,7 +3192,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3056
3192
  var bookingUid = product.booking_uid || ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.booking_uid);
3057
3193
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
3058
3194
  if (linkedBooking) {
3059
- _this17.setProductHolderFromBooking(product, linkedBooking);
3195
+ _this18.setProductHolderFromBooking(product, linkedBooking);
3060
3196
  }
3061
3197
  });
3062
3198
  }
@@ -3184,9 +3320,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3184
3320
  }, {
3185
3321
  key: "findBookingIndexByUniqueIdentificationNumber",
3186
3322
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
3187
- var _this18 = this;
3323
+ var _this19 = this;
3188
3324
  return (tempOrder.bookings || []).findIndex(function (booking) {
3189
- return _this18.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3325
+ return _this19.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3190
3326
  });
3191
3327
  }
3192
3328
  }, {
@@ -3194,12 +3330,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3194
3330
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
3195
3331
  var _product$metadata5,
3196
3332
  _product$metadata6,
3197
- _this19 = this;
3333
+ _this20 = this;
3198
3334
  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);
3199
3335
  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);
3200
3336
  if (!productUid && !bookingUid) return;
3201
3337
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
3202
- var currentBookingUid = _this19.getBookingUniqueIdentificationNumber(booking);
3338
+ var currentBookingUid = _this20.getBookingUniqueIdentificationNumber(booking);
3203
3339
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
3204
3340
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
3205
3341
  return true;
@@ -3501,7 +3637,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3501
3637
  }, {
3502
3638
  key: "removeSalesNotesForMissingProductLines",
3503
3639
  value: function removeSalesNotesForMissingProductLines(tempOrder) {
3504
- var _this20 = this;
3640
+ var _this21 = this;
3505
3641
  var state = this.ensureSalesNotesRuntimeState(tempOrder);
3506
3642
  if (!state.loaded || !Array.isArray(tempOrder.notes) || tempOrder.notes.length === 0) {
3507
3643
  return;
@@ -3513,7 +3649,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3513
3649
  return typeof uid === 'string' && uid.length > 0;
3514
3650
  }));
3515
3651
  var nextNotes = tempOrder.notes.filter(function (note) {
3516
- var primary = _this20.getSalesNotePrimaryRelation(note);
3652
+ var primary = _this21.getSalesNotePrimaryRelation(note);
3517
3653
  if (!primary || primary.target_type !== 'order_detail') return true;
3518
3654
  return remainingProductUids.has(primary.target_uuid);
3519
3655
  });
@@ -3525,7 +3661,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3525
3661
  key: "setSalesNoteOnTempOrder",
3526
3662
  value: function setSalesNoteOnTempOrder(tempOrder, input) {
3527
3663
  var _input$target,
3528
- _this21 = this,
3664
+ _this22 = this,
3529
3665
  _tempOrder$shop_order;
3530
3666
  this.ensureSalesNotesLoadedForMutation(tempOrder);
3531
3667
  var note_type = String(input.note_type || '').trim();
@@ -3549,7 +3685,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3549
3685
  var notes = tempOrder.notes || [];
3550
3686
  // 当前 allergy policy 固定同一商品行只保留一条;业务调用方不参与去重规则。
3551
3687
  var existingIndex = policy.uniquePerPrimaryTarget ? notes.findIndex(function (note) {
3552
- var primary = _this21.getSalesNotePrimaryRelation(note);
3688
+ var primary = _this22.getSalesNotePrimaryRelation(note);
3553
3689
  return note.note_type === note_type && (primary === null || primary === void 0 ? void 0 : primary.target_type) === 'order_detail' && primary.target_uuid === target_uuid;
3554
3690
  }) : -1;
3555
3691
  var existing = existingIndex >= 0 ? notes[existingIndex] : null;
@@ -3821,7 +3957,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3821
3957
  value: function isCustomerBoundDiscount(discount) {
3822
3958
  var _discount$type5;
3823
3959
  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;
3824
- return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
3960
+ return type === 'entitlement_pass' || type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
3825
3961
  }
3826
3962
  }, {
3827
3963
  key: "shouldKeepCustomerBoundDiscountAfterCustomerChange",
@@ -3831,15 +3967,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3831
3967
  }, {
3832
3968
  key: "productHasCustomerBoundDiscount",
3833
3969
  value: function productHasCustomerBoundDiscount(product) {
3834
- var _this22 = this;
3970
+ var _this23 = this;
3835
3971
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3836
- return _this22.isCustomerBoundDiscount(discount);
3972
+ return _this23.isCustomerBoundDiscount(discount);
3837
3973
  })) {
3838
3974
  return true;
3839
3975
  }
3840
3976
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3841
3977
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3842
- return _this22.isCustomerBoundDiscount(discount);
3978
+ return _this23.isCustomerBoundDiscount(discount);
3843
3979
  });
3844
3980
  });
3845
3981
  }
@@ -3848,18 +3984,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3848
3984
  value: function shouldSkipDiscountCalculation(tempOrder) {
3849
3985
  var _this$store$discount20,
3850
3986
  _this$store$discount21,
3851
- _this23 = this;
3987
+ _this24 = this;
3852
3988
  if (this.hasActiveCustomerBoundDiscount) return false;
3853
3989
  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)) || [];
3854
3990
  if (discountList.length > 0) return false;
3855
3991
  return !(tempOrder.products || []).some(function (product) {
3856
- return _this23.productHasCustomerBoundDiscount(product);
3992
+ return _this24.productHasCustomerBoundDiscount(product);
3857
3993
  });
3858
3994
  }
3859
3995
  }, {
3860
3996
  key: "clearCustomerBoundDiscounts",
3861
3997
  value: function clearCustomerBoundDiscounts(tempOrder) {
3862
- var _this24 = this,
3998
+ var _this25 = this,
3863
3999
  _discountModule$getDi,
3864
4000
  _discountModule$getOr,
3865
4001
  _discountModule$setDi,
@@ -3868,7 +4004,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3868
4004
  var filterDiscountList = function filterDiscountList(discountList) {
3869
4005
  if (!Array.isArray(discountList)) return [];
3870
4006
  return discountList.filter(function (discount) {
3871
- var shouldRemove = _this24.isCustomerBoundDiscount(discount);
4007
+ var shouldRemove = _this25.isCustomerBoundDiscount(discount);
3872
4008
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3873
4009
  return !shouldRemove;
3874
4010
  });
@@ -3895,12 +4031,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3895
4031
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3896
4032
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3897
4033
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3898
- if (_this24.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3899
- return !_this24.isCustomerBoundDiscount(discount);
4034
+ if (_this25.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4035
+ return !_this25.isCustomerBoundDiscount(discount);
3900
4036
  });
3901
4037
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3902
- if (_this24.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3903
- return !_this24.isCustomerBoundDiscount(discount);
4038
+ if (_this25.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4039
+ return !_this25.isCustomerBoundDiscount(discount);
3904
4040
  });
3905
4041
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3906
4042
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -4064,10 +4200,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4064
4200
  }, {
4065
4201
  key: "setOrderPayments",
4066
4202
  value: function setOrderPayments(payments) {
4067
- var _this25 = this;
4203
+ var _this26 = this;
4068
4204
  var tempOrder = this.ensureTempOrder();
4069
4205
  tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
4070
- return _this25.normalizePaymentSource(payment, {
4206
+ return _this26.normalizePaymentSource(payment, {
4071
4207
  defaultPaid: false
4072
4208
  });
4073
4209
  }));
@@ -4122,7 +4258,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4122
4258
  }, {
4123
4259
  key: "addOrderPaymentWithDevicePrefix",
4124
4260
  value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
4125
- var _this26 = this;
4261
+ var _this27 = this;
4126
4262
  this.logInfo('addOrderPayment', {
4127
4263
  payment: payment
4128
4264
  });
@@ -4140,7 +4276,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4140
4276
  void this.recalculateSummary({
4141
4277
  createIfMissing: true
4142
4278
  }).catch(function (error) {
4143
- _this26.logError('recalculate summary after addOrderPayment failed', {
4279
+ _this27.logError('recalculate summary after addOrderPayment failed', {
4144
4280
  error: error instanceof Error ? error.message : String(error)
4145
4281
  });
4146
4282
  });
@@ -4253,7 +4389,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4253
4389
  }, {
4254
4390
  key: "applyPaymentLifecycleChange",
4255
4391
  value: function applyPaymentLifecycleChange(tempOrder, options) {
4256
- var _this27 = this;
4392
+ var _this28 = this;
4257
4393
  this.updateTempOrderPaymentStatus(tempOrder);
4258
4394
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
4259
4395
  this.persistTempOrder();
@@ -4263,7 +4399,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4263
4399
  void this.recalculateSummary({
4264
4400
  createIfMissing: true
4265
4401
  }).catch(function (error) {
4266
- _this27.logError("recalculate summary after ".concat(logContext, " failed"), {
4402
+ _this28.logError("recalculate summary after ".concat(logContext, " failed"), {
4267
4403
  error: error instanceof Error ? error.message : String(error)
4268
4404
  });
4269
4405
  });
@@ -4307,7 +4443,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4307
4443
  }, {
4308
4444
  key: "updateVoucherOrderPayments",
4309
4445
  value: function updateVoucherOrderPayments(payments, options) {
4310
- var _this28 = this;
4446
+ var _this29 = this;
4311
4447
  var tempOrder = this.ensureTempOrder();
4312
4448
  var isOrderPaymentType = function isOrderPaymentType(value) {
4313
4449
  return value === 'normal' || value === 'deposit';
@@ -4342,7 +4478,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4342
4478
  });
4343
4479
  };
4344
4480
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
4345
- return _this28.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4481
+ return _this29.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4346
4482
  defaultPaid: false,
4347
4483
  devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
4348
4484
  });
@@ -4395,7 +4531,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4395
4531
  void this.recalculateSummary({
4396
4532
  createIfMissing: true
4397
4533
  }).catch(function (error) {
4398
- _this28.logError('recalculate summary after updateVoucherOrderPayments failed', {
4534
+ _this29.logError('recalculate summary after updateVoucherOrderPayments failed', {
4399
4535
  error: error instanceof Error ? error.message : String(error)
4400
4536
  });
4401
4537
  });
@@ -4453,7 +4589,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4453
4589
  key: "shouldMergeProductToOrder",
4454
4590
  value: function shouldMergeProductToOrder(params) {
4455
4591
  var _this$orderHooks,
4456
- _this29 = this;
4592
+ _this30 = this;
4457
4593
  var onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
4458
4594
  if (!onBeforeMergeProductToOrder) return true;
4459
4595
  var result = onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
@@ -4461,7 +4597,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4461
4597
  }));
4462
4598
  if (result && _typeof(result) === 'object' && typeof result.then === 'function') {
4463
4599
  return Promise.resolve(result).then(function (resolved) {
4464
- return _this29.normalizeShouldMergeProductResult(resolved);
4600
+ return _this30.normalizeShouldMergeProductResult(resolved);
4465
4601
  });
4466
4602
  }
4467
4603
  return this.normalizeShouldMergeProductResult(result);
@@ -4662,7 +4798,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4662
4798
  _metadata,
4663
4799
  _productToAdd$metadat,
4664
4800
  _origin,
4665
- _this30 = this;
4801
+ _this31 = this;
4666
4802
  var linked = booking ? this.createLinkedProductAndBooking({
4667
4803
  product: product,
4668
4804
  booking: booking
@@ -4689,18 +4825,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4689
4825
  }
4690
4826
  normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
4691
4827
  var hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
4828
+ var hasIncomingEntitlementPass = this.hasEntitlementPassDiscount(normalizedIncoming);
4829
+ var isIncomingEntitlementAppend = this.isRuntimeEntitlementAppend(productToAdd, tempOrder);
4830
+ var isIncomingPersistedEntitlementPass = hasIncomingEntitlementPass && this.isPersistedProductLine(normalizedIncoming);
4692
4831
  var hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
4693
4832
  var hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
4694
4833
  var hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
4695
4834
  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;
4696
- var shouldForceNewLine = disableMerge || !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4697
- var matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4698
- var _item$metadata3;
4699
- if (_this30.hasGoodPassDiscount(item)) return false;
4700
- if (_this30.hasOrderProductLineNote(item)) return false;
4701
- if (isManualProductDiscountProduct(item)) return false;
4702
- if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
4703
- if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
4835
+ var shouldForceNewLine = disableMerge || !!booking || hasIncomingGoodPass || isIncomingPersistedEntitlementPass || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4836
+ var matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4837
+ if (_this31.hasGoodPassDiscount(item)) return false;
4838
+ var isRuntimeEntitlementPass = _this31.isRuntimeEntitlementAppend(item, tempOrder);
4839
+ if (isIncomingEntitlementAppend !== isRuntimeEntitlementPass) {
4840
+ return false;
4841
+ }
4842
+ if (isIncomingEntitlementAppend && _this31.isPersistedProductLine(item)) {
4843
+ return false;
4844
+ }
4845
+ var hasExistingProductNote = _this31.hasOrderProductLineNote(item);
4846
+ if ((hasIncomingProductNote || hasExistingProductNote) && (!isRuntimeEntitlementPass || String(normalizedIncoming.note || '').trim() !== String(item.note || '').trim())) {
4847
+ return false;
4848
+ }
4849
+ var hasExistingManualProductDiscount = isManualProductDiscountProduct(item);
4850
+ if (isRuntimeEntitlementPass && !_this31.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
4851
+ return false;
4852
+ }
4853
+ if ((hasIncomingManualProductDiscount || hasExistingManualProductDiscount) && !isRuntimeEntitlementPass) {
4854
+ return false;
4855
+ }
4856
+ if (_this31.isPersistedProductLine(item)) return false;
4704
4857
  if (item.product_id !== productToAdd.product_id) return false;
4705
4858
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
4706
4859
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -4711,7 +4864,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4711
4864
  var commitProductLine = function commitProductLine(shouldMerge) {
4712
4865
  var committedProduct;
4713
4866
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4714
- _this30.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4867
+ _this31.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4715
4868
  if (linked) {
4716
4869
  normalizedIncoming.booking_uid = linked.bookingUid;
4717
4870
  normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
@@ -4729,7 +4882,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4729
4882
  var _targetProduct$metada;
4730
4883
  var targetProduct = matchedProduct;
4731
4884
  var targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4732
- var normalizedProduct = _this30.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4885
+ var normalizedProduct = _this31.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4733
4886
  metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4734
4887
  unique_identification_number: targetUid
4735
4888
  })
@@ -4752,7 +4905,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4752
4905
  order_detail_id: targetProduct.order_detail_id,
4753
4906
  num: nextNum
4754
4907
  });
4755
- _this30.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4908
+ _this31.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4756
4909
  committedProduct = tempOrder.products[matchedIndex];
4757
4910
  if (matchedIndex !== tempOrder.products.length - 1) {
4758
4911
  var mergedProduct = tempOrder.products[matchedIndex];
@@ -4862,7 +5015,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4862
5015
  key: "addProductToOrder",
4863
5016
  value: (function () {
4864
5017
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(product, booking, options) {
4865
- var _this31 = this;
5018
+ var _this32 = this;
4866
5019
  var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref68, _productRecord$num, productRecord, splitCount, i, splitLine, committedProduct, _committedProduct, _committedProduct2;
4867
5020
  return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4868
5021
  while (1) switch (_context25.prev = _context25.next) {
@@ -4891,7 +5044,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4891
5044
  throw new Error('[Order Notes] 商品行缺少 unique_identification_number');
4892
5045
  }
4893
5046
  salesNoteDrafts.forEach(function (draft) {
4894
- _this31.setSalesNoteOnTempOrder(tempOrder, {
5047
+ _this32.setSalesNoteOnTempOrder(tempOrder, {
4895
5048
  note_type: draft.note_type,
4896
5049
  target: {
4897
5050
  target_type: 'order_detail',
@@ -5125,45 +5278,99 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5125
5278
  return addProductsToOrder;
5126
5279
  }())
5127
5280
  }, {
5128
- key: "hasGoodPassDiscount",
5129
- value: function hasGoodPassDiscount(product) {
5281
+ key: "getFullCoveragePassDiscounts",
5282
+ value: function getFullCoveragePassDiscounts(product) {
5130
5283
  var _product$_extend;
5131
- var hasMainGoodPass = (product.discount_list || []).some(function (item) {
5132
- return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
5133
- });
5134
- if (hasMainGoodPass) return true;
5135
- var bundleDiscountList = [];
5284
+ var discountList = _toConsumableArray(product.discount_list || []);
5136
5285
  (product.product_bundle || []).forEach(function (item) {
5137
- bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5286
+ discountList.push.apply(discountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5138
5287
  });
5139
5288
  ((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) {
5140
- bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5289
+ discountList.push.apply(discountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5141
5290
  });
5142
- return bundleDiscountList.some(function (item) {
5143
- return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
5291
+ return discountList.filter(function (item) {
5292
+ return isFullCoveragePass(item);
5293
+ });
5294
+ }
5295
+ }, {
5296
+ key: "hasEntitlementPassDiscount",
5297
+ value: function hasEntitlementPassDiscount(product) {
5298
+ return this.getFullCoveragePassDiscounts(product).some(function (item) {
5299
+ return isEntitlementPass(item);
5144
5300
  });
5145
5301
  }
5302
+ }, {
5303
+ key: "hasGoodPassDiscount",
5304
+ value: function hasGoodPassDiscount(product) {
5305
+ return this.getFullCoveragePassDiscounts(product).some(function (item) {
5306
+ return !isEntitlementPass(item);
5307
+ });
5308
+ }
5309
+ }, {
5310
+ key: "isPersistedProductLine",
5311
+ value: function isPersistedProductLine(product) {
5312
+ var _product$metadata11;
5313
+ 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;
5314
+ }
5315
+ }, {
5316
+ key: "isRuntimeEntitlementAppend",
5317
+ value: function isRuntimeEntitlementAppend(product, tempOrder) {
5318
+ var _product$metadata$uni, _product$metadata12, _tempOrder$_extend10, _product$_origin;
5319
+ if (this.isPersistedProductLine(product)) return false;
5320
+ 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;
5321
+ 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;
5322
+ 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);
5323
+ }
5324
+ }, {
5325
+ key: "hasSameEntitlementMergePriceConfig",
5326
+ value: function hasSameEntitlementMergePriceConfig(incoming, existing) {
5327
+ var _this33 = this;
5328
+ var buildPriceConfig = function buildPriceConfig(product) {
5329
+ var metadata = product.metadata || {};
5330
+ var bundle = (product.product_bundle || []).map(function (item) {
5331
+ var _ref70, _item$bundle_id, _ref71, _ref72, _item$bundle_product_, _ref73, _item$bundle_variant_, _ref74, _item$price_type, _ref75, _item$price_type_ext;
5332
+ return {
5333
+ bundle_id: (_ref70 = (_item$bundle_id = item.bundle_id) !== null && _item$bundle_id !== void 0 ? _item$bundle_id : item.id) !== null && _ref70 !== void 0 ? _ref70 : null,
5334
+ bundle_product_id: (_ref71 = (_ref72 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref72 !== void 0 ? _ref72 : item.product_id) !== null && _ref71 !== void 0 ? _ref71 : null,
5335
+ bundle_variant_id: (_ref73 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.product_variant_id) !== null && _ref73 !== void 0 ? _ref73 : 0,
5336
+ price_type: (_ref74 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref74 !== void 0 ? _ref74 : '',
5337
+ price_type_ext: (_ref75 = (_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 && _ref75 !== void 0 ? _ref75 : ''
5338
+ };
5339
+ }).sort(function (left, right) {
5340
+ return JSON.stringify(left).localeCompare(JSON.stringify(right));
5341
+ });
5342
+ return JSON.stringify({
5343
+ original_price: _this33.normalizeFingerprintMoney(product.original_price),
5344
+ source_product_price: _this33.normalizeFingerprintMoney(metadata.source_product_price),
5345
+ main_product_original_price: _this33.normalizeFingerprintMoney(metadata.main_product_original_price),
5346
+ price_override: _this33.normalizeFingerprintMoney(metadata.price_override),
5347
+ is_manual_discount: Boolean(metadata.is_manual_discount),
5348
+ bundle: bundle
5349
+ });
5350
+ };
5351
+ return buildPriceConfig(incoming) === buildPriceConfig(existing);
5352
+ }
5146
5353
  }, {
5147
5354
  key: "getBundleRuntimeIdentity",
5148
5355
  value: function getBundleRuntimeIdentity(bundle) {
5149
- var _ref70, _bundle$bundle_id2, _ref71, _bundle$bundle_group_2, _ref72, _ref73, _bundle$bundle_produc3, _ref74, _bundle$bundle_varian3;
5356
+ var _ref76, _bundle$bundle_id2, _ref77, _bundle$bundle_group_2, _ref78, _ref79, _bundle$bundle_produc3, _ref80, _bundle$bundle_varian3;
5150
5357
  if (!bundle || _typeof(bundle) !== 'object') return '';
5151
- return [(_ref70 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref70 !== void 0 ? _ref70 : '', (_ref71 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref71 !== void 0 ? _ref71 : '', (_ref72 = (_ref73 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref73 !== void 0 ? _ref73 : bundle.product_id) !== null && _ref72 !== void 0 ? _ref72 : '', (_ref74 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref74 !== void 0 ? _ref74 : 0].join('|');
5358
+ return [(_ref76 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref76 !== void 0 ? _ref76 : '', (_ref77 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref77 !== void 0 ? _ref77 : '', (_ref78 = (_ref79 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref79 !== void 0 ? _ref79 : bundle.product_id) !== null && _ref78 !== void 0 ? _ref78 : '', (_ref80 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref80 !== void 0 ? _ref80 : 0].join('|');
5152
5359
  }
5153
5360
  }, {
5154
5361
  key: "preservePersistedBundlePriceFields",
5155
5362
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
5156
- var _this32 = this;
5363
+ var _this34 = this;
5157
5364
  if (!Array.isArray(nextBundles)) return nextBundles;
5158
5365
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
5159
5366
  var previousByIdentity = new Map();
5160
5367
  previousBundles.forEach(function (bundle) {
5161
- var identity = _this32.getBundleRuntimeIdentity(bundle);
5368
+ var identity = _this34.getBundleRuntimeIdentity(bundle);
5162
5369
  if (identity) previousByIdentity.set(identity, bundle);
5163
5370
  });
5164
5371
  return nextBundles.map(function (bundle, index) {
5165
5372
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
5166
- var previous = previousByIdentity.get(_this32.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
5373
+ var previous = previousByIdentity.get(_this34.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
5167
5374
  if (!previous || _typeof(previous) !== 'object') return bundle;
5168
5375
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
5169
5376
  cover: previous.cover
@@ -5299,13 +5506,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5299
5506
  delete nextProduct.metadata.main_product_original_price;
5300
5507
  delete nextProduct.metadata.price_schema_version;
5301
5508
  } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5302
- var _ref75, _targetProduct$metada10, _targetProduct$metada11, _ref76, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
5509
+ var _ref81, _targetProduct$metada10, _targetProduct$metada11, _ref82, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
5303
5510
  // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
5304
5511
  // 但必须让 original 与 selling 一起随新的 option 金额移动。
5305
5512
  var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
5306
5513
  var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
5307
- var _previousMainOriginal = new Decimal(Number((_ref75 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref75 !== void 0 ? _ref75 : 0) || 0);
5308
- var _previousMainSelling = new Decimal(Number((_ref76 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref76 !== void 0 ? _ref76 : _previousMainOriginal.toNumber()) || 0);
5514
+ var _previousMainOriginal = new Decimal(Number((_ref81 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref81 !== void 0 ? _ref81 : 0) || 0);
5515
+ var _previousMainSelling = new Decimal(Number((_ref82 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref82 !== void 0 ? _ref82 : _previousMainOriginal.toNumber()) || 0);
5309
5516
  var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
5310
5517
  var previousSource = ((_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal.minus(previousOptionSum);
5311
5518
  var _nextMainOriginal = previousSource.plus(nextOptionSum);
@@ -5326,7 +5533,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5326
5533
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
5327
5534
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
5328
5535
  var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
5329
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
5536
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
5330
5537
  var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada15 = targetProduct.metadata) === null || _targetProduct$metada15 === void 0 ? void 0 : _targetProduct$metada15.booking_uid);
5331
5538
  if (!booking && preservedBookingUid) {
5332
5539
  normalizedProduct.booking_uid = preservedBookingUid;
@@ -5405,7 +5612,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5405
5612
  key: "updateOrderProducts",
5406
5613
  value: function () {
5407
5614
  var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
5408
- var _this33 = this;
5615
+ var _this35 = this;
5409
5616
  var tempOrder, reapplyBookingDiscountProductUids;
5410
5617
  return _regeneratorRuntime().wrap(function _callee26$(_context28) {
5411
5618
  while (1) switch (_context28.prev = _context28.next) {
@@ -5418,7 +5625,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5418
5625
  return _context28.abrupt("return", tempOrder.products);
5419
5626
  case 3:
5420
5627
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
5421
- var updatedProductUid = _this33.applyOrderProductUpdateToTempOrder(tempOrder, params);
5628
+ var updatedProductUid = _this35.applyOrderProductUpdateToTempOrder(tempOrder, params);
5422
5629
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
5423
5630
  if (params.allow_booking_discount_reapply && updatedProductUid) {
5424
5631
  acc.push(String(updatedProductUid));
@@ -5450,7 +5657,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5450
5657
  value: function () {
5451
5658
  var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
5452
5659
  var _targetProduct$metada17;
5453
- 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;
5660
+ 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;
5454
5661
  return _regeneratorRuntime().wrap(function _callee27$(_context29) {
5455
5662
  while (1) switch (_context29.prev = _context29.next) {
5456
5663
  case 0:
@@ -5488,16 +5695,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5488
5695
  throw new Error('[Order] 目标商品不存在,无法更新数量');
5489
5696
  case 13:
5490
5697
  targetProduct = tempOrder.products[productIndex];
5698
+ isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
5491
5699
  normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
5492
5700
  num: getSafeProductNum(num),
5493
5701
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
5494
5702
  unique_identification_number: ((_targetProduct$metada17 = targetProduct.metadata) === null || _targetProduct$metada17 === void 0 ? void 0 : _targetProduct$metada17.unique_identification_number) || unique_identification_number
5495
5703
  })
5496
5704
  })));
5497
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
5705
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
5498
5706
  settlementSnapshot = getSelectedSettlementSnapshot(normalizedProduct);
5499
5707
  if (!(this.isMultiCurrencySettlementEnabled() && (settlementSnapshot === null || settlementSnapshot === void 0 ? void 0 : settlementSnapshot.settlement_type) === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1)) {
5500
- _context29.next = 26;
5708
+ _context29.next = 27;
5501
5709
  break;
5502
5710
  }
5503
5711
  currencyProductId = Number(settlementSnapshot.currency_product_id);
@@ -5505,11 +5713,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5505
5713
  return Number(item === null || item === void 0 ? void 0 : item.product_id) === currencyProductId;
5506
5714
  });
5507
5715
  if (asset) {
5508
- _context29.next = 22;
5716
+ _context29.next = 23;
5509
5717
  break;
5510
5718
  }
5511
5719
  throw new VirtualCurrencyAssetNotFoundError(currencyProductId);
5512
- case 22:
5720
+ case 23:
5513
5721
  requiredAmount = tempOrder.products.reduce(function (sum, item, index) {
5514
5722
  var current = index === productIndex ? normalizedProduct : item;
5515
5723
  var currentSnapshot = getSelectedSettlementSnapshot(current);
@@ -5517,44 +5725,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5517
5725
  }, new Decimal(0));
5518
5726
  balance = new Decimal(asset.balance || 0);
5519
5727
  if (!balance.lt(requiredAmount)) {
5520
- _context29.next = 26;
5728
+ _context29.next = 27;
5521
5729
  break;
5522
5730
  }
5523
5731
  throw new VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
5524
- case 26:
5732
+ case 27:
5525
5733
  tempOrder.products[productIndex] = normalizedProduct;
5526
5734
  this.prepareVirtualSettlementTempOrder(tempOrder);
5527
5735
  isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
5528
5736
  if (isVirtualSettlement) {
5529
- _context29.next = 35;
5737
+ _context29.next = 36;
5530
5738
  break;
5531
5739
  }
5532
- _context29.next = 32;
5740
+ _context29.next = 33;
5533
5741
  return this.evaluatePromotion();
5534
- case 32:
5742
+ case 33:
5535
5743
  _context29.t0 = _context29.sent;
5536
- _context29.next = 36;
5744
+ _context29.next = 37;
5537
5745
  break;
5538
- case 35:
5539
- _context29.t0 = null;
5540
5746
  case 36:
5747
+ _context29.t0 = null;
5748
+ case 37:
5541
5749
  promotionPayload = _context29.t0;
5542
5750
  if (!isVirtualSettlement) {
5543
5751
  this.applyDiscount();
5544
5752
  }
5545
5753
  this.sanitizeTempOrderProducts(tempOrder);
5546
- _context29.next = 41;
5754
+ _context29.next = 42;
5547
5755
  return this.recalculateSummary({
5548
5756
  createIfMissing: true
5549
5757
  });
5550
- case 41:
5758
+ case 42:
5551
5759
  this.persistTempOrder();
5552
5760
  this.emitPromotionApplied(promotionPayload);
5553
5761
  this.logInfo('updateOrderProductQuantity success', {
5554
5762
  params: params
5555
5763
  });
5556
5764
  return _context29.abrupt("return", tempOrder.products);
5557
- case 45:
5765
+ case 46:
5558
5766
  case "end":
5559
5767
  return _context29.stop();
5560
5768
  }
@@ -5644,7 +5852,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5644
5852
  key: "removeProductsFromOrder",
5645
5853
  value: (function () {
5646
5854
  var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(identities, options) {
5647
- var _this34 = this;
5855
+ var _this36 = this;
5648
5856
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
5649
5857
  return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5650
5858
  while (1) switch (_context32.prev = _context32.next) {
@@ -5709,7 +5917,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5709
5917
  }
5710
5918
  if (productUid !== undefined && productUid !== null && productUid !== '') {
5711
5919
  bookingsBeforeRemove.forEach(function (booking) {
5712
- var bookingUid = _this34.getBookingUniqueIdentificationNumber(booking);
5920
+ var bookingUid = _this36.getBookingUniqueIdentificationNumber(booking);
5713
5921
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
5714
5922
  linkedBookingUidsToRemove.add(bookingUid);
5715
5923
  }
@@ -5924,23 +6132,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5924
6132
  }, {
5925
6133
  key: "buildCurrentSubmitPayloadForLocalPrint",
5926
6134
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
5927
- var _params$cacheId, _this$otherParams5, _ref77, _params$businessCode, _this$otherParams6, _this$otherParams7;
6135
+ var _params$cacheId, _this$otherParams5, _ref83, _params$businessCode, _this$otherParams6, _this$otherParams7;
5928
6136
  var tempOrder = this.ensureTempOrder();
5929
6137
  this.persistTempOrder();
5930
6138
  var payload = buildSubmitPayload({
5931
6139
  tempOrder: tempOrder,
5932
6140
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
5933
6141
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
5934
- businessCode: (_ref77 = (_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 && _ref77 !== void 0 ? _ref77 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
6142
+ businessCode: (_ref83 = (_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 && _ref83 !== void 0 ? _ref83 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
5935
6143
  channel: params === null || params === void 0 ? void 0 : params.channel,
5936
6144
  type: params === null || params === void 0 ? void 0 : params.type,
5937
6145
  summary: this.store.summary || createEmptySummary(),
5938
6146
  enhance: function enhance(nextPayload) {
5939
- var _ref78, _tempOrder$order_numb, _ref79, _tempOrder$shop_order2, _ref80, _tempOrder$shop_full_;
6147
+ var _ref84, _tempOrder$order_numb, _ref85, _tempOrder$shop_order2, _ref86, _tempOrder$shop_full_;
5940
6148
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
5941
- order_number: (_ref78 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref78 !== void 0 ? _ref78 : null,
5942
- shop_order_number: (_ref79 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref79 !== void 0 ? _ref79 : null,
5943
- shop_full_order_number: (_ref80 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref80 !== void 0 ? _ref80 : null,
6149
+ order_number: (_ref84 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref84 !== void 0 ? _ref84 : null,
6150
+ shop_order_number: (_ref85 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref85 !== void 0 ? _ref85 : null,
6151
+ shop_full_order_number: (_ref86 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref86 !== void 0 ? _ref86 : null,
5944
6152
  small_ticket_data_flag: 1
5945
6153
  });
5946
6154
  }
@@ -6104,7 +6312,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6104
6312
  key: "runSubmitTempOrder",
6105
6313
  value: function () {
6106
6314
  var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
6107
- var _params$cacheId3, _this$otherParams12, _ref81, _ref82, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6315
+ var _params$cacheId3, _this$otherParams12, _ref87, _ref88, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6108
6316
  var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
6109
6317
  return _regeneratorRuntime().wrap(function _callee37$(_context40) {
6110
6318
  while (1) switch (_context40.prev = _context40.next) {
@@ -6171,7 +6379,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6171
6379
  tempOrder: tempOrder,
6172
6380
  cacheId: effectiveCacheId,
6173
6381
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
6174
- businessCode: (_ref81 = (_ref82 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref82 !== void 0 ? _ref82 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref81 !== void 0 ? _ref81 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6382
+ businessCode: (_ref87 = (_ref88 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref88 !== void 0 ? _ref88 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref87 !== void 0 ? _ref87 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6175
6383
  channel: params === null || params === void 0 ? void 0 : params.channel,
6176
6384
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
6177
6385
  summary: latestSummary,
@@ -6341,10 +6549,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6341
6549
  value: function extractSubmitErrorResponse(error) {
6342
6550
  var _error$response,
6343
6551
  _error$response2,
6344
- _this35 = this;
6552
+ _this37 = this;
6345
6553
  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];
6346
6554
  return candidates.find(function (candidate) {
6347
- return _this35.isSubmitErrorResponse(candidate);
6555
+ return _this37.isSubmitErrorResponse(candidate);
6348
6556
  }) || null;
6349
6557
  }
6350
6558
  }, {
@@ -6372,7 +6580,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6372
6580
  key: "syncPaymentsToOrder",
6373
6581
  value: function () {
6374
6582
  var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
6375
- var _this36 = this,
6583
+ var _this38 = this,
6376
6584
  _params$confirmPendin;
6377
6585
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, enhancePayload, submitParams, submitResult;
6378
6586
  return _regeneratorRuntime().wrap(function _callee39$(_context42) {
@@ -6397,7 +6605,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6397
6605
  case 9:
6398
6606
  devicePrefix = _context42.t0;
6399
6607
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
6400
- return _this36.normalizePaymentSource(payment, {
6608
+ return _this38.normalizePaymentSource(payment, {
6401
6609
  defaultPaid: false,
6402
6610
  devicePrefix: devicePrefix
6403
6611
  });
@@ -6476,7 +6684,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6476
6684
  }, {
6477
6685
  key: "createOrder",
6478
6686
  value: function createOrder(params) {
6479
- var _this37 = this;
6687
+ var _this39 = this;
6480
6688
  var order = _objectSpread({
6481
6689
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
6482
6690
  // 要从外面拿,virtual
@@ -6508,7 +6716,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6508
6716
 
6509
6717
  // 为预约补齐 holder 信息
6510
6718
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
6511
- ensureCartItemOriginHolder(item, _this37.window);
6719
+ ensureCartItemOriginHolder(item, _this39.window);
6512
6720
  }
6513
6721
 
6514
6722
  // 购物车是否为普通商品
@@ -7150,10 +7358,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7150
7358
  _step22;
7151
7359
  try {
7152
7360
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
7153
- var _product$metadata11;
7361
+ var _product$metadata13;
7154
7362
  var product = _step22.value;
7155
7363
  var productUid = getOrderCollectionUid('product', product);
7156
- 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);
7364
+ 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);
7157
7365
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
7158
7366
  continue;
7159
7367
  }
@@ -7211,7 +7419,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7211
7419
  }, {
7212
7420
  key: "normalizeTempOrderForRuntime",
7213
7421
  value: function normalizeTempOrderForRuntime(raw, options) {
7214
- var _this38 = this,
7422
+ var _this40 = this,
7215
7423
  _raw$_extend;
7216
7424
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
7217
7425
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
@@ -7236,12 +7444,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7236
7444
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
7237
7445
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
7238
7446
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
7239
- return _this38.normalizeHydratedOrderProduct(p, {
7447
+ return _this40.normalizeHydratedOrderProduct(p, {
7240
7448
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
7241
7449
  });
7242
7450
  }) : [];
7243
7451
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
7244
- var booking = _this38.normalizeHydratedBookingHolder(b || {});
7452
+ var booking = _this40.normalizeHydratedBookingHolder(b || {});
7245
7453
  return _objectSpread(_objectSpread({}, booking), {}, {
7246
7454
  is_all: normalizeBookingIsAll(booking),
7247
7455
  sub_type: normalizeBookingSubType(booking)
@@ -7291,15 +7499,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7291
7499
  _step24;
7292
7500
  try {
7293
7501
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
7294
- var _product$metadata12, _ref83, _ref84, _existed$origin, _rawProduct$metadata;
7502
+ var _product$metadata14, _ref89, _ref90, _existed$origin, _rawProduct$metadata;
7295
7503
  var _step24$value = _slicedToArray(_step24.value, 2),
7296
7504
  index = _step24$value[0],
7297
7505
  product = _step24$value[1];
7298
- var uid = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number;
7506
+ var uid = (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number;
7299
7507
  if (!uid) continue;
7300
7508
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
7301
7509
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
7302
- var origin = (_ref83 = (_ref84 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref84 !== void 0 ? _ref84 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref83 !== void 0 ? _ref83 : rawProduct;
7510
+ var origin = (_ref89 = (_ref90 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref90 !== void 0 ? _ref90 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref89 !== void 0 ? _ref89 : rawProduct;
7303
7511
  var originSnapshot = cloneDeep(origin);
7304
7512
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
7305
7513
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -7350,8 +7558,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7350
7558
  var bookingUidByProductUid = new Map();
7351
7559
  var productByUid = new Map();
7352
7560
  (tempOrder.products || []).forEach(function (product) {
7353
- var _product$metadata13;
7354
- 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);
7561
+ var _product$metadata15;
7562
+ 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);
7355
7563
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
7356
7564
  productByUid.set(String(productUid), product);
7357
7565
  }
@@ -7372,8 +7580,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7372
7580
  bookingUidByProductUid.set(String(productUid), bookingUid);
7373
7581
  });
7374
7582
  (tempOrder.products || []).forEach(function (product) {
7375
- var _product$metadata14;
7376
- 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);
7583
+ var _product$metadata16;
7584
+ 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);
7377
7585
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
7378
7586
  var bookingUid = bookingUidByProductUid.get(String(productUid));
7379
7587
  if (!bookingUid) return;
@@ -7428,10 +7636,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7428
7636
  }, {
7429
7637
  key: "normalizeHydratedProductOptionItem",
7430
7638
  value: function normalizeHydratedProductOptionItem(optionItem) {
7431
- var _ref85, _optionItem$num, _ref86, _optionItem$add_price;
7432
- var rawNum = (_ref85 = (_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 && _ref85 !== void 0 ? _ref85 : 1;
7639
+ var _ref91, _optionItem$num, _ref92, _optionItem$add_price;
7640
+ var rawNum = (_ref91 = (_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 && _ref91 !== void 0 ? _ref91 : 1;
7433
7641
  var parsedNum = Number(rawNum);
7434
- var rawPrice = (_ref86 = (_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 && _ref86 !== void 0 ? _ref86 : 0;
7642
+ var rawPrice = (_ref92 = (_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 && _ref92 !== void 0 ? _ref92 : 0;
7435
7643
  var parsedPrice = Number(rawPrice);
7436
7644
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
7437
7645
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -7448,7 +7656,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7448
7656
  }, {
7449
7657
  key: "normalizeHydratedOrderProduct",
7450
7658
  value: function normalizeHydratedOrderProduct(product, options) {
7451
- var _this39 = this;
7659
+ var _this41 = this;
7452
7660
  var row = _objectSpread({}, product || {});
7453
7661
  if (row.num === undefined && row.product_quantity !== undefined) {
7454
7662
  row.num = row.product_quantity;
@@ -7456,7 +7664,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7456
7664
  var productSku = ensureProductSku(row);
7457
7665
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
7458
7666
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
7459
- return _this39.normalizeHydratedProductOptionItem(optionItem || {});
7667
+ return _this41.normalizeHydratedProductOptionItem(optionItem || {});
7460
7668
  }))
7461
7669
  });
7462
7670
  delete row["product_".concat('option', "_item")];
@@ -7564,11 +7772,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7564
7772
  targetMap.set(discountKey, (targetMap.get(discountKey) || new Decimal(0)).plus(amount));
7565
7773
  };
7566
7774
  var addProductDiscountAmount = function addProductDiscountAmount(discount, quantity, isPersistedProduct) {
7567
- var _discount$discount3, _discount$metadata;
7775
+ var _discount$discount3, _discount$metadata2;
7568
7776
  var discountKey = ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.resource_id) || discount.id;
7569
7777
  if (discountKey == null) return;
7570
7778
  var qty = Number(quantity) || 1;
7571
- 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);
7779
+ 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);
7572
7780
  addDiscountAmount(savedMap, discountKey, amount);
7573
7781
  addDiscountAmount(isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap, discountKey, amount);
7574
7782
  };