taxtank-core 0.28.69 → 0.28.70

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.
@@ -2908,19 +2908,22 @@ class TransactionBase extends AbstractModel {
2908
2908
  return !!this.business;
2909
2909
  }
2910
2910
  get amountWithGst() {
2911
- return this.isGST ? +(this.amount * ChartAccounts.GSTCoefficient).toFixed(2) : this.amount;
2911
+ return this.isGST ? this.amount * ChartAccounts.GSTCoefficient : this.amount;
2912
2912
  }
2913
2913
  get gstAmount() {
2914
- return +(this.amountWithGst - this.amount).toFixed(2);
2914
+ return this.amountWithGst - this.amount;
2915
2915
  }
2916
2916
  get gstClaimAmount() {
2917
2917
  return this.gstAmount * this.claimRatio;
2918
2918
  }
2919
+ /**
2920
+ * base grossAmount, extends in child classes
2921
+ */
2919
2922
  get grossAmount() {
2920
2923
  return this.amount + this.gstAmount;
2921
2924
  }
2922
2925
  get grossClaimAmount() {
2923
- return +(this.grossAmount * (this.claimPercent / 100)).toFixed(2);
2926
+ return this.grossAmount * this.claimRatio;
2924
2927
  }
2925
2928
  }
2926
2929
  __decorate([
@@ -3447,8 +3450,7 @@ class Depreciation extends Depreciation$1 {
3447
3450
  var _a, _b;
3448
3451
  return plainToClass(Transaction, Object.assign(params, this, {
3449
3452
  amount: -((_a = this.currentYearForecast) === null || _a === void 0 ? void 0 : _a.amount) || 0,
3450
- claimAmount: ((_b = this.currentYearForecast) === null || _b === void 0 ? void 0 : _b.claimAmount) || 0,
3451
- date: this.purchaseDate
3453
+ claimAmount: -((_b = this.currentYearForecast) === null || _b === void 0 ? void 0 : _b.claimAmount) || 0,
3452
3454
  }));
3453
3455
  }
3454
3456
  /**
@@ -3459,18 +3461,17 @@ class Depreciation extends Depreciation$1 {
3459
3461
  return ((_a = this.currentYearForecast) === null || _a === void 0 ? void 0 : _a.claimAmount) || 0;
3460
3462
  }
3461
3463
  get amountWithGst() {
3462
- // only new assets
3463
- if (new FinancialYear(this.purchaseDate).year !== new FinancialYear().year) {
3464
- return this.amount;
3464
+ // gst applies only to new assets
3465
+ if (this.isNew()) {
3466
+ return super.amountWithGst;
3465
3467
  }
3466
- return super.amountWithGst;
3468
+ return this.amount;
3467
3469
  }
3468
3470
  /**
3469
- * @TODO temporary hack, in future backend should return negative numbers
3471
+ * assets purchased in the current financial year
3470
3472
  */
3471
- get grossAmount() {
3472
- var _a;
3473
- return -((_a = this.currentYearForecast) === null || _a === void 0 ? void 0 : _a.amount) - this.gstAmount;
3473
+ isNew() {
3474
+ return new FinancialYear(this.purchaseDate).year === new FinancialYear().year;
3474
3475
  }
3475
3476
  }
3476
3477
  Depreciation.WRITTEN_OFF_THRESHOLD = 300;
@@ -3662,12 +3663,12 @@ class Transaction extends Transaction$1 {
3662
3663
  isAllocated(allocations) {
3663
3664
  return this.grossAmount === this.getAllocatedAmount(allocations);
3664
3665
  }
3665
- /**
3666
- * Get transaction allocated amount
3667
- */
3668
3666
  getAllocatedAmount(allocations) {
3669
3667
  return allocations.filterBy('transaction.id', this.id).sumBy('amount');
3670
3668
  }
3669
+ getAllocatedClaimAmount(allocations) {
3670
+ return this.getAllocatedAmount(allocations) * this.claimRatio;
3671
+ }
3671
3672
  /**
3672
3673
  * Get transaction unallocated amount
3673
3674
  */
@@ -6205,17 +6206,11 @@ class TransactionCollection extends ExportableCollection {
6205
6206
  constructor(transactions = [], depreciations = []) {
6206
6207
  super([...transactions, ...depreciations.map((depreciation) => depreciation.toTransaction())]);
6207
6208
  }
6208
- /**
6209
- * Get business related transactions
6210
- */
6211
- getWithBusiness() {
6212
- return this.filter((transaction) => !!transaction.business);
6209
+ getSoleTransactions() {
6210
+ return this.filter((transaction) => transaction.isSoleTank());
6213
6211
  }
6214
- /**
6215
- * Get total amount of all transactions in the collection
6216
- */
6217
6212
  get amount() {
6218
- return +this.items.reduce((sum, transaction) => sum + transaction.amount, 0).toFixed(2);
6213
+ return this.sumBy('amount');
6219
6214
  }
6220
6215
  /**
6221
6216
  * Difference between allocated amount and total amount
@@ -6413,17 +6408,17 @@ class TransactionCollection extends ExportableCollection {
6413
6408
  return chartData;
6414
6409
  }
6415
6410
  /**
6416
- * user pays GST only from allocated part of income (the rest user didn't get, so don't have to pay)
6417
- *
6418
- * @param allocations
6411
+ * user pays GST only from allocated part (or paid) of income
6419
6412
  */
6420
- calculateAllocatedGST(allocations) {
6421
- const allocationsByTransaction = allocations.groupBy('transaction.id');
6422
- let allocatedGST = 0;
6413
+ calculateAllocatedClaimAmount(allocations) {
6414
+ let allocatedClaimAmount = 0;
6423
6415
  this.filterBy('isGST', true).toArray().forEach((transaction) => {
6424
- allocatedGST += allocationsByTransaction.get(transaction.id).sumBy('amount') * transaction.claimRatio * ChartAccounts.GSTRatio;
6416
+ allocatedClaimAmount += transaction.getAllocatedClaimAmount(allocations);
6425
6417
  });
6426
- return allocatedGST;
6418
+ return allocatedClaimAmount;
6419
+ }
6420
+ calculateAllocatedGST(allocations) {
6421
+ return this.calculateAllocatedClaimAmount(allocations) * ChartAccounts.GSTRatio;
6427
6422
  }
6428
6423
  getAllocatedAmount(allocations) {
6429
6424
  return allocations.getByTransactionsIds(this.getIds()).sumBy('amount');
@@ -6472,23 +6467,11 @@ class TransactionAllocationCollection extends Collection {
6472
6467
  * used to combine transactions/depreciations
6473
6468
  */
6474
6469
  class TransactionBaseCollection extends Collection {
6475
- filterByBusiness(business) {
6476
- return this.filterBy('business.id', business.id);
6477
- }
6478
6470
  getClaimAmountByBusinessId(businessId) {
6479
6471
  return +this.filterBy('business.id', businessId).items.map((transaction) => transaction instanceof Depreciation ? -transaction.claimAmount : transaction['claimAmount']).reduce((sum, claimAmount) => sum + claimAmount, 0).toFixed(2);
6480
6472
  }
6481
- /**
6482
- * Get business related transactions
6483
- */
6484
- getWithBusiness() {
6485
- return this.filter((transaction) => !!transaction.business);
6486
- }
6487
- getIncomeTransactions() {
6488
- return this.create(this.items.filter((transaction) => transaction.isIncome()));
6489
- }
6490
- getExpenseTransactions() {
6491
- return this.create(this.items.filter((transaction) => transaction.isExpense() && !transaction.isInterest()));
6473
+ getSoleTransactions() {
6474
+ return this.filter((transaction) => transaction.isSoleTank());
6492
6475
  }
6493
6476
  }
6494
6477
 
@@ -6776,17 +6759,11 @@ class ClientPortfolioReportCollection extends Collection {
6776
6759
  * @TODO extend from TransactionBaseCollection
6777
6760
  */
6778
6761
  class DepreciationCollection extends Collection {
6779
- /**
6780
- * Get business related transactions
6781
- */
6782
- getWithBusiness() {
6783
- return this.filter((depreciation) => !!depreciation.business);
6762
+ getSoleTransactions() {
6763
+ return this.filter((depreciation) => depreciation.isSoleTank());
6784
6764
  }
6785
- /**
6786
- * assets purchased in the current financial year
6787
- */
6788
6765
  getNew() {
6789
- return this.filter((depreciation) => new FinancialYear(depreciation.purchaseDate).year === new FinancialYear().year);
6766
+ return this.filter((depreciation) => depreciation.isNew());
6790
6767
  }
6791
6768
  /**
6792
6769
  * Get total amount of all depreciations in the collection