@pisell/pisellos 2.3.6 → 2.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +17 -13
- package/dist/modules/Order/index.d.ts +18 -2
- package/dist/modules/Order/index.js +392 -222
- package/dist/modules/Order/types.d.ts +15 -2
- package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
- package/dist/modules/Order/utils.d.ts +4 -0
- package/dist/modules/Order/utils.js +114 -28
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.d.ts +3 -3
- package/dist/modules/Rules/index.js +8 -3
- package/dist/modules/Rules/types.d.ts +2 -1
- package/dist/server/index.js +1 -0
- package/dist/server/modules/order/index.d.ts +4 -4
- package/dist/server/modules/order/index.js +4 -4
- package/dist/solution/BaseSales/index.d.ts +8 -1
- package/dist/solution/BaseSales/index.js +145 -104
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -2
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -1
- package/lib/modules/Order/index.d.ts +18 -2
- package/lib/modules/Order/index.js +229 -40
- package/lib/modules/Order/types.d.ts +15 -2
- package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/lib/modules/Order/utils/bundleDiscountHydration.js +139 -0
- package/lib/modules/Order/utils.d.ts +4 -0
- package/lib/modules/Order/utils.js +84 -2
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.d.ts +3 -3
- package/lib/modules/Rules/index.js +4 -3
- package/lib/modules/Rules/types.d.ts +2 -1
- package/lib/server/modules/order/index.d.ts +4 -4
- package/lib/server/modules/order/index.js +4 -4
- package/lib/solution/BaseSales/index.d.ts +8 -1
- package/lib/solution/BaseSales/index.js +58 -22
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -5
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- 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,20 @@ 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
|
+
}
|
|
67
82
|
export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
68
83
|
_inherits(OrderModule, _BaseModule);
|
|
69
84
|
var _super = _createSuper(OrderModule);
|
|
@@ -108,7 +123,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
108
123
|
key: "collectHydratedEditDiscounts",
|
|
109
124
|
value: function collectHydratedEditDiscounts(products) {
|
|
110
125
|
var discountMap = new Map();
|
|
111
|
-
var _iterator = _createForOfIteratorHelper(products
|
|
126
|
+
var _iterator = _createForOfIteratorHelper(expandHydratedProductsForDiscountCollection(products)),
|
|
112
127
|
_step;
|
|
113
128
|
try {
|
|
114
129
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -138,6 +153,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
138
153
|
discount: item === null || item === void 0 ? void 0 : item.discount,
|
|
139
154
|
_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
155
|
};
|
|
156
|
+
var existed = discountMap.get(key);
|
|
157
|
+
if (existed) {
|
|
158
|
+
existed.amount = Number(existed.amount || 0) + amount;
|
|
159
|
+
existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
|
|
160
|
+
existed.balance = String(Number(existed.balance || 0) + amount);
|
|
161
|
+
existed.applicableProductDetails = [].concat(_toConsumableArray(existed.applicableProductDetails || []), [detail]);
|
|
162
|
+
existed.appliedProductDetails = [].concat(_toConsumableArray(existed.appliedProductDetails || []), [detail]);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
141
165
|
discountMap.set(key, {
|
|
142
166
|
id: key,
|
|
143
167
|
product_name: '',
|
|
@@ -224,6 +248,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
224
248
|
product.metadata.main_product_selling_price = newMainSellingPrice;
|
|
225
249
|
product.metadata.price_schema_version = 2;
|
|
226
250
|
}
|
|
251
|
+
if (Array.isArray(product.product_bundle)) {
|
|
252
|
+
product.product_bundle = product.product_bundle.map(function (bundle) {
|
|
253
|
+
var _ref12, _bundle$original_pric;
|
|
254
|
+
var hasBundleDiscount = Array.isArray(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) && bundle.discount_list.length > 0;
|
|
255
|
+
if (hasBundleDiscount) return bundle;
|
|
256
|
+
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;
|
|
257
|
+
if (restoredPrice === undefined || restoredPrice === null || restoredPrice === '') return bundle;
|
|
258
|
+
return _objectSpread(_objectSpread({}, bundle), {}, {
|
|
259
|
+
price: restoredPrice,
|
|
260
|
+
bundle_selling_price: restoredPrice
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
227
264
|
product.selling_price = composeLinePrice({
|
|
228
265
|
mainPrice: newMainSellingPrice,
|
|
229
266
|
bundle: product.product_bundle
|
|
@@ -553,8 +590,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
553
590
|
key: "scanCode",
|
|
554
591
|
value: function () {
|
|
555
592
|
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
|
|
556
|
-
var _this$store$discount7, _tempOrder$holder, _this$store$summary
|
|
557
|
-
var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders,
|
|
593
|
+
var _this$store$discount7, _tempOrder$holder, _this$store$summary;
|
|
594
|
+
var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, unavailableReason, _this$store$discount8;
|
|
558
595
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
559
596
|
while (1) switch (_context5.prev = _context5.next) {
|
|
560
597
|
case 0:
|
|
@@ -624,20 +661,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
624
661
|
});
|
|
625
662
|
case 16:
|
|
626
663
|
tempOrder = this.store.tempOrder;
|
|
627
|
-
holders = tempOrder
|
|
628
|
-
|
|
629
|
-
}] : [];
|
|
630
|
-
_ref12 = rulesModule.isDiscountListAvailable({
|
|
664
|
+
holders = (tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
|
|
665
|
+
_ref13 = rulesModule.isDiscountListAvailable({
|
|
631
666
|
productList: (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products) || [],
|
|
632
667
|
oldDiscountList: this.getDiscountList(),
|
|
633
668
|
newDiscountList: withScanList,
|
|
634
669
|
orderTotalAmount: Number(((_this$store$summary = this.store.summary) === null || _this$store$summary === void 0 ? void 0 : _this$store$summary.total_amount) || 0),
|
|
635
670
|
holders: holders,
|
|
636
|
-
isFormSubject:
|
|
671
|
+
isFormSubject: function isFormSubject(product) {
|
|
672
|
+
return resolveIsFormSubject(tempOrder, product);
|
|
673
|
+
}
|
|
637
674
|
}) || {
|
|
638
675
|
isAvailable: false,
|
|
639
676
|
discountList: this.getDiscountList()
|
|
640
|
-
}, isAvailable =
|
|
677
|
+
}, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, unavailableReason = _ref13.unavailableReason;
|
|
641
678
|
if (isAvailable && newDiscountList) {
|
|
642
679
|
(_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(newDiscountList);
|
|
643
680
|
this.applyDiscount();
|
|
@@ -664,8 +701,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
664
701
|
key: "applyDiscount",
|
|
665
702
|
value: function applyDiscount() {
|
|
666
703
|
var _this$store$discount9,
|
|
667
|
-
_tempOrder$
|
|
668
|
-
_tempOrder$holder4,
|
|
704
|
+
_tempOrder$holder2,
|
|
669
705
|
_this$store$summary2,
|
|
670
706
|
_this2 = this;
|
|
671
707
|
var tempOrder = this.store.tempOrder;
|
|
@@ -674,26 +710,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
674
710
|
// appliedProductDetails / savedAmount 复位。
|
|
675
711
|
if (!tempOrder) return;
|
|
676
712
|
delete tempOrder.discount_list;
|
|
677
|
-
|
|
713
|
+
var discountList = ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.getDiscountList()) || [];
|
|
714
|
+
var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
|
|
715
|
+
if (shouldSkipDiscountCalculation) return;
|
|
678
716
|
var rulesModule = this.store.rules;
|
|
679
717
|
if (!rulesModule) return;
|
|
680
|
-
var
|
|
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
|
-
}] : [];
|
|
718
|
+
var holders = ((_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_record) || [];
|
|
684
719
|
var result = rulesModule.calcDiscount({
|
|
685
720
|
productList: tempOrder.products,
|
|
686
721
|
discountList: discountList,
|
|
687
722
|
holders: holders,
|
|
688
|
-
isFormSubject:
|
|
723
|
+
isFormSubject: function isFormSubject(product) {
|
|
724
|
+
return resolveIsFormSubject(tempOrder, product);
|
|
725
|
+
},
|
|
689
726
|
orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
|
|
690
727
|
});
|
|
691
728
|
if (result !== null && result !== void 0 && result.productList) {
|
|
692
729
|
var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
|
|
693
730
|
tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
|
|
694
|
-
var
|
|
731
|
+
var _ref14;
|
|
695
732
|
var uid = getOrderProductLineUid(product);
|
|
696
|
-
var previous = (
|
|
733
|
+
var previous = (_ref14 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref14 !== void 0 ? _ref14 : previousProductsByUid.get("__index__:".concat(index));
|
|
697
734
|
if (isManualProductDiscountProduct(previous)) {
|
|
698
735
|
return previous;
|
|
699
736
|
}
|
|
@@ -1218,15 +1255,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1218
1255
|
}, {
|
|
1219
1256
|
key: "extractOrderIdFromSubmitResult",
|
|
1220
1257
|
value: function extractOrderIdFromSubmitResult(result) {
|
|
1221
|
-
var
|
|
1222
|
-
return (
|
|
1258
|
+
var _ref15, _ref16, _ref17, _result$data$order_id, _result$data, _result$data2;
|
|
1259
|
+
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
1260
|
}
|
|
1224
1261
|
}, {
|
|
1225
1262
|
key: "calculatePaymentEffectiveAmount",
|
|
1226
1263
|
value: function calculatePaymentEffectiveAmount(payment) {
|
|
1227
|
-
var
|
|
1264
|
+
var _ref18, _payment$origin_amoun;
|
|
1228
1265
|
var amount = new Decimal(payment.amount || 0);
|
|
1229
|
-
var originAmount = new Decimal((
|
|
1266
|
+
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
1267
|
var serviceFee = new Decimal(payment.service_fee || 0);
|
|
1231
1268
|
// TODO: 后端允许 amount 表示顾客实际支付总额后,移除这个兼容分支。
|
|
1232
1269
|
var effectiveAmount = serviceFee.gt(0) && amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
|
|
@@ -1240,6 +1277,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1240
1277
|
return mapPaymentItemsToOrderPayments(payments, {
|
|
1241
1278
|
includeVoided: false
|
|
1242
1279
|
}).reduce(function (sum, payment) {
|
|
1280
|
+
if (!isPaidPaymentRecord(payment)) return sum;
|
|
1243
1281
|
return sum.plus(_this4.calculatePaymentEffectiveAmount(payment));
|
|
1244
1282
|
}, new Decimal(0));
|
|
1245
1283
|
}
|
|
@@ -1315,13 +1353,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1315
1353
|
})
|
|
1316
1354
|
});
|
|
1317
1355
|
tempOrder.deposit_amount = snapshot.depositAmount;
|
|
1318
|
-
tempOrder.is_deposit = snapshot.isDeposit;
|
|
1356
|
+
tempOrder.is_deposit = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0) ? 0 : snapshot.isDeposit;
|
|
1319
1357
|
return nextSummary;
|
|
1320
1358
|
}
|
|
1321
1359
|
}, {
|
|
1322
1360
|
key: "isDepositOrder",
|
|
1323
1361
|
value: function isDepositOrder(tempOrder, depositAmount) {
|
|
1324
|
-
return tempOrder.is_deposit === 1
|
|
1362
|
+
return tempOrder.is_deposit === 1 && depositAmount.gt(0);
|
|
1325
1363
|
}
|
|
1326
1364
|
}, {
|
|
1327
1365
|
key: "getOrderExpectedAmount",
|
|
@@ -1368,7 +1406,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1368
1406
|
var _this5 = this;
|
|
1369
1407
|
return (payments || []).reduce(function (sum, payment) {
|
|
1370
1408
|
var paymentRecord = payment;
|
|
1371
|
-
if ((paymentRecord
|
|
1409
|
+
if (!isPaidPaymentRecord(paymentRecord)) return sum;
|
|
1372
1410
|
var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
|
|
1373
1411
|
if (!isDepositPayment) return sum;
|
|
1374
1412
|
if (paymentRecord.origin_amount !== undefined && paymentRecord.origin_amount !== null && paymentRecord.origin_amount !== '') {
|
|
@@ -1390,7 +1428,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1390
1428
|
}, {
|
|
1391
1429
|
key: "normalizePaymentSource",
|
|
1392
1430
|
value: function normalizePaymentSource(payment, options) {
|
|
1393
|
-
var
|
|
1431
|
+
var _ref19, _paymentRecord$origin;
|
|
1394
1432
|
var paymentRecord = payment;
|
|
1395
1433
|
var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
|
|
1396
1434
|
if (!metadata.unique_payment_number) {
|
|
@@ -1398,7 +1436,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1398
1436
|
}
|
|
1399
1437
|
var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
|
|
1400
1438
|
metadata: metadata,
|
|
1401
|
-
origin_amount: (
|
|
1439
|
+
origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
|
|
1402
1440
|
});
|
|
1403
1441
|
if (paymentRecord.status !== undefined) {
|
|
1404
1442
|
normalized.status = paymentRecord.status;
|
|
@@ -1519,7 +1557,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1519
1557
|
var _this6 = this;
|
|
1520
1558
|
return (payments || []).reduce(function (summary, payment) {
|
|
1521
1559
|
var paymentRecord = payment;
|
|
1522
|
-
if ((paymentRecord
|
|
1560
|
+
if (!isPaidPaymentRecord(paymentRecord)) return summary;
|
|
1523
1561
|
return {
|
|
1524
1562
|
customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
|
|
1525
1563
|
orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
|
|
@@ -1731,7 +1769,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1731
1769
|
_product$payment_pric,
|
|
1732
1770
|
_sku$code,
|
|
1733
1771
|
_sku$barcode,
|
|
1734
|
-
|
|
1772
|
+
_ref20,
|
|
1735
1773
|
_sku$variant_id,
|
|
1736
1774
|
_this8 = this;
|
|
1737
1775
|
var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
|
|
@@ -1758,24 +1796,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1758
1796
|
product_sku: this.normalizeFingerprintValue({
|
|
1759
1797
|
code: (_sku$code = sku.code) !== null && _sku$code !== void 0 ? _sku$code : '',
|
|
1760
1798
|
barcode: (_sku$barcode = sku.barcode) !== null && _sku$barcode !== void 0 ? _sku$barcode : '',
|
|
1761
|
-
variant_id: (
|
|
1799
|
+
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,
|
|
1762
1800
|
variant: sku.variant || [],
|
|
1763
1801
|
option: getProductSkuOptions(product || {}).map(function (option) {
|
|
1764
|
-
var
|
|
1802
|
+
var _ref21, _option$id, _option$option_group_, _ref22, _option$option_group_2, _option$num, _option$add_price;
|
|
1765
1803
|
return {
|
|
1766
|
-
id: (
|
|
1804
|
+
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,
|
|
1767
1805
|
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,
|
|
1768
|
-
option_group_item_id: (
|
|
1806
|
+
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,
|
|
1769
1807
|
num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
|
|
1770
1808
|
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)
|
|
1771
1809
|
};
|
|
1772
1810
|
})
|
|
1773
1811
|
}),
|
|
1774
1812
|
product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
|
|
1775
|
-
var
|
|
1813
|
+
var _ref23, _ref24, _bundle$bundle_produc, _ref25, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
|
|
1776
1814
|
return {
|
|
1777
|
-
bundle_product_id: (
|
|
1778
|
-
bundle_variant_id: (
|
|
1815
|
+
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,
|
|
1816
|
+
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,
|
|
1779
1817
|
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),
|
|
1780
1818
|
price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
|
|
1781
1819
|
bundle_selling_price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
|
|
@@ -1784,10 +1822,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1784
1822
|
};
|
|
1785
1823
|
})),
|
|
1786
1824
|
discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
|
|
1787
|
-
var
|
|
1825
|
+
var _ref26, _discount$type2, _ref27, _ref28, _discount$discount_id, _discount$discount;
|
|
1788
1826
|
return {
|
|
1789
|
-
type: (
|
|
1790
|
-
discount_id: (
|
|
1827
|
+
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 : '',
|
|
1828
|
+
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,
|
|
1791
1829
|
amount: _this8.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
|
|
1792
1830
|
};
|
|
1793
1831
|
}))
|
|
@@ -1811,14 +1849,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1811
1849
|
var _product$product_id3,
|
|
1812
1850
|
_product$product_vari2,
|
|
1813
1851
|
_product$num2,
|
|
1814
|
-
|
|
1852
|
+
_ref29,
|
|
1815
1853
|
_metadata$unique_iden,
|
|
1816
1854
|
_metadata$price_overr,
|
|
1817
1855
|
_metadata$is_manual_d,
|
|
1818
1856
|
_metadata$product_dis,
|
|
1819
1857
|
_sku$code2,
|
|
1820
1858
|
_sku$barcode2,
|
|
1821
|
-
|
|
1859
|
+
_ref30,
|
|
1822
1860
|
_sku$variant_id2,
|
|
1823
1861
|
_this10 = this;
|
|
1824
1862
|
var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
|
|
@@ -1834,7 +1872,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1834
1872
|
extension_type: extensionType,
|
|
1835
1873
|
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),
|
|
1836
1874
|
metadata: {
|
|
1837
|
-
unique_identification_number: (
|
|
1875
|
+
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 : '',
|
|
1838
1876
|
price_override: (_metadata$price_overr = metadata.price_override) !== null && _metadata$price_overr !== void 0 ? _metadata$price_overr : '',
|
|
1839
1877
|
is_manual_discount: (_metadata$is_manual_d = metadata.is_manual_discount) !== null && _metadata$is_manual_d !== void 0 ? _metadata$is_manual_d : '',
|
|
1840
1878
|
product_discount_reason: (_metadata$product_dis = metadata.product_discount_reason) !== null && _metadata$product_dis !== void 0 ? _metadata$product_dis : ''
|
|
@@ -1842,35 +1880,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1842
1880
|
product_sku: this.normalizeFingerprintValue({
|
|
1843
1881
|
code: (_sku$code2 = sku.code) !== null && _sku$code2 !== void 0 ? _sku$code2 : '',
|
|
1844
1882
|
barcode: (_sku$barcode2 = sku.barcode) !== null && _sku$barcode2 !== void 0 ? _sku$barcode2 : '',
|
|
1845
|
-
variant_id: (
|
|
1883
|
+
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,
|
|
1846
1884
|
variant: sku.variant || [],
|
|
1847
1885
|
option: getProductSkuOptions(product || {}).map(function (option) {
|
|
1848
|
-
var
|
|
1886
|
+
var _ref31, _option$id2, _option$option_group_3, _ref32, _option$option_group_4, _option$num2, _option$add_price2;
|
|
1849
1887
|
return {
|
|
1850
|
-
id: (
|
|
1888
|
+
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,
|
|
1851
1889
|
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,
|
|
1852
|
-
option_group_item_id: (
|
|
1890
|
+
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,
|
|
1853
1891
|
num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
|
|
1854
1892
|
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)
|
|
1855
1893
|
};
|
|
1856
1894
|
})
|
|
1857
1895
|
}),
|
|
1858
1896
|
product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
|
|
1859
|
-
var
|
|
1897
|
+
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;
|
|
1860
1898
|
return {
|
|
1861
|
-
bundle_id: (
|
|
1862
|
-
bundle_group_id: (
|
|
1863
|
-
bundle_product_id: (
|
|
1864
|
-
bundle_variant_id: (
|
|
1899
|
+
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,
|
|
1900
|
+
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,
|
|
1901
|
+
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,
|
|
1902
|
+
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,
|
|
1865
1903
|
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),
|
|
1866
1904
|
price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
|
|
1867
1905
|
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 : '',
|
|
1868
1906
|
option: _this10.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
|
|
1869
|
-
var
|
|
1907
|
+
var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
|
|
1870
1908
|
return {
|
|
1871
|
-
id: (
|
|
1909
|
+
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,
|
|
1872
1910
|
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,
|
|
1873
|
-
option_group_item_id: (
|
|
1911
|
+
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,
|
|
1874
1912
|
num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
|
|
1875
1913
|
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)
|
|
1876
1914
|
};
|
|
@@ -1878,10 +1916,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1878
1916
|
};
|
|
1879
1917
|
})),
|
|
1880
1918
|
discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
|
|
1881
|
-
var
|
|
1919
|
+
var _ref40, _discount$type4, _ref41, _ref42, _discount$discount_id2, _discount$discount2;
|
|
1882
1920
|
return {
|
|
1883
|
-
type: (
|
|
1884
|
-
discount_id: (
|
|
1921
|
+
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 : '',
|
|
1922
|
+
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,
|
|
1885
1923
|
amount: _this10.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
|
|
1886
1924
|
};
|
|
1887
1925
|
}))
|
|
@@ -2088,6 +2126,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2088
2126
|
key: "restoreOrder",
|
|
2089
2127
|
value: function restoreOrder() {
|
|
2090
2128
|
var _this$store$discount11, _this$store$discount12;
|
|
2129
|
+
this.logInfo('restoreOrder start', {});
|
|
2091
2130
|
var freshTempOrder = this.createDefaultTempOrderInstance();
|
|
2092
2131
|
this.ensureExternalSaleNumber(freshTempOrder);
|
|
2093
2132
|
this.store.tempOrder = freshTempOrder;
|
|
@@ -2161,11 +2200,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2161
2200
|
}, {
|
|
2162
2201
|
key: "getOrderIdentity",
|
|
2163
2202
|
value: function getOrderIdentity() {
|
|
2164
|
-
var
|
|
2203
|
+
var _ref43, _ref44, _tempOrder$order_id, _tempOrder$_extend6;
|
|
2165
2204
|
var tempOrder = this.store.tempOrder;
|
|
2166
2205
|
if (!tempOrder) return null;
|
|
2167
2206
|
var lastOrderInfo = this.store.lastOrderInfo || {};
|
|
2168
|
-
var orderId = (
|
|
2207
|
+
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;
|
|
2169
2208
|
return {
|
|
2170
2209
|
localId: this.cacheId || ((_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.localId),
|
|
2171
2210
|
orderId: orderId,
|
|
@@ -2200,7 +2239,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2200
2239
|
orderPaidAmount: paidPaymentSummary.gapPaidAmount
|
|
2201
2240
|
});
|
|
2202
2241
|
return {
|
|
2203
|
-
isDeposit: tempOrder.is_deposit === 1
|
|
2242
|
+
isDeposit: tempOrder.is_deposit === 1,
|
|
2204
2243
|
depositAmount: depositAmount,
|
|
2205
2244
|
expectAmount: summary.expect_amount || '0.00',
|
|
2206
2245
|
totalAmount: summary.total_amount || '0.00',
|
|
@@ -2318,11 +2357,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2318
2357
|
}, {
|
|
2319
2358
|
key: "captureProductRuntime",
|
|
2320
2359
|
value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
|
|
2321
|
-
var _extend$productsByUid,
|
|
2360
|
+
var _extend$productsByUid, _ref45, _rawProduct$_origin;
|
|
2322
2361
|
var uid = existedUid || this.getProductUid(normalizedProduct);
|
|
2323
2362
|
var extend = this.ensureExtend(tempOrder);
|
|
2324
2363
|
var existed = ((_extend$productsByUid = extend.productsByUid) === null || _extend$productsByUid === void 0 ? void 0 : _extend$productsByUid[uid]) || {};
|
|
2325
|
-
var origin = (
|
|
2364
|
+
var origin = (_ref45 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref45 !== void 0 ? _ref45 : existed.origin;
|
|
2326
2365
|
extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
|
|
2327
2366
|
origin: origin
|
|
2328
2367
|
} : {});
|
|
@@ -2423,7 +2462,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2423
2462
|
}, {
|
|
2424
2463
|
key: "buildTempOrderHolderFromBookings",
|
|
2425
2464
|
value: function buildTempOrderHolderFromBookings(tempOrder) {
|
|
2426
|
-
var _baseHolder$customer_, _baseHolder,
|
|
2465
|
+
var _baseHolder$customer_, _baseHolder, _ref46, _baseHolder$form_id, _baseHolder2, _tempOrder$holder3, _baseHolder3, _this$otherParams;
|
|
2427
2466
|
var holderRecords = [];
|
|
2428
2467
|
var holderNames = [];
|
|
2429
2468
|
var baseHolder = null;
|
|
@@ -2470,7 +2509,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2470
2509
|
}
|
|
2471
2510
|
var nextHolder = {
|
|
2472
2511
|
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,
|
|
2473
|
-
form_id: (
|
|
2512
|
+
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,
|
|
2474
2513
|
form_record: holderRecords
|
|
2475
2514
|
};
|
|
2476
2515
|
if (holderNames.length) {
|
|
@@ -2565,15 +2604,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2565
2604
|
hasDeposit: true
|
|
2566
2605
|
} : undefined
|
|
2567
2606
|
});
|
|
2607
|
+
var isExistingDepositDisabled = tempOrder.is_deposit === 0 && new Decimal(tempOrder.deposit_amount || 0).gt(0);
|
|
2568
2608
|
tempOrder.deposit_amount = depositAmount;
|
|
2569
|
-
tempOrder.is_deposit = hasDepositAmount ? 1 : 0;
|
|
2609
|
+
tempOrder.is_deposit = hasDepositAmount && !isExistingDepositDisabled ? 1 : 0;
|
|
2570
2610
|
return this.applyLastOrderDepositSnapshot(tempOrder, nextSummary);
|
|
2571
2611
|
}
|
|
2572
2612
|
}, {
|
|
2573
2613
|
key: "recalculateSummary",
|
|
2574
2614
|
value: function () {
|
|
2575
2615
|
var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(options) {
|
|
2576
|
-
var
|
|
2616
|
+
var _ref47, _salesSummaryResult$e;
|
|
2577
2617
|
var tempOrder, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
|
|
2578
2618
|
return _regeneratorRuntime().wrap(function _callee11$(_context13) {
|
|
2579
2619
|
while (1) switch (_context13.prev = _context13.next) {
|
|
@@ -2646,7 +2686,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2646
2686
|
roundingAmount = paidPaymentSummary.roundingAmount;
|
|
2647
2687
|
payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
|
|
2648
2688
|
hasSalesSummaryAmount = salesSummaryResult.expect_amount !== undefined || salesSummaryResult.total_amount !== undefined;
|
|
2649
|
-
expectAmount = hasSalesSummaryAmount ? new Decimal((
|
|
2689
|
+
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;
|
|
2650
2690
|
amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? _objectSpread({
|
|
2651
2691
|
rounding_amount: roundingAmount.toFixed(2)
|
|
2652
2692
|
}, expectAmount ? {
|
|
@@ -2824,17 +2864,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2824
2864
|
}, {
|
|
2825
2865
|
key: "buildTempOrderCustomer",
|
|
2826
2866
|
value: function buildTempOrderCustomer(params) {
|
|
2827
|
-
var
|
|
2867
|
+
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;
|
|
2828
2868
|
if (!params.customerId) return null;
|
|
2829
2869
|
var source = params.source ? cloneDeep(params.source) : {};
|
|
2830
|
-
var name = (
|
|
2831
|
-
var customerName = (
|
|
2870
|
+
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;
|
|
2871
|
+
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;
|
|
2832
2872
|
return _objectSpread(_objectSpread({}, source), {}, {
|
|
2833
2873
|
id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
|
|
2834
2874
|
customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
|
|
2835
2875
|
name: String(name || ''),
|
|
2836
2876
|
customer_name: String(customerName || ''),
|
|
2837
|
-
country_calling_code: String((
|
|
2877
|
+
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),
|
|
2838
2878
|
phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
|
|
2839
2879
|
email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
|
|
2840
2880
|
});
|
|
@@ -2933,14 +2973,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2933
2973
|
}, {
|
|
2934
2974
|
key: "updateTempOrderCustomer",
|
|
2935
2975
|
value: function updateTempOrderCustomer(customer) {
|
|
2936
|
-
var _tempOrder$customer_i2,
|
|
2976
|
+
var _tempOrder$customer_i2, _ref55, _ref56, _customer$customer_id, _ref57, _ref58, _ref59, _customer$customer_na, _ref60, _customer$country_cal, _tempOrder$customer_i3;
|
|
2937
2977
|
var tempOrder = this.ensureTempOrder();
|
|
2938
2978
|
var previousCustomerId = (_tempOrder$customer_i2 = tempOrder.customer_id) !== null && _tempOrder$customer_i2 !== void 0 ? _tempOrder$customer_i2 : null;
|
|
2939
|
-
var customerId = (
|
|
2940
|
-
var customerName = (
|
|
2979
|
+
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;
|
|
2980
|
+
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 : '';
|
|
2941
2981
|
tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
|
|
2942
2982
|
tempOrder.customer_name = String(customerName || '');
|
|
2943
|
-
tempOrder.country_calling_code = String((
|
|
2983
|
+
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 : '');
|
|
2944
2984
|
tempOrder.phone = String(customer.phone || '');
|
|
2945
2985
|
tempOrder.email = String(customer.email || '');
|
|
2946
2986
|
tempOrder.customer = this.buildTempOrderCustomer({
|
|
@@ -2991,6 +3031,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2991
3031
|
if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
|
|
2992
3032
|
clearTempOrderHolderAssignments(tempOrder);
|
|
2993
3033
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
3034
|
+
this.applyDiscount();
|
|
2994
3035
|
}
|
|
2995
3036
|
this.persistTempOrder();
|
|
2996
3037
|
this.saveDraftInBackground();
|
|
@@ -3157,6 +3198,76 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3157
3198
|
this.persistTempOrder();
|
|
3158
3199
|
return tempOrder.payments;
|
|
3159
3200
|
}
|
|
3201
|
+
}, {
|
|
3202
|
+
key: "confirmPendingVoucherPaymentsInList",
|
|
3203
|
+
value: function confirmPendingVoucherPaymentsInList(payments) {
|
|
3204
|
+
return (payments || []).map(function (payment) {
|
|
3205
|
+
if (!isPendingVoucherPaymentRecord(payment)) return payment;
|
|
3206
|
+
return _objectSpread(_objectSpread({}, payment), {}, {
|
|
3207
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
3208
|
+
});
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
3211
|
+
}, {
|
|
3212
|
+
key: "discardPendingVoucherPaymentsFromList",
|
|
3213
|
+
value: function discardPendingVoucherPaymentsFromList(payments) {
|
|
3214
|
+
return (payments || []).filter(function (payment) {
|
|
3215
|
+
return !isPendingVoucherPaymentRecord(payment);
|
|
3216
|
+
});
|
|
3217
|
+
}
|
|
3218
|
+
}, {
|
|
3219
|
+
key: "prepareVoucherPaymentsForSubmit",
|
|
3220
|
+
value: function prepareVoucherPaymentsForSubmit(payments) {
|
|
3221
|
+
var confirmPendingVoucherPayments = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
3222
|
+
var mappedPayments = mapPaymentItemsToOrderPayments(payments || []);
|
|
3223
|
+
return confirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : this.discardPendingVoucherPaymentsFromList(mappedPayments);
|
|
3224
|
+
}
|
|
3225
|
+
}, {
|
|
3226
|
+
key: "applyPaymentLifecycleChange",
|
|
3227
|
+
value: function applyPaymentLifecycleChange(tempOrder, options) {
|
|
3228
|
+
var _this19 = this;
|
|
3229
|
+
this.updateTempOrderPaymentStatus(tempOrder);
|
|
3230
|
+
if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
|
|
3231
|
+
this.persistTempOrder();
|
|
3232
|
+
}
|
|
3233
|
+
if ((options === null || options === void 0 ? void 0 : options.recalculateSummary) === false) return;
|
|
3234
|
+
var logContext = (options === null || options === void 0 ? void 0 : options.logContext) || 'payment lifecycle change';
|
|
3235
|
+
void this.recalculateSummary({
|
|
3236
|
+
createIfMissing: true
|
|
3237
|
+
}).catch(function (error) {
|
|
3238
|
+
_this19.logError("recalculate summary after ".concat(logContext, " failed"), {
|
|
3239
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3240
|
+
});
|
|
3241
|
+
});
|
|
3242
|
+
}
|
|
3243
|
+
}, {
|
|
3244
|
+
key: "confirmPendingVoucherPayments",
|
|
3245
|
+
value: function confirmPendingVoucherPayments(options) {
|
|
3246
|
+
var tempOrder = this.ensureTempOrder();
|
|
3247
|
+
var payments = tempOrder.payments || [];
|
|
3248
|
+
var hasPendingVoucher = payments.some(function (payment) {
|
|
3249
|
+
return isPendingVoucherPaymentRecord(payment);
|
|
3250
|
+
});
|
|
3251
|
+
if (!hasPendingVoucher) return payments;
|
|
3252
|
+
tempOrder.payments = this.confirmPendingVoucherPaymentsInList(payments);
|
|
3253
|
+
this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
|
|
3254
|
+
logContext: 'confirmPendingVoucherPayments'
|
|
3255
|
+
}));
|
|
3256
|
+
return tempOrder.payments;
|
|
3257
|
+
}
|
|
3258
|
+
}, {
|
|
3259
|
+
key: "discardPendingVoucherPayments",
|
|
3260
|
+
value: function discardPendingVoucherPayments(options) {
|
|
3261
|
+
var tempOrder = this.ensureTempOrder();
|
|
3262
|
+
var payments = tempOrder.payments || [];
|
|
3263
|
+
var nextPayments = this.discardPendingVoucherPaymentsFromList(payments);
|
|
3264
|
+
if (nextPayments.length === payments.length) return payments;
|
|
3265
|
+
tempOrder.payments = nextPayments;
|
|
3266
|
+
this.applyPaymentLifecycleChange(tempOrder, _objectSpread(_objectSpread({}, options), {}, {
|
|
3267
|
+
logContext: 'discardPendingVoucherPayments'
|
|
3268
|
+
}));
|
|
3269
|
+
return tempOrder.payments;
|
|
3270
|
+
}
|
|
3160
3271
|
|
|
3161
3272
|
/**
|
|
3162
3273
|
* 覆盖当前订单中的 wallet pass 支付项。
|
|
@@ -3166,45 +3277,59 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3166
3277
|
*/
|
|
3167
3278
|
}, {
|
|
3168
3279
|
key: "updateVoucherOrderPayments",
|
|
3169
|
-
value: function updateVoucherOrderPayments(payments) {
|
|
3170
|
-
var
|
|
3280
|
+
value: function updateVoucherOrderPayments(payments, options) {
|
|
3281
|
+
var _this20 = this;
|
|
3171
3282
|
var tempOrder = this.ensureTempOrder();
|
|
3172
|
-
var
|
|
3173
|
-
return
|
|
3283
|
+
var isOrderPaymentType = function isOrderPaymentType(value) {
|
|
3284
|
+
return value === 'normal' || value === 'deposit';
|
|
3174
3285
|
};
|
|
3175
|
-
var
|
|
3176
|
-
|
|
3286
|
+
var voucherOrderPaymentType = this.resolveNextOrderPaymentType(tempOrder);
|
|
3287
|
+
var withVoucherPaymentType = function withVoucherPaymentType(payment) {
|
|
3288
|
+
var paymentRecord = payment;
|
|
3289
|
+
if (!isVoucherPaymentRecord(paymentRecord)) return payment;
|
|
3290
|
+
var explicitPaymentType = isOrderPaymentType(paymentRecord.order_payment_type) ? paymentRecord.order_payment_type : isOrderPaymentType(paymentRecord.type) ? paymentRecord.type : undefined;
|
|
3291
|
+
var nextPaymentType = explicitPaymentType || voucherOrderPaymentType;
|
|
3292
|
+
var shouldPreserveCustomPaymentType = paymentRecord.custom_payment_type === undefined && paymentRecord.type !== undefined && !isOrderPaymentType(paymentRecord.type);
|
|
3293
|
+
return _objectSpread(_objectSpread(_objectSpread({}, paymentRecord), shouldPreserveCustomPaymentType ? {
|
|
3294
|
+
custom_payment_type: paymentRecord.type
|
|
3295
|
+
} : {}), {}, {
|
|
3296
|
+
type: nextPaymentType,
|
|
3297
|
+
order_payment_type: nextPaymentType
|
|
3298
|
+
});
|
|
3299
|
+
};
|
|
3300
|
+
var normalizeVoucherPaymentStatus = function normalizeVoucherPaymentStatus(payment) {
|
|
3301
|
+
var paymentRecord = payment;
|
|
3302
|
+
if (!isVoucherPaymentRecord(paymentRecord)) return payment;
|
|
3303
|
+
if (hasSyncedOrderPaymentRecord(paymentRecord) && (paymentRecord.status === undefined || paymentRecord.status === 'active')) {
|
|
3304
|
+
return _objectSpread(_objectSpread({}, paymentRecord), {}, {
|
|
3305
|
+
status: ORDER_PAYMENT_STATUS_PAID
|
|
3306
|
+
});
|
|
3307
|
+
}
|
|
3308
|
+
if (paymentRecord.status !== undefined && paymentRecord.status !== 'active') {
|
|
3309
|
+
return payment;
|
|
3310
|
+
}
|
|
3311
|
+
return _objectSpread(_objectSpread({}, paymentRecord), {}, {
|
|
3312
|
+
status: (options === null || options === void 0 ? void 0 : options.status) || ORDER_PAYMENT_STATUS_PENDING
|
|
3313
|
+
});
|
|
3177
3314
|
};
|
|
3178
|
-
// const normalizeVoucherPaymentStatus = (payment: OrderPaymentSource): OrderPaymentSource => {
|
|
3179
|
-
// const paymentRecord = payment as Record<string, any>;
|
|
3180
|
-
// // if (paymentRecord.status !== 'active') return payment;
|
|
3181
|
-
// // return {
|
|
3182
|
-
// // ...paymentRecord,
|
|
3183
|
-
// // status: 'paid',
|
|
3184
|
-
// // };
|
|
3185
|
-
// if (paymentRecord.status === 'active') {
|
|
3186
|
-
// paymentRecord.status = 'paid'
|
|
3187
|
-
// }
|
|
3188
|
-
// return paymentRecord
|
|
3189
|
-
// };
|
|
3190
3315
|
var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
|
|
3191
|
-
return
|
|
3192
|
-
defaultPaid:
|
|
3316
|
+
return _this20.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
|
|
3317
|
+
defaultPaid: false
|
|
3193
3318
|
});
|
|
3194
3319
|
})).filter(function (payment) {
|
|
3195
|
-
return
|
|
3320
|
+
return isVoucherPaymentRecord(payment);
|
|
3196
3321
|
});
|
|
3197
3322
|
var nonVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
|
|
3198
|
-
return !
|
|
3323
|
+
return !isVoucherPaymentRecord(payment);
|
|
3199
3324
|
});
|
|
3200
3325
|
var syncedVoucherPayments = (tempOrder.payments || []).filter(function (payment) {
|
|
3201
|
-
return
|
|
3326
|
+
return isVoucherPaymentRecord(payment) && hasSyncedOrderPaymentRecord(payment);
|
|
3202
3327
|
});
|
|
3203
3328
|
var syncedVoucherPaymentIds = new Set(syncedVoucherPayments.map(function (payment) {
|
|
3204
3329
|
return String(payment.order_payment_id);
|
|
3205
3330
|
}));
|
|
3206
3331
|
var replaceableVouchers = mappedVouchers.filter(function (payment) {
|
|
3207
|
-
if (!
|
|
3332
|
+
if (!hasSyncedOrderPaymentRecord(payment)) return true;
|
|
3208
3333
|
return !syncedVoucherPaymentIds.has(String(payment.order_payment_id));
|
|
3209
3334
|
});
|
|
3210
3335
|
var cappedVouchers = this.capVoucherPaymentsByRemainingAmount({
|
|
@@ -3217,7 +3342,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3217
3342
|
void this.recalculateSummary({
|
|
3218
3343
|
createIfMissing: true
|
|
3219
3344
|
}).catch(function (error) {
|
|
3220
|
-
|
|
3345
|
+
_this20.logError('recalculate summary after updateVoucherOrderPayments failed', {
|
|
3221
3346
|
error: error instanceof Error ? error.message : String(error)
|
|
3222
3347
|
});
|
|
3223
3348
|
});
|
|
@@ -3353,7 +3478,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3353
3478
|
var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, product, booking) {
|
|
3354
3479
|
var _booking_uid,
|
|
3355
3480
|
_metadata,
|
|
3356
|
-
|
|
3481
|
+
_this21 = this;
|
|
3357
3482
|
var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
|
|
3358
3483
|
return _regeneratorRuntime().wrap(function _callee16$(_context18) {
|
|
3359
3484
|
while (1) switch (_context18.prev = _context18.next) {
|
|
@@ -3378,8 +3503,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3378
3503
|
hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
|
|
3379
3504
|
shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
|
|
3380
3505
|
matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
|
|
3381
|
-
if (
|
|
3382
|
-
if (
|
|
3506
|
+
if (_this21.hasGoodPassDiscount(item)) return false;
|
|
3507
|
+
if (_this21.hasOrderProductLineNote(item)) return false;
|
|
3383
3508
|
if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
|
|
3384
3509
|
if (item.product_id !== productToAdd.product_id) return false;
|
|
3385
3510
|
if (item.product_variant_id !== productToAdd.product_variant_id) return false;
|
|
@@ -3485,49 +3610,52 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3485
3610
|
key: "addProductToOrder",
|
|
3486
3611
|
value: (function () {
|
|
3487
3612
|
var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(product, booking) {
|
|
3488
|
-
var tempOrder,
|
|
3613
|
+
var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
|
|
3489
3614
|
return _regeneratorRuntime().wrap(function _callee17$(_context19) {
|
|
3490
3615
|
while (1) switch (_context19.prev = _context19.next) {
|
|
3491
3616
|
case 0:
|
|
3492
3617
|
tempOrder = this.ensureTempOrder();
|
|
3493
|
-
debugger;
|
|
3494
3618
|
if (!booking) {
|
|
3495
|
-
_context19.next =
|
|
3619
|
+
_context19.next = 18;
|
|
3496
3620
|
break;
|
|
3497
3621
|
}
|
|
3498
3622
|
productRecord = product;
|
|
3499
|
-
splitCount = getSafeProductNum((
|
|
3623
|
+
splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
|
|
3500
3624
|
if (!(splitCount > 1)) {
|
|
3501
|
-
_context19.next =
|
|
3625
|
+
_context19.next = 18;
|
|
3502
3626
|
break;
|
|
3503
3627
|
}
|
|
3504
3628
|
i = 0;
|
|
3505
|
-
case
|
|
3629
|
+
case 6:
|
|
3506
3630
|
if (!(i < splitCount)) {
|
|
3507
|
-
_context19.next =
|
|
3631
|
+
_context19.next = 15;
|
|
3508
3632
|
break;
|
|
3509
3633
|
}
|
|
3510
3634
|
singleLine = cloneDeep(productRecord);
|
|
3511
3635
|
singleLine.num = 1;
|
|
3512
3636
|
delete singleLine.product_quantity;
|
|
3513
|
-
_context19.next =
|
|
3637
|
+
_context19.next = 12;
|
|
3514
3638
|
return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
|
|
3515
|
-
case
|
|
3639
|
+
case 12:
|
|
3516
3640
|
i += 1;
|
|
3517
|
-
_context19.next =
|
|
3641
|
+
_context19.next = 6;
|
|
3518
3642
|
break;
|
|
3519
|
-
case
|
|
3520
|
-
_context19.next =
|
|
3643
|
+
case 15:
|
|
3644
|
+
_context19.next = 17;
|
|
3521
3645
|
return this.finalizeProductOrderMutation(tempOrder);
|
|
3522
|
-
case
|
|
3646
|
+
case 17:
|
|
3523
3647
|
return _context19.abrupt("return", tempOrder.products);
|
|
3524
|
-
case
|
|
3525
|
-
_context19.next =
|
|
3648
|
+
case 18:
|
|
3649
|
+
_context19.next = 20;
|
|
3526
3650
|
return this.appendProductLineToTempOrder(tempOrder, product, booking);
|
|
3527
|
-
case
|
|
3528
|
-
_context19.next =
|
|
3651
|
+
case 20:
|
|
3652
|
+
_context19.next = 22;
|
|
3529
3653
|
return this.finalizeProductOrderMutation(tempOrder);
|
|
3530
|
-
case
|
|
3654
|
+
case 22:
|
|
3655
|
+
this.logInfo('addProductToOrder success', {
|
|
3656
|
+
product_id: product.product_id,
|
|
3657
|
+
with_booking: !!booking
|
|
3658
|
+
});
|
|
3531
3659
|
return _context19.abrupt("return", tempOrder.products);
|
|
3532
3660
|
case 24:
|
|
3533
3661
|
case "end":
|
|
@@ -3554,7 +3682,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3554
3682
|
key: "addProductsToOrder",
|
|
3555
3683
|
value: (function () {
|
|
3556
3684
|
var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(items, options) {
|
|
3557
|
-
var tempOrder, _iterator20, _step20, item, product, booking,
|
|
3685
|
+
var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
|
|
3558
3686
|
return _regeneratorRuntime().wrap(function _callee18$(_context20) {
|
|
3559
3687
|
while (1) switch (_context20.prev = _context20.next) {
|
|
3560
3688
|
case 0:
|
|
@@ -3586,7 +3714,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3586
3714
|
break;
|
|
3587
3715
|
}
|
|
3588
3716
|
productRecord = product;
|
|
3589
|
-
splitCount = getSafeProductNum((
|
|
3717
|
+
splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
|
|
3590
3718
|
if (!(splitCount > 1)) {
|
|
3591
3719
|
_context20.next = 26;
|
|
3592
3720
|
break;
|
|
@@ -3629,8 +3757,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3629
3757
|
_context20.next = 40;
|
|
3630
3758
|
return this.finalizeProductOrderMutation(tempOrder, options);
|
|
3631
3759
|
case 40:
|
|
3760
|
+
this.logInfo('addProductsToOrder success', {
|
|
3761
|
+
itemsCount: items.length
|
|
3762
|
+
});
|
|
3632
3763
|
return _context20.abrupt("return", tempOrder.products);
|
|
3633
|
-
case
|
|
3764
|
+
case 42:
|
|
3634
3765
|
case "end":
|
|
3635
3766
|
return _context20.stop();
|
|
3636
3767
|
}
|
|
@@ -3663,24 +3794,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3663
3794
|
}, {
|
|
3664
3795
|
key: "getBundleRuntimeIdentity",
|
|
3665
3796
|
value: function getBundleRuntimeIdentity(bundle) {
|
|
3666
|
-
var
|
|
3797
|
+
var _ref63, _bundle$bundle_id2, _ref64, _bundle$bundle_group_2, _ref65, _ref66, _bundle$bundle_produc3, _ref67, _bundle$bundle_varian3;
|
|
3667
3798
|
if (!bundle || _typeof(bundle) !== 'object') return '';
|
|
3668
|
-
return [(
|
|
3799
|
+
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('|');
|
|
3669
3800
|
}
|
|
3670
3801
|
}, {
|
|
3671
3802
|
key: "preservePersistedBundlePriceFields",
|
|
3672
3803
|
value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
|
|
3673
|
-
var
|
|
3804
|
+
var _this22 = this;
|
|
3674
3805
|
if (!Array.isArray(nextBundles)) return nextBundles;
|
|
3675
3806
|
if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
|
|
3676
3807
|
var previousByIdentity = new Map();
|
|
3677
3808
|
previousBundles.forEach(function (bundle) {
|
|
3678
|
-
var identity =
|
|
3809
|
+
var identity = _this22.getBundleRuntimeIdentity(bundle);
|
|
3679
3810
|
if (identity) previousByIdentity.set(identity, bundle);
|
|
3680
3811
|
});
|
|
3681
3812
|
return nextBundles.map(function (bundle, index) {
|
|
3682
3813
|
if (!bundle || _typeof(bundle) !== 'object') return bundle;
|
|
3683
|
-
var previous = previousByIdentity.get(
|
|
3814
|
+
var previous = previousByIdentity.get(_this22.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
|
|
3684
3815
|
if (!previous || _typeof(previous) !== 'object') return bundle;
|
|
3685
3816
|
return _objectSpread(_objectSpread({}, bundle), {}, {
|
|
3686
3817
|
price: previous.price,
|
|
@@ -3848,8 +3979,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3848
3979
|
});
|
|
3849
3980
|
case 8:
|
|
3850
3981
|
this.persistTempOrder();
|
|
3982
|
+
this.logInfo('updateOrderProduct success', {
|
|
3983
|
+
params: params
|
|
3984
|
+
});
|
|
3851
3985
|
return _context21.abrupt("return", tempOrder.products);
|
|
3852
|
-
case
|
|
3986
|
+
case 11:
|
|
3853
3987
|
case "end":
|
|
3854
3988
|
return _context21.stop();
|
|
3855
3989
|
}
|
|
@@ -3864,7 +3998,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3864
3998
|
key: "updateOrderProducts",
|
|
3865
3999
|
value: function () {
|
|
3866
4000
|
var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(paramsList) {
|
|
3867
|
-
var
|
|
4001
|
+
var _this23 = this;
|
|
3868
4002
|
var tempOrder;
|
|
3869
4003
|
return _regeneratorRuntime().wrap(function _callee20$(_context22) {
|
|
3870
4004
|
while (1) switch (_context22.prev = _context22.next) {
|
|
@@ -3877,13 +4011,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3877
4011
|
return _context22.abrupt("return", tempOrder.products);
|
|
3878
4012
|
case 3:
|
|
3879
4013
|
paramsList.forEach(function (params) {
|
|
3880
|
-
|
|
4014
|
+
_this23.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
3881
4015
|
});
|
|
3882
4016
|
_context22.next = 6;
|
|
3883
4017
|
return this.finalizeAfterProductsMutation(tempOrder);
|
|
3884
4018
|
case 6:
|
|
4019
|
+
this.logInfo('updateOrderProduct success', {
|
|
4020
|
+
paramsList: paramsList
|
|
4021
|
+
});
|
|
3885
4022
|
return _context22.abrupt("return", tempOrder.products);
|
|
3886
|
-
case
|
|
4023
|
+
case 8:
|
|
3887
4024
|
case "end":
|
|
3888
4025
|
return _context22.stop();
|
|
3889
4026
|
}
|
|
@@ -3955,8 +4092,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3955
4092
|
});
|
|
3956
4093
|
case 22:
|
|
3957
4094
|
this.persistTempOrder();
|
|
4095
|
+
this.logInfo('updateOrderProductQuantity success', {
|
|
4096
|
+
params: params
|
|
4097
|
+
});
|
|
3958
4098
|
return _context23.abrupt("return", tempOrder.products);
|
|
3959
|
-
case
|
|
4099
|
+
case 25:
|
|
3960
4100
|
case "end":
|
|
3961
4101
|
return _context23.stop();
|
|
3962
4102
|
}
|
|
@@ -4041,7 +4181,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4041
4181
|
key: "removeProductsFromOrder",
|
|
4042
4182
|
value: (function () {
|
|
4043
4183
|
var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(identities) {
|
|
4044
|
-
var
|
|
4184
|
+
var _this24 = this;
|
|
4045
4185
|
var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
|
|
4046
4186
|
return _regeneratorRuntime().wrap(function _callee23$(_context26) {
|
|
4047
4187
|
while (1) switch (_context26.prev = _context26.next) {
|
|
@@ -4096,7 +4236,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4096
4236
|
}
|
|
4097
4237
|
if (productUid !== undefined && productUid !== null && productUid !== '') {
|
|
4098
4238
|
bookingsBeforeRemove.forEach(function (booking) {
|
|
4099
|
-
var bookingUid =
|
|
4239
|
+
var bookingUid = _this24.getBookingUniqueIdentificationNumber(booking);
|
|
4100
4240
|
if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
|
|
4101
4241
|
linkedBookingUidsToRemove.add(bookingUid);
|
|
4102
4242
|
}
|
|
@@ -4148,8 +4288,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4148
4288
|
_context26.next = 31;
|
|
4149
4289
|
return this.finalizeAfterProductsMutation(tempOrder);
|
|
4150
4290
|
case 31:
|
|
4291
|
+
this.logInfo('removeProductsFromOrder success', {
|
|
4292
|
+
identities: identities
|
|
4293
|
+
});
|
|
4151
4294
|
return _context26.abrupt("return", tempOrder.products);
|
|
4152
|
-
case
|
|
4295
|
+
case 33:
|
|
4153
4296
|
case "end":
|
|
4154
4297
|
return _context26.stop();
|
|
4155
4298
|
}
|
|
@@ -4211,8 +4354,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4211
4354
|
});
|
|
4212
4355
|
case 11:
|
|
4213
4356
|
this.persistTempOrder();
|
|
4357
|
+
this.logInfo('clearOrderCartLines success', {});
|
|
4214
4358
|
return _context28.abrupt("return", tempOrder);
|
|
4215
|
-
case
|
|
4359
|
+
case 14:
|
|
4216
4360
|
case "end":
|
|
4217
4361
|
return _context28.stop();
|
|
4218
4362
|
}
|
|
@@ -4227,23 +4371,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4227
4371
|
}, {
|
|
4228
4372
|
key: "buildCurrentSubmitPayloadForLocalPrint",
|
|
4229
4373
|
value: function buildCurrentSubmitPayloadForLocalPrint(params) {
|
|
4230
|
-
var _params$cacheId, _this$otherParams2,
|
|
4374
|
+
var _params$cacheId, _this$otherParams2, _ref68, _params$businessCode, _this$otherParams3, _this$otherParams4;
|
|
4231
4375
|
var tempOrder = this.ensureTempOrder();
|
|
4232
4376
|
this.persistTempOrder();
|
|
4233
4377
|
var payload = buildSubmitPayload({
|
|
4234
4378
|
tempOrder: tempOrder,
|
|
4235
4379
|
cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
|
|
4236
4380
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams2 = this.otherParams) === null || _this$otherParams2 === void 0 ? void 0 : _this$otherParams2.platform),
|
|
4237
|
-
businessCode: (
|
|
4381
|
+
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,
|
|
4238
4382
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
4239
4383
|
type: params === null || params === void 0 ? void 0 : params.type,
|
|
4240
4384
|
summary: this.store.summary || createEmptySummary(),
|
|
4241
4385
|
enhance: function enhance(nextPayload) {
|
|
4242
|
-
var
|
|
4386
|
+
var _ref69, _tempOrder$order_numb, _ref70, _tempOrder$shop_order, _ref71, _tempOrder$shop_full_;
|
|
4243
4387
|
return _objectSpread(_objectSpread({}, nextPayload), {}, {
|
|
4244
|
-
order_number: (
|
|
4245
|
-
shop_order_number: (
|
|
4246
|
-
shop_full_order_number: (
|
|
4388
|
+
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,
|
|
4389
|
+
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,
|
|
4390
|
+
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,
|
|
4247
4391
|
small_ticket_data_flag: 1
|
|
4248
4392
|
});
|
|
4249
4393
|
}
|
|
@@ -4340,40 +4484,55 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4340
4484
|
key: "runSubmitTempOrder",
|
|
4341
4485
|
value: function () {
|
|
4342
4486
|
var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
|
|
4343
|
-
var _params$cacheId2, _this$otherParams5,
|
|
4344
|
-
var tempOrder, latestSummary, effectiveCacheId,
|
|
4487
|
+
var _params$cacheId2, _this$otherParams5, _ref72, _ref73, _submitSnapshot$busin, _this$otherParams6, _this$otherParams7, _submitSnapshot$type;
|
|
4488
|
+
var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
|
|
4345
4489
|
return _regeneratorRuntime().wrap(function _callee29$(_context32) {
|
|
4346
4490
|
while (1) switch (_context32.prev = _context32.next) {
|
|
4347
4491
|
case 0:
|
|
4348
4492
|
tempOrder = this.ensureTempOrder();
|
|
4493
|
+
shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
|
|
4494
|
+
hasPaymentOverride = (params === null || params === void 0 ? void 0 : params.payments) !== undefined;
|
|
4495
|
+
preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit((params === null || params === void 0 ? void 0 : params.payments) || [], shouldConfirmPendingVoucherPayments) : undefined;
|
|
4496
|
+
if (!hasPaymentOverride) {
|
|
4497
|
+
if (shouldConfirmPendingVoucherPayments) {
|
|
4498
|
+
this.confirmPendingVoucherPayments({
|
|
4499
|
+
persist: false,
|
|
4500
|
+
recalculateSummary: false
|
|
4501
|
+
});
|
|
4502
|
+
} else {
|
|
4503
|
+
this.discardPendingVoucherPayments({
|
|
4504
|
+
persist: false,
|
|
4505
|
+
recalculateSummary: false
|
|
4506
|
+
});
|
|
4507
|
+
}
|
|
4508
|
+
}
|
|
4349
4509
|
this.persistTempOrder();
|
|
4350
|
-
_context32.next =
|
|
4510
|
+
_context32.next = 8;
|
|
4351
4511
|
return this.recalculateSummary({
|
|
4352
4512
|
createIfMissing: true
|
|
4353
4513
|
});
|
|
4354
|
-
case
|
|
4514
|
+
case 8:
|
|
4355
4515
|
_context32.t1 = _context32.sent;
|
|
4356
4516
|
if (_context32.t1) {
|
|
4357
|
-
_context32.next =
|
|
4517
|
+
_context32.next = 11;
|
|
4358
4518
|
break;
|
|
4359
4519
|
}
|
|
4360
4520
|
_context32.t1 = this.store.summary;
|
|
4361
|
-
case
|
|
4521
|
+
case 11:
|
|
4362
4522
|
_context32.t0 = _context32.t1;
|
|
4363
4523
|
if (_context32.t0) {
|
|
4364
|
-
_context32.next =
|
|
4524
|
+
_context32.next = 14;
|
|
4365
4525
|
break;
|
|
4366
4526
|
}
|
|
4367
4527
|
_context32.t0 = createEmptySummary();
|
|
4368
|
-
case
|
|
4528
|
+
case 14:
|
|
4369
4529
|
latestSummary = _context32.t0;
|
|
4370
4530
|
effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
|
|
4371
|
-
hasPaymentOverride = (params === null || params === void 0 ? void 0 : params.payments) !== undefined;
|
|
4372
4531
|
hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
|
|
4373
4532
|
hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
|
|
4374
4533
|
enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
|
|
4375
4534
|
var nextPayload = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, payload), hasPaymentOverride ? {
|
|
4376
|
-
payments:
|
|
4535
|
+
payments: preparedPaymentOverride || []
|
|
4377
4536
|
} : {}), hasPaymentStatusOverride ? {
|
|
4378
4537
|
payment_status: params === null || params === void 0 ? void 0 : params.paymentStatus
|
|
4379
4538
|
} : {}), hasSmallTicketDataFlagOverride ? {
|
|
@@ -4387,13 +4546,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4387
4546
|
tempOrder: tempOrder,
|
|
4388
4547
|
cacheId: effectiveCacheId,
|
|
4389
4548
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
|
|
4390
|
-
businessCode: (
|
|
4549
|
+
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,
|
|
4391
4550
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
4392
4551
|
type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
|
|
4393
4552
|
summary: latestSummary,
|
|
4394
4553
|
request_unique_idempotency_token: params === null || params === void 0 ? void 0 : params.request_unique_idempotency_token,
|
|
4395
4554
|
enhance: enhancePayload
|
|
4396
4555
|
});
|
|
4556
|
+
console.log('[Order.runSubmitTempOrder.payload]', payload);
|
|
4397
4557
|
if (params !== null && params !== void 0 && params.syncMode) {
|
|
4398
4558
|
payload.sync_mode = true;
|
|
4399
4559
|
}
|
|
@@ -4401,10 +4561,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4401
4561
|
if (!payload.created_at) {
|
|
4402
4562
|
payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
|
|
4403
4563
|
}
|
|
4404
|
-
_context32.next =
|
|
4564
|
+
_context32.next = 26;
|
|
4405
4565
|
return this.saveDraft();
|
|
4406
|
-
case
|
|
4407
|
-
_context32.prev =
|
|
4566
|
+
case 26:
|
|
4567
|
+
_context32.prev = 26;
|
|
4408
4568
|
this.logInfo('submitTempOrder calling sales checkout', {
|
|
4409
4569
|
orderId: payload.order_id,
|
|
4410
4570
|
externalSaleNumber: payload.external_sale_number,
|
|
@@ -4414,26 +4574,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4414
4574
|
smallTicketDataFlag: payload.small_ticket_data_flag,
|
|
4415
4575
|
syncMode: payload.sync_mode
|
|
4416
4576
|
});
|
|
4417
|
-
_context32.next =
|
|
4577
|
+
_context32.next = 30;
|
|
4418
4578
|
return this.submitSalesOrder({
|
|
4419
4579
|
query: payload
|
|
4420
4580
|
});
|
|
4421
|
-
case
|
|
4581
|
+
case 30:
|
|
4422
4582
|
result = _context32.sent;
|
|
4423
|
-
_context32.next =
|
|
4583
|
+
_context32.next = 43;
|
|
4424
4584
|
break;
|
|
4425
|
-
case
|
|
4426
|
-
_context32.prev =
|
|
4427
|
-
_context32.t2 = _context32["catch"](
|
|
4585
|
+
case 33:
|
|
4586
|
+
_context32.prev = 33;
|
|
4587
|
+
_context32.t2 = _context32["catch"](26);
|
|
4428
4588
|
backendErrorResponse = this.extractSubmitErrorResponse(_context32.t2);
|
|
4429
4589
|
if (!backendErrorResponse) {
|
|
4430
|
-
_context32.next =
|
|
4590
|
+
_context32.next = 40;
|
|
4431
4591
|
break;
|
|
4432
4592
|
}
|
|
4433
4593
|
this.store.syncState = 'failed';
|
|
4434
4594
|
this.logSubmitBackendRejected(backendErrorResponse, payload);
|
|
4435
4595
|
return _context32.abrupt("return", backendErrorResponse);
|
|
4436
|
-
case
|
|
4596
|
+
case 40:
|
|
4437
4597
|
this.store.syncState = 'failed';
|
|
4438
4598
|
this.logError('submitTempOrder failed', {
|
|
4439
4599
|
error: _context32.t2 instanceof Error ? _context32.t2.message : String(_context32.t2),
|
|
@@ -4443,15 +4603,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4443
4603
|
paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
|
|
4444
4604
|
});
|
|
4445
4605
|
throw _context32.t2;
|
|
4446
|
-
case
|
|
4606
|
+
case 43:
|
|
4447
4607
|
if (!this.isSubmitResponseRejected(result)) {
|
|
4448
|
-
_context32.next =
|
|
4608
|
+
_context32.next = 47;
|
|
4449
4609
|
break;
|
|
4450
4610
|
}
|
|
4451
4611
|
this.store.syncState = 'failed';
|
|
4452
4612
|
this.logSubmitBackendRejected(result, payload);
|
|
4453
4613
|
return _context32.abrupt("return", result);
|
|
4454
|
-
case
|
|
4614
|
+
case 47:
|
|
4455
4615
|
submittedOrderId = this.extractOrderIdFromSubmitResult(result);
|
|
4456
4616
|
this.logInfo('runSubmitTempOrder: 提交成功', {
|
|
4457
4617
|
submittedOrderId: submittedOrderId,
|
|
@@ -4459,29 +4619,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4459
4619
|
tempOrder: tempOrder
|
|
4460
4620
|
});
|
|
4461
4621
|
if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
|
|
4462
|
-
_context32.next =
|
|
4622
|
+
_context32.next = 56;
|
|
4463
4623
|
break;
|
|
4464
4624
|
}
|
|
4465
4625
|
tempOrder.order_id = submittedOrderId;
|
|
4466
4626
|
resultRecord = result;
|
|
4467
|
-
_context32.next =
|
|
4627
|
+
_context32.next = 54;
|
|
4468
4628
|
return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
|
|
4469
|
-
case
|
|
4470
|
-
_context32.next =
|
|
4629
|
+
case 54:
|
|
4630
|
+
_context32.next = 57;
|
|
4471
4631
|
break;
|
|
4472
|
-
case
|
|
4632
|
+
case 56:
|
|
4473
4633
|
if (this.isLocalPendingSubmitResult(result)) {
|
|
4474
4634
|
this.store.syncState = 'local';
|
|
4475
4635
|
} else {
|
|
4476
4636
|
this.store.syncState = 'submitted';
|
|
4477
4637
|
}
|
|
4478
|
-
case
|
|
4638
|
+
case 57:
|
|
4479
4639
|
return _context32.abrupt("return", result);
|
|
4480
|
-
case
|
|
4640
|
+
case 58:
|
|
4481
4641
|
case "end":
|
|
4482
4642
|
return _context32.stop();
|
|
4483
4643
|
}
|
|
4484
|
-
}, _callee29, this, [[
|
|
4644
|
+
}, _callee29, this, [[26, 33]]);
|
|
4485
4645
|
}));
|
|
4486
4646
|
function runSubmitTempOrder(_x32) {
|
|
4487
4647
|
return _runSubmitTempOrder.apply(this, arguments);
|
|
@@ -4553,10 +4713,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4553
4713
|
value: function extractSubmitErrorResponse(error) {
|
|
4554
4714
|
var _error$response,
|
|
4555
4715
|
_error$response2,
|
|
4556
|
-
|
|
4716
|
+
_this25 = this;
|
|
4557
4717
|
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];
|
|
4558
4718
|
return candidates.find(function (candidate) {
|
|
4559
|
-
return
|
|
4719
|
+
return _this25.isSubmitErrorResponse(candidate);
|
|
4560
4720
|
}) || null;
|
|
4561
4721
|
}
|
|
4562
4722
|
}, {
|
|
@@ -4584,41 +4744,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4584
4744
|
key: "syncPaymentsToOrder",
|
|
4585
4745
|
value: function () {
|
|
4586
4746
|
var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
|
|
4587
|
-
var
|
|
4747
|
+
var _params$confirmPendin;
|
|
4748
|
+
var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, paidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
|
|
4588
4749
|
return _regeneratorRuntime().wrap(function _callee31$(_context34) {
|
|
4589
4750
|
while (1) switch (_context34.prev = _context34.next) {
|
|
4590
4751
|
case 0:
|
|
4591
4752
|
tempOrder = this.ensureTempOrder();
|
|
4592
4753
|
mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4754
|
+
shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
|
|
4755
|
+
effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
|
|
4756
|
+
completion = this.getPaymentCompletion(effectivePayments);
|
|
4757
|
+
paidPaymentTotal = this.calculatePaymentTotal(effectivePayments);
|
|
4758
|
+
paymentStatus = completion.isOrderFullyPaid ? params.paymentStatus || 'paid' : paidPaymentTotal.gt(0) ? 'partially_paid' : 'payment_processing';
|
|
4759
|
+
tempOrder.payments = effectivePayments;
|
|
4596
4760
|
tempOrder.payment_status = paymentStatus;
|
|
4597
4761
|
this.persistTempOrder();
|
|
4598
|
-
_context34.next =
|
|
4762
|
+
_context34.next = 12;
|
|
4599
4763
|
return this.saveDraft();
|
|
4600
|
-
case
|
|
4764
|
+
case 12:
|
|
4601
4765
|
if (params.submitWhenPaid) {
|
|
4602
|
-
_context34.next =
|
|
4766
|
+
_context34.next = 14;
|
|
4603
4767
|
break;
|
|
4604
4768
|
}
|
|
4605
4769
|
return _context34.abrupt("return", completion);
|
|
4606
|
-
case
|
|
4770
|
+
case 14:
|
|
4607
4771
|
if (!(this.store.syncState === 'submitting')) {
|
|
4608
|
-
_context34.next =
|
|
4772
|
+
_context34.next = 16;
|
|
4609
4773
|
break;
|
|
4610
4774
|
}
|
|
4611
4775
|
return _context34.abrupt("return", completion);
|
|
4612
|
-
case
|
|
4776
|
+
case 16:
|
|
4613
4777
|
this.store.syncState = 'submitting';
|
|
4614
|
-
paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder,
|
|
4615
|
-
_context34.next =
|
|
4778
|
+
paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
|
|
4779
|
+
_context34.next = 20;
|
|
4616
4780
|
return this.submitTempOrder({
|
|
4617
|
-
payments:
|
|
4781
|
+
payments: effectivePayments,
|
|
4618
4782
|
paymentStatus: paymentStatus,
|
|
4619
4783
|
smallTicketDataFlag: params.smallTicketDataFlag,
|
|
4620
4784
|
businessCode: params.businessCode,
|
|
4621
4785
|
channel: params.channel,
|
|
4786
|
+
confirmPendingVoucherPayments: true,
|
|
4622
4787
|
enhancePayload: function enhancePayload(payload) {
|
|
4623
4788
|
var nextPayload = _objectSpread(_objectSpread({}, payload), {}, {
|
|
4624
4789
|
request_unique_idempotency_token: paymentSyncIdempotencyToken
|
|
@@ -4626,12 +4791,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
4626
4791
|
return nextPayload;
|
|
4627
4792
|
}
|
|
4628
4793
|
});
|
|
4629
|
-
case
|
|
4794
|
+
case 20:
|
|
4630
4795
|
submitResult = _context34.sent;
|
|
4631
4796
|
return _context34.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
|
|
4632
4797
|
submitResult: submitResult
|
|
4633
4798
|
}));
|
|
4634
|
-
case
|
|
4799
|
+
case 22:
|
|
4635
4800
|
case "end":
|
|
4636
4801
|
return _context34.stop();
|
|
4637
4802
|
}
|
|
@@ -5144,27 +5309,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5144
5309
|
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() || [] : [];
|
|
5145
5310
|
shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
|
|
5146
5311
|
if (shouldSkipEmptyDiscountSync) {
|
|
5147
|
-
_context42.next =
|
|
5312
|
+
_context42.next = 17;
|
|
5148
5313
|
break;
|
|
5149
5314
|
}
|
|
5150
|
-
|
|
5315
|
+
OrderModule.populateSavedAmounts(nextTempOrder.products, hydratedEditDiscounts);
|
|
5316
|
+
_context42.next = 15;
|
|
5151
5317
|
return (_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList(hydratedEditDiscounts);
|
|
5152
|
-
case
|
|
5153
|
-
_context42.next =
|
|
5318
|
+
case 15:
|
|
5319
|
+
_context42.next = 17;
|
|
5154
5320
|
return (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList(hydratedEditDiscounts);
|
|
5155
|
-
case
|
|
5321
|
+
case 17:
|
|
5156
5322
|
if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
|
|
5157
|
-
_context42.next =
|
|
5323
|
+
_context42.next = 20;
|
|
5158
5324
|
break;
|
|
5159
5325
|
}
|
|
5160
|
-
_context42.next =
|
|
5326
|
+
_context42.next = 20;
|
|
5161
5327
|
return this.recalculateSummary({
|
|
5162
5328
|
createIfMissing: false
|
|
5163
5329
|
});
|
|
5164
|
-
case
|
|
5330
|
+
case 20:
|
|
5165
5331
|
this.persistTempOrder();
|
|
5166
5332
|
return _context42.abrupt("return", nextTempOrder);
|
|
5167
|
-
case
|
|
5333
|
+
case 22:
|
|
5168
5334
|
case "end":
|
|
5169
5335
|
return _context42.stop();
|
|
5170
5336
|
}
|
|
@@ -5211,7 +5377,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5211
5377
|
}, {
|
|
5212
5378
|
key: "normalizeTempOrderForRuntime",
|
|
5213
5379
|
value: function normalizeTempOrderForRuntime(raw, options) {
|
|
5214
|
-
var
|
|
5380
|
+
var _this26 = this;
|
|
5215
5381
|
var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
|
|
5216
5382
|
// ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
|
|
5217
5383
|
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) {
|
|
@@ -5234,10 +5400,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5234
5400
|
nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
|
|
5235
5401
|
var rawProducts = Array.isArray(raw.products) ? raw.products : [];
|
|
5236
5402
|
nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
|
|
5237
|
-
return
|
|
5403
|
+
return _this26.normalizeHydratedOrderProduct(p);
|
|
5238
5404
|
}) : [];
|
|
5239
5405
|
nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
|
|
5240
|
-
var booking =
|
|
5406
|
+
var booking = _this26.normalizeHydratedBookingHolder(b || {});
|
|
5241
5407
|
return _objectSpread(_objectSpread({}, booking), {}, {
|
|
5242
5408
|
is_all: normalizeBookingIsAll(booking),
|
|
5243
5409
|
sub_type: normalizeBookingSubType(booking)
|
|
@@ -5267,7 +5433,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5267
5433
|
_step22;
|
|
5268
5434
|
try {
|
|
5269
5435
|
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
5270
|
-
var _product$metadata8,
|
|
5436
|
+
var _product$metadata8, _ref74, _ref75, _existed$origin, _rawProduct$metadata;
|
|
5271
5437
|
var _step22$value = _slicedToArray(_step22.value, 2),
|
|
5272
5438
|
index = _step22$value[0],
|
|
5273
5439
|
product = _step22$value[1];
|
|
@@ -5275,7 +5441,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5275
5441
|
if (!uid) continue;
|
|
5276
5442
|
var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
|
|
5277
5443
|
var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
|
|
5278
|
-
var origin = (
|
|
5444
|
+
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;
|
|
5279
5445
|
var originSnapshot = cloneDeep(origin);
|
|
5280
5446
|
var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
|
|
5281
5447
|
if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
|
|
@@ -5385,10 +5551,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5385
5551
|
}, {
|
|
5386
5552
|
key: "normalizeHydratedProductOptionItem",
|
|
5387
5553
|
value: function normalizeHydratedProductOptionItem(optionItem) {
|
|
5388
|
-
var
|
|
5389
|
-
var rawNum = (
|
|
5554
|
+
var _ref76, _optionItem$num, _ref77, _optionItem$add_price;
|
|
5555
|
+
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;
|
|
5390
5556
|
var parsedNum = Number(rawNum);
|
|
5391
|
-
var rawPrice = (
|
|
5557
|
+
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;
|
|
5392
5558
|
var parsedPrice = Number(rawPrice);
|
|
5393
5559
|
var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
|
|
5394
5560
|
option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
|
|
@@ -5405,7 +5571,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5405
5571
|
}, {
|
|
5406
5572
|
key: "normalizeHydratedOrderProduct",
|
|
5407
5573
|
value: function normalizeHydratedOrderProduct(product) {
|
|
5408
|
-
var
|
|
5574
|
+
var _this27 = this;
|
|
5409
5575
|
var row = _objectSpread({}, product || {});
|
|
5410
5576
|
if (row.num === undefined && row.product_quantity !== undefined) {
|
|
5411
5577
|
row.num = row.product_quantity;
|
|
@@ -5413,7 +5579,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5413
5579
|
var productSku = ensureProductSku(row);
|
|
5414
5580
|
row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
|
|
5415
5581
|
option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
|
|
5416
|
-
return
|
|
5582
|
+
return _this27.normalizeHydratedProductOptionItem(optionItem || {});
|
|
5417
5583
|
}))
|
|
5418
5584
|
});
|
|
5419
5585
|
delete row["product_".concat('option', "_item")];
|
|
@@ -5422,6 +5588,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5422
5588
|
if (row.booking_uid && !row.metadata.booking_uid) {
|
|
5423
5589
|
row.metadata.booking_uid = row.booking_uid;
|
|
5424
5590
|
}
|
|
5591
|
+
row = restoreHydratedBundleDiscounts(row, normalizeOrderProductDiscountList);
|
|
5425
5592
|
var existingIdentity = row.metadata.unique_identification_number || row.unique_identification_number;
|
|
5426
5593
|
if (!existingIdentity) {
|
|
5427
5594
|
row.metadata.unique_identification_number = createUuidV4();
|
|
@@ -5433,7 +5600,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5433
5600
|
metadata: _objectSpread(_objectSpread({}, row.metadata), normalized.metadata)
|
|
5434
5601
|
});
|
|
5435
5602
|
if (result.metadata) delete result.metadata.price_schema_version;
|
|
5436
|
-
|
|
5603
|
+
var restored = restoreHydratedBundleDiscounts(result, normalizeOrderProductDiscountList);
|
|
5604
|
+
return this.sanitizeOrderProductForTempOrder(restored);
|
|
5437
5605
|
}
|
|
5438
5606
|
}, {
|
|
5439
5607
|
key: "getLastOrderInfo",
|
|
@@ -5452,6 +5620,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5452
5620
|
_context43.next = 2;
|
|
5453
5621
|
return this.request.get("/order/sales/".concat(order_id), {
|
|
5454
5622
|
with: ['products', 'bookings']
|
|
5623
|
+
}, {
|
|
5624
|
+
osServer: true
|
|
5455
5625
|
});
|
|
5456
5626
|
case 2:
|
|
5457
5627
|
res = _context43.sent;
|
|
@@ -5515,10 +5685,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5515
5685
|
_step27;
|
|
5516
5686
|
try {
|
|
5517
5687
|
for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
|
|
5518
|
-
var
|
|
5688
|
+
var _ref78, _bundle$num3;
|
|
5519
5689
|
var bundle = _step27.value;
|
|
5520
5690
|
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));
|
|
5521
|
-
var bundleQty = new Decimal(Number(qty) || 1).times(Number((
|
|
5691
|
+
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();
|
|
5522
5692
|
var _iterator28 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
|
|
5523
5693
|
_step28;
|
|
5524
5694
|
try {
|