taxtank-core 0.28.29 → 0.28.31

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 (39) hide show
  1. package/bundles/taxtank-core.umd.js +592 -455
  2. package/bundles/taxtank-core.umd.js.map +1 -1
  3. package/esm2015/lib/collections/collection.js +23 -1
  4. package/esm2015/lib/collections/index.js +2 -1
  5. package/esm2015/lib/collections/tax-summary/tax-return-categories.const.js +6 -2
  6. package/esm2015/lib/collections/transaction/index.js +4 -0
  7. package/esm2015/lib/collections/transaction/transaction-base.collection.js +8 -0
  8. package/esm2015/lib/db/Models/sole/sole-business-loss-offset-rule.js +4 -0
  9. package/esm2015/lib/db/Models/sole/sole-business-loss.js +1 -1
  10. package/esm2015/lib/forms/sole/index.js +2 -1
  11. package/esm2015/lib/forms/sole/sole-business-loss.form.js +25 -0
  12. package/esm2015/lib/models/endpoint/endpoints.const.js +5 -2
  13. package/esm2015/lib/models/service-subscription/service-subscription.js +14 -1
  14. package/esm2015/lib/models/sole/index.js +2 -1
  15. package/esm2015/lib/models/sole/sole-business-loss-offset-rule.js +9 -0
  16. package/esm2015/lib/models/sole/sole-business-loss.js +12 -1
  17. package/esm2015/lib/models/tax-summary/tax-summary.js +1 -3
  18. package/esm2015/lib/services/http/sole/index.js +2 -1
  19. package/esm2015/lib/services/http/sole/sole-business-loss/sole-business-loss-rules/sole-business-loss-offset-rule.service.js +24 -0
  20. package/esm2015/public-api.js +1 -3
  21. package/fesm2015/taxtank-core.js +450 -341
  22. package/fesm2015/taxtank-core.js.map +1 -1
  23. package/lib/collections/collection.d.ts +7 -0
  24. package/lib/collections/index.d.ts +1 -0
  25. package/lib/collections/transaction/index.d.ts +3 -0
  26. package/lib/collections/transaction/transaction-base.collection.d.ts +6 -0
  27. package/lib/db/Models/sole/sole-business-loss-offset-rule.d.ts +7 -0
  28. package/lib/db/Models/sole/sole-business-loss.d.ts +2 -0
  29. package/lib/forms/sole/index.d.ts +1 -0
  30. package/lib/forms/sole/sole-business-loss.form.d.ts +11 -0
  31. package/lib/models/service-subscription/service-subscription.d.ts +5 -0
  32. package/lib/models/sole/index.d.ts +1 -0
  33. package/lib/models/sole/sole-business-loss-offset-rule.d.ts +4 -0
  34. package/lib/models/sole/sole-business-loss.d.ts +4 -0
  35. package/lib/models/tax-summary/tax-summary.d.ts +0 -2
  36. package/lib/services/http/sole/index.d.ts +1 -0
  37. package/lib/services/http/sole/sole-business-loss/sole-business-loss-rules/sole-business-loss-offset-rule.service.d.ts +13 -0
  38. package/package.json +1 -1
  39. package/public-api.d.ts +0 -2
@@ -1067,7 +1067,10 @@
1067
1067
  SOLE_BUSINESSES_GET: new Endpoint('GET', '\\/sole-businesses'),
1068
1068
  SOLE_BUSINESSES_POST: new Endpoint('POST', '\\/sole-businesses'),
1069
1069
  SOLE_BUSINESSES_PUT: new Endpoint('PUT', '\\/sole-businesses\\/\\d+'),
1070
- SOLE_BUSINESSES_LOSSES_GET: new Endpoint('GET', '\\/sole-business-losses'),
1070
+ SOLE_BUSINESS_LOSSES_GET: new Endpoint('GET', '\\/sole-business-losses'),
1071
+ SOLE_BUSINESS_LOSSES_POST: new Endpoint('POST', '\\/sole-business-losses'),
1072
+ SOLE_BUSINESS_LOSSES_PUT: new Endpoint('PUT', '\\/sole-business-losses\\/\\d+'),
1073
+ SOLE_BUSINESS_LOSS_OFFSET_RULES_GET: new Endpoint('GET', '\\/sole-business-loss-offset-rules'),
1071
1074
  SOLE_CONTACTS_POST: new Endpoint('POST', '\\/sole-contacts'),
1072
1075
  SOLE_CONTACTS_PUT: new Endpoint('PUT', '\\/sole-contacts\\/\\d+'),
1073
1076
  BUSINESS_ACTIVITIES_GET: new Endpoint('GET', '\\/sole-business-activities'),
@@ -1815,6 +1818,10 @@
1815
1818
  var Collection = /** @class */ (function () {
1816
1819
  function Collection(items) {
1817
1820
  if (items === void 0) { items = []; }
1821
+ /**
1822
+ * index of current item, used to iterate over the collection
1823
+ */
1824
+ this.index = 0;
1818
1825
  this.items = items;
1819
1826
  }
1820
1827
  /**
@@ -1851,6 +1858,24 @@
1851
1858
  enumerable: false,
1852
1859
  configurable: true
1853
1860
  });
1861
+ Collection.prototype.reset = function () {
1862
+ this.index = 0;
1863
+ return this.items[this.index];
1864
+ };
1865
+ Collection.prototype.next = function () {
1866
+ if (this.index < this.length) {
1867
+ this.index++;
1868
+ return this.items[this.index];
1869
+ }
1870
+ return null;
1871
+ };
1872
+ Collection.prototype.back = function () {
1873
+ if (this.index > 0) {
1874
+ this.index--;
1875
+ return this.items[this.index];
1876
+ }
1877
+ return null;
1878
+ };
1854
1879
  Collection.prototype.getIds = function () {
1855
1880
  return this.items.map(function (item) { return item['id']; });
1856
1881
  };
@@ -2667,6 +2692,19 @@
2667
2692
  ServiceSubscription.prototype.hasItem = function (itemToCheck) {
2668
2693
  return !!this.items.find(function (item) { return item.price.id === itemToCheck.price.id; });
2669
2694
  };
2695
+ /**
2696
+ * Recommended number of properties to buy,
2697
+ * based on the property service product and the number of properties the user has
2698
+ */
2699
+ ServiceSubscription.prototype.getRecommendedPropertiesQty = function (propertyItem, propertiesQty) {
2700
+ var max = propertyItem.price.product.maxQty;
2701
+ var min = propertyItem.price.product.minQty;
2702
+ // if user has property subscription and number of properties doesn't exceed the maximum in the service product - return one more
2703
+ if (this.hasItem(propertyItem)) {
2704
+ propertiesQty = propertiesQty < max ? propertiesQty + 1 : max;
2705
+ }
2706
+ return Math.max(min, propertiesQty);
2707
+ };
2670
2708
  return ServiceSubscription;
2671
2709
  }(ServiceSubscription$1));
2672
2710
  __decorate([
@@ -2717,16 +2755,47 @@
2717
2755
  return SoleBusinessLoss;
2718
2756
  }(AbstractModel));
2719
2757
 
2758
+ var SoleBusinessLossOffsetRule$1 = /** @class */ (function (_super) {
2759
+ __extends(SoleBusinessLossOffsetRule, _super);
2760
+ function SoleBusinessLossOffsetRule() {
2761
+ return _super !== null && _super.apply(this, arguments) || this;
2762
+ }
2763
+ return SoleBusinessLossOffsetRule;
2764
+ }(AbstractModel));
2765
+
2766
+ var SoleBusinessLossOffsetRule = /** @class */ (function (_super) {
2767
+ __extends(SoleBusinessLossOffsetRule, _super);
2768
+ function SoleBusinessLossOffsetRule() {
2769
+ return _super !== null && _super.apply(this, arguments) || this;
2770
+ }
2771
+ return SoleBusinessLossOffsetRule;
2772
+ }(SoleBusinessLossOffsetRule$1));
2773
+ __decorate([
2774
+ classTransformer.Type(function () { return SoleBusinessLossOffsetRule; })
2775
+ ], SoleBusinessLossOffsetRule.prototype, "parent", void 0);
2776
+
2720
2777
  var SoleBusinessLoss = /** @class */ (function (_super) {
2721
2778
  __extends(SoleBusinessLoss, _super);
2722
2779
  function SoleBusinessLoss() {
2723
- return _super !== null && _super.apply(this, arguments) || this;
2780
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
2781
+ _this.openBalance = 0;
2782
+ return _this;
2724
2783
  }
2784
+ Object.defineProperty(SoleBusinessLoss.prototype, "hasOffset", {
2785
+ get: function () {
2786
+ return !!this.offsetRule;
2787
+ },
2788
+ enumerable: false,
2789
+ configurable: true
2790
+ });
2725
2791
  return SoleBusinessLoss;
2726
2792
  }(SoleBusinessLoss$1));
2727
2793
  __decorate([
2728
2794
  classTransformer.Type(function () { return SoleBusiness; })
2729
2795
  ], SoleBusinessLoss.prototype, "business", void 0);
2796
+ __decorate([
2797
+ classTransformer.Type(function () { return SoleBusinessLossOffsetRule; })
2798
+ ], SoleBusinessLoss.prototype, "offsetRule", void 0);
2730
2799
 
2731
2800
  var SoleInvoice$1 = /** @class */ (function (_super) {
2732
2801
  __extends(SoleInvoice, _super);
@@ -7132,155 +7201,482 @@
7132
7201
  return PropertyCategoryMovementCollection;
7133
7202
  }(Collection));
7134
7203
 
7135
- // @TODO Alex move here all collections
7136
-
7137
- var AccountSetupItemCollection = /** @class */ (function (_super) {
7138
- __extends(AccountSetupItemCollection, _super);
7139
- function AccountSetupItemCollection(items) {
7140
- var _this = _super.call(this, compact__default["default"](items)) || this;
7141
- _this.sortBy('isCompleted', false);
7142
- return _this;
7204
+ /**
7205
+ * Chart serie class: chart data item
7206
+ * @TODO consider rename to ChartSerieData
7207
+ */
7208
+ var ChartSerie = /** @class */ (function () {
7209
+ function ChartSerie() {
7143
7210
  }
7144
- AccountSetupItemCollection.prototype.isCompleted = function () {
7145
- return this.filterBy('isCompleted', true).length === this.length;
7146
- };
7147
- return AccountSetupItemCollection;
7148
- }(Collection));
7211
+ return ChartSerie;
7212
+ }());
7149
7213
 
7150
7214
  /**
7151
- * Maximal delay between transfer transactions
7215
+ * Chart data class
7216
+ * @TODO consider rename to ChartSerie
7152
7217
  */
7153
- var TRANSACTION_TRANSFER_DELAY = 96 * 3600 * 1000;
7218
+ var ChartData = /** @class */ (function () {
7219
+ function ChartData() {
7220
+ }
7221
+ return ChartData;
7222
+ }());
7223
+ __decorate([
7224
+ classTransformer.Type(function () { return ChartSerie; })
7225
+ ], ChartData.prototype, "data", void 0);
7226
+
7227
+ var MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan'];
7228
+
7154
7229
  /**
7155
- * Collection of bank transactions.
7156
- * IMPORTANT: Create this collection based on bank transactions from TransactionAllocationService
7157
- * @TODO find way to accept interface with allocation instead of bankTransaction to prevent wrong usage
7158
- * because all amounts calculates with allocated amounts but not from bank transactions amounts.
7230
+ * Collection of transactions
7159
7231
  */
7160
- var BankTransactionCollection = /** @class */ (function (_super) {
7161
- __extends(BankTransactionCollection, _super);
7162
- function BankTransactionCollection() {
7232
+ var TransactionCollection = /** @class */ (function (_super) {
7233
+ __extends(TransactionCollection, _super);
7234
+ function TransactionCollection() {
7163
7235
  return _super !== null && _super.apply(this, arguments) || this;
7164
7236
  }
7165
- BankTransactionCollection.prototype.getAmount = function () {
7166
- return this.sumBy('amount');
7167
- };
7168
- /**
7169
- * Difference between total bank transactions amount and sum of allocations for passed bank transactions
7170
- */
7171
- BankTransactionCollection.prototype.getUnallocatedAmount = function (allocations) {
7172
- return +(this.getAmount() - allocations.getByBankTransactionsIds(this.getIds()).amount).toFixed(2);
7173
- };
7237
+ Object.defineProperty(TransactionCollection.prototype, "amount", {
7238
+ /**
7239
+ * Get total amount of all transactions in the collection
7240
+ */
7241
+ get: function () {
7242
+ return +this.items.reduce(function (sum, transaction) { return sum + transaction.getNetAmount(); }, 0).toFixed(2);
7243
+ },
7244
+ enumerable: false,
7245
+ configurable: true
7246
+ });
7174
7247
  /**
7175
- * get date of the last transaction
7248
+ * Difference between allocated amount and total amount
7176
7249
  */
7177
- BankTransactionCollection.prototype.getLastTransactionDate = function () {
7178
- return new Date(Math.max.apply(Math, this.items.map(function (bankTransaction) { return bankTransaction.date; })));
7250
+ TransactionCollection.prototype.getUnallocatedAmount = function (allocations) {
7251
+ return +(this.amount - allocations.getByTransactionsIds(this.getIds()).amount).toFixed(2);
7179
7252
  };
7180
- Object.defineProperty(BankTransactionCollection.prototype, "creditTransactions", {
7253
+ Object.defineProperty(TransactionCollection.prototype, "cashPosition", {
7181
7254
  /**
7182
- * get list of credit transactions
7255
+ * Get cash position
7256
+ * Cash Position = Income - Expenses
7257
+ * Cash position is equal to Total Amount because income is positive and expense is negative,
7183
7258
  */
7184
7259
  get: function () {
7185
- return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return bankTransaction.isCredit(); }));
7260
+ return this.claimAmount;
7186
7261
  },
7187
7262
  enumerable: false,
7188
7263
  configurable: true
7189
7264
  });
7190
- Object.defineProperty(BankTransactionCollection.prototype, "debitTransactions", {
7265
+ /**
7266
+ * get date of the last transaction
7267
+ */
7268
+ TransactionCollection.prototype.getLastTransactionDate = function () {
7269
+ return new Date(Math.max.apply(Math, this.items.map(function (transaction) { return transaction.date; })));
7270
+ };
7271
+ Object.defineProperty(TransactionCollection.prototype, "claimAmount", {
7191
7272
  /**
7192
- * get list of debit transactions
7273
+ * Get summary of claim amounts
7193
7274
  */
7194
7275
  get: function () {
7195
- return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return bankTransaction.isDebit(); }));
7276
+ return this.items.reduce(function (sum, transaction) { return sum + transaction.claimAmount; }, 0);
7196
7277
  },
7197
7278
  enumerable: false,
7198
7279
  configurable: true
7199
7280
  });
7200
- Object.defineProperty(BankTransactionCollection.prototype, "balanceAmount", {
7201
- /**
7202
- * get difference between debit and credit transactions amounts
7203
- */
7281
+ Object.defineProperty(TransactionCollection.prototype, "grossAmount", {
7204
7282
  get: function () {
7205
- return this.items.reduce(function (sum, bankTransaction) { return sum + bankTransaction.balanceAmount; }, 0);
7283
+ return +this.items.reduce(function (sum, transaction) { return sum + transaction.amount; }, 0).toFixed(2);
7206
7284
  },
7207
7285
  enumerable: false,
7208
7286
  configurable: true
7209
7287
  });
7288
+ TransactionCollection.prototype.getByChartAccountsCategories = function (categories) {
7289
+ return new TransactionCollection(this.items.filter(function (transaction) { return categories.includes(transaction.chartAccounts.category); }));
7290
+ };
7210
7291
  /**
7211
- * get list of transactions for passed month
7212
- * @param monthIndex Month number from 0 to 11
7292
+ * Get transactions by month
7293
+ * @param monthIndex by which desired month should be taken
7213
7294
  */
7214
- BankTransactionCollection.prototype.getTransactionsByMonth = function (monthIndex) {
7215
- return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return bankTransaction.date.getMonth() === monthIndex; }));
7295
+ TransactionCollection.prototype.getByMonth = function (monthIndex) {
7296
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.date.getMonth() === monthIndex; }));
7216
7297
  };
7217
7298
  /**
7218
- * get list of transactions by provided bank accounts
7219
- * @param bankAccounts by which transactions should be returned
7299
+ * Get collection of transactions metadata
7220
7300
  */
7221
- BankTransactionCollection.prototype.getByBankAccounts = function (bankAccounts) {
7222
- var bankAccountIds = bankAccounts.map(function (bankAccount) { return bankAccount.id; });
7223
- return this.items.filter(function (bankTransaction) { return bankAccountIds.includes(bankTransaction.bankAccount.id); });
7301
+ TransactionCollection.prototype.getTransactionsMetadata = function () {
7302
+ var metadataArray = [];
7303
+ this.items.forEach(function (transaction) {
7304
+ metadataArray.push.apply(metadataArray, __spreadArray([], __read(transaction.metadata)));
7305
+ });
7306
+ return new Collection(metadataArray);
7307
+ };
7308
+ TransactionCollection.prototype.getIncomeTransactions = function () {
7309
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isIncome(); }));
7310
+ };
7311
+ Object.defineProperty(TransactionCollection.prototype, "claimIncome", {
7312
+ get: function () {
7313
+ return this.getIncomeTransactions().claimAmount;
7314
+ },
7315
+ enumerable: false,
7316
+ configurable: true
7317
+ });
7318
+ TransactionCollection.prototype.getExpenseTransactions = function () {
7319
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isExpense() && !transaction.isInterest(); }));
7320
+ };
7321
+ Object.defineProperty(TransactionCollection.prototype, "claimExpense", {
7322
+ get: function () {
7323
+ return this.getExpenseTransactions().claimAmount;
7324
+ },
7325
+ enumerable: false,
7326
+ configurable: true
7327
+ });
7328
+ TransactionCollection.prototype.getInterestTransactions = function () {
7329
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isInterest(); }));
7224
7330
  };
