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)
*