fixing cal position & level
This commit is contained in:
parent
1a39c0bfb1
commit
6cf2477fbe
1 changed files with 85 additions and 13 deletions
|
|
@ -123,28 +123,78 @@ export class ProfileSalaryController extends Controller {
|
||||||
);
|
);
|
||||||
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [profileId]);
|
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [profileId]);
|
||||||
const _position = position.length > 0 ? position[0] : [];
|
const _position = position.length > 0 ? position[0] : [];
|
||||||
|
|
||||||
const mapPosition =
|
const mapPosition =
|
||||||
_position.length > 1
|
_position.length > 1
|
||||||
? _position.slice(1).map((curr: any, index: number) => ({
|
? _position.slice(1).map((curr: any, index: number) => ({
|
||||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
days: curr.days_diff ? Number(curr.days_diff) : 0,
|
||||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
// year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
// month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||||
|
// day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||||
name: _position[index]?.positionName,
|
name: _position[index]?.positionName,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const groupMapPosition = mapPosition.reduce(
|
||||||
|
(acc: any, curr: any) => {
|
||||||
|
let existing = acc.find((item: any) => item.name === curr.name);
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
existing.days += curr.days;
|
||||||
|
} else {
|
||||||
|
existing = { name: curr.name, days: curr.days };
|
||||||
|
acc.push(existing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalculate year, month, and day
|
||||||
|
existing.year = Math.floor(existing.days / 365.2524);
|
||||||
|
existing.month = Math.floor((existing.days / 30.4375) % 12);
|
||||||
|
existing.day = Math.floor(existing.days % 30.4375);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
[] as { name: string; days: number; year: number; month: number; day: number }[],
|
||||||
|
);
|
||||||
|
|
||||||
const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?)", [profileId]);
|
const posLevel = await AppDataSource.query("CALL GetProfileSalaryLevel(?)", [profileId]);
|
||||||
const _posLevel = posLevel.length > 0 ? posLevel[0] : [];
|
const _posLevel = posLevel.length > 0 ? posLevel[0] : [];
|
||||||
const mapPosLevel =
|
const mapPosLevel =
|
||||||
_posLevel.length > 1
|
_posLevel.length > 1
|
||||||
? _posLevel.slice(1).map((curr: any, index: number) => ({
|
? _posLevel.slice(1).map((curr: any, index: number) => ({
|
||||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
days: curr.days_diff ? Number(curr.days_diff) : 0,
|
||||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
// year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
// month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||||
name: _posLevel[index]?.positionLevel,
|
// day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||||
|
name: !_posLevel[index]?.positionType
|
||||||
|
? `ระดับ ${_posLevel[index]?.positionCee.trim()}`
|
||||||
|
: _posLevel[index]?.positionType == "บริหาร" ||
|
||||||
|
_posLevel[index]?.positionType == "อำนวยการ"
|
||||||
|
? `${_posLevel[index]?.positionType}${_posLevel[index]?.positionLevel}`
|
||||||
|
: _posLevel[index]?.positionLevel,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const groupMapPosLevel = mapPosLevel.reduce(
|
||||||
|
(acc: any, curr: any) => {
|
||||||
|
let existing = acc.find((item: any) => item.name === curr.name);
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
existing.days += curr.days;
|
||||||
|
} else {
|
||||||
|
existing = { name: curr.name, days: curr.days };
|
||||||
|
acc.push(existing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalculate year, month, and day
|
||||||
|
existing.year = Math.floor(existing.days / 365.2524);
|
||||||
|
existing.month = Math.floor((existing.days / 30.4375) % 12);
|
||||||
|
existing.day = Math.floor(existing.days % 30.4375);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
[] as { name: string; days: number; year: number; month: number; day: number }[],
|
||||||
|
);
|
||||||
|
|
||||||
const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?)", [
|
const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?)", [
|
||||||
profileId,
|
profileId,
|
||||||
]);
|
]);
|
||||||
|
|
@ -152,17 +202,39 @@ export class ProfileSalaryController extends Controller {
|
||||||
const mapPosExecutive =
|
const mapPosExecutive =
|
||||||
_posExecutive.length > 1
|
_posExecutive.length > 1
|
||||||
? _posExecutive.slice(1).map((curr: any, index: number) => ({
|
? _posExecutive.slice(1).map((curr: any, index: number) => ({
|
||||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
// year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
// month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
// day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||||
|
days: curr.days_diff ? Number(curr.days_diff) : 0,
|
||||||
name: _posExecutive[index]?.positionExecutive,
|
name: _posExecutive[index]?.positionExecutive,
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const groupMapPosExecutive = mapPosExecutive.reduce(
|
||||||
|
(acc: any, curr: any) => {
|
||||||
|
let existing = acc.find((item: any) => item.name === curr.name);
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
existing.days += curr.days;
|
||||||
|
} else {
|
||||||
|
existing = { name: curr.name, days: curr.days };
|
||||||
|
acc.push(existing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recalculate year, month, and day
|
||||||
|
existing.year = Math.floor(existing.days / 365.2524);
|
||||||
|
existing.month = Math.floor((existing.days / 30.4375) % 12);
|
||||||
|
existing.day = Math.floor(existing.days % 30.4375);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
[] as { name: string; days: number; year: number; month: number; day: number }[],
|
||||||
|
);
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
position: mapPosition,
|
position: groupMapPosition,
|
||||||
posLevel: mapPosLevel,
|
posLevel: groupMapPosLevel,
|
||||||
posExecutive: mapPosExecutive,
|
posExecutive: groupMapPosExecutive,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue