From 1696890f74c23044778451439572b1b9b68480ab Mon Sep 17 00:00:00 2001 From: harid Date: Fri, 6 Feb 2026 14:47:47 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5=20"?= =?UTF-8?q?=E0=B8=AD=E0=B8=B2=E0=B8=A2=E0=B8=B8=E0=B8=A3=E0=B8=B2=E0=B8=8A?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=20(=E0=B8=81=E0=B8=97=E0=B8=A1.)"?= =?UTF-8?q?=20#2285?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileGovernmentController.ts | 3 +++ src/controllers/ProfileGovernmentEmployeeController.ts | 3 +++ src/interfaces/utils.ts | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index f2208036..dcb138df 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -127,6 +127,7 @@ export class ProfileGovernmentHistoryController extends Controller { dateRetireLaw: record.dateRetireLaw ?? null, // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), govAge: await calculateGovAge(profile.id, "OFFICER"), + govAgeBkk: await calculateGovAge(profile.id, "OFFICER", true), dateAppoint: record.dateAppoint, dateStart: record.dateStart, govAgeAbsent: record.govAgeAbsent, @@ -310,6 +311,7 @@ export class ProfileGovernmentHistoryController extends Controller { dateRetireLaw: record?.dateRetireLaw ?? null, // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), govAge: await calculateGovAge(profileId, "OFFICER"), + govAgeBkk: await calculateGovAge(profileId, "OFFICER", true), dateAppoint: record?.dateAppoint, dateStart: record?.dateStart, govAgeAbsent: record?.govAgeAbsent, @@ -483,6 +485,7 @@ export class ProfileGovernmentHistoryController extends Controller { dateRetireLaw: record?.dateRetireLaw ?? null, // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), govAge: await calculateGovAge(profileId, "OFFICER"), + govAgeBkk: await calculateGovAge(profileId, "OFFICER", true), dateAppoint: record?.dateAppoint, dateStart: record?.dateStart, govAgeAbsent: record?.govAgeAbsent, diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index c44b3583..6709e5db 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -121,6 +121,7 @@ export class ProfileGovernmentEmployeeController extends Controller { dateRetireLaw: record.dateRetireLaw ?? null, // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), govAge: await calculateGovAge(profile.id, "EMPLOYEE"), + govAgeBkk: await calculateGovAge(profile.id, "EMPLOYEE", true), dateAppoint: record.dateAppoint, dateStart: record.dateStart, govAgeAbsent: record.govAgeAbsent, @@ -292,6 +293,7 @@ export class ProfileGovernmentEmployeeController extends Controller { dateRetire: record?.dateRetire ?? null, //วันครบเกษียณอายุ // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), //อายุราชการ govAge: await calculateGovAge(profileEmployeeId, "EMPLOYEE"), + govAgeBkk: await calculateGovAge(profileEmployeeId, "EMPLOYEE", true), govAgeAbsent: record?.govAgeAbsent ?? null, // ขาดราชการ govAgePlus: record?.govAgePlus, // อายุราชการเกื้อกูล dateRetireLaw: record?.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย @@ -451,6 +453,7 @@ export class ProfileGovernmentEmployeeController extends Controller { dateRetire: record?.dateRetire ?? null, //วันครบเกษียณอายุ // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), //อายุราชการ govAge: await calculateGovAge(profileEmployeeId, "EMPLOYEE"), + govAgeBkk: await calculateGovAge(profileEmployeeId, "EMPLOYEE", true), govAgeAbsent: record?.govAgeAbsent ?? null, // ขาดราชการ govAgePlus: record?.govAgePlus, // อายุราชการเกื้อกูล dateRetireLaw: record?.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index abe4bd4a..e572f038 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -44,7 +44,7 @@ export function calculateAge(start: Date, end = new Date()) { return { year, month, day }; } -export async function calculateGovAge(profileId: string, type: string) { +export async function calculateGovAge(profileId: string, type: string, bkk?: boolean) { // type = OFFICER , EMPLOYEE const isEmployee = type === "EMPLOYEE"; @@ -107,7 +107,9 @@ export async function calculateGovAge(profileId: string, type: string) { }); } // const firstStartDate = new Date(records[0].date); - const firstStartDate = profile?.dateAppoint ? profile?.dateAppoint : new Date(); + const firstStartDate = !bkk + ? profile?.dateAppoint ? profile?.dateAppoint : new Date() + : profile?.dateStart ? profile?.dateStart : new Date() ; const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date(); // console.log("firstStartDate1", firstStartDate);