7331
+ Object.defineProperty(TransactionCollection.prototype, "claimInterest", {
7332
+ get: function () {
7333
+ return this.getInterestTransactions().claimAmount;
7334
+ },
7335
+ enumerable: false,
7336
+ configurable: true
7337
+ });
7225
7338
  /**
7226
- * get list of transactions by provided ids of bank accounts
7227
- * @param ids of bank accounts
7339
+ * Get collection of transactions and properties filtered by properties ids
7340
+ * @param ids Ids of properties for filter
7228
7341
  */
7229
- BankTransactionCollection.prototype.getByBankAccountsIds = function (ids) {
7230
- return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return ids.includes(bankTransaction.bankAccount.id); }));
7342
+ TransactionCollection.prototype.getByPropertiesIds = function (ids) {
7343
+ return new TransactionCollection(this.items.filter(function (transaction) {
7344
+ var _a;
7345
+ return ids.includes((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id);
7346
+ }));
7231
7347
  };
7232
7348
  /**
7233
- * Find Bank Transaction available for transfer
7349
+ * Get new collection filtered by income source id
7350
+ * @param id id of income source for filter
7234
7351
  */
7235
- BankTransactionCollection.prototype.findTransfer = function (bankTransaction) {
7236
- return this.items.find(function (item) {
7237
- return item.amount + bankTransaction.amount === 0 &&
7238
- Math.abs(bankTransaction.date.getTime() - item.date.getTime()) < TRANSACTION_TRANSFER_DELAY;
7239
- });
7352
+ TransactionCollection.prototype.getByIncomeSourceId = function (id) {
7353
+ return new TransactionCollection(this.items.filter(function (transaction) { var _a; return ((_a = transaction.incomeSource) === null || _a === void 0 ? void 0 : _a.id) === id; }));
7240
7354
  };
7241
7355
  /**
7242
- * Group bank transactions by transaction id.
7243
- * Each group is bank transaction collection and contains bank transactions related to transactions via allocations
7356
+ * Get new collection filtered by chart accounts category
7357
+ * @param category Chart accounts category value
7244
7358
  */
7245
- BankTransactionCollection.prototype.groupByTransaction = function (allocations) {
7246
- var _this = this;
7247
- // Group allocations by transaction id
7248
- var allocationsByTransactions = new CollectionDictionary(allocations, 'transaction.id');
7249
- // Init an empty dictionary we will fill below
7250
- var bankTransactionsByTransactions = new CollectionDictionary(new BankTransactionCollection([]));
7251
- // Fill dictionary with the same keys as at allocationsByTransactions
7252
- allocationsByTransactions.keys.forEach(function (key) {
7253
- bankTransactionsByTransactions.add(key, _this.getByAllocations(allocationsByTransactions.get(key)));
7254
- });
7255
- return bankTransactionsByTransactions;
7359
+ TransactionCollection.prototype.getByChartAccountsCategory = function (category) {
7360
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.chartAccounts.category === category; }));
7256
7361
  };
7257
7362
  /**
7258
- * Get collection of bank transactions related with passed allocations
7363
+ * Get new collection of property transactions
7259
7364
  */
7260
- BankTransactionCollection.prototype.getByAllocations = function (allocations) {
7261
- return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return allocations.hasBankTransaction(bankTransaction); }));
7365
+ TransactionCollection.prototype.getPropertyTransactions = function () {
7366
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isPropertyTank(); }));
7367
+ };
7368
+ TransactionCollection.prototype.getDebitTransactions = function () {
7369
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isDebit(); }));
7370
+ };
7371
+ TransactionCollection.prototype.getCreditTransactions = function () {
7372
+ return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isCredit(); }));
7373
+ };
7374
+ TransactionCollection.prototype.getByAllocations = function (allocations) {
7375
+ return new TransactionCollection(this.items.filter(function (transaction) { return allocations.hasTransaction(transaction); }));
7262
7376
  };
7263
7377
  /**
7264
- * Set allocate operation for bank transactions with amounts equal to salary
7378
+ * Get transactions related to Vehicle category
7265
7379
  */
