Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Suphonchai Phoonsawat 2024-12-10 10:05:46 +07:00
commit c5d0d4a941
28 changed files with 496 additions and 219 deletions

View file

@ -128,4 +128,56 @@ export class ApiKeyController extends Controller {
});
return new HttpSuccess(apiName);
}
/**
* API Api Key
*
* @summary Api Key (ADMIN)
*
*/
@Post("history")
async getHistory(
@Body()
requestBody: {
startDate: Date;
endDate: Date;
apiNameId: string | null;
},
@Request() request: RequestWithUser,
) {
if (requestBody.apiNameId) {
const apiName = await this.apiNameRepository.findOne({
where: { id: requestBody.apiNameId },
});
if (!apiName)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรายการ Web Service นี้ในระบบ");
}
const apiHistory = await AppDataSource.getRepository(ApiHistory)
.createQueryBuilder("apiHistory")
.leftJoinAndSelect("apiHistory.apiKey", "apiKey")
.leftJoinAndSelect("apiHistory.apiName", "apiName")
.andWhere(requestBody.apiNameId ? `apiHistory.apiNameId = :apiNameId` : "1=1", {
apiNameId: requestBody.apiNameId,
})
.andWhere(
`apiHistory.createdAt >= DATE(:startDate) AND apiHistory.createdAt <= DATE(:endDate)`,
{
startDate: new Date(requestBody.startDate),
endDate: new Date(
requestBody.endDate.setDate(new Date(requestBody.endDate).getDate() + 1),
),
},
)
.orderBy("apiHistory.createdAt", "DESC")
.getMany();
const result = apiHistory.map((x) => ({
id: x.id,
apiName: x.apiName.name,
apiKey: x.apiKey.name,
createdAt: x.createdAt,
ipApi: x.ipApi,
}));
return new HttpSuccess(result);
}
}

View file

