report ขรก.

This commit is contained in:
Bright 2024-03-18 13:07:09 +07:00
parent 19a3af1cc8
commit 153d29557b
4 changed files with 508 additions and 715 deletions

View file

@ -1,284 +0,0 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
SuccessResponse,
Response,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { In, IsNull, Not } from "typeorm";
import { Salarys } from "../entities/Salarys";
import { SalaryRanks } from "../entities/SalaryRanks";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import Extension from "../interfaces/extension";
import { SalaryPeriod } from "../entities/SalaryPeriod";
import { SalaryProfile } from "../entities/SalaryProfile";
@Route("api/v1/salary/report")
@Tags("Report")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class Report2Controller extends Controller {
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
private salaryRepository = AppDataSource.getRepository(Salarys);
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
private poTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
/**
* API
*
* @summary
*
*/
@Get("report1/{rootId}/{salaryPeriodId}")
async SalaryReport1(@Path() rootId: string, @Path() salaryPeriodId: string) {
const salaryPeriodAPR = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
snapshot: "SNAP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
salaryPeriod: {
period: "APR",
},
},
},
order: {
orgShortName: "ASC",
posMasterNo: "ASC",
},
});
if (!salaryPeriodAPR) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const agency = salaryPeriodAPR[0]?.root;
const formattedData = salaryPeriodAPR.map((profile, index) => {
const fullNameParts = [
profile?.child4,
profile?.child3,
profile?.child2,
profile?.child1,
profile?.root,
`${profile?.prefix}${profile?.firstName} ${profile?.lastName}`,
];
const fullName = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName ? fullName : null,
posLevel: profile?.posLevel ? profile?.posLevel : null,
posNumber:
profile?.orgShortName + profile?.posMasterNo
? profile?.orgShortName + Extension.ToThaiNumber(profile?.posMasterNo.toLocaleString())
: null,
amount: profile?.amount ? Extension.ToThaiNumber(profile?.amount.toLocaleString()) : null,
reason: null,
};
});
return { agency: agency, data: formattedData };
}
/**
* API
*
* @summary
*
*/
@Get("report2/{rootId}/{salaryPeriodId}/{salaryOrgId}")
async SalaryReport2(
@Path() rootId: string,
@Path() salaryPeriodId: string,
@Path() salaryOrgId: string,
) {
// const counts = await AppDataSource.getRepository(SalaryProfile)
// .createQueryBuilder("salaryProfile")
// .leftJoin("salaryProfile.salaryOrg", "salaryOrg")
// .leftJoin("salaryOrg.salaryPeriod", "salaryPeriod")
// .where({
// salaryOrg: {
// rootId: rootId,
// salaryPeriodId: salaryPeriodId,
// group: "GROUP2",
// snapshot: "SNAP1",
// }
// })
// .select([
// "COUNT(CASE WHEN salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ทักษะพิเศษ' THEN 1 END) AS count1",
// "COUNT(CASE WHEN salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'เชี่ยวชาญ' THEN 1 END) AS count2",
// "COUNT(CASE WHEN salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ทรงคุณวุฒิ' THEN 1 END) AS count3",
// "COUNT(CASE WHEN salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'สูง' THEN 1 END) AS count4",
// "COUNT(CASE WHEN salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'ต้น' THEN 1 END) AS count5",
// "COUNT(CASE WHEN salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'สูง' THEN 1 END) AS count6",
// ])
// .getRawOne();
// const [data1,count1] = await this.salaryProfileRepository.findAndCount({
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
// where: {
// salaryOrg: {
// snapshot: "SNAP1",
// group: "GROUP2",
// rootId: rootId,
// salaryPeriodId: salaryPeriodId,
// salaryPeriod: {
// period: "APR",
// },
// },
// posType: "ทั่วไป",
// posLevel: "ทักษะพิเศษ",
// },
// select: ["posType", "posLevel"],
// });
// const [data2,count2] = await this.salaryProfileRepository.findAndCount({
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
// where: {
// salaryOrg: {
// snapshot: "SNAP1",
// group: "GROUP2",
// rootId: rootId,
// salaryPeriodId: salaryPeriodId,
// salaryPeriod: {
// period: "APR",
// },
// },
// posType: "วิชาการ",
// posLevel: "เชี่ยวชาญ",
// },
// select: ["posType", "posLevel"],
// });
// const [data3,count3] = await this.salaryProfileRepository.findAndCount({
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
// where: {
// salaryOrg: {
// snapshot: "SNAP1",
// group: "GROUP2",
// rootId: rootId,
// salaryPeriodId: salaryPeriodId,
// salaryPeriod: {
// period: "APR",
// },
// },
// posType: "วิชาการ",
// posLevel: "ทรงคุณวุฒิ",
// },
// select: ["posType", "posLevel"],
// });
// const [data4,count4] = await this.salaryProfileRepository.findAndCount({
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
// where: {
// salaryOrg: {
// snapshot: "SNAP1",
// group: "GROUP2",
// rootId: rootId,
// salaryPeriodId: salaryPeriodId,
// salaryPeriod: {
// period: "APR",
// },
// },
// posType: "อำนวยการ",
// posLevel: "สูง",
// },
// select: ["posType", "posLevel"],
// });
// const [data5,count5] = await this.salaryProfileRepository.findAndCount({
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
// where: {
// salaryOrg: {
// snapshot: "SNAP1",
// group: "GROUP2",
// rootId: rootId,
// salaryPeriodId: salaryPeriodId,
// salaryPeriod: {
// period: "APR",
// },
// },
// posType: "บริหาร",
// posLevel: "ต้น",
// },
// select: ["posType", "posLevel"],
// });
// const [data6,count6] = await this.salaryProfileRepository.findAndCount({
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
// where: {
// salaryOrg: {
// snapshot: "SNAP1",
// group: "GROUP2",
// rootId: rootId,
// salaryPeriodId: salaryPeriodId,
// salaryPeriod: {
// period: "APR",
// },
// },
// posType: "บริหาร",
// posLevel: "สูง",
// },
// select: ["posType", "posLevel"],
// });
const statistics = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
id: salaryOrgId,
snapshot: "SNAP1",
group: "GROUP2",
rootId: rootId,
salaryPeriod: {
id: salaryPeriodId,
period: "APR",
},
},
},
});
const notPromoSum =
(statistics[0]?.salaryOrg?.total ?? 0) - (statistics[0]?.salaryOrg?.fifteenPercent ?? 0);
const haftCount = statistics?.filter((item) => item.type === "HAFT").length ?? 0;
const data = {
group: statistics[0]?.salaryOrg.total ? "กลุ่ม 2" : "",
total: statistics[0]?.salaryOrg.total ? statistics[0]?.salaryOrg.total : "",
fifteenPercent: statistics[0]?.salaryOrg.fifteenPercent
? statistics[0]?.salaryOrg.fifteenPercent
: "",
full: statistics[0]?.salaryOrg.quantityUsed ? statistics[0]?.salaryOrg.quantityUsed : "",
remaining: statistics[0]?.salaryOrg.remainQuota ? statistics[0]?.salaryOrg.remainQuota : "",
haft: haftCount,
notPromoted: notPromoSum,
reason: null,
};
return data;
}
}

