taxtank-core 0.10.5 → 0.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/bundles/taxtank-core.umd.js +1185 -979
  2. package/bundles/taxtank-core.umd.js.map +1 -1
  3. package/esm2015/lib/collections/collection-dictionary.js +6 -6
  4. package/esm2015/lib/collections/collection.js +8 -1
  5. package/esm2015/lib/collections/report/property/property-report-item-depreciation.collection.js +22 -0
  6. package/esm2015/lib/collections/report/property/property-report-item-transaction.collection.js +22 -0
  7. package/esm2015/lib/collections/report/property/property-report-item.collection.js +13 -0
  8. package/esm2015/lib/models/depreciation/depreciation.js +3 -3
  9. package/esm2015/lib/models/report/property/property-report-item-depreciation.js +19 -0
  10. package/esm2015/lib/models/report/property/property-report-item-transaction.js +12 -0
  11. package/esm2015/lib/models/report/property/property-report-item.js +27 -0
  12. package/esm2015/lib/services/report/property/property-transaction-report.service.js +76 -0
  13. package/esm2015/public-api.js +7 -1
  14. package/fesm2015/taxtank-core.js +1000 -830
  15. package/fesm2015/taxtank-core.js.map +1 -1
  16. package/lib/collections/collection-dictionary.d.ts +1 -1
  17. package/lib/collections/collection.d.ts +4 -0
  18. package/lib/collections/report/property/property-report-item-depreciation.collection.d.ts +12 -0
  19. package/lib/collections/report/property/property-report-item-transaction.collection.d.ts +12 -0
  20. package/lib/collections/report/property/property-report-item.collection.d.ts +9 -0
  21. package/lib/models/depreciation/depreciation.d.ts +1 -1
  22. package/lib/models/report/property/property-report-item-depreciation.d.ts +10 -0
  23. package/lib/models/report/property/property-report-item-transaction.d.ts +10 -0
  24. package/lib/models/report/property/property-report-item.d.ts +22 -0
  25. package/lib/services/report/property/property-transaction-report.service.d.ts +42 -0
  26. package/package.json +1 -1
  27. package/public-api.d.ts +6 -0
@@ -1129,9 +1129,8 @@
1129
1129
  * @param path Path to the property to be grouped (Examples: 'transaction', 'property.category')
1130
1130
  * @param prop Optional: Field to group by (Default 'id', Examples: 'id', 'amount', 'date')
1131
1131
  */