7266
- BankTransactionCollection.prototype.preselectAllocateOperationForSalary = function (salaryIncomeSources) {
7267
- // incomeSource.salaryForecasts[0] because each income source has only one forecast for current fin year
7268
- var salaryAmounts = salaryIncomeSources.map(function (incomeSource) { var _a; return ((_a = incomeSource.salaryForecasts[0]) === null || _a === void 0 ? void 0 : _a.netPay) || 0; });
7269
- this.items.forEach(function (bankTransaction) {
7270
- if (salaryAmounts.includes(bankTransaction.amount)) {
7271
- bankTransaction.operation = exports.TransactionOperationEnum.ALLOCATE;
7272
- }
7273
- });
7380
+ TransactionCollection.prototype.getVehicleTransactions = function () {
7381
+ return this.create(this.items.filter(function (transaction) {
7382
+ return transaction.isVehicleTransaction();
7383
+ }));
7274
7384
  };
7275
7385
  /**
7276
- * Get collection of unallocated bankTransactions
7386
+ * Get new transaction collection filtered by tank type
7277
7387
  */
7278
- BankTransactionCollection.prototype.getUnallocated = function (allocations) {
7279
- return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return !bankTransaction.isAllocated(allocations); }));
7280
- };
7281
- return BankTransactionCollection;
7282
- }(Collection));
7283
-
7388
+ TransactionCollection.prototype.getByTankType = function (tankType) {
7389
+ return this.create(this.items.filter(function (transaction) {
7390
+ switch (tankType) {
7391
+ case exports.TankTypeEnum.PROPERTY:
7392
+ return transaction.isPropertyTank();
7393
+ case exports.TankTypeEnum.WORK:
7394
+ return transaction.isWorkTank();
7395
+ case exports.TankTypeEnum.SOLE:
7396
+ return transaction.isSoleTank();
7397
+ // Transaction may be not related to any tank type (personal)
7398
+ default:
7399
+ return false;
7400
+ }
7401
+ }));
7402
+ };
7403
+ TransactionCollection.prototype.getExportHeader = function () {
7404
+ return ['Date', 'Description', 'Debit', 'Credit'];
7405
+ };
7406
+ TransactionCollection.prototype.getExportFooter = function () {
7407
+ return [
7408
+ classTransformer.plainToClass(ExportCell, { value: 'Total', type: ExportCellTypeEnum.STRING }),
7409
+ classTransformer.plainToClass(ExportCell, { value: '', type: ExportCellTypeEnum.STRING }),
7410
+ classTransformer.plainToClass(ExportCell, { value: this.sumBy('debit'), type: ExportCellTypeEnum.CURRENCY }),
7411
+ classTransformer.plainToClass(ExportCell, { value: this.sumBy('credit'), type: ExportCellTypeEnum.CURRENCY })
7412
+ ];
7413
+ };
7414
+ TransactionCollection.prototype.getExportBody = function () {
7415
+ return this.items.map(function (transaction) {
7416
+ return [
7417
+ classTransformer.plainToClass(ExportCell, { value: transaction.date, type: ExportCellTypeEnum.DATE }),
7418
+ classTransformer.plainToClass(ExportCell, { value: transaction.description, type: ExportCellTypeEnum.STRING }),
7419
+ classTransformer.plainToClass(ExportCell, { value: transaction.debit, type: ExportCellTypeEnum.CURRENCY }),
7420
+ classTransformer.plainToClass(ExportCell, { value: transaction.credit, type: ExportCellTypeEnum.CURRENCY })
7421
+ ];
7422
+ });
7423
+ };
7424
+ /**
7425
+ * Get list of vehicle transactions filtered by vehicle claim
7426
+ */
7427
+ TransactionCollection.prototype.getByVehicleClaim = function (vehicleClaim) {
7428
+ if (!vehicleClaim) {
7429
+ return this.create([]);
7430
+ }
7431
+ return vehicleClaim.isSoleTank()
7432
+ // sole tank may have multiple vehicle claims, so we need to filter by business.id
7433
+ ? this.getVehicleTransactions().filterBy('business.id', vehicleClaim.business.id)
7434
+ // work tank may have only one vehicle claim, so we need to filter by tank type
7435
+ : this.getVehicleTransactions().filterBy('tankType', exports.TankTypeEnum.WORK);
7436
+ };
7437
+ /**
7438
+ * Get list of vehicle transactions except KMS transactions
7439
+ */
7440
+ TransactionCollection.prototype.getLogbookTransactions = function () {
7441
+ return this
7442
+ .getVehicleTransactions()
7443
+ .removeBy('chartAccounts.id', [exports.ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK, exports.ChartAccountsListEnum.KLMS_TRAVELLED]);
7444
+ };
7445
+ /**
7446
+ * Build chart data with transactions cash position.
7447
+ * Cash position = Income - Expenses (include depreciations)
7448
+ * Chart data for each month from fin year start till current month
7449
+ */
7450
+ TransactionCollection.prototype.getCashPositionChartData = function () {
7451
+ var _this = this;
7452
+ var chartData = [
7453
+ classTransformer.plainToClass(ChartData, { name: 'Income', data: [] }),
7454
+ classTransformer.plainToClass(ChartData, { name: 'Expense', data: [] })
7455
+ ];
7456
+ new FinancialYear().getPastMonths().forEach(function (month) {
7457
+ chartData[0].data.push({
7458
+ label: MONTHS[month],
7459
+ value: _this.getIncomeTransactions().getByMonth(month).claimAmount
7460
+ });
7461
+ chartData[1].data.push({
7462
+ label: MONTHS[month],
7463
+ value: Math.abs(_this.getExpenseTransactions().getByMonth(month).claimAmount)
7464
+ });
7465
+ });
7466
+ return chartData;
7467
+ };
7468
+ return TransactionCollection;
7469
+ }(ExportableCollection));
7470
+
7471
+ var TransactionAllocationCollection = /** @class */ (function (_super) {
7472
+ __extends(TransactionAllocationCollection, _super);
7473
+ function TransactionAllocationCollection() {
7474
+ return _super !== null && _super.apply(this, arguments) || this;
7475
+ }
7476
+ Object.defineProperty(TransactionAllocationCollection.prototype, "amount", {
7477
+ get: function () {
7478
+ return this.sumBy('amount');
7479
+ },
7480
+ enumerable: false,
7481
+ configurable: true
7482
+ });
7483
+ TransactionAllocationCollection.prototype.getByTransactionsIds = function (ids) {
7484
+ return new TransactionAllocationCollection(this.items.filter(function (allocation) { return ids.includes(allocation.transaction.id); }));
7485
+ };
7486
+ TransactionAllocationCollection.prototype.getByBankTransactionsIds = function (ids) {
7487
+ return new TransactionAllocationCollection(this.items.filter(function (allocation) { return ids.includes(allocation.bankTransaction.id); }));
7488
+ };
7489
+ /**
7490
+ * Group allocations by bank account via bank transactions collection
7491
+ */
7492
+ TransactionAllocationCollection.prototype.groupByBankAccount = function (bankTransactions) {
7493
+ var _this = this;
7494
+ // Group bank transactions by bank account id
7495
+ var bankTransactionsByBankAccount = new CollectionDictionary(bankTransactions, 'bankAccount.id');
7496
+ // Create empty dictionary of transaction allocations
7497
+ var allocationsByBankAccount = new CollectionDictionary(new TransactionAllocationCollection([]));
7498
+ // Fill allocations dictionary with bank transactions dictionary keys and allocations related with each bank transaction collection
7499
+ bankTransactionsByBankAccount.keys.forEach(function (key) {
7500
+ allocationsByBankAccount.add(key, _this.getByBankTransactionsIds(bankTransactionsByBankAccount.get(key).getIds()));
7501
+ });
7502
+ return allocationsByBankAccount;
7503
+ };
7504
+ /**
7505
+ * check if collection includes allocation of passed transaction
7506
+ */
7507
+ TransactionAllocationCollection.prototype.hasTransaction = function (transaction) {
7508
+ return !!this.items.find(function (allocation) { return allocation.transaction.id === transaction.id; });
7509
+ };
7510
+ /**
7511
+ * Check if bank transaction is related with current allocations
7512
+ */
7513
+ TransactionAllocationCollection.prototype.hasBankTransaction = function (bankTransaction) {
7514
+ return !!this.items.find(function (allocation) { return allocation.bankTransaction.id === bankTransaction.id; });
7515
+ };
7516
+ return TransactionAllocationCollection;
7517
+ }(Collection));
7518
+
7519
+ var TransactionBaseCollection = /** @class */ (function (_super) {
7520
+ __extends(TransactionBaseCollection, _super);
7521
+ function TransactionBaseCollection() {
7522
+ return _super !== null && _super.apply(this, arguments) || this;
7523
+ }
7524
+ TransactionBaseCollection.prototype.getClaimAmountByBusiness = function (business) {
7525
+ return this.filterBy('business.id', business.id)
7526
+ .sumBy('claimAmount');
7527
+ };
7528
+ return TransactionBaseCollection;
7529
+ }(Collection));
7530
+
7531
+ // @TODO Alex move here all collections
7532
+
7533
+ var AccountSetupItemCollection = /** @class */ (function (_super) {
7534
+ __extends(AccountSetupItemCollection, _super);
7535
+ function AccountSetupItemCollection(items) {
7536
+ var _this = _super.call(this, compact__default["default"](items)) || this;
7537
+ _this.sortBy('isCompleted', false);
7538
+ return _this;
7539
+ }
7540
+ AccountSetupItemCollection.prototype.isCompleted = function () {
7541
+ return this.filterBy('isCompleted', true).length === this.length;
7542
+ };
7543
+ return AccountSetupItemCollection;
7544
+ }(Collection));
7545
+
7546
+ /**
7547
+ * Maximal delay between transfer transactions
7548
+ */
7549
+ var TRANSACTION_TRANSFER_DELAY = 96 * 3600 * 1000;
7550
+ /**
7551
+ * Collection of bank transactions.
7552
+ * IMPORTANT: Create this collection based on bank transactions from TransactionAllocationService
7553
+ * @TODO find way to accept interface with allocation instead of bankTransaction to prevent wrong usage
7554
+ * because all amounts calculates with allocated amounts but not from bank transactions amounts.
7555
+ */
7556
+ var BankTransactionCollection = /** @class */ (function (_super) {
7557
+ __extends(BankTransactionCollection, _super);
7558
+ function BankTransactionCollection() {
7559
+ return _super !== null && _super.apply(this, arguments) || this;
7560
+ }
7561
+ BankTransactionCollection.prototype.getAmount = function () {
7562
+ return this.sumBy('amount');
7563
+ };
7564
+ /**
7565
+ * Difference between total bank transactions amount and sum of allocations for passed bank transactions
7566
+ */
7567
+ BankTransactionCollection.prototype.getUnallocatedAmount = function (allocations) {
7568
+ return +(this.getAmount() - allocations.getByBankTransactionsIds(this.getIds()).amount).toFixed(2);
7569
+ };
7570
+ /**
7571
+ * get date of the last transaction
7572
+ */
7573
+ BankTransactionCollection.prototype.getLastTransactionDate = function () {
7574
+ return new Date(Math.max.apply(Math, this.items.map(function (bankTransaction) { return bankTransaction.date; })));
7575
+ };
7576
+ Object.defineProperty(BankTransactionCollection.prototype, "creditTransactions", {
7577
+ /**
7578
+ * get list of credit transactions
7579
+ */
7580
+ get: function () {
7581
+ return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return bankTransaction.isCredit(); }));
7582
+ },
7583
+ enumerable: false,
7584
+ configurable: true
7585
+ });
7586
+ Object.defineProperty(BankTransactionCollection.prototype, "debitTransactions", {
7587
+ /**
7588
+ * get list of debit transactions
7589
+ */
7590
+ get: function () {
7591
+ return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return bankTransaction.isDebit(); }));
7592
+ },
7593
+ enumerable: false,
7594
+ configurable: true
7595
+ });
7596
+ Object.defineProperty(BankTransactionCollection.prototype, "balanceAmount", {
7597
+ /**
7598
+ * get difference between debit and credit transactions amounts
7599
+ */
7600
+ get: function () {
7601
+ return this.items.reduce(function (sum, bankTransaction) { return sum + bankTransaction.balanceAmount; }, 0);
7602
+ },
7603
+ enumerable: false,
7604
+ configurable: true
7605
+ });
7606
+ /**
7607
+ * get list of transactions for passed month
7608
+ * @param monthIndex Month number from 0 to 11
7609
+ */
7610
+ BankTransactionCollection.prototype.getTransactionsByMonth = function (monthIndex) {
7611
+ return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return bankTransaction.date.getMonth() === monthIndex; }));
7612
+ };
7613
+ /**
7614
+ * get list of transactions by provided bank accounts
7615
+ * @param bankAccounts by which transactions should be returned
7616
+ */
7617
+ BankTransactionCollection.prototype.getByBankAccounts = function (bankAccounts) {
7618
+ var bankAccountIds = bankAccounts.map(function (bankAccount) { return bankAccount.id; });
7619
+ return this.items.filter(function (bankTransaction) { return bankAccountIds.includes(bankTransaction.bankAccount.id); });
7620
+ };
7621
+ /**
7622
+ * get list of transactions by provided ids of bank accounts
7623
+ * @param ids of bank accounts
7624
+ */
7625
+ BankTransactionCollection.prototype.getByBankAccountsIds = function (ids) {
7626
+ return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return ids.includes(bankTransaction.bankAccount.id); }));
7627
+ };
7628
+ /**
7629
+ * Find Bank Transaction available for transfer
7630
+ */
7631
+ BankTransactionCollection.prototype.findTransfer = function (bankTransaction) {
7632
+ return this.items.find(function (item) {
7633
+ return item.amount + bankTransaction.amount === 0 &&
7634
+ Math.abs(bankTransaction.date.getTime() - item.date.getTime()) < TRANSACTION_TRANSFER_DELAY;
7635
+ });
7636
+ };
7637
+ /**
7638
+ * Group bank transactions by transaction id.
7639
+ * Each group is bank transaction collection and contains bank transactions related to transactions via allocations
7640
+ */
7641
+ BankTransactionCollection.prototype.groupByTransaction = function (allocations) {
7642
+ var _this = this;
7643
+ // Group allocations by transaction id
7644
+ var allocationsByTransactions = new CollectionDictionary(allocations, 'transaction.id');
7645
+ // Init an empty dictionary we will fill below
7646
+ var bankTransactionsByTransactions = new CollectionDictionary(new BankTransactionCollection([]));
7647
+ // Fill dictionary with the same keys as at allocationsByTransactions
7648
+ allocationsByTransactions.keys.forEach(function (key) {
7649
+ bankTransactionsByTransactions.add(key, _this.getByAllocations(allocationsByTransactions.get(key)));
7650
+ });
7651
+ return bankTransactionsByTransactions;
7652
+ };
7653
+ /**
7654
+ * Get collection of bank transactions related with passed allocations
7655
+ */
7656
+ BankTransactionCollection.prototype.getByAllocations = function (allocations) {
7657
+ return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return allocations.hasBankTransaction(bankTransaction); }));
7658
+ };
7659
+ /**
7660
+ * Set allocate operation for bank transactions with amounts equal to salary
7661
+ */
7662
+ BankTransactionCollection.prototype.preselectAllocateOperationForSalary = function (salaryIncomeSources) {
7663
+ // incomeSource.salaryForecasts[0] because each income source has only one forecast for current fin year
7664
+ var salaryAmounts = salaryIncomeSources.map(function (incomeSource) { var _a; return ((_a = incomeSource.salaryForecasts[0]) === null || _a === void 0 ? void 0 : _a.netPay) || 0; });
7665
+ this.items.forEach(function (bankTransaction) {
7666
+ if (salaryAmounts.includes(bankTransaction.amount)) {
7667
+ bankTransaction.operation = exports.TransactionOperationEnum.ALLOCATE;
7668
+ }
7669
+ });
7670
+ };
7671
+ /**
7672
+ * Get collection of unallocated bankTransactions
7673
+ */
7674
+ BankTransactionCollection.prototype.getUnallocated = function (allocations) {
7675
+ return new BankTransactionCollection(this.items.filter(function (bankTransaction) { return !bankTransaction.isAllocated(allocations); }));
7676
+ };
7677
+ return BankTransactionCollection;
7678
+ }(Collection));
7679
+
7284
7680
  var ChartAccountsCollection = /** @class */ (function (_super) {
7285
7681
  __extends(ChartAccountsCollection, _super);
7286
7682
  function ChartAccountsCollection() {
@@ -7497,330 +7893,63 @@
7497
7893
  }
7498
7894
  Object.defineProperty(ClientPortfolioReportCollection.prototype, "marketValue", {
7499
7895
  get: function () {
7500
- return this.sumBy('marketValue');
7501
- },
7502
- enumerable: false,
7503
- configurable: true
7504
- });
7505
- Object.defineProperty(ClientPortfolioReportCollection.prototype, "loanBalance", {
7506
- get: function () {
7507
- return this.sumBy('loanBalance');
7508
- },
7509
- enumerable: false,
7510
- configurable: true
7511
- });
7512
- Object.defineProperty(ClientPortfolioReportCollection.prototype, "equityPosition", {
7513
- get: function () {
7514
- return this.sumBy('equityPosition');
7515
- },
7516
- enumerable: false,
7517
- configurable: true
7518
- });
7519
- Object.defineProperty(ClientPortfolioReportCollection.prototype, "averageMarketValue", {
7520
- /**
7521
- * Get average market value if there are more than 1 item in the collection
7522
- */
7523
- get: function () {
7524
- return this.items.length > 1 ? this.marketValue / this.items.length : null;
7525
- },
7526
- enumerable: false,
7527
- configurable: true
7528
- });
7529
- Object.defineProperty(ClientPortfolioReportCollection.prototype, "averageLoanBalance", {
7530
- /**
7531
- * Get average loan balance if there are more than 1 item in the collection
7532
- */
7533
- get: function () {
7534
- return this.items.length > 1 ? this.loanBalance / this.items.length : null;
7535
- },
7536
- enumerable: false,
7537
- configurable: true
7538
- });
7539
- Object.defineProperty(ClientPortfolioReportCollection.prototype, "averageEquityPosition", {
7540
- /**
7541
- * Get average equity position if there are more than 1 item in the collection
7542
- */
7543
- get: function () {
7544
- return this.items.length > 1 ? this.equityPosition / this.items.length : null;
7545
- },
7546
- enumerable: false,
7547
- configurable: true
7548
- });
7549
- /**
7550
- * Return report by provided category name
7551
- */
7552
- ClientPortfolioReportCollection.prototype.getByCategoryName = function (name) {
7553
- return this.items.find(function (item) { return item.category === name; });
7554
- };
7555
- return ClientPortfolioReportCollection;
7556
- }(Collection));
7557
-
7558
- /**
7559
- * Chart serie class: chart data item
7560
- * @TODO consider rename to ChartSerieData
7561
- */
7562
- var ChartSerie = /** @class */ (function () {
7563
- function ChartSerie() {
7564
- }
7565
- return ChartSerie;
7566
- }());
7567
-
7568
- /**
7569
- * Chart data class
7570
- * @TODO consider rename to ChartSerie
7571
- */
7572
- var ChartData = /** @class */ (function () {
7573
- function ChartData() {
7574
- }
7575
- return ChartData;
7576
- }());
7577
- __decorate([
7578
- classTransformer.Type(function () { return ChartSerie; })
7579
- ], ChartData.prototype, "data", void 0);
7580
-
7581
- var MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan'];
7582
-
7583
- /**
7584
- * Collection of transactions
7585
- */
7586
- var TransactionCollection = /** @class */ (function (_super) {
7587
- __extends(TransactionCollection, _super);
7588
- function TransactionCollection() {
7589
- return _super !== null && _super.apply(this, arguments) || this;
7590
- }
7591
- Object.defineProperty(TransactionCollection.prototype, "amount", {
7592
- /**
7593
- * Get total amount of all transactions in the collection
7594
- */
7595
- get: function () {
7596
- return +this.items.reduce(function (sum, transaction) { return sum + transaction.getNetAmount(); }, 0).toFixed(2);
7597
- },
7598
- enumerable: false,
7599
- configurable: true
7600
- });
7601
- /**
7602
- * Difference between allocated amount and total amount
7603
- */
7604
- TransactionCollection.prototype.getUnallocatedAmount = function (allocations) {
7605
- return +(this.amount - allocations.getByTransactionsIds(this.getIds()).amount).toFixed(2);
7606
- };
7607
- Object.defineProperty(TransactionCollection.prototype, "cashPosition", {
7608
- /**
7609
- * Get cash position
7610
- * Cash Position = Income - Expenses
7611
- * Cash position is equal to Total Amount because income is positive and expense is negative,
7612
- */
7613
- get: function () {
7614
- return this.claimAmount;
7615
- },
7616
- enumerable: false,
7617
- configurable: true
7618
- });
7619
- /**
7620
- * get date of the last transaction
7621
- */
7622
- TransactionCollection.prototype.getLastTransactionDate = function () {
7623
- return new Date(Math.max.apply(Math, this.items.map(function (transaction) { return transaction.date; })));
7624
- };
7625
- Object.defineProperty(TransactionCollection.prototype, "claimAmount", {
7626
- /**
7627
- * Get summary of claim amounts
7628
- */
7629
- get: function () {
7630
- return this.items.reduce(function (sum, transaction) { return sum + transaction.claimAmount; }, 0);
7631
- },
7632
- enumerable: false,
7633
- configurable: true
7634
- });
7635
- Object.defineProperty(TransactionCollection.prototype, "grossAmount", {
7636
- get: function () {
7637
- return +this.items.reduce(function (sum, transaction) { return sum + transaction.amount; }, 0).toFixed(2);
7638
- },
7639
- enumerable: false,
7640
- configurable: true
7641
- });
7642
- TransactionCollection.prototype.getByChartAccountsCategories = function (categories) {
7643
- return new TransactionCollection(this.items.filter(function (transaction) { return categories.includes(transaction.chartAccounts.category); }));
7644
- };
7645
- /**
7646
- * Get transactions by month
7647
- * @param monthIndex by which desired month should be taken
7648
- */
7649
- TransactionCollection.prototype.getByMonth = function (monthIndex) {
7650
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.date.getMonth() === monthIndex; }));
7651
- };
7652
- /**
7653
- * Get collection of transactions metadata
7654
- */
7655
- TransactionCollection.prototype.getTransactionsMetadata = function () {
7656
- var metadataArray = [];
7657
- this.items.forEach(function (transaction) {
7658
- metadataArray.push.apply(metadataArray, __spreadArray([], __read(transaction.metadata)));
7659
- });
7660
- return new Collection(metadataArray);
7661
- };
7662
- TransactionCollection.prototype.getIncomeTransactions = function () {
7663
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isIncome(); }));
7664
- };
7665
- Object.defineProperty(TransactionCollection.prototype, "claimIncome", {
7896
+ return this.sumBy('marketValue');
7897
+ },
7898
+ enumerable: false,
7899
+ configurable: true
7900
+ });
7901
+ Object.defineProperty(ClientPortfolioReportCollection.prototype, "loanBalance", {
7666
7902
  get: function () {
7667
- return this.getIncomeTransactions().claimAmount;
7903
+ return this.sumBy('loanBalance');
7668
7904
  },
7669
7905
  enumerable: false,
7670
7906
  configurable: true
7671
7907
  });