View file

@ -20,11 +20,14 @@ import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { In, IsNull, Not } from "typeorm";
import { In, Not, IsNull, MoreThan } from "typeorm";
import { Salarys } from "../entities/Salarys";
import { SalaryRanks } from "../entities/SalaryRanks";
import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import { SalaryPeriod } from "../entities/SalaryPeriod";
import { SalaryOrg } from "../entities/SalaryOrg";
import { SalaryProfile } from "../entities/SalaryProfile";
import Extension from "../interfaces/extension";
@Route("api/v1/salary/report")
@Tags("Report")
@ -39,6 +42,9 @@ export class ReportController extends Controller {
private salaryRankRepository = AppDataSource.getRepository(SalaryRanks);
private poTypeRepository = AppDataSource.getRepository(PosType);
private posLevelRepository = AppDataSource.getRepository(PosLevel);
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
/**
* API
@ -47,7 +53,7 @@ export class ReportController extends Controller {
*
* @param {string} id Guid, *Id
*/
@Get("{id}")
@Get("1/0/{id}")
async SalaryReport(@Path() id: string) {
const salarys = await this.salaryRepository.findOne({
where: { id: id }
@ -116,5 +122,501 @@ export class ReportController extends Controller {
salaryRanks: mapSalaryRank
}
});
}
}
/**
* API 1
*
* @summary 1
*
*/
@Get("1/1/{rootId}/{salaryPeriodId}")
async SalaryReport1(@Path() rootId: string, @Path() salaryPeriodId: string) {
const salaryPeriodAPR = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
snapshot: "SNAP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
salaryPeriod: {
period: "APR",
},
},
},
order: {
orgShortName: "ASC",
posMasterNo: "ASC",
},
});
if (!salaryPeriodAPR) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const agency = salaryPeriodAPR[0]?.root;
const formattedData = salaryPeriodAPR.map((profile, index) => {
const fullNameParts = [
profile?.child4,
profile?.child3,
profile?.child2,
profile?.child1,
profile?.root,
`${profile?.prefix}${profile?.firstName} ${profile?.lastName}`,
];
const fullName = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName ? fullName : null,
posLevel: profile?.posLevel ? profile?.posLevel : null,
posNumber:
profile?.orgShortName + profile?.posMasterNo
? profile?.orgShortName + Extension.ToThaiNumber(profile?.posMasterNo.toLocaleString())
: null,
amount: profile?.amount ? Extension.ToThaiNumber(profile?.amount.toLocaleString()) : null,
reason: null,
};
});
return { agency: agency, data: formattedData };
}
/**
* API
*
* @summary
*
*/
@Get("1/2/{rootId}/{salaryPeriodId}/{salaryOrgId}")
async SalaryReport2(
@Path() rootId: string,
@Path() salaryPeriodId: string,
@Path() salaryOrgId: string,
) {
const statistics = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
id: salaryOrgId,
snapshot: "SNAP1",
group: "GROUP2",
rootId: rootId,
salaryPeriod: {
id: salaryPeriodId,
period: "APR",
},
},
},
});
const notPromoSum =
(statistics[0]?.salaryOrg?.total ?? 0) - (statistics[0]?.salaryOrg?.fifteenPercent ?? 0);
const haftCount = statistics?.filter((item) => item.type === "HAFT").length ?? 0;
const data = {
group: statistics[0]?.salaryOrg.total ? "กลุ่ม 2" : "",
total: statistics[0]?.salaryOrg.total ? statistics[0]?.salaryOrg.total : "",
fifteenPercent: statistics[0]?.salaryOrg.fifteenPercent
? statistics[0]?.salaryOrg.fifteenPercent
: "",
full: statistics[0]?.salaryOrg.quantityUsed ? statistics[0]?.salaryOrg.quantityUsed : "",
remaining: statistics[0]?.salaryOrg.remainQuota ? statistics[0]?.salaryOrg.remainQuota : "",
haft: haftCount,
notPromoted: notPromoSum,
reason: null,
};
return data;
}
/**
* API
*
* @summary
*
* @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period
*/
@Get("1/3/{rootId}/{salaryPeriodId}")
async SalaryReport3(
// @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.salaryProfileRepository.find({
where: {
salaryOrgId: salaryOrg?.id,
type: "FULL", //หนึ่งขั้น
},
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,
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
amount:
item.amount == undefined || item.amount == null
? ""
: Extension.ToThaiNumber(String(item.amount)),
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
remark: null, //หมายเหตุ
})),
};
return mapData;
}
/**
* API 1
*
* @summary 1
*
* @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period
*/
@Get("1/4/{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.salaryProfileRepository.find({
where: { salaryOrgId: salaryOrg?.id },
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 + 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)),
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
remark: null, //หมายเหตุ
})),
};
return mapData;
}
/**
* API
*
* @summary
*
* @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period
*/
@Get("1/7/{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.salaryProfileRepository.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("1/8/{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.salaryProfileRepository.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.salaryProfileRepository.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

@ -1,428 +0,0 @@
import {
Controller,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
SuccessResponse,
Response,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { In, IsNull, Not, MoreThan } from "typeorm";
import { SalaryProfile } from "../entities/SalaryProfile";
import { SalaryPeriod } from "../entities/SalaryPeriod";
import { SalaryOrg } from "../entities/SalaryOrg";
import Extension from "../interfaces/extension";
@Route("api/v1/salary/report/1")
@Tags("Report")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class Report_1_Controller extends Controller {
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
private salaryProfile = AppDataSource.getRepository(SalaryProfile);
/**
* API 1
*
* @summary 1
*
* @param {string} rootId Guid, *Id Root
* @param {string} salaryPeriodId Guid, *Id Period
*/
@Get("03/{rootId}/{salaryPeriodId}")
async SalaryReport3(
// @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,
type: "FULL", //หนึ่งขั้น
},
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,
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
amount:
item.amount == undefined || item.amount == null
? ""
: Extension.ToThaiNumber(String(item.amount)),
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({
where: { salaryOrgId: salaryOrg?.id },
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 + 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)),
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
remark: null, //หมายเหตุ
})),
};
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

@ -34,6 +34,9 @@
},
{
"name": "SalaryRank", "description": "อัตราเงินเดือน"
},
{
"name": "Report", "description": "รายงานเงินเดือนข้าราชการ รอบเดือนเมษายน"
}
]
},