แก้ไขเงินเดือน

This commit is contained in:
Kittapath 2024-02-27 08:58:22 +07:00
parent f79704c7a7
commit bf12751bfa
10 changed files with 969 additions and 582 deletions

View file

@ -32,9 +32,7 @@ import { Not } from "typeorm";
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class PosLevelController extends Controller {
private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
@ -45,14 +43,12 @@ export class PosLevelController extends Controller {
*
*/
@Post()
@Example(
{
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf"
},
)
@Example({
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
})
async createLevel(
@Body()
requestBody: CreatePosLevel,
@ -62,19 +58,29 @@ export class PosLevelController extends Controller {
if (!posLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
id: requestBody.posTypeId }
})
if(!chkPosTypeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
const chkPosTypeId = await this.posTypeRepository.findOne({
where: {
id: requestBody.posTypeId,
},
});
if (!chkPosTypeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId,
);
}
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
posTypeId: requestBody.posTypeId, //ระดับประเภทเดียวกัน ชื่อระดับตำแหน่ง ห้ามซ้ำ
posLevelName: requestBody.posLevelName }
})
if(chkPosLevelName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
const chkPosLevelName = await this.posLevelRepository.findOne({
where: {
posTypeId: requestBody.posTypeId, //ระดับประเภทเดียวกัน ชื่อระดับตำแหน่ง ห้ามซ้ำ
posLevelName: requestBody.posLevelName,
},
});
if (chkPosLevelName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว",
);
}
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
@ -86,12 +92,12 @@ export class PosLevelController extends Controller {
}
// try {
posLevel.createdUserId = request.user.sub;
posLevel.createdFullName = request.user.name;
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel);
posLevel.createdUserId = request.user.sub;
posLevel.createdFullName = request.user.name;
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel);
// } catch (error) {
// return error;
// }
@ -105,12 +111,10 @@ export class PosLevelController extends Controller {
* @param {string} id Id
*/
@Put("{id}")
@Example(
{
positionName: "นักบริหาร",
posTypeRank: 1,
},
)
@Example({
positionName: "นักบริหาร",
posTypeRank: 1,
})
async editLevel(
@Path() id: string,
@Body() requestBody: UpdatePosLevel,
@ -121,20 +125,30 @@ export class PosLevelController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
id: requestBody.posTypeId }
})
if(!chkPosTypeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
const chkPosTypeId = await this.posTypeRepository.findOne({
where: {
id: requestBody.posTypeId,
},
});
if (!chkPosTypeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId,
);
}
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
id: Not(id),
posTypeId: requestBody.posTypeId,
posLevelName: requestBody.posLevelName }
})
if(chkPosLevelName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
const chkPosLevelName = await this.posLevelRepository.findOne({
where: {
id: Not(id),
posTypeId: requestBody.posTypeId,
posLevelName: requestBody.posLevelName,
},
});
if (chkPosLevelName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว",
);
}
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
if (
@ -145,11 +159,11 @@ export class PosLevelController extends Controller {
}
// try {
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
this.posLevelRepository.merge(posLevel, requestBody);
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel.id);
posLevel.lastUpdateUserId = request.user.sub;
posLevel.lastUpdateFullName = request.user.name;
this.posLevelRepository.merge(posLevel, requestBody);
await this.posLevelRepository.save(posLevel);
return new HttpSuccess(posLevel.id);
// } catch (error) {
// return error;
// }
@ -169,8 +183,8 @@ export class PosLevelController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
// try {
await this.posLevelRepository.remove(delPosLevel);
return new HttpSuccess();
await this.posLevelRepository.remove(delPosLevel);
return new HttpSuccess();
// } catch (error) {
// return error;
// }
@ -184,43 +198,41 @@ export class PosLevelController extends Controller {
* @param {string} id Id
*/
@Get("{id}")
@Example(
{
@Example({
id: "00000000-0000-0000-0000-000000000000",
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypes: {
id: "00000000-0000-0000-0000-000000000000",
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD",
posTypes: {
id: "00000000-0000-0000-0000-000000000000",
posTypeName: "นักบริหาร",
posTypeRank: 1,
},
posTypeName: "นักบริหาร",
posTypeRank: 1,
},
)
})
async GetLevelDetail(@Path() id: string) {
// try {
const getPosType = await this.posLevelRepository.findOne({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"],
relations: ["posType"],
where: { id: id }
});
if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const getPosType = await this.posLevelRepository.findOne({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"],
relations: ["posType"],
where: { id: id },
});
if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const mapPosLevel = {
id: getPosType.id,
posLevelName: getPosType.posLevelName,
posLevelRank: getPosType.posLevelRank,
posLevelAuthority: getPosType.posLevelAuthority,
posTypes:{
id: getPosType.posType.id,
posTypeName: getPosType.posType.posTypeName,
posTypeRank: getPosType.posType.posTypeRank
}
}
const mapPosLevel = {
id: getPosType.id,
posLevelName: getPosType.posLevelName,
posLevelRank: getPosType.posLevelRank,
posLevelAuthority: getPosType.posLevelAuthority,
posTypes: {
id: getPosType.posType.id,
posTypeName: getPosType.posType.posTypeName,
posTypeRank: getPosType.posType.posTypeRank,
},
};
return new HttpSuccess(mapPosLevel);
return new HttpSuccess(mapPosLevel);
// } catch (error) {
// return error;
// }
@ -248,25 +260,23 @@ export class PosLevelController extends Controller {
])
async GetPosLevel() {
// try {
const posLevel = await this.posLevelRepository.find({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"],
relations: ["posType"],
});
if (!posLevel) {
return new HttpSuccess([]);
}
const mapPosLevel = posLevel.map((item) => ({
id: item.id,
posLevelName: item.posLevelName,
posLevelRank: item.posLevelRank,
posLevelAuthority: item.posLevelAuthority,
posTypes: {
id: item.posType.id,
posTypeName: item.posType.posTypeName,
posTypeRank: item.posType.posTypeRank,
}
}));
return new HttpSuccess(mapPosLevel);
const posLevel = await this.posLevelRepository.find({
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"],
relations: ["posType"],
});
const mapPosLevel = posLevel.map((item) => ({
id: item.id,
posLevelName: item.posLevelName,
posLevelRank: item.posLevelRank,
posLevelAuthority: item.posLevelAuthority,
posTypes: {
id: item.posType.id,
posTypeName: item.posType.posTypeName,
posTypeRank: item.posType.posTypeRank,
},
}));
return new HttpSuccess(mapPosLevel);
// } catch (error) {
// return error;
// }

View file

@ -32,9 +32,7 @@ import { Not } from "typeorm";
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class PosTypeController extends Controller {
private posTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
@ -45,34 +43,37 @@ export class PosTypeController extends Controller {
*
*/
@Post()
@Example(
{
positionName: "นักบริหาร",
posTypeRank: 1,
},
)
@Example({
positionName: "นักบริหาร",
posTypeRank: 1,
})
async createType(
@Body()
requestBody: CreatePosType,
@Request() request: { user: Record<string, any> },
@Request() request: { user: Record<string, any> },
) {
const posType = Object.assign(new PosType(), requestBody);
if (!posType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chkPosTypeName = await this.posTypeRepository.findOne({ where: {
posTypeName: requestBody.posTypeName }
})
if(chkPosTypeName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว");
const chkPosTypeName = await this.posTypeRepository.findOne({
where: {
posTypeName: requestBody.posTypeName,
},
});
if (chkPosTypeName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว",
);
}
// try {
posType.createdUserId = request.user.sub;
posType.createdFullName = request.user.name;
posType.lastUpdateUserId = request.user.sub;
posType.lastUpdateFullName = request.user.name;
await this.posTypeRepository.save(posType);
return new HttpSuccess(posType);
posType.createdUserId = request.user.sub;
posType.createdFullName = request.user.name;
posType.lastUpdateUserId = request.user.sub;
posType.lastUpdateFullName = request.user.name;
await this.posTypeRepository.save(posType);
return new HttpSuccess(posType);
// } catch (error) {
// return error;
// }
@ -86,12 +87,10 @@ export class PosTypeController extends Controller {
* @param {string} id Id
*/
@Put("{id}")
@Example(
{
positionName: "นักบริหาร",
posTypeRank: 1,
},
)
@Example({
positionName: "นักบริหาร",
posTypeRank: 1,
})
async editType(
@Path() id: string,
@Body() requestBody: UpdatePosType,
@ -101,19 +100,24 @@ export class PosTypeController extends Controller {
if (!posType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const chkPosTypeName = await this.posTypeRepository.findOne({ where: {
id: Not(id),
posTypeName: requestBody.posTypeName }
})
if(chkPosTypeName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว");
const chkPosTypeName = await this.posTypeRepository.findOne({
where: {
id: Not(id),
posTypeName: requestBody.posTypeName,
},
});
if (chkPosTypeName) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ชื่อประเภทตำแหน่ง: " + requestBody.posTypeName + " มีอยู่ในระบบแล้ว",
);
}
// try {
posType.lastUpdateUserId = request.user.sub;
posType.lastUpdateFullName = request.user.name;
this.posTypeRepository.merge(posType, requestBody);
await this.posTypeRepository.save(posType);
return new HttpSuccess(posType.id);
posType.lastUpdateUserId = request.user.sub;
posType.lastUpdateFullName = request.user.name;
this.posTypeRepository.merge(posType, requestBody);
await this.posTypeRepository.save(posType);
return new HttpSuccess(posType.id);
// } catch (error) {
// return error;
// }
@ -133,15 +137,15 @@ export class PosTypeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const IdExitsInLevel = await this.posLevelRepository.find({
where: { posTypeId: id }
})
if(IdExitsInLevel.length > 0){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับ posLevel",);
where: { posTypeId: id },
});
if (IdExitsInLevel.length > 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับ posLevel");
}
// try {
await this.posTypeRepository.remove(delPosType);
return new HttpSuccess();
await this.posTypeRepository.remove(delPosType);
return new HttpSuccess();
// } catch (error) {
// return error;
// }
@ -165,35 +169,35 @@ export class PosTypeController extends Controller {
id: "00000000-0000-0000-0000-000000000000",
posLevelName: "นักบริหาร",
posLevelRank: 1,
posLevelAuthority: "HEAD"
}
]
posLevelAuthority: "HEAD",
},
],
},
])
async GetTypeDetail(@Path() id: string) {
// try {
const getPosType = await this.posTypeRepository.findOne({
select: ["id", "posTypeName", "posTypeRank"],
relations: ["posLevels"],
where: { id: id }
});
if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const getPosType = await this.posTypeRepository.findOne({
select: ["id", "posTypeName", "posTypeRank"],
relations: ["posLevels"],
where: { id: id },
});
if (!getPosType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const mapGetPosType = {
id : getPosType.id,
posTypeName : getPosType.posTypeName,
posTypeRank : getPosType.posTypeRank,
posLevels : getPosType.posLevels.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
}
return new HttpSuccess(mapGetPosType);
const mapGetPosType = {
id: getPosType.id,
posTypeName: getPosType.posTypeName,
posTypeRank: getPosType.posTypeRank,
posLevels: getPosType.posLevels.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
};
return new HttpSuccess(mapGetPosType);
// } catch (error) {
// return error;
// }
@ -223,25 +227,23 @@ export class PosTypeController extends Controller {
])
async GetPosType() {
// try {
const posType = await this.posTypeRepository.find({
select: ["id", "posTypeName", "posTypeRank"],
relations: ["posLevels"],
});
if (!posType) {
return new HttpSuccess([]);
}
const mapPosType = posType.map((item) => ({
id: item.id,
posTypeName: item.posTypeName,
posTypeRank: item.posTypeRank,
posLevels: item.posLevels.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
}));
return new HttpSuccess(mapPosType);
const posType = await this.posTypeRepository.find({
select: ["id", "posTypeName", "posTypeRank"],
relations: ["posLevels"],
});
const mapPosType = posType.map((item) => ({
id: item.id,
posTypeName: item.posTypeName,
posTypeRank: item.posTypeRank,
posLevels: item.posLevels.map((posLevel) => ({
id: posLevel.id,
posLevelName: posLevel.posLevelName,
posLevelRank: posLevel.posLevelRank,
posLevelAuthority: posLevel.posLevelAuthority,
})),
}));
return new HttpSuccess(mapPosType);
// } catch (error) {
// return error;
// }

View file

@ -57,48 +57,48 @@ export class Salary extends Controller {
@Request() request: { user: Record<string, any> },
) {
// try {
const salarys = Object.assign(new Salarys(), requestBody);
if (!salarys) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const salarys = Object.assign(new Salarys(), requestBody);
if (!salarys) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chk_salaryType = ["OFFICER", "EMPLOYEE"];
if (!chk_salaryType.includes(salarys.salaryType.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง");
}
const chk_salaryType = ["OFFICER", "EMPLOYEE"];
if (!chk_salaryType.includes(salarys.salaryType.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง");
}
const chk_posTypeId = await this.poTypeRepository.findOne({
where: { id: salarys.posTypeId },
});
if (!chk_posTypeId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทของตำแหน่ง ไม่ถูกต้อง");
}
const chk_posTypeId = await this.poTypeRepository.findOne({
where: { id: salarys.posTypeId },
});
if (!chk_posTypeId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทของตำแหน่ง ไม่ถูกต้อง");
}
const chk_posLevelId = await this.posLevelRepository.findOne({
where: { id: salarys.posLevelId },
});
if (!chk_posLevelId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับของตำแหน่ง ไม่ถูกต้อง");
}
const chk_posLevelId = await this.posLevelRepository.findOne({
where: { id: salarys.posLevelId },
});
if (!chk_posLevelId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับของตำแหน่ง ไม่ถูกต้อง");
}
const chk_3fields = await this.salaryRepository.findOne({
where: {
salaryType: salarys.salaryType,
posTypeId: salarys.posTypeId,
posLevelId: salarys.posLevelId,
},
});
if (chk_3fields && salarys.isActive) {
salarys.isActive = false;
}
salarys.salaryType = salarys.salaryType.toUpperCase();
salarys.isSpecial = salarys.isSpecial;
salarys.createdUserId = request.user.sub;
salarys.createdFullName = request.user.name;
salarys.lastUpdateUserId = request.user.sub;
salarys.lastUpdateFullName = request.user.name;
await this.salaryRepository.save(salarys);
return new HttpSuccess(salarys.id);
const chk_3fields = await this.salaryRepository.findOne({
where: {
salaryType: salarys.salaryType,
posTypeId: salarys.posTypeId,
posLevelId: salarys.posLevelId,
},
});
if (chk_3fields && salarys.isActive) {
salarys.isActive = false;
}
salarys.salaryType = salarys.salaryType.toUpperCase();
salarys.isSpecial = salarys.isSpecial;
salarys.createdUserId = request.user.sub;
salarys.createdFullName = request.user.name;
salarys.lastUpdateUserId = request.user.sub;
salarys.lastUpdateFullName = request.user.name;
await this.salaryRepository.save(salarys);
return new HttpSuccess(salarys.id);
// } catch (error: any) {
// throw new Error(error);
// }
@ -128,64 +128,64 @@ export class Salary extends Controller {
@Request() request: { user: Record<string, any> },
) {
// try {
const chk_Salary = await this.salaryRepository.findOne({
where: { id: id },
});
if (!chk_Salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
}
const chk_Salary = await this.salaryRepository.findOne({
where: { id: id },
});
if (!chk_Salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
}
if (chk_Salary.isActive && !requestBody.isActive) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถแก้ไขสถานะการใช้งานที่เป็น Default ได้",
);
}
if (chk_Salary.isActive && !requestBody.isActive) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถแก้ไขสถานะการใช้งานที่เป็น Default ได้",
);
}
const chk_3fields = await this.salaryRepository.findOne({
where: {
salaryType: requestBody.salaryType,
posTypeId: requestBody.posTypeId,
posLevelId: requestBody.posLevelId,
isActive: true,
id: Not(id),
},
});
const chk_3fields = await this.salaryRepository.findOne({
where: {
salaryType: requestBody.salaryType,
posTypeId: requestBody.posTypeId,
posLevelId: requestBody.posLevelId,
isActive: true,
id: Not(id),
},
});
if (chk_3fields != null && requestBody.isActive) {
chk_3fields.isActive = false;
chk_3fields.lastUpdateUserId = request.user.sub;
chk_3fields.lastUpdateFullName = request.user.name;
chk_3fields.lastUpdatedAt = new Date();
await this.salaryRepository.save(chk_3fields);
}
if (chk_3fields != null && requestBody.isActive) {
chk_3fields.isActive = false;
chk_3fields.lastUpdateUserId = request.user.sub;
chk_3fields.lastUpdateFullName = request.user.name;
chk_3fields.lastUpdatedAt = new Date();
await this.salaryRepository.save(chk_3fields);
}
const chk_salaryType = ["OFFICER", "EMPLOYEE"];
if (!chk_salaryType.includes(String(requestBody.salaryType).toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง");
}
const chk_salaryType = ["OFFICER", "EMPLOYEE"];
if (!chk_salaryType.includes(String(requestBody.salaryType).toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผัง ไม่ถูกต้อง");
}
const chk_posTypeId = await this.poTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!chk_posTypeId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทของตำแหน่ง ไม่ถูกต้อง");
}
const chk_posTypeId = await this.poTypeRepository.findOne({
where: { id: requestBody.posTypeId },
});
if (!chk_posTypeId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทของตำแหน่ง ไม่ถูกต้อง");
}
const chk_posLevelId = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
if (!chk_posLevelId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับของตำแหน่ง ไม่ถูกต้อง");
}
const mergeData = Object.assign(new Salarys(), requestBody);
chk_Salary.lastUpdateUserId = request.user.sub;
chk_Salary.lastUpdateFullName = request.user.name;
chk_Salary.lastUpdatedAt = new Date();
this.salaryRepository.merge(chk_Salary, mergeData);
await this.salaryRepository.save(chk_Salary);
return new HttpSuccess(id);
const chk_posLevelId = await this.posLevelRepository.findOne({
where: { id: requestBody.posLevelId },
});
if (!chk_posLevelId) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับของตำแหน่ง ไม่ถูกต้อง");
}
const mergeData = Object.assign(new Salarys(), requestBody);
chk_Salary.lastUpdateUserId = request.user.sub;
chk_Salary.lastUpdateFullName = request.user.name;
chk_Salary.lastUpdatedAt = new Date();
this.salaryRepository.merge(chk_Salary, mergeData);
await this.salaryRepository.save(chk_Salary);
return new HttpSuccess(id);
// } catch (error: any) {
// throw new Error(error);
// }
@ -201,25 +201,25 @@ export class Salary extends Controller {
@Delete("{id}")
async delete_salary(@Path() id: string) {
// try {
const chk_Salary = await this.salaryRepository.findOne({
where: { id: id },
});
if (!chk_Salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
}
if (chk_Salary.isActive) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
// "ไม่สามารถลบไอดี: " + id + " ได้ เนื่องสถานะการใช้งานที่เป็น Default",
"ไม่สามารถลบข้อมูลนี้ได้ เนื่องจากเปิดใช้งานอยู่",
);
}
const del_SalaryRank = await this.salaryRankRepository.find({
where: { salaryId: chk_Salary.id }
});
await this.salaryRankRepository.remove(del_SalaryRank);
await this.salaryRepository.remove(chk_Salary);
return new HttpSuccess();
const chk_Salary = await this.salaryRepository.findOne({
where: { id: id },
});
if (!chk_Salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
}
if (chk_Salary.isActive) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
// "ไม่สามารถลบไอดี: " + id + " ได้ เนื่องสถานะการใช้งานที่เป็น Default",
"ไม่สามารถลบข้อมูลนี้ได้ เนื่องจากเปิดใช้งานอยู่",
);
}
const del_SalaryRank = await this.salaryRankRepository.find({
where: { salaryId: chk_Salary.id },
});
await this.salaryRankRepository.remove(del_SalaryRank);
await this.salaryRepository.remove(chk_Salary);
return new HttpSuccess();
// } catch (error: any) {
// throw new Error(error);
// }
@ -245,24 +245,24 @@ export class Salary extends Controller {
})
async GetSalaryById(@Path() id: string) {
// try {
const salary = await this.salaryRepository.findOne({
where: { id: id },
select: [
"salaryType",
"isSpecial",
"posTypeId",
"posLevelId",
"isActive",
"date",
"startDate",
"endDate",
"details",
],
});
if (!salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
}
return new HttpSuccess(salary);
const salary = await this.salaryRepository.findOne({
where: { id: id },
select: [
"salaryType",
"isSpecial",
"posTypeId",
"posLevelId",
"isActive",
"date",
"startDate",
"endDate",
"details",
],
});
if (!salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
}
return new HttpSuccess(salary);
// } catch (error: any) {
// throw new Error(error);
// }
@ -280,52 +280,31 @@ export class Salary extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
//ssss total ผิด
// try {
const [salary, total] = await this.salaryRepository.findAndCount({
relations: ["posLevel_", "posType_"],
order: {
startDate: "DESC",
},
skip: (page - 1) * pageSize,
take: pageSize,
});
if (keyword != undefined && keyword !== "") {
const filteredSalary = salary.filter(
(x) =>
x.salaryType?.toString().includes(keyword) ||
x.isSpecial?.toString().includes(keyword) || //new 20.02.67
x.posLevel_?.posLevelName?.toString().includes(keyword) ||
x.posType_?.posTypeName?.toString().includes(keyword) ||
x.isActive?.toString().includes(keyword) ||
x.date?.toString().includes(keyword) ||
x.startDate?.toString().includes(keyword) ||
x.endDate?.toString().includes(keyword) ||
x.details?.toString().includes(keyword),
);
const [salary, total] = await this.salaryRepository.findAndCount({
relations: ["posLevel_", "posType_"],
order: {
startDate: "DESC",
},
skip: (page - 1) * pageSize,
take: pageSize,
});
if (keyword != undefined && keyword !== "") {
const filteredSalary = salary.filter(
(x) =>
x.salaryType?.toString().includes(keyword) ||
x.isSpecial?.toString().includes(keyword) || //new 20.02.67
x.posLevel_?.posLevelName?.toString().includes(keyword) ||
x.posType_?.posTypeName?.toString().includes(keyword) ||
x.isActive?.toString().includes(keyword) ||
x.date?.toString().includes(keyword) ||
x.startDate?.toString().includes(keyword) ||
x.endDate?.toString().includes(keyword) ||
x.details?.toString().includes(keyword),
);
const formattedData = filteredSalary.map((item) => ({
id: item.id,
salaryType: item.salaryType,
isSpecial: item.isSpecial,
posTypeId: item.posType_?.id,
posType: item.posType_?.posTypeName,
posLevelId: item.posLevel_?.id,
posLevel: item.posLevel_?.posLevelName,
isActive: item.isActive,
date: item.date,
startDate: item.startDate,
endDate: item.endDate,
details: item.details,
}));
return new HttpSuccess({ data: formattedData, total: formattedData.length });
}
if (!salary) {
return new HttpSuccess([]);
}
const formattedData = salary.map((item) => ({
const formattedData = filteredSalary.map((item) => ({
id: item.id,
salaryType: item.salaryType,
isSpecial: item.isSpecial,
@ -339,7 +318,25 @@ export class Salary extends Controller {
endDate: item.endDate,
details: item.details,
}));
return new HttpSuccess({ data: formattedData, total });
return new HttpSuccess({ data: formattedData, total: formattedData.length });
}
const formattedData = salary.map((item) => ({
id: item.id,
salaryType: item.salaryType,
isSpecial: item.isSpecial,
posTypeId: item.posType_?.id,
posType: item.posType_?.posTypeName,
posLevelId: item.posLevel_?.id,
posLevel: item.posLevel_?.posLevelName,
isActive: item.isActive,
date: item.date,
startDate: item.startDate,
endDate: item.endDate,
details: item.details,
}));
return new HttpSuccess({ data: formattedData, total });
// } catch (error: any) {
// throw new Error(error);
// }
@ -357,34 +354,31 @@ export class Salary extends Controller {
@Request() request: { user: Record<string, any> },
) {
// try {
const salary = await this.salaryRepository.findOne({
relations: ["posLevel_", "posType_", "salaryRanks_"],
where: { id: body.id },
});
const salary = await this.salaryRepository.findOne({
relations: ["posLevel_", "posType_", "salaryRanks_"],
where: { id: body.id },
});
if (!salary) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลเงินเดือนจากไอดีนี้ : " + body.id,
);
}
if (!salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเงินเดือนจากไอดีนี้ : " + body.id);
}
const salaryRank = await this.salaryRankRepository.find({
where: { salaryId: salary?.id },
});
const salaryRank = await this.salaryRankRepository.find({
where: { salaryId: salary?.id },
});
const newSalary = { ...salary, id: randomUUID(), isActive: false };
const newSalary = { ...salary, id: randomUUID(), isActive: false };
await this.salaryRepository.save(newSalary);
await this.salaryRepository.save(newSalary);
await Promise.all(
salaryRank.map(async (v) => {
const newSalaryRank = { ...v, id: randomUUID() };
await this.salaryRankRepository.save(newSalaryRank);
}),
);
await Promise.all(
salaryRank.map(async (v) => {
const newSalaryRank = { ...v, id: randomUUID() };
await this.salaryRankRepository.save(newSalaryRank);
}),
);
return new HttpSuccess({ id: newSalary.id });
return new HttpSuccess({ id: newSalary.id });
// } catch (error: any) {
// throw new Error(error);
// }

View file

@ -15,18 +15,22 @@ import {
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import { DeepPartial, In, IsNull, Not, Between } from "typeorm";
import { DeepPartial, In, IsNull, Not, Between, MoreThan } from "typeorm";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
import { CreateSalaryPeriod, SalaryPeriod, UpdateSalaryPeriod } from "../entities/SalaryPeriod";
import Extension from "../interfaces/extension";
import Extension from "../interfaces/extension";
import { SalaryOrg } from "../entities/SalaryOrg";
import { CreateSalaryProfile, SalaryProfile } from "../entities/SalaryProfile";
@Route("api/v1/salary")
@Route("api/v1/salary/period")
@Tags("Salary")
@Security("bearerAuth")
export class SalaryPeriodController extends Controller {
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
/**
* API
@ -34,11 +38,12 @@ export class SalaryPeriodController extends Controller {
* @summary SLR_016 - #16
*
*/
@Post("period")
@Post()
async create_salary_period(
@Body() requestBody: CreateSalaryPeriod,
@Request() request: { user: Record<string, any> },
) {
//ssss ไม่ต้องเช็ค?
const salaryPeriod = Object.assign(new SalaryPeriod(), requestBody);
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -52,14 +57,17 @@ export class SalaryPeriodController extends Controller {
const startOfYear = new Date(salaryPeriod.effectiveDate.getFullYear(), 0, 1);
const endOfYear = new Date(salaryPeriod.effectiveDate.getFullYear(), 11, 31);
const chk_period = await this.salaryPeriodRepository.findOne({
where: {
where: {
period: salaryPeriod.period,
effectiveDate: Between(startOfYear, endOfYear)
effectiveDate: Between(startOfYear, endOfYear),
},
});
if (chk_period) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผังปี "+ salaryPeriod.effectiveDate.getFullYear() +" ซ้ำ");
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ประเภทผังปี " + salaryPeriod.effectiveDate.getFullYear() + " ซ้ำ",
);
}
salaryPeriod.period = salaryPeriod.period.toUpperCase();
@ -70,7 +78,7 @@ export class SalaryPeriodController extends Controller {
await this.salaryPeriodRepository.save(salaryPeriod);
return new HttpSuccess(salaryPeriod.id);
}
/**
* API
*
@ -78,7 +86,7 @@ export class SalaryPeriodController extends Controller {
*
* @param {string} id Guid, *Id
*/
@Put("period/{id}")
@Put("{id}")
async update_salary_period(
@Path() id: string,
@Body() requestBody: UpdateSalaryPeriod,
@ -99,15 +107,18 @@ export class SalaryPeriodController extends Controller {
const startOfYear = new Date(requestBody.effectiveDate.getFullYear(), 0, 1);
const endOfYear = new Date(requestBody.effectiveDate.getFullYear(), 11, 31);
const chk_period = await this.salaryPeriodRepository.findOne({
where: {
where: {
period: requestBody.period,
id: Not(id),
effectiveDate: Between(startOfYear, endOfYear)
effectiveDate: Between(startOfYear, endOfYear),
},
});
if (chk_period) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทผังปี "+ (requestBody.effectiveDate.getFullYear()+543) +" ซ้ำ");
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ประเภทผังปี " + (requestBody.effectiveDate.getFullYear() + 543) + " ซ้ำ",
);
}
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
@ -117,7 +128,6 @@ export class SalaryPeriodController extends Controller {
this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody);
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
return new HttpSuccess(id);
}
/**
@ -127,7 +137,7 @@ export class SalaryPeriodController extends Controller {
*
* @param {string} id Guid, *Id
*/
@Delete("period/{id}")
@Delete("{id}")
async delete_salary_period(@Path() id: string) {
const SalaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id },
@ -146,18 +156,11 @@ export class SalaryPeriodController extends Controller {
*
* @param {string} id Guid, *Id
*/
@Get("period/{id}")
@Get("{id}")
async GetSalaryPeriod_ById(@Path() id: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id },
select: [
"id",
"period",
"isActive",
"effectiveDate",
"isActive",
"status",
],
select: ["id", "period", "isActive", "effectiveDate", "isActive", "status"],
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
@ -171,27 +174,27 @@ export class SalaryPeriodController extends Controller {
* @summary SLR_020 - #20
*
*/
@Get("period")
@Get()
async GetListsSalaryPeriod(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
@Query("year") year: number = 2024,
) {
let salaryPeriod: any
let total: any
if(year != 0){
//ssss total ผิด
let salaryPeriod: any;
let total: any;
if (year != 0) {
const startOfYear = new Date(year, 0, 1);
const endOfYear = new Date(year, 11, 31);
[salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
skip: (page - 1) * pageSize,
take: pageSize,
where: {
effectiveDate: Between(startOfYear, endOfYear)
}
effectiveDate: Between(startOfYear, endOfYear),
},
});
}else{
} else {
[salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
skip: (page - 1) * pageSize,
take: pageSize,
@ -200,13 +203,13 @@ export class SalaryPeriodController extends Controller {
if (keyword != undefined && keyword !== "") {
const filteredSalaryPeriod = salaryPeriod.filter(
(x:any) =>
(x: any) =>
x.period.toString().includes(keyword) ||
x.isActive.toString().includes(keyword) ||
x.effectiveDate.getFullYear().toString().includes(keyword)
x.effectiveDate.getFullYear().toString().includes(keyword),
);
const formattedData = filteredSalaryPeriod.map((item:any) => ({
const formattedData = filteredSalaryPeriod.map((item: any) => ({
id: item.id,
period: item.period,
isActive: item.isActive,
@ -216,19 +219,320 @@ export class SalaryPeriodController extends Controller {
return new HttpSuccess({ data: formattedData, total: formattedData.length });
}
if (!salaryPeriod) {
return new HttpSuccess([]);
}
const formattedData = salaryPeriod.map((item:any) => ({
id: item.id,
period: item.period,
isActive: item.isActive,
effectiveDate: item.effectiveDate,
status: item.status,
const formattedData = salaryPeriod.map((item: any) => ({
id: item.id,
period: item.period,
isActive: item.isActive,
effectiveDate: item.effectiveDate,
status: item.status,
}));
return new HttpSuccess({ data: formattedData, total });
}
/**
* API
*
* @summary SLR_030 - #29
*
*/
@Get("latest")
async GetGroupSalaryPeriodLatest() {
//xxxx รอบเงินเดือนล่าสุดยังไม่แน่ใจเอาจากรอบไหน
//xxxx หาสังกัดคนนั้น
// const dateNow = new Date();
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
// effectiveDate: MoreThan(dateNow),
isActive: true,
},
order: { effectiveDate: "DESC" },
relations: ["salaryOrgs"],
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const data = {
group1id: salaryPeriod.salaryOrgs.find((x) => x.group == "GROUP1")?.id,
group2id: salaryPeriod.salaryOrgs.find((x) => x.group == "GROUP2")?.id,
effectiveDate: salaryPeriod.effectiveDate,
period: salaryPeriod.period,
};
return new HttpSuccess(data);
}
/**
* API
*
* @summary SLR_029 - #28
*
* @param {string} id Guid, *Id (salaryOrgId/groupId)
*/
@Get("quota/{id}")
async GetSalaryquotaLatest(@Path() id: string) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: id,
},
select: ["total", "fifteenPercent"],
relations: ["salaryProfiles"],
});
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const data = {
total: salaryOrg.total,
fifteenPercent: salaryOrg.fifteenPercent,
chosen: salaryOrg.salaryProfiles.filter((x) => x.posType == "FULL").length,
remaining:
salaryOrg.fifteenPercent -
salaryOrg.salaryProfiles.filter((x) => x.posType == "FULL").length,
};
return new HttpSuccess(data);
}
/**
* API
*
* @summary SLR_024 - #23
*
* @param {string} id profile Id
*/
@Delete("profile/{id}")
async deleteSalaryProfile(@Path() id: string) {
const salaryProfile = await this.salaryProfileRepository.findOne({
where: { id: id },
});
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
await this.salaryProfileRepository.remove(salaryProfile);
return new HttpSuccess();
}
/**
* API
*
* @summary SLR_025 - #24
*
* @param {string} id profile Id
* @param {string} amount
*/
@Post("change/amount")
async changeAmount(@Body() body: { profileId: string; amount: number }) {
const salaryProfile = await this.salaryProfileRepository.findOne({
where: { id: body.profileId },
});
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
salaryProfile.amount = body.amount;
// salaryProfile.amountSpecial = xxxx;
// salaryProfile.amountUse = xxxx;
// salaryProfile.positionSalaryAmount = xxxx;
//xxxxxx คำนวนเงินเดือนใหม่
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess();
}
/**
* API
*
* @summary SLR_026 - #25
*
* @param {string} id profile Id
* @param {string} groupId groupId
*/
@Post("change/group")
async changeGroup(@Body() body: { profileId: string; groupId: string }) {
const salaryProfile = await this.salaryProfileRepository.findOne({
where: { id: body.profileId },
});
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
const salaryOrg = await this.salaryOrgRepository.findOne({
where: { id: body.groupId },
});
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
}
salaryProfile.salaryOrgId = salaryOrg.id;
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess();
}
/**
* API
*
* @summary SLR_025 - #24
*
* @param {string} id profile Id
* @param {string} type NONE-> HAFT-> FULL->1 FULLHAFT->1.5
*/
@Post("change/type")
async changeType(@Body() body: { profileId: string; type: string }) {
const salaryProfile = await this.salaryProfileRepository.findOne({
where: { id: body.profileId },
});
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
body.type = body.type.toUpperCase();
//xxxxxx คำนวนเงินเดือนใหม่
if (body.type == "NONE") {
//xxxx เงินไม่เปลืี่ยน
} else if (body.type == "HAFT") {
//xxxx เลื่อน0.5ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
} else if (body.type == "FULL") {
//xxxx เลื่อน1ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
} else if (body.type == "FULLHAFT") {
//xxxx เลื่อน1.0ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}
salaryProfile.type = body.type;
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess();
}
/**
* API
*
* @summary SLR_023 - #22
*
*/
@Put("org/{id}")
async GetListsSalaryProfile(
@Path() id: string,
@Body() body: { page: number; pageSize: number; keyword?: string; type: string },
) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: id,
},
});
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const [salaryProfile, total] = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("profile")
.andWhere({
salaryOrgId: salaryOrg.id,
})
.andWhere(body.type != null && body.type != "" ? "profile.type LIKE :type" : "1=1", {
type: `%${body.type}%`,
})
//xxxx รอ fe ว่าแสดงค่าไหนบ่างใหเfilterเฉพาะค่านั้น
.orWhere("profile.posMasterNoPrefix LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.posMasterNo LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.posMasterNoSuffix LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.orgShortName LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.prefix LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.firstName LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.lastName LIKE :keyword", { keyword: `%${body.keyword}%` })
// .orWhere("profile.citizenId LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.position LIKE :keyword", { keyword: `%${body.keyword}%` })
// .orWhere("profile.posType LIKE :keyword", { keyword: `%${body.keyword}%` })
// .orWhere("profile.posLevel LIKE :keyword", { keyword: `%${body.keyword}%` })
// .orWhere("profile.posExecutive LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.amount LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.amountSpecial LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.amountUse LIKE :keyword", { keyword: `%${body.keyword}%` })
.orWhere("profile.positionSalaryAmount LIKE :keyword", { keyword: `%${body.keyword}%` })
.orderBy("profile.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
return new HttpSuccess({ data: salaryProfile, total });
}
/**
* API
*
* @summary SLR_028 - #27
*
*/
@Post("org/profile")
async addSalaryProfile(
@Body() requestBody: CreateSalaryProfile,
@Request() request: { user: Record<string, any> },
) {
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
id: requestBody.id,
},
});
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const salaryOrgAll = await this.salaryOrgRepository.find({
where: {
salaryPeriodId: salaryOrg.salaryPeriodId,
},
});
if (!salaryOrgAll) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const salaryProfileAll = await this.salaryProfileRepository.findOne({
where: {
salaryOrgId: In(salaryOrgAll.map((x) => x.id)),
citizenId: requestBody.citizenId,
// prefix: requestBody.prefix,
// firstName: requestBody.firstName,
// lastName: requestBody.lastName,
},
});
if (salaryProfileAll != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถเพิ่มรายชื่อนี้ได้ เนื่องจากมีการยื่นของเลื่อนเงินเดือนแล้ว",
);
}
const salaryProfile = Object.assign(new SalaryProfile(), requestBody);
salaryProfile.type = salaryProfile.type.toUpperCase();
//xxxxxx คำนวนเงินเดือนใหม่
if (salaryProfile.type == "NONE") {
//xxxx เงินไม่เปลืี่ยน
} else if (salaryProfile.type == "HAFT") {
//xxxx เลื่อน0.5ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
} else if (salaryProfile.type == "FULL") {
//xxxx เลื่อน1ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
} else if (salaryProfile.type == "FULLHAFT") {
//xxxx เลื่อน1.0ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}
salaryProfile.salaryOrgId = salaryOrg.id;
salaryProfile.createdUserId = request.user.sub;
salaryProfile.createdFullName = request.user.name;
salaryProfile.lastUpdateUserId = request.user.sub;
salaryProfile.lastUpdateFullName = request.user.name;
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess(salaryProfile.id);
}
}

View file

@ -82,15 +82,15 @@ export class SalaryRanksController extends Controller {
@Request() request: { user: Record<string, any> },
) {
// try {
const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } });
if (!salaryRank) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
salaryRank.lastUpdateUserId = request.user.sub;
salaryRank.lastUpdateFullName = request.user.name;
this.salaryRankRepository.merge(salaryRank, requestBody);
await this.salaryRankRepository.save(salaryRank);
return new HttpSuccess();
const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } });
if (!salaryRank) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
salaryRank.lastUpdateUserId = request.user.sub;
salaryRank.lastUpdateFullName = request.user.name;
this.salaryRankRepository.merge(salaryRank, requestBody);
await this.salaryRankRepository.save(salaryRank);
return new HttpSuccess();
// } catch (error: any) {
// throw new Error(error);
// }
@ -106,14 +106,14 @@ export class SalaryRanksController extends Controller {
@Delete("{id}")
async deleteSalaryRanks(@Path() id: string) {
// try {
const delSalaryRanks = await this.salaryRankRepository.findOne({
where: { id },
});
if (!delSalaryRanks) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
}
await this.salaryRankRepository.delete({ id: id });
return new HttpSuccess();
const delSalaryRanks = await this.salaryRankRepository.findOne({
where: { id },
});
if (!delSalaryRanks) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
}
await this.salaryRankRepository.delete({ id: id });
return new HttpSuccess();
// } catch (error: any) {
// throw new Error(error);
// }
@ -156,47 +156,45 @@ export class SalaryRanksController extends Controller {
@Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string,
) {
//ssss total ผิด
// try {
const [salaryRank, total] = await this.salaryRankRepository.findAndCount({
where: {
salaryId: id,
},
select: [
"id",
"salary",
"salaryHalf",
"salaryHalfSpecial",
"salaryFull",
"salaryFullSpecial",
"salaryFullHalf",
"salaryFullHalfSpecial",
"isNext",
],
order: {
salary: "DESC",
salaryHalf: "DESC",
},
skip: (page - 1) * pageSize,
take: pageSize,
});
if (keyword != undefined && keyword !== "") {
const filteredSalaryRank = salaryRank.filter(
(x) =>
x.salary?.toString().includes(keyword) ||
x.salaryHalf?.toString().includes(keyword) ||
x.salaryHalfSpecial?.toString().includes(keyword) ||
x.salaryFull?.toString().includes(keyword) ||
x.salaryFullSpecial?.toString().includes(keyword) ||
x.salaryFullHalf?.toString().includes(keyword) ||
x.salaryFullHalfSpecial?.toString().includes(keyword),
);
return new HttpSuccess({ data: filteredSalaryRank, total: filteredSalaryRank.length });
}
const [salaryRank, total] = await this.salaryRankRepository.findAndCount({
where: {
salaryId: id,
},
select: [
"id",
"salary",
"salaryHalf",
"salaryHalfSpecial",
"salaryFull",
"salaryFullSpecial",
"salaryFullHalf",
"salaryFullHalfSpecial",
"isNext",
],
order: {
salary: "DESC",
salaryHalf: "DESC",
},
skip: (page - 1) * pageSize,
take: pageSize,
});
if (keyword != undefined && keyword !== "") {
const filteredSalaryRank = salaryRank.filter(
(x) =>
x.salary?.toString().includes(keyword) ||
x.salaryHalf?.toString().includes(keyword) ||
x.salaryHalfSpecial?.toString().includes(keyword) ||
x.salaryFull?.toString().includes(keyword) ||
x.salaryFullSpecial?.toString().includes(keyword) ||
x.salaryFullHalf?.toString().includes(keyword) ||
x.salaryFullHalfSpecial?.toString().includes(keyword),
);
return new HttpSuccess({ data: filteredSalaryRank, total: filteredSalaryRank.length });
}
if (!salaryRank) {
return new HttpSuccess([]);
}
return new HttpSuccess({ data: salaryRank, total });
return new HttpSuccess({ data: salaryRank, total });
// } catch (error: any) {
// throw new Error(error);
// }

View file

@ -1,5 +1,7 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { SalaryPeriod } from "./SalaryPeriod";
import { SalaryProfile } from "./SalaryProfile";
@Entity("salaryOrg")
export class SalaryOrg extends EntityBase {
@ -7,49 +9,58 @@ export class SalaryOrg extends EntityBase {
comment: "",
length: 40,
})
salaryPreiodId: string;
salaryPeriodId: string;
@Column({
comment:"",
comment: "สถานะ",
})
status: string;
@Column({
comment:"",
comment: "id หน่วยงาน",
length: 40,
})
rootId : string;
rootId: string;
@Column({
comment:"สถานะ",
comment: "จำนวนคนทั้งหมด",
})
total : number;
total: number;
@Column({
comment:"15%ของจำนวนคน",
comment: "15%ของจำนวนคน",
})
fifteenPercent : number;
fifteenPercent: number;
@Column({
comment: "กลุ่ม GROUP1->กลุ่ม1 GROUP2->กลุ่ม2",
length: 10,
})
group: string;
@ManyToOne(() => SalaryPeriod, (salaryPeriod) => salaryPeriod.salaryOrgs)
@JoinColumn({ name: "salaryPeriodId" })
salaryPeriod: SalaryPeriod;
@OneToMany(() => SalaryProfile, (salaryProfile) => salaryProfile.salaryOrg)
salaryProfiles: SalaryProfile[];
}
export class CreateSalaryOrg {
@Column("uuid")
salaryPreiodId: string;
salaryPeriodId: string;
@Column()
status: string;
@Column("uuid")
rootId : string;
rootId: string;
@Column()
total : number;
total: number;
@Column()
fifteenPercent : number;
fifteenPercent: number;
}
export type UpdateSalaryOrg = Partial<CreateSalaryOrg>;

View file

@ -1,5 +1,6 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { SalaryOrg } from "./SalaryOrg";
@Entity("salaryPeriod")
export class SalaryPeriod extends EntityBase {
@ -29,10 +30,11 @@ export class SalaryPeriod extends EntityBase {
})
status?: string;
@OneToMany(() => SalaryOrg, (salaryOrg) => salaryOrg.salaryPeriod)
salaryOrgs: SalaryOrg[];
}
export class CreateSalaryPeriod {
@Column()
period: string;
@ -41,11 +43,9 @@ export class CreateSalaryPeriod {
@Column()
effectiveDate: Date;
}
export class UpdateSalaryPeriod {
@Column()
period: string;
@ -54,5 +54,4 @@ export class UpdateSalaryPeriod {
@Column()
effectiveDate: Date;
}
}

View file

@ -1,5 +1,6 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { SalaryOrg } from "./SalaryOrg";
@Entity("salaryProfile")
export class SalaryProfile extends EntityBase {
@ -34,9 +35,41 @@ export class SalaryProfile extends EntityBase {
lastName: string;
@Column({
comment:"เลขที่ตำแหน่ง",
nullable: true,
comment: "เลขบัตรประชาชน",
length: 100,
default: null,
})
posNumber : number;
citizenId: string;
@Column({
nullable: true,
comment: "Prefix นำหน้าเลขที่ตำแหน่ง เป็น Optional (ไม่ใช่อักษรย่อของหน่วยงาน/ส่วนราชการ)",
length: 100,
default: null,
})
posMasterNoPrefix: string;
@Column({
comment: "เลขที่ตำแหน่ง เป็นตัวเลข",
})
posMasterNo: number;
@Column({
nullable: true,
comment: "Suffix หลังเลขที่ตำแหน่ง เช่น ช.",
length: 100,
default: null,
})
posMasterNoSuffix: string;
@Column({
nullable: true,
comment: "ชื่อย่อหน่วยงาน",
length: 100,
default: null,
})
orgShortName: string;
@Column({
nullable: true,
@ -48,21 +81,32 @@ export class SalaryProfile extends EntityBase {
@Column({
comment: "ประเภทตำแหน่ง",
length: 40,
length: 100,
})
posTypeId: string;
posType: string;
@Column({
comment: "ระดับตำแหน่ง",
length: 40,
length: 100,
})
posLevelId: string;
posLevel: string;
@Column({
comment: "ตำแหน่งทางการบริหาร",
length: 255,
})
posExecutive: string;
@Column({
comment: "เงินเดือนฐาน",
})
amount: number;
@Column({
comment: "เงินพิเศษ",
})
amountSpecial: number;
@Column({
comment: "จำนวนเงินที่ใช้เลื่อน",
})
@ -75,8 +119,9 @@ export class SalaryProfile extends EntityBase {
@Column({
nullable: true,
comment: "ประเภทการเลื่อน NONE->ไม่ได้เลื่อน HAFT->ครึ่งขั้น FULL->1ขั้น FULLHAFT->1.5ขั้น group กลุ่ม GROUP1->กลุ่ม1 GROUP2->กลุ่ม2",
length: 255,
comment:
"ประเภทการเลื่อน(ขั้น) PENDING->รายชื่อคนครอง NONE->ไม่ได้เลื่อน HAFT->ครึ่งขั้น FULL->1ขั้น FULLHAFT->1.5ขั้น",
length: 20,
default: null,
})
type: string;
@ -151,77 +196,81 @@ export class SalaryProfile extends EntityBase {
})
child4: string;
@ManyToOne(() => SalaryOrg, (salaryOrg) => salaryOrg.salaryProfiles)
@JoinColumn({ name: "salaryOrgId" })
salaryOrg: SalaryOrg;
}
export class CreateSalaryProfile {
@Column("uuid")
id: string;
@Column("uuid")
salaryOrgId: string;
@Column()
prefix: string;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
posNumber : number;
@Column()
position: string;
@Column("uuid")
posTypeId: string;
@Column("uuid")
posLevelId: string;
@Column()
amount: number;
@Column()
amountUse: number;
@Column()
positionSalaryAmount: number;
@Column()
type: string;
@Column("uuid")
rootId: string;
@Column()
root: string;
@Column("uuid")
child1Id: string;
@Column()
child1: string;
@Column("uuid")
child2Id: string;
@Column()
child2: string;
@Column("uuid")
child3Id: string;
@Column()
child3: string;
@Column("uuid")
child4Id: string;
@Column()
child4: string;
@Column()
type: string;
@Column()
prefix: string;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
citizenId: string;
@Column()
posMasterNoPrefix: string;
@Column()
posMasterNo: number;
@Column()
posMasterNoSuffix: string;
@Column()
orgShortName: string;
@Column()
position: string;
@Column()
posType: string;
@Column()
posLevel: string;
@Column()
amount: number;
@Column("uuid")
rootId: string;
@Column()
root: string;
@Column("uuid")
child1Id: string;
@Column()
child1: string;
@Column("uuid")
child2Id: string;
@Column()
child2: string;
@Column("uuid")
child3Id: string;
@Column()
child3: string;
@Column("uuid")
child4Id: string;
@Column()
child4: string;
}
export type UpdateSalaryProfile = Partial<CreateSalaryProfile>;

View file

@ -4,9 +4,9 @@ export class CreateSalaryPeriodTable1708585607075 implements MigrationInterface
name = "CreateSalaryPeriodTable1708585607075";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE \`salaryPeriod\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`period\` varchar(255) NOT NULL COMMENT 'ประเภทผัง (SPECIAL->รอบพิเศษ,APR->รอบเมษายน,OCT->รอบตุลาคม)', \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 0, \`effectiveDate\` datetime NULL COMMENT 'วันที่มีผลบังคับใช้', \`status\` varchar(255) NOT NULL COMMENT 'สถานะ' DEFAULT 'PENDING', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
);
// await queryRunner.query(
// `CREATE TABLE \`salaryPeriod\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`period\` varchar(255) NOT NULL COMMENT 'ประเภทผัง (SPECIAL->รอบพิเศษ,APR->รอบเมษายน,OCT->รอบตุลาคม)', \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน' DEFAULT 0, \`effectiveDate\` datetime NULL COMMENT 'วันที่มีผลบังคับใช้', \`status\` varchar(255) NOT NULL COMMENT 'สถานะ' DEFAULT 'PENDING', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`,
// );
// await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_fa211557e2cbee0bb3bbef363f2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
// await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_683719e5363cc977da591556731\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
@ -14,6 +14,6 @@ export class CreateSalaryPeriodTable1708585607075 implements MigrationInterface
public async down(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_683719e5363cc977da591556731\``);
// await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_fa211557e2cbee0bb3bbef363f2\``);
await queryRunner.query(`DROP TABLE \`salaryPeriod\``);
// await queryRunner.query(`DROP TABLE \`salaryPeriod\``);
}
}

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableSalaryProfile1708952006038 implements MigrationInterface {
name = 'AddTableSalaryProfile1708952006038'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`salaryOrg\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`salaryPeriodId\` varchar(40) NOT NULL, \`status\` varchar(255) NOT NULL COMMENT 'สถานะ', \`rootId\` varchar(40) NOT NULL COMMENT 'id หน่วยงาน', \`total\` int NOT NULL COMMENT 'จำนวนคนทั้งหมด', \`fifteenPercent\` int NOT NULL COMMENT '15%ของจำนวนคน', \`group\` varchar(10) NOT NULL COMMENT 'กลุ่ม GROUP1->กลุ่ม1 GROUP2->กลุ่ม2', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`salaryProfile\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`salaryOrgId\` varchar(40) NOT NULL, \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า', \`firstName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'สกุล', \`citizenId\` varchar(100) NULL COMMENT 'เลขบัตรประชาชน', \`posMasterNoPrefix\` varchar(100) NULL COMMENT 'Prefix นำหน้าเลขที่ตำแหน่ง เป็น Optional (ไม่ใช่อักษรย่อของหน่วยงาน/ส่วนราชการ)', \`posMasterNo\` int NOT NULL COMMENT 'เลขที่ตำแหน่ง เป็นตัวเลข', \`posMasterNoSuffix\` varchar(100) NULL COMMENT 'Suffix หลังเลขที่ตำแหน่ง เช่น ช.', \`orgShortName\` varchar(100) NULL COMMENT 'ชื่อย่อหน่วยงาน', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`posType\` varchar(100) NOT NULL COMMENT 'ประเภทตำแหน่ง', \`posLevel\` varchar(100) NOT NULL COMMENT 'ระดับตำแหน่ง', \`posExecutive\` varchar(255) NOT NULL COMMENT 'ตำแหน่งทางการบริหาร', \`amount\` int NOT NULL COMMENT 'เงินเดือนฐาน', \`amountSpecial\` int NOT NULL COMMENT 'เงินพิเศษ', \`amountUse\` int NOT NULL COMMENT 'จำนวนเงินที่ใช้เลื่อน', \`positionSalaryAmount\` int NOT NULL COMMENT 'เงินเดือนหลังเลื่อน', \`type\` varchar(20) NULL COMMENT 'ประเภทการเลื่อน(ขั้น) PENDING->รายชื่อคนครอง NONE->ไม่ได้เลื่อน HAFT->ครึ่งขั้น FULL->1ขั้น FULLHAFT->1.5ขั้น', \`rootId\` varchar(40) NOT NULL, \`root\` varchar(255) NULL, \`child1Id\` varchar(40) NOT NULL, \`child1\` varchar(255) NULL, \`child2Id\` varchar(40) NOT NULL, \`child2\` varchar(255) NULL, \`child3Id\` varchar(40) NOT NULL, \`child3\` varchar(255) NULL, \`child4Id\` varchar(40) NOT NULL, \`child4\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`salaryOrg\` ADD CONSTRAINT \`FK_7fd317035fe8d0e03dc2443cf36\` FOREIGN KEY (\`salaryPeriodId\`) REFERENCES \`salaryPeriod\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD CONSTRAINT \`FK_d925088feca62ab41c131a87914\` FOREIGN KEY (\`salaryOrgId\`) REFERENCES \`salaryOrg\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP FOREIGN KEY \`FK_d925088feca62ab41c131a87914\``);
await queryRunner.query(`ALTER TABLE \`salaryOrg\` DROP FOREIGN KEY \`FK_7fd317035fe8d0e03dc2443cf36\``);
await queryRunner.query(`DROP TABLE \`salaryProfile\``);
await queryRunner.query(`DROP TABLE \`salaryOrg\``);
}
}