new-salary gen (emp)

This commit is contained in:
AdisakKanthawilang 2025-04-17 10:20:56 +07:00
parent e585e41a70
commit 1a38978b17
2 changed files with 431 additions and 16 deletions

View file

@ -20,6 +20,7 @@ import { viewPosMaster } from "../entities/view/viewPosMaster";
import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmployeeEvaluation";
import Extension from "../interfaces/extension";
import { resetPassword } from "../keycloak";
import { viewEmployeePosMaster } from "../entities/view/viewEmployeePosMaster";
@Route("api/v1/org/unauthorize")
@Tags("OrganizationUnauthorize")
@Response(
@ -299,8 +300,8 @@ export class OrganizationUnauthorizeController extends Controller {
* @summary TEST #76 (unauthorize)
*
*/
@Post("testsalary/gen")
async testsalaryGen(
@Post("new-salary/gen")
async newSalaryGen(
@Body()
body: {
page: number;
@ -388,7 +389,7 @@ export class OrganizationUnauthorizeController extends Controller {
if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster");
}
const formattedData = findPosMaster.map((item) => {
let orgShortName = "";
@ -476,21 +477,18 @@ export class OrganizationUnauthorizeController extends Controller {
child4Order: item.orgChild4Order,
result: pointSum,
duration: null,
// isPunish:
// item.current_holder.profileDisciplines.filter(
// (x: any) =>
// new Date(
// `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
// ) >= datePeriodStart &&
// new Date(
// `${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
// ) <= datePeriodEnd,
// ).length > 0
// ? true
// : false,
isPunish:
new Date(
`${new Date(item.disCriplineDate).getFullYear()}-${String(new Date(item.disCriplineDate).getMonth() + 1).padStart(2, "0")}-${String(new Date(item.disCriplineDate).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) >= datePeriodStart &&
new Date(
`${new Date(item.disCriplineDate).getFullYear()}-${String(new Date(item.disCriplineDate).getMonth() + 1).padStart(2, "0")}-${String(new Date(item.disCriplineDate).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) <= datePeriodEnd
? true
: false,
isSuspension: item.dateRetire == null ? false : true,
isAbsent: item.profileDisciplineId ? true : false,
isLeave: item.profileLeaveId ? true : false,
isLeave: item.profileLeaveId ? true : false,
isRetired:
item.birthDate == null ||
calculateRetireDate(item.birthDate).getFullYear() != body.year
@ -722,6 +720,208 @@ export class OrganizationUnauthorizeController extends Controller {
return new HttpSuccess({ data: formattedData, total: total });
}
/**
* API (unauthorize)
*
* @summary ORG_072 - #76 (unauthorize)
*
*/
@Post("new-salary/employee/gen")
async newSalaryEmployeeGen(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
year: number;
period: string;
},
) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const [findPosMaster, total] = await AppDataSource.getRepository(viewEmployeePosMaster)
.createQueryBuilder("viewEmployeePosMaster")
.where({
orgRevisionId: findRevision?.id,
})
.andWhere(
new Brackets((qb) => {
qb.where(
body.keyword != null && body.keyword != ""
? "prefix LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "firstName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "lastName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "position LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posType.posTypeName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posLevel.posLevelName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
);
}),
)
.orderBy("citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster");
}
const formattedData = findPosMaster.map((item) => {
let orgShortName = "";
if (item.orgChild1Id === null) {
orgShortName = item?.orgRootShortName;
} else if (item.orgChild2Id === null) {
orgShortName = item?.orgChild1ShortName;
} else if (item.orgChild3Id === null) {
orgShortName = item?.orgChild2ShortName;
} else if (item.orgChild4Id === null) {
orgShortName = item?.orgChild3ShortName;
} else {
orgShortName = item?.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 ? item.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`,
);
let datePeriodEnd = 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`,
);
if (body.period.toLocaleUpperCase() == "APR") {
datePeriodStart = new Date(`${body.year}-03-31T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-03-31T00:00:00.000Z`);
}
if (body.period.toLocaleUpperCase() == "OCT") {
datePeriodStart = new Date(`${body.year}-09-30T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-09-30T00:00:00.000Z`);
}
datePeriodStart = new Date(
new Date(datePeriodStart.setDate(datePeriodStart.getDate() + 1)).setMonth(
datePeriodStart.getMonth() - 6,
),
);
// const latestProfileAssessment = item.current_holder.profileAssessments
// ? item.current_holder.profileAssessments.sort((a: any, b: any) => b.date - a.date)[0]
// : null;
// const pointSum = latestProfileAssessment
// ? `(${this.textPointSummaryKpi(latestProfileAssessment.pointSum)})${latestProfileAssessment.pointSum}`
// : null;
const pointSum = item.pointSum
? `(${this.textPointSummaryKpi(item.pointSum)})${item.pointSum}` //่join ธรรมดาดึง row ล่าสุดอยู่แล้ว
: null;
return {
profileId: item.id,
salaryLevel: item.salaryLevel,
group: item.group,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
citizenId: item.citizenId,
posMasterNoPrefix: item.posMasterNoPrefix,
posMasterNo: item.posMasterNo,
posMasterNoSuffix: item.posMasterNoSuffix,
orgShortName: orgShortName,
position: item.position,
posType: item.posTypeName,
posTypeShort: item.posTypeShortName,
posLevel: item.posLevelName,
amount: amount ? amount : null,
rootId: item.orgRootId,
root: item?.orgRootName ? item.orgRootName : null,
rootOrder: item?.orgRootOrder ? item.orgRootOrder : null,
child1Id: item.orgChild1Id,
child1: item?.orgChild1Name ? item.orgChild1Name : null,
child1Order: item?.orgChild1Order ? item.orgChild1Order : null,
child2Id: item.orgChild2Id,
child2: item?.orgChild2Name ? item.orgChild2Name : null,
child2Order: item?.orgChild2Order ? item.orgChild2Order : null,
child3Id: item.orgChild3Id,
child3: item?.orgChild3Name ? item.orgChild3Name : null,
child3Order: item?.orgChild3Order ? item.orgChild3Order : null,
child4Id: item.orgChild4Id,
child4: item?.orgChild4Name ? item.orgChild4Name : null,
child4Order: item?.orgChild4Order ? item.orgChild4Order : null,
result: pointSum,
duration: null,
isPunish:
new Date(
`${new Date(item.disCriplineDate).getFullYear()}-${String(new Date(item.disCriplineDate).getMonth() + 1).padStart(2, "0")}-${String(new Date(item.disCriplineDate).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) >= datePeriodStart &&
new Date(
`${new Date(item.disCriplineDate).getFullYear()}-${String(new Date(item.disCriplineDate).getMonth() + 1).padStart(2, "0")}-${String(new Date(item.disCriplineDate).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) <= datePeriodEnd
? true
: false,
isSuspension: item.dateRetire == null ? false : true,
isAbsent: item.profileDisciplineId ? true : false,
isLeave: item.profileLeaveId ? true : false,
isRetired:
item.birthDate == null ||
calculateRetireDate(item.birthDate).getFullYear() != body.year
? false
: true,
};
});
return new HttpSuccess({ data: formattedData, total: total });
}
/**
* API (unauthorize)
*

View file

@ -0,0 +1,215 @@
import { ViewColumn, ViewEntity } from "typeorm";
@ViewEntity({
expression: `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
`,
})
export class viewEmployeePosMaster {
@ViewColumn()
id: string;
@ViewColumn()
posMasterNoPrefix: string;
@ViewColumn()
posMasterNo: number;
@ViewColumn()
posMasterNoSuffix: string;
@ViewColumn()
orgRevisionId: string;
@ViewColumn()
orgRootId: string;
@ViewColumn()
orgChild1Id: string;
@ViewColumn()
orgChild2Id: string;
@ViewColumn()
orgChild3Id: string;
@ViewColumn()
orgChild4Id: string;
@ViewColumn()
current_holderId: string;
@ViewColumn()
profileId: string;
@ViewColumn()
prefix: string;
@ViewColumn()
firstName: string;
@ViewColumn()
lastName: string;
@ViewColumn()
citizenId: number;
@ViewColumn()
position: string;
@ViewColumn()
amount: number;
@ViewColumn()
dateRetire: Date;
@ViewColumn()
birthDate: Date;
@ViewColumn()
rootId: string;
@ViewColumn()
orgRootShortName: string;
@ViewColumn()
orgRootOrder: string;
@ViewColumn()
orgRootName: string;
@ViewColumn()
child1Id: string;
@ViewColumn()
orgChild1ShortName: string;
@ViewColumn()
orgChild1Order: string;
@ViewColumn()
orgChild1Name: string;
@ViewColumn()
child2Id: string;
@ViewColumn()
orgChild2ShortName: string;
@ViewColumn()
orgChild2Order: string;
@ViewColumn()
orgChild2Name: string;
@ViewColumn()
child3Id: string;
@ViewColumn()
orgChild3ShortName: string;
@ViewColumn()
orgChild3Order: string;
@ViewColumn()
orgChild3Name: string;
@ViewColumn()
child4Id: string;
@ViewColumn()
orgChild4ShortName: string;
@ViewColumn()
orgChild4Order: string;
@ViewColumn()
orgChild4Name: string;
@ViewColumn()
positionId: string;
@ViewColumn()
positionIsSelected: boolean;
@ViewColumn()
positionPosExecutiveId: string;
@ViewColumn()
isSpecial: boolean;
@ViewColumn()
posExecutiveId: string;
@ViewColumn()
posExecutiveName: string;
@ViewColumn()
profileDisciplineId: string;
@ViewColumn()
disCriplineDate: Date;
@ViewColumn()
profileLeaveId: string;
@ViewColumn()
profileAssessmentId: string;
@ViewColumn()
pointSum: number;
@ViewColumn()
posLevelId: string;
@ViewColumn()
posLevelName: string;
@ViewColumn()
posTypeId: string;
@ViewColumn()
posTypeName: string;
@ViewColumn()
salaryLevel: number;
@ViewColumn()
group: number;
@ViewColumn()
posTypeShortName: string;
}