7672
- TransactionCollection.prototype.getExpenseTransactions = function () {
7673
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isExpense() && !transaction.isInterest(); }));
7674
- };
7675
- Object.defineProperty(TransactionCollection.prototype, "claimExpense", {
7908
+ Object.defineProperty(ClientPortfolioReportCollection.prototype, "equityPosition", {
7676
7909
  get: function () {
7677
- return this.getExpenseTransactions().claimAmount;
7910
+ return this.sumBy('equityPosition');
7678
7911
  },
7679
7912
  enumerable: false,
7680
7913
  configurable: true
7681
7914
  });
7682
- TransactionCollection.prototype.getInterestTransactions = function () {
7683
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isInterest(); }));
7684
- };
7685
- Object.defineProperty(TransactionCollection.prototype, "claimInterest", {
7915
+ Object.defineProperty(ClientPortfolioReportCollection.prototype, "averageMarketValue", {
7916
+ /**
7917
+ * Get average market value if there are more than 1 item in the collection
7918
+ */
7686
7919
  get: function () {
7687
- return this.getInterestTransactions().claimAmount;
7920
+ return this.items.length > 1 ? this.marketValue / this.items.length : null;
7921
+ },
7922
+ enumerable: false,
7923
+ configurable: true
7924
+ });
7925
+ Object.defineProperty(ClientPortfolioReportCollection.prototype, "averageLoanBalance", {
7926
+ /**
7927
+ * Get average loan balance if there are more than 1 item in the collection
7928
+ */
7929
+ get: function () {
7930
+ return this.items.length > 1 ? this.loanBalance / this.items.length : null;
7931
+ },
7932
+ enumerable: false,
7933
+ configurable: true
7934
+ });
7935
+ Object.defineProperty(ClientPortfolioReportCollection.prototype, "averageEquityPosition", {
7936
+ /**
7937
+ * Get average equity position if there are more than 1 item in the collection
7938
+ */
7939
+ get: function () {
7940
+ return this.items.length > 1 ? this.equityPosition / this.items.length : null;
7688
7941
  },
7689
7942
  enumerable: false,
7690
7943
  configurable: true
7691
7944
  });
7692
7945
  /**
7693
- * Get collection of transactions and properties filtered by properties ids
7694
- * @param ids Ids of properties for filter
7695
- */
7696
- TransactionCollection.prototype.getByPropertiesIds = function (ids) {
7697
- return new TransactionCollection(this.items.filter(function (transaction) {
7698
- var _a;
7699
- return ids.includes((_a = transaction.property) === null || _a === void 0 ? void 0 : _a.id);
7700
- }));
7701
- };
7702
- /**
7703
- * Get new collection filtered by income source id
7704
- * @param id id of income source for filter
7705
- */
7706
- TransactionCollection.prototype.getByIncomeSourceId = function (id) {
7707
- return new TransactionCollection(this.items.filter(function (transaction) { var _a; return ((_a = transaction.incomeSource) === null || _a === void 0 ? void 0 : _a.id) === id; }));
7708
- };
7709
- /**
7710
- * Get new collection filtered by chart accounts category
7711
- * @param category Chart accounts category value
7712
- */
7713
- TransactionCollection.prototype.getByChartAccountsCategory = function (category) {
7714
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.chartAccounts.category === category; }));
7715
- };
7716
- /**
7717
- * Get new collection of property transactions
7718
- */
7719
- TransactionCollection.prototype.getPropertyTransactions = function () {
7720
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isPropertyTank(); }));
7721
- };
7722
- TransactionCollection.prototype.getDebitTransactions = function () {
7723
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isDebit(); }));
7724
- };
7725
- TransactionCollection.prototype.getCreditTransactions = function () {
7726
- return new TransactionCollection(this.items.filter(function (transaction) { return transaction.isCredit(); }));
7727
- };
7728
- TransactionCollection.prototype.getByAllocations = function (allocations) {
7729
- return new TransactionCollection(this.items.filter(function (transaction) { return allocations.hasTransaction(transaction); }));
7730
- };
7731
- /**
7732
- * Get transactions related to Vehicle category
7733
- */
7734
- TransactionCollection.prototype.getVehicleTransactions = function () {
7735
- return this.create(this.items.filter(function (transaction) {
7736
- return transaction.isVehicleTransaction();
7737
- }));
7738
- };
7739
- /**
7740
- * Get new transaction collection filtered by tank type
7741
- */
7742
- TransactionCollection.prototype.getByTankType = function (tankType) {
7743
- return this.create(this.items.filter(function (transaction) {
7744
- switch (tankType) {
7745
- case exports.TankTypeEnum.PROPERTY:
7746
- return transaction.isPropertyTank();
7747
- case exports.TankTypeEnum.WORK:
7748
- return transaction.isWorkTank();
7749
- case exports.TankTypeEnum.SOLE:
7750
- return transaction.isSoleTank();
7751
- // Transaction may be not related to any tank type (personal)
7752
- default:
7753
- return false;
7754
- }
7755
- }));
7756
- };
7757
- TransactionCollection.prototype.getExportHeader = function () {
7758
- return ['Date', 'Description', 'Debit', 'Credit'];
7759
- };
7760
- TransactionCollection.prototype.getExportFooter = function () {
7761
- return [
7762
- classTransformer.plainToClass(ExportCell, { value: 'Total', type: ExportCellTypeEnum.STRING }),
7763
- classTransformer.plainToClass(ExportCell, { value: '', type: ExportCellTypeEnum.STRING }),
7764
- classTransformer.plainToClass(ExportCell, { value: this.sumBy('debit'), type: ExportCellTypeEnum.CURRENCY }),
7765
- classTransformer.plainToClass(ExportCell, { value: this.sumBy('credit'), type: ExportCellTypeEnum.CURRENCY })
7766
- ];
7767
- };
7768
- TransactionCollection.prototype.getExportBody = function () {
7769
- return this.items.map(function (transaction) {
7770
- return [
7771
- classTransformer.plainToClass(ExportCell, { value: transaction.date, type: ExportCellTypeEnum.DATE }),
7772
- classTransformer.plainToClass(ExportCell, { value: transaction.description, type: ExportCellTypeEnum.STRING }),
7773
- classTransformer.plainToClass(ExportCell, { value: transaction.debit, type: ExportCellTypeEnum.CURRENCY }),
7774
- classTransformer.plainToClass(ExportCell, { value: transaction.credit, type: ExportCellTypeEnum.CURRENCY })
7775
- ];
7776
- });
7777
- };
7778
- /**
7779
- * Get list of vehicle transactions filtered by vehicle claim
7780
- */
7781
- TransactionCollection.prototype.getByVehicleClaim = function (vehicleClaim) {
7782
- if (!vehicleClaim) {
7783
- return this.create([]);
7784
- }
7785
- return vehicleClaim.isSoleTank()
7786
- // sole tank may have multiple vehicle claims, so we need to filter by business.id
7787
- ? this.getVehicleTransactions().filterBy('business.id', vehicleClaim.business.id)
7788
- // work tank may have only one vehicle claim, so we need to filter by tank type
7789
- : this.getVehicleTransactions().filterBy('tankType', exports.TankTypeEnum.WORK);
7790
- };
7791
- /**
7792
- * Get list of vehicle transactions except KMS transactions
7793
- */
7794
- TransactionCollection.prototype.getLogbookTransactions = function () {
7795
- return this
7796
- .getVehicleTransactions()
7797
- .removeBy('chartAccounts.id', [exports.ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK, exports.ChartAccountsListEnum.KLMS_TRAVELLED]);
7798
- };
7799
- /**
7800
- * Build chart data with transactions cash position.
7801
- * Cash position = Income - Expenses (include depreciations)
7802
- * Chart data for each month from fin year start till current month
7946
+ * Return report by provided category name
7803
7947
  */