1132
- function CollectionDictionary(collection, path, prop) {
1133
- if (path === void 0) { path = ''; }
1134
- if (prop === void 0) { prop = 'id'; }
1132
+ function CollectionDictionary(collection, path) {
1133
+ if (path === void 0) { path = 'id'; }
1135
1134
  /**
1136
1135
  * List of grouped collections
1137
1136
  */
@@ -1142,10 +1141,10 @@
1142
1141
  return;
1143
1142
  }
1144
1143
  // Check if the first collection item has property by path
1145
- if (!has__default["default"](collection.items[0], path) && path) {
1144
+ if (!has__default["default"](collection.items[0], path)) {
1146
1145
  return;
1147
1146
  }
1148
- this.groupItems(collection, path, prop);
1147
+ this.groupItems(collection, path);
1149
1148
  }
1150
1149
  Object.defineProperty(CollectionDictionary.prototype, "keys", {
1151
1150
  /**
@@ -1189,13 +1188,13 @@
1189
1188
  /**
1190
1189
  * Group collection items by passed path into items object
1191
1190
  */
1192
- CollectionDictionary.prototype.groupItems = function (collection, path, prop) {
1191
+ CollectionDictionary.prototype.groupItems = function (collection, path) {
1193
1192
  var _this = this;
1194
1193
  // Create empty initial object for groups
1195
1194
  var obj = {};
1196
1195
  // Group collection items
1197
1196
  collection.items.forEach(function (item) {
1198
- var key = get__default["default"](item, "" + (path ? path + '.' : '') + prop);
1197
+ var key = get__default["default"](item, path);
1199
1198
  // if object does not have property for grouping it will be grouped as 'other'
1200
1199
  if (key === undefined) {
1201
1200
  key = 'other';
@@ -1213,6 +1212,52 @@
1213
1212
  return CollectionDictionary;
1214
1213
  }());
1215
1214
 
1215
+ // replace array element with the new one (only arrays of objects)
1216
+ function replace(array, item, matchField) {
1217
+ if (matchField === void 0) { matchField = 'id'; }
1218
+ var index = array.findIndex(function (i) { return i[matchField] === item[matchField]; });
1219
+ array.splice(index, 1, item);
1220
+ }
1221
+
1222
+ // sort array of objects by field
1223
+ function sort(array, field, isDesc) {
1224
+ if (field === void 0) { field = 'id'; }
1225
+ if (isDesc === void 0) { isDesc = true; }
1226
+ array.sort(function (a, b) {
1227
+ if (a[field] > b[field]) {
1228
+ return !isDesc ? 1 : -1;
1229
+ }
1230
+ if (a[field] < b[field]) {
1231
+ return !isDesc ? -1 : 1;
1232
+ }
1233
+ return 0;
1234
+ });
1235
+ }
1236
+
1237
+ // sort array of objects by field
1238
+ function sortDeep(array, fieldsQueue, isDesc) {
1239
+ if (fieldsQueue === void 0) { fieldsQueue = ['id']; }
1240
+ if (isDesc === void 0) { isDesc = true; }
1241
+ array.sort(function (a, b) {
1242
+ var aValue = getValue(a, fieldsQueue);
1243
+ var bValue = getValue(b, fieldsQueue);
1244
+ if (aValue > bValue) {
1245
+ return !isDesc ? 1 : -1;
1246
+ }
1247
+ if (aValue < bValue) {
1248
+ return !isDesc ? -1 : 1;
1249
+ }
1250
+ return 0;
1251
+ });
1252
+ }
1253
+ function getValue(obj, fields) {
1254
+ var value = obj;
1255
+ fields.forEach(function (field) {
1256
+ value = value[field];
1257
+ });
1258
+ return value;
1259
+ }
1260
+
1216
1261
  var DEFAULT_INDEX = 'other';
1217
1262
  /**
1218
1263
  * Base collection class. Contains common properties and methods for all collections
@@ -1291,6 +1336,14 @@
1291
1336
  Collection.prototype.filter = function (callback) {
1292
1337
  return new Collection(this.items.filter(callback));
1293
1338
  };
1339
+ /**
1340
+ * Sort collection items by provided field
1341
+ */
1342
+ Collection.prototype.sortBy = function (filed, isDesc) {
1343
+ if (filed === void 0) { filed = 'id'; }
1344
+ if (isDesc === void 0) { isDesc = true; }
1345
+ sort(this.items, filed, isDesc);
1346
+ };
1294
1347
  Object.defineProperty(Collection.prototype, "first", {
1295
1348
  get: function () {
1296
1349
  return first__default["default"](this.items);
@@ -4907,8 +4960,9 @@
4907
4960
  /**
4908
4961
  * Create a new transaction from current depreciation
4909
4962
  */
4910
- Depreciation.prototype.toTransaction = function () {
4911
- return classTransformer.plainToClass(Transaction, Object.assign({}, this, { amount: this.currentYearForecast.amount }));
4963
+ Depreciation.prototype.toTransaction = function (params) {
4964
+ if (params === void 0) { params = {}; }
4965
+ return classTransformer.plainToClass(Transaction, Object.assign(params, this, { amount: this.currentYearForecast.amount }));
4912
4966
  };
4913
4967
  Object.defineProperty(Depreciation.prototype, "claimAmount", {
4914
4968
  get: function () {
@@ -5059,6 +5113,139 @@
5059
5113
  return DepreciationReportItemCollection;
5060
5114
  }(DepreciationCollection));
5061
5115
 
5116
+ /**
5117
+ * Base collection to work with property report items
5118
+ */
5119
+ var PropertyReportItemCollection = /** @class */ (function (_super) {
5120
+ __extends(PropertyReportItemCollection, _super);
5121
+ function PropertyReportItemCollection() {
5122
+ return _super !== null && _super.apply(this, arguments) || this;
5123
+ }
5124
+ PropertyReportItemCollection.prototype.getIncomes = function () {
5125
+ return this.create(this.items.filter(function (item) { return item.isIncome(); }));
5126
+ };
5127
+ PropertyReportItemCollection.prototype.getExpenses = function () {
5128
+ return this.create(this.items.filter(function (item) { return item.isExpense(); }));
5129
+ };
5130
+ return PropertyReportItemCollection;
5131
+ }(Collection));
5132
+
5133
+ /**
5134
+ * Class with property transactions report entities
5135
+ */
5136
+ var PropertyReportItem = /** @class */ (function () {
5137
+ function PropertyReportItem(property, chartAccounts) {
5138
+ this.chartAccounts = chartAccounts;
5139
+ this.propertyId = property.id;
5140
+ this.claimPercent = property.claimPercent;
5141
+ this.sharePercent = property.sharePercent;
5142
+ this.subCode = chartAccounts.taxReturnItem.subCode;
5143
+ this.description = chartAccounts.name;
5144
+ }
5145
+ Object.defineProperty(PropertyReportItem.prototype, "claimAmount", {
5146
+ get: function () {
5147
+ return +(this.amount * (this.claimPercent / 100)).toFixed(2);
5148
+ },
5149
+ enumerable: false,
5150
+ configurable: true
5151
+ });
5152
+ Object.defineProperty(PropertyReportItem.prototype, "shareClaimAmount", {
5153
+ get: function () {
5154
+ return this.claimAmount * (this.sharePercent / 100);
5155
+ },
5156
+ enumerable: false,
5157
+ configurable: true
5158
+ });
5159
+ PropertyReportItem.prototype.isIncome = function () {
5160
+ return CHART_ACCOUNTS_CATEGORIES.income.includes(this.chartAccounts.category);
5161
+ };
5162
+ PropertyReportItem.prototype.isExpense = function () {
5163
+ return CHART_ACCOUNTS_CATEGORIES.expense.includes(this.chartAccounts.category);
5164
+ };
5165
+ return PropertyReportItem;
5166
+ }());
5167
+
5168
+ /**
5169
+ * Class with transaction-based property transactions report entities
5170
+ */
5171
+ var PropertyReportItemTransaction = /** @class */ (function (_super) {
5172
+ __extends(PropertyReportItemTransaction, _super);
5173
+ function PropertyReportItemTransaction(transactions, property, chartAccounts) {
5174
+ var _this = _super.call(this, property, chartAccounts) || this;
5175
+ _this.amount = Math.abs(transactions.amount);
5176
+ _this.description = chartAccounts.name;
5177
+ return _this;
5178
+ }
5179
+ return PropertyReportItemTransaction;
5180
+ }(PropertyReportItem));
5181
+
5182
+ /**
5183
+ * Collection to work with transaction-based property report items
5184
+ */
5185
+ var PropertyReportItemTransactionCollection = /** @class */ (function (_super) {
5186
+ __extends(PropertyReportItemTransactionCollection, _super);
5187
+ function PropertyReportItemTransactionCollection(transactions, properties, chartAccounts) {
5188
+ var _this = _super.call(this) || this;
5189
+ _this.setItems(transactions, properties, chartAccounts);
5190
+ return _this;
5191
+ }
5192
+ PropertyReportItemTransactionCollection.prototype.setItems = function (transactions, properties, chartAccounts) {
5193
+ var _this = this;
5194
+ this.items = [];
5195
+ properties.items.forEach(function (property) {
5196
+ var transactionsDictionary = new CollectionDictionary(transactions.getByPropertiesIds([property.id]), 'chartAccounts.id');
5197
+ transactionsDictionary.keys.map(function (chartAccountId) {
5198
+ _this.items.push(new PropertyReportItemTransaction(transactionsDictionary.get(chartAccountId), property, chartAccounts.getById(+chartAccountId)));
5199
+ });
5200
+ });
5201
+ };
5202
+ return PropertyReportItemTransactionCollection;
5203
+ }(PropertyReportItemCollection));
5204
+
5205
+ /**
5206
+ * Const with labels based on depreciation type
5207
+ */
5208
+ var DEPRECIATION_TYPE_LABELS = {
5209
+ 1: 'Plant & Equipment',
5210
+ 2: 'Building & Improvements'
5211
+ };
5212
+ /**
5213
+ * Class with depreciation-based property transactions report entities
5214
+ */
5215
+ var PropertyReportItemDepreciation = /** @class */ (function (_super) {
5216
+ __extends(PropertyReportItemDepreciation, _super);
5217
+ function PropertyReportItemDepreciation(depreciations, property, chartAccounts) {
5218
+ var _this = _super.call(this, property, chartAccounts) || this;
5219
+ _this.amount = Math.abs(depreciations.getCurrentYearForecastAmount());
5220
+ _this.description = DEPRECIATION_TYPE_LABELS[depreciations.first.type];
5221
+ return _this;
5222
+ }
5223
+ return PropertyReportItemDepreciation;
5224
+ }(PropertyReportItem));
5225
+
5226
+ /**
5227
+ * Collection to work with depreciation-based property report items
5228
+ */
5229
+ var PropertyReportItemDepreciationCollection = /** @class */ (function (_super) {
5230
+ __extends(PropertyReportItemDepreciationCollection, _super);
5231
+ function PropertyReportItemDepreciationCollection(depreciations, properties, chartAccounts) {
5232
+ var _this = _super.call(this) || this;
5233
+ _this.setItems(depreciations, properties, chartAccounts);
5234
+ return _this;
5235
+ }
5236
+ PropertyReportItemDepreciationCollection.prototype.setItems = function (depreciations, properties, chartAccounts) {
5237
+ var _this = this;
5238
+ this.items = [];
5239
+ properties.items.forEach(function (property) {
5240
+ var depreciationsByType = new CollectionDictionary(depreciations, 'type');
5241
+ depreciationsByType.keys.map(function (type) {
5242
+ _this.items.push(new PropertyReportItemDepreciation(depreciationsByType.get(type), property, chartAccounts.getById(depreciationsByType.get(type).first.chartAccounts.id)));
5243
+ });
5244
+ });
5245
+ };
5246
+ return PropertyReportItemDepreciationCollection;
5247
+ }(PropertyReportItemCollection));
5248
+
5062
5249
  var ServicePriceCollection = /** @class */ (function (_super) {
5063
5250
  __extends(ServicePriceCollection, _super);
5064
5251
  function ServicePriceCollection() {
@@ -8264,52 +8451,6 @@
8264
8451
  }] }];
8265
8452
  } });
8266
8453
 
8267
- // replace array element with the new one (only arrays of objects)
8268
- function replace(array, item, matchField) {
8269
- if (matchField === void 0) { matchField = 'id'; }
8270
- var index = array.findIndex(function (i) { return i[matchField] === item[matchField]; });
8271
- array.splice(index, 1, item);
8272
- }
8273
-
8274
- // sort array of objects by field
8275
- function sort(array, field, isDesc) {
8276
- if (field === void 0) { field = 'id'; }
8277
- if (isDesc === void 0) { isDesc = true; }
8278
- array.sort(function (a, b) {
8279
- if (a[field] > b[field]) {
8280
- return !isDesc ? 1 : -1;
8281
- }
8282
- if (a[field] < b[field]) {
8283
- return !isDesc ? -1 : 1;
8284
- }
8285
- return 0;
8286
- });
8287
- }
8288
-
8289
- // sort array of objects by field
8290
- function sortDeep(array, fieldsQueue, isDesc) {
8291
- if (fieldsQueue === void 0) { fieldsQueue = ['id']; }
8292
- if (isDesc === void 0) { isDesc = true; }
8293
- array.sort(function (a, b) {
8294
- var aValue = getValue(a, fieldsQueue);
8295
- var bValue = getValue(b, fieldsQueue);
8296
- if (aValue > bValue) {
8297
- return !isDesc ? 1 : -1;
8298
- }
8299
- if (aValue < bValue) {
8300
- return !isDesc ? -1 : 1;
8301
- }
8302
- return 0;
8303
- });
8304
- }
8305
- function getValue(obj, fields) {
8306
- var value = obj;
8307
- fields.forEach(function (field) {
8308
- value = value[field];
8309
- });
8310
- return value;
8311
- }
8312
-
8313
8454
  var EventDispatcherService = /** @class */ (function () {
8314
8455
  function EventDispatcherService() {
8315
8456
  this.eventSubject = new rxjs.Subject();
@@ -11048,152 +11189,72 @@
11048
11189
  }] }];
11049
11190
  } });
11050
11191
 
11192
+ function enumToList(data) {
11193
+ var list = [];
11194
+ for (var key in data) {
11195
+ if (Number(key) >= 0) {
11196
+ list.push({
11197
+ label: data[key],
11198
+ value: Number(key)
11199
+ });
11200
+ }
11201
+ }
11202
+ return list;
11203
+ }
11204
+
11205
+ var MessagesEnum;
11206
+ (function (MessagesEnum) {
11207
+ MessagesEnum["DELETED_MESSAGE"] = "Transaction deleted";
11208
+ MessagesEnum["UPDATED_MESSAGE"] = "Transaction updated";
11209
+ MessagesEnum["CREATED_MESSAGE"] = "Transaction(s) created";
11210
+ })(MessagesEnum || (MessagesEnum = {}));
11211
+
11051
11212
  /**
11052
- * Service with calculations methods for properties related with other entities.
11053
- * Logic here works like collections methods but for several entities
11213
+ * popup notifications service (toast, snackbar).
11054
11214
  */
11055
- var PropertyCalculationService = /** @class */ (function () {
11056
- function PropertyCalculationService() {
11215
+ var ToastService = /** @class */ (function () {
11216
+ function ToastService() {
11217
+ this.toast$ = new rxjs.ReplaySubject(1);
11057
11218
  }
11058
- PropertyCalculationService.prototype.getTaxPosition = function (transactions, depreciations) {
11059
- // @TODO hack: math abs added because we have mismatching of real values signs
11060
- return transactions.cashPosition - Math.abs(depreciations.claimAmount);
11061
- };
11062
- PropertyCalculationService.prototype.getTaxPosition$ = function (transactions$, depreciations$) {
11063
- var _this = this;
11064
- return rxjs.combineLatest([
11065
- transactions$,
11066
- depreciations$
11067
- ]).pipe(operators.map(function (_b) {
11068
- var _c = __read(_b, 2), transactions = _c[0], depreciations = _c[1];
11069
- return _this.getTaxPosition(transactions, depreciations);
11070
- }));
11219
+ ToastService.prototype.get = function () {
11220
+ return this.toast$.asObservable();
11071
11221
  };
11072
- PropertyCalculationService.prototype.taxPositionGrowth = function (properties, transactions, depreciations) {
11073
- var taxPosition = this.getTaxPosition(transactions, depreciations);
11074
- // check if taxPosition = 0 to avoid division by zero
11075
- if (!taxPosition) {
11076
- return 0;
11077
- }
11078
- return (taxPosition - properties.forecastedTaxPosition) / taxPosition;
11222
+ ToastService.prototype.add = function (toast) {
11223
+ this.toast$.next(toast);
11079
11224
  };
11080
- PropertyCalculationService.prototype.taxPositionGrowth$ = function (properties$, transactions$, depreciations$) {
11081
- var _this = this;
11082
- return rxjs.combineLatest([
11083
- properties$,
11084
- transactions$,
11085
- depreciations$
11086
- ]).pipe(operators.map(function (_b) {
11087
- var _c = __read(_b, 3), properties = _c[0], transactions = _c[1], depreciations = _c[2];
11088
- return _this.taxPositionGrowth(properties, transactions, depreciations);
11225
+ ToastService.prototype.success = function (message) {
11226
+ this.add(classTransformer.plainToClass(Toast, {
11227
+ type: exports.ToastTypeEnum.SUCCESS,
11228
+ title: 'Success!',
11229
+ message: message,
11089
11230
  }));
11090
11231
  };
11091
- PropertyCalculationService.prototype.getRentalReturn = function (properties, transactions) {
11092
- return transactions.claimIncome / properties.marketValue;
11232
+ ToastService.prototype.warning = function (message) {
11233
+ this.add(classTransformer.plainToClass(Toast, {
11234
+ type: exports.ToastTypeEnum.WARNING,
11235
+ title: 'Warning!',
11236
+ message: message,
11237
+ }));
11093
11238
  };
11094
- PropertyCalculationService.prototype.getLoanAmount = function (properties, bankAccounts, loans) {
11095
- return properties.items.reduce(function (totalAmount, property) {
11096
- return totalAmount + bankAccounts.items
11097
- .reduce(function (propertyAmount, bankAccount) {
11098
- var _a;
11099
- return propertyAmount + bankAccount.getPropertyPercentage(property.id) * (((_a = loans.getByBankAccountId(bankAccount.id)) === null || _a === void 0 ? void 0 : _a.amount) || 0);
11100
- }, 0);
11101
- }, 0);
11239
+ ToastService.prototype.error = function (message) {
11240
+ this.add(classTransformer.plainToClass(Toast, {
11241
+ type: exports.ToastTypeEnum.ERROR,
11242
+ title: 'Error!',
11243
+ message: message,
11244
+ }));
11102
11245
  };
11103
- PropertyCalculationService.prototype.getLoanValue = function (properties, bankAccounts) {
11104
- return properties.items.reduce(function (totalAmount, property) {
11105
- return totalAmount + bankAccounts.items
11106
- .reduce(function (propertyAmount, bankAccount) {
11107
- return propertyAmount + bankAccount.getPropertyBalanceAmount(property.id);
11108
- }, 0);
11109
- }, 0);
11246
+ ToastService.prototype.info = function (message) {
11247
+ this.add(classTransformer.plainToClass(Toast, {
11248
+ type: exports.ToastTypeEnum.INFO,
11249
+ title: 'Information',
11250
+ message: message,
11251
+ }));
11110
11252
  };
11111
- /**
11112
- * LVR
11113
- */
11114
- PropertyCalculationService.prototype.getLvr = function (properties, bankAccounts) {
11115
- // Math abs is required for correct percentage calculation
11116
- return Math.abs(this.getLoanValue(properties, bankAccounts)) / properties.marketValue;
11117
- };
11118
- PropertyCalculationService.prototype.getLvr$ = function (properties$, bankAccounts$) {
11119
- var _this = this;
11120
- return rxjs.combineLatest([
11121
- properties$,
11122
- bankAccounts$
11123
- ]).pipe(operators.map(function (_b) {
11124
- var _c = __read(_b, 2), properties = _c[0], bankAccounts = _c[1];
11125
- return _this.getLvr(properties, bankAccounts);
11126
- }));
11127
- };
11128
- PropertyCalculationService.prototype.getLvrCommencement = function (properties, loans, bankAccounts) {
11129
- // Math abs is required for correct percentage calculation
11130
- return Math.abs(this.getLoanAmount(properties, bankAccounts, loans)) / properties.purchasePrice;
11131
- };
11132
- PropertyCalculationService.prototype.getLvrCommencement$ = function (properties$, bankAccounts$, loans$) {
11133
- var _this = this;
11134
- return rxjs.combineLatest([
11135
- properties$,
11136
- bankAccounts$,
11137
- loans$
11138
- ]).pipe(operators.map(function (_b) {
11139
- var _c = __read(_b, 3), properties = _c[0], bankAccounts = _c[1], loans = _c[2];
11140
- return _this.getLvrCommencement(properties, loans, bankAccounts);
11141
- }));
11142
- };
11143
- PropertyCalculationService.prototype.getLvrGrowth = function (properties, bankAccounts, loans) {
11144
- var lvr = this.getLvr(properties, bankAccounts);
11145
- if (!lvr) {
11146
- // check if lvr = 0 to avoid division by zero
11147
- return 0;
11148
- }
11149
- return (lvr - this.getLvrCommencement(properties, loans, bankAccounts)) / lvr;
11150
- };
11151
- PropertyCalculationService.prototype.getLvrGrowth$ = function (properties$, bankAccounts$, loans$) {
11152
- var _this = this;
11153
- return rxjs.combineLatest([
11154
- properties$,
11155
- bankAccounts$,
11156
- loans$
11157
- ]).pipe(operators.map(function (_b) {
11158
- var _c = __read(_b, 3), properties = _c[0], bankAccounts = _c[1], loans = _c[2];
11159
- return _this.getLvrGrowth(properties, bankAccounts, loans);
11160
- }));
11161
- };
11162
- PropertyCalculationService.prototype.getEquityPosition = function (properties, bankAccounts) {
11163
- // Math abs is required for correct percentage calculation
11164
- return properties.marketValue - Math.abs(this.getLoanValue(properties, bankAccounts));
11165
- };
11166
- PropertyCalculationService.prototype.getPurchaseEquity = function (properties, bankAccounts, loans) {
11167
- // Math abs is required for correct percentage calculation
11168
- return properties.purchasePrice - Math.abs(this.getLoanAmount(properties, bankAccounts, loans));
11169
- };
11170
- return PropertyCalculationService;
11253
+ return ToastService;
11171
11254
  }());
11172
- PropertyCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCalculationService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11173
- PropertyCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCalculationService, providedIn: 'root' });
11174
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCalculationService, decorators: [{
11175
- type: i0.Injectable,
11176
- args: [{
11177
- providedIn: 'root'
11178
- }]
11179
- }] });
11180
-
11181
- /**
11182
- * Service for work with Property Categories
11183
- */
11184
- var PropertyCategoryService = /** @class */ (function (_super) {
11185
- __extends(PropertyCategoryService, _super);
11186
- function PropertyCategoryService() {
11187
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11188
- _this.modelClass = PropertyCategory;
11189
- _this.url = 'properties/categories';
11190
- return _this;
11191
- }
11192
- return PropertyCategoryService;
11193
- }(RestService));
11194
- PropertyCategoryService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
11195
- PropertyCategoryService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryService, providedIn: 'root' });
11196
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryService, decorators: [{
11255
+ ToastService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ToastService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11256
+ ToastService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ToastService, providedIn: 'root' });
11257
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ToastService, decorators: [{
11197
11258
  type: i0.Injectable,
11198
11259
  args: [{
11199
11260
  providedIn: 'root'
@@ -11201,174 +11262,320 @@
11201
11262
  }] });
11202
11263
 
11203
11264
  /**
11204
- * Class for work with Property Documents
11265
+ * Service for transactions business logic
11205
11266
  */
11206
- var PropertyDocumentService = /** @class */ (function (_super) {
11207
- __extends(PropertyDocumentService, _super);
11208
- function PropertyDocumentService(http, eventDispatcherService, environment) {
11267
+ var TransactionService = /** @class */ (function (_super) {
11268
+ __extends(TransactionService, _super);
11269
+ function TransactionService(http, eventDispatcherService, environment, toastService) {
11209
11270
  var _this = _super.call(this, http, eventDispatcherService, environment) || this;
11210
11271
  _this.http = http;
11211
11272
  _this.eventDispatcherService = eventDispatcherService;
11212
11273
  _this.environment = environment;
11213
- _this.modelClass = PropertyDocument;
11214
- _this.url = 'properties/documents';
11274
+ _this.toastService = toastService;
11275
+ // url part for Transaction API
11276
+ _this.url = 'transactions';
11277
+ _this.modelClass = Transaction;
11278
+ _this.transactionDeleted = new i0.EventEmitter();
11215
11279
  _this.listenEvents();
11216
11280
  return _this;
11217
11281
  }
11218
11282
  /**
11219
- * Add new Property Document
11283
+ * Listen events from Event Dispatcher services
11220
11284
  */
11221
- PropertyDocumentService.prototype.upload = function (file, propertyId) {
11222
- var _this = this;
11223
- // create formData object with provided file
11224
- var formDataDocument = new FormData();
11225
- formDataDocument.append('file', file);
11226
- return this.http.post(this.environment.apiV2 + "/properties/" + propertyId + "/documents", formDataDocument).pipe(operators.map(function (documentBase) {
11227
- var newDocument = classTransformer.plainToClass(PropertyDocument, documentBase);
11228
- if (_this.cache) {
11229
- _this.cache.push(newDocument);
11230
- _this.updateCache();
11231
- }
11232
- return newDocument;
11233
- }));
11285
+ TransactionService.prototype.listenEvents = function () {
11286
+ this.listenDepreciationChange();
11287
+ this.listenPropertyShareUpdate();
11234
11288
  };
11235
11289
  /**
11236
- * Get documents by property id
11237
- * @param propertyId to get desired documents
11290
+ * get list of all user's TaxTank transactions
11238
11291
  */
11239
- PropertyDocumentService.prototype.getByPropertyId = function (propertyId) {
11240
- return this.get()
11241
- .pipe(operators.map(function (documents) {
11242
- return documents
11243
- .filter(function (document) { return document.property.id === propertyId; });
11244
- }));
11245
- };
11246
- PropertyDocumentService.prototype.listenEvents = function () {
11247
- this.listenPropertyUpdateWithDocument();
11248
- };
11249
- PropertyDocumentService.prototype.listenPropertyUpdateWithDocument = function () {
11292
+ TransactionService.prototype.get = function () {
11250
11293
  var _this = this;
11251
- this.eventDispatcherService.on(exports.AppEventTypeEnum.PROPERTY_UPDATED_WITH_DOCUMENT).subscribe(function (property) {
11252
- _this.upload(property.documentFile, property.id).subscribe();
11253
- });
11254
- };
11255
- return PropertyDocumentService;
11256
- }(RestService));
11257
- PropertyDocumentService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyDocumentService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11258
- PropertyDocumentService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyDocumentService, providedIn: 'root' });
11259
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyDocumentService, decorators: [{
11260
- type: i0.Injectable,
11261
- args: [{
11262
- providedIn: 'root'
11263
- }]
11264
- }], ctorParameters: function () {
11265
- return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
11266
- type: i0.Inject,
11267
- args: ['environment']
11268
- }] }];
11269
- } });
11270
-
11271
- // @TODO check and improve logic during refactoring
11272
- var PropertyShareService = /** @class */ (function (_super) {
11273
- __extends(PropertyShareService, _super);
11274
- function PropertyShareService(http, eventDispatcherService, environment) {
11275
- var _this = _super.call(this, http, eventDispatcherService, environment) || this;
11276
- _this.http = http;
11277
- _this.eventDispatcherService = eventDispatcherService;
11278
- _this.environment = environment;
11279
- // api url parameter for properties shares
11280
- _this.url = 'properties/shares';
11281
- _this.modelClass = PropertyShare;
11282
- _this.listenEvents();
11283
- return _this;
11284
- }
11285
- /**
11286
- * Listen to Event Dispatcher events
11287
- */
11288
- PropertyShareService.prototype.listenEvents = function () {
11289
- this.listenUserUpdated();
11294
+ if (!this.cache) {
11295
+ // set cache as default empty array to avoid multiple backend requests
11296
+ this.cache = [];
11297
+ this.fetch()
11298
+ .subscribe(function (transactions) {
11299
+ _this.cache = transactions;
11300
+ _this.updateCache();
11301
+ });
11302
+ }
11303
+ return this.cacheSubject.asObservable().pipe(
11304
+ // assign child transactions (fees) to parent transactions
11305
+ operators.map(function (transactions) {
11306
+ transactions.forEach(function (transaction) {
11307
+ transaction.transactions = transactions
11308
+ // get list of child transactions
11309
+ .filter(function (t) { return t.parentTransaction && t.parentTransaction.id === transaction.id; });
11310
+ });
11311
+ sort(transactions, 'date', false);
11312
+ return transactions;
11313
+ }));
11290
11314
  };
11291
11315
  /**
11292
- * Updated loan
11316
+ * Add single new transaction
11317
+ * @param model New Transaction instance for saving
11293
11318
  */
11294
- PropertyShareService.prototype.update = function (propertyShare) {
11319
+ TransactionService.prototype.add = function (model) {
11295
11320
  var _this = this;
11296
- return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + propertyShare.id, propertyShare)
11297
- .pipe(operators.map(function (updatedPropertyShareBase) {
11298
- var updatedPropertyShare = classTransformer.plainToClass(PropertyShare, updatedPropertyShareBase);
11299
- // if loan type is NOT vehicle - fire EventDispatcher event
11300
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_SHARE_UPDATED, null));
11301
- replace(_this.cache, updatedPropertyShare);
11302
- _this.updateCache();
11303
- return updatedPropertyShare;
11321
+ // we don't have POST API endpoint for single transaction
11322
+ return this.addBatch([model])
11323
+ .pipe(operators.map(function (newTransactions) {
11324
+ // @TODO alex
11325
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_CREATED, newTransactions[0]));
11326
+ return newTransactions[0];
11304
11327
  }));
11305
11328
  };
11306
11329
  /**
11307
- * Re-invite property share
11308
- * @param share user to share property
11330
+ * get transactions related with property
11309
11331
  */
11310
- PropertyShareService.prototype.reinvite = function (share) {
11311
- return this.http.post(this.environment.apiV2 + "/" + this.url + "/" + share.id + "/reinvite", {});
11312
- };
11313
- PropertyShareService.prototype.getIncoming = function () {
11332
+ TransactionService.prototype.getByPropertyId = function (propertyId) {
11314
11333
  return this.get()
11315
- .pipe(operators.map(function (propertyShares) {
11316
- var propertySharesIncoming = [];
11317
- propertyShares.forEach(function (propertyShare) {
11334
+ .pipe(operators.map(function (transactions) {
11335
+ return transactions.filter(function (transaction) {
11318
11336
  var _a;
11319
- if (((_a = propertyShare.user) === null || _a === void 0 ? void 0 : _a.isLoggedIn()) && propertyShare.isPending() && propertyShare.property.user.id !== +localStorage.getItem('userId')) {
11320
- propertySharesIncoming.push(propertyShare);
11321
- }
11337
+ return ((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id) === propertyId;
11322
11338
  });
11323
- return propertySharesIncoming;
11324
11339
  }));
11325
11340
  };
11326
11341
  /**
11327
- * Get outcoming property shares list
11342
+ * get list of transactions with tank type 'Work'
11328
11343
  */
11329
- PropertyShareService.prototype.getOutcoming = function () {
11330
- var _this = this;
11331
- return this.get().pipe(operators.map(function (propertyShares) {
11332
- return _this.filterOutcoming(propertyShares);
11344
+ TransactionService.prototype.getWorkTransactions = function () {
11345
+ return this.get()
11346
+ .pipe(operators.map(function (transactions) {
11347
+ return transactions.filter(function (transaction) { return transaction.isWorkTank(); });
11333
11348
  }));
11334
11349
  };
11335
11350
  /**
11336
- * Filter outcoming property shares
11351
+ * get list of taxable transactions with tank type 'Work'
11337
11352
  */
11338
- PropertyShareService.prototype.filterOutcoming = function (propertyShares) {
11339
- var propertySharesOutcoming = [];
11340
- propertyShares.forEach(function (propertyShare) {
11341
- var _a;
11342
- if (!((_a = propertyShare.user) === null || _a === void 0 ? void 0 : _a.isLoggedIn())) {
11343
- propertySharesOutcoming.push(propertyShare);
11344
- }
11345
- });
11346
- return propertySharesOutcoming;
11347
- };
11348
- PropertyShareService.prototype.getByPropertyId = function (propertyId) {
11349
- return this.get()
11350
- .pipe(operators.map(function (propertyShares) {
11351
- return propertyShares.filter(function (propertyShare) { return propertyShare.property.id === propertyId; });
11353
+ TransactionService.prototype.getTaxableWorkTransactions = function () {
11354
+ return this.getWorkTransactions()
11355
+ .pipe(operators.map(function (transactions) {
11356
+ return transactions.filter(function (transaction) { return !!transaction.chartAccounts.taxReturnItem; });
11352
11357
  }));
11353
11358
  };
11354
11359
  /**
11355
- * Listen to User updated event
11360
+ * add multiple transactions
11361
+ * @param transactions List of new Transaction instances for saving
11356
11362
  */
11357
- PropertyShareService.prototype.listenUserUpdated = function () {
11363
+ TransactionService.prototype.addBatch = function (transactions) {
11358
11364
  var _this = this;
11359
- this.eventDispatcherService.on(exports.AppEventTypeEnum.USER_UPDATED)
11360
- .subscribe(function () {
11361
- _this.fetch().subscribe(function (propertyShares) {
11362
- _this.cache = propertyShares;
11365
+ transactions = ___default["default"].cloneDeep(transactions);
11366
+ return this.http.post(this.environment.apiV2 + "/" + this.url, transactions)
11367
+ .pipe(operators.map(function (response) {
11368
+ var _c;
11369
+ var addedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
11370
+ transactions.forEach(function (transaction, index) {
11371
+ // @TODO backend: need to upload file in the same backend endpoint with transaction add/update
11372
+ // check if passed receipt and upload file
11373
+ if (transaction.file) {
11374
+ transaction.id = response[index].id;
11375
+ addedTransactions[index].file = transaction.file;
11376
+ _this.uploadReceipt(addedTransactions[index]);
11377
+ }
11378
+ // @TODO Viktor: implement API for saving of nested transactions
11379
+ // add child transactions if exist
11380
+ if (transaction.transactions.length) {
11381
+ transaction.transactions.forEach(function (childTransaction) {
11382
+ childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: addedTransactions[index].id });
11383
+ });
11384
+ _this.addBatch(transaction.transactions).subscribe();
11385
+ }
11386
+ // add transfer transaction to cache
11387
+ if (transaction.operation === exports.TransactionOperationEnum.TRANSFER) {
11388
+ addedTransactions.push(addedTransactions[0].transfer);
11389
+ }
11390
+ });
11391
+ if (_this.cache) {
11392
+ (_c = _this.cache).push.apply(_c, __spreadArray([], __read(addedTransactions)));
11363
11393
  _this.updateCache();
11394
+ }
11395
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTIONS_CREATED, addedTransactions));
11396
+ _this.toastService.success(MessagesEnum.CREATED_MESSAGE);
11397
+ return addedTransactions;
11398
+ }));
11399
+ };
11400
+ /**
11401
+ * update existing transaction
11402
+ * @param transaction Transaction instance for updating
11403
+ */
11404
+ TransactionService.prototype.update = function (transaction) {
11405
+ var _this = this;
11406
+ return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + transaction.id, transaction)
11407
+ .pipe(operators.map(function (response) {
11408
+ var updatedTransaction = classTransformer.plainToClass(Transaction, response);
11409
+ // @TODO need to upload file in the same backend endpoint with transaction add/update
11410
+ // check if passed new receipt and upload file
11411
+ if (transaction.file) {
11412
+ updatedTransaction.file = transaction.file;
11413
+ _this.uploadReceipt(updatedTransaction);
11414
+ }
11415
+ // @TODO Viktor: implement API for saving of nested transactions
11416
+ if (transaction.transactions.length) {
11417
+ // add parent transaction to child transactions
11418
+ transaction.transactions.forEach(function (childTransaction) {
11419
+ childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: updatedTransaction.id });
11420
+ });
11421
+ // separate child transactions by id existing to define add or update action.
11422
+ var childTransactionsToUpdate = transaction.transactions.filter(function (t) { return t.id; });
11423
+ var childTransactionsToAdd = transaction.transactions.filter(function (t) { return !t.id; });
11424
+ // update child transactions
11425
+ if (childTransactionsToUpdate.length) {
11426
+ _this.updateBatch(childTransactionsToUpdate).subscribe();
11427
+ }
11428
+ // add child transactions
11429
+ if (childTransactionsToAdd.length) {
11430
+ _this.addBatch(childTransactionsToAdd).subscribe();
11431
+ }
11432
+ }
11433
+ _this.toastService.success(MessagesEnum.UPDATED_MESSAGE);
11434
+ replace(_this.cache, updatedTransaction);
11435
+ _this.updateCache();
11436
+ return updatedTransaction;
11437
+ }));
11438
+ };
11439
+ /**
11440
+ * update multiple transactions
11441
+ * @param transactions list of transactions for updating
11442
+ */
11443
+ TransactionService.prototype.updateBatch = function (transactions) {
11444
+ var _this = this;
11445
+ return this.http.put(this.environment.apiV2 + "/" + this.url, transactions)
11446
+ .pipe(operators.map(function (response) {
11447
+ var updatedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
11448
+ updatedTransactions.forEach(function (updatedTransaction) {
11449
+ replace(_this.cache, updatedTransaction);
11364
11450
  });
11451
+ _this.updateCache();
11452
+ return updatedTransactions;
11453
+ }));
11454
+ };
11455
+ /**
11456
+ * delete transaction and related transactions
11457
+ * @param model
11458
+ */
11459
+ TransactionService.prototype.delete = function (model) {
11460
+ var _this = this;
11461
+ return this.http.delete(this.environment.apiV2 + "/" + this.url + "/" + model.id)
11462
+ .pipe(operators.map(function () {
11463
+ _this.cache = _this.cache.filter(function (transaction) {
11464
+ var _a;
11465
+ // when delete transfer we delete actually 2 transactions
11466
+ if (model.isTransfer) {
11467
+ var ids = [model.id];
11468
+ // get id of related transfer transaction
11469
+ if (model.transfer) {
11470
+ // just take id if we delete source transaction
11471
+ ids.push(model.transfer.id);
11472
+ }
11473
+ else {
11474
+ // find source transaction id if we delete destination transaction
11475
+ ids.push(_this.cache.find(function (t) { return t.transfer.id === model.id; }).id);
11476
+ }
11477
+ return !ids.includes(transaction.id);
11478
+ }
11479
+ return transaction.id !== model.id && ((_a = transaction.parentTransaction) === null || _a === void 0 ? void 0 : _a.id) !== model.id;
11480
+ });
11481
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_DELETED, model));
11482
+ _this.toastService.success(MessagesEnum.DELETED_MESSAGE);
11483
+ _this.updateCache();
11484
+ _this.transactionDeleted.emit(model);
11485
+ }));
11486
+ };
11487
+ /**
11488
+ * upload transaction receipt image
11489
+ * @param transaction Еhe transaction for which the receipt will be imported
11490
+ */
11491
+ TransactionService.prototype.uploadReceipt = function (transaction) {
11492
+ var _this = this;
11493
+ var formData = new FormData();
11494
+ formData.append('file', transaction.file);
11495
+ transaction.receipt = null;
11496
+ this.http.post(this.environment.apiV2 + "/" + this.url + "/" + transaction.id + "/receipts", formData)
11497
+ .subscribe(function (receiptResponse) {
11498
+ // we don't need to keep file after save
11499
+ transaction.file = null;
11500
+ transaction.receipt = classTransformer.plainToClass(TransactionReceipt, receiptResponse);
11501
+ replace(_this.cache, transaction);
11502
+ _this.updateCache();
11365
11503
  });
11366
11504
  };
11367
- return PropertyShareService;
11505
+ /**
11506
+ * calculate gross income amount based on transaction amount and taxes (fees)
11507
+ * @param transaction Transaction instance for calculation
11508
+ */
11509
+ TransactionService.prototype.calculateGrossAmount = function (transaction) {
11510
+ var amount = transaction.amount || 0;
11511
+ // gross income amount includes amount of fees for property tank and tax for work tank
11512
+ if (transaction.isPropertyTank()) {
11513
+ amount += transaction.transactions.reduce(function (sum, item) { return sum + item.amount; }, 0);
11514
+ }
11515
+ else {
11516
+ // @TODO Alex: fix logic after TT-641 ready
11517
+ amount += (transaction.tax || 0);
11518
+ }
11519
+ return amount;
11520
+ };
11521
+ /**
11522
+ * get label for transaction tax field depended of selected chart account.
11523
+ * tax type depends of chart account heading or category.
11524
+ */
11525
+ TransactionService.prototype.getTaxLabel = function (chartAccounts) {
11526
+ var _a, _b;
11527
+ // get simple array of ids from enum with taxable chart accounts headings
11528
+ var taxableCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxableEnum)
11529
+ .map(function (item) { return item.value; });
11530
+ // get simple array of ids from enum with tax deductible chart accounts headings
11531
+ var deductibleCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxDeductibleEnum)
11532
+ .map(function (item) { return item.value; });
11533
+ // check if one of ids arrays includes current chart accounts heading id and set tax label
11534
+ // otherwise label is empty for this class
11535
+ switch (true) {
11536
+ case taxableCAHeadingsIds.includes((_a = chartAccounts.heading) === null || _a === void 0 ? void 0 : _a.id):
11537
+ return exports.ChartAccountsTaxLabelsEnum.TAX_PAID;
11538
+ case deductibleCAHeadingsIds.includes((_b = chartAccounts.heading) === null || _b === void 0 ? void 0 : _b.id):
11539
+ return exports.ChartAccountsTaxLabelsEnum.TAX_DEDUCTED;
11540
+ case CHART_ACCOUNTS_CATEGORIES.workIncome.includes(chartAccounts.category):
11541
+ return exports.ChartAccountsTaxLabelsEnum.TAX_WITHHELD;
11542
+ default:
11543
+ return null;
11544
+ }
11545
+ };
11546
+ /**
11547
+ * Get transactions related to Vehicle category
11548
+ */
11549
+ TransactionService.prototype.getVehicleTransactions = function () {
11550
+ return this.get().pipe(operators.map(function (transactions) {
11551
+ return transactions.filter(function (transaction) { return transaction.isVehicleTransaction(); });
11552
+ }));
11553
+ };
11554
+ /**
11555
+ * Listen to EventDispatcherService event related to Depreciation changing
11556
+ */
11557
+ TransactionService.prototype.listenDepreciationChange = function () {
11558
+ var _this = this;
11559
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.DEPRECIATION_DELETED).subscribe(function () {
11560
+ _this.fetch()
11561
+ .subscribe(function (transactions) {
11562
+ _this.cache = transactions;
11563
+ _this.updateCache();
11564
+ });
11565
+ });
11566
+ };
11567
+ /**
11568
+ * Listen to EventDispatcherService event related to Property Share changing
11569
+ */
11570
+ TransactionService.prototype.listenPropertyShareUpdate = function () {
11571
+ var _this = this;
11572
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.PROPERTY_SHARE_UPDATED).subscribe(function () { return _this.resetCache(); });
11573
+ };
11574
+ return TransactionService;
11368
11575
  }(RestService));
11369
- PropertyShareService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyShareService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11370
- PropertyShareService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyShareService, providedIn: 'root' });
11371
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyShareService, decorators: [{
11576
+ TransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }, { token: ToastService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11577
+ TransactionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, providedIn: 'root' });
11578
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, decorators: [{
11372
11579
  type: i0.Injectable,
11373
11580
  args: [{
11374
11581
  providedIn: 'root'
@@ -11377,358 +11584,389 @@
11377
11584
  return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
11378
11585
  type: i0.Inject,
11379
11586
  args: ['environment']
11380
- }] }];
11587
+ }] }, { type: ToastService }];
11381
11588
  } });
11382
11589
 
11383
- var PropertySaleService = /** @class */ (function (_super) {
11384
- __extends(PropertySaleService, _super);
11385
- function PropertySaleService() {
11386
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11387
- _this.modelClass = PropertySale;
11388
- _this.url = 'properties/sales';
11389
- return _this;
11390
- }
11391
- return PropertySaleService;
11392
- }(RestService));
11393
- PropertySaleService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertySaleService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
11394
- PropertySaleService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertySaleService, providedIn: 'root' });
11395
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertySaleService, decorators: [{
11396
- type: i0.Injectable,
11397
- args: [{
11398
- providedIn: 'root'
11399
- }]
11400
- }] });
11401
-
11402
11590
  /**
11403
- * Service for get property equity position half-year history chart data
11591
+ * Service to handle Property transactions report items data (get income / expense report items, e.t.c.)
11404
11592
  */
