ปรับ report k1

This commit is contained in:
Bright 2024-07-12 14:04:00 +07:00
parent dd680e91f8
commit 99b45e4392
2 changed files with 155 additions and 75 deletions

View file

@ -235,6 +235,13 @@ export class ProfileController extends Controller {
return new HttpSuccess(mapData);
}
/**
* ..1 ()
*
* @summary ..1 ()
*
* @param {string} id Id
*/
@Get("kk1/{id}")
public async getKk1(@Path() id: string) {
const profiles = await this.profileRepo.findOne({
@ -385,11 +392,15 @@ export class ProfileController extends Controller {
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
Division: "",
Institute: "",
StartDate: profiles?.dateStart,
AppointDate: profiles?.dateAppoint ?? "",
StartDate: profiles?.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateStart))
: "",
AppointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "",
BirthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: null,
: "",
RetireDate:
profiles.dateRetireLaw != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw))
@ -496,7 +507,7 @@ export class ProfileController extends Controller {
Position: item.position != null ? Extension.ToThaiNumber(item.position) : null,
PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null,
Salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
Rank: item.positionLevel ?? null,
Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null,
PositionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
PositionType: item.positionType ?? null,

View file

@ -61,6 +61,8 @@ import { ProfileEmployeeEmploymentHistory } from "../entities/ProfileEmployeeEmp
import CallAPI from "../interfaces/call-api";
import e from "cors";
import { EmployeePosition } from "../entities/EmployeePosition";
import { ProfileInsignia } from "../entities/ProfileInsignia";
import { ProfileLeave } from "../entities/ProfileLeave";
@Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee")
@ -102,7 +104,8 @@ export class ProfileEmployeeController extends Controller {
ProfileEmployeeEmploymentHistory,
);
private profileEducationRepository = AppDataSource.getRepository(ProfileEducation);
private profileInsigniaRepo = AppDataSource.getRepository(ProfileInsignia);
private profileLeaveRepository = AppDataSource.getRepository(ProfileLeave);
/**
* report
*
@ -227,25 +230,28 @@ export class ProfileEmployeeController extends Controller {
}
/**
* report
* @param id Id
* @returns
* ..1 ()
*
* @summary ..1 ()
*
* @param {string} id Id
*/
@Get("kk1/{id}")
public async getKk1Employee(@Path() id: string) {
const profiles = await this.profileRepo.findOne({
select: [
"citizenId",
"prefix",
"firstName",
"lastName",
"birthDate",
"currentAddress",
"currentDistrictId",
"currentProvinceId",
"telephoneNumber",
"avatar",
],
// select: [
// "citizenId",
// "prefix",
// "firstName",
// "lastName",
// "birthDate",
// "currentAddress",
// "currentDistrictId",
// "currentProvinceId",
// "telephoneNumber",
// "avatar",
// ],
relations: ["currentSubDistrict", "currentDistrict", "currentProvince"],
where: { id: id },
});
const profileOc = await this.profileRepo.findOne({
@ -262,34 +268,26 @@ export class ProfileEmployeeController extends Controller {
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: { profileEmployeeId: id },
select: ["couplePrefix", "coupleFirstName", "coupleLastNameOld"],
select: ["couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld"],
order: { lastUpdatedAt: "DESC" },
});
const profileFamilyMother = await this.profileFamilyMotherRepository.findOne({
where: { profileEmployeeId: id },
select: ["motherPrefix", "motherFirstName", "motherLastName"],
order: { lastUpdatedAt: "DESC" },
});
const profileFamilyFather = await this.profileFamilyFatherRepository.findOne({
where: { profileEmployeeId: id },
select: ["fatherPrefix", "fatherFirstName", "fatherLastName"],
order: { lastUpdatedAt: "DESC" },
});
const root =
@ -327,17 +325,6 @@ export class ProfileEmployeeController extends Controller {
? 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}/` : "";
@ -351,13 +338,13 @@ export class ProfileEmployeeController extends Controller {
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}`,
FullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
BirthDay: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getDate().toString())
: null,
BirthDayText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate(profiles.birthDate).toString())
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString())
: "",
BirthMonth: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getMonth() + (1).toString())
@ -367,46 +354,65 @@ export class ProfileEmployeeController extends Controller {
: null,
BirthYearText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate(profiles.birthDate).toString())
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString())
: "",
Address: "",
District: "",
Area: "",
Province: "",
Telephone: profiles?.telephoneNumber ?? null,
Telephone:
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
CoupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
CouplePrefix: profileFamilyCouple?.couplePrefix ?? "",
CoupleFullName:
profileFamilyCouple?.couplePrefix ||
profileFamilyCouple?.coupleFirstName ||
profileFamilyCouple?.coupleLastNameOld
? `${profileFamilyCouple?.couplePrefix ?? ""} ${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastNameOld ?? ""}`.trim()
? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastNameOld ?? ""}`.trim()
: null,
FatherPrefix: profileFamilyFather?.fatherPrefix ?? "",
FatherFullName:
profileFamilyFather?.fatherPrefix ||
profileFamilyFather?.fatherFirstName ||
profileFamilyFather?.fatherLastName
? `${profileFamilyFather?.fatherPrefix ?? ""} ${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
: null,
MotherPrefix: profileFamilyMother?.motherPrefix ?? "",
MotherFullName:
profileFamilyMother?.motherPrefix ||
profileFamilyMother?.motherFirstName ||
profileFamilyMother?.motherLastName
? `${profileFamilyMother?.motherPrefix ?? ""} ${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
? `${profileFamilyMother?.motherPrefix ?? ""}${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
: null,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
Division: "",
Institute: "",
StartDate: profiles?.dateStart,
AppointDate: profiles?.dateAppoint ?? "",
StartDate: profiles?.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateStart))
: "",
AppointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "",
BirthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiShortDate(profiles.birthDate))
: null,
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: "",
RetireDate:
profiles.dateRetireLaw != null
? Extension.ToThaiNumber(profiles.dateRetireLaw.toString())
? Extension.ToThaiFullDate2(profiles.dateRetireLaw)
: "",
CurrentAddress:
profiles.currentAddress != null ? Extension.ToThaiNumber(profiles.currentAddress) : "",
CurrentSubDistrict:
profiles.currentSubDistrict != null
? Extension.ToThaiNumber(profiles.currentSubDistrict.name)
: "",
CurrentDistrict:
profiles.currentDistrict != null
? Extension.ToThaiNumber(profiles.currentDistrict.name)
: "",
CurrentProvince:
profiles.currentProvince != null
? Extension.ToThaiNumber(profiles.currentProvince.name)
: "",
// AvatarId: profiles?.avatar ?? null,
};
@ -418,8 +424,8 @@ export class ProfileEmployeeController extends Controller {
const Cert = certs.map((item) => ({
CertificateType: item.certificateType ?? null,
Issuer: item.issuer ?? null,
CertificateNo: item.certificateNo ?? null,
IssueDate: Extension.ToThaiShortDate(item.issueDate) ?? null,
CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null,
IssueDate: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) ?? null,
}));
const trainings = await this.trainingRepository.find({
select: ["startDate", "endDate", "place", "department"],
@ -430,14 +436,14 @@ export class ProfileEmployeeController extends Controller {
Start:
item.startDate == null
? ""
: Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()),
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)),
End:
item.endDate == null
? ""
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)),
Date:
item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}`
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
: "",
Level: "",
Degree: item.name,
@ -449,24 +455,32 @@ export class ProfileEmployeeController extends Controller {
where: { profileEmployeeId: id },
});
const Discipline = disciplines.map((item) => ({
DisciplineYear: new Date(item.refCommandDate).getFullYear().toString() ?? null,
DisciplineYear:
Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ?? null,
DisciplineDetail: item.detail ?? null,
RefNo: item.refCommandNo ?? null,
RefNo: Extension.ToThaiNumber(item.refCommandNo) ?? null,
}));
const educations = await this.educationRepository.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileEmployeeId: id },
order: { lastUpdatedAt: "DESC" },
});
const Education = educations.map((item) => ({
Institute: item.institute ?? null,
Start: new Date(item.startDate).getFullYear().toString() ?? null,
End: new Date(item.endDate).getFullYear().toString() ?? null,
Start:
item.startDate == null
? ""
: Extension.ToThaiNumber(new Date(item.startDate).getFullYear().toString()),
End:
item.endDate == null
? ""
: Extension.ToThaiNumber(new Date(item.endDate).getFullYear().toString()),
Date:
item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))}`
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
: "",
Level: item.educationLevel ?? null,
Level: item.educationLevel ?? "",
Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "",
Field: item.field ?? "-",
}));
@ -479,24 +493,79 @@ export class ProfileEmployeeController extends Controller {
"positionLevel",
"positionSalaryAmount",
"refCommandNo",
"amount",
"templateDoc",
],
where: { profileEmployeeId: id },
});
const Salary = salarys.map((item) => ({
SalaryDate: item.date ? Extension.ToThaiShortDate(item.date) : null,
Position: item.position ?? null,
PosNo: item.posNo ?? null,
Salary: "",
Rank: item.positionLevel ?? null,
RefAll: item.refCommandNo ?? null,
SalaryDate: item.date ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) : null,
Position: item.position != null ? Extension.ToThaiNumber(item.position) : null,
PosNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null,
Salary: item.amount != null ? Extension.ToThaiNumber(item.amount.toLocaleString()) : null,
Rank: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
RefAll: item.templateDoc ? Extension.ToThaiNumber(item.templateDoc) : null,
PositionType: item.positionType ?? null,
PositionLevel: item.positionLevel ?? null,
PositionAmount: item.positionSalaryAmount ?? null,
PositionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null,
PositionAmount:
item.positionSalaryAmount == null
? null
: Extension.ToThaiNumber(item.positionSalaryAmount.toLocaleString()),
FullName: `${profiles?.prefix} ${profiles?.firstName} ${profiles?.lastName}`,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
}));
return new HttpSuccess({ Profile: [Profile], Cert, Training, Discipline, Education, Salary });
const insignias = await this.profileInsigniaRepo.find({
relations: {
insignia: {
insigniaType: true,
},
},
where: { profileEmployeeId: id },
order: { receiveDate: "ASC" },
});
const Insignia = insignias.map((item) => ({
ReceiveDate: item.receiveDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate))
: "",
InsigniaName: item.insignia.name,
InsigniaShortName: item.insignia.shortName,
InsigniaTypeName: item.insignia.insigniaType.name,
No: item.no ? Extension.ToThaiNumber(item.no) : "",
Issue: item.issue ? item.issue : "",
VolumeNo: item.volumeNo ? Extension.ToThaiNumber(item.volumeNo) : "",
Volume: item.volume ? Extension.ToThaiNumber(item.volume) : "",
Section: item.section ? Extension.ToThaiNumber(item.section) : "",
Page: item.page ? Extension.ToThaiNumber(item.page) : "",
RefCommandDate: item.refCommandDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate))
: "",
}));
const leaves = await this.profileLeaveRepository.find({
relations: { leaveType: true },
where: { profileEmployeeId: id },
order: { dateLeaveStart: "ASC" },
});
const Leave = leaves.map((item) => ({
LeaveTypeName: item.leaveType.name,
DateLeaveStart: item.dateLeaveStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart))
: "",
LeaveDays: item.leaveDays ? Extension.ToThaiNumber(item.leaveDays.toString()) : "",
}));
return new HttpSuccess({
Profile: [Profile],
Cert,
Training,
Discipline,
Education,
Salary,
Insignia,
Leave,
});
}
/**