2024-04-09 11:38:13 +07:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Delete,
|
|
|
|
|
Route,
|
|
|
|
|
Security,
|
|
|
|
|
Tags,
|
|
|
|
|
Body,
|
|
|
|
|
Path,
|
|
|
|
|
Request,
|
|
|
|
|
Query,
|
|
|
|
|
} from "tsoa";
|
|
|
|
|
import { AppDataSource } from "../database/data-source";
|
|
|
|
|
import { Brackets, Not } from "typeorm";
|
|
|
|
|
import HttpSuccess from "../interfaces/http-success";
|
|
|
|
|
import HttpError from "../interfaces/http-error";
|
|
|
|
|
import HttpStatusCode from "../interfaces/http-status";
|
|
|
|
|
import { Development } from "../entities/Development";
|
|
|
|
|
import {
|
|
|
|
|
CreateDevelopmentHistory,
|
|
|
|
|
DevelopmentHistory,
|
|
|
|
|
UpdateDevelopmentHistory,
|
|
|
|
|
} from "../entities/DevelopmentHistory";
|
|
|
|
|
import { PosType } from "../entities/PosType";
|
|
|
|
|
import { PosLevel } from "../entities/PosLevel";
|
2024-04-11 18:02:03 +07:00
|
|
|
import Extension from "../interfaces/extension";
|
2024-04-13 20:47:28 +07:00
|
|
|
import { DevelopmentScholarship } from "../entities/DevelopmentScholarship";
|
2024-04-09 11:38:13 +07:00
|
|
|
@Route("api/v1/development/report")
|
|
|
|
|
@Tags("Report")
|
|
|
|
|
@Security("bearerAuth")
|
|
|
|
|
export class ReportController extends Controller {
|
|
|
|
|
private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory);
|
|
|
|
|
private developmentRepository = AppDataSource.getRepository(Development);
|
|
|
|
|
private posTypeRepository = AppDataSource.getRepository(PosType);
|
|
|
|
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
2024-04-13 20:47:28 +07:00
|
|
|
private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship);
|
2024-04-09 11:38:13 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด
|
|
|
|
|
*
|
|
|
|
|
* @summary DEV_0xx - Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด #xx
|
|
|
|
|
*
|
|
|
|
|
* @param {string} type type ประเภท report
|
|
|
|
|
*/
|
|
|
|
|
@Get("main/{type}")
|
|
|
|
|
async GetReportDevelopemtMain(@Path() type: string) {
|
2024-07-17 12:47:36 +07:00
|
|
|
// const _type = type.trim().toUpperCase();
|
2024-04-09 11:38:13 +07:00
|
|
|
const formattedData = {
|
2024-07-17 12:47:36 +07:00
|
|
|
org: "_type",
|
2024-04-09 11:38:13 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
|
|
|
|
template: "development",
|
|
|
|
|
reportName: "development",
|
|
|
|
|
data: {
|
|
|
|
|
data: formattedData,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API Report รายการประวัติการฝึกอบรม/ดูงานของข้าราชการกรุงเทพมหานครสามัญ
|
|
|
|
|
*
|
|
|
|
|
* @summary DEV_0xx - Report รายการประวัติการฝึกอบรม/ดูงานของข้าราชการกรุงเทพมหานครสามัญ #xx
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-04-13 20:47:28 +07:00
|
|
|
@Post("history-officer")
|
|
|
|
|
async PostReportDevelopemtHistoryOfficer(
|
|
|
|
|
@Body()
|
|
|
|
|
body: {
|
|
|
|
|
year: number;
|
|
|
|
|
root: string;
|
|
|
|
|
},
|
|
|
|
|
) {
|
2024-04-11 18:02:03 +07:00
|
|
|
const development = await AppDataSource.getRepository(DevelopmentHistory)
|
|
|
|
|
.createQueryBuilder("developmentHistory")
|
|
|
|
|
.leftJoinAndSelect("developmentHistory.posLevel", "posLevel")
|
|
|
|
|
.leftJoinAndSelect("developmentHistory.posType", "posType")
|
|
|
|
|
.leftJoinAndSelect("developmentHistory.development", "development")
|
2024-04-13 20:47:28 +07:00
|
|
|
.andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", {
|
|
|
|
|
year: body.year,
|
|
|
|
|
})
|
|
|
|
|
.andWhere(body.root != null ? "development.root = :root" : "1=1", {
|
|
|
|
|
root: body.root,
|
|
|
|
|
})
|
|
|
|
|
.andWhere("developmentHistory.type = :type", { type: "OFFICER" })
|
2024-04-11 18:02:03 +07:00
|
|
|
.select([
|
|
|
|
|
"developmentHistory.citizenId",
|
|
|
|
|
"developmentHistory.rank",
|
|
|
|
|
"developmentHistory.position",
|
|
|
|
|
"developmentHistory.posExecutive",
|
|
|
|
|
"developmentHistory.developmentId",
|
|
|
|
|
"developmentHistory.prefix",
|
|
|
|
|
"developmentHistory.firstName",
|
|
|
|
|
"developmentHistory.lastName",
|
|
|
|
|
"posLevel.posLevelName",
|
|
|
|
|
"posType.posTypeName",
|
|
|
|
|
"development.projectName",
|
2024-04-13 20:47:28 +07:00
|
|
|
"development.root",
|
2024-04-11 18:02:03 +07:00
|
|
|
])
|
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
|
|
const formattedData = development.map((item) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
citizenId: Extension.ToThaiNumber(item.citizenId.toString()),
|
|
|
|
|
fullName: item.prefix + item.firstName + " " + item.lastName,
|
|
|
|
|
position: item.position,
|
|
|
|
|
posType: item.posType ? item.posType.posTypeName : null,
|
|
|
|
|
posLevel: item.posLevel ? item.posLevel.posLevelName : null,
|
|
|
|
|
posExecutive: item.posExecutive,
|
|
|
|
|
projectName: item.development ? item.development.projectName : null,
|
2024-04-13 20:47:28 +07:00
|
|
|
root: item.root,
|
2024-04-11 18:02:03 +07:00
|
|
|
}));
|
2024-04-09 11:38:13 +07:00
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
2024-04-11 18:02:03 +07:00
|
|
|
template: "developmentHistoryOfficer",
|
|
|
|
|
reportName: "developmentHistoryOfficer",
|
2024-04-09 11:38:13 +07:00
|
|
|
data: {
|
|
|
|
|
data: formattedData,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API Report รายการประวัติฝึกอบรม/ดูงานลูกจ้าง
|
|
|
|
|
*
|
|
|
|
|
* @summary DEV_0xx - Report รายการประวัติฝึกอบรม/ดูงานลูกจ้าง #xx
|
|
|
|
|
*
|
2024-04-11 18:02:03 +07:00
|
|
|
* @param {number} year year ปี report
|
2024-04-09 11:38:13 +07:00
|
|
|
*/
|
2024-04-13 20:47:28 +07:00
|
|
|
@Post("history-employee")
|
|
|
|
|
async PostReportDevelopemtHistoryEmployee(
|
|
|
|
|
@Body()
|
|
|
|
|
body: {
|
|
|
|
|
year: number;
|
|
|
|
|
root: string;
|
|
|
|
|
},
|
|
|
|
|
) {
|
2024-04-11 18:02:03 +07:00
|
|
|
const development = await AppDataSource.getRepository(DevelopmentHistory)
|
|
|
|
|
.createQueryBuilder("developmentHistory")
|
|
|
|
|
.leftJoinAndSelect("developmentHistory.employeePosLevel", "employeePosLevel")
|
|
|
|
|
.leftJoinAndSelect("developmentHistory.employeePosType", "employeePosType")
|
|
|
|
|
.leftJoinAndSelect("developmentHistory.development", "development")
|
2024-04-13 20:47:28 +07:00
|
|
|
.andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", {
|
|
|
|
|
year: body.year,
|
|
|
|
|
})
|
|
|
|
|
.andWhere(body.root != null ? "development.root = :root" : "1=1", {
|
|
|
|
|
root: body.root,
|
|
|
|
|
})
|
|
|
|
|
.andWhere("developmentHistory.type = :type", { type: "EMPLOYEE" })
|
2024-04-11 18:02:03 +07:00
|
|
|
.select([
|
|
|
|
|
"developmentHistory.citizenId",
|
|
|
|
|
"developmentHistory.position",
|
|
|
|
|
"developmentHistory.developmentId",
|
|
|
|
|
"developmentHistory.prefix",
|
|
|
|
|
"developmentHistory.firstName",
|
|
|
|
|
"developmentHistory.lastName",
|
|
|
|
|
"employeePosLevel.posLevelName",
|
|
|
|
|
"employeePosType.posTypeName",
|
|
|
|
|
"employeePosType.posTypeShortName",
|
|
|
|
|
"development.projectName",
|
2024-04-13 20:47:28 +07:00
|
|
|
"development.root",
|
2024-04-11 18:02:03 +07:00
|
|
|
])
|
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
|
|
const formattedData = development.map((item) => ({
|
|
|
|
|
id: item.id,
|
|
|
|
|
citizenId: Extension.ToThaiNumber(item.citizenId.toString()),
|
|
|
|
|
fullName: item.prefix + item.firstName + " " + item.lastName,
|
|
|
|
|
position: item.position,
|
|
|
|
|
employeePosType: item.employeePosType ? item.employeePosType.posTypeName : null,
|
|
|
|
|
employeePosLevel:
|
|
|
|
|
item.employeePosType.posTypeShortName +
|
|
|
|
|
" " +
|
|
|
|
|
Extension.ToThaiNumber(item.employeePosLevel.posLevelName.toString()),
|
|
|
|
|
projectName: item.development ? item.development.projectName : null,
|
2024-04-13 20:47:28 +07:00
|
|
|
root: item.root,
|
2024-04-11 18:02:03 +07:00
|
|
|
}));
|
2024-04-09 11:38:13 +07:00
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
2024-04-11 18:02:03 +07:00
|
|
|
template: "developmentHistoryEmployee",
|
|
|
|
|
reportName: "developmentHistoryEmployee",
|
2024-04-09 11:38:13 +07:00
|
|
|
data: {
|
|
|
|
|
data: formattedData,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API Report รายการข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรม
|
|
|
|
|
*
|
|
|
|
|
* @summary DEV_0xx - Report รายการข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรม #xx
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("scholarship")
|
|
|
|
|
async GetReportDevelopemtScholarship() {
|
|
|
|
|
const formattedData = {
|
|
|
|
|
org: "_type",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
|
|
|
|
template: "development",
|
|
|
|
|
reportName: "development",
|
|
|
|
|
data: {
|
|
|
|
|
data: formattedData,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-13 20:47:28 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API Report ข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรมใน detail
|
|
|
|
|
*
|
|
|
|
|
* @summary DEV_0xx - Report ข้าราชการฯที่ได้รับทุนการศึกษา/ฝึกอบรมใน detail #xx
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id Id scholarship
|
|
|
|
|
*/
|
|
|
|
|
@Get("scholarship/{id}")
|
|
|
|
|
async GetReportDevelopemtScholarshipDetail(@Path() id: string) {
|
|
|
|
|
const getDevelopment = await this.developmentScholarshipRepository.findOne({
|
|
|
|
|
where: { id: id },
|
|
|
|
|
});
|
|
|
|
|
if (!getDevelopment) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้");
|
|
|
|
|
}
|
|
|
|
|
if (getDevelopment.scholarshipType != null) {
|
|
|
|
|
switch (getDevelopment.scholarshipType.trim().toUpperCase()) {
|
|
|
|
|
case "DOMESTICE":
|
|
|
|
|
getDevelopment.scholarshipType = "การศึกษาในประเทศ";
|
|
|
|
|
break;
|
|
|
|
|
case "NOABROAD":
|
|
|
|
|
getDevelopment.scholarshipType =
|
|
|
|
|
"ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)";
|
|
|
|
|
break;
|
|
|
|
|
case "ABROAD":
|
|
|
|
|
getDevelopment.scholarshipType =
|
|
|
|
|
"ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)";
|
|
|
|
|
break;
|
|
|
|
|
case "EXECUTIVE":
|
|
|
|
|
getDevelopment.scholarshipType =
|
|
|
|
|
"ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formattedData = {
|
|
|
|
|
id: getDevelopment.id,
|
|
|
|
|
firstName: getDevelopment.firstName,
|
|
|
|
|
lastName: getDevelopment.lastName,
|
|
|
|
|
position: getDevelopment.position,
|
2024-04-19 09:28:57 +07:00
|
|
|
org: getDevelopment.org,
|
2024-04-13 20:47:28 +07:00
|
|
|
degreeLevel: getDevelopment.degreeLevel,
|
|
|
|
|
course: getDevelopment.course,
|
|
|
|
|
field: getDevelopment.field,
|
|
|
|
|
studyPlace: getDevelopment.studyPlace,
|
|
|
|
|
scholarshipType: getDevelopment.scholarshipType,
|
2024-04-19 09:28:57 +07:00
|
|
|
bookNoDate:
|
|
|
|
|
getDevelopment.bookNoDate == null
|
|
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.bookNoDate)),
|
2024-04-13 20:47:28 +07:00
|
|
|
startDate:
|
|
|
|
|
getDevelopment.startDate == null
|
|
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.startDate)),
|
|
|
|
|
endDate:
|
|
|
|
|
getDevelopment.endDate == null
|
|
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.endDate)),
|
|
|
|
|
reportBackNo:
|
|
|
|
|
getDevelopment.reportBackNo == null
|
|
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(getDevelopment.reportBackNo),
|
|
|
|
|
reportBackNoDate:
|
|
|
|
|
getDevelopment.reportBackNoDate == null
|
|
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.reportBackNoDate)),
|
|
|
|
|
governmentDate:
|
|
|
|
|
getDevelopment.governmentDate == null
|
|
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.governmentDate)),
|
|
|
|
|
graduatedDate:
|
|
|
|
|
getDevelopment.graduatedDate == null
|
|
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(getDevelopment.graduatedDate)),
|
|
|
|
|
graduatedReason: getDevelopment.graduatedReason,
|
2024-04-30 11:48:23 +07:00
|
|
|
useOfficialTime: getDevelopment.useOfficialTime,
|
2024-07-17 12:49:07 +07:00
|
|
|
useOffTime: getDevelopment.useOfficialTime == true ? "🗹 ใช้ ☐ ไม่ใช้" : "☐ ใช้ 🗹 ไม่ใช้",
|
2024-05-17 10:05:15 +07:00
|
|
|
isGraduated: getDevelopment.isGraduated,
|
2024-07-17 12:49:07 +07:00
|
|
|
isG1: getDevelopment.isGraduated == true ? "🗹" : "☐",
|
|
|
|
|
isG2: getDevelopment.isGraduated == true ? "☐" : "🗹",
|
2024-07-17 12:47:36 +07:00
|
|
|
totalPeriod:
|
2024-05-17 10:05:15 +07:00
|
|
|
getDevelopment.totalPeriod == null || getDevelopment.totalPeriod == ""
|
2024-07-17 12:47:36 +07:00
|
|
|
? ""
|
|
|
|
|
: Extension.ToThaiNumber(getDevelopment.totalPeriod),
|
2024-04-13 20:47:28 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
|
|
|
|
template: "repatriation",
|
|
|
|
|
reportName: "repatriation",
|
|
|
|
|
data: formattedData,
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-09 11:38:13 +07:00
|
|
|
}
|