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
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('@angular/common/http'), require('rxjs'), require('rxjs/operators'), require('class-transformer'), require('@auth0/angular-jwt'), require('lodash/get'), require('lodash/last'), require('lodash/flatten'), require('lodash/hasIn'), require('lodash/first'), require('moment'), require('moment-range'), require('lodash/uniqBy'), require('lodash/concat'), require('rxjs/internal/observable/throwError'), require('lodash/cloneDeep'), require('lodash/compact'), require('@angular/forms'), require('lodash/isEqual'), require('lodash/fromPairs'), require('lodash'), require('event-source-polyfill/src/eventsource.min.js'), require('@angular/router'), require('lodash/clone'), require('html2pdf.js'), require('jspdf'), require('jspdf-autotable'), require('@stripe/stripe-js'), require('xlsx'), require('file-saver')) :
3
3
  typeof define === 'function' && define.amd ? define('taxtank-core', ['exports', '@angular/core', '@angular/common', '@angular/common/http', 'rxjs', 'rxjs/operators', 'class-transformer', '@auth0/angular-jwt', 'lodash/get', 'lodash/last', 'lodash/flatten', 'lodash/hasIn', 'lodash/first', 'moment', 'moment-range', 'lodash/uniqBy', 'lodash/concat', 'rxjs/internal/observable/throwError', 'lodash/cloneDeep', 'lodash/compact', '@angular/forms', 'lodash/isEqual', 'lodash/fromPairs', 'lodash', 'event-source-polyfill/src/eventsource.min.js', '@angular/router', 'lodash/clone', 'html2pdf.js', 'jspdf', 'jspdf-autotable', '@stripe/stripe-js', 'xlsx', 'file-saver'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["taxtank-core"] = {}, global.ng.core, global.ng.common, global.ng.common.http, global.rxjs, global.rxjs.operators, global.classTransformer, global.angularJwt, global.get, global.last, global.flatten, global.hasIn, global.first, global.moment, global.momentRange, global.uniqBy, global.concat, global.rxjs["internal/observable/throwError"], global.cloneDeep$1, global.compact, global.ng.forms, global.isEqual, global.fromPairs, global._, global.eventsource_min_js, global.ng.router, global.clone, global.html2pdf, global.jsPDF, global.autoTable, global.stripeJs, global.xlsx, global.FileSaver));
5
- })(this, (function (exports, i0, i1$1, i1, rxjs, operators, classTransformer, angularJwt, get, last, flatten, hasIn, first, moment, momentRange, uniqBy, concat, throwError, cloneDeep$1, compact, forms, isEqual, fromPairs, _, eventsource_min_js, i1$2, clone, html2pdf, jsPDF, autoTable, stripeJs, xlsx, FileSaver) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["taxtank-core"] = {}, global.ng.core, global.ng.common, global.ng.common.http, global.rxjs, global.rxjs.operators, global.classTransformer, global.angularJwt, global.get, global.last, global.flatten, global.hasIn, global.first, global.moment$1, global.momentRange, global.uniqBy, global.concat, global.rxjs["internal/observable/throwError"], global.cloneDeep$1, global.compact, global.ng.forms, global.isEqual, global.fromPairs, global._, global.eventsource_min_js, global.ng.router, global.clone, global.html2pdf, global.jsPDF, global.autoTable, global.stripeJs, global.xlsx, global.FileSaver));
5
+ })(this, (function (exports, i0, i1$1, i1, rxjs, operators, classTransformer, angularJwt, get, last, flatten, hasIn, first, moment$1, momentRange, uniqBy, concat, throwError, cloneDeep$1, compact, forms, isEqual, fromPairs, _, eventsource_min_js, i1$2, clone, html2pdf, jsPDF, autoTable, stripeJs, xlsx, FileSaver) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -32,7 +32,7 @@
32
32
  var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
33
33
  var hasIn__default = /*#__PURE__*/_interopDefaultLegacy(hasIn);
34
34
  var first__default = /*#__PURE__*/_interopDefaultLegacy(first);
35
- var moment__namespace = /*#__PURE__*/_interopNamespace(moment);
35
+ var moment__namespace = /*#__PURE__*/_interopNamespace(moment$1);
36
36
  var uniqBy__default = /*#__PURE__*/_interopDefaultLegacy(uniqBy);
37
37
  var concat__default = /*#__PURE__*/_interopDefaultLegacy(concat);
38
38
  var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep$1);
@@ -1674,6 +1674,7 @@
1674
1674
  };
1675
1675
  return FinancialYear;
1676
1676
  }());
1677
+ FinancialYear.weeksInYear = 52;
1677
1678
  FinancialYear.startMonthIndex = 6;
1678
1679
 
1679
1680
  /**
@@ -2983,26 +2984,26 @@
2983
2984
  return this.name;
2984
2985
  };
2985
2986
  /**
2986
- * Check if chart accounts id is related for 'Klms travelled for work' category
2987
+ * Check if chart accounts id is related for 'Kms travelled for work' category
2987
2988
  */
2988
- ChartAccounts.prototype.isKlmsForWork = function () {
2989
+ ChartAccounts.prototype.isKmsForWork = function () {
2989
2990
  return this.id === exports.ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK;
2990
2991
  };
2991
2992
  /**
2992
- * Check if chart accounts id is related for 'Klms travelled for sole' category
2993
+ * Check if chart accounts id is related for 'Kms travelled for sole' category
2993
2994
  */
2994
- ChartAccounts.prototype.isKlmsForSole = function () {
2995
+ ChartAccounts.prototype.isKmsForSole = function () {
2995
2996
  return this.id === exports.ChartAccountsListEnum.KLMS_TRAVELLED;
2996
2997
  };
2997
2998
  /**
2998
- * Check if accounts id is related for KLMs category related to passed tank type
2999
+ * Check if accounts id is related for KMs category related to passed tank type
2999
3000
  */
3000
- ChartAccounts.prototype.isKLMsByTankType = function (tankType) {
3001
+ ChartAccounts.prototype.isKMsByTankType = function (tankType) {
3001
3002
  switch (tankType) {
3002
3003
  case exports.TankTypeEnum.WORK:
3003
- return this.isKlmsForWork();
3004
+ return this.isKmsForWork();
3004
3005
  case exports.TankTypeEnum.SOLE:
3005
- return this.isKlmsForSole();
3006
+ return this.isKmsForSole();
3006
3007
  default:
3007
3008
  return false;
3008
3009
  }
@@ -3190,11 +3191,10 @@
3190
3191
  var SoleInvoiceTemplate = /** @class */ (function (_super) {
3191
3192
  __extends(SoleInvoiceTemplate, _super);
3192
3193
  function SoleInvoiceTemplate() {
3193
- return _super !== null && _super.apply(this, arguments) || this;
3194
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3195
+ _this.isTaxIncluded = false;
3196
+ return _this;
3194
3197
  }
3195
- SoleInvoiceTemplate.create = function (businessId) {
3196
- return classTransformer.plainToClass(SoleInvoiceTemplate, { business: { id: businessId }, isTaxIncluded: false });
3197
- };
3198
3198
  return SoleInvoiceTemplate;
3199
3199
  }(SoleInvoiceTemplate$1));
3200
3200
  __decorate([
@@ -3236,6 +3236,7 @@
3236
3236
  /**
3237
3237
  * Class contains traveled kilometers and work usage percent in 12 weeks date range
3238
3238
  * @TODO Vik: Best period: move this and related logic to backend
3239
+ * @TODO Alex: check if we need this class when calculation refactored with backend
3239
3240
  */
3240
3241
  var LogbookPeriod = /** @class */ (function () {
3241
3242
  function LogbookPeriod() {
@@ -3272,6 +3273,7 @@
3272
3273
  return VehicleLogbook;
3273
3274
  }(AbstractModel));
3274
3275
 
3276
+ var moment = momentRange.extendMoment(moment__namespace);
3275
3277
  var VehicleLogbook = /** @class */ (function (_super) {
3276
3278
  __extends(VehicleLogbook, _super);
3277
3279
  function VehicleLogbook() {
@@ -3297,14 +3299,19 @@
3297
3299
  VehicleLogbook.prototype.isSoleTank = function () {
3298
3300
  return !!this.business;
3299
3301
  };
3302
+ /**
3303
+ * Get logbook period date range from logbook date and weeksInPeriod duration
3304
+ */
3305
+ VehicleLogbook.prototype.getPeriod = function () {
3306
+ return moment.rangeFromInterval('weeks', VehicleLogbook.bestPeriodWeeks, this.date);
3307
+ };
3300
3308
  return VehicleLogbook;
3301
3309
  }(VehicleLogbook$1));
3302
3310
  /**
3303
- * 12 weeks in milliseconds
3304
- * "To work out your business-use percentage, you need to keep a logbook and the odometer readings for the logbook period.
3305
- * The logbook period is a minimum continuous period of 12 weeks." © Nicole Kelly
3311
+ * Logbook period duration in weeks.
3312
+ * https://taxtank.atlassian.net/wiki/spaces/TAXTANK/pages/211517441/Logbook+Vehicle
3306
3313
  */
3307
- VehicleLogbook.periodDuration = 7257600000;
3314
+ VehicleLogbook.bestPeriodWeeks = 12;
3308
3315
  __decorate([
3309
3316
  classTransformer.Type(function () { return Date; })
3310
3317
  ], VehicleLogbook.prototype, "date", void 0);
@@ -3348,22 +3355,21 @@
3348
3355
  var VehicleClaimDetails = /** @class */ (function (_super) {
3349
3356
  __extends(VehicleClaimDetails, _super);
3350
3357
  function VehicleClaimDetails() {
3351
- return _super !== null && _super.apply(this, arguments) || this;
3358
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3359
+ /**
3360
+ * Init default values for the new instances
3361
+ */
3362
+ _this.isManual = true;
3363
+ _this.method = exports.VehicleClaimDetailsMethodEnum.KMS;
3364
+ _this.financialYear = new FinancialYear().year;
3365
+ return _this;
3352
3366
  }
3353
3367
  VehicleClaimDetails.prototype.isLogbookMethod = function () {
3354
3368
  return this.method === exports.VehicleClaimDetailsMethodEnum.LOGBOOK;
3355
3369
  };
3356
- VehicleClaimDetails.prototype.isKlmsMethod = function () {
3370
+ VehicleClaimDetails.prototype.isKmsMethod = function () {
3357
3371
  return this.method === exports.VehicleClaimDetailsMethodEnum.KMS;
3358
3372
  };
3359
- // @TODO Alex: discuss with Vik and think about abstract method in AbstractModel
3360
- VehicleClaimDetails.create = function () {
3361
- return classTransformer.plainToClass(VehicleClaimDetails, {
3362
- isManual: true,
3363
- method: exports.VehicleClaimDetailsMethodEnum.KMS,
3364
- financialYear: new FinancialYear().year
3365
- });
3366
- };
3367
3373
  return VehicleClaimDetails;
3368
3374
  }(VehicleClaimDetails$1));
3369
3375
  __decorate([
@@ -3373,7 +3379,10 @@
3373
3379
  var VehicleClaim = /** @class */ (function (_super) {
3374
3380
  __extends(VehicleClaim, _super);
3375
3381
  function VehicleClaim() {
3376
- return _super !== null && _super.apply(this, arguments) || this;
3382
+ var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
3383
+ _this.kilometers = 0;
3384
+ _this.workUsage = 0;
3385
+ return _this;
3377
3386
  }
3378
3387
  VehicleClaim.prototype.isWorkTank = function () {
3379
3388
  return !this.business;
@@ -3389,9 +3398,9 @@
3389
3398
  configurable: true
3390
3399
  });
3391
3400
  /**
3392
- * Claim amount for KLMs method. Exists only for KLMs method.
3401
+ * Claim amount for KMs method. Exists only for KMs method.
3393
3402
  */
3394
- VehicleClaim.prototype.getKLMsClaimAmount = function (vehicleClaimRate) {
3403
+ VehicleClaim.prototype.getKMSClaimAmount = function (vehicleClaimRate) {
3395
3404
  return +(this.kilometers * vehicleClaimRate).toFixed(2);
3396
3405
  };
3397
3406
  /**
@@ -3406,20 +3415,14 @@
3406
3415
  // Math.abs because amount will be negative (because we sum expenses), but we don't want negative percent value
3407
3416
  return Math.abs(transactionsAmount) * this.workUsage / 100;
3408
3417
  };
3409
- VehicleClaim.prototype.getKlmsChartAccountsIdByTankType = function (tankType) {
3410
- if (tankType === void 0) { tankType = this.tankType; }
3418
+ VehicleClaim.prototype.getAverageWeeklyKMS = function () {
3419
+ return this.kilometers / FinancialYear.weeksInYear;
3420
+ };
3421
+ VehicleClaim.getKMSChartAccountsIdByTankType = function (tankType) {
3411
3422
  return tankType === exports.TankTypeEnum.WORK
3412
3423
  ? exports.ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK
3413
3424
  : exports.ChartAccountsListEnum.KLMS_TRAVELLED;
3414
3425
  };
3415
- VehicleClaim.create = function (details, business) {
3416
- return classTransformer.plainToClass(VehicleClaim, {
3417
- kilometers: 0,
3418
- workUsage: 0,
3419
- details: details,
3420
- business: business
3421
- });
3422
- };
3423
3426
  return VehicleClaim;
3424
3427
  }(VehicleClaim$1));
3425
3428
  /**
@@ -3521,6 +3524,7 @@
3521
3524
  (function (DepreciationCalculationEnum) {
3522
3525
  DepreciationCalculationEnum[DepreciationCalculationEnum["PRIME_COST"] = 1] = "PRIME_COST";
3523
3526
  DepreciationCalculationEnum[DepreciationCalculationEnum["DIMINISHING"] = 2] = "DIMINISHING";
3527
+ DepreciationCalculationEnum[DepreciationCalculationEnum["CAPITAL"] = 3] = "CAPITAL";
3524
3528
  DepreciationCalculationEnum[DepreciationCalculationEnum["LVP"] = 4] = "LVP";
3525
3529
  DepreciationCalculationEnum[DepreciationCalculationEnum["AMORTISATION"] = 5] = "AMORTISATION";
3526
3530
  DepreciationCalculationEnum[DepreciationCalculationEnum["SBP"] = 6] = "SBP";
@@ -4057,9 +4061,9 @@
4057
4061
  enumerable: false,
4058
4062
  configurable: true
4059
4063
  });
4060
- Object.defineProperty(Transaction.prototype, "isKlmsChartAccountsCategory", {
4064
+ Object.defineProperty(Transaction.prototype, "isKmsChartAccountsCategory", {
4061
4065
  /**
4062
- * Check if transaction has 'Klms travelled for work' chart accounts category
4066
+ * Check if transaction has 'Kms travelled for work' chart accounts category
4063
4067
  */
4064
4068
  get: function () {
4065
4069
  return this.chartAccounts.id === exports.ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK;
@@ -5474,6 +5478,13 @@
5474
5478
  function BankAccount() {
5475
5479
  return _super !== null && _super.apply(this, arguments) || this;
5476
5480
  }
5481
+ Object.defineProperty(BankAccount.prototype, "bank", {
5482
+ get: function () {
5483
+ return this.bankConnection.bank;
5484
+ },
5485
+ enumerable: false,
5486
+ configurable: true
5487
+ });
5477
5488
  /**
5478
5489
  * Get current opening balance amount
5479
5490
  */
@@ -6150,9 +6161,8 @@
6150
6161
  }
6151
6162
  /**
6152
6163
  * Get remaining kilometers limit. Total limit ({@link VehicleClaim.totalKmsLimit}) - claimed kilometers from other vehicle claims
6153
- * @param claim may not exist when user come to vehicle claim page 1st time and not created claim yet
6154
6164
  */
6155
- VehicleClaimCollection.prototype.getKlmsLimitForClaim = function (claim) {
6165
+ VehicleClaimCollection.prototype.getKmsLimitForClaim = function (claim) {
6156
6166
  var collection = this;
6157
6167
  if (claim) {
6158
6168
  collection = collection.removeBy('id', claim.id);
@@ -6161,7 +6171,6 @@
6161
6171
  };
6162
6172
  /**
6163
6173
  * Get remaining work usage limit. Total limit ({@link VehicleClaim.totalWorkUsagePercent}) - claimed percent from other vehicle claims
6164
- * @param claim may not exist when user come to vehicle claim page 1st time and not created claim yet
6165
6174
  */
6166
6175
  VehicleClaimCollection.prototype.getWorkUsageLimitForClaim = function (claim) {
6167
6176
  var collection = this;
@@ -6179,14 +6188,14 @@
6179
6188
  return _super !== null && _super.apply(this, arguments) || this;
6180
6189
  }
6181
6190
  /**
6182
- * Best period may be calculated only when user has logbooks minimum for {@link VehicleLogbook.periodDuration}
6191
+ * Best period may be calculated only when user has logbooks minimum for VehicleLogbook.bestPeriodWeeks
6183
6192
  * @TODO Vik: Best period: move this and related logic to backend
6184
6193
  */
6185
6194
  VehicleLogbookCollection.prototype.isBestPeriodExist = function () {
6186
6195
  if (this.items.length < 2) {
6187
6196
  return false;
6188
6197
  }
6189
- return VehicleLogbook.periodDuration < (this.last.date.getTime() - this.first.date.getTime());
6198
+ return VehicleLogbook.bestPeriodWeeks < (this.last.date.getTime() - this.first.date.getTime());
6190
6199
  };
6191
6200
  /**
6192
6201
  * Get collection of non-personal logbooks (work-related, sole-related).
@@ -6196,15 +6205,14 @@
6196
6205
  return this.filterBy('isPersonal', false);
6197
6206
  };
6198
6207
  /**
6199
- * Logbook Period is the best when it has the biggest work usage percent
6200
- * Best period duration is defined as {@link VehicleLogbook.periodDuration} by the ATO
6208
+ * Get Logbook Period with the biggest work usage percent
6209
+ * Best period duration is defined as VehicleLogbook.bestPeriodWeeks by the ATO
6201
6210
  * @TODO Vik: Best period: move this and related logic to backend
6202
6211
  */
6203
6212
  VehicleLogbookCollection.prototype.getBestPeriod = function () {
6204
6213
  if (!this.isBestPeriodExist()) {
6205
6214
  return null;
6206
6215
  }
6207
- // declare best period variable
6208
6216
  var bestPeriod;
6209
6217
  // get list of all logbooks available for best period calculation
6210
6218
  var claimableLogbooks = this.getClaimableLogbooks().toArray();
@@ -6214,12 +6222,12 @@
6214
6222
  break;
6215
6223
  }
6216
6224
  // get date range started from current handling logbook date
6217
- var dateRange = this.getPeriodRange(claimableLogbooks[i].date);
6225
+ var dateRange = claimableLogbooks[i].getPeriod();
6218
6226
  // get all logbooks included in current logbook period
6219
- var logbooksInRange = this.filterByRange('date', dateRange.from, dateRange.to);
6227
+ var logbooksInRange = this.filterByRange('date', dateRange.start, dateRange.end);
6220
6228
  var currentPeriod = classTransformer.plainToClass(LogbookPeriod, {
6221
- from: dateRange.from,
6222
- to: dateRange.to,
6229
+ from: dateRange.start,
6230
+ to: dateRange.end,
6223
6231
  kilometers: logbooksInRange.getClaimableLogbooks().kilometers,
6224
6232
  workUsage: logbooksInRange.getWorkUsage(),
6225
6233
  logbooks: logbooksInRange
@@ -6257,28 +6265,15 @@
6257
6265
  var workKilometers = this.getClaimableLogbooks().kilometers;
6258
6266
  return Math.round(workKilometers / this.kilometers * 100);
6259
6267
  };
6260
- /**
6261
- * Get LOGBOOK_PERIOD_DURATION date range from passed start date
6262
- * @TODO Vik: Best period: move this and related logic to backend
6263
- */
6264
- VehicleLogbookCollection.prototype.getPeriodRange = function (from) {
6265
- // set end date as VehicleLogbook.periodDuration after start date
6266
- var to = new Date(from.getTime() + VehicleLogbook.periodDuration);
6267
- var financialYear = new FinancialYear();
6268
- // set as period last VehicleLogbook.periodDuration of current year if period end date after end of current year
6269
- if (to > financialYear.endDate) {
6270
- to = financialYear.endDate;
6271
- from = new Date(to.getTime() - VehicleLogbook.periodDuration);
6272
- }
6273
- return { from: from, to: to };
6274
- };
6275
6268
  /**
6276
6269
  * Get list of logbooks related to passed vehicle claim
6277
6270
  */
6278
- VehicleLogbookCollection.prototype.getByVehicleClaim = function (claim) {
6279
- return claim.isWorkTank()
6280
- ? this.filterBy('tankType', exports.TankTypeEnum.WORK)
6281
- : this.filterBy('business.id', claim.business.id);
6271
+ VehicleLogbookCollection.prototype.getByVehicleClaim = function (vehicleClaim) {
6272
+ return vehicleClaim.isSoleTank()
6273
+ // sole tank may have multiple vehicle claims, so we need to filter by business.id
6274
+ ? this.filterBy('business.id', vehicleClaim.business.id)
6275
+ // work tank may have only one vehicle claim, so we need to filter by tank type
6276
+ : this.filterBy('tankType', exports.TankTypeEnum.WORK);
6282
6277
  };
6283
6278
  return VehicleLogbookCollection;
6284
6279
  }(Collection));
@@ -6438,9 +6433,9 @@
6438
6433
  return _super !== null && _super.apply(this, arguments) || this;
6439
6434
  }
6440
6435
  /**
6441
- * Get 'Klms travelled for work' related chart account value
6436
+ * Get 'Kms travelled for work' related chart account value
6442
6437
  */
6443
- ChartAccountsCollection.prototype.getVehicleKlmsRate = function (year) {
6438
+ ChartAccountsCollection.prototype.getVehicleKmsRate = function (year) {
6444
6439
  if (year === void 0) { year = new FinancialYear().year; }
6445
6440
  return this.findBy('id', exports.ChartAccountsListEnum.KLMS_TRAVELLED_FOR_WORK).getValueByYear(year).value;
6446
6441
  };
@@ -6801,6 +6796,9 @@
6801
6796
  * Get list of vehicle transactions filtered by vehicle claim
6802
6797
  */
6803
6798
  TransactionCollection.prototype.getByVehicleClaim = function (vehicleClaim) {
6799
+ if (!vehicleClaim) {
6800
+ return this.create([]);
6801
+ }
6804
6802
  return vehicleClaim.isSoleTank()
6805
6803
  // sole tank may have multiple vehicle claims, so we need to filter by business.id
6806
6804
  ? this.getVehicleTransactions().filterBy('business.id', vehicleClaim.business.id)
@@ -6808,7 +6806,7 @@
6808
6806
  : this.getVehicleTransactions().filterBy('tankType', exports.TankTypeEnum.WORK);
6809
6807
  };
6810
6808
  /**
6811
- * Get list of vehicle transactions except KLMS transactions
6809
+ * Get list of vehicle transactions except KMS transactions
6812
6810
  */
6813
6811
  TransactionCollection.prototype.getLogbookTransactions = function () {
6814
6812
  return this
@@ -10176,7 +10174,7 @@
10176
10174
  return 0;
10177
10175
  };
10178
10176
  MyTaxDeductions.prototype.setVehicleClaimData = function () {
10179
- this.klmsMethodClaimAmount = this.vehicleClaim.getKLMsClaimAmount(this.vehicleClaimRate);
10177
+ this.klmsMethodClaimAmount = this.vehicleClaim.getKMSClaimAmount(this.vehicleClaimRate);
10180
10178
  this.totalExpensesAmount = this.vehicleClaim.getLogbookClaimAmount(new TransactionCollection(__spreadArray(__spreadArray([], __read(this.transactions.getByTankType(this.vehicleClaim.tankType))), __read(this.depreciations.getByTankType(this.vehicleClaim.tankType).toTransactions().toArray()))));
10181
10179
  };
10182
10180
  /**
@@ -11248,10 +11246,7 @@
11248
11246
  */
11249
11247
  VehicleClaimService.prototype.listenVehicleClaimDetailsChanges = function () {
11250
11248
  var _this = this;
11251
- this.eventDispatcherService.on([
11252
- exports.AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_CREATED,
11253
- exports.AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED
11254
- ])
11249
+ this.eventDispatcherService.on(exports.AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED)
11255
11250
  .subscribe(function () {
11256
11251
  _this.resetCache();
11257
11252
  });
@@ -11278,14 +11273,17 @@
11278
11273
  */
11279
11274
  VehicleClaimService.prototype.updateWorkUsage = function (bestPeriod) {
11280
11275
  var _this = this;
11281
- // We are sure this.cache exist here because logbook best period calculation is based on vehicle claims,
11282
- // so before we can get logbook best period changes, we must get vehicle claims
11276
+ // no need to update if cache not exist
11277
+ if (!this.cache) {
11278
+ return;
11279
+ }
11280
+ // @TODO Vik (TT-2210): need batch endpoint for this update
11281
+ // @TODO Alex (TT-2210): fix frontend when endpoint ready
11283
11282
  var batch$ = this.cache.map(function (claim) {
11284
11283
  var claimToUpdate = classTransformer.plainToClass(VehicleClaim, Object.assign({}, claim, { workUsage: bestPeriod === null || bestPeriod === void 0 ? void 0 : bestPeriod.getWorkUsageByClaim(claim) }));
11285
11284
  return _this.update(claimToUpdate);
11286
11285
  });
11287
- // take(1) is using to avoid unnecessary callback calling whe user updated details directly
11288
- rxjs.combineLatest(batch$).pipe(operators.take(1)).subscribe();
11286
+ rxjs.combineLatest(batch$).subscribe();
11289
11287
  };
11290
11288
  return VehicleClaimService;
11291
11289
  }(RestService));
@@ -11364,11 +11362,12 @@
11364
11362
  * @TODO Vik: Best period move this and related logic to backend
11365
11363
  */
11366
11364
  VehicleClaimDetailsService.prototype.updateToManual = function () {
11367
- // We are sure this.cache exist here because logbook best period calculation is based on vehicle claim details,
11368
- // so before we can get logbook best period changes, we must get vehicle claim details
11365
+ // no need to update if cache not exist
11366
+ if (!this.cache) {
11367
+ return;
11368
+ }
11369
11369
  var vehicleClaimDetails = classTransformer.plainToClass(VehicleClaimDetails, Object.assign({}, this.cache, { isManual: true }));
11370
- // take(1) is using to avoid unnecessary callback calling whe user updated details directly
11371
- this.update(vehicleClaimDetails).pipe(operators.take(1)).subscribe();
11370
+ this.update(vehicleClaimDetails).subscribe();
11372
11371
  };
11373
11372
  return VehicleClaimDetailsService;
11374
11373
  }());
@@ -11688,7 +11687,7 @@
11688
11687
  }),
11689
11688
  _a[AccountSetupItemsEnum.WORK_LOGBOOK] = classTransformer.plainToClass(AccountSetupItem, {
11690
11689
  title: 'Set up your logbook method',
11691
- 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.',
11690
+ 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.',
11692
11691
  url: '/client/work-tank/logbook',
11693
11692
  urlFragment: 'productTour'
11694
11693
  }),
@@ -12630,7 +12629,6 @@
12630
12629
  this.eventDispatcherService.on([
12631
12630
  exports.AppEventTypeEnum.VEHICLE_CLAIM_CREATED,
12632
12631
  exports.AppEventTypeEnum.VEHICLE_CLAIM_UPDATED,
12633
- exports.AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_CREATED,
12634
12632
  exports.AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED
12635
12633
  ]).subscribe(function () {
12636
12634
  _this.resetCache();
@@ -12738,7 +12736,7 @@
12738
12736
  }
12739
12737
  // Bank feeds item is completed when user added at least one bank account (basiq or manual)
12740
12738
  batch.push(this.create(AccountSetupItemsEnum.BANK_FEEDS, this.bankAccountsService.get()));
12741
- // Logbook item is completed when user has at least one vehicle claim with any method (klms or logbook)
12739
+ // Logbook item is completed when user has at least one vehicle claim with any method (kms or logbook)
12742
12740
  batch.push(this.getLogbookItem());
12743
12741
  // @TODO waiting for sole tank forecast page
12744
12742
  // Sole item is completed when user added at least one sole income source
@@ -13974,7 +13972,6 @@
13974
13972
  this.eventDispatcherService.on([
13975
13973
  exports.AppEventTypeEnum.VEHICLE_CLAIM_CREATED,
13976
13974
  exports.AppEventTypeEnum.VEHICLE_CLAIM_UPDATED,
13977
- exports.AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_CREATED,
13978
13975
  exports.AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED
13979
13976
  ]).subscribe(function () {
13980
13977
  _this.resetCache();
@@ -16465,7 +16462,7 @@
16465
16462
  /**
16466
16463
  * Abstract form class
16467
16464
  * @TODO rename to AbstractFormGroup
16468
- * @TODO Alex: refactor: check and improve logic
16465
+ * @TODO Alex TT-2190: refactor: check and improve logic
16469
16466
  */
16470
16467
  var AbstractForm = /** @class */ (function (_super) {
16471
16468
  __extends(AbstractForm, _super);
@@ -16482,9 +16479,7 @@
16482
16479
  if (model && !model['id']) {
16483
16480
  _this.markAsUnsaved();
16484
16481
  }
16485
- _this.valueChanges.subscribe(function () {
16486
- !!model && !!model['id'] && isEqual__default["default"](_this.value, _this.initialValue) ? _this.markAsSaved() : _this.markAsUnsaved();
16487
- });
16482
+ _this.listenValueChanges();
16488
16483
  return _this;
16489
16484
  }
16490
16485
  Object.defineProperty(AbstractForm.prototype, "saved", {
@@ -16494,6 +16489,13 @@
16494
16489
  enumerable: false,
16495
16490
  configurable: true
16496
16491
  });
16492
+ Object.defineProperty(AbstractForm.prototype, "currentValue", {
16493
+ get: function () {
16494
+ return this.createModelInstance(Object.assign({}, this.model, this.getRawValue()));
16495
+ },
16496
+ enumerable: false,
16497
+ configurable: true
16498
+ });
16497
16499
  /**
16498
16500
  * Check validation and return a new instance of generic model.
16499
16501
  * Merge form value to initial object
@@ -16524,6 +16526,12 @@
16524
16526
  if (data === void 0) { data = {}; }
16525
16527
  return classTransformer.plainToClass(this.modelClass, data);
16526
16528
  };
16529
+ AbstractForm.prototype.listenValueChanges = function () {
16530
+ var _this = this;
16531
+ this.valueChanges.subscribe(function () {
16532
+ !!_this.model && !!_this.model['id'] && isEqual__default["default"](_this.value, _this.initialValue) ? _this.markAsSaved() : _this.markAsUnsaved();
16533
+ });
16534
+ };
16527
16535
  return AbstractForm;
16528
16536
  }(forms.FormGroup));
16529
16537
 
@@ -16818,6 +16826,7 @@
16818
16826
  /**
16819
16827
  * Form array with bank account business allocations
16820
16828
  * @TODO create AbstractFormArray
16829
+ * @TODO Alex/Vik (TT-2184): copypasted from bank-account-properties.form, improve logic and create common parent class maybe
16821
16830
  */
16822
16831
  var SoleBusinessAllocationsForm = /** @class */ (function (_super) {
16823
16832
  __extends(SoleBusinessAllocationsForm, _super);
@@ -16924,7 +16933,7 @@
16924
16933
  name: new forms.FormControl(invoiceTemplate.name, forms.Validators.required),
16925
16934
  isTaxIncluded: new forms.FormControl(invoiceTemplate.isTaxIncluded),
16926
16935
  term: new forms.FormControl(invoiceTemplate.term, [forms.Validators.required, forms.Validators.min(0)]),
16927
- bankAccount: new forms.FormControl(invoiceTemplate.bankAccount)
16936
+ bankAccount: new forms.FormControl(invoiceTemplate.bankAccount, [forms.Validators.required])
16928
16937
  }, invoiceTemplate) || this;
16929
16938
  }
16930
16939
  return SoleInvoiceTemplateForm;
@@ -16943,10 +16952,13 @@
16943
16952
  if (bankAccount === null || bankAccount === void 0 ? void 0 : bankAccount.isSoleTank()) {
16944
16953
  _this.addControl('businessAllocations', new SoleBusinessAllocationsForm(bankAccount.businessAllocations));
16945
16954
  }
16946
- _this.watchTankType();
16955
+ _this.listenEvents();
16947
16956
  return _this;
16948
16957
  }
16949
- BankAccountAllocationForm.prototype.watchTankType = function () {
16958
+ BankAccountAllocationForm.prototype.listenEvents = function () {
16959
+ this.listenTankTypeChanges();
16960
+ };
16961
+ BankAccountAllocationForm.prototype.listenTankTypeChanges = function () {
16950
16962
  var _this = this;
16951
16963
  this.get('tankType').valueChanges.subscribe(function (tankType) {
16952
16964
  var _a, _b;
@@ -17684,17 +17696,23 @@
17684
17696
  * @param details required for form controls disabled state management
17685
17697
  */
17686
17698
  function VehicleClaimForm(vehicleClaim, details) {
17687
- return _super.call(this, {
17699
+ var _this = _super.call(this, {
17688
17700
  kilometers: new forms.FormControl({
17689
17701
  value: vehicleClaim.kilometers,
17690
17702
  disabled: !details.isManual || details.isLogbookMethod()
17691
17703
  }),
17692
17704
  workUsage: new forms.FormControl({
17693
17705
  value: vehicleClaim.workUsage,
17694
- disabled: !details.isManual || details.isKlmsMethod()
17706
+ disabled: !details.isManual || details.isKmsMethod()
17695
17707
  })
17696
17708
  }, vehicleClaim) || this;
17709
+ _this.vehicleClaim = vehicleClaim;
17710
+ _this.details = details;
17711
+ return _this;
17697
17712
  }
17713
+ VehicleClaimForm.prototype.getAverageWeeklyKMS = function () {
17714
+ return this.get('kilometers').value / FinancialYear.weeksInYear;
17715
+ };
17698
17716
  return VehicleClaimForm;
17699
17717
  }(AbstractForm));
17700
17718
 
@@ -17703,16 +17721,12 @@
17703
17721
  */
17704
17722
  var VehicleClaimDetailsForm = /** @class */ (function (_super) {
17705
17723
  __extends(VehicleClaimDetailsForm, _super);
17706
- /**
17707
- * @param vehicleClaimDetails required because we create a new details with prefilled data (like Financial year)
17708
- * @param logbooks required for isManual field disabled state management
17709
- */
17710
- function VehicleClaimDetailsForm(vehicleClaimDetails, logbooks) {
17724
+ function VehicleClaimDetailsForm(vehicleClaimDetails, isBestPeriodExist) {
17711
17725
  return _super.call(this, {
17712
17726
  method: new forms.FormControl(vehicleClaimDetails.method, forms.Validators.required),
17713
17727
  isManual: new forms.FormControl({
17714
17728
  value: vehicleClaimDetails.isManual,
17715
- disabled: !logbooks.isBestPeriodExist()
17729
+ disabled: !isBestPeriodExist
17716
17730
  }),
17717
17731
  }, vehicleClaimDetails) || this;
17718
17732
  }
@@ -17739,36 +17753,44 @@
17739
17753
  date: new forms.FormControl(logbook.date, forms.Validators.required),
17740
17754
  odometerStart: new forms.FormControl(logbook.odometerStart, forms.Validators.required),
17741
17755
  odometerEnd: new forms.FormControl(logbook.odometerEnd, forms.Validators.required),
17742
- business: new forms.FormControl(logbook.business),
17743
- // @TODO Alex: remove when backend fixed
17744
- purpose: new forms.FormControl(exports.VehicleLogbookPurposeEnum.BUSINESS)
17756
+ business: new forms.FormControl(logbook.business)
17745
17757
  }, logbook) || this;
17746
17758
  _this.logbook = logbook;
17747
17759
  _this.logbooks = logbooks;
17760
+ _this.updateStateAndValidators();
17761
+ return _this;
17762
+ }
17763
+ /**
17764
+ * Set logbook validators and disable state depends of initial logbook and its place in the whole list
17765
+ */
17766
+ VehicleLogbookForm.prototype.updateStateAndValidators = function () {
17748
17767
  switch (true) {
17749
17768
  // Create the first or edit the single logbook
17750
- case !logbook.id && !logbooks.length:
17751
- case !!logbook.id && logbooks.length === 1:
17752
- _this.get('odometerStart').setValidators(forms.Validators.min(0));
17753
- _this.get('date').setValidators(dateRangeValidator(new FinancialYear().startDate, new FinancialYear().endDate));
17769
+ case !this.logbook.id && !this.logbooks.length:
17770
+ case !!this.logbook.id && this.logbooks.length === 1:
17771
+ this.get('odometerStart').setValidators(forms.Validators.min(0));
17772
+ this.get('date').setValidators(dateRangeValidator(new FinancialYear().startDate, new FinancialYear().endDate));
17754
17773
  break;
17755
- // Create the non-first or edit the last logbook
17756
- case !logbook.id && !!logbooks.length:
17757
- case !!logbook.id && logbook.id === logbooks.last.id && logbooks.length > 1:
17758
- _this.get('odometerStart').disable();
17759
- _this.get('odometerEnd').setValidators(forms.Validators.min(logbooks.last.odometerEnd));
17760
- if (!!logbook.id) {
17761
- }
17762
- _this.get('date').setValidators(dateRangeValidator(logbooks.last.date, new FinancialYear().endDate));
17774
+ // Create the non-first
17775
+ case !this.logbook.id && !!this.logbooks.length:
17776
+ this.get('odometerStart').disable();
17777
+ this.get('odometerEnd').setValidators(forms.Validators.min(this.logbooks.last.odometerEnd));
17778
+ this.get('date').setValidators(dateRangeValidator(this.logbooks.last.date, new FinancialYear().endDate));
17779
+ break;
17780
+ // Edit the last logbook
17781
+ case !!this.logbook.id && this.logbook.id === this.logbooks.last.id && this.logbooks.length > 1:
17782
+ this.get('odometerStart').disable();
17783
+ this.get('odometerEnd').setValidators(forms.Validators.min(this.logbooks.last.odometerEnd));
17784
+ var preLastDate = this.logbooks.toArray()[this.logbooks.length - 1].date;
17785
+ this.get('date').setValidators(dateRangeValidator(preLastDate, new FinancialYear().endDate));
17763
17786
  break;
17764
17787
  // Edit the non-last logbook
17765
- case !!logbook.id && logbook.id !== logbooks.last.id && logbooks.length > 1:
17766
- _this.get('odometerStart').disable();
17767
- _this.get('odometerEnd').disable();
17768
- _this.get('date').disable();
17788
+ case !!this.logbook.id && this.logbook.id !== this.logbooks.last.id && this.logbooks.length > 1:
17789
+ this.get('odometerStart').disable();
17790
+ this.get('odometerEnd').disable();
17791
+ this.get('date').disable();
17769
17792
  }
17770
- return _this;
17771
- }
17793
+ };
17772
17794
  return VehicleLogbookForm;
17773
17795
  }(AbstractForm));
17774
17796
  VehicleLogbookForm.maxDescriptionLength = 60;