7804
- TransactionCollection.prototype.getCashPositionChartData = function () {
7805
- var _this = this;
7806
- var chartData = [
7807
- classTransformer.plainToClass(ChartData, { name: 'Income', data: [] }),
7808
- classTransformer.plainToClass(ChartData, { name: 'Expense', data: [] })
7809
- ];
7810
- new FinancialYear().getPastMonths().forEach(function (month) {
7811
- chartData[0].data.push({
7812
- label: MONTHS[month],
7813
- value: _this.getIncomeTransactions().getByMonth(month).claimAmount
7814
- });
7815
- chartData[1].data.push({
7816
- label: MONTHS[month],
7817
- value: Math.abs(_this.getExpenseTransactions().getByMonth(month).claimAmount)
7818
- });
7819
- });
7820
- return chartData;
7948
+ ClientPortfolioReportCollection.prototype.getByCategoryName = function (name) {
7949
+ return this.items.find(function (item) { return item.category === name; });
7821
7950
  };
7822
- return TransactionCollection;
7823
- }(ExportableCollection));
7951
+ return ClientPortfolioReportCollection;
7952
+ }(Collection));
7824
7953
 
7825
7954
  var DepreciationCollection = /** @class */ (function (_super) {
7826
7955
  __extends(DepreciationCollection, _super);
@@ -8639,7 +8768,11 @@
8639
8768
  exports.TaxReturnCategoryListEnum.DEPRECIATION_EXPENSES,
8640
8769
  exports.TaxReturnCategoryListEnum.MOTOR_VEHICLE_EXPENSES,
8641
8770
  exports.TaxReturnCategoryListEnum.ALL_OTHER_EXPENSES
8642
- ]
8771
+ ],
8772
+ // @TODO TT-2386 Nikita to move sole tax offsets in separated category
8773
+ taxOffsets: [
8774
+ exports.TaxReturnCategoryListEnum.TAX_OFFSETS
8775
+ ],
8643
8776
  },
