@pisell/pisellos 2.2.257 → 2.2.258

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 (46) hide show
  1. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
  2. package/dist/modules/Order/index.d.ts +30 -2
  3. package/dist/modules/Order/index.js +508 -241
  4. package/dist/modules/Order/types.d.ts +20 -2
  5. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  6. package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
  7. package/dist/modules/Order/utils.d.ts +4 -0
  8. package/dist/modules/Order/utils.js +114 -28
  9. package/dist/modules/Rules/index.d.ts +3 -3
  10. package/dist/modules/Rules/index.js +8 -3
  11. package/dist/modules/Rules/types.d.ts +2 -1
  12. package/dist/server/index.d.ts +3 -0
  13. package/dist/server/index.js +1208 -920
  14. package/dist/server/modules/order/index.d.ts +22 -3
  15. package/dist/server/modules/order/index.js +397 -314
  16. package/dist/solution/BaseSales/index.d.ts +16 -2
  17. package/dist/solution/BaseSales/index.js +484 -314
  18. package/dist/solution/BaseSales/types.d.ts +1 -0
  19. package/dist/solution/BaseSales/types.js +2 -1
  20. package/dist/solution/BookingByStep/index.d.ts +1 -1
  21. package/dist/solution/BookingTicket/index.d.ts +9 -1
  22. package/dist/solution/BookingTicket/index.js +162 -6
  23. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  24. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
  25. package/lib/modules/Order/index.d.ts +30 -2
  26. package/lib/modules/Order/index.js +340 -57
  27. package/lib/modules/Order/types.d.ts +20 -2
  28. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
  29. package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
  30. package/lib/modules/Order/utils.d.ts +4 -0
  31. package/lib/modules/Order/utils.js +84 -2
  32. package/lib/modules/Rules/index.d.ts +3 -3
  33. package/lib/modules/Rules/index.js +4 -3
  34. package/lib/modules/Rules/types.d.ts +2 -1
  35. package/lib/server/index.d.ts +3 -0
  36. package/lib/server/index.js +201 -9
  37. package/lib/server/modules/order/index.d.ts +22 -3
  38. package/lib/server/modules/order/index.js +102 -51
  39. package/lib/solution/BaseSales/index.d.ts +16 -2
  40. package/lib/solution/BaseSales/index.js +143 -31
  41. package/lib/solution/BaseSales/types.d.ts +1 -0
  42. package/lib/solution/BaseSales/types.js +2 -1
  43. package/lib/solution/BookingByStep/index.d.ts +1 -1
  44. package/lib/solution/BookingTicket/index.d.ts +9 -1
  45. package/lib/solution/BookingTicket/index.js +112 -0
  46. package/package.json +1 -1
@@ -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;
@@ -674,26 +713,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
674
713
  // appliedProductDetails / savedAmount 复位。
675
714
  if (!tempOrder) return;
676
715
  delete tempOrder.discount_list;
677
- if (this.shouldSkipDiscountCalculation(tempOrder)) return;
716
+ var discountList = ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.getDiscountList()) || [];
717
+ var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
718
+ if (shouldSkipDiscountCalculation) return;
678
719
  var rulesModule = this.store.rules;
679
720
  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
