taxtank-core 0.27.4 → 0.27.5

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 (53) hide show
  1. package/bundles/taxtank-core.umd.js +153 -131
  2. package/bundles/taxtank-core.umd.js.map +1 -1
  3. package/esm2015/lib/collections/chart-accounts.collection.js +3 -3
  4. package/esm2015/lib/collections/transaction/transaction.collection.js +5 -2
  5. package/esm2015/lib/collections/vehicle/vehicle-claim.collection.js +2 -4
  6. package/esm2015/lib/collections/vehicle/vehicle-logbook.collection.js +15 -30
  7. package/esm2015/lib/db/Enums/depreciation-calculation.enum.js +2 -1
  8. package/esm2015/lib/forms/abstract.form.js +11 -5
  9. package/esm2015/lib/forms/bank/bank-account/bank-account-allocation.form.js +6 -3
  10. package/esm2015/lib/forms/sole/sole-business-allocations.form.js +2 -1
  11. package/esm2015/lib/forms/sole/sole-invoice-template.form.js +2 -2
  12. package/esm2015/lib/forms/vehicle/vehicle-claim-details.form.js +3 -7
  13. package/esm2015/lib/forms/vehicle/vehicle-claim.form.js +8 -2
  14. package/esm2015/lib/forms/vehicle/vehicle-logbook.form.js +22 -15
  15. package/esm2015/lib/models/account-setup/account-setup-items.const.js +2 -2
  16. package/esm2015/lib/models/bank/bank-account.js +4 -1
  17. package/esm2015/lib/models/chart-accounts/chart-accounts.js +9 -9
  18. package/esm2015/lib/models/financial-year/financial-year.js +2 -1
  19. package/esm2015/lib/models/report/my-tax/my-tax-deductions/my-tax-deductions.js +2 -2
  20. package/esm2015/lib/models/sole/sole-invoice-template.js +5 -4
  21. package/esm2015/lib/models/transaction/transaction.js +3 -3
  22. package/esm2015/lib/models/vehicle/logbook-period.js +2 -1
  23. package/esm2015/lib/models/vehicle/vehicle-claim-details.js +12 -11
  24. package/esm2015/lib/models/vehicle/vehicle-claim.js +14 -13
  25. package/esm2015/lib/models/vehicle/vehicle-logbook.js +18 -5
  26. package/esm2015/lib/services/account-setup/account-setup.service.js +2 -2
  27. package/esm2015/lib/services/http/depreciation/depreciation.service.js +1 -2
  28. package/esm2015/lib/services/http/transaction/transaction.service.js +1 -2
  29. package/esm2015/lib/services/http/vehicle/vehicle-claim-details.service.js +7 -6
  30. package/esm2015/lib/services/http/vehicle/vehicle-claim.service.js +10 -10
  31. package/fesm2015/taxtank-core.js +137 -118
  32. package/fesm2015/taxtank-core.js.map +1 -1
  33. package/lib/collections/chart-accounts.collection.d.ts +2 -2
  34. package/lib/collections/transaction/transaction.collection.d.ts +2 -2
  35. package/lib/collections/vehicle/vehicle-claim.collection.d.ts +1 -3
  36. package/lib/collections/vehicle/vehicle-logbook.collection.d.ts +4 -9
  37. package/lib/db/Enums/depreciation-calculation.enum.d.ts +1 -0
  38. package/lib/forms/abstract.form.d.ts +3 -1
  39. package/lib/forms/bank/bank-account/bank-account-allocation.form.d.ts +4 -2
  40. package/lib/forms/sole/sole-business-allocations.form.d.ts +1 -0
  41. package/lib/forms/vehicle/vehicle-claim-details.form.d.ts +1 -6
  42. package/lib/forms/vehicle/vehicle-claim.form.d.ts +3 -0
  43. package/lib/forms/vehicle/vehicle-logbook.form.d.ts +4 -0
  44. package/lib/models/bank/bank-account.d.ts +2 -0
  45. package/lib/models/chart-accounts/chart-accounts.d.ts +6 -6
  46. package/lib/models/financial-year/financial-year.d.ts +1 -0
  47. package/lib/models/sole/sole-invoice-template.d.ts +1 -1
  48. package/lib/models/transaction/transaction.d.ts +2 -2
  49. package/lib/models/vehicle/logbook-period.d.ts +1 -0
  50. package/lib/models/vehicle/vehicle-claim-details.d.ts +8 -2
  51. package/lib/models/vehicle/vehicle-claim.d.ts +6 -4
  52. package/lib/models/vehicle/vehicle-logbook.d.ts +8 -4
  53. package/package.json +1 -1
@@ -14,8 +14,8 @@ import last from 'lodash/last';
14
14
  import flatten from 'lodash/flatten';
15
15
  import hasIn from 'lodash/hasIn';
16
16
  import first from 'lodash/first';
