Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-03-07 16:07:34 +07:00
commit e7d59e4397
9 changed files with 700 additions and 260 deletions

View file

@ -102,8 +102,8 @@ export class ReportController extends Controller {
return new HttpSuccess({ template: "SalaryRank", reportName: "SalaryRank", return new HttpSuccess({ template: "SalaryRank", reportName: "SalaryRank",
data: { data: {
nameType: salarys.salaryType == "OFFICER" ? "ผังข้าราชการกรุงเทพมหานครสามัญ" : nameType: salarys.name == "OFFICER" ? "ผังข้าราชการกรุงเทพมหานครสามัญ" :
salarys.salaryType == "EMPLOYEE" ? "ผังลูกจ้างประจำกรุงเทพมหานคร" : "", salarys.name == "EMPLOYEE" ? "ผังลูกจ้างประจำกรุงเทพมหานคร" : "",
level: posLevel?.posLevelName == null ? "" : posLevel?.posLevelName, level: posLevel?.posLevelName == null ? "" : posLevel?.posLevelName,
type: posType?.posTypeName == null ? "" : posType?.posTypeName, type: posType?.posTypeName == null ? "" : posType?.posTypeName,
date: salarys.date == null ? "" : date: salarys.date == null ? "" :

View file

@ -20,7 +20,7 @@ import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status"; import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { In, IsNull, Not } from "typeorm"; import { In, IsNull, Not, MoreThan } from "typeorm";
import { SalaryProfile } from "../entities/SalaryProfile"; import { SalaryProfile } from "../entities/SalaryProfile";
import { SalaryPeriod } from "../entities/SalaryPeriod"; import { SalaryPeriod } from "../entities/SalaryPeriod";
import { SalaryOrg } from "../entities/SalaryOrg"; import { SalaryOrg } from "../entities/SalaryOrg";
@ -40,18 +40,33 @@ export class Report_1_Controller extends Controller {
private salaryProfile = AppDataSource.getRepository(SalaryProfile); private salaryProfile = AppDataSource.getRepository(SalaryProfile);
/** /**
* API 1 * API 1
* *
* @summary 1 * @summary 1
* *
* @param {string} rootId Guid, *Id Root * @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period * @param {string} salaryPeriodId Guid, *Id Period
*/ */
@Get("{rootId}/{salaryPeriodId}") @Get("03/{rootId}/{salaryPeriodId}")
async SalaryReport4( async SalaryReport3(
@Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37", // @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
@Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2", // @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
@Path() rootId : string,
@Path() salaryPeriodId: string,
) { ) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
period: "APR",
isActive: true
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const salaryOrg = await this.salaryOrgRepository.findOne({ const salaryOrg = await this.salaryOrgRepository.findOne({
where: { where: {
salaryPeriodId: salaryPeriodId, salaryPeriodId: salaryPeriodId,
@ -60,42 +75,285 @@ export class Report_1_Controller extends Controller {
}, },
order: { order: {
group: "ASC" group: "ASC"
} },
// relations: ["salaryProfiles"], relations: ["salaryProfiles"],
}); });
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); const salaryProfile = await this.salaryProfile.find({
}
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { where: {
id: String(salaryOrg.salaryPeriodId), salaryOrgId: salaryOrg?.id,
period: "APR", type: "FULL", //หนึ่งขั้น
isActive: true
}, },
select: [
"id", "prefix" , "firstName", "lastName", "root",
"position", "posType", "posLevel", "orgShortName",
"posMasterNo", "amount", "amountSpecial"
]
}); });
const mapData = {
effectiveDate : salaryPeriod?.effectiveDate,
// root: salaryProfile[0]?.root,
profile: salaryProfile.map((item, index) => ({
no: Extension.ToThaiNumber(String(index+1)),
fullname: item.prefix + item.firstName +" "+ item.lastName,
position: item.position + "/" +
(item.child4==undefined && item.child4==null ? "" : item.child4+"/")+
(item.child3==undefined && item.child3==null ? "" : item.child3+"/")+
(item.child2==undefined && item.child2==null ? "" : item.child2+"/")+
(item.child1==undefined && item.child1==null ? "" : item.child1+"/")+
(item.root==undefined && item.root==null ? "" : item.root),
posLevel: item.posLevel,
orgShortName: item.orgShortName+item.posMasterNo,
amount: item.amount == undefined || item.amount == null ? "" : Extension.ToThaiNumber(String(item.amount)),
amountSpecial: item.amountSpecial == undefined || item.amountSpecial == null ? "" : Extension.ToThaiNumber(String(item.amountSpecial)),
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
remark: null //หมายเหตุ
}))
}
return mapData
}
/**
* API 1
*
* @summary 1
*
* @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period
*/
@Get("04/{rootId}/{salaryPeriodId}")
async SalaryReport4(
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
@Path() rootId : string,
@Path() salaryPeriodId: string,
) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
period: "APR",
isActive: true
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodId,
rootId: rootId,
snapshot: "SNAP2",
},
order: {
group: "ASC"
},
relations: ["salaryProfiles"],
});
const salaryProfile = await this.salaryProfile.find({ const salaryProfile = await this.salaryProfile.find({
where: { salaryOrgId: salaryOrg.id}, where: { salaryOrgId: salaryOrg?.id},
select: ["id", "prefix" , "firstName", "lastName", "root", select: [
"position", "posType", "posLevel", "orgShortName", "posMasterNo", "amount", "amountSpecial"] "id", "prefix" , "firstName", "lastName", "root",
"position", "posType", "posLevel", "orgShortName",
"posMasterNo", "amount", "amountSpecial"
]
}); });
const mapData = { const mapData = {
effectiveDate : salaryPeriod?.effectiveDate, effectiveDate : salaryPeriod?.effectiveDate,
root: salaryProfile[0]?.root, root: salaryProfile[0]?.root,
profile: salaryProfile.map((item, index) => ({ profile: salaryProfile.map((item, index) => ({
no: index+1, no: Extension.ToThaiNumber(String(index+1)),
fullname: item.prefix + item.firstName +" "+ item.lastName, fullname: item.prefix + item.firstName +" "+ item.lastName,
position: item.position + " / " + item.posType, position: item.position + "/" +
(item.child4==undefined && item.child4==null ? "" : item.child4+"/")+
(item.child3==undefined && item.child3==null ? "" : item.child3+"/")+
(item.child2==undefined && item.child2==null ? "" : item.child2+"/")+
(item.child1==undefined && item.child1==null ? "" : item.child1+"/")+
(item.root==undefined && item.root==null ? "" : item.root),
posLevel: item.posLevel, posLevel: item.posLevel,
orgShortName: item.orgShortName+item.posMasterNo, orgShortName: item.orgShortName+item.posMasterNo,
amount: item.amount, amount: item.amount == undefined || item.amount == null ? "" : Extension.ToThaiNumber(String(item.amount)),
amountSpecial: item.amountSpecial, amountSpecial: item.amountSpecial == undefined || item.amountSpecial == null ? "" : Extension.ToThaiNumber(String(item.amountSpecial)),
root: item.root,
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
remark: null //หมายเหตุ remark: null //หมายเหตุ
})) }))
} }
return mapData return mapData
} }
/**
* API
*
* @summary
*
* @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period
*/
@Get("07/{rootId}/{salaryPeriodId}")
async SalaryReport7(
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
@Path() rootId : string,
@Path() salaryPeriodId: string,
) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
period: "APR",
isActive: true
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodId,
rootId: rootId,
snapshot: "SNAP2",
},
order: {
group: "ASC"
},
relations: ["salaryProfiles"],
});
const salaryProfile = await this.salaryProfile.find({
where: {
salaryOrgId: salaryOrg?.id,
amountSpecial: IsNull() || 0,
amountUse: MoreThan(1),
},
select: [
"id", "prefix" , "firstName", "lastName", "root",
"position", "posType", "posLevel", "orgShortName", "posMasterNo",
"amount", "amountUse", "positionSalaryAmount"
],
order: {
posMasterNo: "ASC"
}
});
const mapData = salaryProfile.map((item, index) => ({
no: Extension.ToThaiNumber(String(index+1)),
fullname: item.prefix + item.firstName +" "+ item.lastName,
position: item.position,
posType: item.posType,
posLevel: item.posLevel,
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
amount: item.amount == undefined || item.amount == null ? "" : Extension.ToThaiNumber(String(item.amount)),
positionSalaryAmount: item.positionSalaryAmount == undefined || item.positionSalaryAmount == null ? "" : Extension.ToThaiNumber(String(item.positionSalaryAmount)),
remark: null
}));
return mapData;
}
/**
* API
*
* @summary
*
* @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period
*/
@Get("08/{rootId}/{salaryPeriodId}")
async SalaryReport8(
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
@Path() rootId : string,
@Path() salaryPeriodId: string,
) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
period: "APR",
isActive: true
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodId,
rootId: rootId,
snapshot: "SNAP2",
},
order: {
group: "ASC"
},
relations: ["salaryProfiles"],
});
const salaryProfileSpecial = await this.salaryProfile.find({
where: {
salaryOrgId: salaryOrg?.id,
amountSpecial: MoreThan(1),
},
select: [
"id", "prefix" , "firstName", "lastName", "root",
"position", "posType", "posLevel", "orgShortName",
"posMasterNo", "amount", "amountSpecial",
],
order: {
posMasterNo: "ASC"
}
});
const salaryProfileNoAmount = await this.salaryProfile.find({
where: {
salaryOrgId: salaryOrg?.id,
amountUse: IsNull() || 0,
positionSalaryAmount: IsNull() || 0,
},
select: [
"id", "prefix" , "firstName", "lastName", "root",
"position", "posType", "posLevel", "orgShortName",
"posMasterNo", "amount",
],
order: {
posMasterNo: "ASC"
}
});
const profileSpecial = salaryProfileSpecial.map((item, index) => ({
no: Extension.ToThaiNumber(String(index+1)),
fullname: item.prefix + item.firstName +" "+ item.lastName,
position: item.position,
posType: item.posType,
posLevel: item.posLevel,
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
amount: item.amount == undefined || item.amount == null ? "" : Extension.ToThaiNumber(String(item.amount)),
amountSpecial: item.amountSpecial == undefined || item.amountSpecial == null ? "" : Extension.ToThaiNumber(String(item.amountSpecial)),
remark: null
}));
const profileNoAmount = salaryProfileNoAmount.map((item, index) => ({
no: Extension.ToThaiNumber(String(index+1)),
fullname: item.prefix + item.firstName +" "+ item.lastName,
position: item.position,
posType: item.posType,
posLevel: item.posLevel,
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
amount: item.amount == undefined || item.amount == null ? "" : Extension.ToThaiNumber(String(item.amount)),
remark: null
}));
const mapData = {
profileSpecial,
profileNoAmount
}
return mapData;
}
} }