11405
- var EquityPositionChartService = /** @class */ (function () {
11406
- function EquityPositionChartService(http, environment) {
11407
- this.http = http;
11408
- this.environment = environment;
11409
- }
11410
- EquityPositionChartService.prototype.get = function () {
11411
- // @TODO refactor backend
11412
- return this.http.get(this.environment.apiV2 + "/properties/categories/equity")
11413
- .pipe(operators.map(function (response) {
11414
- return response.map(function (item) {
11415
- return classTransformer.plainToClass(ChartData, {
11416
- name: item.category.name,
11417
- data: item.equity.map(function (serie) {
11418
- return classTransformer.plainToClass(ChartSerie, {
11419
- label: serie.date,
11420
- value: serie.amount
11421
- });
11422
- })
11423
- });
11424
- });
11425
- }));
11426
- };
11427
- return EquityPositionChartService;
11428
- }());
11429
- EquityPositionChartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: EquityPositionChartService, deps: [{ token: i1__namespace.HttpClient }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11430
- EquityPositionChartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: EquityPositionChartService, providedIn: 'root' });
11431
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: EquityPositionChartService, decorators: [{
11432
- type: i0.Injectable,
11433
- args: [{
11434
- providedIn: 'root'
11435
- }]
11436
- }], ctorParameters: function () {
11437
- return [{ type: i1__namespace.HttpClient }, { type: undefined, decorators: [{
11438
- type: i0.Inject,
11439
- args: ['environment']
11440
- }] }];
11441
- } });
11442
-
11443
- var PropertyCategoryMovementService = /** @class */ (function (_super) {
11444
- __extends(PropertyCategoryMovementService, _super);
11445
- function PropertyCategoryMovementService() {
11446
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11447
- _this.modelClass = PropertyCategoryMovement;
11448
- _this.url = 'properties/category-movements';
11449
- return _this;
11593
+ var PropertyTransactionReportService = /** @class */ (function () {
11594
+ function PropertyTransactionReportService(propertyService, transactionService, depreciationService, chartAccountsService) {
11595
+ this.propertyService = propertyService;
11596
+ this.transactionService = transactionService;
11597
+ this.depreciationService = depreciationService;
11598
+ this.chartAccountsService = chartAccountsService;
11450
11599
  }
11451
- PropertyCategoryMovementService.prototype.add = function (model) {
11600
+ /**
11601
+ * Get collection of report items based on transactions & depreciations
11602
+ */
11603
+ PropertyTransactionReportService.prototype.get = function () {
11452
11604
  var _this = this;
11453
- return _super.prototype.add.call(this, model).pipe(operators.map(function (newMovement) {
11454
- // @TODO Alex: we need to teach restService to dispatch events + limit list of methods (not all services have all 4 or even more considering batch requests) + collections
11455
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_MOVEMENT_CREATED, null));
11456
- return newMovement;
11605
+ return rxjs.combineLatest([
11606
+ this.propertyService.get(),
11607
+ this.getTransactions(),
11608
+ this.getDepreciations(),
11609
+ this.chartAccountsService.getChartAccounts()
11610
+ ]).pipe(operators.map(function (_a) {
11611
+ var _b = __read(_a, 4), properties = _b[0], transactions = _b[1], depreciations = _b[2], chartAccounts = _b[3];
11612
+ return new CollectionDictionary(_this.create(transactions, depreciations, new PropertyCollection(properties), new Collection(chartAccounts)), 'propertyId');
11457
11613
  }));
11458
11614
  };
11459
- PropertyCategoryMovementService.prototype.update = function (model) {
11460
- var _this = this;
11461
- return _super.prototype.update.call(this, model).pipe(operators.map(function (updatedMovement) {
11462
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_MOVEMENT_CREATED, null));
11463
- return updatedMovement;
11464
- }));
11615
+ PropertyTransactionReportService.prototype.create = function (transactions, depreciations, properties, chartAccounts) {
11616
+ return new PropertyReportItemCollection(__spreadArray(__spreadArray([], __read(new PropertyReportItemTransactionCollection(transactions, properties, chartAccounts).items)), __read(new PropertyReportItemDepreciationCollection(depreciations, properties, chartAccounts).items)));
11465
11617
  };
11466
- PropertyCategoryMovementService.prototype.delete = function (model) {
11467
- var _this = this;
11468
- return _super.prototype.delete.call(this, model).pipe(operators.map(function () {
11469
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_MOVEMENT_CREATED, null));
11618
+ /**
11619
+ * Get collection of property transactions
11620
+ */
11621
+ PropertyTransactionReportService.prototype.getTransactions = function () {
11622
+ return this.transactionService.get().pipe(operators.map(function (transactions) {
11623
+ return new TransactionCollection(transactions)
11624
+ .getByChartAccountsCategories(CHART_ACCOUNTS_CATEGORIES.property);
11470
11625
  }));
11471
11626
  };
11472
- // @TODO Alex: Move to collection
11473
- PropertyCategoryMovementService.prototype.getByPropertyId = function (id) {
11474
- return this.get().pipe(operators.map(function (movements) {
11475
- return movements.filter(function (movement) { return movement.property.id === id; });
11627
+ /**
11628
+ * Get list of asset & capital property depreciations
11629
+ */
11630
+ PropertyTransactionReportService.prototype.getDepreciations = function () {
11631
+ return this.depreciationService.get().pipe(operators.map(function (depreciations) {
11632
+ return new DepreciationCollection(depreciations)
11633
+ .getByChartAccountsCategories(CHART_ACCOUNTS_CATEGORIES.property)
11634
+ // we don't need borrowing expenses for this report
11635
+ .getWithoutBorrowingExpenses();
11476
11636
  }));
11477
11637
  };
11478
- return PropertyCategoryMovementService;
11479
- }(RestService));
11480
- PropertyCategoryMovementService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryMovementService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
11481
- PropertyCategoryMovementService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryMovementService, providedIn: 'root' });
11482
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryMovementService, decorators: [{
11638
+ return PropertyTransactionReportService;
11639
+ }());
11640
+ PropertyTransactionReportService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyTransactionReportService, deps: [{ token: PropertyService }, { token: TransactionService }, { token: DepreciationService }, { token: ChartAccountsService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11641
+ PropertyTransactionReportService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyTransactionReportService, providedIn: 'root' });
11642
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyTransactionReportService, decorators: [{
11483
11643
  type: i0.Injectable,
11484
11644
  args: [{
11485
11645
  providedIn: 'root'
11486
11646
  }]
11487
- }] });
11647
+ }], ctorParameters: function () { return [{ type: PropertyService }, { type: TransactionService }, { type: DepreciationService }, { type: ChartAccountsService }]; } });
11488
11648
 
11489
- var SubscriptionService = /** @class */ (function () {
11490
- function SubscriptionService(http, eventDispatcherService, sseService, environment) {
11491
- this.http = http;
11492
- this.eventDispatcherService = eventDispatcherService;
11493
- this.sseService = sseService;
11494
- this.environment = environment;
11495
- this.serviceSubscriptionSubject = new rxjs.ReplaySubject(1);
11496
- this.serviceSubscriptionsSubject = new rxjs.ReplaySubject(1);
11497
- this.servicePaymentsSubject = new rxjs.ReplaySubject(1);
11498
- this.subscriptionChangeSubject = new rxjs.BehaviorSubject(null);
11499
- this.listenEvents();
11649
+ /**
11650
+ * Service with calculations methods for properties related with other entities.
11651
+ * Logic here works like collections methods but for several entities
11652
+ */
11653
+ var PropertyCalculationService = /** @class */ (function () {
11654
+ function PropertyCalculationService() {
11500
11655
  }
11501
- SubscriptionService.prototype.listenEvents = function () {
11502
- this.listenSubscriptions();
11656
+ PropertyCalculationService.prototype.getTaxPosition = function (transactions, depreciations) {
11657
+ // @TODO hack: math abs added because we have mismatching of real values signs
11658
+ return transactions.cashPosition - Math.abs(depreciations.claimAmount);
11503
11659
  };
11504
- SubscriptionService.prototype.getSubscription = function (force) {
11660
+ PropertyCalculationService.prototype.getTaxPosition$ = function (transactions$, depreciations$) {
11505
11661
  var _this = this;
11506
- if (force === void 0) { force = false; }
11507
- if (!this._serviceSubscription || force) {
11508
- this.http.get(this.environment.apiV2 + "/subscriptions/last")
11509
- .pipe(operators.map(function (response) {
11510
- return classTransformer.plainToClass(ServiceSubscription, response);
11511
- }))
11512
- .subscribe(function (subsciption) {
11513
- _this._serviceSubscription = subsciption;
11514
- _this.serviceSubscriptionSubject.next(_this._serviceSubscription);
11515
- });
11662
+ return rxjs.combineLatest([
11663
+ transactions$,
11664
+ depreciations$
11665
+ ]).pipe(operators.map(function (_b) {
11666
+ var _c = __read(_b, 2), transactions = _c[0], depreciations = _c[1];
11667
+ return _this.getTaxPosition(transactions, depreciations);
11668
+ }));
11669
+ };
11670
+ PropertyCalculationService.prototype.taxPositionGrowth = function (properties, transactions, depreciations) {
11671
+ var taxPosition = this.getTaxPosition(transactions, depreciations);
11672
+ // check if taxPosition = 0 to avoid division by zero
11673
+ if (!taxPosition) {
11674
+ return 0;
11516
11675
  }
11517
- return this.serviceSubscriptionSubject.asObservable();
11676
+ return (taxPosition - properties.forecastedTaxPosition) / taxPosition;
11518
11677
  };
11519
- /**
11520
- * @TODO right now we have only monthly prices, the function should be refactored to support other options in future
11521
- *
11522
- * create available subscription plans based on existing products
11523
- */
11524
- SubscriptionService.prototype.getSubscriptionPlans = function () {
11678
+ PropertyCalculationService.prototype.taxPositionGrowth$ = function (properties$, transactions$, depreciations$) {
11525
11679
  var _this = this;
11526
- if (!this._serviceSubscriptions) {
11527
- this.http.get(this.environment.apiV2 + "/service-prices")
11528
- .pipe(operators.map(function (response) {
11529
- return new ServicePriceCollection(response['hydra:member'].map(function (item) { return classTransformer.plainToClass(ServicePrice, item); }));
11530
- }))
11531
- .subscribe(function (prices) {
11532
- _this._serviceSubscriptions = new ServiceSubscriptionCollection([
11533
- classTransformer.plainToClass(ServiceSubscription, { items: [] }),
11534
- classTransformer.plainToClass(ServiceSubscription, {
11535
- items: [classTransformer.plainToClass(ServiceSubscriptionItem, {
11536
- price: prices.property,
11537
- quantity: 2
11538
- })]
11539
- }),
11540
- classTransformer.plainToClass(ServiceSubscription, {
11541
- items: [classTransformer.plainToClass(ServiceSubscriptionItem, {
11542
- price: prices.property,
11543
- quantity: 3
11544
- })]
11545
- })
11546
- ]);
11547
- _this._serviceSubscriptions.items.forEach(function (subscription) {
11548
- subscription.items.push(classTransformer.plainToClass(ServiceSubscriptionItem, { price: prices.work, quantity: 1 }));
11549
- });
11550
- _this.serviceSubscriptionsSubject.next(_this._serviceSubscriptions);
11551
- });
11552
- }
11553
- return this.serviceSubscriptionsSubject.asObservable();
11680
+ return rxjs.combineLatest([
11681
+ properties$,
11682
+ transactions$,
11683
+ depreciations$
11684
+ ]).pipe(operators.map(function (_b) {
11685
+ var _c = __read(_b, 3), properties = _c[0], transactions = _c[1], depreciations = _c[2];
11686
+ return _this.taxPositionGrowth(properties, transactions, depreciations);
11687
+ }));
11554
11688
  };
11555
- /**
11556
- * redirect to stripe payment page
11557
- */
11558
- SubscriptionService.prototype.checkoutRedirect = function (subscription, successUrl, cancelUrl) {
11559
- return __awaiter(this, void 0, void 0, function () {
11560
- var stripe, lineItems;
11561
- return __generator(this, function (_a) {
11562
- switch (_a.label) {
11563
- case 0: return [4 /*yield*/, stripeJs.loadStripe(this.environment.stripePk)];
11564
- case 1:
11565
- stripe = _a.sent();
11566
- lineItems = subscription.items.map(function (item) {
11567
- return { servicePriceId: item.price.id, quantity: item.quantity };
11568
- });
11569
- this.http.post(this.environment.apiV2 + "/stripe/checkout-session", {
11570
- lineItems: lineItems,
11571
- successUrl: successUrl,
11572
- cancelUrl: cancelUrl
11573
- })
11574
- .subscribe(function (session) {
11575
- // @Todo remove user TRIAL status
11576
- stripe.redirectToCheckout({ sessionId: session });
11577
- });
11578
- return [2 /*return*/];
11579
- }
11580
- });
11581
- });
11689
+ PropertyCalculationService.prototype.getRentalReturn = function (properties, transactions) {
11690
+ return transactions.claimIncome / properties.marketValue;
11691
+ };
11692
+ PropertyCalculationService.prototype.getLoanAmount = function (properties, bankAccounts, loans) {
11693
+ return properties.items.reduce(function (totalAmount, property) {
11694
+ return totalAmount + bankAccounts.items
11695
+ .reduce(function (propertyAmount, bankAccount) {
11696
+ var _a;
11697
+ return propertyAmount + bankAccount.getPropertyPercentage(property.id) * (((_a = loans.getByBankAccountId(bankAccount.id)) === null || _a === void 0 ? void 0 : _a.amount) || 0);
11698
+ }, 0);
11699
+ }, 0);
11700
+ };
11701
+ PropertyCalculationService.prototype.getLoanValue = function (properties, bankAccounts) {
11702
+ return properties.items.reduce(function (totalAmount, property) {
11703
+ return totalAmount + bankAccounts.items
11704
+ .reduce(function (propertyAmount, bankAccount) {
11705
+ return propertyAmount + bankAccount.getPropertyBalanceAmount(property.id);
11706
+ }, 0);
11707
+ }, 0);
11582
11708
  };
11583
11709
  /**
11584
- * redirect to stripe billing page
11710
+ * LVR
11585
11711
  */
11586
- SubscriptionService.prototype.billingRedirect = function (returnUrl) {
11587
- this.http.get(this.environment.apiV2 + "/stripe/billing-portal-session", {
11588
- params: { returnUrl: returnUrl }
11589
- }).subscribe(function (response) {
11590
- window.location.replace(response.url);
11591
- });
11712
+ PropertyCalculationService.prototype.getLvr = function (properties, bankAccounts) {
11713
+ // Math abs is required for correct percentage calculation
11714
+ return Math.abs(this.getLoanValue(properties, bankAccounts)) / properties.marketValue;
11715
+ };
11716
+ PropertyCalculationService.prototype.getLvr$ = function (properties$, bankAccounts$) {
11717
+ var _this = this;
11718
+ return rxjs.combineLatest([
11719
+ properties$,
11720
+ bankAccounts$
11721
+ ]).pipe(operators.map(function (_b) {
11722
+ var _c = __read(_b, 2), properties = _c[0], bankAccounts = _c[1];
11723
+ return _this.getLvr(properties, bankAccounts);
11724
+ }));
11725
+ };
11726
+ PropertyCalculationService.prototype.getLvrCommencement = function (properties, loans, bankAccounts) {
11727
+ // Math abs is required for correct percentage calculation
11728
+ return Math.abs(this.getLoanAmount(properties, bankAccounts, loans)) / properties.purchasePrice;
11592
11729
  };
11593
- SubscriptionService.prototype.getPayments = function () {
11730
+ PropertyCalculationService.prototype.getLvrCommencement$ = function (properties$, bankAccounts$, loans$) {
11594
11731
  var _this = this;
11595
- if (!this._servicePayments) {
11596
- this.http.get(this.environment.apiV2 + "/service-payments").subscribe(function (response) {
11597
- _this._servicePayments = response.map(function (item) { return classTransformer.plainToClass(ServicePayment, item); });
11598
- _this.servicePaymentsSubject.next(_this._servicePayments);
11599
- });
11732
+ return rxjs.combineLatest([
11733
+ properties$,
11734
+ bankAccounts$,
11735
+ loans$
11736
+ ]).pipe(operators.map(function (_b) {
11737
+ var _c = __read(_b, 3), properties = _c[0], bankAccounts = _c[1], loans = _c[2];
11738
+ return _this.getLvrCommencement(properties, loans, bankAccounts);
11739
+ }));
11740
+ };
11741
+ PropertyCalculationService.prototype.getLvrGrowth = function (properties, bankAccounts, loans) {
11742
+ var lvr = this.getLvr(properties, bankAccounts);
11743
+ if (!lvr) {
11744
+ // check if lvr = 0 to avoid division by zero
11745
+ return 0;
11600
11746
  }
11601
- return this.servicePaymentsSubject.asObservable();
11747
+ return (lvr - this.getLvrCommencement(properties, loans, bankAccounts)) / lvr;
11748
+ };
11749
+ PropertyCalculationService.prototype.getLvrGrowth$ = function (properties$, bankAccounts$, loans$) {
11750
+ var _this = this;
11751
+ return rxjs.combineLatest([
11752
+ properties$,
11753
+ bankAccounts$,
11754
+ loans$
11755
+ ]).pipe(operators.map(function (_b) {
11756
+ var _c = __read(_b, 3), properties = _c[0], bankAccounts = _c[1], loans = _c[2];
11757
+ return _this.getLvrGrowth(properties, bankAccounts, loans);
11758
+ }));
11759
+ };
11760
+ PropertyCalculationService.prototype.getEquityPosition = function (properties, bankAccounts) {
11761
+ // Math abs is required for correct percentage calculation
11762
+ return properties.marketValue - Math.abs(this.getLoanValue(properties, bankAccounts));
11763
+ };
11764
+ PropertyCalculationService.prototype.getPurchaseEquity = function (properties, bankAccounts, loans) {
11765
+ // Math abs is required for correct percentage calculation
11766
+ return properties.purchasePrice - Math.abs(this.getLoanAmount(properties, bankAccounts, loans));
11602
11767
  };
11768
+ return PropertyCalculationService;
11769
+ }());
11770
+ PropertyCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCalculationService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11771
+ PropertyCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCalculationService, providedIn: 'root' });
11772
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCalculationService, decorators: [{
11773
+ type: i0.Injectable,
11774
+ args: [{
11775
+ providedIn: 'root'
11776
+ }]
11777
+ }] });
11778
+
11779
+ /**
11780
+ * Service for work with Property Categories
11781
+ */
11782
+ var PropertyCategoryService = /** @class */ (function (_super) {
11783
+ __extends(PropertyCategoryService, _super);
11784
+ function PropertyCategoryService() {
11785
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11786
+ _this.modelClass = PropertyCategory;
11787
+ _this.url = 'properties/categories';
11788
+ return _this;
11789
+ }
11790
+ return PropertyCategoryService;
11791
+ }(RestService));
11792
+ PropertyCategoryService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
11793
+ PropertyCategoryService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryService, providedIn: 'root' });
11794
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryService, decorators: [{
11795
+ type: i0.Injectable,
11796
+ args: [{
11797
+ providedIn: 'root'
11798
+ }]
11799
+ }] });
11800
+
11801
+ /**
11802
+ * Class for work with Property Documents
11803
+ */
11804
+ var PropertyDocumentService = /** @class */ (function (_super) {
11805
+ __extends(PropertyDocumentService, _super);
11806
+ function PropertyDocumentService(http, eventDispatcherService, environment) {
11807
+ var _this = _super.call(this, http, eventDispatcherService, environment) || this;
11808
+ _this.http = http;
11809
+ _this.eventDispatcherService = eventDispatcherService;
11810
+ _this.environment = environment;
11811
+ _this.modelClass = PropertyDocument;
11812
+ _this.url = 'properties/documents';
11813
+ _this.listenEvents();
11814
+ return _this;
11815
+ }
11603
11816
  /**
11604
- * Get difference between current subscription and selected new subscription
11817
+ * Add new Property Document
11605
11818
  */
11606
- SubscriptionService.prototype.getProrationCost = function (items) {
11607
- return this.http.post(this.environment.apiV2 + "/subscriptions/proration-cost", items).pipe(operators.map(function (prorationCost) {
11608
- return prorationCost;
11819
+ PropertyDocumentService.prototype.upload = function (file, propertyId) {
11820
+ var _this = this;
11821
+ // create formData object with provided file
11822
+ var formDataDocument = new FormData();
11823
+ formDataDocument.append('file', file);
11824
+ return this.http.post(this.environment.apiV2 + "/properties/" + propertyId + "/documents", formDataDocument).pipe(operators.map(function (documentBase) {
11825
+ var newDocument = classTransformer.plainToClass(PropertyDocument, documentBase);
11826
+ if (_this.cache) {
11827
+ _this.cache.push(newDocument);
11828
+ _this.updateCache();
11829
+ }
11830
+ return newDocument;
11609
11831
  }));
11610
11832
  };
11611
11833
  /**
11612
- * Change subscription plan
11834
+ * Get documents by property id
11835
+ * @param propertyId to get desired documents
11613
11836
  */
11614
- SubscriptionService.prototype.changeSubscription = function (items) {
11615
- return this.http.put(this.environment.apiV2 + "/subscriptions/items", items);
11837
+ PropertyDocumentService.prototype.getByPropertyId = function (propertyId) {
11838
+ return this.get()
11839
+ .pipe(operators.map(function (documents) {
11840
+ return documents
11841
+ .filter(function (document) { return document.property.id === propertyId; });
11842
+ }));
11616
11843
  };
11617
- SubscriptionService.prototype.listenSubscriptions = function () {
11844
+ PropertyDocumentService.prototype.listenEvents = function () {
11845
+ this.listenPropertyUpdateWithDocument();
11846
+ };
11847
+ PropertyDocumentService.prototype.listenPropertyUpdateWithDocument = function () {
11618
11848
  var _this = this;
11619
- this.sseService.on("serviceSubscriptions")
11620
- .pipe(operators.map(function (event) { return classTransformer.plainToClass(ServiceSubscription, event); }))
11621
- .subscribe(function (subscription) {
11622
- _this.getSubscription(true).subscribe();
11623
- _this.subscriptionChangeSubject.next(subscription);
11624
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.SERVICE_SUBSCRIPTION_UPDATED, null));
11849
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.PROPERTY_UPDATED_WITH_DOCUMENT).subscribe(function (property) {
11850
+ _this.upload(property.documentFile, property.id).subscribe();
11625
11851
  });
11626
11852
  };
11627
- return SubscriptionService;
11628
- }());
11629
- SubscriptionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SubscriptionService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: SseService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11630
- SubscriptionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SubscriptionService, providedIn: 'root' });
11631
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SubscriptionService, decorators: [{
11853
+ return PropertyDocumentService;
11854
+ }(RestService));
11855
+ PropertyDocumentService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyDocumentService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11856
+ PropertyDocumentService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyDocumentService, providedIn: 'root' });
11857
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyDocumentService, decorators: [{
11632
11858
  type: i0.Injectable,
11633
11859
  args: [{
11634
11860
  providedIn: 'root'
11635
11861
  }]
11636
11862
  }], ctorParameters: function () {
11637
- return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: SseService }, { type: undefined, decorators: [{
11863
+ return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
11638
11864
  type: i0.Inject,
11639
11865
  args: ['environment']
11640
11866
  }] }];
11641
11867
  } });
11642
11868
 
11643
- /**
11644
- * Service to work with tax review
11645
- */
11646
- var TaxReviewService = /** @class */ (function (_super) {
11647
- __extends(TaxReviewService, _super);
11648
- function TaxReviewService(http, eventDispatcherService, environment) {
11869
+ // @TODO check and improve logic during refactoring
11870
+ var PropertyShareService = /** @class */ (function (_super) {
11871
+ __extends(PropertyShareService, _super);
11872
+ function PropertyShareService(http, eventDispatcherService, environment) {
11649
11873
  var _this = _super.call(this, http, eventDispatcherService, environment) || this;
11650
11874
  _this.http = http;
11651
11875
  _this.eventDispatcherService = eventDispatcherService;
11652
11876
  _this.environment = environment;
11653
- _this.url = 'tax-reviews';
11654
- _this.modelClass = TaxReview;
11877
+ // api url parameter for properties shares
11878
+ _this.url = 'properties/shares';
11879
+ _this.modelClass = PropertyShare;
11655
11880
  _this.listenEvents();
11656
11881
  return _this;
11657
11882
  }
11658
11883
  /**
11659
- * Listen events from SSE and Event Dispatcher services
11884
+ * Listen to Event Dispatcher events
11660
11885
  */
11661
- TaxReviewService.prototype.listenEvents = function () {
11662
- this.listenFirmChanges();
11663
- this.listenClientTransfer();
11886
+ PropertyShareService.prototype.listenEvents = function () {
11887
+ this.listenUserUpdated();
11664
11888
  };
11665
11889
  /**
11666
- * Add new Tax Review (request from client to firm)
11667
- * @param finYear
11890
+ * Updated loan
11668
11891
  */
11669
- TaxReviewService.prototype.request = function (finYear) {
11892
+ PropertyShareService.prototype.update = function (propertyShare) {
11670
11893
  var _this = this;
11671
- return this.http.post(this.environment.apiV2 + "/" + this.url + "?financialYear=" + finYear, {})
11672
- .pipe(operators.map(function (newTaxReview) {
11673
- var taxReview = classTransformer.plainToClass(TaxReview, newTaxReview);
11674
- var tempCache = ___default["default"].cloneDeep(_this.cache);
11675
- tempCache.push(taxReview);
11676
- _this.cache = tempCache;
11894
+ return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + propertyShare.id, propertyShare)
11895
+ .pipe(operators.map(function (updatedPropertyShareBase) {
11896
+ var updatedPropertyShare = classTransformer.plainToClass(PropertyShare, updatedPropertyShareBase);
11897
+ // if loan type is NOT vehicle - fire EventDispatcher event
11898
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_SHARE_UPDATED, null));
11899
+ replace(_this.cache, updatedPropertyShare);
11677
11900
  _this.updateCache();
11678
- return taxReview;
11901
+ return updatedPropertyShare;
11679
11902
  }));
11680
11903
  };
11681
11904
  /**
11682
- * Update tax review
11683
- * @param taxReview to be updated
11905
+ * Re-invite property share
11906
+ * @param share user to share property
11684
11907
  */
11685
- TaxReviewService.prototype.update = function (taxReview) {
11686
- var _this = this;
11687
- return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + taxReview.id, taxReview)
11688
- .pipe(operators.map(function (updatedTaxReview) {
11689
- var updatedInstance = classTransformer.plainToClass(TaxReview, updatedTaxReview);
11690
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TAX_REVIEW_UPDATED, updatedInstance));
11691
- var tempCache = ___default["default"].cloneDeep(_this.cache);
11692
- replace(tempCache, updatedInstance);
11693
- _this.cache = tempCache;
11694
- _this.updateCache();
11695
- return updatedInstance;
11908
+ PropertyShareService.prototype.reinvite = function (share) {
11909
+ return this.http.post(this.environment.apiV2 + "/" + this.url + "/" + share.id + "/reinvite", {});
11910
+ };
11911
+ PropertyShareService.prototype.getIncoming = function () {
11912
+ return this.get()
11913
+ .pipe(operators.map(function (propertyShares) {
11914
+ var propertySharesIncoming = [];
11915
+ propertyShares.forEach(function (propertyShare) {
11916
+ var _a;
11917
+ if (((_a = propertyShare.user) === null || _a === void 0 ? void 0 : _a.isLoggedIn()) && propertyShare.isPending() && propertyShare.property.user.id !== +localStorage.getItem('userId')) {
11918
+ propertySharesIncoming.push(propertyShare);
11919
+ }
11920
+ });
11921
+ return propertySharesIncoming;
11696
11922
  }));
11697
11923
  };
11698
11924
  /**
11699
- * Clear cache when user reject firm
11925
+ * Get outcoming property shares list
11700
11926
  */
11701
- TaxReviewService.prototype.listenFirmChanges = function () {
11927
+ PropertyShareService.prototype.getOutcoming = function () {
11702
11928
  var _this = this;
11703
- this.eventDispatcherService.on([exports.AppEventTypeEnum.CLIENT_MOVEMENT_CLOSED, exports.AppEventTypeEnum.CLIENT_INVITE_ACCEPTED])
11704
- .subscribe(function () {
11705
- _this.cache = [];
11706
- _this.updateCache();
11707
- });
11929
+ return this.get().pipe(operators.map(function (propertyShares) {
11930
+ return _this.filterOutcoming(propertyShares);
11931
+ }));
11708
11932
  };
11709
11933
  /**
11710
- * Update firm for all transferred clients
11711
- * @private
11934
+ * Filter outcoming property shares
11712
11935
  */
11713
- TaxReviewService.prototype.listenClientTransfer = function () {
11714
- var _this = this;
11715
- this.eventDispatcherService.on(exports.AppEventTypeEnum.CLIENT_TRANSFER_TO_OTHER_EMPLOYEE)
11716
- .subscribe(function (transferredClients) {
11717
- var tempCache = ___default["default"].cloneDeep(_this.cache);
11718
- transferredClients.forEach(function (transferredClient) {
11719
- var taxReviewIndex = tempCache.findIndex(function (taxReview) { return taxReview.id === transferredClient.id; });
11720
- // @TODO vik
11721
- // tempCache[taxReviewIndex].employee = transferredClient.accountant;
11936
+ PropertyShareService.prototype.filterOutcoming = function (propertyShares) {
11937
+ var propertySharesOutcoming = [];
11938
+ propertyShares.forEach(function (propertyShare) {
11939
+ var _a;
11940
+ if (!((_a = propertyShare.user) === null || _a === void 0 ? void 0 : _a.isLoggedIn())) {
11941
+ propertySharesOutcoming.push(propertyShare);
11942
+ }
11943
+ });
11944
+ return propertySharesOutcoming;
11945
+ };
11946
+ PropertyShareService.prototype.getByPropertyId = function (propertyId) {
11947
+ return this.get()
11948
+ .pipe(operators.map(function (propertyShares) {
11949
+ return propertyShares.filter(function (propertyShare) { return propertyShare.property.id === propertyId; });
11950
+ }));
11951
+ };
11952
+ /**
11953
+ * Listen to User updated event
11954
+ */
11955
+ PropertyShareService.prototype.listenUserUpdated = function () {
11956
+ var _this = this;
11957
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.USER_UPDATED)
11958
+ .subscribe(function () {
11959
+ _this.fetch().subscribe(function (propertyShares) {
11960
+ _this.cache = propertyShares;
11961
+ _this.updateCache();
11722
11962
  });
11723
- _this.cache = tempCache;
11724
- _this.updateCache();
11725
11963
  });
11726
11964
  };
11727
- return TaxReviewService;
11965
+ return PropertyShareService;
11728
11966
  }(RestService));
11729
- TaxReviewService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11730
- TaxReviewService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewService, providedIn: 'root' });
11731
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewService, decorators: [{
11967
+ PropertyShareService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyShareService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11968
+ PropertyShareService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyShareService, providedIn: 'root' });
11969
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyShareService, decorators: [{
11732
11970
  type: i0.Injectable,
11733
11971
  args: [{
11734
11972
  providedIn: 'root'
@@ -11740,499 +11978,461 @@
11740
11978
  }] }];
11741
11979
  } });
11742
11980
 
11743
- /**
11744
- * Service to work with tax review history
11745
- */
11746
- var TaxReviewHistoryService = /** @class */ (function (_super) {
11747
- __extends(TaxReviewHistoryService, _super);
11748
- function TaxReviewHistoryService(http, eventDispatcherService, environment) {
11749
- var _this = _super.call(this, http, eventDispatcherService, environment) || this;
11750
- _this.http = http;
11751
- _this.eventDispatcherService = eventDispatcherService;
11752
- _this.environment = environment;
11753
- _this.url = 'tax-reviews/history';
11754
- _this.modelClass = TaxReview;
11755
- // subscribe on tax review updating
11756
- eventDispatcherService.on(exports.AppEventTypeEnum.TAX_REVIEW_UPDATED).subscribe(function (taxReview) {
11757
- var tempCache = ___default["default"].cloneDeep(_this.cache);
11758
- // insert element at the beginning of the array
11759
- tempCache.unshift(taxReview);
11760
- _this.cache = tempCache;
11761
- _this.updateCache();
11762
- });
11981
+ var PropertySaleService = /** @class */ (function (_super) {
11982
+ __extends(PropertySaleService, _super);
11983
+ function PropertySaleService() {
11984
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
11985
+ _this.modelClass = PropertySale;
11986
+ _this.url = 'properties/sales';
11763
11987
  return _this;
11764
11988
  }
11765
- return TaxReviewHistoryService;
11989
+ return PropertySaleService;
11766
11990
  }(RestService));
11767
- TaxReviewHistoryService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewHistoryService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11768
- TaxReviewHistoryService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewHistoryService, providedIn: 'root' });
11769
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewHistoryService, decorators: [{
11991
+ PropertySaleService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertySaleService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
11992
+ PropertySaleService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertySaleService, providedIn: 'root' });
11993
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertySaleService, decorators: [{
11770
11994
  type: i0.Injectable,
11771
11995
  args: [{
11772
11996
  providedIn: 'root'
11773
11997
  }]
11774
- }], ctorParameters: function () {
11775
- return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
11776
- type: i0.Inject,
11777
- args: ['environment']
11778
- }] }];
11779
- } });
11998
+ }] });
11780
11999
 
