Skip to content

Commit 968d3a5

Browse files
committed
Fixing planHours.
1 parent f2db73e commit 968d3a5

3 files changed

Lines changed: 84 additions & 73 deletions

File tree

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/workday-entity/workday-entity-dialog.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@
360360
matInput
361361
id="planHours"
362362
name="planHours"
363-
[disabled]="isInTheFuture || data.planningPrDayModels.message === null"
363+
[disabled]="data.planningPrDayModels.message === null && data.assignedSiteModel.useOnlyPlanHours !== true"
364364
[(ngModel)]="data.planningPrDayModels.planHours"
365365
(change)="calculatePlanHours()"
366366
>

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-planning-actions/workday-entity/workday-entity-dialog.component.ts

Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {Component, EventEmitter, Inject, OnInit, TemplateRef, ViewChild} from '@angular/core';
22
import {
3-
MAT_DIALOG_DATA,
4-
MatDialogActions,
5-
MatDialogClose,
6-
MatDialogContent,
7-
MatDialogTitle
3+
MAT_DIALOG_DATA,
4+
MatDialogActions,
5+
MatDialogClose,
6+
MatDialogContent,
7+
MatDialogTitle
88
} from '@angular/material/dialog';
99
import {MatButton, MatIconButton} from '@angular/material/button';
1010
import {TranslatePipe, TranslateService} from '@ngx-translate/core';
@@ -13,9 +13,9 @@ import {MatCheckbox} from '@angular/material/checkbox';
1313
import {FormsModule} from '@angular/forms';
1414
import {TimePlanningMessagesEnum} from '../../../../enums';
1515
import {
16-
AssignedSiteModel,
17-
PlanningPrDayModel,
18-
PlanningPrDayUpdateModel
16+
AssignedSiteModel,
17+
PlanningPrDayModel,
18+
PlanningPrDayUpdateModel
1919
} from '../../../../models';
2020
import {MtxGrid, MtxGridColumn} from '@ng-matero/extensions/grid';
2121
import {TimePlanningPnPlanningsService} from '../../../../services';
@@ -25,28 +25,28 @@ import {NgxMaterialTimepickerModule} from 'ngx-material-timepicker';
2525
import {MatIcon} from '@angular/material/icon';
2626

2727
@Component({
28-
selector: 'app-workday-entity-dialog',
29-
templateUrl: './workday-entity-dialog.component.html',
30-
imports: [
31-
MatButton,
32-
MatDialogActions,
33-
MatDialogClose,
34-
TranslatePipe,
35-
MatDialogTitle,
36-
MatDialogContent,
37-
MatCheckbox,
38-
FormsModule,
39-
NgForOf,
40-
NgIf,
41-
MtxGrid,
42-
MatFormField,
43-
MatInput,
44-
MatLabel,
45-
NgxMaterialTimepickerModule,
46-
MatIconButton,
47-
MatIcon
48-
],
49-
styleUrls: ['./workday-entity-dialog.component.scss']
28+
selector: 'app-workday-entity-dialog',
29+
templateUrl: './workday-entity-dialog.component.html',
30+
imports: [
31+
MatButton,
32+
MatDialogActions,
33+
MatDialogClose,
34+
TranslatePipe,
35+
MatDialogTitle,
36+
MatDialogContent,
37+
MatCheckbox,
38+
FormsModule,
39+
NgForOf,
40+
NgIf,
41+
MtxGrid,
42+
MatFormField,
43+
MatInput,
44+
MatLabel,
45+
NgxMaterialTimepickerModule,
46+
MatIconButton,
47+
MatIcon
48+
],
49+
styleUrls: ['./workday-entity-dialog.component.scss']
5050
})
5151
export class WorkdayEntityDialogComponent implements OnInit {
5252
TimePlanningMessagesEnum = TimePlanningMessagesEnum;
@@ -88,7 +88,7 @@ export class WorkdayEntityDialogComponent implements OnInit {
8888

8989
ngOnInit(): void {
9090
this.enumKeys = Object.keys(TimePlanningMessagesEnum).filter(key => isNaN(Number(key)));
91-
this.data[this.enumKeys[this.data.planningPrDayModels.message - 1]] = true;
91+
this.data.planningPrDayModels[this.enumKeys[this.data.planningPrDayModels.message - 1]] = true;
9292
this.plannedStartOfShift1 = this.convertMinutesToTime(this.data.planningPrDayModels.plannedStartOfShift1);
9393
this.plannedEndOfShift1 = this.convertMinutesToTime(this.data.planningPrDayModels.plannedEndOfShift1);
9494
this.plannedBreakOfShift1 = this.convertMinutesToTime(this.data.planningPrDayModels.plannedBreakOfShift1);
@@ -105,7 +105,18 @@ export class WorkdayEntityDialogComponent implements OnInit {
105105
this.todaysFlex = this.data.planningPrDayModels.actualHours - this.data.planningPrDayModels.planHours;
106106
this.date = Date.parse(this.data.planningPrDayModels.date);
107107

108-
this.tableHeaders = [
108+
this.tableHeaders = this.data.assignedSiteModel.useOnlyPlanHours ? [
109+
{
110+
header: this.translateService.stream('Shift'), field: 'shift',
111+
pinned: 'left'
112+
},
113+
{
114+
cellTemplate: this.actualColumnTemplate,
115+
header: this.translateService.stream('Registered'),
116+
field: 'actualStart',
117+
sortable: false,
118+
},
119+
]: [
109120
{
110121
header: this.translateService.stream('Shift'), field: 'shift',
111122
pinned: 'left'
@@ -157,7 +168,7 @@ export class WorkdayEntityDialogComponent implements OnInit {
157168
if (selectedOption !== this.data.planningPrDayModels.message) {
158169
this.data.planningPrDayModels.message = selectedOption;
159170
this.enumKeys.forEach(key => {
160-
this.data[key] = selectedOption
171+
this.data.planningPrDayModels[key] = selectedOption
161172
=== TimePlanningMessagesEnum[key as keyof typeof TimePlanningMessagesEnum];
162173
});
163174
}
@@ -261,17 +272,17 @@ export class WorkdayEntityDialogComponent implements OnInit {
261272
);
262273
}
263274

264-
getMaxDifference(start: string, end: string): string {
265-
const startTime = this.convertTimeToMinutes(start);
266-
const endTime = this.convertTimeToMinutes(end);
267-
const diff = endTime - startTime;
268-
if (diff < 0) {
269-
return '00:00';
270-
}
271-
const hours = Math.floor(diff / 60);
272-
const minutes = diff % 60;
273-
return `${hours}:${minutes}`;
275+
getMaxDifference(start: string, end: string): string {
276+
const startTime = this.convertTimeToMinutes(start);
277+
const endTime = this.convertTimeToMinutes(end);
278+
const diff = endTime - startTime;
279+
if (diff < 0) {
280+
return '00:00';
274281
}
282+
const hours = Math.floor(diff / 60);
283+
const minutes = diff % 60;
284+
return `${hours}:${minutes}`;
285+
}
275286

276287
convertTimeToDateTimeOfToday(hourMinutes: string): string {
277288
const today = new Date();
@@ -280,37 +291,37 @@ export class WorkdayEntityDialogComponent implements OnInit {
280291
return today.toISOString();
281292
}
282293

283-
convertTimeToMinutes(timeStamp: string, isFiveNumberIntervals: boolean = false): number {
284-
if (timeStamp === '' || timeStamp === null) {
285-
return null;
286-
}
287-
const parts = timeStamp.split(':');
288-
const hours = parseInt(parts[0], 10);
289-
const minutes = parseInt(parts[1], 10);
290-
if (isFiveNumberIntervals) {
291-
const result = ((hours * 60 + minutes) / 5);
292-
if (result !== 0) {
293-
return result + 1
294-
}
295-
return 0;
296-
}
297-
return hours * 60 + minutes;
294+
convertTimeToMinutes(timeStamp: string, isFiveNumberIntervals: boolean = false): number {
295+
if (timeStamp === '' || timeStamp === null) {
296+
return null;
298297
}
298+
const parts = timeStamp.split(':');
299+
const hours = parseInt(parts[0], 10);
300+
const minutes = parseInt(parts[1], 10);
301+
if (isFiveNumberIntervals) {
302+
const result = ((hours * 60 + minutes) / 5);
303+
if (result !== 0) {
304+
return result + 1
305+
}
306+
return 0;
307+
}
308+
return hours * 60 + minutes;
309+
}
299310

300-
convertHoursToTime(hours: number): string {
301-
const isNegative = hours < 0;
302-
if (hours < 0) {
303-
hours = Math.abs(hours);
304-
}
305-
const totalMinutes = Math.floor(hours * 60)
306-
const hrs = Math.floor(totalMinutes / 60);
307-
let mins = totalMinutes % 60;
308-
if (isNegative) {
309-
// return '${padZero(hrs)}:${padZero(60 - mins)}';
310-
return `-${hrs}:${this.padZero(mins)}`;
311-
}
312-
return `${this.padZero(hrs)}:${this.padZero(mins)}`;
311+
convertHoursToTime(hours: number): string {
312+
const isNegative = hours < 0;
313+
if (hours < 0) {
314+
hours = Math.abs(hours);
313315
}
316+
const totalMinutes = Math.floor(hours * 60)
317+
const hrs = Math.floor(totalMinutes / 60);
318+
let mins = totalMinutes % 60;
319+
if (isNegative) {
320+
// return '${padZero(hrs)}:${padZero(60 - mins)}';
321+
return `-${hrs}:${this.padZero(mins)}`;
322+
}
323+
return `${this.padZero(hrs)}:${this.padZero(mins)}`;
324+
}
314325

315326
onCancel() {
316327
}

eform-client/src/app/plugins/modules/time-planning-pn/components/plannings/time-plannings-table/time-plannings-table.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export class TimePlanningsTableComponent implements OnInit, OnChanges {
189189
this.timePlanningPnSettingsService.getAssignedSite(siteId).subscribe(result => {
190190
if (result && result.success) {
191191
this.dialog.open(WorkdayEntityDialogComponent, {
192-
data: {planningPrDayModels: cellData, site: result.model},
192+
data: {planningPrDayModels: cellData, assignedSiteModel: result.model},
193193
}).afterClosed().subscribe((data) => {
194194
if (data) {
195195
this.timePlanningChanged.emit(data);

0 commit comments

Comments
 (0)