- }] : [];
721
+ var holders = ((_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_record) || [];
684
722
  var result = rulesModule.calcDiscount({
685
723
  productList: tempOrder.products,
686
724
  discountList: discountList,
687
725
  holders: holders,
688
- isFormSubject: !!((_tempOrder$holder4 = tempOrder.holder) !== null && _tempOrder$holder4 !== void 0 && _tempOrder$holder4.type) && tempOrder.holder.type === 'form',
726
+ isFormSubject: function isFormSubject(product) {
727
+ return resolveIsFormSubject(tempOrder, product);
728
+ },
689
729
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
690
730
  });
691
731
  if (result !== null && result !== void 0 && result.productList) {
692
732
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
693
733
  tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
694
- var _ref13;
734
+ var _ref14;
695
735
  var uid = getOrderProductLineUid(product);
696
- var previous = (_ref13 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref13 !== void 0 ? _ref13 : previousProductsByUid.get("__index__:".concat(index));
736
+ var previous = (_ref14 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref14 !== void 0 ? _ref14 : previousProductsByUid.get("__index__:".concat(index));
697
737
  if (isManualProductDiscountProduct(previous)) {
698
738
  return previous;
699
739
  }
@@ -1218,15 +1258,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1218
1258
  }, {
1219
1259
  key: "extractOrderIdFromSubmitResult",
1220
1260
  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;
1261
+ var _ref15, _ref16, _ref17, _result$data$order_id, _result$data, _result$data2;
1262
+ 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
1263
  }
1224
1264
  }, {
1225
1265
  key: "calculatePaymentEffectiveAmount",
1226
1266
  value: function calculatePaymentEffectiveAmount(payment) {
1227
- var _ref17, _payment$origin_amoun;
1267
+ var _ref18, _payment$origin_amoun;
1228
1268
  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);
1269
+ 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
1270
  var serviceFee = new Decimal(payment.service_fee || 0);
1231
1271
  // TODO: 后端允许 amount 表示顾客实际支付总额后,移除这个兼容分支。
1232
1272
  var effectiveAmount = serviceFee.gt(0) && amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
@@ -1240,6 +1280,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1240
1280
  return mapPaymentItemsToOrderPayments(payments, {
1241
1281
  includeVoided: false
1242
1282
  }).reduce(function (sum, payment) {
1283
+ if (!isPaidPaymentRecord(payment)) return sum;
1243
1284
  return sum.plus(_this4.calculatePaymentEffectiveAmount(payment));
1244
1285
  }, new Decimal(0));
1245
1286
  }
@@ -1253,6 +1294,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1253
1294
  value: function normalizeDepositAmount(amount) {
1254
1295
  return Decimal.max(new Decimal(Number(amount) || 0), 0).toDecimalPlaces(2).toFixed(2);
1255
1296
  }
1297
+ }, {
1298
+ key: "getLastOrderDepositSnapshot",
1299
+ value: function getLastOrderDepositSnapshot() {
1300
+ var _lastOrderInfo$deposi, _lastOrderInfo$summar;
1301
+ var lastOrderInfo = this.store.lastOrderInfo;
1302
+ if (!lastOrderInfo || _typeof(lastOrderInfo) !== 'object') return null;
1303
+ 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;
1304
+ var depositAmount = this.normalizeDepositAmount(rawDepositAmount !== null && rawDepositAmount !== void 0 ? rawDepositAmount : 0);
1305
+ var hasDepositAmount = new Decimal(depositAmount).gt(0);
1306
+ var isDeposit = Number(lastOrderInfo.is_deposit) === 1 || hasDepositAmount;
1307
+ if (!isDeposit || !hasDepositAmount) return null;
1308
+ return {
1309
+ isDeposit: 1,
1310
+ depositAmount: depositAmount
1311
+ };
1312
+ }
1313
+ }, {
1314
+ key: "getLastOrderSubmitSnapshot",
1315
+ value: function getLastOrderSubmitSnapshot() {
1316
+ var lastOrderInfo = this.store.lastOrderInfo;
1317
+ if (!lastOrderInfo || _typeof(lastOrderInfo) !== 'object') return {};
1318
+ var businessCode = lastOrderInfo.business_code;
1319
+ var type = lastOrderInfo.type;
1320
+ return _objectSpread(_objectSpread({}, typeof businessCode === 'string' && businessCode ? {
1321
+ businessCode: businessCode
1322
+ } : {}), typeof type === 'string' && type ? {
1323
+ type: type
1324
+ } : {});
1325
+ }
1256
1326
  }, {
1257
1327
  key: "applyDepositAmountToSummary",
1258
1328
  value: function applyDepositAmountToSummary(tempOrder, summary, amount) {
@@ -1271,10 +1341,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1271
1341
  tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
1272
1342
  return nextSummary;
1273
1343
  }
1344
+ }, {
1345
+ key: "applyLastOrderDepositSnapshot",
1346
+ value: function applyLastOrderDepositSnapshot(tempOrder, summary) {
1347
+ var snapshot = this.getLastOrderDepositSnapshot();
1348
+ if (!snapshot) return summary;
1349
+ var existedDeposit = summary.deposit && _typeof(summary.deposit) === 'object' ? summary.deposit : undefined;
1350
+ var nextSummary = _objectSpread(_objectSpread({}, summary), {}, {
1351
+ deposit_amount: snapshot.depositAmount,
1352
+ deposit: _objectSpread(_objectSpread({}, existedDeposit || {}), {}, {
1353
+ total: snapshot.depositAmount,
1354
+ deposit_policy_ids: (existedDeposit === null || existedDeposit === void 0 ? void 0 : existedDeposit.deposit_policy_ids) || [],
1355
+ hasDeposit: true
1356
+ })
1357
+ });
1358
+ tempOrder.deposit_amount = snapshot.depositAmount;
1359
+ tempOrder.is_deposit = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
1360
+ return nextSummary;
1361
+ }
1274
1362
  }, {
1275
1363
  key: "isDepositOrder",
1276
1364
  value: function isDepositOrder(tempOrder, depositAmount) {
1277
- return tempOrder.is_deposit === 1 || depositAmount.gt(0);
1365
+ return tempOrder.is_deposit === 1 && depositAmount.gt(0);
1278
1366
  }
1279
1367
  }, {
1280
1368
  key: "getOrderExpectedAmount",
@@ -1289,13 +1377,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1289
1377
  if (depositAmount.lte(0)) return false;
1290
1378
  return params.paidAmount.gte(depositAmount);
1291
1379
  }
1380
+ }, {
1381
+ key: "getPaymentCompletion",
1382
+ value: function getPaymentCompletion(payments) {
1383
+ var tempOrder = this.ensureTempOrder();
1384
+ var summary = this.store.summary || createEmptySummary();
1385
+ var paymentList = payments || tempOrder.payments || [];
1386
+ var refundAmount = this.getSummaryRefundAmount(summary);
1387
+ var netPaidAmount = Decimal.max(this.calculatePaymentTotal(paymentList).minus(refundAmount), 0);
1388
+ var depositAmount = this.getDepositAmount(tempOrder, summary);
1389
+ var orderExpectedAmount = this.getOrderExpectedAmount(summary);
1390
+ var isDepositFullyPaid = this.isDepositCovered({
1391
+ tempOrder: tempOrder,
1392
+ summary: summary,
1393
+ paidAmount: netPaidAmount
1394
+ });
1395
+ var isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
1396
+ var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? 'deposit' : 'normal';
1397
+ return {
1398
+ isFullyPaid: isOrderFullyPaid,
1399
+ isOrderFullyPaid: isOrderFullyPaid,
1400
+ isDepositFullyPaid: isDepositFullyPaid,
1401
+ paymentStage: paymentStage,
1402
+ depositAmount: depositAmount.toFixed(2),
1403
+ orderExpectedAmount: orderExpectedAmount.toFixed(2)
1404
+ };
1405
+ }
1292
1406
  }, {
1293
1407
  key: "calculateDepositPaidAmount",
1294
1408
  value: function calculateDepositPaidAmount(payments) {
1295
1409
  var _this5 = this;
1296
1410
  return (payments || []).reduce(function (sum, payment) {
1297
1411
  var paymentRecord = payment;
1298
- if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return sum;
1412
+ if (!isPaidPaymentRecord(paymentRecord)) return sum;
1299
1413
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1300
1414
  if (!isDepositPayment) return sum;
1301
1415
  if (paymentRecord.origin_amount !== undefined && paymentRecord.origin_amount !== null && paymentRecord.origin_amount !== '') {
@@ -1317,7 +1431,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1317
1431
  }, {
1318
1432
  key: "normalizePaymentSource",
1319
1433
  value: function normalizePaymentSource(payment, options) {
1320
- var _ref18, _paymentRecord$origin;
1434
+ var _ref19, _paymentRecord$origin;
1321
1435
  var paymentRecord = payment;
1322
1436
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1323
1437
  if (!metadata.unique_payment_number) {
@@ -1325,7 +1439,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1325
1439
  }
1326
1440
  var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1327
1441
  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'
1442
+ 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
1443
  });
1330
1444
  if (paymentRecord.status !== undefined) {
1331
1445
  normalized.status = paymentRecord.status;
@@ -1446,7 +1560,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1446
1560
  var _this6 = this;
1447
1561
  return (payments || []).reduce(function (summary, payment) {
1448
1562
  var paymentRecord = payment;
1449
- if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return summary;
1563
+ if (!isPaidPaymentRecord(paymentRecord)) return summary;
1450
1564
  return {
1451
1565
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1452
1566
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
@@ -1658,7 +1772,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1658
1772
  _product$payment_pric,
1659
1773
  _sku$code,
1660
1774
  _sku$barcode,
1661
- _ref19,
1775
+ _ref20,
1662
1776
  _sku$variant_id,
1663
1777
  _this8 = this;
1664
1778
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
@@ -1685,24 +1799,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1685
1799
  product_sku: this.normalizeFingerprintValue({
1686
1800
  code: (_sku$code = sku.code) !== null && _sku$code !== void 0 ? _sku$code : '',
1687
1801
  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,
1802
+ 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
1803
  variant: sku.variant || [],
1690
1804
  option: getProductSkuOptions(product || {}).map(function (option) {
1691
- var _ref20, _option$id, _option$option_group_, _ref21, _option$option_group_2, _option$num, _option$add_price;
1805
+ var _ref21, _option$id, _option$option_group_, _ref22, _option$option_group_2, _option$num, _option$add_price;
1692
1806
  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,
1807
+ 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
1808
  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,
1809
+ 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
1810
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1697
1811
  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
1812
  };
1699
1813
  })
1700
1814
  }),
1701
1815
  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;
1816
+ var _ref23, _ref24, _bundle$bundle_produc, _ref25, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
1703
1817
  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,
1818
+ 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,
1819
+ 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
1820
  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
1821
  price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1708
1822
  bundle_selling_price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
@@ -1711,10 +1825,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1711
1825
  };
1712
1826
  })),
1713
1827
  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;
1828
+ var _ref26, _discount$type2, _ref27, _ref28, _discount$discount_id, _discount$discount;
1715
1829
  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,
1830
+ 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 : '',
1831
+ 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
1832
  amount: _this8.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1719
1833
  };
1720
1834
  }))
@@ -1738,14 +1852,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1738
1852
  var _product$product_id3,
1739
1853
  _product$product_vari2,
1740
1854
  _product$num2,
1741
- _ref28,
1855
+ _ref29,
1742
1856
  _metadata$unique_iden,
1743
1857
  _metadata$price_overr,
1744
1858
  _metadata$is_manual_d,
1745
1859
  _metadata$product_dis,
1746
1860
  _sku$code2,
1747
1861
  _sku$barcode2,
1748
- _ref29,
1862
+ _ref30,
1749
1863
  _sku$variant_id2,
1750
1864
  _this10 = this;
1751
1865
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
@@ -1761,7 +1875,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1761
1875
  extension_type: extensionType,
1762
1876
  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
1877
  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 : '',
1878
+ 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
1879
  price_override: (_metadata$price_overr = metadata.price_override) !== null && _metadata$price_overr !== void 0 ? _metadata$price_overr : '',
1766
1880
  is_manual_discount: (_metadata$is_manual_d = metadata.is_manual_discount) !== null && _metadata$is_manual_d !== void 0 ? _metadata$is_manual_d : '',
1767
1881
  product_discount_reason: (_metadata$product_dis = metadata.product_discount_reason) !== null && _metadata$product_dis !== void 0 ? _metadata$product_dis : ''