17
- import * as moment from 'moment';
18
- import { DateRange } from 'moment-range';
17
+ import * as moment$1 from 'moment';
18
+ import { extendMoment, DateRange } from 'moment-range';
19
19
  import uniqBy from 'lodash/uniqBy';
20
20
  import concat from 'lodash/concat';
21
21
  import { throwError as throwError$1 } from 'rxjs/internal/observable/throwError';
@@ -1241,6 +1241,7 @@ class FinancialYear {
1241
1241
  return months;
1242
1242
  }
1243
1243
  }
1244
+ FinancialYear.weeksInYear = 52;
1244
1245
  FinancialYear.startMonthIndex = 6;
1245
1246
 
1246
1247
  /**
@@ -2241,26 +2242,26 @@ class ChartAccounts extends ChartAccounts$1 {
2241
2242
  return this.name;
2242
2243
  }
2243
2244
  /**
2244
- * Check if chart accounts id is related for 'Klms travelled for work' category
2245
+ * Check if chart accounts id is related for 'Kms travelled for work' category
2245
2246
  */
2246
- isKlmsForWork() {
2247
+ isKmsForWork() {
2247
2248
  return this.id === ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK;
2248
2249
  }
2249
2250
  /**
2250
- * Check if chart accounts id is related for 'Klms travelled for sole' category
2251
+ * Check if chart accounts id is related for 'Kms travelled for sole' category
2251
2252
  */
2252
- isKlmsForSole() {
2253
+ isKmsForSole() {
2253
2254
  return this.id === ChartAccountsListEnum.KLMS_TRAVELLED;
2254
2255
  }
2255
2256
  /**
2256
- * Check if accounts id is related for KLMs category related to passed tank type
2257
+ * Check if accounts id is related for KMs category related to passed tank type
2257
2258
  */
2258
- isKLMsByTankType(tankType) {
2259
+ isKMsByTankType(tankType) {
2259
2260
  switch (tankType) {
2260
2261
  case TankTypeEnum.WORK:
2261
- return this.isKlmsForWork();
2262
+ return this.isKmsForWork();
2262
2263
  case TankTypeEnum.SOLE:
2263
- return this.isKlmsForSole();
2264
+ return this.isKmsForSole();
2264
2265
  default:
2265
2266
  return false;
2266
2267
  }
@@ -2421,8 +2422,9 @@ class SoleInvoiceTemplate$1 extends AbstractModel {
2421
2422
  }
2422
2423
 
2423
2424
  class SoleInvoiceTemplate extends SoleInvoiceTemplate$1 {
2424
- static create(businessId) {
2425
- return plainToClass(SoleInvoiceTemplate, { business: { id: businessId }, isTaxIncluded: false });
2425
+ constructor() {
2426
+ super(...arguments);
2427
+ this.isTaxIncluded = false;
2426
2428
  }
2427
2429
  }
2428
2430
  __decorate([
@@ -2459,6 +2461,7 @@ __decorate([
2459
2461
  /**
2460
2462
  * Class contains traveled kilometers and work usage percent in 12 weeks date range
2461
2463
  * @TODO Vik: Best period: move this and related logic to backend
2464
+ * @TODO Alex: check if we need this class when calculation refactored with backend
2462
2465
  */
2463
2466
  class LogbookPeriod {
2464
2467
  isEndOfYear() {
@@ -2482,6 +2485,7 @@ class Vehicle$1 extends AbstractModel {
2482
2485
  class VehicleLogbook$1 extends AbstractModel {
2483
2486
  }
2484
2487
 
2488
+ const moment = extendMoment(moment$1);
2485
2489
  class VehicleLogbook extends VehicleLogbook$1 {
2486
2490
  get kilometers() {
2487
2491
  return this.odometerEnd - this.odometerStart;
@@ -2495,13 +2499,18 @@ class VehicleLogbook extends VehicleLogbook$1 {
2495
2499
  isSoleTank() {
2496
2500
  return !!this.business;
2497
2501
  }
2502
+ /**
2503
+ * Get logbook period date range from logbook date and weeksInPeriod duration
2504
+ */
2505
+ getPeriod() {
2506
+ return moment.rangeFromInterval('weeks', VehicleLogbook.bestPeriodWeeks, this.date);
2507
+ }
2498
2508
  }
2499
2509
  /**
2500
- * 12 weeks in milliseconds
2501
- * "To work out your business-use percentage, you need to keep a logbook and the odometer readings for the logbook period.
2502
- * The logbook period is a minimum continuous period of 12 weeks." © Nicole Kelly
2510
+ * Logbook period duration in weeks.
2511
+ * https://taxtank.atlassian.net/wiki/spaces/TAXTANK/pages/211517441/Logbook+Vehicle
2503
2512
  */
2504
- VehicleLogbook.periodDuration = 7257600000;
2513
+ VehicleLogbook.bestPeriodWeeks = 12;
2505
2514
  __decorate([
2506
2515
  Type(() => Date)
2507
2516
  ], VehicleLogbook.prototype, "date", void 0);
@@ -2528,26 +2537,32 @@ var VehicleClaimDetailsMethodEnum;
2528
2537
  })(VehicleClaimDetailsMethodEnum || (VehicleClaimDetailsMethodEnum = {}));
2529
2538
 
2530
2539
  class VehicleClaimDetails extends VehicleClaimDetails$1 {
2540
+ constructor() {
2541
+ super(...arguments);
2542
+ /**
2543
+ * Init default values for the new instances
2544
+ */
2545
+ this.isManual = true;
2546
+ this.method = VehicleClaimDetailsMethodEnum.KMS;
2547
+ this.financialYear = new FinancialYear().year;
2548
+ }
2531
2549
  isLogbookMethod() {
2532
2550
  return this.method === VehicleClaimDetailsMethodEnum.LOGBOOK;
2533
2551
  }
2534
- isKlmsMethod() {
2552
+ isKmsMethod() {
2535
2553
  return this.method === VehicleClaimDetailsMethodEnum.KMS;
2536
2554
  }
2537
- // @TODO Alex: discuss with Vik and think about abstract method in AbstractModel
2538
- static create() {
2539
- return plainToClass(VehicleClaimDetails, {
2540
- isManual: true,
2541
- method: VehicleClaimDetailsMethodEnum.KMS,
2542
- financialYear: new FinancialYear().year
2543
- });
2544
- }
2545
2555
  }
2546
2556
  __decorate([
2547
2557
  Type(() => User)
2548
2558
  ], VehicleClaimDetails.prototype, "user", void 0);
2549
2559
 
2550
2560
  class VehicleClaim extends VehicleClaim$1 {
2561
+ constructor() {
2562
+ super(...arguments);
2563
+ this.kilometers = 0;
2564
+ this.workUsage = 0;
2565
+ }
2551
2566
  isWorkTank() {
2552
2567
  return !this.business;
2553
2568
  }
@@ -2558,9 +2573,9 @@ class VehicleClaim extends VehicleClaim$1 {
2558
2573
  return this.isSoleTank() ? TankTypeEnum.SOLE : TankTypeEnum.WORK;
2559
2574
  }
2560
2575
  /**
2561
- * Claim amount for KLMs method. Exists only for KLMs method.
2576
+ * Claim amount for KMs method. Exists only for KMs method.
2562
2577
  */
2563
- getKLMsClaimAmount(vehicleClaimRate) {
2578
+ getKMSClaimAmount(vehicleClaimRate) {
2564
2579
  return +(this.kilometers * vehicleClaimRate).toFixed(2);
2565
2580
  }
2566
2581
  /**
@@ -2575,19 +2590,14 @@ class VehicleClaim extends VehicleClaim$1 {
2575
2590
  // Math.abs because amount will be negative (because we sum expenses), but we don't want negative percent value
2576
2591
  return Math.abs(transactionsAmount) * this.workUsage / 100;
2577
2592
  }
2578
- getKlmsChartAccountsIdByTankType(tankType = this.tankType) {
2593
+ getAverageWeeklyKMS() {
2594
+ return this.kilometers / FinancialYear.weeksInYear;
2595
+ }
2596
+ static getKMSChartAccountsIdByTankType(tankType) {
2579
2597
  return tankType === TankTypeEnum.WORK
2580
2598
  ? ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK
2581
2599
  : ChartAccountsListEnum.KLMS_TRAVELLED;
2582
2600
  }
2583
- static create(details, business) {
2584
- return plainToClass(VehicleClaim, {
2585
- kilometers: 0,
2586
- workUsage: 0,
2587
- details,
2588
- business
2589
- });
2590
- }
2591
2601
  }
2592
2602
  /**
2593
2603
  * limit for kms claim method
@@ -2673,6 +2683,7 @@ var DepreciationCalculationEnum;
2673
2683
  (function (DepreciationCalculationEnum) {
2674
2684
  DepreciationCalculationEnum[DepreciationCalculationEnum["PRIME_COST"] = 1] = "PRIME_COST";
2675
2685
  DepreciationCalculationEnum[DepreciationCalculationEnum["DIMINISHING"] = 2] = "DIMINISHING";
2686
+ DepreciationCalculationEnum[DepreciationCalculationEnum["CAPITAL"] = 3] = "CAPITAL";
2676
2687
  DepreciationCalculationEnum[DepreciationCalculationEnum["LVP"] = 4] = "LVP";
2677
2688
  DepreciationCalculationEnum[DepreciationCalculationEnum["AMORTISATION"] = 5] = "AMORTISATION";
2678
2689
  DepreciationCalculationEnum[DepreciationCalculationEnum["SBP"] = 6] = "SBP";
@@ -2695,7 +2706,7 @@ class DepreciationForecast extends DepreciationForecast$1 {
2695
2706
  return this.claimAmount / this.daysApplied;
2696
2707
  }
2697
2708
  get daysApplied() {
2698
- return moment(this.toDate).diff(moment(this.fromDate), 'days');
2709
+ return moment$1(this.toDate).diff(moment$1(this.fromDate), 'days');
2699
2710
  }
2700
2711
  getDaysByMonth(month) {
2701
2712
  // @TODO find a better place
@@ -3047,9 +3058,9 @@ class Transaction extends Transaction$1 {
3047
3058
  }
3048
3059
  }
3049
3060
  /**
3050
- * Check if transaction has 'Klms travelled for work' chart accounts category
3061
+ * Check if transaction has 'Kms travelled for work' chart accounts category
3051
3062
  */
3052
- get isKlmsChartAccountsCategory() {
3063
+ get isKmsChartAccountsCategory() {
3053
3064
  return this.chartAccounts.id === ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK;
3054
3065
  }
3055
3066
  /**
@@ -3992,7 +4003,7 @@ class Property extends Property$1 {
3992
4003
  * ownership duration from purchase till sale
3993
4004
  */
3994
4005
  getOwnershipDuration(sale, unitOfTime = 'days') {
3995
- return moment(sale.contractDate).diff(moment(this.contractDate), unitOfTime);
4006
+ return moment$1(sale.contractDate).diff(moment$1(this.contractDate), unitOfTime);
3996
4007
  }
3997
4008
  /**
3998
4009
  * Tax Position = Income - Expense - Interest - Depreciation
@@ -4132,6 +4143,9 @@ __decorate([
4132
4143
  ], BankConnection.prototype, "bank", void 0);
4133
4144
 
4134
4145
  class BankAccount extends BankAccount$1 {
4146
+ get bank() {
4147
+ return this.bankConnection.bank;
4148
+ }
4135
4149
  /**
4136
4150
  * Get current opening balance amount
4137
4151
  */
@@ -4758,9 +4772,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
4758
4772
  class VehicleClaimCollection extends Collection {
4759
4773
  /**
4760
4774
  * Get remaining kilometers limit. Total limit ({@link VehicleClaim.totalKmsLimit}) - claimed kilometers from other vehicle claims
4761
- * @param claim may not exist when user come to vehicle claim page 1st time and not created claim yet
4762
4775
  */
4763
- getKlmsLimitForClaim(claim) {
4776
+ getKmsLimitForClaim(claim) {
4764
4777
  let collection = this;
4765
4778
  if (claim) {
4766
4779
  collection = collection.removeBy('id', claim.id);
@@ -4769,7 +4782,6 @@ class VehicleClaimCollection extends Collection {
4769
4782
  }
4770
4783
  /**
4771
4784
  * Get remaining work usage limit. Total limit ({@link VehicleClaim.totalWorkUsagePercent}) - claimed percent from other vehicle claims
4772
- * @param claim may not exist when user come to vehicle claim page 1st time and not created claim yet
4773
4785
  */
4774
4786
  getWorkUsageLimitForClaim(claim) {
4775
4787
  let collection = this;
@@ -4782,14 +4794,14 @@ class VehicleClaimCollection extends Collection {
4782
4794
 
4783
4795
  class VehicleLogbookCollection extends Collection {
4784
4796
  /**
4785
- * Best period may be calculated only when user has logbooks minimum for {@link VehicleLogbook.periodDuration}
4797
+ * Best period may be calculated only when user has logbooks minimum for VehicleLogbook.bestPeriodWeeks
4786
4798
  * @TODO Vik: Best period: move this and related logic to backend
4787
4799
  */
4788
4800
  isBestPeriodExist() {
4789
4801
  if (this.items.length < 2) {
4790
4802
  return false;
4791
4803
  }
4792
- return VehicleLogbook.periodDuration < (this.last.date.getTime() - this.first.date.getTime());
4804
+ return VehicleLogbook.bestPeriodWeeks < (this.last.date.getTime() - this.first.date.getTime());
4793
4805
  }
4794
4806
  /**
4795
4807
  * Get collection of non-personal logbooks (work-related, sole-related).
@@ -4799,15 +4811,14 @@ class VehicleLogbookCollection extends Collection {
4799
4811
  return this.filterBy('isPersonal', false);
4800
4812
  }
4801
4813
  /**
4802
- * Logbook Period is the best when it has the biggest work usage percent
4803
- * Best period duration is defined as {@link VehicleLogbook.periodDuration} by the ATO
4814
+ * Get Logbook Period with the biggest work usage percent
4815
+ * Best period duration is defined as VehicleLogbook.bestPeriodWeeks by the ATO
4804
4816
  * @TODO Vik: Best period: move this and related logic to backend
4805
4817
  */
4806
4818
  getBestPeriod() {
4807
4819
  if (!this.isBestPeriodExist()) {
4808
4820
  return null;
4809
4821
  }
4810
- // declare best period variable
4811
4822
  let bestPeriod;
4812
4823
  // get list of all logbooks available for best period calculation
4813
4824
  const claimableLogbooks = this.getClaimableLogbooks().toArray();
@@ -4817,12 +4828,12 @@ class VehicleLogbookCollection extends Collection {
4817
4828
  break;
4818
4829
  }
4819
4830
  // get date range started from current handling logbook date
4820
- const dateRange = this.getPeriodRange(claimableLogbooks[i].date);
4831
+ const dateRange = claimableLogbooks[i].getPeriod();
4821
4832
  // get all logbooks included in current logbook period
4822
- const logbooksInRange = this.filterByRange('date', dateRange.from, dateRange.to);
4833
+ const logbooksInRange = this.filterByRange('date', dateRange.start, dateRange.end);
4823
4834
  const currentPeriod = plainToClass(LogbookPeriod, {
4824
- from: dateRange.from,
4825
- to: dateRange.to,
4835
+ from: dateRange.start,
4836
+ to: dateRange.end,
4826
4837
  kilometers: logbooksInRange.getClaimableLogbooks().kilometers,
4827
4838
  workUsage: logbooksInRange.getWorkUsage(),
4828
4839
  logbooks: logbooksInRange
@@ -4856,28 +4867,15 @@ class VehicleLogbookCollection extends Collection {
4856
4867
  const workKilometers = this.getClaimableLogbooks().kilometers;
4857
4868
  return Math.round(workKilometers / this.kilometers * 100);
4858
4869
  }
4859
- /**
4860
- * Get LOGBOOK_PERIOD_DURATION date range from passed start date
4861
- * @TODO Vik: Best period: move this and related logic to backend
4862
- */
4863
- getPeriodRange(from) {
4864
- // set end date as VehicleLogbook.periodDuration after start date
4865
- let to = new Date(from.getTime() + VehicleLogbook.periodDuration);
4866
- const financialYear = new FinancialYear();
4867
- // set as period last VehicleLogbook.periodDuration of current year if period end date after end of current year
4868
- if (to > financialYear.endDate) {
4869
- to = financialYear.endDate;
4870
- from = new Date(to.getTime() - VehicleLogbook.periodDuration);
4871
- }
4872
- return { from, to };
4873
- }
4874
4870
  /**
4875
4871
  * Get list of logbooks related to passed vehicle claim
4876
4872
  */
4877
- getByVehicleClaim(claim) {
4878
- return claim.isWorkTank()
4879
- ? this.filterBy('tankType', TankTypeEnum.WORK)
4880
- : this.filterBy('business.id', claim.business.id);
4873
+ getByVehicleClaim(vehicleClaim) {
4874
+ return vehicleClaim.isSoleTank()
4875
+ // sole tank may have multiple vehicle claims, so we need to filter by business.id
4876
+ ? this.filterBy('business.id', vehicleClaim.business.id)
4877
+ // work tank may have only one vehicle claim, so we need to filter by tank type
4878
+ : this.filterBy('tankType', TankTypeEnum.WORK);
4881
4879
  }
4882
4880
  }
4883
4881
 
@@ -5011,9 +5009,9 @@ class BankTransactionCollection extends Collection {
5011
5009
 
5012
5010
  class ChartAccountsCollection extends Collection {
5013
5011
  /**
5014
- * Get 'Klms travelled for work' related chart account value
5012
+ * Get 'Kms travelled for work' related chart account value
5015
5013
  */
5016
- getVehicleKlmsRate(year = new FinancialYear().year) {
5014
+ getVehicleKmsRate(year = new FinancialYear().year) {
5017
5015
  return this.findBy('id', ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK).getValueByYear(year).value;
5018
5016
  }
5019
5017
  }
@@ -5271,6 +5269,9 @@ class TransactionCollection extends ExportableCollection {
5271
5269
  * Get list of vehicle transactions filtered by vehicle claim
5272
5270
  */
5273
5271
  getByVehicleClaim(vehicleClaim) {
5272
+ if (!vehicleClaim) {
5273
+ return this.create([]);
5274
+ }
5274
5275
  return vehicleClaim.isSoleTank()
5275
5276
  // sole tank may have multiple vehicle claims, so we need to filter by business.id
5276
5277
  ? this.getVehicleTransactions().filterBy('business.id', vehicleClaim.business.id)
@@ -5278,7 +5279,7 @@ class TransactionCollection extends ExportableCollection {
5278
5279
  : this.getVehicleTransactions().filterBy('tankType', TankTypeEnum.WORK);
5279
5280
  }
5280
5281
  /**
5281
- * Get list of vehicle transactions except KLMS transactions
5282
+ * Get list of vehicle transactions except KMS transactions
5282
5283
  */
5283
5284
  getLogbookTransactions() {
5284
5285
  return this
@@ -8101,7 +8102,7 @@ class MyTaxDeductions {
8101
8102
  return 0;
8102
8103
  }
8103
8104
  setVehicleClaimData() {
8104
- this.klmsMethodClaimAmount = this.vehicleClaim.getKLMsClaimAmount(this.vehicleClaimRate);
8105
+ this.klmsMethodClaimAmount = this.vehicleClaim.getKMSClaimAmount(this.vehicleClaimRate);
8105
8106
  this.totalExpensesAmount = this.vehicleClaim.getLogbookClaimAmount(new TransactionCollection([
8106
8107
  ...this.transactions.getByTankType(this.vehicleClaim.tankType),
8107
8108
  ...this.depreciations.getByTankType(this.vehicleClaim.tankType).toTransactions().toArray()
@@ -9008,10 +9009,7 @@ class VehicleClaimService extends RestService {
9008
9009
  * when details method changed, all claims current values become 0
9009
9010
  */
9010
9011
  listenVehicleClaimDetailsChanges() {
9011
- this.eventDispatcherService.on([
9012
- AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_CREATED,
9013
- AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED
9014
- ])
9012
+ this.eventDispatcherService.on(AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED)
9015
9013
  .subscribe(() => {
9016
9014
  this.resetCache();
9017
9015
  });
@@ -9036,14 +9034,17 @@ class VehicleClaimService extends RestService {
9036
9034
  * @TODO Vik: Best period move this and related logic to backend
9037
9035
  */
9038
9036
  updateWorkUsage(bestPeriod) {
9039
- // We are sure this.cache exist here because logbook best period calculation is based on vehicle claims,
9040
- // so before we can get logbook best period changes, we must get vehicle claims
9037
+ // no need to update if cache not exist
9038
+ if (!this.cache) {
9039
+ return;
9040
+ }
9041
+ // @TODO Vik (TT-2210): need batch endpoint for this update
9042
+ // @TODO Alex (TT-2210): fix frontend when endpoint ready
9041
9043
  const batch$ = this.cache.map((claim) => {
9042
9044
  const claimToUpdate = plainToClass(VehicleClaim, Object.assign({}, claim, { workUsage: bestPeriod === null || bestPeriod === void 0 ? void 0 : bestPeriod.getWorkUsageByClaim(claim) }));
9043
9045
  return this.update(claimToUpdate);
9044
9046
  });
9045
- // take(1) is using to avoid unnecessary callback calling whe user updated details directly
9046
- combineLatest(batch$).pipe(take(1)).subscribe();
9047
+ combineLatest(batch$).subscribe();
9047
9048
  }
9048
9049
  }
9049
9050
  VehicleClaimService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: VehicleClaimService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
@@ -9117,11 +9118,12 @@ class VehicleClaimDetailsService {
9117
9118
  * @TODO Vik: Best period move this and related logic to backend
9118
9119
  */
9119
9120
  updateToManual() {
9120
- // We are sure this.cache exist here because logbook best period calculation is based on vehicle claim details,
9121
- // so before we can get logbook best period changes, we must get vehicle claim details
9121
+ // no need to update if cache not exist
9122
+ if (!this.cache) {
9123
+ return;
9124
+ }
9122
9125
  const vehicleClaimDetails = plainToClass(VehicleClaimDetails, Object.assign({}, this.cache, { isManual: true }));
9123
- // take(1) is using to avoid unnecessary callback calling whe user updated details directly
9124
- this.update(vehicleClaimDetails).pipe(take(1)).subscribe();
9126
+ this.update(vehicleClaimDetails).subscribe();
9125
9127
  }
9126
9128
  }
9127
9129
  VehicleClaimDetailsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: VehicleClaimDetailsService, deps: [{ token: 'environment' }, { token: i1.HttpClient }, { token: EventDispatcherService }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -9412,7 +9414,7 @@ const ACCOUNT_SETUP_ITEMS = {
9412
9414
  }),
9413
9415
  [AccountSetupItemsEnum.WORK_LOGBOOK]: plainToClass(AccountSetupItem, {
9414
9416
  title: 'Set up your logbook method',
9415
- description: 'Do you use your vehicle for work? Select your method and the klms or logbook % to automate accurately all vehicle expenses throughout the year.',
9417
+ description: 'Do you use your vehicle for work? Select your method and the kms or logbook % to automate accurately all vehicle expenses throughout the year.',
9416
9418
  url: '/client/work-tank/logbook',
9417
9419
  urlFragment: 'productTour'
9418
9420
  }),
@@ -10288,7 +10290,6 @@ class TransactionService extends RestService {
10288
10290
  this.eventDispatcherService.on([
10289
10291
  AppEventTypeEnum.VEHICLE_CLAIM_CREATED,
10290
10292
  AppEventTypeEnum.VEHICLE_CLAIM_UPDATED,
10291
- AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_CREATED,
10292
10293
  AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED
10293
10294
  ]).subscribe(() => {
10294
10295
  this.resetCache();
@@ -10392,7 +10393,7 @@ class AccountSetupService {
10392
10393
  }
10393
10394
  // Bank feeds item is completed when user added at least one bank account (basiq or manual)
10394
10395
  batch.push(this.create(AccountSetupItemsEnum.BANK_FEEDS, this.bankAccountsService.get()));
10395
- // Logbook item is completed when user has at least one vehicle claim with any method (klms or logbook)
10396
+ // Logbook item is completed when user has at least one vehicle claim with any method (kms or logbook)
10396
10397
  batch.push(this.getLogbookItem());
10397
10398
  // @TODO waiting for sole tank forecast page
10398
10399
  // Sole item is completed when user added at least one sole income source
@@ -11532,7 +11533,6 @@ class DepreciationService extends RestService {
11532
11533
  this.eventDispatcherService.on([
11533
11534
  AppEventTypeEnum.VEHICLE_CLAIM_CREATED,
11534
11535
  AppEventTypeEnum.VEHICLE_CLAIM_UPDATED,
11535
- AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_CREATED,
11536
11536
  AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED
11537
11537
  ]).subscribe(() => {
11538
11538
  this.resetCache();
@@ -13822,7 +13822,7 @@ function taxReviewFilterPredicate(data, filter) {
13822
13822
  /**
13823
13823
  * Abstract form class
13824
13824
  * @TODO rename to AbstractFormGroup
13825
- * @TODO Alex: refactor: check and improve logic
13825
+ * @TODO Alex TT-2190: refactor: check and improve logic
13826
13826
  */
13827
13827
  class AbstractForm extends FormGroup {
13828
13828
  constructor(controls, model, validatorOrOpts, asyncValidator) {
@@ -13838,13 +13838,14 @@ class AbstractForm extends FormGroup {
13838
13838
  if (model && !model['id']) {
13839
13839
  this.markAsUnsaved();
13840
13840
  }
13841
- this.valueChanges.subscribe(() => {
13842
- !!model && !!model['id'] && isEqual(this.value, this.initialValue) ? this.markAsSaved() : this.markAsUnsaved();
13843
- });
13841
+ this.listenValueChanges();
13844
13842
  }
13845
13843
  get saved() {
13846
13844
  return !this.unsaved;
13847
13845
  }
13846
+ get currentValue() {
13847
+ return this.createModelInstance(Object.assign({}, this.model, this.getRawValue()));
13848
+ }
13848
13849
  /**
13849
13850
  * Check validation and return a new instance of generic model.
13850
13851
  * Merge form value to initial object
@@ -13873,6 +13874,11 @@ class AbstractForm extends FormGroup {
13873
13874
  createModelInstance(data = {}) {
13874
13875
  return plainToClass(this.modelClass, data);
13875
13876
  }
13877
+ listenValueChanges() {
13878
+ this.valueChanges.subscribe(() => {
13879
+ !!this.model && !!this.model['id'] && isEqual(this.value, this.initialValue) ? this.markAsSaved() : this.markAsUnsaved();
13880
+ });
13881
+ }
13876
13882
  }
13877
13883
 
13878
13884
  /**
@@ -14152,6 +14158,7 @@ class SoleBusinessForm extends AbstractForm {
14152
14158
  /**
14153
14159
  * Form array with bank account business allocations
14154
14160
  * @TODO create AbstractFormArray
14161
+ * @TODO Alex/Vik (TT-2184): copypasted from bank-account-properties.form, improve logic and create common parent class maybe
14155
14162
  */
14156
14163
  class SoleBusinessAllocationsForm extends FormArray {
14157
14164
  constructor(businessAllocations) {
@@ -14248,7 +14255,7 @@ class SoleInvoiceTemplateForm extends AbstractForm {
14248
14255
  name: new FormControl(invoiceTemplate.name, Validators.required),
14249
14256
  isTaxIncluded: new FormControl(invoiceTemplate.isTaxIncluded),
14250
14257
  term: new FormControl(invoiceTemplate.term, [Validators.required, Validators.min(0)]),
14251
- bankAccount: new FormControl(invoiceTemplate.bankAccount)
14258
+ bankAccount: new FormControl(invoiceTemplate.bankAccount, [Validators.required])
14252
14259
  }, invoiceTemplate);
14253
14260
  }
14254
14261
  }
@@ -14265,9 +14272,12 @@ class BankAccountAllocationForm extends AbstractForm {
14265
14272
  if (bankAccount === null || bankAccount === void 0 ? void 0 : bankAccount.isSoleTank()) {
14266
14273
  this.addControl('businessAllocations', new SoleBusinessAllocationsForm(bankAccount.businessAllocations));
14267
14274
  }
14268
- this.watchTankType();
14275
+ this.listenEvents();
14276
+ }
14277
+ listenEvents() {
14278
+ this.listenTankTypeChanges();
14269
14279
  }
14270
- watchTankType() {
14280
+ listenTankTypeChanges() {
14271
14281
  this.get('tankType').valueChanges.subscribe((tankType) => {
14272
14282
  var _a, _b;
14273
14283
  this.removeControl('bankAccountProperties');
@@ -14928,9 +14938,14 @@ class VehicleClaimForm extends AbstractForm {
14928
14938
  }),
14929
14939
  workUsage: new FormControl({
14930
14940
  value: vehicleClaim.workUsage,
14931
- disabled: !details.isManual || details.isKlmsMethod()
14941
+ disabled: !details.isManual || details.isKmsMethod()
14932
14942
  })
14933
14943
  }, vehicleClaim);
14944
+ this.vehicleClaim = vehicleClaim;
14945
+ this.details = details;
14946
+ }
14947
+ getAverageWeeklyKMS() {
14948
+ return this.get('kilometers').value / FinancialYear.weeksInYear;
14934
14949
  }
14935
14950
  }
14936
14951
 
@@ -14938,16 +14953,12 @@ class VehicleClaimForm extends AbstractForm {
14938
14953
  * Add/Edit vehicle claim details form
14939
14954
  */
14940
14955
  class VehicleClaimDetailsForm extends AbstractForm {
14941
- /**
14942
- * @param vehicleClaimDetails required because we create a new details with prefilled data (like Financial year)
14943
- * @param logbooks required for isManual field disabled state management
14944
- */
14945
- constructor(vehicleClaimDetails, logbooks) {
14956
+ constructor(vehicleClaimDetails, isBestPeriodExist) {
14946
14957
  super({
14947
14958
  method: new FormControl(vehicleClaimDetails.method, Validators.required),
14948
14959
  isManual: new FormControl({
14949
14960
  value: vehicleClaimDetails.isManual,
14950
- disabled: !logbooks.isBestPeriodExist()
14961
+ disabled: !isBestPeriodExist
14951
14962
  }),
14952
14963
  }, vehicleClaimDetails);
14953
14964
  }
@@ -14972,30 +14983,38 @@ class VehicleLogbookForm extends AbstractForm {
14972
14983
  date: new FormControl(logbook.date, Validators.required),
14973
14984
  odometerStart: new FormControl(logbook.odometerStart, Validators.required),
14974
14985
  odometerEnd: new FormControl(logbook.odometerEnd, Validators.required),
14975
- business: new FormControl(logbook.business),
14976
- // @TODO Alex: remove when backend fixed
14977
- purpose: new FormControl(VehicleLogbookPurposeEnum.BUSINESS)
14986
+ business: new FormControl(logbook.business)
14978
14987
  }, logbook);
14979
14988
  this.logbook = logbook;
14980
14989
  this.logbooks = logbooks;
14990
+ this.updateStateAndValidators();
14991
+ }
14992
+ /**
14993
+ * Set logbook validators and disable state depends of initial logbook and its place in the whole list
14994
+ */
14995
+ updateStateAndValidators() {
14981
14996
  switch (true) {
14982
14997
  // Create the first or edit the single logbook
14983
- case !logbook.id && !logbooks.length:
14984
- case !!logbook.id && logbooks.length === 1:
14998
+ case !this.logbook.id && !this.logbooks.length:
14999
+ case !!this.logbook.id && this.logbooks.length === 1:
14985
15000
  this.get('odometerStart').setValidators(Validators.min(0));
14986
15001
  this.get('date').setValidators(dateRangeValidator(new FinancialYear().startDate, new FinancialYear().endDate));
14987
15002
  break;
14988
- // Create the non-first or edit the last logbook
14989
- case !logbook.id && !!logbooks.length:
14990
- case !!logbook.id && logbook.id === logbooks.last.id && logbooks.length > 1:
15003
+ // Create the non-first
15004
+ case !this.logbook.id && !!this.logbooks.length:
14991
15005
  this.get('odometerStart').disable();
14992
- this.get('odometerEnd').setValidators(Validators.min(logbooks.last.odometerEnd));
14993
- if (!!logbook.id) {
14994
- }
14995
- this.get('date').setValidators(dateRangeValidator(logbooks.last.date, new FinancialYear().endDate));
15006
+ this.get('odometerEnd').setValidators(Validators.min(this.logbooks.last.odometerEnd));
15007
+ this.get('date').setValidators(dateRangeValidator(this.logbooks.last.date, new FinancialYear().endDate));
15008
+ break;
15009
+ // Edit the last logbook
15010
+ case !!this.logbook.id && this.logbook.id === this.logbooks.last.id && this.logbooks.length > 1:
15011
+ this.get('odometerStart').disable();
15012
+ this.get('odometerEnd').setValidators(Validators.min(this.logbooks.last.odometerEnd));
15013
+ const preLastDate = this.logbooks.toArray()[this.logbooks.length - 1].date;
15014
+ this.get('date').setValidators(dateRangeValidator(preLastDate, new FinancialYear().endDate));
14996
15015
  break;
14997
15016
  // Edit the non-last logbook
14998
- case !!logbook.id && logbook.id !== logbooks.last.id && logbooks.length > 1:
15017
+ case !!this.logbook.id && this.logbook.id !== this.logbooks.last.id && this.logbooks.length > 1:
14999
15018
  this.get('odometerStart').disable();
15000
15019
  this.get('odometerEnd').disable();
15001
15020
  this.get('date').disable();