เพิ่ม report kk1 employee

This commit is contained in:
AnandaTon 2024-05-24 15:57:29 +07:00
parent a242f7bbdd
commit ee030a0e2d
2 changed files with 315 additions and 23 deletions

View file

@ -222,14 +222,19 @@ export class ProfileController extends Controller {
],
where: { id: id },
});
const province = await this.provinceRepository.findOneBy({
id: profiles?.registrationProvinceId,
const profileOc = await this.profileRepo.findOne({
relations: [
"current_holders",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { id: id },
});
const district = await this.districtRepository.findOneBy({
id: profiles?.registrationDistrictId,
});
if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
@ -249,21 +254,40 @@ export class ProfileController extends Controller {
select: ["fatherPrefix", "fatherFirstName", "fatherLastName"],
});
// Extract relevant data
const root =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgRoot ?? null;
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot;
const child1 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild1 ??
null;
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1;
const child2 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild2 ??
null;
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2;
const child3 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild3 ??
null;
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3;
const child4 =
profiles?.current_holders?.find((x) => x.orgRevisionId === orgRevision?.id)?.orgChild4 ??
null;
profileOc.current_holders == null ||
profileOc.current_holders.length == 0 ||
profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profileOc.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4;
// Construct org path
const _root = root ? `${root.orgRootName}` : "";
@ -279,14 +303,20 @@ export class ProfileController extends Controller {
LastName: profiles?.lastName != null ? profiles.lastName : "",
FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`,
BirthDay: profiles?.birthDate ? new Date(profiles.birthDate).getDate() : null,
BirthDayText: "ห้า",
BirthDayText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profiles.birthDate))
: "",
BirthMonth: profiles?.birthDate ? new Date(profiles.birthDate).getMonth() + 1 : null, // Months are zero-based
BirthYear: profiles?.birthDate ? new Date(profiles.birthDate).getFullYear() : null,
BirthYearText: "สองพันห้าร้อยสามสิบสี่",
Address: profiles?.currentAddress,
District: district?.name ?? null,
BirthYearText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profiles.birthDate))
: "",
Address: "",
District: "",
Area: "",
Province: province?.name ?? null,
Province: "",
Telephone: profiles?.telephoneNumber ?? null,
CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
CouplePrefix: profileFamilyCouple?.couplePrefix ?? null,
@ -315,7 +345,7 @@ export class ProfileController extends Controller {
Institute: "",
StartDate: profiles?.dateStart,
AppointDate: profiles?.dateAppoint,
BirthDate: profiles?.birthDate,
BirthDate: profiles?.birthDate ? Extension.ToThaiShortDate(profiles.birthDate) : null,
RetireDate: profiles?.dateRetireLaw,
AvatarId: profiles?.avatar ?? null,
};