diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 7163b44a..74be9cb5 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -230,17 +230,17 @@ export class CommandController extends Controller { const regex = /\/(\d{4})$/; const match = keyword.match(regex); if (match) { - baseKeyword = keyword.substring(0, keyword.lastIndexOf('/')).trim(); + baseKeyword = keyword.substring(0, keyword.lastIndexOf("/")).trim(); yearKeyword = match[1].trim(); } - let yearInBC = yearKeyword ? (parseInt(yearKeyword) - 543) : null; + let yearInBC = yearKeyword ? parseInt(yearKeyword) - 543 : null; // - + // console.log("k>>",keyword); // console.log("bk>>",baseKeyword); // console.log("yk>>",yearKeyword); // console.log("yi>>",yearInBC); - + const [commands, total] = await this.commandRepository .createQueryBuilder("command") .andWhere( @@ -292,9 +292,12 @@ export class CommandController extends Controller { ) .andWhere( new Brackets((qb) => { - qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :baseKeyword" : "1=1", { - baseKeyword: `%${baseKeyword}%`, - }) + qb.where( + keyword != null && keyword != "" ? "command.commandNo LIKE :baseKeyword" : "1=1", + { + baseKeyword: `%${baseKeyword}%`, + }, + ) .orWhere(keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }) @@ -2513,20 +2516,13 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; - posNo: string | null; - position: string | null; - positionLine: string | null; - positionPathSide: string | null; positionExecutive: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; posmasterId: string; positionId: string; commandId?: string | null; @@ -2535,9 +2531,16 @@ export class CommandController extends Controller { orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number | null; + posNo: string | null; + posNoAbb: string | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + positionName: string | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -2563,7 +2566,6 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), }; Object.assign(data, { ...item, ...meta }); @@ -2647,17 +2649,12 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; - posNo: string | null; - position: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; posmasterId: string; positionId: string; commandId?: string | null; @@ -2666,9 +2663,16 @@ export class CommandController extends Controller { orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number | null; + posNo: string | null; + posNoAbb: string | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + positionName: string | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -2694,7 +2698,6 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), }; Object.assign(data, { @@ -2788,20 +2791,13 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; - posNo: string | null; - position: string | null; - positionLine: string | null; - positionPathSide: string | null; positionExecutive: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; isLeave: boolean; leaveReason?: string | null; dateLeave?: Date | null; @@ -2812,9 +2808,16 @@ export class CommandController extends Controller { orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number | null; + posNo: string | null; + posNoAbb: string | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + positionName: string | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -2846,7 +2849,6 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), }; Object.assign(data, { ...item, ...meta }); @@ -2879,9 +2881,9 @@ export class CommandController extends Controller { } } profile.leaveCommandId = item.commandId ?? _null; - profile.leaveCommandNo = item.refCommandNo ?? _null; + profile.leaveCommandNo = item.commandNo ?? _null; profile.leaveRemark = clearProfile.leaveRemark ?? _null; - profile.leaveDate = item.date ?? _null; + profile.leaveDate = item.commandDateAffect ?? _null; profile.leaveType = clearProfile.LeaveType ?? _null; profile.position = _null; profile.posTypeId = _null; @@ -2952,17 +2954,12 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; - posNo: string | null; - position: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; isLeave: boolean; leaveReason?: string | null; dateLeave?: Date | null; @@ -2973,12 +2970,17 @@ export class CommandController extends Controller { orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; - positionLine?: string | null; - positionPathSide?: string | null; positionExecutive?: string | null; + commandNo: string | null; + commandYear: number | null; + posNo: string | null; + posNoAbb: string | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + positionName: string | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -3007,7 +3009,6 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), }; Object.assign(data, { @@ -3045,9 +3046,9 @@ export class CommandController extends Controller { } } profile.leaveCommandId = item.commandId ?? _null; - profile.leaveCommandNo = item.refCommandNo ?? _null; + profile.leaveCommandNo = item.commandNo ?? _null; profile.leaveRemark = clearProfile.leaveRemark ?? _null; - profile.leaveDate = item.date ?? _null; + profile.leaveDate = item.commandDateAffect ?? _null; profile.leaveType = clearProfile.LeaveType ?? _null; profile.position = _null; profile.posTypeId = _null; @@ -3067,20 +3068,13 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; - posNo: string | null; - position: string | null; - positionLine: string | null; - positionPathSide: string | null; positionExecutive: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; commandId?: string | null; leaveReason?: string | null; dateLeave?: Date | null; @@ -3090,12 +3084,19 @@ export class CommandController extends Controller { orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; officerOrg?: string | null; dateStart?: Date | null; dateEnd?: Date | null; + commandNo: string | null; + commandYear: number | null; + posNo: string | null; + posNoAbb: string | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + positionName: string | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -3124,7 +3125,6 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), }; if (item.isLeave != undefined && item.isLeave == true) { await removeProfileInOrganize(profile.id, "OFFICER"); @@ -3142,9 +3142,9 @@ export class CommandController extends Controller { } profile.isLeave = item.isLeave; profile.leaveCommandId = item.commandId ?? _null; - profile.leaveCommandNo = item.refCommandNo ?? _null; + profile.leaveCommandNo = item.commandNo ?? _null; profile.leaveRemark = clearProfile.leaveRemark ?? _null; - profile.leaveDate = item.date ?? _null; + profile.leaveDate = item.commandDateAffect ?? _null; profile.leaveType = clearProfile.LeaveType ?? _null; profile.position = _null; profile.posTypeId = _null; @@ -3178,7 +3178,7 @@ export class CommandController extends Controller { agency: item.officerOrg, dateStart: item.dateStart, dateEnd: item.dateEnd, - commandNo: item.refCommandNo, + commandNo: item.commandNo, refCommandDate: new Date(), commandId: item.commandId, createdUserId: req.user.sub, @@ -3211,29 +3211,31 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; - posNo: string | null; - position: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; commandId?: string | null; orgRoot?: string | null; orgChild1?: string | null; orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; officerOrg?: string | null; dateStart?: Date | null; dateEnd?: Date | null; + commandNo: string | null; + commandYear: number | null; + posNo: string | null; + posNoAbb: string | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + positionName: string | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -3259,7 +3261,6 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), }; Object.assign(data, { @@ -3289,7 +3290,7 @@ export class CommandController extends Controller { agency: item.officerOrg, dateStart: item.dateStart, dateEnd: item.dateEnd, - commandNo: item.refCommandNo, + commandNo: item.commandNo, refCommandDate: new Date(), commandId: item.commandId, createdUserId: req.user.sub, @@ -3323,9 +3324,6 @@ export class CommandController extends Controller { data: { profileId: string; profileType?: string | null; - date?: Date | null; - refCommandNo?: string | null; - salaryRef?: string | null; isLeave: boolean | null; leaveReason?: string | null; dateLeave?: Date | null; @@ -3338,10 +3336,13 @@ export class CommandController extends Controller { positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; isGovernment?: boolean | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; - refCommandDate?: Date | null; + commandNo: string | null; + commandYear: number | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -3390,27 +3391,28 @@ export class CommandController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; + const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; let position = profile.current_holders .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -3420,15 +3422,9 @@ export class CommandController extends Controller { const meta = { profileId: profile.id, commandId: item.commandId, - date: item.date, - refCommandNo: item.refCommandNo, - templateDoc: item.salaryRef, position: profile.position, positionType: profile?.posType?.posTypeName ?? null, positionLevel: profile?.posLevel?.posLevelName ?? null, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: item.amount ? item.amount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, @@ -3452,10 +3448,16 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - refCommandDate: new Date(), isGovernment: item.isGovernment, - refCommandCode: item.refCommandCode, - refCommandName: item.refCommandName, + commandNo: item.commandNo, + commandYear: item.commandYear, + posNo: shortName, + posNoAbb: posNo, + commandDateAffect: item.commandDateAffect, + commandDateSign: item.commandDateSign, + commandCode: item.commandCode, + commandName: item.commandName, + remark: item.remark, }; Object.assign(data, meta); @@ -3506,12 +3508,11 @@ export class CommandController extends Controller { if (exceptClear.status) { _profile.leaveReason = item.leaveReason ?? _null; _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveCommandNo = item.commandNo ?? _null; _profile.leaveRemark = exceptClear.leaveRemark ?? _null; - _profile.leaveDate = item.date ?? _null; + _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = exceptClear.LeaveType ?? _null; - } - else { + } else { await removeProfileInOrganize(_profile.id, "OFFICER"); } } @@ -3526,9 +3527,9 @@ export class CommandController extends Controller { } } _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveCommandNo = item.commandNo ?? _null; _profile.leaveRemark = clearProfile.leaveRemark ?? _null; - _profile.leaveDate = item.date ?? _null; + _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; @@ -3579,27 +3580,28 @@ export class CommandController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; + const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; // let position = // profile.current_holders // .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -3609,16 +3611,9 @@ export class CommandController extends Controller { const meta = { profileEmployeeId: profile.id, commandId: item.commandId, - date: item.date, - refCommandNo: item.refCommandNo, - templateDoc: item.salaryRef, position: profile.position, positionType: profile?.posType?.posTypeName ?? null, positionLevel: profile?.posLevel?.posLevelName ?? null, - posNo: shortName ? shortName : null, - // positionLine: position?.positionField ?? "-", - // positionPathSide: position?.positionArea ?? "-", - // positionExecutive: position?.posExecutive?.posExecutiveName ?? "-", amount: item.amount ? item.amount : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, mouthSalaryAmount: item.mouthSalaryAmount ? item.mouthSalaryAmount : null, @@ -3640,10 +3635,16 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - refCommandDate: new Date(), isGovernment: item.isGovernment, - refCommandCode: item.refCommandCode, - refCommandName: item.refCommandName, + commandNo: item.commandNo, + commandYear: item.commandYear, + posNo: shortName, + posNoAbb: posNo, + commandDateAffect: item.commandDateAffect, + commandDateSign: item.commandDateSign, + commandCode: item.commandCode, + commandName: item.commandName, + remark: item.remark, }; Object.assign(data, meta); @@ -3699,12 +3700,11 @@ export class CommandController extends Controller { if (exceptClear.status) { _profile.leaveReason = item.leaveReason ?? _null; _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveCommandNo = item.commandNo ?? _null; _profile.leaveRemark = exceptClear.leaveRemark ?? _null; - _profile.leaveDate = item.date ?? _null; + _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = exceptClear.LeaveType ?? _null; - } - else { + } else { await removeProfileInOrganize(_profile.id, "EMPLOYEE"); } } @@ -3719,9 +3719,9 @@ export class CommandController extends Controller { } } _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveCommandNo = item.commandNo ?? _null; _profile.leaveRemark = clearProfile.leaveRemark ?? _null; - _profile.leaveDate = item.date ?? _null; + _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; @@ -3743,9 +3743,6 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; - refCommandNo?: string | null; - salaryRef?: string | null; isLeave: boolean | null; leaveReason?: string | null; dateLeave?: Date | null; @@ -3758,9 +3755,13 @@ export class CommandController extends Controller { positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; isGovernment?: boolean | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -3808,26 +3809,27 @@ export class CommandController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; + const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; // let position = // profile.current_holders // .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -3837,16 +3839,9 @@ export class CommandController extends Controller { const meta = { profileEmployeeId: profile.id, commandId: item.commandId, - date: item.date, - refCommandNo: item.refCommandNo, - templateDoc: item.salaryRef, position: profile.position, positionType: profile?.posType?.posTypeName ?? null, positionLevel: profile?.posLevel?.posLevelName ?? null, - posNo: shortName ? shortName : null, - // positionLine: position?.positionField ?? "-", - // positionPathSide: position?.positionArea ?? "-", - // positionExecutive: position?.posExecutive?.posExecutiveName ?? "-", amount: item.amount ? item.amount : null, amountSpecial: item.amountSpecial ? item.amountSpecial : null, positionSalaryAmount: item.positionSalaryAmount ? item.positionSalaryAmount : null, @@ -3869,10 +3864,16 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - refCommandDate: new Date(), isGovernment: item.isGovernment, - refCommandCode: item.refCommandCode, - refCommandName: item.refCommandName, + commandNo: item.commandNo, + commandYear: item.commandYear, + posNo: shortName, + posNoAbb: posNo, + commandDateAffect: item.commandDateAffect, + commandDateSign: item.commandDateSign, + commandCode: item.commandCode, + commandName: item.commandName, + remark: item.remark, }; Object.assign(data, meta); @@ -3928,12 +3929,11 @@ export class CommandController extends Controller { if (exceptClear.status) { _profile.leaveReason = item.leaveReason ?? _null; _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveCommandNo = item.commandNo ?? _null; _profile.leaveRemark = exceptClear.leaveRemark ?? _null; - _profile.leaveDate = item.date ?? _null; + _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = exceptClear.LeaveType ?? _null; - } - else { + } else { await removeProfileInOrganize(_profile.id, "EMPLOYEE"); } } @@ -3948,9 +3948,9 @@ export class CommandController extends Controller { } } _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveCommandNo = item.commandNo ?? _null; _profile.leaveRemark = clearProfile.leaveRemark ?? _null; - _profile.leaveDate = item.date ?? _null; + _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; @@ -3971,17 +3971,21 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; - refCommandNo?: string | null; - salaryRef?: string | null; commandId?: string | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number | null; + posNo: string | null; + posNoAbb: string | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + positionName: string | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -4030,26 +4034,27 @@ export class CommandController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; + const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; let position = profile.current_holders .filter((x) => x.orgRevisionId == orgRevision?.id)[0] @@ -4058,16 +4063,10 @@ export class CommandController extends Controller { const data = new ProfileSalary(); const meta = { profileId: item.profileId, - date: item.date, - refCommandNo: item.refCommandNo, - templateDoc: item.salaryRef, commandId: item.commandId, position: profile.position, positionType: profile?.posType?.posTypeName ?? null, positionLevel: profile?.posLevel?.posLevelName ?? null, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: item.amount ? item.amount : null, amountSpecial: item.amountSpecial ? item.amountSpecial : null, @@ -4090,9 +4089,15 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: item.refCommandCode, - refCommandName: item.refCommandName, + commandNo: item.commandNo, + commandYear: item.commandYear, + posNo: shortName, + posNoAbb: posNo, + commandDateAffect: item.commandDateAffect, + commandDateSign: item.commandDateSign, + commandCode: item.commandCode, + commandName: item.commandName, + remark: item.remark, }; Object.assign(data, meta); const history = new ProfileSalaryHistory(); @@ -4127,18 +4132,19 @@ export class CommandController extends Controller { body: { data: { profileId: string; - date?: Date | null; - refCommandNo?: string | null; - salaryRef?: string | null; commandId?: string | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; isGovernment?: boolean | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -4175,7 +4181,7 @@ export class CommandController extends Controller { if (!_profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = item.date; + let dateLeave_: any = item.commandDateAffect; _profile.isLeave = true; _profile.leaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; @@ -4203,42 +4209,37 @@ export class CommandController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; + const posNo = `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}`; let position = profile.current_holders .filter((x) => x.orgRevisionId == orgRevision?.id)[0] ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: item.profileId, - date: item.date, - refCommandNo: item.refCommandNo, - templateDoc: item.salaryRef, commandId: item.commandId, position: profile.position, positionType: profile?.posType?.posTypeName ?? null, positionLevel: profile?.posLevel?.posLevelName ?? null, - posNo: shortName, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: item.amount ? item.amount : null, amountSpecial: item.amountSpecial ? item.amountSpecial : null, @@ -4262,10 +4263,16 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - refCommandDate: new Date(), isGovernment: item.isGovernment, - refCommandCode: item.refCommandCode, - refCommandName: item.refCommandName, + commandNo: item.commandNo, + commandYear: item.commandYear, + posNo: shortName, + posNoAbb: posNo, + commandDateAffect: item.commandDateAffect, + commandDateSign: item.commandDateSign, + commandCode: item.commandCode, + commandName: item.commandName, + remark: item.remark, }); await removeProfileInOrganize(profile.id, "OFFICER"); const clearProfile = await checkCommandType(String(item.commandId)); @@ -4280,9 +4287,9 @@ export class CommandController extends Controller { } } _profile.leaveCommandId = item.commandId ?? _null; - _profile.leaveCommandNo = item.refCommandNo ?? _null; + _profile.leaveCommandNo = item.commandNo ?? _null; _profile.leaveRemark = clearProfile.leaveRemark ?? _null; - _profile.leaveDate = item.date ?? _null; + _profile.leaveDate = item.commandDateAffect ?? _null; _profile.leaveType = clearProfile.LeaveType ?? _null; _profile.position = _null; _profile.posTypeId = _null; @@ -4335,7 +4342,6 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), }; const _null: any = null; if (item.bodyProfile.posLevelId === "") item.bodyProfile.posLevelId = null; @@ -4493,7 +4499,6 @@ export class CommandController extends Controller { profile.lastUpdateUserId = req.user.sub; profile.lastUpdateFullName = req.user.name; profile.lastUpdatedAt = new Date(); - profile.refCommandDate = new Date(); await this.profileRepository.save(profile); setLogDataDiff(req, { before, after: profile }); } @@ -4696,18 +4701,18 @@ export class CommandController extends Controller { body: { refIds: { refId: string; - commandAffectDate: Date | null; - commandNo: string | null; commandId?: string | null; - commandYear: number; - templateDoc: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -4725,15 +4730,15 @@ export class CommandController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const orgRevision = await this.orgRevisionRepository.findOne({ - where: { + where: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }); const _posMaster = await this.employeePosMasterRepository.findOne({ - where: { + where: { orgRevisionId: orgRevision?.id, - id: profile.posmasterIdTemp + id: profile.posmasterIdTemp, // current_holderId: profile.id }, relations: { @@ -4767,33 +4772,35 @@ export class CommandController extends Controller { const meta = { profileEmployeeId: profile.id, - date: new Date(), amount: item.amount, amountSpecial: item.amountSpecial, commandId: item.commandId, positionSalaryAmount: item.positionSalaryAmount, mouthSalaryAmount: item.mouthSalaryAmount, - posNo: `${orgShortName ?? ""} ${profile.posMasterNoTemp ?? ""}`, position: profile.positionTemp, positionType: profile.posTypeNameTemp, positionLevel: profile.posLevelNameTemp, - refCommandNo: `${item.commandNo}/${Extension.ToThaiYear(item.commandYear)}`, - templateDoc: item.templateDoc, order: dest_item == null ? 1 : dest_item.order + 1, // orgRoot: orgRootRef?.orgRootName??null, // orgChild1: orgChild1Ref?.orgChild1Name??null, // orgChild2: orgChild2Ref?.orgChild2Name??null, // orgChild3: orgChild3Ref?.orgChild3Name??null, // orgChild4: orgChild4Ref?.orgChild4Name??null, - refCommandCode: item.refCommandCode, - refCommandName: item.refCommandName, createdUserId: req.user.sub, createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), + commandNo: item.commandNo, + commandYear: item.commandYear, + posNo: orgShortName, + posNoAbb: profile.posMasterNoTemp ?? "", + commandDateAffect: item.commandDateAffect, + commandDateSign: item.commandDateSign, + commandCode: item.commandCode, + commandName: item.commandName, + remark: item.remark, }; Object.assign(data, meta); @@ -4921,11 +4928,11 @@ export class CommandController extends Controller { root: posMaster.orgRoot.orgRootName, rootId: posMaster.orgRootId, rootShortName: posMaster.orgRoot.orgRootShortName, - rootDnaId: posMaster.orgRoot?.ancestorDNA??_null, - child1DnaId: posMaster.orgChild1?.ancestorDNA??_null, - child2DnaId: posMaster.orgChild2?.ancestorDNA??_null, - child3DnaId: posMaster.orgChild3?.ancestorDNA??_null, - child4DnaId: posMaster.orgChild4?.ancestorDNA??_null, + rootDnaId: posMaster.orgRoot?.ancestorDNA ?? _null, + child1DnaId: posMaster.orgChild1?.ancestorDNA ?? _null, + child2DnaId: posMaster.orgChild2?.ancestorDNA ?? _null, + child3DnaId: posMaster.orgChild3?.ancestorDNA ?? _null, + child4DnaId: posMaster.orgChild4?.ancestorDNA ?? _null, }); await this.profileEmployeeRepository.save(profile); await this.employeePositionRepository.save(positionNew); @@ -4966,18 +4973,18 @@ export class CommandController extends Controller { body: { refIds: { refId: string; - commandAffectDate: Date | null; - commandNo: string | null; commandId?: string | null; - commandYear: number; - templateDoc: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -5016,25 +5023,22 @@ export class CommandController extends Controller { const shortName = item.posMaster != null && item.posMaster.orgChild4 != null - ? `${item.posMaster.orgChild4.orgChild4ShortName}${item.posMaster.posMasterNo}` + ? `${item.posMaster.orgChild4.orgChild4ShortName}` : item.posMaster != null && item.posMaster?.orgChild3 != null - ? `${item.posMaster.orgChild3.orgChild3ShortName}${item.posMaster.posMasterNo}` + ? `${item.posMaster.orgChild3.orgChild3ShortName}` : item.posMaster != null && item.posMaster?.orgChild2 != null - ? `${item.posMaster.orgChild2.orgChild2ShortName}${item.posMaster.posMasterNo}` + ? `${item.posMaster.orgChild2.orgChild2ShortName}` : item.posMaster != null && item.posMaster?.orgChild1 != null - ? `${item.posMaster.orgChild1.orgChild1ShortName}${item.posMaster.posMasterNo}` + ? `${item.posMaster.orgChild1.orgChild1ShortName}` : item.posMaster != null && item.posMaster?.orgRoot != null - ? `${item.posMaster.orgRoot.orgRootShortName}${item.posMaster.posMasterNo}` + ? `${item.posMaster.orgRoot.orgRootShortName}` : null; const metaAct = { profileId: item.posMasterChild.current_holderId, - dateStart: body.refIds[0].commandAffectDate, + dateStart: body.refIds[0].commandDateAffect, dateEnd: null, - posNo: shortName, position: item.posMaster.current_holder.position, status: true, - commandNo: `${body.refIds[0].commandNo}/${Extension.ToThaiYear(body.refIds[0].commandYear)}`, - refCommandDate: new Date(), commandId: body.refIds[0].commandId, createdUserId: req.user.sub, createdFullName: req.user.name, @@ -5042,6 +5046,15 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), + commandNo: body.refIds[0].commandNo, + commandYear: body.refIds[0].commandYear, + posNo: shortName, + posNoAbb: item.posMaster.posMasterNo, + commandDateAffect: body.refIds[0].commandDateAffect, + commandDateSign: body.refIds[0].commandDateSign, + commandCode: body.refIds[0].commandCode, + commandName: body.refIds[0].commandName, + remark: body.refIds[0].remark, }; const dataAct = new ProfileActposition(); @@ -5188,18 +5201,18 @@ export class CommandController extends Controller { body: { refIds: { refId: string; - commandAffectDate: Date | null; - commandNo: string | null; commandId?: string | null; - commandYear: number; - templateDoc: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }[]; }, ) { @@ -5229,15 +5242,15 @@ export class CommandController extends Controller { const orgChild4Ref = posMaster?.orgChild4 ?? null; const shortName = posMaster != null && posMaster.orgChild4 != null - ? `${posMaster.orgChild4.orgChild4ShortName}${posMaster.posMasterNo}` + ? `${posMaster.orgChild4.orgChild4ShortName}` : posMaster != null && posMaster.orgChild3 != null - ? `${posMaster.orgChild3.orgChild3ShortName}${posMaster.posMasterNo}` + ? `${posMaster.orgChild3.orgChild3ShortName}` : posMaster != null && posMaster.orgChild2 != null - ? `${posMaster.orgChild2.orgChild2ShortName}${posMaster.posMasterNo}` + ? `${posMaster.orgChild2.orgChild2ShortName}` : posMaster != null && posMaster.orgChild1 != null - ? `${posMaster.orgChild1.orgChild1ShortName}${posMaster.posMasterNo}` + ? `${posMaster.orgChild1.orgChild1ShortName}` : posMaster != null && posMaster?.orgRoot != null - ? `${posMaster.orgRoot.orgRootShortName}${posMaster.posMasterNo}` + ? `${posMaster.orgRoot.orgRootShortName}` : null; const profile = await this.profileRepository.findOne({ where: { id: posMaster.next_holderId }, @@ -5263,27 +5276,30 @@ export class CommandController extends Controller { commandId: item.commandId, positionSalaryAmount: item.positionSalaryAmount, mouthSalaryAmount: item.mouthSalaryAmount, - posNo: shortName ?? null, position: position?.positionName ?? null, positionType: position?.posType?.posTypeName ?? null, positionLevel: position?.posLevel?.posLevelName ?? null, - refCommandNo: `${item.commandNo}/${Extension.ToThaiYear(item.commandYear)}`, - templateDoc: item.templateDoc, order: dest_item == null ? 1 : dest_item.order + 1, orgRoot: orgRootRef?.orgRootName ?? null, orgChild1: orgChild1Ref?.orgChild1Name ?? null, orgChild2: orgChild2Ref?.orgChild2Name ?? null, orgChild3: orgChild3Ref?.orgChild3Name ?? null, orgChild4: orgChild4Ref?.orgChild4Name ?? null, - refCommandCode: item.refCommandCode, - refCommandName: item.refCommandName, createdUserId: req.user.sub, createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), + commandNo: item.commandNo, + commandYear: item.commandYear, + posNo: shortName, + posNoAbb: posMaster.posMasterNo, + commandDateAffect: item.commandDateAffect, + commandDateSign: item.commandDateSign, + commandCode: item.commandCode, + commandName: item.commandName, + remark: item.remark, }; Object.assign(data, meta); const history = new ProfileSalaryHistory(); diff --git a/src/controllers/DPISController.ts b/src/controllers/DPISController.ts index 90cc09c0..16ac3e90 100644 --- a/src/controllers/DPISController.ts +++ b/src/controllers/DPISController.ts @@ -258,7 +258,7 @@ export class DPISController extends Controller { //relations: ["current_holders", "current_holders.orgRoot"], order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileLeaves: { dateLeaveStart: "ASC", @@ -314,7 +314,7 @@ export class DPISController extends Controller { salaries: profile.profileSalary.map((item) => { return { posNo: item.posNo, - position: item.position, + position: item.positionName, positionType: item.positionType, positionLevel: item.positionLevel, amount: item.amount, diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 5b581859..d4f3fe24 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -20,7 +20,6 @@ import * as fs from "fs"; import * as path from "path"; const { createConnection } = require("typeorm"); import csvParser from "csv-parser"; -import { HR_POSITION_OFFICER } from "../entities/HR_POSITION_OFFICER"; import { HR_PERSONAL_OFFICER_FAMILY } from "../entities/HR_PERSONAL_OFFICER_FAMILY"; const BATCH_SIZE = 1000; @@ -47,7 +46,8 @@ import { OrgRevision } from "../entities/OrgRevision"; import { OFFICER } from "../entities/OFFICER"; import { Position } from "../entities/Position"; import { PosMaster } from "../entities/PosMaster"; - +import { positionOfficer } from "../entities/positionOfficer"; +// import { uuidv7 } from "uuidv7"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") @@ -61,7 +61,7 @@ export class ImportDataController extends Controller { private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private posLevelRepo = AppDataSource.getRepository(PosLevel); private posTypeRepo = AppDataSource.getRepository(PosType); - private HR_POSITION_OFFICERRepo = AppDataSource.getRepository(HR_POSITION_OFFICER); + private positionOfficerRepo = AppDataSource.getRepository(positionOfficer); private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY); private HR_EDUCATIONRepo = AppDataSource.getRepository(HR_EDUCATION); private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource.getRepository( @@ -323,125 +323,321 @@ export class ImportDataController extends Controller { async UploadFileSQLSalary(@Request() request: { user: Record }) { let rowCount = 0; let null_: any = null; + let sqlStatements: string[] = []; const [profiles, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") - .skip(20000) + // .where("profile.citizenId = '3101702379675'") + .skip(0) .take(10000) .getManyAndCount(); - // for (var i = 1; i <= total / BATCH_SIZE; i++) { - // const profiles = await AppDataSource.getRepository(Profile) - // .createQueryBuilder("profile") - // .select(["profile.citizenId", "profile.id"]) - // .orderBy("profile.citizenId", "ASC") - // .skip((i - 1) * BATCH_SIZE) - // .take(BATCH_SIZE) - // .getMany(); + var _profiles: ProfileSalary[] = []; + const filePath = path.join(__dirname, "salaryProfile.csv"); + // CSV Header + let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId"\n`; + fs.appendFile(filePath, csvData, (err) => { + if (err) { + console.error("Error writing CSV file:", err); + } else { + console.log("Salary profiles successfully written to salaryProfile.csv"); + } + }); await Promise.all( profiles.map(async (_item) => { - console.log(">>>>>>>>>>>>>>>>>>>" + _item.citizenId); - const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ - where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" }, - select: [ - "CIT", - "MP_POS_DATE", - "SALARY", - "MP_COMMAND_NUM", - "POS_NUM_NAME", - "POS_NUM_CODE", - "FLAG_TO_NAME", - "WORK_LINE_NAME", - "SPECIALIST_NAME", - "ADMIN_NAME", - "REMARK", - "ORDER_MOVE_POSITION", - "SAL_POS_AMOUNT_1", - "SAL_POS_AMOUNT_2", - "SPECIAL_AMT", - "MP_COMMAND_DATE", - "FLAG_TO_NAME_CODE", - "DEPARTMENT_NAME", - "DIVISION_NAME", - "SECTION_NAME", - "JOB_NAME", - "MP_CEE", - "USER_CREATE", - "USER_UPDATE", - ], + const existingProfile = await this.positionOfficerRepo.find({ + where: { citizenId: _item.citizenId, flag_person_type: "1" }, + order: { + mp_pos_date: "ASC", + order_move_position: "ASC", + }, }); - + let order = 1; await Promise.all( existingProfile.map(async (item) => { rowCount++; - const profileSalary = new ProfileSalary(); - profileSalary.date = item.MP_POS_DATE - ? new Date(item.MP_POS_DATE.replace(" +0700 +07:00", "")) - : null_; - const SALARY: any = - item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); - profileSalary.amount = SALARY; - const SAL_POS_AMOUNT_1: any = - item.SAL_POS_AMOUNT_1 == null || item.SAL_POS_AMOUNT_1 == "" - ? null_ - : Number(item.SAL_POS_AMOUNT_1); - const SAL_POS_AMOUNT_2: any = - item.SAL_POS_AMOUNT_2 == null || item.SAL_POS_AMOUNT_2 == "" - ? null_ - : Number(item.SAL_POS_AMOUNT_2); - profileSalary.positionSalaryAmount = SAL_POS_AMOUNT_1 ?? SAL_POS_AMOUNT_2; - const SPECIAL_AMT: any = - item.SPECIAL_AMT == null || item.SPECIAL_AMT == "" ? null_ : Number(item.SPECIAL_AMT); - profileSalary.amountSpecial = SPECIAL_AMT; + const profileSalary: any = new ProfileSalary(); profileSalary.profileId = _item.id; - profileSalary.refCommandNo = item.MP_COMMAND_NUM; - profileSalary.posNo = item.POS_NUM_NAME + item.POS_NUM_CODE; - profileSalary.position = item.WORK_LINE_NAME; - profileSalary.positionPathSide = item.SPECIALIST_NAME; - profileSalary.positionExecutive = item.ADMIN_NAME; - profileSalary.templateDoc = item.REMARK; - profileSalary.refCommandDate = - item.MP_COMMAND_DATE == "" - ? new Date(item.MP_COMMAND_DATE.replace(" +0700 +07:00", "")) - : null_; - profileSalary.refCommandCode = item.FLAG_TO_NAME_CODE; - profileSalary.refCommandName = item.FLAG_TO_NAME; - profileSalary.orgRoot = item.DEPARTMENT_NAME; - profileSalary.orgChild1 = item.DIVISION_NAME; - profileSalary.orgChild2 = item.SECTION_NAME; - profileSalary.orgChild3 = item.JOB_NAME; - if (item.DEPARTMENT_CODE == "50") { - profileSalary.orgRoot = item.DIVISION_NAME; - profileSalary.orgChild1 = item.SECTION_NAME; - profileSalary.orgChild2 = item.JOB_NAME; + profileSalary.order = order; + order = order + 1; + profileSalary.commandNo = item.mp_command_num; + profileSalary.commandYear = item.cur_year > 2500 ? item.cur_year - 543 : item.cur_year; + profileSalary.commandDateSign = item.mp_command_date; + profileSalary.commandDateAffect = item.mp_pos_date; + if ( + [ + "0", + "11", + "22", + "31", + "39", + "45", + "46", + "47", + "49", + "50", + "51", + "56", + "60", + "61", + "62", + "99", + ].includes(item.flag_to_name_code) + ) { + profileSalary.commandCode = "0"; + profileSalary.commandName = "อื่น ๆ"; + } else if (["1", "58"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "1"; + profileSalary.commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้"; + } else if (["23"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "2"; + profileSalary.commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก"; + } else if (["3", "6", "34", "36", "37"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "3"; + profileSalary.commandName = "แต่งตั้ง ย้าย"; + } else if (["10", "55"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "4"; + profileSalary.commandName = "เลื่อน"; + } else if (["14"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "5"; + profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; + } else if ( + ["8", "20", "24", "25", "43", "44", "52", "66", "67"].includes(item.flag_to_name_code) + ) { + profileSalary.commandCode = "6"; + profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + } else if (["-"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "7"; + profileSalary.commandName = "เงินพิเศษอื่น ๆ"; + } else if (["38", "40", "53", "54"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "8"; + profileSalary.commandName = "ปรับโครงสร้าง"; + } else if (["12"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "9"; + profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; + } else if (["2", "18"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "10"; + profileSalary.commandName = "บรรจุกลับ"; + } else if (["4", "32", "33"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "11"; + profileSalary.commandName = "รับโอน"; + } else if (["5"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "12"; + profileSalary.commandName = "ให้โอน"; + } else if (["15", "95"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "13"; + profileSalary.commandName = "แก้ไขคำสั่ง"; + } else if (["19"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "14"; + profileSalary.commandName = "ยกเลิกคำสั่ง"; + } else if (["27", "35"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "15"; + profileSalary.commandName = "ลาออกจากราชการ"; + } else if ( + ["13", "17", "21", "28", "29", "30", "59"].includes(item.flag_to_name_code) + ) { + profileSalary.commandCode = "16"; + profileSalary.commandName = "พ้นจากราชการ"; + } else if (["7", "9", "16", "26", "63", "68"].includes(item.flag_to_name_code)) { + profileSalary.commandCode = "17"; + profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; } - profileSalary.mpCee = item.MP_CEE; - const ORDER_MOVE_POSITION: any = - item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" + if ( + item.flag_to_name == "" && + (item.flag_to_name_code == "เลื่อน 1 ขั้นและเลื่อนระดับ" || + item.flag_to_name_code == "เลื่อน 0.5 ขั้นและเลื่อนระดับ" || + item.flag_to_name_code == "ลาศึกษาต่อ") + ) { + profileSalary.commandCode = "0"; + profileSalary.commandName = "อื่น ๆ"; + } else if (item.flag_to_name == "" && item.flag_to_name_code == "เลื่อนเงินเดือน") { + profileSalary.commandCode = "5"; + profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; + } else if ( + item.flag_to_name == "" && + (item.flag_to_name_code == "ปรับตามบัญชีเงินเดือนใหม่" || + item.flag_to_name_code == "เลื่อนเงินเดือน" || + item.flag_to_name_code == "ปรับเงินเดือนตาม กพ.") + ) { + profileSalary.commandCode = "6"; + profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + } else if ( + item.flag_to_name == "" && + item.flag_to_name_code == "แต่งตั้งตามการปรับปรุงโครงฯ" + ) { + profileSalary.commandCode = "8"; + profileSalary.commandName = "ปรับโครงสร้าง"; + } else if ( + item.flag_to_name == "" && + item.flag_to_name_code == "พ้นทดลองปฏิบัติราชการ" + ) { + profileSalary.commandCode = "9"; + profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; + } else if (item.flag_to_name == "" && item.flag_to_name_code == "ให้โอนมา") { + profileSalary.commandCode = "11"; + profileSalary.commandName = "รับโอน"; + } else if ( + item.flag_to_name == "" && + item.flag_to_name_code == "โอนไปปฏิบัติราชการที่อื่น" + ) { + profileSalary.commandCode = "12"; + profileSalary.commandName = "ให้โอน"; + } else if (item.flag_to_name == "" && item.flag_to_name_code == "ยกเลิกคำสั่ง") { + profileSalary.commandCode = "14"; + profileSalary.commandName = "ยกเลิกคำสั่ง"; + } else if (item.flag_to_name == "" && item.flag_to_name_code == "รักษาการในตำแหน่ง") { + profileSalary.commandCode = "17"; + profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; + } + profileSalary.posNoAbb = item.pos_num_name; + profileSalary.posNo = item.pos_num_code; + profileSalary.positionName = item.work_line_name; + var positionType = ""; + var positionLevel = ""; + if (item.mp_cee == "21") { + positionType = "ทั่วไป"; + positionLevel = "ปฏิบัติงาน"; + } else if (item.mp_cee == "22") { + positionType = "ทั่วไป"; + positionLevel = "ชำนาญงาน"; + } else if (item.mp_cee == "23") { + positionType = "ทั่วไป"; + positionLevel = "อาวุโส"; + } else if (item.mp_cee == "24") { + positionType = "ทั่วไป"; + positionLevel = "อาวุโสเฉพาะสายงานที่กำหนด"; + } else if (item.mp_cee == "25") { + positionType = "ทั่วไป"; + positionLevel = "ทักษะพิเศษ"; + } else if (item.mp_cee == "26") { + positionType = "วิชาการ"; + positionLevel = "ปฏิบัติการ"; + } else if (item.mp_cee == "27") { + positionType = "วิชาการ"; + positionLevel = "ชำนาญการ"; + } else if (item.mp_cee == "28") { + positionType = "วิชาการ"; + positionLevel = "ชำนาญการพิเศษ"; + } else if (item.mp_cee == "29") { + positionType = "วิชาการ"; + positionLevel = "เชี่ยวชาญ"; + } else if (item.mp_cee == "30") { + positionType = "วิชาการ"; + positionLevel = "ทรงคุณวุฒิ"; + } else if (item.mp_cee == "31") { + positionType = "วิชาการ"; + positionLevel = "ทรงคุณวุฒิเฉพาะสายงานที่กำหนด"; + } else if (item.mp_cee == "32") { + positionType = "อำนวยการ"; + positionLevel = "ต้น"; + } else if (item.mp_cee == "33") { + positionType = "อำนวยการ"; + positionLevel = "สูง"; + } else if (item.mp_cee == "34") { + positionType = "บริหาร"; + positionLevel = "ต้น"; + } else if (item.mp_cee == "35") { + positionType = "บริหาร"; + positionLevel = "สูง"; + } else { + profileSalary.positionCee = item.mp_cee; + } + profileSalary.positionType = positionType; + profileSalary.positionLevel = positionLevel; + profileSalary.orgRoot = item.department_name; + profileSalary.orgChild1 = item.division_name; + profileSalary.orgChild2 = item.section_name; + profileSalary.orgChild3 = item.job_name; + if (item.department_code == "50") { + profileSalary.orgRoot = item.division_name; + profileSalary.orgChild1 = item.section_name; + profileSalary.orgChild2 = item.job_name; + } + profileSalary.positionExecutive = item.admin_name; + profileSalary.amount = item.salary; + profileSalary.remark = item.remark; + + const sal_pos_amount_1: any = + item.sal_pos_amount_1 == null || item.sal_pos_amount_1 == "" ? null_ - : Number(item.ORDER_MOVE_POSITION); - profileSalary.order = ORDER_MOVE_POSITION; + : Number(item.sal_pos_amount_1); + const sal_pos_amount_2: any = + item.sal_pos_amount_2 == null || item.sal_pos_amount_2 == "" + ? null_ + : Number(item.sal_pos_amount_2); + profileSalary.positionSalaryAmount = sal_pos_amount_1 ?? sal_pos_amount_2; + const special_amt: any = + item.special_amt == null || item.special_amt == "" ? null_ : Number(item.special_amt); + profileSalary.amountSpecial = special_amt; + profileSalary.createdUserId = request.user.sub; profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; - profileSalary.createdAt = - item.USER_CREATE == "" - ? new Date(item.USER_CREATE.replace(" +0700 +07:00", "")) - : new Date(); - profileSalary.lastUpdatedAt = - item.USER_UPDATE == "" - ? new Date(item.USER_UPDATE.replace(" +0700 +07:00", "")) - : new Date(); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - await this.salaryRepo.save(profileSalary); + profileSalary.createdAt = new Date(); + profileSalary.lastUpdatedAt = new Date(); + // const result = uuidv7(); + // profileSalary.id = result; + // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + + // // Generate SQL INSERT Statement using TypeORM QueryBuilder but don't execute it + // const queryBuilder = AppDataSource.createQueryBuilder() + // .insert() + // .into(ProfileSalary) + // .values(profileSalary); + + // const sql = queryBuilder.getSql(); + // sqlStatements.push(sql); + // _profiles.push(profileSalary); + // save to file + // Define the output file path + + // CSV Header + // let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId"\n`; + + // Loop through each salary profile and format data as CSV + // _profiles.forEach((profile) => { + csvData = `"${profileSalary.id || "NULL"}","${profileSalary.createdAt?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.createdUserId || "NULL"}","${profileSalary.lastUpdatedAt?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.lastUpdateUserId || "NULL"}","${profileSalary.createdFullName || "NULL"}","${profileSalary.lastUpdateFullName || "NULL"}","${profileSalary.profileId || "NULL"}","${profileSalary.profileEmployeeId || "NULL"}","${profileSalary.order || "NULL"}","${profileSalary.commandNo || "NULL"}","${profileSalary.commandYear || "NULL"}","${profileSalary.commandDateSign?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.commandDateAffect?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.commandCode || "NULL"}","${profileSalary.commandName || "NULL"}","${profileSalary.posNoAbb || "NULL"}","${profileSalary.posNo || "NULL"}","${profileSalary.positionName || "NULL"}","${profileSalary.positionType || "NULL"}","${profileSalary.positionLevel || "NULL"}","${profileSalary.positionCee || "NULL"}","${profileSalary.orgRoot || "NULL"}","${profileSalary.orgChild1 || "NULL"}","${profileSalary.orgChild2 || "NULL"}","${profileSalary.orgChild3 || "NULL"}","${profileSalary.orgChild4 || "NULL"}","${profileSalary.positionExecutive || "NULL"}","${profileSalary.amount || 0}","${profileSalary.amountSpecial || 0}","${profileSalary.positionSalaryAmount || 0}","${profileSalary.mouthSalaryAmount || 0}","${profileSalary.remark || "NULL"}","${profileSalary.dateGovernment?.toISOString()?.split("T")[0] || "NULL"}","${profileSalary.isGovernment || "NULL"}","${profileSalary.commandId || "NULL"}"\n`; + // }); + + // Write the CSV data to the file + fs.appendFile(filePath, csvData.replace('"NULL"', "NULL"), (err) => { + if (err) { + console.error("Error writing CSV file:", err); + } else { + console.log( + "Salary profiles successfully written to salaryProfile.csv: " + rowCount, + ); + } + }); + // await this.salaryRepo.save(profileSalary); }), ); + order = 1; }), ); - console.log(rowCount); + // // console.log(rowCount); + // // Define the output file path + // const filePath = path.join(__dirname, "salaryProfile.csv"); + + // // CSV Header + // let csvData = `"id","createdAt","createdUserId","lastUpdatedAt","lastUpdateUserId","createdFullName","lastUpdateFullName","profileId","profileEmployeeId","order","commandNo","commandYear","commandDateSign","commandDateAffect","commandCode","commandName","posNoAbb","posNo","positionName","positionType","positionLevel","positionCee","orgRoot","orgChild1","orgChild2","orgChild3","orgChild4","positionExecutive","amount","amountSpecial","positionSalaryAmount","mouthSalaryAmount","remark","dateGovernment","isGovernment","commandId"\n`; + + // // Loop through each salary profile and format data as CSV + // _profiles.forEach((profile) => { + // csvData += `"${profile.id || "NULL"}","${profile.createdAt?.toISOString()?.split("T")[0] || "NULL"}","${profile.createdUserId || "NULL"}","${profile.lastUpdatedAt?.toISOString()?.split("T")[0] || "NULL"}","${profile.lastUpdateUserId || "NULL"}","${profile.createdFullName || "NULL"}","${profile.lastUpdateFullName || "NULL"}","${profile.profileId || "NULL"}","${profile.profileEmployeeId || "NULL"}","${profile.order || "NULL"}","${profile.commandNo || "NULL"}","${profile.commandYear || "NULL"}","${profile.commandDateSign?.toISOString()?.split("T")[0] || "NULL"}","${profile.commandDateAffect?.toISOString()?.split("T")[0] || "NULL"}","${profile.commandCode || "NULL"}","${profile.commandName || "NULL"}","${profile.posNoAbb || "NULL"}","${profile.posNo || "NULL"}","${profile.positionName || "NULL"}","${profile.positionType || "NULL"}","${profile.positionLevel || "NULL"}","${profile.positionCee || "NULL"}","${profile.orgRoot || "NULL"}","${profile.orgChild1 || "NULL"}","${profile.orgChild2 || "NULL"}","${profile.orgChild3 || "NULL"}","${profile.orgChild4 || "NULL"}","${profile.positionExecutive || "NULL"}","${profile.amount || 0}","${profile.amountSpecial || 0}","${profile.positionSalaryAmount || 0}","${profile.mouthSalaryAmount || 0}","${profile.remark || "NULL"}","${profile.dateGovernment?.toISOString()?.split("T")[0] || "NULL"}","${profile.isGovernment || "NULL"}","${profile.commandId || "NULL"}"\n`; + // }); + + // // Write the CSV data to the file + // fs.writeFile(filePath, csvData, (err) => { + // if (err) { + // console.error("Error writing CSV file:", err); + // } else { + // console.log("Salary profiles successfully written to salaryProfile.csv"); + // } + // }); return new HttpSuccess(); } @@ -457,115 +653,75 @@ export class ImportDataController extends Controller { .createQueryBuilder("profile") .select(["profile.citizenId", "profile.id"]) .orderBy("profile.citizenId", "ASC") - // .skip(0) - // .take(20) + .skip(0) + .take(10000) .getManyAndCount(); - // for (var i = 1; i <= total / BATCH_SIZE; i++) { - // const profiles = await AppDataSource.getRepository(ProfileEmployee) - // .createQueryBuilder("profile") - // .select(["profile.citizenId", "profile.id"]) - // .orderBy("profile.citizenId", "ASC") - // .skip((i - 1) * BATCH_SIZE) - // .take(BATCH_SIZE) - // .getMany(); await Promise.all( profiles.map(async (_item) => { - const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "MP_POS_DATE", - "SALARY", - "MP_COMMAND_NUM", - "POS_NUM_NAME", - "POS_NUM_CODE", - "FLAG_TO_NAME", - "WORK_LINE_NAME", - "SPECIALIST_NAME", - "ADMIN_NAME", - "REMARK", - "ORDER_MOVE_POSITION", - "SAL_POS_AMOUNT_1", - "SAL_POS_AMOUNT_2", - "SPECIAL_AMT", - "MP_COMMAND_DATE", - "FLAG_TO_NAME_CODE", - "DEPARTMENT_NAME", - "DIVISION_NAME", - "SECTION_NAME", - "JOB_NAME", - "MP_CEE", - "USER_CREATE", - "USER_UPDATE", - ], + const existingProfile = await this.positionOfficerRepo.find({ + where: { citizenId: _item.citizenId, flag_person_type: "7" }, }); await Promise.all( existingProfile.map(async (item) => { rowCount++; - const profileSalary = new ProfileSalary(); - profileSalary.date = - item.MP_POS_DATE == "" - ? new Date(item.MP_POS_DATE.replace(" +0700 +07:00", "")) - : null_; - const SALARY: any = - item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); - profileSalary.amount = SALARY; - const SAL_POS_AMOUNT_1: any = - item.SAL_POS_AMOUNT_1 == null || item.SAL_POS_AMOUNT_1 == "" + const profileSalary: any = new ProfileSalary(); + profileSalary.profileId = _item.id; + profileSalary.order = item.order_move_position; /// + profileSalary.commandNo = item.mp_command_num; + profileSalary.commandYear = item.cur_year; + profileSalary.commandDateSign = item.mp_command_date; + profileSalary.commandDateAffect = item.mp_pos_date; + profileSalary.commandCode = item.flag_to_name_code; + profileSalary.commandName = item.flag_to_name; + profileSalary.posNoAbb = item.pos_num_name; + profileSalary.posNo = item.pos_num_code; + profileSalary.positionName = item.work_line_name; + profileSalary.positionCee = item.mp_cee; + profileSalary.positionType = item.mp_cee; + profileSalary.positionLevel = item.mp_cee; + profileSalary.orgRoot = item.department_name; + profileSalary.orgChild1 = item.division_name; + profileSalary.orgChild2 = item.section_name; + profileSalary.orgChild3 = item.job_name; + if (item.department_code == "50") { + profileSalary.orgRoot = item.division_name; + profileSalary.orgChild1 = item.section_name; + profileSalary.orgChild2 = item.job_name; + } + profileSalary.positionExecutive = item.admin_name; + profileSalary.amount = item.salary; + profileSalary.remark = item.remark; + + const sal_pos_amount_1: any = + item.sal_pos_amount_1 == null || item.sal_pos_amount_1 == "" ? null_ - : Number(item.SAL_POS_AMOUNT_1); - const SAL_POS_AMOUNT_2: any = - item.SAL_POS_AMOUNT_2 == null || item.SAL_POS_AMOUNT_2 == "" + : Number(item.sal_pos_amount_1); + const sal_pos_amount_2: any = + item.sal_pos_amount_2 == null || item.sal_pos_amount_2 == "" ? null_ - : Number(item.SAL_POS_AMOUNT_2); - profileSalary.positionSalaryAmount = SAL_POS_AMOUNT_1 ?? SAL_POS_AMOUNT_2; - const SPECIAL_AMT: any = - item.SPECIAL_AMT == null || item.SPECIAL_AMT == "" ? null_ : Number(item.SPECIAL_AMT); - profileSalary.amountSpecial = SPECIAL_AMT; - profileSalary.profileEmployeeId = _item.id; - profileSalary.refCommandNo = item.MP_COMMAND_NUM; - profileSalary.posNo = item.POS_NUM_NAME + item.POS_NUM_CODE; - profileSalary.position = item.WORK_LINE_NAME; - profileSalary.positionPathSide = item.SPECIALIST_NAME; - profileSalary.positionExecutive = item.ADMIN_NAME; - profileSalary.templateDoc = item.REMARK; - profileSalary.refCommandDate = - item.MP_COMMAND_DATE == "" - ? new Date(item.MP_COMMAND_DATE.replace(" +0700 +07:00", "")) - : null_; - profileSalary.refCommandCode = item.FLAG_TO_NAME_CODE; - profileSalary.refCommandName = item.FLAG_TO_NAME; - profileSalary.orgRoot = item.DEPARTMENT_NAME; - profileSalary.orgChild1 = item.DIVISION_NAME; - profileSalary.orgChild2 = item.SECTION_NAME; - profileSalary.orgChild3 = item.JOB_NAME; - profileSalary.mpCee = item.MP_CEE; - const ORDER_MOVE_POSITION: any = - item.ORDER_MOVE_POSITION == null || item.ORDER_MOVE_POSITION == "" - ? null_ - : Number(item.ORDER_MOVE_POSITION); - profileSalary.order = ORDER_MOVE_POSITION; + : Number(item.sal_pos_amount_2); + profileSalary.positionSalaryAmount = sal_pos_amount_1 ?? sal_pos_amount_2; + const special_amt: any = + item.special_amt == null || item.special_amt == "" ? null_ : Number(item.special_amt); + profileSalary.amountSpecial = special_amt; + + profileSalary.commandId; + profileSalary.createdUserId = request.user.sub; profileSalary.createdFullName = request.user.name; profileSalary.lastUpdateUserId = request.user.sub; profileSalary.lastUpdateFullName = request.user.name; - profileSalary.createdAt = - item.USER_CREATE == "" - ? new Date(item.USER_CREATE.replace(" +0700 +07:00", "")) - : new Date(); - profileSalary.lastUpdatedAt = - item.USER_UPDATE == "" - ? new Date(item.USER_UPDATE.replace(" +0700 +07:00", "")) - : new Date(); + profileSalary.createdAt = new Date(); + profileSalary.lastUpdatedAt = new Date(); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - await this.salaryRepo.save(profileSalary); + // save to file + // await this.salaryRepo.save(profileSalary); }), ); }), ); - // } console.log(rowCount); return new HttpSuccess(); } @@ -1472,12 +1628,12 @@ export class ImportDataController extends Controller { const allId = _profileOff.concat(_profileEmp); for (var i = 1; i <= 1000; i++) { - const HR_POSITION_OFFICER = await this.HR_POSITION_OFFICERRepo.find({ - where: { CIT: Not(In(allId)) }, + const positionOfficer = await this.positionOfficerRepo.find({ + where: { citizenId: Not(In(allId)) }, take: 1000, skip: 0, }); - this.HR_POSITION_OFFICERRepo.remove(HR_POSITION_OFFICER); + this.positionOfficerRepo.remove(positionOfficer); // const HR_PERSONAL_OFFICER_FAMILY = await this.HR_PERSONAL_OFFICER_FAMILYRepo.find({ // where: { CIT: Not(In(allId)) }, // take: 1000, diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index afde8364..d46d0105 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -289,7 +289,7 @@ export class OrganizationDotnetController extends Controller { where: { keycloak: keycloakId }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -318,7 +318,7 @@ export class OrganizationDotnetController extends Controller { where: { keycloak: keycloakId }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -918,7 +918,7 @@ export class OrganizationDotnetController extends Controller { where: { id: profileId }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -944,7 +944,7 @@ export class OrganizationDotnetController extends Controller { where: { id: profileId }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -1571,7 +1571,7 @@ export class OrganizationDotnetController extends Controller { where: { citizenId: citizenId }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -1597,7 +1597,7 @@ export class OrganizationDotnetController extends Controller { where: { citizenId: citizenId }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -2166,7 +2166,7 @@ export class OrganizationDotnetController extends Controller { where: { current_holders: { orgRootId: rootId } }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -2383,7 +2383,7 @@ export class OrganizationDotnetController extends Controller { where: { current_holders: { orgRootId: rootId } }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -2539,7 +2539,7 @@ export class OrganizationDotnetController extends Controller { })), order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", diff --git a/src/controllers/OrganizationUnauthorizeController.ts b/src/controllers/OrganizationUnauthorizeController.ts index 72858648..764b3b30 100644 --- a/src/controllers/OrganizationUnauthorizeController.ts +++ b/src/controllers/OrganizationUnauthorizeController.ts @@ -18,7 +18,7 @@ import { format } from "path"; import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation"; import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmployeeEvaluation"; import Extension from "../interfaces/extension"; - +import { resetPassword } from "../keycloak"; @Route("api/v1/org/unauthorize") @Tags("OrganizationUnauthorize") @Response( @@ -32,8 +32,24 @@ export class OrganizationUnauthorizeController extends Controller { private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private profileAssessmentRepo = AppDataSource.getRepository(ProfileAssessment); private viewProfileEvaluationRepo = AppDataSource.getRepository(viewProfileEvaluation); - private viewProfileEmployeeEvaluationRepo = AppDataSource.getRepository(viewProfileEmployeeEvaluation); + private viewProfileEmployeeEvaluationRepo = AppDataSource.getRepository( + viewProfileEmployeeEvaluation, + ); + @Post("user/reset-password") + async forgetPassword( + @Body() + body: { + username: string; + }, + ) { + const result = await resetPassword(body.username); + if (!result) { + throw new Error("Failed. Cannot change password."); + } + return result; + } + /** * API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize) * @@ -1001,7 +1017,7 @@ export class OrganizationUnauthorizeController extends Controller { where: { current_holders: { orgRootId: rootId } }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -1080,7 +1096,7 @@ export class OrganizationUnauthorizeController extends Controller { where: { current_holders: { orgRootId: rootId } }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, profileInsignias: { receiveDate: "DESC", @@ -1170,7 +1186,6 @@ export class OrganizationUnauthorizeController extends Controller { return new HttpSuccess("Email verified successfully."); } - /** * API ผลการประเมิน 5 ปีย้อนหลังนับจากปีปัจจุบัน * @@ -1208,80 +1223,102 @@ export class OrganizationUnauthorizeController extends Controller { // where:{ // ...condition // } - }) - if(conType == "EMPLOYEE"){ - lists = await this.viewProfileEmployeeEvaluationRepo.find({}) + }); + if (conType == "EMPLOYEE") { + lists = await this.viewProfileEmployeeEvaluationRepo.find({}); } - const groupData: any = {}; + const groupData: any = {}; const year = new Date().getFullYear(); const years = [year, year - 1, year - 2, year - 3, year - 4]; - + lists.forEach((item: any) => { - if (!groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId]) { - groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId] = { - profileId: conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId, - yearAPR1: "-", periodAPR1: "-", resultAPR1: "-", - yearOCT1: "-", periodOCT1: "-", resultOCT1: "-", - yearAPR2: "-", periodAPR2: "-", resultAPR2: "-", - yearOCT2: "-", periodOCT2: "-", resultOCT2: "-", - yearAPR3: "-", periodAPR3: "-", resultAPR3: "-", - yearOCT3: "-", periodOCT3: "-", resultOCT3: "-", - yearAPR4: "-", periodAPR4: "-", resultAPR4: "-", - yearOCT4: "-", periodOCT4: "-", resultOCT4: "-", - yearAPR5: "-", periodAPR5: "-", resultAPR5: "-", - yearOCT5: "-", periodOCT5: "-", resultOCT5: "-" + if (!groupData[conType == "EMPLOYEE" ? item.profileEmployeeId : item.profileId]) { + groupData[conType == "EMPLOYEE" ? item.profileEmployeeId : item.profileId] = { + profileId: conType == "EMPLOYEE" ? item.profileEmployeeId : item.profileId, + yearAPR1: "-", + periodAPR1: "-", + resultAPR1: "-", + yearOCT1: "-", + periodOCT1: "-", + resultOCT1: "-", + yearAPR2: "-", + periodAPR2: "-", + resultAPR2: "-", + yearOCT2: "-", + periodOCT2: "-", + resultOCT2: "-", + yearAPR3: "-", + periodAPR3: "-", + resultAPR3: "-", + yearOCT3: "-", + periodOCT3: "-", + resultOCT3: "-", + yearAPR4: "-", + periodAPR4: "-", + resultAPR4: "-", + yearOCT4: "-", + periodOCT4: "-", + resultOCT4: "-", + yearAPR5: "-", + periodAPR5: "-", + resultAPR5: "-", + yearOCT5: "-", + periodOCT5: "-", + resultOCT5: "-", }; } - const yearIndex = years.indexOf(parseInt(item.year)); + const yearIndex = years.indexOf(parseInt(item.year)); if (yearIndex !== -1) { const yearSuffix = yearIndex + 1; const yearKey = `year${item.period}${yearSuffix}`; const periodKey = `period${item.period}${yearSuffix}`; const resultKey = `result${item.period}${yearSuffix}`; - - groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][yearKey] = item.year; - groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][periodKey] = item.period; - groupData[conType == "EMPLOYEE"?item.profileEmployeeId:item.profileId][resultKey] = item.result; + + groupData[conType == "EMPLOYEE" ? item.profileEmployeeId : item.profileId][yearKey] = + item.year; + groupData[conType == "EMPLOYEE" ? item.profileEmployeeId : item.profileId][periodKey] = + item.period; + groupData[conType == "EMPLOYEE" ? item.profileEmployeeId : item.profileId][resultKey] = + item.result; } }); const formattedResults = Object.values(groupData).map((x: any) => ({ profileId: x.profileId, yearAPR1: x.yearAPR1, periodAPR1: x.periodAPR1, - resultAPR1: x.resultAPR1?Extension.textPoint(x.resultAPR1):"-", + resultAPR1: x.resultAPR1 ? Extension.textPoint(x.resultAPR1) : "-", yearOCT1: x.yearOCT1, periodOCT1: x.periodOCT1, - resultOCT1: x.resultOCT1?Extension.textPoint(x.resultOCT1):"-", + resultOCT1: x.resultOCT1 ? Extension.textPoint(x.resultOCT1) : "-", yearAPR2: x.yearAPR2, periodAPR2: x.periodAPR2, - resultAPR2: x.resultAPR2?Extension.textPoint(x.resultAPR2):"-", + resultAPR2: x.resultAPR2 ? Extension.textPoint(x.resultAPR2) : "-", yearOCT2: x.yearOCT2, periodOCT2: x.periodOCT2, - resultOCT2: x.resultOCT2?Extension.textPoint(x.resultOCT2):"-", + resultOCT2: x.resultOCT2 ? Extension.textPoint(x.resultOCT2) : "-", yearAPR3: x.yearAPR3, periodAPR3: x.periodAPR3, - resultAPR3: x.resultAPR3?Extension.textPoint(x.resultAPR3):"-", + resultAPR3: x.resultAPR3 ? Extension.textPoint(x.resultAPR3) : "-", yearOCT3: x.yearOCT3, periodOCT3: x.periodOCT3, - resultOCT3: x.resultOCT3?Extension.textPoint(x.resultOCT3):"-", + resultOCT3: x.resultOCT3 ? Extension.textPoint(x.resultOCT3) : "-", yearAPR4: x.yearAPR4, periodAPR4: x.periodAPR4, - resultAPR4: x.resultAPR4?Extension.textPoint(x.resultAPR4):"-", + resultAPR4: x.resultAPR4 ? Extension.textPoint(x.resultAPR4) : "-", yearOCT4: x.yearOCT4, periodOCT4: x.periodOCT4, - resultOCT4: x.resultOCT4?Extension.textPoint(x.resultOCT4):"-", + resultOCT4: x.resultOCT4 ? Extension.textPoint(x.resultOCT4) : "-", yearAPR5: x.yearAPR5, periodAPR5: x.periodAPR5, - resultAPR5: x.resultAPR5?Extension.textPoint(x.resultAPR5):"-", + resultAPR5: x.resultAPR5 ? Extension.textPoint(x.resultAPR5) : "-", yearOCT5: x.yearOCT5, periodOCT5: x.periodOCT5, - resultOCT5: x.resultOCT5?Extension.textPoint(x.resultOCT5):"-", + resultOCT5: x.resultOCT5 ? Extension.textPoint(x.resultOCT5) : "-", })); - + return new HttpSuccess(formattedResults); } - // @Patch("retirement") // public async updateStatusRetirement( // @Body() @@ -1306,10 +1343,10 @@ export class OrganizationUnauthorizeController extends Controller { // profiles.push(_profile); // }) // ); - // await this.profileRepo.save(profiles); + // await this.profileRepo.save(profiles); // return new HttpSuccess(); // } - + // @Patch("retirement-employee") // public async updateStatusRetirementEmp( // @Body() @@ -1334,7 +1371,7 @@ export class OrganizationUnauthorizeController extends Controller { // profiles.push(_profile); // }) // ); - // await this.profileEmpRepo.save(profiles); + // await this.profileEmpRepo.save(profiles); // return new HttpSuccess(); // } } diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index a9d160da..ec74fe15 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -137,7 +137,7 @@ export class ProfileController extends Controller { where: { id: id }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, }, }); @@ -225,40 +225,39 @@ export class ProfileController extends Controller { const salary_raw = await this.salaryRepo.find({ select: [ - "date", - "position", + "commandDateAffect", + "positionName", "posNo", "positionType", "positionLevel", "positionSalaryAmount", - "refCommandNo", + "commandNo", "amount", - "templateDoc", - "position", + "remark", "orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4", - "mpCee", "positionExecutive", ], where: { profileId: id }, - order: { date: "ASC" }, + order: { commandDateAffect: "ASC" }, }); const salarys = salary_raw.length > 1 ? salary_raw.slice(1).map((item) => ({ - date: item.date ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.date)) : null, - position: item.position != null ? item.position : "-", + date: item.commandDateAffect + ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.commandDateAffect)) + : null, + position: item.positionName != null ? item.positionName : "-", posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, orgRoot: item.orgRoot, orgChild1: item.orgChild1, orgChild2: item.orgChild2, orgChild3: item.orgChild3, orgChild4: item.orgChild4, - mpCee: item.mpCee, positionExecutive: item.positionExecutive, })) : [ @@ -271,7 +270,7 @@ export class ProfileController extends Controller { orgChild2: null, orgChild3: null, orgChild4: null, - mpCee: null, + positionCee: null, positionExecutive: null, }, ]; @@ -320,8 +319,8 @@ export class ProfileController extends Controller { `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, ), date: - salary_raw.length > 0 && salary_raw[0].date != null - ? Extension.ToThaiNumber(Extension.ToThaiShortDate(salary_raw[0].date)) + salary_raw.length > 0 && salary_raw[0].commandDateAffect != null + ? Extension.ToThaiNumber(Extension.ToThaiShortDate(salary_raw[0].commandDateAffect)) : "", positionName: profile.position != null ? profile.position : "", appointText: @@ -333,12 +332,12 @@ export class ProfileController extends Controller { ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].posNo)) : "", position: - salary_raw.length > 0 && salary_raw[0].position != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].position)) + salary_raw.length > 0 && salary_raw[0].positionName != null + ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionName)) : "", - mpCee: - salary_raw.length > 0 && salary_raw[0].mpCee != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].mpCee)) + positionCee: + salary_raw.length > 0 && salary_raw[0].positionCee != null + ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionCee)) : "", positionExecutive: salary_raw.length > 0 && salary_raw[0].positionExecutive != null @@ -639,15 +638,15 @@ export class ProfileController extends Controller { ]; const salary_raw = await this.salaryRepo.find({ select: [ - "date", - "position", + "commandDateAffect", + "positionName", "posNo", "positionType", "positionLevel", "positionSalaryAmount", - "refCommandNo", + "commandNo", "amount", - "templateDoc", + "remark", ], where: { profileId: id }, order: { order: "ASC" }, @@ -656,15 +655,15 @@ export class ProfileController extends Controller { const salarys = salary_raw.length > 0 ? salary_raw.map((item) => ({ - salaryDate: item.date - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) + salaryDate: item.commandDateAffect + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect)) : null, - position: item.position != null ? Extension.ToThaiNumber(item.position) : null, + position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : 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, + refAll: item.remark ? Extension.ToThaiNumber(item.remark) : null, positionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, positionType: item.positionType ?? null, @@ -2406,11 +2405,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -2446,23 +2447,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -2475,16 +2476,8 @@ export class ProfileController extends Controller { profile.lastUpdatedAt = new Date(); const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - //profile.position, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -2506,9 +2499,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await Promise.all([this.salaryRepo.save(profileSalary)]); } @@ -2527,11 +2528,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -2552,7 +2555,7 @@ export class ProfileController extends Controller { if (!_profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; + let dateLeave_: any = body.commandDateAffect; _profile.isLeave = true; _profile.leaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; @@ -2580,23 +2583,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -2604,15 +2607,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -2634,9 +2630,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await removeProfileInOrganize(profile.id, "OFFICER"); await Promise.all([this.profileRepo.save(_profile), this.salaryRepo.save(profileSalary)]); @@ -2656,11 +2660,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -2681,7 +2687,7 @@ export class ProfileController extends Controller { if (!_profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; + let dateLeave_: any = body.commandDateAffect; _profile.isLeave = true; _profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; _profile.dateLeave = dateLeave_; @@ -2708,23 +2714,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -2732,15 +2738,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -2762,9 +2761,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await removeProfileInOrganize(profile.id, "OFFICER"); await Promise.all([this.profileRepo.save(_profile), this.salaryRepo.save(profileSalary)]); @@ -2784,11 +2791,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -2809,7 +2818,7 @@ export class ProfileController extends Controller { if (!_profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; + let dateLeave_: any = body.commandDateAffect; _profile.isLeave = true; _profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; _profile.dateLeave = dateLeave_; @@ -2836,23 +2845,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -2860,15 +2869,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -2890,9 +2892,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await removeProfileInOrganize(profile.id, "OFFICER"); await Promise.all([this.profileRepo.save(_profile), this.salaryRepo.save(profileSalary)]); @@ -2912,11 +2922,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -2937,7 +2949,7 @@ export class ProfileController extends Controller { if (!_profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; + let dateLeave_: any = body.commandDateAffect; _profile.isLeave = true; _profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ"; _profile.dateLeave = dateLeave_; @@ -2964,23 +2976,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -2988,15 +3000,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -3018,9 +3023,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await removeProfileInOrganize(profile.id, "OFFICER"); await Promise.all([this.profileRepo.save(_profile), this.salaryRepo.save(profileSalary)]); @@ -3040,11 +3053,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -3065,7 +3080,7 @@ export class ProfileController extends Controller { if (!_profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } - let dateLeave_: any = body.date; + let dateLeave_: any = body.commandDateAffect; _profile.isLeave = true; _profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน"; _profile.dateLeave = dateLeave_; @@ -3091,23 +3106,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -3115,15 +3130,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -3145,9 +3153,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await removeProfileInOrganize(profile.id, "OFFICER"); await Promise.all([this.profileRepo.save(_profile), this.salaryRepo.save(profileSalary)]); @@ -3167,11 +3183,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -3212,23 +3230,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -3236,15 +3254,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -3266,9 +3277,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await Promise.all([this.salaryRepo.save(profileSalary)]); @@ -3287,11 +3306,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -3332,23 +3353,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -3356,15 +3377,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -3386,9 +3400,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await Promise.all([this.salaryRepo.save(profileSalary)]); @@ -3407,11 +3429,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -3452,23 +3476,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = @@ -3477,15 +3501,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -3507,9 +3524,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await Promise.all([this.salaryRepo.save(profileSalary)]); @@ -3528,11 +3553,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -3573,23 +3600,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}` : null; let position = profile.current_holders @@ -3597,15 +3624,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -3627,9 +3647,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await Promise.all([this.salaryRepo.save(profileSalary)]); @@ -3648,11 +3676,13 @@ export class ProfileController extends Controller { @Body() body: { profileId: string; - date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + commandNo: string | null; + commandYear: number; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; + commandCode?: string | null; + commandName?: string | null; + remark: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -3693,23 +3723,23 @@ export class ProfileController extends Controller { : 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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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)?.posMasterNo}` + ? `${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}${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.posMasterNo}` + ? `${profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgRoot.orgRootShortName}}` : null; let position = @@ -3718,15 +3748,8 @@ export class ProfileController extends Controller { ?.positions?.filter((pos) => pos.positionIsSelected === true)[0] ?? null; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, - date: body.date, - refCommandNo: body.refCommandNo, - templateDoc: body.salaryRef, - position: profile.position, positionType: profile.posType.posTypeName, positionLevel: profile.posLevel.posLevelName, - posNo: shortName ? shortName : null, - positionLine: position?.positionField ?? null, - positionPathSide: position?.positionArea ?? null, positionExecutive: position?.posExecutive?.posExecutiveName ?? null, amount: profile.amount, positionSalaryAmount: profile.positionSalaryAmount, @@ -3748,9 +3771,17 @@ export class ProfileController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), - refCommandDate: new Date(), - refCommandCode: body.refCommandCode, - refCommandName: body.refCommandName, + positionName: profile.position, + commandNo: body.commandNo, + commandYear: body.commandYear, + posNo: shortName, + posNoAbb: profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) + ?.posMasterNo, + commandDateAffect: body.commandDateAffect, + commandDateSign: body.commandDateSign, + commandCode: body.commandCode, + commandName: body.commandName, + remark: body.remark, }); await Promise.all([this.salaryRepo.save(profileSalary)]); @@ -3770,8 +3801,7 @@ export class ProfileController extends Controller { body: { profileId: string; date: Date | null; - refCommandNo: string | null; - salaryRef: string | null; + commandNo: string | null; }, ) { const profile = await this.profileRepo.findOne({ @@ -4660,7 +4690,7 @@ export class ProfileController extends Controller { @Query() isAll?: boolean, @Query() retireType?: string, @Query() sortBy: string = "current_holders.posMasterNo", - @Query() sort: "ASC"|"DESC" = "ASC", + @Query() sort: "ASC" | "DESC" = "ASC", ) { let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER"); let queryLike = @@ -4794,12 +4824,12 @@ export class ProfileController extends Controller { .andWhere( isRetire != undefined && isRetire != null ? isRetire == false - // ? `profile.dateLeave IS NULL` - ? `profile.isLeave IS FALSE` + ? // ? `profile.dateLeave IS NULL` + `profile.isLeave IS FALSE` : isRetire == true && retireType != undefined && retireType != null - // ? `profile.dateLeave IS NOT NULL AND profile.leaveType = '${retireType}'` - // : `profile.dateLeave IS NOT NULL` - ? `profile.isLeave IS TRUE AND profile.leaveType = '${retireType}'` + ? // ? `profile.dateLeave IS NOT NULL AND profile.leaveType = '${retireType}'` + // : `profile.dateLeave IS NOT NULL` + `profile.isLeave IS TRUE AND profile.leaveType = '${retireType}'` : `profile.isLeave IS TRUE` : "1=1", ) @@ -7471,10 +7501,10 @@ export class ProfileController extends Controller { lastName: item.lastName, position: item.position, idcard: item.citizenId, - refCommandNo: + commandNo: item.profileSalary.sort((a, b) => b.order - a.order).length == 0 ? null - : item.profileSalary.sort((a, b) => b.order - a.order)[0].refCommandNo, + : item.profileSalary.sort((a, b) => b.order - a.order)[0].commandNo, posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName, posTypeName: item.posType == null ? null : item.posType.posTypeName, posNo: posMaster == null ? null : `${posMaster.posMasterNo}${shortName}`, @@ -8650,8 +8680,8 @@ export class ProfileController extends Controller { .createQueryBuilder("profile") .leftJoinAndSelect("profile.profileSalary", "profileSalary") .where("YEAR(profileSalary.date) = :year", { year: body.year }) - .where("profileSalary.refCommandNo LIKE :refCommandNo", { - refCommandNo: `%${body.posno}%`, + .where("profileSalary.commandNo LIKE :commandNo", { + commandNo: `%${body.posno}%`, }) // .andWhere("profileSalary.commandType LIKE :commandType", { // commandType: `${body.commandType}`, @@ -8664,8 +8694,8 @@ export class ProfileController extends Controller { id: _data.id, fullName: `${_data.prefix}${_data.firstName} ${_data.lastName}`, citizenId: _data.citizenId, - posNo: _data.profileSalary.filter((x) => x.id != null)[0].refCommandNo, - position: _data.profileSalary.filter((x) => x.id != null)[0].position, + posNo: _data.profileSalary.filter((x) => x.id != null)[0].commandNo, + position: _data.profileSalary.filter((x) => x.id != null)[0].positionName, })); return new HttpSuccess({ data: _profiles, total }); @@ -8884,7 +8914,7 @@ export class ProfileController extends Controller { }); return { ..._data, - position: salary?.position ?? _null, + position: salary?.positionName ?? _null, posLevelId: level?.id ?? _null, posTypeId: type?.id ?? _null, }; diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 0d39aea0..fbc05caa 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -138,7 +138,7 @@ export class ProfileEmployeeController extends Controller { where: { id: id }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, }, }); @@ -229,39 +229,40 @@ export class ProfileEmployeeController extends Controller { const salary_raw = await this.salaryRepo.find({ select: [ - "date", - "position", + "commandDateAffect", "posNo", "positionType", "positionLevel", "positionSalaryAmount", - "refCommandNo", + "commandNo", "amount", - "templateDoc", - "position", + "remark", + "positionName", "orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4", - "mpCee", + "positionCee", "positionExecutive", ], where: { profileEmployeeId: id }, - order: { date: "ASC" }, + order: { commandDateAffect: "ASC" }, }); const salarys = salary_raw.length > 1 ? salary_raw.slice(1).map((item) => ({ - date: item.date ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.date)) : null, - position: item.position != null ? item.position : "-", + date: item.commandDateAffect + ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.commandDateAffect)) + : null, + position: item.positionName != null ? item.positionName : "-", posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, orgRoot: item.orgRoot, orgChild1: item.orgChild1, orgChild2: item.orgChild2, orgChild3: item.orgChild3, orgChild4: item.orgChild4, - mpCee: item.mpCee, + positionCee: item.positionCee, positionExecutive: item.positionExecutive, })) : [ @@ -274,7 +275,7 @@ export class ProfileEmployeeController extends Controller { orgChild2: null, orgChild3: null, orgChild4: null, - mpCee: null, + positionCee: null, positionExecutive: null, }, ]; @@ -323,8 +324,8 @@ export class ProfileEmployeeController extends Controller { `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, ), date: - salary_raw.length > 0 && salary_raw[0].date != null - ? Extension.ToThaiNumber(Extension.ToThaiShortDate(salary_raw[0].date)) + salary_raw.length > 0 && salary_raw[0].commandDateAffect != null + ? Extension.ToThaiNumber(Extension.ToThaiShortDate(salary_raw[0].commandDateAffect)) : "", positionName: profile.position != null ? profile.position : "", appointText: @@ -336,12 +337,12 @@ export class ProfileEmployeeController extends Controller { ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].posNo)) : "", position: - salary_raw.length > 0 && salary_raw[0].position != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].position)) + salary_raw.length > 0 && salary_raw[0].positionName != null + ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionName)) : "", - mpCee: - salary_raw.length > 0 && salary_raw[0].mpCee != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].mpCee)) + positionCee: + salary_raw.length > 0 && salary_raw[0].positionCee != null + ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionCee)) : "", positionExecutive: salary_raw.length > 0 && salary_raw[0].positionExecutive != null @@ -643,15 +644,15 @@ export class ProfileEmployeeController extends Controller { ]; const salary_raw = await this.salaryRepo.find({ select: [ - "date", - "position", + "commandDateAffect", + "positionName", "posNo", "positionType", "positionLevel", "positionSalaryAmount", - "refCommandNo", + "commandNo", "amount", - "templateDoc", + "remark", ], where: { profileEmployeeId: id }, order: { order: "ASC" }, @@ -660,15 +661,15 @@ export class ProfileEmployeeController extends Controller { const salarys = salary_raw.length > 0 ? salary_raw.map((item) => ({ - SalaryDate: item.date - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) + SalaryDate: item.commandDateAffect + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect)) : null, - Position: item.position != null ? Extension.ToThaiNumber(item.position) : null, + Position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : 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, + RefAll: item.remark ? Extension.ToThaiNumber(item.remark) : null, PositionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, PositionType: item.positionType ?? null, @@ -1705,7 +1706,7 @@ export class ProfileEmployeeController extends Controller { @Query() isAll?: boolean, @Query() retireType?: string, @Query() sortBy: string = "current_holders.posMasterNo", - @Query() sort: "ASC"|"DESC" = "ASC", + @Query() sort: "ASC" | "DESC" = "ASC", ) { let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_EMP"); let queryLike = @@ -4432,7 +4433,7 @@ export class ProfileEmployeeController extends Controller { body: { result: { id: string; - templateDoc: string; + remark: string; amount: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; @@ -4462,7 +4463,7 @@ export class ProfileEmployeeController extends Controller { positionType: profile.posTypeNameTemp, positionLevel: profile.posLevelNameTemp, refCommandNo: v.refCommandNo, - templateDoc: v.templateDoc, + remark: v.remark, }) .then(async () => { profile.statusTemp = "DONE"; diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index d814e787..e0187366 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -133,7 +133,7 @@ export class ProfileEmployeeTempController extends Controller { where: { id: id }, order: { profileSalary: { - date: "DESC", + commandDateAffect: "DESC", }, }, }); @@ -224,38 +224,40 @@ export class ProfileEmployeeTempController extends Controller { const salary_raw = await this.salaryRepo.find({ select: [ - "date", - "position", + "commandDateAffect", + "positionName", "posNo", "positionType", "positionLevel", "positionSalaryAmount", - "refCommandNo", + "commandNo", "amount", - "templateDoc", + "remark", "orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4", - "mpCee", + "positionCee", "positionExecutive", ], where: { profileEmployeeId: id }, - order: { date: "ASC" }, + order: { commandDateAffect: "ASC" }, }); const salarys = salary_raw.length > 1 ? salary_raw.slice(1).map((item) => ({ - date: item.date ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.date)) : null, - position: item.position != null ? item.position : "-", + date: item.commandDateAffect + ? Extension.ToThaiNumber(Extension.ToThaiShortDate(item.commandDateAffect)) + : null, + position: item.positionName != null ? item.positionName : "-", posNo: item.posNo != null ? Extension.ToThaiNumber(item.posNo) : null, orgRoot: item.orgRoot, orgChild1: item.orgChild1, orgChild2: item.orgChild2, orgChild3: item.orgChild3, orgChild4: item.orgChild4, - mpCee: item.mpCee, + positionCee: item.positionCee, positionExecutive: item.positionExecutive, })) : [ @@ -268,7 +270,7 @@ export class ProfileEmployeeTempController extends Controller { orgChild2: null, orgChild3: null, orgChild4: null, - mpCee: null, + positionCee: null, positionExecutive: null, }, ]; @@ -316,8 +318,8 @@ export class ProfileEmployeeTempController extends Controller { `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, ), date: - salary_raw.length > 0 && salary_raw[0].date != null - ? Extension.ToThaiNumber(Extension.ToThaiShortDate(salary_raw[0].date)) + salary_raw.length > 0 && salary_raw[0].commandDateAffect != null + ? Extension.ToThaiNumber(Extension.ToThaiShortDate(salary_raw[0].commandDateAffect)) : "", positionName: profile.position != null ? profile.position : "", appointText: @@ -329,12 +331,12 @@ export class ProfileEmployeeTempController extends Controller { ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].posNo)) : "", position: - salary_raw.length > 0 && salary_raw[0].position != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].position)) + salary_raw.length > 0 && salary_raw[0].positionName != null + ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionName)) : "", - mpCee: - salary_raw.length > 0 && salary_raw[0].mpCee != null - ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].mpCee)) + positionCee: + salary_raw.length > 0 && salary_raw[0].positionCee != null + ? Extension.ToThaiNumber(Extension.ToThaiNumber(salary_raw[0].positionCee)) : "", positionExecutive: salary_raw.length > 0 && salary_raw[0].positionExecutive != null @@ -366,8 +368,10 @@ export class ProfileEmployeeTempController extends Controller { salarys: salarys.map((item) => { return { ...item, - mpCee: - item.mpCee == null ? "" : Extension.ToThaiNumber(Extension.ToThaiNumber(item.mpCee)), + positionCee: + item.positionCee == null + ? "" + : Extension.ToThaiNumber(Extension.ToThaiNumber(item.positionCee)), org: `${item.orgChild4 && item.orgChild4 != "-" ? item.orgChild4 + " " : ""}${item.orgChild3 && item.orgChild3 != "-" ? item.orgChild3 + " " : ""}${item.orgChild2 && item.orgChild2 != "-" ? item.orgChild2 + " " : ""}${item.orgChild1 && item.orgChild1 != "-" ? item.orgChild1 + " " : ""}${item.orgRoot && item.orgRoot != "-" ? item.orgRoot + " " : ""}`, }; }), @@ -638,15 +642,15 @@ export class ProfileEmployeeTempController extends Controller { ]; const salary_raw = await this.salaryRepo.find({ select: [ - "date", - "position", + "commandDateAffect", + "positionName", "posNo", "positionType", "positionLevel", "positionSalaryAmount", - "refCommandNo", + "commandNo", "amount", - "templateDoc", + "remark", ], where: { profileEmployeeId: id }, order: { order: "ASC" }, @@ -655,15 +659,15 @@ export class ProfileEmployeeTempController extends Controller { const salarys = salary_raw.length > 0 ? salary_raw.map((item) => ({ - SalaryDate: item.date - ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.date)) + SalaryDate: item.commandDateAffect + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.commandDateAffect)) : null, - Position: item.position != null ? Extension.ToThaiNumber(item.position) : null, + Position: item.positionName != null ? Extension.ToThaiNumber(item.positionName) : 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, + RefAll: item.remark ? Extension.ToThaiNumber(item.remark) : null, PositionLevel: item.positionLevel != null ? Extension.ToThaiNumber(item.positionLevel) : null, PositionType: item.positionType ?? null, @@ -1820,16 +1824,18 @@ export class ProfileEmployeeTempController extends Controller { let profileSalary; if (profile.profileSalary && profile.profileSalary.length > 0) { profileSalary = profile.profileSalary.reduce((latest, current) => { - return new Date(current.date) > new Date(latest.date) ? current : latest; + return new Date(current.commandDateAffect) > new Date(latest.commandDateAffect) + ? current + : latest; }); } return { id: profile.id, fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, citizenId: profile.citizenId, - position: profileSalary ? profileSalary.position : null, + position: profileSalary ? profileSalary.positionName : null, posNo: profileSalary ? profileSalary.posNo : null, - date: profileSalary ? profileSalary.date : null, + date: profileSalary ? profileSalary.commandDateAffect : null, }; }); @@ -3482,7 +3488,7 @@ export class ProfileEmployeeTempController extends Controller { body: { result: { id: string; - templateDoc: string; + remark: string; amount: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; @@ -3513,7 +3519,7 @@ export class ProfileEmployeeTempController extends Controller { positionType: profile.posTypeNameTemp, positionLevel: profile.posLevelNameTemp, refCommandNo: v.refCommandNo, - templateDoc: v.templateDoc, + remark: v.remark, }) .then(async () => { profile.statusTemp = "DONE"; diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index b83552e3..cbba0397 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -43,6 +43,19 @@ export class ProfileSalaryController extends Controller { return new HttpSuccess(record); } + @Get("position/user") + public async getSalaryPositionUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.salaryRepo.find({ + where: { profileId: profile.id }, + order: { order: "ASC" }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") public async getSalary(@Path() profileId: string, @Request() req: RequestWithUser) { let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER"); @@ -55,6 +68,18 @@ export class ProfileSalaryController extends Controller { return new HttpSuccess(record); } + @Get("position/{profileId}") + public async getPositionSalary(@Path() profileId: string, @Request() req: RequestWithUser) { + let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_OFFICER"); + if (_workflow == false) + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); + const record = await this.salaryRepo.find({ + where: { profileId: profileId }, + order: { order: "ASC" }, + }); + return new HttpSuccess(record); + } + @Get("admin/{profileId}") public async getSalaryAdmin(@Path() profileId: string, @Request() req: RequestWithUser) { let _workflow = await new permission().Workflow(req, profileId, "SYS_SALARY_OFFICER"); @@ -119,7 +144,6 @@ export class ProfileSalaryController extends Controller { createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, - refCommandDate: new Date(), createdAt: new Date(), lastUpdatedAt: new Date(), }; @@ -165,7 +189,6 @@ export class ProfileSalaryController extends Controller { createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, - refCommandDate: new Date(), createdAt: new Date(), lastUpdatedAt: new Date(), }; @@ -210,7 +233,6 @@ export class ProfileSalaryController extends Controller { history.lastUpdateFullName = req.user.name; history.createdUserId = req.user.sub; history.createdFullName = req.user.name; - record.refCommandDate = new Date(); history.createdAt = new Date(); history.lastUpdatedAt = new Date(); diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index 9cb74f29..8294eb34 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -47,6 +47,19 @@ export class ProfileSalaryEmployeeController extends Controller { return new HttpSuccess(record); } + @Get("position/user") + public async getSalaryPositionUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.salaryRepo.find({ + where: { profileEmployeeId: profile.id }, + order: { order: "ASC" }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") public async getSalaryEmployee(@Path() profileId: string, @Request() req: RequestWithUser) { let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP"); @@ -59,6 +72,21 @@ export class ProfileSalaryEmployeeController extends Controller { return new HttpSuccess(record); } + @Get("position/{profileId}") + public async getPositionSalaryEmployee( + @Path() profileId: string, + @Request() req: RequestWithUser, + ) { + let _workflow = await new permission().Workflow(req, profileId, "SYS_REGISTRY_EMP"); + if (_workflow == false) + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); + const record = await this.salaryRepo.find({ + where: { profileEmployeeId: profileId }, + order: { order: "ASC" }, + }); + return new HttpSuccess(record); + } + @Get("admin/{profileId}") public async getSalaryEmployeeAdmin(@Path() profileId: string, @Request() req: RequestWithUser) { let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE"); @@ -130,7 +158,6 @@ export class ProfileSalaryEmployeeController extends Controller { createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, - refCommandDate: new Date(), createdAt: new Date(), lastUpdatedAt: new Date(), }; @@ -180,7 +207,6 @@ export class ProfileSalaryEmployeeController extends Controller { createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, - refCommandDate: new Date(), createdAt: new Date(), lastUpdatedAt: new Date(), }; @@ -230,7 +256,6 @@ export class ProfileSalaryEmployeeController extends Controller { history.lastUpdateFullName = req.user.name; history.createdUserId = req.user.sub; history.createdFullName = req.user.name; - record.refCommandDate = new Date(); history.createdAt = new Date(); history.lastUpdatedAt = new Date(); diff --git a/src/controllers/ProfileSalaryEmployeeTempController.ts b/src/controllers/ProfileSalaryEmployeeTempController.ts index 48d98ad3..f4be602a 100644 --- a/src/controllers/ProfileSalaryEmployeeTempController.ts +++ b/src/controllers/ProfileSalaryEmployeeTempController.ts @@ -122,7 +122,6 @@ export class ProfileSalaryEmployeeTempController extends Controller { createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, - refCommandDate: new Date(), createdAt: new Date(), lastUpdatedAt: new Date(), }; @@ -159,7 +158,6 @@ export class ProfileSalaryEmployeeTempController extends Controller { record.lastUpdateUserId = req.user.sub; record.lastUpdateFullName = req.user.name; record.lastUpdatedAt = new Date(); - record.refCommandDate = new Date(); history.lastUpdateUserId = req.user.sub; history.lastUpdateFullName = req.user.name; history.createdUserId = req.user.sub; diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index e9eeee3f..644031af 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -174,23 +174,31 @@ export class ReportController extends Controller { async registryOfficer( @Query() node?: number, @Query() nodeId?: string, - @Query() posTypeName?: string, - @Query() posLevelName?: string, + @Query() posType?: string, + @Query() posLevel?: string, @Query() position?: string, - @Query() posExecutiveName?: string, + @Query() positionExecutive?: string, @Query() gender?: string, - @Query() relationship?: string, - @Query() degree?: string, - @Query() startDateAppoint?: Date, - @Query() endDateAppoint?: Date, + @Query() status?: string, + @Query() education?: string, + @Query() dateStart?: Date, + @Query() dateEnd?: Date, @Query() ageMin?: number, @Query() ageMax?: number, @Query() isProbation?: boolean, @Query() isRetire?: boolean, + @Query() isRetireLaw?: boolean, @Query() retireType?: string, @Query() sortBy: string = "posMasterNo", @Query() sort: "ASC" | "DESC" = "ASC", ) { + const _null: any = null; + if(!dateStart) { + dateStart = _null + } + if(!dateEnd) { + dateEnd = _null + } if (ageMin && (ageMin < 18 || ageMin > 60)) { throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60"); } @@ -216,23 +224,28 @@ export class ReportController extends Controller { nodeCondition = "registryOfficer.orgChild4Id = :nodeId"; } let dateAppointCondition = "1=1"; - if (startDateAppoint && endDateAppoint) { + if (dateStart && dateEnd) { dateAppointCondition = "DATE(registryOfficer.dateAppoint) >= :startDateAppoint AND DATE(registryOfficer.dateAppoint) <= :endDateAppoint"; - } else if (startDateAppoint) { + } else if (dateStart) { dateAppointCondition = "DATE(registryOfficer.dateAppoint) >= :startDateAppoint"; - } else if (endDateAppoint) { + } else if (dateEnd) { dateAppointCondition = "DATE(registryOfficer.dateAppoint) <= :endDateAppoint"; } const IsLeavecondition = ["registryOfficer.isLeave = :isLeave"]; const parameters: any = { isLeave: isRetire }; - if (retireType && retireType.trim() !== "") { IsLeavecondition.push("registryOfficer.leaveType = :retireType"); parameters.retireType = retireType; } + let retireLawCondition = "1=1"; + if(isRetireLaw) { + retireLawCondition = + "DATE(registryOfficer.dateRetireLaw) >= :startDateRetireLaw AND DATE(registryOfficer.dateRetireLaw) <= :endDateRetireLaw"; + } + const [lists, total] = await AppDataSource.getRepository(viewRegistryOfficer) .createQueryBuilder("registryOfficer") .where(nodeCondition, { @@ -243,66 +256,72 @@ export class ReportController extends Controller { ageMax, }) .andWhere(dateAppointCondition, { - startDateAppoint: startDateAppoint?.toISOString().split("T")[0], - endDateAppoint: endDateAppoint?.toISOString().split("T")[0], + startDateAppoint: dateStart?.toISOString().split("T")[0], + endDateAppoint: dateEnd?.toISOString().split("T")[0], + }) + .andWhere(retireLawCondition, { + startDateRetireLaw: new Date(new Date().getFullYear() - 1, 9, 1, 0, 0, 0, 0)?.toISOString().split("T")[0], + endDateRetireLaw: new Date(new Date().getFullYear(), 8, 30, 23, 59, 59, 999).toISOString().split("T")[0], }) .andWhere("registryOfficer.isProbation = :isProbation", { isProbation: isProbation, }) .andWhere(IsLeavecondition.join(" AND "), parameters) .andWhere( - new Brackets((qb) => { - qb.orWhere( - posTypeName != null && posTypeName != "" - ? "registryOfficer.posTypeName LIKE :posTypeName" - : "1=1", - { - posTypeName: `%${posTypeName}%`, - }, - ); - qb.orWhere( - posLevelName != null && posLevelName != "" - ? "registryOfficer.posLevelName LIKE :posLevelName" - : "1=1", - { - posLevelName: `%${posLevelName}%`, - }, - ); - qb.orWhere( - position != null && position != "" ? "registryOfficer.position LIKE :position" : "1=1", - { - position: `%${position}%`, - }, - ); - qb.orWhere( - posExecutiveName != null && posExecutiveName != "" - ? "registryOfficer.posExecutiveName LIKE :posExecutiveName" - : "1=1", - { - posExecutiveName: `%${posExecutiveName}%`, - }, - ); - qb.orWhere( - gender != null && gender != "" ? "registryOfficer.gender LIKE :gender" : "1=1", - { - gender: `%${gender}%`, - }, - ); - qb.orWhere( - relationship != null && relationship != "" - ? "registryOfficer.relationship LIKE :relationship" - : "1=1", - { - relationship: `%${relationship}%`, - }, - ); - qb.orWhere( - degree != null && degree != "" ? "registryOfficer.degree LIKE :degree" : "1=1", - { - degree: `%${degree}%`, - }, - ); - }), + posType != null && posType != "" + ? "registryOfficer.posTypeName LIKE :posTypeName" + : "1=1", + { + posTypeName: `%${posType}%`, + } + ) + .andWhere( + posLevel != null && posLevel != "" + ? "registryOfficer.posLevelName LIKE :posLevelName" + : "1=1", + { + posLevelName: `%${posLevel}%`, + } + ) + .andWhere( + position != null && position != "" + ? "registryOfficer.position LIKE :position" + : "1=1", + { + position: `%${position}%`, + } + ) + .andWhere( + positionExecutive != null && positionExecutive != "" + ? "registryOfficer.posExecutiveName LIKE :posExecutiveName" + : "1=1", + { + posExecutiveName: `%${positionExecutive}%`, + } + ) + .andWhere( + gender != null && gender != "" + ? "registryOfficer.gender LIKE :gender" + : "1=1", + { + gender: `%${gender}%`, + } + ) + .andWhere( + status != null && status != "" + ? "registryOfficer.relationship LIKE :relationship" + : "1=1", + { + relationship: `%${status}%`, + } + ) + .andWhere( + education != null && education != "" + ? "registryOfficer.degree LIKE :degree" + : "1=1", + { + degree: `%${education}%`, + } ) .orderBy(`registryOfficer.${sortBy}`, sort) .getManyAndCount(); @@ -336,6 +355,8 @@ export class ReportController extends Controller { gender: x.gender, relationship: x.relationship, dateAppoint: x.dateAppoint, + dateRetire: x.dateRetire, + dateRetireLaw: x.dateRetireLaw, birthdate: x.birthdate, degree: x.degree, age: x.age, @@ -469,22 +490,30 @@ export class ReportController extends Controller { async registryEmployee( @Query() node?: number, @Query() nodeId?: string, - @Query() posTypeName?: string, - @Query() posLevelName?: string, + @Query() posType?: string, + @Query() posLevel?: string, @Query() position?: string, @Query() gender?: string, - @Query() relationship?: string, - @Query() degree?: string, - @Query() startDateAppoint?: Date, - @Query() endDateAppoint?: Date, + @Query() status?: string, + @Query() education?: string, + @Query() dateStart?: Date, + @Query() dateEnd?: Date, @Query() isProbation?: boolean, @Query() isRetire?: boolean, + @Query() isRetireLaw?: boolean, @Query() retireType?: string, @Query() ageMin?: number, @Query() ageMax?: number, @Query() sortBy: string = "posMasterNo", @Query() sort: "ASC" | "DESC" = "ASC", ) { + const _null: any = null; + if(!dateStart) { + dateStart = _null + } + if(!dateEnd) { + dateEnd = _null + } if (ageMin && (ageMin < 18 || ageMin > 60)) { throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60"); } @@ -510,22 +539,28 @@ export class ReportController extends Controller { nodeCondition = "registryEmployee.orgChild4Id = :nodeId"; } let dateAppointCondition = "1=1"; - if (startDateAppoint && endDateAppoint) { + if (dateStart && dateEnd) { dateAppointCondition = "DATE(registryEmployee.dateAppoint) >= :startDateAppoint AND DATE(registryEmployee.dateAppoint) <= :endDateAppoint"; - } else if (startDateAppoint) { + } else if (dateStart) { dateAppointCondition = "DATE(registryEmployee.dateAppoint) >= :startDateAppoint"; - } else if (endDateAppoint) { + } else if (dateEnd) { dateAppointCondition = "DATE(registryEmployee.dateAppoint) <= :endDateAppoint"; } const IsLeavecondition = ["registryEmployee.isLeave = :isLeave"]; const parameters: any = { isLeave: isRetire }; - if (retireType && retireType.trim() !== "") { IsLeavecondition.push("registryEmployee.leaveType = :retireType"); parameters.retireType = retireType; } + + let retireLawCondition = "1=1"; + if(isRetireLaw) { + retireLawCondition = + "DATE(registryEmployee.dateRetireLaw) >= :startDateRetireLaw AND DATE(registryEmployee.dateRetireLaw) <= :endDateRetireLaw"; + } + const [lists, total] = await AppDataSource.getRepository(viewRegistryEmployee) .createQueryBuilder("registryEmployee") .where(nodeCondition, { @@ -536,8 +571,12 @@ export class ReportController extends Controller { ageMax, }) .andWhere(dateAppointCondition, { - startDateAppoint: startDateAppoint?.toISOString().split("T")[0], - endDateAppoint: endDateAppoint?.toISOString().split("T")[0], + startDateAppoint: dateStart?.toISOString().split("T")[0], + endDateAppoint: dateEnd?.toISOString().split("T")[0], + }) + .andWhere(retireLawCondition, { + startDateRetireLaw: new Date(new Date().getFullYear() - 1, 9, 1, 0, 0, 0, 0)?.toISOString().split("T")[0], + endDateRetireLaw: new Date(new Date().getFullYear(), 8, 30, 23, 59, 59, 999).toISOString().split("T")[0], }) .andWhere("registryEmployee.isProbation = :isProbation", { isProbation: isProbation, @@ -545,50 +584,52 @@ export class ReportController extends Controller { .andWhere(IsLeavecondition.join(" AND "), parameters) .andWhere("registryEmployee.employeeClass = 'PERM'") .andWhere( - new Brackets((qb) => { - qb.orWhere( - posTypeName != null && posTypeName != "" - ? "registryEmployee.posTypeName LIKE :posTypeName" - : "1=1", - { - posTypeName: `%${posTypeName}%`, - }, - ); - qb.orWhere( - posLevelName != null && posLevelName != "" - ? "registryEmployee.posLevelName LIKE :posLevelName" - : "1=1", - { - posLevelName: `%${posLevelName}%`, - }, - ); - qb.orWhere( - position != null && position != "" ? "registryEmployee.position LIKE :position" : "1=1", - { - position: `%${position}%`, - }, - ); - qb.orWhere( - gender != null && gender != "" ? "registryEmployee.gender LIKE :gender" : "1=1", - { - gender: `%${gender}%`, - }, - ); - qb.orWhere( - relationship != null && relationship != "" - ? "registryEmployee.relationship LIKE :relationship" - : "1=1", - { - relationship: `%${relationship}%`, - }, - ); - qb.orWhere( - degree != null && degree != "" ? "registryEmployee.degree LIKE :degree" : "1=1", - { - degree: `%${degree}%`, - }, - ); - }), + posType != null && posType != "" + ? "registryEmployee.posTypeName LIKE :posTypeName" + : "1=1", + { + posTypeName: `%${posType}%`, + } + ) + .andWhere( + posLevel != null && posLevel != "" + ? "registryEmployee.posLevelName LIKE :posLevelName" + : "1=1", + { + posLevelName: `%${posLevel}%`, + } + ) + .andWhere( + position != null && position != "" + ? "registryEmployee.position LIKE :position" + : "1=1", + { + position: `%${position}%`, + } + ) + .andWhere( + gender != null && gender != "" + ? "registryEmployee.gender LIKE :gender" + : "1=1", + { + gender: `%${gender}%`, + } + ) + .andWhere( + status != null && status != "" + ? "registryEmployee.relationship LIKE :relationship" + : "1=1", + { + relationship: `%${status}%`, + } + ) + .andWhere( + education != null && education != "" + ? "registryEmployee.degree LIKE :degree" + : "1=1", + { + degree: `%${education}%`, + } ) .orderBy(`registryEmployee.${sortBy}`, sort) .getManyAndCount(); @@ -621,6 +662,8 @@ export class ReportController extends Controller { gender: x.gender, relationship: x.relationship, dateAppoint: x.dateAppoint, + dateRetire: x.dateRetire, + dateRetireLaw: x.dateRetireLaw, birthdate: x.birthdate, degree: x.degree, age: x.age, @@ -1583,8 +1626,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -1957,8 +2000,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -2339,8 +2382,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -2737,8 +2780,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -3139,8 +3182,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -3734,8 +3777,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.current_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -4108,8 +4151,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.current_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -4490,8 +4533,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.current_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -4888,8 +4931,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.current_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -5290,8 +5333,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.current_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -5841,8 +5884,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -6033,8 +6076,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -6233,8 +6276,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -6441,8 +6484,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; @@ -6656,8 +6699,8 @@ export class ReportController extends Controller { ) { let _salary: any = posMaster.next_holder.profileSalary.sort( (a, b) => - (b.date == null ? 0 : b.date.getTime()) - - (a.date == null ? 0 : a.date.getTime()), + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), ); if (_salary.length > 0) { salary = _salary[0]; diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index be68be2a..4dd90dbf 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -830,18 +830,4 @@ export class KeycloakController extends Controller { return result; } - @Post("user/reset-password") - async forgetPassword( - @Request() request: { user: { sub: string; preferred_username: string } }, - @Body() - body: { - username: string; - }, - ) { - const result = await resetPassword(body.username); - if (!result) { - throw new Error("Failed. Cannot change password."); - } - return result; - } } diff --git a/src/entities/CommandType.ts b/src/entities/CommandType.ts index 9ffe3162..a9aaa4eb 100644 --- a/src/entities/CommandType.ts +++ b/src/entities/CommandType.ts @@ -30,11 +30,11 @@ export class CommandType extends EntityBase { @Column({ nullable: true, - comment: "รหัสประเภทของคำสั่งแต่งตั้ง", + comment: "รหัสประเภทของคำสั่ง", length: 255, default: null, }) - refCommandCode: string; + commandCode: string; @Column({ nullable: true, diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index edf937aa..d4039270 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -25,11 +25,61 @@ export class ProfileSalary extends EntityBase { profileEmployeeId: string; @Column({ - comment: "วันที่", + nullable: true, + comment: "เรียงลำดับใหมาตามการนำเข้า", + default: null, + }) + order: number; + + @Column({ + nullable: true, + comment: "เลขที่คำสั่ง", + default: null, + }) + commandNo: number; + + @Column({ + nullable: true, + comment: "ปีที่ออกคำสั่ง", + default: null, + }) + commandYear: number; + + @Column({ + comment: "คำสั่งวันที่", type: "datetime", nullable: true, }) - date: Date; + commandDateSign: Date; + + @Column({ + comment: "คำสั่งมีผลวันที่", + type: "datetime", + nullable: true, + }) + commandDateAffect: Date; + + @Column({ + nullable: true, + comment: "รหัสประเภทของคำสั่ง", + default: null, + }) + commandCode: string; + + @Column({ + nullable: true, + comment: "ชื่อประเภทคำสั่ง", + default: null, + }) + commandName: string; + + @Column({ + nullable: true, + length: 40, + comment: "ตัวย่อเลขที่ตำแหน่ง", + default: null, + }) + posNoAbb: string; @Column({ nullable: true, @@ -45,31 +95,7 @@ export class ProfileSalary extends EntityBase { comment: "ตำแหน่ง", default: null, }) - position: string; - - @Column({ - nullable: true, - length: 255, - comment: "สายงาน", - default: null, - }) - positionLine: string; - - @Column({ - nullable: true, - length: 255, - comment: "ด้าน/สาขา", - default: null, - }) - positionPathSide: string; - - @Column({ - nullable: true, - length: 255, - comment: "ตำแหน่งทางการบริหาร", - default: null, - }) - positionExecutive: string; + positionName: string; @Column({ nullable: true, @@ -88,44 +114,11 @@ export class ProfileSalary extends EntityBase { positionLevel: string; @Column({ - comment: "เงินเดือนฐาน", - default: 0, nullable: true, - type: "double", + comment: "ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง", + default: null, }) - amount: Double; - - @Column({ - comment: "เงินพิเศษ", - default: 0, - nullable: true, - type: "double", - }) - amountSpecial: Double; - - @Column({ - comment: "เงินประจำตำแหน่ง", - default: 0, - nullable: true, - type: "double", - }) - positionSalaryAmount: Double; - - @Column({ - comment: "เงินค่าตอบแทนรายเดือน", - default: 0, - nullable: true, - type: "double", - }) - mouthSalaryAmount: Double; - - // @Column({ - // nullable: true, - // comment: "ประเภทคำสั่ง", - // type: "text", - // default: null, - // }) - // commandType: string; + positionCee: string; @Column({ nullable: true, @@ -164,54 +157,51 @@ export class ProfileSalary extends EntityBase { @Column({ nullable: true, - comment: "ระดับ", + length: 255, + comment: "ตำแหน่งทางการบริหาร", default: null, }) - mpCee: string; + positionExecutive: string; + + @Column({ + comment: "เงินเดือนฐาน", + default: 0, + nullable: true, + type: "double", + }) + amount: Double; + + @Column({ + comment: "เงินพิเศษ", + default: 0, + nullable: true, + type: "double", + }) + amountSpecial: Double; + + @Column({ + comment: "เงินประจำตำแหน่ง", + default: 0, + nullable: true, + type: "double", + }) + positionSalaryAmount: Double; + + @Column({ + comment: "เงินค่าตอบแทนรายเดือน", + default: 0, + nullable: true, + type: "double", + }) + mouthSalaryAmount: Double; @Column({ nullable: true, - comment: "รหัสประเภทของคำสั่งแต่งตั้ง", + length: 255, + comment: "หมายเหตุ", default: null, }) - refCommandCode: string; - - @Column({ - nullable: true, - comment: "ชื่อประเภทคำสั่ง", - default: null, - }) - refCommandName: string; - - @Column({ - nullable: true, - comment: "เลขที่คำสั่ง", - type: "text", - default: null, - }) - refCommandNo: string; - - @Column({ - comment: "วันที่ออกคำสั่ง", - type: "datetime", - nullable: true, - }) - refCommandDate: Date; - - @Column({ - nullable: true, - comment: "เอกสารอ้างอิง", - type: "text", - default: null, - }) - templateDoc: string; - - @Column({ - nullable: true, - comment: "ลำดับตำแหน่ง", - default: null, - }) - order: number; + remark: string; @Column({ comment: "วันที่", @@ -253,110 +243,107 @@ export class ProfileSalary extends EntityBase { export class CreateProfileSalary { profileId: string; - date?: Date | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; posNo: string | null; - position: string | null; - positionLine: string | null; - positionPathSide: string | null; + posNoAbb: string | null; + positionName: string | null; positionExecutive: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; commandId?: string | null; - // commandType?: string | null; - templateDoc: string | null; + remark: string | null; isGovernment?: boolean | null; - orgRoot?: string | null; orgChild1?: string | null; orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + positionCee?: string | null; + commandCode?: string | null; + commandName?: string | null; + commandNo?: number | null; + commandYear?: number | null; } export class CreateProfileSalaryEmployee { profileEmployeeId: string | null; - date?: Date | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; amount?: Double | null; amountSpecial?: Double | null; commandId?: string | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; posNo: string | null; - position: string | null; - // positionLine: string | null; - // positionPathSide: string | null; - // positionExecutive: string | null; + posNoAbb: string | null; + positionName: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; - + remark: string | null; orgRoot?: string | null; orgChild1?: string | null; orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + positionCee?: string | null; + commandCode?: string | null; + commandName?: string | null; + commandNo?: number | null; + commandYear?: number | null; } export class UpdateProfileSalaryEmployee { - date?: Date | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; posNo: string | null; - position: string | null; - // positionLine: string | null; - // positionPathSide: string | null; - // positionExecutive: string | null; + posNoAbb: string | null; + positionName: string | null; positionType: string | null; positionLevel: string | null; - refCommandNo: string | null; - templateDoc: string | null; - + remark: string | null; orgRoot?: string | null; orgChild1?: string | null; orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + positionCee?: string | null; + commandCode?: string | null; + commandName?: string | null; + commandNo?: number | null; + commandYear?: number | null; } export type UpdateProfileSalary = { - date?: Date | null; + commandDateAffect?: Date | null; + commandDateSign?: Date | null; amount?: Double | null; amountSpecial?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; posNo?: string | null; - position?: string | null; - positionLine?: string | null; - positionPathSide?: string | null; + posNoAbb: string | null; + positionName: string | null; positionExecutive?: string | null; positionType?: string | null; positionLevel?: string | null; - refCommandNo?: string | null; - templateDoc?: string | null; - + remark?: string | null; orgRoot?: string | null; orgChild1?: string | null; orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + positionCee?: string | null; + commandCode?: string | null; + commandName?: string | null; + commandNo?: number | null; + commandYear?: number | null; }; diff --git a/src/entities/ProfileSalaryHistory.ts b/src/entities/ProfileSalaryHistory.ts index d0ffc6d8..de1c212e 100644 --- a/src/entities/ProfileSalaryHistory.ts +++ b/src/entities/ProfileSalaryHistory.ts @@ -5,19 +5,62 @@ import { Command } from "./Command"; @Entity("profileSalaryHistory") export class ProfileSalaryHistory extends EntityBase { - // @Column({ - // length: 40, - // comment: "คีย์นอก(FK)ของตาราง profile", - // type: "uuid", - // }) - // profileId: string; + @Column({ + nullable: true, + comment: "เรียงลำดับใหมาตามการนำเข้า", + default: null, + }) + order: number; @Column({ - comment: "วันที่", + nullable: true, + comment: "เลขที่คำสั่ง", + default: null, + }) + commandNo: number; + + @Column({ + nullable: true, + comment: "ปีที่ออกคำสั่ง", + default: null, + }) + commandYear: number; + + @Column({ + comment: "คำสั่งวันที่", type: "datetime", nullable: true, }) - date: Date; + commandDateSign: Date; + + @Column({ + comment: "คำสั่งมีผลวันที่", + type: "datetime", + nullable: true, + }) + commandDateAffect: Date; + + @Column({ + nullable: true, + comment: "รหัสประเภทของคำสั่ง", + default: null, + }) + commandCode: string; + + @Column({ + nullable: true, + comment: "ชื่อประเภทคำสั่ง", + default: null, + }) + commandName: string; + + @Column({ + nullable: true, + length: 40, + comment: "ตัวย่อเลขที่ตำแหน่ง", + default: null, + }) + posNoAbb: string; @Column({ nullable: true, @@ -33,31 +76,7 @@ export class ProfileSalaryHistory extends EntityBase { comment: "ตำแหน่ง", default: null, }) - position: string; - - @Column({ - nullable: true, - length: 255, - comment: "สายงาน", - default: null, - }) - positionLine: string; - - @Column({ - nullable: true, - length: 255, - comment: "ด้าน/สาขา", - default: null, - }) - positionPathSide: string; - - @Column({ - nullable: true, - length: 255, - comment: "ตำแหน่งทางการบริหาร", - default: null, - }) - positionExecutive: string; + positionName: string; @Column({ nullable: true, @@ -76,44 +95,11 @@ export class ProfileSalaryHistory extends EntityBase { positionLevel: string; @Column({ - comment: "เงินเดือนฐาน", - default: 0, nullable: true, - type: "double", + comment: "ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง", + default: null, }) - amount: Double; - - @Column({ - comment: "เงินพิเศษ", - default: 0, - nullable: true, - type: "double", - }) - amountSpecial: Double; - - @Column({ - comment: "เงินประจำตำแหน่ง", - default: 0, - nullable: true, - type: "double", - }) - positionSalaryAmount: Double; - - @Column({ - comment: "เงินค่าตอบแทนรายเดือน", - default: 0, - nullable: true, - type: "double", - }) - mouthSalaryAmount: Double; - - // @Column({ - // nullable: true, - // comment: "ประเภทคำสั่ง", - // type: "text", - // default: null, - // }) - // commandType: string; + positionCee: string; @Column({ nullable: true, @@ -152,47 +138,65 @@ export class ProfileSalaryHistory extends EntityBase { @Column({ nullable: true, - comment: "ระดับ", + length: 255, + comment: "ตำแหน่งทางการบริหาร", default: null, }) - mpCee: string; + positionExecutive: string; + + @Column({ + comment: "เงินเดือนฐาน", + default: 0, + nullable: true, + type: "double", + }) + amount: Double; + + @Column({ + comment: "เงินพิเศษ", + default: 0, + nullable: true, + type: "double", + }) + amountSpecial: Double; + + @Column({ + comment: "เงินประจำตำแหน่ง", + default: 0, + nullable: true, + type: "double", + }) + positionSalaryAmount: Double; + + @Column({ + comment: "เงินค่าตอบแทนรายเดือน", + default: 0, + nullable: true, + type: "double", + }) + mouthSalaryAmount: Double; @Column({ nullable: true, - comment: "รหัสประเภทของคำสั่งแต่งตั้ง", + length: 255, + comment: "หมายเหตุ", default: null, }) - refCommandCode: string; + remark: string; @Column({ - nullable: true, - comment: "ชื่อประเภทคำสั่ง", - default: null, - }) - refCommandName: string; - - @Column({ - nullable: true, - comment: "เลขที่คำสั่ง", - type: "text", - default: null, - }) - refCommandNo: string; - - @Column({ - comment: "วันที่ออกคำสั่ง", + comment: "วันที่", type: "datetime", nullable: true, }) - refCommandDate: Date; + dateGovernment: Date; @Column({ nullable: true, - comment: "เอกสารอ้างอิง", - type: "text", + comment: "เข้ารับราชการ", default: null, }) - templateDoc: string; + isGovernment: boolean; @Column({ length: 40, @@ -200,13 +204,6 @@ export class ProfileSalaryHistory extends EntityBase { }) profileSalaryId: string; - @Column({ - nullable: true, - comment: "ลำดับตำแหน่ง", - default: null, - }) - order: number; - @Column({ nullable: true, length: 40, @@ -239,16 +236,16 @@ export class CreateProfileSalaryHistory { positionType: string | null; positionLevel: string | null; refCommandNo: string | null; - templateDoc: string | null; + remark: string | null; orgRoot?: string | null; orgChild1?: string | null; orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + positionCee?: string | null; + commandCode?: string | null; + commandName?: string | null; } export class UpdateProfileSalaryHistory { @@ -265,14 +262,14 @@ export class UpdateProfileSalaryHistory { positionType?: string | null; positionLevel?: string | null; refCommandNo?: string | null; - templateDoc?: string | null; + remark?: string | null; orgRoot?: string | null; orgChild1?: string | null; orgChild2?: string | null; orgChild3?: string | null; orgChild4?: string | null; - mpCee?: string | null; - refCommandCode?: string | null; - refCommandName?: string | null; + positionCee?: string | null; + commandCode?: string | null; + commandName?: string | null; } diff --git a/src/entities/HR_POSITION_OFFICER.ts b/src/entities/positionOfficer.ts similarity index 71% rename from src/entities/HR_POSITION_OFFICER.ts rename to src/entities/positionOfficer.ts index 09312f1a..232b19db 100644 --- a/src/entities/HR_POSITION_OFFICER.ts +++ b/src/entities/positionOfficer.ts @@ -1,13 +1,7 @@ import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; -@Entity("HR_POSITION_OFFICER") -export class HR_POSITION_OFFICER { - @Column({ - nullable: true, - type: "text", - default: null, - }) - CIT: string; +@Entity("positionOfficer") +export class positionOfficer { @PrimaryGeneratedColumn() id!: number; @@ -16,173 +10,175 @@ export class HR_POSITION_OFFICER { type: "text", default: null, }) - FLAG_PERSON_TYPE: string; + citizenId: string; @Column({ nullable: true, type: "text", default: null, }) - MP_POS_DATE: string; + flag_person_type: string; @Column({ nullable: true, type: "text", default: null, }) - SALARY: string; + order_move_position: number; @Column({ nullable: true, type: "text", default: null, }) - MP_COMMAND_NUM: string; + pos_num_code_sit: string; @Column({ nullable: true, type: "text", default: null, }) - POS_NUM_NAME: string; + pos_num_code_sit_abb: string; + + @Column({ + nullable: true, + default: null, + }) + mp_command_num: number; + + @Column({ + nullable: true, + default: null, + }) + cur_year: number; + + @Column({ + nullable: true, + default: null, + }) + mp_command_date: Date; + + @Column({ + nullable: true, + default: null, + }) + mp_pos_date: Date; @Column({ nullable: true, type: "text", default: null, }) - POS_NUM_CODE: string; + flag_to_name_code: string; @Column({ nullable: true, type: "text", default: null, }) - FLAG_TO_NAME: string; + flag_to_name: string; @Column({ nullable: true, type: "text", default: null, }) - WORK_LINE_NAME: string; + pos_num_name: string; @Column({ nullable: true, type: "text", default: null, }) - SPECIALIST_NAME: string; + pos_num_code: string; @Column({ nullable: true, type: "text", default: null, }) - ADMIN_NAME: string; + work_line_name: string; @Column({ nullable: true, type: "text", default: null, }) - REMARK: string; + mp_cee: string; @Column({ nullable: true, type: "text", default: null, }) - ORDER_MOVE_POSITION: string; + job_name: string; @Column({ nullable: true, type: "text", default: null, }) - MP_COMMAND_DATE: string; + section_name: string; @Column({ nullable: true, type: "text", default: null, }) - FLAG_TO_NAME_CODE: string; + division_name: string; @Column({ nullable: true, type: "text", default: null, }) - JOB_NAME: string; + department_code: string; @Column({ nullable: true, type: "text", default: null, }) - SECTION_NAME: string; + department_name: string; @Column({ nullable: true, type: "text", default: null, }) - DIVISION_NAME: string; + admin_name: string; + + @Column({ + nullable: true, + default: null, + }) + salary: number; @Column({ nullable: true, type: "text", default: null, }) - DEPARTMENT_NAME: string; + remark: string; @Column({ nullable: true, type: "text", default: null, }) - DEPARTMENT_CODE: string; + sal_pos_amount_1: string; @Column({ nullable: true, type: "text", default: null, }) - MP_CEE: string; + sal_pos_amount_2: string; @Column({ nullable: true, type: "text", default: null, }) - SAL_POS_AMOUNT_1: string; - - @Column({ - nullable: true, - type: "text", - default: null, - }) - SAL_POS_AMOUNT_2: string; - - @Column({ - nullable: true, - type: "text", - default: null, - }) - SPECIAL_AMT: string; - - @Column({ - nullable: true, - type: "text", - default: null, - }) - USER_CREATE: string; - - @Column({ - nullable: true, - type: "text", - default: null, - }) - USER_UPDATE: string; + special_amt: string; } diff --git a/src/entities/view/viewRegistryEmployee.ts b/src/entities/view/viewRegistryEmployee.ts index c2d46732..c27f869c 100644 --- a/src/entities/view/viewRegistryEmployee.ts +++ b/src/entities/view/viewRegistryEmployee.ts @@ -47,7 +47,7 @@ import { ViewColumn, ViewEntity } from "typeorm"; ed.degree, ed.profileEmployeeId, ed.level, - ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level DESC) AS ed_number + ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level ASC) AS ed_number FROM profileEducation ed WHERE ed.isUse IS TRUE ORDER BY ed.level ASC @@ -85,10 +85,12 @@ import { ViewColumn, ViewEntity } from "typeorm"; pm.searchShortName, p.position, posType.posTypeName, - posLevel.posLevelName, + CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) AS "posLevelName", p.gender, p.relationship, p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, p.birthdate, ed.degree, TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age @@ -183,6 +185,12 @@ export class viewRegistryEmployee { @ViewColumn() dateAppoint: Date; + + @ViewColumn() + dateRetire: Date; + + @ViewColumn() + dateRetireLaw: Date; @ViewColumn() birthdate: Date; diff --git a/src/entities/view/viewRegistryOfficer.ts b/src/entities/view/viewRegistryOfficer.ts index e52aa7dc..b60ed1cb 100644 --- a/src/entities/view/viewRegistryOfficer.ts +++ b/src/entities/view/viewRegistryOfficer.ts @@ -51,7 +51,7 @@ import { ViewColumn, ViewEntity } from "typeorm"; ed.degree, ed.profileId, ed.level, - ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level DESC) AS ed_number + ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level ASC) AS ed_number FROM profileEducation ed WHERE ed.isUse IS TRUE ORDER BY ed.level ASC @@ -93,6 +93,8 @@ import { ViewColumn, ViewEntity } from "typeorm"; p.gender, p.relationship, p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, p.birthdate, ed.degree, TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age @@ -191,6 +193,12 @@ export class viewRegistryOfficer { @ViewColumn() dateAppoint: Date; + @ViewColumn() + dateRetire: Date; + + @ViewColumn() + dateRetireLaw: Date; + @ViewColumn() birthdate: Date; diff --git a/src/interfaces/functionMain.ts b/src/interfaces/functionMain.ts index 7c6fef4c..25f6a1bf 100644 --- a/src/interfaces/functionMain.ts +++ b/src/interfaces/functionMain.ts @@ -34,7 +34,6 @@ class FunctionMain { createdFullName: req.user.name, lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, - refCommandDate: new Date(), createdAt: new Date(), lastUpdatedAt: new Date(), }; diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index e112e9c7..183561b1 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -51,7 +51,7 @@ export async function calculateGovAge(profileId: string, type: string) { where: { [isEmployee ? "profileEmployeeId" : "profileId"]: profileId, }, - select: ["date", "dateGovernment", "isGovernment"], + select: ["commandDateAffect", "dateGovernment", "isGovernment"], order: { order: "ASC" }, }); diff --git a/src/keycloak/index.ts b/src/keycloak/index.ts index 26701940..1297b70f 100644 --- a/src/keycloak/index.ts +++ b/src/keycloak/index.ts @@ -4,6 +4,8 @@ const KC_URL = process.env.KC_URL; const KC_REALMS = process.env.KC_REALMS; const KC_CLIENT_ID = process.env.KC_SERVICE_ACCOUNT_CLIENT_ID; const KC_SECRET = process.env.KC_SERVICE_ACCOUNT_SECRET; +const AUTH_ACCOUNT_SECRET = process.env.AUTH_ACCOUNT_SECRET +const API_KEY = process.env.API_KEY let token: string | null = null; let decoded: DecodedJwt | null = null; @@ -765,9 +767,31 @@ export async function changeUserPassword(userId: string, newPassword: string) { // Function to reset password export async function resetPassword(username: string) { try { + // if (!API_KEY || !AUTH_ACCOUNT_SECRET) { + // throw new Error("KC_CLIENT_ID and KC_SECRET are required to used this feature."); + // } + // const body = new URLSearchParams(); + // body.append("client_id", "gettoken"); + // body.append("client_secret", AUTH_ACCOUNT_SECRET?.toString()); + // body.append("grant_type", "client_credentials"); + // const tokenResponse = await fetch(`${process.env.KC_URL}/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`, { + // method: "POST", + // headers: { + // "Content-Type": "application/x-www-form-urlencoded", + // api_key: API_KEY, + // }, + // body: body + // }); + // if (!tokenResponse.ok) { + // throw new Error("Failed to get admin token"); + // } + // const tokenData = await tokenResponse.json(); + // const adminToken = tokenData.access_token; + const users = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users?email=${encodeURIComponent(username)}`, { headers: { "authorization": `Bearer ${await getToken()}`, + // "authorization": `Bearer ${adminToken}`, "content-type": `application/json`, }, }); @@ -780,6 +804,7 @@ export async function resetPassword(username: string) { method: "PUT", headers: { "Authorization": `Bearer ${await getToken()}`, + // "Authorization": `Bearer ${adminToken}`, "Content-Type": "application/json" }, body: JSON.stringify(["UPDATE_PASSWORD"]) diff --git a/src/migration/1740139573883-updateprofilesalaryaddmis.ts b/src/migration/1740139573883-updateprofilesalaryaddmis.ts new file mode 100644 index 00000000..9618d258 --- /dev/null +++ b/src/migration/1740139573883-updateprofilesalaryaddmis.ts @@ -0,0 +1,108 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Updateprofilesalaryaddmis1740139573883 implements MigrationInterface { + name = 'Updateprofilesalaryaddmis1740139573883' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandType\` CHANGE \`refCommandCode\` \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่งแต่งตั้ง'`); + await queryRunner.query(`CREATE TABLE \`positionOfficer\` (\`id\` int NOT NULL AUTO_INCREMENT, \`citizenId\` text NULL, \`flag_person_type\` text NULL, \`order_move_position\` text NULL, \`pos_num_code_sit\` text NULL, \`pos_num_code_sit_abb\` text NULL, \`mp_command_num\` int NULL, \`cur_year\` int NULL, \`mp_command_date\` datetime NULL, \`mp_pos_date\` datetime NULL, \`flag_to_name_code\` text NULL, \`flag_to_name\` text NULL, \`pos_num_name\` text NULL, \`pos_num_code\` text NULL, \`work_line_name\` text NULL, \`mp_cee\` text NULL, \`job_name\` text NULL, \`section_name\` text NULL, \`division_name\` text NULL, \`department_code\` text NULL, \`department_name\` text NULL, \`admin_name\` text NULL, \`salary\` int NULL, \`remark\` text NULL, \`sal_pos_amount_1\` text NULL, \`sal_pos_amount_2\` text NULL, \`special_amt\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`date\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`mpCee\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`position\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`positionLine\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`positionPathSide\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`refCommandCode\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`refCommandDate\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`refCommandName\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`refCommandNo\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`templateDoc\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`date\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`mpCee\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`position\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`positionLine\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`positionPathSide\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`refCommandCode\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`refCommandDate\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`refCommandName\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`refCommandNo\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`templateDoc\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`commandNo\` int NULL COMMENT 'เลขที่คำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`commandYear\` int NULL COMMENT 'ปีที่ออกคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`commandDateSign\` datetime NULL COMMENT 'คำสั่งวันที่'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`commandDateAffect\` datetime NULL COMMENT 'คำสั่งมีผลวันที่'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`commandName\` varchar(255) NULL COMMENT 'ชื่อประเภทคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`posNoAbb\` varchar(40) NULL COMMENT 'ตัวย่อเลขที่ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`positionName\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`positionCee\` varchar(255) NULL COMMENT 'ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`remark\` varchar(255) NULL COMMENT 'หมายเหตุ'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`dateGovernment\` datetime NULL COMMENT 'วันที่'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`isGovernment\` tinyint NULL COMMENT 'เข้ารับราชการ'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`commandNo\` int NULL COMMENT 'เลขที่คำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`commandYear\` int NULL COMMENT 'ปีที่ออกคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`commandDateSign\` datetime NULL COMMENT 'คำสั่งวันที่'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`commandDateAffect\` datetime NULL COMMENT 'คำสั่งมีผลวันที่'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`commandName\` varchar(255) NULL COMMENT 'ชื่อประเภทคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`posNoAbb\` varchar(40) NULL COMMENT 'ตัวย่อเลขที่ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`positionName\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`positionCee\` varchar(255) NULL COMMENT 'ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`remark\` varchar(255) NULL COMMENT 'หมายเหตุ'`); + await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`commandCode\``); + await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` CHANGE \`order\` \`order\` int NULL COMMENT 'เรียงลำดับใหมาตามการนำเข้า'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`order\` \`order\` int NULL COMMENT 'เรียงลำดับใหมาตามการนำเข้า'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`order\` \`order\` int NULL COMMENT 'ลำดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` CHANGE \`order\` \`order\` int NULL COMMENT 'ลำดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`commandCode\``); + await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่งแต่งตั้ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`remark\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`positionCee\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`positionName\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`posNoAbb\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`commandName\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`commandCode\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`commandDateAffect\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`commandDateSign\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`commandYear\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`commandNo\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`isGovernment\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`dateGovernment\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`remark\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`positionCee\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`positionName\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`posNoAbb\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`commandName\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`commandCode\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`commandDateAffect\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`commandDateSign\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`commandYear\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`commandNo\``); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`templateDoc\` text NULL COMMENT 'เอกสารอ้างอิง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`refCommandNo\` text NULL COMMENT 'เลขที่คำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`refCommandName\` varchar(255) NULL COMMENT 'ชื่อประเภทคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`refCommandDate\` datetime NULL COMMENT 'วันที่ออกคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`refCommandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่งแต่งตั้ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`positionPathSide\` varchar(255) NULL COMMENT 'ด้าน/สาขา'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`positionLine\` varchar(255) NULL COMMENT 'สายงาน'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`mpCee\` varchar(255) NULL COMMENT 'ระดับ'`); + await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`date\` datetime NULL COMMENT 'วันที่'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`templateDoc\` text NULL COMMENT 'เอกสารอ้างอิง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`refCommandNo\` text NULL COMMENT 'เลขที่คำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`refCommandName\` varchar(255) NULL COMMENT 'ชื่อประเภทคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`refCommandDate\` datetime NULL COMMENT 'วันที่ออกคำสั่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`refCommandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่งแต่งตั้ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`positionPathSide\` varchar(255) NULL COMMENT 'ด้าน/สาขา'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`positionLine\` varchar(255) NULL COMMENT 'สายงาน'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`mpCee\` varchar(255) NULL COMMENT 'ระดับ'`); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`date\` datetime NULL COMMENT 'วันที่'`); + await queryRunner.query(`DROP TABLE \`positionOfficer\``); + await queryRunner.query(`ALTER TABLE \`commandType\` CHANGE \`commandCode\` \`refCommandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่งแต่งตั้ง'`); + } + +} diff --git a/src/migration/1740366319309-update2242025.ts b/src/migration/1740366319309-update2242025.ts new file mode 100644 index 00000000..bbcd2248 --- /dev/null +++ b/src/migration/1740366319309-update2242025.ts @@ -0,0 +1,246 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Update22420251740366319309 implements MigrationInterface { + name = 'Update22420251740366319309' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`idOFFICER\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP PRIMARY KEY`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ID\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RANK_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TYPE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_YEAR\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETURN_OCCUPY_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FORCE_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UPCLASS_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FUND_COURSE_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`EDUCATION_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MAJOR_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MAJOR_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UNIVER_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POSITION_CATG\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ADMIN_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ADMIN_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_2\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIALIST_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIALIST_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME_1\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_1\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ADMIN_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_ADD\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_PERCENT\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_AMT\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`PAYMENT_AMT\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`PAYMENT_PERCENT\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_1\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`COST_LIVING_AMOUNT\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`DEPARTMENT_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`DIVISION_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SECTION_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`JOB_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_CUR_ST\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_NUM\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_POS_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_YEAR\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_MP_YEAR\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_CODE_1\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CUR_YEAR\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_ABB\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CONTENT_NO\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_ABB_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_NUM_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CUR_YEAR_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_YEAR_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_DATE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_POS_DATE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_1_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_AMT_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_ADD_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_CODE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`GROUPWORK_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_CODE_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_NAME_O\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_RETIRE_STATUS\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MARRIAGE_STATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SUN_NO\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETIRE_TYPE_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETIRE_POS_NO\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`DEXPIRE_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`HELP_LIVING_AMOUNT\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_DEPARTMENT_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_DIVISION_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_SECTION_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_JOB_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CREATE_DATE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UPDATE_DATE\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` DROP COLUMN \`STREET\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` DROP COLUMN \`TEL\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` DROP COLUMN \`CONTACT_STREET\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` DROP COLUMN \`CONTACT_TEL\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` DROP COLUMN \`FATHER_RANK_CODE\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` DROP COLUMN \`MOTHER_RANK_CODE\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` DROP COLUMN \`SPOUSE_RANK_CODE\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` DROP COLUMN \`LIFE_SPOUSE\``); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` DROP COLUMN \`SUN_NO\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`FLAG_EDUCATION\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`MAJOR_CODE\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`MINOR_CODE\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`FUND_COURSE_CODE\``); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`id\` int NOT NULL PRIMARY KEY AUTO_INCREMENT`); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`id\``); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`id\` int NOT NULL PRIMARY KEY AUTO_INCREMENT`); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`order_move_position\``); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`order_move_position\` text NULL`); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`EDUCATION_SEQ\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`EDUCATION_SEQ\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`EDUCATION_SEQ\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`EDUCATION_SEQ\` varchar(255) NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` DROP COLUMN \`EDUCATION_SEQ\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`EDUCATION_SEQ\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`EDUCATION_SEQ\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`EDUCATION_SEQ\` text NULL`); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`order_move_position\``); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`order_move_position\` int NULL`); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`id\``); + await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`id\` int NOT NULL DEFAULT '0'`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`id\``); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`FUND_COURSE_CODE\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`MINOR_CODE\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`MAJOR_CODE\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_EDUCATION_EMP\` ADD \`FLAG_EDUCATION\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` ADD \`SUN_NO\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` ADD \`LIFE_SPOUSE\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` ADD \`SPOUSE_RANK_CODE\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` ADD \`MOTHER_RANK_CODE\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_FAMILY\` ADD \`FATHER_RANK_CODE\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` ADD \`CONTACT_TEL\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` ADD \`CONTACT_STREET\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` ADD \`TEL\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`HR_PERSONAL_EMP_ADDRESS\` ADD \`STREET\` mediumtext NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UPDATE_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CREATE_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_JOB_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_SECTION_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_DIVISION_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_DEPARTMENT_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`HELP_LIVING_AMOUNT\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`DEXPIRE_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETIRE_POS_NO\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETIRE_TYPE_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SUN_NO\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MARRIAGE_STATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_RETIRE_STATUS\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_NAME_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_CODE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`GROUPWORK_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_CODE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_ADD_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_AMT_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_CODE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG_1_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_POS_DATE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_DATE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME_CODE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_YEAR_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CUR_YEAR_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_NUM_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_ABB_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_O\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CONTENT_NO\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_ABB\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CUR_YEAR\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_CODE_1\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_MP_YEAR\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_YEAR\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_POS_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_NUM\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_CUR_ST\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`JOB_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SECTION_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`DIVISION_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`DEPARTMENT_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`COST_LIVING_AMOUNT\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG_1\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`PAYMENT_PERCENT\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`PAYMENT_AMT\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_AMT\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_PERCENT\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_ADD\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ADMIN_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SAL_POS_AMOUNT_1\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_ABB_NAME_1\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIALIST_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIALIST_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SAL_POS_AMOUNT_2\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_ABB_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ADMIN_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ADMIN_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POSITION_CATG\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UNIVER_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MAJOR_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MAJOR_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`EDUCATION_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FUND_COURSE_NAME\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UPCLASS_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FORCE_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETURN_OCCUPY_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_YEAR\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_DATE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TYPE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RANK_CODE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ID\` varchar(13) NOT NULL`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD PRIMARY KEY (\`ID\`)`); + await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`idOFFICER\` int NULL`); + } + +} diff --git a/src/migration/1740373723906-updateViewRegistryOfficerAndEmployee.ts b/src/migration/1740373723906-updateViewRegistryOfficerAndEmployee.ts new file mode 100644 index 00000000..594497a6 --- /dev/null +++ b/src/migration/1740373723906-updateViewRegistryOfficerAndEmployee.ts @@ -0,0 +1,424 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateViewRegistryOfficerAndEmployee1740373723906 implements MigrationInterface { + name = 'UpdateViewRegistryOfficerAndEmployee1740373723906' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_employee","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_employee\``); + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_officer\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP FOREIGN KEY \`FK_f1ded3e1f83ab2437f739a14f38\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD CONSTRAINT \`FK_f1ded3e1f83ab2437f739a14f38\` FOREIGN KEY (\`profileSalaryId\`) REFERENCES \`profileSalary\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`CREATE VIEW \`view_registry_officer\` AS + WITH Position AS ( + SELECT + posExecutive.posExecutiveName, + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM position pn + LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + pn.posExecutiveName, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM posMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE + orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level DESC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + pm.posExecutiveName, + p.position, + posType.posTypeName, + posLevel.posLevelName, + p.gender, + p.relationship, + p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profile p + LEFT JOIN posLevel ON p.posLevelId = posLevel.id + LEFT JOIN posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1 + `); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM position pn\n LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n pn.posExecutiveName,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM posMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE \n orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level DESC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n pm.posExecutiveName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profile p\n LEFT JOIN posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1"]); + await queryRunner.query(`CREATE VIEW \`view_registry_employee\` AS + WITH Position AS ( + SELECT + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM employeePosition pn + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM employeePosMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileEmployeeId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level DESC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileEmployeeId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + p.employeeClass, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + p.position, + posType.posTypeName, + posLevel.posLevelName, + p.gender, + p.relationship, + p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profileEmployee p + LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id + LEFT JOIN employeePosType posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1 + `); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_employee","WITH Position AS (\n SELECT \n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM employeePosition pn\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM employeePosMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileEmployeeId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level DESC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileEmployeeId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n p.employeeClass,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profileEmployee p\n LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN employeePosType posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_employee","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_employee\``); + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_officer\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP FOREIGN KEY \`FK_f1ded3e1f83ab2437f739a14f38\``); + await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD CONSTRAINT \`FK_f1ded3e1f83ab2437f739a14f38\` FOREIGN KEY (\`profileSalaryId\`) REFERENCES \`profileSalary\`(\`id\`) ON DELETE RESTRICT ON UPDATE RESTRICT`); + await queryRunner.query(`CREATE VIEW \`view_registry_officer\` AS WITH Position AS ( + SELECT + posExecutive.posExecutiveName, + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM position pn + LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + pn.posExecutiveName, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM posMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE + orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level DESC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + pm.posExecutiveName, + p.position, + posType.posTypeName, + posLevel.posLevelName, + p.gender, + p.relationship, + p.dateAppoint, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profile p + LEFT JOIN posLevel ON p.posLevelId = posLevel.id + LEFT JOIN posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM position pn\n LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n pn.posExecutiveName,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM posMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE \n orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level DESC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n pm.posExecutiveName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profile p\n LEFT JOIN posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1"]); + await queryRunner.query(`CREATE VIEW \`view_registry_employee\` AS WITH Position AS ( + SELECT + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM employeePosition pn + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM employeePosMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileEmployeeId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level DESC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileEmployeeId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + p.employeeClass, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + p.position, + posType.posTypeName, + posLevel.posLevelName, + p.gender, + p.relationship, + p.dateAppoint, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profileEmployee p + LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id + LEFT JOIN employeePosType posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_employee","WITH Position AS (\n SELECT \n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM employeePosition pn\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM employeePosMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileEmployeeId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level DESC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileEmployeeId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n p.employeeClass,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profileEmployee p\n LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN employeePosType posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1"]); + } + +} diff --git a/src/migration/1740382878673-updateViewRegistryEmployee.ts b/src/migration/1740382878673-updateViewRegistryEmployee.ts new file mode 100644 index 00000000..e0b4c4f9 --- /dev/null +++ b/src/migration/1740382878673-updateViewRegistryEmployee.ts @@ -0,0 +1,424 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateViewRegistryEmployee1740382878673 implements MigrationInterface { + name = 'UpdateViewRegistryEmployee1740382878673' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_employee","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_employee\``); + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_officer\``); + await queryRunner.query(`CREATE VIEW \`view_registry_officer\` AS + WITH Position AS ( + SELECT + posExecutive.posExecutiveName, + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM position pn + LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + pn.posExecutiveName, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM posMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE + orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level ASC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + pm.posExecutiveName, + p.position, + posType.posTypeName, + posLevel.posLevelName, + p.gender, + p.relationship, + p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profile p + LEFT JOIN posLevel ON p.posLevelId = posLevel.id + LEFT JOIN posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1 + `); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM position pn\n LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n pn.posExecutiveName,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM posMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE \n orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level ASC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n pm.posExecutiveName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profile p\n LEFT JOIN posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1"]); + await queryRunner.query(`CREATE VIEW \`view_registry_employee\` AS + WITH Position AS ( + SELECT + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM employeePosition pn + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM employeePosMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileEmployeeId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level ASC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileEmployeeId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + p.employeeClass, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + p.position, + posType.posTypeName, + CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) AS "posLevelName", + p.gender, + p.relationship, + p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profileEmployee p + LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id + LEFT JOIN employeePosType posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1 + `); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_employee","WITH Position AS (\n SELECT \n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM employeePosition pn\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM employeePosMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileEmployeeId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level ASC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileEmployeeId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n p.employeeClass,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n p.position,\n posType.posTypeName,\n CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) AS \"posLevelName\",\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profileEmployee p\n LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN employeePosType posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1"]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_employee","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_employee\``); + await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","bma_ehr_organization_demo"]); + await queryRunner.query(`DROP VIEW \`view_registry_officer\``); + await queryRunner.query(`CREATE VIEW \`view_registry_officer\` AS WITH Position AS ( + SELECT + posExecutive.posExecutiveName, + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM position pn + LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + pn.posExecutiveName, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM posMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE + orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level DESC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + pm.posExecutiveName, + p.position, + posType.posTypeName, + posLevel.posLevelName, + p.gender, + p.relationship, + p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profile p + LEFT JOIN posLevel ON p.posLevelId = posLevel.id + LEFT JOIN posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM position pn\n LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n pn.posExecutiveName,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM posMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE \n orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level DESC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n pm.posExecutiveName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profile p\n LEFT JOIN posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1"]); + await queryRunner.query(`CREATE VIEW \`view_registry_employee\` AS WITH Position AS ( + SELECT + pn.posMasterId, + ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number + FROM employeePosition pn + WHERE pn.positionIsSelected IS TRUE + ), + PosMaster AS ( + SELECT + pm.current_holderId, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + orgRoot.orgRootName, + orgChild1.orgChild1Name, + orgChild2.orgChild2Name, + orgChild3.orgChild3Name, + orgChild4.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo) + WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo) + ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo) + END AS searchShortName, + ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number + FROM employeePosMaster pm + LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId + LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId + LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id + LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id + LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id + LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id + LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1 + WHERE orgRevision.orgRevisionIsCurrent IS TRUE + AND orgRevision.orgRevisionIsDraft IS FALSE + ), + Education AS ( + SELECT + ed.degree, + ed.profileEmployeeId, + ed.level, + ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level DESC) AS ed_number + FROM profileEducation ed + WHERE ed.isUse IS TRUE + ORDER BY ed.level ASC + ) + SELECT + p.id as profileEmployeeId, + p.citizenId, + p.rank, + p.prefix, + p.firstName, + p.lastName, + p.isProbation, + p.isLeave, + p.isRetirement, + p.leaveType, + p.employeeClass, + pm.posMasterNo, + pm.orgRootId, + pm.orgChild1Id, + pm.orgChild2Id, + pm.orgChild3Id, + pm.orgChild4Id, + pm.orgRootName, + pm.orgChild1Name, + pm.orgChild2Name, + pm.orgChild3Name, + pm.orgChild4Name, + CASE + WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName + WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName) + END AS org, + pm.searchShortName, + p.position, + posType.posTypeName, + CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) AS "posLevelName", + p.gender, + p.relationship, + p.dateAppoint, + p.dateRetire, + p.dateRetireLaw, + p.birthdate, + ed.degree, + TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age + FROM profileEmployee p + LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id + LEFT JOIN employeePosType posType ON p.posTypeId = posType.id + LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1 + LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1`); + await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_employee","WITH Position AS (\n SELECT \n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM employeePosition pn\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM employeePosMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileEmployeeId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileEmployeeId ORDER BY ed.level DESC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileEmployeeId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n p.employeeClass,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n p.position,\n posType.posTypeName,\n CONCAT(posType.posTypeShortName, ' ', posLevel.posLevelName) AS \"posLevelName\",\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profileEmployee p\n LEFT JOIN employeePosLevel posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN employeePosType posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileEmployeeId AND ed.ed_number = 1"]); + } + +} diff --git a/src/services/rabbitmq.ts b/src/services/rabbitmq.ts index 1035e842..7b1d35dd 100644 --- a/src/services/rabbitmq.ts +++ b/src/services/rabbitmq.ts @@ -42,7 +42,7 @@ export async function init() { console.log("[AMQ] Listening for message..."); createConsumer(queue, channel, handler), //----> (3) Process Consumer - createConsumer(queue_org, channel, handler_org); + createConsumer(queue_org, channel, handler_org); // createConsumer(queue2, channel, handler2); } @@ -93,17 +93,18 @@ async function handler(msg: amqp.ConsumeMessage): Promise { .filter((x) => x.refId != null) .map((x) => ({ refId: x.refId, - commandAffectDate: command.commandAffectDate, commandNo: command.commandNo, commandYear: command.commandYear, commandId: command.id, - templateDoc: command.positionDetail, + remark: command.positionDetail, amount: x.amount, amountSpecial: x.amountSpecial, positionSalaryAmount: x.positionSalaryAmount, mouthSalaryAmount: x.mouthSalaryAmount, - refCommandCode: command.commandType.refCommandCode, - refCommandName: command.commandType.name, + commandCode: command.commandType.commandCode, + commandName: command.commandType.name, + commandDateAffect: command.commandExcecuteDate, + commandDateSign: command.commandAffectDate, })), }, false, @@ -172,3 +173,4 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise { return false; } } +