@@ -1769,35 +1883,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1769
1883
  product_sku: this.normalizeFingerprintValue({
1770
1884
  code: (_sku$code2 = sku.code) !== null && _sku$code2 !== void 0 ? _sku$code2 : '',
1771
1885
  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,
1886
+ 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
1887
  variant: sku.variant || [],
1774
1888
  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;
1889
+ var _ref31, _option$id2, _option$option_group_3, _ref32, _option$option_group_4, _option$num2, _option$add_price2;
1776
1890
  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,
1891
+ 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
1892
  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,
1893
+ 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
1894
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
1781
1895
  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
1896
  };
1783
1897
  })
1784
1898
  }),
1785
1899
  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;
1900
+ 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
1901
  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,
1902
+ 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,
1903
+ 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,
1904
+ 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,
1905
+ 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
1906
  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
1907
  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
1908
  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
1909
  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;
1910
+ var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
1797
1911
  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,
1912
+ 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
1913
  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,
1914
+ 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
1915
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
1802
1916
  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
1917
  };
@@ -1805,10 +1919,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1805
1919
  };
1806
1920
  })),
1807
1921
  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;
1922
+ var _ref40, _discount$type4, _ref41, _ref42, _discount$discount_id2, _discount$discount2;
1809
1923
  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,
1924
+ 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 : '',
1925
+ 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
1926
  amount: _this10.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1813
1927
  };
1814
1928
  }))
@@ -2015,6 +2129,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2015
2129
  key: "restoreOrder",
2016
2130
  value: function restoreOrder() {
2017
2131
  var _this$store$discount11, _this$store$discount12;
2132
+ this.logInfo('restoreOrder start', {});
2018
2133
  var freshTempOrder = this.createDefaultTempOrderInstance();
2019
2134
  this.ensureExternalSaleNumber(freshTempOrder);
2020
2135
  this.store.tempOrder = freshTempOrder;
@@ -2088,11 +2203,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2088
2203
  }, {
2089
2204
  key: "getOrderIdentity",
2090
2205
  value: function getOrderIdentity() {
2091
- var _ref42, _ref43, _tempOrder$order_id, _tempOrder$_extend6;
2206
+ var _ref43, _ref44, _tempOrder$order_id, _tempOrder$_extend6;
2092
2207
  var tempOrder = this.store.tempOrder;
2093
2208
  if (!tempOrder) return null;
2094
2209
  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;
2210
+ 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
2211
  return {
2097
2212
  localId: this.cacheId || ((_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.localId),
2098
2213
  orderId: orderId,
@@ -2127,7 +2242,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2127
2242
  orderPaidAmount: paidPaymentSummary.gapPaidAmount
2128
2243
  });
2129
2244
  return {
2130
- isDeposit: tempOrder.is_deposit === 1 || depositAmount !== '0.00',
2245
+ isDeposit: tempOrder.is_deposit === 1,
2131
2246
  depositAmount: depositAmount,
2132
2247
  expectAmount: summary.expect_amount || '0.00',
2133
2248
  totalAmount: summary.total_amount || '0.00',
@@ -2245,11 +2360,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2245
2360
  }, {
2246
2361
  key: "captureProductRuntime",
2247
2362
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
2248
- var _extend$productsByUid, _ref44, _rawProduct$_origin;
2363
+ var _extend$productsByUid, _ref45, _rawProduct$_origin;
2249
2364
  var uid = existedUid || this.getProductUid(normalizedProduct);
2250
2365
  var extend = this.ensureExtend(tempOrder);
2251
2366
  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;
2367
+ var origin = (_ref45 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref45 !== void 0 ? _ref45 : existed.origin;
2253
2368
  extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
2254
2369
  origin: origin
2255
2370
  } : {});
@@ -2350,7 +2465,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2350
2465
  }, {
2351
2466
  key: "buildTempOrderHolderFromBookings",
2352
2467
  value: function buildTempOrderHolderFromBookings(tempOrder) {
2353
- var _baseHolder$customer_, _baseHolder, _ref45, _baseHolder$form_id, _baseHolder2, _tempOrder$holder5, _baseHolder3, _this$otherParams;
2468
+ var _baseHolder$customer_, _baseHolder, _ref46, _baseHolder$form_id, _baseHolder2, _tempOrder$holder3, _baseHolder3, _this$otherParams;
2354
2469
  var holderRecords = [];
2355
2470
  var holderNames = [];
2356
2471
  var baseHolder = null;
@@ -2397,7 +2512,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2397
2512
  }
2398
2513
  var nextHolder = {
2399
2514
  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,
2515
+ 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
2516
  form_record: holderRecords
2402
2517
  };
2403
2518
  if (holderNames.length) {
@@ -2492,15 +2607,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2492
2607
  hasDeposit: true
2493
2608
  } : undefined
2494
2609
  });
2610
+ var isExistingDepositDisabled = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0);
2495
2611
  tempOrder.deposit_amount = depositAmount;
2496
- tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
2497
- return nextSummary;
2612
+ tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
2613
+ return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
2498
2614
  }
