diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index b6af2bfd..e5232e4d 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1742,17 +1742,18 @@ export class CommandController extends Controller { return { no: Extension.ToThaiNumber((idx + 1).toString()), - org: commandCode != "C-PM-21" - ? (_child4 == null ? "" : _child4 + "\n") + - (_child3 == null ? "" : _child3 + "\n") + - (_child2 == null ? "" : _child2 + "\n") + - (_child1 == null ? "" : _child1 + "\n") + - (_root == null ? "" : _root) - : (profile?.child4Temp == null ? "" : profile?.child4Temp + "\n") + - (profile?.child3Temp == null ? "" : profile?.child3Temp + "\n") + - (profile?.child2Temp == null ? "" : profile?.child2Temp + "\n") + - (profile?.child1Temp == null ? "" : profile?.child1Temp + "\n") + - (profile?.rootTemp == null ? "" : profile?.rootTemp), + org: + commandCode != "C-PM-21" + ? (_child4 == null ? "" : _child4 + "\n") + + (_child3 == null ? "" : _child3 + "\n") + + (_child2 == null ? "" : _child2 + "\n") + + (_child1 == null ? "" : _child1 + "\n") + + (_root == null ? "" : _root) + : (profile?.child4Temp == null ? "" : profile?.child4Temp + "\n") + + (profile?.child3Temp == null ? "" : profile?.child3Temp + "\n") + + (profile?.child2Temp == null ? "" : profile?.child2Temp + "\n") + + (profile?.child1Temp == null ? "" : profile?.child1Temp + "\n") + + (profile?.rootTemp == null ? "" : profile?.rootTemp), fullName: `${x.prefix}${x.firstName} ${x.lastName}`, citizenId: Extension.ToThaiNumber(x.citizenId), position: profile?.position ? profile?.position : "-", @@ -1762,24 +1763,27 @@ export class CommandController extends Controller { `${profile?.posType.posTypeShortName} ${profile?.posLevel.posLevelName}`, ) : "-", - posNo: commandCode != "C-PM-21" - ? shortName - ? Extension.ToThaiNumber(shortName) - : "-" - : Extension.ToThaiNumber(`${profile?.rootShortNameTemp}${profile?.posMasterNoTemp}`) , + posNo: + commandCode != "C-PM-21" + ? shortName + ? Extension.ToThaiNumber(shortName) + : "-" + : Extension.ToThaiNumber( + `${profile?.rootShortNameTemp}${profile?.posMasterNoTemp}`, + ), amount: x.amount ? Extension.ToThaiNumber(x.amount.toLocaleString()) : "-", - dateRetire: profile?.dateRetire - ? Extension.ToThaiNumber( - Extension.ToThaiShortDate_monthYear(profile?.dateRetire) - ) + dateRetire: profile?.dateRetire + ? Extension.ToThaiNumber(Extension.ToThaiShortDate_monthYear(profile?.dateRetire)) : profile?.birthDate && commandCode == "C-PM-21" ? Extension.ToThaiNumber( - Extension.ToThaiShortDate_monthYear( - new Date( - profile.birthDate.getFullYear() + 60, profile.birthDate.getMonth(), profile.birthDate.getDate() - ) + Extension.ToThaiShortDate_monthYear( + new Date( + profile.birthDate.getFullYear() + 60, + profile.birthDate.getMonth(), + profile.birthDate.getDate(), + ), + ), ) - ) : "-", dateExecute: command.commandExcecuteDate ? Extension.ToThaiNumber( @@ -2421,12 +2425,10 @@ export class CommandController extends Controller { "C-PM-22", "C-PM-23", "C-PM-24", - "C-PM-34", "C-PM-36", "C-PM-37", - "C-PM-37", - "C-PM-37", - "C-PM-37", + "C-PM-42", + "C-PM-43", ].includes(commandCode) ) { let posMaster = await this.employeePosMasterRepository.find({ @@ -2953,10 +2955,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -2965,35 +2967,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -3129,10 +3131,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -3141,35 +3143,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -3324,10 +3326,10 @@ export class CommandController extends Controller { const roleKeycloak = await this.roleKeycloakRepo.findOne({ where: { name: Like("USER") }, }); - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -3336,35 +3338,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -3541,10 +3543,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -3553,35 +3555,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -3702,10 +3704,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -3714,35 +3716,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -4011,10 +4013,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -4023,35 +4025,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -4492,10 +4494,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -4504,35 +4506,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -4764,10 +4766,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -4776,35 +4778,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -4968,10 +4970,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.data.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -4980,35 +4982,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -5137,7 +5139,7 @@ export class CommandController extends Controller { commandName: item.commandName, remark: item.remark, posNumCodeSit: _posNumCodeSit, - posNumCodeSitAbb: _posNumCodeSitAbb + posNumCodeSitAbb: _posNumCodeSitAbb, }); await removeProfileInOrganize(profile.id, "OFFICER"); const clearProfile = await checkCommandType(String(item.commandId)); @@ -5219,10 +5221,10 @@ export class CommandController extends Controller { const list = await getRoles(); if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server."); const _null: any = null; - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.data.find(x => x.bodySalarys?.commandId)?.bodySalarys?.commandId ?? "" } + where: { id: body.data.find((x) => x.bodySalarys?.commandId)?.bodySalarys?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -5231,35 +5233,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -5724,10 +5726,10 @@ export class CommandController extends Controller { const roleKeycloak = await this.roleKeycloakRepo.findOne({ where: { name: Like("USER") }, }); - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.refIds.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.refIds.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -5736,35 +5738,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( @@ -6274,10 +6276,10 @@ export class CommandController extends Controller { }[]; }, ) { - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.refIds.find(x => x.commandId)?.commandId ?? "" } + where: { id: body.refIds.find((x) => x.commandId)?.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -6286,35 +6288,35 @@ export class CommandController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileRepository.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } await Promise.all( diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 4b6ef89f..a7e17165 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -572,7 +572,7 @@ export class EmployeePositionController extends Controller { const chk_SName0 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgRoot: { orgRootShortName: SName }, + orgRoot: { orgRootShortName: SName, /*id: requestBody.orgRootId ?? ""*/ }, orgChild1Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -588,7 +588,7 @@ export class EmployeePositionController extends Controller { const chk_SName1 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild1: { orgChild1ShortName: SName }, + orgChild1: { orgChild1ShortName: SName, /*id: requestBody.orgChild1Id ?? ""*/ }, orgChild2Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -604,7 +604,7 @@ export class EmployeePositionController extends Controller { const chk_SName2 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild2: { orgChild2ShortName: SName }, + orgChild2: { orgChild2ShortName: SName, /*id: requestBody.orgChild2Id ?? ""*/ }, orgChild3Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -620,7 +620,7 @@ export class EmployeePositionController extends Controller { const chk_SName3 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild3: { orgChild3ShortName: SName }, + orgChild3: { orgChild3ShortName: SName, /*id: requestBody.orgChild3Id ?? ""*/ }, orgChild4Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -636,7 +636,7 @@ export class EmployeePositionController extends Controller { const chk_SName4 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild4: { orgChild4ShortName: SName }, + orgChild4: { orgChild4ShortName: SName, /*id: requestBody.orgChild4Id ?? ""*/ }, posMasterNo: requestBody.posMasterNo, }, relations: ["orgChild4"], @@ -780,7 +780,7 @@ export class EmployeePositionController extends Controller { const chk_SName0 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgRoot: { orgRootShortName: SName }, + orgRoot: { orgRootShortName: SName, /*id: requestBody.orgRootId ?? ""*/ }, orgChild1Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -797,7 +797,7 @@ export class EmployeePositionController extends Controller { const chk_SName1 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild1: { orgChild1ShortName: SName }, + orgChild1: { orgChild1ShortName: SName, /*id: requestBody.orgChild1Id ?? ""*/ }, orgChild2Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -814,7 +814,7 @@ export class EmployeePositionController extends Controller { const chk_SName2 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild2: { orgChild2ShortName: SName }, + orgChild2: { orgChild2ShortName: SName, /*id: requestBody.orgChild2Id ?? ""*/ }, orgChild3Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -831,7 +831,7 @@ export class EmployeePositionController extends Controller { const chk_SName3 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild3: { orgChild3ShortName: SName }, + orgChild3: { orgChild3ShortName: SName, /*id: requestBody.orgChild3Id ?? ""*/ }, orgChild4Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -848,7 +848,7 @@ export class EmployeePositionController extends Controller { const chk_SName4 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild4: { orgChild4ShortName: SName }, + orgChild4: { orgChild4ShortName: SName, /*id: requestBody.orgChild4Id ?? ""*/ }, posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), }, diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index d05c5454..f1c1ead8 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -54,11 +54,26 @@ import { HR_MAJOR_CODE } from "../entities/HR_MAJOR_CODE"; // import { uuidv7 } from "uuidv7"; import { ProfileSalaries } from "../entities/ProfileSalaries"; import { HR_POSITION_OFFICER } from "../entities/HR_POSITION_OFFICER"; +import { EMPLOYEE } from "../entities/EMPLOYEE"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { EmployeePosMaster } from "../entities/EmployeePosMaster"; +import { EmployeePosition } from "../entities/EmployeePosition"; +import { HR_POSITION_EMPLOYEE } from "../entities/HR_POSITION_EMPLOYEE"; +import { ProfileDiscipline } from "../entities/ProfileDiscipline"; +import { ProfileInsignia } from "../entities/ProfileInsignia"; +import { HR_DISCIPLINE_EMP } from "../entities/HR_DISCIPLINE_EMP"; +import { HR_DISCIPLINE } from "../entities/HR_DISCIPLINE"; +import { HR_INSIGNIA } from "../entities/HR_INSIGNIA"; +import { HR_INSIGNIA_EMP } from "../entities/HR_INSIGNIA_EMP"; +import { Insignia } from "../entities/Insignia"; @Route("api/v1/org/upload") @Tags("UPLOAD") @Security("bearerAuth") export class ImportDataController extends Controller { private profileEducationRepo = AppDataSource.getRepository(ProfileEducation); + private profileDisciplineRepo = AppDataSource.getRepository(ProfileDiscipline); + private profileInsigniaRepo = AppDataSource.getRepository(ProfileInsignia); private profileFamilyCoupleRepository = AppDataSource.getRepository(ProfileFamilyCouple); private profileFamilyMotherRepository = AppDataSource.getRepository(ProfileFamilyMother); private profileFamilyFatherRepository = AppDataSource.getRepository(ProfileFamilyFather); @@ -67,13 +82,19 @@ export class ImportDataController extends Controller { private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee); private posLevelRepo = AppDataSource.getRepository(PosLevel); private posTypeRepo = AppDataSource.getRepository(PosType); + private posLevelEmpRepo = AppDataSource.getRepository(EmployeePosLevel); + private posTypeEmpRepo = AppDataSource.getRepository(EmployeePosType); private positionOfficerRepo = AppDataSource.getRepository(positionOfficer); private ProfileSalariesRepo = AppDataSource.getRepository(ProfileSalaries); private HR_PERSONAL_OFFICER_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_OFFICER_FAMILY); private HR_EDUCATIONRepo = AppDataSource.getRepository(HR_EDUCATION); + private HR_DISCIPLINERepo = AppDataSource.getRepository(HR_DISCIPLINE); + private HR_INSIGNIARepo = AppDataSource.getRepository(HR_INSIGNIA); private HR_PERSONAL_OFFICER_ADDRESSRepo = AppDataSource.getRepository( HR_PERSONAL_OFFICER_ADDRESS, ); + private HR_DISCIPLINE_EMPRepo = AppDataSource.getRepository(HR_DISCIPLINE_EMP); + private HR_INSIGNIA_EMPRepo = AppDataSource.getRepository(HR_INSIGNIA_EMP); private HR_EDUCATION_EMPRepo = AppDataSource.getRepository(HR_EDUCATION_EMP); private HR_PERSONAL_EMP_ADDRESSRepo = AppDataSource.getRepository(HR_PERSONAL_EMP_ADDRESS); private HR_PERSONAL_EMP_FAMILYRepo = AppDataSource.getRepository(HR_PERSONAL_EMP_FAMILY); @@ -83,6 +104,7 @@ export class ImportDataController extends Controller { private HR_MAJOR_CODERepo = AppDataSource.getRepository(HR_MAJOR_CODE); private HR_FUND_COURSE_CODERepo = AppDataSource.getRepository(HR_FUND_COURSE_CODE); private HR_POSITION_OFFICERRepo = AppDataSource.getRepository(HR_POSITION_OFFICER); + private HR_POSITION_EMPLOYEERepo = AppDataSource.getRepository(HR_POSITION_EMPLOYEE); private provincsRepo = AppDataSource.getRepository(ProvinceImport); private amphurRepo = AppDataSource.getRepository(AmphurImport); private subDistrictRepo = AppDataSource.getRepository(SubDistrictImport); @@ -98,73 +120,125 @@ export class ImportDataController extends Controller { private orgChild4Repo = AppDataSource.getRepository(OrgChild4); private IMPORT_ORGRepo = AppDataSource.getRepository(IMPORT_ORG); private OFFICERRepo = AppDataSource.getRepository(OFFICER); + private EMPLOYEERepo = AppDataSource.getRepository(EMPLOYEE); + + private positionEmpRepo = AppDataSource.getRepository(EmployeePosition); private positionRepo = AppDataSource.getRepository(Position); private posMasterRepo = AppDataSource.getRepository(PosMaster); + private posMasterEmpRepo = AppDataSource.getRepository(EmployeePosMaster); private posExecutiveRepo = AppDataSource.getRepository(PosExecutive); + private insigniaRepo = AppDataSource.getRepository(Insignia); /** * @summary ทะเบียนประวัติ ข้าราชการ */ @Post("uploadProfile-Officer") async UploadFileSqlOfficer(@Request() request: { user: Record }) { const OFFICER = await this.OFFICERRepo.find(); - // let users = []; let rowCount = 0; - // const filePath = path.resolve(__dirname, "OFFICER.csv"); // Corrected file path - // const readStream = fs.createReadStream(filePath).pipe(csvParser()); - // let profiles: any = []; let _null: any = null; let profile: any; - // await Promise.all( - // OFFICER.map(async (item) => { for await (const item of OFFICER) { - // readStream.map(async (item: any) => { rowCount++; let type_: any = null; let level_: any = null; profile = null; profile = new Profile(); - // if (item["FLAG_RETIRE_STATUSxxxx != "" && item["FLAG_RETIRE_STATUSxxxx != null) { - // continue; - // } - // if (item["FLAG_PERSON_TYPExxxx != "1") { - // continue; - // } - // if (new Date(item.RET_YEAR).getFullYear() >= 2567) { - // return; - // } const existingProfile = await this.profileRepo.findOne({ - where: { citizenId: item.id.toString() }, + where: { citizenId: item.CIT.toString() }, }); if (existingProfile) { profile.id = existingProfile.id; + if (profile.typeId != null) { + continue; + } // continue; } - if (item.MP_CATEGORY) { + 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 = "สูง"; + } + if (positionType) { type_ = await this.posTypeRepo.findOne({ - where: { posTypeName: item.MP_CATEGORY }, + where: { posTypeName: positionType }, }); } - if (item.MP_LEVEL) { + if (positionLevel) { if (type_ == null) { level_ = await this.posLevelRepo.findOne({ where: { - posLevelName: item.MP_LEVEL, + posLevelName: positionLevel, }, }); } else { level_ = await this.posLevelRepo.findOne({ where: { - posLevelName: item.MP_LEVEL, + posLevelName: positionLevel, posTypeId: type_.id, }, }); } } - let dateRetire = new Date(item.BORN); - profile.citizenId = item.id.toString() == "" ? "" : item.id.toString(); + let BORN = ""; + if (item.BORN) { + const [datePart] = item.BORN.split(" "); + const [day, month, year] = datePart.split("/"); + BORN = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + let BEGIN_ENTRY_DATE = ""; + if (item.BEGIN_ENTRY_DATE) { + const [datePart] = item.BEGIN_ENTRY_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + BEGIN_ENTRY_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + + profile.citizenId = item.CIT; profile.rank = item.RANK_NAME == "" || item.RANK_NAME == "นาย" || @@ -181,61 +255,28 @@ export class ImportDataController extends Controller { profile.firstName = item.FNAME == "" ? null : item.FNAME; profile.lastName = item.LNAME == "" ? null : item.LNAME; profile.gender = item.SEX == "1" ? "ชาย" : item.SEX == "2" ? "หญิง" : _null; - profile.birthDate = item.BORN == "" ? _null : new Date(item.BORN); - profile.dateAppoint = item.BEGIN_ENTRY_DATE == "" ? _null : new Date(item.BEGIN_ENTRY_DATE); - profile.dateStart = item.BEGIN_ENTRY_DATE == "" ? _null : new Date(item.BEGIN_ENTRY_DATE); - profile.dateRetire = dateRetire == null ? _null : calculateRetireDate(dateRetire); - profile.dateRetireLaw = dateRetire == null ? _null : calculateRetireLaw(dateRetire); + profile.birthDate = BORN == "" ? _null : new Date(BORN); + profile.dateAppoint = BEGIN_ENTRY_DATE == "" ? _null : new Date(BEGIN_ENTRY_DATE); + profile.dateStart = BEGIN_ENTRY_DATE == "" ? _null : new Date(BEGIN_ENTRY_DATE); + profile.dateRetire = BORN == "" ? _null : calculateRetireDate(new Date(BORN)); + profile.dateRetireLaw = BORN == "" ? _null : calculateRetireLaw(new Date(BORN)); profile.position = item.WORK_LINE_NAME == "" ? null : item.WORK_LINE_NAME; profile.posTypeId = - type_ != null && type_.posTypeName == item.MP_CATEGORY && type_ ? type_.id : null; + type_ != null && type_.posTypeName == positionType && type_ ? type_.id : null; profile.posLevelId = - level_ != null && level_.posLevelName == item.MP_LEVEL && level_ ? level_.id : null; - // profile.relationship = - // item.สถานภาพ == "" ? "" : Extension.CheckRelationship(item.สถานภาพ); - // profile.position = - // item.WORK_LINE_NAME == "" ? "" : Extension.CheckRelationship(item.WORK_LINE_NAME); - profile.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"]; - // const level = await this.posLevelRepo.findOne({ - // where: { - // posLevelName: item.MP_LEVEL, - // posType: { - // posTypeName: item.MP_Type, - // }, - // }, - // }); - // profile.posLevelId = level?.id ?? _null; - // const type = await this.posTypeRepo.findOne({ - // where: { posTypeName: item.MP_Type }, - // }); - // profile.posTypeId = type?.id ?? _null; + level_ != null && level_.posLevelName == positionLevel && level_ ? level_.id : null; profile.amount = item.SALARY == "" ? 0 : Number(item.SALARY); - // profile.isLeave = - // item.FLAG_RETIRE_STATUSxxxx == "" || item.FLAG_RETIRE_STATUSxxxx == null ? false : true; profile.createdUserId = request.user.sub; profile.createdFullName = request.user.name; profile.lastUpdateUserId = request.user.sub; profile.lastUpdateFullName = request.user.name; profile.createdAt = new Date(); profile.lastUpdatedAt = new Date(); - // profiles.push(profile); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - // if (profiles.length === BATCH_SIZE) { await this.profileRepo.save(profile); - // console.log(profile); - // profiles = await []; - // if (global.gc) { - // global.gc(); - // } - // } } - // }), - // ); - // ) - // ); - // console.log(rowCount); - // await this.profileRepo.save(profiles); return new HttpSuccess(); } @@ -244,87 +285,122 @@ export class ImportDataController extends Controller { */ @Post("uploadProfile-Employee") async UploadFileSQL(@Request() request: { user: Record }) { - let users = []; - let rowCount = 0; - const filePath = path.resolve(__dirname, "EMP.csv"); // Corrected file path - const readStream = fs.createReadStream(filePath).pipe(csvParser()); - let profiles: any = []; - let _null: any = null; - let profileEmp: any; + const existingProfile = await this.profileEmpRepo.find({ + select: ["citizenId"], + }); - for await (const item of readStream) { + const EMPLOYEE = await this.EMPLOYEERepo.find({ + where: { CIT: Not(In(existingProfile.map((x) => x.citizenId))) }, + }); + let rowCount = 0; + let _null: any = null; + let profile: any; + for await (const item of EMPLOYEE) { rowCount++; - profileEmp = null; - profileEmp = new ProfileEmployee(); - // if (item["FLAG_RETIRE_STATUS"] != "" && item["FLAG_RETIRE_STATUS"] != null) { - // continue; - // } - // if (item["FLAG_PERSON_TYPE"] != "6") { - // continue; - // } - // if (new Date(item["RET_YEAR"]).getFullYear() >= 2567) { - // continue; - // } + let type_: any = null; + let level_: any = null; + profile = null; + profile = new ProfileEmployee(); + const existingProfile = await this.profileEmpRepo.findOne({ - where: { citizenId: item["ID"] }, + where: { citizenId: item.CIT.toString() }, }); if (existingProfile) { - profileEmp.id = existingProfile.id; + profile.id = existingProfile.id; // continue; + } else { + continue; } - let dateRetire = new Date(item["MP_FORCE_DATE"]); + var positionType = ""; + var positionLevel = 0; + if (item.CATEGORY_SAL_CODE == "11") { + positionType = "บริการพื้นฐาน"; + // positionLevel = "ปฏิบัติงาน"; + } else if (item.CATEGORY_SAL_CODE == "12") { + positionType = "สนับสนุน"; + // positionLevel = "ชำนาญงาน"; + } else if (item.CATEGORY_SAL_CODE == "13") { + positionType = "ช่าง"; + // positionLevel = "อาวุโส"; + } + if (positionType) { + type_ = await this.posTypeEmpRepo.findOne({ + where: { posTypeName: positionType }, + }); + } + // if (positionLevel) { + // if (type_ == null) { + // level_ = await this.posLevelEmpRepo.findOne({ + // where: { + // posLevelName: positionLevel, + // }, + // }); + // } else { + // level_ = await this.posLevelEmpRepo.findOne({ + // where: { + // posLevelName: positionLevel, + // posTypeId: type_.id, + // }, + // }); + // } + // } + + // let BORN = ""; + // if (item.BORN) { + // const [datePart] = item.BORN.split(" "); + // const [day, month, year] = datePart.split("/"); + // BORN = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + // } + // let BEGIN_ENTRY_DATE = ""; + // if (item.BEGIN_ENTRY_DATE) { + // const [datePart] = item.BEGIN_ENTRY_DATE.split(" "); + // const [day, month, year] = datePart.split("/"); + // BEGIN_ENTRY_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + // } + + // profile.citizenId = item.CIT; + // profile.rank = + // item.RANK_NAME == "" || + // item.RANK_NAME == "นาย" || + // item.RANK_NAME == "นาง" || + // item.RANK_NAME == "นางสาว" + // ? null + // : item.RANK_NAME; + // profile.prefix = item.RANK_NAME == "" ? null : item.RANK_NAME; + // profile.prefixMain = + // item.RANK_NAME == "" || + // (item.RANK_NAME != "นาย" && item.RANK_NAME != "นาง" && item.RANK_NAME != "นางสาว") + // ? null + // : item.RANK_NAME; + // profile.firstName = item.FNAME == "" ? null : item.FNAME; + // profile.lastName = item.LNAME == "" ? null : item.LNAME; + // profile.employeeClass = "PERM"; + // profile.gender = item.SEX == "1" ? "ชาย" : item.SEX == "2" ? "หญิง" : _null; + // profile.birthDate = BORN == "" ? _null : new Date(BORN); + // profile.dateAppoint = BEGIN_ENTRY_DATE == "" ? _null : new Date(BEGIN_ENTRY_DATE); + // profile.dateStart = BEGIN_ENTRY_DATE == "" ? _null : new Date(BEGIN_ENTRY_DATE); + // profile.dateRetire = BORN == "" ? _null : calculateRetireDate(new Date(BORN)); + // profile.dateRetireLaw = BORN == "" ? _null : calculateRetireLaw(new Date(BORN)); + // profile.position = item.WORK_LINE_NAME == "" ? null : item.WORK_LINE_NAME.split(" ")[0]; + profile.posTypeId = + type_ != null && type_.posTypeName == positionType && type_ ? type_.id : null; + // profile.posLevelId = + // level_ != null && level_.posLevelName == positionLevel && level_ ? level_.id : null; + + // profile.amount = item.SALARY == "" ? 0 : Number(item.SALARY); + // profile.salaryLevel = item.SALARY == "" ? null : Number(item.SALARY_LEVEL_CODE); + // profile.createdUserId = request.user.sub; + // profile.createdFullName = request.user.name; + // profile.lastUpdateUserId = request.user.sub; + // profile.lastUpdateFullName = request.user.name; + // profile.createdAt = new Date(); + // profile.lastUpdatedAt = new Date(); - profileEmp.citizenId = item["ID"] == "" ? "" : item["ID"]; - profileEmp.employeeClass = - item["FLAG_PERSON_TYPE"] == "6" ? "PERM" : item["FLAG_PERSON_TYPE"] == "7" ? "TEMP" : ""; - profileEmp.rank = - item["RANK_NAME"] == "" || - item["RANK_NAME"] == "นาย" || - item["RANK_NAME"] == "นาง" || - item["RANK_NAME"] == "นางสาว" - ? null - : item["RANK_NAME"]; - profileEmp.prefix = item["RANK_NAME"] == "" ? null : item["RANK_NAME"]; - profileEmp.prefixMain = - item["RANK_NAME"] == "" || - (item["RANK_NAME"] != "นาย" && item["RANK_NAME"] != "นาง" && item["RANK_NAME"] != "นางสาว") - ? null - : item["RANK_NAME"]; - profileEmp.firstName = item["FNAME"] == "" ? null : item["FNAME"]; - profileEmp.lastName = item["LNAME"] == "" ? null : item["LNAME"]; - profileEmp.gender = item["SEX"] == "1" ? "ชาย" : item["SEX"] == "2" ? "หญิง" : _null; - profileEmp.birthDate = item["BORN"] == "" ? _null : new Date(item["BORN"]); - profileEmp.dateAppoint = - item["BEGIN_ENTRY_DATE"] == "" ? _null : new Date(item["BEGIN_ENTRY_DATE"]); - profileEmp.dateStart = item["MP_FORCE_DATE"] == "" ? _null : new Date(item["MP_FORCE_DATE"]); - profileEmp.dateRetire = dateRetire == null ? _null : calculateRetireDate(dateRetire); - profileEmp.dateRetireLaw = dateRetire == null ? _null : calculateRetireLaw(dateRetire); - profileEmp.position = item["WORK_LINE_NAME"] == "" ? null : item["WORK_LINE_NAME"]; - profileEmp.salaryLevel = item["SALARY_LEVEL_CODE"] == "" ? null : item["SALARY_LEVEL_CODE"]; - profileEmp.relationship = - item["MARRIAGE_STATE"] == "" ? "" : Extension.CheckRelationship(item["MARRIAGE_STATE"]); - profileEmp.amount = - item["SALARY"] == "" ? 0 : Number(Extension.CheckRelationship(item.SALARY)); - profileEmp.createdUserId = request.user.sub; - profileEmp.createdFullName = request.user.name; - profileEmp.lastUpdateUserId = request.user.sub; - profileEmp.lastUpdateFullName = request.user.name; - profileEmp.createdAt = new Date(); - profileEmp.lastUpdatedAt = new Date(); - // profiles.push(profileEmp); console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - // if (profiles.length === BATCH_SIZE) { - await this.profileEmpRepo.save(profileEmp); - // profiles = await []; - // if (global.gc) { - // global.gc(); - // } - // } + await this.profileEmpRepo.save(profile); } - // console.log(rowCount); - // await this.profileEmpRepo.save(profiles); return new HttpSuccess(); } @@ -358,8 +434,478 @@ export class ImportDataController extends Controller { // "3940900213929", // ]), // }) - .skip(0) - .take(10000) + .leftJoinAndSelect("profile.profileSalary", "profileSalary") + // .where({ citizenId: "3101702379675" }) + .where("profileSalary.id IS NULL") + // .skip(0) + // .take(10000) + .getManyAndCount(); + for await (const _item of profiles) { + // ดึงข้อมูลมาโดยไม่ใส่ order + const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ + where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" }, + }); + + // sort ด้วย JavaScript + existingProfile.sort((a, b) => { + let dateA = new Date().getTime(); + let dateB = new Date().getTime(); + + if (a.MP_POS_DATE) { + const [datePart] = a.MP_POS_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + dateA = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime(); + } + if (b.MP_POS_DATE) { + const [datePart] = b.MP_POS_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + dateB = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime(); + } + if (dateA !== dateB) { + return dateA - dateB; // ASC + } + return a.ORDER_MOVE_POSITION - b.ORDER_MOVE_POSITION; // ASC + }); + + let order = 1; + for await (const item of existingProfile) { + rowCount++; + const profileSalary: any = new ProfileSalary(); + profileSalary.profileId = _item.id; + profileSalary.order = order; + order = order + 1; + profileSalary.commandNo = isNaN(item.MP_COMMAND_NUM) ? null : item.MP_COMMAND_NUM; + profileSalary.commandYear = isNaN(item.MP_COMMAND_NUM) + ? null + : item.CUR_YEAR > 2500 + ? item.CUR_YEAR - 543 + : item.CUR_YEAR; + + let MP_COMMAND_DATE = ""; + if (item.MP_COMMAND_DATE) { + const [datePart] = item.MP_COMMAND_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + MP_COMMAND_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + let MP_POS_DATE = ""; + if (item.MP_POS_DATE) { + const [datePart] = item.MP_POS_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + MP_POS_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + profileSalary.commandDateSign = MP_COMMAND_DATE == null ? _null : new Date(MP_COMMAND_DATE); + profileSalary.commandDateAffect = MP_POS_DATE == null ? _null : new Date(MP_POS_DATE); + if ( + [ + "0", + "11", + "22", + "31", + "39", + "45", + "46", + "47", + "49", + "50", + "51", + "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", "56"].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 = "รักษาราชการ, ช่วยราชการ"; + } + if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "ลาศึกษาต่อ") { + profileSalary.commandCode = "0"; + profileSalary.commandName = "อื่น ๆ"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + (item.FLAG_TO_NAME == "เลื่อน 1 ขั้นและเลื่อนระดับ" || + item.FLAG_TO_NAME == "เลื่อน 0.5 ขั้นและเลื่อนระดับ") + ) { + profileSalary.commandCode = "4"; + profileSalary.commandName = "เลื่อน"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "เลื่อนเงินเดือน") { + profileSalary.commandCode = "5"; + profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + (item.FLAG_TO_NAME == "ปรับตามบัญชีเงินเดือนใหม่" || + item.FLAG_TO_NAME == "เลื่อนเงินเดือน" || + item.FLAG_TO_NAME == "ปรับเงินเดือนตาม กพ.") + ) { + profileSalary.commandCode = "6"; + profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + item.FLAG_TO_NAME == "แต่งตั้งตามการปรับปรุงโครงฯ" + ) { + profileSalary.commandCode = "8"; + profileSalary.commandName = "ปรับโครงสร้าง"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "พ้นทดลองปฏิบัติราชการ") { + profileSalary.commandCode = "9"; + profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "ให้โอนมา") { + profileSalary.commandCode = "11"; + profileSalary.commandName = "รับโอน"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + item.FLAG_TO_NAME == "โอนไปปฏิบัติราชการที่อื่น" + ) { + profileSalary.commandCode = "12"; + profileSalary.commandName = "ให้โอน"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "ยกเลิกคำสั่ง") { + profileSalary.commandCode = "14"; + profileSalary.commandName = "ยกเลิกคำสั่ง"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "รักษาการในตำแหน่ง") { + profileSalary.commandCode = "17"; + profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; + } + if ( + (profileSalary.commandCode == null || profileSalary.commandCode == undefined) && + (profileSalary.commandName == null || profileSalary.commandName == undefined) + ) { + if ( + [ + "อื่นๆ", + "กลับไปปฏิบัติงานทางต้นสังกัด", + "เปลี่ยนประเภทข้าราชการ", + "โอนสับเปลี่ยน", + "เข้ารับฝึกอบรม", + "ดูงาน", + "ศึกษาต่อ", + "ขยายเวลาเข้ารับการฝึกอบรม", + "ขยายเวลาศึกษาต่อ", + "รายงานตัวกลับเข้าปฏิบัติราชการ", + "ไม่ได้เลื่อนขั้น", + "ตัดเงินเดือน", + "ลดขั้นเงินเดือน", + "ให้ข้าราชการกลับเข้ารับราชการ", + "ไม่ระบุ", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "0"; + profileSalary.commandName = "อื่น ๆ"; + } else if ( + [ + "บรรจุและแต่งตั้งผู้สอบแข่งขันได้", + "ทดลองปฎิบัติราชการ", + "ทดลองปฏิบัติราชการและปรับวุฒิ", + "บรรจุใหม่", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "1"; + profileSalary.commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้"; + } else if (["บรรจุและแต่งตั้งผู้ได้รับการคัดเลือก"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "2"; + profileSalary.commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก"; + } else if ( + [ + "แต่งตั้ง (ย้ายสับเปลี่ยน)", + "แต่งตั้ง (ย้าย)", + "แต่งตั้ง", + "เปลี่ยนสายงาน", + "เปลี่ยนตำแหน่ง", + "ตัดโอนตำแหน่ง", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "3"; + profileSalary.commandName = "แต่งตั้ง ย้าย"; + } else if ( + ["เลื่อนและแต่งตั้ง", "เลื่อนระดับ", "เลื่อนเงินเดือนและระดับ"].includes( + item.FLAG_TO_NAME, + ) + ) { + profileSalary.commandCode = "4"; + profileSalary.commandName = "เลื่อน"; + } else if (["เลื่อนขั้นเงินเดือน", "เลื่อนเงินเดือน"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "5"; + profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; + } else if ( + [ + "ปรับเงินเดือนตามคุณวุฒิ", + "ได้รับเงินตอบแทนพิเศษ", + "เงินเพิ่มการครองชีพชั่วคราว", + "เลื่อนขั้นเงินเดือนกรณีพิเศษ", + "ปรับอัตราเงินเดือนตามบัญชีอัตราเงินเดือนใหม่ ท้าย พ.ร.บ. เงินเดือนและเงินประจำตำ", + "ปรับอัตราเงินเดือนตามพระราชกฤษฎีกา การปรับอัตราเงินเดือนของข้าราชการ", + "เลื่อนขั้นเงินเดือน (เพิ่มเติม)", + "ปรับอัตราเงินเดือน", + "ให้ข้าราชการได้รับเงินเดือนตามคุณวุฒิ", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "6"; + profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + } else if (["--"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "7"; + profileSalary.commandName = "เงินพิเศษอื่น ๆ"; + } else if ( + ["ปรับโครงสร้าง", "แต่งตั้ง (จัดคนลงกรอบ)", "แต่งตั้งตามแผนอัตรากำลังฯ"].includes( + item.FLAG_TO_NAME, + ) + ) { + profileSalary.commandCode = "8"; + profileSalary.commandName = "ปรับโครงสร้าง"; + } else if (["พ้นทดลองปฏิบัติราชการ"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "9"; + profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; + } else if ( + [ + "บรรจุกลับ", + "บรรจุกลับข้าราชการ", + "บรรจุและแต่งตั้งผู้ไปรับราชการทหารกลับเข้ารับราชการ", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "10"; + profileSalary.commandName = "บรรจุกลับ"; + } else if ( + [ + "รับโอนข้าราชการตามกฎหมายอื่น", + "รับโอนข้าราชการตามกฎหมายอื่น ผู้สอบแข่งขันได้", + "รับโอนข้าราชการตามกฏหมายอื่น โดยการคัดเลือก", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "11"; + profileSalary.commandName = "รับโอน"; + } else if (["ให้โอน"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "12"; + profileSalary.commandName = "ให้โอน"; + } else if (["แก้ไขคำสั่ง"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "13"; + profileSalary.commandName = "แก้ไขคำสั่ง"; + } else if (["ยกเลิกคำสั่ง"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "14"; + profileSalary.commandName = "ยกเลิกคำสั่ง"; + } else if ( + [ + "ลาออกจากราชการ", + "พ้นจากราชการ/ลาออกจากราชการตามมาตรการพัฒนาและบริหารกำลังคน", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "15"; + profileSalary.commandName = "ลาออกจากราชการ"; + } else if ( + [ + "พ้นจากราชการ/เพื่อไปปฏิบัติราชการทหาร", + "เกษียณ", + "ไม่พ้นทดลองปฏิบัติราชการ", + "พ้นจากราชการ/ให้ออก", + "พ้นจากราชการ/ไล่ออก", + "พ้นจากราชการ/เสียชีวิต", + "พ้นจากราชการ/ปลดออก", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "16"; + profileSalary.commandName = "พ้นจากราชการ"; + } else if ( + [ + "แต่งตั้งข้าราชการรักษาราชการแทน", + "ช่วยราชการ", + "รักษาการ", + "รักษาราชการแทน", + "มอบหมายให้ปฏิบัติหน้าที่", + "มอบหมายข้าราชการปฏิบัติหน้าที่แทน", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "17"; + profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; + } else { + profileSalary.commandCode = "0"; + profileSalary.commandName = item.FLAG_TO_NAME; + } + } + profileSalary.posNoAbb = item.POS_NUM_NAME; + profileSalary.posNo = item.POS_NUM_CODE; + profileSalary.positionName = item.WORK_LINE_NAME; + var positionType = _null; + var positionLevel = _null; + 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 ?? _null; + profileSalary.amount = isNaN(item.SALARY) ? null : item.SALARY; + profileSalary.remark = item.REMARK; + profileSalary.refId = item.id; + profileSalary.isEntry = false; + + 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; + + profileSalary.createdUserId = request.user.sub; + profileSalary.createdFullName = request.user.name; + profileSalary.lastUpdateUserId = request.user.sub; + profileSalary.lastUpdateFullName = request.user.name; + profileSalary.createdAt = new Date().toISOString().split("T")[0]; + profileSalary.lastUpdatedAt = new Date().toISOString().split("T")[0]; + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + + try { + await this.salaryRepo.save(profileSalary); + } catch (error) { + console.error("Error executing function from controller:", item.CIT); + } + } + order = 1; + } + return new HttpSuccess(); + } + + /** + * @summary เงินเดือน ลูกจ้างประจำ + */ + @Post("uploadProfileSalary-Employee") + async UploadFileSQLSalaryEmp(@Request() request: { user: Record }) { + let rowCount = 0; + let _null: any = null; + let sqlStatements: string[] = []; + + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + // .where("profile.citizenId = '3101702379675'") + // .where({ + // citizenId: In([ + // // "1100600109451", + // // "1209900075508", + // // "1739900231556", + // // "1809900305214", + // // "1920600228762", + // // "3101600963742", + // // "3102401171243", + // // "3120100454406", + // // "3180100306172", + // // "3700100094722", + // // "3809900116957", + // "3940900213929", + // ]), + // }) + .leftJoinAndSelect("profile.profileSalary", "profileSalary") + // .where({employeeClass: "P"}) + .where("profileSalary.id IS NULL") + // .skip(0) + // .take(10000) .getManyAndCount(); var _profiles: ProfileSalary[] = []; const filePath = path.join(__dirname, "salaryProfile1.csv"); @@ -373,553 +919,392 @@ export class ImportDataController extends Controller { console.log("Salary profiles successfully written to salaryProfile.csv"); } }); - await Promise.all( - profiles.map(async (_item) => { - 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: any = new ProfileSalary(); - profileSalary.profileId = _item.id; - 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 == null - ? _null - : new Date(item.mp_command_date.setDate(item.mp_command_date.getDate() + 1)) - .toISOString() - .replace("T", " ") - .substring(0, 19); - profileSalary.commandDateAffect = - item.mp_pos_date == null - ? _null - : new Date(item.mp_pos_date.setDate(item.mp_pos_date.getDate() + 1)) - .toISOString() - .replace("T", " ") - .substring(0, 19); - if ( - [ - "0", - "11", - "22", - "31", - "39", - "45", - "46", - "47", - "49", - "50", - "51", - "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", "56"].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 = "รักษาราชการ, ช่วยราชการ"; - } - if (item.flag_to_name_code == null && item.flag_to_name == "ลาศึกษาต่อ") { - profileSalary.commandCode = "0"; - profileSalary.commandName = "อื่น ๆ"; - } else if ( - item.flag_to_name_code == null && - (item.flag_to_name == "เลื่อน 1 ขั้นและเลื่อนระดับ" || - item.flag_to_name == "เลื่อน 0.5 ขั้นและเลื่อนระดับ") - ) { - profileSalary.commandCode = "4"; - profileSalary.commandName = "เลื่อน"; - } else if (item.flag_to_name_code == null && item.flag_to_name == "เลื่อนเงินเดือน") { - profileSalary.commandCode = "5"; - profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; - } else if ( - item.flag_to_name_code == null && - (item.flag_to_name == "ปรับตามบัญชีเงินเดือนใหม่" || - item.flag_to_name == "เลื่อนเงินเดือน" || - item.flag_to_name == "ปรับเงินเดือนตาม กพ.") - ) { - profileSalary.commandCode = "6"; - profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; - } else if ( - item.flag_to_name_code == null && - item.flag_to_name == "แต่งตั้งตามการปรับปรุงโครงฯ" - ) { - profileSalary.commandCode = "8"; - profileSalary.commandName = "ปรับโครงสร้าง"; - } else if ( - item.flag_to_name_code == null && - item.flag_to_name == "พ้นทดลองปฏิบัติราชการ" - ) { - profileSalary.commandCode = "9"; - profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; - } else if (item.flag_to_name_code == null && item.flag_to_name == "ให้โอนมา") { - profileSalary.commandCode = "11"; - profileSalary.commandName = "รับโอน"; - } else if ( - item.flag_to_name_code == null && - item.flag_to_name == "โอนไปปฏิบัติราชการที่อื่น" - ) { - profileSalary.commandCode = "12"; - profileSalary.commandName = "ให้โอน"; - } else if (item.flag_to_name_code == null && item.flag_to_name == "ยกเลิกคำสั่ง") { - profileSalary.commandCode = "14"; - profileSalary.commandName = "ยกเลิกคำสั่ง"; - } else if (item.flag_to_name_code == null && item.flag_to_name == "รักษาการในตำแหน่ง") { - profileSalary.commandCode = "17"; - profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; - } - if ( - (profileSalary.commandCode == null || profileSalary.commandCode == undefined) && - (profileSalary.commandName == null || profileSalary.commandName == undefined) - ) { - if ( - [ - "อื่นๆ", - "กลับไปปฏิบัติงานทางต้นสังกัด", - "เปลี่ยนประเภทข้าราชการ", - "โอนสับเปลี่ยน", - "เข้ารับฝึกอบรม", - "ดูงาน", - "ศึกษาต่อ", - "ขยายเวลาเข้ารับการฝึกอบรม", - "ขยายเวลาศึกษาต่อ", - "รายงานตัวกลับเข้าปฏิบัติราชการ", - "ไม่ได้เลื่อนขั้น", - "ตัดเงินเดือน", - "ลดขั้นเงินเดือน", - "ให้ข้าราชการกลับเข้ารับราชการ", - "ไม่ระบุ", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "0"; - profileSalary.commandName = "อื่น ๆ"; - } else if ( - [ - "บรรจุและแต่งตั้งผู้สอบแข่งขันได้", - "ทดลองปฎิบัติราชการ", - "ทดลองปฏิบัติราชการและปรับวุฒิ", - "บรรจุใหม่", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "1"; - profileSalary.commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้"; - } else if (["บรรจุและแต่งตั้งผู้ได้รับการคัดเลือก"].includes(item.flag_to_name)) { - profileSalary.commandCode = "2"; - profileSalary.commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก"; - } else if ( - [ - "แต่งตั้ง (ย้ายสับเปลี่ยน)", - "แต่งตั้ง (ย้าย)", - "แต่งตั้ง", - "เปลี่ยนสายงาน", - "เปลี่ยนตำแหน่ง", - "ตัดโอนตำแหน่ง", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "3"; - profileSalary.commandName = "แต่งตั้ง ย้าย"; - } else if ( - ["เลื่อนและแต่งตั้ง", "เลื่อนระดับ", "เลื่อนเงินเดือนและระดับ"].includes( - item.flag_to_name, - ) - ) { - profileSalary.commandCode = "4"; - profileSalary.commandName = "เลื่อน"; - } else if (["เลื่อนขั้นเงินเดือน", "เลื่อนเงินเดือน"].includes(item.flag_to_name)) { - profileSalary.commandCode = "5"; - profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; - } else if ( - [ - "ปรับเงินเดือนตามคุณวุฒิ", - "ได้รับเงินตอบแทนพิเศษ", - "เงินเพิ่มการครองชีพชั่วคราว", - "เลื่อนขั้นเงินเดือนกรณีพิเศษ", - "ปรับอัตราเงินเดือนตามบัญชีอัตราเงินเดือนใหม่ ท้าย พ.ร.บ. เงินเดือนและเงินประจำตำ", - "ปรับอัตราเงินเดือนตามพระราชกฤษฎีกา การปรับอัตราเงินเดือนของข้าราชการ", - "เลื่อนขั้นเงินเดือน (เพิ่มเติม)", - "ปรับอัตราเงินเดือน", - "ให้ข้าราชการได้รับเงินเดือนตามคุณวุฒิ", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "6"; - profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; - } else if (["--"].includes(item.flag_to_name)) { - profileSalary.commandCode = "7"; - profileSalary.commandName = "เงินพิเศษอื่น ๆ"; - } else if ( - ["ปรับโครงสร้าง", "แต่งตั้ง (จัดคนลงกรอบ)", "แต่งตั้งตามแผนอัตรากำลังฯ"].includes( - item.flag_to_name, - ) - ) { - profileSalary.commandCode = "8"; - profileSalary.commandName = "ปรับโครงสร้าง"; - } else if (["พ้นทดลองปฏิบัติราชการ"].includes(item.flag_to_name)) { - profileSalary.commandCode = "9"; - profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; - } else if ( - [ - "บรรจุกลับ", - "บรรจุกลับข้าราชการ", - "บรรจุและแต่งตั้งผู้ไปรับราชการทหารกลับเข้ารับราชการ", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "10"; - profileSalary.commandName = "บรรจุกลับ"; - } else if ( - [ - "รับโอนข้าราชการตามกฎหมายอื่น", - "รับโอนข้าราชการตามกฎหมายอื่น ผู้สอบแข่งขันได้", - "รับโอนข้าราชการตามกฏหมายอื่น โดยการคัดเลือก", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "11"; - profileSalary.commandName = "รับโอน"; - } else if (["ให้โอน"].includes(item.flag_to_name)) { - profileSalary.commandCode = "12"; - profileSalary.commandName = "ให้โอน"; - } else if (["แก้ไขคำสั่ง"].includes(item.flag_to_name)) { - profileSalary.commandCode = "13"; - profileSalary.commandName = "แก้ไขคำสั่ง"; - } else if (["ยกเลิกคำสั่ง"].includes(item.flag_to_name)) { - profileSalary.commandCode = "14"; - profileSalary.commandName = "ยกเลิกคำสั่ง"; - } else if ( - [ - "ลาออกจากราชการ", - "พ้นจากราชการ/ลาออกจากราชการตามมาตรการพัฒนาและบริหารกำลังคน", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "15"; - profileSalary.commandName = "ลาออกจากราชการ"; - } else if ( - [ - "พ้นจากราชการ/เพื่อไปปฏิบัติราชการทหาร", - "เกษียณ", - "ไม่พ้นทดลองปฏิบัติราชการ", - "พ้นจากราชการ/ให้ออก", - "พ้นจากราชการ/ไล่ออก", - "พ้นจากราชการ/เสียชีวิต", - "พ้นจากราชการ/ปลดออก", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "16"; - profileSalary.commandName = "พ้นจากราชการ"; - } else if ( - [ - "แต่งตั้งข้าราชการรักษาราชการแทน", - "ช่วยราชการ", - "รักษาการ", - "รักษาราชการแทน", - "มอบหมายให้ปฏิบัติหน้าที่", - "มอบหมายข้าราชการปฏิบัติหน้าที่แทน", - ].includes(item.flag_to_name) - ) { - profileSalary.commandCode = "17"; - profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; - } else { - profileSalary.commandCode = "0"; - profileSalary.commandName = item.flag_to_name; - } - } - 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; - profileSalary.refId = item.id; - profileSalary.isEntry = false; + for await (const _item of profiles) { + const existingProfile = await this.HR_POSITION_EMPLOYEERepo.find({ + where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "6" }, + }); - 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; + // sort ด้วย JavaScript + existingProfile.sort((a, b) => { + let dateA = new Date().getTime(); + let dateB = new Date().getTime(); - profileSalary.createdUserId = request.user.sub; - profileSalary.createdFullName = request.user.name; - profileSalary.lastUpdateUserId = request.user.sub; - profileSalary.lastUpdateFullName = request.user.name; - profileSalary.createdAt = new Date().toISOString().split("T")[0]; - profileSalary.lastUpdatedAt = new Date().toISOString().split("T")[0]; - // const result = uuidv7(); - // profileSalary.id = result; - // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + if (a.MP_POS_DATE) { + const [datePart] = a.MP_POS_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + dateA = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime(); + } + if (b.MP_POS_DATE) { + const [datePart] = b.MP_POS_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + dateB = new Date(`${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`).getTime(); + } + if (dateA !== dateB) { + return dateA - dateB; // ASC + } + return a.ORDER_MOVE_POSITION - b.ORDER_MOVE_POSITION; // ASC + }); + let order = 1; + for await (const item of existingProfile) { + rowCount++; + const profileSalary: any = new ProfileSalary(); + profileSalary.profileEmployeeId = _item.id; + profileSalary.order = order; + order = order + 1; + profileSalary.commandNo = isNaN(item.MP_COMMAND_NUM) ? null : item.MP_COMMAND_NUM; + profileSalary.commandYear = isNaN(item.MP_COMMAND_NUM) + ? null + : item.CUR_YEAR > 2500 + ? item.CUR_YEAR - 543 + : item.CUR_YEAR; - // // Generate SQL INSERT Statement using TypeORM QueryBuilder but don't execute it - // const queryBuilder = AppDataSource.createQueryBuilder() - // .insert() - // .into(ProfileSalary) - // .values(profileSalary); + let MP_COMMAND_DATE = ""; + if (item.MP_COMMAND_DATE) { + const [datePart] = item.MP_COMMAND_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + MP_COMMAND_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + let MP_POS_DATE = ""; + if (item.MP_POS_DATE) { + const [datePart] = item.MP_POS_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + MP_POS_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + profileSalary.commandDateSign = MP_COMMAND_DATE == null ? _null : new Date(MP_COMMAND_DATE); + profileSalary.commandDateAffect = MP_POS_DATE == null ? _null : new Date(MP_POS_DATE); + if ( + [ + "0", + "11", + "22", + "31", + "39", + "45", + "46", + "47", + "49", + "50", + "51", + "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", "56"].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 = "รักษาราชการ, ช่วยราชการ"; + } + if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "ลาศึกษาต่อ") { + profileSalary.commandCode = "0"; + profileSalary.commandName = "อื่น ๆ"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + (item.FLAG_TO_NAME == "เลื่อน 1 ขั้นและเลื่อนระดับ" || + item.FLAG_TO_NAME == "เลื่อน 0.5 ขั้นและเลื่อนระดับ") + ) { + profileSalary.commandCode = "4"; + profileSalary.commandName = "เลื่อน"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "เลื่อนเงินเดือน") { + profileSalary.commandCode = "5"; + profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + (item.FLAG_TO_NAME == "ปรับตามบัญชีเงินเดือนใหม่" || + item.FLAG_TO_NAME == "เลื่อนเงินเดือน" || + item.FLAG_TO_NAME == "ปรับเงินเดือนตาม กพ.") + ) { + profileSalary.commandCode = "6"; + profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + item.FLAG_TO_NAME == "แต่งตั้งตามการปรับปรุงโครงฯ" + ) { + profileSalary.commandCode = "8"; + profileSalary.commandName = "ปรับโครงสร้าง"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "พ้นทดลองปฏิบัติราชการ") { + profileSalary.commandCode = "9"; + profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "ให้โอนมา") { + profileSalary.commandCode = "11"; + profileSalary.commandName = "รับโอน"; + } else if ( + item.FLAG_TO_NAME_CODE == null && + item.FLAG_TO_NAME == "โอนไปปฏิบัติราชการที่อื่น" + ) { + profileSalary.commandCode = "12"; + profileSalary.commandName = "ให้โอน"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "ยกเลิกคำสั่ง") { + profileSalary.commandCode = "14"; + profileSalary.commandName = "ยกเลิกคำสั่ง"; + } else if (item.FLAG_TO_NAME_CODE == null && item.FLAG_TO_NAME == "รักษาการในตำแหน่ง") { + profileSalary.commandCode = "17"; + profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; + } + if ( + (profileSalary.commandCode == null || profileSalary.commandCode == undefined) && + (profileSalary.commandName == null || profileSalary.commandName == undefined) + ) { + if ( + [ + "อื่นๆ", + "กลับไปปฏิบัติงานทางต้นสังกัด", + "เปลี่ยนประเภทข้าราชการ", + "โอนสับเปลี่ยน", + "เข้ารับฝึกอบรม", + "ดูงาน", + "ศึกษาต่อ", + "ขยายเวลาเข้ารับการฝึกอบรม", + "ขยายเวลาศึกษาต่อ", + "รายงานตัวกลับเข้าปฏิบัติราชการ", + "ไม่ได้เลื่อนขั้น", + "ตัดเงินเดือน", + "ลดขั้นเงินเดือน", + "ให้ข้าราชการกลับเข้ารับราชการ", + "ไม่ระบุ", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "0"; + profileSalary.commandName = "อื่น ๆ"; + } else if ( + [ + "บรรจุและแต่งตั้งผู้สอบแข่งขันได้", + "ทดลองปฎิบัติราชการ", + "ทดลองปฏิบัติราชการและปรับวุฒิ", + "บรรจุใหม่", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "1"; + profileSalary.commandName = "บรรจุและแต่งตั้งผู้สอบแข่งขันได้"; + } else if (["บรรจุและแต่งตั้งผู้ได้รับการคัดเลือก"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "2"; + profileSalary.commandName = "บรรจุและแต่งตั้งผู้ได้รับคัดเลือก"; + } else if ( + [ + "แต่งตั้ง (ย้ายสับเปลี่ยน)", + "แต่งตั้ง (ย้าย)", + "แต่งตั้ง", + "เปลี่ยนสายงาน", + "เปลี่ยนตำแหน่ง", + "ตัดโอนตำแหน่ง", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "3"; + profileSalary.commandName = "แต่งตั้ง ย้าย"; + } else if ( + ["เลื่อนและแต่งตั้ง", "เลื่อนระดับ", "เลื่อนเงินเดือนและระดับ"].includes( + item.FLAG_TO_NAME, + ) + ) { + profileSalary.commandCode = "4"; + profileSalary.commandName = "เลื่อน"; + } else if (["เลื่อนขั้นเงินเดือน", "เลื่อนเงินเดือน"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "5"; + profileSalary.commandName = "เลื่อนเงินเดือนตามปกติ"; + } else if ( + [ + "ปรับเงินเดือนตามคุณวุฒิ", + "ได้รับเงินตอบแทนพิเศษ", + "เงินเพิ่มการครองชีพชั่วคราว", + "เลื่อนขั้นเงินเดือนกรณีพิเศษ", + "ปรับอัตราเงินเดือนตามบัญชีอัตราเงินเดือนใหม่ ท้าย พ.ร.บ. เงินเดือนและเงินประจำตำ", + "ปรับอัตราเงินเดือนตามพระราชกฤษฎีกา การปรับอัตราเงินเดือนของข้าราชการ", + "เลื่อนขั้นเงินเดือน (เพิ่มเติม)", + "ปรับอัตราเงินเดือน", + "ให้ข้าราชการได้รับเงินเดือนตามคุณวุฒิ", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "6"; + profileSalary.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + } else if (["--"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "7"; + profileSalary.commandName = "เงินพิเศษอื่น ๆ"; + } else if ( + ["ปรับโครงสร้าง", "แต่งตั้ง (จัดคนลงกรอบ)", "แต่งตั้งตามแผนอัตรากำลังฯ"].includes( + item.FLAG_TO_NAME, + ) + ) { + profileSalary.commandCode = "8"; + profileSalary.commandName = "ปรับโครงสร้าง"; + } else if (["พ้นทดลองปฏิบัติราชการ"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "9"; + profileSalary.commandName = "พ้นทดลองปฏิบัติราชการ"; + } else if ( + [ + "บรรจุกลับ", + "บรรจุกลับข้าราชการ", + "บรรจุและแต่งตั้งผู้ไปรับราชการทหารกลับเข้ารับราชการ", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "10"; + profileSalary.commandName = "บรรจุกลับ"; + } else if ( + [ + "รับโอนข้าราชการตามกฎหมายอื่น", + "รับโอนข้าราชการตามกฎหมายอื่น ผู้สอบแข่งขันได้", + "รับโอนข้าราชการตามกฏหมายอื่น โดยการคัดเลือก", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "11"; + profileSalary.commandName = "รับโอน"; + } else if (["ให้โอน"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "12"; + profileSalary.commandName = "ให้โอน"; + } else if (["แก้ไขคำสั่ง"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "13"; + profileSalary.commandName = "แก้ไขคำสั่ง"; + } else if (["ยกเลิกคำสั่ง"].includes(item.FLAG_TO_NAME)) { + profileSalary.commandCode = "14"; + profileSalary.commandName = "ยกเลิกคำสั่ง"; + } else if ( + [ + "ลาออกจากราชการ", + "พ้นจากราชการ/ลาออกจากราชการตามมาตรการพัฒนาและบริหารกำลังคน", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "15"; + profileSalary.commandName = "ลาออกจากราชการ"; + } else if ( + [ + "พ้นจากราชการ/เพื่อไปปฏิบัติราชการทหาร", + "เกษียณ", + "ไม่พ้นทดลองปฏิบัติราชการ", + "พ้นจากราชการ/ให้ออก", + "พ้นจากราชการ/ไล่ออก", + "พ้นจากราชการ/เสียชีวิต", + "พ้นจากราชการ/ปลดออก", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "16"; + profileSalary.commandName = "พ้นจากราชการ"; + } else if ( + [ + "แต่งตั้งข้าราชการรักษาราชการแทน", + "ช่วยราชการ", + "รักษาการ", + "รักษาราชการแทน", + "มอบหมายให้ปฏิบัติหน้าที่", + "มอบหมายข้าราชการปฏิบัติหน้าที่แทน", + ].includes(item.FLAG_TO_NAME) + ) { + profileSalary.commandCode = "17"; + profileSalary.commandName = "รักษาราชการ, ช่วยราชการ"; + } else { + profileSalary.commandCode = "0"; + profileSalary.commandName = item.FLAG_TO_NAME; + } + } + profileSalary.posNoAbb = item.POS_NUM_NAME; + profileSalary.posNo = item.POS_NUM_CODE; + profileSalary.positionName = item.WORK_LINE_NAME; + var positionType = _null; + var positionLevel = _null; + if (item.CATEGORY_SAL_CODE == "11") { + positionType = "บริการพื้นฐาน"; + } else if (item.CATEGORY_SAL_CODE == "12") { + positionType = "สนับสนุน"; + } else if (item.CATEGORY_SAL_CODE == "13") { + positionType = "ช่าง"; + } - // const sql = queryBuilder.getSql(); - // sqlStatements.push(sql); - // _profiles.push(profileSalary); - // save to file - // Define the output file path + 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 ?? _null; + profileSalary.amount = isNaN(item.SALARY) ? null : item.SALARY; + profileSalary.remark = item.REMARK; + profileSalary.refId = item.id; + profileSalary.isEntry = false; - // 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`; + // 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; - // Loop through each salary profile and format data as CSV - // _profiles.forEach((profile) => { - console.log(profileSalary.commandDateSign); - csvData = `"${profileSalary.id || "NULL"}","${profileSalary.createdAt || "NULL"}","${profileSalary.createdUserId || "NULL"}","${profileSalary.lastUpdatedAt || "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 || "NULL"}","${profileSalary.commandDateAffect || "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 || "NULL"}","${profileSalary.isGovernment || "NULL"}","${profileSalary.commandId || "NULL"}","${profileSalary.refId || "NULL"}"\n`; - // }); + profileSalary.createdUserId = request.user.sub; + profileSalary.createdFullName = request.user.name; + profileSalary.lastUpdateUserId = request.user.sub; + profileSalary.lastUpdateFullName = request.user.name; + profileSalary.createdAt = new Date().toISOString().split("T")[0]; + profileSalary.lastUpdatedAt = new Date().toISOString().split("T")[0]; + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - // 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); - // // 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(); - } - - /** - * @summary เงินเดือน ลูกจ้างประจำ - */ - @Post("uploadProfileSalary-Employee") - async UploadFileSQLSalaryEmp(@Request() request: { user: Record }) { - let rowCount = 0; - let _null: any = null; - - const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) - .createQueryBuilder("profile") - .select(["profile.citizenId", "profile.id"]) - .orderBy("profile.citizenId", "ASC") - .skip(0) - .take(10000) - .getManyAndCount(); - - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.positionOfficerRepo.find({ - where: { citizenId: _item.citizenId, flag_person_type: "7" }, - }); - - await Promise.all( - existingProfile.map(async (item) => { - rowCount++; - 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 == "" - ? _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.commandId; - - profileSalary.createdUserId = request.user.sub; - profileSalary.createdFullName = request.user.name; - profileSalary.lastUpdateUserId = request.user.sub; - profileSalary.lastUpdateFullName = request.user.name; - profileSalary.createdAt = new Date(); - profileSalary.lastUpdatedAt = new Date(); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - // save to file - // await this.salaryRepo.save(profileSalary); - }), - ); - }), - ); - console.log(rowCount); + try { + await this.salaryRepo.save(profileSalary); + } catch (error) { + console.error("Error executing function from controller:", item.CIT); + } + } + order = 1; + } return new HttpSuccess(); } @@ -949,98 +1334,96 @@ export class ImportDataController extends Controller { // .take(BATCH_SIZE) // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "FATHER_RANK_NAME", - "FATHER_FNAME", - "FATHER_LNAME", - "MOTHER_RANK_NAME", - "MOTHER_FNAME", - "MOTHER_LNAME", - "SPOUSE_RANK_NAME", - "SPOUSE_FNAME", - "SPOUSE_LNAME", - "SPOUSE_ID", - "MARRIAGE_STATE", - ], - }); - if (!existingProfile) { - return; - } + for await (const _item of profiles) { + const existingProfile = await this.HR_PERSONAL_OFFICER_FAMILYRepo.findOne({ + where: { CIT: _item.citizenId }, + select: [ + "CIT", + "FATHER_RANK_NAME", + "FATHER_FNAME", + "FATHER_LNAME", + "MOTHER_RANK_NAME", + "MOTHER_FNAME", + "MOTHER_LNAME", + "SPOUSE_RANK_NAME", + "SPOUSE_FNAME", + "SPOUSE_LNAME", + "SPOUSE_ID", + "MARRIAGE_STATE", + ], + }); + if (!existingProfile) { + continue; + } - rowCount++; - const profileFather = new ProfileFamilyFather(); - const profileMother = new ProfileFamilyMother(); - const profileCouple = new ProfileFamilyCouple(); + rowCount++; + const profileFather = new ProfileFamilyFather(); + const profileMother = new ProfileFamilyMother(); + const profileCouple = new ProfileFamilyCouple(); - profileFather.profileId = _item.id; - profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; - profileFather.fatherFirstName = existingProfile.FATHER_FNAME; - profileFather.fatherLastName = existingProfile.FATHER_LNAME; - profileFather.createdUserId = request.user.sub; - profileFather.createdFullName = request.user.name; - profileFather.lastUpdateUserId = request.user.sub; - profileFather.lastUpdateFullName = request.user.name; - profileFather.createdAt = new Date(); - profileFather.lastUpdatedAt = new Date(); + profileFather.profileId = _item.id; + profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; + profileFather.fatherFirstName = existingProfile.FATHER_FNAME; + profileFather.fatherLastName = existingProfile.FATHER_LNAME; + profileFather.createdUserId = request.user.sub; + profileFather.createdFullName = request.user.name; + profileFather.lastUpdateUserId = request.user.sub; + profileFather.lastUpdateFullName = request.user.name; + profileFather.createdAt = new Date(); + profileFather.lastUpdatedAt = new Date(); - profileMother.profileId = _item.id; - profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; - profileMother.motherFirstName = existingProfile.MOTHER_FNAME; - profileMother.motherLastName = existingProfile.MOTHER_LNAME; - profileMother.createdUserId = request.user.sub; - profileMother.createdFullName = request.user.name; - profileMother.lastUpdateUserId = request.user.sub; - profileMother.lastUpdateFullName = request.user.name; - profileMother.createdAt = new Date(); - profileMother.lastUpdatedAt = new Date(); + profileMother.profileId = _item.id; + profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; + profileMother.motherFirstName = existingProfile.MOTHER_FNAME; + profileMother.motherLastName = existingProfile.MOTHER_LNAME; + profileMother.createdUserId = request.user.sub; + profileMother.createdFullName = request.user.name; + profileMother.lastUpdateUserId = request.user.sub; + profileMother.lastUpdateFullName = request.user.name; + profileMother.createdAt = new Date(); + profileMother.lastUpdatedAt = new Date(); - profileCouple.profileId = _item.id; - profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; - profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; - profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; - profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = - existingProfile.MARRIAGE_STATE == "1" - ? "โสด" - : existingProfile.MARRIAGE_STATE == "2" - ? "สมรส" - : existingProfile.MARRIAGE_STATE == "3" - ? "หย่าร้าง" - : existingProfile.MARRIAGE_STATE == "4" - ? "หม้าย" - : "-"; - // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; - profileCouple.createdUserId = request.user.sub; - profileCouple.createdFullName = request.user.name; - profileCouple.lastUpdateUserId = request.user.sub; - profileCouple.lastUpdateFullName = request.user.name; - profileCouple.createdAt = new Date(); - profileCouple.lastUpdatedAt = new Date(); + profileCouple.profileId = _item.id; + profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; + profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; + profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; + profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; + profileCouple.relationship = + existingProfile.MARRIAGE_STATE == "1" + ? "โสด" + : existingProfile.MARRIAGE_STATE == "2" + ? "สมรส" + : existingProfile.MARRIAGE_STATE == "3" + ? "หย่าร้าง" + : existingProfile.MARRIAGE_STATE == "4" + ? "หม้าย" + : "-"; + // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; + profileCouple.createdUserId = request.user.sub; + profileCouple.createdFullName = request.user.name; + profileCouple.lastUpdateUserId = request.user.sub; + profileCouple.lastUpdateFullName = request.user.name; + profileCouple.createdAt = new Date(); + profileCouple.lastUpdatedAt = new Date(); - // fathers.push(profileFather); - // mothers.push(profileMother); - // couples.push(profileCouple); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // fathers.push(profileFather); + // mothers.push(profileMother); + // couples.push(profileCouple); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - // if (fathers.length === BATCH_SIZE) { - await this.profileFamilyFatherRepository.save(profileFather); - // fathers = await []; - // } - // if (mothers.length === BATCH_SIZE) { - await this.profileFamilyMotherRepository.save(profileMother); - // mothers = await []; - // } - // if (couples.length === BATCH_SIZE) { - await this.profileFamilyCoupleRepository.save(profileCouple); - // couples = await []; - // } - }), - ); + // if (fathers.length === BATCH_SIZE) { + await this.profileFamilyFatherRepository.save(profileFather); + // fathers = await []; + // } + // if (mothers.length === BATCH_SIZE) { + await this.profileFamilyMotherRepository.save(profileMother); + // mothers = await []; + // } + // if (couples.length === BATCH_SIZE) { + await this.profileFamilyCoupleRepository.save(profileCouple); + // couples = await []; + // } + } // } // console.log(rowCount); @@ -1079,98 +1462,96 @@ export class ImportDataController extends Controller { // .take(BATCH_SIZE) // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_PERSONAL_EMP_FAMILYRepo.findOne({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "FATHER_RANK_NAME", - "FATHER_FNAME", - "FATHER_LNAME", - "MOTHER_RANK_NAME", - "MOTHER_FNAME", - "MOTHER_LNAME", - "SPOUSE_RANK_NAME", - "SPOUSE_FNAME", - "SPOUSE_LNAME", - "SPOUSE_ID", - "MARRIAGE_STATE", - ], - }); - if (!existingProfile) { - return; - } + for await (const _item of profiles) { + const existingProfile = await this.HR_PERSONAL_EMP_FAMILYRepo.findOne({ + where: { CIT: _item.citizenId }, + select: [ + "CIT", + "FATHER_RANK_NAME", + "FATHER_FNAME", + "FATHER_LNAME", + "MOTHER_RANK_NAME", + "MOTHER_FNAME", + "MOTHER_LNAME", + "SPOUSE_RANK_NAME", + "SPOUSE_FNAME", + "SPOUSE_LNAME", + "SPOUSE_ID", + "MARRIAGE_STATE", + ], + }); + if (!existingProfile) { + continue; + } - rowCount++; - const profileFather = new ProfileFamilyFather(); - const profileMother = new ProfileFamilyMother(); - const profileCouple = new ProfileFamilyCouple(); + rowCount++; + const profileFather = new ProfileFamilyFather(); + const profileMother = new ProfileFamilyMother(); + const profileCouple = new ProfileFamilyCouple(); - profileFather.profileEmployeeId = _item.id; - profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; - profileFather.fatherFirstName = existingProfile.FATHER_FNAME; - profileFather.fatherLastName = existingProfile.FATHER_LNAME; - profileFather.createdUserId = request.user.sub; - profileFather.createdFullName = request.user.name; - profileFather.lastUpdateUserId = request.user.sub; - profileFather.lastUpdateFullName = request.user.name; - profileFather.createdAt = new Date(); - profileFather.lastUpdatedAt = new Date(); + profileFather.profileEmployeeId = _item.id; + profileFather.fatherPrefix = existingProfile.FATHER_RANK_NAME; + profileFather.fatherFirstName = existingProfile.FATHER_FNAME; + profileFather.fatherLastName = existingProfile.FATHER_LNAME; + profileFather.createdUserId = request.user.sub; + profileFather.createdFullName = request.user.name; + profileFather.lastUpdateUserId = request.user.sub; + profileFather.lastUpdateFullName = request.user.name; + profileFather.createdAt = new Date(); + profileFather.lastUpdatedAt = new Date(); - profileMother.profileEmployeeId = _item.id; - profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; - profileMother.motherFirstName = existingProfile.MOTHER_FNAME; - profileMother.motherLastName = existingProfile.MOTHER_LNAME; - profileMother.createdUserId = request.user.sub; - profileMother.createdFullName = request.user.name; - profileMother.lastUpdateUserId = request.user.sub; - profileMother.lastUpdateFullName = request.user.name; - profileMother.createdAt = new Date(); - profileMother.lastUpdatedAt = new Date(); + profileMother.profileEmployeeId = _item.id; + profileMother.motherPrefix = existingProfile.MOTHER_RANK_NAME; + profileMother.motherFirstName = existingProfile.MOTHER_FNAME; + profileMother.motherLastName = existingProfile.MOTHER_LNAME; + profileMother.createdUserId = request.user.sub; + profileMother.createdFullName = request.user.name; + profileMother.lastUpdateUserId = request.user.sub; + profileMother.lastUpdateFullName = request.user.name; + profileMother.createdAt = new Date(); + profileMother.lastUpdatedAt = new Date(); - profileCouple.profileEmployeeId = _item.id; - profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; - profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; - profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; - profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; - profileCouple.relationship = - existingProfile.MARRIAGE_STATE == "1" - ? "โสด" - : existingProfile.MARRIAGE_STATE == "2" - ? "สมรส" - : existingProfile.MARRIAGE_STATE == "3" - ? "หย่าร้าง" - : existingProfile.MARRIAGE_STATE == "4" - ? "หม้าย" - : "-"; - // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; - profileCouple.createdUserId = request.user.sub; - profileCouple.createdFullName = request.user.name; - profileCouple.lastUpdateUserId = request.user.sub; - profileCouple.lastUpdateFullName = request.user.name; - profileCouple.createdAt = new Date(); - profileCouple.lastUpdatedAt = new Date(); + profileCouple.profileEmployeeId = _item.id; + profileCouple.couplePrefix = existingProfile.SPOUSE_RANK_NAME; + profileCouple.coupleFirstName = existingProfile.SPOUSE_FNAME; + profileCouple.coupleLastName = existingProfile.SPOUSE_LNAME; + profileCouple.coupleCitizenId = existingProfile.SPOUSE_ID; + profileCouple.relationship = + existingProfile.MARRIAGE_STATE == "1" + ? "โสด" + : existingProfile.MARRIAGE_STATE == "2" + ? "สมรส" + : existingProfile.MARRIAGE_STATE == "3" + ? "หย่าร้าง" + : existingProfile.MARRIAGE_STATE == "4" + ? "หม้าย" + : "-"; + // profileCouple.coupleLive = existingProfile.LIFE_SPOUSE; + profileCouple.createdUserId = request.user.sub; + profileCouple.createdFullName = request.user.name; + profileCouple.lastUpdateUserId = request.user.sub; + profileCouple.lastUpdateFullName = request.user.name; + profileCouple.createdAt = new Date(); + profileCouple.lastUpdatedAt = new Date(); - // fathers.push(profileFather); - // mothers.push(profileMother); - // couples.push(profileCouple); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + // fathers.push(profileFather); + // mothers.push(profileMother); + // couples.push(profileCouple); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - // if (fathers.length === BATCH_SIZE) { - await this.profileFamilyFatherRepository.save(profileFather); - // fathers = await []; - // } - // if (mothers.length === BATCH_SIZE) { - await this.profileFamilyMotherRepository.save(profileMother); - // mothers = await []; - // } - // if (couples.length === BATCH_SIZE) { - await this.profileFamilyCoupleRepository.save(profileCouple); - // couples = await []; - // } - }), - ); + // if (fathers.length === BATCH_SIZE) { + await this.profileFamilyFatherRepository.save(profileFather); + // fathers = await []; + // } + // if (mothers.length === BATCH_SIZE) { + await this.profileFamilyMotherRepository.save(profileMother); + // mothers = await []; + // } + // if (couples.length === BATCH_SIZE) { + await this.profileFamilyCoupleRepository.save(profileCouple); + // couples = await []; + // } + } // } // console.log(rowCount); @@ -1275,15 +1656,21 @@ export class ImportDataController extends Controller { where: { FUND_COURSE_CODE: item.FUND_COURSE_CODE }, }); - let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) - : _null; - // startDate = startDate ? new Date(startDate, 0, 1) : _null; + // let startDate = item.START_EDUCATION_YEAR + // ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) + // : _null; + let startDate = + item.START_EDUCATION_YEAR != "" && Number(item.START_EDUCATION_YEAR) > 2500 + ? new Date(Number(item.START_EDUCATION_YEAR) - 543, 0, 1) + : _null; - let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) - : _null; - // endDate = endDate ? new Date(endDate, 0, 1) : _null; + // let endDate = item.EDUCATION_YEAR + // ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) + // : _null; + let endDate = + item.EDUCATION_YEAR != "" && Number(item.EDUCATION_YEAR) > 2500 + ? new Date(Number(item.EDUCATION_YEAR) - 543, 0, 1) + : _null; if (item.FLAG_EDUCATION == "1") { const checkData = await this.HR_EDUCATIONRepo.find({ where: { CIT: _item.citizenId, FLAG_EDUCATION: "1" }, @@ -1367,66 +1754,108 @@ export class ImportDataController extends Controller { // .take(BATCH_SIZE) // .getMany(); - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_EDUCATION_EMPRepo.find({ - where: { CIT: _item.citizenId }, - select: [ - "CIT", - "EDUCATION_CODE", - "START_EDUCATION_YEAR", - "EDUCATION_YEAR", - "INSTITUE", - "EDUCATION_SEQ", - ], + for (const _item of profiles) { + const existingProfile = await this.HR_EDUCATION_EMPRepo.find({ + where: { CIT: _item.citizenId }, + // select: [ + // "CIT", + // "EDUCATION_CODE", + // "START_EDUCATION_YEAR", + // "EDUCATION_YEAR", + // "INSTITUE", + // "EDUCATION_SEQ", + // ], + order: { EDUCATION_SEQ: "ASC" }, + }); + + const educationLevel = await this.profileEducationRepo.findOne({ + select: ["id", "level", "profileEmployeeId"], + where: { profileEmployeeId: _item.id }, + order: { level: "DESC" }, + }); + + // educations = await []; + for (const item of existingProfile) { + rowCount++; + const education = new ProfileEducation(); + const educationCode = await this.educationMisRepo.findOne({ + where: { EDUCATION_CODE: item.EDUCATION_CODE }, + }); + const hrMajorCode = await this.HR_MAJOR_CODERepo.findOne({ + where: { MAJOR_CODE: item.MAJOR_CODE }, + }); + const hrFundCourseCode = await this.HR_FUND_COURSE_CODERepo.findOne({ + where: { FUND_COURSE_CODE: item.FUND_COURSE_CODE }, }); - const educationLevel = await this.profileEducationRepo.findOne({ - select: ["id", "level", "profileId"], - where: { profileEmployeeId: _item.id }, - order: { level: "DESC" }, - }); + // let startDate = item.START_EDUCATION_YEAR + // ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) + // : _null; + let startDate = + item.START_EDUCATION_YEAR != "" && Number(item.START_EDUCATION_YEAR) > 2500 + ? new Date(Number(item.START_EDUCATION_YEAR) - 543, 0, 1) + : _null; - educations = await []; - await Promise.all( - existingProfile.map(async (item) => { - rowCount++; - const education = new ProfileEducation(); - const educationCode = await this.educationMisRepo.findOne({ - where: { EDUCATION_CODE: item.EDUCATION_CODE }, + // let endDate = item.EDUCATION_YEAR + // ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) + // : _null; + let endDate = + item.EDUCATION_YEAR != "" && Number(item.EDUCATION_YEAR) > 2500 + ? new Date(Number(item.EDUCATION_YEAR) - 543, 0, 1) + : _null; + if (item.FLAG_EDUCATION == "1") { + const checkData = await this.HR_EDUCATIONRepo.find({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "1" }, + order: { EDUCATION_SEQ: "DESC" }, + }); + if ((checkData.length > 1 && checkData[0].id == item.id) || checkData.length == 1) { + education.isEducation = true; + const findIsHigh = await this.HR_EDUCATIONRepo.findOne({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "3" }, }); - - let startDate = item.START_EDUCATION_YEAR - ? Extension.ConvertToDateTimeV2(item.START_EDUCATION_YEAR) - : _null; - // startDate = startDate ? new Date(startDate, 0, 1) : _null; - - let endDate = item.EDUCATION_YEAR - ? Extension.ConvertToDateTimeV2(item.EDUCATION_YEAR) - : _null; - // endDate = endDate ? new Date(endDate, 0, 1) : _null; - - education.level = educationLevel == null ? 1 : educationLevel.level + 1; - education.profileEmployeeId = _item.id; - education.degree = educationCode ? educationCode.EDUCATION_NAME : ""; - education.institute = item.INSTITUE; - education.level = item.EDUCATION_SEQ ? _null : Number(item.EDUCATION_SEQ); - education.startDate = startDate; - education.endDate = endDate; - education.createdUserId = request.user.sub; - education.createdFullName = request.user.name; - education.lastUpdateUserId = request.user.sub; - education.lastUpdateFullName = request.user.name; - education.createdAt = new Date(); - education.lastUpdatedAt = new Date(); - // educations.push(education); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - await this.profileEducationRepo.save(education); - }), - ); - // await this.profileEducationRepo.save(educations); - }), - ); + if (findIsHigh == null) { + education.isHigh = true; + } + } + } else if (item.FLAG_EDUCATION == "2") { + } else if (item.FLAG_EDUCATION == "3") { + const checkData = await this.HR_EDUCATIONRepo.find({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "3" }, + order: { EDUCATION_SEQ: "DESC" }, + }); + if ((checkData.length > 1 && checkData[0].id == item.id) || checkData.length == 1) { + education.isHigh = true; + const findIsEducation = await this.HR_EDUCATIONRepo.findOne({ + where: { CIT: _item.citizenId, FLAG_EDUCATION: "1" }, + }); + if (findIsEducation == null) { + education.isEducation = true; + } + } + } + education.level = educationLevel == null ? 1 : educationLevel.level + 1; + education.profileEmployeeId = _item.id; + education.degree = educationCode ? educationCode.EDUCATION_NAME : _null; + education.field = hrMajorCode ? hrMajorCode.MAJOR_NAME : _null; + education.educationLevel = hrFundCourseCode ? hrFundCourseCode.FUND_COURSE_NAME : _null; + education.educationLevelId = hrFundCourseCode ? hrFundCourseCode.refId : _null; + education.institute = item.INSTITUE; + education.level = item.EDUCATION_SEQ ? Number(item.EDUCATION_SEQ) : _null; + education.startDate = startDate; + education.endDate = endDate; + education.createdUserId = request.user.sub; + education.createdFullName = request.user.name; + education.lastUpdateUserId = request.user.sub; + education.lastUpdateFullName = request.user.name; + education.createdAt = new Date(); + education.lastUpdatedAt = new Date(); + // await educations.push(await education); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileEducationRepo.save(await education); + } + // await this.profileEducationRepo.save(educations); + // educations = await []; + } // } // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); // await this.profileEducationRepo.save(educations); @@ -1751,143 +2180,190 @@ export class ImportDataController extends Controller { // .skip(0) // .take(20) .getManyAndCount(); - // for (var i = 1; i <= total / BATCH_SIZE; i++) { - // const profiles = await AppDataSource.getRepository(ProfileEmployee) - // .createQueryBuilder("profile") - // .orderBy("profile.citizenId", "ASC") - // .skip((i - 1) * BATCH_SIZE) - // .take(BATCH_SIZE) - // .getMany(); - // profileDatas = await []; - await Promise.all( - profiles.map(async (_item) => { - const existingProfile = await this.HR_PERSONAL_EMP_ADDRESSRepo.findOne({ - where: { CIT: _item.citizenId }, + const meta = { + createdUserId: request.user.sub, + createdFullName: request.user.name, + lastUpdateUserId: request.user.sub, + lastUpdateFullName: request.user.name, + createdAt: new Date(), + lastUpdatedAt: new Date(), + }; + for (const _item of profiles) { + const existingProfile = await this.HR_PERSONAL_EMP_ADDRESSRepo.findOne({ + where: { CIT: _item.citizenId }, + }); + + if (!existingProfile) { + continue; + } + let PROVINCE_CODE = Number(existingProfile.PROVINCE_CODE).toString(); + let DISTRICT_CODE = Number(existingProfile.DISTRICT_CODE).toString(); + let AMPHUR_CODE = Number(existingProfile.AMPHUR_CODE).toString(); + let CONTACT_PROVINCE_CODE = Number(existingProfile.CONTACT_PROVINCE_CODE).toString(); + let CONTACT_DISTRICT_CODE = Number(existingProfile.CONTACT_DISTRICT_CODE).toString(); + let CONTACT_AMPHUR_CODE = Number(existingProfile.CONTACT_AMPHUR_CODE).toString(); + rowCount++; + //registration address + if (PROVINCE_CODE) { + let provinceRegis_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: PROVINCE_CODE }, }); - - if (!existingProfile) { - return; - } - - rowCount++; - let provinceRegis_: any = null; - let districtRegis_: any = null; - let subDistrictRegis_: any = null; - let provinceCurr_: any = null; - let districtCurr_: any = null; - let subDistrictCurr_: any = null; - //registration address - if (existingProfile.PROVINCE_CODE) { - provinceRegis_ = await this.provincsRepo.findOne({ - where: { PROVINCE_CODE: existingProfile.PROVINCE_CODE }, - }); - if (provinceRegis_) { - let provinceId = await this.provinceIdRepo.findOne({ - where: { - name: provinceRegis_.PROVINCE_NAME, - }, - }); - _item.registrationProvinceId = provinceId ? provinceId.id : _null; - } - } - if (existingProfile.AMPHUR_CODE && provinceRegis_) { - districtRegis_ = await this.amphurRepo.findOne({ + if (provinceRegis_) { + let provinceId = await this.provinceIdRepo.findOne({ where: { - AMPHUR_CODE: existingProfile.AMPHUR_CODE, - PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + name: provinceRegis_.PROVINCE_NAME, }, }); - if (districtRegis_) { - let districtId = await this.districtIdRepo.findOne({ + if (provinceId == null) { + provinceId = new Province(); + Object.assign(provinceId, { + ...meta, + name: provinceRegis_.PROVINCE_NAME, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.registrationProvinceId = provinceId ? provinceId.id : _null; + if (AMPHUR_CODE) { + let districtRegis_ = await this.amphurRepo.findOne({ where: { - name: districtRegis_.AMPHUR_NAME, + AMPHUR_CODE: AMPHUR_CODE, + PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, }, }); - _item.registrationDistrictId = districtId ? districtId.id : _null; + if (districtRegis_) { + let districtId = await this.districtIdRepo.findOne({ + where: { + name: districtRegis_.AMPHUR_NAME, + }, + }); + if (districtId == null) { + districtId = new District(); + Object.assign(districtId, { + ...meta, + name: districtRegis_.AMPHUR_NAME, + provinceId: provinceId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.registrationDistrictId = districtId ? districtId.id : _null; + if (DISTRICT_CODE) { + let subDistrictRegis_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: DISTRICT_CODE, + AMPHUR_CODE: districtRegis_.AMPHUR_CODE, + PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + }, + }); + if (subDistrictRegis_) { + let subDistrictId = await this.subDistrictIdRepo.findOne({ + where: { + name: subDistrictRegis_.DISTRICT_NAME, + }, + }); + if (subDistrictId == null) { + subDistrictId = new SubDistrict(); + Object.assign(subDistrictId, { + ...meta, + name: subDistrictRegis_.DISTRICT_NAME, + zipCode: existingProfile.ZIPCODE, + districtId: districtId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : _null; + } + } + } } } - if (existingProfile.DISTRICT_CODE && districtRegis_ && provinceRegis_) { - subDistrictRegis_ = await this.subDistrictRepo.findOne({ + } + //current address + if (CONTACT_PROVINCE_CODE) { + let provinceCurr_ = await this.provincsRepo.findOne({ + where: { PROVINCE_CODE: CONTACT_PROVINCE_CODE }, + }); + if (provinceCurr_) { + let provinceId = await this.provinceIdRepo.findOne({ where: { - DISTRICT_CODE: existingProfile.DISTRICT_CODE, - AMPHUR_CODE: districtRegis_.AMPHUR_CODE, - PROVINCE_CODE: provinceRegis_.PROVINCE_CODE, + name: provinceCurr_.PROVINCE_NAME, }, }); - if (subDistrictRegis_) { - let subDistrictId = await this.subDistrictIdRepo.findOne({ + if (provinceId == null) { + provinceId = new Province(); + Object.assign(provinceId, { + ...meta, + name: provinceCurr_.PROVINCE_NAME, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.currentProvinceId = provinceId ? provinceId.id : _null; + if (CONTACT_AMPHUR_CODE) { + let districtCurr_ = await this.amphurRepo.findOne({ where: { - name: subDistrictRegis_.DISTRICT_NAME, + AMPHUR_CODE: CONTACT_AMPHUR_CODE, + PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, }, }); - _item.registrationSubDistrictId = subDistrictId ? subDistrictId.id : _null; + if (districtCurr_) { + let districtId = await this.districtIdRepo.findOne({ + where: { + name: districtCurr_.AMPHUR_NAME, + }, + }); + if (districtId == null) { + districtId = new District(); + Object.assign(districtId, { + ...meta, + name: districtCurr_.AMPHUR_NAME, + provinceId: provinceId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.currentDistrictId = districtId ? districtId.id : _null; + if (CONTACT_DISTRICT_CODE) { + let subDistrictCurr_ = await this.subDistrictRepo.findOne({ + where: { + DISTRICT_CODE: CONTACT_DISTRICT_CODE, + AMPHUR_CODE: districtCurr_.AMPHUR_CODE, + PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, + }, + }); + if (subDistrictCurr_) { + let subDistrictId = await this.subDistrictIdRepo.findOne({ + where: { + name: subDistrictCurr_.DISTRICT_NAME, + }, + }); + if (subDistrictId == null) { + subDistrictId = new SubDistrict(); + Object.assign(subDistrictId, { + ...meta, + name: subDistrictCurr_.DISTRICT_NAME, + zipCode: existingProfile.CONTACT_ZIPCODE, + districtId: districtId.id, + }); + await this.provinceIdRepo.save(provinceId); + } + _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : _null; + } + } + } } } - //current address - if (existingProfile.CONTACT_PROVINCE_CODE) { - provinceCurr_ = await this.provincsRepo.findOne({ - where: { PROVINCE_CODE: existingProfile.CONTACT_PROVINCE_CODE }, - }); - if (provinceCurr_) { - let provinceId = await this.provinceIdRepo.findOne({ - where: { - name: provinceCurr_.PROVINCE_NAME, - }, - }); - _item.currentProvinceId = provinceId ? provinceId.id : _null; - } - } - if (existingProfile.CONTACT_AMPHUR_CODE && provinceCurr_) { - districtCurr_ = await this.amphurRepo.findOne({ - where: { - AMPHUR_CODE: existingProfile.CONTACT_AMPHUR_CODE, - PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, - }, - }); - if (districtCurr_) { - let districtId = await this.districtIdRepo.findOne({ - where: { - name: districtCurr_.AMPHUR_NAME, - }, - }); - _item.currentDistrictId = districtId ? districtId.id : _null; - } - } - if (existingProfile.CONTACT_DISTRICT_CODE && districtCurr_ && provinceCurr_) { - subDistrictCurr_ = await this.subDistrictRepo.findOne({ - where: { - DISTRICT_CODE: existingProfile.CONTACT_DISTRICT_CODE, - AMPHUR_CODE: districtCurr_.AMPHUR_CODE, - PROVINCE_CODE: provinceCurr_.PROVINCE_CODE, - }, - }); - if (subDistrictCurr_) { - let subDistrictId = await this.subDistrictIdRepo.findOne({ - where: { - name: subDistrictCurr_.DISTRICT_NAME, - }, - }); - _item.currentSubDistrictId = subDistrictId ? subDistrictId.id : _null; - } - } - _item.registrationAddress = existingProfile.H_NUMBER; - _item.registrationZipCode = existingProfile.ZIPCODE; - _item.currentAddress = existingProfile.CONTACT_H_NUMBER; - _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; - _item.createdUserId = request.user.sub; - _item.createdFullName = request.user.name; - _item.lastUpdateUserId = request.user.sub; - _item.lastUpdateFullName = request.user.name; - _item.createdAt = new Date(); - _item.lastUpdatedAt = new Date(); - // profileDatas.push(_item); - console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); - await this.profileEmpRepo.save(_item); - }), - ); - // await this.profileEmpRepo.save(profileDatas); - // } - // console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + } + _item.registrationAddress = existingProfile.H_NUMBER; + _item.registrationZipCode = existingProfile.ZIPCODE; + _item.currentAddress = existingProfile.CONTACT_H_NUMBER; + _item.currentZipCode = existingProfile.CONTACT_ZIPCODE; + _item.createdUserId = request.user.sub; + _item.createdFullName = request.user.name; + _item.lastUpdateUserId = request.user.sub; + _item.lastUpdateFullName = request.user.name; + _item.createdAt = new Date(); + _item.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileEmpRepo.save(_item); + } return new HttpSuccess(); } /** @@ -2302,8 +2778,8 @@ export class ImportDataController extends Controller { let type_: any = null; let level_: any = null; const orgRevision = await this.orgRevisionRepo.findOne({ - // where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, - where: { id: "30e594c9-a65b-485e-a4c5-71aa497e6b8a" }, + where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true }, + // where: { id: "30e594c9-a65b-485e-a4c5-71aa497e6b8a" }, }); if (orgRevision == null) return new HttpSuccess(); for await (const _item of officer) { @@ -2392,7 +2868,9 @@ export class ImportDataController extends Controller { } } } + posMaster.statusReport = "PENDING"; + posMaster.posMasterOrder = 1; posMaster.isCondition = false; posMaster.isStaff = false; posMaster.isDirector = false; @@ -2408,32 +2886,84 @@ export class ImportDataController extends Controller { posMaster.lastUpdateFullName = request.user.name; posMaster.createdAt = new Date(); posMaster.lastUpdatedAt = new Date(); + if (posMaster.orgRootId == null) { + continue; + } await this.posMasterRepo.save(posMaster); posMaster.ancestorDNA = posMaster.id; await this.posMasterRepo.save(posMaster); let position = new Position(); - if (item.MP_CATEGORY) { + 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 = "สูง"; + } + if (positionType) { type_ = await this.posTypeRepo.findOne({ - where: { posTypeName: item.MP_CATEGORY }, + where: { posTypeName: positionType }, }); } - if (item.MP_LEVEL) { + if (positionLevel) { if (type_ == null) { level_ = await this.posLevelRepo.findOne({ where: { - posLevelName: item.MP_LEVEL, + posLevelName: positionLevel, }, }); } else { level_ = await this.posLevelRepo.findOne({ where: { - posLevelName: item.MP_LEVEL, + posLevelName: positionLevel, posTypeId: type_.id, }, }); } } + position.posMasterId = posMaster.id; position.isSpecial = false; position.positionIsSelected = true; @@ -2470,13 +3000,238 @@ export class ImportDataController extends Controller { position.posExecutiveId = posExecutive == null ? _null : posExecutive.id; position.positionName = item.WORK_LINE_NAME == "" ? _null : item.WORK_LINE_NAME; position.posTypeId = - type_ != null && type_.posTypeName == item.MP_CATEGORY && type_ ? type_.id : null; + type_ != null && type_.posTypeName == positionType && type_ ? type_.id : null; position.posLevelId = - level_ != null && level_.posLevelName == item.MP_LEVEL && level_ ? level_.id : null; + level_ != null && level_.posLevelName == positionLevel && level_ ? level_.id : null; + if (position.posTypeId == null || position.posLevelId == null) { + await this.posMasterRepo.delete({ id: posMaster.id }); + continue; + } await this.positionRepo.save(position); } return new HttpSuccess(); } + /** + * @summary ทะเบียนประวัติ ลูกจ้าง + */ + @Post("mapposition-Employee") + async MapPositionEmployee(@Request() request: { user: Record }) { + const employee = await AppDataSource.getRepository(ProfileEmployee) + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.next_holders", "posMaster") + // .where({citizenId: "1720700018869"}) + .where("posMaster.id IS NULL") + .getMany(); + let rowCount = 0; + let _null: any = null; + let type_: any = null; + let level_: any = null; + const orgRevision = await this.orgRevisionRepo.findOne({ + where: { orgRevisionIsCurrent: false, orgRevisionIsDraft: true }, + // where: { id: "30e594c9-a65b-485e-a4c5-71aa497e6b8a" }, + }); + if (orgRevision == null) return new HttpSuccess(); + for await (const _item of employee) { + rowCount++; + console.log(rowCount); + const item = await AppDataSource.getRepository(EMPLOYEE) + .createQueryBuilder("EMPLOYEE") + .where({ CIT: _item.citizenId }) + .getOne(); + + if (item == null) { + continue; + } + + item.DEPARTMENT_CODE = item.DEPARTMENT_CODE.toString().padStart(2, "0"); + item.DIVISION_CODE = item.DIVISION_CODE.toString().padStart(2, "0"); + item.SECTION_CODE = item.SECTION_CODE.toString().padStart(2, "0"); + item.JOB_CODE = item.JOB_CODE.toString().padStart(2, "0"); + let posMaster = new EmployeePosMaster(); + let orgRoot = (await this.orgRootRepo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + })) as OrgRoot; + if (orgRoot != null) { + posMaster.orgRootId = orgRoot.id ?? _null; + } else { + let orgChild1 = await this.orgChild1Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild1 != null) { + posMaster.orgRootId = orgChild1.orgRootId ?? _null; + posMaster.orgChild1Id = orgChild1.id ?? _null; + } else { + let orgChild2 = await this.orgChild2Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild2 != null) { + posMaster.orgRootId = orgChild2.orgRootId ?? _null; + posMaster.orgChild1Id = orgChild2.orgChild1Id ?? _null; + posMaster.orgChild2Id = orgChild2.id ?? _null; + } else { + let orgChild3 = await this.orgChild3Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild3 != null) { + posMaster.orgRootId = orgChild3.orgRootId ?? _null; + posMaster.orgChild1Id = orgChild3.orgChild1Id ?? _null; + posMaster.orgChild2Id = orgChild3.orgChild2Id ?? _null; + posMaster.orgChild3Id = orgChild3.id ?? _null; + } else { + let orgChild4 = await this.orgChild4Repo.findOne({ + where: { + DEPARTMENT_CODE: item.DEPARTMENT_CODE, + DIVISION_CODE: item.DIVISION_CODE, + SECTION_CODE: item.SECTION_CODE, + JOB_CODE: item.JOB_CODE, + orgRevisionId: orgRevision.id, + }, + }); + if (orgChild4 != null) { + posMaster.orgRootId = orgChild4.id ?? _null; + posMaster.orgChild1Id = orgChild4.id ?? _null; + posMaster.orgChild2Id = orgChild4.id ?? _null; + posMaster.orgChild3Id = orgChild4.id ?? _null; + posMaster.orgChild4Id = orgChild4.id ?? _null; + } + } + } + } + } + + // posMaster.statusReport = "PENDING"; + posMaster.posMasterOrder = 1; + // posMaster.isCondition = false; + posMaster.isStaff = false; + posMaster.isDirector = false; + posMaster.isSit = false; + posMaster.next_holderId = _item.id; + posMaster.posMasterNo = + item.POS_NUM_CODE == "" || item.POS_NUM_CODE == null ? _null : Number(item.POS_NUM_CODE); + posMaster.orgRevisionId = orgRevision.id; + posMaster.posMasterCreatedAt = new Date(); + posMaster.createdUserId = request.user.sub; + posMaster.createdFullName = request.user.name; + posMaster.lastUpdateUserId = request.user.sub; + posMaster.lastUpdateFullName = request.user.name; + posMaster.createdAt = new Date(); + posMaster.lastUpdatedAt = new Date(); + if (posMaster.orgRootId == null) { + continue; + } + await this.posMasterEmpRepo.save(posMaster); + posMaster.ancestorDNA = posMaster.id; + await this.posMasterEmpRepo.save(posMaster); + + let position = new EmployeePosition(); + var positionType = ""; + var positionLevel = + item.LEVEL_NAME == "" || item.LEVEL_NAME == null ? 0 : Number(item.LEVEL_NAME); + if (item.CATEGORY_SAL_CODE == "11") { + positionType = "บริการพื้นฐาน"; + } else if (item.CATEGORY_SAL_CODE == "12") { + positionType = "สนับสนุน"; + } else if (item.CATEGORY_SAL_CODE == "13") { + positionType = "ช่าง"; + } + if (positionType) { + type_ = await this.posTypeEmpRepo.findOne({ + where: { posTypeName: positionType }, + }); + } + if (positionType) { + type_ = await this.posTypeEmpRepo.findOne({ + where: { posTypeName: positionType }, + }); + } + if (positionLevel) { + if (type_ == null) { + level_ = await this.posLevelEmpRepo.findOne({ + where: { + posLevelName: positionLevel, + }, + }); + } else { + level_ = await this.posLevelEmpRepo.findOne({ + where: { + posLevelName: positionLevel, + posTypeId: type_.id, + }, + }); + } + } + + position.posMasterId = posMaster.id; + // position.isSpecial = false; + position.positionIsSelected = true; + position.createdUserId = request.user.sub; + position.createdFullName = request.user.name; + position.lastUpdateUserId = request.user.sub; + position.lastUpdateFullName = request.user.name; + position.createdAt = new Date(); + position.lastUpdatedAt = new Date(); + + // const posExecutive = await this.posExecutiveRepo.findOne({ + // where: { + // posExecutiveName: item.ADMIN_NAME, + // }, + // }); + // if (posExecutive == null && item.ADMIN_NAME != "" && item.ADMIN_NAME != null) { + // const posExecutiveOrder = await this.posExecutiveRepo.findOne({ + // where: { posExecutivePriority: Not(IsNull()) }, + // order: { posExecutivePriority: "DESC" }, + // }); + // let posExecutive = new PosExecutive(); + + // posExecutive.posExecutivePriority = + // posExecutiveOrder == null ? _null : posExecutiveOrder.posExecutivePriority + 1; + // posExecutive.posExecutiveName = item.ADMIN_NAME; + // posExecutive.createdUserId = request.user.sub; + // posExecutive.createdFullName = request.user.name; + // posExecutive.lastUpdateUserId = request.user.sub; + // posExecutive.lastUpdateFullName = request.user.name; + // posExecutive.createdAt = new Date(); + // posExecutive.lastUpdatedAt = new Date(); + // await this.posExecutiveRepo.save(posExecutive); + // } + // position.posExecutiveId = posExecutive == null ? _null : posExecutive.id; + position.positionName = item.WORK_LINE_NAME == "" ? _null : item.WORK_LINE_NAME.split(" ")[0]; + position.posTypeId = + type_ != null && type_.posTypeName == positionType && type_ ? type_.id : null; + position.posLevelId = + level_ != null && level_.posLevelName == positionLevel && level_ ? level_.id : null; + if (position.posTypeId == null || position.posLevelId == null) { + await this.posMasterEmpRepo.delete({ id: posMaster.id }); + continue; + } + await this.positionEmpRepo.save(position); + } + return new HttpSuccess(); + } /** * @summary เงินเดือน ข้าราชการ @@ -2892,4 +3647,225 @@ export class ImportDataController extends Controller { data: { data: result }, }); } + + /** + * @summary วินัย ข้าราชการ + */ + @Post("uploadProfileDiscipline-Officer") + async UploadFileSQLDiscipline(@Request() request: { user: Record }) { + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(Profile) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_DISCIPLINERepo.find({ + where: { CIT: _item.citizenId }, + }); + + for (const item of existingProfile) { + let CREATE_DATE = ""; + if (item.CREATE_DATE) { + const [datePart] = item.CREATE_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + CREATE_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + rowCount++; + const discipline = new ProfileDiscipline(); + discipline.profileId = _item.id; + discipline.detail = item.REASON_FLAW; + discipline.date = CREATE_DATE == "" ? _null : new Date(CREATE_DATE); + discipline.createdUserId = request.user.sub; + discipline.createdFullName = request.user.name; + discipline.lastUpdateUserId = request.user.sub; + discipline.lastUpdateFullName = request.user.name; + discipline.createdAt = new Date(); + discipline.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileDisciplineRepo.save(await discipline); + } + } + return new HttpSuccess(); + } + + /** + * @summary วินัย ลูกจ้างประจำ + */ + @Post("uploadProfileDiscipline-Employee") + async UploadFileSQLDisciplineEmp(@Request() request: { user: Record }) { + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_DISCIPLINE_EMPRepo.find({ + where: { CIT: _item.citizenId }, + }); + + for (const item of existingProfile) { + let CREATE_DATE = ""; + if (item.CREATE_DATE) { + const [datePart] = item.CREATE_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + CREATE_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + rowCount++; + const discipline = new ProfileDiscipline(); + discipline.profileEmployeeId = _item.id; + discipline.detail = item.REASON_FLAW; + discipline.date = CREATE_DATE == "" ? _null : new Date(CREATE_DATE); + discipline.createdUserId = request.user.sub; + discipline.createdFullName = request.user.name; + discipline.lastUpdateUserId = request.user.sub; + discipline.lastUpdateFullName = request.user.name; + discipline.createdAt = new Date(); + discipline.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileDisciplineRepo.save(await discipline); + } + } + return new HttpSuccess(); + } + + /** + * @summary เครื่องราช ข้าราชการ + */ + @Post("uploadProfileInsignia-Officer") + async UploadFileSQLInsignia(@Request() request: { user: Record }) { + console.log(">>>>>>>>>>>>>>>>>>>"); + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(Profile) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_INSIGNIARepo.find({ + where: { CIT: _item.citizenId }, + }); + + for (const item of existingProfile) { + let DECORATION_DATE = ""; + if (item.DECORATION_DATE) { + const [datePart] = item.DECORATION_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + DECORATION_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + let PERMISSION_DATE = ""; + if (item.PERMISSION_DATE) { + const [datePart] = item.PERMISSION_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + PERMISSION_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + let CREATE_DATE = ""; + let _year = null; + if (item.CREATE_DATE) { + const [datePart] = item.CREATE_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + CREATE_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + _year = year; + } + rowCount++; + const insignia = new ProfileInsignia(); + insignia.profileId = _item.id; + insignia.year = _year == null ? _null : Number(_year); + insignia.volume = item.BOOK; + insignia.section = item.PART; + insignia.page = item.PAGE; + insignia.receiveDate = PERMISSION_DATE == "" ? _null : new Date(PERMISSION_DATE); + insignia.dateAnnounce = DECORATION_DATE == "" ? _null : new Date(DECORATION_DATE); + insignia.issue = item.ISSUE; + const insigniaMeta = await this.insigniaRepo.findOne({ + where: { name: item.DECORATIONS_NAME }, + }); + if (insigniaMeta != null) { + insignia.insigniaId = insigniaMeta.id; + } + insignia.createdUserId = request.user.sub; + insignia.createdFullName = request.user.name; + insignia.lastUpdateUserId = request.user.sub; + insignia.lastUpdateFullName = request.user.name; + insignia.createdAt = new Date(); + insignia.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileInsigniaRepo.save(await insignia); + } + } + return new HttpSuccess(); + } + + /** + * @summary เครื่องราช ลูกจ้างประจำ + */ + @Post("uploadProfileInsignia-Employee") + async UploadFileSQLInsigniaEmp(@Request() request: { user: Record }) { + let rowCount = 0; + let _null: any = null; + + const [profiles, total] = await AppDataSource.getRepository(ProfileEmployee) + .createQueryBuilder("profile") + .select(["profile.citizenId", "profile.id"]) + .orderBy("profile.citizenId", "ASC") + .getManyAndCount(); + + for (const _item of profiles) { + const existingProfile = await this.HR_INSIGNIA_EMPRepo.find({ + where: { CIT: _item.citizenId }, + }); + + for (const item of existingProfile) { + let DECORATION_DATE = ""; + if (item.DECORATION_DATE) { + const [datePart] = item.DECORATION_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + DECORATION_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + } + let CREATE_DATE = ""; + let _year = null; + if (item.CREATE_DATE) { + const [datePart] = item.CREATE_DATE.split(" "); + const [day, month, year] = datePart.split("/"); + CREATE_DATE = `${year}-${month.padStart(2, "0")}-${day.padStart(2, "0")}`; + _year = year; + } + rowCount++; + const insignia = new ProfileInsignia(); + insignia.profileEmployeeId = _item.id; + insignia.year = _year == null ? _null : Number(_year); + insignia.volume = item.BOOK; + insignia.section = item.PART; + insignia.page = item.PAGE; + insignia.receiveDate = CREATE_DATE == "" ? _null : new Date(CREATE_DATE); + insignia.dateAnnounce = DECORATION_DATE == "" ? _null : new Date(DECORATION_DATE); + insignia.issue = item.ISSUE; + const insigniaMeta = await this.insigniaRepo.findOne({ + where: { name: item.DECORATIONS_NAME }, + }); + if (insigniaMeta != null) { + insignia.insigniaId = insigniaMeta.id; + } + insignia.createdUserId = request.user.sub; + insignia.createdFullName = request.user.name; + insignia.lastUpdateUserId = request.user.sub; + insignia.lastUpdateFullName = request.user.name; + insignia.createdAt = new Date(); + insignia.lastUpdatedAt = new Date(); + console.log(">>>>>>>>>>>>>>>>>>>" + rowCount); + await this.profileInsigniaRepo.save(await insignia); + } + } + return new HttpSuccess(); + } } diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index adabac98..4fc045c7 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -1694,11 +1694,11 @@ export class OrganizationDotnetController extends Controller { return new HttpSuccess(mapProfile); } /** - * 3. API Get Profile จาก keycloak id + * 3. API Get Profile จาก citizen Id * - * @summary 3. API Get Profile จาก keycloak id + * @summary 3. API Get Profile จาก citizen Id * - * @param {string} citizenId Id keycloak + * @param {string} citizenId citizen Id */ @Get("citizenId/{citizenId}") async GetProfileByCitizenIdAsync(@Path() citizenId: string) { diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 78fd3f8a..a92844db 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -1630,7 +1630,7 @@ export class ProfileEmployeeController extends Controller { firstName: _data.firstName, lastName: _data.lastName, citizenId: _data.citizenId, - posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posLevel: `${_data.posType.posTypeShortName?? ""} ${_data.posLevel.posLevelName ?? ""}`, posType: _data.posType == null ? null : _data.posType.posTypeName, posLevelId: _data.posLevel == null ? null : _data.posLevel.id, posTypeId: _data.posType == null ? null : _data.posType.id, @@ -1907,7 +1907,9 @@ export class ProfileEmployeeController extends Controller { : "1=1", ) .andWhere( - retireType != undefined && retireType != null ? `profileEmployee.leaveType = :retireType` : "1=1", + retireType != undefined && retireType != null + ? `profileEmployee.leaveType = :retireType` + : "1=1", { retireType: retireType }, ) .andWhere("profileEmployee.employeeClass LIKE :type", { @@ -2033,7 +2035,7 @@ export class ProfileEmployeeController extends Controller { positionId: _data.positionIdTemp, posmasterId: _data.posmasterIdTemp, position: _data.position, - posNo: + posNo: _data.profileSalary[0].posNoAbb && _data.profileSalary[0].posNo ? _data.profileSalary[0].posNoAbb + _data.profileSalary[0].posNo : _data.profileSalary[0].posNo || "", @@ -2443,11 +2445,19 @@ export class ProfileEmployeeController extends Controller { posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, posType: _data.posType == null ? null : _data.posType.posTypeName, posTypeShortName: _data.posType == null ? null : _data.posType.posTypeShortName, + + posLevelTemp: _data.posLevelNameTemp, + posTypeTemp: _data.posTypeNameTemp, + posTypeShortNameTemp: _data.posTypeShortNameTemp, + posLevelId: _data.posLevel == null ? null : _data.posLevel.id, posTypeId: _data.posType == null ? null : _data.posType.id, positionId: _data.positionIdTemp, posmasterId: _data.posmasterIdTemp, + position: _data.position, + positionTemp: _data.positionTemp, + posNo: _data.employeeClass == "TEMP" ? _data.posMasterNoTemp : shortName, employeeClass: _data.employeeClass == null ? null : _data.employeeClass, govAge: Extension.CalculateGovAge(_data.dateAppoint, 0, 0), @@ -2518,6 +2528,12 @@ export class ProfileEmployeeController extends Controller { (_child2 == null ? "" : _child2 + "\n") + (_child1 == null ? "" : _child1 + "\n") + (_root == null ? "" : _root), + orgTemp: + (_data.child4Temp == null ? "" : _data.child4Temp + "\n") + + (_data.child3Temp == null ? "" : _data.child3Temp + "\n") + + (_data.child2Temp == null ? "" : _data.child2Temp + "\n") + + (_data.child1Temp == null ? "" : _data.child1Temp + "\n") + + (_data.rootTemp == null ? "" : _data.rootTemp), }; }), ); @@ -2574,7 +2590,7 @@ export class ProfileEmployeeController extends Controller { } const [profiles, total] = await this.profileRepo .createQueryBuilder("profileEmployee") - .leftJoinAndSelect("profileEmployee.next_holders", "next_holders") + .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posType", "posType") .where( @@ -2590,12 +2606,29 @@ export class ProfileEmployeeController extends Controller { new Brackets((qb) => { qb.where( requestBody.keyword != null && requestBody.keyword != "" - ? `CONCAT(profileEmployee.prefix, profileEmployee.firstName," ",profileEmployee.lastName) LIKE :keyword` + ? "profileEmployee.prefix LIKE :keyword" : "1=1", { keyword: `%${requestBody.keyword}%`, }, - ).orWhere( + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.firstName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.lastName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( requestBody.keyword != null && requestBody.keyword != "" ? "profileEmployee.citizenId LIKE :keyword" : "1=1", @@ -2626,19 +2659,22 @@ export class ProfileEmployeeController extends Controller { qb.where("profileEmployee.id NOT IN (:...ids)", { ids: orgRevision.employeePosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId).length == 0 + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId).length == 0 ? ["zxc"] : orgRevision.employeePosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId), + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId), }); }), ) .andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "PERM" }) .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) + .orderBy("posType.posTypeRank", "ASC") + .addOrderBy("posLevel.posLevelRank", "ASC") .getManyAndCount(); + const data = profiles.map((_data) => ({ id: _data.id, prefix: _data.prefix, @@ -3670,10 +3706,18 @@ export class ProfileEmployeeController extends Controller { profileEmp.positionFieldTemp = body.positionField; profileEmp.posTypeIdTemp = String(body.posTypeId); profileEmp.posTypeNameTemp = body.posTypeName; + if (body.posTypeId != null) { + const posTypeTemp = await this.posTypeRepo.findOne({ + where: { id: body.posTypeId }, + }); + if (posTypeTemp != null) { + profileEmp.posTypeShortNameTemp = posTypeTemp.posTypeShortName; + } + } profileEmp.posLevelIdTemp = String(body.posLevelId); profileEmp.posLevelNameTemp = body.posLevelName; profileEmp.statusTemp = "PENDING"; - this.profileRepo.merge(profileEmp, body); + // this.profileRepo.merge(profileEmp, body); await this.profileRepo.save(profileEmp); return new HttpSuccess(); } diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index a3e7734b..78a7e665 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1704,7 +1704,7 @@ export class ProfileEmployeeTempController extends Controller { } const [profiles, total] = await this.profileRepo .createQueryBuilder("profileEmployee") - .leftJoinAndSelect("profileEmployee.next_holderTemps", "next_holderTemps") + .leftJoinAndSelect("profileEmployee.current_holderTemps", "current_holderTemps") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posType", "posType") .where( @@ -1720,12 +1720,29 @@ export class ProfileEmployeeTempController extends Controller { new Brackets((qb) => { qb.where( requestBody.keyword != null && requestBody.keyword != "" - ? `CONCAT(profileEmployee.prefix, profileEmployee.firstName," ",profileEmployee.lastName) LIKE :keyword` + ? "profileEmployee.prefix LIKE :keyword" : "1=1", { keyword: `%${requestBody.keyword}%`, }, - ).orWhere( + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.firstName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.lastName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( requestBody.keyword != null && requestBody.keyword != "" ? "profileEmployee.citizenId LIKE :keyword" : "1=1", @@ -1780,18 +1797,20 @@ export class ProfileEmployeeTempController extends Controller { qb.where("profileEmployee.id NOT IN (:...ids)", { ids: orgRevision.employeeTempPosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId).length == 0 + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId).length == 0 ? ["zxc"] : orgRevision.employeeTempPosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId), + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId), }); }), ) .andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "TEMP" }) .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) + .orderBy("posType.posTypeRank", "ASC") + .addOrderBy("posLevel.posLevelRank", "ASC") .getManyAndCount(); const data = profiles.map((_data) => ({ id: _data.id, diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index ab172166..9ad2b02c 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -24,7 +24,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { Profile } from "../entities/Profile"; -import { In, LessThan, MoreThan } from "typeorm"; +import { In, LessThan, IsNull, MoreThan } from "typeorm"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; import { Command } from "../entities/Command"; @@ -47,7 +47,7 @@ export class ProfileSalaryEmployeeController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profile.id }, + where: { profileEmployeeId: profile.id, commandCode: In(["5", "6", "7"]) }, order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -60,7 +60,28 @@ export class ProfileSalaryEmployeeController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profile.id }, + where: [ + { + profileEmployeeId: profile.id, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + }, + { profileEmployeeId: profile.id, commandCode: IsNull() }, + ], order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -87,7 +108,28 @@ export class ProfileSalaryEmployeeController extends Controller { if (_workflow == false) await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profileId }, + where: [ + { + profileEmployeeId: profileId, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + }, + { profileEmployeeId: profileId, commandCode: IsNull() }, + ], order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -131,7 +173,9 @@ export class ProfileSalaryEmployeeController extends Controller { [] as { name: string; days: number; year: number; month: number; day: number }[], ); - const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [profile.id]); + const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [ + profile.id, + ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel = _posLevel.length > 1 @@ -204,7 +248,9 @@ export class ProfileSalaryEmployeeController extends Controller { [] as { name: string; days: number; year: number; month: number; day: number }[], ); - const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [profileId]); + const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [ + profileId, + ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel = _posLevel.length > 1 @@ -248,7 +294,7 @@ export class ProfileSalaryEmployeeController extends Controller { let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE"); const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profileId }, + where: { profileEmployeeId: profileId, commandCode: In(["5", "6", "7"]) }, order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -318,9 +364,9 @@ export class ProfileSalaryEmployeeController extends Controller { lastUpdatedAt: new Date(), }; if (body.commandCode && !body.commandName) { - if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" - else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" - else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" + if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"; + else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"; } Object.assign(data, { ...body, ...meta }); const history = new ProfileSalaryHistory(); @@ -359,10 +405,10 @@ export class ProfileSalaryEmployeeController extends Controller { order: { order: "DESC" }, }); const before = null; - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.commandId ?? "" } + where: { id: body.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -371,35 +417,35 @@ export class ProfileSalaryEmployeeController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileGovementRepo.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } const data = new ProfileSalary(); @@ -451,9 +497,9 @@ export class ProfileSalaryEmployeeController extends Controller { const before = structuredClone(record); const history = new ProfileSalaryHistory(); if (body.commandCode && !body.commandName) { - if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" - else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" - else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" + if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"; + else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"; } Object.assign(record, body); Object.assign(history, { ...record, id: undefined }); diff --git a/src/entities/EMPLOYEE.ts b/src/entities/EMPLOYEE.ts new file mode 100644 index 00000000..a20b6f65 --- /dev/null +++ b/src/entities/EMPLOYEE.ts @@ -0,0 +1,189 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("EMPLOYEE") +export class EMPLOYEE { + @PrimaryGeneratedColumn() + id!: number; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // RET_YEAR: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ID: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // MP_CATEGORY: string; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // MP_LEVEL: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BORN: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + RANK_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LNAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BEGIN_ENTRY_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SEX: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + WORK_LINE_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SALARY: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CATEGORY_SAL_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SALARY_LEVEL_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + LEVEL_NAME: string; +} diff --git a/src/entities/HR_DISCIPLINE.ts b/src/entities/HR_DISCIPLINE.ts new file mode 100644 index 00000000..28f6f521 --- /dev/null +++ b/src/entities/HR_DISCIPLINE.ts @@ -0,0 +1,27 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_DISCIPLINE") +export class HR_DISCIPLINE { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + REASON_FLAW: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CREATE_DATE: string; +} diff --git a/src/entities/HR_DISCIPLINE_EMP.ts b/src/entities/HR_DISCIPLINE_EMP.ts new file mode 100644 index 00000000..f21ce754 --- /dev/null +++ b/src/entities/HR_DISCIPLINE_EMP.ts @@ -0,0 +1,27 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_DISCIPLINE_EMP") +export class HR_DISCIPLINE_EMP { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + REASON_FLAW: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CREATE_DATE: string; +} diff --git a/src/entities/HR_EDUCATION_EMP.ts b/src/entities/HR_EDUCATION_EMP.ts index bec7fed0..143189c7 100644 --- a/src/entities/HR_EDUCATION_EMP.ts +++ b/src/entities/HR_EDUCATION_EMP.ts @@ -52,4 +52,25 @@ export class HR_EDUCATION_EMP { default: null, }) EDUCATION_SEQ: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FUND_COURSE_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + MAJOR_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_EDUCATION: string; } diff --git a/src/entities/HR_INSIGNIA.ts b/src/entities/HR_INSIGNIA.ts new file mode 100644 index 00000000..11eeeb01 --- /dev/null +++ b/src/entities/HR_INSIGNIA.ts @@ -0,0 +1,69 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_INSIGNIA") +export class HR_INSIGNIA { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DECORATION_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CREATE_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + PERMISSION_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BOOK: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + PART: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + PAGE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ISSUE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DECORATIONS_NAME: string; +} diff --git a/src/entities/HR_INSIGNIA_EMP.ts b/src/entities/HR_INSIGNIA_EMP.ts new file mode 100644 index 00000000..37551cd9 --- /dev/null +++ b/src/entities/HR_INSIGNIA_EMP.ts @@ -0,0 +1,62 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_INSIGNIA_EMP") +export class HR_INSIGNIA_EMP { + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DECORATION_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CREATE_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + BOOK: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + PART: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + PAGE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ISSUE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DECORATIONS_NAME: string; +} diff --git a/src/entities/HR_POSITION_EMPLOYEE.ts b/src/entities/HR_POSITION_EMPLOYEE.ts new file mode 100644 index 00000000..08eeced0 --- /dev/null +++ b/src/entities/HR_POSITION_EMPLOYEE.ts @@ -0,0 +1,191 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity("HR_POSITION_EMPLOYEE") +export class HR_POSITION_EMPLOYEE { + @PrimaryGeneratedColumn() + id!: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_PERSON_TYPE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ORDER_MOVE_POSITION: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_CODE_SIT: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + 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: string; + + @Column({ + nullable: true, + default: null, + }) + MP_POS_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_TO_NAME_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_TO_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + WORK_LINE_NAME: string; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // MP_CEE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_NAME: string; + + // @Column({ + // nullable: true, + // type: "text", + // default: null, + // }) + // ADMIN_NAME: string; + + @Column({ + nullable: true, + default: null, + }) + SALARY: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + REMARK: 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, + }) + CATEGORY_SAL_CODE: string; +} diff --git a/src/entities/HR_POSITION_OFFICER.ts b/src/entities/HR_POSITION_OFFICER.ts index 0f57a9f8..58ba959f 100644 --- a/src/entities/HR_POSITION_OFFICER.ts +++ b/src/entities/HR_POSITION_OFFICER.ts @@ -5,6 +5,27 @@ export class HR_POSITION_OFFICER { @PrimaryGeneratedColumn() id!: number; + @Column({ + nullable: true, + type: "text", + default: null, + }) + CIT: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_PERSON_TYPE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ORDER_MOVE_POSITION: number; + @Column({ nullable: true, type: "text", @@ -18,4 +39,146 @@ export class HR_POSITION_OFFICER { default: null, }) 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: string; + + @Column({ + nullable: true, + default: null, + }) + MP_POS_DATE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_TO_NAME_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_TO_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + POS_NUM_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + WORK_LINE_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + MP_CEE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + JOB_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + SECTION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DIVISION_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_CODE: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + DEPARTMENT_NAME: string; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + ADMIN_NAME: string; + + @Column({ + nullable: true, + default: null, + }) + SALARY: number; + + @Column({ + nullable: true, + type: "text", + default: null, + }) + REMARK: 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; } diff --git a/src/entities/OFFICER.ts b/src/entities/OFFICER.ts index 87ce4739..36346b38 100644 --- a/src/entities/OFFICER.ts +++ b/src/entities/OFFICER.ts @@ -5,12 +5,12 @@ export class OFFICER { @PrimaryGeneratedColumn() id!: number; - // @Column({ - // nullable: true, - // type: "text", - // default: null, - // }) - // RET_YEAR: string; + @Column({ + nullable: true, + type: "text", + default: null, + }) + MP_CEE: string; @Column({ nullable: true, diff --git a/src/entities/ProfileEmployee.ts b/src/entities/ProfileEmployee.ts index 56a113dc..09b78efd 100644 --- a/src/entities/ProfileEmployee.ts +++ b/src/entities/ProfileEmployee.ts @@ -405,6 +405,14 @@ export class ProfileEmployee extends EntityBase { }) posTypeNameTemp: string; + @Column({ + nullable: true, + comment: "ประเภทชื่อย่อ", + length: 40, + default: null, + }) + posTypeShortNameTemp: string; + @Column({ nullable: true, comment: "id ระดับ", @@ -787,7 +795,7 @@ export class ProfileEmployee extends EntityBase { @OneToMany(() => StateOperatorUser, (v) => v.profile) stateOperatorUsers: StateOperatorUser[]; - + @OneToMany(() => PositionSalaryEditHistory, (v) => v.profileEmployee) positionSalaryEditHistory: PositionSalaryEditHistory[]; diff --git a/src/entities/ProfileInsignia.ts b/src/entities/ProfileInsignia.ts index 23b91bcb..b08c7e1d 100644 --- a/src/entities/ProfileInsignia.ts +++ b/src/entities/ProfileInsignia.ts @@ -24,7 +24,9 @@ export class ProfileInsignia extends EntityBase { profileEmployeeId: string; @Column({ + nullable: true, comment: "ปีที่ยื่นขอ", + default: null, }) year: number; diff --git a/src/entities/ProfileInsigniaHistory.ts b/src/entities/ProfileInsigniaHistory.ts index 954a3bca..cc4fa5d7 100644 --- a/src/entities/ProfileInsigniaHistory.ts +++ b/src/entities/ProfileInsigniaHistory.ts @@ -5,7 +5,11 @@ import { Insignia } from "./Insignia"; @Entity("profileInsigniaHistory") export class ProfileInsigniaHistory extends EntityBase { - @Column({ comment: "ปีที่ยื่นขอ" }) + @Column({ + nullable: true, + comment: "ปีที่ยื่นขอ", + default: null, + }) year: number; @Column({ nullable: true, length: 20, comment: "ลำดับที่", default: null }) diff --git a/src/migration/1745469749936-update24042025.ts b/src/migration/1745469749936-update24042025.ts deleted file mode 100644 index 82682d2b..00000000 --- a/src/migration/1745469749936-update24042025.ts +++ /dev/null @@ -1,1437 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class Update240420251745469749936 implements MigrationInterface { - name = 'Update240420251745469749936' - - public async up(queryRunner: QueryRunner): Promise { - // await queryRunner.query(`DROP INDEX \`FK_f1ded3e1f83ab2437f739a14f38\` ON \`profileSalaryHistory\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`amount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionSalaryAmount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`mouthSalaryAmount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`profileId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionExecutive\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionType\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionLevel\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`order\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`profileEmployeeId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`dateGovernment\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`isGovernment\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`amountSpecial\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgRoot\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild1\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild2\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild3\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild4\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandYear\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandDateSign\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandDateAffect\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandCode\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNoAbb\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionCee\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`remark\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandNo\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`IsActive\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryClass\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OcId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveSideId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLineId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionPathSideId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OrganizationShortNameId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeeGroupId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeeLevelId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeePositionId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeePositionSideId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoEmployee\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`RefCommandDate\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`RefCommandNo\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`CommandTypeName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryStatus\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`AgencyName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`CLevel\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OrgName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLineName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionPathSideName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionRef\``); - // 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 \`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 \`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 \`IMPORT_ORG\` DROP COLUMN \`ORDER\``); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`HRMS_DEP_CODE\``); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`HRMS_DIV_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_POS_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_NUM\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`WORK_LINE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIALIST_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ADMIN_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`REMARK\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ORDER_MOVE_POSITION\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`JOB_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SECTION_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DIVISION_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DEPARTMENT_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_CEE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_2\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIAL_AMT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`USER_CREATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`USER_UPDATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CUR_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FORCE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`JOB_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SECTION_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DIVISION_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DEPARTMENT_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`WORK_LINE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ADMIN_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_CODE_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIALIST_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FILL_APP_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_POS_STATUS\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`UP_C_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG_CURRENT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`AUDIT_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`AUDIT_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CREATE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`UPDATE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COURSE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COURSE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`PLACE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`PROVINCE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COUNTRY_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POSITION_CATG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`REC_STATUS\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MVMENT_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MVMENT_OF\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_ABB_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_NUM_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CUR_YEAR_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE_E\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_E\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_DATE_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_CEE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_LEVEL\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`GROUPWORK_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`GROUPWORK_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ACTIVE_STATUS\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MINOR_CODE\``); - await queryRunner.query(`ALTER TABLE \`profileTraining\` ADD \`developmentId\` varchar(40) NULL COMMENT 'ไอดีโครงการ/หลักสูตรการฝึกอบรม'`); - await queryRunner.query(`ALTER TABLE \`profileEmployee\` ADD \`statusEmail\` varchar(20) NULL COMMENT 'สถานะอีเมล'`); - await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` ADD \`statusEmail\` varchar(20) NULL COMMENT 'สถานะอีเมล'`); - await queryRunner.query(`ALTER TABLE \`profileAssistanceHistory\` ADD \`commandName\` varchar(255) NULL COMMENT 'ชื่อคำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`Order\` int NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`Amount\` double NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionSalaryAmount\` double NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionName\` varchar(255) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`ProfileId\` varchar(255) NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ID\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`isEntry\` \`isEntry\` tinyint NOT NULL COMMENT 'ข้อมูลจาก Entry'`); - // await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`mp_command_num\``); - // await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`mp_command_num\` int NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD PRIMARY KEY (\`id\`)`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNo\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNo\` varchar(255) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryRef\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryRef\` varchar(255) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoName\` varchar(255) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeName\` varchar(255) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelName\` varchar(255) NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FUND_COURSE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FUND_COURSE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MAJOR_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MAJOR_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FLAG_EDUCATION\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FLAG_EDUCATION\` text NULL`); - // 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, -// pn.positionArea, -// 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 -// pn.positionArea, -// 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 -// ), -// Educations AS ( -// SELECT -// eds.profileId, -// JSON_ARRAYAGG( -// JSON_OBJECT( -// 'degree', eds.degree, -// 'field', eds.field, -// 'educationLevel', eds.educationLevel, -// 'isEducation', eds.isEducation, -// 'isHigh', eds.isHigh -// ) -// ) AS Educations -// FROM ( -// SELECT DISTINCT -// eds.degree, -// eds.field, -// eds.educationLevel, -// eds.isEducation, -// eds.isHigh, -// eds.profileId, -// eds.level -// FROM profileEducation eds -// ) AS eds -// GROUP BY eds.profileId -// ORDER BY eds.level DESC -// ), -// EducationLevels AS ( -// SELECT -// edls.profileId, -// GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels -// FROM profileEducation edls -// WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != '' -// GROUP BY edls.profileId -// ORDER BY edls.level DESC -// ), -// Degrees AS ( -// SELECT -// degs.profileId, -// GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees -// FROM profileEducation degs -// WHERE degs.degree IS NOT NULL AND degs.degree != '' -// GROUP BY degs.profileId -// ORDER BY degs.level DESC -// ), -// Fields AS ( -// SELECT -// fies.profileId, -// GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields -// FROM profileEducation fies -// WHERE fies.field IS NOT NULL AND fies.field != '' -// GROUP BY fies.profileId -// ORDER BY fies.level DESC -// ), -// PositionDate AS ( -// SELECT -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vcto.profileId -// FROM tenurePositionOfficer vcto -// ), -// PositionLevelDate AS ( -// SELECT -// vctlo.Years, -// vctlo.Months, -// vctlo.Days, -// vctlo.profileId -// FROM tenureLevelOfficer vctlo -// ) -// 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, -// pm.positionArea, -// p.position, -// posType.posTypeName, -// posLevel.posLevelName, -// p.gender, -// p.relationship, -// p.dateAppoint, -// p.dateRetire, -// p.dateRetireLaw, -// p.birthdate, -// eds.Educations, -// edls.educationLevels, -// degs.degrees, -// fies.fields, -// TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age, -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vctlo.Years AS levelYears, -// vctlo.Months AS levelMonths, -// vctlo.Days AS levelDays -// 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 Educations eds ON p.id = eds.profileId -// LEFT JOIN EducationLevels edls ON p.id = edls.profileId -// LEFT JOIN Degrees degs ON p.id = degs.profileId -// LEFT JOIN Fields fies ON p.id = fies.profileId -// LEFT JOIN PositionDate vcto ON p.id = vcto.profileId -// LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n pn.positionArea,\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 pn.positionArea,\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 Educations AS (\n SELECT \n eds.profileId,\n JSON_ARRAYAGG(\n JSON_OBJECT(\n 'degree', eds.degree,\n 'field', eds.field,\n 'educationLevel', eds.educationLevel,\n 'isEducation', eds.isEducation,\n 'isHigh', eds.isHigh\n )\n ) AS Educations\n FROM (\n SELECT DISTINCT \n eds.degree, \n eds.field, \n eds.educationLevel, \n eds.isEducation, \n eds.isHigh, \n eds.profileId,\n\t\t\teds.level\n FROM profileEducation eds\n ) AS eds\n GROUP BY eds.profileId\n ORDER BY eds.level DESC\n ),\n EducationLevels AS (\n SELECT \n\t\t edls.profileId,\n GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels\n FROM profileEducation edls\n WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != ''\n GROUP BY edls.profileId\n ORDER BY edls.level DESC\n ),\n Degrees AS (\n SELECT \n\t\t degs.profileId,\n GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees\n FROM profileEducation degs\n WHERE degs.degree IS NOT NULL AND degs.degree != ''\n GROUP BY degs.profileId\n ORDER BY degs.level DESC\n ),\n Fields AS (\n SELECT \n\t\t fies.profileId,\n GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields\n FROM profileEducation fies\n WHERE fies.field IS NOT NULL AND fies.field != ''\n GROUP BY fies.profileId\n ORDER BY fies.level DESC\n ),\n PositionDate AS (\n SELECT \n vcto.Years,\n vcto.Months,\n vcto.Days,\n vcto.profileId\n FROM tenurePositionOfficer vcto\n ),\n PositionLevelDate AS (\n SELECT \n vctlo.Years,\n vctlo.Months,\n vctlo.Days,\n vctlo.profileId\n FROM tenureLevelOfficer vctlo\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 pm.positionArea,\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 eds.Educations,\n edls.educationLevels,\n degs.degrees,\n fies.fields,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,\n vcto.Years,\n vcto.Months,\n vcto.Days,\n vctlo.Years AS levelYears,\n vctlo.Months AS levelMonths,\n vctlo.Days AS levelDays\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 Educations eds ON p.id = eds.profileId\n LEFT JOIN EducationLevels edls ON p.id = edls.profileId\n LEFT JOIN Degrees degs ON p.id = degs.profileId\n LEFT JOIN Fields fies ON p.id = fies.profileId\n LEFT JOIN PositionDate vcto ON p.id = vcto.profileId\n LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId"]); -// 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 -// ), -// Educations AS ( -// SELECT -// eds.profileEmployeeId, -// JSON_ARRAYAGG( -// JSON_OBJECT( -// 'degree', eds.degree, -// 'field', eds.field, -// 'educationLevel', eds.educationLevel, -// 'isEducation', eds.isEducation, -// 'isHigh', eds.isHigh -// ) -// ) AS Educations -// FROM ( -// SELECT DISTINCT -// eds.degree, -// eds.field, -// eds.educationLevel, -// eds.isEducation, -// eds.isHigh, -// eds.profileEmployeeId, -// eds.level -// FROM profileEducation eds -// ) AS eds -// GROUP BY eds.profileEmployeeId -// ORDER BY eds.level DESC -// ), -// EducationLevels AS ( -// SELECT -// edls.profileEmployeeId, -// GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels -// FROM profileEducation edls -// WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != '' -// GROUP BY edls.profileEmployeeId -// ORDER BY edls.level DESC -// ), -// Degrees AS ( -// SELECT -// degs.profileEmployeeId, -// GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees -// FROM profileEducation degs -// WHERE degs.degree IS NOT NULL AND degs.degree != '' -// GROUP BY degs.profileEmployeeId -// ), -// Fields AS ( -// SELECT -// fies.profileEmployeeId, -// GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields -// FROM profileEducation fies -// WHERE fies.field IS NOT NULL AND fies.field != '' -// GROUP BY fies.profileEmployeeId -// ), -// PositionDate AS ( -// SELECT -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vcto.profileEmployeeId -// FROM tenurePositionEmployee vcto -// ), -// PositionLevelDate AS ( -// SELECT -// vctlo.Years, -// vctlo.Months, -// vctlo.Days, -// vctlo.profileEmployeeId -// FROM tenureLevelEmployee vctlo -// ) -// 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, -// eds.Educations, -// edls.educationLevels, -// degs.degrees, -// fies.fields, -// TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age, -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vctlo.Years AS levelYears, -// vctlo.Months AS levelMonths, -// vctlo.Days AS levelDays -// 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 Educations eds ON p.id = eds.profileEmployeeId -// LEFT JOIN EducationLevels edls ON p.id = edls.profileEmployeeId -// LEFT JOIN Degrees degs ON p.id = degs.profileEmployeeId -// LEFT JOIN Fields fies ON p.id = fies.profileEmployeeId -// LEFT JOIN PositionDate vcto ON p.id = vcto.profileEmployeeId -// LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileEmployeeId -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","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 Educations AS (\n SELECT \n eds.profileEmployeeId,\n JSON_ARRAYAGG(\n JSON_OBJECT(\n 'degree', eds.degree,\n 'field', eds.field,\n 'educationLevel', eds.educationLevel,\n 'isEducation', eds.isEducation,\n 'isHigh', eds.isHigh\n )\n ) AS Educations\n FROM (\n SELECT DISTINCT \n eds.degree, \n eds.field, \n eds.educationLevel, \n eds.isEducation, \n eds.isHigh, \n eds.profileEmployeeId,\n\t\t\teds.level\n FROM profileEducation eds\n ) AS eds\n GROUP BY eds.profileEmployeeId\n ORDER BY eds.level DESC\n ),\n EducationLevels AS (\n SELECT \n\t\t edls.profileEmployeeId,\n GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels\n FROM profileEducation edls\n WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != ''\n GROUP BY edls.profileEmployeeId\n ORDER BY edls.level DESC\n ),\n Degrees AS (\n SELECT \n\t\t degs.profileEmployeeId,\n GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees\n FROM profileEducation degs\n WHERE degs.degree IS NOT NULL AND degs.degree != ''\n GROUP BY degs.profileEmployeeId\n ),\n Fields AS (\n SELECT \n\t\t fies.profileEmployeeId,\n GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields\n FROM profileEducation fies\n WHERE fies.field IS NOT NULL AND fies.field != ''\n GROUP BY fies.profileEmployeeId\n ),\n PositionDate AS (\n SELECT \n vcto.Years,\n vcto.Months,\n vcto.Days,\n vcto.profileEmployeeId\n FROM tenurePositionEmployee vcto\n ),\n PositionLevelDate AS (\n SELECT \n vctlo.Years,\n vctlo.Months,\n vctlo.Days,\n vctlo.profileEmployeeId\n FROM tenureLevelEmployee vctlo\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 eds.Educations,\n edls.educationLevels,\n degs.degrees,\n fies.fields,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,\n vcto.Years,\n vcto.Months,\n vcto.Days,\n vctlo.Years AS levelYears,\n vctlo.Months AS levelMonths,\n vctlo.Days AS levelDays\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 Educations eds ON p.id = eds.profileEmployeeId\n LEFT JOIN EducationLevels edls ON p.id = edls.profileEmployeeId\n LEFT JOIN Degrees degs ON p.id = degs.profileEmployeeId\n LEFT JOIN Fields fies ON p.id = fies.profileEmployeeId\n LEFT JOIN PositionDate vcto ON p.id = vcto.profileEmployeeId\n LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileEmployeeId"]); -// await queryRunner.query(`CREATE VIEW \`view_employee_pos_master\` AS SELECT -// employeePosMaster.id, -// employeePosMaster.posMasterNoPrefix, -// employeePosMaster.posMasterNo, -// employeePosMaster.posMasterNoSuffix, -// employeePosMaster.orgRevisionId, -// employeePosMaster.orgRootId, -// employeePosMaster.orgChild1Id, -// employeePosMaster.orgChild2Id, -// employeePosMaster.orgChild3Id, -// employeePosMaster.orgChild4Id, -// employeePosMaster.current_holderId, -// profileEmployee.id as profileId, -// profileEmployee.prefix, -// profileEmployee.firstName, -// profileEmployee.lastName, -// profileEmployee.citizenId, -// profileEmployee.position, -// profileEmployee.amount, -// profileEmployee.dateRetire, -// profileEmployee.birthDate, -// profileEmployee.salaryLevel, -// profileEmployee.group, -// orgRoot.id as rootId, -// orgRoot.orgRootShortName, -// orgRoot.orgRootOrder, -// orgRoot.orgRootName, -// orgChild1.id as child1Id, -// orgChild1.orgChild1ShortName, -// orgChild1.orgChild1Order, -// orgChild1.orgChild1Name, -// orgChild2.id as child2Id, -// orgChild2.orgChild2ShortName, -// orgChild2.orgChild2Order, -// orgChild2.orgChild2Name, -// orgChild3.id as child3Id, -// orgChild3.orgChild3ShortName, -// orgChild3.orgChild3Order, -// orgChild3.orgChild3Name, -// orgChild4.id as child4Id, -// orgChild4.orgChild4ShortName, -// orgChild4.orgChild4Order, -// orgChild4.orgChild4Name, -// position.id as positionId, -// position.positionIsSelected, -// position.posExecutiveId as positionPosExecutiveId, -// position.isSpecial, -// posExecutive.id as posExecutiveId, -// posExecutive.posExecutiveName, -// profileDiscipline.id as profileDisciplineId, -// profileDiscipline.date as disCriplineDate, -// profileLeave.id as profileLeaveId, -// profileAssessment.id as profileAssessmentId, -// profileAssessment.pointSum, -// employeePosLevel.id as posLevelId, -// employeePosLevel.posLevelName, -// employeePosType.id as posTypeId, -// employeePosType.posTypeName, -// employeePosType.posTypeShortName -// FROM -// employeePosMaster -// LEFT JOIN -// profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id -// LEFT JOIN -// orgRoot ON employeePosMaster.orgRootId = orgRoot.id -// LEFT JOIN -// orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id -// LEFT JOIN -// orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id -// LEFT JOIN -// orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id -// LEFT JOIN -// orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id -// LEFT JOIN -// position ON employeePosMaster.id = position.posMasterId -// LEFT JOIN -// posExecutive ON position.posExecutiveId = posExecutive.id -// LEFT JOIN -// profileDiscipline ON profileDiscipline.profileId = profileEmployee.id -// LEFT JOIN -// profileLeave ON profileLeave.profileId = profileEmployee.id -// LEFT JOIN -// profileAssessment ON profileAssessment.profileId = profileEmployee.id -// LEFT JOIN -// employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id -// LEFT JOIN -// employeePosType ON profileEmployee.posTypeId = employeePosType.id -// WHERE -// employeePosMaster.current_holderId IS NOT NULL -// ORDER BY -// profileEmployee.citizenId ASC -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_employee_pos_master","SELECT \n employeePosMaster.id,\n employeePosMaster.posMasterNoPrefix,\n employeePosMaster.posMasterNo,\n employeePosMaster.posMasterNoSuffix,\n employeePosMaster.orgRevisionId,\n employeePosMaster.orgRootId,\n employeePosMaster.orgChild1Id,\n employeePosMaster.orgChild2Id,\n employeePosMaster.orgChild3Id,\n employeePosMaster.orgChild4Id,\n employeePosMaster.current_holderId,\n profileEmployee.id as profileId,\n profileEmployee.prefix,\n profileEmployee.firstName,\n profileEmployee.lastName,\n profileEmployee.citizenId,\n profileEmployee.position,\n profileEmployee.amount,\n profileEmployee.dateRetire,\n profileEmployee.birthDate,\n profileEmployee.salaryLevel,\n profileEmployee.group,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n employeePosLevel.id as posLevelId,\n employeePosLevel.posLevelName,\n\temployeePosType.id as posTypeId,\n employeePosType.posTypeName,\n employeePosType.posTypeShortName\n FROM \n employeePosMaster\n LEFT JOIN \n profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id \n LEFT JOIN \n orgRoot ON employeePosMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON employeePosMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN \n profileDiscipline ON profileDiscipline.profileId = profileEmployee.id \n LEFT JOIN \n profileLeave ON profileLeave.profileId = profileEmployee.id \n LEFT JOIN \n profileAssessment ON profileAssessment.profileId = profileEmployee.id \n LEFT JOIN \n employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id\n LEFT JOIN \n employeePosType ON profileEmployee.posTypeId = employeePosType.id\n WHERE \t\n employeePosMaster.current_holderId IS NOT NULL\n ORDER BY \n profileEmployee.citizenId ASC"]); -// await queryRunner.query(`CREATE VIEW \`view_current_tenure_officer\` AS -// WITH resultData AS ( -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber -// FROM ( -// SELECT -// commandDateAffect, -// commandDateSign, -// positionName, -// positionCee, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, -// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - -// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId -// FROM -// profileSalary -// WHERE -// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) -// ORDER BY -// commandDateAffect ASC, commandDateSign ASC -// ) AS groupedPosition -// WHERE -// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign -// GROUP BY -// profileId, groupedId, positionName -// ) -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// days_diff, -// Years, -// Months, -// Days, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// orderNumber -// FROM resultData - -// UNION ALL - -// SELECT -// CURDATE() AS commandDateAffect, -// NULL AS positionName, -// NULL AS positionCee, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', -// NULL AS posNo, -// NULL AS positionExecutive, -// NULL AS positionType, -// NULL AS positionLevel, -// NULL AS OrgRoot, -// NULL AS orgChild1, -// NULL AS orgChild2, -// NULL AS orgChild3, -// NULL AS orgChild4, -// NULL AS commandCode, -// NULL AS commandName, -// NULL AS commandNo, -// NULL AS commandYear, -// NULL AS remark, -// profileId, -// NULL AS orderNumber -// FROM resultData -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]); -// await queryRunner.query(`CREATE VIEW \`view_current_tenure_employee\` AS -// WITH resultData AS ( -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileEmployeeId, -// ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber -// FROM ( -// SELECT -// commandDateAffect, -// commandDateSign, -// positionName, -// positionCee, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileEmployeeId, -// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, -// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - -// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId -// FROM -// profileSalary -// WHERE -// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) -// ORDER BY -// commandDateAffect ASC, commandDateSign ASC -// ) AS groupedPosition -// WHERE -// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign -// GROUP BY -// profileEmployeeId, groupedId, positionName -// ) -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// days_diff, -// Years, -// Months, -// Days, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileEmployeeId, -// orderNumber -// FROM resultData - -// UNION ALL - -// SELECT -// CURDATE() AS commandDateAffect, -// NULL AS positionName, -// NULL AS positionCee, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', -// NULL AS posNo, -// NULL AS positionExecutive, -// NULL AS positionType, -// NULL AS positionLevel, -// NULL AS OrgRoot, -// NULL AS orgChild1, -// NULL AS orgChild2, -// NULL AS orgChild3, -// NULL AS orgChild4, -// NULL AS commandCode, -// NULL AS commandName, -// NULL AS commandNo, -// NULL AS commandYear, -// NULL AS remark, -// profileEmployeeId, -// NULL AS orderNumber -// FROM resultData -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_employee","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileEmployeeId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileEmployeeId,\n NULL AS orderNumber\n FROM resultData"]); -// await queryRunner.query(`CREATE VIEW \`view_pos_master\` AS SELECT -// posMaster.id, -// posMaster.posMasterNoPrefix, -// posMaster.posMasterNo, -// posMaster.posMasterNoSuffix, -// posMaster.orgRevisionId, -// posMaster.orgRootId, -// posMaster.orgChild1Id, -// posMaster.orgChild2Id, -// posMaster.orgChild3Id, -// posMaster.orgChild4Id, -// posMaster.current_holderId, -// profile.id as profileId, -// profile.prefix, -// profile.firstName, -// profile.lastName, -// profile.citizenId, -// profile.position, -// profile.amount, -// profile.dateRetire, -// profile.birthDate, -// orgRoot.id as rootId, -// orgRoot.orgRootShortName, -// orgRoot.orgRootOrder, -// orgRoot.orgRootName, -// orgChild1.id as child1Id, -// orgChild1.orgChild1ShortName, -// orgChild1.orgChild1Order, -// orgChild1.orgChild1Name, -// orgChild2.id as child2Id, -// orgChild2.orgChild2ShortName, -// orgChild2.orgChild2Order, -// orgChild2.orgChild2Name, -// orgChild3.id as child3Id, -// orgChild3.orgChild3ShortName, -// orgChild3.orgChild3Order, -// orgChild3.orgChild3Name, -// orgChild4.id as child4Id, -// orgChild4.orgChild4ShortName, -// orgChild4.orgChild4Order, -// orgChild4.orgChild4Name, -// position.id as positionId, -// position.positionIsSelected, -// position.posExecutiveId as positionPosExecutiveId, -// position.isSpecial, -// posExecutive.id as posExecutiveId, -// posExecutive.posExecutiveName, -// profileDiscipline.id as profileDisciplineId, -// profileDiscipline.date as disCriplineDate, -// profileLeave.id as profileLeaveId, -// profileAssessment.id as profileAssessmentId, -// profileAssessment.pointSum, -// posLevel.id as posLevelId, -// posLevel.posLevelName, -// posType.id as posTypeId, -// posType.posTypeName -// FROM -// posMaster -// LEFT JOIN -// profile ON posMaster.current_holderId = profile.id -// LEFT JOIN -// orgRoot ON posMaster.orgRootId = orgRoot.id -// LEFT JOIN -// orgChild1 ON posMaster.orgChild1Id = orgChild1.id -// LEFT JOIN -// orgChild2 ON posMaster.orgChild2Id = orgChild2.id -// LEFT JOIN -// orgChild3 ON posMaster.orgChild3Id = orgChild3.id -// LEFT JOIN -// orgChild4 ON posMaster.orgChild4Id = orgChild4.id -// LEFT JOIN -// position ON posMaster.id = position.posMasterId -// LEFT JOIN -// posExecutive ON position.posExecutiveId = posExecutive.id -// LEFT JOIN -// profileDiscipline ON profileDiscipline.profileId = profile.id -// LEFT JOIN -// profileLeave ON profileLeave.profileId = profile.id -// LEFT JOIN -// profileAssessment ON profileAssessment.profileId = profile.id -// LEFT JOIN -// posLevel ON profile.posLevelId = posLevel.id -// LEFT JOIN -// posType ON profile.posTypeId = posType.id -// WHERE -// posMaster.current_holderId IS NOT NULL -// ORDER BY -// profile.citizenId ASC -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_pos_master","SELECT \n posMaster.id,\n posMaster.posMasterNoPrefix,\n posMaster.posMasterNo,\n posMaster.posMasterNoSuffix,\n posMaster.orgRevisionId,\n posMaster.orgRootId,\n posMaster.orgChild1Id,\n posMaster.orgChild2Id,\n posMaster.orgChild3Id,\n posMaster.orgChild4Id,\n posMaster.current_holderId,\n profile.id as profileId,\n profile.prefix,\n profile.firstName,\n profile.lastName,\n profile.citizenId,\n profile.position,\n profile.amount,\n profile.dateRetire,\n profile.birthDate,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n posLevel.id as posLevelId,\n posLevel.posLevelName,\n\t posType.id as posTypeId,\n posType.posTypeName\n FROM \n posMaster\n LEFT JOIN \n profile ON posMaster.current_holderId = profile.id\n LEFT JOIN \n orgRoot ON posMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON posMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON posMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON posMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON posMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON posMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN \n profileDiscipline ON profileDiscipline.profileId = profile.id\n LEFT JOIN \n profileLeave ON profileLeave.profileId = profile.id\n LEFT JOIN \n profileAssessment ON profileAssessment.profileId = profile.id\n LEFT JOIN \n posLevel ON profile.posLevelId = posLevel.id\n LEFT JOIN \n posType ON profile.posTypeId = posType.id\n WHERE \t\n posMaster.current_holderId IS NOT NULL\n ORDER BY \n profile.citizenId ASC"]); -// await queryRunner.query(`CREATE VIEW \`view_current_tenure_exc_officer\` AS -// WITH resultData AS ( -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// orgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber -// FROM ( -// SELECT -// commandDateAffect, -// commandDateSign, -// positionName, -// positionCee, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// orgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - -// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId -// FROM -// profileSalary -// WHERE -// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND -// positionExecutive <> '' -// ORDER BY -// commandDateAffect ASC, commandDateSign ASC -// ) AS groupedPositionExe -// GROUP BY -// groupedId, positionExecutive -// ) -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// days_diff, -// Years, -// Months, -// Days, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// orgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// orderNumber -// FROM resultData - -// UNION ALL - -// SELECT -// CURDATE() AS commandDateAffect, -// NULL AS positionName, -// NULL AS positionCee, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', -// NULL AS posNo, -// NULL AS positionExecutive, -// NULL AS positionType, -// NULL AS positionLevel, -// NULL AS orgRoot, -// NULL AS orgChild1, -// NULL AS orgChild2, -// NULL AS orgChild3, -// NULL AS orgChild4, -// NULL AS commandCode, -// NULL AS commandName, -// NULL AS commandNo, -// NULL AS commandYear, -// NULL AS remark, -// profileId, -// NULL AS orderNumber -// FROM resultData -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_exc_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND\n positionExecutive <> ''\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPositionExe\n GROUP BY\n groupedId, positionExecutive\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff, \n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS orgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]); - } - - public async down(queryRunner: QueryRunner): Promise { - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_exc_officer","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_current_tenure_exc_officer\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_pos_master","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_pos_master\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_employee","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_current_tenure_employee\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_officer","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_current_tenure_officer\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_employee_pos_master","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_employee_pos_master\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_employee","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_registry_employee\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_registry_officer\``); - // await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP FOREIGN KEY \`FK_f1ded3e1f83ab2437f739a14f38\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FLAG_EDUCATION\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FLAG_EDUCATION\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MAJOR_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MAJOR_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FUND_COURSE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FUND_COURSE_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryRef\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryRef\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNo\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNo\` varchar(40) NULL COMMENT 'เลขที่ตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP PRIMARY KEY`); - // await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`mp_command_num\``); - // await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`mp_command_num\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`isEntry\` \`isEntry\` tinyint NULL COMMENT 'ข้อมูลจาก Entry'`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ID\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`ProfileId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionSalaryAmount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`Amount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`Order\``); - await queryRunner.query(`ALTER TABLE \`profileAssistanceHistory\` DROP COLUMN \`commandName\``); - await queryRunner.query(`ALTER TABLE \`profileEmployeeHistory\` DROP COLUMN \`statusEmail\``); - await queryRunner.query(`ALTER TABLE \`profileEmployee\` DROP COLUMN \`statusEmail\``); - await queryRunner.query(`ALTER TABLE \`profileTraining\` DROP COLUMN \`developmentId\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MINOR_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ACTIVE_STATUS\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`GROUPWORK_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`GROUPWORK_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_LEVEL\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_CEE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_DATE_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_E\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_CODE_E\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CUR_YEAR_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_NUM_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_ABB_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MVMENT_OF\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MVMENT_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`REC_STATUS\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POSITION_CATG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COUNTRY_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`PROVINCE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`PLACE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COURSE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COURSE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`UPDATE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CREATE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`AUDIT_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`AUDIT_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG_CURRENT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`UP_C_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_POS_STATUS\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FILL_APP_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIALIST_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_ABB_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_ABB_NAME_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_CODE_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ADMIN_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_LEVEL_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`WORK_LINE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DEPARTMENT_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DIVISION_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SECTION_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`JOB_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FORCE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CUR_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`USER_UPDATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`USER_CREATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIAL_AMT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SAL_POS_AMOUNT_2\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SAL_POS_AMOUNT_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_CEE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DEPARTMENT_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DIVISION_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SECTION_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`JOB_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ORDER_MOVE_POSITION\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`REMARK\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ADMIN_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIALIST_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`WORK_LINE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_NUM\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_POS_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`HRMS_DIV_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`HRMS_DEP_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`ORDER\` 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 \`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_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 \`ProfileSalaries\` ADD \`PositionRef\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionPathSideName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLineName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OrgName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`CLevel\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`AgencyName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryStatus\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`CommandTypeName\` longtext NOT NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`RefCommandNo\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`RefCommandDate\` datetime(6) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoEmployee\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeePositionSideId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeePositionId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeeLevelId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeeGroupId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OrganizationShortNameId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionPathSideId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLineId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveSideId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OcId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryClass\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`IsActive\` tinyint(1) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandNo\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`remark\` varchar(255) NULL COMMENT 'หมายเหตุ'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionCee\` varchar(255) NULL COMMENT 'ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionName\` text NULL COMMENT 'ตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNoAbb\` varchar(40) NULL COMMENT 'ตัวย่อเลขที่ตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandName\` varchar(255) NULL COMMENT 'ชื่อประเภทคำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandDateAffect\` datetime NULL COMMENT 'คำสั่งมีผลวันที่'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandDateSign\` datetime NULL COMMENT 'คำสั่งวันที่'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandYear\` int NULL COMMENT 'ปีที่ออกคำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild4\` varchar(255) NULL COMMENT 'child4 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild3\` varchar(255) NULL COMMENT 'child3 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild2\` varchar(255) NULL COMMENT 'child2 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild1\` varchar(255) NULL COMMENT 'child1 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgRoot\` varchar(255) NULL COMMENT 'root name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง command'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`isGovernment\` tinyint NULL COMMENT 'เข้ารับราชการ'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`dateGovernment\` datetime NULL COMMENT 'วันที่'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`order\` int NULL COMMENT 'เรียงลำดับใหมาตามการนำเข้า'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionLevel\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionType\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionExecutive\` varchar(255) NULL COMMENT 'ตำแหน่งทางการบริหาร'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`mouthSalaryAmount\` double NULL COMMENT 'เงินค่าตอบแทนรายเดือน' DEFAULT '0'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionSalaryAmount\` double NULL COMMENT 'เงินประจำตำแหน่ง' DEFAULT '0'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`amount\` double NULL COMMENT 'เงินเดือนฐาน' DEFAULT '0'`); - // await queryRunner.query(`CREATE INDEX \`FK_f1ded3e1f83ab2437f739a14f38\` ON \`profileSalaryHistory\` (\`profileSalaryId\`)`); - } - -} diff --git a/src/migration/1745565425339-update240420251431.ts b/src/migration/1745565425339-update240420251431.ts deleted file mode 100644 index 62c135c1..00000000 --- a/src/migration/1745565425339-update240420251431.ts +++ /dev/null @@ -1,1433 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class Update2404202514311745565425339 implements MigrationInterface { - name = 'Update2404202514311745565425339' - - public async up(queryRunner: QueryRunner): Promise { - // await queryRunner.query(`DROP INDEX \`FK_f1ded3e1f83ab2437f739a14f38\` ON \`profileSalaryHistory\``); - // await queryRunner.query(`CREATE TABLE \`EMPLOYEE\` (\`id\` int NOT NULL AUTO_INCREMENT, \`ID\` text NULL, \`CIT\` text NULL, \`BORN\` text NULL, \`RANK_NAME\` text NULL, \`FNAME\` text NULL, \`LNAME\` text NULL, \`BEGIN_ENTRY_DATE\` text NULL, \`SEX\` text NULL, \`WORK_LINE_NAME\` text NULL, \`SALARY\` text NULL, \`DEPARTMENT_NAME\` text NULL, \`DEPARTMENT_CODE\` text NULL, \`DIVISION_NAME\` text NULL, \`DIVISION_CODE\` text NULL, \`SECTION_NAME\` text NULL, \`SECTION_CODE\` text NULL, \`JOB_NAME\` text NULL, \`JOB_CODE\` text NULL, \`POS_NUM_CODE\` text NULL, \`POS_NUM_NAME\` text NULL, \`CATEGORY_SAL_CODE\` text NULL, \`SALARY_LEVEL_CODE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`AgencyName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`amount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`amountSpecial\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`CLevel\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandCode\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandDateAffect\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandDateSign\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandNo\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`CommandTypeName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`commandYear\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`dateGovernment\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`IsActive\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`isGovernment\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`mouthSalaryAmount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OcId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`order\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OrganizationShortNameId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild1\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild2\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild3\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgChild4\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`OrgName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`orgRoot\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionCee\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeeGroupId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeeLevelId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeePositionId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionEmployeePositionSideId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionExecutive\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionExecutiveSideId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionLevel\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLineId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLineName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionPathSideId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionPathSideName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionRef\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionSalaryAmount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`positionType\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNoAbb\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoEmployee\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`profileEmployeeId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`profileId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`RefCommandDate\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`RefCommandNo\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`remark\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryClass\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryStatus\``); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`HRMS_DEP_CODE\``); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`HRMS_DIV_CODE\``); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` DROP COLUMN \`ORDER\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ACTIVE_STATUS\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ADMIN_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ADMIN_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`AUDIT_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`AUDIT_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COUNTRY_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COURSE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`COURSE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CREATE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CUR_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`CUR_YEAR_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DEPARTMENT_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DEPARTMENT_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DIVISION_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`DIVISION_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FILL_APP_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_POS_STATUS\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE_E\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_TO_NAME_E\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`GROUPWORK_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`GROUPWORK_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`JOB_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`JOB_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_CEE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_CEE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_DATE_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_NUM\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_COMMAND_NUM_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FLAG_CURRENT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_FORCE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_POS_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MP_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MVMENT_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`MVMENT_OF\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`ORDER_MOVE_POSITION\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`PLACE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_ABB_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_EDIT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POS_NUM_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`POSITION_CATG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`PROVINCE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`REC_STATUS\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`REMARK\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_2\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_LEVEL\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SALARY_POS_CODE_1\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SECTION_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SECTION_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIAL_AMT\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIALIST_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`SPECIALIST_NAME\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`UP_C_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`UPDATE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`USER_CREATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`USER_UPDATE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`WORK_LINE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`WORK_LINE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ADMIN_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ADMIN_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CONTENT_NO\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`COST_LIVING_AMOUNT\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CREATE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CUR_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`CUR_YEAR_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`DEXPIRE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`EDUCATION_NAME\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_CUR_ST\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_RETIRE_STATUS\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FLAG_TO_NAME_CODE\``); - // 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 \`FLAG_TYPE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`FUND_COURSE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`GROUPWORK_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`HELP_LIVING_AMOUNT\``); - // 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 \`MARRIAGE_STATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_CODE_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_NAME\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_CEE_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_DATE_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_NUM\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_COMMAND_NUM_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_1\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_1_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FLAG_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_FORCE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_POS_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_POS_DATE_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`MP_YEAR_O\``); - // 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_JOB_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`OLD_RETIRE_SECTION_CODE\``); - // 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 \`POS_NUM_CODE_SIT\``); - // 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_ABB_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_CODE_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POS_NUM_CODE_SIT_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`POSITION_CATG\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RANK_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_MP_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RET_BORN_YEAR\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETIRE_POS_NO\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETIRE_TYPE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`RETURN_OCCUPY_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_1\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SAL_POS_AMOUNT_2\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_ADD\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_ADD_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_CODE_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_LEVEL_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SALARY_POS_ABB_NAME_1\``); - // 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 \`SPECIAL_AMT\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_AMT_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`SPECIAL_PERCENT\``); - // 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 \`SUN_NO\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UNIVER_NAME\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UPCLASS_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`UPDATE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_CODE_O\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_DATE\``); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`WORK_LINE_NAME_O\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MINOR_CODE\``); - await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`posNumCodeSit\` varchar(255) NULL COMMENT 'หน่วยงานที่ออกคำสั่ง'`); - await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`posNumCodeSitAbb\` varchar(255) NULL COMMENT 'หน่วยงานที่ออกคำสั่ง(ตัวย่อ)'`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`Order\` int NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`Amount\` double NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionSalaryAmount\` double NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionName\` varchar(255) NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`ProfileId\` varchar(255) NULL`); -// await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ID\` text NULL`); -// await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`isEntry\` \`isEntry\` tinyint NOT NULL COMMENT 'ข้อมูลจาก Entry'`); -// await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`mp_command_num\``); -// await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`mp_command_num\` int NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD PRIMARY KEY (\`id\`)`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNo\``); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNo\` varchar(255) NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryRef\``); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryRef\` varchar(255) NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoName\``); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoName\` varchar(255) NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeName\``); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeName\` varchar(255) NULL`); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelName\``); -// await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelName\` varchar(255) NULL`); -// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FUND_COURSE_CODE\``); -// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FUND_COURSE_CODE\` text NULL`); -// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MAJOR_CODE\``); -// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MAJOR_CODE\` text NULL`); -// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FLAG_EDUCATION\``); -// await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FLAG_EDUCATION\` text NULL`); -// 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, -// pn.positionArea, -// 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 -// pn.positionArea, -// 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 -// ), -// Educations AS ( -// SELECT -// eds.profileId, -// JSON_ARRAYAGG( -// JSON_OBJECT( -// 'degree', eds.degree, -// 'field', eds.field, -// 'educationLevel', eds.educationLevel, -// 'isEducation', eds.isEducation, -// 'isHigh', eds.isHigh -// ) -// ) AS Educations -// FROM ( -// SELECT DISTINCT -// eds.degree, -// eds.field, -// eds.educationLevel, -// eds.isEducation, -// eds.isHigh, -// eds.profileId, -// eds.level -// FROM profileEducation eds -// ) AS eds -// GROUP BY eds.profileId -// ORDER BY eds.level DESC -// ), -// EducationLevels AS ( -// SELECT -// edls.profileId, -// GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels -// FROM profileEducation edls -// WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != '' -// GROUP BY edls.profileId -// ORDER BY edls.level DESC -// ), -// Degrees AS ( -// SELECT -// degs.profileId, -// GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees -// FROM profileEducation degs -// WHERE degs.degree IS NOT NULL AND degs.degree != '' -// GROUP BY degs.profileId -// ORDER BY degs.level DESC -// ), -// Fields AS ( -// SELECT -// fies.profileId, -// GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields -// FROM profileEducation fies -// WHERE fies.field IS NOT NULL AND fies.field != '' -// GROUP BY fies.profileId -// ORDER BY fies.level DESC -// ), -// PositionDate AS ( -// SELECT -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vcto.profileId -// FROM tenurePositionOfficer vcto -// ), -// PositionLevelDate AS ( -// SELECT -// vctlo.Years, -// vctlo.Months, -// vctlo.Days, -// vctlo.profileId -// FROM tenureLevelOfficer vctlo -// ) -// 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, -// pm.positionArea, -// p.position, -// posType.posTypeName, -// posLevel.posLevelName, -// p.gender, -// p.relationship, -// p.dateAppoint, -// p.dateRetire, -// p.dateRetireLaw, -// p.birthdate, -// eds.Educations, -// edls.educationLevels, -// degs.degrees, -// fies.fields, -// TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age, -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vctlo.Years AS levelYears, -// vctlo.Months AS levelMonths, -// vctlo.Days AS levelDays -// 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 Educations eds ON p.id = eds.profileId -// LEFT JOIN EducationLevels edls ON p.id = edls.profileId -// LEFT JOIN Degrees degs ON p.id = degs.profileId -// LEFT JOIN Fields fies ON p.id = fies.profileId -// LEFT JOIN PositionDate vcto ON p.id = vcto.profileId -// LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n pn.positionArea,\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 pn.positionArea,\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 Educations AS (\n SELECT \n eds.profileId,\n JSON_ARRAYAGG(\n JSON_OBJECT(\n 'degree', eds.degree,\n 'field', eds.field,\n 'educationLevel', eds.educationLevel,\n 'isEducation', eds.isEducation,\n 'isHigh', eds.isHigh\n )\n ) AS Educations\n FROM (\n SELECT DISTINCT \n eds.degree, \n eds.field, \n eds.educationLevel, \n eds.isEducation, \n eds.isHigh, \n eds.profileId,\n\t\t\teds.level\n FROM profileEducation eds\n ) AS eds\n GROUP BY eds.profileId\n ORDER BY eds.level DESC\n ),\n EducationLevels AS (\n SELECT \n\t\t edls.profileId,\n GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels\n FROM profileEducation edls\n WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != ''\n GROUP BY edls.profileId\n ORDER BY edls.level DESC\n ),\n Degrees AS (\n SELECT \n\t\t degs.profileId,\n GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees\n FROM profileEducation degs\n WHERE degs.degree IS NOT NULL AND degs.degree != ''\n GROUP BY degs.profileId\n ORDER BY degs.level DESC\n ),\n Fields AS (\n SELECT \n\t\t fies.profileId,\n GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields\n FROM profileEducation fies\n WHERE fies.field IS NOT NULL AND fies.field != ''\n GROUP BY fies.profileId\n ORDER BY fies.level DESC\n ),\n PositionDate AS (\n SELECT \n vcto.Years,\n vcto.Months,\n vcto.Days,\n vcto.profileId\n FROM tenurePositionOfficer vcto\n ),\n PositionLevelDate AS (\n SELECT \n vctlo.Years,\n vctlo.Months,\n vctlo.Days,\n vctlo.profileId\n FROM tenureLevelOfficer vctlo\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 pm.positionArea,\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 eds.Educations,\n edls.educationLevels,\n degs.degrees,\n fies.fields,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,\n vcto.Years,\n vcto.Months,\n vcto.Days,\n vctlo.Years AS levelYears,\n vctlo.Months AS levelMonths,\n vctlo.Days AS levelDays\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 Educations eds ON p.id = eds.profileId\n LEFT JOIN EducationLevels edls ON p.id = edls.profileId\n LEFT JOIN Degrees degs ON p.id = degs.profileId\n LEFT JOIN Fields fies ON p.id = fies.profileId\n LEFT JOIN PositionDate vcto ON p.id = vcto.profileId\n LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileId"]); -// await queryRunner.query(`CREATE VIEW \`view_employee_pos_master\` AS SELECT -// employeePosMaster.id, -// employeePosMaster.posMasterNoPrefix, -// employeePosMaster.posMasterNo, -// employeePosMaster.posMasterNoSuffix, -// employeePosMaster.orgRevisionId, -// employeePosMaster.orgRootId, -// employeePosMaster.orgChild1Id, -// employeePosMaster.orgChild2Id, -// employeePosMaster.orgChild3Id, -// employeePosMaster.orgChild4Id, -// employeePosMaster.current_holderId, -// profileEmployee.id as profileId, -// profileEmployee.prefix, -// profileEmployee.firstName, -// profileEmployee.lastName, -// profileEmployee.citizenId, -// profileEmployee.position, -// profileEmployee.amount, -// profileEmployee.dateRetire, -// profileEmployee.birthDate, -// profileEmployee.salaryLevel, -// profileEmployee.group, -// orgRoot.id as rootId, -// orgRoot.orgRootShortName, -// orgRoot.orgRootOrder, -// orgRoot.orgRootName, -// orgChild1.id as child1Id, -// orgChild1.orgChild1ShortName, -// orgChild1.orgChild1Order, -// orgChild1.orgChild1Name, -// orgChild2.id as child2Id, -// orgChild2.orgChild2ShortName, -// orgChild2.orgChild2Order, -// orgChild2.orgChild2Name, -// orgChild3.id as child3Id, -// orgChild3.orgChild3ShortName, -// orgChild3.orgChild3Order, -// orgChild3.orgChild3Name, -// orgChild4.id as child4Id, -// orgChild4.orgChild4ShortName, -// orgChild4.orgChild4Order, -// orgChild4.orgChild4Name, -// position.id as positionId, -// position.positionIsSelected, -// position.posExecutiveId as positionPosExecutiveId, -// position.isSpecial, -// posExecutive.id as posExecutiveId, -// posExecutive.posExecutiveName, -// profileDiscipline.id as profileDisciplineId, -// profileDiscipline.date as disCriplineDate, -// profileLeave.id as profileLeaveId, -// profileAssessment.id as profileAssessmentId, -// profileAssessment.pointSum, -// employeePosLevel.id as posLevelId, -// employeePosLevel.posLevelName, -// employeePosType.id as posTypeId, -// employeePosType.posTypeName, -// employeePosType.posTypeShortName -// FROM -// employeePosMaster -// LEFT JOIN -// profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id -// LEFT JOIN -// orgRoot ON employeePosMaster.orgRootId = orgRoot.id -// LEFT JOIN -// orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id -// LEFT JOIN -// orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id -// LEFT JOIN -// orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id -// LEFT JOIN -// orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id -// LEFT JOIN -// position ON employeePosMaster.id = position.posMasterId -// LEFT JOIN -// posExecutive ON position.posExecutiveId = posExecutive.id -// LEFT JOIN -// profileDiscipline ON profileDiscipline.profileId = profileEmployee.id -// LEFT JOIN -// profileLeave ON profileLeave.profileId = profileEmployee.id -// LEFT JOIN -// profileAssessment ON profileAssessment.profileId = profileEmployee.id -// LEFT JOIN -// employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id -// LEFT JOIN -// employeePosType ON profileEmployee.posTypeId = employeePosType.id -// WHERE -// employeePosMaster.current_holderId IS NOT NULL -// ORDER BY -// profileEmployee.citizenId ASC -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_employee_pos_master","SELECT \n employeePosMaster.id,\n employeePosMaster.posMasterNoPrefix,\n employeePosMaster.posMasterNo,\n employeePosMaster.posMasterNoSuffix,\n employeePosMaster.orgRevisionId,\n employeePosMaster.orgRootId,\n employeePosMaster.orgChild1Id,\n employeePosMaster.orgChild2Id,\n employeePosMaster.orgChild3Id,\n employeePosMaster.orgChild4Id,\n employeePosMaster.current_holderId,\n profileEmployee.id as profileId,\n profileEmployee.prefix,\n profileEmployee.firstName,\n profileEmployee.lastName,\n profileEmployee.citizenId,\n profileEmployee.position,\n profileEmployee.amount,\n profileEmployee.dateRetire,\n profileEmployee.birthDate,\n profileEmployee.salaryLevel,\n profileEmployee.group,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n employeePosLevel.id as posLevelId,\n employeePosLevel.posLevelName,\n\temployeePosType.id as posTypeId,\n employeePosType.posTypeName,\n employeePosType.posTypeShortName\n FROM \n employeePosMaster\n LEFT JOIN \n profileEmployee ON employeePosMaster.current_holderId = profileEmployee.id \n LEFT JOIN \n orgRoot ON employeePosMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON employeePosMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON employeePosMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON employeePosMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON employeePosMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON employeePosMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN \n profileDiscipline ON profileDiscipline.profileId = profileEmployee.id \n LEFT JOIN \n profileLeave ON profileLeave.profileId = profileEmployee.id \n LEFT JOIN \n profileAssessment ON profileAssessment.profileId = profileEmployee.id \n LEFT JOIN \n employeePosLevel ON profileEmployee.posLevelId = employeePosLevel.id\n LEFT JOIN \n employeePosType ON profileEmployee.posTypeId = employeePosType.id\n WHERE \t\n employeePosMaster.current_holderId IS NOT NULL\n ORDER BY \n profileEmployee.citizenId ASC"]); -// 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 -// ), -// Educations AS ( -// SELECT -// eds.profileEmployeeId, -// JSON_ARRAYAGG( -// JSON_OBJECT( -// 'degree', eds.degree, -// 'field', eds.field, -// 'educationLevel', eds.educationLevel, -// 'isEducation', eds.isEducation, -// 'isHigh', eds.isHigh -// ) -// ) AS Educations -// FROM ( -// SELECT DISTINCT -// eds.degree, -// eds.field, -// eds.educationLevel, -// eds.isEducation, -// eds.isHigh, -// eds.profileEmployeeId, -// eds.level -// FROM profileEducation eds -// ) AS eds -// GROUP BY eds.profileEmployeeId -// ORDER BY eds.level DESC -// ), -// EducationLevels AS ( -// SELECT -// edls.profileEmployeeId, -// GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels -// FROM profileEducation edls -// WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != '' -// GROUP BY edls.profileEmployeeId -// ORDER BY edls.level DESC -// ), -// Degrees AS ( -// SELECT -// degs.profileEmployeeId, -// GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees -// FROM profileEducation degs -// WHERE degs.degree IS NOT NULL AND degs.degree != '' -// GROUP BY degs.profileEmployeeId -// ), -// Fields AS ( -// SELECT -// fies.profileEmployeeId, -// GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields -// FROM profileEducation fies -// WHERE fies.field IS NOT NULL AND fies.field != '' -// GROUP BY fies.profileEmployeeId -// ), -// PositionDate AS ( -// SELECT -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vcto.profileEmployeeId -// FROM tenurePositionEmployee vcto -// ), -// PositionLevelDate AS ( -// SELECT -// vctlo.Years, -// vctlo.Months, -// vctlo.Days, -// vctlo.profileEmployeeId -// FROM tenureLevelEmployee vctlo -// ) -// 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, -// eds.Educations, -// edls.educationLevels, -// degs.degrees, -// fies.fields, -// TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age, -// vcto.Years, -// vcto.Months, -// vcto.Days, -// vctlo.Years AS levelYears, -// vctlo.Months AS levelMonths, -// vctlo.Days AS levelDays -// 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 Educations eds ON p.id = eds.profileEmployeeId -// LEFT JOIN EducationLevels edls ON p.id = edls.profileEmployeeId -// LEFT JOIN Degrees degs ON p.id = degs.profileEmployeeId -// LEFT JOIN Fields fies ON p.id = fies.profileEmployeeId -// LEFT JOIN PositionDate vcto ON p.id = vcto.profileEmployeeId -// LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileEmployeeId -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","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 Educations AS (\n SELECT \n eds.profileEmployeeId,\n JSON_ARRAYAGG(\n JSON_OBJECT(\n 'degree', eds.degree,\n 'field', eds.field,\n 'educationLevel', eds.educationLevel,\n 'isEducation', eds.isEducation,\n 'isHigh', eds.isHigh\n )\n ) AS Educations\n FROM (\n SELECT DISTINCT \n eds.degree, \n eds.field, \n eds.educationLevel, \n eds.isEducation, \n eds.isHigh, \n eds.profileEmployeeId,\n\t\t\teds.level\n FROM profileEducation eds\n ) AS eds\n GROUP BY eds.profileEmployeeId\n ORDER BY eds.level DESC\n ),\n EducationLevels AS (\n SELECT \n\t\t edls.profileEmployeeId,\n GROUP_CONCAT(DISTINCT edls.educationLevel ORDER BY edls.educationLevel SEPARATOR ', ') AS educationLevels\n FROM profileEducation edls\n WHERE edls.educationLevel IS NOT NULL AND edls.educationLevel != ''\n GROUP BY edls.profileEmployeeId\n ORDER BY edls.level DESC\n ),\n Degrees AS (\n SELECT \n\t\t degs.profileEmployeeId,\n GROUP_CONCAT(DISTINCT degs.degree ORDER BY degs.degree SEPARATOR ', ') AS degrees\n FROM profileEducation degs\n WHERE degs.degree IS NOT NULL AND degs.degree != ''\n GROUP BY degs.profileEmployeeId\n ),\n Fields AS (\n SELECT \n\t\t fies.profileEmployeeId,\n GROUP_CONCAT(DISTINCT fies.field ORDER BY fies.field SEPARATOR ', ') AS fields\n FROM profileEducation fies\n WHERE fies.field IS NOT NULL AND fies.field != ''\n GROUP BY fies.profileEmployeeId\n ),\n PositionDate AS (\n SELECT \n vcto.Years,\n vcto.Months,\n vcto.Days,\n vcto.profileEmployeeId\n FROM tenurePositionEmployee vcto\n ),\n PositionLevelDate AS (\n SELECT \n vctlo.Years,\n vctlo.Months,\n vctlo.Days,\n vctlo.profileEmployeeId\n FROM tenureLevelEmployee vctlo\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 eds.Educations,\n edls.educationLevels,\n degs.degrees,\n fies.fields,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,\n vcto.Years,\n vcto.Months,\n vcto.Days,\n vctlo.Years AS levelYears,\n vctlo.Months AS levelMonths,\n vctlo.Days AS levelDays\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 Educations eds ON p.id = eds.profileEmployeeId\n LEFT JOIN EducationLevels edls ON p.id = edls.profileEmployeeId\n LEFT JOIN Degrees degs ON p.id = degs.profileEmployeeId\n LEFT JOIN Fields fies ON p.id = fies.profileEmployeeId\n LEFT JOIN PositionDate vcto ON p.id = vcto.profileEmployeeId\n LEFT JOIN PositionLevelDate vctlo ON p.id = vctlo.profileEmployeeId"]); -// await queryRunner.query(`CREATE VIEW \`view_current_tenure_officer\` AS -// WITH resultData AS ( -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber -// FROM ( -// SELECT -// commandDateAffect, -// commandDateSign, -// positionName, -// positionCee, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, -// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - -// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId -// FROM -// profileSalary -// WHERE -// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) -// ORDER BY -// commandDateAffect ASC, commandDateSign ASC -// ) AS groupedPosition -// WHERE -// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign -// GROUP BY -// profileId, groupedId, positionName -// ) -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// days_diff, -// Years, -// Months, -// Days, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// orderNumber -// FROM resultData - -// UNION ALL - -// SELECT -// CURDATE() AS commandDateAffect, -// NULL AS positionName, -// NULL AS positionCee, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', -// NULL AS posNo, -// NULL AS positionExecutive, -// NULL AS positionType, -// NULL AS positionLevel, -// NULL AS OrgRoot, -// NULL AS orgChild1, -// NULL AS orgChild2, -// NULL AS orgChild3, -// NULL AS orgChild4, -// NULL AS commandCode, -// NULL AS commandName, -// NULL AS commandNo, -// NULL AS commandYear, -// NULL AS remark, -// profileId, -// NULL AS orderNumber -// FROM resultData -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]); -// await queryRunner.query(`CREATE VIEW \`view_pos_master\` AS SELECT -// posMaster.id, -// posMaster.posMasterNoPrefix, -// posMaster.posMasterNo, -// posMaster.posMasterNoSuffix, -// posMaster.orgRevisionId, -// posMaster.orgRootId, -// posMaster.orgChild1Id, -// posMaster.orgChild2Id, -// posMaster.orgChild3Id, -// posMaster.orgChild4Id, -// posMaster.current_holderId, -// profile.id as profileId, -// profile.prefix, -// profile.firstName, -// profile.lastName, -// profile.citizenId, -// profile.position, -// profile.amount, -// profile.dateRetire, -// profile.birthDate, -// orgRoot.id as rootId, -// orgRoot.orgRootShortName, -// orgRoot.orgRootOrder, -// orgRoot.orgRootName, -// orgChild1.id as child1Id, -// orgChild1.orgChild1ShortName, -// orgChild1.orgChild1Order, -// orgChild1.orgChild1Name, -// orgChild2.id as child2Id, -// orgChild2.orgChild2ShortName, -// orgChild2.orgChild2Order, -// orgChild2.orgChild2Name, -// orgChild3.id as child3Id, -// orgChild3.orgChild3ShortName, -// orgChild3.orgChild3Order, -// orgChild3.orgChild3Name, -// orgChild4.id as child4Id, -// orgChild4.orgChild4ShortName, -// orgChild4.orgChild4Order, -// orgChild4.orgChild4Name, -// position.id as positionId, -// position.positionIsSelected, -// position.posExecutiveId as positionPosExecutiveId, -// position.isSpecial, -// posExecutive.id as posExecutiveId, -// posExecutive.posExecutiveName, -// profileDiscipline.id as profileDisciplineId, -// profileDiscipline.date as disCriplineDate, -// profileLeave.id as profileLeaveId, -// profileAssessment.id as profileAssessmentId, -// profileAssessment.pointSum, -// posLevel.id as posLevelId, -// posLevel.posLevelName, -// posType.id as posTypeId, -// posType.posTypeName -// FROM -// posMaster -// LEFT JOIN -// profile ON posMaster.current_holderId = profile.id -// LEFT JOIN -// orgRoot ON posMaster.orgRootId = orgRoot.id -// LEFT JOIN -// orgChild1 ON posMaster.orgChild1Id = orgChild1.id -// LEFT JOIN -// orgChild2 ON posMaster.orgChild2Id = orgChild2.id -// LEFT JOIN -// orgChild3 ON posMaster.orgChild3Id = orgChild3.id -// LEFT JOIN -// orgChild4 ON posMaster.orgChild4Id = orgChild4.id -// LEFT JOIN -// position ON posMaster.id = position.posMasterId -// LEFT JOIN -// posExecutive ON position.posExecutiveId = posExecutive.id -// LEFT JOIN -// profileDiscipline ON profileDiscipline.profileId = profile.id -// LEFT JOIN -// profileLeave ON profileLeave.profileId = profile.id -// LEFT JOIN -// profileAssessment ON profileAssessment.profileId = profile.id -// LEFT JOIN -// posLevel ON profile.posLevelId = posLevel.id -// LEFT JOIN -// posType ON profile.posTypeId = posType.id -// WHERE -// posMaster.current_holderId IS NOT NULL -// ORDER BY -// profile.citizenId ASC -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_pos_master","SELECT \n posMaster.id,\n posMaster.posMasterNoPrefix,\n posMaster.posMasterNo,\n posMaster.posMasterNoSuffix,\n posMaster.orgRevisionId,\n posMaster.orgRootId,\n posMaster.orgChild1Id,\n posMaster.orgChild2Id,\n posMaster.orgChild3Id,\n posMaster.orgChild4Id,\n posMaster.current_holderId,\n profile.id as profileId,\n profile.prefix,\n profile.firstName,\n profile.lastName,\n profile.citizenId,\n profile.position,\n profile.amount,\n profile.dateRetire,\n profile.birthDate,\n orgRoot.id as rootId,\n orgRoot.orgRootShortName,\n orgRoot.orgRootOrder,\n orgRoot.orgRootName,\n orgChild1.id as child1Id,\n orgChild1.orgChild1ShortName,\n orgChild1.orgChild1Order,\n orgChild1.orgChild1Name,\n orgChild2.id as child2Id,\n orgChild2.orgChild2ShortName,\n orgChild2.orgChild2Order,\n orgChild2.orgChild2Name,\n orgChild3.id as child3Id,\n orgChild3.orgChild3ShortName,\n orgChild3.orgChild3Order,\n orgChild3.orgChild3Name,\n orgChild4.id as child4Id,\n orgChild4.orgChild4ShortName,\n orgChild4.orgChild4Order,\n orgChild4.orgChild4Name,\n position.id as positionId,\n position.positionIsSelected,\n position.posExecutiveId as positionPosExecutiveId,\n position.isSpecial,\n posExecutive.id as posExecutiveId,\n posExecutive.posExecutiveName,\n profileDiscipline.id as profileDisciplineId,\n profileDiscipline.date as disCriplineDate,\n profileLeave.id as profileLeaveId,\n profileAssessment.id as profileAssessmentId,\n profileAssessment.pointSum,\n posLevel.id as posLevelId,\n posLevel.posLevelName,\n\t posType.id as posTypeId,\n posType.posTypeName\n FROM \n posMaster\n LEFT JOIN \n profile ON posMaster.current_holderId = profile.id\n LEFT JOIN \n orgRoot ON posMaster.orgRootId = orgRoot.id\n LEFT JOIN \n orgChild1 ON posMaster.orgChild1Id = orgChild1.id\n LEFT JOIN \n orgChild2 ON posMaster.orgChild2Id = orgChild2.id\n LEFT JOIN \n orgChild3 ON posMaster.orgChild3Id = orgChild3.id\n LEFT JOIN \n orgChild4 ON posMaster.orgChild4Id = orgChild4.id\n LEFT JOIN \n position ON posMaster.id = position.posMasterId\n LEFT JOIN \n posExecutive ON position.posExecutiveId = posExecutive.id\n LEFT JOIN \n profileDiscipline ON profileDiscipline.profileId = profile.id\n LEFT JOIN \n profileLeave ON profileLeave.profileId = profile.id\n LEFT JOIN \n profileAssessment ON profileAssessment.profileId = profile.id\n LEFT JOIN \n posLevel ON profile.posLevelId = posLevel.id\n LEFT JOIN \n posType ON profile.posTypeId = posType.id\n WHERE \t\n posMaster.current_holderId IS NOT NULL\n ORDER BY \n profile.citizenId ASC"]); -// await queryRunner.query(`CREATE VIEW \`view_current_tenure_exc_officer\` AS -// WITH resultData AS ( -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// orgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber -// FROM ( -// SELECT -// commandDateAffect, -// commandDateSign, -// positionName, -// positionCee, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// orgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - -// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId -// FROM -// profileSalary -// WHERE -// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND -// positionExecutive <> '' -// ORDER BY -// commandDateAffect ASC, commandDateSign ASC -// ) AS groupedPositionExe -// GROUP BY -// groupedId, positionExecutive -// ) -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// days_diff, -// Years, -// Months, -// Days, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// orgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileId, -// orderNumber -// FROM resultData - -// UNION ALL - -// SELECT -// CURDATE() AS commandDateAffect, -// NULL AS positionName, -// NULL AS positionCee, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', -// NULL AS posNo, -// NULL AS positionExecutive, -// NULL AS positionType, -// NULL AS positionLevel, -// NULL AS orgRoot, -// NULL AS orgChild1, -// NULL AS orgChild2, -// NULL AS orgChild3, -// NULL AS orgChild4, -// NULL AS commandCode, -// NULL AS commandName, -// NULL AS commandNo, -// NULL AS commandYear, -// NULL AS remark, -// profileId, -// NULL AS orderNumber -// FROM resultData -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_exc_officer","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND\n positionExecutive <> ''\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPositionExe\n GROUP BY\n groupedId, positionExecutive\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff, \n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n orgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS orgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileId,\n NULL AS orderNumber\n FROM resultData"]); -// await queryRunner.query(`CREATE VIEW \`view_current_tenure_employee\` AS -// WITH resultData AS ( -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff, -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF( -// DAY, -// LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days', -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileEmployeeId, -// ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber -// FROM ( -// SELECT -// commandDateAffect, -// commandDateSign, -// positionName, -// positionCee, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileEmployeeId, -// LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign, -// ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) - -// ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId -// FROM -// profileSalary -// WHERE -// commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) -// ORDER BY -// commandDateAffect ASC, commandDateSign ASC -// ) AS groupedPosition -// WHERE -// prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign -// GROUP BY -// profileEmployeeId, groupedId, positionName -// ) -// SELECT -// commandDateAffect, -// positionName, -// positionCee, -// days_diff, -// Years, -// Months, -// Days, -// posNo, -// positionExecutive, -// positionType, -// positionLevel, -// OrgRoot, -// orgChild1, -// orgChild2, -// orgChild3, -// orgChild4, -// commandCode, -// commandName, -// commandNo, -// commandYear, -// remark, -// profileEmployeeId, -// orderNumber -// FROM resultData - -// UNION ALL - -// SELECT -// CURDATE() AS commandDateAffect, -// NULL AS positionName, -// NULL AS positionCee, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff, -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months', -// TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days', -// NULL AS posNo, -// NULL AS positionExecutive, -// NULL AS positionType, -// NULL AS positionLevel, -// NULL AS OrgRoot, -// NULL AS orgChild1, -// NULL AS orgChild2, -// NULL AS orgChild3, -// NULL AS orgChild4, -// NULL AS commandCode, -// NULL AS commandName, -// NULL AS commandNo, -// NULL AS commandYear, -// NULL AS remark, -// profileEmployeeId, -// NULL AS orderNumber -// FROM resultData -// `); -// await queryRunner.query(`INSERT INTO \`hrms_organization\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["hrms_organization","VIEW","view_current_tenure_employee","WITH resultData AS (\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) AS days_diff,\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(\n DAY,\n LAG(MIN(commandDateAffect)) OVER (ORDER BY commandDateAffect), MIN(commandDateAffect)) % 30.4375 AS 'Days',\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n ROW_NUMBER() OVER (PARTITION BY profileEmployeeId ORDER BY commandDateAffect ASC) AS orderNumber\n FROM (\n SELECT\n commandDateAffect,\n commandDateSign,\n positionName,\n positionCee,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n LAG(commandDateSign) OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) AS prevCommandDateSign,\n ROW_NUMBER() OVER (ORDER BY commandDateAffect ASC, commandDateSign ASC) -\n ROW_NUMBER() OVER (PARTITION BY positionName ORDER BY commandDateAffect ASC, commandDateSign ASC) as groupedId\n FROM\n profileSalary\n WHERE\n commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16)\n ORDER BY\n commandDateAffect ASC, commandDateSign ASC\n ) AS groupedPosition\n WHERE\n prevCommandDateSign IS NULL OR commandDateSign >= prevCommandDateSign\n GROUP BY\n profileEmployeeId, groupedId, positionName\n )\n SELECT\n commandDateAffect,\n positionName,\n positionCee,\n days_diff,\n Years,\n Months,\n Days,\n posNo,\n positionExecutive,\n positionType,\n positionLevel,\n OrgRoot,\n orgChild1,\n orgChild2,\n orgChild3,\n orgChild4,\n commandCode,\n commandName,\n commandNo,\n commandYear,\n remark,\n profileEmployeeId,\n orderNumber\n FROM resultData\n\n UNION ALL\n\n SELECT\n CURDATE() AS commandDateAffect,\n NULL AS positionName,\n NULL AS positionCee,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',\n TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',\n NULL AS posNo,\n NULL AS positionExecutive,\n NULL AS positionType,\n NULL AS positionLevel,\n NULL AS OrgRoot,\n NULL AS orgChild1,\n NULL AS orgChild2,\n NULL AS orgChild3,\n NULL AS orgChild4,\n NULL AS commandCode,\n NULL AS commandName,\n NULL AS commandNo,\n NULL AS commandYear,\n NULL AS remark,\n profileEmployeeId,\n NULL AS orderNumber\n FROM resultData"]); - } - - public async down(queryRunner: QueryRunner): Promise { - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_employee","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_current_tenure_employee\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_exc_officer","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_current_tenure_exc_officer\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_pos_master","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_pos_master\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_current_tenure_officer","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_current_tenure_officer\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_employee","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_registry_employee\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_employee_pos_master","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_employee_pos_master\``); - // await queryRunner.query(`DELETE FROM \`hrms_organization\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","hrms_organization"]); - // await queryRunner.query(`DROP VIEW \`view_registry_officer\``); - // await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP FOREIGN KEY \`FK_f1ded3e1f83ab2437f739a14f38\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FLAG_EDUCATION\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FLAG_EDUCATION\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`MAJOR_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MAJOR_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` DROP COLUMN \`FUND_COURSE_CODE\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`FUND_COURSE_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionLevelName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionTypeName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PosNoName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`SalaryRef\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryRef\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`posNo\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNo\` varchar(40) NULL COMMENT 'เลขที่ตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP PRIMARY KEY`); - // await queryRunner.query(`ALTER TABLE \`positionOfficer\` DROP COLUMN \`mp_command_num\``); - // await queryRunner.query(`ALTER TABLE \`positionOfficer\` ADD \`mp_command_num\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`profileSalary\` CHANGE \`isEntry\` \`isEntry\` tinyint NULL COMMENT 'ข้อมูลจาก Entry'`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` DROP COLUMN \`ID\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`ProfileId\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionName\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`PositionSalaryAmount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`Amount\``); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` DROP COLUMN \`Order\``); - await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`posNumCodeSitAbb\``); - await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`posNumCodeSit\``); - // await queryRunner.query(`ALTER TABLE \`HR_EDUCATION\` ADD \`MINOR_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_NAME_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_CODE_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`WORK_LINE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UPDATE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UPCLASS_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`UNIVER_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SUN_NO\` 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 \`SPECIAL_PERCENT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_AMT_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SPECIAL_AMT\` 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 \`SALARY_POS_ABB_NAME_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_POS_ABB_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_CODE_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_LEVEL\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_ADD_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SALARY_ADD\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SAL_POS_AMOUNT_2\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`SAL_POS_AMOUNT_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETURN_OCCUPY_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETIRE_TYPE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RETIRE_POS_NO\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_MP_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RET_BORN_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`RANK_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POSITION_CATG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT_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_CODE\` 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_ABB\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`POS_NUM_CODE_SIT\` 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 \`OLD_RETIRE_SECTION_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`OLD_RETIRE_JOB_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 \`MP_YEAR_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_POS_DATE_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_POS_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FORCE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG_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_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_NUM_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_NUM\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_DATE_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_COMMAND_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_CODE_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MP_CEE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`MARRIAGE_STATE\` 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 \`HELP_LIVING_AMOUNT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`GROUPWORK_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FUND_COURSE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TYPE\` 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 \`FLAG_TO_NAME_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_TO_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_RETIRE_STATUS\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`FLAG_CUR_ST\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`EDUCATION_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`DEXPIRE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CUR_YEAR_O\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CUR_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CREATE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`COST_LIVING_AMOUNT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`CONTENT_NO\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ADMIN_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`OFFICER\` ADD \`ADMIN_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`WORK_LINE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`WORK_LINE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`USER_UPDATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`USER_CREATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`UPDATE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`UP_C_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIALIST_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIALIST_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SPECIAL_AMT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SECTION_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SECTION_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_CODE_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_ABB_NAME_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_POS_ABB_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_LEVEL_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY_LEVEL\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SALARY\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SAL_POS_AMOUNT_2\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`SAL_POS_AMOUNT_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`REMARK\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`REC_STATUS\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`PROVINCE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POSITION_CATG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE_SIT_ABB_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`POS_NUM_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`PLACE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ORDER_MOVE_POSITION\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MVMENT_OF\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MVMENT_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_POS_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FORCE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG_CURRENT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG_1\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_NUM_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_NUM\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_DATE_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_COMMAND_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_CEE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`MP_CEE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`JOB_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`JOB_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`GROUPWORK_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`GROUPWORK_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_E\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_CODE_E\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_TO_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_POS_STATUS\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FILL_APP_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DIVISION_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DIVISION_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DEPARTMENT_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`DEPARTMENT_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CUR_YEAR_EDIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CUR_YEAR\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CREATE_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COURSE_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COURSE_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`COUNTRY_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`CIT\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`AUDIT_FLAG\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`AUDIT_DATE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ADMIN_NAME\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ADMIN_CODE\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`ACTIVE_STATUS\` text NULL`); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`ORDER\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`HRMS_DIV_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`IMPORT_ORG\` ADD \`HRMS_DEP_CODE\` mediumtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryStatus\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`SalaryClass\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`remark\` varchar(255) NULL COMMENT 'หมายเหตุ'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`RefCommandNo\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`RefCommandDate\` datetime(6) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`profileEmployeeId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง ProfileEmployee'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PosNoEmployee\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`posNoAbb\` varchar(40) NULL COMMENT 'ตัวย่อเลขที่ตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionTypeId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionType\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionSalaryAmount\` double NULL COMMENT 'เงินประจำตำแหน่ง' DEFAULT '0'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionRef\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionPathSideName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionPathSideId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionName\` text NULL COMMENT 'ตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLineName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLineId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionLevelId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionLevel\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveSideId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionExecutiveId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionExecutive\` varchar(255) NULL COMMENT 'ตำแหน่งทางการบริหาร'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeePositionSideId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeePositionId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeeLevelId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`PositionEmployeeGroupId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`positionCee\` varchar(255) NULL COMMENT 'ระดับของเก่าที่ยังไม่เทียบเท่าแบบแท่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgRoot\` varchar(255) NULL COMMENT 'root name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OrgName\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild4\` varchar(255) NULL COMMENT 'child4 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild3\` varchar(255) NULL COMMENT 'child3 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild2\` varchar(255) NULL COMMENT 'child2 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`orgChild1\` varchar(255) NULL COMMENT 'child1 name'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OrganizationShortNameId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`order\` int NULL COMMENT 'เรียงลำดับใหมาตามการนำเข้า'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`OcId\` char(36) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`mouthSalaryAmount\` double NULL COMMENT 'เงินค่าตอบแทนรายเดือน' DEFAULT '0'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`isGovernment\` tinyint NULL COMMENT 'เข้ารับราชการ'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`IsActive\` tinyint(1) NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`dateGovernment\` datetime NULL COMMENT 'วันที่'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandYear\` int NULL COMMENT 'ปีที่ออกคำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`CommandTypeName\` longtext NOT NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandNo\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandName\` varchar(255) NULL COMMENT 'ชื่อประเภทคำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง command'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandDateSign\` datetime NULL COMMENT 'คำสั่งวันที่'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandDateAffect\` datetime NULL COMMENT 'คำสั่งมีผลวันที่'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`commandCode\` varchar(255) NULL COMMENT 'รหัสประเภทของคำสั่ง'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`CLevel\` longtext NULL`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`amount\` double NULL COMMENT 'เงินเดือนฐาน' DEFAULT '0'`); - // await queryRunner.query(`ALTER TABLE \`ProfileSalaries\` ADD \`AgencyName\` longtext NULL`); - // await queryRunner.query(`DROP TABLE \`EMPLOYEE\``); - // await queryRunner.query(`CREATE INDEX \`FK_f1ded3e1f83ab2437f739a14f38\` ON \`profileSalaryHistory\` (\`profileSalaryId\`)`); - } - -}