sort step and fix return report kp7 , kk1 and kk1-emp

This commit is contained in:
AdisakKanthawilang 2024-11-04 12:15:16 +07:00
parent af38addf46
commit e3bcb0c52c
3 changed files with 171 additions and 180 deletions

View file

@ -1388,6 +1388,11 @@ export class CommandController extends Controller {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandSigns"],
order: {
commandSigns:{
createdAt: "ASC"
}
},
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");

View file

@ -237,54 +237,59 @@ export class ProfileController extends Controller {
order: { lastUpdatedAt: "DESC" },
});
const Education = educations.map((item) => ({
Institute: item.institute ? item.institute : "-",
Date:
institute: item.institute ? item.institute : "-",
date:
item.startDate && item.endDate
? `${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate))} - ${Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate))}`
: "-",
Degree: item.degree && item.field ? `${item.degree} ${item.field}` : "-",
degree: item.degree && item.field ? `${item.degree} ${item.field}` : "-",
}));
const mapData = {
Id: profile.id,
CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "-",
Prefix: profile.prefix != null ? profile.prefix : null,
FirstName: profile.firstName != null ? profile.firstName : null,
LastName: profile.lastName != null ? profile.lastName : null,
DateOfBirth:
// Id: profile.id,
fullName: `${profile?.prefix}${profile?.firstName} ${profile?.lastName}`,
prefix: profile.prefix != null ? profile.prefix : null,
firstName: profile.firstName != null ? profile.firstName : null,
lastName: profile.lastName != null ? profile.lastName : null,
citizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "-",
dateOfBirth:
profile.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.birthDate))
: "-",
DateRetire:
dateRetire:
profile.dateRetire != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateRetire))
: "-",
RegistrationAddress: Extension.ToThaiNumber(
`${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
),
SalaryAmount:
salaryAmount:
profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null
? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString())
: "-",
Education: Education,
AppointText:
profile.dateAppoint != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateAppoint))
: "-",
SalaryDate:
registrationAddress: Extension.ToThaiNumber(
`${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
),
salaryDate:
profile.profileSalary.length > 0 && profile.profileSalary[0].date != null
? Extension.ToThaiNumber(
Extension.ToThaiShortDate_monthYear(profile.profileSalary[0].date),
)
: "-",
PositionName: profile.position != null ? profile.position : "-",
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
ImgUrl: ImgUrl
positionName: profile.position != null ? profile.position : "-",
appointText:
profile.dateAppoint != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateAppoint))
: "-",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
educations: Education,
url: ImgUrl
? ImgUrl
: `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
};
return new HttpSuccess(mapData);
return new HttpSuccess({
template: "kp7",
reportName: "docx-report",
data: mapData,
});
}
/**

View file

@ -238,46 +238,51 @@ export class ProfileEmployeeController extends Controller {
}));
const mapData = {
Id: profile.id,
CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "-",
Prefix: profile.prefix != null ? profile.prefix : null,
FirstName: profile.firstName != null ? profile.firstName : null,
LastName: profile.lastName != null ? profile.lastName : null,
DateOfBirth:
// Id: profile.id,
fullName: `${profile?.prefix}${profile?.firstName} ${profile?.lastName}`,
prefix: profile.prefix != null ? profile.prefix : null,
firstName: profile.firstName != null ? profile.firstName : null,
lastName: profile.lastName != null ? profile.lastName : null,
citizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "-",
dateOfBirth:
profile.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.birthDate))
: "-",
DateRetire:
dateRetire:
profile.dateRetire != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateRetire))
: "-",
RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
SalaryAmount:
salaryAmount:
profile.profileSalarys.length > 0 && profile.profileSalarys[0].amount != null
? Extension.ToThaiNumber(profile.profileSalarys[0].amount.toLocaleString())
: "-",
Education: Education,
// profile.profileEducations.length > 0 &&
// profile.profileEducations[profile.profileEducations.length - 1].institute != null
// ? profile.profileEducations[profile.profileEducations.length - 1].institute
// : "",
AppointText:
profile.dateAppoint != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateAppoint))
: "-",
SalaryDate:
registrationAddress: Extension.ToThaiNumber(
`${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`,
),
salaryDate:
profile.profileSalarys.length > 0 && profile.profileSalarys[0].date != null
? Extension.ToThaiNumber(
Extension.ToThaiShortDate_monthYear(profile.profileSalarys[0].date),
)
: "-",
PositionName: profile.position != null ? profile.position : "-",
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
ImgUrl: ImgUrl
positionName: profile.position != null ? profile.position : "-",
appointText:
profile.dateAppoint != null
? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile.dateAppoint))
: "-",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
educations: Education,
url: ImgUrl
? ImgUrl
: `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
};
return new HttpSuccess({
template: "kp7",
reportName: "docx-report",
data: mapData,
});
return new HttpSuccess(mapData);
}
@ -435,108 +440,14 @@ export class ProfileEmployeeController extends Controller {
const _child3 = child3 ? `${child3.orgChild3Name}/` : "";
const _child4 = child4 ? `${child4.orgChild4Name}/` : "";
const Profile = {
CitizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
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
? Extension.ToThaiNumber(new Date(profiles.birthDate).getDate().toString())
: null,
BirthDayText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString())
: "",
BirthMonth: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getMonth() + (1).toString())
: null, // Months are zero-based
BirthYear: profiles?.birthDate
? Extension.ToThaiNumber(new Date(profiles.birthDate).getFullYear().toString())
: null,
BirthYearText:
profiles.birthDate != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate).toString())
: "",
Address: "",
District: "",
Area: "",
Province: "",
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()
: null,
FatherPrefix: profileFamilyFather?.fatherPrefix ?? "",
FatherFullName:
profileFamilyFather?.fatherPrefix ||
profileFamilyFather?.fatherFirstName ||
profileFamilyFather?.fatherLastName
? `${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()
: null,
OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
Division: "",
Institute: "",
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))
: "",
RetireDate:
profiles.dateRetireLaw != null
? Extension.ToThaiNumber(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,
ImgUrl: ImgUrl
? ImgUrl
: `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
ImgUrl1: _ImgUrl[0] ? _ImgUrl[0] : null,
ImgUrl2: _ImgUrl[1] ? _ImgUrl[1] : null,
ImgUrl3: _ImgUrl[2] ? _ImgUrl[2] : null,
ImgUrl4: _ImgUrl[3] ? _ImgUrl[3] : null,
ImgUrl5: _ImgUrl[4] ? _ImgUrl[4] : null,
ImgUrl6: _ImgUrl[5] ? _ImgUrl[5] : null,
ImgUrl7: _ImgUrl[6] ? _ImgUrl[6] : null,
};
const certs = await this.certificateRepository.find({
const cert_raw = await this.certificateRepository.find({
where: { profileEmployeeId: id },
select: ["certificateType", "issuer", "certificateNo", "issueDate"],
order: { createdAt: "ASC" },
});
const Cert =
certs.length > 0
? certs.map((item) => ({
const certs =
cert_raw.length > 0
? cert_raw.slice(-2).map((item) => ({
CertificateType: item.certificateType ?? null,
Issuer: item.issuer ?? null,
CertificateNo: Extension.ToThaiNumber(item.certificateNo) ?? null,
@ -550,13 +461,14 @@ export class ProfileEmployeeController extends Controller {
IssueDate: "-",
},
];
const trainings = await this.trainingRepository.find({
const training_raw = await this.trainingRepository.find({
select: ["startDate", "endDate", "place", "department"],
where: { profileEmployeeId: id },
order: { createdAt: "ASC" },
});
const Training =
trainings.length > 0
? trainings.map((item) => ({
const trainings =
training_raw.length > 0
? training_raw.slice(-2).map((item) => ({
Institute: item.department ?? "",
Start:
item.startDate == null
@ -586,13 +498,14 @@ export class ProfileEmployeeController extends Controller {
},
];
const disciplines = await this.disciplineRepository.find({
const discipline_raw = await this.disciplineRepository.find({
select: ["refCommandDate", "refCommandNo", "detail"],
where: { profileEmployeeId: id },
order: { createdAt: "ASC" },
});
const Discipline =
disciplines.length > 0
? disciplines.map((item) => ({
const disciplines =
discipline_raw.length > 0
? discipline_raw.slice(-2).map((item) => ({
DisciplineYear:
Extension.ToThaiNumber(new Date(item.refCommandDate).getFullYear().toString()) ??
null,
@ -607,14 +520,15 @@ export class ProfileEmployeeController extends Controller {
},
];
const educations = await this.educationRepository.find({
const education_raw = await this.educationRepository.find({
select: ["startDate", "endDate", "educationLevel", "degree", "field", "institute"],
where: { profileEmployeeId: id },
order: { lastUpdatedAt: "DESC" },
// order: { lastUpdatedAt: "DESC" },
order: { createdAt: "ASC" },
});
const Education =
educations.length > 0
? educations.map((item) => ({
const educations =
education_raw.length > 0
? education_raw.slice(-2).map((item) => ({
Institute: item.institute,
Start:
item.startDate == null
@ -643,7 +557,7 @@ export class ProfileEmployeeController extends Controller {
Field: "-",
},
];
const salarys = await this.salaryRepository.find({
const salary_raw = await this.salaryRepository.find({
select: [
"date",
"position",
@ -659,9 +573,9 @@ export class ProfileEmployeeController extends Controller {
order: { order: "ASC" },
});
const Salary =
salarys.length > 0
? salarys.map((item) => ({
const salarys =
salary_raw.length > 0
? salary_raw.map((item) => ({
SalaryDate: item.date
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date))
: null,
@ -697,7 +611,7 @@ export class ProfileEmployeeController extends Controller {
},
];
const insignias = await this.profileInsigniaRepo.find({
const insignia_raw = await this.profileInsigniaRepo.find({
relations: {
insignia: {
insigniaType: true,
@ -706,9 +620,9 @@ export class ProfileEmployeeController extends Controller {
where: { profileEmployeeId: id },
order: { receiveDate: "ASC" },
});
const Insignia =
insignias.length > 0
? insignias.map((item) => ({
const insignias =
insignia_raw.length > 0
? insignia_raw.map((item) => ({
ReceiveDate: item.receiveDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.receiveDate))
: "",
@ -741,14 +655,14 @@ export class ProfileEmployeeController extends Controller {
},
];
const leaves = await this.profileLeaveRepository.find({
const leave_raw = await this.profileLeaveRepository.find({
relations: { leaveType: true },
where: { profileEmployeeId: id },
order: { dateLeaveStart: "ASC" },
});
const Leave =
leaves.length > 0
? leaves.map((item) => ({
const leaves =
leave_raw.length > 0
? leave_raw.map((item) => ({
LeaveTypeName: item.leaveType.name,
DateLeaveStart: item.dateLeaveStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateLeaveStart))
@ -763,16 +677,83 @@ export class ProfileEmployeeController extends Controller {
},
];
return new HttpSuccess({
Profile: [Profile],
Cert,
Training,
Discipline,
Education,
Salary,
Insignia,
Leave,
});
const data = {
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
prefix: profiles?.prefix != null ? profiles.prefix : "",
firstName: profiles?.firstName != null ? profiles.firstName : "",
lastName: profiles?.lastName != null ? profiles.lastName : "",
ocFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`,
birthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: "",
retireDate:
profiles.dateRetireLaw != null
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateRetireLaw))
: "",
appointDate: profiles?.dateAppoint
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.dateAppoint))
: "",
citizenId:
profiles.citizenId != null ? Extension.ToThaiNumber(profiles.citizenId.toString()) : "",
fatherFullName:
profileFamilyFather?.fatherPrefix ||
profileFamilyFather?.fatherFirstName ||
profileFamilyFather?.fatherLastName
? `${profileFamilyFather?.fatherPrefix ?? ""}${profileFamilyFather?.fatherFirstName ?? ""} ${profileFamilyFather?.fatherLastName ?? ""}`.trim()
: null,
motherFullName:
profileFamilyMother?.motherPrefix ||
profileFamilyMother?.motherFirstName ||
profileFamilyMother?.motherLastName
? `${profileFamilyMother?.motherPrefix ?? ""}${profileFamilyMother?.motherFirstName ?? ""} ${profileFamilyMother?.motherLastName ?? ""}`.trim()
: null,
coupleFullName:
profileFamilyCouple?.couplePrefix ||
profileFamilyCouple?.coupleFirstName ||
profileFamilyCouple?.coupleLastNameOld
? `${profileFamilyCouple?.couplePrefix ?? ""}${profileFamilyCouple?.coupleFirstName ?? ""} ${profileFamilyCouple?.coupleLastName ?? ""}`.trim()
: null,
coupleLastNameOld: profileFamilyCouple?.coupleLastNameOld ?? null,
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)
: "",
telephone:
profiles.telephoneNumber != null ? Extension.ToThaiNumber(profiles.telephoneNumber) : "",
url: ImgUrl
? ImgUrl
: `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`,
url1: _ImgUrl[0] ? _ImgUrl[0] : null,
url2: _ImgUrl[1] ? _ImgUrl[1] : null,
url3: _ImgUrl[2] ? _ImgUrl[2] : null,
url4: _ImgUrl[3] ? _ImgUrl[3] : null,
url5: _ImgUrl[4] ? _ImgUrl[4] : null,
url6: _ImgUrl[5] ? _ImgUrl[5] : null,
url7: _ImgUrl[6] ? _ImgUrl[6] : null,
insignias,
leaves,
certs,
trainings,
disciplines,
educations,
salarys,
};
return new HttpSuccess({
template: "kk1-emp",
reportName: "docx-report",
data: data,
});
}
/**