taxtank-core 2.1.1 → 2.1.2
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/fesm2022/taxtank-core.mjs +76 -56
- package/fesm2022/taxtank-core.mjs.map +1 -1
- package/index.d.ts +22 -21
- package/package.json +1 -1
|
@@ -4942,6 +4942,60 @@ __decorate([
|
|
|
4942
4942
|
Type(() => ServiceProduct)
|
|
4943
4943
|
], ServicePromoCode.prototype, "products", void 0);
|
|
4944
4944
|
|
|
4945
|
+
/**
|
|
4946
|
+
* @TODO refactor with Map or Record
|
|
4947
|
+
* List of objects grouped by passed property
|
|
4948
|
+
*/
|
|
4949
|
+
class Dictionary {
|
|
4950
|
+
constructor(items = [], path = 'id') {
|
|
4951
|
+
this.items = {};
|
|
4952
|
+
if (!items.length) {
|
|
4953
|
+
return;
|
|
4954
|
+
}
|
|
4955
|
+
this.groupItems(items, path);
|
|
4956
|
+
}
|
|
4957
|
+
add(key, value) {
|
|
4958
|
+
this.items[key] = value;
|
|
4959
|
+
return this;
|
|
4960
|
+
}
|
|
4961
|
+
get(key) {
|
|
4962
|
+
return this.items[key] !== undefined ? this.items[key] : null;
|
|
4963
|
+
}
|
|
4964
|
+
sum(keys) {
|
|
4965
|
+
return round(keys.reduce((sum, key) => sum + (+this.get(key)), 0), 2);
|
|
4966
|
+
}
|
|
4967
|
+
avg(keys) {
|
|
4968
|
+
return round(this.sum(keys) / keys.length, 2);
|
|
4969
|
+
}
|
|
4970
|
+
merge(dictionary) {
|
|
4971
|
+
Object.assign(this.items, dictionary.items);
|
|
4972
|
+
return this;
|
|
4973
|
+
}
|
|
4974
|
+
toArray() {
|
|
4975
|
+
return Object.values(this.items);
|
|
4976
|
+
}
|
|
4977
|
+
groupItems(items, path) {
|
|
4978
|
+
// Do nothing if provided path was not found in the 1st item
|
|
4979
|
+
if (!hasIn(items[0], path.split('.')[0])) {
|
|
4980
|
+
return;
|
|
4981
|
+
}
|
|
4982
|
+
items.forEach((item) => {
|
|
4983
|
+
let key = get(item, path);
|
|
4984
|
+
// if object does not have property for grouping it will be grouped as 'other'
|
|
4985
|
+
if (key === undefined) {
|
|
4986
|
+
key = 'other';
|
|
4987
|
+
}
|
|
4988
|
+
this.items[key] = item;
|
|
4989
|
+
});
|
|
4990
|
+
}
|
|
4991
|
+
get keys() {
|
|
4992
|
+
return Object.keys(this.items);
|
|
4993
|
+
}
|
|
4994
|
+
get length() {
|
|
4995
|
+
return this.keys.length;
|
|
4996
|
+
}
|
|
4997
|
+
}
|
|
4998
|
+
|
|
4945
4999
|
class ServiceSubscription extends ServiceSubscription$1 {
|
|
4946
5000
|
constructor() {
|
|
4947
5001
|
super(...arguments);
|
|
@@ -4952,7 +5006,7 @@ class ServiceSubscription extends ServiceSubscription$1 {
|
|
|
4952
5006
|
return this.promoCode?.id || null;
|
|
4953
5007
|
}
|
|
4954
5008
|
/**
|
|
4955
|
-
* @TODO Vik rename to userPromoCode
|
|
5009
|
+
* @TODO Vik rename to userPromoCode?
|
|
4956
5010
|
*/
|
|
4957
5011
|
get promoCode() {
|
|
4958
5012
|
return this.promoCodes.find(promoCode => !ServicePromoCode.qtyIds.includes(promoCode.id)) ?? null;
|
|
@@ -4969,6 +5023,26 @@ class ServiceSubscription extends ServiceSubscription$1 {
|
|
|
4969
5023
|
get initialPrice() {
|
|
4970
5024
|
return this.items.reduce((sum, item) => sum + item.total, 0);
|
|
4971
5025
|
}
|
|
5026
|
+
getDiscountPriceByProduct(prices) {
|
|
5027
|
+
// quantity discount
|
|
5028
|
+
const qtyRatio = 1 - PRODUCT_QUANTITY_DISCOUNT_PERCENT[this.items.length] / 100;
|
|
5029
|
+
const priceByProduct = new Dictionary([]);
|
|
5030
|
+
prices.forEach(price => {
|
|
5031
|
+
priceByProduct.add(price.product.id, price.amount * qtyRatio);
|
|
5032
|
+
});
|
|
5033
|
+
if (!this.promoCode || this.promoCode.amountOff) {
|
|
5034
|
+
return priceByProduct;
|
|
5035
|
+
}
|
|
5036
|
+
// promo discount
|
|
5037
|
+
const promoRatio = 1 - (this.promoCode.percentOff) / 100;
|
|
5038
|
+
if (this.promoCode.products.length) {
|
|
5039
|
+
prices = prices.filter(price => this.promoCode.getProductsIds().includes(price.product.id));
|
|
5040
|
+
}
|
|
5041
|
+
prices.forEach(price => {
|
|
5042
|
+
priceByProduct.items[price.product.id] *= promoRatio;
|
|
5043
|
+
});
|
|
5044
|
+
return priceByProduct;
|
|
5045
|
+
}
|
|
4972
5046
|
get discountAmount() {
|
|
4973
5047
|
// quantity discount
|
|
4974
5048
|
const qtyPercent = PRODUCT_QUANTITY_DISCOUNT_PERCENT[this.items.length] / 100;
|
|
@@ -5030,7 +5104,7 @@ class ServiceSubscription extends ServiceSubscription$1 {
|
|
|
5030
5104
|
return this.items.find((item) => item.price.product.isProperties());
|
|
5031
5105
|
}
|
|
5032
5106
|
hasPropertyTank() {
|
|
5033
|
-
return !!this.items.find(
|
|
5107
|
+
return !!this.items.find(item => [ServiceProductIdEnum.PROPERTY_OLD, ServiceProductIdEnum.PROPERTIES].includes(item.price.product.id));
|
|
5034
5108
|
}
|
|
5035
5109
|
hasWorkTank() {
|
|
5036
5110
|
return !!this.items.find((subscriptionItem) => subscriptionItem.price.product.role.includes(UserRolesEnum$1.WORK_TANK));
|
|
@@ -11163,60 +11237,6 @@ __decorate([
|
|
|
11163
11237
|
Expose()
|
|
11164
11238
|
], Message.prototype, "documents", void 0);
|
|
11165
11239
|
|
|
11166
|
-
/**
|
|
11167
|
-
* @TODO refactor with Map or Record
|
|
11168
|
-
* List of objects grouped by passed property
|
|
11169
|
-
*/
|
|
11170
|
-
class Dictionary {
|
|
11171
|
-
constructor(items = [], path = 'id') {
|
|
11172
|
-
this.items = {};
|
|
11173
|
-
if (!items.length) {
|
|
11174
|
-
return;
|
|
11175
|
-
}
|
|
11176
|
-
this.groupItems(items, path);
|
|
11177
|
-
}
|
|
11178
|
-
add(key, value) {
|
|
11179
|
-
this.items[key] = value;
|
|
11180
|
-
return this;
|
|
11181
|
-
}
|
|
11182
|
-
get(key) {
|
|
11183
|
-
return this.items[key] !== undefined ? this.items[key] : null;
|
|
11184
|
-
}
|
|
11185
|
-
sum(keys) {
|
|
11186
|
-
return round(keys.reduce((sum, key) => sum + (+this.get(key)), 0), 2);
|
|
11187
|
-
}
|
|
11188
|
-
avg(keys) {
|
|
11189
|
-
return round(this.sum(keys) / keys.length, 2);
|
|
11190
|
-
}
|
|
11191
|
-
merge(dictionary) {
|
|
11192
|
-
Object.assign(this.items, dictionary.items);
|
|
11193
|
-
return this;
|
|
11194
|
-
}
|
|
11195
|
-
toArray() {
|
|
11196
|
-
return Object.values(this.items);
|
|
11197
|
-
}
|
|
11198
|
-
groupItems(items, path) {
|
|
11199
|
-
// Do nothing if provided path was not found in the 1st item
|
|
11200
|
-
if (!hasIn(items[0], path.split('.')[0])) {
|
|
11201
|
-
return;
|
|
11202
|
-
}
|
|
11203
|
-
items.forEach((item) => {
|
|
11204
|
-
let key = get(item, path);
|
|
11205
|
-
// if object does not have property for grouping it will be grouped as 'other'
|
|
11206
|
-
if (key === undefined) {
|
|
11207
|
-
key = 'other';
|
|
11208
|
-
}
|
|
11209
|
-
this.items[key] = item;
|
|
11210
|
-
});
|
|
11211
|
-
}
|
|
11212
|
-
get keys() {
|
|
11213
|
-
return Object.keys(this.items);
|
|
11214
|
-
}
|
|
11215
|
-
get length() {
|
|
11216
|
-
return this.keys.length;
|
|
11217
|
-
}
|
|
11218
|
-
}
|
|
11219
|
-
|
|
11220
11240
|
/**
|
|
11221
11241
|
* @TODO Alex remove
|
|
11222
11242
|
*/
|