2499
2615
  }, {
2500
2616
  key: "recalculateSummary",
2501
2617
  value: function () {
2502
2618
  var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(options) {
2503
- var _ref46, _salesSummaryResult$e;
2619
+ var _ref47, _salesSummaryResult$e;
2504
2620
  var tempOrder, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
2505
2621
  return _regeneratorRuntime().wrap(function _callee11$(_context13) {
2506
2622
  while (1) switch (_context13.prev = _context13.next) {
@@ -2573,7 +2689,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2573
2689
  roundingAmount = paidPaymentSummary.roundingAmount;
2574
2690
  payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
2575
2691
  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;
2692
+ 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
2693
  amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? _objectSpread({
2578
2694
  rounding_amount: roundingAmount.toFixed(2)
2579
2695
  }, expectAmount ? {
@@ -2751,17 +2867,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2751
2867
  }, {
2752
2868
  key: "buildTempOrderCustomer",
2753
2869
  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;
2870
+ 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
2871
  if (!params.customerId) return null;
2756
2872
  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;
2873
+ 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;
2874
+ 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
2875
  return _objectSpread(_objectSpread({}, source), {}, {
2760
2876
  id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
2761
2877
  customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
2762
2878
  name: String(name || ''),
2763
2879
  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),
2880
+ 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
2881
  phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
2766
2882
  email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
2767
2883
  });
@@ -2860,14 +2976,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2860
2976
  }, {
2861
2977
  key: "updateTempOrderCustomer",
2862
2978
  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;
2979
+ var _tempOrder$customer_i2, _ref55, _ref56, _customer$customer_id, _ref57, _ref58, _ref59, _customer$customer_na, _ref60, _customer$country_cal, _tempOrder$customer_i3;
2864
2980
  var tempOrder = this.ensureTempOrder();
2865
2981
  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 : '';
2982
+ 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;
2983
+ 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
2984
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
2869
2985
  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 : '');
2986
+ 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
2987
  tempOrder.phone = String(customer.phone || '');
2872
2988
  tempOrder.email = String(customer.email || '');
2873
2989
  tempOrder.customer = this.buildTempOrderCustomer({
@@ -2918,6 +3034,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2918
3034
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
2919
3035
  clearTempOrderHolderAssignments(tempOrder);
2920
3036
  this.clearCustomerBoundDiscounts(tempOrder);
3037
+ this.applyDiscount();
2921
3038
  }
2922
3039
  this.persistTempOrder();
2923
3040
  this.saveDraftInBackground();
@@ -3084,6 +3201,77 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3084
3201
  this.persistTempOrder();
3085
3202
  return tempOrder.payments;
3086
3203
  }
3204
+ }, {
3205
+ key: "confirmPendingVoucherPaymentsInList",
3206
+ value: function confirmPendingVoucherPaymentsInList(payments) {
3207
+ return (payments || []).map(function (payment) {
3208
+ if (!isPendingVoucherPaymentRecord(payment)) return payment;
3209
+ return _objectSpread(_objectSpread({}, payment), {}, {
3210
+ status: ORDER_PAYMENT_STATUS_PAID
3211
+ });
3212
+ });
3213
+ }
3214
+ }, {
3215
+ key: "discardPendingVoucherPaymentsFromList",
3216
+ value: function discardPendingVoucherPaymentsFromList(payments) {
3217
+ return (payments || []).filter(function (payment) {
3218
+ return !isPendingVoucherPaymentRecord(payment);
3219
+ });
3220
+ }
3221
+ }, {
3222
+ key: "prepareVoucherPaymentsForSubmit",
3223
+ value: function prepareVoucherPaymentsForSubmit(payments) {
3224
+ var confirmPendingVoucherPayments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
3225
+ var mappedPayments = mapPaymentItemsToOrderPayments(payments || []);
3226
+ return confirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : this.discardPendingVoucherPaymentsFromList(mappedPayments);
3227
+ }
3228
+ }, {
3229
+ key: "applyPaymentLifecycleChange",
3230
+ value: function applyPaymentLifecycleChange(tempOrder, options) {
3231
+ var _this19 = this;
3232
+ this.updateTempOrderPaymentStatus(tempOrder);
3233
+ if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3234
+ this.persistTempOrder();
3235
+ }
3236
+ if ((options === null || options === void 0 ? void 0 : options.recalculateSummary) === false) return;
3237
+ var logContext = (options === null || options === void 0 ? void 0 : options.logContext) || 'payment lifecycle change';
3238
+ void this.recalculateSummary({
3239
+ createIfMissing: true
3240
+ }).catch(function (error) {
3241
+ _this19.logError("recalculate summary after ".concat(logContext, " failed"), {
3242
+ error: error instanceof Error ? error.message : String(error)
3243
+ });
3244
+ });
3245
+ }
3246
+ }, {
3247
+ key: "confirmPendingVoucherPayments",
3248
+ value: function confirmPendingVoucherPayments(options) {
3249
+ var tempOrder = this.ensureTempOrder();
3250
+ var payments = tempOrder.payments || [];
3251
+ var hasPendingVoucher = payments.some(function (payment) {
3252
+ return isPendingVoucherPaymentRecord(payment);
3253
+ });
3254
+ if (!hasPendingVoucher) return payments;
3255
+ tempOrder.payments = this.confirmPendingVoucherPaymentsInList(payments);
3256
+ this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
3257
+ logContext: 'confirmPendingVoucherPayments'
3258
+ }));
3259
+ // this.recalculateSummary();
3260
+ return tempOrder.payments;
3261
+ }
3262
+ }, {
3263
+ key: "discardPendingVoucherPayments",
3264
+ value: function discardPendingVoucherPayments(options) {
3265
+ var tempOrder = this.ensureTempOrder();
3266
+ var payments = tempOrder.payments || [];
3267
+ var nextPayments = this.discardPendingVoucherPaymentsFromList(payments);
3268
+ if (nextPayments.length === payments.length) return payments;
3269
+ tempOrder.payments = nextPayments;
3270
+ this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
3271
+ logContext: 'discardPendingVoucherPayments'
3272
+ }));
3273
+ return tempOrder.payments;
3274
+ }
3087
3275
 
3088
3276
  /**
3089
3277
  * 覆盖当前订单中的 wallet pass 支付项。
@@ -3093,58 +3281,92 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3093
3281
  */
3094
3282
  }, {
3095
3283
  key: "updateVoucherOrderPayments",
3096
- value: function updateVoucherOrderPayments(payments) {
3097
- var _this19 = this;
3284
+ value: function updateVoucherOrderPayments(payments, options) {
3285
+ var _this20 = this;
3098
3286
  var tempOrder = this.ensureTempOrder();
3099
- var isVoucherPayment = function isVoucherPayment(payment) {
3100
- return payment.voucher_id !== undefined && Number(payment.voucher_id) !== 0;
3287
+ var isOrderPaymentType = function isOrderPaymentType(value) {
3288
+ return value === 'normal' || value === 'deposit';
3101
3289
  };
3102
- var hasSyncedOrderPayment = function hasSyncedOrderPayment(payment) {
3103
- return payment.order_payment_id !== undefined && payment.order_payment_id !== null;
3290
+ var voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
3291
+ var withVoucherPaymentType = function withVoucherPaymentType(payment) {
3292
+ var paymentRecord = payment;
3293
+ if (!isVoucherPaymentRecord(paymentRecord)) return payment;
3294
+ var explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : undefined;
3295
+ var nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
3296
+ var shouldPreserveCustomPaymentType = paymentRecord.custom_payment_type === undefined && paymentRecord.type !== undefined && !isOrderPaymentType(paymentRecord.type);
3297
+ return _objectSpread(_objectSpread(_objectSpread({}, paymentRecord), shouldPreserveCustomPaymentType ? {
3298
+ custom_payment_type: paymentRecord.type
3299
+ } : {}), {}, {
3300
+ type: nextPaymentType,
3301
+ order_payment_type: nextPaymentType
3302
+ });
3303
+ };
3304
+ var normalizeVoucherPaymentStatus = function normalizeVoucherPaymentStatus(payment) {
3305
+ var paymentRecord = payment;
3306
+ if (!isVoucherPaymentRecord(paymentRecord)) return payment;
3307
+ if (hasSyncedOrderPaymentRecord(paymentRecord) && (paymentRecord.status === undefined || paymentRecord.status === 'active')) {
3308
+ return _objectSpread(_objectSpread({}, paymentRecord), {}, {
3309
+ status: ORDER_PAYMENT_STATUS_PAID
3310
+ });
3311
+ }
3312
+ if (paymentRecord.status !== undefined && paymentRecord.status !== 'active') {
3313
+ return payment;
3314
+ }
3315
+ return _objectSpread(_objectSpread({}, paymentRecord), {}, {
3316
+ status: (options === null || options === void 0 ? void 0 : options.status) || ORDER_PAYMENT_STATUS_PENDING
3317
+ });
3104
3318
  };
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
3319
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3118
- return _this19.normalizePaymentSource(payment, {
3119
- defaultPaid: true
3320
+ return _this20.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3321
+ defaultPaid: false
3120
3322
  });
3121
3323
  })).filter(function (payment) {
3122
- return isVoucherPayment(payment);
3324
+ return isVoucherPaymentRecord(payment);
3123
3325
  });
3124
3326
  var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3125
- return !isVoucherPayment(payment);
3327
+ return !isVoucherPaymentRecord(payment);
3126
3328
  });
3127
- var syncedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3128
- return isVoucherPayment(payment) && hasSyncedOrderPayment(payment);
3329
+ var normalizeCommittedVoucherPayment = function normalizeCommittedVoucherPayment(payment) {
3330
+ if (hasSyncedOrderPaymentRecord(payment) && (payment.status === undefined || payment.status === 'active')) {
3331
+ return _objectSpread(_objectSpread({}, payment), {}, {
3332
+ status: ORDER_PAYMENT_STATUS_PAID
3333
+ });
3334
+ }
3335
+ return payment;
3336
+ };
3337
+ var committedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
3338
+ return isCommittedVoucherPaymentRecord(payment);
3339
+ }).map(function (payment) {
3340
+ return normalizeCommittedVoucherPayment(payment);
3129
3341
  });
3130
- var syncedVoucherPaymentIds = new Set(syncedVoucherPayments.map(function (payment) {
3342
+ var committedVoucherPaymentIds = new Set(committedVoucherPayments.filter(function (payment) {
3343
+ return hasSyncedOrderPaymentRecord(payment);
3344
+ }).map(function (payment) {
3131
3345
  return String(payment.order_payment_id);
3132
3346
  }));
3347
+ var committedVoucherIds = new Set(committedVoucherPayments.map(function (payment) {
3348
+ return String(payment.voucher_id);
3349
+ }));
3133
3350
  var replaceableVouchers = mappedVouchers.filter(function (payment) {
3134
- if (!hasSyncedOrderPayment(payment)) return true;
3135
- return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
3351
+ if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
3352
+ return false;
3353
+ }
3354
+ if (payment.voucher_id !== undefined && committedVoucherIds.has(String(payment.voucher_id))) {
3355
+ return false;
3356
+ }
3357
+ return true;
3136
3358
  });
3137
3359
  var cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
3138
3360
  vouchers: replaceableVouchers,
3139
- nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments))
3361
+ nonVoucherPayments: [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments))
3140
3362
  });
3141
- tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(syncedVoucherPayments), _toConsumableArray(cappedVouchers));
3363
+ tempOrder.payments = [].concat(_toConsumableArray(nonVoucherPayments), _toConsumableArray(committedVoucherPayments), _toConsumableArray(cappedVouchers));
3142
3364
  this.updateTempOrderPaymentStatus(tempOrder);
3143
3365
  this.persistTempOrder();
