@pisell/pisellos 2.2.260 → 2.2.261

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 (129) hide show
  1. package/dist/model/strategy/adapter/index.d.ts +0 -4
  2. package/dist/model/strategy/adapter/index.js +1 -5
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +1 -1
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
  14. package/dist/modules/Order/index.d.ts +33 -2
  15. package/dist/modules/Order/index.js +615 -288
  16. package/dist/modules/Order/types.d.ts +20 -2
  17. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  18. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  19. package/dist/modules/Order/utils.d.ts +4 -0
  20. package/dist/modules/Order/utils.js +116 -29
  21. package/dist/modules/Product/types.d.ts +0 -22
  22. package/dist/modules/ProductList/index.d.ts +1 -1
  23. package/dist/modules/ProductList/index.js +2 -4
  24. package/dist/modules/ProductList/types.d.ts +0 -2
  25. package/dist/modules/Rules/index.d.ts +4 -3
  26. package/dist/modules/Rules/index.js +42 -17
  27. package/dist/modules/Rules/types.d.ts +2 -1
  28. package/dist/modules/SalesSummary/index.d.ts +7 -3
  29. package/dist/modules/SalesSummary/index.js +67 -39
  30. package/dist/modules/SalesSummary/types.d.ts +1 -0
  31. package/dist/modules/SalesSummary/utils.js +2 -1
  32. package/dist/modules/SurchargeList/index.d.ts +6 -4
  33. package/dist/modules/SurchargeList/index.js +62 -39
  34. package/dist/modules/SurchargeList/types.d.ts +6 -2
  35. package/dist/server/index.d.ts +3 -50
  36. package/dist/server/index.js +1075 -1040
  37. package/dist/server/modules/order/index.d.ts +22 -3
  38. package/dist/server/modules/order/index.js +398 -316
  39. package/dist/server/modules/products/index.d.ts +7 -26
  40. package/dist/server/modules/products/index.js +76 -166
  41. package/dist/server/modules/products/types.d.ts +0 -14
  42. package/dist/solution/BaseSales/index.d.ts +22 -2
  43. package/dist/solution/BaseSales/index.js +995 -701
  44. package/dist/solution/BaseSales/types.d.ts +1 -0
  45. package/dist/solution/BaseSales/types.js +2 -1
  46. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +74 -29
  48. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  49. package/dist/solution/BookingByStep/index.d.ts +1 -1
  50. package/dist/solution/BookingTicket/index.d.ts +9 -1
  51. package/dist/solution/BookingTicket/index.js +153 -6
  52. package/dist/solution/BookingTicket/types.d.ts +0 -2
  53. package/dist/solution/ScanOrder/index.js +31 -20
  54. package/dist/solution/VenueBooking/index.js +30 -19
  55. package/lib/model/strategy/adapter/index.d.ts +0 -4
  56. package/lib/model/strategy/adapter/index.js +2 -13
  57. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  58. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  59. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  60. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  61. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  62. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  63. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  64. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  65. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  66. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  67. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
  68. package/lib/modules/Order/index.d.ts +33 -2
  69. package/lib/modules/Order/index.js +402 -64
  70. package/lib/modules/Order/types.d.ts +20 -2
  71. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  72. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  73. package/lib/modules/Order/utils.d.ts +4 -0
  74. package/lib/modules/Order/utils.js +90 -3
  75. package/lib/modules/Product/types.d.ts +0 -22
  76. package/lib/modules/ProductList/index.d.ts +1 -1
  77. package/lib/modules/ProductList/index.js +2 -4
  78. package/lib/modules/ProductList/types.d.ts +0 -2
  79. package/lib/modules/Rules/index.d.ts +4 -3
  80. package/lib/modules/Rules/index.js +27 -7
  81. package/lib/modules/Rules/types.d.ts +2 -1
  82. package/lib/modules/SalesSummary/index.d.ts +7 -3
  83. package/lib/modules/SalesSummary/index.js +28 -11
  84. package/lib/modules/SalesSummary/types.d.ts +1 -0
  85. package/lib/modules/SalesSummary/utils.js +2 -0
  86. package/lib/modules/SurchargeList/index.d.ts +6 -4
  87. package/lib/modules/SurchargeList/index.js +41 -21
  88. package/lib/modules/SurchargeList/types.d.ts +6 -2
  89. package/lib/server/index.d.ts +3 -50
  90. package/lib/server/index.js +244 -215
  91. package/lib/server/modules/order/index.d.ts +22 -3
  92. package/lib/server/modules/order/index.js +103 -53
  93. package/lib/server/modules/products/index.d.ts +7 -26
  94. package/lib/server/modules/products/index.js +35 -113
  95. package/lib/server/modules/products/types.d.ts +0 -14
  96. package/lib/solution/BaseSales/index.d.ts +22 -2
  97. package/lib/solution/BaseSales/index.js +246 -60
  98. package/lib/solution/BaseSales/types.d.ts +1 -0
  99. package/lib/solution/BaseSales/types.js +2 -1
  100. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  101. package/lib/solution/BaseSales/utils/cartPromotion.js +59 -16
  102. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -6
  103. package/lib/solution/BookingByStep/index.d.ts +1 -1
  104. package/lib/solution/BookingTicket/index.d.ts +9 -1
  105. package/lib/solution/BookingTicket/index.js +101 -0
  106. package/lib/solution/BookingTicket/types.d.ts +0 -2
  107. package/lib/solution/ScanOrder/index.js +8 -0
  108. package/lib/solution/VenueBooking/index.js +8 -0
  109. package/package.json +1 -1
  110. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +0 -49
  111. package/dist/model/strategy/adapter/dataVariant/adapter.js +0 -152
  112. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -87
  113. package/dist/model/strategy/adapter/dataVariant/evaluator.js +0 -755
  114. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  115. package/dist/model/strategy/adapter/dataVariant/examples.js +0 -282
  116. package/dist/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  117. package/dist/model/strategy/adapter/dataVariant/index.js +0 -4
  118. package/dist/model/strategy/adapter/dataVariant/type.d.ts +0 -146
  119. package/dist/model/strategy/adapter/dataVariant/type.js +0 -54
  120. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +0 -49
  121. package/lib/model/strategy/adapter/dataVariant/adapter.js +0 -139
  122. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +0 -87
  123. package/lib/model/strategy/adapter/dataVariant/evaluator.js +0 -564
  124. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +0 -39
  125. package/lib/model/strategy/adapter/dataVariant/examples.js +0 -295
  126. package/lib/model/strategy/adapter/dataVariant/index.d.ts +0 -4
  127. package/lib/model/strategy/adapter/dataVariant/index.js +0 -38
  128. package/lib/model/strategy/adapter/dataVariant/type.d.ts +0 -146
  129. package/lib/model/strategy/adapter/dataVariant/type.js +0 -31
@@ -3,15 +3,15 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
3
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
4
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
5
5
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
- 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."); }
8
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
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; }
11
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); } }
12
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); }); }; }
13
9
  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; }
14
10
  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; }
11
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
+ 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."); }
13
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
15
15
  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; } } }; }
16
16
  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); }
17
17
  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; }
@@ -32,12 +32,13 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
32
32
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
33
33
  import { BaseModule } from "../BaseModule";
34
34
  import { OrderHooks } from "./types";
35
- import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields } from "./utils";
35
+ import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields, resolveIsFormSubject } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import dayjs from 'dayjs';
38
38
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
39
39
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
40
40
  import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
41
+ import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
41
42
  import { DiscountModule } from "../Discount";
42
43
  import { RulesModule } from "../Rules";
43
44
  import { UnavailableReason } from "../Rules/types";
@@ -64,6 +65,23 @@ function isManualProductDiscountProduct(product) {
64
65
  return (item === null || item === void 0 ? void 0 : item.type) === 'product';
65
66
  });
66
67
  }
68
+ var ORDER_PAYMENT_STATUS_PAID = 'paid';
69
+ var ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
70
+ function isVoucherPaymentRecord(payment) {
71
+ return (payment === null || payment === void 0 ? void 0 : payment.voucher_id) !== undefined && Number(payment.voucher_id) !== 0;
72
+ }
73
+ function hasSyncedOrderPaymentRecord(payment) {
74
+ return (payment === null || payment === void 0 ? void 0 : payment.order_payment_id) !== undefined && payment.order_payment_id !== null;
75
+ }
76
+ function isPendingVoucherPaymentRecord(payment) {
77
+ return isVoucherPaymentRecord(payment) && (payment === null || payment === void 0 ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PENDING;
78
+ }
79
+ function isPaidPaymentRecord(payment) {
80
+ return (payment === null || payment === void 0 ? void 0 : payment.status) === ORDER_PAYMENT_STATUS_PAID;
81
+ }
82
+ function isCommittedVoucherPaymentRecord(payment) {
83
+ return isVoucherPaymentRecord(payment) && (payment === null || payment === void 0 ? void 0 : payment.status) !== 'voided' && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
84
+ }
67
85
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
68
86
  _inherits(OrderModule, _BaseModule);
69
87
  var _super = _createSuper(OrderModule);
@@ -108,7 +126,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
108
126
  key: "collectHydratedEditDiscounts",
109
127
  value: function collectHydratedEditDiscounts(products) {
110
128
  var discountMap = new Map();
111
- var _iterator = _createForOfIteratorHelper(products || []),
129
+ var _iterator = _createForOfIteratorHelper(expandHydratedProductsForDiscountCollection(products)),
112
130
  _step;
113
131
  try {
114
132
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -138,6 +156,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
138
156
  discount: item === null || item === void 0 ? void 0 : item.discount,
139
157
  _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
140
158
  };
159
+ var existed = discountMap.get(key);
160
+ if (existed) {
161
+ existed.amount = Number(existed.amount || 0) + amount;
162
+ existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
163
+ existed.balance = String(Number(existed.balance || 0) + amount);
164
+ existed.applicableProductDetails = [].concat(_toConsumableArray(existed.applicableProductDetails || []), [detail]);
165
+ existed.appliedProductDetails = [].concat(_toConsumableArray(existed.appliedProductDetails || []), [detail]);
166
+ continue;
167
+ }
141
168
  discountMap.set(key, {
142
169
  id: key,
143
170
  product_name: '',
@@ -224,6 +251,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
224
251
  product.metadata.main_product_selling_price = newMainSellingPrice;
225
252
  product.metadata.price_schema_version = 2;
226
253
  }
254
+ if (Array.isArray(product.product_bundle)) {
255
+ product.product_bundle = product.product_bundle.map(function (bundle) {
256
+ var _ref12, _bundle$original_pric;
257
+ var hasBundleDiscount = Array.isArray(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) && bundle.discount_list.length > 0;
258
+ if (hasBundleDiscount) return bundle;
259
+ var restoredPrice = (_ref12 = (_bundle$original_pric = bundle === null || bundle === void 0 ? void 0 : bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle === null || bundle === void 0 ? void 0 : bundle.product_price) !== null && _ref12 !== void 0 ? _ref12 : bundle === null || bundle === void 0 ? void 0 : bundle.price;
260
+ if (restoredPrice === undefined || restoredPrice === null || restoredPrice === '') return bundle;
261
+ return _objectSpread(_objectSpread({}, bundle), {}, {
262
+ price: restoredPrice,
263
+ bundle_selling_price: restoredPrice
264
+ });
265
+ });
266
+ }
227
267
  product.selling_price = composeLinePrice({
228
268
  mainPrice: newMainSellingPrice,
229
269
  bundle: product.product_bundle
@@ -553,8 +593,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
553
593
  key: "scanCode",
554
594
  value: function () {
555
595
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
556
- var _this$store$discount7, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
557
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref12, isAvailable, newDiscountList, unavailableReason, _this$store$discount8;
596
+ var _this$store$discount7, _tempOrder$holder, _this$store$summary;
597
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, unavailableReason, _this$store$discount8;
558
598
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
559
599
  while (1) switch (_context5.prev = _context5.next) {
560
600
  case 0:
@@ -624,20 +664,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
624
664
  });
625
665
  case 16:
626
666
  tempOrder = this.store.tempOrder;
627
- holders = tempOrder !== null && tempOrder !== void 0 && (_tempOrder$holder = tempOrder.holder) !== null && _tempOrder$holder !== void 0 && _tempOrder$holder.form_record_id ? [{
628
- form_record_id: tempOrder.holder.form_record_id
629
- }] : [];
630
- _ref12 = rulesModule.isDiscountListAvailable({
667
+ holders = (tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
668
+ _ref13 = rulesModule.isDiscountListAvailable({
631
669
  productList: (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products) || [],
632
670
  oldDiscountList: this.getDiscountList(),
633
671
  newDiscountList: withScanList,
634
672
  orderTotalAmount: Number(((_this$store$summary = this.store.summary) === null || _this$store$summary === void 0 ? void 0 : _this$store$summary.total_amount) || 0),
635
673
  holders: holders,
636
- isFormSubject: !!(tempOrder !== null && tempOrder !== void 0 && (_tempOrder$holder2 = tempOrder.holder) !== null && _tempOrder$holder2 !== void 0 && _tempOrder$holder2.type) && tempOrder.holder.type === 'form'
674
+ isFormSubject: function isFormSubject(product) {
675
+ return resolveIsFormSubject(tempOrder, product);
676
+ }
637
677
  }) || {
638
678
  isAvailable: false,
639
679
  discountList: this.getDiscountList()
640
- }, isAvailable = _ref12.isAvailable, newDiscountList = _ref12.discountList, unavailableReason = _ref12.unavailableReason;
680
+ }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, unavailableReason = _ref13.unavailableReason;
641
681
  if (isAvailable && newDiscountList) {
642
682
  (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(newDiscountList);
643
683
  this.applyDiscount();
@@ -664,8 +704,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
664
704
  key: "applyDiscount",
665
705
  value: function applyDiscount() {
666
706
  var _this$store$discount9,
667
- _tempOrder$holder3,
668
- _tempOrder$holder4,
707
+ _tempOrder$holder2,
669
708
  _this$store$summary2,
670
709
  _this2 = this;
671
710
  var tempOrder = this.store.tempOrder;
@@ -673,27 +712,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
673
712
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
674
713
  // appliedProductDetails / savedAmount 复位。
675
714
  if (!tempOrder) return;
715
+ this.syncLinkedBookingHoldersToProducts(tempOrder);
676
716
  delete tempOrder.discount_list;
677
- if (this.shouldSkipDiscountCalculation(tempOrder)) return;
717
+ var discountList = ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.getDiscountList()) || [];
718
+ var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
719
+ if (shouldSkipDiscountCalculation) return;
678
720
  var rulesModule = this.store.rules;
679
721
  if (!rulesModule) return;
680
- var discountList = ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.getDiscountList()) || [];
681
- var holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
682
- form_record_id: tempOrder.holder.form_record_id
683
- }] : [];
722
+ var holders = ((_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_record) || [];
684
723
  var result = rulesModule.calcDiscount({
685
724
  productList: tempOrder.products,
686
725
  discountList: discountList,
687
726
  holders: holders,
688
- isFormSubject: !!((_tempOrder$holder4 = tempOrder.holder) !== null && _tempOrder$holder4 !== void 0 && _tempOrder$holder4.type) && tempOrder.holder.type === 'form',
727
+ isFormSubject: function isFormSubject(product) {
728
+ return resolveIsFormSubject(tempOrder, product);
729
+ },
689
730
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
690
731
  });
691
732
  if (result !== null && result !== void 0 && result.productList) {
692
733
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
693
734
  tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
694
- var _ref13;
735
+ var _ref14;
695
736
  var uid = getOrderProductLineUid(product);
696
- var previous = (_ref13 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref13 !== void 0 ? _ref13 : previousProductsByUid.get("__index__:".concat(index));
737
+ var previous = (_ref14 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref14 !== void 0 ? _ref14 : previousProductsByUid.get("__index__:".concat(index));
697
738
  if (isManualProductDiscountProduct(previous)) {
698
739
  return previous;
699
740
  }
@@ -1218,15 +1259,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1218
1259
  }, {
1219
1260
  key: "extractOrderIdFromSubmitResult",
1220
1261
  value: function extractOrderIdFromSubmitResult(result) {
1221
- var _ref14, _ref15, _ref16, _result$data$order_id, _result$data, _result$data2;
1222
- return (_ref14 = (_ref15 = (_ref16 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref16 !== void 0 ? _ref16 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref15 !== void 0 ? _ref15 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref14 !== void 0 ? _ref14 : null;
1262
+ var _ref15, _ref16, _ref17, _result$data$order_id, _result$data, _result$data2;
1263
+ return (_ref15 = (_ref16 = (_ref17 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref17 !== void 0 ? _ref17 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref16 !== void 0 ? _ref16 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref15 !== void 0 ? _ref15 : null;
1223
1264
  }
1224
1265
  }, {
1225
1266
  key: "calculatePaymentEffectiveAmount",
1226
1267
  value: function calculatePaymentEffectiveAmount(payment) {
1227
- var _ref17, _payment$origin_amoun;
1268
+ var _ref18, _payment$origin_amoun;
1228
1269
  var amount = new Decimal(payment.amount || 0);
1229
- var originAmount = new Decimal((_ref17 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref17 !== void 0 ? _ref17 : 0);
1270
+ var originAmount = new Decimal((_ref18 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref18 !== void 0 ? _ref18 : 0);
1230
1271
  var serviceFee = new Decimal(payment.service_fee || 0);
1231
1272
  // TODO: 后端允许 amount 表示顾客实际支付总额后,移除这个兼容分支。
1232
1273
  var effectiveAmount = serviceFee.gt(0) && amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
@@ -1240,6 +1281,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1240
1281
  return mapPaymentItemsToOrderPayments(payments, {
1241
1282
  includeVoided: false
1242
1283
  }).reduce(function (sum, payment) {
1284
+ if (!isPaidPaymentRecord(payment)) return sum;
1243
1285
  return sum.plus(_this4.calculatePaymentEffectiveAmount(payment));
1244
1286
  }, new Decimal(0));
1245
1287
  }
@@ -1253,6 +1295,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1253
1295
  value: function normalizeDepositAmount(amount) {
1254
1296
  return Decimal.max(new Decimal(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
1255
1297
  }
1298
+ }, {
1299
+ key: "getLastOrderDepositSnapshot",
1300
+ value: function getLastOrderDepositSnapshot() {
1301
+ var _lastOrderInfo$deposi, _lastOrderInfo$summar;
1302
+ var lastOrderInfo = this.store.lastOrderInfo;
1303
+ if (!lastOrderInfo || _typeof(lastOrderInfo) !== 'object') return null;
1304
+ var rawDepositAmount = (_lastOrderInfo$deposi = lastOrderInfo.deposit_amount) !== null && _lastOrderInfo$deposi !== void 0 ? _lastOrderInfo$deposi : (_lastOrderInfo$summar = lastOrderInfo.summary) === null || _lastOrderInfo$summar === void 0 ? void 0 : _lastOrderInfo$summar.deposit_amount;
1305
+ var depositAmount = this.normalizeDepositAmount(rawDepositAmount !== null && rawDepositAmount !== void 0 ? rawDepositAmount : 0);
1306
+ var hasDepositAmount = new Decimal(depositAmount).gt(0);
1307
+ var isDeposit = Number(lastOrderInfo.is_deposit) === 1 || hasDepositAmount;
1308
+ if (!isDeposit || !hasDepositAmount) return null;
1309
+ return {
1310
+ isDeposit: 1,
1311
+ depositAmount: depositAmount
1312
+ };
1313
+ }
1314
+ }, {
1315
+ key: "getLastOrderSubmitSnapshot",
1316
+ value: function getLastOrderSubmitSnapshot() {
1317
+ var lastOrderInfo = this.store.lastOrderInfo;
1318
+ if (!lastOrderInfo || _typeof(lastOrderInfo) !== 'object') return {};
1319
+ var businessCode = lastOrderInfo.business_code;
1320
+ var type = lastOrderInfo.type;
1321
+ return _objectSpread(_objectSpread({}, typeof businessCode === 'string' && businessCode ? {
1322
+ businessCode: businessCode
1323
+ } : {}), typeof type === 'string' && type ? {
1324
+ type: type
1325
+ } : {});
1326
+ }
1256
1327
  }, {
1257
1328
  key: "applyDepositAmountToSummary",
1258
1329
  value: function applyDepositAmountToSummary(tempOrder, summary, amount) {
@@ -1271,10 +1342,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1271
1342
  tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
1272
1343
  return nextSummary;
1273
1344
  }
1345
+ }, {
1346
+ key: "applyLastOrderDepositSnapshot",
1347
+ value: function applyLastOrderDepositSnapshot(tempOrder, summary) {
1348
+ var snapshot = this.getLastOrderDepositSnapshot();
1349
+ if (!snapshot) return summary;
1350
+ var existedDeposit = summary.deposit && _typeof(summary.deposit) === 'object' ? summary.deposit : undefined;
1351
+ var nextSummary = _objectSpread(_objectSpread({}, summary), {}, {
1352
+ deposit_amount: snapshot.depositAmount,
1353
+ deposit: _objectSpread(_objectSpread({}, existedDeposit || {}), {}, {
1354
+ total: snapshot.depositAmount,
1355
+ deposit_policy_ids: (existedDeposit === null || existedDeposit === void 0 ? void 0 : existedDeposit.deposit_policy_ids) || [],
1356
+ hasDeposit: true
1357
+ })
1358
+ });
1359
+ tempOrder.deposit_amount = snapshot.depositAmount;
1360
+ tempOrder.is_deposit = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
1361
+ return nextSummary;
1362
+ }
1274
1363
  }, {
1275
1364
  key: "isDepositOrder",
1276
1365
  value: function isDepositOrder(tempOrder, depositAmount) {
1277
- return tempOrder.is_deposit === 1 || depositAmount.gt(0);
1366
+ return tempOrder.is_deposit === 1 && depositAmount.gt(0);
1278
1367
  }
1279
1368
  }, {
1280
1369
  key: "getOrderExpectedAmount",
@@ -1289,13 +1378,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1289
1378
  if (depositAmount.lte(0)) return false;
1290
1379
  return params.paidAmount.gte(depositAmount);
1291
1380
  }
1381
+ }, {
1382
+ key: "getPaymentCompletion",
1383
+ value: function getPaymentCompletion(payments) {
1384
+ var tempOrder = this.ensureTempOrder();
1385
+ var summary = this.store.summary || createEmptySummary();
1386
+ var paymentList = payments || tempOrder.payments || [];
1387
+ var refundAmount = this.getSummaryRefundAmount(summary);
1388
+ var netPaidAmount = Decimal.max(this.calculatePaymentTotal(paymentList).minus(refundAmount), 0);
1389
+ var depositAmount = this.getDepositAmount(tempOrder, summary);
1390
+ var orderExpectedAmount = this.getOrderExpectedAmount(summary);
1391
+ var isDepositFullyPaid = this.isDepositCovered({
1392
+ tempOrder: tempOrder,
1393
+ summary: summary,
1394
+ paidAmount: netPaidAmount
1395
+ });
1396
+ var isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
1397
+ var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? 'deposit' : 'normal';
1398
+ return {
1399
+ isFullyPaid: isOrderFullyPaid,
1400
+ isOrderFullyPaid: isOrderFullyPaid,
1401
+ isDepositFullyPaid: isDepositFullyPaid,
1402
+ paymentStage: paymentStage,
1403
+ depositAmount: depositAmount.toFixed(2),
1404
+ orderExpectedAmount: orderExpectedAmount.toFixed(2)
1405
+ };
1406
+ }
1292
1407
  }, {
1293
1408
  key: "calculateDepositPaidAmount",
1294
1409
  value: function calculateDepositPaidAmount(payments) {
1295
1410
  var _this5 = this;
1296
1411
  return (payments || []).reduce(function (sum, payment) {
1297
1412
  var paymentRecord = payment;
1298
- if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return sum;
1413
+ if (!isPaidPaymentRecord(paymentRecord)) return sum;
1299
1414
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1300
1415
  if (!isDepositPayment) return sum;
1301
1416
  if (paymentRecord.origin_amount !== undefined && paymentRecord.origin_amount !== null && paymentRecord.origin_amount !== '') {
@@ -1317,7 +1432,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1317
1432
  }, {
1318
1433
  key: "normalizePaymentSource",
1319
1434
  value: function normalizePaymentSource(payment, options) {
1320
- var _ref18, _paymentRecord$origin;
1435
+ var _ref19, _paymentRecord$origin;
1321
1436
  var paymentRecord = payment;
1322
1437
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1323
1438
  if (!metadata.unique_payment_number) {
@@ -1325,7 +1440,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1325
1440
  }
1326
1441
  var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1327
1442
  metadata: metadata,
1328
- origin_amount: (_ref18 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref18 !== void 0 ? _ref18 : '0.00'
1443
+ origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
1329
1444
  });
1330
1445
  if (paymentRecord.status !== undefined) {
1331
1446
  normalized.status = paymentRecord.status;
@@ -1446,7 +1561,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1446
1561
  var _this6 = this;
1447
1562
  return (payments || []).reduce(function (summary, payment) {
1448
1563
  var paymentRecord = payment;
1449
- if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return summary;
1564
+ if (!isPaidPaymentRecord(paymentRecord)) return summary;
1450
1565
  return {
1451
1566
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1452
1567
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
@@ -1658,7 +1773,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1658
1773
  _product$payment_pric,
1659
1774
  _sku$code,
1660
1775
  _sku$barcode,
1661
- _ref19,
1776
+ _ref20,
1662
1777
  _sku$variant_id,
1663
1778
  _this8 = this;
1664
1779
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
@@ -1685,24 +1800,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1685
1800
  product_sku: this.normalizeFingerprintValue({
1686
1801
  code: (_sku$code = sku.code) !== null && _sku$code !== void 0 ? _sku$code : '',
1687
1802
  barcode: (_sku$barcode = sku.barcode) !== null && _sku$barcode !== void 0 ? _sku$barcode : '',
1688
- variant_id: (_ref19 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref19 !== void 0 ? _ref19 : 0,
1803
+ variant_id: (_ref20 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref20 !== void 0 ? _ref20 : 0,
1689
1804
  variant: sku.variant || [],
1690
1805
  option: getProductSkuOptions(product || {}).map(function (option) {
1691
- var _ref20, _option$id, _option$option_group_, _ref21, _option$option_group_2, _option$num, _option$add_price;
1806
+ var _ref21, _option$id, _option$option_group_, _ref22, _option$option_group_2, _option$num, _option$add_price;
1692
1807
  return {
1693
- id: (_ref20 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref20 !== void 0 ? _ref20 : null,
1808
+ id: (_ref21 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref21 !== void 0 ? _ref21 : null,
1694
1809
  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,
1695
- option_group_item_id: (_ref21 = (_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 && _ref21 !== void 0 ? _ref21 : null,
1810
+ option_group_item_id: (_ref22 = (_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 && _ref22 !== void 0 ? _ref22 : null,
1696
1811
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1697
1812
  add_price: _this8.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)
1698
1813
  };
1699
1814
  })
1700
1815
  }),
1701
1816
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
1702
- var _ref22, _ref23, _bundle$bundle_produc, _ref24, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
1817
+ var _ref23, _ref24, _bundle$bundle_produc, _ref25, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
1703
1818
  return {
1704
- bundle_product_id: (_ref22 = (_ref23 = (_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 && _ref23 !== void 0 ? _ref23 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref22 !== void 0 ? _ref22 : null,
1705
- bundle_variant_id: (_ref24 = (_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 && _ref24 !== void 0 ? _ref24 : 0,
1819
+ bundle_product_id: (_ref23 = (_ref24 = (_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 && _ref24 !== void 0 ? _ref24 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref23 !== void 0 ? _ref23 : null,
1820
+ bundle_variant_id: (_ref25 = (_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 && _ref25 !== void 0 ? _ref25 : 0,
1706
1821
  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),
1707
1822
  price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1708
1823
  bundle_selling_price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
@@ -1711,10 +1826,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1711
1826
  };
1712
1827
  })),
1713
1828
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
1714
- var _ref25, _discount$type2, _ref26, _ref27, _discount$discount_id, _discount$discount;
1829
+ var _ref26, _discount$type2, _ref27, _ref28, _discount$discount_id, _discount$discount;
1715
1830
  return {
1716
- type: (_ref25 = (_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 && _ref25 !== void 0 ? _ref25 : '',
1717
- discount_id: (_ref26 = (_ref27 = (_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 && _ref27 !== void 0 ? _ref27 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref26 !== void 0 ? _ref26 : null,
1831
+ type: (_ref26 = (_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 && _ref26 !== void 0 ? _ref26 : '',
1832
+ discount_id: (_ref27 = (_ref28 = (_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 && _ref28 !== void 0 ? _ref28 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref27 !== void 0 ? _ref27 : null,
1718
1833
  amount: _this8.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1719
1834
  };
1720
1835
  }))
@@ -1738,14 +1853,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1738
1853
  var _product$product_id3,
1739
1854
  _product$product_vari2,
1740
1855
  _product$num2,
1741
- _ref28,
1856
+ _ref29,
1742
1857
  _metadata$unique_iden,
1743
1858
  _metadata$price_overr,
1744
1859
  _metadata$is_manual_d,
1745
1860
  _metadata$product_dis,
1746
1861
  _sku$code2,
1747
1862
  _sku$barcode2,
1748
- _ref29,
1863
+ _ref30,
1749
1864
  _sku$variant_id2,
1750
1865
  _this10 = this;
1751
1866
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
@@ -1761,7 +1876,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1761
1876
  extension_type: extensionType,
1762
1877
  num: getSafeProductNum((_product$num2 = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num2 !== void 0 ? _product$num2 : product === null || product === void 0 ? void 0 : product.product_quantity),
1763
1878
  metadata: {
1764
- unique_identification_number: (_ref28 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref28 !== void 0 ? _ref28 : '',
1879
+ unique_identification_number: (_ref29 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref29 !== void 0 ? _ref29 : '',
1765
1880
  price_override: (_metadata$price_overr = metadata.price_override) !== null && _metadata$price_overr !== void 0 ? _metadata$price_overr : '',
1766
1881
  is_manual_discount: (_metadata$is_manual_d = metadata.is_manual_discount) !== null && _metadata$is_manual_d !== void 0 ? _metadata$is_manual_d : '',
1767
1882
  product_discount_reason: (_metadata$product_dis = metadata.product_discount_reason) !== null && _metadata$product_dis !== void 0 ? _metadata$product_dis : ''
@@ -1769,35 +1884,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1769
1884
  product_sku: this.normalizeFingerprintValue({
1770
1885
  code: (_sku$code2 = sku.code) !== null && _sku$code2 !== void 0 ? _sku$code2 : '',
1771
1886
  barcode: (_sku$barcode2 = sku.barcode) !== null && _sku$barcode2 !== void 0 ? _sku$barcode2 : '',
1772
- variant_id: (_ref29 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref29 !== void 0 ? _ref29 : 0,
1887
+ variant_id: (_ref30 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref30 !== void 0 ? _ref30 : 0,
1773
1888
  variant: sku.variant || [],
1774
1889
  option: getProductSkuOptions(product || {}).map(function (option) {
1775
- var _ref30, _option$id2, _option$option_group_3, _ref31, _option$option_group_4, _option$num2, _option$add_price2;
1890
+ var _ref31, _option$id2, _option$option_group_3, _ref32, _option$option_group_4, _option$num2, _option$add_price2;
1776
1891
  return {
1777
- id: (_ref30 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref30 !== void 0 ? _ref30 : null,
1892
+ id: (_ref31 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref31 !== void 0 ? _ref31 : null,
1778
1893
  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,
1779
- option_group_item_id: (_ref31 = (_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 && _ref31 !== void 0 ? _ref31 : null,
1894
+ option_group_item_id: (_ref32 = (_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 && _ref32 !== void 0 ? _ref32 : null,
1780
1895
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
1781
1896
  add_price: _this10.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)
1782
1897
  };
1783
1898
  })
1784
1899
  }),
1785
1900
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
1786
- var _ref32, _bundle$bundle_id, _ref33, _bundle$bundle_group_, _ref34, _ref35, _bundle$bundle_produc2, _ref36, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
1901
+ var _ref33, _bundle$bundle_id, _ref34, _bundle$bundle_group_, _ref35, _ref36, _bundle$bundle_produc2, _ref37, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
1787
1902
  return {
1788
- bundle_id: (_ref32 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref32 !== void 0 ? _ref32 : null,
1789
- bundle_group_id: (_ref33 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref33 !== void 0 ? _ref33 : null,
1790
- bundle_product_id: (_ref34 = (_ref35 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref34 !== void 0 ? _ref34 : null,
1791
- bundle_variant_id: (_ref36 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref36 !== void 0 ? _ref36 : 0,
1903
+ bundle_id: (_ref33 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref33 !== void 0 ? _ref33 : null,
1904
+ bundle_group_id: (_ref34 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref34 !== void 0 ? _ref34 : null,
1905
+ bundle_product_id: (_ref35 = (_ref36 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref36 !== void 0 ? _ref36 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref35 !== void 0 ? _ref35 : null,
1906
+ bundle_variant_id: (_ref37 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref37 !== void 0 ? _ref37 : 0,
1792
1907
  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),
1793
1908
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
1794
1909
  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 : '',
1795
1910
  option: _this10.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
1796
- var _ref37, _option$id3, _option$option_group_5, _ref38, _option$option_group_6, _option$num3, _option$add_price3;
1911
+ var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
1797
1912
  return {
1798
- id: (_ref37 = (_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 && _ref37 !== void 0 ? _ref37 : null,
1913
+ id: (_ref38 = (_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 && _ref38 !== void 0 ? _ref38 : null,
1799
1914
  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,
1800
- option_group_item_id: (_ref38 = (_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 && _ref38 !== void 0 ? _ref38 : null,
1915
+ option_group_item_id: (_ref39 = (_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 && _ref39 !== void 0 ? _ref39 : null,
1801
1916
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
1802
1917
  add_price: _this10.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)
1803
1918
  };
@@ -1805,10 +1920,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1805
1920
  };
1806
1921
  })),
1807
1922
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
1808
- var _ref39, _discount$type4, _ref40, _ref41, _discount$discount_id2, _discount$discount2;
1923
+ var _ref40, _discount$type4, _ref41, _ref42, _discount$discount_id2, _discount$discount2;
1809
1924
  return {
1810
- type: (_ref39 = (_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 && _ref39 !== void 0 ? _ref39 : '',
1811
- discount_id: (_ref40 = (_ref41 = (_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 && _ref41 !== void 0 ? _ref41 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref40 !== void 0 ? _ref40 : null,
1925
+ type: (_ref40 = (_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 && _ref40 !== void 0 ? _ref40 : '',
1926
+ discount_id: (_ref41 = (_ref42 = (_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 && _ref42 !== void 0 ? _ref42 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref41 !== void 0 ? _ref41 : null,
1812
1927
  amount: _this10.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1813
1928
  };
1814
1929
  }))
@@ -1880,11 +1995,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1880
1995
  });
1881
1996
  return currentAmountGap === snapshotAmountGap;
1882
1997
  }
1998
+ }, {
1999
+ key: "hasShopDiscountChangedFromSnapshot",
2000
+ value: function hasShopDiscountChangedFromSnapshot(tempOrder, snapshot) {
2001
+ var _snapshot$shop_discou;
2002
+ var snapshotSummary = snapshot.summary && _typeof(snapshot.summary) === 'object' ? snapshot.summary : {};
2003
+ var snapshotShopDiscount = (_snapshot$shop_discou = snapshot.shop_discount) !== null && _snapshot$shop_discou !== void 0 ? _snapshot$shop_discou : snapshotSummary.shop_discount;
2004
+ if (snapshotShopDiscount === undefined || snapshotShopDiscount === null || snapshotShopDiscount === '') {
2005
+ return !new Decimal(tempOrder.shop_discount || 0).equals(0);
2006
+ }
2007
+ return !new Decimal(tempOrder.shop_discount || 0).equals(snapshotShopDiscount || 0);
2008
+ }
1883
2009
  }, {
1884
2010
  key: "restoreOriginalSnapshotIfProductsUnchanged",
1885
- value: function restoreOriginalSnapshotIfProductsUnchanged(tempOrder) {
1886
- var snapshot = this.getOriginalSalesSnapshot(tempOrder);
1887
- if (!snapshot) return null;
2011
+ value: function restoreOriginalSnapshotIfProductsUnchanged(tempOrder, snapshot) {
1888
2012
  var currentFingerprint = this.buildOrderProductsFingerprint(tempOrder.products);
1889
2013
  if (currentFingerprint !== snapshot.productFingerprint) {
1890
2014
  var currentStructuralFingerprint = this.buildOrderProductsStructuralFingerprint(tempOrder.products);
@@ -2015,6 +2139,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2015
2139
  key: "restoreOrder",
2016
2140
  value: function restoreOrder() {
2017
2141
  var _this$store$discount11, _this$store$discount12;
2142
+ this.logInfo('restoreOrder start', {});
2018
2143
  var freshTempOrder = this.createDefaultTempOrderInstance();
2019
2144
  this.ensureExternalSaleNumber(freshTempOrder);
2020
2145
  this.store.tempOrder = freshTempOrder;
@@ -2088,11 +2213,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2088
2213
  }, {
2089
2214
  key: "getOrderIdentity",
2090
2215
  value: function getOrderIdentity() {
2091
- var _ref42, _ref43, _tempOrder$order_id, _tempOrder$_extend6;
2216
+ var _ref43, _ref44, _tempOrder$order_id, _tempOrder$_extend6;
2092
2217
  var tempOrder = this.store.tempOrder;
2093
2218
  if (!tempOrder) return null;
2094
2219
  var lastOrderInfo = this.store.lastOrderInfo || {};
2095
- var orderId = (_ref42 = (_ref43 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref43 !== void 0 ? _ref43 : lastOrderInfo.id) !== null && _ref42 !== void 0 ? _ref42 : null;
2220
+ var orderId = (_ref43 = (_ref44 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref44 !== void 0 ? _ref44 : lastOrderInfo.id) !== null && _ref43 !== void 0 ? _ref43 : null;
2096
2221
  return {
2097
2222
  localId: this.cacheId || ((_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.localId),
2098
2223
  orderId: orderId,
@@ -2127,7 +2252,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2127
2252
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
2128
2253
  });
2129
2254
  return {
2130
- isDeposit: tempOrder.is_deposit === 1 || depositAmount !== '0.00',
2255
+ isDeposit: tempOrder.is_deposit === 1,
2131
2256
  depositAmount: depositAmount,
2132
2257
  expectAmount: summary.expect_amount || '0.00',
2133
2258
  totalAmount: summary.total_amount || '0.00',
@@ -2245,11 +2370,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2245
2370
  }, {
2246
2371
  key: "captureProductRuntime",
2247
2372
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
2248
- var _extend$productsByUid, _ref44, _rawProduct$_origin;
2373
+ var _extend$productsByUid, _ref45, _rawProduct$_origin;
2249
2374
  var uid = existedUid || this.getProductUid(normalizedProduct);
2250
2375
  var extend = this.ensureExtend(tempOrder);
2251
2376
  var existed = ((_extend$productsByUid = extend.productsByUid) === null || _extend$productsByUid === void 0 ? void 0 : _extend$productsByUid[uid]) || {};
2252
- var origin = (_ref44 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref44 !== void 0 ? _ref44 : existed.origin;
2377
+ var origin = (_ref45 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref45 !== void 0 ? _ref45 : existed.origin;
2253
2378
  extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
2254
2379
  origin: origin
2255
2380
  } : {});
@@ -2316,6 +2441,48 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2316
2441
  return record !== undefined && record !== null && record !== '';
2317
2442
  });
2318
2443
  }
2444
+ }, {
2445
+ key: "setProductHolderFromBooking",
2446
+ value: function setProductHolderFromBooking(product, booking) {
2447
+ if (!product || !booking) return;
2448
+ var holderRecords = this.collectBookingHolderRecords(booking);
2449
+ if (!product.metadata || _typeof(product.metadata) !== 'object') {
2450
+ product.metadata = {};
2451
+ }
2452
+ product.metadata.holder_id = holderRecords.length > 0 ? holderRecords : null;
2453
+ }
2454
+ }, {
2455
+ key: "syncLinkedBookingHoldersToProducts",
2456
+ value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2457
+ var _this13 = this;
2458
+ var bookings = tempOrder.bookings || [];
2459
+ var products = tempOrder.products || [];
2460
+ if (!bookings.length || !products.length) return;
2461
+ var bookingByProductUid = new Map();
2462
+ var bookingByBookingUid = new Map();
2463
+ bookings.forEach(function (booking) {
2464
+ var _booking$metadata2, _booking$metadata3;
2465
+ if (!booking || _typeof(booking) !== 'object') return;
2466
+ var productUid = booking.product_uid || ((_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.product_uid);
2467
+ if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
2468
+ bookingByProductUid.set(String(productUid), booking);
2469
+ }
2470
+ var bookingUid = ((_booking$metadata3 = booking.metadata) === null || _booking$metadata3 === void 0 ? void 0 : _booking$metadata3.unique_identification_number) || booking.booking_uid;
2471
+ if (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '') {
2472
+ bookingByBookingUid.set(String(bookingUid), booking);
2473
+ }
2474
+ });
2475
+ products.forEach(function (product) {
2476
+ var _product$metadata5, _product$metadata6;
2477
+ if (!product || _typeof(product) !== 'object') return;
2478
+ var productUid = ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || product.unique_identification_number;
2479
+ var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2480
+ var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2481
+ if (linkedBooking) {
2482
+ _this13.setProductHolderFromBooking(product, linkedBooking);
2483
+ }
2484
+ });
2485
+ }
2319
2486
 
2320
2487
  /**
2321
2488
  * 按 form_record 顺序读取 booking holder 的主字段名称。
@@ -2350,7 +2517,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2350
2517
  }, {
2351
2518
  key: "buildTempOrderHolderFromBookings",
2352
2519
  value: function buildTempOrderHolderFromBookings(tempOrder) {
2353
- var _baseHolder$customer_, _baseHolder, _ref45, _baseHolder$form_id, _baseHolder2, _tempOrder$holder5, _baseHolder3, _this$otherParams;
2520
+ var _baseHolder$customer_, _baseHolder, _ref46, _baseHolder$form_id, _baseHolder2, _tempOrder$holder3, _baseHolder3, _this$otherParams;
2354
2521
  var holderRecords = [];
2355
2522
  var holderNames = [];
2356
2523
  var baseHolder = null;
@@ -2397,7 +2564,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2397
2564
  }
2398
2565
  var nextHolder = {
2399
2566
  customer_id: (_baseHolder$customer_ = (_baseHolder = baseHolder) === null || _baseHolder === void 0 ? void 0 : _baseHolder.customer_id) !== null && _baseHolder$customer_ !== void 0 ? _baseHolder$customer_ : tempOrder.customer_id,
2400
- form_id: (_ref45 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder5 = tempOrder.holder) === null || _tempOrder$holder5 === void 0 ? void 0 : _tempOrder$holder5.form_id) !== null && _ref45 !== void 0 ? _ref45 : 0,
2567
+ form_id: (_ref46 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder3 = tempOrder.holder) === null || _tempOrder$holder3 === void 0 ? void 0 : _tempOrder$holder3.form_id) !== null && _ref46 !== void 0 ? _ref46 : 0,
2401
2568
  form_record: holderRecords
2402
2569
  };
2403
2570
  if (holderNames.length) {
@@ -2420,41 +2587,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2420
2587
  value: function syncTempOrderHolderFromBookings(tempOrder) {
2421
2588
  var bookings = tempOrder.bookings || [];
2422
2589
  var hasHolderSource = bookings.some(function (booking) {
2423
- var _booking$metadata2;
2424
- return (booking === null || booking === void 0 ? void 0 : booking.holder) !== undefined || (booking === null || booking === void 0 || (_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.holder_id) !== undefined;
2590
+ var _booking$metadata4;
2591
+ return (booking === null || booking === void 0 ? void 0 : booking.holder) !== undefined || (booking === null || booking === void 0 || (_booking$metadata4 = booking.metadata) === null || _booking$metadata4 === void 0 ? void 0 : _booking$metadata4.holder_id) !== undefined;
2425
2592
  });
2426
2593
  var nextHolder = this.buildTempOrderHolderFromBookings(tempOrder);
2427
2594
  if (nextHolder || hasHolderSource || bookings.length === 0) {
2428
2595
  tempOrder.holder = nextHolder;
2429
2596
  }
2597
+ this.syncLinkedBookingHoldersToProducts(tempOrder);
2430
2598
  }
2431
2599
  }, {
2432
2600
  key: "getBookingUniqueIdentificationNumber",
2433
2601
  value: function getBookingUniqueIdentificationNumber(booking) {
2434
- var _booking$metadata3;
2435
- var uid = booking === null || booking === void 0 || (_booking$metadata3 = booking.metadata) === null || _booking$metadata3 === void 0 ? void 0 : _booking$metadata3.unique_identification_number;
2602
+ var _booking$metadata5;
2603
+ var uid = booking === null || booking === void 0 || (_booking$metadata5 = booking.metadata) === null || _booking$metadata5 === void 0 ? void 0 : _booking$metadata5.unique_identification_number;
2436
2604
  if (uid === undefined || uid === null || uid === '') return null;
2437
2605
  return String(uid);
2438
2606
  }
2439
2607
  }, {
2440
2608
  key: "findBookingIndexByUniqueIdentificationNumber",
2441
2609
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2442
- var _this13 = this;
2610
+ var _this14 = this;
2443
2611
  return (tempOrder.bookings || []).findIndex(function (booking) {
2444
- return _this13.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2612
+ return _this14.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2445
2613
  });
2446
2614
  }
2447
2615
  }, {
2448
2616
  key: "removeLinkedBookingsForProduct",
2449
2617
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2450
- var _product$metadata5,
2451
- _product$metadata6,
2452
- _this14 = this;
2453
- 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);
2454
- 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);
2618
+ var _product$metadata7,
2619
+ _product$metadata8,
2620
+ _this15 = this;
2621
+ var productUid = (product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2622
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_uid);
2455
2623
  if (!productUid && !bookingUid) return;
2456
2624
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2457
- var currentBookingUid = _this14.getBookingUniqueIdentificationNumber(booking);
2625
+ var currentBookingUid = _this15.getBookingUniqueIdentificationNumber(booking);
2458
2626
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2459
2627
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2460
2628
  return true;
@@ -2492,16 +2660,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2492
2660
  hasDeposit: true
2493
2661
  } : undefined
2494
2662
  });
2663
+ var isExistingDepositDisabled = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0);
2495
2664
  tempOrder.deposit_amount = depositAmount;
2496
- tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
2497
- return nextSummary;
2665
+ tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
2666
+ return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
2498
2667
  }
2499
2668
  }, {
2500
2669
  key: "recalculateSummary",
2501
2670
  value: function () {
2502
2671
  var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(options) {
2503
- var _ref46, _salesSummaryResult$e;
2504
- var tempOrder, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
2672
+ var _this$otherParams2, _ref47, _salesSummaryResult$e;
2673
+ var tempOrder, originalSnapshot, hasShopDiscountChanged, shouldReuseOriginalSnapshot, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
2505
2674
  return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2506
2675
  while (1) switch (_context13.prev = _context13.next) {
2507
2676
  case 0:
@@ -2513,14 +2682,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2513
2682
  return _context13.abrupt("return", null);
2514
2683
  case 3:
2515
2684
  this.sanitizeTempOrderProducts(tempOrder);
2516
- snapshotSummary = this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder);
2685
+ originalSnapshot = this.getOriginalSalesSnapshot(tempOrder);
2686
+ hasShopDiscountChanged = originalSnapshot ? this.hasShopDiscountChangedFromSnapshot(tempOrder, originalSnapshot) : false;
2687
+ shouldReuseOriginalSnapshot = originalSnapshot && !hasShopDiscountChanged;
2688
+ snapshotSummary = shouldReuseOriginalSnapshot ? this.restoreOriginalSnapshotIfProductsUnchanged(tempOrder, originalSnapshot) : null;
2517
2689
  if (!snapshotSummary) {
2518
- _context13.next = 7;
2690
+ _context13.next = 10;
2519
2691
  break;
2520
2692
  }
2521
2693
  return _context13.abrupt("return", snapshotSummary);
2522
- case 7:
2523
- shouldFullRecalculateFromSnapshot = Boolean(this.getOriginalSalesSnapshot(tempOrder));
2694
+ case 10:
2695
+ shouldFullRecalculateFromSnapshot = Boolean(originalSnapshot);
2524
2696
  summaryProducts = shouldFullRecalculateFromSnapshot ? cloneDeep(tempOrder.products || []) : tempOrder.products;
2525
2697
  if (shouldFullRecalculateFromSnapshot) {
2526
2698
  this.clearPersistedAmountFieldsForFullRecalc(summaryProducts || []);
@@ -2530,7 +2702,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2530
2702
  totalRefundAmount = existedSummary.total_refund_amount || '0.00';
2531
2703
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
2532
2704
  if (salesSummary) {
2533
- _context13.next = 23;
2705
+ _context13.next = 26;
2534
2706
  break;
2535
2707
  }
2536
2708
  emptyBaseSummary = _objectSpread(_objectSpread(_objectSpread({}, createEmptySummary()), existedSummary), {}, {
@@ -2557,14 +2729,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2557
2729
  summary: emptySummary
2558
2730
  });
2559
2731
  return _context13.abrupt("return", this.store.summary);
2560
- case 23:
2561
- _context13.next = 25;
2562
- return salesSummary.getSummary({
2732
+ case 26:
2733
+ _context13.next = 28;
2734
+ return salesSummary.getSummary(_objectSpread({
2563
2735
  products: summaryProducts,
2564
2736
  isPriceIncludeTax: tempOrder.is_price_include_tax,
2565
2737
  shopDiscount: tempOrder.shop_discount
2566
- });
2567
- case 25:
2738
+ }, (_this$otherParams2 = this.otherParams) !== null && _this$otherParams2 !== void 0 && _this$otherParams2.channel ? {
2739
+ channel: this.otherParams.channel
2740
+ } : {}));
2741
+ case 28:
2568
2742
  salesSummaryResult = _context13.sent;
2569
2743
  if (shouldFullRecalculateFromSnapshot) {
2570
2744
  tempOrder.products = summaryProducts;
@@ -2573,7 +2747,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2573
2747
  roundingAmount = paidPaymentSummary.roundingAmount;
2574
2748
  payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
2575
2749
  hasSalesSummaryAmount = salesSummaryResult.expect_amount !== undefined || salesSummaryResult.total_amount !== undefined;
2576
- expectAmount = hasSalesSummaryAmount ? new Decimal((_ref46 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref46 !== void 0 ? _ref46 : 0) : null;
2750
+ expectAmount = hasSalesSummaryAmount ? new Decimal((_ref47 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref47 !== void 0 ? _ref47 : 0) : null;
2577
2751
  amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? _objectSpread({
2578
2752
  rounding_amount: roundingAmount.toFixed(2)
2579
2753
  }, expectAmount ? {
@@ -2611,7 +2785,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2611
2785
  summary: summary
2612
2786
  });
2613
2787
  return _context13.abrupt("return", this.store.summary);
2614
- case 43:
2788
+ case 46:
2615
2789
  case "end":
2616
2790
  return _context13.stop();
2617
2791
  }
@@ -2751,17 +2925,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2751
2925
  }, {
2752
2926
  key: "buildTempOrderCustomer",
2753
2927
  value: function buildTempOrderCustomer(params) {
2754
- var _ref47, _ref48, _ref49, _source$name, _ref50, _ref51, _ref52, _source$customer_name, _source$id, _source$customer_id, _ref53, _source$country_calli, _source$phone, _source$email;
2928
+ var _ref48, _ref49, _ref50, _source$name, _ref51, _ref52, _ref53, _source$customer_name, _source$id, _source$customer_id, _ref54, _source$country_calli, _source$phone, _source$email;
2755
2929
  if (!params.customerId) return null;
2756
2930
  var source = params.source ? cloneDeep(params.source) : {};
2757
- var name = (_ref47 = (_ref48 = (_ref49 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref49 !== void 0 ? _ref49 : source.customerName) !== null && _ref48 !== void 0 ? _ref48 : source.customer_name) !== null && _ref47 !== void 0 ? _ref47 : params.customerName;
2758
- var customerName = (_ref50 = (_ref51 = (_ref52 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref52 !== void 0 ? _ref52 : source.display_name) !== null && _ref51 !== void 0 ? _ref51 : source.name) !== null && _ref50 !== void 0 ? _ref50 : params.customerName;
2931
+ var name = (_ref48 = (_ref49 = (_ref50 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref50 !== void 0 ? _ref50 : source.customerName) !== null && _ref49 !== void 0 ? _ref49 : source.customer_name) !== null && _ref48 !== void 0 ? _ref48 : params.customerName;
2932
+ var customerName = (_ref51 = (_ref52 = (_ref53 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref53 !== void 0 ? _ref53 : source.display_name) !== null && _ref52 !== void 0 ? _ref52 : source.name) !== null && _ref51 !== void 0 ? _ref51 : params.customerName;
2759
2933
  return _objectSpread(_objectSpread({}, source), {}, {
2760
2934
  id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
2761
2935
  customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
2762
2936
  name: String(name || ''),
2763
2937
  customer_name: String(customerName || ''),
2764
- country_calling_code: String((_ref53 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref53 !== void 0 ? _ref53 : params.countryCallingCode),
2938
+ country_calling_code: String((_ref54 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref54 !== void 0 ? _ref54 : params.countryCallingCode),
2765
2939
  phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
2766
2940
  email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
2767
2941
  });
@@ -2776,15 +2950,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2776
2950
  }, {
2777
2951
  key: "productHasCustomerBoundDiscount",
2778
2952
  value: function productHasCustomerBoundDiscount(product) {
2779
- var _this15 = this;
2953
+ var _this16 = this;
2780
2954
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
2781
- return _this15.isCustomerBoundDiscount(discount);
2955
+ return _this16.isCustomerBoundDiscount(discount);
2782
2956
  })) {
2783
2957
  return true;
2784
2958
  }
2785
2959
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
2786
2960
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
2787
- return _this15.isCustomerBoundDiscount(discount);
2961
+ return _this16.isCustomerBoundDiscount(discount);
2788
2962
  });
2789
2963
  });
2790
2964
  }
@@ -2793,18 +2967,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2793
2967
  value: function shouldSkipDiscountCalculation(tempOrder) {
2794
2968
  var _this$store$discount13,
2795
2969
  _this$store$discount14,
2796
- _this16 = this;
2970
+ _this17 = this;
2797
2971
  if (this.hasActiveCustomerBoundDiscount) return false;
2798
2972
  var discountList = ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 || (_this$store$discount14 = _this$store$discount13.getDiscountList) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.call(_this$store$discount13)) || [];
2799
2973
  if (discountList.length > 0) return false;
2800
2974
  return !(tempOrder.products || []).some(function (product) {
2801
- return _this16.productHasCustomerBoundDiscount(product);
2975
+ return _this17.productHasCustomerBoundDiscount(product);
2802
2976
  });
2803
2977
  }
2804
2978
  }, {
2805
2979
  key: "clearCustomerBoundDiscounts",
2806
2980
  value: function clearCustomerBoundDiscounts(tempOrder) {
2807
- var _this17 = this,
2981
+ var _this18 = this,
2808
2982
  _discountModule$getDi,
2809
2983
  _discountModule$getOr,
2810
2984
  _discountModule$setDi,
@@ -2813,7 +2987,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2813
2987
  var filterDiscountList = function filterDiscountList(discountList) {
2814
2988
  if (!Array.isArray(discountList)) return [];
2815
2989
  return discountList.filter(function (discount) {
2816
- var shouldRemove = _this17.isCustomerBoundDiscount(discount);
2990
+ var shouldRemove = _this18.isCustomerBoundDiscount(discount);
2817
2991
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
2818
2992
  return !shouldRemove;
2819
2993
  });
@@ -2841,11 +3015,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2841
3015
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
2842
3016
  var nextDiscounts = currentDiscounts.filter(function (discount) {
2843
3017
  if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
2844
- return !_this17.isCustomerBoundDiscount(discount);
3018
+ return !_this18.isCustomerBoundDiscount(discount);
2845
3019
  });
2846
3020
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
2847
3021
  if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
2848
- return !_this17.isCustomerBoundDiscount(discount);
3022
+ return !_this18.isCustomerBoundDiscount(discount);
2849
3023
  });
2850
3024
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
2851
3025
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -2860,14 +3034,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2860
3034
  }, {
2861
3035
  key: "updateTempOrderCustomer",
2862
3036
  value: function updateTempOrderCustomer(customer) {
2863
- var _tempOrder$customer_i2, _ref54, _ref55, _customer$customer_id, _ref56, _ref57, _ref58, _customer$customer_na, _ref59, _customer$country_cal, _tempOrder$customer_i3;
3037
+ var _tempOrder$customer_i2, _ref55, _ref56, _customer$customer_id, _ref57, _ref58, _ref59, _customer$customer_na, _ref60, _customer$country_cal, _tempOrder$customer_i3;
2864
3038
  var tempOrder = this.ensureTempOrder();
2865
3039
  var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
2866
- var customerId = (_ref54 = (_ref55 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref55 !== void 0 ? _ref55 : customer.id) !== null && _ref54 !== void 0 ? _ref54 : null;
2867
- var customerName = (_ref56 = (_ref57 = (_ref58 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref58 !== void 0 ? _ref58 : customer.display_name) !== null && _ref57 !== void 0 ? _ref57 : customer.name) !== null && _ref56 !== void 0 ? _ref56 : '';
3040
+ var customerId = (_ref55 = (_ref56 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref56 !== void 0 ? _ref56 : customer.id) !== null && _ref55 !== void 0 ? _ref55 : null;
3041
+ var customerName = (_ref57 = (_ref58 = (_ref59 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref59 !== void 0 ? _ref59 : customer.display_name) !== null && _ref58 !== void 0 ? _ref58 : customer.name) !== null && _ref57 !== void 0 ? _ref57 : '';
2868
3042
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
2869
3043
  tempOrder.customer_name = String(customerName || '');
2870
- tempOrder.country_calling_code = String((_ref59 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref59 !== void 0 ? _ref59 : '');
3044
+ tempOrder.country_calling_code = String((_ref60 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref60 !== void 0 ? _ref60 : '');
2871
3045
  tempOrder.phone = String(customer.phone || '');
2872
3046
  tempOrder.email = String(customer.email || '');
2873
3047
  tempOrder.customer = this.buildTempOrderCustomer({
@@ -2918,6 +3092,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2918
3092
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
2919
3093
  clearTempOrderHolderAssignments(tempOrder);
2920
3094
  this.clearCustomerBoundDiscounts(tempOrder);
3095
+ this.applyDiscount();
2921
3096
  }
2922
3097
  this.persistTempOrder();
2923
3098
  this.saveDraftInBackground();
@@ -3012,7 +3187,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3012
3187
  }, {
3013
3188
  key: "addOrderPayment",
3014
3189
  value: function addOrderPayment(payment) {
3015
- var _this18 = this;
3190
+ var _this19 = this;
3016
3191
  this.logInfo('addOrderPayment', {
3017
3192
  payment: payment
3018
3193
  });
@@ -3029,7 +3204,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3029
3204
  void this.recalculateSummary({
3030
3205
  createIfMissing: true
3031
3206
  }).catch(function (error) {
3032
- _this18.logError('recalculate summary after addOrderPayment failed', {
3207
+ _this19.logError('recalculate summary after addOrderPayment failed', {
3033
3208
  error: error instanceof Error ? error.message : String(error)
3034
3209
  });
3035
3210
  });
@@ -3084,6 +3259,77 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3084
3259
  this.persistTempOrder();
3085
3260
  return tempOrder.payments;
3086
3261
  }
3262
+ }, {
3263
+ key: "confirmPendingVoucherPaymentsInList",
3264
+ value: function confirmPendingVoucherPaymentsInList(payments) {
3265
+ return (payments || []).map(function (payment) {
3266
+ if (!isPendingVoucherPaymentRecord(payment)) return payment;
3267
+ return _objectSpread(_objectSpread({}, payment), {}, {
3268
+ status: ORDER_PAYMENT_STATUS_PAID
3269
+ });
3270
+ });
3271
+ }
3272
+ }, {
3273
+ key: "discardPendingVoucherPaymentsFromList",
3274
+ value: function discardPendingVoucherPaymentsFromList(payments) {
3275
+ return (payments || []).filter(function (payment) {
3276
+ return !isPendingVoucherPaymentRecord(payment);
3277
+ });
3278
+ }
3279
+ }, {
3280
+ key: "prepareVoucherPaymentsForSubmit",
3281
+ value: function prepareVoucherPaymentsForSubmit(payments) {
3282
+ var confirmPendingVoucherPayments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3283
+ var mappedPayments = mapPaymentItemsToOrderPayments(payments || []);
3284
+ return confirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : this.discardPendingVoucherPaymentsFromList(mappedPayments);
3285
+ }
3286
+ }, {
3287
+ key: "applyPaymentLifecycleChange",
3288
+ value: function applyPaymentLifecycleChange(tempOrder, options) {
3289
+ var _this20 = this;
3290
+ this.updateTempOrderPaymentStatus(tempOrder);
3291
+ if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3292
+ this.persistTempOrder();
3293
+ }
3294
+ if ((options === null || options === void 0 ? void 0 : options.recalculateSummary) === false) return;
3295
+ var logContext = (options === null || options === void 0 ? void 0 : options.logContext) || 'payment lifecycle change';
3296
+ void this.recalculateSummary({
3297
+ createIfMissing: true
3298
+ }).catch(function (error) {
3299
+ _this20.logError("recalculate summary after ".concat(logContext, " failed"), {
3300
+ error: error instanceof Error ? error.message : String(error)
3301
+ });
3302
+ });
3303
+ }
3304
+ }, {
3305
+ key: "confirmPendingVoucherPayments",
3306
+ value: function confirmPendingVoucherPayments(options) {
3307
+ var tempOrder = this.ensureTempOrder();
3308
+ var payments = tempOrder.payments || [];
3309
+ var hasPendingVoucher = payments.some(function (payment) {
3310
+ return isPendingVoucherPaymentRecord(payment);
3311
+ });
3312
+ if (!hasPendingVoucher) return payments;
3313
+ tempOrder.payments = this.confirmPendingVoucherPaymentsInList(payments);
3314
+ this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
3315
+ logContext: 'confirmPendingVoucherPayments'
3316
+ }));
3317
+ // this.recalculateSummary();
3318
+ return tempOrder.payments;
3319
+ }
3320
+ }, {
3321
+ key: "discardPendingVoucherPayments",
3322
+ value: function discardPendingVoucherPayments(options) {
3323
+ var tempOrder = this.ensureTempOrder();
3324
+ var payments = tempOrder.payments || [];
3325
+ var nextPayments = this.discardPendingVoucherPaymentsFromList(payments);
3326
+ if (nextPayments.length === payments.length) return payments;
3327
+ tempOrder.payments = nextPayments;
3328
+ this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
3329
+ logContext: 'discardPendingVoucherPayments'
3330
+ }));
3331
+ return tempOrder.payments;
3332
+ }
3087
3333
 
3088
3334
  /**
3089
3335
  * 覆盖当前订单中的 wallet pass 支付项。
@@ -3093,58 +3339,92 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3093
3339
  */
3094
3340
  }, {
3095
3341
  key: "updateVoucherOrderPayments",
3096
- value: function updateVoucherOrderPayments(payments) {
3097
- var _this19 = this;
3342
+ value: function updateVoucherOrderPayments(payments, options) {
3343
+ var _this21 = this;
3098
3344
  var tempOrder = this.ensureTempOrder();
3099
- var isVoucherPayment = function isVoucherPayment(payment) {
3100
- return payment.voucher_id !== undefined && Number(payment.voucher_id) !== 0;
3345
+ var isOrderPaymentType = function isOrderPaymentType(value) {
3346
+ return value === 'normal' || value === 'deposit';
3347
+ };
3348
+ var voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
3349
+ var withVoucherPaymentType = function withVoucherPaymentType(payment) {
3350
+ var paymentRecord = payment;
3351
+ if (!isVoucherPaymentRecord(paymentRecord)) return payment;
3352
+ var explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : undefined;
3353
+ var nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
3354
+ var shouldPreserveCustomPaymentType = paymentRecord.custom_payment_type === undefined && paymentRecord.type !== undefined && !isOrderPaymentType(paymentRecord.type);
3355
+ return _objectSpread(_objectSpread(_objectSpread({}, paymentRecord), shouldPreserveCustomPaymentType ? {
3356
+ custom_payment_type: paymentRecord.type
3357
+ } : {}), {}, {
3358
+ type: nextPaymentType,
3359
+ order_payment_type: nextPaymentType
3360
+ });
3101
3361
  };
3102
- var hasSyncedOrderPayment = function hasSyncedOrderPayment(payment) {
3103
- return payment.order_payment_id !== undefined && payment.order_payment_id !== null;
3362
+ var normalizeVoucherPaymentStatus = function normalizeVoucherPaymentStatus(payment) {
3363
+ var paymentRecord = payment;
3364
+ if (!isVoucherPaymentRecord(paymentRecord)) return payment;
3365
+ if (hasSyncedOrderPaymentRecord(paymentRecord) && (paymentRecord.status === undefined || paymentRecord.status === 'active')) {
3366
+ return _objectSpread(_objectSpread({}, paymentRecord), {}, {
3367
+ status: ORDER_PAYMENT_STATUS_PAID
3368
+ });
3369
+ }
3370
+ if (paymentRecord.status !== undefined && paymentRecord.status !== 'active') {
3371
+ return payment;
3372
+ }
3373
+ return _objectSpread(_objectSpread({}, paymentRecord), {}, {
3374
+ status: (options === null || options === void 0 ? void 0 : options.status) || ORDER_PAYMENT_STATUS_PENDING
3375
+ });
3104
3376
  };
3105
- // const normalizeVoucherPaymentStatus = (payment: OrderPaymentSource): OrderPaymentSource => {
3106
- // const paymentRecord = payment as Record<string, any>;
3107
- // // if (paymentRecord.status !== 'active') return payment;
3108
- // // return {
3109
- // // ...paymentRecord,
3110
- // // status: 'paid',
3111
- // // };
3112
- // if (paymentRecord.status === 'active') {
3113
- // paymentRecord.status = 'paid'
3114
- // }
3115
- // return paymentRecord
3116
- // };
3117
3377
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3118
- return _this19.normalizePaymentSource(payment, {
3119
- defaultPaid: true
3378
+ return _this21.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3379
+ defaultPaid: false
3120
3380
  });
3121
3381
  })).filter(function (payment) {
3122
- return isVoucherPayment(payment);
3382
+ return isVoucherPaymentRecord(payment);
3123
3383
  });
3124
3384
  var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3125
- return !isVoucherPayment(payment);
3385
+ return !isVoucherPaymentRecord(payment);
3126
3386
  });
3127
- var syncedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3128
- return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
3387
+ var normalizeCommittedVoucherPayment = function normalizeCommittedVoucherPayment(payment) {
3388
+ if (hasSyncedOrderPaymentRecord(payment) && (payment.status === undefined || payment.status === 'active')) {
3389
+ return _objectSpread(_objectSpread({}, payment), {}, {
3390
+ status: ORDER_PAYMENT_STATUS_PAID
3391
+ });
3392
+ }
3393
+ return payment;
3394
+ };
3395
+ var committedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3396
+ return isCommittedVoucherPaymentRecord(payment);
3397
+ }).map(function (payment) {
3398
+ return normalizeCommittedVoucherPayment(payment);
3129
3399
  });
3130
- var syncedVoucherPaymentIds = new Set(syncedVoucherPayments.map(function (payment) {
3400
+ var committedVoucherPaymentIds = new Set(committedVoucherPayments.filter(function (payment) {
3401
+ return hasSyncedOrderPaymentRecord(payment);
3402
+ }).map(function (payment) {
3131
3403
  return String(payment.order_payment_id);
3132
3404
  }));
3405
+ var committedVoucherIds = new Set(committedVoucherPayments.map(function (payment) {
3406
+ return String(payment.voucher_id);
3407
+ }));
3133
3408
  var replaceableVouchers = mappedVouchers.filter(function (payment) {
3134
- if (!hasSyncedOrderPayment(payment)) return true;
3135
- return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
3409
+ if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
3410
+ return false;
3411
+ }
3412
+ if (payment.voucher_id !== undefined && committedVoucherIds.has(String(payment.voucher_id))) {
3413
+ return false;
3414
+ }
3415
+ return true;
3136
3416
  });
3137
3417
  var cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
3138
3418
  vouchers: replaceableVouchers,
3139
- nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments))
3419
+ nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments))
3140
3420
  });
3141
- tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments), _toConsumableArray(cappedVouchers));
3421
+ tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments), _toConsumableArray(cappedVouchers));
3142
3422
  this.updateTempOrderPaymentStatus(tempOrder);
3143
3423
  this.persistTempOrder();
3144
3424
  void this.recalculateSummary({
3145
3425
  createIfMissing: true
3146
3426
  }).catch(function (error) {
3147
- _this19.logError('recalculate summary after updateVoucherOrderPayments failed', {
3427
+ _this21.logError('recalculate summary after updateVoucherOrderPayments failed', {
3148
3428
  error: error instanceof Error ? error.message : String(error)
3149
3429
  });
3150
3430
  });
@@ -3211,8 +3491,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3211
3491
  }, {
3212
3492
  key: "hasLinkedBookingUid",
3213
3493
  value: function hasLinkedBookingUid(product) {
3214
- var _product$booking_uid, _product$metadata7;
3215
- var bookingUid = (_product$booking_uid = product === null || product === void 0 ? void 0 : product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.booking_uid;
3494
+ var _product$booking_uid, _product$metadata9;
3495
+ var bookingUid = (_product$booking_uid = product === null || product === void 0 ? void 0 : product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : product === null || product === void 0 || (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.booking_uid;
3216
3496
  return bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '';
3217
3497
  }
3218
3498
 
@@ -3280,7 +3560,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3280
3560
  var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, product, booking) {
3281
3561
  var _booking_uid,
3282
3562
  _metadata,
3283
- _this20 = this;
3563
+ _this22 = this;
3284
3564
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3285
3565
  return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3286
3566
  while (1) switch (_context18.prev = _context18.next) {
@@ -3305,8 +3585,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3305
3585
  hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3306
3586
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3307
3587
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3308
- if (_this20.hasGoodPassDiscount(item)) return false;
3309
- if (_this20.hasOrderProductLineNote(item)) return false;
3588
+ if (_this22.hasGoodPassDiscount(item)) return false;
3589
+ if (_this22.hasOrderProductLineNote(item)) return false;
3310
3590
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3311
3591
  if (item.product_id !== productToAdd.product_id) return false;
3312
3592
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
@@ -3412,49 +3692,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3412
3692
  key: "addProductToOrder",
3413
3693
  value: (function () {
3414
3694
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(product, booking) {
3415
- var tempOrder, _ref60, _productRecord$num, productRecord, splitCount, i, singleLine;
3695
+ var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3416
3696
  return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3417
3697
  while (1) switch (_context19.prev = _context19.next) {
3418
3698
  case 0:
3419
3699
  tempOrder = this.ensureTempOrder();
3420
- debugger;
3421
3700
  if (!booking) {
3422
- _context19.next = 19;
3701
+ _context19.next = 18;
3423
3702
  break;
3424
3703
  }
3425
3704
  productRecord = product;
3426
- splitCount = getSafeProductNum((_ref60 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref60 !== void 0 ? _ref60 : 1);
3705
+ splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3427
3706
  if (!(splitCount > 1)) {
3428
- _context19.next = 19;
3707
+ _context19.next = 18;
3429
3708
  break;
3430
3709
  }
3431
3710
  i = 0;
3432
- case 7:
3711
+ case 6:
3433
3712
  if (!(i < splitCount)) {
3434
- _context19.next = 16;
3713
+ _context19.next = 15;
3435
3714
  break;
3436
3715
  }
3437
3716
  singleLine = cloneDeep(productRecord);
3438
3717
  singleLine.num = 1;
3439
3718
  delete singleLine.product_quantity;
3440
- _context19.next = 13;
3719
+ _context19.next = 12;
3441
3720
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3442
- case 13:
3721
+ case 12:
3443
3722
  i += 1;
3444
- _context19.next = 7;
3723
+ _context19.next = 6;
3445
3724
  break;
3446
- case 16:
3447
- _context19.next = 18;
3725
+ case 15:
3726
+ _context19.next = 17;
3448
3727
  return this.finalizeProductOrderMutation(tempOrder);
3449
- case 18:
3728
+ case 17:
3450
3729
  return _context19.abrupt("return", tempOrder.products);
3451
- case 19:
3452
- _context19.next = 21;
3730
+ case 18:
3731
+ _context19.next = 20;
3453
3732
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3454
- case 21:
3455
- _context19.next = 23;
3733
+ case 20:
3734
+ _context19.next = 22;
3456
3735
  return this.finalizeProductOrderMutation(tempOrder);
3457
- case 23:
3736
+ case 22:
3737
+ this.logInfo('addProductToOrder success', {
3738
+ product_id: product.product_id,
3739
+ with_booking: !!booking
3740
+ });
3458
3741
  return _context19.abrupt("return", tempOrder.products);
3459
3742
  case 24:
3460
3743
  case "end":
@@ -3481,7 +3764,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3481
3764
  key: "addProductsToOrder",
3482
3765
  value: (function () {
3483
3766
  var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(items, options) {
3484
- var tempOrder, _iterator20, _step20, item, product, booking, _ref61, _productRecord$num2, productRecord, splitCount, i, singleLine;
3767
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3485
3768
  return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3486
3769
  while (1) switch (_context20.prev = _context20.next) {
3487
3770
  case 0:
@@ -3513,7 +3796,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3513
3796
  break;
3514
3797
  }
3515
3798
  productRecord = product;
3516
- splitCount = getSafeProductNum((_ref61 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3799
+ splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3517
3800
  if (!(splitCount > 1)) {
3518
3801
  _context20.next = 26;
3519
3802
  break;
@@ -3556,8 +3839,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3556
3839
  _context20.next = 40;
3557
3840
  return this.finalizeProductOrderMutation(tempOrder, options);
3558
3841
  case 40:
3842
+ this.logInfo('addProductsToOrder success', {
3843
+ itemsCount: items.length
3844
+ });
3559
3845
  return _context20.abrupt("return", tempOrder.products);
3560
- case 41:
3846
+ case 42:
3561
3847
  case "end":
3562
3848
  return _context20.stop();
3563
3849
  }
@@ -3590,24 +3876,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3590
3876
  }, {
3591
3877
  key: "getBundleRuntimeIdentity",
3592
3878
  value: function getBundleRuntimeIdentity(bundle) {
3593
- var _ref62, _bundle$bundle_id2, _ref63, _bundle$bundle_group_2, _ref64, _ref65, _bundle$bundle_produc3, _ref66, _bundle$bundle_varian3;
3879
+ var _ref63, _bundle$bundle_id2, _ref64, _bundle$bundle_group_2, _ref65, _ref66, _bundle$bundle_produc3, _ref67, _bundle$bundle_varian3;
3594
3880
  if (!bundle || _typeof(bundle) !== 'object') return '';
3595
- return [(_ref62 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref62 !== void 0 ? _ref62 : '', (_ref63 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref63 !== void 0 ? _ref63 : '', (_ref64 = (_ref65 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref65 !== void 0 ? _ref65 : bundle.product_id) !== null && _ref64 !== void 0 ? _ref64 : '', (_ref66 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref66 !== void 0 ? _ref66 : 0].join('|');
3881
+ return [(_ref63 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref63 !== void 0 ? _ref63 : '', (_ref64 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref64 !== void 0 ? _ref64 : '', (_ref65 = (_ref66 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref66 !== void 0 ? _ref66 : bundle.product_id) !== null && _ref65 !== void 0 ? _ref65 : '', (_ref67 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref67 !== void 0 ? _ref67 : 0].join('|');
3596
3882
  }
3597
3883
  }, {
3598
3884
  key: "preservePersistedBundlePriceFields",
3599
3885
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
3600
- var _this21 = this;
3886
+ var _this23 = this;
3601
3887
  if (!Array.isArray(nextBundles)) return nextBundles;
3602
3888
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
3603
3889
  var previousByIdentity = new Map();
3604
3890
  previousBundles.forEach(function (bundle) {
3605
- var identity = _this21.getBundleRuntimeIdentity(bundle);
3891
+ var identity = _this23.getBundleRuntimeIdentity(bundle);
3606
3892
  if (identity) previousByIdentity.set(identity, bundle);
3607
3893
  });
3608
3894
  return nextBundles.map(function (bundle, index) {
3609
3895
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
3610
- var previous = previousByIdentity.get(_this21.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
3896
+ var previous = previousByIdentity.get(_this23.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
3611
3897
  if (!previous || _typeof(previous) !== 'object') return bundle;
3612
3898
  return _objectSpread(_objectSpread({}, bundle), {}, {
3613
3899
  price: previous.price,
@@ -3775,8 +4061,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3775
4061
  });
3776
4062
  case 8:
3777
4063
  this.persistTempOrder();
4064
+ this.logInfo('updateOrderProduct success', {
4065
+ params: params
4066
+ });
3778
4067
  return _context21.abrupt("return", tempOrder.products);
3779
- case 10:
4068
+ case 11:
3780
4069
  case "end":
3781
4070
  return _context21.stop();
3782
4071
  }
@@ -3791,7 +4080,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3791
4080
  key: "updateOrderProducts",
3792
4081
  value: function () {
3793
4082
  var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(paramsList) {
3794
- var _this22 = this;
4083
+ var _this24 = this;
3795
4084
  var tempOrder;
3796
4085
  return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3797
4086
  while (1) switch (_context22.prev = _context22.next) {
@@ -3804,13 +4093,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3804
4093
  return _context22.abrupt("return", tempOrder.products);
3805
4094
  case 3:
3806
4095
  paramsList.forEach(function (params) {
3807
- _this22.applyOrderProductUpdateToTempOrder(tempOrder, params);
4096
+ _this24.applyOrderProductUpdateToTempOrder(tempOrder, params);
3808
4097
  });
3809
4098
  _context22.next = 6;
3810
4099
  return this.finalizeAfterProductsMutation(tempOrder);
3811
4100
  case 6:
4101
+ this.logInfo('updateOrderProduct success', {
4102
+ paramsList: paramsList
4103
+ });
3812
4104
  return _context22.abrupt("return", tempOrder.products);
3813
- case 7:
4105
+ case 8:
3814
4106
  case "end":
3815
4107
  return _context22.stop();
3816
4108
  }
@@ -3882,8 +4174,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3882
4174
  });
3883
4175
  case 22:
3884
4176
  this.persistTempOrder();
4177
+ this.logInfo('updateOrderProductQuantity success', {
4178
+ params: params
4179
+ });
3885
4180
  return _context23.abrupt("return", tempOrder.products);
3886
- case 24:
4181
+ case 25:
3887
4182
  case "end":
3888
4183
  return _context23.stop();
3889
4184
  }
@@ -3968,7 +4263,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3968
4263
  key: "removeProductsFromOrder",
3969
4264
  value: (function () {
3970
4265
  var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(identities) {
3971
- var _this23 = this;
4266
+ var _this25 = this;
3972
4267
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
3973
4268
  return _regeneratorRuntime().wrap(function _callee23$(_context26) {
3974
4269
  while (1) switch (_context26.prev = _context26.next) {
@@ -4023,7 +4318,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4023
4318
  }
4024
4319
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4025
4320
  bookingsBeforeRemove.forEach(function (booking) {
4026
- var bookingUid = _this23.getBookingUniqueIdentificationNumber(booking);
4321
+ var bookingUid = _this25.getBookingUniqueIdentificationNumber(booking);
4027
4322
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4028
4323
  linkedBookingUidsToRemove.add(bookingUid);
4029
4324
  }
@@ -4075,8 +4370,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4075
4370
  _context26.next = 31;
4076
4371
  return this.finalizeAfterProductsMutation(tempOrder);
4077
4372
  case 31:
4373
+ this.logInfo('removeProductsFromOrder success', {
4374
+ identities: identities
4375
+ });
4078
4376
  return _context26.abrupt("return", tempOrder.products);
4079
- case 32:
4377
+ case 33:
4080
4378
  case "end":
4081
4379
  return _context26.stop();
4082
4380
  }
@@ -4138,8 +4436,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4138
4436
  });
4139
4437
  case 11:
4140
4438
  this.persistTempOrder();
4439
+ this.logInfo('clearOrderCartLines success', {});
4141
4440
  return _context28.abrupt("return", tempOrder);
4142
- case 13:
4441
+ case 14:
4143
4442
  case "end":
4144
4443
  return _context28.stop();
4145
4444
  }
@@ -4154,23 +4453,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4154
4453
  }, {
4155
4454
  key: "buildCurrentSubmitPayloadForLocalPrint",
4156
4455
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
4157
- var _params$cacheId, _this$otherParams2, _ref67, _params$businessCode, _this$otherParams3, _this$otherParams4;
4456
+ var _params$cacheId, _this$otherParams3, _ref68, _params$businessCode, _this$otherParams4, _this$otherParams5;
4158
4457
  var tempOrder = this.ensureTempOrder();
4159
4458
  this.persistTempOrder();
4160
4459
  var payload = buildSubmitPayload({
4161
4460
  tempOrder: tempOrder,
4162
4461
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
4163
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform),
4164
- businessCode: (_ref67 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.businessCode) !== null && _ref67 !== void 0 ? _ref67 : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.business_code,
4462
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams3 = this.otherParams) === null || _this$otherParams3 === void 0 ? void 0 : _this$otherParams3.platform),
4463
+ businessCode: (_ref68 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.businessCode) !== null && _ref68 !== void 0 ? _ref68 : (_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.business_code,
4165
4464
  channel: params === null || params === void 0 ? void 0 : params.channel,
4166
4465
  type: params === null || params === void 0 ? void 0 : params.type,
4167
4466
  summary: this.store.summary || createEmptySummary(),
4168
4467
  enhance: function enhance(nextPayload) {
4169
- var _ref68, _tempOrder$order_numb, _ref69, _tempOrder$shop_order, _ref70, _tempOrder$shop_full_;
4468
+ var _ref69, _tempOrder$order_numb, _ref70, _tempOrder$shop_order, _ref71, _tempOrder$shop_full_;
4170
4469
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
4171
- order_number: (_ref68 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref68 !== void 0 ? _ref68 : null,
4172
- shop_order_number: (_ref69 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref69 !== void 0 ? _ref69 : null,
4173
- shop_full_order_number: (_ref70 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref70 !== void 0 ? _ref70 : null,
4470
+ order_number: (_ref69 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref69 !== void 0 ? _ref69 : null,
4471
+ shop_order_number: (_ref70 = (_tempOrder$shop_order = tempOrder.shop_order_number) !== null && _tempOrder$shop_order !== void 0 ? _tempOrder$shop_order : nextPayload.shop_order_number) !== null && _ref70 !== void 0 ? _ref70 : null,
4472
+ shop_full_order_number: (_ref71 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref71 !== void 0 ? _ref71 : null,
4174
4473
  small_ticket_data_flag: 1
4175
4474
  });
4176
4475
  }
@@ -4267,41 +4566,56 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4267
4566
  key: "runSubmitTempOrder",
4268
4567
  value: function () {
4269
4568
  var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4270
- var _params$cacheId2, _this$otherParams5, _ref71, _params$businessCode2, _this$otherParams6, _this$otherParams7;
4271
- var tempOrder, latestSummary, effectiveCacheId, hasPaymentOverride, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4569
+ var _params$cacheId2, _this$otherParams6, _ref72, _ref73, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
4570
+ var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4272
4571
  return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4273
4572
  while (1) switch (_context32.prev = _context32.next) {
4274
4573
  case 0:
4275
4574
  tempOrder = this.ensureTempOrder();
4575
+ shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
4576
+ hasPaymentOverride = (params === null || params === void 0 ? void 0 : params.payments) !== undefined;
4577
+ preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit((params === null || params === void 0 ? void 0 : params.payments) || [], shouldConfirmPendingVoucherPayments) : undefined;
4578
+ if (!hasPaymentOverride) {
4579
+ if (shouldConfirmPendingVoucherPayments) {
4580
+ this.confirmPendingVoucherPayments({
4581
+ persist: false,
4582
+ recalculateSummary: false
4583
+ });
4584
+ } else {
4585
+ this.discardPendingVoucherPayments({
4586
+ persist: false,
4587
+ recalculateSummary: false
4588
+ });
4589
+ }
4590
+ }
4276
4591
  this.persistTempOrder();
4277
- _context32.next = 4;
4592
+ _context32.next = 8;
4278
4593
  return this.recalculateSummary({
4279
4594
  createIfMissing: true
4280
4595
  });
4281
- case 4:
4596
+ case 8:
4282
4597
  _context32.t1 = _context32.sent;
4283
4598
  if (_context32.t1) {
4284
- _context32.next = 7;
4599
+ _context32.next = 11;
4285
4600
  break;
4286
4601
  }
4287
4602
  _context32.t1 = this.store.summary;
4288
- case 7:
4603
+ case 11:
4289
4604
  _context32.t0 = _context32.t1;
4290
4605
  if (_context32.t0) {
4291
- _context32.next = 10;
4606
+ _context32.next = 14;
4292
4607
  break;
4293
4608
  }
4294
4609
  _context32.t0 = createEmptySummary();
4295
- case 10:
4610
+ case 14:
4296
4611
  latestSummary = _context32.t0;
4297
4612
  effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
4298
- hasPaymentOverride = (params === null || params === void 0 ? void 0 : params.payments) !== undefined;
4299
4613
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4300
4614
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4301
4615
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
4302
4616
  var nextPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, payload), hasPaymentOverride ? {
4303
- payments: mapPaymentItemsToOrderPayments((params === null || params === void 0 ? void 0 : params.payments) || [])
4304
- } : {}), hasPaymentStatusOverride ? {
4617
+ payments: preparedPaymentOverride || []
4618
+ } : {}), hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? {
4305
4619
  payment_status: params === null || params === void 0 ? void 0 : params.paymentStatus
4306
4620
  } : {}), hasSmallTicketDataFlagOverride ? {
4307
4621
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
@@ -4309,17 +4623,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4309
4623
  var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
4310
4624
  return enhancedPayload;
4311
4625
  } : undefined;
4626
+ submitSnapshot = this.getLastOrderSubmitSnapshot();
4312
4627
  payload = buildSubmitPayload({
4313
4628
  tempOrder: tempOrder,
4314
4629
  cacheId: effectiveCacheId,
4315
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
4316
- businessCode: (_ref71 = (_params$businessCode2 = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode2 !== void 0 ? _params$businessCode2 : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref71 !== void 0 ? _ref71 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
4630
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4631
+ businessCode: (_ref72 = (_ref73 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4317
4632
  channel: params === null || params === void 0 ? void 0 : params.channel,
4318
- type: params === null || params === void 0 ? void 0 : params.type,
4633
+ type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4319
4634
  summary: latestSummary,
4320
4635
  request_unique_idempotency_token: params === null || params === void 0 ? void 0 : params.request_unique_idempotency_token,
4321
4636
  enhance: enhancePayload
4322
4637
  });
4638
+ console.log('[Order.runSubmitTempOrder.payload]', payload);
4323
4639
  if (params !== null && params !== void 0 && params.syncMode) {
4324
4640
  payload.sync_mode = true;
4325
4641
  }
@@ -4327,10 +4643,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4327
4643
  if (!payload.created_at) {
4328
4644
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4329
4645
  }
4330
- _context32.next = 21;
4646
+ _context32.next = 26;
4331
4647
  return this.saveDraft();
4332
- case 21:
4333
- _context32.prev = 21;
4648
+ case 26:
4649
+ _context32.prev = 26;
4334
4650
  this.logInfo('submitTempOrder calling sales checkout', {
4335
4651
  orderId: payload.order_id,
4336
4652
  externalSaleNumber: payload.external_sale_number,
@@ -4340,26 +4656,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4340
4656
  smallTicketDataFlag: payload.small_ticket_data_flag,
4341
4657
  syncMode: payload.sync_mode
4342
4658
  });
4343
- _context32.next = 25;
4659
+ _context32.next = 30;
4344
4660
  return this.submitSalesOrder({
4345
4661
  query: payload
4346
4662
  });
4347
- case 25:
4663
+ case 30:
4348
4664
  result = _context32.sent;
4349
- _context32.next = 38;
4665
+ _context32.next = 43;
4350
4666
  break;
4351
- case 28:
4352
- _context32.prev = 28;
4353
- _context32.t2 = _context32["catch"](21);
4667
+ case 33:
4668
+ _context32.prev = 33;
4669
+ _context32.t2 = _context32["catch"](26);
4354
4670
  backendErrorResponse = this.extractSubmitErrorResponse(_context32.t2);
4355
4671
  if (!backendErrorResponse) {
4356
- _context32.next = 35;
4672
+ _context32.next = 40;
4357
4673
  break;
4358
4674
  }
4359
4675
  this.store.syncState = 'failed';
4360
4676
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4361
4677
  return _context32.abrupt("return", backendErrorResponse);
4362
- case 35:
4678
+ case 40:
4363
4679
  this.store.syncState = 'failed';
4364
4680
  this.logError('submitTempOrder failed', {
4365
4681
  error: _context32.t2 instanceof Error ? _context32.t2.message : String(_context32.t2),
@@ -4369,45 +4685,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4369
4685
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4370
4686
  });
4371
4687
  throw _context32.t2;
4372
- case 38:
4688
+ case 43:
4373
4689
  if (!this.isSubmitResponseRejected(result)) {
4374
- _context32.next = 42;
4690
+ _context32.next = 47;
4375
4691
  break;
4376
4692
  }
4377
4693
  this.store.syncState = 'failed';
4378
4694
  this.logSubmitBackendRejected(result, payload);
4379
4695
  return _context32.abrupt("return", result);
4380
- case 42:
4696
+ case 47:
4381
4697
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4382
4698
  this.logInfo('runSubmitTempOrder: 提交成功', {
4383
4699
  submittedOrderId: submittedOrderId,
4384
4700
  result: result,
4385
- tempOrder: tempOrder
4701
+ tempOrder: _objectSpread(_objectSpread({}, tempOrder), {}, {
4702
+ _extend: undefined
4703
+ })
4386
4704
  });
4387
4705
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4388
- _context32.next = 51;
4706
+ _context32.next = 56;
4389
4707
  break;
4390
4708
  }
4391
4709
  tempOrder.order_id = submittedOrderId;
4392
4710
  resultRecord = result;
4393
- _context32.next = 49;
4711
+ _context32.next = 54;
4394
4712
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4395
- case 49:
4396
- _context32.next = 52;
4713
+ case 54:
4714
+ _context32.next = 57;
4397
4715
  break;
4398
- case 51:
4716
+ case 56:
4399
4717
  if (this.isLocalPendingSubmitResult(result)) {
4400
4718
  this.store.syncState = 'local';
4401
4719
  } else {
4402
4720
  this.store.syncState = 'submitted';
4403
4721
  }
4404
- case 52:
4722
+ case 57:
4405
4723
  return _context32.abrupt("return", result);
4406
- case 53:
4724
+ case 58:
4407
4725
  case "end":
4408
4726
  return _context32.stop();
4409
4727
  }
4410
- }, _callee29, this, [[21, 28]]);
4728
+ }, _callee29, this, [[26, 33]]);
4411
4729
  }));
4412
4730
  function runSubmitTempOrder(_x32) {
4413
4731
  return _runSubmitTempOrder.apply(this, arguments);
@@ -4479,10 +4797,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4479
4797
  value: function extractSubmitErrorResponse(error) {
4480
4798
  var _error$response,
4481
4799
  _error$response2,
4482
- _this24 = this;
4800
+ _this26 = this;
4483
4801
  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];
4484
4802
  return candidates.find(function (candidate) {
4485
- return _this24.isSubmitErrorResponse(candidate);
4803
+ return _this26.isSubmitErrorResponse(candidate);
4486
4804
  }) || null;
4487
4805
  }
4488
4806
  }, {
@@ -4510,47 +4828,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4510
4828
  key: "syncPaymentsToOrder",
4511
4829
  value: function () {
4512
4830
  var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4513
- var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
4831
+ var _params$confirmPendin;
4832
+ var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, paidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
4514
4833
  return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4515
4834
  while (1) switch (_context34.prev = _context34.next) {
4516
4835
  case 0:
4517
4836
  tempOrder = this.ensureTempOrder();
4518
4837
  mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
4519
- paymentTotal = this.calculatePaymentTotal(mappedPayments);
4520
- targetAmount = this.getPaymentTargetAmount();
4521
- isFullyPaid = targetAmount.lte(0) ? true : paymentTotal.gte(targetAmount);
4522
- paymentStatus = isFullyPaid ? params.paymentStatus || 'paid' : 'partially_paid';
4523
- tempOrder.payments = mappedPayments;
4838
+ shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
4839
+ effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
4840
+ completion = this.getPaymentCompletion(effectivePayments);
4841
+ paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
4842
+ paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || 'paid' : paidPaymentTotal.gt(0) ? 'partially_paid' : 'payment_processing';
4843
+ tempOrder.payments = effectivePayments;
4524
4844
  tempOrder.payment_status = paymentStatus;
4525
4845
  this.persistTempOrder();
4526
- _context34.next = 11;
4846
+ _context34.next = 12;
4527
4847
  return this.saveDraft();
4528
- case 11:
4848
+ case 12:
4529
4849
  if (params.submitWhenPaid) {
4530
- _context34.next = 13;
4850
+ _context34.next = 14;
4531
4851
  break;
4532
4852
  }
4533
- return _context34.abrupt("return", {
4534
- isFullyPaid: isFullyPaid
4535
- });
4536
- case 13:
4853
+ return _context34.abrupt("return", completion);
4854
+ case 14:
4537
4855
  if (!(this.store.syncState === 'submitting')) {
4538
- _context34.next = 15;
4856
+ _context34.next = 16;
4539
4857
  break;
4540
4858
  }
4541
- return _context34.abrupt("return", {
4542
- isFullyPaid: isFullyPaid
4543
- });
4544
- case 15:
4859
+ return _context34.abrupt("return", completion);
4860
+ case 16:
4545
4861
  this.store.syncState = 'submitting';
4546
- paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
4547
- _context34.next = 19;
4862
+ paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
4863
+ _context34.next = 20;
4548
4864
  return this.submitTempOrder({
4549
- payments: mappedPayments,
4865
+ payments: effectivePayments,
4550
4866
  paymentStatus: paymentStatus,
4551
4867
  smallTicketDataFlag: params.smallTicketDataFlag,
4552
4868
  businessCode: params.businessCode,
4553
4869
  channel: params.channel,
4870
+ confirmPendingVoucherPayments: true,
4554
4871
  enhancePayload: function enhancePayload(payload) {
4555
4872
  var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
4556
4873
  request_unique_idempotency_token: paymentSyncIdempotencyToken
@@ -4558,13 +4875,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4558
4875
  return nextPayload;
4559
4876
  }
4560
4877
  });
4561
- case 19:
4878
+ case 20:
4562
4879
  submitResult = _context34.sent;
4563
- return _context34.abrupt("return", {
4564
- isFullyPaid: isFullyPaid,
4880
+ return _context34.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
4565
4881
  submitResult: submitResult
4566
- });
4567
- case 21:
4882
+ }));
4883
+ case 22:
4568
4884
  case "end":
4569
4885
  return _context34.stop();
4570
4886
  }
@@ -5069,6 +5385,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5069
5385
  products: cloneDeep(nextTempOrder.products || []),
5070
5386
  payments: cloneDeep(nextTempOrder.payments || []),
5071
5387
  surcharges: cloneDeep(nextTempOrder.surcharges || []),
5388
+ shop_discount: nextTempOrder.shop_discount || '0.00',
5072
5389
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5073
5390
  }
5074
5391
  });
@@ -5077,27 +5394,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5077
5394
  currentDiscounts = typeof ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5078
5395
  shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
5079
5396
  if (shouldSkipEmptyDiscountSync) {
5080
- _context42.next = 16;
5397
+ _context42.next = 17;
5081
5398
  break;
5082
5399
  }
5083
- _context42.next = 14;
5400
+ OrderModule.populateSavedAmounts(nextTempOrder.products, hydratedEditDiscounts);
5401
+ _context42.next = 15;
5084
5402
  return (_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList(hydratedEditDiscounts);
5085
- case 14:
5086
- _context42.next = 16;
5403
+ case 15:
5404
+ _context42.next = 17;
5087
5405
  return (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList(hydratedEditDiscounts);
5088
- case 16:
5406
+ case 17:
5089
5407
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5090
- _context42.next = 19;
5408
+ _context42.next = 20;
5091
5409
  break;
5092
5410
  }
5093
- _context42.next = 19;
5411
+ _context42.next = 20;
5094
5412
  return this.recalculateSummary({
5095
5413
  createIfMissing: false
5096
5414
  });
5097
- case 19:
5415
+ case 20:
5098
5416
  this.persistTempOrder();
5099
5417
  return _context42.abrupt("return", nextTempOrder);
5100
- case 21:
5418
+ case 22:
5101
5419
  case "end":
5102
5420
  return _context42.stop();
5103
5421
  }
@@ -5144,7 +5462,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5144
5462
  }, {
5145
5463
  key: "normalizeTempOrderForRuntime",
5146
5464
  value: function normalizeTempOrderForRuntime(raw, options) {
5147
- var _this25 = this;
5465
+ var _this27 = this;
5148
5466
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
5149
5467
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5150
5468
  if ((nextTempOrder.order_id === undefined || nextTempOrder.order_id === null) && (raw === null || raw === void 0 ? void 0 : raw.id) !== undefined && (raw === null || raw === void 0 ? void 0 : raw.id) !== null) {
@@ -5167,10 +5485,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5167
5485
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5168
5486
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5169
5487
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5170
- return _this25.normalizeHydratedOrderProduct(p);
5488
+ return _this27.normalizeHydratedOrderProduct(p);
5171
5489
  }) : [];
5172
5490
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5173
- var booking = _this25.normalizeHydratedBookingHolder(b || {});
5491
+ var booking = _this27.normalizeHydratedBookingHolder(b || {});
5174
5492
  return _objectSpread(_objectSpread({}, booking), {}, {
5175
5493
  is_all: normalizeBookingIsAll(booking),
5176
5494
  sub_type: normalizeBookingSubType(booking)
@@ -5200,15 +5518,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5200
5518
  _step22;
5201
5519
  try {
5202
5520
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
5203
- var _product$metadata8, _ref72, _ref73, _existed$origin, _rawProduct$metadata;
5521
+ var _product$metadata10, _ref74, _ref75, _existed$origin, _rawProduct$metadata;
5204
5522
  var _step22$value = _slicedToArray(_step22.value, 2),
5205
5523
  index = _step22$value[0],
5206
5524
  product = _step22$value[1];
5207
- var uid = (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.unique_identification_number;
5525
+ var uid = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number;
5208
5526
  if (!uid) continue;
5209
5527
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
5210
5528
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
5211
- var origin = (_ref72 = (_ref73 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref73 !== void 0 ? _ref73 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref72 !== void 0 ? _ref72 : rawProduct;
5529
+ var origin = (_ref74 = (_ref75 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref75 !== void 0 ? _ref75 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref74 !== void 0 ? _ref74 : rawProduct;
5212
5530
  var originSnapshot = cloneDeep(origin);
5213
5531
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
5214
5532
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -5242,8 +5560,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5242
5560
  var bookingUidByProductUid = new Map();
5243
5561
  var productByUid = new Map();
5244
5562
  (tempOrder.products || []).forEach(function (product) {
5245
- var _product$metadata9;
5246
- var productUid = (product === null || product === void 0 || (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5563
+ var _product$metadata11;
5564
+ var productUid = (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5247
5565
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
5248
5566
  productByUid.set(String(productUid), product);
5249
5567
  }
@@ -5264,8 +5582,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5264
5582
  bookingUidByProductUid.set(String(productUid), bookingUid);
5265
5583
  });
5266
5584
  (tempOrder.products || []).forEach(function (product) {
5267
- var _product$metadata10;
5268
- var productUid = (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5585
+ var _product$metadata12;
5586
+ var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5269
5587
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
5270
5588
  var bookingUid = bookingUidByProductUid.get(String(productUid));
5271
5589
  if (!bookingUid) return;
@@ -5276,6 +5594,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5276
5594
  product.booking_uid = linkedBookingUid;
5277
5595
  product.metadata.booking_uid = linkedBookingUid;
5278
5596
  });
5597
+ this.syncLinkedBookingHoldersToProducts(tempOrder);
5279
5598
  }
5280
5599
  }, {
5281
5600
  key: "pickHydratedDisplayText",
@@ -5318,10 +5637,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5318
5637
  }, {
5319
5638
  key: "normalizeHydratedProductOptionItem",
5320
5639
  value: function normalizeHydratedProductOptionItem(optionItem) {
5321
- var _ref74, _optionItem$num, _ref75, _optionItem$add_price;
5322
- var rawNum = (_ref74 = (_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 && _ref74 !== void 0 ? _ref74 : 1;
5640
+ var _ref76, _optionItem$num, _ref77, _optionItem$add_price;
5641
+ var rawNum = (_ref76 = (_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 && _ref76 !== void 0 ? _ref76 : 1;
5323
5642
  var parsedNum = Number(rawNum);
5324
- var rawPrice = (_ref75 = (_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 && _ref75 !== void 0 ? _ref75 : 0;
5643
+ var rawPrice = (_ref77 = (_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 && _ref77 !== void 0 ? _ref77 : 0;
5325
5644
  var parsedPrice = Number(rawPrice);
5326
5645
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
5327
5646
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -5338,7 +5657,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5338
5657
  }, {
5339
5658
  key: "normalizeHydratedOrderProduct",
5340
5659
  value: function normalizeHydratedOrderProduct(product) {
5341
- var _this26 = this;
5660
+ var _this28 = this;
5342
5661
  var row = _objectSpread({}, product || {});
5343
5662
  if (row.num === undefined && row.product_quantity !== undefined) {
5344
5663
  row.num = row.product_quantity;
@@ -5346,7 +5665,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5346
5665
  var productSku = ensureProductSku(row);
5347
5666
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5348
5667
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5349
- return _this26.normalizeHydratedProductOptionItem(optionItem || {});
5668
+ return _this28.normalizeHydratedProductOptionItem(optionItem || {});
5350
5669
  }))
5351
5670
  });
5352
5671
  delete row["product_".concat('option', "_item")];
@@ -5355,6 +5674,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5355
5674
  if (row.booking_uid && !row.metadata.booking_uid) {
5356
5675
  row.metadata.booking_uid = row.booking_uid;
5357
5676
  }
5677
+ row = restoreHydratedBundleDiscounts(row, normalizeOrderProductDiscountList);
5358
5678
  var existingIdentity = row.metadata.unique_identification_number || row.unique_identification_number;
5359
5679
  if (!existingIdentity) {
5360
5680
  row.metadata.unique_identification_number = createUuidV4();
@@ -5366,7 +5686,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5366
5686
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
5367
5687
  });
5368
5688
  if (result.metadata) delete result.metadata.price_schema_version;
5369
- return this.sanitizeOrderProductForTempOrder(result);
5689
+ var restored = restoreHydratedBundleDiscounts(result, normalizeOrderProductDiscountList);
5690
+ return this.sanitizeOrderProductForTempOrder(restored);
5370
5691
  }
5371
5692
  }, {
5372
5693
  key: "getLastOrderInfo",
@@ -5402,6 +5723,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5402
5723
  }
5403
5724
  return getOrderInfo;
5404
5725
  }()
5726
+ }, {
5727
+ key: "getVouchers",
5728
+ value: function getVouchers() {
5729
+ var _this$store$tempOrder5;
5730
+ return ((_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.vouchers) || [];
5731
+ }
5405
5732
  }], [{
5406
5733
  key: "populateSavedAmounts",
5407
5734
  value: function populateSavedAmounts(productList, discountList) {
@@ -5450,10 +5777,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5450
5777
  _step27;
5451
5778
  try {
5452
5779
  for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
5453
- var _ref76, _bundle$num3;
5780
+ var _ref78, _bundle$num3;
5454
5781
  var bundle = _step27.value;
5455
5782
  var isPersistedBundleProduct = isPersistedProduct || Boolean((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) || (bundle === null || bundle === void 0 ? void 0 : bundle.orderDetailId) || (bundle === null || bundle === void 0 ? void 0 : bundle.booking_id));
5456
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref76 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref76 !== void 0 ? _ref76 : 1) || 1).toNumber();
5783
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref78 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref78 !== void 0 ? _ref78 : 1) || 1).toNumber();
5457
5784
  var _iterator28 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
5458
5785
  _step28;
5459
5786
  try {