แก้ไขการคำนวนระยะเวลาครองตำแหน่ง
This commit is contained in:
parent
f1c546ba8f
commit
d093953fbe
3 changed files with 227 additions and 143 deletions
|
|
@ -23,7 +23,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee";
|
|||
import { In, IsNull, LessThan, MoreThan, Not } from "typeorm";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { calculateTenure } from "../utils/tenure";
|
||||
import { normalizeDurationSumSimple } from "../utils/tenure";
|
||||
import { TenurePositionOfficer } from "../entities/TenurePositionOfficer";
|
||||
import { TenureLevelOfficer } from "../entities/TenureLevelOfficer";
|
||||
import { TenurePositionEmployee } from "../entities/TenurePositionEmployee";
|
||||
|
|
@ -78,33 +78,28 @@ export class ProfileSalaryController extends Controller {
|
|||
_currentDate,
|
||||
]);
|
||||
const _position = position.length > 0 ? position[0] : [];
|
||||
// Filter for current position and use SP's calculated values (calendar arithmetic)
|
||||
const mapPosition =
|
||||
_position.length > 1
|
||||
? _position.slice(1).map((curr: any, index: number) => ({
|
||||
days_diff: curr.days_diff,
|
||||
positionName: _position[index]?.positionName,
|
||||
// Use stored procedure's calculated values (calendar arithmetic)
|
||||
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
|
||||
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
|
||||
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
|
||||
}))
|
||||
: [];
|
||||
const calDayDiff = mapPosition
|
||||
.filter((curr: any) => curr.positionName == x.position)
|
||||
.reduce(
|
||||
(acc: any, curr: any) => {
|
||||
acc.days_diff += Number(curr.days_diff) || 0;
|
||||
acc.positionName = curr.positionName;
|
||||
return acc;
|
||||
},
|
||||
{ days_diff: 0, positionName: null },
|
||||
);
|
||||
const { year, month, day } = calculateTenure(calDayDiff.days_diff);
|
||||
const mapData: any = {
|
||||
profileId: x.id,
|
||||
positionName: calDayDiff.positionName,
|
||||
days_diff: calDayDiff.days_diff,
|
||||
Years: year,
|
||||
Months: month,
|
||||
Days: day,
|
||||
};
|
||||
data.push(mapData);
|
||||
const currentTenure = mapPosition.find((curr: any) => curr.positionName == x.position);
|
||||
if (currentTenure) {
|
||||
const mapData: any = {
|
||||
profileId: x.id,
|
||||
positionName: currentTenure.positionName,
|
||||
year: currentTenure.year,
|
||||
month: currentTenure.month,
|
||||
day: currentTenure.day,
|
||||
};
|
||||
data.push(mapData);
|
||||
}
|
||||
}
|
||||
await this.positionOfficerRepo.save(data);
|
||||
|
||||
|
|
@ -128,33 +123,28 @@ export class ProfileSalaryController extends Controller {
|
|||
_currentDate,
|
||||
]);
|
||||
const _position = position.length > 0 ? position[0] : [];
|
||||
// Filter for current position and use SP's calculated values (calendar arithmetic)
|
||||
const mapPosition =
|
||||
_position.length > 1
|
||||
? _position.slice(1).map((curr: any, index: number) => ({
|
||||
days_diff: curr.days_diff,
|
||||
positionName: _position[index]?.positionName,
|
||||
// Use stored procedure's calculated values (calendar arithmetic)
|
||||
year: curr.Years !== null && curr.Years !== undefined ? Math.floor(Number(curr.Years)) : 0,
|
||||
month: curr.Months !== null && curr.Months !== undefined ? Math.floor(Number(curr.Months)) : 0,
|
||||
day: curr.Days !== null && curr.Days !== undefined ? Math.floor(Number(curr.Days)) : 0,
|
||||
}))
|
||||
: [];
|
||||
const calDayDiff = mapPosition
|
||||
.filter((curr: any) => curr.positionName == x.position)
|
||||
.reduce(
|
||||
(acc: any, curr: any) => {
|
||||
acc.days_diff += Number(curr.days_diff) || 0;
|
||||
acc.positionName = curr.positionName;
|
||||
return acc;
|
||||
},
|
||||
{ days_diff: 0, positionName: null },
|
||||
);
|
||||
const { year, month, day } = calculateTenure(calDayDiff.days_diff);
|
||||
const mapData: any = {
|
||||
profileEmployeeId: x.id,
|
||||
positionName: calDayDiff.positionName,
|
||||
days_diff: calDayDiff.days_diff,
|
||||
Years: year,
|
||||
Months: month,
|
||||
Days: day,
|
||||
};
|
||||
data.push(mapData);
|
||||
const currentTenure = mapPosition.find((curr: any) => curr.positionName == x.position);
|
||||
if (currentTenure) {
|
||||
const mapData: any = {
|
||||
profileEmployeeId: x.id,
|
||||
positionName: currentTenure.positionName,
|
||||
year: currentTenure.year,
|
||||
month: currentTenure.month,
|
||||
day: currentTenure.day,
|
||||
};
|
||||
data.push(mapData);
|
||||
}
|
||||
}
|
||||
await this.positionEmployeeRepo.save(data);
|
||||
|
||||
|
|
@ -203,16 +193,17 @@ export class ProfileSalaryController extends Controller {
|
|||
},
|
||||
{ days_diff: 0, positionType: null, positionLevel: null, positionCee: null },
|
||||
);
|
||||
const { year, month, day } = calculateTenure(calDayDiff.days_diff);
|
||||
const years = calDayDiff.days_diff / 365;
|
||||
const normalized = normalizeDurationSumSimple(years, 0, 0);
|
||||
const mapData: any = {
|
||||
profileId: x.id,
|
||||
positionType: calDayDiff.positionType,
|
||||
positionLevel: calDayDiff.positionLevel,
|
||||
positionCee: calDayDiff.positionCee,
|
||||
days_diff: calDayDiff.days_diff,
|
||||
Years: x.posLevel == null ? 0 : year.toFixed(4),
|
||||
Months: x.posLevel == null ? 0 : month.toFixed(4),
|
||||
Days: x.posLevel == null ? 0 : day.toFixed(4),
|
||||
Years: x.posLevel == null ? 0 : normalized.years.toFixed(4),
|
||||
Months: x.posLevel == null ? 0 : normalized.months.toFixed(4),
|
||||
Days: x.posLevel == null ? 0 : normalized.days.toFixed(4),
|
||||
};
|
||||
data.push(mapData);
|
||||
}
|
||||
|
|
@ -263,16 +254,17 @@ export class ProfileSalaryController extends Controller {
|
|||
},
|
||||
{ days_diff: 0, positionType: null, positionLevel: null, positionCee: null },
|
||||
);
|
||||
const { year, month, day } = calculateTenure(calDayDiff.days_diff);
|
||||
const years = calDayDiff.days_diff / 365;
|
||||
const normalized = normalizeDurationSumSimple(years, 0, 0);
|
||||
const mapData: any = {
|
||||
profileEmployeeId: x.id,
|
||||
positionType: calDayDiff.positionType,
|
||||
positionLevel: calDayDiff.positionLevel,
|
||||
positionCee: calDayDiff.positionCee,
|
||||
days_diff: calDayDiff.days_diff,
|
||||
Years: x.posLevel == null ? 0 : year.toFixed(4),
|
||||
Months: x.posLevel == null ? 0 : month.toFixed(4),
|
||||
Days: x.posLevel == null ? 0 : day.toFixed(4),
|
||||
Years: x.posLevel == null ? 0 : normalized.years.toFixed(4),
|
||||
Months: x.posLevel == null ? 0 : normalized.months.toFixed(4),
|
||||
Days: x.posLevel == null ? 0 : normalized.days.toFixed(4),
|
||||
};
|
||||
data.push(mapData);
|
||||
}
|
||||
|
|
@ -337,14 +329,15 @@ export class ProfileSalaryController extends Controller {
|
|||
},
|
||||
{ days_diff: 0, positionExecutive: null },
|
||||
);
|
||||
const { year, month, day } = calculateTenure(calDayDiff.days_diff);
|
||||
const years = calDayDiff.days_diff / 365;
|
||||
const normalized = normalizeDurationSumSimple(years, 0, 0);
|
||||
const mapData: any = {
|
||||
profileId: x.id,
|
||||
positionExecutiveName: calDayDiff.positionExecutive,
|
||||
days_diff: calDayDiff.days_diff,
|
||||
Years: year.toFixed(4),
|
||||
Months: month.toFixed(4),
|
||||
Days: day.toFixed(4),
|
||||
Years: normalized.years.toFixed(4),
|
||||
Months: normalized.months.toFixed(4),
|
||||
Days: normalized.days.toFixed(4),
|
||||
};
|
||||
data.push(mapData);
|
||||
}
|
||||
|
|
@ -617,15 +610,15 @@ export class ProfileSalaryController extends Controller {
|
|||
acc.push(existing);
|
||||
}
|
||||
|
||||
// Normalize the summed values (convert excess days to months, months to years)
|
||||
while (existing.day >= 30) {
|
||||
existing.month += Math.floor(existing.day / 30);
|
||||
existing.day = existing.day % 30;
|
||||
}
|
||||
while (existing.month >= 12) {
|
||||
existing.year += Math.floor(existing.month / 12);
|
||||
existing.month = existing.month % 12;
|
||||
}
|
||||
// Normalize the summed values using calendar arithmetic
|
||||
const normalized = normalizeDurationSumSimple(
|
||||
existing.year,
|
||||
existing.month,
|
||||
existing.day
|
||||
);
|
||||
existing.year = normalized.years;
|
||||
existing.month = normalized.months;
|
||||
existing.day = normalized.days;
|
||||
|
||||
return acc;
|
||||
},
|
||||
|
|
@ -668,15 +661,15 @@ export class ProfileSalaryController extends Controller {
|
|||
acc.push(existing);
|
||||
}
|
||||
|
||||
// Normalize the summed values (convert excess days to months, months to years)
|
||||
while (existing.day >= 30) {
|
||||
existing.month += Math.floor(existing.day / 30);
|
||||
existing.day = existing.day % 30;
|
||||
}
|
||||
while (existing.month >= 12) {
|
||||
existing.year += Math.floor(existing.month / 12);
|
||||
existing.month = existing.month % 12;
|
||||
}
|
||||
// Normalize the summed values using calendar arithmetic
|
||||
const normalized = normalizeDurationSumSimple(
|
||||
existing.year,
|
||||
existing.month,
|
||||
existing.day
|
||||
);
|
||||
existing.year = normalized.years;
|
||||
existing.month = normalized.months;
|
||||
existing.day = normalized.days;
|
||||
|
||||
return acc;
|
||||
},
|
||||
|
|
@ -714,15 +707,15 @@ export class ProfileSalaryController extends Controller {
|
|||
acc.push(existing);
|
||||
}
|
||||
|
||||
// Normalize the summed values (convert excess days to months, months to years)
|
||||
while (existing.day >= 30) {
|
||||
existing.month += Math.floor(existing.day / 30);
|
||||
existing.day = existing.day % 30;
|
||||
}
|
||||
while (existing.month >= 12) {
|
||||
existing.year += Math.floor(existing.month / 12);
|
||||
existing.month = existing.month % 12;
|
||||
}
|
||||
// Normalize the summed values using calendar arithmetic
|
||||
const normalized = normalizeDurationSumSimple(
|
||||
existing.year,
|
||||
existing.month,
|
||||
existing.day
|
||||
);
|
||||
existing.year = normalized.years;
|
||||
existing.month = normalized.months;
|
||||
existing.day = normalized.days;
|
||||
|
||||
return acc;
|
||||
},
|
||||
|
|
@ -787,15 +780,15 @@ export class ProfileSalaryController extends Controller {
|
|||
acc.push(existing);
|
||||
}
|
||||
|
||||
// Normalize the summed values (convert excess days to months, months to years)
|
||||
while (existing.day >= 30) {
|
||||
existing.month += Math.floor(existing.day / 30);
|
||||
existing.day = existing.day % 30;
|
||||
}
|
||||
while (existing.month >= 12) {
|
||||
existing.year += Math.floor(existing.month / 12);
|
||||
existing.month = existing.month % 12;
|
||||
}
|
||||
// Normalize the summed values using calendar arithmetic
|
||||
const normalized = normalizeDurationSumSimple(
|
||||
existing.year,
|
||||
existing.month,
|
||||
existing.day
|
||||
);
|
||||
existing.year = normalized.years;
|
||||
existing.month = normalized.months;
|
||||
existing.day = normalized.days;
|
||||
|
||||
return acc;
|
||||
},
|
||||
|
|
@ -839,15 +832,15 @@ export class ProfileSalaryController extends Controller {
|
|||
acc.push(existing);
|
||||
}
|
||||
|
||||
// Normalize the summed values (convert excess days to months, months to years)
|
||||
while (existing.day >= 30) {
|
||||
existing.month += Math.floor(existing.day / 30);
|
||||
existing.day = existing.day % 30;
|
||||
}
|
||||
while (existing.month >= 12) {
|
||||
existing.year += Math.floor(existing.month / 12);
|
||||
existing.month = existing.month % 12;
|
||||
}
|
||||
// Normalize the summed values using calendar arithmetic
|
||||
const normalized = normalizeDurationSumSimple(
|
||||
existing.year,
|
||||
existing.month,
|
||||
existing.day
|
||||
);
|
||||
existing.year = normalized.years;
|
||||
existing.month = normalized.months;
|
||||
existing.day = normalized.days;
|
||||
|
||||
return acc;
|
||||
},
|
||||
|
|
@ -885,15 +878,15 @@ export class ProfileSalaryController extends Controller {
|
|||
acc.push(existing);
|
||||
}
|
||||
|
||||
// Normalize the summed values (convert excess days to months, months to years)
|
||||
while (existing.day >= 30) {
|
||||
existing.month += Math.floor(existing.day / 30);
|
||||
existing.day = existing.day % 30;
|
||||
}
|
||||
while (existing.month >= 12) {
|
||||
existing.year += Math.floor(existing.month / 12);
|
||||
existing.month = existing.month % 12;
|
||||
}
|
||||
// Normalize the summed values using calendar arithmetic
|
||||
const normalized = normalizeDurationSumSimple(
|
||||
existing.year,
|
||||
existing.month,
|
||||
existing.day
|
||||
);
|
||||
existing.year = normalized.years;
|
||||
existing.month = normalized.months;
|
||||
existing.day = normalized.days;
|
||||
|
||||
return acc;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue