เงินเดือนลูกจ้าง
This commit is contained in:
parent
4f178cffa0
commit
29f95d3ae2
8 changed files with 1317 additions and 28 deletions
|
|
@ -25,6 +25,7 @@ import { Brackets, IsNull, Not } from "typeorm";
|
|||
import { OrgRoot } from "../entities/OrgRoot";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { calculateRetireDate } from "../interfaces/utils";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
|
||||
@Route("api/v1/org/unauthorize")
|
||||
@Tags("OrganizationUnauthorize")
|
||||
|
|
@ -247,6 +248,204 @@ export class OrganizationUnauthorizeController extends Controller {
|
|||
return new HttpSuccess({ data: formattedData, total: total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize)
|
||||
*
|
||||
* @summary ORG_072 - รายชื่อราชการที่เลื่อนเงินเดือน #76 (unauthorize)
|
||||
*
|
||||
*/
|
||||
@Post("salary/employee/gen")
|
||||
async salaryEmployeeGen(
|
||||
@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(EmployeePosMaster)
|
||||
.createQueryBuilder("employeePosMaster")
|
||||
.leftJoinAndSelect("employeePosMaster.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("employeePosMaster.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("employeePosMaster.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("employeePosMaster.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("employeePosMaster.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("employeePosMaster.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("employeePosMaster.positions", "positions")
|
||||
.leftJoinAndSelect("current_holder.profileSalary", "profileSalary")
|
||||
.leftJoinAndSelect("current_holder.profileDiscipline", "profileDiscipline")
|
||||
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("current_holder.posType", "posType")
|
||||
.where({
|
||||
orgRevisionId: findRevision?.id,
|
||||
current_holderId: Not(IsNull()),
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.prefix LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.firstName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.lastName LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.position LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${body.keyword}%`,
|
||||
},
|
||||
)
|
||||
|
||||
.orWhere(
|
||||
body.keyword != null && body.keyword != ""
|
||||
? "current_holder.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("current_holder.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.orgRoot?.orgRootShortName;
|
||||
} else if (item.orgChild2Id === null) {
|
||||
orgShortName = item.orgChild1?.orgChild1ShortName;
|
||||
} else if (item.orgChild3Id === null) {
|
||||
orgShortName = item.orgChild2?.orgChild2ShortName;
|
||||
} else if (item.orgChild4Id === null) {
|
||||
orgShortName = item.orgChild3?.orgChild3ShortName;
|
||||
} else {
|
||||
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;
|
||||
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,
|
||||
),
|
||||
);
|
||||
return {
|
||||
prefix: item.current_holder.prefix,
|
||||
firstName: item.current_holder.firstName,
|
||||
lastName: item.current_holder.lastName,
|
||||
citizenId: item.current_holder.citizenId,
|
||||
posMasterNoPrefix: item.posMasterNoPrefix,
|
||||
posMasterNo: item.posMasterNo,
|
||||
posMasterNoSuffix: item.posMasterNoSuffix,
|
||||
orgShortName: orgShortName,
|
||||
position: item.current_holder.position,
|
||||
posType: item.current_holder.posType.posTypeName,
|
||||
posLevel: item.current_holder.posLevel.posLevelName,
|
||||
amount: amount ? amount : null,
|
||||
rootId: item.orgRootId,
|
||||
root: item.orgRoot?.orgRootName ? item.orgRoot.orgRootName : null,
|
||||
child1Id: item.orgChild1Id,
|
||||
child1: item.orgChild1?.orgChild1Name ? item.orgChild1.orgChild1Name : null,
|
||||
child2Id: item.orgChild2Id,
|
||||
child2: item.orgChild2?.orgChild2Name ? item.orgChild2.orgChild2Name : null,
|
||||
child3Id: item.orgChild3Id,
|
||||
child3: item.orgChild3?.orgChild3Name ? item.orgChild3.orgChild3Name : null,
|
||||
child4Id: item.orgChild4Id,
|
||||
child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null,
|
||||
result: null,
|
||||
duration: null,
|
||||
isPunish:
|
||||
item.current_holder.profileDiscipline.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,
|
||||
isSuspension: item.current_holder.dateRetire == null ? false : true,
|
||||
isAbsent: false,
|
||||
isLeave: false,
|
||||
isRetired:
|
||||
item.current_holder.birthDate == null ||
|
||||
calculateRetireDate(item.current_holder.birthDate).getFullYear() != body.year
|
||||
? false
|
||||
: true,
|
||||
};
|
||||
});
|
||||
return new HttpSuccess({ data: formattedData, total: total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API หาสำนักทั้งหมด (unauthorize)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -271,10 +271,6 @@ export class ProfileEmployeeController extends Controller {
|
|||
return new HttpSuccess({ data: formattedData, total: formattedData.length });
|
||||
}
|
||||
|
||||
// if (!profile) {
|
||||
// return new HttpSuccess([]);
|
||||
// }
|
||||
|
||||
const formattedData = profile.map((item) => ({
|
||||
id: item.id,
|
||||
prefix: item.prefix,
|
||||
|
|
@ -1028,10 +1024,10 @@ 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;
|
||||
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`,
|
||||
);
|
||||
|
|
@ -1064,9 +1060,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
position: item.current_holder.position,
|
||||
posType: item.current_holder.posType.posTypeName,
|
||||
posLevel: item.current_holder.posLevel.posLevelName,
|
||||
amount: null,
|
||||
// amount: amount ? amount : null,
|
||||
// revisionId: item.orgRevisionId,
|
||||
amount: amount ? amount : null,
|
||||
rootId: item.orgRootId,
|
||||
root: item.orgRoot?.orgRootName ? item.orgRoot.orgRootName : null,
|
||||
child1Id: item.orgChild1Id,
|
||||
|
|
@ -1079,19 +1073,18 @@ export class ProfileEmployeeController extends Controller {
|
|||
child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null,
|
||||
result: null,
|
||||
duration: null,
|
||||
isPunish: false,
|
||||
// isPunish:
|
||||
// item.current_holder.profileDiscipline.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:
|
||||
item.current_holder.profileDiscipline.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,
|
||||
isSuspension: item.current_holder.dateRetire == null ? false : true,
|
||||
isAbsent: false,
|
||||
isLeave: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue