???(???): holiday work, forget what it was. Probably related to timesheet approval and its filters
This commit is contained in:
parent
d613d97a1a
commit
6adbcad352
|
|
@ -10,7 +10,13 @@ export class PayPeriodOverviewDto {
|
|||
|
||||
export class EmployeePeriodOverviewDto {
|
||||
email: string;
|
||||
employee_name: string;
|
||||
employee_first_name: string;
|
||||
employee_last_name: string;
|
||||
supervisor?: {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
email: string;
|
||||
} | null;
|
||||
is_active: boolean;
|
||||
regular_hours: number;
|
||||
other_hours: {
|
||||
|
|
@ -53,5 +59,5 @@ export type Overview = {
|
|||
|
||||
export type options = {
|
||||
filtered_employee_ids?: number[];
|
||||
seed_names?: Map<number, { name: string, email: string }>
|
||||
seed_names?: Map<number, { first_name: string, last_name: string, email: string }>
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ export class GetOverviewService {
|
|||
select: {
|
||||
first_name: true,
|
||||
last_name: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -84,27 +85,36 @@ export class GetOverviewService {
|
|||
|
||||
// seed for employee without data
|
||||
if (overview.options?.seed_names) {
|
||||
for (const [id, { name, email }] of overview.options.seed_names.entries()) {
|
||||
by_employee.set(id, this.createEmployeeSeeds(email, name));
|
||||
for (const [id, { first_name, last_name, email }] of overview.options.seed_names.entries()) {
|
||||
by_employee.set(id, this.createEmployeeSeeds(email, first_name, last_name));
|
||||
}
|
||||
} else {
|
||||
for (const employee of employee_overviews) {
|
||||
const name = `${employee.user.first_name} ${employee.user.last_name}`;
|
||||
const record = this.createEmployeeSeeds(employee.user.email, name);
|
||||
const record = this.createEmployeeSeeds(
|
||||
employee.user.email,
|
||||
employee.user.first_name,
|
||||
employee.user.last_name,
|
||||
employee.supervisor?.user ?? null,
|
||||
);
|
||||
by_employee.set(employee.id, record);
|
||||
}
|
||||
}
|
||||
|
||||
const ensure = (id: number, name: string, email: string) => {
|
||||
const ensure = (id: number, first_name: string, last_name: string, email: string) => {
|
||||
if (!by_employee.has(id)) {
|
||||
by_employee.set(id, this.createEmployeeSeeds(email, name));
|
||||
by_employee.set(id, this.createEmployeeSeeds(email, first_name, last_name));
|
||||
}
|
||||
return by_employee.get(id)!;
|
||||
};
|
||||
|
||||
for (const employee of employee_overviews) {
|
||||
const name = `${employee.user.first_name} ${employee.user.last_name}`.trim();
|
||||
const record = ensure(employee.id, name, employee.user.email);
|
||||
const record = ensure(
|
||||
employee.id,
|
||||
employee.user.first_name,
|
||||
employee.user.last_name,
|
||||
employee.user.email
|
||||
);
|
||||
|
||||
for (const timesheet of employee.timesheet) {
|
||||
//totals by types for shifts
|
||||
for (const shift of timesheet.shift) {
|
||||
|
|
@ -153,11 +163,17 @@ export class GetOverviewService {
|
|||
if (!record) continue;
|
||||
const timesheets = employee.timesheet;
|
||||
const has_data = timesheets.some(timesheet => timesheet.shift.length > 0 || timesheet.expense.length > 0);
|
||||
|
||||
const cutoff_date = new Date();
|
||||
cutoff_date.setDate(cutoff_date.getDate() + 14);
|
||||
const is_active = employee.last_work_day ? employee.last_work_day.getTime() >= cutoff_date.getTime() : true;
|
||||
|
||||
record.is_approved = has_data && timesheets.every(timesheet => timesheet.is_approved === true);
|
||||
record.is_active = is_active;
|
||||
}
|
||||
|
||||
const employees_overview = Array.from(by_employee.values()).sort((a, b) =>
|
||||
a.employee_name.localeCompare(b.employee_name, "fr", { sensitivity: "base" }),
|
||||
a.employee_first_name.localeCompare(b.employee_first_name, "fr", { sensitivity: "base" }),
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
@ -174,10 +190,21 @@ export class GetOverviewService {
|
|||
};
|
||||
}
|
||||
|
||||
createEmployeeSeeds = (email: string, employee_name: string, is_active = true): EmployeePeriodOverviewDto => ({
|
||||
createEmployeeSeeds = (
|
||||
email: string,
|
||||
employee_first_name: string,
|
||||
employee_last_name: string,
|
||||
supervisor: {
|
||||
first_name: string;
|
||||
last_name:string;
|
||||
email: string;
|
||||
} | null = null,
|
||||
): EmployeePeriodOverviewDto => ({
|
||||
email,
|
||||
employee_name,
|
||||
is_active,
|
||||
employee_first_name,
|
||||
employee_last_name,
|
||||
supervisor: supervisor ?? null,
|
||||
is_active: true,
|
||||
regular_hours: 0,
|
||||
other_hours: {
|
||||
evening_hours: 0,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user