View file

@ -43,7 +43,7 @@ export class Salary extends Controller {
*/ */
@Post() @Post()
@Example({ @Example({
salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร") name: "string", //*ชื่อผัง
posTypeId: "string(Guid)", //*ระดับของตำแหน่ง posTypeId: "string(Guid)", //*ระดับของตำแหน่ง
posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง
isActive: "boolean", //*สถานะการใช้งาน isActive: "boolean", //*สถานะการใช้งาน
@ -62,11 +62,6 @@ export class Salary extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); 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({ const chk_posTypeId = await this.poTypeRepository.findOne({
where: { id: salarys.posTypeId }, where: { id: salarys.posTypeId },
}); });
@ -83,7 +78,7 @@ export class Salary extends Controller {
const chk_3fields = await this.salaryRepository.findOne({ const chk_3fields = await this.salaryRepository.findOne({
where: { where: {
salaryType: salarys.salaryType, name: salarys.name,
posTypeId: salarys.posTypeId, posTypeId: salarys.posTypeId,
posLevelId: salarys.posLevelId, posLevelId: salarys.posLevelId,
}, },
@ -91,7 +86,7 @@ export class Salary extends Controller {
if (chk_3fields && salarys.isActive) { if (chk_3fields && salarys.isActive) {
salarys.isActive = false; salarys.isActive = false;
} }
salarys.salaryType = salarys.salaryType.toUpperCase(); salarys.name = salarys.name;
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;
@ -113,7 +108,7 @@ export class Salary extends Controller {
*/ */
@Put("{id}") @Put("{id}")
@Example({ @Example({
salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร") name: "string", //*ชื่อผัง
posTypeId: "string(Guid)", //*ระดับของตำแหน่ง posTypeId: "string(Guid)", //*ระดับของตำแหน่ง
posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง
isActive: "boolean", //*สถานะการใช้งาน isActive: "boolean", //*สถานะการใช้งาน
@ -144,7 +139,7 @@ export class Salary extends Controller {
const chk_3fields = await this.salaryRepository.findOne({ const chk_3fields = await this.salaryRepository.findOne({
where: { where: {
salaryType: requestBody.salaryType, name: requestBody.name,
posTypeId: requestBody.posTypeId, posTypeId: requestBody.posTypeId,
posLevelId: requestBody.posLevelId, posLevelId: requestBody.posLevelId,
isActive: true, isActive: true,
@ -160,11 +155,6 @@ export class Salary extends Controller {
await this.salaryRepository.save(chk_3fields); 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_posTypeId = await this.poTypeRepository.findOne({ const chk_posTypeId = await this.poTypeRepository.findOne({
where: { id: requestBody.posTypeId }, where: { id: requestBody.posTypeId },
}); });
@ -233,7 +223,7 @@ export class Salary extends Controller {
*/ */
@Get("{id}") @Get("{id}")
@Example({ @Example({
salaryType: "string", //*ประเภทผัง (OFFICER->"ข้าราชการกรุงเทพมหานครสามัญ",EMPLOYEE->"ลูกจ้างประจำกรุงเทพมหานคร") name: "string", //*ชื่อผัง
posTypeId: "string(Guid)", //*ระดับของตำแหน่ง posTypeId: "string(Guid)", //*ระดับของตำแหน่ง
posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง posLevelId: "string(Guid)", //*ประเภทของตำแหน่ง
isActive: "boolean", //*สถานะการใช้งาน isActive: "boolean", //*สถานะการใช้งาน
@ -247,7 +237,7 @@ export class Salary extends Controller {
const salary = await this.salaryRepository.findOne({ const salary = await this.salaryRepository.findOne({
where: { id: id }, where: { id: id },
select: [ select: [
"salaryType", "name",
"isSpecial", "isSpecial",
"posTypeId", "posTypeId",
"posLevelId", "posLevelId",
@ -282,14 +272,21 @@ export class Salary extends Controller {
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",
isActive: "ASC",
posType_: {
posTypeRank: "ASC"
},
posLevel_: {
posLevelRank: "ASC"
},
}, },
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), ...(keyword ? {} : { skip: (page - 1) * 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.name?.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) ||
@ -302,7 +299,7 @@ export class Salary extends Controller {
const formattedData = filteredSalary.map((item) => ({ const formattedData = filteredSalary.map((item) => ({
id: item.id, id: item.id,
salaryType: item.salaryType, name: item.name,
isSpecial: item.isSpecial, isSpecial: item.isSpecial,
posTypeId: item.posType_?.id, posTypeId: item.posType_?.id,
posType: item.posType_?.posTypeName, posType: item.posType_?.posTypeName,
@ -320,7 +317,7 @@ export class Salary extends Controller {
const formattedData = salary.map((item) => ({ const formattedData = salary.map((item) => ({
id: item.id, id: item.id,
salaryType: item.salaryType, name: item.name,
isSpecial: item.isSpecial, isSpecial: item.isSpecial,
posTypeId: item.posType_?.id, posTypeId: item.posType_?.id,
posType: item.posType_?.posTypeName, posType: item.posType_?.posTypeName,
@ -333,7 +330,6 @@ export class Salary extends Controller {
details: item.details, details: item.details,
})); }));
return new HttpSuccess({ data: formattedData, total }); return new HttpSuccess({ data: formattedData, total });
} }
/** /**

View file

@ -118,6 +118,9 @@ export class SalaryPeriodController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
} }
const sum = salaryOrg.salaryProfiles.reduce((accumulator, object) => {
return accumulator + object.amountSpecial;
}, 0);
const data = { const data = {
total: salaryOrg.total, total: salaryOrg.total,
fifteenPercent: salaryOrg.fifteenPercent, fifteenPercent: salaryOrg.fifteenPercent,
@ -129,6 +132,8 @@ export class SalaryPeriodController extends Controller {
sixPercentSpentAmount: salaryOrg.sixPercentAmount - salaryOrg.spentAmount, sixPercentSpentAmount: salaryOrg.sixPercentAmount - salaryOrg.spentAmount,
useAmount: salaryOrg.useAmount, useAmount: salaryOrg.useAmount,
remainingAmount: salaryOrg.remainingAmount, remainingAmount: salaryOrg.remainingAmount,
totalAmountSpecial: sum,
totalBackup: salaryOrg.salaryProfiles.filter((x) => x.isReserve == true).length,
}; };
return new HttpSuccess(data); return new HttpSuccess(data);
} }
@ -175,7 +180,9 @@ export class SalaryPeriodController extends Controller {
}) })
.getRawOne(); .getRawOne();
const calRemainAmount = const calRemainAmount =
salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
@ -246,8 +253,7 @@ export class SalaryPeriodController extends Controller {
if (salaryProfile.type == "NONE") { if (salaryProfile.type == "NONE") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount;
salaryProfile.amount == null ? 0 : salaryProfile.amount;
} else if (salaryProfile.type == "PENDING") { } else if (salaryProfile.type == "PENDING") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
@ -263,11 +269,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryHalf == null || salaryRanks.salaryHalf == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryHalf - salaryProfile.amount + salaryRanks.salaryHalfSpecial; : salaryRanks.salaryHalf - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryHalf == null salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf;
? 0
: salaryRanks.salaryHalf;
} else if (salaryProfile.type == "FULL") { } else if (salaryProfile.type == "FULL") {
salaryProfile.amountSpecial = salaryProfile.amountSpecial =
salaryRanks == null || salaryRanks.salaryFullSpecial == null salaryRanks == null || salaryRanks.salaryFullSpecial == null
@ -279,11 +283,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryFull == null || salaryRanks.salaryFull == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryFull - salaryProfile.amount + salaryRanks.salaryFullSpecial; : salaryRanks.salaryFull - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFull == null salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull;
? 0
: salaryRanks.salaryFull;
} else if (salaryProfile.type == "FULLHAFT") { } else if (salaryProfile.type == "FULLHAFT") {
salaryProfile.amountSpecial = salaryProfile.amountSpecial =
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null
@ -295,11 +297,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryFullHalf == null || salaryRanks.salaryFullHalf == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryFullHalf - salaryProfile.amount + salaryRanks.salaryFullHalfSpecial; : salaryRanks.salaryFullHalf - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFullHalf == null salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf;
? 0
: salaryRanks.salaryFullHalf;
} else { } else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
} }
@ -309,16 +309,18 @@ export class SalaryPeriodController extends Controller {
// หาจำนวน Quota คงเหลือ // หาจำนวน Quota คงเหลือ
if (salaryProfile.salaryOrg.snapshot == "SNAP1") { if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") { if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
const amountFullType = await this.salaryProfileRepository.count({ if (salaryProfile.isReserve == false) {
where: { const amountFullType = await this.salaryProfileRepository.count({
salaryOrgId: salaryProfile?.salaryOrg.id, where: {
type: "FULL", salaryOrgId: salaryProfile?.salaryOrg.id,
}, type: "FULL",
}); },
const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType; });
salaryProfile.salaryOrg.quantityUsed = amountFullType; const calRemainQuota = salaryProfile?.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota; salaryProfile.salaryOrg.quantityUsed = amountFullType;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
}
} else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") { } else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile") .createQueryBuilder("salaryProfile")
@ -329,7 +331,9 @@ export class SalaryPeriodController extends Controller {
}) })
.getRawOne(); .getRawOne();
const calRemainAmount = const calRemainAmount =
salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); await this.salaryOrgRepository.save(salaryProfile?.salaryOrg);
@ -369,16 +373,18 @@ export class SalaryPeriodController extends Controller {
// หาจำนวน Quota คงเหลือ // หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") { if (salaryOrg.snapshot == "SNAP1") {
if (salaryOrg.salaryPeriod.period == "APR") { if (salaryOrg.salaryPeriod.period == "APR") {
const amountFullType = await this.salaryProfileRepository.count({ if (salaryProfile.isReserve == false) {
where: { const amountFullType = await this.salaryProfileRepository.count({
salaryOrgId: salaryOrg.id, where: {
type: "FULL", salaryOrgId: salaryOrg.id,
}, type: "FULL",
}); },
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType; });
salaryOrg.quantityUsed = amountFullType; const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota; salaryOrg.quantityUsed = amountFullType;
await this.salaryOrgRepository.save(salaryOrg); salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
}
} else if (salaryOrg.salaryPeriod.period == "OCT") { } else if (salaryOrg.salaryPeriod.period == "OCT") {
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile") .createQueryBuilder("salaryProfile")
@ -388,7 +394,8 @@ export class SalaryPeriodController extends Controller {
type: In(["HAFT", "FULL", "FULLHAFT"]), type: In(["HAFT", "FULL", "FULLHAFT"]),
}) })
.getRawOne(); .getRawOne();
const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount = sumAmountUse.totalAmount; salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount; salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg); await this.salaryOrgRepository.save(salaryOrg);
@ -407,7 +414,7 @@ export class SalaryPeriodController extends Controller {
* @param {string} type NONE-> HAFT-> FULL->1 FULLHAFT->1.5 * @param {string} type NONE-> HAFT-> FULL->1 FULLHAFT->1.5
*/ */
@Post("change/type") @Post("change/type")
async changeType(@Body() body: { profileId: string; type: string }) { async changeType(@Body() body: { profileId: string; type: string; isReserve: boolean }) {
const salaryProfile = await this.salaryProfileRepository.findOne({ const salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"], relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: body.profileId }, where: { id: body.profileId },
@ -485,8 +492,7 @@ export class SalaryPeriodController extends Controller {
if (body.type == "NONE") { if (body.type == "NONE") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount;
salaryProfile.amount == null ? 0 : salaryProfile.amount;
} else if (body.type == "PENDING") { } else if (body.type == "PENDING") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
@ -502,11 +508,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryHalf == null || salaryRanks.salaryHalf == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryHalf - salaryProfile.amount + salaryRanks.salaryHalfSpecial; : salaryRanks.salaryHalf - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryHalf == null salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf;
? 0
: salaryRanks.salaryHalf;
} else if (body.type == "FULL") { } else if (body.type == "FULL") {
salaryProfile.amountSpecial = salaryProfile.amountSpecial =
salaryRanks == null || salaryRanks.salaryFullSpecial == null salaryRanks == null || salaryRanks.salaryFullSpecial == null
@ -518,11 +522,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryFull == null || salaryRanks.salaryFull == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryFull - salaryProfile.amount + salaryRanks.salaryFullSpecial; : salaryRanks.salaryFull - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFull == null salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull;
? 0
: salaryRanks.salaryFull;
} else if (body.type == "FULLHAFT") { } else if (body.type == "FULLHAFT") {
salaryProfile.amountSpecial = salaryProfile.amountSpecial =
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null
@ -534,31 +536,32 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryFullHalf == null || salaryRanks.salaryFullHalf == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryFullHalf - salaryProfile.amount + salaryRanks.salaryFullHalfSpecial; : salaryRanks.salaryFullHalf - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFullHalf == null salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf;
? 0
: salaryRanks.salaryFullHalf;
} else { } else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
} }
salaryProfile.type = body.type; salaryProfile.type = body.type;
salaryProfile.isReserve = body.isReserve;
await this.salaryProfileRepository.save(salaryProfile); await this.salaryProfileRepository.save(salaryProfile);
if (salaryProfile.salaryOrg) { if (salaryProfile.salaryOrg) {
// หาจำนวน Quota คงเหลือ // หาจำนวน Quota คงเหลือ
if (salaryProfile.salaryOrg.snapshot == "SNAP1") { if (salaryProfile.salaryOrg.snapshot == "SNAP1") {
if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") { if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") {
const amountFullType = await this.salaryProfileRepository.count({ if (body.isReserve == false) {
where: { const amountFullType = await this.salaryProfileRepository.count({
salaryOrgId: salaryProfile.salaryOrg.id, where: {
type: "FULL", salaryOrgId: salaryProfile.salaryOrg.id,
}, type: "FULL",
}); },
const calRemainQuota = salaryProfile.salaryOrg.fifteenPercent - amountFullType; });
salaryProfile.salaryOrg.quantityUsed = amountFullType; const calRemainQuota = salaryProfile.salaryOrg.fifteenPercent - amountFullType;
salaryProfile.salaryOrg.remainQuota = calRemainQuota; salaryProfile.salaryOrg.quantityUsed = amountFullType;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg); salaryProfile.salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg);
}
} else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") { } else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile") .createQueryBuilder("salaryProfile")
@ -569,7 +572,9 @@ export class SalaryPeriodController extends Controller {
}) })
.getRawOne(); .getRawOne();
const calRemainAmount = const calRemainAmount =
salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; salaryProfile.salaryOrg.sixPercentAmount -
sumAmountUse.totalAmount -
salaryProfile.salaryOrg.spentAmount;
salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryProfile.salaryOrg.remainingAmount = calRemainAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryProfile.salaryOrg); await this.salaryOrgRepository.save(salaryProfile.salaryOrg);
@ -652,6 +657,43 @@ export class SalaryPeriodController extends Controller {
return new HttpSuccess({ data: salaryProfile, total }); return new HttpSuccess({ data: salaryProfile, total });
} }
/**
* API
*
* @summary SLR_031 - #30
*
*/
@Put("org/property/{id}")
async editProperty(
@Path() id: string,
@Body()
body: {
isPunish: boolean;
isSuspension: boolean;
isAbsent: boolean;
isLeave: boolean;
},
@Request() request: { user: Record<string, any> },
) {
const salaryProfile = await this.salaryProfileRepository.findOne({
where: {
id: id,
},
});
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
}
salaryProfile.isPunish = body.isPunish;
salaryProfile.isSuspension = body.isSuspension;
salaryProfile.isAbsent = body.isAbsent;
salaryProfile.isLeave = body.isLeave;
salaryProfile.lastUpdateUserId = request.user.sub;
salaryProfile.lastUpdateFullName = request.user.name;
salaryProfile.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess();
}
/** /**
* API * API
* *
@ -664,7 +706,7 @@ export class SalaryPeriodController extends Controller {
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const salaryOrg = await this.salaryOrgRepository.findOne({ const salaryOrg = await this.salaryOrgRepository.findOne({
relations: ["salaryPeriod"], relations: ["salaryPeriod", "salaryProfiles"],
where: { where: {
id: requestBody.id, id: requestBody.id,
}, },
@ -744,8 +786,7 @@ export class SalaryPeriodController extends Controller {
if (salaryProfile.type == "NONE") { if (salaryProfile.type == "NONE") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount;
salaryProfile.amount == null ? 0 : salaryProfile.amount;
} else if (salaryProfile.type == "PENDING") { } else if (salaryProfile.type == "PENDING") {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
@ -761,11 +802,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryHalf == null || salaryRanks.salaryHalf == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryHalf - salaryProfile.amount + salaryRanks.salaryHalfSpecial; : salaryRanks.salaryHalf - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryHalf == null salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf;
? 0
: salaryRanks.salaryHalf;
} else if (salaryProfile.type == "FULL") { } else if (salaryProfile.type == "FULL") {
salaryProfile.amountSpecial = salaryProfile.amountSpecial =
salaryRanks == null || salaryRanks.salaryFullSpecial == null salaryRanks == null || salaryRanks.salaryFullSpecial == null
@ -777,11 +816,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryFull == null || salaryRanks.salaryFull == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryFull - salaryProfile.amount + salaryRanks.salaryFullSpecial; : salaryRanks.salaryFull - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFull == null salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull;
? 0
: salaryRanks.salaryFull;
} else if (salaryProfile.type == "FULLHAFT") { } else if (salaryProfile.type == "FULLHAFT") {
salaryProfile.amountSpecial = salaryProfile.amountSpecial =
salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null
@ -793,11 +830,9 @@ export class SalaryPeriodController extends Controller {
salaryRanks.salaryFullHalf == null || salaryRanks.salaryFullHalf == null ||
salaryProfile.amount == null salaryProfile.amount == null
? 0 ? 0
: salaryRanks.salaryFullHalf - salaryProfile.amount + salaryRanks.salaryFullHalfSpecial; : salaryRanks.salaryFullHalf - salaryProfile.amount;
salaryProfile.positionSalaryAmount = salaryProfile.positionSalaryAmount =
salaryRanks == null || salaryRanks.salaryFullHalf == null salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf;
? 0
: salaryRanks.salaryFullHalf;
} else { } else {
salaryProfile.amountSpecial = 0; salaryProfile.amountSpecial = 0;
salaryProfile.amountUse = 0; salaryProfile.amountUse = 0;
@ -814,6 +849,10 @@ export class SalaryPeriodController extends Controller {
// หาจำนวน Quota คงเหลือ // หาจำนวน Quota คงเหลือ
if (salaryOrg.snapshot == "SNAP1") { if (salaryOrg.snapshot == "SNAP1") {
if (salaryOrg.salaryPeriod.period == "APR") { if (salaryOrg.salaryPeriod.period == "APR") {
salaryOrg.total = salaryOrg.salaryProfiles.length;
salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100);
salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100;
const amountFullType = await this.salaryProfileRepository.count({ const amountFullType = await this.salaryProfileRepository.count({
where: { where: {
salaryOrgId: salaryOrg.id, salaryOrgId: salaryOrg.id,
@ -825,6 +864,10 @@ export class SalaryPeriodController extends Controller {
salaryOrg.remainQuota = calRemainQuota; salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg); await this.salaryOrgRepository.save(salaryOrg);
} else if (salaryOrg.salaryPeriod.period == "OCT") { } else if (salaryOrg.salaryPeriod.period == "OCT") {
const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount");
salaryOrg.currentAmount = totalProfile;
salaryOrg.sixPercentAmount = totalProfile * 0.06;
const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) const sumAmountUse = await AppDataSource.getRepository(SalaryProfile)
.createQueryBuilder("salaryProfile") .createQueryBuilder("salaryProfile")
.select("SUM(salaryProfile.amountUse)", "totalAmount") .select("SUM(salaryProfile.amountUse)", "totalAmount")
@ -833,7 +876,8 @@ export class SalaryPeriodController extends Controller {
type: In(["HAFT", "FULL", "FULLHAFT"]), type: In(["HAFT", "FULL", "FULLHAFT"]),
}) })
.getRawOne(); .getRawOne();
const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; const calRemainAmount =
salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount;
salaryOrg.useAmount = sumAmountUse.totalAmount; salaryOrg.useAmount = sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount; salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg); await this.salaryOrgRepository.save(salaryOrg);
@ -843,6 +887,26 @@ export class SalaryPeriodController extends Controller {
return new HttpSuccess(salaryProfile.id); return new HttpSuccess(salaryProfile.id);
} }
/**
* API
*
* @summary SLR_032 - #31
*
* @param {string} id Guid, *Id
*/
@Get("close/{id}")
async closeSalaryPeriod_ById(@Path() id: string) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id },
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
}
salaryPeriod.isClose = !salaryPeriod.isClose;
await this.salaryPeriodRepository.save(salaryPeriod);
return new HttpSuccess();
}
/** /**
* API * API
* *
@ -973,7 +1037,7 @@ export class SalaryPeriodController extends Controller {
"period", "period",
"isActive", "isActive",
"effectiveDate", "effectiveDate",
"isActive", "isClose",
"status", "status",
"year", "year",
"revisionId", "revisionId",
@ -1007,6 +1071,7 @@ export class SalaryPeriodController extends Controller {
"salaryPeriod.id", "salaryPeriod.id",
"salaryPeriod.period", "salaryPeriod.period",
"salaryPeriod.isActive", "salaryPeriod.isActive",
"salaryPeriod.isClose",
"salaryPeriod.effectiveDate", "salaryPeriod.effectiveDate",
"salaryPeriod.status", "salaryPeriod.status",
"salaryPeriod.year", "salaryPeriod.year",
@ -1096,60 +1161,61 @@ export class SalaryPeriodController extends Controller {
await this.salaryOrgRepository.save(salaryOrgNew); await this.salaryOrgRepository.save(salaryOrgNew);
}), }),
); );
if (salaryPeriod.period != "SPECIAL") {
await Promise.all( await Promise.all(
orgProfiles.map(async (profile: any) => { orgProfiles.map(async (profile: any) => {
let group = "GROUP1"; let group = "GROUP1";
if ( if (
(profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") || (profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") || (profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") || (profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") ||
(profile.posType == "อำนวยการ" && profile.posLevel == "สูง") || (profile.posType == "อำนวยการ" && profile.posLevel == "สูง") ||
(profile.posType == "บริหาร" && profile.posLevel == "ต้น") || (profile.posType == "บริหาร" && profile.posLevel == "ต้น") ||
(profile.posType == "บริหาร" && profile.posLevel == "สูง") (profile.posType == "บริหาร" && profile.posLevel == "สูง")
) { ) {
group = "GROUP2"; group = "GROUP2";
}
const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod.id,
rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
delete profile.id;
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? "PENDING" : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
} }
await this.salaryProfileRepository.save(salaryProfileNew); const salaryOrgNew = await this.salaryOrgRepository.findOne({
} where: {
}), salaryPeriodId: salaryPeriod.id,
); rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
delete profile.id;
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? "PENDING" : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
}),
);
}
const salaryOrgNew = await this.salaryOrgRepository.find({ const salaryOrgNew = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot }, where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
@ -1195,6 +1261,7 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.currentAmount = totalProfile; _salaryOrg.currentAmount = totalProfile;
_salaryOrg.sixPercentAmount = totalProfile * 0.06; _salaryOrg.sixPercentAmount = totalProfile * 0.06;
_salaryOrg.spentAmount = totalAmount; _salaryOrg.spentAmount = totalAmount;
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
} else { } else {
_salaryOrg.currentAmount = salaryOrgSnap1.currentAmount; _salaryOrg.currentAmount = salaryOrgSnap1.currentAmount;
_salaryOrg.sixPercentAmount = salaryOrgSnap1.sixPercentAmount; _salaryOrg.sixPercentAmount = salaryOrgSnap1.sixPercentAmount;
@ -1207,12 +1274,13 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.currentAmount = totalProfile; _salaryOrg.currentAmount = totalProfile;
_salaryOrg.sixPercentAmount = totalProfile * 0.06; _salaryOrg.sixPercentAmount = totalProfile * 0.06;
_salaryOrg.spentAmount = totalAmount; _salaryOrg.spentAmount = totalAmount;
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
} }
await this.salaryOrgRepository.save(_salaryOrg); await this.salaryOrgRepository.save(_salaryOrg);
}), }),
); );
} else { } else if (salaryPeriod.period == "APR") {
await Promise.all( await Promise.all(
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => { salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
if (snapshot == "SNAP2") { if (snapshot == "SNAP2") {
@ -1228,6 +1296,7 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.total = _salaryOrg.salaryProfiles.length; _salaryOrg.total = _salaryOrg.salaryProfiles.length;
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100); _salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100; _salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
} else { } else {
_salaryOrg.total = salaryOrgSnap1.total; _salaryOrg.total = salaryOrgSnap1.total;
_salaryOrg.fifteenPercent = salaryOrgSnap1.fifteenPercent; _salaryOrg.fifteenPercent = salaryOrgSnap1.fifteenPercent;
@ -1239,6 +1308,7 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.total = _salaryOrg.salaryProfiles.length; _salaryOrg.total = _salaryOrg.salaryProfiles.length;
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100); _salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100; _salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
} }
await this.salaryOrgRepository.save(_salaryOrg); await this.salaryOrgRepository.save(_salaryOrg);
@ -1374,58 +1444,60 @@ export class SalaryPeriodController extends Controller {
}), }),
); );
await Promise.all( if (salaryPeriod.period != "SPECIAL") {
orgProfiles.map(async (profile: any) => { await Promise.all(
let group = "GROUP1"; orgProfiles.map(async (profile: any) => {
if ( let group = "GROUP1";
(profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") || if (
(profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") || (profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") || (profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") ||
(profile.posType == "อำนวยการ" && profile.posLevel == "สูง") || (profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") ||
(profile.posType == "บริหาร" && profile.posLevel == "ต้น") || (profile.posType == "อำนวยการ" && profile.posLevel == "สูง") ||
(profile.posType == "บริหาร" && profile.posLevel == "สูง") (profile.posType == "บริหาร" && profile.posLevel == "ต้น") ||
) { (profile.posType == "บริหาร" && profile.posLevel == "สูง")
group = "GROUP2"; ) {
} group = "GROUP2";
const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod.id,
rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
} }
await this.salaryProfileRepository.save(salaryProfileNew); const salaryOrgNew = await this.salaryOrgRepository.findOne({
} where: {
}), salaryPeriodId: salaryPeriod.id,
); rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
}),
);
}
const salaryOrgNew = await this.salaryOrgRepository.find({ const salaryOrgNew = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot }, where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
@ -1471,6 +1543,7 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.currentAmount = totalProfile; _salaryOrg.currentAmount = totalProfile;
_salaryOrg.sixPercentAmount = totalProfile * 0.06; _salaryOrg.sixPercentAmount = totalProfile * 0.06;
_salaryOrg.spentAmount = totalAmount; _salaryOrg.spentAmount = totalAmount;
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
} else { } else {
_salaryOrg.currentAmount = salaryOrgSnap1.currentAmount; _salaryOrg.currentAmount = salaryOrgSnap1.currentAmount;
_salaryOrg.sixPercentAmount = salaryOrgSnap1.sixPercentAmount; _salaryOrg.sixPercentAmount = salaryOrgSnap1.sixPercentAmount;
@ -1483,12 +1556,13 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.currentAmount = totalProfile; _salaryOrg.currentAmount = totalProfile;
_salaryOrg.sixPercentAmount = totalProfile * 0.06; _salaryOrg.sixPercentAmount = totalProfile * 0.06;
_salaryOrg.spentAmount = totalAmount; _salaryOrg.spentAmount = totalAmount;
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
} }
await this.salaryOrgRepository.save(_salaryOrg); await this.salaryOrgRepository.save(_salaryOrg);
}), }),
); );
} else { } else if (salaryPeriod.period == "APR") {
await Promise.all( await Promise.all(
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => { salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
if (snapshot == "SNAP2") { if (snapshot == "SNAP2") {
@ -1504,6 +1578,7 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.total = _salaryOrg.salaryProfiles.length; _salaryOrg.total = _salaryOrg.salaryProfiles.length;
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100); _salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100; _salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
} else { } else {
_salaryOrg.total = salaryOrgSnap1.total; _salaryOrg.total = salaryOrgSnap1.total;
_salaryOrg.fifteenPercent = salaryOrgSnap1.fifteenPercent; _salaryOrg.fifteenPercent = salaryOrgSnap1.fifteenPercent;
@ -1515,6 +1590,7 @@ export class SalaryPeriodController extends Controller {
_salaryOrg.total = _salaryOrg.salaryProfiles.length; _salaryOrg.total = _salaryOrg.salaryProfiles.length;
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100); _salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100; _salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
} }
await this.salaryOrgRepository.save(_salaryOrg); await this.salaryOrgRepository.save(_salaryOrg);

View file

@ -16,6 +16,12 @@ export class SalaryPeriod extends EntityBase {
}) })
isActive: boolean; isActive: boolean;
@Column({
comment: "ปิดรอบ",
default: false,
})
isClose: boolean;
@Column({ @Column({
nullable: true, nullable: true,
type: "datetime", type: "datetime",

View file

@ -233,38 +233,45 @@ export class SalaryProfile extends EntityBase {
@Column({ @Column({
nullable: true, nullable: true,
comment: "ผลการประเมิน", comment: "ผลการประเมินผลการปฏิบัติราชการ",
default: null, default: null,
}) })
result: string; result: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ระยะเวลา", comment: "ระยะเวลาการปฏิบัติราชการในรอบครึ่งปี",
default: null, default: null,
}) })
duration: string; duration: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "การลงโทษ", comment: "การลงโทษทางวินัย",
default: null, default: false,
}) })
punish: string; isPunish: boolean;
@Column({ @Column({
nullable: true, nullable: true,
comment: "พักราชการ", comment: "พักราชการ",
default: null, default: false,
}) })
retired: string; isSuspension: boolean;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ขาดราชการ", comment: "ขาดราชการ",
default: null, default: false,
}) })
retired2: string; isAbsent: boolean;
@Column({
nullable: true,
comment: "วันลา",
default: false,
})
isLeave: boolean;
@Column({ @Column({
nullable: true, nullable: true,
@ -273,6 +280,13 @@ export class SalaryProfile extends EntityBase {
}) })
isRetired: boolean; isRetired: boolean;
@Column({
nullable: true,
comment: "สำรอง",
default: false,
})
isReserve: boolean;
@ManyToOne(() => SalaryOrg, (salaryOrg) => salaryOrg.salaryProfiles) @ManyToOne(() => SalaryOrg, (salaryOrg) => salaryOrg.salaryProfiles)
@JoinColumn({ name: "salaryOrgId" }) @JoinColumn({ name: "salaryOrgId" })
salaryOrg: SalaryOrg; salaryOrg: SalaryOrg;
@ -361,13 +375,16 @@ export class CreateSalaryProfile {
duration: string | null; duration: string | null;
@Column() @Column()
punish: string | null; isPunish: boolean;
@Column() @Column()
retired: string | null; isSuspension: boolean;
@Column() @Column()
retired2: string | null; isAbsent: boolean;
@Column()
isLeave: boolean;
@Column() @Column()
isRetired: boolean; isRetired: boolean;

View file

@ -7,10 +7,10 @@ import { PosLevel } from "./PosLevel";
@Entity("salarys") @Entity("salarys")
export class Salarys extends EntityBase { export class Salarys extends EntityBase {
@Column({ @Column({
comment: "ประเภทผัง", comment: "ชื่อผัง",
length: 255, length: 255,
}) })
salaryType: string; name: string;
@Column({ @Column({
length: 40, length: 40,
@ -80,9 +80,8 @@ export class Salarys extends EntityBase {
} }
export class CreateSalary { export class CreateSalary {
@Column() @Column()
salaryType: string; name: string;
@Column("uuid") @Column("uuid")
posTypeId: string; posTypeId: string;
@ -94,13 +93,13 @@ export class CreateSalary {
isActive: boolean; isActive: boolean;
@Column() @Column()
date?: Date; date?: Date | null;
@Column() @Column()
startDate?: Date; startDate?: Date | null;
@Column() @Column()
endDate?: Date; endDate?: Date | null;
@Column() @Column()
details?: string | null; details?: string | null;
@ -110,9 +109,8 @@ export class CreateSalary {
} }
export class UpdateSalary { export class UpdateSalary {
@Column() @Column()
salaryType: string; name: string;
@Column("uuid") @Column("uuid")
posTypeId: string; posTypeId: string;
@ -124,13 +122,13 @@ export class UpdateSalary {
isActive: boolean; isActive: boolean;
@Column() @Column()
date?: Date; date?: Date | null;
@Column() @Column()
startDate?: Date; startDate?: Date | null;
@Column() @Column()
endDate?: Date; endDate?: Date | null;
@Column() @Column()
details?: string | null; details?: string | null;
@ -139,4 +137,4 @@ export class UpdateSalary {
isSpecial: boolean; isSpecial: boolean;
} }
// export type UpdateSalary = Partial<CreateSalary> ; // export type UpdateSalary = Partial<CreateSalary> ;

View file

@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class RenameFiels1709797298860 implements MigrationInterface {
name = 'RenameFiels1709797298860'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`salaryType\` \`name\` varchar(255) NOT NULL COMMENT 'ประเภทผัง'`);
await queryRunner.query(`ALTER TABLE \`salaryPeriod\` ADD \`isClose\` tinyint NOT NULL COMMENT 'ปิดรอบ' DEFAULT 0`);
await queryRunner.query(`ALTER TABLE \`salarys\` DROP COLUMN \`name\``);
await queryRunner.query(`ALTER TABLE \`salarys\` ADD \`name\` varchar(255) NOT NULL COMMENT 'ชื่อผัง'`);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountSpecial\` \`amountSpecial\` double NOT NULL COMMENT 'เงินพิเศษ' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountUse\` \`amountUse\` double NOT NULL COMMENT 'จำนวนเงินที่ใช้เลื่อน' DEFAULT '0'`);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`positionSalaryAmount\` \`positionSalaryAmount\` double NOT NULL COMMENT 'เงินเดือนหลังเลื่อน' DEFAULT '0'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`positionSalaryAmount\` \`positionSalaryAmount\` double NULL COMMENT 'เงินเดือนหลังเลื่อน'`);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountUse\` \`amountUse\` double NULL COMMENT 'จำนวนเงินที่ใช้เลื่อน'`);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`amountSpecial\` \`amountSpecial\` double NULL COMMENT 'เงินพิเศษ'`);
await queryRunner.query(`ALTER TABLE \`salarys\` DROP COLUMN \`name\``);
await queryRunner.query(`ALTER TABLE \`salarys\` ADD \`name\` varchar(255) NOT NULL COMMENT 'ประเภทผัง'`);
await queryRunner.query(`ALTER TABLE \`salaryPeriod\` DROP COLUMN \`isClose\``);
await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`name\` \`salaryType\` varchar(255) NOT NULL COMMENT 'ประเภทผัง'`);
}
}

View file

@ -0,0 +1,63 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableSalaryProfileAddIsClose1709801227584 implements MigrationInterface {
name = "UpdateTableSalaryProfileAddIsClose1709801227584";
public async up(queryRunner: QueryRunner): Promise<void> {
// await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`salaryType\` \`name\` varchar(255) NOT NULL COMMENT 'ประเภทผัง'`);
// await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`punish\``);
// await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`retired\``);
// await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`retired2\``);
// await queryRunner.query(`ALTER TABLE \`salaryPeriod\` ADD \`isClose\` tinyint NOT NULL COMMENT 'ปิดรอบ' DEFAULT 0`);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` ADD \`isPunish\` tinyint NULL COMMENT 'การลงโทษทางวินัย' DEFAULT 0`,
);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` ADD \`isSuspension\` tinyint NULL COMMENT 'พักราชการ' DEFAULT 0`,
);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` ADD \`isAbsent\` tinyint NULL COMMENT 'ขาดราชการ' DEFAULT 0`,
);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` ADD \`isLeave\` tinyint NULL COMMENT 'วันลา' DEFAULT 0`,
);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` ADD \`isReserve\` tinyint NULL COMMENT 'สำรอง' DEFAULT 0`,
);
// await queryRunner.query(`ALTER TABLE \`salarys\` DROP COLUMN \`name\``);
// await queryRunner.query(`ALTER TABLE \`salarys\` ADD \`name\` varchar(255) NOT NULL COMMENT 'ชื่อผัง'`);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` CHANGE \`result\` \`result\` varchar(255) NULL COMMENT 'ผลการประเมินผลการปฏิบัติราชการ'`,
);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` CHANGE \`duration\` \`duration\` varchar(255) NULL COMMENT 'ระยะเวลาการปฏิบัติราชการในรอบครึ่งปี'`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` CHANGE \`duration\` \`duration\` varchar(255) NULL COMMENT 'ระยะเวลา'`,
);
await queryRunner.query(
`ALTER TABLE \`salaryProfile\` CHANGE \`result\` \`result\` varchar(255) NULL COMMENT 'ผลการประเมิน'`,
);
// await queryRunner.query(`ALTER TABLE \`salarys\` DROP COLUMN \`name\``);
// await queryRunner.query(`ALTER TABLE \`salarys\` ADD \`name\` varchar(255) NOT NULL COMMENT 'ประเภทผัง'`);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`isReserve\``);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`isLeave\``);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`isAbsent\``);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`isSuspension\``);
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`isPunish\``);
// await queryRunner.query(`ALTER TABLE \`salaryPeriod\` DROP COLUMN \`isClose\``);
// await queryRunner.query(
// `ALTER TABLE \`salaryProfile\` ADD \`retired2\` varchar(255) NULL COMMENT 'ขาดราชการ'`,
// );
// await queryRunner.query(
// `ALTER TABLE \`salaryProfile\` ADD \`retired\` varchar(255) NULL COMMENT 'พักราชการ'`,
// );
// await queryRunner.query(
// `ALTER TABLE \`salaryProfile\` ADD \`punish\` varchar(255) NULL COMMENT 'การลงโทษ'`,
// );
// await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`name\` \`salaryType\` varchar(255) NOT NULL COMMENT 'ประเภทผัง'`);
}
}