taxtank-core 0.30.127 → 0.30.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/collections/bank-account.collection.mjs +24 -3
- package/esm2020/lib/collections/collection-dictionary.mjs +4 -3
- package/esm2020/lib/collections/property/property.collection.mjs +5 -2
- package/esm2020/lib/models/bank/bank-account.mjs +4 -1
- package/esm2020/lib/models/property/borrowing-report.mjs +35 -1
- package/fesm2015/taxtank-core.mjs +63 -5
- package/fesm2015/taxtank-core.mjs.map +1 -1
- package/fesm2020/taxtank-core.mjs +63 -5
- package/fesm2020/taxtank-core.mjs.map +1 -1
- package/lib/collections/bank-account.collection.d.ts +4 -1
- package/lib/collections/collection-dictionary.d.ts +2 -2
- package/lib/collections/property/property.collection.d.ts +3 -3
- package/lib/models/bank/bank-account.d.ts +1 -0
- package/lib/models/property/borrowing-report.d.ts +18 -0
- package/package.json +1 -1
|
@@ -14,10 +14,10 @@ import round from 'lodash/round';
|
|
|
14
14
|
import flatten from 'lodash/flatten';
|
|
15
15
|
import hasIn from 'lodash/hasIn';
|
|
16
16
|
import intersection from 'lodash/intersection';
|
|
17
|
+
import uniqBy from 'lodash/uniqBy';
|
|
17
18
|
import first from 'lodash/first';
|
|
18
19
|
import last from 'lodash/last';
|
|
19
20
|
import orderBy from 'lodash/orderBy';
|
|
20
|
-
import uniqBy from 'lodash/uniqBy';
|
|
21
21
|
import differenceBy from 'lodash/differenceBy';
|
|
22
22
|
import uniq from 'lodash/uniq';
|
|
23
23
|
import moment from 'moment';
|
|
@@ -1640,13 +1640,13 @@ class CollectionDictionary {
|
|
|
1640
1640
|
return this.items[key] ? this.items[key] : this.createCollection([]);
|
|
1641
1641
|
}
|
|
1642
1642
|
/**
|
|
1643
|
-
* Join several collections by ids
|
|
1643
|
+
* Join several collections by ids, return collection of uniq models (skip duplicates)
|
|
1644
1644
|
*/
|
|
1645
1645
|
merge(keys) {
|
|
1646
1646
|
if (!this.length) {
|
|
1647
1647
|
return this.createCollection([]);
|
|
1648
1648
|
}
|
|
1649
|
-
return this.createCollection(flatten(keys.map((key) => this.get(key.toString()).items)));
|
|
1649
|
+
return this.createCollection(uniqBy(flatten(keys.map((key) => this.get(key.toString()).items)), 'id'));
|
|
1650
1650
|
}
|
|
1651
1651
|
/**
|
|
1652
1652
|
* Create instance of collection
|
|
@@ -2174,6 +2174,9 @@ class PropertyCollection extends Collection {
|
|
|
2174
2174
|
newItems.unshift(...bestProperties);
|
|
2175
2175
|
return this.create(newItems);
|
|
2176
2176
|
}
|
|
2177
|
+
get netIncome() {
|
|
2178
|
+
return this.sumBy('currentYearForecast.income') + this.sumBy('currentYearForecast.expense');
|
|
2179
|
+
}
|
|
2177
2180
|
}
|
|
2178
2181
|
|
|
2179
2182
|
class PropertyCategoryMovementCollection extends Collection {
|
|
@@ -5944,6 +5947,10 @@ __decorate([
|
|
|
5944
5947
|
let BorrowingReport$1 = class BorrowingReport extends AbstractModel {
|
|
5945
5948
|
};
|
|
5946
5949
|
|
|
5950
|
+
/**
|
|
5951
|
+
* Borrowing power report, shows if u can afford new property loan
|
|
5952
|
+
* https://taxtank.atlassian.net/wiki/spaces/TAXTANK/pages/4717608961/Borrowing+Power+Report+-+Property+Tank
|
|
5953
|
+
*/
|
|
5947
5954
|
class BorrowingReport extends BorrowingReport$1 {
|
|
5948
5955
|
constructor() {
|
|
5949
5956
|
super(...arguments);
|
|
@@ -5952,6 +5959,33 @@ class BorrowingReport extends BorrowingReport$1 {
|
|
|
5952
5959
|
this.otherLiabilities = 0;
|
|
5953
5960
|
this.livingExpenses = 0;
|
|
5954
5961
|
}
|
|
5962
|
+
/**
|
|
5963
|
+
* some fields calculated automatically until user filled them manually
|
|
5964
|
+
*/
|
|
5965
|
+
static calculate(salaryForecasts, incomeSourceForecasts, clientDetails = plainToClass(AnnualClientDetails, {}), report = plainToClass(BorrowingReport, {})) {
|
|
5966
|
+
if (!report.netSalary) {
|
|
5967
|
+
report.netSalary = new Collection(salaryForecasts).sumBy('monthlyAmount')
|
|
5968
|
+
+ new IncomeSourceForecastCollection(incomeSourceForecasts).bonuses.sumBy('monthlyAmount');
|
|
5969
|
+
}
|
|
5970
|
+
if (!report.spouseNetSalary) {
|
|
5971
|
+
report.spouseNetSalary = clientDetails.spouseMonthlyIncome;
|
|
5972
|
+
}
|
|
5973
|
+
return report;
|
|
5974
|
+
}
|
|
5975
|
+
/**
|
|
5976
|
+
* free money after expenses
|
|
5977
|
+
*/
|
|
5978
|
+
getNetIncomeSurplus(profit, repaymentAmount) {
|
|
5979
|
+
return profit + this.netRentIncome + this.netSalary + this.spouseNetSalary - repaymentAmount
|
|
5980
|
+
- this.loanRepaymentAmount - this.otherLiabilities - this.livingExpenses;
|
|
5981
|
+
}
|
|
5982
|
+
/**
|
|
5983
|
+
* surplus income to cover your debt obligations
|
|
5984
|
+
*/
|
|
5985
|
+
getNetSurplusRatio(profit, repaymentAmount) {
|
|
5986
|
+
return (profit + this.netRentIncome + this.netSalary + this.spouseNetSalary - this.livingExpenses)
|
|
5987
|
+
/ (repaymentAmount + this.loanRepaymentAmount + this.otherLiabilities);
|
|
5988
|
+
}
|
|
5955
5989
|
}
|
|
5956
5990
|
__decorate([
|
|
5957
5991
|
Type(() => User)
|
|
@@ -7752,8 +7786,26 @@ class BankAccountCollection extends Collection {
|
|
|
7752
7786
|
getPropertyBalanceAmount(propertyId) {
|
|
7753
7787
|
return this.items.reduce((sum, bankAccount) => sum + bankAccount.getPropertyBalanceAmount(propertyId), 0);
|
|
7754
7788
|
}
|
|
7755
|
-
|
|
7756
|
-
|
|
7789
|
+
get propertiesBalanceAmount() {
|
|
7790
|
+
let balanceAmount = 0;
|
|
7791
|
+
this.items.forEach((bankAccount) => {
|
|
7792
|
+
bankAccount.bankAccountProperties.forEach((bankAccountProperty) => {
|
|
7793
|
+
balanceAmount += Math.abs(bankAccount.getPropertyBalanceAmount(bankAccountProperty.property.id));
|
|
7794
|
+
});
|
|
7795
|
+
});
|
|
7796
|
+
return balanceAmount;
|
|
7797
|
+
}
|
|
7798
|
+
get propertiesMonthlyRepaymentAmount() {
|
|
7799
|
+
let repaymentAmount = 0;
|
|
7800
|
+
this.getLoanAccounts().items.forEach((bankAccount) => {
|
|
7801
|
+
bankAccount.bankAccountProperties.forEach((bankAccountProperty) => {
|
|
7802
|
+
repaymentAmount += bankAccount.getMonthlyRepaymentAmount(bankAccountProperty.property.id);
|
|
7803
|
+
});
|
|
7804
|
+
});
|
|
7805
|
+
return repaymentAmount;
|
|
7806
|
+
}
|
|
7807
|
+
getPropertyMonthlyRepaymentAmount(propertyId) {
|
|
7808
|
+
return this.getLoanAccounts().reduce((sum, bankAccount) => sum + bankAccount.getMonthlyRepaymentAmount(propertyId), 0);
|
|
7757
7809
|
}
|
|
7758
7810
|
getLVR(property) {
|
|
7759
7811
|
return this.getPropertyBalanceAmount(property.id) / property.currentYearForecast.marketValue;
|
|
@@ -7762,6 +7814,9 @@ class BankAccountCollection extends Collection {
|
|
|
7762
7814
|
// TODO Alex/Vik: maybe we should get it from jwtToken or think about some localStorageService?
|
|
7763
7815
|
return this.filter((bankAccount) => bankAccount.isOwner(+localStorage.getItem('userId')));
|
|
7764
7816
|
}
|
|
7817
|
+
getActiveLoanAccountsByProperties(ids) {
|
|
7818
|
+
return this.getActiveBankAccounts().getLoanAccounts().getByPropertiesIds(ids);
|
|
7819
|
+
}
|
|
7765
7820
|
}
|
|
7766
7821
|
|
|
7767
7822
|
/**
|
|
@@ -8539,6 +8594,9 @@ class BankAccount extends BankAccount$1 {
|
|
|
8539
8594
|
getPropertyBalanceAmount(propertyId) {
|
|
8540
8595
|
return this.currentBalance * this.getPropertyPercentage(propertyId);
|
|
8541
8596
|
}
|
|
8597
|
+
getMonthlyRepaymentAmount(propertyId) {
|
|
8598
|
+
return this.loan.monthlyRepaymentAmount * this.getPropertyPercentage(propertyId);
|
|
8599
|
+
}
|
|
8542
8600
|
/**
|
|
8543
8601
|
* Check if bank account is active (has 'active' status or hasn't been paid out/refinanced)
|
|
8544
8602
|
*/
|