taxtank-core 0.28.69 → 0.28.71

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.
@@ -3179,6 +3179,10 @@
3179
3179
  classTransformer.Type(function () { return SoleBusinessLossOffsetRule; })
3180
3180
  ], SoleBusinessLossOffsetRule.prototype, "parent", void 0);
3181
3181
 
3182
+ /**
3183
+ * If a sole trader business makes a tax loss in a current year, you can generally carry forward that loss and offset profit in future years.
3184
+ * https://taxtank.atlassian.net/wiki/spaces/TAXTANK/pages/4641357930/Rules+when+a+business+makes+a+loss+Tax+Summary#Offsetting-current-year-business-losses
3185
+ */
3182
3186
  var SoleBusinessLoss = /** @class */ (function (_super) {
3183
3187
  __extends(SoleBusinessLoss, _super);
3184
3188
  function SoleBusinessLoss() {
@@ -3738,14 +3742,14 @@
3738
3742
  };
3739
3743
  Object.defineProperty(TransactionBase.prototype, "amountWithGst", {
3740
3744
  get: function () {
3741
- return this.isGST ? +(this.amount * ChartAccounts.GSTCoefficient).toFixed(2) : this.amount;
3745
+ return this.isGST ? this.amount * ChartAccounts.GSTCoefficient : this.amount;
3742
3746
  },
3743
3747
  enumerable: false,
3744
3748
  configurable: true
3745
3749
  });
3746
3750
  Object.defineProperty(TransactionBase.prototype, "gstAmount", {
3747
3751
  get: function () {
3748
- return +(this.amountWithGst - this.amount).toFixed(2);
3752
+ return this.amountWithGst - this.amount;
3749
3753
  },
3750
3754
  enumerable: false,
3751
3755
  configurable: true
@@ -3758,6 +3762,9 @@
3758
3762
  configurable: true
3759
3763
  });
3760
3764
  Object.defineProperty(TransactionBase.prototype, "grossAmount", {
3765
+ /**
3766
+ * base grossAmount, extends in child classes
3767
+ */
3761
3768
  get: function () {
3762
3769
  return this.amount + this.gstAmount;
3763
3770
  },
@@ -3766,7 +3773,7 @@
3766
3773
  });
3767
3774
  Object.defineProperty(TransactionBase.prototype, "grossClaimAmount", {
3768
3775
  get: function () {
3769
- return +(this.grossAmount * (this.claimPercent / 100)).toFixed(2);
3776
+ return this.grossAmount * this.claimRatio;
3770
3777
  },
3771
3778
  enumerable: false,
3772
3779
  configurable: true
@@ -4478,8 +4485,7 @@
4478
4485
  var _a, _b;
4479
4486
  return classTransformer.plainToClass(Transaction, Object.assign(params, this, {
4480
4487
  amount: -((_a = this.currentYearForecast) === null || _a === void 0 ? void 0 : _a.amount) || 0,
4481
- claimAmount: ((_b = this.currentYearForecast) === null || _b === void 0 ? void 0 : _b.claimAmount) || 0,
4482
- date: this.purchaseDate
4488
+ claimAmount: -((_b = this.currentYearForecast) === null || _b === void 0 ? void 0 : _b.claimAmount) || 0,
4483
4489
  }));
4484
4490
  };
4485
4491
  Object.defineProperty(Depreciation.prototype, "claimAmount", {
@@ -4495,26 +4501,21 @@
4495
4501
  });
4496
4502
  Object.defineProperty(Depreciation.prototype, "amountWithGst", {
4497
4503
  get: function () {
4498
- // only new assets
4499
- if (new FinancialYear(this.purchaseDate).year !== new FinancialYear().year) {
4500
- return this.amount;
4504
+ // gst applies only to new assets
4505
+ if (this.isNew()) {
4506
+ return _super.prototype.amountWithGst;
4501
4507
  }
4502
- return _super.prototype.amountWithGst;
4503
- },
4504
- enumerable: false,
4505
- configurable: true
4506
- });
4507
- Object.defineProperty(Depreciation.prototype, "grossAmount", {
4508
- /**
4509
- * @TODO temporary hack, in future backend should return negative numbers
4510
- */
4511
- get: function () {
4512
- var _a;
4513
- return -((_a = this.currentYearForecast) === null || _a === void 0 ? void 0 : _a.amount) - this.gstAmount;
4508
+ return this.amount;
4514
4509
  },
4515
4510
  enumerable: false,
4516
4511
  configurable: true
4517
4512
  });
4513
+ /**
4514
+ * assets purchased in the current financial year
4515
+ */
4516
+ Depreciation.prototype.isNew = function () {
4517
+ return new FinancialYear(this.purchaseDate).year === new FinancialYear().year;
4518
+ };
4518
4519
  return Depreciation;
4519
4520
  }(Depreciation$1));
4520
4521
  Depreciation.WRITTEN_OFF_THRESHOLD = 300;
@@ -4745,12 +4746,12 @@
4745
4746
  Transaction.prototype.isAllocated = function (allocations) {
4746
4747
  return this.grossAmount === this.getAllocatedAmount(allocations);
4747
4748
  };
4748
- /**
4749
- * Get transaction allocated amount
4750
- */
4751
4749
  Transaction.prototype.getAllocatedAmount = function (allocations) {
4752
4750
  return allocations.filterBy('transaction.id', this.id).sumBy('amount');
4753
4751
  };
4752
+ Transaction.prototype.getAllocatedClaimAmount = function (allocations) {
4753
+ return this.getAllocatedAmount(allocations) * this.claimRatio;
4754
+ };
4754
4755
  /**
4755
4756
  * Get transaction unallocated amount
4756
4757
  */
@@ -7594,27 +7595,42 @@
7594
7595
  return _super !== null && _super.apply(this, arguments) || this;
7595
7596
  }
7596
7597
  /**
7597
- * Calculate business losses applied to the current year
7598
+ * Business loss applied in current year, includes previous year losses and current year losses for businesses matching offset rule
7598
7599
  */
7599
7600
  SoleBusinessLossesCollection.prototype.calculateBusinessLossApplied = function (transactions) {
7600
7601
  var _this = this;
7601
- var transactionsByBusinessIds = new CollectionDictionary(transactions, 'business.id');
7602
- // Dictionary with pairs key = business id, value = business claim amount
7602
+ // claim amounts for businesses that can be applied to be reduced by prior year business losses
7603
+ var claimAmountsByBusinessId = this.getClaimAmountsByBusinessId(transactions);
7604
+ return Object.keys(claimAmountsByBusinessId.items).reduce(function (sum, businessId) {
7605
+ var loss = _this.findBy('business.id', +businessId);
7606
+ var lossOpenBalance = (loss === null || loss === void 0 ? void 0 : loss.openBalance) || 0;
7607
+ // business loss can be applied to business profit or other income types profit in case in offset rule met
7608
+ return sum + (loss.offsetRule ? lossOpenBalance : Math.min(lossOpenBalance, claimAmountsByBusinessId.get(businessId)));
7609
+ }, 0);
7610
+ };
7611
+ /**
7612
+ * Get business claim amounts that can be applied to be reduced by prior year business losses:
7613
+ * businesses with income or businesses with a loss, but which met the non-commercial loss rules
7614
+ * https://www.ato.gov.au/Business/Non-commercial-losses/
7615
+ */
7616
+ SoleBusinessLossesCollection.prototype.getClaimAmountsByBusinessId = function (transactions) {
7617
+ var _this = this;
7603
7618
  var claimAmountsByBusinessId = new Dictionary([]);
7604
- transactionsByBusinessIds.keys.forEach(function (businessId) {
7605
- var businessClaimAmount = transactionsByBusinessIds
7619
+ var transactionsByBusinessId = new CollectionDictionary(transactions, 'business.id');
7620
+ transactionsByBusinessId.keys.forEach(function (businessId) {
7621
+ var _a;
7622
+ // business loss may not exist if, when creating a business, user didn't add losses for previous years
7623
+ var lossOffsetRule = (_a = _this.findBy('business.id', +businessId)) === null || _a === void 0 ? void 0 : _a.offsetRule;
7624
+ var businessClaimAmount = transactionsByBusinessId
7606
7625
  .get(businessId)
7607
7626
  .getClaimAmountByBusinessId(+businessId);
7608
- // only businesses with positive income are included in the calculation
7609
- if (businessClaimAmount > 0) {
7610
- claimAmountsByBusinessId.add(businessId, businessClaimAmount);
7627
+ // no way to apply loss for business without profit if offset rules not met
7628
+ if (businessClaimAmount < 0 && !lossOffsetRule) {
7629
+ return;
7611
7630
  }
7631
+ claimAmountsByBusinessId.add(businessId, businessClaimAmount);
7612
7632
  });
7613
- return Object.keys(claimAmountsByBusinessId.items).reduce(function (sum, businessId) {
7614
- var _a;
7615
- var lossOpenBalance = ((_a = _this.findBy('business.id', +businessId)) === null || _a === void 0 ? void 0 : _a.openBalance) || 0;
7616
- return sum + Math.min(lossOpenBalance, claimAmountsByBusinessId.get(businessId));
7617
- }, 0);
7633
+ return claimAmountsByBusinessId;
7618
7634
  };
7619
7635
  return SoleBusinessLossesCollection;
7620
7636
  }(Collection));
@@ -7868,18 +7884,12 @@
7868
7884
  if (depreciations === void 0) { depreciations = []; }
7869
7885
  return _super.call(this, __spreadArray(__spreadArray([], __read(transactions)), __read(depreciations.map(function (depreciation) { return depreciation.toTransaction(); })))) || this;
7870
7886
  }
7871
- /**
7872
- * Get business related transactions
7873
- */
7874
- TransactionCollection.prototype.getWithBusiness = function () {
7875
- return this.filter(function (transaction) { return !!transaction.business; });
7887
+ TransactionCollection.prototype.getSoleTransactions = function () {
7888
+ return this.filter(function (transaction) { return transaction.isSoleTank(); });
7876
7889
  };
7877
7890
  Object.defineProperty(TransactionCollection.prototype, "amount", {
7878
- /**
7879
- * Get total amount of all transactions in the collection
7880
- */
7881
7891
  get: function () {
7882
- return +this.items.reduce(function (sum, transaction) { return sum + transaction.amount; }, 0).toFixed(2);
7892
+ return this.sumBy('amount');
7883
7893
  },
7884
7894
  enumerable: false,
7885
7895
  configurable: true
@@ -8101,17 +8111,17 @@
8101
8111
  return chartData;
8102
8112
  };
8103
8113
  /**
8104
- * user pays GST only from allocated part of income (the rest user didn't get, so don't have to pay)
8105
- *
8106
- * @param allocations
8114
+ * user pays GST only from allocated part (or paid) of income
8107
8115
  */
8108
- TransactionCollection.prototype.calculateAllocatedGST = function (allocations) {
8109
- var allocationsByTransaction = allocations.groupBy('transaction.id');
8110
- var allocatedGST = 0;
8116
+ TransactionCollection.prototype.calculateAllocatedClaimAmount = function (allocations) {
8117
+ var allocatedClaimAmount = 0;
8111
8118
  this.filterBy('isGST', true).toArray().forEach(function (transaction) {
8112
- allocatedGST += allocationsByTransaction.get(transaction.id).sumBy('amount') * transaction.claimRatio * ChartAccounts.GSTRatio;
8119
+ allocatedClaimAmount += transaction.getAllocatedClaimAmount(allocations);
8113
8120
  });
8114
- return allocatedGST;
8121
+ return allocatedClaimAmount;
8122
+ };
8123
+ TransactionCollection.prototype.calculateAllocatedGST = function (allocations) {
8124
+ return this.calculateAllocatedClaimAmount(allocations) * ChartAccounts.GSTRatio;
8115
8125
  };
8116
8126
  TransactionCollection.prototype.getAllocatedAmount = function (allocations) {
8117
8127
  return allocations.getByTransactionsIds(this.getIds()).sumBy('amount');
@@ -8175,23 +8185,11 @@
8175
8185
  function TransactionBaseCollection() {
8176
8186
  return _super !== null && _super.apply(this, arguments) || this;
8177
8187
  }
8178
- TransactionBaseCollection.prototype.filterByBusiness = function (business) {
8179
- return this.filterBy('business.id', business.id);
8180
- };
8181
8188
  TransactionBaseCollection.prototype.getClaimAmountByBusinessId = function (businessId) {
8182
8189
  return +this.filterBy('business.id', businessId).items.map(function (transaction) { return transaction instanceof Depreciation ? -transaction.claimAmount : transaction['claimAmount']; }).reduce(function (sum, claimAmount) { return sum + claimAmount; }, 0).toFixed(2);
8183
8190
  };
8184
- /**
8185
- * Get business related transactions
8186
- */
8187
- TransactionBaseCollection.prototype.getWithBusiness = function () {
8188
- return this.filter(function (transaction) { return !!transaction.business; });
8189
- };
8190
- TransactionBaseCollection.prototype.getIncomeTransactions = function () {
8191
- return this.create(this.items.filter(function (transaction) { return transaction.isIncome(); }));
8192
- };
8193
- TransactionBaseCollection.prototype.getExpenseTransactions = function () {
8194
- return this.create(this.items.filter(function (transaction) { return transaction.isExpense() && !transaction.isInterest(); }));
8191
+ TransactionBaseCollection.prototype.getSoleTransactions = function () {
8192
+ return this.filter(function (transaction) { return transaction.isSoleTank(); });
8195
8193
  };
8196
8194
  return TransactionBaseCollection;
8197
8195
  }(Collection));
@@ -8591,17 +8589,11 @@
8591
8589
  function DepreciationCollection() {
8592
8590
  return _super !== null && _super.apply(this, arguments) || this;
8593
8591
  }
8594
- /**
8595
- * Get business related transactions
8596
- */
8597
- DepreciationCollection.prototype.getWithBusiness = function () {
8598
- return this.filter(function (depreciation) { return !!depreciation.business; });
8592
+ DepreciationCollection.prototype.getSoleTransactions = function () {
8593
+ return this.filter(function (depreciation) { return depreciation.isSoleTank(); });
8599
8594
  };
8600
- /**
8601
- * assets purchased in the current financial year
8602
- */
8603
8595
  DepreciationCollection.prototype.getNew = function () {
8604
- return this.filter(function (depreciation) { return new FinancialYear(depreciation.purchaseDate).year === new FinancialYear().year; });
8596
+ return this.filter(function (depreciation) { return depreciation.isNew(); });
8605
8597
  };
8606
8598
  Object.defineProperty(DepreciationCollection.prototype, "amount", {
8607
8599
  /**