Fix เลขที่ตำแหน่งไม่แสดง #2230 + Add api สำหรับใบลา #2233
All checks were successful
Build & Deploy on Dev / build (push) Successful in 59s

This commit is contained in:
harid 2026-01-26 15:42:56 +07:00
parent 6e6253887f
commit 1ade81a048

View file

@ -39,6 +39,7 @@ import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
import { PosMasterAssign } from "../entities/PosMasterAssign";
import { Assign } from "../entities/Assign";
import { ProfileSalary } from "../entities/ProfileSalary";
import { ProfileEducation } from "../entities/ProfileEducation";
@Route("api/v1/org/dotnet")
@Tags("Dotnet")
@Security("bearerAuth")
@ -67,6 +68,7 @@ export class OrganizationDotnetController extends Controller {
private posMasterAssignRepo = AppDataSource.getRepository(PosMasterAssign);
private assignRepository = AppDataSource.getRepository(Assign);
private salaryRepo = AppDataSource.getRepository(ProfileSalary);
private educationRepo = AppDataSource.getRepository(ProfileEducation);
/**
* service call
@ -6788,6 +6790,308 @@ export class OrganizationDotnetController extends Controller {
return new HttpSuccess(mapProfile);
}
@Post("profile-leave/keycloak")
async GetProfileLeaveReportByKeycloakIdAsync(
@Body() body: {
keycloakId: string,
report?: string
}
) {
const profile = await this.profileRepo.findOne({
relations: {
currentProvince: true,
currentDistrict: true,
currentSubDistrict: true,
posLevel: true,
posType: true,
current_holders: {
orgRevision: true,
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
},
where: {
keycloak: body.keycloakId,
},
});
// ลูกจ้างประจำ
if (!profile) {
const profile = await this.profileEmpRepo.findOne({
relations: {
currentProvince: true,
currentDistrict: true,
currentSubDistrict: true,
posLevel: true,
posType: true,
current_holders: {
orgRevision: true,
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
},
},
where: {
keycloak: body.keycloakId,
}
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
/* =========================================
* current holder
* ========================================= */
const currentHolder = profile.current_holders?.find(
x =>
x.orgRevision?.orgRevisionIsDraft === false &&
x.orgRevision?.orgRevisionIsCurrent === true,
);
let oc = "";
if (currentHolder) {
if (!currentHolder.orgChild1Id) {
oc = currentHolder.orgRoot?.orgRootName;
} else if (!currentHolder.orgChild2Id) {
oc = `${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
} else if (!currentHolder.orgChild3Id) {
oc = `${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
} else if (!currentHolder.orgChild4Id) {
oc = `${currentHolder.orgChild3?.orgChild3Name} ${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
} else {
oc = currentHolder.orgChild4?.orgChild4Name;
}
}
let _positions: any[] = [];
let _educations: any[] = [];
if (body.report && ["LEAVE16"].includes(body.report.trim().toUpperCase())) {
const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today");
let _currentDate = CURRENT_DATE[0].today;
if (profile && profile?.isLeave) {
_currentDate =
profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate;
}
const positions = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [
profile!.id,
_currentDate,
]);
_positions = positions[0].length > 0
? _positions.slice(0, -1).map((x: any, idx: number) => ({
positionName: x.positionName,
dateStart: x.commandDateAffect ?? null,
dateEnd: _positions[idx + 1]?.commandDateAffect ?? null,
}))
: [];
const profileEducations = await this.educationRepo.find({
where: { profileEmployeeId: profile!.id },
order: { level: "ASC" },
});
_educations = profileEducations.length > 0
? profileEducations.map((x) => ({
educationLevel: x.educationLevel,
institute: x.institute ?? "-",
country: x.country ?? "-",
finishDate: x.finishDate,
}))
: [];
}
const mapProfile = {
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
birthDate: profile.birthDate,
retireDate: profile.birthDate
? calculateRetireLaw(profile.birthDate)
: null,
govAge: profile.dateAppoint
? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี`
: null,
age: profile.birthDate
? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET")
: null,
dateAppoint: profile.dateAppoint,
dateCurrent: new Date(),
amount: profile.amount,
telephoneNumber: profile.telephoneNumber,
currentAddress:
profile && profile.currentAddress
? profile.currentAddress +
(profile.currentSubDistrict && profile.currentSubDistrict.name
? " ตำบล/แขวง " + profile.currentSubDistrict.name
: "") +
(profile.currentDistrict && profile.currentDistrict.name
? " อำเภอ/เขต " + profile.currentDistrict.name
: "") +
(profile.currentProvince && profile.currentProvince.name
? " จังหวัด " + profile.currentProvince.name + " "
: "") +
profile.currentZipCode
: "-",
position: profile.position,
posType: profile.posType?.posTypeName,
posLevel: `${profile.posType?.posTypeShortName} ${profile.posLevel?.posLevelName}`,
positionLeaveName: null,
posExecutiveName: null,
isCommission: currentHolder?.orgRoot?.isCommission ?? false,
root: currentHolder?.orgRoot?.orgRootName ?? null,
child1: currentHolder?.orgChild1?.orgChild1Name ?? null,
child2: currentHolder?.orgChild2?.orgChild2Name ?? null,
child3: currentHolder?.orgChild3?.orgChild3Name ?? null,
child4: currentHolder?.orgChild4?.orgChild4Name ?? null,
oc: oc,
positions: _positions,
educations: _educations,
};
return new HttpSuccess(mapProfile);
}
/* =========================================
* current holder
* ========================================= */
const currentHolder = profile.current_holders?.find(
x =>
x.orgRevision?.orgRevisionIsDraft === false &&
x.orgRevision?.orgRevisionIsCurrent === true,
);
let oc = "";
if (currentHolder) {
if (!currentHolder.orgChild1Id) {
oc = currentHolder.orgRoot?.orgRootName;
} else if (!currentHolder.orgChild2Id) {
oc = `${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
} else if (!currentHolder.orgChild3Id) {
oc = `${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
} else if (!currentHolder.orgChild4Id) {
oc = `${currentHolder.orgChild3?.orgChild3Name} ${currentHolder.orgChild2?.orgChild2Name} ${currentHolder.orgChild1?.orgChild1Name} ${currentHolder.orgRoot?.orgRootName}`;
} else {
oc = currentHolder.orgChild4?.orgChild4Name;
}
}
/* =========================================
* posType + posLevel
* ========================================= */
const positionLeaveName =
profile.posType &&
profile.posLevel &&
(profile.posType.posTypeName === "บริหาร" ||
profile.posType.posTypeName === "อำนวยการ")
? `${profile.posType.posTypeName}${profile.posLevel.posLevelName}`
: profile.posLevel?.posLevelName ?? null;
/* =========================================
* position executive
* ========================================= */
const _posExec = await this.positionRepository.findOne({
where: {
positionIsSelected: true,
posMaster: {
orgRevisionId: currentHolder?.orgRevisionId,
current_holderId: profile.id,
},
},
order: { createdAt: "DESC" },
relations: { posExecutive: true },
});
let _positions: any[] = [];
let _educations: any[] = [];
if (body.report && ["LEAVE16"].includes(body.report.trim().toUpperCase())) {
const CURRENT_DATE = await AppDataSource.query("SELECT CURRENT_DATE() as today");
let _currentDate = CURRENT_DATE[0].today;
if (profile && profile?.isLeave) {
_currentDate =
profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate;
}
const positions = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [
profile!.id,
_currentDate,
]);
_positions = positions[0].length > 0
? _positions.slice(0, -1).map((x: any, idx: number) => ({
positionName: x.positionName,
dateStart: x.commandDateAffect ?? null,
dateEnd: _positions[idx + 1]?.commandDateAffect ?? null,
}))
: [];
const profileEducations = await this.educationRepo.find({
where: { profileId: profile!.id },
order: { level: "ASC" },
});
_educations = profileEducations.length > 0
? profileEducations.map((x) => ({
educationLevel: x.educationLevel,
institute: x.institute ?? "-",
country: x.country ?? "-",
finishDate: x.finishDate,
}))
: [];
}
const mapProfile = {
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
birthDate: profile.birthDate,
retireDate: profile.birthDate
? calculateRetireLaw(profile.birthDate)
: null,
govAge: profile.dateAppoint
? `${Extension.CalculateGovAge(profile.dateAppoint, 0, 0)} ปี`
: null,
age: profile.birthDate
? Extension.CalculateAgeStrV2(profile.birthDate, 0, 0, "GET")
: null,
dateAppoint: profile.dateAppoint,
dateCurrent: new Date(),
amount: profile.amount,
telephoneNumber: profile.telephoneNumber,
currentAddress:
profile && profile.currentAddress
? profile.currentAddress +
(profile.currentSubDistrict && profile.currentSubDistrict.name
? " ตำบล/แขวง " + profile.currentSubDistrict.name
: "") +
(profile.currentDistrict && profile.currentDistrict.name
? " อำเภอ/เขต " + profile.currentDistrict.name
: "") +
(profile.currentProvince && profile.currentProvince.name
? " จังหวัด " + profile.currentProvince.name + " "
: "") +
profile.currentZipCode
: "-",
position: profile.position ?? "-",
posLevel: profile.posLevel?.posLevelName ?? "-",
posType: profile.posType?.posTypeName ?? "-",
positionLeaveName,
posExecutiveName: _posExec?.posExecutive?.posExecutiveName ?? null,
isCommission: currentHolder?.orgRoot?.isCommission ?? false,
root: currentHolder?.orgRoot?.orgRootName ?? null,
child1: currentHolder?.orgChild1?.orgChild1Name ?? null,
child2: currentHolder?.orgChild2?.orgChild2Name ?? null,
child3: currentHolder?.orgChild3?.orgChild3Name ?? null,
child4: currentHolder?.orgChild4?.orgChild4Name ?? null,
oc: oc,
positions: _positions,
educations: _educations,
};
return new HttpSuccess(mapProfile);
}
/**
* API Get Profile Mark
*
@ -7723,7 +8027,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile?.dateStart ?? null,
dateAppoint: profile?.dateAppoint ?? null,
keycloak: profile?.keycloak ?? null,
posNo: item.shortName,
posNo: `${item.shortName} ${item.posMasterNo}`,
position: item.position,
positionLevel: item.posLevel,
positionType: item.posType,