3144
3366
  void this.recalculateSummary({
3145
3367
  createIfMissing: true
3146
3368
  }).catch(function (error) {
3147
- _this19.logError('recalculate summary after updateVoucherOrderPayments failed', {
3369
+ _this20.logError('recalculate summary after updateVoucherOrderPayments failed', {
3148
3370
  error: error instanceof Error ? error.message : String(error)
3149
3371
  });
3150
3372
  });
@@ -3280,7 +3502,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3280
3502
  var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, product, booking) {
3281
3503
  var _booking_uid,
3282
3504
  _metadata,
3283
- _this20 = this;
3505
+ _this21 = this;
3284
3506
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3285
3507
  return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3286
3508
  while (1) switch (_context18.prev = _context18.next) {
@@ -3305,8 +3527,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3305
3527
  hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3306
3528
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3307
3529
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3308
- if (_this20.hasGoodPassDiscount(item)) return false;
3309
- if (_this20.hasOrderProductLineNote(item)) return false;
3530
+ if (_this21.hasGoodPassDiscount(item)) return false;
3531
+ if (_this21.hasOrderProductLineNote(item)) return false;
3310
3532
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3311
3533
  if (item.product_id !== productToAdd.product_id) return false;
3312
3534
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
@@ -3412,49 +3634,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3412
3634
  key: "addProductToOrder",
3413
3635
  value: (function () {
3414
3636
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(product, booking) {
3415
- var tempOrder, _ref60, _productRecord$num, productRecord, splitCount, i, singleLine;
3637
+ var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3416
3638
  return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3417
3639
  while (1) switch (_context19.prev = _context19.next) {
3418
3640
  case 0:
3419
3641
  tempOrder = this.ensureTempOrder();
3420
- debugger;
3421
3642
  if (!booking) {
3422
- _context19.next = 19;
3643
+ _context19.next = 18;
3423
3644
  break;
3424
3645
  }
3425
3646
  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);
3647
+ splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3427
3648
  if (!(splitCount > 1)) {
3428
- _context19.next = 19;
3649
+ _context19.next = 18;
3429
3650
  break;
3430
3651
  }
3431
3652
  i = 0;
3432
- case 7:
3653
+ case 6:
3433
3654
  if (!(i < splitCount)) {
3434
- _context19.next = 16;
3655
+ _context19.next = 15;
3435
3656
  break;
3436
3657
  }
3437
3658
  singleLine = cloneDeep(productRecord);
3438
3659
  singleLine.num = 1;
3439
3660
  delete singleLine.product_quantity;
3440
- _context19.next = 13;
3661
+ _context19.next = 12;
3441
3662
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3442
- case 13:
3663
+ case 12:
3443
3664
  i += 1;
3444
- _context19.next = 7;
3665
+ _context19.next = 6;
3445
3666
  break;
3446
- case 16:
3447
- _context19.next = 18;
3667
+ case 15:
3668
+ _context19.next = 17;
3448
3669
  return this.finalizeProductOrderMutation(tempOrder);
3449
- case 18:
3670
+ case 17:
3450
3671
  return _context19.abrupt("return", tempOrder.products);
3451
- case 19:
3452
- _context19.next = 21;
3672
+ case 18:
3673
+ _context19.next = 20;
3453
3674
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3454
- case 21:
3455
- _context19.next = 23;
3675
+ case 20:
3676
+ _context19.next = 22;
3456
3677
  return this.finalizeProductOrderMutation(tempOrder);
3457
- case 23:
3678
+ case 22:
3679
+ this.logInfo('addProductToOrder success', {
3680
+ product_id: product.product_id,
3681
+ with_booking: !!booking
3682
+ });
3458
3683
  return _context19.abrupt("return", tempOrder.products);
3459
3684
  case 24:
3460
3685
  case "end":
@@ -3481,7 +3706,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3481
3706
  key: "addProductsToOrder",
3482
3707
  value: (function () {
3483
3708
  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;
3709
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3485
3710
  return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3486
3711
  while (1) switch (_context20.prev = _context20.next) {
3487
3712
  case 0:
@@ -3513,7 +3738,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3513
3738
  break;
3514
3739
  }
3515
3740
  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);
3741
+ splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3517
3742
  if (!(splitCount > 1)) {
3518
3743
  _context20.next = 26;
3519
3744
  break;
@@ -3556,8 +3781,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3556
3781
  _context20.next = 40;
3557
3782
  return this.finalizeProductOrderMutation(tempOrder, options);
3558
3783
  case 40:
3784
+ this.logInfo('addProductsToOrder success', {
3785
+ itemsCount: items.length
3786
+ });
3559
3787
  return _context20.abrupt("return", tempOrder.products);
3560
- case 41:
3788
+ case 42:
3561
3789
  case "end":
3562
3790
  return _context20.stop();
3563
3791
  }
@@ -3590,24 +3818,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3590
3818
  }, {
3591
3819
  key: "getBundleRuntimeIdentity",
3592
3820
  value: function getBundleRuntimeIdentity(bundle) {
3593
- var _ref62, _bundle$bundle_id2, _ref63, _bundle$bundle_group_2, _ref64, _ref65, _bundle$bundle_produc3, _ref66, _bundle$bundle_varian3;
3821
+ var _ref63, _bundle$bundle_id2, _ref64, _bundle$bundle_group_2, _ref65, _ref66, _bundle$bundle_produc3, _ref67, _bundle$bundle_varian3;
3594
3822
  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('|');
3823
+ 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
3824
  }
3597
3825
  }, {
3598
3826
  key: "preservePersistedBundlePriceFields",
3599
3827
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
3600
- var _this21 = this;
3828
+ var _this22 = this;
3601
3829
  if (!Array.isArray(nextBundles)) return nextBundles;
3602
3830
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
3603
3831
  var previousByIdentity = new Map();
3604
3832
  previousBundles.forEach(function (bundle) {
3605
- var identity = _this21.getBundleRuntimeIdentity(bundle);
3833
+ var identity = _this22.getBundleRuntimeIdentity(bundle);
3606
3834
  if (identity) previousByIdentity.set(identity, bundle);
3607
3835
  });
3608
3836
  return nextBundles.map(function (bundle, index) {
3609
3837
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
3610
- var previous = previousByIdentity.get(_this21.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
3838
+ var previous = previousByIdentity.get(_this22.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
3611
3839
  if (!previous || _typeof(previous) !== 'object') return bundle;
3612
3840
  return _objectSpread(_objectSpread({}, bundle), {}, {
3613
3841
  price: previous.price,
@@ -3775,8 +4003,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3775
4003
  });
3776
4004
  case 8:
3777
4005
  this.persistTempOrder();
4006
+ this.logInfo('updateOrderProduct success', {
4007
+ params: params
4008
+ });
3778
4009
  return _context21.abrupt("return", tempOrder.products);
3779
- case 10:
4010
+ case 11:
3780
4011
  case "end":
3781
4012
  return _context21.stop();
3782
4013
  }
@@ -3791,7 +4022,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3791
4022
  key: "updateOrderProducts",
3792
4023
  value: function () {
3793
4024
  var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(paramsList) {
3794
- var _this22 = this;
4025
+ var _this23 = this;
3795
4026
  var tempOrder;
3796
4027
  return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3797
4028
  while (1) switch (_context22.prev = _context22.next) {
@@ -3804,13 +4035,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3804
4035
  return _context22.abrupt("return", tempOrder.products);
3805
4036
  case 3:
3806
4037
  paramsList.forEach(function (params) {
3807
- _this22.applyOrderProductUpdateToTempOrder(tempOrder, params);
4038
+ _this23.applyOrderProductUpdateToTempOrder(tempOrder, params);
3808
4039
  });
3809
4040
  _context22.next = 6;
3810
4041
  return this.finalizeAfterProductsMutation(tempOrder);
3811
4042
  case 6:
4043
+ this.logInfo('updateOrderProduct success', {
4044
+ paramsList: paramsList
4045
+ });
3812
4046
  return _context22.abrupt("return", tempOrder.products);
3813
- case 7:
4047
+ case 8:
3814
4048
  case "end":
3815
4049
  return _context22.stop();
3816
4050
  }
@@ -3882,8 +4116,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3882
4116
  });
3883
4117
  case 22:
3884
4118
  this.persistTempOrder();
4119
+ this.logInfo('updateOrderProductQuantity success', {
4120
+ params: params
4121
+ });
3885
4122
  return _context23.abrupt("return", tempOrder.products);
3886
- case 24:
4123
+ case 25:
3887
4124
  case "end":
3888
4125
  return _context23.stop();
3889
4126
  }
@@ -3968,7 +4205,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3968
4205
  key: "removeProductsFromOrder",
3969
4206
  value: (function () {
3970
4207
  var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(identities) {
3971
- var _this23 = this;
4208
+ var _this24 = this;
3972
4209
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
3973
4210
  return _regeneratorRuntime().wrap(function _callee23$(_context26) {
3974
4211
  while (1) switch (_context26.prev = _context26.next) {
@@ -4023,7 +4260,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4023
4260
  }
4024
4261
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4025
4262
  bookingsBeforeRemove.forEach(function (booking) {
4026
- var bookingUid = _this23.getBookingUniqueIdentificationNumber(booking);
4263
+ var bookingUid = _this24.getBookingUniqueIdentificationNumber(booking);
4027
4264
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4028
4265
  linkedBookingUidsToRemove.add(bookingUid);
4029
4266
  }
@@ -4075,8 +4312,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4075
4312
  _context26.next = 31;
4076
4313
  return this.finalizeAfterProductsMutation(tempOrder);
4077
4314
  case 31:
4315
+ this.logInfo('removeProductsFromOrder success', {
4316
+ identities: identities
4317
+ });
4078
4318
  return _context26.abrupt("return", tempOrder.products);
4079
- case 32:
4319
+ case 33:
4080
4320
  case "end":
4081
4321
  return _context26.stop();
4082
4322
  }
@@ -4138,8 +4378,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4138
4378
  });
4139
4379
  case 11:
4140
4380
  this.persistTempOrder();
4381
+ this.logInfo('clearOrderCartLines success', {});
4141
4382
  return _context28.abrupt("return", tempOrder);
4142
- case 13:
4383
+ case 14:
4143
4384
  case "end":
4144
4385
  return _context28.stop();
4145
4386
  }
@@ -4154,23 +4395,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4154
4395
  }, {
4155
4396
  key: "buildCurrentSubmitPayloadForLocalPrint",
4156
4397
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
4157
- var _params$cacheId, _this$otherParams2, _ref67, _params$businessCode, _this$otherParams3, _this$otherParams4;
4398
+ var _params$cacheId, _this$otherParams2, _ref68, _params$businessCode, _this$otherParams3, _this$otherParams4;
4158
4399
  var tempOrder = this.ensureTempOrder();
4159
4400
  this.persistTempOrder();
4160
4401
  var payload = buildSubmitPayload({
4161
4402
  tempOrder: tempOrder,
4162
4403
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
4163
4404
  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,
4405
+ businessCode: (_ref68 = (_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 && _ref68 !== void 0 ? _ref68 : (_this$otherParams4 = this.otherParams) === null || _this$otherParams4 === void 0 ? void 0 : _this$otherParams4.business_code,
4165
4406
  channel: params === null || params === void 0 ? void 0 : params.channel,
4166
4407
  type: params === null || params === void 0 ? void 0 : params.type,
4167
4408
  summary: this.store.summary || createEmptySummary(),
4168
4409
  enhance: function enhance(nextPayload) {
4169
- var _ref68, _tempOrder$order_numb, _ref69, _tempOrder$shop_order, _ref70, _tempOrder$shop_full_;
4410
+ var _ref69, _tempOrder$order_numb, _ref70, _tempOrder$shop_order, _ref71, _tempOrder$shop_full_;
4170
4411
  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,
4412
+ 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,
4413
+ 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,
4414
+ 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
4415
  small_ticket_data_flag: 1
4175
4416
  });
4176
4417
  }
@@ -4267,41 +4508,56 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4267
4508
  key: "runSubmitTempOrder",
4268
4509
  value: function () {
4269
4510
  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;
4511
+ var _params$cacheId2, _this$otherParams5, _ref72, _ref73, _submitSnapshot$busin, _this$otherParams6, _this$otherParams7, _submitSnapshot$type;
4512
+ var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4272
4513
  return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4273
4514
  while (1) switch (_context32.prev = _context32.next) {
4274
4515
  case 0:
4275
4516
  tempOrder = this.ensureTempOrder();
4517
+ shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
4518
+ hasPaymentOverride = (params === null || params === void 0 ? void 0 : params.payments) !== undefined;
4519
+ preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit((params === null || params === void 0 ? void 0 : params.payments) || [], shouldConfirmPendingVoucherPayments) : undefined;
4520
+ if (!hasPaymentOverride) {
4521
+ if (shouldConfirmPendingVoucherPayments) {
4522
+ this.confirmPendingVoucherPayments({
4523
+ persist: false,
4524
+ recalculateSummary: false
4525
+ });
4526
+ } else {
4527
+ this.discardPendingVoucherPayments({
4528
+ persist: false,
4529
+ recalculateSummary: false
4530
+ });
4531
+ }
4532
+ }
4276
4533
  this.persistTempOrder();
4277
- _context32.next = 4;
4534
+ _context32.next = 8;
4278
4535
  return this.recalculateSummary({
4279
4536
  createIfMissing: true
4280
4537
  });
4281
- case 4:
4538
+ case 8:
4282
4539
  _context32.t1 = _context32.sent;
4283
4540
  if (_context32.t1) {
4284
- _context32.next = 7;
4541
+ _context32.next = 11;
4285
4542
  break;
4286
4543
  }
4287
4544
  _context32.t1 = this.store.summary;
4288
- case 7:
4545
+ case 11:
4289
4546
  _context32.t0 = _context32.t1;
4290
4547
  if (_context32.t0) {
4291
- _context32.next = 10;
4548
+ _context32.next = 14;
4292
4549
  break;
4293
4550
  }
4294
4551
  _context32.t0 = createEmptySummary();
4295
- case 10:
4552
+ case 14:
4296
4553
  latestSummary = _context32.t0;
4297
4554
  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
4555
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4300
4556
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4301
4557
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
4302
4558
  var nextPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, payload), hasPaymentOverride ? {
4303
- payments: mapPaymentItemsToOrderPayments((params === null || params === void 0 ? void 0 : params.payments) || [])
4304
- } : {}), hasPaymentStatusOverride ? {
4559
+ payments: preparedPaymentOverride || []
4560
+ } : {}), hasPaymentStatusOverride && !shouldConfirmPendingVoucherPayments ? {
4305
4561
  payment_status: params === null || params === void 0 ? void 0 : params.paymentStatus
4306
4562
  } : {}), hasSmallTicketDataFlagOverride ? {
4307
4563
  small_ticket_data_flag: params === null || params === void 0 ? void 0 : params.smallTicketDataFlag
@@ -4309,17 +4565,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4309
4565
  var enhancedPayload = params !== null && params !== void 0 && params.enhancePayload ? params.enhancePayload(nextPayload, ctx) : nextPayload;
4310
4566
  return enhancedPayload;
4311
4567
  } : undefined;
4568
+ submitSnapshot = this.getLastOrderSubmitSnapshot();
4312
4569
  payload = buildSubmitPayload({
4313
4570
  tempOrder: tempOrder,
4314
4571
  cacheId: effectiveCacheId,
4315
4572
  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,
4573
+ 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$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
4317
4574
  channel: params === null || params === void 0 ? void 0 : params.channel,
4318
- type: params === null || params === void 0 ? void 0 : params.type,
4575
+ type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4319
4576
  summary: latestSummary,
4320
4577
  request_unique_idempotency_token: params === null || params === void 0 ? void 0 : params.request_unique_idempotency_token,
4321
4578
  enhance: enhancePayload
4322
4579
  });
4580
+ console.log('[Order.runSubmitTempOrder.payload]', payload);
4323
4581
  if (params !== null && params !== void 0 && params.syncMode) {
4324
4582
  payload.sync_mode = true;
4325
4583
  }
@@ -4327,10 +4585,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4327
4585
  if (!payload.created_at) {
4328
4586
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4329
4587
  }
4330
- _context32.next = 21;
4588
+ _context32.next = 26;
4331
4589
  return this.saveDraft();
4332
- case 21:
4333
- _context32.prev = 21;
4590
+ case 26:
4591
+ _context32.prev = 26;
4334
4592
  this.logInfo('submitTempOrder calling sales checkout', {
4335
4593
  orderId: payload.order_id,
4336
4594
  externalSaleNumber: payload.external_sale_number,
@@ -4340,26 +4598,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4340
4598
  smallTicketDataFlag: payload.small_ticket_data_flag,
4341
4599
  syncMode: payload.sync_mode
4342
4600
  });
4343
- _context32.next = 25;
4601
+ _context32.next = 30;
4344
4602
  return this.submitSalesOrder({
4345
4603
  query: payload
4346
4604
  });
4347
- case 25:
4605
+ case 30:
4348
4606
  result = _context32.sent;
4349
- _context32.next = 38;
4607
+ _context32.next = 43;
4350
4608
  break;
4351
- case 28:
4352
- _context32.prev = 28;
4353
- _context32.t2 = _context32["catch"](21);
4609
+ case 33:
4610
+ _context32.prev = 33;
4611
+ _context32.t2 = _context32["catch"](26);
4354
4612
  backendErrorResponse = this.extractSubmitErrorResponse(_context32.t2);
4355
4613
  if (!backendErrorResponse) {
4356
- _context32.next = 35;
4614
+ _context32.next = 40;
4357
4615
  break;
4358
4616
  }
4359
4617
  this.store.syncState = 'failed';
4360
4618
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4361
4619
  return _context32.abrupt("return", backendErrorResponse);
4362
- case 35:
4620
+ case 40:
4363
4621
  this.store.syncState = 'failed';
4364
4622
  this.logError('submitTempOrder failed', {
4365
4623
  error: _context32.t2 instanceof Error ? _context32.t2.message : String(_context32.t2),
@@ -4369,45 +4627,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4369
4627
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4370
4628
  });
4371
4629
  throw _context32.t2;
4372
- case 38:
4630
+ case 43:
4373
4631
  if (!this.isSubmitResponseRejected(result)) {
4374
- _context32.next = 42;
4632
+ _context32.next = 47;
4375
4633
  break;
4376
4634
  }
4377
4635
  this.store.syncState = 'failed';
4378
4636
  this.logSubmitBackendRejected(result, payload);
4379
4637
  return _context32.abrupt("return", result);
4380
- case 42:
4638
+ case 47:
4381
4639
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4382
4640
  this.logInfo('runSubmitTempOrder: 提交成功', {
4383
4641
  submittedOrderId: submittedOrderId,
4384
4642
  result: result,
4385
- tempOrder: tempOrder
4643
+ tempOrder: _objectSpread(_objectSpread({}, tempOrder), {}, {
4644
+ _extend: undefined
4645
+ })
4386
4646
  });
4387
4647
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4388
- _context32.next = 51;
4648
+ _context32.next = 56;
4389
4649
  break;
4390
4650
  }
4391
4651
  tempOrder.order_id = submittedOrderId;
4392
4652
  resultRecord = result;
4393
- _context32.next = 49;
4653
+ _context32.next = 54;
4394
4654
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4395
- case 49:
4396
- _context32.next = 52;
4655
+ case 54:
4656
+ _context32.next = 57;
4397
4657
  break;
4398
- case 51:
4658
+ case 56:
4399
4659
  if (this.isLocalPendingSubmitResult(result)) {
4400
4660
  this.store.syncState = 'local';
4401
4661
  } else {
4402
4662
  this.store.syncState = 'submitted';
4403
4663
  }
4404
- case 52:
4664
+ case 57:
4405
4665
  return _context32.abrupt("return", result);
4406
- case 53:
4666
+ case 58:
4407
4667
  case "end":
4408
4668
  return _context32.stop();
4409
4669
  }
4410
- }, _callee29, this, [[21, 28]]);
4670
+ }, _callee29, this, [[26, 33]]);
4411
4671
  }));
4412
4672
  function runSubmitTempOrder(_x32) {
4413
4673
  return _runSubmitTempOrder.apply(this, arguments);
@@ -4479,10 +4739,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4479
4739
  value: function extractSubmitErrorResponse(error) {
4480
4740
  var _error$response,
4481
4741
  _error$response2,
4482
- _this24 = this;
4742
+ _this25 = this;
4483
4743
  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
4744
  return candidates.find(function (candidate) {
4485
- return _this24.isSubmitErrorResponse(candidate);
4745
+ return _this25.isSubmitErrorResponse(candidate);
4486
4746
  }) || null;
4487
4747
  }
4488
4748
  }, {
@@ -4510,47 +4770,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4510
4770
  key: "syncPaymentsToOrder",
4511
4771
  value: function () {
4512
4772
  var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4513
- var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, paymentStatus, paymentSyncIdempotencyToken, submitResult;
4773
+ var _params$confirmPendin;
4774
+ var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, paidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
4514
4775
  return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4515
4776
  while (1) switch (_context34.prev = _context34.next) {
4516
4777
  case 0:
4517
4778
  tempOrder = this.ensureTempOrder();
4518
4779
  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;
4780
+ shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
4781
+ effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
4782
+ completion = this.getPaymentCompletion(effectivePayments);
4783
+ paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
4784
+ paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || 'paid' : paidPaymentTotal.gt(0) ? 'partially_paid' : 'payment_processing';
4785
+ tempOrder.payments = effectivePayments;
4524
4786
  tempOrder.payment_status = paymentStatus;
4525
4787
  this.persistTempOrder();
4526
- _context34.next = 11;
4788
+ _context34.next = 12;
4527
4789
  return this.saveDraft();
4528
- case 11:
4790
+ case 12:
4529
4791
  if (params.submitWhenPaid) {
4530
- _context34.next = 13;
4792
+ _context34.next = 14;
4531
4793
  break;
4532
4794
  }
4533
- return _context34.abrupt("return", {
4534
- isFullyPaid: isFullyPaid
4535
- });
4536
- case 13:
4795
+ return _context34.abrupt("return", completion);
4796
+ case 14:
4537
4797
  if (!(this.store.syncState === 'submitting')) {
4538
- _context34.next = 15;
4798
+ _context34.next = 16;
4539
4799
  break;
4540
4800
  }
4541
- return _context34.abrupt("return", {
4542
- isFullyPaid: isFullyPaid
4543
- });
4544
- case 15:
4801
+ return _context34.abrupt("return", completion);
4802
+ case 16:
4545
4803
  this.store.syncState = 'submitting';
4546
- paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, mappedPayments);
4547
- _context34.next = 19;
4804
+ paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
4805
+ _context34.next = 20;
4548
4806
  return this.submitTempOrder({
4549
- payments: mappedPayments,
4807
+ payments: effectivePayments,
4550
4808
  paymentStatus: paymentStatus,
4551
4809
  smallTicketDataFlag: params.smallTicketDataFlag,
4552
4810
  businessCode: params.businessCode,
4553
4811
  channel: params.channel,
4812
+ confirmPendingVoucherPayments: true,
4554
4813
  enhancePayload: function enhancePayload(payload) {
4555
4814
  var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
4556
4815
  request_unique_idempotency_token: paymentSyncIdempotencyToken
@@ -4558,13 +4817,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4558
4817
  return nextPayload;
4559
4818
  }
4560
4819
  });
4561
- case 19:
4820
+ case 20:
4562
4821
  submitResult = _context34.sent;
4563
- return _context34.abrupt("return", {
4564
- isFullyPaid: isFullyPaid,
4822
+ return _context34.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
4565
4823
  submitResult: submitResult
4566
- });
4567
- case 21:
4824
+ }));
4825
+ case 22:
4568
4826
  case "end":
4569
4827
  return _context34.stop();
4570
4828
  }
