เพิ่ม report kk1 employee
This commit is contained in:
parent
a242f7bbdd
commit
ee030a0e2d
2 changed files with 315 additions and 23 deletions
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,6 +35,14 @@ import { Position } from "../entities/Position";
|
|||
import { Province } from "../entities/Province";
|
||||
import { District } from "../entities/District";
|
||||
import { SubDistrict } from "../entities/SubDistrict";
|
||||
import { ProfileCertificate } from "../entities/ProfileCertificate";
|
||||
import { ProfileTraining } from "../entities/ProfileTraining";
|
||||
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
|
||||
import { ProfileEducation } from "../entities/ProfileEducation";
|
||||
import { ProfileSalary } from "../entities/ProfileSalary";
|
||||
import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
|
||||
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
|
||||
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
|
||||
import Extension from "../interfaces/extension";
|
||||
|
||||
@Route("api/v1/org/profile-employee")
|
||||
|
|
@ -55,6 +63,14 @@ export class ProfileEmployeeController extends Controller {
|
|||
private provinceRepository = AppDataSource.getRepository(Province);
|
||||
private districtRepository = AppDataSource.getRepository(District);
|
||||
private subDistrict = AppDataSource.getRepository(SubDistrict);
|
||||
private certificateRepository = AppDataSource.getRepository(ProfileCertificate);
|
||||
private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple);
|
||||
private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother);
|
||||
private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather);
|
||||
private trainingRepository = AppDataSource.getRepository(ProfileTraining);
|
||||
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
|
||||
private educationRepository = AppDataSource.getRepository(ProfileEducation);
|
||||
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
|
||||
|
||||
/**
|
||||
* report ประวัติแบบย่อ ลูกจ้าง
|
||||
|
|
@ -179,6 +195,252 @@ export class ProfileEmployeeController extends Controller {
|
|||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
/**
|
||||
* report
|
||||
* @param id Id โปรไฟล์
|
||||
* @returns
|
||||
*/
|
||||
@Get("kk1/{id}")
|
||||
public async getKk1(@Path() id: string) {
|
||||
const profiles = await this.profileRepo.findOne({
|
||||
select: [
|
||||
"citizenId",
|
||||
"prefix",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"birthDate",
|
||||
"currentAddress",
|
||||
"currentDistrictId",
|
||||
"currentProvinceId",
|
||||
"telephoneNumber",
|
||||
"avatar",
|
||||
],
|
||||
where: { id: id },
|
||||
});
|
||||
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 },
|
||||
});
|
||||
if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
// const province = await this.provinceRepository.findOneBy({
|
||||
// id: profileOc?.registrationProvinceId,
|
||||
// });
|
||||
// const district = await this.districtRepository.findOneBy({
|
||||
// id: profileOc?.registrationDistrictId,
|
||||
// });
|
||||
|
||||
// const subDistrict = await this.subDistrict.findOneBy({
|
||||
// id: profileOc.registrationSubDistrictId,
|
||||
// });
|
||||
|
||||
const orgRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
|
||||
const profileFamilyCouple = await this.profileFamilyCoupleRepository.findOne({
|
||||
where: { id },
|
||||
select: ["couplePrefix", "coupleFirstName", "coupleLastNameOld"],
|
||||
});
|
||||
|
||||
const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({
|
||||
where: { id },
|
||||
select: ["motherPrefix", "motherFirstName", "motherLastName"],
|
||||
});
|
||||
|
||||
const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({
|
||||
where: { id },
|
||||
select: ["fatherPrefix", "fatherFirstName", "fatherLastName"],
|
||||
});
|
||||
|
||||
const root =
|
||||
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 =
|
||||
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 =
|
||||
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 =
|
||||
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 =
|
||||
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;
|
||||
|
||||
// let _regisAddres =
|
||||
// profileOc && profileOc.registrationAddress != null ? profileOc.registrationAddress : "";
|
||||
// let _subDistrict =
|
||||
// subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : "";
|
||||
// let _district = district && district.name != null ? `\r\nเขต/อำเภอ ${district?.name}` : "";
|
||||
// let _province = province && province.name != null ? `\r\nจังหวัด ${province?.name}` : "";
|
||||
// let registrationZipCode =
|
||||
// profileOc && profileOc.registrationZipCode != null
|
||||
// ? ` รหัสไปรษณีย์ ${profileOc.registrationZipCode}`
|
||||
// : "";
|
||||
|
||||
// Construct org path
|
||||
const _root = root ? `${root.orgRootName}` : "";
|
||||
const _child1 = child1 ? `${child1.orgChild1Name}/` : "";
|
||||
const _child2 = child2 ? `${child2.orgChild2Name}/` : "";
|
||||
const _child3 = child3 ? `${child3.orgChild3Name}/` : "";
|
||||
const _child4 = child4 ? `${child4.orgChild4Name}/` : "";
|
||||
|
||||
const profile = {
|
||||
CitizenId: profiles?.citizenId ?? null,
|
||||
Prefix: profiles?.prefix != null ? profiles.prefix : "",
|
||||
FirstName: profiles?.firstName != null ? profiles.firstName : "",
|
||||
LastName: profiles?.lastName != null ? profiles.lastName : "",
|
||||
FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`,
|
||||
BirthDay: profiles?.birthDate ? new Date(profiles.birthDate).getDate() : null,
|
||||
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:
|
||||
profiles.birthDate != null
|
||||
? Extension.ToThaiNumber(Extension.ToThaiFullDate(profiles.birthDate))
|
||||
: "",
|
||||
Address: "",
|
||||
District: "",
|
||||
Area: "",
|
||||
Province: "",
|
||||
Telephone: profiles?.telephoneNumber ?? null,
|
||||
CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
|
||||
CouplePrefix: profileFamilyCouple?.couplePrefix ?? null,
|
||||
CoupleFullName:
|
||||
profileFamilyCouple?.couplePrefix ||
|
||||
profileFamilyCouple?.coupleFirstName ||
|
||||
profileFamilyCouple?.coupleLastNameOld
|
||||
? `${profileFamilyCouple?.couplePrefix ?? ""} ${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastNameOld ?? ""}`.trim()
|
||||
: null,
|
||||
FatherPrefix: profileFamilyFather?.fatherPrefix ?? null,
|
||||
FatherFullName:
|
||||
profileFamilyFather?.fatherPrefix ||
|
||||
profileFamilyFather?.fatherFirstName ||
|
||||
profileFamilyFather?.fatherLastName
|
||||
? `${profileFamilyFather?.fatherPrefix ?? ""} ${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
|
||||
: null,
|
||||
MotherPrefix: profileFamilyMother?.motherPrefix ?? null,
|
||||
MotherFullName:
|
||||
profileFamilyMother?.motherPrefix ||
|
||||
profileFamilyMother?.motherFirstName ||
|
||||
profileFamilyMother?.motherLastName
|
||||
? `${profileFamilyMother?.motherPrefix ?? ""} ${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
|
||||
: null,
|
||||
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
||||
Division: "",
|
||||
Institute: "",
|
||||
StartDate: profiles?.dateStart,
|
||||
AppointDate: profiles?.dateAppoint,
|
||||
BirthDate: profiles?.birthDate ? Extension.ToThaiShortDate(profiles.birthDate) : null,
|
||||
RetireDate: profiles?.dateRetireLaw,
|
||||
AvatarId: profiles?.avatar ?? null,
|
||||
};
|
||||
|
||||
const certs = await this.certificateRepository.find({
|
||||
where: { profileEmployeeId: id },
|
||||
select: ["certificateType", "issuer", "certificateNo", "issueDate"],
|
||||
});
|
||||
const cert = certs.map((item) => ({
|
||||
CertificateType: item.certificateType ?? null,
|
||||
Issuer: item.issuer ?? null,
|
||||
CertificateNo: item.certificateNo ?? null,
|
||||
IssueDate: item.issueDate ?? null,
|
||||
}));
|
||||
const trainings = await this.trainingRepository.find({
|
||||
select: ["startDate", "endDate", "place", "department"],
|
||||
where: { profileEmployeeId: id },
|
||||
});
|
||||
const training = trainings.map((item) => ({
|
||||
institute: item.department ?? null,
|
||||
start: item.startDate ?? null,
|
||||
end: item.endDate ?? null,
|
||||
level: "",
|
||||
degree: "",
|
||||
field: item.place ?? null,
|
||||
}));
|
||||
|
||||
const disciplines = await this.disciplineRepository.find({
|
||||
select: ["refCommandDate", "refCommandNo", "detail"],
|
||||
where: { profileEmployeeId: id },
|
||||
});
|
||||
const discipline = disciplines.map((item) => ({
|
||||
DisciplineYear: item.refCommandDate ?? null,
|
||||
DisciplineDetail: item.detail ?? null,
|
||||
RefNo: item.refCommandNo ?? null,
|
||||
}));
|
||||
|
||||
const educations = await this.educationRepository.find({
|
||||
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
|
||||
where: { profileEmployeeId: id },
|
||||
});
|
||||
const education = educations.map((item) => ({
|
||||
Institute: item.institute ?? null,
|
||||
Start: item.startDate ?? null,
|
||||
End: item.endDate ?? null,
|
||||
Level: item.educationLevel ?? null,
|
||||
Degree: item.degree ?? null,
|
||||
Field: item.field ?? null,
|
||||
}));
|
||||
const salarys = await this.salaryRepository.find({
|
||||
select: [
|
||||
"date",
|
||||
"position",
|
||||
"posNo",
|
||||
"positionType",
|
||||
"positionLevel",
|
||||
"positionSalaryAmount",
|
||||
"refCommandNo",
|
||||
],
|
||||
where: { profileEmployeeId: id },
|
||||
});
|
||||
|
||||
const salary = salarys.map((item) => ({
|
||||
SalaryDate: item.date ?? null,
|
||||
Position: item.position ?? null,
|
||||
PosNo: item.posNo ?? null,
|
||||
Salary: "",
|
||||
RefAll: item.refCommandNo ?? null,
|
||||
PositionType: item.positionType ?? null,
|
||||
PositionLevel: item.positionLevel ?? null,
|
||||
PositionAmount: item.positionSalaryAmount ?? null,
|
||||
FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`,
|
||||
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
|
||||
}));
|
||||
return new HttpSuccess({ profile, cert, training, discipline, education, salary });
|
||||
}
|
||||
|
||||
/**
|
||||
* API สร้างทะเบียนประวัติ
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue