clean(time_and_attendance): cleaning helpers, types, mappers, constants
This commit is contained in:
parent
4cb01de970
commit
7eb3844713
|
|
@ -3,9 +3,9 @@ import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { computeHours } from "src/common/utils/date-utils";
|
import { computeHours } from "src/common/utils/date-utils";
|
||||||
import { PayPeriodOverviewDto } from "../dtos/overview-pay-period.dto";
|
import { PayPeriodOverviewDto } from "../dtos/overview-pay-period.dto";
|
||||||
import { EmployeePeriodOverviewDto } from "../dtos/overview-employee-period.dto";
|
import { EmployeePeriodOverviewDto } from "../dtos/overview-employee-period.dto";
|
||||||
import { computePeriod, listPayYear, payYearOfDate } from "../utils/pay-year.util";
|
|
||||||
import { PayPeriodDto } from "../dtos/pay-period.dto";
|
import { PayPeriodDto } from "../dtos/pay-period.dto";
|
||||||
import { mapPayPeriodToDto } from "../mappers/pay-periods.mapper";
|
import { mapPayPeriodToDto } from "../mappers/pay-periods.mapper";
|
||||||
|
import { computePeriod, listPayYear, payYearOfDate } from "src/time-and-attendance/utils/date-time.utils";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PayPeriodsQueryService {
|
export class PayPeriodsQueryService {
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
import { toStringFromDate, toUTCDateFromString } from "src/time-and-attendance/utils/date-time.utils";
|
|
||||||
|
|
||||||
export const ANCHOR_ISO = '2023-12-17'; // ancre date
|
|
||||||
|
|
||||||
|
|
||||||
export function payYearOfDate(date: string | Date, anchorISO = ANCHOR_ISO): number {
|
|
||||||
const ANCHOR = toUTCDateFromString(anchorISO);
|
|
||||||
const d = toUTCDateFromString(date);
|
|
||||||
const days = Math.floor((+d - +ANCHOR) / MS_PER_DAY);
|
|
||||||
const cycles = Math.floor(days / (PERIODS_PER_YEAR * PERIOD_DAYS));
|
|
||||||
return ANCHOR.getUTCFullYear() + 1 + cycles;
|
|
||||||
}
|
|
||||||
//compute labels for periods
|
|
||||||
export function computePeriod(pay_year: number, period_no: number, anchorISO = ANCHOR_ISO) {
|
|
||||||
const ANCHOR = toUTCDateFromString(anchorISO);
|
|
||||||
const cycles = pay_year - (ANCHOR.getUTCFullYear() + 1);
|
|
||||||
const offsetPeriods = cycles * PERIODS_PER_YEAR + (period_no - 1);
|
|
||||||
const start = new Date(+ANCHOR + offsetPeriods * PERIOD_DAYS * MS_PER_DAY);
|
|
||||||
const end = new Date(+start + (PERIOD_DAYS - 1) * MS_PER_DAY);
|
|
||||||
const pay = new Date(end.getTime() + 6 * MS_PER_DAY);
|
|
||||||
return {
|
|
||||||
period_no: period_no,
|
|
||||||
pay_year: pay_year,
|
|
||||||
payday: toStringFromDate(pay),
|
|
||||||
period_start: toStringFromDate(start),
|
|
||||||
period_end: toStringFromDate(end),
|
|
||||||
label: `${toStringFromDate(start)}.${toStringFromDate(end)}`,
|
|
||||||
start, end,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//list of all 26 periods for a full year
|
|
||||||
export function listPayYear(pay_year: number, anchorISO = ANCHOR_ISO) {
|
|
||||||
return Array.from({ length: PERIODS_PER_YEAR }, (_, i) => computePeriod(pay_year, i + 1, anchorISO));
|
|
||||||
}
|
|
||||||
|
|
@ -2,6 +2,7 @@ const NUMBER_OF_TIMESHEETS_TO_RETURN = 2;
|
||||||
const DAILY_LIMIT_HOURS = 8;
|
const DAILY_LIMIT_HOURS = 8;
|
||||||
const WEEKLY_LIMIT_HOURS = 40;
|
const WEEKLY_LIMIT_HOURS = 40;
|
||||||
const PAY_PERIOD_ANCHOR = 2023-12-17;
|
const PAY_PERIOD_ANCHOR = 2023-12-17;
|
||||||
|
const ANCHOR_ISO = '2023-12-17'; // ancre date
|
||||||
const PERIOD_DAYS = 14;
|
const PERIOD_DAYS = 14;
|
||||||
const PERIODS_PER_YEAR = 26;
|
const PERIODS_PER_YEAR = 26;
|
||||||
const MS_PER_DAY = 86_400_000;
|
const MS_PER_DAY = 86_400_000;
|
||||||
|
|
|
||||||
|
|
@ -52,4 +52,35 @@ export const sevenDaysFrom = (date: Date | string): Date[] => {
|
||||||
d.setUTCDate(d.getUTCDate() + i );
|
d.setUTCDate(d.getUTCDate() + i );
|
||||||
return d;
|
return d;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function payYearOfDate(date: string | Date, anchorISO = ANCHOR_ISO): number {
|
||||||
|
const ANCHOR = toUTCDateFromString(anchorISO);
|
||||||
|
const d = toUTCDateFromString(date);
|
||||||
|
const days = Math.floor((+d - +ANCHOR) / MS_PER_DAY);
|
||||||
|
const cycles = Math.floor(days / (PERIODS_PER_YEAR * PERIOD_DAYS));
|
||||||
|
return ANCHOR.getUTCFullYear() + 1 + cycles;
|
||||||
|
}
|
||||||
|
//compute labels for periods
|
||||||
|
export function computePeriod(pay_year: number, period_no: number, anchorISO = ANCHOR_ISO) {
|
||||||
|
const ANCHOR = toUTCDateFromString(anchorISO);
|
||||||
|
const cycles = pay_year - (ANCHOR.getUTCFullYear() + 1);
|
||||||
|
const offsetPeriods = cycles * PERIODS_PER_YEAR + (period_no - 1);
|
||||||
|
const start = new Date(+ANCHOR + offsetPeriods * PERIOD_DAYS * MS_PER_DAY);
|
||||||
|
const end = new Date(+start + (PERIOD_DAYS - 1) * MS_PER_DAY);
|
||||||
|
const pay = new Date(end.getTime() + 6 * MS_PER_DAY);
|
||||||
|
return {
|
||||||
|
period_no: period_no,
|
||||||
|
pay_year: pay_year,
|
||||||
|
payday: toStringFromDate(pay),
|
||||||
|
period_start: toStringFromDate(start),
|
||||||
|
period_end: toStringFromDate(end),
|
||||||
|
label: `${toStringFromDate(start)}.${toStringFromDate(end)}`,
|
||||||
|
start, end,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//list of all 26 periods for a full year
|
||||||
|
export function listPayYear(pay_year: number, anchorISO = ANCHOR_ISO) {
|
||||||
|
return Array.from({ length: PERIODS_PER_YEAR }, (_, i) => computePeriod(pay_year, i + 1, anchorISO));
|
||||||
}
|
}
|
||||||
|
|
@ -1,45 +1,49 @@
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
|
|
||||||
export const expense_select = {
|
export const expense_select = {
|
||||||
id: true,
|
id: true,
|
||||||
timesheet_id: true,
|
timesheet_id: true,
|
||||||
bank_code_id: true,
|
bank_code_id: true,
|
||||||
attachment: true,
|
attachment: true,
|
||||||
date: true,
|
date: true,
|
||||||
amount: true,
|
amount: true,
|
||||||
mileage: true,
|
mileage: true,
|
||||||
comment: true,
|
comment: true,
|
||||||
supervisor_comment: true,
|
supervisor_comment: true,
|
||||||
is_approved: true,
|
is_approved: true,
|
||||||
} satisfies Prisma.ExpensesSelect;
|
} satisfies Prisma.ExpensesSelect;
|
||||||
|
|
||||||
export const shift_select = {
|
export const shift_select = {
|
||||||
id: true,
|
id: true,
|
||||||
timesheet_id: true,
|
timesheet_id: true,
|
||||||
bank_code_id: true,
|
bank_code_id: true,
|
||||||
date: true,
|
date: true,
|
||||||
start_time: true,
|
start_time: true,
|
||||||
end_time: true,
|
end_time: true,
|
||||||
is_remote: true,
|
is_remote: true,
|
||||||
is_approved: true,
|
is_approved: true,
|
||||||
comment: true,
|
comment: true,
|
||||||
} satisfies Prisma.ShiftsSelect;
|
} satisfies Prisma.ShiftsSelect;
|
||||||
|
|
||||||
export const leaveRequestsSelect = {
|
export const leaveRequestsSelect = {
|
||||||
id: true,
|
id: true,
|
||||||
bank_code_id: true,
|
bank_code_id: true,
|
||||||
leave_type: true,
|
leave_type: true,
|
||||||
date: true,
|
date: true,
|
||||||
payable_hours: true,
|
payable_hours: true,
|
||||||
requested_hours: true,
|
requested_hours: true,
|
||||||
comment: true,
|
comment: true,
|
||||||
approval_status: true,
|
approval_status: true,
|
||||||
employee: { select: {
|
employee: {
|
||||||
id: true,
|
select: {
|
||||||
user: { select: {
|
id: true,
|
||||||
email: true,
|
user: {
|
||||||
first_name: true,
|
select: {
|
||||||
last_name: true,
|
email: true,
|
||||||
}},
|
first_name: true,
|
||||||
}},
|
last_name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
} satisfies Prisma.LeaveRequestsSelect;
|
} satisfies Prisma.LeaveRequestsSelect;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user