@@ -5077,27 +5335,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5077
5335
  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
5336
  shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
5079
5337
  if (shouldSkipEmptyDiscountSync) {
5080
- _context42.next = 16;
5338
+ _context42.next = 17;
5081
5339
  break;
5082
5340
  }
5083
- _context42.next = 14;
5341
+ OrderModule.populateSavedAmounts(nextTempOrder.products, hydratedEditDiscounts);
5342
+ _context42.next = 15;
5084
5343
  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;
5344
+ case 15:
5345
+ _context42.next = 17;
5087
5346
  return (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList(hydratedEditDiscounts);
5088
- case 16:
5347
+ case 17:
5089
5348
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5090
- _context42.next = 19;
5349
+ _context42.next = 20;
5091
5350
  break;
5092
5351
  }
5093
- _context42.next = 19;
5352
+ _context42.next = 20;
5094
5353
  return this.recalculateSummary({
5095
5354
  createIfMissing: false
5096
5355
  });
5097
- case 19:
5356
+ case 20:
5098
5357
  this.persistTempOrder();
5099
5358
  return _context42.abrupt("return", nextTempOrder);
5100
- case 21:
5359
+ case 22:
5101
5360
  case "end":
5102
5361
  return _context42.stop();
5103
5362
  }
@@ -5144,7 +5403,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5144
5403
  }, {
5145
5404
  key: "normalizeTempOrderForRuntime",
5146
5405
  value: function normalizeTempOrderForRuntime(raw, options) {
5147
- var _this25 = this;
5406
+ var _this26 = this;
5148
5407
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
5149
5408
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5150
5409
  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 +5426,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5167
5426
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5168
5427
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5169
5428
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5170
- return _this25.normalizeHydratedOrderProduct(p);
5429
+ return _this26.normalizeHydratedOrderProduct(p);
5171
5430
  }) : [];