8644
8777
  };
8645
8778
 
@@ -8701,54 +8834,6 @@
8701
8834
  return TaxReviewCollection;
8702
8835
  }(Collection));
8703
8836
 
8704
- var TransactionAllocationCollection = /** @class */ (function (_super) {
8705
- __extends(TransactionAllocationCollection, _super);
8706
- function TransactionAllocationCollection() {
8707
- return _super !== null && _super.apply(this, arguments) || this;
8708
- }
8709
- Object.defineProperty(TransactionAllocationCollection.prototype, "amount", {
8710
- get: function () {
8711
- return this.sumBy('amount');
8712
- },
8713
- enumerable: false,
8714
- configurable: true
8715
- });
8716
- TransactionAllocationCollection.prototype.getByTransactionsIds = function (ids) {
8717
- return new TransactionAllocationCollection(this.items.filter(function (allocation) { return ids.includes(allocation.transaction.id); }));
8718
- };
8719
- TransactionAllocationCollection.prototype.getByBankTransactionsIds = function (ids) {
8720
- return new TransactionAllocationCollection(this.items.filter(function (allocation) { return ids.includes(allocation.bankTransaction.id); }));
8721
- };
8722
- /**
8723
- * Group allocations by bank account via bank transactions collection
8724
- */
8725
- TransactionAllocationCollection.prototype.groupByBankAccount = function (bankTransactions) {
8726
- var _this = this;
8727
- // Group bank transactions by bank account id
8728
- var bankTransactionsByBankAccount = new CollectionDictionary(bankTransactions, 'bankAccount.id');
8729
- // Create empty dictionary of transaction allocations
8730
- var allocationsByBankAccount = new CollectionDictionary(new TransactionAllocationCollection([]));
8731
- // Fill allocations dictionary with bank transactions dictionary keys and allocations related with each bank transaction collection
8732
- bankTransactionsByBankAccount.keys.forEach(function (key) {
8733
- allocationsByBankAccount.add(key, _this.getByBankTransactionsIds(bankTransactionsByBankAccount.get(key).getIds()));
8734
- });
8735
- return allocationsByBankAccount;
8736
- };
8737
- /**
8738
- * check if collection includes allocation of passed transaction
8739
- */
8740
- TransactionAllocationCollection.prototype.hasTransaction = function (transaction) {
8741
- return !!this.items.find(function (allocation) { return allocation.transaction.id === transaction.id; });
8742
- };
8743
- /**
8744
- * Check if bank transaction is related with current allocations
8745
- */
8746
- TransactionAllocationCollection.prototype.hasBankTransaction = function (bankTransaction) {
8747
- return !!this.items.find(function (allocation) { return allocation.bankTransaction.id === bankTransaction.id; });
8748
- };
8749
- return TransactionAllocationCollection;
8750
- }(Collection));
8751
-
8752
8837
  /**
8753
8838
  * Collection of user event settings
8754
8839
  */
