filter case call leave server error #2304 & เพิ่มตัวเลือกการครอง-ไม่ครองตำแหน่ง #2311

This commit is contained in:
harid 2026-02-19 09:32:17 +07:00
parent 9382482f06
commit c8ed816a1f
2 changed files with 32 additions and 125 deletions

View file

@ -5821,7 +5821,6 @@ export class CommandController extends Controller {
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
relations: [
// "profileSalary",
"posType",
"posLevel",
"current_holders",
@ -5832,11 +5831,6 @@ export class CommandController extends Controller {
"current_holders.orgChild4",
],
where: { id: item.profileId },
// order: {
// profileSalary: {
// order: "DESC",
// },
// },
});
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
@ -5848,46 +5842,19 @@ export class CommandController extends Controller {
});
const nextOrder = lastSalary ? lastSalary.order + 1 : 1;
const orgRevision = await this.orgRevisionRepo.findOne({
where: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
const orgRevisionRef =
profile?.current_holders?.find((x) => x.orgRevisionId == orgRevision?.id) ?? null;
const orgRootRef = orgRevisionRef?.orgRoot ?? null;
const orgChild1Ref = orgRevisionRef?.orgChild1 ?? null;
const orgChild2Ref = orgRevisionRef?.orgChild2 ?? null;
const orgChild3Ref = orgRevisionRef?.orgChild3 ?? null;
const orgChild4Ref = orgRevisionRef?.orgChild4 ?? null;
const shortName =
!profile.current_holders || profile.current_holders.length == 0
? null
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild4 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4.orgChild4ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild3 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild3.orgChild3ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) != null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild2 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild2.orgChild2ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgChild1 != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild1.orgChild1ShortName}`
: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) !=
null &&
profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)
?.orgRoot != null
? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}`
: null;
const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`;
orgRevisionRef?.orgChild4?.orgChild4ShortName ??
orgRevisionRef?.orgChild3?.orgChild3ShortName ??
orgRevisionRef?.orgChild2?.orgChild2ShortName ??
orgRevisionRef?.orgChild1?.orgChild1ShortName ??
orgRevisionRef?.orgRoot?.orgRootShortName ??
null;
const posNo = orgRevisionRef?.posMasterNo?.toString() ?? null;
let position =
profile.current_holders
.filter((x) => x.orgRevisionId == orgRevision?.id)[0]
@ -5907,18 +5874,12 @@ export class CommandController extends Controller {
amountSpecial: item.amountSpecial ? item.amountSpecial : null,
positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null,
mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null,
// order:
// profile.profileSalary.length >= 0
// ? profile.profileSalary.length > 0
// ? profile.profileSalary[0].order + 1
// : 1
// : null,
order: nextOrder,
orgRoot: orgRootRef?.orgRootName ?? null,
orgChild1: orgChild1Ref?.orgChild1Name ?? null,
orgChild2: orgChild2Ref?.orgChild2Name ?? null,
orgChild3: orgChild3Ref?.orgChild3Name ?? null,
orgChild4: orgChild4Ref?.orgChild4Name ?? null,
orgRoot: orgRevisionRef?.orgRoot?.orgRootName ?? null,
orgChild1: orgRevisionRef?.orgChild1?.orgChild1Name ?? null,
orgChild2: orgRevisionRef?.orgChild2?.orgChild2Name ?? null,
orgChild3: orgRevisionRef?.orgChild3?.orgChild3Name ?? null,
orgChild4: orgRevisionRef?.orgChild4?.orgChild4Name ?? null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
@ -5944,19 +5905,8 @@ export class CommandController extends Controller {
await this.salaryHistoryRepo.save(history);
}),
);
// const checkCommandType = await this.commandRepository.findOne({
// where: { id: body.data.length > 0 ? body.data[0].commandId?.toString() : "" },
// relations: ["commandType"],
// });
if (commandType && String(commandType.code) == "C-PM-11") {
// const profile = await this.profileRepository.find({
// where: { id: In(body.data.map((x) => x.profileId)) },
// });
// const data = profile.map((x) => ({
// ...x,
// isProbation: false,
// }));
// await this.profileRepository.save(data);
const profileIds = body.data.map((x) => x.profileId);
await this.profileRepository.update(
{ id: In(profileIds) },
@ -5976,6 +5926,8 @@ export class CommandController extends Controller {
beginningLeaveDays: 0,
beginningLeaveCount: 0,
})
.then(() => {})
.catch(() => {})
)
);
}

View file

@ -87,6 +87,7 @@ export class ReportController extends Controller {
@Query() isProbation?: boolean,
@Query() isRetire?: boolean,
@Query() isRetireLaw?: boolean,
@Query() isCurrent?: boolean,
@Query() retireType?: string,
@Query() tenureType?: string,
@Query() tenureMin?: number,
@ -253,62 +254,16 @@ export class ReportController extends Controller {
.andWhere(field != null && field != "" ? "registryOfficer.fields LIKE :fields" : "1=1", {
fields: `%${field}%`,
})
.andWhere(
isCurrent === undefined || isCurrent === null
? "1=1"
: isCurrent === true
? "registryOfficer.posMasterNo IS NOT NULL"
: "registryOfficer.posMasterNo IS NULL",
)
.orderBy(`registryOfficer.${sortBy}`, sort)
.getManyAndCount();
// const mapData1 = await Promise.all(
// lists.map(async (x) => {
// return {
// profileId: x.profileId,
// citizenId: x.citizenId,
// prefix: x.prefix,
// firstName: x.firstName,
// lastName: x.lastName,
// isProbation: x.isProbation,
// isLeave: x.isLeave,
// isRetirement: x.isRetirement,
// leaveType: x.leaveType,
// posMasterNo: x.posMasterNo,
// orgRootId: x.orgRootId,
// orgChild1Id: x.orgChild1Id,
// orgChild2Id: x.orgChild2Id,
// orgChild3Id: x.orgChild3Id,
// orgChild4Id: x.orgChild4Id,
// orgRootName: x.orgRootName,
// orgChild1Name: x.orgChild1Name,
// orgChild2Name: x.orgChild2Name,
// orgChild3Name: x.orgChild3Name,
// orgChild4Name: x.orgChild4Name,
// org: x.org,
// searchShortName: x.searchShortName,
// posExecutiveName: x.posExecutiveName,
// position: x.position,
// posTypeName: x.posTypeName,
// posLevelName: x.posLevelName,
// gender: x.gender,
// relationship: x.relationship,
// dateAppoint: x.dateAppoint,
// dateRetire: x.dateRetire,
// dateRetireLaw: x.dateRetireLaw,
// birthdate: x.birthdate,
// degree: x.degrees,
// age: x.age,
// currentPosition: null,
// lengthPosition: null,
// positionDate: {
// Years: x.Years ? x.Years : 0,
// Months: x.Months ? x.Months : 0,
// Days: x.Days ? x.Days : 0,
// },
// levelDate: {
// posExecutiveYears: x.levelYears,
// posExecutiveMonths: x.levelMonths,
// posExecutiveDays: x.levelDays,
// },
// };
// }),
// );
const mapData = [];
for await (const x of lists) {
let _educations: any = [];
@ -322,11 +277,6 @@ export class ReportController extends Controller {
Array.isArray(x.Educations) && x.Educations != null
? (x.Educations as any[]).filter((i: any) => i.isHigh == true)
: [];
// if(_educations.length == 0) {
// _educations = Array.isArray(x.Educations) && x.Educations != null
// ? (x.Educations as any[])[0]
// : []
// }
}
} else {
_educations =
@ -379,9 +329,6 @@ export class ReportController extends Controller {
dateRetireLaw: x.dateRetireLaw,
birthdate: x.birthdate,
Educations: _educations,
// degree: x.degrees,
// educationLevel: x.educationLevels,
// field: x.fields,
age: x.age,
currentPosition: null,
lengthPosition: null,
@ -429,6 +376,7 @@ export class ReportController extends Controller {
@Query() isProbation?: boolean,
@Query() isRetire?: boolean,
@Query() isRetireLaw?: boolean,
@Query() isCurrent?: boolean,
@Query() retireType?: string,
@Query() ageMin?: number,
@Query() ageMax?: number,
@ -581,6 +529,13 @@ export class ReportController extends Controller {
.andWhere(field != null && field != "" ? "registryEmployee.fields LIKE :fields" : "1=1", {
fields: `%${field}%`,
})
.andWhere(
isCurrent === undefined || isCurrent === null
? "1=1"
: isCurrent === true
? "registryEmployee.posMasterNo IS NOT NULL"
: "registryEmployee.posMasterNo IS NULL",
)
.orderBy(`registryEmployee.${sortBy}`, sort)
.getManyAndCount();