@questwork/q-store-model 0.1.34 → 0.1.36
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/index.min.cjs +1031 -641
- package/dist/{index.min.js → q-store-model.min.js} +1204 -813
- package/package.json +14 -17
|
@@ -1,86 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
module.exports = factory(require("@questwork/q-utilities"), require("lodash"));
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
define(["@questwork/q-utilities", "lodash"], factory);
|
|
6
|
+
else if(typeof exports === 'object')
|
|
7
|
+
exports["@questwork/q-store-model"] = factory(require("@questwork/q-utilities"), require("lodash"));
|
|
8
|
+
else
|
|
9
|
+
root["@questwork/q-store-model"] = factory(root["@questwork/q-utilities"], root["lodash"]);
|
|
10
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__898__, __WEBPACK_EXTERNAL_MODULE__773__) => {
|
|
11
|
+
return /******/ (() => { // webpackBootstrap
|
|
12
|
+
/******/ var __webpack_modules__ = ({
|
|
13
|
+
|
|
14
|
+
/***/ 773:
|
|
15
|
+
/***/ ((module) => {
|
|
16
|
+
|
|
17
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__773__;
|
|
18
|
+
|
|
19
|
+
/***/ }),
|
|
20
|
+
|
|
21
|
+
/***/ 898:
|
|
22
|
+
/***/ ((module) => {
|
|
23
|
+
|
|
24
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__898__;
|
|
25
|
+
|
|
26
|
+
/***/ })
|
|
27
|
+
|
|
28
|
+
/******/ });
|
|
6
29
|
/************************************************************************/
|
|
7
|
-
/******/
|
|
8
|
-
/******/
|
|
9
|
-
/******/
|
|
10
|
-
/******/
|
|
11
|
-
/******/
|
|
12
|
-
/******/
|
|
13
|
-
/******/
|
|
14
|
-
/******/
|
|
30
|
+
/******/ // The module cache
|
|
31
|
+
/******/ var __webpack_module_cache__ = {};
|
|
32
|
+
/******/
|
|
33
|
+
/******/ // The require function
|
|
34
|
+
/******/ function __webpack_require__(moduleId) {
|
|
35
|
+
/******/ // Check if module is in cache
|
|
36
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
37
|
+
/******/ if (cachedModule !== undefined) {
|
|
38
|
+
/******/ return cachedModule.exports;
|
|
15
39
|
/******/ }
|
|
16
|
-
/******/
|
|
17
|
-
/******/
|
|
18
|
-
/******/
|
|
19
|
-
/******/
|
|
20
|
-
/******/
|
|
21
|
-
/******/
|
|
22
|
-
/******/
|
|
23
|
-
/******/
|
|
24
|
-
/******/
|
|
25
|
-
/******/
|
|
26
|
-
/******/
|
|
27
|
-
/******/
|
|
28
|
-
/******/
|
|
29
|
-
/******/
|
|
30
|
-
|
|
31
|
-
/******/
|
|
32
|
-
/******/
|
|
33
|
-
/******/
|
|
34
|
-
/******/
|
|
40
|
+
/******/ // Create a new module (and put it into the cache)
|
|
41
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
42
|
+
/******/ // no module.id needed
|
|
43
|
+
/******/ // no module.loaded needed
|
|
44
|
+
/******/ exports: {}
|
|
45
|
+
/******/ };
|
|
46
|
+
/******/
|
|
47
|
+
/******/ // Execute the module function
|
|
48
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
49
|
+
/******/
|
|
50
|
+
/******/ // Return the exports of the module
|
|
51
|
+
/******/ return module.exports;
|
|
52
|
+
/******/ }
|
|
53
|
+
/******/
|
|
54
|
+
/************************************************************************/
|
|
55
|
+
/******/ /* webpack/runtime/define property getters */
|
|
56
|
+
/******/ (() => {
|
|
57
|
+
/******/ // define getter functions for harmony exports
|
|
58
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
59
|
+
/******/ for(var key in definition) {
|
|
60
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
61
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
62
|
+
/******/ }
|
|
63
|
+
/******/ }
|
|
64
|
+
/******/ };
|
|
65
|
+
/******/ })();
|
|
66
|
+
/******/
|
|
67
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
68
|
+
/******/ (() => {
|
|
69
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
70
|
+
/******/ })();
|
|
71
|
+
/******/
|
|
72
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
73
|
+
/******/ (() => {
|
|
74
|
+
/******/ // define __esModule on exports
|
|
75
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
76
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
77
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
78
|
+
/******/ }
|
|
79
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
80
|
+
/******/ };
|
|
81
|
+
/******/ })();
|
|
82
|
+
/******/
|
|
35
83
|
/************************************************************************/
|
|
36
84
|
var __webpack_exports__ = {};
|
|
85
|
+
// ESM COMPAT FLAG
|
|
86
|
+
__webpack_require__.r(__webpack_exports__);
|
|
37
87
|
|
|
38
88
|
// EXPORTS
|
|
39
89
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
Amount: () => (/* reexport */ Amount),
|
|
91
|
+
Cart: () => (/* reexport */ Cart),
|
|
92
|
+
CartItem: () => (/* reexport */ CartItem),
|
|
93
|
+
Category: () => (/* reexport */ Category),
|
|
94
|
+
Chain: () => (/* reexport */ Chain),
|
|
95
|
+
ChainManager: () => (/* reexport */ ChainManager),
|
|
96
|
+
ChainManagerFactory: () => (/* reexport */ ChainManagerFactory),
|
|
97
|
+
ChainTarget: () => (/* reexport */ ChainTarget),
|
|
98
|
+
CouponManager: () => (/* reexport */ CouponManager),
|
|
99
|
+
CreditNote: () => (/* reexport */ CreditNote),
|
|
100
|
+
CreditNoteLine: () => (/* reexport */ CreditNoteLine),
|
|
101
|
+
CreditNoteRepo: () => (/* reexport */ CreditNoteRepo),
|
|
102
|
+
Currency: () => (/* reexport */ Currency),
|
|
103
|
+
Invoice: () => (/* reexport */ Invoice),
|
|
104
|
+
InvoiceLine: () => (/* reexport */ InvoiceLine),
|
|
105
|
+
ItemOption: () => (/* reexport */ ItemOption),
|
|
106
|
+
ItemOptionLocale: () => (/* reexport */ ItemOptionLocale),
|
|
107
|
+
KeyValueObject: () => (/* reexport */ q_utilities_.KeyValueObject),
|
|
108
|
+
Merchandise: () => (/* reexport */ Merchandise),
|
|
109
|
+
PaymentGateway: () => (/* reexport */ PaymentGateway),
|
|
110
|
+
PaymentResult: () => (/* reexport */ PaymentResult),
|
|
111
|
+
Price: () => (/* reexport */ Price),
|
|
112
|
+
PriceStrategy: () => (/* reexport */ PriceStrategy),
|
|
113
|
+
Product: () => (/* reexport */ Product),
|
|
114
|
+
Status: () => (/* reexport */ Status),
|
|
115
|
+
StoreItem: () => (/* reexport */ StoreItem),
|
|
116
|
+
Transaction: () => (/* reexport */ Transaction),
|
|
117
|
+
WalletItem: () => (/* reexport */ WalletItem),
|
|
118
|
+
adminSettle: () => (/* reexport */ adminSettle),
|
|
119
|
+
calculateByCoupon: () => (/* reexport */ calculateByCoupon),
|
|
120
|
+
calculator: () => (/* reexport */ calculator),
|
|
121
|
+
checkDuplicate: () => (/* reexport */ checkDuplicate),
|
|
122
|
+
convertTimestampToString: () => (/* reexport */ convertTimestampToString),
|
|
123
|
+
defaultComparator: () => (/* reexport */ defaultComparator),
|
|
124
|
+
defaultSort: () => (/* reexport */ defaultSort),
|
|
125
|
+
eleInArrayComparator: () => (/* reexport */ eleInArrayComparator),
|
|
126
|
+
firstLetterToLower: () => (/* reexport */ firstLetterToLower),
|
|
127
|
+
getFakeClass: () => (/* reexport */ getFakeClass),
|
|
128
|
+
getSubClass: () => (/* reexport */ getSubClass),
|
|
129
|
+
handlerOrderList: () => (/* reexport */ handlerOrderList),
|
|
130
|
+
isAllEqual: () => (/* reexport */ isAllEqual),
|
|
131
|
+
isDescendingOrder: () => (/* reexport */ isDescendingOrder),
|
|
132
|
+
makeResponseHelper: () => (/* reexport */ makeResponseHelper),
|
|
133
|
+
models: () => (/* reexport */ models),
|
|
134
|
+
objectAllInArrayComparator: () => (/* reexport */ objectAllInArrayComparator),
|
|
135
|
+
objectComparator: () => (/* reexport */ objectComparator),
|
|
136
|
+
objectOrderInArrayComparator: () => (/* reexport */ objectOrderInArrayComparator),
|
|
137
|
+
setQuery: () => (/* reexport */ setQuery),
|
|
138
|
+
stringHelper: () => (/* reexport */ stringHelper)
|
|
84
139
|
});
|
|
85
140
|
|
|
86
141
|
// NAMESPACE OBJECT: ./lib/models/index.js
|
|
@@ -97,7 +152,9 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
97
152
|
Currency: () => (Currency),
|
|
98
153
|
Invoice: () => (Invoice),
|
|
99
154
|
InvoiceLine: () => (InvoiceLine),
|
|
100
|
-
|
|
155
|
+
ItemOption: () => (ItemOption),
|
|
156
|
+
ItemOptionLocale: () => (ItemOptionLocale),
|
|
157
|
+
KeyValueObject: () => (q_utilities_.KeyValueObject),
|
|
101
158
|
Merchandise: () => (Merchandise),
|
|
102
159
|
PaymentGateway: () => (PaymentGateway),
|
|
103
160
|
PaymentResult: () => (PaymentResult),
|
|
@@ -105,6 +162,7 @@ __webpack_require__.d(models_namespaceObject, {
|
|
|
105
162
|
PriceStrategy: () => (PriceStrategy),
|
|
106
163
|
Product: () => (Product),
|
|
107
164
|
Status: () => (Status),
|
|
165
|
+
StoreItem: () => (StoreItem),
|
|
108
166
|
Transaction: () => (Transaction),
|
|
109
167
|
WalletItem: () => (WalletItem)
|
|
110
168
|
});
|
|
@@ -188,18 +246,10 @@ class Amount {
|
|
|
188
246
|
|
|
189
247
|
|
|
190
248
|
|
|
191
|
-
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var y = (x) => (() => (x))
|
|
196
|
-
const q_utilities_namespaceObject = x({ ["KeyValueObject"]: () => (__WEBPACK_EXTERNAL_MODULE__questwork_q_utilities_9fa93684__.KeyValueObject), ["Metadata"]: () => (__WEBPACK_EXTERNAL_MODULE__questwork_q_utilities_9fa93684__.Metadata), ["Repo"]: () => (__WEBPACK_EXTERNAL_MODULE__questwork_q_utilities_9fa93684__.Repo) });
|
|
197
|
-
;// external "lodash"
|
|
198
|
-
var external_lodash_x = (y) => {
|
|
199
|
-
var x = {}; __webpack_require__.d(x, y); return x
|
|
200
|
-
}
|
|
201
|
-
var external_lodash_y = (x) => (() => (x))
|
|
202
|
-
const external_lodash_namespaceObject = external_lodash_x({ ["default"]: () => (__WEBPACK_EXTERNAL_MODULE_lodash__["default"]) });
|
|
249
|
+
// EXTERNAL MODULE: external "@questwork/q-utilities"
|
|
250
|
+
var q_utilities_ = __webpack_require__(898);
|
|
251
|
+
// EXTERNAL MODULE: external "lodash"
|
|
252
|
+
var external_lodash_ = __webpack_require__(773);
|
|
203
253
|
;// ./lib/models/itemOptionFillIn/itemOptionFillIn.js
|
|
204
254
|
|
|
205
255
|
const updateAllowedProps = [
|
|
@@ -284,7 +334,7 @@ class ItemOptionFillIn {
|
|
|
284
334
|
;// ./lib/helpers/utilHelper/calculator.js
|
|
285
335
|
|
|
286
336
|
|
|
287
|
-
const lodash =
|
|
337
|
+
const lodash = external_lodash_.noConflict()
|
|
288
338
|
|
|
289
339
|
function calculator(qty, rules) {
|
|
290
340
|
const groupRules = _getArrayCombination(rules)
|
|
@@ -376,7 +426,7 @@ function _getArrayCombination(input = []) {
|
|
|
376
426
|
;// ./lib/helpers/utilHelper/checkDuplicateHelper.js
|
|
377
427
|
|
|
378
428
|
|
|
379
|
-
const checkDuplicateHelper_lodash =
|
|
429
|
+
const checkDuplicateHelper_lodash = external_lodash_.noConflict()
|
|
380
430
|
|
|
381
431
|
function checkDuplicate(target, compare, options) {
|
|
382
432
|
options = options || {}
|
|
@@ -712,20 +762,83 @@ const stringHelper = {
|
|
|
712
762
|
|
|
713
763
|
|
|
714
764
|
|
|
765
|
+
;// ./lib/models/itemOption/itemOptionLocale.js
|
|
766
|
+
const itemOptionLocale_updateAllowedProps = [
|
|
767
|
+
'label',
|
|
768
|
+
'locale',
|
|
769
|
+
'value'
|
|
770
|
+
]
|
|
771
|
+
|
|
772
|
+
class ItemOptionLocale {
|
|
773
|
+
constructor(options = {}) {
|
|
774
|
+
options = options || {}
|
|
775
|
+
this.locale = options.locale
|
|
776
|
+
this.label = options.label
|
|
777
|
+
this.value = options.value || ''
|
|
778
|
+
}
|
|
779
|
+
static dummyData() {
|
|
780
|
+
return {
|
|
781
|
+
// locale: 'zh-hk',
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
static init(options = {}) {
|
|
785
|
+
if (options instanceof this) {
|
|
786
|
+
return options
|
|
787
|
+
}
|
|
788
|
+
const instance = new this(options)
|
|
789
|
+
return instance.isValid ? instance : null
|
|
790
|
+
}
|
|
791
|
+
static initFromArray(arr = []) {
|
|
792
|
+
if (Array.isArray(arr)) {
|
|
793
|
+
return arr.map((a) => this.init(a))
|
|
794
|
+
}
|
|
795
|
+
return []
|
|
796
|
+
}
|
|
797
|
+
static initOnlyValidFromArray(arr = []) {
|
|
798
|
+
return this.initFromArray(arr).filter((i) => i)
|
|
799
|
+
}
|
|
800
|
+
static get _classname() {
|
|
801
|
+
return 'ItemOptionLocale'
|
|
802
|
+
}
|
|
803
|
+
static get _superclass() {
|
|
804
|
+
return 'ItemOptionLocale'
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
get isValid() {
|
|
808
|
+
return !!this
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
update(update) {
|
|
812
|
+
Object.keys(update).forEach((key) => {
|
|
813
|
+
if (itemOptionLocale_updateAllowedProps.includes(key)) {
|
|
814
|
+
this[key] = update[key]
|
|
815
|
+
}
|
|
816
|
+
})
|
|
817
|
+
return this
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
715
823
|
;// ./lib/models/itemOption/itemOption.js
|
|
716
824
|
|
|
717
825
|
|
|
826
|
+
|
|
718
827
|
const itemOption_updateAllowedProps = [
|
|
719
828
|
'description',
|
|
720
829
|
'key',
|
|
721
830
|
'label',
|
|
722
831
|
'type',
|
|
723
|
-
'value'
|
|
832
|
+
'value',
|
|
833
|
+
'locales'
|
|
724
834
|
]
|
|
725
835
|
|
|
726
836
|
class ItemOption {
|
|
727
837
|
constructor(options = {}) {
|
|
728
838
|
options = options || {}
|
|
839
|
+
const { _ItemOptionLocale } = options._constructor || {}
|
|
840
|
+
this._ItemOptionLocale = _ItemOptionLocale && (_ItemOptionLocale._superclass === ItemOptionLocale._superclass) ? _ItemOptionLocale : ItemOptionLocale
|
|
841
|
+
|
|
729
842
|
this.approved = options.approved || false
|
|
730
843
|
this.description = options.description
|
|
731
844
|
// this.header = options.header
|
|
@@ -733,9 +846,11 @@ class ItemOption {
|
|
|
733
846
|
this.itemOptionType = options.itemOptionType || 'ItemOption'
|
|
734
847
|
this.key = options.key
|
|
735
848
|
this.label = options.label
|
|
849
|
+
this.layout = options.layout
|
|
736
850
|
this.required = options.required || false
|
|
737
851
|
this.type = options.type
|
|
738
852
|
this.value = options.value || ''
|
|
853
|
+
this.locales = this._ItemOptionLocale.initOnlyValidFromArray(options.locales)
|
|
739
854
|
}
|
|
740
855
|
static dummyData() {
|
|
741
856
|
return {
|
|
@@ -796,7 +911,12 @@ class ItemOption {
|
|
|
796
911
|
update(update) {
|
|
797
912
|
Object.keys(update).forEach((key) => {
|
|
798
913
|
if (itemOption_updateAllowedProps.includes(key)) {
|
|
799
|
-
|
|
914
|
+
if (key === 'locales') {
|
|
915
|
+
this[key] = this._ItemOptionLocale.initOnlyValidFromArray(update[key])
|
|
916
|
+
} else {
|
|
917
|
+
this[key] = update[key]
|
|
918
|
+
}
|
|
919
|
+
// this[key] = update[key]
|
|
800
920
|
}
|
|
801
921
|
})
|
|
802
922
|
return this
|
|
@@ -818,6 +938,7 @@ function itemOption_setCode(options, key) {
|
|
|
818
938
|
|
|
819
939
|
|
|
820
940
|
|
|
941
|
+
|
|
821
942
|
;// ./lib/models/merchandiseOption/merchandiseOption.js
|
|
822
943
|
class MerchandiseOption {
|
|
823
944
|
constructor(options = {}) {
|
|
@@ -1005,7 +1126,7 @@ class PriceStrategy {
|
|
|
1005
1126
|
// this.order = options.order || 1
|
|
1006
1127
|
this.qtyPerTransaction = this._QtyPerTransaction.init(options.qtyPerTransaction)
|
|
1007
1128
|
this.priceStrategyType = options.priceStrategyType || 'PriceStrategy'
|
|
1008
|
-
this.remarks =
|
|
1129
|
+
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1009
1130
|
}
|
|
1010
1131
|
|
|
1011
1132
|
// class method
|
|
@@ -1118,7 +1239,7 @@ class PriceStrategy {
|
|
|
1118
1239
|
}
|
|
1119
1240
|
|
|
1120
1241
|
isMatchedRestrictions(payload = {}) {
|
|
1121
|
-
const [restrictions = []] =
|
|
1242
|
+
const [restrictions = []] = q_utilities_.KeyValueObject.getValuesByKey(this.remarks, 'restrictions')
|
|
1122
1243
|
if (restrictions.length === 0) {
|
|
1123
1244
|
return true
|
|
1124
1245
|
}
|
|
@@ -1127,7 +1248,7 @@ class PriceStrategy {
|
|
|
1127
1248
|
acc = acc || matchAnd(key, value, payload)
|
|
1128
1249
|
// Object.keys(value).forEach((path) => {
|
|
1129
1250
|
// const val = lodash.get(payload[key], path)
|
|
1130
|
-
// acc = acc ||
|
|
1251
|
+
// acc = acc || _matcher(val, value[path])
|
|
1131
1252
|
// })
|
|
1132
1253
|
return acc
|
|
1133
1254
|
}, false)
|
|
@@ -1143,7 +1264,7 @@ class PriceStrategy {
|
|
|
1143
1264
|
|
|
1144
1265
|
setRemarks(remarks) {
|
|
1145
1266
|
if (Array.isArray(remarks)) {
|
|
1146
|
-
this.remarks =
|
|
1267
|
+
this.remarks = q_utilities_.KeyValueObject.initFromArray(remarks)
|
|
1147
1268
|
}
|
|
1148
1269
|
return this
|
|
1149
1270
|
}
|
|
@@ -1180,8 +1301,9 @@ class PriceStrategy {
|
|
|
1180
1301
|
|
|
1181
1302
|
function matchAnd(key, value, payload) {
|
|
1182
1303
|
return Object.keys(value).reduce((acc, path) => {
|
|
1183
|
-
const val =
|
|
1184
|
-
|
|
1304
|
+
const val = external_lodash_.get(payload[key], path)
|
|
1305
|
+
const actions = Object.keys(value[path])
|
|
1306
|
+
acc = acc && _matcher(val, value[path], actions, true)
|
|
1185
1307
|
return acc
|
|
1186
1308
|
}, true)
|
|
1187
1309
|
}
|
|
@@ -1192,20 +1314,40 @@ function matchAnd(key, value, payload) {
|
|
|
1192
1314
|
* @param {Object} [formula={}] - The formula object to check the value against.
|
|
1193
1315
|
* @returns {boolean} - Whether the value matches the formula.
|
|
1194
1316
|
*/
|
|
1195
|
-
function
|
|
1196
|
-
const
|
|
1317
|
+
function _matcher(val, formula = {}, actions = [], match = true) {
|
|
1318
|
+
// const actions = Object.keys(formula)
|
|
1319
|
+
if (!match || actions.length === 0) {
|
|
1320
|
+
return match
|
|
1321
|
+
}
|
|
1322
|
+
const action = actions.shift()
|
|
1323
|
+
// const [action] = Object.keys(formula)
|
|
1197
1324
|
const formulaValue = formula[action]
|
|
1325
|
+
match = _match({ action, formulaValue, val })
|
|
1326
|
+
return _matcher(val, formula, actions, match)
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function _match({ action, formulaValue, val }) {
|
|
1198
1330
|
switch (action) {
|
|
1331
|
+
case 'elemMatch':
|
|
1199
1332
|
case '$elemMatch': // val is array and formulaValue is object
|
|
1200
1333
|
return (val || []).some((v) => {
|
|
1201
1334
|
return (Object.keys(formulaValue)).filter((key) => {
|
|
1202
1335
|
return Object.prototype.hasOwnProperty.call(v, key) && v[key] === formulaValue[key]
|
|
1203
1336
|
}).length > 0
|
|
1204
1337
|
})
|
|
1338
|
+
case 'eq':
|
|
1205
1339
|
case '$eq':
|
|
1206
|
-
return
|
|
1340
|
+
return external_lodash_.isEqual(val, formulaValue)
|
|
1341
|
+
case 'gt':
|
|
1342
|
+
case '$gt':
|
|
1343
|
+
return val > formulaValue
|
|
1344
|
+
case 'gte':
|
|
1345
|
+
case '$gte':
|
|
1346
|
+
return val >= formulaValue
|
|
1207
1347
|
case '$in':
|
|
1208
1348
|
return formulaValue.includes(val)
|
|
1349
|
+
case '$includes':
|
|
1350
|
+
return val.includes(formulaValue)
|
|
1209
1351
|
case '$keyValue':
|
|
1210
1352
|
if (Array.isArray(val)) {
|
|
1211
1353
|
return (val.find((remark) => {
|
|
@@ -1216,6 +1358,15 @@ function matcher(val, formula = {}) {
|
|
|
1216
1358
|
return formulaValue.key === val.key && formulaValue.values.includes(val.value)
|
|
1217
1359
|
}
|
|
1218
1360
|
return false
|
|
1361
|
+
case 'lt':
|
|
1362
|
+
case '$lt':
|
|
1363
|
+
return val < formulaValue
|
|
1364
|
+
case 'lte':
|
|
1365
|
+
case '$lte':
|
|
1366
|
+
return val <= formulaValue
|
|
1367
|
+
case 'ne':
|
|
1368
|
+
case '$ne':
|
|
1369
|
+
return val !== formulaValue
|
|
1219
1370
|
default:
|
|
1220
1371
|
return true
|
|
1221
1372
|
}
|
|
@@ -1254,7 +1405,7 @@ class Price {
|
|
|
1254
1405
|
this.name = options.name
|
|
1255
1406
|
this.priceStrategies = this._PriceStrategy.initOnlyValidFromArray(options.priceStrategies)
|
|
1256
1407
|
// this.qtyPerTransaction = QtyPerTransaction.init(options.qtyPerTransaction)
|
|
1257
|
-
this.remarks =
|
|
1408
|
+
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1258
1409
|
// this.roleCodes = options.roleCodes || []
|
|
1259
1410
|
}
|
|
1260
1411
|
|
|
@@ -1269,7 +1420,7 @@ class Price {
|
|
|
1269
1420
|
name: 'Standard',
|
|
1270
1421
|
dateBegin: new Date().valueOf(),
|
|
1271
1422
|
dateEnd: new Date().valueOf() + 1,
|
|
1272
|
-
priceStrategies: [
|
|
1423
|
+
priceStrategies: [PriceStrategy.dummyData()],
|
|
1273
1424
|
// roles: []
|
|
1274
1425
|
// qtyPerTransaction: QtyPerTransaction.init()
|
|
1275
1426
|
}
|
|
@@ -1401,7 +1552,7 @@ class Price {
|
|
|
1401
1552
|
Object.keys(update).forEach((key) => {
|
|
1402
1553
|
if (price_updateAllowedProps.includes(key)) {
|
|
1403
1554
|
if (key === 'remarks') {
|
|
1404
|
-
this[key] =
|
|
1555
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
1405
1556
|
} else if (key === 'priceStrategies') {
|
|
1406
1557
|
this[key] = this._PriceStrategy.initOnlyValidFromArray(update[key])
|
|
1407
1558
|
} else {
|
|
@@ -1427,16 +1578,15 @@ class Price {
|
|
|
1427
1578
|
|
|
1428
1579
|
|
|
1429
1580
|
const product_updateAllowedProps = [
|
|
1430
|
-
'
|
|
1431
|
-
'deleted',
|
|
1581
|
+
'couponDetails',
|
|
1432
1582
|
'description',
|
|
1433
1583
|
'entitlements',
|
|
1434
1584
|
'intangible',
|
|
1435
1585
|
'limitPercentage',
|
|
1586
|
+
'lineOptions',
|
|
1436
1587
|
'maxPerWallet',
|
|
1437
1588
|
'name',
|
|
1438
1589
|
'originalStock',
|
|
1439
|
-
'owner',
|
|
1440
1590
|
'printable',
|
|
1441
1591
|
'printLayoutCodes',
|
|
1442
1592
|
'printLayoutMappingCodes',
|
|
@@ -1444,34 +1594,31 @@ const product_updateAllowedProps = [
|
|
|
1444
1594
|
// 'productCategoryCodes',
|
|
1445
1595
|
'productGroupName',
|
|
1446
1596
|
'productOptions',
|
|
1447
|
-
'remarks',
|
|
1448
1597
|
'requiredProductCode',
|
|
1449
1598
|
'stock'
|
|
1450
1599
|
]
|
|
1451
1600
|
|
|
1452
|
-
class Product {
|
|
1601
|
+
class Product extends q_utilities_.TenantAwareEntity {
|
|
1453
1602
|
constructor(options = {}) {
|
|
1454
1603
|
options = options || {}
|
|
1604
|
+
super(options)
|
|
1605
|
+
|
|
1455
1606
|
const { _ItemOption } = options._constructor || {}
|
|
1456
1607
|
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
|
|
1457
1608
|
|
|
1458
1609
|
const id = options._id || options.id
|
|
1459
1610
|
this.id = setId(id)
|
|
1460
1611
|
this._type = options._type || 'Product'
|
|
1461
|
-
|
|
1462
|
-
this.
|
|
1463
|
-
this.creator = options.creator
|
|
1464
|
-
this.deleted = options.deleted || false
|
|
1612
|
+
|
|
1613
|
+
this.couponDetails = options.couponDetails
|
|
1465
1614
|
this.description = options.description || ''
|
|
1466
1615
|
this.entitlements = options.entitlements // ['freeRegistration'], ['presidentialDinner', 'galaDinner']
|
|
1467
1616
|
this.intangible = options.intangible || false
|
|
1468
1617
|
this.limitPercentage = options.limitPercentage || 100
|
|
1618
|
+
this.lineOptions = this._ItemOption.initOnlyValidFromArray(options.lineOptions)
|
|
1469
1619
|
this.maxPerWallet = options.maxPerWallet || 1
|
|
1470
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
1471
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
1472
1620
|
this.name = options.name || ''
|
|
1473
1621
|
this.originalStock = options.originalStock || 0
|
|
1474
|
-
this.owner = options.owner
|
|
1475
1622
|
this.printable = options.printable || false
|
|
1476
1623
|
this.printLayoutCodes = options.printLayoutCodes || []
|
|
1477
1624
|
// will be not use property 'printLayoutMappingCodes'
|
|
@@ -1481,10 +1628,9 @@ class Product {
|
|
|
1481
1628
|
this.productCode = product_setCode(options, 'productCode')
|
|
1482
1629
|
this.productGroupName = (typeof options.productGroupName !== 'undefined') ? options.productGroupName.toUpperCase() : options.productGroupName || 'DEFAULT'
|
|
1483
1630
|
this.productOptions = this._ItemOption.initOnlyValidFromArray(options.productOptions)
|
|
1631
|
+
this.productType = options.productType || 'Product'
|
|
1484
1632
|
this.requiredProductCode = options.requiredProductCode
|
|
1485
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1486
1633
|
this.stock = options.stock || 0
|
|
1487
|
-
this.tenantCode = options.tenantCode
|
|
1488
1634
|
}
|
|
1489
1635
|
|
|
1490
1636
|
// class method
|
|
@@ -1494,22 +1640,6 @@ class Product {
|
|
|
1494
1640
|
tenantCode: 'tenantCode'
|
|
1495
1641
|
}
|
|
1496
1642
|
}
|
|
1497
|
-
static init(options = {}) {
|
|
1498
|
-
if (options instanceof this) {
|
|
1499
|
-
return options
|
|
1500
|
-
}
|
|
1501
|
-
const instance = new this(options)
|
|
1502
|
-
return instance.isValid ? instance : null
|
|
1503
|
-
}
|
|
1504
|
-
static initFromArray(arr = []) {
|
|
1505
|
-
if (Array.isArray(arr)) {
|
|
1506
|
-
return arr.map((a) => this.init(a))
|
|
1507
|
-
}
|
|
1508
|
-
return []
|
|
1509
|
-
}
|
|
1510
|
-
static initOnlyValidFromArray(arr = []) {
|
|
1511
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
1512
|
-
}
|
|
1513
1643
|
static get _classname() {
|
|
1514
1644
|
return 'Product'
|
|
1515
1645
|
}
|
|
@@ -1519,11 +1649,17 @@ class Product {
|
|
|
1519
1649
|
|
|
1520
1650
|
// getters
|
|
1521
1651
|
get isValid() {
|
|
1522
|
-
return
|
|
1652
|
+
return super.isValid && !!this.name
|
|
1523
1653
|
}
|
|
1524
1654
|
get isBadge() {
|
|
1525
1655
|
return this.productGroupName === 'BADGE'
|
|
1526
1656
|
}
|
|
1657
|
+
get isCoupon() {
|
|
1658
|
+
return this.productGroupName === 'COUPON'
|
|
1659
|
+
}
|
|
1660
|
+
get isItemCoupon() {
|
|
1661
|
+
return this.couponDetails ? this.couponDetails.item : false
|
|
1662
|
+
}
|
|
1527
1663
|
get isPrintable() {
|
|
1528
1664
|
return this.printLayoutMappingCodes.length > 0
|
|
1529
1665
|
}
|
|
@@ -1562,6 +1698,12 @@ class Product {
|
|
|
1562
1698
|
return acc
|
|
1563
1699
|
}, { errMsgs: [] })
|
|
1564
1700
|
}
|
|
1701
|
+
getCode() {
|
|
1702
|
+
return this.productCode
|
|
1703
|
+
}
|
|
1704
|
+
getMetadataValueByKey(key) {
|
|
1705
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata || [], key)
|
|
1706
|
+
}
|
|
1565
1707
|
getProductOptionByKey(key) {
|
|
1566
1708
|
const arr = this._ItemOption.getByKey(this.productOptions, key)
|
|
1567
1709
|
if (arr.length === 1) {
|
|
@@ -1572,28 +1714,32 @@ class Product {
|
|
|
1572
1714
|
hasStock(qty) {
|
|
1573
1715
|
return this.stock >= qty
|
|
1574
1716
|
}
|
|
1717
|
+
isApplicableCoupon(obj) {
|
|
1718
|
+
const { merchandiseCodes = [] } = this.couponDetails || {}
|
|
1719
|
+
return merchandiseCodes.length > 0 ? merchandiseCodes.includes(obj.merchandiseCode) : true
|
|
1720
|
+
}
|
|
1721
|
+
isQualified(data) {
|
|
1722
|
+
const rules = this.getMetadataValueByKey('RULES') || []
|
|
1723
|
+
return (rules.length === 0)
|
|
1724
|
+
? true
|
|
1725
|
+
: rules.reduce((acc, r) => {
|
|
1726
|
+
return acc || (0,q_utilities_.getValidation)(r, data, _getDataByKey, q_utilities_.KeyValueObject)
|
|
1727
|
+
}, false)
|
|
1728
|
+
}
|
|
1575
1729
|
isTicket() {
|
|
1576
1730
|
return false
|
|
1577
1731
|
}
|
|
1578
|
-
setModified() {
|
|
1579
|
-
this.modified = (new Date()).valueOf()
|
|
1580
|
-
return this
|
|
1581
|
-
}
|
|
1582
1732
|
update(update) {
|
|
1583
1733
|
Object.keys(update).forEach((key) => {
|
|
1584
1734
|
if (product_updateAllowedProps.includes(key)) {
|
|
1585
|
-
if (key === '
|
|
1586
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
1587
|
-
} else if (key === 'productOptions') {
|
|
1735
|
+
if (key === 'productOptions' || key === 'lineOptions') {
|
|
1588
1736
|
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
1589
|
-
} else if (key === 'remarks') {
|
|
1590
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
1591
1737
|
} else {
|
|
1592
1738
|
this[key] = update[key]
|
|
1593
1739
|
}
|
|
1594
1740
|
}
|
|
1595
1741
|
})
|
|
1596
|
-
return
|
|
1742
|
+
return super.update(update)
|
|
1597
1743
|
}
|
|
1598
1744
|
}
|
|
1599
1745
|
|
|
@@ -1612,13 +1758,17 @@ function product_setCode(options, key) {
|
|
|
1612
1758
|
return stringHelper.setCode()
|
|
1613
1759
|
}
|
|
1614
1760
|
|
|
1761
|
+
function _getDataByKey(key, data) {
|
|
1762
|
+
return (0,q_utilities_.getValueByKeys)(key.split('.'), data)
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1615
1765
|
|
|
1616
1766
|
|
|
1617
1767
|
;// ./lib/models/product/productRepo.js
|
|
1618
1768
|
|
|
1619
1769
|
|
|
1620
1770
|
|
|
1621
|
-
class ProductRepo extends
|
|
1771
|
+
class ProductRepo extends q_utilities_.Repo {
|
|
1622
1772
|
constructor(options = {}) {
|
|
1623
1773
|
options = options || {}
|
|
1624
1774
|
super(options)
|
|
@@ -1651,11 +1801,8 @@ class ProductRepo extends q_utilities_namespaceObject.Repo {
|
|
|
1651
1801
|
|
|
1652
1802
|
|
|
1653
1803
|
|
|
1654
|
-
|
|
1655
1804
|
const merchandise_updateAllowedProps = [
|
|
1656
|
-
'active',
|
|
1657
1805
|
'defaultCurrency',
|
|
1658
|
-
'deleted',
|
|
1659
1806
|
'description',
|
|
1660
1807
|
'eventSessionCode',
|
|
1661
1808
|
'intangible',
|
|
@@ -1663,23 +1810,22 @@ const merchandise_updateAllowedProps = [
|
|
|
1663
1810
|
'max',
|
|
1664
1811
|
'merchandiseCategoryCodes',
|
|
1665
1812
|
'merchandiseOptions',
|
|
1666
|
-
'metadata',
|
|
1667
1813
|
'name',
|
|
1668
1814
|
'onlyFor',
|
|
1669
|
-
'owner',
|
|
1670
1815
|
'prices',
|
|
1671
1816
|
'pricings',
|
|
1672
1817
|
'priority',
|
|
1673
1818
|
'productCodes',
|
|
1674
|
-
'remarks',
|
|
1675
1819
|
'sku',
|
|
1676
1820
|
'stock',
|
|
1677
1821
|
'visibleBy'
|
|
1678
1822
|
]
|
|
1679
1823
|
|
|
1680
|
-
class Merchandise {
|
|
1824
|
+
class Merchandise extends q_utilities_.TenantAwareEntity {
|
|
1681
1825
|
constructor(options = {}) {
|
|
1682
1826
|
options = options || {}
|
|
1827
|
+
super(options)
|
|
1828
|
+
|
|
1683
1829
|
const { _ItemOption, _ItemOptionFillIn, _MerchandiseOption, _Price, _Product } = options._constructor || {}
|
|
1684
1830
|
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption._superclass) ? _I_ItemOptiontemOptionFillIn : ItemOption
|
|
1685
1831
|
this._ItemOptionFillIn = _ItemOptionFillIn && (_ItemOptionFillIn._superclass === ItemOptionFillIn._superclass) ? _ItemOptionFillIn : ItemOptionFillIn
|
|
@@ -1688,16 +1834,11 @@ class Merchandise {
|
|
|
1688
1834
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
1689
1835
|
|
|
1690
1836
|
this._products = options._products || []
|
|
1691
|
-
this._tenant = options._tenant
|
|
1692
1837
|
this._type = options._type || 'Merchandise'
|
|
1693
1838
|
|
|
1694
1839
|
const id = options._id || options.id
|
|
1695
1840
|
this.id = merchandise_setId(id)
|
|
1696
|
-
|
|
1697
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
1698
|
-
this.created = options.created || (new Date()).valueOf()
|
|
1699
|
-
this.creator = options.creator
|
|
1700
|
-
this.deleted = options.deleted || false
|
|
1841
|
+
|
|
1701
1842
|
this.defaultCurrency = options.defaultCurrency || 'HKD'
|
|
1702
1843
|
this.description = options.description
|
|
1703
1844
|
this.free = options.free || false
|
|
@@ -1706,17 +1847,12 @@ class Merchandise {
|
|
|
1706
1847
|
this.merchandiseCategoryCodes = options.merchandiseCategoryCodes || []
|
|
1707
1848
|
this.merchandiseCode = merchandise_setCode(options, 'merchandiseCode')
|
|
1708
1849
|
this.merchandiseOptions = initMerchandiseOptions(this, options)
|
|
1709
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
1710
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
1711
1850
|
this.name = options.name || ''
|
|
1712
|
-
this.owner = options.owner
|
|
1713
1851
|
this.prices = this._Price.initOnlyValidFromArray(options.prices)
|
|
1714
1852
|
this.productCodes = options.productCodes || []
|
|
1715
1853
|
this.priority = options.priority || 100
|
|
1716
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
1717
1854
|
this.sku = options.sku || ''
|
|
1718
1855
|
this.stock = options.stock || 0
|
|
1719
|
-
this.tenantCode = options.tenantCode
|
|
1720
1856
|
}
|
|
1721
1857
|
|
|
1722
1858
|
// Class Mehtods
|
|
@@ -1737,22 +1873,6 @@ class Merchandise {
|
|
|
1737
1873
|
tenantCode: '85223977000',
|
|
1738
1874
|
}
|
|
1739
1875
|
}
|
|
1740
|
-
static init(options = {}) {
|
|
1741
|
-
if (options instanceof this) {
|
|
1742
|
-
return options
|
|
1743
|
-
}
|
|
1744
|
-
const instance = new this(options)
|
|
1745
|
-
return instance.isValid ? instance : null
|
|
1746
|
-
}
|
|
1747
|
-
static initFromArray(arr = []) {
|
|
1748
|
-
if (Array.isArray(arr)) {
|
|
1749
|
-
return arr.map((a) => this.init(a))
|
|
1750
|
-
}
|
|
1751
|
-
return []
|
|
1752
|
-
}
|
|
1753
|
-
static initOnlyValidFromArray(arr = []) {
|
|
1754
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
1755
|
-
}
|
|
1756
1876
|
static get _classname() {
|
|
1757
1877
|
return 'Merchandise'
|
|
1758
1878
|
}
|
|
@@ -1806,7 +1926,7 @@ class Merchandise {
|
|
|
1806
1926
|
return this.printOut.isPrintable
|
|
1807
1927
|
}
|
|
1808
1928
|
get isValid() {
|
|
1809
|
-
return
|
|
1929
|
+
return super.isValid && !!this.name && (!!this.productCodes && this.productCodes.length > 0)
|
|
1810
1930
|
}
|
|
1811
1931
|
get products() {
|
|
1812
1932
|
return this._Product.initOnlyValidFromArray(this._products || [])
|
|
@@ -1953,6 +2073,43 @@ class Merchandise {
|
|
|
1953
2073
|
}
|
|
1954
2074
|
return info
|
|
1955
2075
|
}
|
|
2076
|
+
getBeginAndEndDates() {
|
|
2077
|
+
const dates = {
|
|
2078
|
+
dateBegin: null,
|
|
2079
|
+
dateEnd: null
|
|
2080
|
+
}
|
|
2081
|
+
// BUG this.pricings is undefind
|
|
2082
|
+
return this.pricings.reduce((acc, pricing) => {
|
|
2083
|
+
if (!acc.dateBegin || (pricing.dateBegin > acc.dateBegin)) {
|
|
2084
|
+
acc.dateBegin = pricing.dateBegin
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2087
|
+
if (!acc.dateEnd || (pricing.dateEnd <= acc.dateEnd)) {
|
|
2088
|
+
acc.dateEnd = pricing.dateEnd
|
|
2089
|
+
}
|
|
2090
|
+
return acc
|
|
2091
|
+
}, dates)
|
|
2092
|
+
}
|
|
2093
|
+
getCode() {
|
|
2094
|
+
return this.merchandiseCode
|
|
2095
|
+
}
|
|
2096
|
+
getCurrentPrice() {
|
|
2097
|
+
const timestamp = (new Date()).valueOf()
|
|
2098
|
+
const prices = this.getPricesByTime(timestamp)
|
|
2099
|
+
if (prices.length === 1) {
|
|
2100
|
+
return prices[0]
|
|
2101
|
+
}
|
|
2102
|
+
return null
|
|
2103
|
+
}
|
|
2104
|
+
getCurrentPriceByRoleCodes(roleCodes) {
|
|
2105
|
+
const timestamp = (new Date()).valueOf()
|
|
2106
|
+
let prices = this.getPricesByTime(timestamp)
|
|
2107
|
+
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
2108
|
+
if (prices.length === 1) {
|
|
2109
|
+
return prices[0]
|
|
2110
|
+
}
|
|
2111
|
+
return null
|
|
2112
|
+
}
|
|
1956
2113
|
getItemOptionInfos(cartItems = []) {
|
|
1957
2114
|
return cartItems.reduce((acc, cartItem) => {
|
|
1958
2115
|
const itemOptionFillIns = cartItem.getItemOptionFillIns()
|
|
@@ -1979,47 +2136,13 @@ class Merchandise {
|
|
|
1979
2136
|
}
|
|
1980
2137
|
return null
|
|
1981
2138
|
}
|
|
1982
|
-
|
|
1983
|
-
return this.
|
|
1984
|
-
}
|
|
1985
|
-
getCurrentPriceByRoleCodes(roleCodes) {
|
|
1986
|
-
const timestamp = (new Date()).valueOf()
|
|
1987
|
-
let prices = this.getPricesByTime(timestamp)
|
|
1988
|
-
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
1989
|
-
if (prices.length === 1) {
|
|
1990
|
-
return prices[0]
|
|
1991
|
-
}
|
|
1992
|
-
return null
|
|
1993
|
-
}
|
|
1994
|
-
getCurrentPrice() {
|
|
1995
|
-
const timestamp = (new Date()).valueOf()
|
|
1996
|
-
const prices = this.getPricesByTime(timestamp)
|
|
1997
|
-
if (prices.length === 1) {
|
|
1998
|
-
return prices[0]
|
|
1999
|
-
}
|
|
2000
|
-
return null
|
|
2139
|
+
getPrices() {
|
|
2140
|
+
return this.prices ? this.prices : []
|
|
2001
2141
|
}
|
|
2002
2142
|
getPricesByTime(timestamp) {
|
|
2003
2143
|
const copyDate = timestamp || (new Date()).valueOf()
|
|
2004
2144
|
return Price.getPricesByTime(this.prices, copyDate)
|
|
2005
2145
|
}
|
|
2006
|
-
getBeginAndEndDates() {
|
|
2007
|
-
const dates = {
|
|
2008
|
-
dateBegin: null,
|
|
2009
|
-
dateEnd: null
|
|
2010
|
-
}
|
|
2011
|
-
// BUG this.pricings is undefind
|
|
2012
|
-
return this.pricings.reduce((acc, pricing) => {
|
|
2013
|
-
if (!acc.dateBegin || (pricing.dateBegin > acc.dateBegin)) {
|
|
2014
|
-
acc.dateBegin = pricing.dateBegin
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
|
-
if (!acc.dateEnd || (pricing.dateEnd <= acc.dateEnd)) {
|
|
2018
|
-
acc.dateEnd = pricing.dateEnd
|
|
2019
|
-
}
|
|
2020
|
-
return acc
|
|
2021
|
-
}, dates)
|
|
2022
|
-
}
|
|
2023
2146
|
getPriceByTimeAndRoleCodes(timestamp, roleCodes) {
|
|
2024
2147
|
let prices = this.getPricesByTime(timestamp)
|
|
2025
2148
|
prices = Price.getPricesByRoleCodes(prices, roleCodes)
|
|
@@ -2028,14 +2151,13 @@ class Merchandise {
|
|
|
2028
2151
|
}
|
|
2029
2152
|
return null
|
|
2030
2153
|
}
|
|
2031
|
-
|
|
2032
|
-
return this.
|
|
2033
|
-
}
|
|
2034
|
-
getRemarksByKey(key) {
|
|
2035
|
-
return q_utilities_namespaceObject.KeyValueObject.getValuesByKey(this.remarks, key)
|
|
2154
|
+
getProducts() {
|
|
2155
|
+
return this.products || []
|
|
2036
2156
|
}
|
|
2037
|
-
|
|
2038
|
-
return this.
|
|
2157
|
+
getProductsMetadataValuesByKey(key) {
|
|
2158
|
+
return this.products.map((p) => {
|
|
2159
|
+
return p.getMetadataValueByKey(key)
|
|
2160
|
+
}).filter((i) => i)
|
|
2039
2161
|
}
|
|
2040
2162
|
getProductsQty(qty = 1) {
|
|
2041
2163
|
return this.productCodes.reduce((acc, productCode) => {
|
|
@@ -2047,13 +2169,16 @@ class Merchandise {
|
|
|
2047
2169
|
return acc
|
|
2048
2170
|
}, {})
|
|
2049
2171
|
}
|
|
2172
|
+
getRemarksByKey(key) {
|
|
2173
|
+
return q_utilities_.KeyValueObject.getValuesByKey(this.remarks, key)
|
|
2174
|
+
}
|
|
2175
|
+
getStock() {
|
|
2176
|
+
return this.stock || 0
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2050
2179
|
reachLimit(qty) {
|
|
2051
2180
|
return this.max < qty
|
|
2052
2181
|
}
|
|
2053
|
-
setModified() {
|
|
2054
|
-
this.modified = (new Date()).valueOf()
|
|
2055
|
-
return this
|
|
2056
|
-
}
|
|
2057
2182
|
setPrices(prices) {
|
|
2058
2183
|
if (Array.isArray(prices)) {
|
|
2059
2184
|
this.prices = Price.initOnlyValidFromArray(prices)
|
|
@@ -2067,18 +2192,14 @@ class Merchandise {
|
|
|
2067
2192
|
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
2068
2193
|
} else if (key === 'merchandiseOptions' && !!this.tenantCode) {
|
|
2069
2194
|
this[key] = MerchandiseOption.initOnlyValidFromArray(update[key])
|
|
2070
|
-
} else if (key === 'metadata') {
|
|
2071
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
2072
2195
|
} else if (key === 'prices') {
|
|
2073
2196
|
this[key] = Price.initOnlyValidFromArray(update[key])
|
|
2074
|
-
} else if (key === 'remarks') {
|
|
2075
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
2076
2197
|
} else {
|
|
2077
2198
|
this[key] = update[key]
|
|
2078
2199
|
}
|
|
2079
2200
|
}
|
|
2080
2201
|
})
|
|
2081
|
-
return
|
|
2202
|
+
return super.update(update)
|
|
2082
2203
|
}
|
|
2083
2204
|
}
|
|
2084
2205
|
|
|
@@ -2110,7 +2231,7 @@ function merchandise_setId(id) {
|
|
|
2110
2231
|
|
|
2111
2232
|
|
|
2112
2233
|
|
|
2113
|
-
class MerchandiseRepo extends
|
|
2234
|
+
class MerchandiseRepo extends q_utilities_.Repo {
|
|
2114
2235
|
constructor(options = {}) {
|
|
2115
2236
|
options = options || {}
|
|
2116
2237
|
super(options)
|
|
@@ -2165,11 +2286,11 @@ class CartItem {
|
|
|
2165
2286
|
this.discount = this._Amount.init(options.discount)
|
|
2166
2287
|
this.itemOptionFillIns = this._ItemOptionFillIn.initOnlyValidFromArray(options.itemOptionFillIns)
|
|
2167
2288
|
this.merchandiseCode = options.merchandiseCode
|
|
2168
|
-
this.metadata =
|
|
2289
|
+
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
2169
2290
|
this.price = this._Amount.init(options.price)
|
|
2170
|
-
this.purchaseOptions =
|
|
2291
|
+
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
2171
2292
|
this.qty = options.qty
|
|
2172
|
-
this.remarks =
|
|
2293
|
+
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
2173
2294
|
this.subTotal = this._Amount.init(options.subTotal)
|
|
2174
2295
|
this.waived = options.waived || 0
|
|
2175
2296
|
}
|
|
@@ -2268,9 +2389,9 @@ class CartItem {
|
|
|
2268
2389
|
} else if (key === 'itemOptionFillIns') {
|
|
2269
2390
|
this[key] = this._ItemOptionFillIn.initOnlyValidFromArray(update[key])
|
|
2270
2391
|
} else if (key === 'metadata') {
|
|
2271
|
-
this[key] =
|
|
2392
|
+
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
2272
2393
|
} else if (key === 'purchaseOptions' || key === 'remarks') {
|
|
2273
|
-
this[key] =
|
|
2394
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
2274
2395
|
} else {
|
|
2275
2396
|
this[key] = update[key]
|
|
2276
2397
|
}
|
|
@@ -2288,11 +2409,11 @@ function mergeDuplicateCartItems(cartItems, array = []) {
|
|
|
2288
2409
|
}
|
|
2289
2410
|
if (cartItem.merchandiseCode === item.merchandiseCode && cartItem.itemOptionFillIns.length === item.itemOptionFillIns.length) {
|
|
2290
2411
|
const { itemOptionFillIns } = item
|
|
2291
|
-
const arr =
|
|
2412
|
+
const arr = external_lodash_.intersectionWith(itemOptionFillIns, cartItem.itemOptionFillIns, (obj1, obj2) => {
|
|
2292
2413
|
return obj1.target === obj2.target
|
|
2293
2414
|
&& obj1.targetCode === obj2.targetCode
|
|
2294
2415
|
&& obj1.key === obj2.key
|
|
2295
|
-
&&
|
|
2416
|
+
&& external_lodash_.intersection(obj1.value, obj2.value).length === obj1.value.length
|
|
2296
2417
|
})
|
|
2297
2418
|
if (arr.length === itemOptionFillIns.length) {
|
|
2298
2419
|
acc.matched = item
|
|
@@ -2400,8 +2521,8 @@ class Status {
|
|
|
2400
2521
|
return this.assigned !== null
|
|
2401
2522
|
}
|
|
2402
2523
|
get isCancelled() {
|
|
2403
|
-
return this.lastStatus === 'cancelled'
|
|
2404
|
-
|
|
2524
|
+
// return this.lastStatus === 'cancelled'
|
|
2525
|
+
return this.cancelled !== null
|
|
2405
2526
|
}
|
|
2406
2527
|
get isCompleted() {
|
|
2407
2528
|
return this.completed !== null
|
|
@@ -2598,6 +2719,9 @@ class Status {
|
|
|
2598
2719
|
// this.cancelled = null
|
|
2599
2720
|
// return this
|
|
2600
2721
|
// }
|
|
2722
|
+
unSetOnHold() {
|
|
2723
|
+
this.onHold = null
|
|
2724
|
+
}
|
|
2601
2725
|
update(update) {
|
|
2602
2726
|
Object.keys(update).forEach((key) => {
|
|
2603
2727
|
if (!notUpdateAllowedProps.includes(key)) {
|
|
@@ -2619,14 +2743,14 @@ class Status {
|
|
|
2619
2743
|
// import { WalletItem } from '../walletItem/index.js'
|
|
2620
2744
|
|
|
2621
2745
|
const cart_updateAllowedProps = [
|
|
2622
|
-
|
|
2623
|
-
'remarks',
|
|
2624
|
-
'deleted',
|
|
2746
|
+
|
|
2625
2747
|
]
|
|
2626
2748
|
|
|
2627
|
-
class Cart {
|
|
2749
|
+
class Cart extends q_utilities_.TenantAwareEntity {
|
|
2628
2750
|
constructor(options = {}) {
|
|
2629
2751
|
options = options || {}
|
|
2752
|
+
super(options)
|
|
2753
|
+
|
|
2630
2754
|
const { _CartItem, _Merchandise, _Status } = options._constructor || {}
|
|
2631
2755
|
this._CartItem = _CartItem && (_CartItem._superclass === CartItem._superclass) ? _CartItem : CartItem
|
|
2632
2756
|
this._Merchandise = _Merchandise && (_Merchandise._superclass === Merchandise._superclass) ? _Merchandise : Merchandise
|
|
@@ -2639,18 +2763,9 @@ class Cart {
|
|
|
2639
2763
|
this._merchandises = options._merchandises
|
|
2640
2764
|
this._type = options._type || 'Cart'
|
|
2641
2765
|
|
|
2642
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
2643
2766
|
this.cartCode = cart_setCode(options, 'cartCode')
|
|
2644
2767
|
this.cartItems = this._CartItem.initOnlyValidFromArray(options.cartItems)
|
|
2645
|
-
this.created = options.created || (new Date()).valueOf()
|
|
2646
|
-
this.creator = options.creator
|
|
2647
|
-
this.deleted = options.deleted || false
|
|
2648
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
2649
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
2650
|
-
this.owner = options.owner
|
|
2651
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
2652
2768
|
this.status = this._Status.init(options.status)
|
|
2653
|
-
this.tenantCode = options.tenantCode
|
|
2654
2769
|
}
|
|
2655
2770
|
|
|
2656
2771
|
// Class Methods
|
|
@@ -2660,22 +2775,6 @@ class Cart {
|
|
|
2660
2775
|
tenantCode: 'tenantCode'
|
|
2661
2776
|
}
|
|
2662
2777
|
}
|
|
2663
|
-
static init(options = {}) {
|
|
2664
|
-
if (options instanceof this) {
|
|
2665
|
-
return options
|
|
2666
|
-
}
|
|
2667
|
-
const instance = new this(options)
|
|
2668
|
-
return instance.isValid ? instance : null
|
|
2669
|
-
}
|
|
2670
|
-
static initFromArray(arr = []) {
|
|
2671
|
-
if (Array.isArray(arr)) {
|
|
2672
|
-
return arr.map((a) => this.init(a))
|
|
2673
|
-
}
|
|
2674
|
-
return []
|
|
2675
|
-
}
|
|
2676
|
-
static initOnlyValidFromArray(arr = []) {
|
|
2677
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
2678
|
-
}
|
|
2679
2778
|
static get _classname() {
|
|
2680
2779
|
return 'Cart'
|
|
2681
2780
|
}
|
|
@@ -2685,7 +2784,7 @@ class Cart {
|
|
|
2685
2784
|
|
|
2686
2785
|
// getters
|
|
2687
2786
|
get isValid() {
|
|
2688
|
-
return
|
|
2787
|
+
return super.isValid
|
|
2689
2788
|
}
|
|
2690
2789
|
get isActive() {
|
|
2691
2790
|
return !!this.active
|
|
@@ -2801,6 +2900,9 @@ class Cart {
|
|
|
2801
2900
|
getCartItemCodes() {
|
|
2802
2901
|
return this.cartItems.map((cartItem) => cartItem.cartItemCode)
|
|
2803
2902
|
}
|
|
2903
|
+
getCode() {
|
|
2904
|
+
return this.cartCode
|
|
2905
|
+
}
|
|
2804
2906
|
getCurrencyCode() {
|
|
2805
2907
|
return this.cartItems.length > 0
|
|
2806
2908
|
? this.cartItems[0].getCurrencyCode()
|
|
@@ -2854,10 +2956,6 @@ class Cart {
|
|
|
2854
2956
|
this.status.setCompleted()
|
|
2855
2957
|
return this.setModified()
|
|
2856
2958
|
}
|
|
2857
|
-
setModified() {
|
|
2858
|
-
this.modified = (new Date()).valueOf()
|
|
2859
|
-
return this
|
|
2860
|
-
}
|
|
2861
2959
|
updateAvailable({ isCoordinator, selectCartItems }) {
|
|
2862
2960
|
try {
|
|
2863
2961
|
if (!isCoordinator) {
|
|
@@ -2871,16 +2969,10 @@ class Cart {
|
|
|
2871
2969
|
update(update) {
|
|
2872
2970
|
Object.keys(update).forEach((key) => {
|
|
2873
2971
|
if (cart_updateAllowedProps.includes(key)) {
|
|
2874
|
-
|
|
2875
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
2876
|
-
} else if (key === 'remarks') {
|
|
2877
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
2878
|
-
} else {
|
|
2879
|
-
this[key] = update[key]
|
|
2880
|
-
}
|
|
2972
|
+
this[key] = update[key]
|
|
2881
2973
|
}
|
|
2882
2974
|
})
|
|
2883
|
-
return
|
|
2975
|
+
return super.update(update)
|
|
2884
2976
|
}
|
|
2885
2977
|
updateStock() {
|
|
2886
2978
|
if (this.cartItems.length === 0) {
|
|
@@ -2935,7 +3027,7 @@ function cart_setId(id) {
|
|
|
2935
3027
|
|
|
2936
3028
|
|
|
2937
3029
|
|
|
2938
|
-
class CartRepo extends
|
|
3030
|
+
class CartRepo extends q_utilities_.Repo {
|
|
2939
3031
|
constructor(options = {}) {
|
|
2940
3032
|
options = options || {}
|
|
2941
3033
|
super(options)
|
|
@@ -2966,22 +3058,20 @@ class CartRepo extends q_utilities_namespaceObject.Repo {
|
|
|
2966
3058
|
|
|
2967
3059
|
|
|
2968
3060
|
const category_updateAllowedProps = [
|
|
2969
|
-
'active',
|
|
2970
3061
|
'codes',
|
|
2971
|
-
'deleted',
|
|
2972
3062
|
'description',
|
|
2973
3063
|
'max',
|
|
2974
3064
|
'min',
|
|
2975
3065
|
'name',
|
|
2976
|
-
'owner',
|
|
2977
3066
|
'priority',
|
|
2978
3067
|
'productCodes',
|
|
2979
|
-
'remarks',
|
|
2980
3068
|
]
|
|
2981
3069
|
|
|
2982
|
-
class Category {
|
|
3070
|
+
class Category extends q_utilities_.TenantAwareEntity {
|
|
2983
3071
|
constructor(options) {
|
|
2984
3072
|
options = options || {}
|
|
3073
|
+
super(options)
|
|
3074
|
+
|
|
2985
3075
|
const { _Product } = options._constructor || {}
|
|
2986
3076
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
2987
3077
|
|
|
@@ -2990,22 +3080,15 @@ class Category {
|
|
|
2990
3080
|
|
|
2991
3081
|
const id = options._id || options.id
|
|
2992
3082
|
this.id = category_setId(id)
|
|
2993
|
-
|
|
3083
|
+
|
|
2994
3084
|
this.categoryCode = category_setCode(options, 'categoryCode')
|
|
2995
3085
|
this.codes = options.codes || []
|
|
2996
|
-
this.created = options.created || (new Date()).valueOf()
|
|
2997
|
-
this.creator = options.creator
|
|
2998
|
-
this.deleted = options.deleted || false
|
|
2999
3086
|
this.description = options.description
|
|
3000
3087
|
this.max = options.max || 1
|
|
3001
3088
|
this.min = options.min || 0
|
|
3002
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3003
3089
|
this.name = options.name
|
|
3004
|
-
this.owner = options.owner
|
|
3005
3090
|
this.priority = options.priority || 10
|
|
3006
3091
|
this.productCodes = options.productCodes || []
|
|
3007
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3008
|
-
this.tenantCode = options.tenantCode
|
|
3009
3092
|
}
|
|
3010
3093
|
|
|
3011
3094
|
// class methods
|
|
@@ -3015,22 +3098,6 @@ class Category {
|
|
|
3015
3098
|
tenantCode: 'tenantCode'
|
|
3016
3099
|
}
|
|
3017
3100
|
}
|
|
3018
|
-
static init(options = {}) {
|
|
3019
|
-
if (options instanceof this) {
|
|
3020
|
-
return options
|
|
3021
|
-
}
|
|
3022
|
-
const instance = new this(options)
|
|
3023
|
-
return instance.isValid ? instance : null
|
|
3024
|
-
}
|
|
3025
|
-
static initFromArray(arr = []) {
|
|
3026
|
-
if (Array.isArray(arr)) {
|
|
3027
|
-
return arr.map((a) => this.init(a))
|
|
3028
|
-
}
|
|
3029
|
-
return []
|
|
3030
|
-
}
|
|
3031
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3032
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3033
|
-
}
|
|
3034
3101
|
static get _classname() {
|
|
3035
3102
|
return 'Category'
|
|
3036
3103
|
}
|
|
@@ -3040,29 +3107,20 @@ class Category {
|
|
|
3040
3107
|
|
|
3041
3108
|
// getters
|
|
3042
3109
|
get isValid() {
|
|
3043
|
-
return
|
|
3110
|
+
return super.isValid && !!this.name && this.max > this. min
|
|
3044
3111
|
}
|
|
3045
3112
|
get products() {
|
|
3046
3113
|
return this._Product.initOnlyValidFromArray(this._products)
|
|
3047
3114
|
}
|
|
3048
3115
|
|
|
3049
3116
|
// instance methods
|
|
3050
|
-
setModified() {
|
|
3051
|
-
this.modified = (new Date()).valueOf()
|
|
3052
|
-
return this
|
|
3053
|
-
}
|
|
3054
|
-
|
|
3055
3117
|
update(update) {
|
|
3056
3118
|
Object.keys(update).forEach((key) => {
|
|
3057
3119
|
if (category_updateAllowedProps.includes(key)) {
|
|
3058
|
-
|
|
3059
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3060
|
-
} else {
|
|
3061
|
-
this[key] = update[key]
|
|
3062
|
-
}
|
|
3120
|
+
this[key] = update[key]
|
|
3063
3121
|
}
|
|
3064
3122
|
})
|
|
3065
|
-
return
|
|
3123
|
+
return super.update(update)
|
|
3066
3124
|
}
|
|
3067
3125
|
}
|
|
3068
3126
|
|
|
@@ -3087,7 +3145,7 @@ function category_setId(id) {
|
|
|
3087
3145
|
|
|
3088
3146
|
|
|
3089
3147
|
|
|
3090
|
-
class CategoryRepo extends
|
|
3148
|
+
class CategoryRepo extends q_utilities_.Repo {
|
|
3091
3149
|
constructor(options = {}) {
|
|
3092
3150
|
options = options || {}
|
|
3093
3151
|
super(options)
|
|
@@ -3119,20 +3177,19 @@ class CategoryRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3119
3177
|
|
|
3120
3178
|
|
|
3121
3179
|
const creditNoteLine_updateAllowedProps = [
|
|
3122
|
-
'active',
|
|
3123
3180
|
'amount',
|
|
3124
3181
|
// 'deduction',
|
|
3125
|
-
'deleted',
|
|
3126
3182
|
'description',
|
|
3127
3183
|
// 'discount',
|
|
3128
3184
|
'qty',
|
|
3129
|
-
'remarks',
|
|
3130
3185
|
// 'unitPrice'
|
|
3131
3186
|
]
|
|
3132
3187
|
|
|
3133
|
-
class CreditNoteLine {
|
|
3188
|
+
class CreditNoteLine extends q_utilities_.TenantAwareEntity {
|
|
3134
3189
|
constructor(options = {}) {
|
|
3135
3190
|
options = options || {}
|
|
3191
|
+
super(options)
|
|
3192
|
+
|
|
3136
3193
|
const { _Amount } = options._constructor || {}
|
|
3137
3194
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3138
3195
|
|
|
@@ -3141,21 +3198,14 @@ class CreditNoteLine {
|
|
|
3141
3198
|
|
|
3142
3199
|
const id = options._id || options.id
|
|
3143
3200
|
this.id = creditNoteLine_setId(id)
|
|
3144
|
-
|
|
3201
|
+
|
|
3145
3202
|
this.amount = this._Amount.init(options.amount)
|
|
3146
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3147
|
-
this.creator = options.creator
|
|
3148
3203
|
this.creditNoteCode = options.creditNoteCode
|
|
3149
3204
|
this.creditNoteLineCode = creditNoteLine_setCode(options, 'creditNoteLineCode')
|
|
3150
3205
|
// this.deduction = this._Amount.init(options.deduction)
|
|
3151
|
-
this.deleted = options.deleted || false
|
|
3152
3206
|
this.description = options.description
|
|
3153
3207
|
// this.discount = options.discount || 0
|
|
3154
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3155
|
-
this.owner = options.owner
|
|
3156
3208
|
this.qty = options.qty || 1
|
|
3157
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3158
|
-
this.tenantCode = options.tenantCode
|
|
3159
3209
|
// this.unitPrice = Amount.init(options.unitPrice)
|
|
3160
3210
|
}
|
|
3161
3211
|
|
|
@@ -3166,22 +3216,6 @@ class CreditNoteLine {
|
|
|
3166
3216
|
tenantCode: 'tenantCode'
|
|
3167
3217
|
}
|
|
3168
3218
|
}
|
|
3169
|
-
static init(options = {}) {
|
|
3170
|
-
if (options instanceof this) {
|
|
3171
|
-
return options
|
|
3172
|
-
}
|
|
3173
|
-
const instance = new this(options)
|
|
3174
|
-
return instance.isValid ? instance : null
|
|
3175
|
-
}
|
|
3176
|
-
static initFromArray(arr = []) {
|
|
3177
|
-
if (Array.isArray(arr)) {
|
|
3178
|
-
return arr.map((a) => this.init(a))
|
|
3179
|
-
}
|
|
3180
|
-
return []
|
|
3181
|
-
}
|
|
3182
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3183
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3184
|
-
}
|
|
3185
3219
|
static get _classname() {
|
|
3186
3220
|
return 'CreditNoteLine'
|
|
3187
3221
|
}
|
|
@@ -3192,7 +3226,7 @@ class CreditNoteLine {
|
|
|
3192
3226
|
|
|
3193
3227
|
// getters
|
|
3194
3228
|
get isValid() {
|
|
3195
|
-
return
|
|
3229
|
+
return super.isValid && !!this.creditNoteCode
|
|
3196
3230
|
}
|
|
3197
3231
|
|
|
3198
3232
|
// instance methods
|
|
@@ -3203,10 +3237,6 @@ class CreditNoteLine {
|
|
|
3203
3237
|
}
|
|
3204
3238
|
return this
|
|
3205
3239
|
}
|
|
3206
|
-
setModified() {
|
|
3207
|
-
this.modified = (new Date()).valueOf()
|
|
3208
|
-
return this
|
|
3209
|
-
}
|
|
3210
3240
|
|
|
3211
3241
|
update(update) {
|
|
3212
3242
|
Object.keys(update).forEach((key) => {
|
|
@@ -3214,13 +3244,13 @@ class CreditNoteLine {
|
|
|
3214
3244
|
if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
|
|
3215
3245
|
this[key] = this._Amount.init(update[key])
|
|
3216
3246
|
} else if (key === 'purchaseOptions') {
|
|
3217
|
-
this[key] =
|
|
3247
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3218
3248
|
} else {
|
|
3219
3249
|
this[key] = update[key]
|
|
3220
3250
|
}
|
|
3221
3251
|
}
|
|
3222
3252
|
})
|
|
3223
|
-
return
|
|
3253
|
+
return super.update(update)
|
|
3224
3254
|
}
|
|
3225
3255
|
}
|
|
3226
3256
|
|
|
@@ -3245,7 +3275,7 @@ function creditNoteLine_setId(id) {
|
|
|
3245
3275
|
|
|
3246
3276
|
|
|
3247
3277
|
|
|
3248
|
-
class CreditNoteLineRepo extends
|
|
3278
|
+
class CreditNoteLineRepo extends q_utilities_.Repo {
|
|
3249
3279
|
constructor(options = {}) {
|
|
3250
3280
|
options = options || {}
|
|
3251
3281
|
super(options)
|
|
@@ -3279,17 +3309,16 @@ class CreditNoteLineRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3279
3309
|
|
|
3280
3310
|
|
|
3281
3311
|
const creditNote_updateAllowedProps = [
|
|
3282
|
-
'active',
|
|
3283
|
-
'deleted',
|
|
3284
3312
|
'description',
|
|
3285
|
-
'remarks',
|
|
3286
3313
|
'status'
|
|
3287
3314
|
]
|
|
3288
3315
|
|
|
3289
|
-
class CreditNote {
|
|
3316
|
+
class CreditNote extends q_utilities_.TenantAwareEntity {
|
|
3290
3317
|
constructor(options = {}) {
|
|
3291
3318
|
options = options || {}
|
|
3292
|
-
|
|
3319
|
+
super(options)
|
|
3320
|
+
|
|
3321
|
+
const { _Amount, _CreditNoteLine, _Status } = options._constructor || {}
|
|
3293
3322
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3294
3323
|
this._CreditNoteLine = _CreditNoteLine && (_CreditNoteLine._superclass === CreditNoteLine._superclass) ? _CreditNoteLine : CreditNoteLine
|
|
3295
3324
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
@@ -3298,21 +3327,13 @@ class CreditNote {
|
|
|
3298
3327
|
|
|
3299
3328
|
const id = options._id || options.id
|
|
3300
3329
|
this.id = creditNote_setId(id)
|
|
3301
|
-
|
|
3330
|
+
|
|
3302
3331
|
this.amount = this._Amount.init(options.amount)
|
|
3303
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3304
|
-
this.creator = options.creator
|
|
3305
3332
|
this.creditNoteCode = creditNote_setCode(options, 'creditNoteCode')
|
|
3306
3333
|
this.creditNoteLines = this._CreditNoteLine.initOnlyValidFromArray(options.creditNoteLines)
|
|
3307
|
-
this.deleted = options.deleted || false
|
|
3308
3334
|
this.description = options.description
|
|
3309
3335
|
this.invoiceCode = options.invoiceCode
|
|
3310
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3311
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3312
|
-
this.owner = options.owner
|
|
3313
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3314
3336
|
this.status = this._Status.init(options.status)
|
|
3315
|
-
this.tenantCode = options.tenantCode
|
|
3316
3337
|
}
|
|
3317
3338
|
|
|
3318
3339
|
// Class Methods
|
|
@@ -3322,22 +3343,6 @@ class CreditNote {
|
|
|
3322
3343
|
tenantCode: 'tenantCode'
|
|
3323
3344
|
}
|
|
3324
3345
|
}
|
|
3325
|
-
static init(options = {}) {
|
|
3326
|
-
if (options instanceof this) {
|
|
3327
|
-
return options
|
|
3328
|
-
}
|
|
3329
|
-
const instance = new this(options)
|
|
3330
|
-
return instance.isValid ? instance : null
|
|
3331
|
-
}
|
|
3332
|
-
static initFromArray(arr = []) {
|
|
3333
|
-
if (Array.isArray(arr)) {
|
|
3334
|
-
return arr.map((a) => this.init(a))
|
|
3335
|
-
}
|
|
3336
|
-
return []
|
|
3337
|
-
}
|
|
3338
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3339
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3340
|
-
}
|
|
3341
3346
|
static get _classname() {
|
|
3342
3347
|
return 'CreditNote'
|
|
3343
3348
|
}
|
|
@@ -3355,9 +3360,11 @@ class CreditNote {
|
|
|
3355
3360
|
}
|
|
3356
3361
|
|
|
3357
3362
|
get isValid() {
|
|
3358
|
-
return
|
|
3363
|
+
return super.isValid && !!this.invoiceCode
|
|
3364
|
+
}
|
|
3365
|
+
getCode() {
|
|
3366
|
+
return this.creditNoteCode
|
|
3359
3367
|
}
|
|
3360
|
-
|
|
3361
3368
|
setAmount(amount) {
|
|
3362
3369
|
const a = this_Amount.init(amount)
|
|
3363
3370
|
if (this.isPending && a) {
|
|
@@ -3369,10 +3376,6 @@ class CreditNote {
|
|
|
3369
3376
|
this.status.setCompleted()
|
|
3370
3377
|
return this.setModified()
|
|
3371
3378
|
}
|
|
3372
|
-
setModified() {
|
|
3373
|
-
this.modified = (new Date()).valueOf()
|
|
3374
|
-
return this
|
|
3375
|
-
}
|
|
3376
3379
|
setPaid(t) {
|
|
3377
3380
|
this.status.setPaid(t)
|
|
3378
3381
|
return this.setModified()
|
|
@@ -3382,10 +3385,6 @@ class CreditNote {
|
|
|
3382
3385
|
if (creditNote_updateAllowedProps.includes(key)) {
|
|
3383
3386
|
if (key === 'amount') {
|
|
3384
3387
|
this[key] = this._Amount.init(update[key])
|
|
3385
|
-
} else if (key === 'metadata') {
|
|
3386
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
3387
|
-
} else if (key === 'remarks') {
|
|
3388
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3389
3388
|
} else if (key === 'status') {
|
|
3390
3389
|
this[key] = this._Status.init(update[key])
|
|
3391
3390
|
} else {
|
|
@@ -3393,7 +3392,7 @@ class CreditNote {
|
|
|
3393
3392
|
}
|
|
3394
3393
|
}
|
|
3395
3394
|
})
|
|
3396
|
-
return
|
|
3395
|
+
return super.update(update)
|
|
3397
3396
|
}
|
|
3398
3397
|
}
|
|
3399
3398
|
|
|
@@ -3418,7 +3417,7 @@ function creditNote_setId(id) {
|
|
|
3418
3417
|
|
|
3419
3418
|
|
|
3420
3419
|
|
|
3421
|
-
class CreditNoteRepo extends
|
|
3420
|
+
class CreditNoteRepo extends q_utilities_.Repo {
|
|
3422
3421
|
constructor(options = {}) {
|
|
3423
3422
|
options = options || {}
|
|
3424
3423
|
super(options)
|
|
@@ -3447,35 +3446,27 @@ class CreditNoteRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3447
3446
|
|
|
3448
3447
|
|
|
3449
3448
|
const currency_updateAllowedProps = [
|
|
3450
|
-
'active',
|
|
3451
|
-
'deleted',
|
|
3452
3449
|
'description',
|
|
3453
3450
|
'name',
|
|
3454
|
-
'remarks',
|
|
3455
3451
|
'symbol'
|
|
3456
3452
|
]
|
|
3457
3453
|
|
|
3458
|
-
class Currency {
|
|
3454
|
+
class Currency extends q_utilities_.TenantAwareEntity {
|
|
3459
3455
|
constructor(options = {}) {
|
|
3460
3456
|
options = options || {}
|
|
3457
|
+
super(options)
|
|
3458
|
+
|
|
3461
3459
|
const id = options._id || options.id
|
|
3462
3460
|
this.id = currency_setId(id)
|
|
3463
3461
|
|
|
3464
3462
|
this._type = options._type || 'Currency'
|
|
3465
|
-
|
|
3463
|
+
|
|
3466
3464
|
this.code = options.code // 'HKD'
|
|
3467
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3468
|
-
this.creator = options.creator
|
|
3469
3465
|
this.currencyCode = currency_setCode(options, 'currencyCode')
|
|
3470
|
-
this.deleted = options.deleted || false
|
|
3471
3466
|
this.description = options.description
|
|
3472
3467
|
this.factor = options.factor || 1 // 100
|
|
3473
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3474
3468
|
this.name = options.name
|
|
3475
|
-
this.owner = options.owner
|
|
3476
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3477
3469
|
this.symbol = options.symbol || null
|
|
3478
|
-
this.tenantCode = options.tenantCode
|
|
3479
3470
|
this.unit = options.unit
|
|
3480
3471
|
}
|
|
3481
3472
|
static dummyData() {
|
|
@@ -3487,22 +3478,6 @@ class Currency {
|
|
|
3487
3478
|
unit: 'Cent',
|
|
3488
3479
|
}
|
|
3489
3480
|
}
|
|
3490
|
-
static init(options = {}) {
|
|
3491
|
-
if (options instanceof this) {
|
|
3492
|
-
return options
|
|
3493
|
-
}
|
|
3494
|
-
const instance = new this(options)
|
|
3495
|
-
return instance.isValid ? instance : null
|
|
3496
|
-
}
|
|
3497
|
-
static initFromArray(arr = []) {
|
|
3498
|
-
if (Array.isArray(arr)) {
|
|
3499
|
-
return arr.map((a) => this.init(a))
|
|
3500
|
-
}
|
|
3501
|
-
return []
|
|
3502
|
-
}
|
|
3503
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3504
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3505
|
-
}
|
|
3506
3481
|
static get _classname() {
|
|
3507
3482
|
return 'Currency'
|
|
3508
3483
|
}
|
|
@@ -3511,29 +3486,23 @@ class Currency {
|
|
|
3511
3486
|
}
|
|
3512
3487
|
|
|
3513
3488
|
get isValid() {
|
|
3514
|
-
return !!this.code && typeof this.factor === 'number' && !!this.name && !!this.unit
|
|
3489
|
+
return super.isValid && !!this.code && typeof this.factor === 'number' && !!this.name && !!this.unit
|
|
3515
3490
|
}
|
|
3516
3491
|
|
|
3517
3492
|
fromCurrencyValue(value) {
|
|
3518
3493
|
return value / this.factor
|
|
3519
3494
|
}
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
this.modified = (new Date()).valueOf()
|
|
3523
|
-
return this
|
|
3495
|
+
getCode() {
|
|
3496
|
+
return this.currencyCode
|
|
3524
3497
|
}
|
|
3525
3498
|
|
|
3526
3499
|
update(update) {
|
|
3527
3500
|
Object.keys(update).forEach((key) => {
|
|
3528
3501
|
if (currency_updateAllowedProps.includes(key)) {
|
|
3529
|
-
|
|
3530
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3531
|
-
} else {
|
|
3532
|
-
this[key] = update[key]
|
|
3533
|
-
}
|
|
3502
|
+
this[key] = update[key]
|
|
3534
3503
|
}
|
|
3535
3504
|
})
|
|
3536
|
-
return
|
|
3505
|
+
return super.update(update)
|
|
3537
3506
|
}
|
|
3538
3507
|
}
|
|
3539
3508
|
|
|
@@ -3558,7 +3527,7 @@ function currency_setId(id) {
|
|
|
3558
3527
|
|
|
3559
3528
|
|
|
3560
3529
|
|
|
3561
|
-
class CurrencyRepo extends
|
|
3530
|
+
class CurrencyRepo extends q_utilities_.Repo {
|
|
3562
3531
|
constructor(options = {}) {
|
|
3563
3532
|
options = options || {}
|
|
3564
3533
|
super(options)
|
|
@@ -3584,6 +3553,74 @@ class CurrencyRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3584
3553
|
|
|
3585
3554
|
|
|
3586
3555
|
|
|
3556
|
+
;// ./lib/helpers/getPurchaseOptionValue/getPurchaseOptionValue.js
|
|
3557
|
+
function getPurchaseOptionValue(options) {
|
|
3558
|
+
const {
|
|
3559
|
+
delimiter = ': ',
|
|
3560
|
+
key,
|
|
3561
|
+
purchaseOptions,
|
|
3562
|
+
tag = 'div'
|
|
3563
|
+
} = options || {}
|
|
3564
|
+
if (!key) {
|
|
3565
|
+
return purchaseOptions.reduce((acc, purchaseOption) => {
|
|
3566
|
+
const arr = _getOnePurchaseOptionValue({
|
|
3567
|
+
delimiter, purchaseOption, tag
|
|
3568
|
+
})
|
|
3569
|
+
if (tag) {
|
|
3570
|
+
acc.push(`<${tag}>${arr.join('')}</${tag}>`)
|
|
3571
|
+
} else {
|
|
3572
|
+
acc.push(`${arr.join('; ')}`)
|
|
3573
|
+
}
|
|
3574
|
+
return acc
|
|
3575
|
+
}, [])
|
|
3576
|
+
}
|
|
3577
|
+
const purchaseOption = (purchaseOptions || []).find((po) => {
|
|
3578
|
+
return !!key && po.key === key
|
|
3579
|
+
})
|
|
3580
|
+
if (!purchaseOption) {
|
|
3581
|
+
return []
|
|
3582
|
+
}
|
|
3583
|
+
return _getOnePurchaseOptionValue({
|
|
3584
|
+
delimiter, purchaseOption, tag
|
|
3585
|
+
})
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
function _getOnePurchaseOptionValue({
|
|
3589
|
+
delimiter = ': ',
|
|
3590
|
+
purchaseOption,
|
|
3591
|
+
tag = 'div'
|
|
3592
|
+
}) {
|
|
3593
|
+
return (purchaseOption.value || []).reduce((acc, val) => {
|
|
3594
|
+
const { label, value = {} } = val || {}
|
|
3595
|
+
const _label = label ?? ''
|
|
3596
|
+
if (Array.isArray(value)) {
|
|
3597
|
+
if (tag) {
|
|
3598
|
+
acc.push(`<${tag}>${_label}${delimiter}${value.join(delimiter)}</${tag}>`)
|
|
3599
|
+
} else {
|
|
3600
|
+
acc.push(`${_label}${delimiter}${value.join(delimiter)}`)
|
|
3601
|
+
}
|
|
3602
|
+
} else if (typeof value === 'object') {
|
|
3603
|
+
Object.keys(value).map((key) => {
|
|
3604
|
+
if (tag) {
|
|
3605
|
+
acc.push(`<${tag}>${key}${delimiter}${value[key]}</${tag}>`)
|
|
3606
|
+
} else {
|
|
3607
|
+
acc.push(`${key}${delimiter}${value[key]}`)
|
|
3608
|
+
}
|
|
3609
|
+
})
|
|
3610
|
+
} else {
|
|
3611
|
+
if (tag) {
|
|
3612
|
+
acc.push(`<${tag}>${_label}${delimiter}${value}</${tag}>`)
|
|
3613
|
+
} else {
|
|
3614
|
+
acc.push(`${_label}${delimiter}${value}`)
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3618
|
+
return acc
|
|
3619
|
+
}, [])
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3622
|
+
|
|
3623
|
+
|
|
3587
3624
|
;// ./lib/models/invoiceLine/invoiceLine.js
|
|
3588
3625
|
|
|
3589
3626
|
|
|
@@ -3592,22 +3629,22 @@ class CurrencyRepo extends q_utilities_namespaceObject.Repo {
|
|
|
3592
3629
|
|
|
3593
3630
|
|
|
3594
3631
|
|
|
3632
|
+
|
|
3595
3633
|
const invoiceLine_updateAllowedProps = [
|
|
3596
|
-
'active',
|
|
3597
3634
|
'amount',
|
|
3598
3635
|
'deduction',
|
|
3599
|
-
'deleted',
|
|
3600
3636
|
'description',
|
|
3601
3637
|
'discount',
|
|
3602
3638
|
'purchaseOptions',
|
|
3603
3639
|
'qty',
|
|
3604
|
-
'remarks',
|
|
3605
3640
|
'unitPrice'
|
|
3606
3641
|
]
|
|
3607
3642
|
|
|
3608
|
-
class InvoiceLine {
|
|
3643
|
+
class InvoiceLine extends q_utilities_.TenantAwareEntity {
|
|
3609
3644
|
constructor(options = {}) {
|
|
3610
3645
|
options = options || {}
|
|
3646
|
+
super(options)
|
|
3647
|
+
|
|
3611
3648
|
const { _Amount, _Invoice, _Merchandise, _Status } = options._constructor || {}
|
|
3612
3649
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
3613
3650
|
this._Invoice = _Invoice && (_Invoice._superclass === Invoice._superclass) ? _Invoice : Invoice
|
|
@@ -3620,23 +3657,16 @@ class InvoiceLine {
|
|
|
3620
3657
|
const id = options._id || options.id
|
|
3621
3658
|
this.id = invoiceLine_setId(id)
|
|
3622
3659
|
this._type = options._type || 'InvoiceLine'
|
|
3623
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
3624
3660
|
this.amount = this._Amount.init(options.amount)
|
|
3625
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3626
|
-
this.creator = options.creator
|
|
3627
3661
|
this.deduction = this._Amount.init(options.deduction)
|
|
3628
|
-
this.deleted = options.deleted || false
|
|
3629
3662
|
this.description = options.description
|
|
3630
3663
|
this.discount = options.discount || 0
|
|
3631
3664
|
this.invoiceCode = options.invoiceCode
|
|
3632
3665
|
this.invoiceLineCode = invoiceLine_setCode(options, 'invoiceLineCode')
|
|
3633
3666
|
this.merchandiseCode = options.merchandiseCode
|
|
3634
|
-
this.
|
|
3635
|
-
this.purchaseOptions = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3667
|
+
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3636
3668
|
this.qty = options.qty || 1
|
|
3637
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3638
3669
|
this.status = this._Status.init(options.status)
|
|
3639
|
-
this.tenantCode = options.tenantCode
|
|
3640
3670
|
this.unitPrice = this._Amount.init(options.unitPrice)
|
|
3641
3671
|
this.waived = options.waived || 0
|
|
3642
3672
|
}
|
|
@@ -3649,22 +3679,6 @@ class InvoiceLine {
|
|
|
3649
3679
|
tenantCode: 'tenantCode'
|
|
3650
3680
|
}
|
|
3651
3681
|
}
|
|
3652
|
-
static init(options = {}) {
|
|
3653
|
-
if (options instanceof this) {
|
|
3654
|
-
return options
|
|
3655
|
-
}
|
|
3656
|
-
const instance = new this(options)
|
|
3657
|
-
return instance.isValid ? instance : null
|
|
3658
|
-
}
|
|
3659
|
-
static initFromArray(arr = []) {
|
|
3660
|
-
if (Array.isArray(arr)) {
|
|
3661
|
-
return arr.map((a) => this.init(a))
|
|
3662
|
-
}
|
|
3663
|
-
return []
|
|
3664
|
-
}
|
|
3665
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3666
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3667
|
-
}
|
|
3668
3682
|
static get _classname() {
|
|
3669
3683
|
return 'InvoiceLine'
|
|
3670
3684
|
}
|
|
@@ -3674,7 +3688,7 @@ class InvoiceLine {
|
|
|
3674
3688
|
|
|
3675
3689
|
// getters
|
|
3676
3690
|
get isValid() {
|
|
3677
|
-
return
|
|
3691
|
+
return super.isValid && !!this.amount && !!this.invoiceCode
|
|
3678
3692
|
}
|
|
3679
3693
|
get invoice() {
|
|
3680
3694
|
return this._Invoice.init(this._invoice)
|
|
@@ -3684,24 +3698,26 @@ class InvoiceLine {
|
|
|
3684
3698
|
}
|
|
3685
3699
|
|
|
3686
3700
|
// instance methods
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
return
|
|
3701
|
+
getPurchaseOptionValue(options) {
|
|
3702
|
+
const { delimiter, key, tag } = options || {}
|
|
3703
|
+
return getPurchaseOptionValue({
|
|
3704
|
+
key,
|
|
3705
|
+
purchaseOptions: this.purchaseOptions
|
|
3706
|
+
})
|
|
3690
3707
|
}
|
|
3691
|
-
|
|
3692
3708
|
update(update) {
|
|
3693
3709
|
Object.keys(update).forEach((key) => {
|
|
3694
3710
|
if (invoiceLine_updateAllowedProps.includes(key)) {
|
|
3695
3711
|
if (key === 'amount' || key === 'unitPrice' || key === 'deduction') {
|
|
3696
3712
|
this[key] = this._Amount.init(update[key])
|
|
3697
3713
|
} else if (key === 'purchaseOptions') {
|
|
3698
|
-
this[key] =
|
|
3714
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
3699
3715
|
} else {
|
|
3700
3716
|
this[key] = update[key]
|
|
3701
3717
|
}
|
|
3702
3718
|
}
|
|
3703
3719
|
})
|
|
3704
|
-
return
|
|
3720
|
+
return super.update(update)
|
|
3705
3721
|
}
|
|
3706
3722
|
}
|
|
3707
3723
|
|
|
@@ -3726,7 +3742,7 @@ function invoiceLine_setId(id) {
|
|
|
3726
3742
|
|
|
3727
3743
|
|
|
3728
3744
|
|
|
3729
|
-
class InvoiceLineRepo extends
|
|
3745
|
+
class InvoiceLineRepo extends q_utilities_.Repo {
|
|
3730
3746
|
constructor(options = {}) {
|
|
3731
3747
|
options = options || {}
|
|
3732
3748
|
super(options)
|
|
@@ -3811,45 +3827,38 @@ class Issuer {
|
|
|
3811
3827
|
|
|
3812
3828
|
|
|
3813
3829
|
|
|
3830
|
+
|
|
3814
3831
|
// import { Transaction } from '../transaction/index.js'
|
|
3815
3832
|
|
|
3816
3833
|
const walletItem_updateAllowedProps = [
|
|
3817
|
-
'active',
|
|
3818
|
-
'deleted',
|
|
3819
|
-
'owner',
|
|
3820
3834
|
'purchaseOptions',
|
|
3821
3835
|
'qty',
|
|
3822
|
-
'remarks',
|
|
3823
3836
|
'status',
|
|
3824
3837
|
]
|
|
3825
3838
|
|
|
3826
|
-
class WalletItem {
|
|
3839
|
+
class WalletItem extends q_utilities_.TenantAwareEntity {
|
|
3827
3840
|
constructor(options = {}) {
|
|
3828
3841
|
options = options || {}
|
|
3842
|
+
super(options)
|
|
3843
|
+
|
|
3829
3844
|
const { _Product, _Status } = options._constructor || {}
|
|
3830
3845
|
this._Product = _Product && (_Product._superclass === Product._superclass) ? _Product : Product
|
|
3831
3846
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
3832
3847
|
// this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
3833
3848
|
|
|
3849
|
+
this._eventRegistration = options._eventRegistration
|
|
3850
|
+
this._invoiceLine = options._invoiceLine
|
|
3834
3851
|
this._product = options._product
|
|
3835
3852
|
this._tenant = options._tenant
|
|
3836
3853
|
this._transaction = options._transaction
|
|
3837
3854
|
|
|
3838
3855
|
const id = options._id || options.id
|
|
3839
3856
|
this.id = walletItem_setId(id)
|
|
3840
|
-
this.
|
|
3841
|
-
this.created = options.created || (new Date()).valueOf()
|
|
3842
|
-
this.creator = options.creator
|
|
3843
|
-
this.deleted = options.deleted || false
|
|
3844
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
3845
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
3846
|
-
this.owner = options.owner
|
|
3857
|
+
this.invoiceLineCode = options.invoiceLineCode
|
|
3847
3858
|
this.productCode = options.productCode
|
|
3848
|
-
this.purchaseOptions =
|
|
3859
|
+
this.purchaseOptions = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.purchaseOptions)
|
|
3849
3860
|
this.qty = options.qty || 1
|
|
3850
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
3851
3861
|
this.status = this._Status.init(options.status)
|
|
3852
|
-
this.tenantCode = options.tenantCode
|
|
3853
3862
|
this.transactionCode = options.transactionCode
|
|
3854
3863
|
this.walletItemCode = walletItem_setCode(options, 'walletItemCode')
|
|
3855
3864
|
}
|
|
@@ -3865,22 +3874,7 @@ class WalletItem {
|
|
|
3865
3874
|
transactionCode: 'transactionCode'
|
|
3866
3875
|
}
|
|
3867
3876
|
}
|
|
3868
|
-
|
|
3869
|
-
if (options instanceof this) {
|
|
3870
|
-
return options
|
|
3871
|
-
}
|
|
3872
|
-
const instance = new this(options)
|
|
3873
|
-
return instance.isValid ? instance : null
|
|
3874
|
-
}
|
|
3875
|
-
static initFromArray(arr = []) {
|
|
3876
|
-
if (Array.isArray(arr)) {
|
|
3877
|
-
return arr.map((a) => this.init(a))
|
|
3878
|
-
}
|
|
3879
|
-
return []
|
|
3880
|
-
}
|
|
3881
|
-
static initOnlyValidFromArray(arr = []) {
|
|
3882
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
3883
|
-
}
|
|
3877
|
+
|
|
3884
3878
|
static get _classname() {
|
|
3885
3879
|
return 'WalletItem'
|
|
3886
3880
|
}
|
|
@@ -3890,11 +3884,14 @@ class WalletItem {
|
|
|
3890
3884
|
|
|
3891
3885
|
// getters
|
|
3892
3886
|
get isValid() {
|
|
3893
|
-
return
|
|
3887
|
+
return super.isValid && !!this.productCode
|
|
3894
3888
|
}
|
|
3895
3889
|
get isAssigned() {
|
|
3896
3890
|
return this.status.isAssigned
|
|
3897
3891
|
}
|
|
3892
|
+
get isAvailableCoupon() {
|
|
3893
|
+
return this.isCoupon && !this.isCancelled && !this.isUsed
|
|
3894
|
+
}
|
|
3898
3895
|
get isCancelled() {
|
|
3899
3896
|
return this.status.isCancelled
|
|
3900
3897
|
}
|
|
@@ -3904,9 +3901,21 @@ class WalletItem {
|
|
|
3904
3901
|
get isConfirmed() {
|
|
3905
3902
|
return this.status.isConfirmed
|
|
3906
3903
|
}
|
|
3904
|
+
get isCoupon() {
|
|
3905
|
+
return this.product ? this.product.isCoupon : false
|
|
3906
|
+
}
|
|
3907
3907
|
get isDelivered() {
|
|
3908
3908
|
return this.status.isDelivered
|
|
3909
3909
|
}
|
|
3910
|
+
get isInWallet() {
|
|
3911
|
+
return !this.isCancelled && !this.isRefundRequested
|
|
3912
|
+
}
|
|
3913
|
+
get isItemCoupon() {
|
|
3914
|
+
return this.product ? this.product.isItemCoupon : false
|
|
3915
|
+
}
|
|
3916
|
+
get isOnHold() {
|
|
3917
|
+
return this.status.onHold
|
|
3918
|
+
}
|
|
3910
3919
|
get isOwned() {
|
|
3911
3920
|
return (
|
|
3912
3921
|
!this.isCancelled && !this.isRejected && !this.isRefunded
|
|
@@ -3930,6 +3939,9 @@ class WalletItem {
|
|
|
3930
3939
|
get isRefunded() {
|
|
3931
3940
|
return this.status.isRefunded
|
|
3932
3941
|
}
|
|
3942
|
+
get isRefundRequested() {
|
|
3943
|
+
return this.status.isRefundRequested
|
|
3944
|
+
}
|
|
3933
3945
|
get isRejected() {
|
|
3934
3946
|
return this.status.rejected
|
|
3935
3947
|
}
|
|
@@ -3945,6 +3957,10 @@ class WalletItem {
|
|
|
3945
3957
|
get isWaived() {
|
|
3946
3958
|
return this.status.isWaived
|
|
3947
3959
|
}
|
|
3960
|
+
|
|
3961
|
+
get couponDetails() {
|
|
3962
|
+
return this.product ? this.product.couponDetails : null
|
|
3963
|
+
}
|
|
3948
3964
|
get product() {
|
|
3949
3965
|
return this._Product.init(this._product)
|
|
3950
3966
|
}
|
|
@@ -3976,8 +3992,23 @@ class WalletItem {
|
|
|
3976
3992
|
return this
|
|
3977
3993
|
}
|
|
3978
3994
|
}
|
|
3995
|
+
getCode() {
|
|
3996
|
+
return this.walletItemCode
|
|
3997
|
+
}
|
|
3998
|
+
getPurchaseOptionValue(options) {
|
|
3999
|
+
const { delimiter, key, tag } = options || {}
|
|
4000
|
+
return getPurchaseOptionValue({
|
|
4001
|
+
delimiter,
|
|
4002
|
+
key,
|
|
4003
|
+
purchaseOptions: this.purchaseOptions,
|
|
4004
|
+
tag,
|
|
4005
|
+
})
|
|
4006
|
+
}
|
|
4007
|
+
isApplicableCoupon(obj) {
|
|
4008
|
+
return this.isAvailableCoupon && (this.product ? this.product.isApplicableCoupon(obj) : false)
|
|
4009
|
+
}
|
|
3979
4010
|
isSameOwner(userId) {
|
|
3980
|
-
return userId
|
|
4011
|
+
return userId && this.owner
|
|
3981
4012
|
? (userId === this.owner)
|
|
3982
4013
|
: false
|
|
3983
4014
|
}
|
|
@@ -3993,8 +4024,8 @@ class WalletItem {
|
|
|
3993
4024
|
this.status.setDelivered(value)
|
|
3994
4025
|
return this
|
|
3995
4026
|
}
|
|
3996
|
-
|
|
3997
|
-
this.
|
|
4027
|
+
setOnHold() {
|
|
4028
|
+
this.status.setOnHold()
|
|
3998
4029
|
return this
|
|
3999
4030
|
}
|
|
4000
4031
|
setPaid() {
|
|
@@ -4027,6 +4058,11 @@ class WalletItem {
|
|
|
4027
4058
|
// this.statusTimestamp.setUsed()
|
|
4028
4059
|
return this
|
|
4029
4060
|
}
|
|
4061
|
+
setUsedCouponFor(walletItemCode) {
|
|
4062
|
+
const _usedFor = q_utilities_.KeyValueObject.foundValueByKey(this.metadata, 'USED_COUPON_FOR') || []
|
|
4063
|
+
_usedFor.push(walletItemCode)
|
|
4064
|
+
this.metadata = q_utilities_.Metadata.insertOrUpdateRecord(this.metadata, 'USED_COUPON_FOR', _usedFor)
|
|
4065
|
+
}
|
|
4030
4066
|
setWaived() {
|
|
4031
4067
|
this.status.setWaived()
|
|
4032
4068
|
return this
|
|
@@ -4047,13 +4083,15 @@ class WalletItem {
|
|
|
4047
4083
|
// walletItemCode: this.walletItemCode
|
|
4048
4084
|
// }
|
|
4049
4085
|
// }
|
|
4086
|
+
unSetOnHold() {
|
|
4087
|
+
this.status.unSetOnHold()
|
|
4088
|
+
return this
|
|
4089
|
+
}
|
|
4050
4090
|
update(update) {
|
|
4051
4091
|
Object.keys(update).forEach((key) => {
|
|
4052
4092
|
if (walletItem_updateAllowedProps.includes(key)) {
|
|
4053
|
-
if (key === '
|
|
4054
|
-
this[key] =
|
|
4055
|
-
} else if (key === 'purchaseOptions' || key === 'remarks') {
|
|
4056
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4093
|
+
if (key === 'purchaseOptions') {
|
|
4094
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4057
4095
|
} else if (key === 'status') {
|
|
4058
4096
|
this[key] = this._Status.init(update[key])
|
|
4059
4097
|
} else {
|
|
@@ -4061,7 +4099,7 @@ class WalletItem {
|
|
|
4061
4099
|
}
|
|
4062
4100
|
}
|
|
4063
4101
|
})
|
|
4064
|
-
return
|
|
4102
|
+
return super.update(update)
|
|
4065
4103
|
}
|
|
4066
4104
|
}
|
|
4067
4105
|
|
|
@@ -4086,7 +4124,7 @@ function walletItem_setCode(options, key) {
|
|
|
4086
4124
|
|
|
4087
4125
|
|
|
4088
4126
|
|
|
4089
|
-
class WalletItemRepo extends
|
|
4127
|
+
class WalletItemRepo extends q_utilities_.Repo {
|
|
4090
4128
|
constructor(options = {}) {
|
|
4091
4129
|
options = options || {}
|
|
4092
4130
|
super(options)
|
|
@@ -4117,18 +4155,17 @@ class WalletItemRepo extends q_utilities_namespaceObject.Repo {
|
|
|
4117
4155
|
|
|
4118
4156
|
|
|
4119
4157
|
const transaction_updateAllowedProps = [
|
|
4120
|
-
'active',
|
|
4121
4158
|
'amount',
|
|
4122
4159
|
'couponCodes',
|
|
4123
|
-
'deleted',
|
|
4124
4160
|
// 'refundedAmount',
|
|
4125
|
-
'remarks',
|
|
4126
4161
|
'status'
|
|
4127
4162
|
]
|
|
4128
4163
|
|
|
4129
|
-
class Transaction {
|
|
4164
|
+
class Transaction extends q_utilities_.TenantAwareEntity {
|
|
4130
4165
|
constructor(options = {}) {
|
|
4131
4166
|
options = options || {}
|
|
4167
|
+
super(options)
|
|
4168
|
+
|
|
4132
4169
|
const { _Amount, _Status, _WalletItem } = options._constructor || {}
|
|
4133
4170
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4134
4171
|
this._Status = _Status && (_Status._superclass === Status._superclass) ? _Status : Status
|
|
@@ -4144,22 +4181,14 @@ class Transaction {
|
|
|
4144
4181
|
const id = options._id || options.id
|
|
4145
4182
|
this.id = transaction_setId(id)
|
|
4146
4183
|
this._type = options._type || 'Transaction'
|
|
4147
|
-
|
|
4184
|
+
|
|
4148
4185
|
this.amount = this._Amount.init(options.amount)
|
|
4149
4186
|
this.couponCodes = options.couponCodes || []
|
|
4150
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4151
|
-
this.creator = options.creator
|
|
4152
4187
|
this.creditNoteCodes = options.creditNoteCodes || []
|
|
4153
|
-
this.deleted = options.deleted || false
|
|
4154
4188
|
this.invoiceCode = options.invoiceCode
|
|
4155
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4156
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4157
|
-
this.owner = options.owner
|
|
4158
4189
|
this.paymentGatewayCode = options.paymentGatewayCode
|
|
4159
4190
|
this.paymentResultRef = options.paymentResultRef
|
|
4160
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4161
4191
|
this.status = this._Status.init(options.status)
|
|
4162
|
-
this.tenantCode = options.tenantCode
|
|
4163
4192
|
this.transactionCode = transaction_setCode(options, 'transactionCode')
|
|
4164
4193
|
}
|
|
4165
4194
|
|
|
@@ -4170,22 +4199,6 @@ class Transaction {
|
|
|
4170
4199
|
tenantCode: 'tenantCode'
|
|
4171
4200
|
}
|
|
4172
4201
|
}
|
|
4173
|
-
static init(options = {}) {
|
|
4174
|
-
if (options instanceof this) {
|
|
4175
|
-
return options
|
|
4176
|
-
}
|
|
4177
|
-
const instance = new this(options)
|
|
4178
|
-
return instance.isValid ? instance : null
|
|
4179
|
-
}
|
|
4180
|
-
static initFromArray(arr = []) {
|
|
4181
|
-
if (Array.isArray(arr)) {
|
|
4182
|
-
return arr.map((a) => this.init(a))
|
|
4183
|
-
}
|
|
4184
|
-
return []
|
|
4185
|
-
}
|
|
4186
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4187
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4188
|
-
}
|
|
4189
4202
|
static get _classname() {
|
|
4190
4203
|
return 'Transaction'
|
|
4191
4204
|
}
|
|
@@ -4195,7 +4208,7 @@ class Transaction {
|
|
|
4195
4208
|
|
|
4196
4209
|
// getters
|
|
4197
4210
|
get isValid() {
|
|
4198
|
-
return
|
|
4211
|
+
return super.isValid
|
|
4199
4212
|
}
|
|
4200
4213
|
get isActive() {
|
|
4201
4214
|
return this.active === true
|
|
@@ -4334,9 +4347,6 @@ class Transaction {
|
|
|
4334
4347
|
setFailed() {
|
|
4335
4348
|
return this.status.setFailed()
|
|
4336
4349
|
}
|
|
4337
|
-
setModified() {
|
|
4338
|
-
return this.modified = (new Date()).valueOf()
|
|
4339
|
-
}
|
|
4340
4350
|
setOnHold() {
|
|
4341
4351
|
return this.status.setOnHold()
|
|
4342
4352
|
}
|
|
@@ -4393,10 +4403,6 @@ class Transaction {
|
|
|
4393
4403
|
if (transaction_updateAllowedProps.includes(key)) {
|
|
4394
4404
|
if (key === 'amount') {
|
|
4395
4405
|
this[key] = this._Amount.init(update[key])
|
|
4396
|
-
} else if (key === 'metadata') {
|
|
4397
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4398
|
-
} else if (key === 'remarks') {
|
|
4399
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4400
4406
|
} else if (key === 'status') {
|
|
4401
4407
|
this[key] = this._Status.init(update[key])
|
|
4402
4408
|
// } else if (key === 'refundedAmount') {
|
|
@@ -4406,7 +4412,7 @@ class Transaction {
|
|
|
4406
4412
|
}
|
|
4407
4413
|
}
|
|
4408
4414
|
})
|
|
4409
|
-
return
|
|
4415
|
+
return super.update(update)
|
|
4410
4416
|
}
|
|
4411
4417
|
// updatePayment(payment = {}) {
|
|
4412
4418
|
// this.payments = Payment.updatePaymentItem(this.payments, payment)
|
|
@@ -4446,7 +4452,7 @@ function transaction_setId(id) {
|
|
|
4446
4452
|
|
|
4447
4453
|
|
|
4448
4454
|
|
|
4449
|
-
class TransactionRepo extends
|
|
4455
|
+
class TransactionRepo extends q_utilities_.Repo {
|
|
4450
4456
|
constructor(options = {}) {
|
|
4451
4457
|
options = options || {}
|
|
4452
4458
|
super(options)
|
|
@@ -4481,21 +4487,19 @@ class TransactionRepo extends q_utilities_namespaceObject.Repo {
|
|
|
4481
4487
|
|
|
4482
4488
|
|
|
4483
4489
|
const invoice_updateAllowedProps = [
|
|
4484
|
-
'active',
|
|
4485
4490
|
'checkoutDateTime',
|
|
4486
|
-
'deleted',
|
|
4487
4491
|
'description',
|
|
4488
4492
|
'invoiceDate',
|
|
4489
4493
|
'issuer',
|
|
4490
|
-
'metadata',
|
|
4491
|
-
'remarks',
|
|
4492
4494
|
'revisionNumber',
|
|
4493
4495
|
'status'
|
|
4494
4496
|
]
|
|
4495
4497
|
|
|
4496
|
-
class Invoice {
|
|
4498
|
+
class Invoice extends q_utilities_.TenantAwareEntity {
|
|
4497
4499
|
constructor(options) {
|
|
4498
4500
|
options = options || {}
|
|
4501
|
+
super(options)
|
|
4502
|
+
|
|
4499
4503
|
const { _Amount, _Cart, _InvoiceLine, _Issuer, _Status, _Transaction } = options._constructor || {}
|
|
4500
4504
|
this._Amount = _Amount && (_Amount._superclass === Amount._superclass) ? _Amount : Amount
|
|
4501
4505
|
this._Cart = _Cart && (_Cart._superclass === Cart._superclass) ? _Cart : Cart
|
|
@@ -4511,25 +4515,16 @@ class Invoice {
|
|
|
4511
4515
|
const id = options._id || options.id
|
|
4512
4516
|
this.id = invoice_setId(id)
|
|
4513
4517
|
this._type = options._type || 'Invoice'
|
|
4514
|
-
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
4515
4518
|
this.amount = this._Amount.init(options.amount)
|
|
4516
4519
|
this.cartCode = options.cartCode
|
|
4517
4520
|
this.checkoutDateTime = options.checkoutDateTime || (new Date()).valueOf()
|
|
4518
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4519
|
-
this.creator = options.creator
|
|
4520
|
-
this.deleted = options.deleted || false
|
|
4521
4521
|
this.description = options.description
|
|
4522
4522
|
this.invoiceCode = invoice_setCode(options, 'invoiceCode')
|
|
4523
4523
|
this.invoiceDate = options.invoiceDate || (new Date()).valueOf()
|
|
4524
4524
|
this.invoiceNumber = options.invoiceNumber
|
|
4525
4525
|
this.issuer = this._Issuer.init(options.issuer)
|
|
4526
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4527
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4528
|
-
this.owner = options.owner
|
|
4529
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4530
4526
|
this.revisionNumber = options.revisionNumber || 1
|
|
4531
4527
|
this.status = this._Status.init(options.status)
|
|
4532
|
-
this.tenantCode = options.tenantCode
|
|
4533
4528
|
}
|
|
4534
4529
|
|
|
4535
4530
|
static dummyData() {
|
|
@@ -4537,22 +4532,6 @@ class Invoice {
|
|
|
4537
4532
|
tenantCode: 'tenantCode'
|
|
4538
4533
|
}
|
|
4539
4534
|
}
|
|
4540
|
-
static init(options = {}) {
|
|
4541
|
-
if (options instanceof this) {
|
|
4542
|
-
return options
|
|
4543
|
-
}
|
|
4544
|
-
const instance = new this(options)
|
|
4545
|
-
return instance.isValid ? instance : null
|
|
4546
|
-
}
|
|
4547
|
-
static initFromArray(arr = []) {
|
|
4548
|
-
if (Array.isArray(arr)) {
|
|
4549
|
-
return arr.map((a) => this.init(a))
|
|
4550
|
-
}
|
|
4551
|
-
return []
|
|
4552
|
-
}
|
|
4553
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4554
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4555
|
-
}
|
|
4556
4535
|
static get _classname() {
|
|
4557
4536
|
return 'Invoice'
|
|
4558
4537
|
}
|
|
@@ -4561,7 +4540,7 @@ class Invoice {
|
|
|
4561
4540
|
}
|
|
4562
4541
|
|
|
4563
4542
|
get isValid() {
|
|
4564
|
-
return
|
|
4543
|
+
return super.isValid
|
|
4565
4544
|
}
|
|
4566
4545
|
get cart() {
|
|
4567
4546
|
return this._Cart.init(this._cart)
|
|
@@ -4634,7 +4613,9 @@ class Invoice {
|
|
|
4634
4613
|
getAmount() {
|
|
4635
4614
|
return this.amount
|
|
4636
4615
|
}
|
|
4637
|
-
|
|
4616
|
+
getCode() {
|
|
4617
|
+
return this.invoiceCode
|
|
4618
|
+
}
|
|
4638
4619
|
getCurrencyCode() {
|
|
4639
4620
|
return this.amount ? this.amount.getCurrencyCode() : null
|
|
4640
4621
|
}
|
|
@@ -4658,12 +4639,6 @@ class Invoice {
|
|
|
4658
4639
|
}
|
|
4659
4640
|
return this
|
|
4660
4641
|
}
|
|
4661
|
-
|
|
4662
|
-
setModified() {
|
|
4663
|
-
this.modified = (new Date()).valueOf()
|
|
4664
|
-
return this
|
|
4665
|
-
}
|
|
4666
|
-
|
|
4667
4642
|
setCompleted() {
|
|
4668
4643
|
this.status.setCompleted()
|
|
4669
4644
|
return this.setModified()
|
|
@@ -4677,12 +4652,8 @@ class Invoice {
|
|
|
4677
4652
|
update(update) {
|
|
4678
4653
|
Object.keys(update).forEach((key) => {
|
|
4679
4654
|
if (invoice_updateAllowedProps.includes(key)) {
|
|
4680
|
-
if (key === '
|
|
4681
|
-
this[key] = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
4682
|
-
} else if (key === 'amount') {
|
|
4655
|
+
if (key === 'amount') {
|
|
4683
4656
|
this[key] = this._Amount.init(update[key])
|
|
4684
|
-
} else if (key === 'metadata') {
|
|
4685
|
-
this[key] = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(update[key])
|
|
4686
4657
|
} else if (key === 'issuer') {
|
|
4687
4658
|
this[key] = this._Issuer.init(update[key])
|
|
4688
4659
|
} else if (key === 'status') {
|
|
@@ -4692,7 +4663,7 @@ class Invoice {
|
|
|
4692
4663
|
}
|
|
4693
4664
|
}
|
|
4694
4665
|
})
|
|
4695
|
-
return
|
|
4666
|
+
return super.update(update)
|
|
4696
4667
|
}
|
|
4697
4668
|
}
|
|
4698
4669
|
|
|
@@ -4717,7 +4688,7 @@ function invoice_setId(id) {
|
|
|
4717
4688
|
|
|
4718
4689
|
|
|
4719
4690
|
|
|
4720
|
-
class InvoiceRepo extends
|
|
4691
|
+
class InvoiceRepo extends q_utilities_.Repo {
|
|
4721
4692
|
constructor(options = {}) {
|
|
4722
4693
|
options = options || {}
|
|
4723
4694
|
super(options)
|
|
@@ -4747,40 +4718,33 @@ class InvoiceRepo extends q_utilities_namespaceObject.Repo {
|
|
|
4747
4718
|
;// ./lib/models/paymentGateway/paymentGateway.js
|
|
4748
4719
|
|
|
4749
4720
|
|
|
4721
|
+
|
|
4750
4722
|
const paymentGateway_updateAllowedProps = [
|
|
4751
|
-
'active',
|
|
4752
|
-
'deleted',
|
|
4753
4723
|
'label',
|
|
4754
4724
|
'logoUrl',
|
|
4755
4725
|
'name',
|
|
4756
|
-
'owner',
|
|
4757
4726
|
'sandbox',
|
|
4758
4727
|
'setting'
|
|
4759
4728
|
]
|
|
4760
4729
|
|
|
4761
|
-
|
|
4762
|
-
class PaymentGateway {
|
|
4730
|
+
class PaymentGateway extends q_utilities_.TenantAwareEntity {
|
|
4763
4731
|
constructor(options = {}) {
|
|
4764
4732
|
options = options || {}
|
|
4733
|
+
super(options)
|
|
4734
|
+
|
|
4765
4735
|
const id = options._id || options.id
|
|
4766
4736
|
this.id = paymentGateway_setId(id)
|
|
4767
4737
|
this._type = options._type || 'PaymentGateway'
|
|
4768
|
-
|
|
4769
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4770
|
-
this.creator = options.creator
|
|
4771
|
-
this.deleted = options.deleted || false
|
|
4738
|
+
|
|
4772
4739
|
this.hasWebhook = options.hasWebhook || false
|
|
4773
4740
|
this.label = options.label
|
|
4774
4741
|
this.logoUrl = options.logoUrl
|
|
4775
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4776
4742
|
this.name = options.name || ''
|
|
4777
|
-
this.owner = options.owner
|
|
4778
4743
|
this.paymentGatewayCode = paymentGateway_setCode(options, 'paymentGatewayCode')
|
|
4779
4744
|
this.paymentGatewayType = options.paymentGatewayType || 'PaymentGateway'
|
|
4780
4745
|
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4781
4746
|
this.sandbox = options.sandbox || false
|
|
4782
4747
|
this.setting = options.setting || null
|
|
4783
|
-
this.tenantCode = options.tenantCode
|
|
4784
4748
|
}
|
|
4785
4749
|
static dummyData() {
|
|
4786
4750
|
return {
|
|
@@ -4788,22 +4752,6 @@ class PaymentGateway {
|
|
|
4788
4752
|
tenantCode: 'tenantCode'
|
|
4789
4753
|
}
|
|
4790
4754
|
}
|
|
4791
|
-
static init(options = {}) {
|
|
4792
|
-
if (options instanceof this) {
|
|
4793
|
-
return options
|
|
4794
|
-
}
|
|
4795
|
-
const instance = new this(options)
|
|
4796
|
-
return instance.isValid ? instance : null
|
|
4797
|
-
}
|
|
4798
|
-
static initFromArray(arr = []) {
|
|
4799
|
-
if (Array.isArray(arr)) {
|
|
4800
|
-
return arr.map((a) => this.init(a))
|
|
4801
|
-
}
|
|
4802
|
-
return []
|
|
4803
|
-
}
|
|
4804
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4805
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4806
|
-
}
|
|
4807
4755
|
static get _classname() {
|
|
4808
4756
|
return 'PaymentGateway'
|
|
4809
4757
|
}
|
|
@@ -4813,7 +4761,7 @@ class PaymentGateway {
|
|
|
4813
4761
|
|
|
4814
4762
|
// getters
|
|
4815
4763
|
get isValid() {
|
|
4816
|
-
return
|
|
4764
|
+
return super.isValid && !!this.name
|
|
4817
4765
|
}
|
|
4818
4766
|
|
|
4819
4767
|
// instance methods
|
|
@@ -4823,6 +4771,9 @@ class PaymentGateway {
|
|
|
4823
4771
|
async getAppPayParams() {
|
|
4824
4772
|
throw new Error(`${this._classname} subclass should implement getAppPayParams`)
|
|
4825
4773
|
}
|
|
4774
|
+
getCode() {
|
|
4775
|
+
return this.paymentGatewayCode
|
|
4776
|
+
}
|
|
4826
4777
|
async updatePayment() {
|
|
4827
4778
|
throw new Error(`${this._classname} subclass should implement updatePayment`)
|
|
4828
4779
|
}
|
|
@@ -4836,18 +4787,13 @@ class PaymentGateway {
|
|
|
4836
4787
|
setCompletedRelatedStatus(status) {
|
|
4837
4788
|
throw new Error(`${this.name} subclass should implement setCompletedRelatedStatus`)
|
|
4838
4789
|
}
|
|
4839
|
-
|
|
4840
|
-
setModified() {
|
|
4841
|
-
this.modified = (new Date()).valueOf()
|
|
4842
|
-
return this
|
|
4843
|
-
}
|
|
4844
4790
|
update(update) {
|
|
4845
4791
|
Object.keys(update).forEach((key) => {
|
|
4846
4792
|
if (paymentGateway_updateAllowedProps.includes(key)) {
|
|
4847
4793
|
this[key] = update[key]
|
|
4848
4794
|
}
|
|
4849
4795
|
})
|
|
4850
|
-
return
|
|
4796
|
+
return super.update(update)
|
|
4851
4797
|
}
|
|
4852
4798
|
}
|
|
4853
4799
|
|
|
@@ -4872,7 +4818,7 @@ function paymentGateway_setId(id) {
|
|
|
4872
4818
|
|
|
4873
4819
|
|
|
4874
4820
|
|
|
4875
|
-
class PaymentGatewayRepo extends
|
|
4821
|
+
class PaymentGatewayRepo extends q_utilities_.Repo {
|
|
4876
4822
|
constructor(options = {}) {
|
|
4877
4823
|
options = options || {}
|
|
4878
4824
|
super(options)
|
|
@@ -4908,9 +4854,11 @@ const paymentResult_updateAllowedProps = [
|
|
|
4908
4854
|
'result'
|
|
4909
4855
|
]
|
|
4910
4856
|
|
|
4911
|
-
class PaymentResult {
|
|
4857
|
+
class PaymentResult extends q_utilities_.TenantAwareEntity {
|
|
4912
4858
|
constructor(options = {}) {
|
|
4913
4859
|
options = options || {}
|
|
4860
|
+
super(options)
|
|
4861
|
+
|
|
4914
4862
|
const { _Transaction } = options._constructor || {}
|
|
4915
4863
|
this._Transaction = _Transaction && (_Transaction._superclass === Transaction._superclass) ? _Transaction : Transaction
|
|
4916
4864
|
|
|
@@ -4919,20 +4867,12 @@ class PaymentResult {
|
|
|
4919
4867
|
|
|
4920
4868
|
const id = options._id || options.id
|
|
4921
4869
|
this.id = paymentResult_setId(id)
|
|
4922
|
-
|
|
4923
|
-
this.created = options.created || (new Date()).valueOf()
|
|
4924
|
-
this.creator = options.creator
|
|
4925
|
-
this.deleted = options.deleted || false
|
|
4926
|
-
this.metadata = q_utilities_namespaceObject.Metadata.initOnlyValidFromArray(options.metadata)
|
|
4927
|
-
this.modified = options.modified || (new Date()).valueOf()
|
|
4928
|
-
this.owner = options.owner
|
|
4870
|
+
|
|
4929
4871
|
this.paymentResultCode = paymentResult_setCode(options, 'paymentResultCode')
|
|
4930
4872
|
this.paymentResultType = options.paymentResultType || 'PaymentResult'
|
|
4931
|
-
this.remarks = q_utilities_namespaceObject.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
4932
4873
|
this.result = options.result
|
|
4933
4874
|
this.resultRef = options.resultRef
|
|
4934
4875
|
this.resultType = options.resultType
|
|
4935
|
-
this.tenantCode = options.tenantCode
|
|
4936
4876
|
// this.transaction = this._Transaction.init(options.transaction)
|
|
4937
4877
|
this.transactionCode = options.transactionCode
|
|
4938
4878
|
}
|
|
@@ -4947,22 +4887,6 @@ class PaymentResult {
|
|
|
4947
4887
|
transactionCode: 'transactionCode'
|
|
4948
4888
|
}
|
|
4949
4889
|
}
|
|
4950
|
-
static init(options = {}) {
|
|
4951
|
-
if (options instanceof this) {
|
|
4952
|
-
return options
|
|
4953
|
-
}
|
|
4954
|
-
const instance = new this(options)
|
|
4955
|
-
return instance.isValid ? instance : null
|
|
4956
|
-
}
|
|
4957
|
-
static initFromArray(arr = []) {
|
|
4958
|
-
if (Array.isArray(arr)) {
|
|
4959
|
-
return arr.map((a) => this.init(a))
|
|
4960
|
-
}
|
|
4961
|
-
return []
|
|
4962
|
-
}
|
|
4963
|
-
static initOnlyValidFromArray(arr = []) {
|
|
4964
|
-
return this.initFromArray(arr).filter((i) => i)
|
|
4965
|
-
}
|
|
4966
4890
|
static get _classname() {
|
|
4967
4891
|
return 'PaymentResult'
|
|
4968
4892
|
}
|
|
@@ -4972,7 +4896,7 @@ class PaymentResult {
|
|
|
4972
4896
|
|
|
4973
4897
|
// getters
|
|
4974
4898
|
get isValid() {
|
|
4975
|
-
return
|
|
4899
|
+
return super.isValid && !!this.resultType && !!this.transactionCode
|
|
4976
4900
|
// return !!this.result && !!this.resultType && !!this.tenantCode
|
|
4977
4901
|
}
|
|
4978
4902
|
get amount() {
|
|
@@ -4982,7 +4906,7 @@ class PaymentResult {
|
|
|
4982
4906
|
throw new Error(`${this._classname} subclass should implement get paymentMethod`)
|
|
4983
4907
|
}
|
|
4984
4908
|
get transaction() {
|
|
4985
|
-
return this.
|
|
4909
|
+
return this._Transaction.init(this._transaction)
|
|
4986
4910
|
}
|
|
4987
4911
|
|
|
4988
4912
|
// instance methods
|
|
@@ -4990,81 +4914,298 @@ class PaymentResult {
|
|
|
4990
4914
|
// throw new Error(`${this.paymentResultType} subclass should implement getPaymentId`)
|
|
4991
4915
|
// }
|
|
4992
4916
|
addMetadata(key, value) {
|
|
4993
|
-
|
|
4917
|
+
q_utilities_.Metadata.addItem(this.metadata, key, value)
|
|
4994
4918
|
return this
|
|
4995
4919
|
}
|
|
4996
4920
|
addRemark(key, value) {
|
|
4997
|
-
|
|
4921
|
+
q_utilities_.KeyValueObject.addItem(this.remarks, key, value)
|
|
4998
4922
|
return this
|
|
4999
4923
|
}
|
|
5000
4924
|
|
|
5001
|
-
compareStatus(paymentResult) {
|
|
5002
|
-
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
5003
|
-
}
|
|
5004
|
-
|
|
5005
|
-
|
|
4925
|
+
compareStatus(paymentResult) {
|
|
4926
|
+
throw new Error(`${this.paymentResultType} subclass should implement compareStatus`)
|
|
4927
|
+
}
|
|
4928
|
+
getCode() {
|
|
4929
|
+
return this.paymentResultCode
|
|
4930
|
+
}
|
|
4931
|
+
getPaidAmount() {
|
|
4932
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaidAmount`)
|
|
4933
|
+
}
|
|
4934
|
+
getPaidTimestamp() {
|
|
4935
|
+
throw new Error(
|
|
4936
|
+
`${this.paymentResultType} subclass should implement getPaidTimestamp in milliseconds`
|
|
4937
|
+
)
|
|
4938
|
+
}
|
|
4939
|
+
getPaymentCode() {
|
|
4940
|
+
throw new Error(`${this.paymentResultType} subclass should implement getPaymentCode`)
|
|
4941
|
+
}
|
|
4942
|
+
getTransactionStatus() {
|
|
4943
|
+
throw new Error(`${this.paymentResultType} subclass should implement getTransactionStatus`)
|
|
4944
|
+
}
|
|
4945
|
+
handlePayment(payment) {
|
|
4946
|
+
if (!this.isForThisPayment(payment)) {
|
|
4947
|
+
return { payment, err: new Error('the payment result is not for this payment') }
|
|
4948
|
+
}
|
|
4949
|
+
if (!this.isSameAmount(payment)) {
|
|
4950
|
+
return { payment, err: new Error('the amount was not matched') }
|
|
4951
|
+
}
|
|
4952
|
+
try {
|
|
4953
|
+
payment.settled()
|
|
4954
|
+
payment
|
|
4955
|
+
.setPaidAmount(this.getPaidAmount())
|
|
4956
|
+
.setPaidTimestamp(this.getPaidTimestamp())
|
|
4957
|
+
.setPaymentResultCode(this.paymentResultCode)
|
|
4958
|
+
return { payment, err: null }
|
|
4959
|
+
} catch (err) {
|
|
4960
|
+
return { payment, err }
|
|
4961
|
+
}
|
|
4962
|
+
}
|
|
4963
|
+
isForThisPayment(payment) {
|
|
4964
|
+
return this.getPaymentCode() === payment.paymentCode
|
|
4965
|
+
}
|
|
4966
|
+
isSameAmount(payment) {
|
|
4967
|
+
return this.getPaidAmount() === payment.getAmount()
|
|
4968
|
+
}
|
|
4969
|
+
isSuccess() {
|
|
4970
|
+
throw new Error(`${this.paymentResultType} subclass should implement isSuccess`)
|
|
4971
|
+
}
|
|
4972
|
+
setupMetadata() {
|
|
4973
|
+
const amount = this.amount
|
|
4974
|
+
const paymentMethod = this.paymentMethod
|
|
4975
|
+
q_utilities_.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
4976
|
+
q_utilities_.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
4977
|
+
q_utilities_.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
4978
|
+
q_utilities_.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
4979
|
+
return this
|
|
4980
|
+
}
|
|
4981
|
+
setupRemarks() {
|
|
4982
|
+
return this.setupMetadata()
|
|
4983
|
+
}
|
|
4984
|
+
update(update) {
|
|
4985
|
+
Object.keys(update).forEach((key) => {
|
|
4986
|
+
if (paymentResult_updateAllowedProps.includes(key)) {
|
|
4987
|
+
this[key] = update[key]
|
|
4988
|
+
}
|
|
4989
|
+
})
|
|
4990
|
+
return super.update(update)
|
|
4991
|
+
}
|
|
4992
|
+
}
|
|
4993
|
+
|
|
4994
|
+
function paymentResult_setCode(options, key) {
|
|
4995
|
+
const copyOptions = options || {}
|
|
4996
|
+
if (copyOptions[key]) {
|
|
4997
|
+
return copyOptions[key]
|
|
4998
|
+
}
|
|
4999
|
+
return stringHelper.setCode()
|
|
5000
|
+
}
|
|
5001
|
+
|
|
5002
|
+
function paymentResult_setId(id) {
|
|
5003
|
+
if (id && typeof id.toString === 'function') {
|
|
5004
|
+
return id.toString()
|
|
5005
|
+
}
|
|
5006
|
+
return id
|
|
5007
|
+
}
|
|
5008
|
+
|
|
5009
|
+
|
|
5010
|
+
|
|
5011
|
+
;// ./lib/models/paymentResult/paymentResultRepo.js
|
|
5012
|
+
|
|
5013
|
+
|
|
5014
|
+
|
|
5015
|
+
class PaymentResultRepo extends q_utilities_.Repo {
|
|
5016
|
+
constructor(options = {}) {
|
|
5017
|
+
options = options || {}
|
|
5018
|
+
super(options)
|
|
5019
|
+
const { _PaymentResult } = options._constructor || {}
|
|
5020
|
+
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
5021
|
+
}
|
|
5022
|
+
static get _classname() {
|
|
5023
|
+
return 'PaymentResultRepo'
|
|
5024
|
+
}
|
|
5025
|
+
init(options) {
|
|
5026
|
+
return this._PaymentResult.init(options)
|
|
5027
|
+
}
|
|
5028
|
+
}
|
|
5029
|
+
|
|
5030
|
+
|
|
5031
|
+
|
|
5032
|
+
;// ./lib/models/paymentResult/index.js
|
|
5033
|
+
|
|
5034
|
+
|
|
5035
|
+
|
|
5036
|
+
|
|
5037
|
+
|
|
5038
|
+
|
|
5039
|
+
;// ./lib/models/status/index.js
|
|
5040
|
+
|
|
5041
|
+
|
|
5042
|
+
|
|
5043
|
+
|
|
5044
|
+
|
|
5045
|
+
;// ./lib/models/storeItem/storeItem.js
|
|
5046
|
+
|
|
5047
|
+
|
|
5048
|
+
|
|
5049
|
+
|
|
5050
|
+
|
|
5051
|
+
const storeItem_updateAllowedProps = [
|
|
5052
|
+
'active',
|
|
5053
|
+
'deleted',
|
|
5054
|
+
'description',
|
|
5055
|
+
'intangible',
|
|
5056
|
+
'limitPercentage',
|
|
5057
|
+
'lineOptions',
|
|
5058
|
+
'maxPerWallet',
|
|
5059
|
+
'name',
|
|
5060
|
+
'originalStock',
|
|
5061
|
+
'owner',
|
|
5062
|
+
'productOptions',
|
|
5063
|
+
'remarks',
|
|
5064
|
+
'requiredStoreItemCode',
|
|
5065
|
+
'stock'
|
|
5066
|
+
]
|
|
5067
|
+
|
|
5068
|
+
class StoreItem {
|
|
5069
|
+
constructor(options = {}) {
|
|
5070
|
+
options = options || {}
|
|
5071
|
+
const { _ItemOption } = options._constructor || {}
|
|
5072
|
+
this._ItemOption = _ItemOption && (_ItemOption._superclass === ItemOption) ? _ItemOption : ItemOption
|
|
5073
|
+
|
|
5074
|
+
const id = options._id || options.id
|
|
5075
|
+
this.id = storeItem_setId(id)
|
|
5076
|
+
this._type = options._type || 'StoreItem'
|
|
5077
|
+
this.active = (typeof options.active !== 'undefined') ? !!options.active : true
|
|
5078
|
+
this.created = options.created || (new Date()).valueOf()
|
|
5079
|
+
this.creator = options.creator
|
|
5080
|
+
this.deleted = options.deleted || false
|
|
5081
|
+
this.description = options.description || ''
|
|
5082
|
+
this.intangible = options.intangible || false
|
|
5083
|
+
this.limitPercentage = options.limitPercentage || 100
|
|
5084
|
+
this.lineOptions = this._ItemOption.initOnlyValidFromArray(options.lineOptions)
|
|
5085
|
+
this.maxPerWallet = options.maxPerWallet || 1
|
|
5086
|
+
this.metadata = q_utilities_.Metadata.initOnlyValidFromArray(options.metadata)
|
|
5087
|
+
this.modified = options.modified || (new Date()).valueOf()
|
|
5088
|
+
this.name = options.name || ''
|
|
5089
|
+
this.originalStock = options.originalStock || 0
|
|
5090
|
+
this.owner = options.owner
|
|
5091
|
+
this.productCode = storeItem_setCode(options, 'productCode')
|
|
5092
|
+
this.productOptions = this._ItemOption.initOnlyValidFromArray(options.productOptions)
|
|
5093
|
+
this.requiredStoreItemCode = options.requiredStoreItemCode
|
|
5094
|
+
this.remarks = q_utilities_.KeyValueObject.initOnlyValidFromArray(options.remarks)
|
|
5095
|
+
this.stock = options.stock || 0
|
|
5096
|
+
this.storeItemType = options.storeItemType || 'StoreItem'
|
|
5097
|
+
this.tenantCode = options.tenantCode
|
|
5098
|
+
}
|
|
5099
|
+
|
|
5100
|
+
// class method
|
|
5101
|
+
static dummyData() {
|
|
5102
|
+
return {
|
|
5103
|
+
name: 'badge',
|
|
5104
|
+
tenantCode: 'tenantCode'
|
|
5105
|
+
}
|
|
5106
|
+
}
|
|
5107
|
+
static init(options = {}) {
|
|
5108
|
+
if (options instanceof this) {
|
|
5109
|
+
return options
|
|
5110
|
+
}
|
|
5111
|
+
const instance = new this(options)
|
|
5112
|
+
return instance.isValid ? instance : null
|
|
5113
|
+
}
|
|
5114
|
+
static initFromArray(arr = []) {
|
|
5115
|
+
if (Array.isArray(arr)) {
|
|
5116
|
+
return arr.map((a) => this.init(a))
|
|
5117
|
+
}
|
|
5118
|
+
return []
|
|
5119
|
+
}
|
|
5120
|
+
static initOnlyValidFromArray(arr = []) {
|
|
5121
|
+
return this.initFromArray(arr).filter((i) => i)
|
|
5122
|
+
}
|
|
5123
|
+
static get _classname() {
|
|
5124
|
+
return 'StoreItem'
|
|
5125
|
+
}
|
|
5126
|
+
static get _superclass() {
|
|
5127
|
+
return 'StoreItem'
|
|
5128
|
+
}
|
|
5129
|
+
|
|
5130
|
+
// getters
|
|
5131
|
+
get isValid() {
|
|
5132
|
+
return !!this.tenantCode && !!this.name
|
|
5133
|
+
}
|
|
5134
|
+
get isReachedLimitPercentage() {
|
|
5135
|
+
return this.soldPercentage >= this.limitPercentage
|
|
5136
|
+
}
|
|
5137
|
+
get soldPercentage() {
|
|
5138
|
+
return ((this.originalStock - this.stock) / this.originalStock) * 100
|
|
5139
|
+
}
|
|
5140
|
+
get summary() {
|
|
5141
|
+
return {
|
|
5142
|
+
product: this,
|
|
5143
|
+
productCode: this.productCode,
|
|
5144
|
+
name: this.name,
|
|
5145
|
+
}
|
|
5146
|
+
}
|
|
5147
|
+
|
|
5148
|
+
// instance methods
|
|
5149
|
+
ableToHave(qty) {
|
|
5150
|
+
return this.maxPerWallet >= qty
|
|
5006
5151
|
}
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
)
|
|
5152
|
+
|
|
5153
|
+
checkStoreItemItemOptions(itemOptionFillIns = []) {
|
|
5154
|
+
const copyItemOptionsFillIns = ItemOptionFillIn.getItemOptionFillInsByTarget({ itemOptionFillIns, target: 'StoreItem', targetCode: this.productCode })
|
|
5155
|
+
return copyItemOptionsFillIns.reduce((acc, fillIn) => {
|
|
5156
|
+
const key = fillIn.getKey()
|
|
5157
|
+
const itemOption = this.getStoreItemOptionByKey(key)
|
|
5158
|
+
if (!itemOption) {
|
|
5159
|
+
acc.errMsgs.push(`options of the product(${this.productCode}) does not contain key: "${key}"`)
|
|
5160
|
+
return acc
|
|
5161
|
+
}
|
|
5162
|
+
const isValid = itemOption.isValidFillInValue(fillIn.getValue())
|
|
5163
|
+
if (!isValid) {
|
|
5164
|
+
acc.errMsgs.push(`the product(${this.productCode}) option's(${key}) fillInValue is invalid`)
|
|
5165
|
+
}
|
|
5166
|
+
return acc
|
|
5167
|
+
}, { errMsgs: [] })
|
|
5011
5168
|
}
|
|
5012
|
-
|
|
5013
|
-
|
|
5169
|
+
getCode() {
|
|
5170
|
+
return this.productCode
|
|
5014
5171
|
}
|
|
5015
|
-
|
|
5016
|
-
|
|
5172
|
+
getMetadataValueByKey(key) {
|
|
5173
|
+
return q_utilities_.Metadata.getValueByKey(this.metadata || [], key)
|
|
5017
5174
|
}
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
if (!this.isSameAmount(payment)) {
|
|
5023
|
-
return { payment, err: new Error('the amount was not matched') }
|
|
5024
|
-
}
|
|
5025
|
-
try {
|
|
5026
|
-
payment.settled()
|
|
5027
|
-
payment
|
|
5028
|
-
.setPaidAmount(this.getPaidAmount())
|
|
5029
|
-
.setPaidTimestamp(this.getPaidTimestamp())
|
|
5030
|
-
.setPaymentResultCode(this.paymentResultCode)
|
|
5031
|
-
return { payment, err: null }
|
|
5032
|
-
} catch (err) {
|
|
5033
|
-
return { payment, err }
|
|
5175
|
+
getStoreItemOptionByKey(key) {
|
|
5176
|
+
const arr = this._ItemOption.getByKey(this.productOptions, key)
|
|
5177
|
+
if (arr.length === 1) {
|
|
5178
|
+
return arr[0]
|
|
5034
5179
|
}
|
|
5180
|
+
return null
|
|
5035
5181
|
}
|
|
5036
|
-
|
|
5037
|
-
return this.
|
|
5182
|
+
hasStock(qty) {
|
|
5183
|
+
return this.stock >= qty
|
|
5038
5184
|
}
|
|
5039
|
-
|
|
5040
|
-
|
|
5185
|
+
isQualified(data) {
|
|
5186
|
+
const rules = this.getMetadataValueByKey('RULES') || []
|
|
5187
|
+
return (rules.length === 0)
|
|
5188
|
+
? true
|
|
5189
|
+
: rules.reduce((acc, r) => {
|
|
5190
|
+
return acc || (0,q_utilities_.getValidation)(r, data, storeItem_getDataByKey, q_utilities_.KeyValueObject)
|
|
5191
|
+
}, false)
|
|
5041
5192
|
}
|
|
5042
|
-
|
|
5043
|
-
|
|
5193
|
+
isTicket() {
|
|
5194
|
+
return false
|
|
5044
5195
|
}
|
|
5045
5196
|
setModified() {
|
|
5046
5197
|
this.modified = (new Date()).valueOf()
|
|
5047
5198
|
return this
|
|
5048
5199
|
}
|
|
5049
|
-
setupMetadata() {
|
|
5050
|
-
const amount = this.amount
|
|
5051
|
-
const paymentMethod = this.paymentMethod
|
|
5052
|
-
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'AMOUNT', amount)
|
|
5053
|
-
q_utilities_namespaceObject.Metadata.addItem(this.metadata, 'PAYMENT_METHOD', paymentMethod)
|
|
5054
|
-
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'amount', amount)
|
|
5055
|
-
q_utilities_namespaceObject.KeyValueObject.addItem(this.remarks, 'paymentMethod', paymentMethod)
|
|
5056
|
-
return this
|
|
5057
|
-
}
|
|
5058
|
-
setupRemarks() {
|
|
5059
|
-
return this.setupMetadata()
|
|
5060
|
-
}
|
|
5061
5200
|
update(update) {
|
|
5062
5201
|
Object.keys(update).forEach((key) => {
|
|
5063
|
-
if (
|
|
5202
|
+
if (storeItem_updateAllowedProps.includes(key)) {
|
|
5064
5203
|
if (key === 'metadata') {
|
|
5065
|
-
this[key] =
|
|
5204
|
+
this[key] = q_utilities_.Metadata.initOnlyValidFromArray(update[key])
|
|
5205
|
+
} else if (key === 'productOptions') {
|
|
5206
|
+
this[key] = this._ItemOption.initOnlyValidFromArray(update[key])
|
|
5066
5207
|
} else if (key === 'remarks') {
|
|
5067
|
-
this[key] =
|
|
5208
|
+
this[key] = q_utilities_.KeyValueObject.initOnlyValidFromArray(update[key])
|
|
5068
5209
|
} else {
|
|
5069
5210
|
this[key] = update[key]
|
|
5070
5211
|
}
|
|
@@ -5074,58 +5215,35 @@ class PaymentResult {
|
|
|
5074
5215
|
}
|
|
5075
5216
|
}
|
|
5076
5217
|
|
|
5077
|
-
function
|
|
5078
|
-
const copyOptions = options || {}
|
|
5079
|
-
if (copyOptions[key]) {
|
|
5080
|
-
return copyOptions[key]
|
|
5081
|
-
}
|
|
5082
|
-
return stringHelper.setCode()
|
|
5083
|
-
}
|
|
5084
|
-
|
|
5085
|
-
function paymentResult_setId(id) {
|
|
5218
|
+
function storeItem_setId(id) {
|
|
5086
5219
|
if (id && typeof id.toString === 'function') {
|
|
5087
5220
|
return id.toString()
|
|
5088
5221
|
}
|
|
5089
5222
|
return id
|
|
5090
5223
|
}
|
|
5091
5224
|
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
class PaymentResultRepo extends q_utilities_namespaceObject.Repo {
|
|
5099
|
-
constructor(options = {}) {
|
|
5100
|
-
options = options || {}
|
|
5101
|
-
super(options)
|
|
5102
|
-
const { _PaymentResult } = options._constructor || {}
|
|
5103
|
-
this._PaymentResult = _PaymentResult && (_PaymentResult._superclass === PaymentResult._superclass) ? _PaymentResult : PaymentResult
|
|
5104
|
-
}
|
|
5105
|
-
static get _classname() {
|
|
5106
|
-
return 'PaymentResultRepo'
|
|
5107
|
-
}
|
|
5108
|
-
init(options) {
|
|
5109
|
-
return this._PaymentResult.init(options)
|
|
5225
|
+
function storeItem_setCode(options, key) {
|
|
5226
|
+
const copyOptions = options || {}
|
|
5227
|
+
if (copyOptions[key]) {
|
|
5228
|
+
return copyOptions[key]
|
|
5110
5229
|
}
|
|
5230
|
+
return stringHelper.setCode()
|
|
5111
5231
|
}
|
|
5112
5232
|
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5233
|
+
function storeItem_getDataByKey(key, data) {
|
|
5234
|
+
return (0,q_utilities_.getValueByKeys)(key.split('.'), data)
|
|
5235
|
+
}
|
|
5118
5236
|
|
|
5119
5237
|
|
|
5120
5238
|
|
|
5239
|
+
;// ./lib/models/storeItem/index.js
|
|
5121
5240
|
|
|
5122
|
-
;// ./lib/models/status/index.js
|
|
5123
5241
|
|
|
5124
5242
|
|
|
5125
5243
|
|
|
5244
|
+
;// ./lib/models/index.js
|
|
5126
5245
|
|
|
5127
5246
|
|
|
5128
|
-
;// ./lib/models/index.js
|
|
5129
5247
|
|
|
5130
5248
|
|
|
5131
5249
|
|
|
@@ -5257,6 +5375,34 @@ class Chain {
|
|
|
5257
5375
|
|
|
5258
5376
|
|
|
5259
5377
|
|
|
5378
|
+
;// ./lib/helpers/calculateByCoupon/calculateCoupon.js
|
|
5379
|
+
|
|
5380
|
+
function calculateByCoupon({ coupon, price }) {
|
|
5381
|
+
const { couponDetails } = coupon
|
|
5382
|
+
if (!couponDetails) {
|
|
5383
|
+
return 0
|
|
5384
|
+
}
|
|
5385
|
+
const { type, item } = couponDetails
|
|
5386
|
+
if (item) {
|
|
5387
|
+
switch(type) {
|
|
5388
|
+
case ('Percentage'): {
|
|
5389
|
+
return _caculateByPercentage(price, couponDetails)
|
|
5390
|
+
}
|
|
5391
|
+
default: {
|
|
5392
|
+
return 0
|
|
5393
|
+
}
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5398
|
+
function _caculateByPercentage(price, couponDetails) {
|
|
5399
|
+
const { value } = couponDetails
|
|
5400
|
+
return price.value * (value / 100)
|
|
5401
|
+
}
|
|
5402
|
+
|
|
5403
|
+
|
|
5404
|
+
|
|
5405
|
+
|
|
5260
5406
|
;// ./lib/eventManager/chains/helpers.js
|
|
5261
5407
|
|
|
5262
5408
|
|
|
@@ -5265,6 +5411,7 @@ class Chain {
|
|
|
5265
5411
|
|
|
5266
5412
|
|
|
5267
5413
|
|
|
5414
|
+
|
|
5268
5415
|
;// ./lib/eventManager/chains/chainCategoryLimit.js
|
|
5269
5416
|
|
|
5270
5417
|
|
|
@@ -5372,7 +5519,7 @@ class ChainGetPrice extends Chain {
|
|
|
5372
5519
|
try {
|
|
5373
5520
|
const { lines, user } = chainTarget
|
|
5374
5521
|
// const entitlements = JSON.parse(JSON.stringify(this.entitlements))
|
|
5375
|
-
const entitlements =
|
|
5522
|
+
const entitlements = external_lodash_.cloneDeep(this.entitlements)
|
|
5376
5523
|
lines.forEach((line) => {
|
|
5377
5524
|
const prices = getPricesByTime(line, this.dateTime)
|
|
5378
5525
|
const priceStrategies = getStrategiesByRestrictions(prices, line, user)
|
|
@@ -5384,6 +5531,7 @@ class ChainGetPrice extends Chain {
|
|
|
5384
5531
|
// }
|
|
5385
5532
|
})
|
|
5386
5533
|
cutEntitlements(lines, entitlements, this.currency.code)
|
|
5534
|
+
// useCoupons(lines, this.currency.code)
|
|
5387
5535
|
// getAmount()
|
|
5388
5536
|
await this.next(chainTarget)
|
|
5389
5537
|
} catch (err) {
|
|
@@ -5600,6 +5748,13 @@ function getStrategiesByRestrictions(prices, line, user) {
|
|
|
5600
5748
|
}
|
|
5601
5749
|
|
|
5602
5750
|
|
|
5751
|
+
// function useCoupons(lines, currencyCode) {
|
|
5752
|
+
// lines.forEach((line) => {
|
|
5753
|
+
|
|
5754
|
+
// })
|
|
5755
|
+
// }
|
|
5756
|
+
|
|
5757
|
+
|
|
5603
5758
|
|
|
5604
5759
|
;// ./lib/eventManager/chains/ChainGetPriceForGroup.js
|
|
5605
5760
|
|
|
@@ -5617,7 +5772,7 @@ class ChainGetPriceForGroup extends Chain {
|
|
|
5617
5772
|
async handleRequest(chainTarget) {
|
|
5618
5773
|
try {
|
|
5619
5774
|
const { lines, user } = chainTarget
|
|
5620
|
-
const entitlements =
|
|
5775
|
+
const entitlements = external_lodash_.cloneDeep(this.entitlements)
|
|
5621
5776
|
|
|
5622
5777
|
lines.forEach((line) => {
|
|
5623
5778
|
const prices = ChainGetPriceForGroup_getPricesByTime(line, this.dateTime)
|
|
@@ -5855,7 +6010,7 @@ class ChainMerchandiseLimit extends Chain {
|
|
|
5855
6010
|
const stock = merchandise.getStock()
|
|
5856
6011
|
if (stock === 0) {
|
|
5857
6012
|
line.disabled = true
|
|
5858
|
-
line.errors.push('
|
|
6013
|
+
line.errors.push('Full.')
|
|
5859
6014
|
} else {
|
|
5860
6015
|
const { qty } = updatedItem
|
|
5861
6016
|
updatedItem.qty = qty > stock ? stock : qty
|
|
@@ -5900,7 +6055,7 @@ class ChainProductLimit extends Chain {
|
|
|
5900
6055
|
// const newRest = balance - ordered
|
|
5901
6056
|
if (balance === 0) {
|
|
5902
6057
|
updatedItem.qty = 0
|
|
5903
|
-
line.errors.push(`"${name}" is out of stock`)
|
|
6058
|
+
// line.errors.push(`"${name}" is out of stock`)
|
|
5904
6059
|
} else {
|
|
5905
6060
|
const ordered = (productQty * qty)
|
|
5906
6061
|
const newBalance = balance - ordered
|
|
@@ -5997,8 +6152,8 @@ class ChainProductRestrictions extends Chain {
|
|
|
5997
6152
|
if (!(product.maxPerWallet > qty)) {
|
|
5998
6153
|
line.disabled = true
|
|
5999
6154
|
}
|
|
6000
|
-
const [restrictions = []] =
|
|
6001
|
-
const [requiredProductCodes = []] =
|
|
6155
|
+
const [restrictions = []] = q_utilities_.KeyValueObject.getValuesByKey(product.remarks, 'restrictions')
|
|
6156
|
+
const [requiredProductCodes = []] = q_utilities_.KeyValueObject.getValuesByKey(restrictions, 'requiredProductCodes')
|
|
6002
6157
|
if (requiredProductCodes.length === 0) {
|
|
6003
6158
|
return
|
|
6004
6159
|
}
|
|
@@ -6044,22 +6199,141 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6044
6199
|
if (required && !value && !notFinishRequired) {
|
|
6045
6200
|
notFinishRequired = true
|
|
6046
6201
|
line.validated = false
|
|
6047
|
-
line.errors.push('
|
|
6202
|
+
line.errors.push('Please fill in the option(s).')
|
|
6048
6203
|
}
|
|
6049
6204
|
if (validated && !notFinishValidated) {
|
|
6050
6205
|
notFinishValidated = true
|
|
6051
|
-
line.errors.push('
|
|
6206
|
+
line.errors.push('Invalid option(s).')
|
|
6052
6207
|
}
|
|
6053
6208
|
})
|
|
6054
6209
|
})
|
|
6055
6210
|
})
|
|
6056
6211
|
await this.next(chainTarget)
|
|
6057
6212
|
} catch (err) {
|
|
6058
|
-
chainTarget.addException('
|
|
6213
|
+
chainTarget.addException('Check product restriction failed.', err.message)
|
|
6214
|
+
this.exitChain()
|
|
6215
|
+
}
|
|
6216
|
+
}
|
|
6217
|
+
}
|
|
6218
|
+
|
|
6219
|
+
|
|
6220
|
+
|
|
6221
|
+
;// ./lib/eventManager/chains/chainRelatedCoupons.js
|
|
6222
|
+
|
|
6223
|
+
// import { WalletItem } from '../../models/walletItem/index.js'
|
|
6224
|
+
|
|
6225
|
+
class ChainRelatedCoupons extends Chain {
|
|
6226
|
+
constructor(options = {}) {
|
|
6227
|
+
super(options)
|
|
6228
|
+
this.autoUseCoupon = options.autoUseCoupon || false
|
|
6229
|
+
this.currency = options.currency
|
|
6230
|
+
this.walletItems = options.walletItems
|
|
6231
|
+
}
|
|
6232
|
+
|
|
6233
|
+
async handleRequest(chainTarget) {
|
|
6234
|
+
try {
|
|
6235
|
+
const { lines, users } = chainTarget
|
|
6236
|
+
// const walletItems = WalletItem.initOnlyValidFromArray(this.walletItems)
|
|
6237
|
+
const couponWalletItems = this.walletItems.filter((i) => i.isCoupon)
|
|
6238
|
+
lines.forEach((line) => {
|
|
6239
|
+
_calculateAmountByCoupons({ line, currencyCode: this.currency.code })
|
|
6240
|
+
_updateRelatedCoupons(line, couponWalletItems, this.autoUseCoupon, this.currency.code)
|
|
6241
|
+
})
|
|
6242
|
+
lines.forEach((line) => {
|
|
6243
|
+
_getAvailableCoupons(line)
|
|
6244
|
+
})
|
|
6245
|
+
await this.next(chainTarget)
|
|
6246
|
+
} catch (err) {
|
|
6247
|
+
chainTarget.addException('calculate categories limit fail', err.message)
|
|
6059
6248
|
this.exitChain()
|
|
6060
6249
|
}
|
|
6061
6250
|
}
|
|
6062
6251
|
}
|
|
6252
|
+
function _calculateAmountByCoupons({ line, currencyCode }) {
|
|
6253
|
+
const { usedCoupons = {}, updatedItem } = line
|
|
6254
|
+
Object.keys(usedCoupons).forEach((key) => {
|
|
6255
|
+
usedCoupons[key].forEach((coupon) => {
|
|
6256
|
+
const obj = _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode })
|
|
6257
|
+
Object.assign(updatedItem, obj)
|
|
6258
|
+
})
|
|
6259
|
+
})
|
|
6260
|
+
}
|
|
6261
|
+
|
|
6262
|
+
function _calculateAmountByOneCoupon({ updatedItem, coupon, currencyCode }) {
|
|
6263
|
+
const { couponDetails, walletItemCode } = coupon
|
|
6264
|
+
if (!couponDetails) {
|
|
6265
|
+
return updatedItem
|
|
6266
|
+
}
|
|
6267
|
+
const { price, qty, discount, remarks, subTotal } = updatedItem
|
|
6268
|
+
const _discount = calculateByCoupon({ coupon, price })
|
|
6269
|
+
const discountValue = _discount + discount.value
|
|
6270
|
+
const subTotalValue = subTotal.value > _discount ? subTotal.value - _discount : 0
|
|
6271
|
+
const _usedCoupons = q_utilities_.KeyValueObject.foundValueByKey(remarks, 'USED_ITEM_COUPONS') || []
|
|
6272
|
+
_usedCoupons.push(walletItemCode)
|
|
6273
|
+
return {
|
|
6274
|
+
...updatedItem,
|
|
6275
|
+
discount: Amount.init({ value: discountValue, currencyCode }),
|
|
6276
|
+
remarks: q_utilities_.KeyValueObject.insertOrUpdateRecord(remarks, 'USED_ITEM_COUPONS', _usedCoupons ),
|
|
6277
|
+
subTotal: Amount.init({ value: subTotalValue, currencyCode })
|
|
6278
|
+
}
|
|
6279
|
+
}
|
|
6280
|
+
|
|
6281
|
+
|
|
6282
|
+
function _getAvailableCoupons(line) {
|
|
6283
|
+
const { relatedCoupons = [] } = line
|
|
6284
|
+
line.relatedCoupons = relatedCoupons.map((c) => ({
|
|
6285
|
+
...c,
|
|
6286
|
+
availableCoupons: c.coupons.filter((_c) => (!_c.isOnHold))
|
|
6287
|
+
}))
|
|
6288
|
+
}
|
|
6289
|
+
|
|
6290
|
+
function _getRelatedCoupons(cartItemLine, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6291
|
+
const { merchandise, usedCoupons = {}, updatedItem = {} } = cartItemLine
|
|
6292
|
+
const relatedWalletItems = couponWalletItems.filter(
|
|
6293
|
+
item => item.isApplicableCoupon(merchandise) && item.isItemCoupon
|
|
6294
|
+
)
|
|
6295
|
+
// .sort((a, b) => (
|
|
6296
|
+
// b.couponDetails.value - a.couponDetails.value
|
|
6297
|
+
// ))
|
|
6298
|
+
return relatedWalletItems.reduce((acc, w) => {
|
|
6299
|
+
const productCode = w.product.productCode
|
|
6300
|
+
let exist = acc.find((i) => i.productCode === productCode)
|
|
6301
|
+
const isOnHold = w.isOnHold // max? || only use One Coupon?
|
|
6302
|
+
if (!exist) {
|
|
6303
|
+
exist = {
|
|
6304
|
+
coupons: [],
|
|
6305
|
+
product: w.product,
|
|
6306
|
+
productCode: productCode,
|
|
6307
|
+
usedQty: (usedCoupons[productCode] || []).length
|
|
6308
|
+
}
|
|
6309
|
+
acc.push(exist)
|
|
6310
|
+
}
|
|
6311
|
+
exist.coupons.push(w)
|
|
6312
|
+
const { qty: itemQty, subTotal } = updatedItem
|
|
6313
|
+
if (autoUseCoupon && !isOnHold && exist.usedQty < itemQty && subTotal.value > 0) {
|
|
6314
|
+
// use coupon
|
|
6315
|
+
w.setOnHold()
|
|
6316
|
+
usedCoupons[productCode] = [
|
|
6317
|
+
...usedCoupons[productCode] || [],
|
|
6318
|
+
w
|
|
6319
|
+
]
|
|
6320
|
+
const obj = _calculateAmountByOneCoupon({ updatedItem, currencyCode, coupon: w })
|
|
6321
|
+
Object.assign(updatedItem, obj)
|
|
6322
|
+
exist.usedQty = usedCoupons[productCode].length
|
|
6323
|
+
}
|
|
6324
|
+
return acc
|
|
6325
|
+
}, [])
|
|
6326
|
+
}
|
|
6327
|
+
|
|
6328
|
+
|
|
6329
|
+
function _updateRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyCode) {
|
|
6330
|
+
if (couponWalletItems.length > 0) {
|
|
6331
|
+
line.relatedCoupons = _getRelatedCoupons(line, couponWalletItems, autoUseCoupon, currencyCode)
|
|
6332
|
+
}
|
|
6333
|
+
}
|
|
6334
|
+
|
|
6335
|
+
|
|
6336
|
+
|
|
6063
6337
|
|
|
6064
6338
|
|
|
6065
6339
|
|
|
@@ -6075,6 +6349,7 @@ class ChainPurchaseOptions extends Chain {
|
|
|
6075
6349
|
|
|
6076
6350
|
|
|
6077
6351
|
|
|
6352
|
+
|
|
6078
6353
|
;// ./lib/helpers/corHelper/chainException.js
|
|
6079
6354
|
|
|
6080
6355
|
class ChainException {
|
|
@@ -6336,6 +6611,7 @@ class ChainManagerFactory {
|
|
|
6336
6611
|
|
|
6337
6612
|
function _calculateAmountChainsFactory(payload) {
|
|
6338
6613
|
const {
|
|
6614
|
+
autoUseCoupon,
|
|
6339
6615
|
categories,
|
|
6340
6616
|
currency,
|
|
6341
6617
|
dateTime,
|
|
@@ -6359,6 +6635,7 @@ function _calculateAmountChainsFactory(payload) {
|
|
|
6359
6635
|
new ChainGetPrice({
|
|
6360
6636
|
currency, dateTime, entitlements, merchandises
|
|
6361
6637
|
}),
|
|
6638
|
+
new ChainRelatedCoupons({ currency, autoUseCoupon, walletItems }),
|
|
6362
6639
|
]
|
|
6363
6640
|
}
|
|
6364
6641
|
|
|
@@ -6500,6 +6777,11 @@ function getFakeClass() {
|
|
|
6500
6777
|
|
|
6501
6778
|
|
|
6502
6779
|
|
|
6780
|
+
;// ./lib/helpers/calculateByCoupon/index.js
|
|
6781
|
+
|
|
6782
|
+
|
|
6783
|
+
|
|
6784
|
+
|
|
6503
6785
|
;// ./lib/helpers/corHelper/index.js
|
|
6504
6786
|
|
|
6505
6787
|
|
|
@@ -6507,6 +6789,150 @@ function getFakeClass() {
|
|
|
6507
6789
|
|
|
6508
6790
|
|
|
6509
6791
|
|
|
6792
|
+
;// ./lib/helpers/getRolesChangesRelatedCouponsHelper/getRolesChangesRelatedCouponsHelper.js
|
|
6793
|
+
function getRolesChangesRelatedCouponsHelper({ newRoles, originalRoles }) {
|
|
6794
|
+
const couponFromNewRoles = _getCouponsByRoles(newRoles)
|
|
6795
|
+
const couponFromOriginalRoles = _getCouponsByRoles(originalRoles)
|
|
6796
|
+
const allKeys = new Set([
|
|
6797
|
+
...Object.keys(couponFromNewRoles),
|
|
6798
|
+
...Object.keys(couponFromOriginalRoles)
|
|
6799
|
+
])
|
|
6800
|
+
return Array.from(allKeys).reduce((acc, key) => {
|
|
6801
|
+
const newValue = couponFromNewRoles[key] || 0;
|
|
6802
|
+
const originalValue = couponFromOriginalRoles[key] || 0;
|
|
6803
|
+
const delta = newValue - originalValue;
|
|
6804
|
+
if (delta !== 0) {
|
|
6805
|
+
acc.push({
|
|
6806
|
+
key,
|
|
6807
|
+
value: {
|
|
6808
|
+
delta,
|
|
6809
|
+
newValue,
|
|
6810
|
+
originalValue
|
|
6811
|
+
}
|
|
6812
|
+
});
|
|
6813
|
+
}
|
|
6814
|
+
return acc
|
|
6815
|
+
}, [])
|
|
6816
|
+
}
|
|
6817
|
+
|
|
6818
|
+
|
|
6819
|
+
function _getCouponsByRoles(roles) {
|
|
6820
|
+
return roles.reduce((acc, role) => {
|
|
6821
|
+
const couponCodes = role.getCouponCodes()
|
|
6822
|
+
couponCodes.forEach((c) => {
|
|
6823
|
+
const { key, value } = c
|
|
6824
|
+
acc[key] = acc[key] ? acc[key] + value : value
|
|
6825
|
+
})
|
|
6826
|
+
return acc
|
|
6827
|
+
}, {})
|
|
6828
|
+
}
|
|
6829
|
+
|
|
6830
|
+
|
|
6831
|
+
|
|
6832
|
+
;// ./lib/helpers/couponManager/couponManager.js
|
|
6833
|
+
|
|
6834
|
+
|
|
6835
|
+
|
|
6836
|
+
|
|
6837
|
+
class CouponManager {
|
|
6838
|
+
constructor(options) {
|
|
6839
|
+
this.products = options.products || []
|
|
6840
|
+
this.walletItems = options.walletItems || []
|
|
6841
|
+
this.originalRoles = options.originalRoles || []
|
|
6842
|
+
this.newRoles = options.newRoles || []
|
|
6843
|
+
}
|
|
6844
|
+
|
|
6845
|
+
static init(options = {}) {
|
|
6846
|
+
if (options instanceof this) {
|
|
6847
|
+
return options
|
|
6848
|
+
}
|
|
6849
|
+
const instance = new this(options)
|
|
6850
|
+
return instance.isValid ? instance : null
|
|
6851
|
+
}
|
|
6852
|
+
|
|
6853
|
+
get isValid() {
|
|
6854
|
+
return !!this
|
|
6855
|
+
}
|
|
6856
|
+
|
|
6857
|
+
get couponProducts() {
|
|
6858
|
+
return this.products.filter((p) => p.isCoupon)
|
|
6859
|
+
}
|
|
6860
|
+
|
|
6861
|
+
get couponWalletItems() {
|
|
6862
|
+
return this.walletItems.filter((w) => w.isCoupon)
|
|
6863
|
+
}
|
|
6864
|
+
|
|
6865
|
+
get roleRelatedCoupons() {
|
|
6866
|
+
return getRolesChangesRelatedCouponsHelper({ newRoles: this.newRoles, originalRoles: this.originalRoles })
|
|
6867
|
+
}
|
|
6868
|
+
|
|
6869
|
+
|
|
6870
|
+
get couponItemList() {
|
|
6871
|
+
return this.couponProducts.map((p) => {
|
|
6872
|
+
const relatedWalletItems = this.walletItems.filter(
|
|
6873
|
+
item => item.productCode === p.productCode
|
|
6874
|
+
)
|
|
6875
|
+
|
|
6876
|
+
const usedCoupons = relatedWalletItems.filter(item => item.isUsed)
|
|
6877
|
+
usedCoupons.forEach((c) => {
|
|
6878
|
+
c.useForWalletItems = this.walletItems.filter((item) => (c.useFor || []).includes(item.walletItemCode)) // useFor
|
|
6879
|
+
})
|
|
6880
|
+
|
|
6881
|
+
const availableCoupons = relatedWalletItems.filter(item => !item.isAvailableCoupon)
|
|
6882
|
+
|
|
6883
|
+
const roleBase = q_utilities_.KeyValueObject.foundValueByKey(this.roleRelatedCoupons, p.productCode) || {}
|
|
6884
|
+
|
|
6885
|
+
const remainingQuota = p.maxPerWallet - (usedCoupons.length + availableCoupons.length)
|
|
6886
|
+
|
|
6887
|
+
const { qty, remarks } = _handler({ product: p, availableCoupons, roleBase, remainingQuota })
|
|
6888
|
+
|
|
6889
|
+
return {
|
|
6890
|
+
product: p,
|
|
6891
|
+
usedCoupons,
|
|
6892
|
+
availableCoupons,
|
|
6893
|
+
alreadyHave: usedCoupons.length + availableCoupons.length,
|
|
6894
|
+
maxLimit: p.maxPerWallet,
|
|
6895
|
+
remainingQuota,
|
|
6896
|
+
qty,
|
|
6897
|
+
roleBase,
|
|
6898
|
+
remarks
|
|
6899
|
+
};
|
|
6900
|
+
})
|
|
6901
|
+
}
|
|
6902
|
+
|
|
6903
|
+
setNewRoles() {
|
|
6904
|
+
this.newRoles = newRoles
|
|
6905
|
+
}
|
|
6906
|
+
|
|
6907
|
+
}
|
|
6908
|
+
|
|
6909
|
+
|
|
6910
|
+
|
|
6911
|
+
|
|
6912
|
+
function _handler({ product, remainingQuota, availableCoupons, roleBase }) {
|
|
6913
|
+
const { delta = 0 } = roleBase
|
|
6914
|
+
const { maxPerWallet } = product
|
|
6915
|
+
let qty = delta
|
|
6916
|
+
const remarks = []
|
|
6917
|
+
if (delta > 0 && maxPerWallet && delta > remainingQuota) {
|
|
6918
|
+
qty = 0
|
|
6919
|
+
remarks.push(`max ${maxPerWallet}`)
|
|
6920
|
+
}
|
|
6921
|
+
if (delta < 0 && maxPerWallet && availableCoupons.length < delta) {
|
|
6922
|
+
qty = availableCoupons.length
|
|
6923
|
+
remarks.push(`only ${availableCoupons.length} could be cancelled`)
|
|
6924
|
+
}
|
|
6925
|
+
return {
|
|
6926
|
+
qty,
|
|
6927
|
+
remarks
|
|
6928
|
+
}
|
|
6929
|
+
}
|
|
6930
|
+
|
|
6931
|
+
;// ./lib/helpers/couponManager/index.js
|
|
6932
|
+
|
|
6933
|
+
|
|
6934
|
+
|
|
6935
|
+
|
|
6510
6936
|
;// ./lib/helpers/dateHelper/handler/handler.js
|
|
6511
6937
|
class Handler {
|
|
6512
6938
|
constructor(date) {
|
|
@@ -6634,7 +7060,11 @@ function createDate(timestamp) {
|
|
|
6634
7060
|
const mthIdx = Number(mthStr) - 1
|
|
6635
7061
|
return new Date(timestamp.slice(0, 4), mthIdx, timestamp.slice(6, 8))
|
|
6636
7062
|
}
|
|
6637
|
-
|
|
7063
|
+
try {
|
|
7064
|
+
return new Date(timestamp)
|
|
7065
|
+
} catch (e) {
|
|
7066
|
+
throw new Error('timestamp does not meet the requirements')
|
|
7067
|
+
}
|
|
6638
7068
|
}
|
|
6639
7069
|
|
|
6640
7070
|
function convert(date, dateFormat) {
|
|
@@ -6903,6 +7333,8 @@ function isDescendingOrder({ arr = [], key }) {
|
|
|
6903
7333
|
|
|
6904
7334
|
|
|
6905
7335
|
|
|
7336
|
+
|
|
7337
|
+
|
|
6906
7338
|
;// ./lib/index.js
|
|
6907
7339
|
|
|
6908
7340
|
const models = models_namespaceObject
|
|
@@ -6913,48 +7345,7 @@ const models = models_namespaceObject
|
|
|
6913
7345
|
;// ./index.js
|
|
6914
7346
|
|
|
6915
7347
|
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
var __webpack_exports__Chain = __webpack_exports__.sW;
|
|
6921
|
-
var __webpack_exports__ChainManager = __webpack_exports__.RU;
|
|
6922
|
-
var __webpack_exports__ChainManagerFactory = __webpack_exports__.n$;
|
|
6923
|
-
var __webpack_exports__ChainTarget = __webpack_exports__.FH;
|
|
6924
|
-
var __webpack_exports__CreditNote = __webpack_exports__.cT;
|
|
6925
|
-
var __webpack_exports__CreditNoteLine = __webpack_exports__.w0;
|
|
6926
|
-
var __webpack_exports__CreditNoteRepo = __webpack_exports__.iY;
|
|
6927
|
-
var __webpack_exports__Currency = __webpack_exports__.Sj;
|
|
6928
|
-
var __webpack_exports__Invoice = __webpack_exports__.qO;
|
|
6929
|
-
var __webpack_exports__InvoiceLine = __webpack_exports__.cY;
|
|
6930
|
-
var __webpack_exports__KeyValueObject = __webpack_exports__.Yc;
|
|
6931
|
-
var __webpack_exports__Merchandise = __webpack_exports__.So;
|
|
6932
|
-
var __webpack_exports__PaymentGateway = __webpack_exports__.Zg;
|
|
6933
|
-
var __webpack_exports__PaymentResult = __webpack_exports__.gp;
|
|
6934
|
-
var __webpack_exports__Price = __webpack_exports__.gm;
|
|
6935
|
-
var __webpack_exports__PriceStrategy = __webpack_exports__.X0;
|
|
6936
|
-
var __webpack_exports__Product = __webpack_exports__.Yt;
|
|
6937
|
-
var __webpack_exports__Status = __webpack_exports__.nW;
|
|
6938
|
-
var __webpack_exports__Transaction = __webpack_exports__.ZX;
|
|
6939
|
-
var __webpack_exports__WalletItem = __webpack_exports__.vU;
|
|
6940
|
-
var __webpack_exports__adminSettle = __webpack_exports__.Do;
|
|
6941
|
-
var __webpack_exports__calculator = __webpack_exports__.Jw;
|
|
6942
|
-
var __webpack_exports__checkDuplicate = __webpack_exports__.C6;
|
|
6943
|
-
var __webpack_exports__convertTimestampToString = __webpack_exports__.S0;
|
|
6944
|
-
var __webpack_exports__defaultComparator = __webpack_exports__.G3;
|
|
6945
|
-
var __webpack_exports__defaultSort = __webpack_exports__.AG;
|
|
6946
|
-
var __webpack_exports__eleInArrayComparator = __webpack_exports__.RC;
|
|
6947
|
-
var __webpack_exports__firstLetterToLower = __webpack_exports__.F4;
|
|
6948
|
-
var __webpack_exports__getFakeClass = __webpack_exports__.al;
|
|
6949
|
-
var __webpack_exports__getSubClass = __webpack_exports__.xy;
|
|
6950
|
-
var __webpack_exports__handlerOrderList = __webpack_exports__.Nc;
|
|
6951
|
-
var __webpack_exports__isAllEqual = __webpack_exports__.M1;
|
|
6952
|
-
var __webpack_exports__isDescendingOrder = __webpack_exports__.zv;
|
|
6953
|
-
var __webpack_exports__makeResponseHelper = __webpack_exports__.gP;
|
|
6954
|
-
var __webpack_exports__models = __webpack_exports__.Jn;
|
|
6955
|
-
var __webpack_exports__objectAllInArrayComparator = __webpack_exports__.pJ;
|
|
6956
|
-
var __webpack_exports__objectComparator = __webpack_exports__.aL;
|
|
6957
|
-
var __webpack_exports__objectOrderInArrayComparator = __webpack_exports__.il;
|
|
6958
|
-
var __webpack_exports__setQuery = __webpack_exports__.NY;
|
|
6959
|
-
var __webpack_exports__stringHelper = __webpack_exports__.yO;
|
|
6960
|
-
export { __webpack_exports__Amount as Amount, __webpack_exports__Cart as Cart, __webpack_exports__CartItem as CartItem, __webpack_exports__Category as Category, __webpack_exports__Chain as Chain, __webpack_exports__ChainManager as ChainManager, __webpack_exports__ChainManagerFactory as ChainManagerFactory, __webpack_exports__ChainTarget as ChainTarget, __webpack_exports__CreditNote as CreditNote, __webpack_exports__CreditNoteLine as CreditNoteLine, __webpack_exports__CreditNoteRepo as CreditNoteRepo, __webpack_exports__Currency as Currency, __webpack_exports__Invoice as Invoice, __webpack_exports__InvoiceLine as InvoiceLine, __webpack_exports__KeyValueObject as KeyValueObject, __webpack_exports__Merchandise as Merchandise, __webpack_exports__PaymentGateway as PaymentGateway, __webpack_exports__PaymentResult as PaymentResult, __webpack_exports__Price as Price, __webpack_exports__PriceStrategy as PriceStrategy, __webpack_exports__Product as Product, __webpack_exports__Status as Status, __webpack_exports__Transaction as Transaction, __webpack_exports__WalletItem as WalletItem, __webpack_exports__adminSettle as adminSettle, __webpack_exports__calculator as calculator, __webpack_exports__checkDuplicate as checkDuplicate, __webpack_exports__convertTimestampToString as convertTimestampToString, __webpack_exports__defaultComparator as defaultComparator, __webpack_exports__defaultSort as defaultSort, __webpack_exports__eleInArrayComparator as eleInArrayComparator, __webpack_exports__firstLetterToLower as firstLetterToLower, __webpack_exports__getFakeClass as getFakeClass, __webpack_exports__getSubClass as getSubClass, __webpack_exports__handlerOrderList as handlerOrderList, __webpack_exports__isAllEqual as isAllEqual, __webpack_exports__isDescendingOrder as isDescendingOrder, __webpack_exports__makeResponseHelper as makeResponseHelper, __webpack_exports__models as models, __webpack_exports__objectAllInArrayComparator as objectAllInArrayComparator, __webpack_exports__objectComparator as objectComparator, __webpack_exports__objectOrderInArrayComparator as objectOrderInArrayComparator, __webpack_exports__setQuery as setQuery, __webpack_exports__stringHelper as stringHelper };
|
|
7348
|
+
/******/ return __webpack_exports__;
|
|
7349
|
+
/******/ })()
|
|
7350
|
+
;
|
|
7351
|
+
});
|