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

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

View file

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

View file

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

View file

@ -15,18 +15,22 @@ import {
Query, Query,
} from "tsoa"; } from "tsoa";
import { AppDataSource } from "../database/data-source"; 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 HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import { CreateSalaryPeriod, SalaryPeriod, UpdateSalaryPeriod } from "../entities/SalaryPeriod"; 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") @Tags("Salary")
@Security("bearerAuth") @Security("bearerAuth")
export class SalaryPeriodController extends Controller { export class SalaryPeriodController extends Controller {
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
/** /**
* API * API
@ -34,11 +38,12 @@ export class SalaryPeriodController extends Controller {
* @summary SLR_016 - #16 * @summary SLR_016 - #16
* *
*/ */
@Post("period") @Post()
async create_salary_period( async create_salary_period(
@Body() requestBody: CreateSalaryPeriod, @Body() requestBody: CreateSalaryPeriod,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
//ssss ไม่ต้องเช็ค?
const salaryPeriod = Object.assign(new SalaryPeriod(), requestBody); const salaryPeriod = Object.assign(new SalaryPeriod(), requestBody);
if (!salaryPeriod) { if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -54,12 +59,15 @@ export class SalaryPeriodController extends Controller {
const chk_period = await this.salaryPeriodRepository.findOne({ const chk_period = await this.salaryPeriodRepository.findOne({
where: { where: {
period: salaryPeriod.period, period: salaryPeriod.period,
effectiveDate: Between(startOfYear, endOfYear) effectiveDate: Between(startOfYear, endOfYear),
}, },
}); });
if (chk_period) { 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(); salaryPeriod.period = salaryPeriod.period.toUpperCase();
@ -78,7 +86,7 @@ export class SalaryPeriodController extends Controller {
* *
* @param {string} id Guid, *Id * @param {string} id Guid, *Id
*/ */
@Put("period/{id}") @Put("{id}")
async update_salary_period( async update_salary_period(
@Path() id: string, @Path() id: string,
@Body() requestBody: UpdateSalaryPeriod, @Body() requestBody: UpdateSalaryPeriod,
@ -102,12 +110,15 @@ export class SalaryPeriodController extends Controller {
where: { where: {
period: requestBody.period, period: requestBody.period,
id: Not(id), id: Not(id),
effectiveDate: Between(startOfYear, endOfYear) effectiveDate: Between(startOfYear, endOfYear),
}, },
}); });
if (chk_period) { 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(); chk_SalaryPeriod.period = requestBody.period.toUpperCase();
@ -117,7 +128,6 @@ export class SalaryPeriodController extends Controller {
this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody); this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody);
await this.salaryPeriodRepository.save(chk_SalaryPeriod); await this.salaryPeriodRepository.save(chk_SalaryPeriod);
return new HttpSuccess(id); return new HttpSuccess(id);
} }
/** /**
@ -127,7 +137,7 @@ export class SalaryPeriodController extends Controller {
* *
* @param {string} id Guid, *Id * @param {string} id Guid, *Id
*/ */
@Delete("period/{id}") @Delete("{id}")
async delete_salary_period(@Path() id: string) { async delete_salary_period(@Path() id: string) {
const SalaryPeriod = await this.salaryPeriodRepository.findOne({ const SalaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id }, where: { id: id },
@ -146,18 +156,11 @@ export class SalaryPeriodController extends Controller {
* *
* @param {string} id Guid, *Id * @param {string} id Guid, *Id
*/ */
@Get("period/{id}") @Get("{id}")
async GetSalaryPeriod_ById(@Path() id: string) { async GetSalaryPeriod_ById(@Path() id: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({ const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id }, where: { id: id },
select: [ select: ["id", "period", "isActive", "effectiveDate", "isActive", "status"],
"id",
"period",
"isActive",
"effectiveDate",
"isActive",
"status",
],
}); });
if (!salaryPeriod) { if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี: " + id);
@ -171,27 +174,27 @@ export class SalaryPeriodController extends Controller {
* @summary SLR_020 - #20 * @summary SLR_020 - #20
* *
*/ */
@Get("period") @Get()
async GetListsSalaryPeriod( async GetListsSalaryPeriod(
@Query("page") page: number = 1, @Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
@Query("year") year: number = 2024, @Query("year") year: number = 2024,
) { ) {
//ssss total ผิด
let salaryPeriod: any let salaryPeriod: any;
let total: any let total: any;
if(year != 0){ if (year != 0) {
const startOfYear = new Date(year, 0, 1); const startOfYear = new Date(year, 0, 1);
const endOfYear = new Date(year, 11, 31); const endOfYear = new Date(year, 11, 31);
[salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({ [salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
skip: (page - 1) * pageSize, skip: (page - 1) * pageSize,
take: pageSize, take: pageSize,
where: { where: {
effectiveDate: Between(startOfYear, endOfYear) effectiveDate: Between(startOfYear, endOfYear),
} },
}); });
}else{ } else {
[salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({ [salaryPeriod, total] = await this.salaryPeriodRepository.findAndCount({
skip: (page - 1) * pageSize, skip: (page - 1) * pageSize,
take: pageSize, take: pageSize,
@ -200,13 +203,13 @@ export class SalaryPeriodController extends Controller {
if (keyword != undefined && keyword !== "") { if (keyword != undefined && keyword !== "") {
const filteredSalaryPeriod = salaryPeriod.filter( const filteredSalaryPeriod = salaryPeriod.filter(
(x:any) => (x: any) =>
x.period.toString().includes(keyword) || x.period.toString().includes(keyword) ||
x.isActive.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, id: item.id,
period: item.period, period: item.period,
isActive: item.isActive, isActive: item.isActive,
@ -216,19 +219,320 @@ export class SalaryPeriodController extends Controller {
return new HttpSuccess({ data: formattedData, total: formattedData.length }); return new HttpSuccess({ data: formattedData, total: formattedData.length });
} }
if (!salaryPeriod) {
return new HttpSuccess([]);
}
const formattedData = salaryPeriod.map((item:any) => ({ const formattedData = salaryPeriod.map((item: any) => ({
id: item.id, id: item.id,
period: item.period, period: item.period,
isActive: item.isActive, isActive: item.isActive,
effectiveDate: item.effectiveDate, effectiveDate: item.effectiveDate,
status: item.status, status: item.status,
})); }));
return new HttpSuccess({ data: formattedData, total }); 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> }, @Request() request: { user: Record<string, any> },
) { ) {
// try { // try {
const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } }); const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } });
if (!salaryRank) { if (!salaryRank) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
} }
salaryRank.lastUpdateUserId = request.user.sub; salaryRank.lastUpdateUserId = request.user.sub;
salaryRank.lastUpdateFullName = request.user.name; salaryRank.lastUpdateFullName = request.user.name;
this.salaryRankRepository.merge(salaryRank, requestBody); this.salaryRankRepository.merge(salaryRank, requestBody);
await this.salaryRankRepository.save(salaryRank); await this.salaryRankRepository.save(salaryRank);
return new HttpSuccess(); return new HttpSuccess();
// } catch (error: any) { // } catch (error: any) {
// throw new Error(error); // throw new Error(error);
// } // }
@ -106,14 +106,14 @@ export class SalaryRanksController extends Controller {
@Delete("{id}") @Delete("{id}")
async deleteSalaryRanks(@Path() id: string) { async deleteSalaryRanks(@Path() id: string) {
// try { // try {
const delSalaryRanks = await this.salaryRankRepository.findOne({ const delSalaryRanks = await this.salaryRankRepository.findOne({
where: { id }, where: { id },
}); });
if (!delSalaryRanks) { if (!delSalaryRanks) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
} }
await this.salaryRankRepository.delete({ id: id }); await this.salaryRankRepository.delete({ id: id });
return new HttpSuccess(); return new HttpSuccess();
// } catch (error: any) { // } catch (error: any) {
// throw new Error(error); // throw new Error(error);
// } // }
@ -156,47 +156,45 @@ export class SalaryRanksController extends Controller {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Query("keyword") keyword?: string, @Query("keyword") keyword?: string,
) { ) {
//ssss total ผิด
// try { // try {
const [salaryRank, total] = await this.salaryRankRepository.findAndCount({ const [salaryRank, total] = await this.salaryRankRepository.findAndCount({
where: { where: {
salaryId: id, salaryId: id,
}, },
select: [ select: [
"id", "id",
"salary", "salary",
"salaryHalf", "salaryHalf",
"salaryHalfSpecial", "salaryHalfSpecial",
"salaryFull", "salaryFull",
"salaryFullSpecial", "salaryFullSpecial",
"salaryFullHalf", "salaryFullHalf",
"salaryFullHalfSpecial", "salaryFullHalfSpecial",
"isNext", "isNext",
], ],
order: { order: {
salary: "DESC", salary: "DESC",
salaryHalf: "DESC", salaryHalf: "DESC",
}, },
skip: (page - 1) * pageSize, skip: (page - 1) * pageSize,
take: pageSize, take: pageSize,
}); });
if (keyword != undefined && keyword !== "") { if (keyword != undefined && keyword !== "") {
const filteredSalaryRank = salaryRank.filter( const filteredSalaryRank = salaryRank.filter(
(x) => (x) =>
x.salary?.toString().includes(keyword) || x.salary?.toString().includes(keyword) ||
x.salaryHalf?.toString().includes(keyword) || x.salaryHalf?.toString().includes(keyword) ||
x.salaryHalfSpecial?.toString().includes(keyword) || x.salaryHalfSpecial?.toString().includes(keyword) ||
x.salaryFull?.toString().includes(keyword) || x.salaryFull?.toString().includes(keyword) ||
x.salaryFullSpecial?.toString().includes(keyword) || x.salaryFullSpecial?.toString().includes(keyword) ||
x.salaryFullHalf?.toString().includes(keyword) || x.salaryFullHalf?.toString().includes(keyword) ||
x.salaryFullHalfSpecial?.toString().includes(keyword), x.salaryFullHalfSpecial?.toString().includes(keyword),
); );
return new HttpSuccess({ data: filteredSalaryRank, total: filteredSalaryRank.length }); return new HttpSuccess({ data: filteredSalaryRank, total: filteredSalaryRank.length });
} }
if (!salaryRank) { return new HttpSuccess({ data: salaryRank, total });
return new HttpSuccess([]);
}
return new HttpSuccess({ data: salaryRank, total });
// } catch (error: any) { // } catch (error: any) {
// throw new Error(error); // throw new Error(error);
// } // }

View file

@ -1,5 +1,7 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base"; import { EntityBase } from "./base/Base";
import { SalaryPeriod } from "./SalaryPeriod";
import { SalaryProfile } from "./SalaryProfile";
@Entity("salaryOrg") @Entity("salaryOrg")
export class SalaryOrg extends EntityBase { export class SalaryOrg extends EntityBase {
@ -7,49 +9,58 @@ export class SalaryOrg extends EntityBase {
comment: "", comment: "",
length: 40, length: 40,
}) })
salaryPreiodId: string; salaryPeriodId: string;
@Column({ @Column({
comment:"", comment: "สถานะ",
}) })
status: string; status: string;
@Column({ @Column({
comment:"", comment: "id หน่วยงาน",
length: 40, length: 40,
}) })
rootId : string; rootId: string;
@Column({ @Column({
comment:"สถานะ", comment: "จำนวนคนทั้งหมด",
}) })
total : number; total: number;
@Column({ @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 { export class CreateSalaryOrg {
@Column("uuid") @Column("uuid")
salaryPreiodId: string; salaryPeriodId: string;
@Column() @Column()
status: string; status: string;
@Column("uuid") @Column("uuid")
rootId : string; rootId: string;
@Column() @Column()
total : number; total: number;
@Column() @Column()
fifteenPercent : number; fifteenPercent: number;
} }
export type UpdateSalaryOrg = Partial<CreateSalaryOrg>; export type UpdateSalaryOrg = Partial<CreateSalaryOrg>;

View file

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

View file

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