5172
5431
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5173
- var booking = _this25.normalizeHydratedBookingHolder(b || {});
5432
+ var booking = _this26.normalizeHydratedBookingHolder(b || {});
5174
5433
  return _objectSpread(_objectSpread({}, booking), {}, {
5175
5434
  is_all: normalizeBookingIsAll(booking),
5176
5435
  sub_type: normalizeBookingSubType(booking)
@@ -5200,7 +5459,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5200
5459
  _step22;
5201
5460
  try {
5202
5461
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
5203
- var _product$metadata8, _ref72, _ref73, _existed$origin, _rawProduct$metadata;
5462
+ var _product$metadata8, _ref74, _ref75, _existed$origin, _rawProduct$metadata;
5204
5463
  var _step22$value = _slicedToArray(_step22.value, 2),
5205
5464
  index = _step22$value[0],
5206
5465
  product = _step22$value[1];
@@ -5208,7 +5467,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5208
5467
  if (!uid) continue;
5209
5468
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
5210
5469
  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;
5470
+ 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
5471
  var originSnapshot = cloneDeep(origin);
5213
5472
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
5214
5473
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -5318,10 +5577,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5318
5577
  }, {
5319
5578
  key: "normalizeHydratedProductOptionItem",
5320
5579
  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;
5580
+ var _ref76, _optionItem$num, _ref77, _optionItem$add_price;
5581
+ 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
5582
  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;
5583
+ 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
5584
  var parsedPrice = Number(rawPrice);
5326
5585
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
5327
5586
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -5338,7 +5597,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5338
5597
  }, {
5339
5598
  key: "normalizeHydratedOrderProduct",
5340
5599
  value: function normalizeHydratedOrderProduct(product) {
5341
- var _this26 = this;
5600
+ var _this27 = this;
5342
5601
  var row = _objectSpread({}, product || {});
5343
5602
  if (row.num === undefined && row.product_quantity !== undefined) {
5344
5603
  row.num = row.product_quantity;
@@ -5346,7 +5605,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5346
5605
  var productSku = ensureProductSku(row);
5347
5606
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5348
5607
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5349
- return _this26.normalizeHydratedProductOptionItem(optionItem || {});
5608
+ return _this27.normalizeHydratedProductOptionItem(optionItem || {});
5350
5609
  }))
5351
5610
  });
5352
5611
  delete row["product_".concat('option', "_item")];
@@ -5355,6 +5614,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5355
5614
  if (row.booking_uid && !row.metadata.booking_uid) {
5356
5615
  row.metadata.booking_uid = row.booking_uid;
5357
5616
  }
5617
+ row = restoreHydratedBundleDiscounts(row, normalizeOrderProductDiscountList);
5358
5618
  var existingIdentity = row.metadata.unique_identification_number || row.unique_identification_number;
5359
5619
  if (!existingIdentity) {
5360
5620
  row.metadata.unique_identification_number = createUuidV4();
@@ -5366,7 +5626,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5366
5626
  metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
5367
5627
  });
5368
5628
  if (result.metadata) delete result.metadata.price_schema_version;
5369
- return this.sanitizeOrderProductForTempOrder(result);
5629
+ var restored = restoreHydratedBundleDiscounts(result, normalizeOrderProductDiscountList);
5630
+ return this.sanitizeOrderProductForTempOrder(restored);
5370
5631
  }
5371
5632
  }, {
5372
5633
  key: "getLastOrderInfo",
@@ -5402,6 +5663,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5402
5663
  }
5403
5664
  return getOrderInfo;
5404
5665
  }()
5666
+ }, {
5667
+ key: "getVouchers",
5668
+ value: function getVouchers() {
5669
+ var _this$store$tempOrder5;
5670
+ return ((_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.vouchers) || [];
5671
+ }
5405
5672
  }], [{
5406
5673
  key: "populateSavedAmounts",
5407
5674
  value: function populateSavedAmounts(productList, discountList) {
@@ -5450,10 +5717,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5450
5717
  _step27;
5451
5718
  try {
5452
5719
  for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
5453
- var _ref76, _bundle$num3;
5720
+ var _ref78, _bundle$num3;
5454
5721
  var bundle = _step27.value;
5455
5722
  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();
5723
+ 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
5724
  var _iterator28 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
5458
5725
  _step28;
5459
5726
  try {