Commit 56b17fc5 authored by Pearu Sarv's avatar Pearu Sarv
Browse files

Merge branch 'feature/TEIS-2497' into 'develop'

Resolve TEIS-2497 "Feature/"

Closes TEIS-2497

See merge request teis/public-web-client!723
parents 8c3b0a66 a88e6894
<teis-modal [icon]="numberOfInspectedItems ? 'icon-edit' : 'icon-add'" [title]="numberOfInspectedItems ? ('edit_number_of_inspected_items_' + numberOfInspectedItems.item) : ('add_number_of_inspected_items_' + item) | translate">
<teis-modal
[icon]="numberOfInspectedItems ? 'icon-edit' : 'icon-add'"
[title]="numberOfInspectedItems ? 'edit_number_of_inspected_items_' + numberOfInspectedItems.item : ('add_number_of_inspected_items_' + item | translate)"
>
<teis-form-layout [colsize]="18">
<form-row *ngFor="let numbersFormItem of numbersForm.controls | keyvalue:keepOrder" [label]="numbersFormItem.key | translate">
<ska-number min="0" max="999999999" [formControl]="numbersFormItem.value" [name]="numbersFormItem.key" required pattern="\d+"></ska-number>
<form-row *ngFor="let numbersFormItem of numbersForm.controls | keyvalue: keepOrder" [label]="numbersFormItem.key | translate">
<ska-number min="0" max="999999999" [formControl]="numbersFormItem.value" [name]="numbersFormItem.key" required pattern="\d+"></ska-number>
</form-row>
<div *ngIf="numbersForm.errors" class="pb-2">
<teis-alert *ngFor="let error of numbersForm.errors | keyvalue" class="mb-2" variant="danger" [closeable]="false" [message]="error.key | translate"> </teis-alert>
<teis-alert *ngFor="let error of numbersForm.errors | keyvalue" class="mb-2" variant="danger" [closeable]="false" [message]="(error.key | translate) + error.value"> </teis-alert>
</div>
<teis-flex>
......
......@@ -29,19 +29,23 @@ export class AddOrEditNumberOfInspectedItemsComponent implements OnInit {
}
private initializeForm() {
this.numbersForm = this.fb.group(
this.numbersForm = this.fb.group(
{
generallyWithoutM: [this.numberOfInspectedItems?.generallyWithoutM ?? 0],
goodsAM: [this.numberOfInspectedItems?.goodsAM ?? 0],
goodsDM: [this.numberOfInspectedItems?.goodsDM ?? 0],
passengersAM: [this.numberOfInspectedItems?.passengersAM ?? 0],
passengersDM: [this.numberOfInspectedItems?.passengersDM ?? 0],
unspecifiedAM: [this.numberOfInspectedItems?.unspecifiedAM ?? 0],
unspecifiedDM: [this.numberOfInspectedItems?.unspecifiedDM ?? 0],
// TODO: remove hardcode when BE changed
...(true
? { goodsAM: [this.numberOfInspectedItems?.goodsAM ?? 0], goodsDM: [this.numberOfInspectedItems?.goodsDM ?? 0], goodsSM: [this.numberOfInspectedItems?.goodsSM ?? 0] }
: {
passengersAM: [this.numberOfInspectedItems?.passengersAM ?? 0],
passengersDM: [this.numberOfInspectedItems?.passengersDM ?? 0],
passengersSM: [this.numberOfInspectedItems?.passengersSM ?? 0],
}),
earningAM: [this.numberOfInspectedItems?.earningAM ?? 0],
earningDM: [this.numberOfInspectedItems?.earningDM ?? 0],
earningSM: [this.numberOfInspectedItems?.earningDM ?? 0],
ownPurposesAM: [this.numberOfInspectedItems?.ownPurposesAM ?? 0],
ownPurposesDM: [this.numberOfInspectedItems?.ownPurposesDM ?? 0],
ownPurposesSM: [this.numberOfInspectedItems?.ownPurposesDM ?? 0],
},
{
validators: [numberOfInspectedItemsSumsValidator],
......@@ -53,22 +57,41 @@ export class AddOrEditNumberOfInspectedItemsComponent implements OnInit {
this.modal.close();
}
getNumberOfInspectedItemsDto = (): CreateOrEditNumberOfInspectedItemsDto => {
const formValue = this.numbersForm.value;
const { earningAM, ownPurposesAM, earningDM, ownPurposesDM, earningSM, ownPurposesSM, passengersAM, passengersDM, passengersSM, goodsAM, goodsDM, goodsSM } = formValue;
const generallyAM = earningAM + ownPurposesAM;
const generallyDM = earningDM + ownPurposesDM;
const generallySM = earningSM + ownPurposesSM;
return {
...formValue,
generallyAM,
generallyDM,
generallySM,
goodsAM: goodsAM ?? 0,
goodsDM: goodsDM ?? 0,
goodsSM: goodsSM ?? 0,
passengersAM: passengersAM ?? 0,
passengersDM: passengersDM ?? 0,
passengersSM: passengersSM ?? 0,
unspecifiedAM: 0,
unspecifiedDM: 0,
unspecifiedSM: 0,
item: this.item ? this.item : this.numberOfInspectedItems.item,
};
}
save() {
triggerValidation(this.numbersForm);
this.numbersForm.updateValueAndValidity();
if (this.numbersForm.invalid) {
return;
}
const formValue = this.numbersForm.value;
const { goodsAM, passengersAM, unspecifiedAM } = formValue;
const { goodsDM, passengersDM, unspecifiedDM } = formValue;
const generallyAM = goodsAM + passengersAM + unspecifiedAM;
const generallyDM = goodsDM + passengersDM + unspecifiedDM;
const numberOfInspectedItems: CreateOrEditNumberOfInspectedItemsDto = { ...formValue, generallyAM, generallyDM };
const numberOfInspectedItems: CreateOrEditNumberOfInspectedItemsDto = this.getNumberOfInspectedItemsDto();
if (this.numberOfInspectedItems) {
this.facade.putNumberOfInspectedItems(this.numberOfInspectedItems.id, { ...numberOfInspectedItems, item: this.numberOfInspectedItems.item });
this.facade.putNumberOfInspectedItems(this.numberOfInspectedItems.id, numberOfInspectedItems);
} else {
this.facade.postNumberOfInspectedItems({ item: this.item, ...numberOfInspectedItems });
this.facade.postNumberOfInspectedItems(numberOfInspectedItems);
}
}
......
import { FormGroup, ValidationErrors } from '@angular/forms';
const isAMSumValid = (group: FormGroup): boolean => {
const { goodsAM, passengersAM, unspecifiedAM, earningAM, ownPurposesAM } = group.controls;
if (goodsAM.dirty && passengersAM.dirty && unspecifiedAM.dirty && earningAM.dirty && ownPurposesAM.dirty) {
if (!amSumsMatch(group)) {
return false;
}
}
return true;
const sumsMatch = (group: FormGroup, type: 'AM' | 'DM' | 'SM'): boolean => {
const goodsValue = group.value[`goods${type}`] ?? 0;
const passengersValue = group.value[`passengers${type}`] ?? 0;
const earningValue = group.value[`earning${type}`];
const ownPurposesValue = group.value[`ownPurposes${type}`];
return goodsValue + passengersValue === earningValue + ownPurposesValue;
};
const amSumsMatch = (group: FormGroup): boolean => {
const { goodsAM, passengersAM, unspecifiedAM, earningAM, ownPurposesAM } = group.value;
return goodsAM + passengersAM + unspecifiedAM === earningAM + ownPurposesAM;
};
const isDMSumValid = (group: FormGroup): boolean => {
const { goodsDM, passengersDM, unspecifiedDM, earningDM, ownPurposesDM } = group.controls;
if (goodsDM.dirty && passengersDM.dirty && unspecifiedDM.dirty && earningDM.dirty && ownPurposesDM.dirty) {
if (!dmSumsMatch(group)) {
const isValidForType = (group: FormGroup, type: 'AM' | 'DM' | 'SM') => {
const goodsControl = group.get(`goods${type}`);
const passengersControl = group.get(`passengers${type}`);
const earningControl = group.get(`earning${type}`);
const ownPurposesControl = group.get(`ownPurposes${type}`);
if ((!goodsControl || goodsControl.dirty) && (!passengersControl || passengersControl.dirty) && earningControl.dirty && ownPurposesControl.dirty) {
if (!sumsMatch(group, type)) {
return false;
}
}
return true;
};
const dmSumsMatch = (group: FormGroup): boolean => {
const { goodsDM, passengersDM, unspecifiedDM, earningDM, ownPurposesDM } = group.value;
return goodsDM + passengersDM + unspecifiedDM === earningDM + ownPurposesDM;
};
export const numberOfInspectedItemsSumsValidator = (group: FormGroup): ValidationErrors | null => {
const invalidSums = [];
if (!isAMSumValid(group)) {
if (!isValidForType(group, 'AM')) {
invalidSums.push('AM');
}
if (!isDMSumValid(group)) {
if (!isValidForType(group, 'DM')) {
invalidSums.push('DM');
}
if (!isValidForType(group, 'SM')) {
invalidSums.push('SM');
}
if (invalidSums.length) {
return { [`${invalidSums.join('_')}_sum_error`]: true };
return { sum_error: `(${invalidSums.join(', ')})` };
}
return null;
};
......@@ -9,7 +9,7 @@
<tr *ngFor="let item of itemsData">
<td *ngFor="let field of tableFields">{{ item[field] === null ? '-' : item[field] }}</td>
<td class="table-actions fit-width">
<ng-container *permission="{ id: item.id, type: permissionType, permission: managePermission }">
<ng-container *ngIf="itemHasManagePermission(item)">
<teis-icon-button role="button" variant="no-style" icon="icon-edit" (click)="openEditInspectedItemsModal(item)"> </teis-icon-button>
<teis-icon-button role="button" variant="no-style" icon="icon-delete" (click)="delete(item)"></teis-icon-button>
</ng-container>
......
import { Component, Input, OnInit } from '@angular/core';
import { DriversInspectionsFacade } from '@teis/features/drivers-inspections/drivers-inspections-facade.service';
import { NumberOfInspectedItemsDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { DriversInspectionType, NumberOfInspectedItemsDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { GenericPermission, PermissionDataObjectType } from '@teis/services/permissions/permissions.model';
import { ConfirmationOptions } from '@teis/widgets/teis-modal/confirmation/confirmation.component';
import { ModalService } from '@teis/widgets/teis-modal/modal.service';
......@@ -16,24 +16,30 @@ import { calculateSums, numberOfInspectedItemsTableFields } from './utils';
export class NumberOfInspectedItemsTableComponent implements OnInit {
@Input() itemsData: NumberOfInspectedItemsDto[] = [];
@Input() inspectionType: DriversInspectionType;
constructor(private modal: ModalService, private facade: DriversInspectionsFacade) { }
readonly managePermission = GenericPermission.MANAGE;
readonly permissionType = PermissionDataObjectType.DRIVERS_NUMBER_OF_INSPECTED_ITEMS;
readonly tableFields = numberOfInspectedItemsTableFields;
tableFields: (keyof NumberOfInspectedItemsDto)[];
fieldSums: Partial<Record<keyof NumberOfInspectedItemsDto, number>> = {};
ngOnInit(): void {
this.tableFields = numberOfInspectedItemsTableFields(this.inspectionType);
if (this.itemsData.length > 1) {
this.fieldSums = calculateSums(this.itemsData);
this.fieldSums = calculateSums(this.itemsData, this.inspectionType);
}
}
openEditInspectedItemsModal(numberOfInspectedItems: NumberOfInspectedItemsDto) {
openEditInspectedItemsModal(numberOfInspectedItems: NumberOfInspectedItemsDto): void {
this.modal.openWithComponent(AddOrEditNumberOfInspectedItemsComponent, { numberOfInspectedItems });
}
delete(numberOfInspectedItems: NumberOfInspectedItemsDto) {
itemHasManagePermission(numberOfInspectedItems: NumberOfInspectedItemsDto): boolean {
return numberOfInspectedItems.permissions.some(permission => permission.dataObjectPermissions?.includes(this.managePermission));
}
delete(numberOfInspectedItems: NumberOfInspectedItemsDto): void {
const options: ConfirmationOptions = {
title: `number_of_inspected_items_delete_${numberOfInspectedItems.item}`,
question: `number_of_inspected_items_delete_confirmation_${numberOfInspectedItems.item}`,
......
import { NumberOfInspectedItemsDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { DriversInspectionType, NumberOfInspectedItemsDto } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
export const numberOfInspectedItemsTableFields: (keyof NumberOfInspectedItemsDto)[] = [
export const numberOfInspectedItemsTableFields = (inspectionType: DriversInspectionType): (keyof NumberOfInspectedItemsDto)[] => [
'generallyAM',
'generallyDM',
'generallySM',
'generallyWithoutM',
'goodsAM',
'goodsDM',
'passengersAM',
'passengersDM',
'unspecifiedAM',
'unspecifiedDM',
...((inspectionType === DriversInspectionType.GOODS ? ['goodsAM', 'goodsDM', 'goodsSM'] : ['passengersAM', 'passengersDM', 'passengersSM']) as (keyof NumberOfInspectedItemsDto)[]),
'earningAM',
'earningDM',
'earningSM',
'ownPurposesAM',
'ownPurposesDM',
'ownPurposesSM',
];
export const calculateSums = (items: NumberOfInspectedItemsDto[]): Partial<Record<keyof NumberOfInspectedItemsDto, number>> => {
export const calculateSums = (items: NumberOfInspectedItemsDto[], inspectionType: DriversInspectionType): Partial<Record<keyof NumberOfInspectedItemsDto, number>> => {
return items.reduce((previousSums, item) => {
const sums = {};
for (const field of numberOfInspectedItemsTableFields) {
for (const field of numberOfInspectedItemsTableFields(inspectionType)) {
sums[field] = (item[field] ?? 0) + (previousSums[field] ?? 0);
}
return sums;
}, {});
};
export const calculateTotalSum = (items: NumberOfInspectedItemsDto[]): number | null => {
return !items?.length
? null
: items.reduce((totalSum, item) => {
return totalSum + item.generallyAM + item.generallyDM + item.generallySM;
}, 0);
};
......@@ -7,26 +7,36 @@
<p class="font-weight-bold">{{ 'inspected_drivers' | translate }}</p>
<teis-number-of-inspected-items-table
*ngIf="(numberOfDriversItems$ | async)?.length; else inspectedDriversNotFound"
[inspectionType]="inspectionType$ | async"
[itemsData]="numberOfDriversItems$ | async"
></teis-number-of-inspected-items-table>
<ng-template #inspectedDriversNotFound>
<teis-alert variant="info" [closeable]="false" [message]="'inspected_drivers_not_found' | translate" class="mb-2"></teis-alert>
</ng-template>
<button *permission="{ id: inspectionId$ | async, type: permissionType, permission: addItemPermission }" teis-button variant="plain" class="p-0 mb-4" (click)="openAddInspectedItemsModal('DRIVERS')">
<teis-icon icon="icon-add-round"></teis-icon>
{{ 'add' | translate }}
</button>
<p class="font-weight-bold">{{ 'inspected_work_days' | translate }}</p>
<teis-flex position="spaceBetween">
<button *permission="{ id: inspectionId$ | async, type: permissionType, permission: addItemPermission }" teis-button variant="plain" class="p-0" (click)="openAddInspectedItemsModal('DRIVERS')">
<teis-icon icon="icon-add-round"></teis-icon>
{{ 'add' | translate }}
</button>
<p *ngIf="(totalSumOfDriversItems$ | async) !== null" class="ml-auto font-weight-bold">{{'sum' | translate}} {{totalSumOfDriversItems$ | async}}</p>
</teis-flex>
<p class="font-weight-bold mt-4">{{ 'inspected_work_days' | translate }}</p>
<teis-number-of-inspected-items-table
*ngIf="(numberOfWorkDaysItems$ | async)?.length; else inspectedWorkDaysNotFound"
[inspectionType]="inspectionType$ | async"
[itemsData]="numberOfWorkDaysItems$ | async"
></teis-number-of-inspected-items-table>
<ng-template #inspectedWorkDaysNotFound>
<teis-alert variant="info" [closeable]="false" [message]="'inspected_work_days_not_found' | translate" class="mb-2"></teis-alert>
</ng-template>
</ng-template>
<button *permission="{ id: inspectionId$ | async, type: permissionType, permission: addItemPermission }" teis-button variant="plain" class="p-0" (click)="openAddInspectedItemsModal('WORKINGDAYS')">
<teis-icon icon="icon-add-round"></teis-icon>
{{ 'add' | translate }}
</button>
<teis-flex position="spaceBetween">
<button *permission="{ id: inspectionId$ | async, type: permissionType, permission: addItemPermission }" teis-button variant="plain" class="p-0" (click)="openAddInspectedItemsModal('WORKINGDAYS')">
<teis-icon icon="icon-add-round"></teis-icon>
{{ 'add' | translate }}
</button>
<p *ngIf="(totalSumOfWorkDaysItems$ | async) !== null" class="ml-auto font-weight-bold">{{'sum' | translate}} {{totalSumOfWorkDaysItems$ | async}}</p>
</teis-flex>
......@@ -3,8 +3,9 @@ import { DriversInspectionsFacade } from '@teis/features/drivers-inspections/dri
import { DriversInspectionPermission, InspectedItem } from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { PermissionDataObjectType } from '@teis/services/permissions/permissions.model';
import { ModalService } from '@teis/widgets/teis-modal/modal.service';
import { shareReplay } from 'rxjs/operators';
import { map, shareReplay } from 'rxjs/operators';
import { AddOrEditNumberOfInspectedItemsComponent } from '../add-or-edit-number-of-inspected-items/add-or-edit-number-of-inspected-items.component';
import { calculateTotalSum } from '../number-of-inspected-items-table/utils';
@Component({
selector: 'teis-number-of-inspected-items',
......@@ -16,7 +17,10 @@ export class NumberOfInspectedItemsComponent implements OnInit {
constructor(public facade: DriversInspectionsFacade, private modal: ModalService) { }
numberOfDriversItems$ = this.facade.numberOfDriversItems.pipe(shareReplay({ refCount: true }));
totalSumOfDriversItems$ = this.facade.numberOfDriversItems.pipe(map(calculateTotalSum), shareReplay({ refCount: true }));
numberOfWorkDaysItems$ = this.facade.numberOfWorkingDaysItems.pipe(shareReplay({ refCount: true }));
totalSumOfWorkDaysItems$ = this.facade.numberOfWorkingDaysItems.pipe(map(calculateTotalSum), shareReplay({ refCount: true }));
inspectionType$ = this.facade.driversInspectionInspectedItems.pipe(map(items => items.inspectionType?.code), shareReplay({ refCount: true }));
inspectionId$ = this.facade.driversInspectionId;
readonly addItemPermission = DriversInspectionPermission.ADD_DRIVERS_NUMBER_OF_INSPECTED_ITEM;
......
......@@ -1101,17 +1101,22 @@
"inspected_work_days": "Kontrollitud tööpäevade arv EN",
"generallyAM": "Kokku AM EN",
"generallyDM": "Kokku DM EN",
"generallySM": "Kokku NM EN",
"generallyWithoutM": "Kokku meerikuta EN",
"goodsAM": "Veose veol AM EN",
"goodsDM": "Veose veol DM EN",
"goodsSM": "Veose veol NM EN",
"passengersAM": "Sõitjate veol AM EN",
"passengersDM": "Sõitjate veol DM EN",
"passengersSM": "Sõitjate veol NM EN",
"unspecifiedAM": "Määramata sisuga veol AM EN",
"unspecifiedDM": "Määramata sisuga veol DM EN",
"earningAM": "Tasulisel veol AM EN",
"earningDM": "Tasulisel veol DM EN",
"earningSM": "Tasulisel veol NM EN",
"ownPurposesAM": "Oma tarbeks veol AM EN",
"ownPurposesDM": "Oma tarbeks veol DM EN",
"ownPurposesSM": "Oma tarbeks veol NM EN",
"inspected_drivers_not_found": "Kontrollitud juhtide arvud puuduvad EN",
"inspected_work_days_not_found": "Kontrollitud tööpäevade arvud puuduvad EN",
"processing_report": "Töötlemise aruanne EN",
......@@ -1148,9 +1153,6 @@
"add_justification_file_success": "Kõrvalekalde põhjenduse fail edukalt lisatud EN",
"justification_file_delete_success": "Kõrvalekalde põhjenduse fail edukalt kustutatud EN",
"add": "Lisa EN",
"AM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (AM) EN",
"DM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (DM) EN",
"AM_DM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (AM, DM) EN",
"number_of_inspected_items_delete_DRIVERS": "Kontrollitud juhtide arvude kustutamine EN",
"number_of_inspected_items_delete_confirmation_DRIVERS": "Kas oled kindel, et soovid kontrollitud juhtide arvud kustutada? EN",
"number_of_inspected_items_delete_success_DRIVERS": "Kontrollitud juhtide arvud edukalt kustutatud EN",
......@@ -1164,5 +1166,6 @@
"edit_number_of_inspected_items_DRIVERS": "Kontrollitud juhtide arvude muutmine EN",
"edit_number_of_inspected_items_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine EN",
"edit_number_of_inspected_items_success_DRIVERS": "Kontrollitud juhtide arvude muutmine edukas EN",
"edit_number_of_inspected_items_success_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine edukas EN"
"edit_number_of_inspected_items_success_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine edukas EN",
"sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga EN"
}
\ No newline at end of file
......@@ -1101,17 +1101,22 @@
"inspected_work_days": "Kontrollitud tööpäevade arv",
"generallyAM": "Kokku AM",
"generallyDM": "Kokku DM",
"generallySM": "Kokku NM",
"generallyWithoutM": "Kokku meerikuta",
"goodsAM": "Veose veol AM",
"goodsDM": "Veose veol DM",
"goodsSM": "Veose veol NM",
"passengersAM": "Sõitjate veol AM",
"passengersDM": "Sõitjate veol DM",
"passengersSM": "Sõitjate veol NM",
"unspecifiedAM": "Määramata sisuga veol AM",
"unspecifiedDM": "Määramata sisuga veol DM",
"earningAM": "Tasulisel veol AM",
"earningDM": "Tasulisel veol DM",
"earningSM": "Tasulisel veol NM",
"ownPurposesAM": "Oma tarbeks veol AM",
"ownPurposesDM": "Oma tarbeks veol DM",
"ownPurposesSM": "Oma tarbeks veol NM",
"inspected_drivers_not_found": "Kontrollitud juhtide arvud puuduvad",
"inspected_work_days_not_found": "Kontrollitud tööpäevade arvud puuduvad",
"processing_report": "Töötlemise aruanne",
......@@ -1148,9 +1153,6 @@
"add_justification_file_success": "Kõrvalekalde põhjenduse fail edukalt lisatud",
"justification_file_delete_success": "Kõrvalekalde põhjenduse fail edukalt kustutatud",
"add": "Lisa",
"AM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (AM)",
"DM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (DM)",
"AM_DM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (AM, DM)",
"number_of_inspected_items_delete_DRIVERS": "Kontrollitud juhtide arvude kustutamine",
"number_of_inspected_items_delete_confirmation_DRIVERS": "Kas oled kindel, et soovid kontrollitud juhtide arvud kustutada?",
"number_of_inspected_items_delete_success_DRIVERS": "Kontrollitud juhtide arvud edukalt kustutatud",
......@@ -1164,5 +1166,6 @@
"edit_number_of_inspected_items_DRIVERS": "Kontrollitud juhtide arvude muutmine",
"edit_number_of_inspected_items_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine",
"edit_number_of_inspected_items_success_DRIVERS": "Kontrollitud juhtide arvude muutmine edukas",
"edit_number_of_inspected_items_success_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine edukas"
"edit_number_of_inspected_items_success_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine edukas",
"sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga "
}
\ No newline at end of file
......@@ -1101,17 +1101,22 @@
"inspected_work_days": "Kontrollitud tööpäevade arv RU",
"generallyAM": "Kokku AM RU",
"generallyDM": "Kokku DM RU",
"generallySM": "Kokku NM RU",
"generallyWithoutM": "Kokku meerikuta RU",
"goodsAM": "Veose veol AM RU",
"goodsDM": "Veose veol DM RU",
"goodsSM": "Veose veol NM RU",
"passengersAM": "Sõitjate veol AM RU",
"passengersDM": "Sõitjate veol DM RU",
"passengersSM": "Sõitjate veol NM RU",
"unspecifiedAM": "Määramata sisuga veol AM RU",
"unspecifiedDM": "Määramata sisuga veol DM RU",
"earningAM": "Tasulisel veol AM RU",
"earningDM": "Tasulisel veol DM RU",
"earningSM": "Tasulisel veol NM RU",
"ownPurposesAM": "Oma tarbeks veol AM RU",
"ownPurposesDM": "Oma tarbeks veol DM RU",
"ownPurposesSM": "Oma tarbeks veol NM RU",
"inspected_drivers_not_found": "Kontrollitud juhtide arvud puuduvad RU",
"inspected_work_days_not_found": "Kontrollitud tööpäevade arvud puuduvad RU",
"processing_report": "Töötlemise aruanne RU",
......@@ -1148,9 +1153,6 @@
"add_justification_file_success": "Kõrvalekalde põhjenduse fail edukalt lisatud RU",
"justification_file_delete_success": "Kõrvalekalde põhjenduse fail edukalt kustutatud RU",
"add": "Lisa RU",
"AM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (AM) RU",
"DM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (DM) RU",
"AM_DM_sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga (AM, DM) RU",
"number_of_inspected_items_delete_DRIVERS": "Kontrollitud juhtide arvude kustutamine RU",
"number_of_inspected_items_delete_confirmation_DRIVERS": "Kas oled kindel, et soovid kontrollitud juhtide arvud kustutada? RU",
"number_of_inspected_items_delete_success_DRIVERS": "Kontrollitud juhtide arvud edukalt kustutatud RU",
......@@ -1164,5 +1166,6 @@
"edit_number_of_inspected_items_DRIVERS": "Kontrollitud juhtide arvude muutmine RU",
"edit_number_of_inspected_items_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine RU",
"edit_number_of_inspected_items_success_DRIVERS": "Kontrollitud juhtide arvude muutmine edukas RU",
"edit_number_of_inspected_items_success_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine edukas RU"
"edit_number_of_inspected_items_success_WORKINGDAYS": "Kontrollitud tööpäevade arvude muutmine edukas RU",
"sum_error": "Veose ja sõitjate veo arvude summa peab võrduma tasulise veo ja oma tarbeks veo arvude summaga RU"
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ import {
DriversViolationTypePublicDto,
DriversViolationPublicDto,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { distinctUntilChanged, map, take, takeUntil, tap } from 'rxjs/operators';
......@@ -89,6 +90,7 @@ export class DriversInspectionsFacade implements OnDestroy {
private openedViolation$ = new BehaviorSubject<string>(null);
private driversInspectionFiles$ = new BehaviorSubject<DriversInspectionFileDto[]>([]);
private numberOfInspectedItems$ = new BehaviorSubject<NumberOfInspectedItemsDto[]>([]);
private driversInspectionInspectedItems$ = new BehaviorSubject<DriversInspectionInspectedItemsDto>(null);
driversViolationsFilter = new FormControl(this.allDriversFilterOption);
private driversViolationsFilterValue$ = new BehaviorSubject<DriverDto>(null);
private driversViolationTypes$ = new BehaviorSubject<DriversViolationTypeDto[]>([]);
......@@ -148,6 +150,10 @@ export class DriversInspectionsFacade implements OnDestroy {
return this.numberOfInspectedItems$.asObservable().pipe(map((items: NumberOfInspectedItemsDto[]) => items.filter((item: NumberOfInspectedItemsDto) => item.item === InspectedItem.WORKINGDAYS)));
}
get driversInspectionInspectedItems(): Observable<DriversInspectionInspectedItemsDto> {
return this.driversInspectionInspectedItems$.asObservable();
}
getViolationDetailById(id: string): Observable<DriversViolationDto> {
return this.violationDetails$.asObservable().pipe(map((details: DriversViolationDto[]) => details.find((detail: DriversViolationDto) => detail.id === id)));
}
......@@ -350,11 +356,13 @@ export class DriversInspectionsFacade implements OnDestroy {
const { id } = this.driversInspection$.getValue();
this.handleLoading('numberOfInspectedItems', true);
this.driversInspectionOfficeApi.getNumberOfInspectedItems(id).subscribe(
(items) => {
this.numberOfInspectedItems$.next(items);
(items: DriversInspectionInspectedItemsDto) => {
this.driversInspectionInspectedItems$.next(items);
this.numberOfInspectedItems$.next(items.numberOfInspectedItems);
this.handleLoading('numberOfInspectedItems', false);
},
() => {
this.driversInspectionInspectedItems$.next(null);
this.numberOfInspectedItems$.next([]);
this.handleLoading('numberOfInspectedItems', false);
}
......@@ -453,6 +461,7 @@ export class DriversInspectionsFacade implements OnDestroy {
this.driversViolationsFilterValue$.next(null);
this.loading$.next(initialLoading);
this.driversInspectionFiles$.next([]);
this.driversInspectionInspectedItems$.next(null);
this.numberOfInspectedItems$.next([]);
this.driversViolationTypes$.next([]);
}
......
......@@ -7,6 +7,7 @@ import {
CreateOrEditDriversInfringmentDto,
NumberOfInspectedItemsDto,
CreateOrEditNumberOfInspectedItemsDto,
DriversInspectionInspectedItemsDto,
} from '@teis/features/drivers-inspections/services/drivers-inspections.model';
import { ApiOffice } from '@teis/services/api-office';
......@@ -47,7 +48,7 @@ export class DriversInspectionsOfficeApi extends ApiOffice {
}
getNumberOfInspectedItems(id: string) {
return this.http.get<NumberOfInspectedItemsDto[]>(`${this.url}/${id}/number-of-inspected-items`);
return this.http.get<DriversInspectionInspectedItemsDto>(`${this.url}/${id}/number-of-inspected-items`);
}
postNumberOfInspectedItems(id: string, body: CreateOrEditNumberOfInspectedItemsDto) {
......
......@@ -16,6 +16,11 @@ export enum DriversInfringementStatus {
UNIMPORTANT = 'UNIMPORTANT',
}
export enum DriversInspectionType {