@ -1615,19 +1615,23 @@ export class CommandController extends Controller {
persons: {
refId: string;
profileId?: string | null;
citizenId: string | null;
prefix: string | null;
firstName: string | null;
lastName: string | null;
citizenId?: string | null;
prefix?: string | null;
firstName?: string | null;
lastName?: string | null;
remarkVertical?: string | null;
remarkHorizontal?: string | null;
rootId?: string | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
}[];
},
@Request() request: RequestWithUser,
) {
let command = new Command();
let commandCode = null;
let commandCode:string = "";
let null_: any = null;
if (
requestBody.commandId != undefined &&
@ -1707,30 +1711,40 @@ export class CommandController extends Controller {
commandRecive = Object.assign(new CommandRecive(), item);
commandRecive.order = order;
let salaryData = null_;
if (item.profileId) {
salaryData = await this.profileRepository.findOne({
where: {
id: item.profileId,
},
});
let null_: any = 0;
if (!salaryData) {
salaryData = await this.profileEmployeeRepository.findOne({
const excludedCommands = ["C-PM-33", "C-PM-34", "C-PM-35", "C-PM-36", "C-PM-37"];
if (!excludedCommands.includes(commandCode)) {
if (item.profileId) {
salaryData = await this.profileRepository.findOne({
where: {
id: item.profileId,
},
});
let null_: any = 0;
if (!salaryData) {
salaryData = await this.profileEmployeeRepository.findOne({
where: {
id: item.profileId,
},
});
}
commandRecive.amount = salaryData ? salaryData.amount : null_;
commandRecive.positionSalaryAmount = salaryData
? salaryData.positionSalaryAmount
: null_;
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
} else {
commandRecive.amount = null_;
commandRecive.positionSalaryAmount = null_;
commandRecive.mouthSalaryAmount = null_;
}
commandRecive.amount = salaryData ? salaryData.amount : null_;
commandRecive.positionSalaryAmount = salaryData
? salaryData.positionSalaryAmount
: null_;
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
} else {
commandRecive.amount = null_;
commandRecive.positionSalaryAmount = null_;
commandRecive.mouthSalaryAmount = null_;
commandRecive.amount = item.amount ?? null_;
commandRecive.amountSpecial = item.amountSpecial ?? null_;
commandRecive.positionSalaryAmount = item.positionSalaryAmount ?? null_;
commandRecive.mouthSalaryAmount = item.mouthSalaryAmount ?? null_;
}
commandRecive.remarkVertical =
item.remarkVertical == null ? null_ : item.remarkVertical;
commandRecive.remarkHorizontal =
@ -1898,6 +1912,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -1917,7 +1932,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOneBy({ id: item.profileId });
const profile:any = await this.profileRepository.findOneBy({ id: item.profileId });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
@ -2002,6 +2017,8 @@ export class CommandController extends Controller {
profile.posLevelId = positionNew.posLevelId;
profile.posTypeId = positionNew.posTypeId;
profile.position = positionNew.positionName;
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
await this.profileRepository.save(profile);
await this.positionRepository.save(positionNew);
}
@ -2020,6 +2037,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -2036,7 +2054,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
const profile:any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
@ -2131,7 +2149,8 @@ export class CommandController extends Controller {
profile.position = positionNew.positionName;
profile.employeeOc = posMaster?.orgRoot?.orgRootName ?? null;
profile.positionEmployeePositionId = positionNew.positionName;
profile.amount = item.amount ?? null;
profile.amountSpecial = item.amountSpecial ?? null;
await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew);
}
@ -2150,6 +2169,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -2215,7 +2235,6 @@ export class CommandController extends Controller {
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date();
// profile.dateStart = new Date();
if (item.isLeave == true) {
await removeProfileInOrganize(profile.id, "OFFICER");
}
@ -2236,21 +2255,28 @@ export class CommandController extends Controller {
const returnWork = await checkReturnCommandType(String(item.commandId));
//คำสั่งบรรจุกลับเข้ารับราชการ หรือ ผู้ออกไปรับราชการทหารกลับเข้ารับราชการ solutionเดิม ให้ enable user เปลี่ยนเป็นสร้าง user ใหม่เลยเพราะยังไงตอนถูกพักก็ถูกลบ user
if (returnWork && item.isGovernment) {
/*if (profile.keycloak != null) {
const enableActive = await enableStatus(profile.keycloak, true);
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
} else {*/
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
// if (typeof userKeycloakId !== "string") {
// throw new Error(userKeycloakId.errorMessage);
// }
const list = await getRoles();
if (!Array.isArray(list))
throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles(
let userKeycloakId;
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
// กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่ และหากยังไม่สามารถลบได้ให้แสดง Error
if (profile.keycloak != null && userKeycloakId && userKeycloakId.errorMessage === "User exists with same username") {
const delUserKeycloak = await deleteUser(profile.keycloak);
if(delUserKeycloak) {
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
}
else {
throw new HttpError(HttpStatus.BAD_REQUEST, "พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้");
}
}
const list = await getRoles();
let result = false;
if (Array.isArray(list) && userKeycloakId) {
result = await addUserRoles(
userKeycloakId,
list
.filter((v) => v.name === "USER")
@ -2259,10 +2285,11 @@ export class CommandController extends Controller {
name: x.name,
})),
);
// if (!result) throw new Error("Failed. Cannot set user's role.");
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
/*}*/
}
profile.amount = item.amount ?? _null;
profile.amountSpecial = item.amountSpecial ?? _null;
profile.isActive = true;
profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : "";
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
}
await this.profileRepository.save(profile);
@ -2378,6 +2405,7 @@ export class CommandController extends Controller {
profileId: string;
date?: Date | null;
amount?: Double | null;
amountSpecial?: Double | null;
positionSalaryAmount?: Double | null;
mouthSalaryAmount?: Double | null;
posNo: string | null;
@ -2398,7 +2426,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile = await this.profileRepository.findOne({
const profile:any = await this.profileRepository.findOne({
where: { id: item.profileId },
relations: ["roleKeycloaks"],
});
@ -2441,6 +2469,8 @@ export class CommandController extends Controller {
profile.posLevelId = _null;
profile.leaveReason = item.leaveReason ?? _null;
profile.dateLeave = item.dateLeave ?? _null;
profile.amount = item.amount ?? _null;
profile.amountSpecial = item.amountSpecial ?? _null;
await this.profileRepository.save(profile, { data: req });
}
Object.assign(data, { ...item, ...meta });
@ -3082,6 +3112,8 @@ export class CommandController extends Controller {
profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : [];
profile.email = item.bodyProfile.email;
profile.dateStart = item.bodyProfile.dateStart;
profile.amount = item.bodyProfile.amount ?? null;
profile.amountSpecial = item.bodyProfile.amountSpecial ?? null;
await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile });
}
@ -3125,13 +3157,17 @@ export class CommandController extends Controller {
where: { profileId: profile.id },
order: { order: "DESC" },
});
const profileSal = new ProfileSalary();
const profileSal: any = new ProfileSalary();
Object.assign(profileSal, { ...item.bodySalarys, ...meta });
const salaryHistory = new ProfileSalaryHistory();
Object.assign(salaryHistory, { ...profileSal, id: undefined });
profileSal.order = dest_item == null ? 1 : dest_item.order + 1;
profileSal.profileId = profile.id;
profileSal.dateGovernment = meta.createdAt;
profileSal.amount = item.bodySalarys.amount ?? null;
profileSal.amountSpecial = item.bodySalarys.amountSpecial ?? null;
profileSal.positionSalaryAmount = item.bodySalarys.positionSalaryAmount ?? null;
profileSal.mouthSalaryAmount = item.bodySalarys.mouthSalaryAmount ?? null;
await this.salaryRepo.save(profileSal, { data: req });
setLogDataDiff(req, { before, after: profileSal });
salaryHistory.profileSalaryId = profileSal.id;
@ -3279,6 +3315,7 @@ export class CommandController extends Controller {
commandYear: number;
templateDoc: string | null;
amount: Double | null;
amountSpecial: Double | null;
positionSalaryAmount: Double | null;
mouthSalaryAmount: Double | null;
}[];
@ -3308,6 +3345,7 @@ export class CommandController extends Controller {
profileEmployeeId: profile.id,
date: new Date(),
amount: item.amount,
amountSpecial: item.amountSpecial,
commandId: item.commandId,
positionSalaryAmount: item.positionSalaryAmount,
mouthSalaryAmount: item.mouthSalaryAmount,
@ -3426,9 +3464,8 @@ export class CommandController extends Controller {
const _null: any = null;
profile.employeeWage = item.amount == null ? _null : item.amount.toString();
profile.dateStart = new Date();
// profile.amount = item.amount == null ? _null : item.amount.toString(); //เผื่อไว้
// profile.positionSalaryAmount = item.positionSalaryAmount == null ? _null : item.positionSalaryAmount.toString();
// profile.mouthSalaryAmount = item.mouthSalaryAmount == null ? _null : item.mouthSalaryAmount.toString();
profile.amount = item.amount == null ? _null : item.amount;
profile.amountSpecial = item.amountSpecial == null ? _null : item.amountSpecial;
await this.profileEmployeeRepository.save(profile);
await this.employeePositionRepository.save(positionNew);

View file

@ -199,7 +199,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: item.dateStart,
govAgeAbsent: item.govAgeAbsent,
govAgePlus: item.govAgePlus,
birthDate: item.birthDate,
birthDate: item.birthDate ?? new Date(),
reasonSameDate: item.reasonSameDate,
ethnicity: item.ethnicity,
telephoneNumber: item.telephoneNumber,
@ -495,7 +495,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -732,7 +732,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -1028,7 +1028,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -1295,7 +1295,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -1621,7 +1621,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -1888,7 +1888,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -2072,7 +2072,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -2209,7 +2209,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
@ -2316,7 +2316,7 @@ export class OrganizationDotnetController extends Controller {
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
position: profile.position,
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
@ -2417,7 +2417,7 @@ export class OrganizationDotnetController extends Controller {
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
birthDate: profile.birthDate,
birthDate: profile.birthDate ?? new Date(),
position: profile.position,
posMaster: posMaster == null ? null : posMaster.posMasterNo,
posMasterNo: posMaster == null ? null : posMaster.posMasterNo,
@ -2589,7 +2589,7 @@ export class OrganizationDotnetController extends Controller {
dateStart: item.dateStart,
govAgeAbsent: item.govAgeAbsent,
govAgePlus: item.govAgePlus,
birthDate: item.birthDate,
birthDate: item.birthDate ?? new Date(),
reasonSameDate: item.reasonSameDate,
ethnicity: item.ethnicity,
telephoneNumber: item.telephoneNumber,

View file

@ -163,10 +163,11 @@ export class OrganizationUnauthorizeController extends Controller {
: item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0
? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
// const amount =
// item.current_holder == null || item.current_holder.profileSalary.length == 0
// ? null
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);
@ -380,10 +381,11 @@ export class OrganizationUnauthorizeController extends Controller {
orgShortName = item.orgChild4?.orgChild4ShortName;
}
const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0
? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
// const amount =
// item.current_holder == null || item.current_holder.profileSalary.length == 0
// ? null
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);

View file

@ -106,22 +106,15 @@ export class PermissionOrgController extends Controller {
} else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") {
queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild3.orgChild3ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild2.orgChild2ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
queryLike = `
CASE
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
END LIKE :keyword
`;
}
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },

View file

@ -3757,22 +3757,15 @@ export class ProfileController extends Controller {
} else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") {
queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild3.orgChild3ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild2.orgChild2ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
queryLike = `
CASE
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
END LIKE :keyword
`;
}
let nodeCondition = "1=1";
let nodeAll = "";
@ -4116,22 +4109,15 @@ export class ProfileController extends Controller {
} else if (searchField == "position") {
queryLike = "profile.position LIKE :keyword";
} else if (searchField == "posNo") {
queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild3.orgChild3ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild2.orgChild2ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
queryLike = `
CASE
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
END LIKE :keyword
`;
}
let nodeCondition = "1=1";
let nodeAll = "";
@ -4249,20 +4235,22 @@ export class ProfileController extends Controller {
: `profile.dateLeave IS NOT NULL`
: "1=1",
)
.andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
.andWhere(nodeCondition, {
nodeId: nodeId,
nodeId: nodeId,
})
// .andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
// orgRevisionId: findRevision.id,
// })
.andWhere(
new Brackets((qb) => {
qb.orWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
)
})
)
.orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
@ -6039,7 +6027,12 @@ export class ProfileController extends Controller {
switch (body.fieldName) {
case "citizenId":
[findProfile, total] = await this.profileRepo.findAndCount({
where: { citizenId: Like(`%${body.keyword}%`) },
where: {
citizenId: Like(`%${body.keyword}%`),
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [
"posType",
"posLevel",
@ -6066,7 +6059,8 @@ export class ProfileController extends Controller {
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.where("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` })
.where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id })
.andWhere("CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` })
.skip(skip)
.take(take)
.getManyAndCount();
@ -6074,7 +6068,12 @@ export class ProfileController extends Controller {
case "position":
[findProfile, total] = await this.profileRepo.findAndCount({
where: { position: Like(`%${body.keyword}%`) },
where: {
position: Like(`%${body.keyword}%`),
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [
"posType",
"posLevel",
@ -6122,6 +6121,9 @@ export class ProfileController extends Controller {
where: {
posType: {
posTypeName:Like(`%${body.keyword}%`)
},
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [
@ -6145,6 +6147,9 @@ export class ProfileController extends Controller {
where: {
posLevel: {
posLevelName:Like(`%${body.keyword}%`)
},
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [
@ -6167,6 +6172,7 @@ export class ProfileController extends Controller {
[findProfile, total] = await this.profileRepo.findAndCount({
where: {
current_holders:{
orgRevisionId:revision?.id,
orgRoot:{
orgRootName:Like(`%${body.keyword}%`)
}
@ -6189,6 +6195,11 @@ export class ProfileController extends Controller {
default:
[findProfile, total] = await this.profileRepo.findAndCount({
where:{
current_holders:{
orgRevisionId:revision?.id
}
},
relations: [
"posType",
"posLevel",
@ -7236,10 +7247,11 @@ export class ProfileController extends Controller {
: item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0
? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
// const amount =
// item.current_holder == null || item.current_holder.profileSalary.length == 0
// ? null
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);

View file

@ -1385,22 +1385,15 @@ export class ProfileEmployeeController extends Controller {
} else if (searchField == "position") {
queryLike = "profileEmployee.position LIKE :keyword";
} else if (searchField == "posNo") {
queryLike = `CONCAT(
IFNULL(orgChild4.orgChild4ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild3.orgChild3ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild2.orgChild2ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgChild1.orgChild1ShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword OR CONCAT(
IFNULL(orgRoot.orgRootShortName, ''),
IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`;
queryLike = `
CASE
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild2Id IS NOT NULL THEN CONCAT(orgChild2.orgChild2ShortName, current_holders.posMasterNo)
WHEN current_holders.orgChild1Id IS NOT NULL THEN CONCAT(orgChild1.orgChild1ShortName, current_holders.posMasterNo)
ELSE CONCAT(orgRoot.orgRootShortName, current_holders.posMasterNo)
END LIKE :keyword
`;
}
let nodeCondition = "1=1";
let nodeAll = "";
@ -2957,10 +2950,11 @@ export class ProfileEmployeeController extends Controller {
orgShortName = item.orgChild4?.orgChild4ShortName;
}
const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0
? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
// const amount =
// item.current_holder == null || item.current_holder.profileSalary.length == 0
// ? null
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);

View file

@ -2699,10 +2699,11 @@ export class ProfileEmployeeTempController extends Controller {
orgShortName = item.orgChild4?.orgChild4ShortName;
}
const amount =
item.current_holder == null || item.current_holder.profileSalary.length == 0
? null
: item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
// const amount =
// item.current_holder == null || item.current_holder.profileSalary.length == 0
// ? null
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
const amount = item.current_holder?item.current_holder.amount:null;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);

View file

@ -122,7 +122,7 @@ export class ProfileSalaryController extends Controller {
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
const _null:any = null;
Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
@ -131,6 +131,11 @@ export class ProfileSalaryController extends Controller {
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
profile.amount = body?.amount??_null;
profile.positionSalaryAmount = body?.positionSalaryAmount??_null;
profile.mouthSalaryAmount = body.mouthSalaryAmount??_null;
await this.profileRepo.save(profile, { data: req });
return new HttpSuccess();
}
@ -173,6 +178,7 @@ export class ProfileSalaryController extends Controller {
let null_:any = null;
profile.amount = body.amount ?? null_;
profile.amountSpecial = body.amountSpecial ?? null_;
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
profile.mouthSalaryAmount = body.mouthSalaryAmount ?? null_;
await this.profileRepo.save(profile);

View file

@ -137,12 +137,17 @@ export class ProfileSalaryEmployeeController extends Controller {
Object.assign(data, { ...body, ...meta });
const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined });
const _null:any = null;
await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history, { data: req });
profile.amount = body?.amount??_null;
profile.positionSalaryAmount = body?.positionSalaryAmount??_null;
profile.mouthSalaryAmount = body.mouthSalaryAmount??_null;
await this.profileRepo.save(profile, { data: req });
return new HttpSuccess();
}
@ -189,6 +194,7 @@ export class ProfileSalaryEmployeeController extends Controller {
let null_:any = null;
profile.amount = body.amount ?? null_;
profile.amountSpecial = body.amountSpecial ?? null_;
profile.positionSalaryAmount = body.positionSalaryAmount ?? null_;
profile.mouthSalaryAmount = body.mouthSalaryAmount ?? null_;
await this.profileRepo.save(profile);