@@ -11652,7 +11737,6 @@
11652
11737
  });
11653
11738
  Object.defineProperty(TaxSummary.prototype, "soleNetCash", {
11654
11739
  /**
11655
- * @TODO Nicole update documentation + check calculations
11656
11740
  * Sole Net Cash = gross income – expenses
11657
11741
  * https://taxtank.atlassian.net/wiki/spaces/TAXTANK/pages/217677990/Dashboard+Main
11658
11742
  */
@@ -11666,7 +11750,6 @@
11666
11750
  });
11667
11751
  Object.defineProperty(TaxSummary.prototype, "soleNetTotal", {
11668
11752
  /**
11669
- * @TODO Nicole update documentation + check calculations
11670
11753
  * Sole Net Total = Gross income - expenses
11671
11754
  * https://taxtank.atlassian.net/wiki/spaces/TAXTANK/pages/217677990/Dashboard+Main
11672
11755
  */
@@ -11921,6 +12004,29 @@
11921
12004
  }]
11922
12005
  }] });
11923
12006
 
12007
+ /**
12008
+ * @TODO vik replace with json when the final list is confirmed
12009
+ */
12010
+ var SoleBusinessLossOffsetRuleService = /** @class */ (function (_super) {
12011
+ __extends(SoleBusinessLossOffsetRuleService, _super);
12012
+ function SoleBusinessLossOffsetRuleService() {
12013
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
12014
+ _this.modelClass = SoleBusinessLossOffsetRule;
12015
+ _this.url = 'sole-business-loss-offset-rules';
12016
+ _this.isHydra = true;
12017
+ return _this;
12018
+ }
12019
+ return SoleBusinessLossOffsetRuleService;
12020
+ }(RestService));
12021
+ SoleBusinessLossOffsetRuleService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SoleBusinessLossOffsetRuleService, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
12022
+ SoleBusinessLossOffsetRuleService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SoleBusinessLossOffsetRuleService, providedIn: 'root' });
12023
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SoleBusinessLossOffsetRuleService, decorators: [{
12024
+ type: i0.Injectable,
12025
+ args: [{
12026
+ providedIn: 'root'
12027
+ }]
12028
+ }] });
12029
+
11924
12030
  var SoleContactService = /** @class */ (function (_super) {
11925
12031
  __extends(SoleContactService, _super);
11926
12032
  function SoleContactService() {
@@ -17759,6 +17865,33 @@
17759
17865
  return SoleBusinessAllocationsForm;
17760
17866
  }(forms.FormArray));
17761
17867
 
17868
+ var SoleBusinessLossForm = /** @class */ (function (_super) {
17869
+ __extends(SoleBusinessLossForm, _super);
17870
+ function SoleBusinessLossForm(loss, balance) {
17871
+ var _this = this;
17872
+ var _a;
17873
+ _this = _super.call(this, {
17874
+ openBalance: new forms.FormControl(loss.openBalance, forms.Validators.required),
17875
+ offsetRule: new forms.FormControl((_a = loss.offsetRule) === null || _a === void 0 ? void 0 : _a.id),
17876
+ // sum of depreciations/transactions claim amount - openBalance
17877
+ balance: new forms.FormControl({ value: balance, disabled: true }),
17878
+ }, loss) || this;
17879
+ _this.loss = loss;
17880
+ _this.get('openBalance').valueChanges.subscribe(function (openBalance) {
17881
+ _this.get('balance').setValue(balance - openBalance);
17882
+ });
17883
+ return _this;
17884
+ }
17885
+ /**
17886
+ * radio buttons can't work with object
17887
+ * https://github.com/angular/components/issues/10495
17888
+ */
17889
+ SoleBusinessLossForm.prototype.submit = function () {
17890
+ return _super.prototype.submit.call(this, { offsetRule: this.get('offsetRule').value ? { id: this.get('offsetRule').value } : null });
17891
+ };
17892
+ return SoleBusinessLossForm;
17893
+ }(AbstractForm));
17894
+
17762
17895
  var SoleContactForm = /** @class */ (function (_super) {
17763
17896
  __extends(SoleContactForm, _super);
17764
17897
  function SoleContactForm(contact) {
@@ -19281,6 +19414,9 @@
19281
19414
  exports.SoleBusinessAllocationsForm = SoleBusinessAllocationsForm;
19282
19415
  exports.SoleBusinessForm = SoleBusinessForm;
19283
19416
  exports.SoleBusinessLoss = SoleBusinessLoss;
19417
+ exports.SoleBusinessLossForm = SoleBusinessLossForm;
19418
+ exports.SoleBusinessLossOffsetRule = SoleBusinessLossOffsetRule;
19419
+ exports.SoleBusinessLossOffsetRuleService = SoleBusinessLossOffsetRuleService;
19284
19420
  exports.SoleBusinessLossReport = SoleBusinessLossReport;
19285
19421
  exports.SoleBusinessLossService = SoleBusinessLossService;
19286
19422
  exports.SoleBusinessService = SoleBusinessService;
@@ -19325,6 +19461,7 @@
19325
19461
  exports.TransactionAllocationCollection = TransactionAllocationCollection;
19326
19462
  exports.TransactionAllocationService = TransactionAllocationService;
19327
19463
  exports.TransactionBase = TransactionBase;
19464
+ exports.TransactionBaseCollection = TransactionBaseCollection;
19328
19465
  exports.TransactionCalculationService = TransactionCalculationService;
19329
19466
  exports.TransactionCollection = TransactionCollection;
19330
19467
  exports.TransactionMetadata = TransactionMetadata;