แก้ไขการคำนวนระยะเวลาครองตำแหน่ง

This commit is contained in:
Warunee Tamkoo 2026-05-18 20:56:20 +07:00
parent f1c546ba8f
commit d093953fbe
3 changed files with 227 additions and 143 deletions

View file

@ -27,7 +27,7 @@ import { Profile } from "../entities/Profile";
import { In, LessThan, IsNull, MoreThan } from "typeorm";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
import { calculateTenure } from "../utils/tenure";
import { normalizeDurationSumSimple } from "../utils/tenure";
import { Command } from "../entities/Command";
import { OrgRoot } from "../entities/OrgRoot";
import Extension from "../interfaces/extension";
@ -161,6 +161,14 @@ export class ProfileSalaryEmployeeController extends Controller {
_position.length > 1
? _position.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// 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,
name: _position[index]?.positionName,
}))
: [];
@ -171,15 +179,25 @@ export class ProfileSalaryEmployeeController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// 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;
},
@ -195,6 +213,14 @@ export class ProfileSalaryEmployeeController extends Controller {
_posLevel.length > 1
? _posLevel.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// 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,
name:
!_posLevel[index]?.positionType && _posLevel[index]?.positionCee
? `ระดับ ${_posLevel[index]?.positionCee.trim()}`
@ -208,15 +234,25 @@ export class ProfileSalaryEmployeeController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// 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;
},
@ -254,6 +290,14 @@ export class ProfileSalaryEmployeeController extends Controller {
_position.length > 1
? _position.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// 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,
name: _position[index]?.positionName,
}))
: [];
@ -264,15 +308,25 @@ export class ProfileSalaryEmployeeController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// 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;
},
@ -288,6 +342,14 @@ export class ProfileSalaryEmployeeController extends Controller {
_posLevel.length > 1
? _posLevel.slice(1).map((curr: any, index: number) => ({
days: curr.days_diff ? Number(curr.days_diff) : 0,
// 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,
name:
!_posLevel[index]?.positionType && _posLevel[index]?.positionCee
? `ระดับ ${_posLevel[index]?.positionCee.trim()}`
@ -301,15 +363,25 @@ export class ProfileSalaryEmployeeController extends Controller {
if (existing) {
existing.days += curr.days;
existing.year += curr.year;
existing.month += curr.month;
existing.day += curr.day;
} else {
existing = { name: curr.name, days: curr.days };
existing = {
name: curr.name,
days: curr.days,
year: curr.year,
month: curr.month,
day: curr.day,
};
acc.push(existing);
}
const { year, month, day } = calculateTenure(existing.days);
existing.year = year;
existing.month = month;
existing.day = day;
// 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;
},