taxtank-core 0.32.2 → 0.32.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.
- package/esm2022/lib/collections/vehicle/best-vehicle-logbook.collection.mjs +39 -44
- package/esm2022/lib/collections/vehicle/vehicle-logbook.collection.mjs +9 -32
- package/esm2022/lib/models/financial-year/financial-year.mjs +4 -2
- package/esm2022/lib/models/vehicle/vehicle-logbook.mjs +9 -8
- package/esm2022/lib/services/http/vehicle/vehicle-claim.service.mjs +4 -23
- package/fesm2022/taxtank-core.mjs +60 -102
- package/fesm2022/taxtank-core.mjs.map +1 -1
- package/lib/collections/vehicle/best-vehicle-logbook.collection.d.ts +10 -12
- package/lib/collections/vehicle/vehicle-logbook.collection.d.ts +3 -16
- package/lib/models/financial-year/financial-year.d.ts +1 -1
- package/lib/models/vehicle/vehicle-logbook.d.ts +0 -2
- package/lib/services/http/vehicle/vehicle-claim.service.d.ts +3 -9
- package/package.json +1 -1
|
@@ -1554,7 +1554,9 @@ class FinancialYear {
|
|
|
1554
1554
|
static { this.weeksInYear = 52; }
|
|
1555
1555
|
static { this.monthsInYear = 12; }
|
|
1556
1556
|
static { this.startMonthIndex = 6; }
|
|
1557
|
-
static
|
|
1557
|
+
static get year() {
|
|
1558
|
+
return +localStorage.getItem('financialYear');
|
|
1559
|
+
}
|
|
1558
1560
|
constructor(date) {
|
|
1559
1561
|
this.yearStartDate = '-07-01';
|
|
1560
1562
|
this.yearEndDate = '-06-30';
|
|
@@ -4930,13 +4932,14 @@ class VehicleLogbook extends VehicleLogbook$1 {
|
|
|
4930
4932
|
return this.odometerEnd - this.odometerStart;
|
|
4931
4933
|
}
|
|
4932
4934
|
get tankType() {
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4935
|
+
switch (true) {
|
|
4936
|
+
case !!this.business:
|
|
4937
|
+
return TankTypeEnum.SOLE;
|
|
4938
|
+
case this.isPersonal:
|
|
4939
|
+
return TankTypeEnum.PERSONAL;
|
|
4940
|
+
default:
|
|
4941
|
+
return TankTypeEnum.WORK;
|
|
4942
|
+
}
|
|
4940
4943
|
}
|
|
4941
4944
|
}
|
|
4942
4945
|
__decorate([
|
|
@@ -8492,41 +8495,19 @@ class ReportItemCollection extends Collection {
|
|
|
8492
8495
|
}
|
|
8493
8496
|
|
|
8494
8497
|
class VehicleLogbookCollection extends Collection {
|
|
8495
|
-
/**
|
|
8496
|
-
* Get collection of non-personal logbooks (work-related, sole-related).
|
|
8497
|
-
* @TODO Vik: Best period: move this and related logic to backend
|
|
8498
|
-
*/
|
|
8499
|
-
getClaimableLogbooks(isSole = false) {
|
|
8500
|
-
return this.filter((logbook) => !logbook.isPersonal && (isSole ? logbook.isSoleTank() : logbook.isWorkTank()));
|
|
8501
|
-
}
|
|
8502
8498
|
/**
|
|
8503
8499
|
* Calculate total kilometers traveled
|
|
8504
8500
|
*/
|
|
8505
8501
|
get kilometers() {
|
|
8506
8502
|
return this.sumBy('kilometers');
|
|
8507
8503
|
}
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
* @TODO Alex: TT-2089 replace with getter
|
|
8511
|
-
*/
|
|
8512
|
-
get workUsage() {
|
|
8513
|
-
if (!this.length) {
|
|
8514
|
-
return 0;
|
|
8515
|
-
}
|
|
8516
|
-
const workKilometers = this.items
|
|
8517
|
-
.filter((logbook) => !logbook.isPersonal)
|
|
8518
|
-
.reduce((sum, logbook) => sum + logbook.kilometers, 0);
|
|
8519
|
-
return round(workKilometers / this.kilometers * 100, 2);
|
|
8504
|
+
getWorkUsage(vehicleClaim) {
|
|
8505
|
+
return +(this.getClaimable(vehicleClaim).kilometers / this.kilometers * 100).toFixed(10);
|
|
8520
8506
|
}
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
.
|
|
8524
|
-
|
|
8525
|
-
}
|
|
8526
|
-
/**
|
|
8527
|
-
* Get list of logbooks related to passed vehicle claim
|
|
8528
|
-
*/
|
|
8529
|
-
getByVehicleClaim(vehicleClaim) {
|
|
8507
|
+
getClaimable(vehicleClaim) {
|
|
8508
|
+
if (!vehicleClaim) {
|
|
8509
|
+
return this.filter((logbook) => !logbook.isPersonal);
|
|
8510
|
+
}
|
|
8530
8511
|
return vehicleClaim.isSoleTank()
|
|
8531
8512
|
// sole tank may have multiple vehicle claims, so we need to filter by business.id
|
|
8532
8513
|
? this.filterBy('business.id', vehicleClaim.business.id)
|
|
@@ -8536,8 +8517,8 @@ class VehicleLogbookCollection extends Collection {
|
|
|
8536
8517
|
/**
|
|
8537
8518
|
* get collection of logbooks with the biggest work usage for {@link BestVehicleLogbookCollection.periodDuration}
|
|
8538
8519
|
*/
|
|
8539
|
-
getBest(
|
|
8540
|
-
return BestVehicleLogbookCollection.fromLogbooks(this
|
|
8520
|
+
getBest() {
|
|
8521
|
+
return BestVehicleLogbookCollection.fromLogbooks(this);
|
|
8541
8522
|
}
|
|
8542
8523
|
}
|
|
8543
8524
|
|
|
@@ -8555,29 +8536,47 @@ class BestVehicleLogbookCollection extends VehicleLogbookCollection {
|
|
|
8555
8536
|
* constructor is private because we want to prevent collection initialization via 'new' operator.
|
|
8556
8537
|
* We should create instances only with fromLogbooks method
|
|
8557
8538
|
*/
|
|
8558
|
-
constructor(logbooks
|
|
8559
|
-
super(
|
|
8560
|
-
this.isSole = isSole;
|
|
8561
|
-
if (!this.isBestPeriodExist(logbooks)) {
|
|
8562
|
-
return;
|
|
8563
|
-
}
|
|
8564
|
-
this.calculateBestPeriod(logbooks);
|
|
8539
|
+
constructor(logbooks) {
|
|
8540
|
+
super(logbooks);
|
|
8565
8541
|
}
|
|
8566
8542
|
/**
|
|
8567
8543
|
* Best period may be calculated only when user has logbooks minimum for VehicleLogbook.bestPeriodWeeks
|
|
8568
8544
|
*/
|
|
8569
|
-
isBestPeriodExist(logbooks
|
|
8545
|
+
static isBestPeriodExist(logbooks) {
|
|
8570
8546
|
if (logbooks.length < 2) {
|
|
8571
8547
|
return false;
|
|
8572
8548
|
}
|
|
8573
8549
|
if (!(logbooks instanceof VehicleLogbookCollection)) {
|
|
8574
8550
|
logbooks = new VehicleLogbookCollection(logbooks);
|
|
8575
8551
|
}
|
|
8576
|
-
return
|
|
8552
|
+
return this.periodDuration < (logbooks.last.date.getTime() - logbooks.first.date.getTime());
|
|
8577
8553
|
}
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8554
|
+
// get list of date ranges for each of passed logbook
|
|
8555
|
+
static getPeriods(logbooks) {
|
|
8556
|
+
const claimable = logbooks.getClaimable();
|
|
8557
|
+
// get a list of date ranges that could potentially be the best
|
|
8558
|
+
const periods = claimable
|
|
8559
|
+
// skip logbooks whose range ends after the last logbook
|
|
8560
|
+
.filter((logbook) => this.getPeriodByLogbook(logbook).end.toDate() < logbooks.last.date)
|
|
8561
|
+
.map((logbook) => this.getPeriodByLogbook(logbook));
|
|
8562
|
+
// skip if the last logbook already included to the last existing date range
|
|
8563
|
+
// if (last(periods).end.toDate() < logbooks.last.date) {
|
|
8564
|
+
// add extra date range for the last claimable logbook
|
|
8565
|
+
// @TODO vik
|
|
8566
|
+
periods.push(this.getPeriodByLogbook(claimable.last, true));
|
|
8567
|
+
// }
|
|
8568
|
+
return periods;
|
|
8569
|
+
}
|
|
8570
|
+
/**
|
|
8571
|
+
* Get claimable date range for passed logbook
|
|
8572
|
+
* @param logbook logbook instance for range calculation
|
|
8573
|
+
* @param isBackward Flag false - range for logbook + duration; flag true - range for logbook - duration. Used for extra case, when we should add an extra date range for the last logbook
|
|
8574
|
+
*/
|
|
8575
|
+
static getPeriodByLogbook(logbook, isBackward = false) {
|
|
8576
|
+
if (isBackward) {
|
|
8577
|
+
return new DateRange([new Date(logbook.date.getTime() - this.periodDuration), logbook.date]);
|
|
8578
|
+
}
|
|
8579
|
+
return new DateRange([logbook.date, new Date(logbook.date.getTime() + this.periodDuration)]);
|
|
8581
8580
|
}
|
|
8582
8581
|
/**
|
|
8583
8582
|
* Set Date Range with the biggest work usage percent
|
|
@@ -8593,44 +8592,22 @@ class BestVehicleLogbookCollection extends VehicleLogbookCollection {
|
|
|
8593
8592
|
*/
|
|
8594
8593
|
calculateBestPeriod(logbooks) {
|
|
8595
8594
|
// get a list of date ranges that could potentially be the best
|
|
8596
|
-
const periods =
|
|
8595
|
+
const periods = BestVehicleLogbookCollection.getPeriods(logbooks);
|
|
8597
8596
|
periods.forEach((period) => {
|
|
8598
8597
|
const logbooksInPeriod = logbooks.filterByRange('date', period.start.toDate(), period.end.toDate());
|
|
8599
|
-
if (!this.period || (this.
|
|
8598
|
+
if (!this.period || (this.getWorkUsage() < logbooksInPeriod.getWorkUsage())) {
|
|
8600
8599
|
this.period = period;
|
|
8601
8600
|
this.items = logbooksInPeriod.toArray();
|
|
8602
8601
|
}
|
|
8603
8602
|
});
|
|
8604
8603
|
}
|
|
8605
|
-
|
|
8606
|
-
|
|
8607
|
-
|
|
8608
|
-
// get a list of date ranges that could potentially be the best
|
|
8609
|
-
const periods = claimable
|
|
8610
|
-
// skip logbooks whose range ends after the last logbook
|
|
8611
|
-
.filter((logbook) => this.getPeriodByLogbook(logbook).end.toDate() < logbooks.last.date)
|
|
8612
|
-
.map((logbook) => this.getPeriodByLogbook(logbook));
|
|
8613
|
-
// skip if the last logbook already included to the last existing date range
|
|
8614
|
-
// if (last(periods).end.toDate() < logbooks.last.date) {
|
|
8615
|
-
// add extra date range for the last claimable logbook
|
|
8616
|
-
periods.push(this.getPeriodByLogbook(claimable.last, true));
|
|
8617
|
-
// }
|
|
8618
|
-
return periods;
|
|
8619
|
-
}
|
|
8620
|
-
/**
|
|
8621
|
-
* Get claimable date range for passed logbook
|
|
8622
|
-
* @param logbook logbook instance for range calculation
|
|
8623
|
-
* @param isBackward Flag false - range for logbook + duration; flag true - range for logbook - duration. Used for extra case, when we should add an extra date range for the last logbook
|
|
8624
|
-
*/
|
|
8625
|
-
getPeriodByLogbook(logbook, isBackward = false) {
|
|
8626
|
-
if (isBackward) {
|
|
8627
|
-
return new DateRange([new Date(logbook.date.getTime() - BestVehicleLogbookCollection.periodDuration), logbook.date]);
|
|
8604
|
+
static fromLogbooks(logbooks) {
|
|
8605
|
+
if (!this.isBestPeriodExist(logbooks)) {
|
|
8606
|
+
return null;
|
|
8628
8607
|
}
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
const collection = new BestVehicleLogbookCollection(logbooks, isSole);
|
|
8633
|
-
return collection.isBestPeriodExist(logbooks) ? collection : null;
|
|
8608
|
+
const collection = new BestVehicleLogbookCollection(logbooks.toArray());
|
|
8609
|
+
collection.calculateBestPeriod(logbooks);
|
|
8610
|
+
return collection;
|
|
8634
8611
|
}
|
|
8635
8612
|
}
|
|
8636
8613
|
|
|
@@ -15259,9 +15236,6 @@ class VehicleClaimService extends RestService {
|
|
|
15259
15236
|
this.url = 'vehicle-claims';
|
|
15260
15237
|
this.roles = [UserRolesEnum.WORK_TANK, UserRolesEnum.SOLE_TANK];
|
|
15261
15238
|
}
|
|
15262
|
-
listenEvents() {
|
|
15263
|
-
this.listenVehicleClaimDetailsChanges();
|
|
15264
|
-
}
|
|
15265
15239
|
add(model) {
|
|
15266
15240
|
return super.add(model).pipe(map((vehicleClaim) => {
|
|
15267
15241
|
this.eventDispatcherService.dispatch(new AppEvent(AppEventTypeEnum.VEHICLE_CLAIM_CREATED, vehicleClaim));
|
|
@@ -15274,32 +15248,16 @@ class VehicleClaimService extends RestService {
|
|
|
15274
15248
|
return vehicleClaim;
|
|
15275
15249
|
}));
|
|
15276
15250
|
}
|
|
15277
|
-
/**
|
|
15278
|
-
* Details changes may affect vehicle claims:
|
|
15279
|
-
* when details method changed, all claims current values become 0
|
|
15280
|
-
*/
|
|
15281
|
-
listenVehicleClaimDetailsChanges() {
|
|
15282
|
-
this.eventDispatcherService.on(AppEventTypeEnum.VEHICLE_CLAIM_DETAILS_UPDATED)
|
|
15283
|
-
.subscribe(() => {
|
|
15284
|
-
this.refreshCache();
|
|
15285
|
-
});
|
|
15286
|
-
}
|
|
15287
15251
|
/**
|
|
15288
15252
|
* Update workUsage for all vehicle claims if logbook best period changed
|
|
15289
15253
|
* @TODO Vik: Best period move this and related logic to backend
|
|
15290
15254
|
*/
|
|
15291
15255
|
updateWorkUsage(bestLogbooks) {
|
|
15292
|
-
|
|
15293
|
-
|
|
15294
|
-
return;
|
|
15295
|
-
}
|
|
15296
|
-
// @TODO Vik (TT-2210): need batch endpoint for this update
|
|
15297
|
-
// @TODO Alex (TT-2210): fix frontend when endpoint ready
|
|
15298
|
-
const batch$ = this.cache.map((claim) => {
|
|
15299
|
-
const claimToUpdate = plainToClass(VehicleClaim, Object.assign({}, claim, { workUsage: bestLogbooks.getWorkUsageByClaim(claim) }));
|
|
15256
|
+
const batch$ = (this.cache ?? []).map((claim) => {
|
|
15257
|
+
const claimToUpdate = plainToClass(VehicleClaim, Object.assign({}, claim, { workUsage: bestLogbooks.getWorkUsage(claim) }));
|
|
15300
15258
|
return this.update(claimToUpdate);
|
|
15301
15259
|
});
|
|
15302
|
-
combineLatest(batch$)
|
|
15260
|
+
return combineLatest(batch$);
|
|
15303
15261
|
}
|
|
15304
15262
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: VehicleClaimService, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
15305
15263
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: VehicleClaimService, providedIn: 'root' }); }
|