fix(banking_hours): added modifier of 1.5 to ensure real display and manipulations of banked hours
This commit is contained in:
parent
d414670d80
commit
560bb9cc3c
|
|
@ -40,7 +40,7 @@ export class BankedHoursService {
|
||||||
const new_balance = await tx.paidTimeOff.update({
|
const new_balance = await tx.paidTimeOff.update({
|
||||||
where: { employee_id: employee.id },
|
where: { employee_id: employee.id },
|
||||||
data: {
|
data: {
|
||||||
banked_hours: { increment: asked_hours },
|
banked_hours: { increment: (asked_hours) },
|
||||||
last_updated: new Date(),
|
last_updated: new Date(),
|
||||||
},
|
},
|
||||||
select: { banked_hours: true },
|
select: { banked_hours: true },
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,14 @@ export class PaidTimeOFfBankHoursService {
|
||||||
og_start: Date,
|
og_start: Date,
|
||||||
og_end: Date
|
og_end: Date
|
||||||
): Promise<Result<boolean, string>> => {
|
): Promise<Result<boolean, string>> => {
|
||||||
const original_hours = computeHours(og_start, og_end);
|
let original_hours = computeHours(og_start, og_end);
|
||||||
const ajusted_hours = computeHours(start_time, end_time);
|
let ajusted_hours = computeHours(start_time, end_time);
|
||||||
|
|
||||||
|
if (type === 'BANKING') {
|
||||||
|
original_hours = original_hours * 1.5;
|
||||||
|
ajusted_hours = ajusted_hours * 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
const diff_hours = Math.abs(ajusted_hours - original_hours);
|
const diff_hours = Math.abs(ajusted_hours - original_hours);
|
||||||
|
|
||||||
if (diff_hours === 0) return { success: true, data: true };
|
if (diff_hours === 0) return { success: true, data: true };
|
||||||
|
|
@ -83,8 +89,11 @@ export class PaidTimeOFfBankHoursService {
|
||||||
|
|
||||||
//called during delete function of Shifts Module
|
//called during delete function of Shifts Module
|
||||||
updatePaidTimeoffBankHoursWhenShiftDelete = async (start: Date, end: Date, type: string, employee_id: number) => {
|
updatePaidTimeoffBankHoursWhenShiftDelete = async (start: Date, end: Date, type: string, employee_id: number) => {
|
||||||
const ajusted_hours = computeHours(start, end);
|
let ajusted_hours = computeHours(start, end);
|
||||||
if (!paid_time_off_types.includes(type)) return;
|
if (!paid_time_off_types.includes(type)) return;
|
||||||
|
if (type === 'BANKING') {
|
||||||
|
ajusted_hours = ajusted_hours * 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
const config = paid_time_off_mapping[type];
|
const config = paid_time_off_mapping[type];
|
||||||
await this.prisma.paidTimeOff.update({
|
await this.prisma.paidTimeOff.update({
|
||||||
|
|
|
||||||
|
|
@ -103,13 +103,17 @@ export class ShiftsCreateService {
|
||||||
|
|
||||||
let adjusted_end_time = normed_shift.data.end_time;
|
let adjusted_end_time = normed_shift.data.end_time;
|
||||||
|
|
||||||
if (paid_time_off_types.includes(dto.type)) {
|
|
||||||
const amount_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
|
|
||||||
const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED'];
|
|
||||||
|
|
||||||
|
if (paid_time_off_types.includes(dto.type)) {
|
||||||
let result: Result<number, string>;
|
let result: Result<number, string>;
|
||||||
|
|
||||||
|
let amount_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
|
||||||
|
const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED'];
|
||||||
|
|
||||||
if (banking_types.includes(dto.type)) {
|
if (banking_types.includes(dto.type)) {
|
||||||
|
if (dto.type === 'BANKING') {
|
||||||
|
amount_hours = amount_hours * 1.5;
|
||||||
|
}
|
||||||
result = await this.bankingService.manageBankingHours(employee_id, amount_hours, dto.type);
|
result = await this.bankingService.manageBankingHours(employee_id, amount_hours, dto.type);
|
||||||
} else {
|
} else {
|
||||||
switch (dto.type) {
|
switch (dto.type) {
|
||||||
|
|
|
||||||
|
|
@ -92,13 +92,19 @@ export class ShiftsUpdateService {
|
||||||
//call to ajust paid_time_off hour banks
|
//call to ajust paid_time_off hour banks
|
||||||
if (paid_time_off_types.includes(original_type) || paid_time_off_types.includes(new_type)) {
|
if (paid_time_off_types.includes(original_type) || paid_time_off_types.includes(new_type)) {
|
||||||
if (type_changed) {
|
if (type_changed) {
|
||||||
const original_hours = computeHours(original.start_time, original.end_time);
|
let original_hours = computeHours(original.start_time, original.end_time);
|
||||||
|
if (original_type === 'BANKING') {
|
||||||
|
original_hours = original_hours * 1.5;
|
||||||
|
}
|
||||||
if (paid_time_off_types.includes(original_type)) {
|
if (paid_time_off_types.includes(original_type)) {
|
||||||
const restoration = await this.paidTimeOffService.restorePaidTimeOffHours(employee.data, original_type, original_hours);
|
const restoration = await this.paidTimeOffService.restorePaidTimeOffHours(employee.data, original_type, original_hours);
|
||||||
if (!restoration.success) return { success: false, error: restoration.error };
|
if (!restoration.success) return { success: false, error: restoration.error };
|
||||||
}
|
}
|
||||||
if (paid_time_off_types.includes(new_type)) {
|
if (paid_time_off_types.includes(new_type)) {
|
||||||
const new_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
|
let new_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time);
|
||||||
|
if (new_type === 'BANKING') {
|
||||||
|
new_hours = new_hours * 1.5;
|
||||||
|
}
|
||||||
const validation = await this.paidTimeOffService.validateAndDeductPaidTimeOff(employee.data, new_type, new_hours);
|
const validation = await this.paidTimeOffService.validateAndDeductPaidTimeOff(employee.data, new_type, new_hours);
|
||||||
if (!validation.success) return { success: false, error: validation.error };
|
if (!validation.success) return { success: false, error: validation.error };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user