11781
12000
  /**
11782
- * Service to work with tax summary logic
12001
+ * Service for get property equity position half-year history chart data
11783
12002
  */
11784
- var TaxSummaryService = /** @class */ (function () {
11785
- function TaxSummaryService(http, eventDispatcherService, environment) {
12003
+ var EquityPositionChartService = /** @class */ (function () {
12004
+ function EquityPositionChartService(http, environment) {
11786
12005
  this.http = http;
11787
- this.eventDispatcherService = eventDispatcherService;
11788
12006
  this.environment = environment;
11789
- this.taxSummaryActualsSubject = new rxjs.ReplaySubject(1);
11790
- this.taxSummaryForecastsSubject = new rxjs.ReplaySubject(1);
11791
- this.listenEvents();
11792
12007
  }
11793
- TaxSummaryService.prototype.listenEvents = function () {
11794
- this.listenToIncomeSourceForecastsEvents();
11795
- };
11796
- /**
11797
- * Get actual tax summary items
11798
- */
11799
- TaxSummaryService.prototype.getActuals = function () {
11800
- var _this = this;
11801
- this.http.get(this.environment.apiV2 + "/tax-summary/" + exports.TaxSummaryTypeEnum.ACTUALS, {})
11802
- .subscribe(function (response) {
11803
- var taxSummary = classTransformer.plainToClass(TaxSummary, response);
11804
- _this.taxSummaryActualsSubject.next(taxSummary);
11805
- return taxSummary;
11806
- });
11807
- return this.taxSummaryActualsSubject.asObservable();
11808
- };
11809
- /**
11810
- * Get forecast tax summary items
11811
- */
11812
- TaxSummaryService.prototype.getForecast = function () {
11813
- var _this = this;
11814
- this.http.get(this.environment.apiV2 + "/tax-summary/" + exports.TaxSummaryTypeEnum.FORECASTS, {})
11815
- .subscribe(function (response) {
11816
- var taxSummary = classTransformer.plainToClass(TaxSummary, response);
11817
- _this.taxSummaryForecastsSubject.next(taxSummary);
11818
- return taxSummary;
11819
- });
11820
- return this.taxSummaryForecastsSubject.asObservable();
11821
- };
11822
- /**
11823
- * Listen to EventDispatcherService events related to Income source forecasts
11824
- */
11825
- TaxSummaryService.prototype.listenToIncomeSourceForecastsEvents = function () {
11826
- var _this = this;
11827
- this.eventDispatcherService
11828
- .on([exports.AppEventTypeEnum.INCOME_SOURCES_FORECASTS_CREATED, exports.AppEventTypeEnum.INCOME_SOURCES_FORECASTS_UPDATED])
11829
- .subscribe(function () {
11830
- _this.getForecast().subscribe();
11831
- });
12008
+ EquityPositionChartService.prototype.get = function () {
12009
+ // @TODO refactor backend
12010
+ return this.http.get(this.environment.apiV2 + "/properties/categories/equity")
12011
+ .pipe(operators.map(function (response) {
12012
+ return response.map(function (item) {
12013
+ return classTransformer.plainToClass(ChartData, {
12014
+ name: item.category.name,
12015
+ data: item.equity.map(function (serie) {
12016
+ return classTransformer.plainToClass(ChartSerie, {
12017
+ label: serie.date,
12018
+ value: serie.amount
12019
+ });
12020
+ })
12021
+ });
12022
+ });
12023
+ }));
11832
12024
  };
11833
- return TaxSummaryService;
12025
+ return EquityPositionChartService;
11834
12026
  }());
11835
- TaxSummaryService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxSummaryService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11836
- TaxSummaryService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxSummaryService, providedIn: 'root' });
11837
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxSummaryService, decorators: [{
12027
+ EquityPositionChartService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: EquityPositionChartService, deps: [{ token: i1__namespace.HttpClient }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
12028
+ EquityPositionChartService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: EquityPositionChartService, providedIn: 'root' });
12029
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: EquityPositionChartService, decorators: [{
11838
12030
  type: i0.Injectable,
11839
12031
  args: [{
11840
12032
  providedIn: 'root'
11841
12033
  }]
11842
12034
  }], ctorParameters: function () {
11843
- return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
12035
+ return [{ type: i1__namespace.HttpClient }, { type: undefined, decorators: [{
11844
12036
  type: i0.Inject,
11845
12037
  args: ['environment']
11846
12038
  }] }];
11847
12039
  } });
11848
12040
 
11849
- /**
11850
- * popup notifications service (toast, snackbar).
11851
- */
11852
- var ToastService = /** @class */ (function () {
11853
- function ToastService() {
11854
- this.toast$ = new rxjs.ReplaySubject(1);
12041
+ var PropertyCategoryMovementService = /** @class */ (function (_super) {
12042
+ __extends(PropertyCategoryMovementService, _super);
12043
+ function PropertyCategoryMovementService() {
12044
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
12045
+ _this.modelClass = PropertyCategoryMovement;
12046
+ _this.url = 'properties/category-movements';
12047
+ return _this;
11855
12048
  }
11856
- ToastService.prototype.get = function () {
11857
- return this.toast$.asObservable();
11858
- };
11859
- ToastService.prototype.add = function (toast) {
11860
- this.toast$.next(toast);
11861
- };
11862
- ToastService.prototype.success = function (message) {
11863
- this.add(classTransformer.plainToClass(Toast, {
11864
- type: exports.ToastTypeEnum.SUCCESS,
11865
- title: 'Success!',
11866
- message: message,
12049
+ PropertyCategoryMovementService.prototype.add = function (model) {
12050
+ var _this = this;
12051
+ return _super.prototype.add.call(this, model).pipe(operators.map(function (newMovement) {
12052
+ // @TODO Alex: we need to teach restService to dispatch events + limit list of methods (not all services have all 4 or even more considering batch requests) + collections
12053
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_MOVEMENT_CREATED, null));
12054
+ return newMovement;
11867
12055
  }));
11868
12056
  };
11869
- ToastService.prototype.warning = function (message) {
11870
- this.add(classTransformer.plainToClass(Toast, {
11871
- type: exports.ToastTypeEnum.WARNING,
11872
- title: 'Warning!',
11873
- message: message,
12057
+ PropertyCategoryMovementService.prototype.update = function (model) {
12058
+ var _this = this;
12059
+ return _super.prototype.update.call(this, model).pipe(operators.map(function (updatedMovement) {
12060
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_MOVEMENT_CREATED, null));
12061
+ return updatedMovement;
11874
12062
  }));
11875
12063
  };
11876
- ToastService.prototype.error = function (message) {
11877
- this.add(classTransformer.plainToClass(Toast, {
11878
- type: exports.ToastTypeEnum.ERROR,
11879
- title: 'Error!',
11880
- message: message,
12064
+ PropertyCategoryMovementService.prototype.delete = function (model) {
12065
+ var _this = this;
12066
+ return _super.prototype.delete.call(this, model).pipe(operators.map(function () {
12067
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.PROPERTY_MOVEMENT_CREATED, null));
11881
12068
  }));
11882
12069
  };
11883
- ToastService.prototype.info = function (message) {
11884
- this.add(classTransformer.plainToClass(Toast, {
11885
- type: exports.ToastTypeEnum.INFO,
11886
- title: 'Information',
11887
- message: message,
12070
+ // @TODO Alex: Move to collection
12071
+ PropertyCategoryMovementService.prototype.getByPropertyId = function (id) {
12072
+ return this.get().pipe(operators.map(function (movements) {
12073
+ return movements.filter(function (movement) { return movement.property.id === id; });
11888
12074
  }));
11889
12075
  };
11890
- return ToastService;
11891
- }());
11892
- ToastService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ToastService, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
11893
- ToastService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ToastService, providedIn: 'root' });
11894
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ToastService, decorators: [{
12076
+ return PropertyCategoryMovementService;
12077
+ }(RestService));
12078
+ PropertyCategoryMovementService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryMovementService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
12079
+ PropertyCategoryMovementService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryMovementService, providedIn: 'root' });
12080
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: PropertyCategoryMovementService, decorators: [{
11895
12081
  type: i0.Injectable,
11896
12082
  args: [{
11897
12083
  providedIn: 'root'
11898
12084
  }]
11899
12085
  }] });
11900
12086
 
11901
- function enumToList(data) {
11902
- var list = [];
11903
- for (var key in data) {
11904
- if (Number(key) >= 0) {
11905
- list.push({
11906
- label: data[key],
11907
- value: Number(key)
11908
- });
11909
- }
11910
- }
11911
- return list;
11912
- }
11913
-
11914
- var MessagesEnum;
11915
- (function (MessagesEnum) {
11916
- MessagesEnum["DELETED_MESSAGE"] = "Transaction deleted";
11917
- MessagesEnum["UPDATED_MESSAGE"] = "Transaction updated";
11918
- MessagesEnum["CREATED_MESSAGE"] = "Transaction(s) created";
11919
- })(MessagesEnum || (MessagesEnum = {}));
11920
-
11921
- /**
11922
- * Service for transactions business logic
11923
- */
11924
- var TransactionService = /** @class */ (function (_super) {
11925
- __extends(TransactionService, _super);
11926
- function TransactionService(http, eventDispatcherService, environment, toastService) {
11927
- var _this = _super.call(this, http, eventDispatcherService, environment) || this;
11928
- _this.http = http;
11929
- _this.eventDispatcherService = eventDispatcherService;
11930
- _this.environment = environment;
11931
- _this.toastService = toastService;
11932
- // url part for Transaction API
11933
- _this.url = 'transactions';
11934
- _this.modelClass = Transaction;
11935
- _this.transactionDeleted = new i0.EventEmitter();
11936
- _this.listenEvents();
11937
- return _this;
12087
+ var SubscriptionService = /** @class */ (function () {
12088
+ function SubscriptionService(http, eventDispatcherService, sseService, environment) {
12089
+ this.http = http;
12090
+ this.eventDispatcherService = eventDispatcherService;
12091
+ this.sseService = sseService;
12092
+ this.environment = environment;
12093
+ this.serviceSubscriptionSubject = new rxjs.ReplaySubject(1);
12094
+ this.serviceSubscriptionsSubject = new rxjs.ReplaySubject(1);
12095
+ this.servicePaymentsSubject = new rxjs.ReplaySubject(1);
12096
+ this.subscriptionChangeSubject = new rxjs.BehaviorSubject(null);
12097
+ this.listenEvents();
11938
12098
  }
11939
- /**
11940
- * Listen events from Event Dispatcher services
11941
- */
11942
- TransactionService.prototype.listenEvents = function () {
11943
- this.listenDepreciationChange();
11944
- this.listenPropertyShareUpdate();
12099
+ SubscriptionService.prototype.listenEvents = function () {
12100
+ this.listenSubscriptions();
11945
12101
  };
11946
- /**
11947
- * get list of all user's TaxTank transactions
11948
- */
11949
- TransactionService.prototype.get = function () {
12102
+ SubscriptionService.prototype.getSubscription = function (force) {
11950
12103
  var _this = this;
11951
- if (!this.cache) {
11952
- // set cache as default empty array to avoid multiple backend requests
11953
- this.cache = [];
11954
- this.fetch()
11955
- .subscribe(function (transactions) {
11956
- _this.cache = transactions;
11957
- _this.updateCache();
12104
+ if (force === void 0) { force = false; }
12105
+ if (!this._serviceSubscription || force) {
12106
+ this.http.get(this.environment.apiV2 + "/subscriptions/last")
12107
+ .pipe(operators.map(function (response) {
12108
+ return classTransformer.plainToClass(ServiceSubscription, response);
12109
+ }))
12110
+ .subscribe(function (subsciption) {
12111
+ _this._serviceSubscription = subsciption;
12112
+ _this.serviceSubscriptionSubject.next(_this._serviceSubscription);
11958
12113
  });
11959
12114
  }
11960
- return this.cacheSubject.asObservable().pipe(
11961
- // assign child transactions (fees) to parent transactions
11962
- operators.map(function (transactions) {
11963
- transactions.forEach(function (transaction) {
11964
- transaction.transactions = transactions
11965
- // get list of child transactions
11966
- .filter(function (t) { return t.parentTransaction && t.parentTransaction.id === transaction.id; });
11967
- });
11968
- sort(transactions, 'date', false);
11969
- return transactions;
11970
- }));
12115
+ return this.serviceSubscriptionSubject.asObservable();
11971
12116
  };
11972
12117
  /**
11973
- * Add single new transaction
11974
- * @param model New Transaction instance for saving
12118
+ * @TODO right now we have only monthly prices, the function should be refactored to support other options in future
12119
+ *
12120
+ * create available subscription plans based on existing products
11975
12121
  */
11976
- TransactionService.prototype.add = function (model) {
12122
+ SubscriptionService.prototype.getSubscriptionPlans = function () {
11977
12123
  var _this = this;
11978
- // we don't have POST API endpoint for single transaction
11979
- return this.addBatch([model])
11980
- .pipe(operators.map(function (newTransactions) {
11981
- // @TODO alex
11982
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_CREATED, newTransactions[0]));
11983
- return newTransactions[0];
11984
- }));
12124
+ if (!this._serviceSubscriptions) {
12125
+ this.http.get(this.environment.apiV2 + "/service-prices")
12126
+ .pipe(operators.map(function (response) {
12127
+ return new ServicePriceCollection(response['hydra:member'].map(function (item) { return classTransformer.plainToClass(ServicePrice, item); }));
12128
+ }))
12129
+ .subscribe(function (prices) {
12130
+ _this._serviceSubscriptions = new ServiceSubscriptionCollection([
12131
+ classTransformer.plainToClass(ServiceSubscription, { items: [] }),
12132
+ classTransformer.plainToClass(ServiceSubscription, {
12133
+ items: [classTransformer.plainToClass(ServiceSubscriptionItem, {
12134
+ price: prices.property,
12135
+ quantity: 2
12136
+ })]
12137
+ }),
12138
+ classTransformer.plainToClass(ServiceSubscription, {
12139
+ items: [classTransformer.plainToClass(ServiceSubscriptionItem, {
12140
+ price: prices.property,
12141
+ quantity: 3
12142
+ })]
12143
+ })
12144
+ ]);
12145
+ _this._serviceSubscriptions.items.forEach(function (subscription) {
12146
+ subscription.items.push(classTransformer.plainToClass(ServiceSubscriptionItem, { price: prices.work, quantity: 1 }));
12147
+ });
12148
+ _this.serviceSubscriptionsSubject.next(_this._serviceSubscriptions);
12149
+ });
12150
+ }
12151
+ return this.serviceSubscriptionsSubject.asObservable();
11985
12152
  };
11986
12153
  /**
11987
- * get transactions related with property
12154
+ * redirect to stripe payment page
11988
12155
  */
11989
- TransactionService.prototype.getByPropertyId = function (propertyId) {
11990
- return this.get()
11991
- .pipe(operators.map(function (transactions) {
11992
- return transactions.filter(function (transaction) {
11993
- var _a;
11994
- return ((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id) === propertyId;
12156
+ SubscriptionService.prototype.checkoutRedirect = function (subscription, successUrl, cancelUrl) {
12157
+ return __awaiter(this, void 0, void 0, function () {
12158
+ var stripe, lineItems;
12159
+ return __generator(this, function (_a) {
12160
+ switch (_a.label) {
12161
+ case 0: return [4 /*yield*/, stripeJs.loadStripe(this.environment.stripePk)];
12162
+ case 1:
12163
+ stripe = _a.sent();
12164
+ lineItems = subscription.items.map(function (item) {
12165
+ return { servicePriceId: item.price.id, quantity: item.quantity };
12166
+ });
12167
+ this.http.post(this.environment.apiV2 + "/stripe/checkout-session", {
12168
+ lineItems: lineItems,
12169
+ successUrl: successUrl,
12170
+ cancelUrl: cancelUrl
12171
+ })
12172
+ .subscribe(function (session) {
12173
+ // @Todo remove user TRIAL status
12174
+ stripe.redirectToCheckout({ sessionId: session });
12175
+ });
12176
+ return [2 /*return*/];
12177
+ }
11995
12178
  });
11996
- }));
12179
+ });
11997
12180
  };
11998
12181
  /**
11999
- * get list of transactions with tank type 'Work'
12182
+ * redirect to stripe billing page
12000
12183
  */
12001
- TransactionService.prototype.getWorkTransactions = function () {
12002
- return this.get()
12003
- .pipe(operators.map(function (transactions) {
12004
- return transactions.filter(function (transaction) { return transaction.isWorkTank(); });
12005
- }));
12184
+ SubscriptionService.prototype.billingRedirect = function (returnUrl) {
12185
+ this.http.get(this.environment.apiV2 + "/stripe/billing-portal-session", {
12186
+ params: { returnUrl: returnUrl }
12187
+ }).subscribe(function (response) {
12188
+ window.location.replace(response.url);
12189
+ });
12006
12190
  };
12007
- /**
12008
- * get list of taxable transactions with tank type 'Work'
12009
- */
12010
- TransactionService.prototype.getTaxableWorkTransactions = function () {
12011
- return this.getWorkTransactions()
12012
- .pipe(operators.map(function (transactions) {
12013
- return transactions.filter(function (transaction) { return !!transaction.chartAccounts.taxReturnItem; });
12014
- }));
12191
+ SubscriptionService.prototype.getPayments = function () {
12192
+ var _this = this;
12193
+ if (!this._servicePayments) {
12194
+ this.http.get(this.environment.apiV2 + "/service-payments").subscribe(function (response) {
12195
+ _this._servicePayments = response.map(function (item) { return classTransformer.plainToClass(ServicePayment, item); });
12196
+ _this.servicePaymentsSubject.next(_this._servicePayments);
12197
+ });
12198
+ }
12199
+ return this.servicePaymentsSubject.asObservable();
12015
12200
  };
12016
12201
  /**
12017
- * add multiple transactions
12018
- * @param transactions List of new Transaction instances for saving
12202
+ * Get difference between current subscription and selected new subscription
12019
12203
  */
12020
- TransactionService.prototype.addBatch = function (transactions) {
12021
- var _this = this;
12022
- transactions = ___default["default"].cloneDeep(transactions);
12023
- return this.http.post(this.environment.apiV2 + "/" + this.url, transactions)
12024
- .pipe(operators.map(function (response) {
12025
- var _c;
12026
- var addedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
12027
- transactions.forEach(function (transaction, index) {
12028
- // @TODO backend: need to upload file in the same backend endpoint with transaction add/update
12029
- // check if passed receipt and upload file
12030
- if (transaction.file) {
12031
- transaction.id = response[index].id;
12032
- addedTransactions[index].file = transaction.file;
12033
- _this.uploadReceipt(addedTransactions[index]);
12034
- }
12035
- // @TODO Viktor: implement API for saving of nested transactions
12036
- // add child transactions if exist
12037
- if (transaction.transactions.length) {
12038
- transaction.transactions.forEach(function (childTransaction) {
12039
- childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: addedTransactions[index].id });
12040
- });
12041
- _this.addBatch(transaction.transactions).subscribe();
12042
- }
12043
- // add transfer transaction to cache
12044
- if (transaction.operation === exports.TransactionOperationEnum.TRANSFER) {
12045
- addedTransactions.push(addedTransactions[0].transfer);
12046
- }
12047
- });
12048
- if (_this.cache) {
12049
- (_c = _this.cache).push.apply(_c, __spreadArray([], __read(addedTransactions)));
12050
- _this.updateCache();
12051
- }
12052
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTIONS_CREATED, addedTransactions));
12053
- _this.toastService.success(MessagesEnum.CREATED_MESSAGE);
12054
- return addedTransactions;
12204
+ SubscriptionService.prototype.getProrationCost = function (items) {
12205
+ return this.http.post(this.environment.apiV2 + "/subscriptions/proration-cost", items).pipe(operators.map(function (prorationCost) {
12206
+ return prorationCost;
12055
12207
  }));
12056
12208
  };
12057
12209
  /**
12058
- * update existing transaction
12059
- * @param transaction Transaction instance for updating
12210
+ * Change subscription plan
12060
12211
  */
12061
- TransactionService.prototype.update = function (transaction) {
12212
+ SubscriptionService.prototype.changeSubscription = function (items) {
12213
+ return this.http.put(this.environment.apiV2 + "/subscriptions/items", items);
12214
+ };
12215
+ SubscriptionService.prototype.listenSubscriptions = function () {
12062
12216
  var _this = this;
12063
- return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + transaction.id, transaction)
12064
- .pipe(operators.map(function (response) {
12065
- var updatedTransaction = classTransformer.plainToClass(Transaction, response);
12066
- // @TODO need to upload file in the same backend endpoint with transaction add/update
12067
- // check if passed new receipt and upload file
12068
- if (transaction.file) {
12069
- updatedTransaction.file = transaction.file;
12070
- _this.uploadReceipt(updatedTransaction);
12071
- }
12072
- // @TODO Viktor: implement API for saving of nested transactions
12073
- if (transaction.transactions.length) {
12074
- // add parent transaction to child transactions
12075
- transaction.transactions.forEach(function (childTransaction) {
12076
- childTransaction.parentTransaction = classTransformer.plainToClass(Transaction, { id: updatedTransaction.id });
12077
- });
12078
- // separate child transactions by id existing to define add or update action.
12079
- var childTransactionsToUpdate = transaction.transactions.filter(function (t) { return t.id; });
12080
- var childTransactionsToAdd = transaction.transactions.filter(function (t) { return !t.id; });
12081
- // update child transactions
12082
- if (childTransactionsToUpdate.length) {
12083
- _this.updateBatch(childTransactionsToUpdate).subscribe();
12084
- }
12085
- // add child transactions
12086
- if (childTransactionsToAdd.length) {
12087
- _this.addBatch(childTransactionsToAdd).subscribe();
12088
- }
12089
- }
12090
- _this.toastService.success(MessagesEnum.UPDATED_MESSAGE);
12091
- replace(_this.cache, updatedTransaction);
12092
- _this.updateCache();
12093
- return updatedTransaction;
12094
- }));
12217
+ this.sseService.on("serviceSubscriptions")
12218
+ .pipe(operators.map(function (event) { return classTransformer.plainToClass(ServiceSubscription, event); }))
12219
+ .subscribe(function (subscription) {
12220
+ _this.getSubscription(true).subscribe();
12221
+ _this.subscriptionChangeSubject.next(subscription);
12222
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.SERVICE_SUBSCRIPTION_UPDATED, null));
12223
+ });
12224
+ };
12225
+ return SubscriptionService;
12226
+ }());
12227
+ SubscriptionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SubscriptionService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: SseService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
12228
+ SubscriptionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SubscriptionService, providedIn: 'root' });
12229
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SubscriptionService, decorators: [{
12230
+ type: i0.Injectable,
12231
+ args: [{
12232
+ providedIn: 'root'
12233
+ }]
12234
+ }], ctorParameters: function () {
12235
+ return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: SseService }, { type: undefined, decorators: [{
12236
+ type: i0.Inject,
12237
+ args: ['environment']
12238
+ }] }];
12239
+ } });
12240
+
12241
+ /**
12242
+ * Service to work with tax review
12243
+ */
12244
+ var TaxReviewService = /** @class */ (function (_super) {
12245
+ __extends(TaxReviewService, _super);
12246
+ function TaxReviewService(http, eventDispatcherService, environment) {
12247
+ var _this = _super.call(this, http, eventDispatcherService, environment) || this;
12248
+ _this.http = http;
12249
+ _this.eventDispatcherService = eventDispatcherService;
12250
+ _this.environment = environment;
12251
+ _this.url = 'tax-reviews';
12252
+ _this.modelClass = TaxReview;
12253
+ _this.listenEvents();
12254
+ return _this;
12255
+ }
12256
+ /**
12257
+ * Listen events from SSE and Event Dispatcher services
12258
+ */
12259
+ TaxReviewService.prototype.listenEvents = function () {
12260
+ this.listenFirmChanges();
12261
+ this.listenClientTransfer();
12095
12262
  };
12096
12263
  /**
12097
- * update multiple transactions
12098
- * @param transactions list of transactions for updating
12264
+ * Add new Tax Review (request from client to firm)
12265
+ * @param finYear
12099
12266
  */
12100
- TransactionService.prototype.updateBatch = function (transactions) {
12267
+ TaxReviewService.prototype.request = function (finYear) {
12101
12268
  var _this = this;
12102
- return this.http.put(this.environment.apiV2 + "/" + this.url, transactions)
12103
- .pipe(operators.map(function (response) {
12104
- var updatedTransactions = response.map(function (item) { return classTransformer.plainToClass(Transaction, item); });
12105
- updatedTransactions.forEach(function (updatedTransaction) {
12106
- replace(_this.cache, updatedTransaction);
12107
- });
12269
+ return this.http.post(this.environment.apiV2 + "/" + this.url + "?financialYear=" + finYear, {})
12270
+ .pipe(operators.map(function (newTaxReview) {
12271
+ var taxReview = classTransformer.plainToClass(TaxReview, newTaxReview);
12272
+ var tempCache = ___default["default"].cloneDeep(_this.cache);
12273
+ tempCache.push(taxReview);
12274
+ _this.cache = tempCache;
12108
12275
  _this.updateCache();
12109
- return updatedTransactions;
12276
+ return taxReview;
12110
12277
  }));
12111
12278
  };
12112
12279
  /**
12113
- * delete transaction and related transactions
12114
- * @param model
12280
+ * Update tax review
12281
+ * @param taxReview to be updated
12115
12282
  */
12116
- TransactionService.prototype.delete = function (model) {
12283
+ TaxReviewService.prototype.update = function (taxReview) {
12117
12284
  var _this = this;
12118
- return this.http.delete(this.environment.apiV2 + "/" + this.url + "/" + model.id)
12119
- .pipe(operators.map(function () {
12120
- _this.cache = _this.cache.filter(function (transaction) {
12121
- var _a;
12122
- // when delete transfer we delete actually 2 transactions
12123
- if (model.isTransfer) {
12124
- var ids = [model.id];
12125
- // get id of related transfer transaction
12126
- if (model.transfer) {
12127
- // just take id if we delete source transaction
12128
- ids.push(model.transfer.id);
12129
- }
12130
- else {
12131
- // find source transaction id if we delete destination transaction
12132
- ids.push(_this.cache.find(function (t) { return t.transfer.id === model.id; }).id);
12133
- }
12134
- return !ids.includes(transaction.id);
12135
- }
12136
- return transaction.id !== model.id && ((_a = transaction.parentTransaction) === null || _a === void 0 ? void 0 : _a.id) !== model.id;
12137
- });
12138
- _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TRANSACTION_DELETED, model));
12139
- _this.toastService.success(MessagesEnum.DELETED_MESSAGE);
12285
+ return this.http.put(this.environment.apiV2 + "/" + this.url + "/" + taxReview.id, taxReview)
12286
+ .pipe(operators.map(function (updatedTaxReview) {
12287
+ var updatedInstance = classTransformer.plainToClass(TaxReview, updatedTaxReview);
12288
+ _this.eventDispatcherService.dispatch(new AppEvent(exports.AppEventTypeEnum.TAX_REVIEW_UPDATED, updatedInstance));
12289
+ var tempCache = ___default["default"].cloneDeep(_this.cache);
12290
+ replace(tempCache, updatedInstance);
12291
+ _this.cache = tempCache;
12140
12292
  _this.updateCache();
12141
- _this.transactionDeleted.emit(model);
12293
+ return updatedInstance;
12142
12294
  }));
12143
12295
  };
12144
12296
  /**
12145
- * upload transaction receipt image
12146
- * @param transaction Еhe transaction for which the receipt will be imported
12297
+ * Clear cache when user reject firm
12147
12298
  */
12148
- TransactionService.prototype.uploadReceipt = function (transaction) {
12299
+ TaxReviewService.prototype.listenFirmChanges = function () {
12149
12300
  var _this = this;
12150
- var formData = new FormData();
12151
- formData.append('file', transaction.file);
12152
- transaction.receipt = null;
12153
- this.http.post(this.environment.apiV2 + "/" + this.url + "/" + transaction.id + "/receipts", formData)
12154
- .subscribe(function (receiptResponse) {
12155
- // we don't need to keep file after save
12156
- transaction.file = null;
12157
- transaction.receipt = classTransformer.plainToClass(TransactionReceipt, receiptResponse);
12158
- replace(_this.cache, transaction);
12301
+ this.eventDispatcherService.on([exports.AppEventTypeEnum.CLIENT_MOVEMENT_CLOSED, exports.AppEventTypeEnum.CLIENT_INVITE_ACCEPTED])
12302
+ .subscribe(function () {
12303
+ _this.cache = [];
12159
12304
  _this.updateCache();
12160
12305
  });
12161
12306
  };
12162
12307
  /**
12163
- * calculate gross income amount based on transaction amount and taxes (fees)
12164
- * @param transaction Transaction instance for calculation
12308
+ * Update firm for all transferred clients
12309
+ * @private
12165
12310
  */
12166
- TransactionService.prototype.calculateGrossAmount = function (transaction) {
12167
- var amount = transaction.amount || 0;
12168
- // gross income amount includes amount of fees for property tank and tax for work tank
12169
- if (transaction.isPropertyTank()) {
12170
- amount += transaction.transactions.reduce(function (sum, item) { return sum + item.amount; }, 0);
12171
- }
12172
- else {
12173
- // @TODO Alex: fix logic after TT-641 ready
12174
- amount += (transaction.tax || 0);
12175
- }
12176
- return amount;
12311
+ TaxReviewService.prototype.listenClientTransfer = function () {
12312
+ var _this = this;
12313
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.CLIENT_TRANSFER_TO_OTHER_EMPLOYEE)
12314
+ .subscribe(function (transferredClients) {
12315
+ var tempCache = ___default["default"].cloneDeep(_this.cache);
12316
+ transferredClients.forEach(function (transferredClient) {
12317
+ var taxReviewIndex = tempCache.findIndex(function (taxReview) { return taxReview.id === transferredClient.id; });
12318
+ // @TODO vik
12319
+ // tempCache[taxReviewIndex].employee = transferredClient.accountant;
12320
+ });
12321
+ _this.cache = tempCache;
12322
+ _this.updateCache();
12323
+ });
12177
12324
  };
12178
- /**
12179
- * get label for transaction tax field depended of selected chart account.
12180
- * tax type depends of chart account heading or category.
12181
- */
12182
- TransactionService.prototype.getTaxLabel = function (chartAccounts) {
12183
- var _a, _b;
12184
- // get simple array of ids from enum with taxable chart accounts headings
12185
- var taxableCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxableEnum)
12186
- .map(function (item) { return item.value; });
12187
- // get simple array of ids from enum with tax deductible chart accounts headings
12188
- var deductibleCAHeadingsIds = enumToList(exports.ChartAccountsHeadingTaxDeductibleEnum)
12189
- .map(function (item) { return item.value; });
12190
- // check if one of ids arrays includes current chart accounts heading id and set tax label
12191
- // otherwise label is empty for this class
12192
- switch (true) {
12193
- case taxableCAHeadingsIds.includes((_a = chartAccounts.heading) === null || _a === void 0 ? void 0 : _a.id):
12194
- return exports.ChartAccountsTaxLabelsEnum.TAX_PAID;
12195
- case deductibleCAHeadingsIds.includes((_b = chartAccounts.heading) === null || _b === void 0 ? void 0 : _b.id):
12196
- return exports.ChartAccountsTaxLabelsEnum.TAX_DEDUCTED;
12197
- case CHART_ACCOUNTS_CATEGORIES.workIncome.includes(chartAccounts.category):
12198
- return exports.ChartAccountsTaxLabelsEnum.TAX_WITHHELD;
12199
- default:
12200
- return null;
12201
- }
12325
+ return TaxReviewService;
12326
+ }(RestService));
12327
+ TaxReviewService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
12328
+ TaxReviewService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewService, providedIn: 'root' });
12329
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewService, decorators: [{
12330
+ type: i0.Injectable,
12331
+ args: [{
12332
+ providedIn: 'root'
12333
+ }]
12334
+ }], ctorParameters: function () {
12335
+ return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
12336
+ type: i0.Inject,
12337
+ args: ['environment']
12338
+ }] }];
12339
+ } });
12340
+
12341
+ /**
12342
+ * Service to work with tax review history
12343
+ */
12344
+ var TaxReviewHistoryService = /** @class */ (function (_super) {
12345
+ __extends(TaxReviewHistoryService, _super);
12346
+ function TaxReviewHistoryService(http, eventDispatcherService, environment) {
12347
+ var _this = _super.call(this, http, eventDispatcherService, environment) || this;
12348
+ _this.http = http;
12349
+ _this.eventDispatcherService = eventDispatcherService;
12350
+ _this.environment = environment;
12351
+ _this.url = 'tax-reviews/history';
12352
+ _this.modelClass = TaxReview;
12353
+ // subscribe on tax review updating
12354
+ eventDispatcherService.on(exports.AppEventTypeEnum.TAX_REVIEW_UPDATED).subscribe(function (taxReview) {
12355
+ var tempCache = ___default["default"].cloneDeep(_this.cache);
12356
+ // insert element at the beginning of the array
12357
+ tempCache.unshift(taxReview);
12358
+ _this.cache = tempCache;
12359
+ _this.updateCache();
12360
+ });
12361
+ return _this;
12362
+ }
12363
+ return TaxReviewHistoryService;
12364
+ }(RestService));
12365
+ TaxReviewHistoryService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewHistoryService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
12366
+ TaxReviewHistoryService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewHistoryService, providedIn: 'root' });
12367
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxReviewHistoryService, decorators: [{
12368
+ type: i0.Injectable,
12369
+ args: [{
12370
+ providedIn: 'root'
12371
+ }]
12372
+ }], ctorParameters: function () {
12373
+ return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
12374
+ type: i0.Inject,
12375
+ args: ['environment']
12376
+ }] }];
12377
+ } });
12378
+
12379
+ /**
12380
+ * Service to work with tax summary logic
12381
+ */
12382
+ var TaxSummaryService = /** @class */ (function () {
12383
+ function TaxSummaryService(http, eventDispatcherService, environment) {
12384
+ this.http = http;
12385
+ this.eventDispatcherService = eventDispatcherService;
12386
+ this.environment = environment;
12387
+ this.taxSummaryActualsSubject = new rxjs.ReplaySubject(1);
12388
+ this.taxSummaryForecastsSubject = new rxjs.ReplaySubject(1);
12389
+ this.listenEvents();
12390
+ }
12391
+ TaxSummaryService.prototype.listenEvents = function () {
12392
+ this.listenToIncomeSourceForecastsEvents();
12202
12393
  };
12203
12394
  /**
12204
- * Get transactions related to Vehicle category
12395
+ * Get actual tax summary items
12205
12396
  */
12206
- TransactionService.prototype.getVehicleTransactions = function () {
12207
- return this.get().pipe(operators.map(function (transactions) {
12208
- return transactions.filter(function (transaction) { return transaction.isVehicleTransaction(); });
12209
- }));
12397
+ TaxSummaryService.prototype.getActuals = function () {
12398
+ var _this = this;
12399
+ this.http.get(this.environment.apiV2 + "/tax-summary/" + exports.TaxSummaryTypeEnum.ACTUALS, {})
12400
+ .subscribe(function (response) {
12401
+ var taxSummary = classTransformer.plainToClass(TaxSummary, response);
12402
+ _this.taxSummaryActualsSubject.next(taxSummary);
12403
+ return taxSummary;
12404
+ });
12405
+ return this.taxSummaryActualsSubject.asObservable();
12210
12406
  };
12211
12407
  /**
12212
- * Listen to EventDispatcherService event related to Depreciation changing
12408
+ * Get forecast tax summary items
12213
12409
  */
12214
- TransactionService.prototype.listenDepreciationChange = function () {
12410
+ TaxSummaryService.prototype.getForecast = function () {
12215
12411
  var _this = this;
12216
- this.eventDispatcherService.on(exports.AppEventTypeEnum.DEPRECIATION_DELETED).subscribe(function () {
12217
- _this.fetch()
12218
- .subscribe(function (transactions) {
12219
- _this.cache = transactions;
12220
- _this.updateCache();
12221
- });
12412
+ this.http.get(this.environment.apiV2 + "/tax-summary/" + exports.TaxSummaryTypeEnum.FORECASTS, {})
12413
+ .subscribe(function (response) {
12414
+ var taxSummary = classTransformer.plainToClass(TaxSummary, response);
12415
+ _this.taxSummaryForecastsSubject.next(taxSummary);
12416
+ return taxSummary;
12222
12417
  });
12418
+ return this.taxSummaryForecastsSubject.asObservable();
12223
12419
  };
12224
12420
  /**
12225
- * Listen to EventDispatcherService event related to Property Share changing
12421
+ * Listen to EventDispatcherService events related to Income source forecasts
12226
12422
  */
12227
- TransactionService.prototype.listenPropertyShareUpdate = function () {
12423
+ TaxSummaryService.prototype.listenToIncomeSourceForecastsEvents = function () {
12228
12424
  var _this = this;
12229
- this.eventDispatcherService.on(exports.AppEventTypeEnum.PROPERTY_SHARE_UPDATED).subscribe(function () { return _this.resetCache(); });
12425
+ this.eventDispatcherService
12426
+ .on([exports.AppEventTypeEnum.INCOME_SOURCES_FORECASTS_CREATED, exports.AppEventTypeEnum.INCOME_SOURCES_FORECASTS_UPDATED])
12427
+ .subscribe(function () {
12428
+ _this.getForecast().subscribe();
12429
+ });
12230
12430
  };
12231
- return TransactionService;
12232
- }(RestService));
12233
- TransactionService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }, { token: ToastService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
12234
- TransactionService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, providedIn: 'root' });
12235
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TransactionService, decorators: [{
12431
+ return TaxSummaryService;
12432
+ }());
12433
+ TaxSummaryService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxSummaryService, deps: [{ token: i1__namespace.HttpClient }, { token: EventDispatcherService }, { token: 'environment' }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
12434
+ TaxSummaryService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxSummaryService, providedIn: 'root' });
12435
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: TaxSummaryService, decorators: [{
12236
12436
  type: i0.Injectable,
12237
12437
  args: [{
12238
12438
  providedIn: 'root'
@@ -12241,7 +12441,7 @@
12241
12441
  return [{ type: i1__namespace.HttpClient }, { type: EventDispatcherService }, { type: undefined, decorators: [{
12242
12442
  type: i0.Inject,
12243
12443
  args: ['environment']
12244
- }] }, { type: ToastService }];
12444
+ }] }];
12245
12445
  } });
12246
12446
 
12247
12447
  // @TODO Don't look at the commented code. Will be refactored/removed during TT-1503
@@ -13239,6 +13439,11 @@
13239
13439
  exports.PropertyEquityChartData = PropertyEquityChartData;
13240
13440
  exports.PropertyEquityChartItem = PropertyEquityChartItem;
13241
13441
  exports.PropertyForecast = PropertyForecast;
13442
+ exports.PropertyReportItem = PropertyReportItem;
13443
+ exports.PropertyReportItemCollection = PropertyReportItemCollection;
13444
+ exports.PropertyReportItemDepreciationCollection = PropertyReportItemDepreciationCollection;
13445
+ exports.PropertyReportItemTransaction = PropertyReportItemTransaction;
13446
+ exports.PropertyReportItemTransactionCollection = PropertyReportItemTransactionCollection;
13242
13447
  exports.PropertySale = PropertySale;
13243
13448
  exports.PropertySaleService = PropertySaleService;
13244
13449
  exports.PropertySaleTaxExemptionMetadata = PropertySaleTaxExemptionMetadata;
@@ -13246,6 +13451,7 @@
13246
13451
  exports.PropertyShare = PropertyShare;
13247
13452
  exports.PropertyShareService = PropertyShareService;
13248
13453
  exports.PropertySubscription = PropertySubscription;
13454
+ exports.PropertyTransactionReportService = PropertyTransactionReportService;
13249
13455
  exports.PropertyValuation = PropertyValuation;
13250
13456
  exports.RegisterClientForm = RegisterClientForm;
13251
13457
  exports.RegisterFirmForm = RegisterFirmForm;