Merge branch 'develop'
* develop: update update fix update report + migrate fix migrate update 3 4 update update report3 report 3 (test)
This commit is contained in:
commit
c452de859a
5 changed files with 483 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { Controller, Get, Post, Route, Security, Tags, Body, Path } from "tsoa";
|
import { Controller, Get, Post, Route, Security, Tags, Body, Path, Query } from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
|
|
@ -9,13 +9,15 @@ import { PosType } from "../entities/PosType";
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
import Extension from "../interfaces/extension";
|
import Extension from "../interfaces/extension";
|
||||||
import { DevelopmentScholarship } from "../entities/DevelopmentScholarship";
|
import { DevelopmentScholarship } from "../entities/DevelopmentScholarship";
|
||||||
import { IsNull, Not } from "typeorm";
|
import { In, IsNull, Not } from "typeorm";
|
||||||
|
import { viewDevScholarship } from "../entities/view/viewDevScholarship";
|
||||||
|
import { isNotEmittedStatement } from "typescript";
|
||||||
@Route("api/v1/development/report")
|
@Route("api/v1/development/report")
|
||||||
@Tags("Report")
|
@Tags("Report")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
export class ReportController extends Controller {
|
export class ReportController extends Controller {
|
||||||
private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship);
|
private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship);
|
||||||
|
private viewDevScholarship = AppDataSource.getRepository(viewDevScholarship);
|
||||||
/**
|
/**
|
||||||
* API Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด
|
* API Report รายการโครงการ/หลักสูตรการฝึกอบรมที่หน่วยงานของกรุงเทพมหานครเป็นผู้จัด
|
||||||
*
|
*
|
||||||
|
|
@ -24,7 +26,10 @@ export class ReportController extends Controller {
|
||||||
* @param {string} type type ประเภท report
|
* @param {string} type type ประเภท report
|
||||||
*/
|
*/
|
||||||
@Get("main")
|
@Get("main")
|
||||||
async GetReportDevelopemtMain(/*@Path() type: string*/) {
|
async GetReportDevelopemtMain(
|
||||||
|
@Query("year") year?: number,
|
||||||
|
@Query("rootId") rootId?: string,
|
||||||
|
) {
|
||||||
|
|
||||||
// const _type = type.trim().toUpperCase();
|
// const _type = type.trim().toUpperCase();
|
||||||
const formattedData = {
|
const formattedData = {
|
||||||
|
|
@ -563,14 +568,82 @@ export class ReportController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("report3")
|
@Get("report3")
|
||||||
async report3() {
|
async report3(
|
||||||
|
@Query("year") year?: number,
|
||||||
|
@Query("rootId") rootId?: string,
|
||||||
|
) {
|
||||||
|
const developments = await AppDataSource.getRepository(DevelopmentScholarship)
|
||||||
|
.createQueryBuilder("developmentScholarship")
|
||||||
|
.leftJoinAndSelect("developmentScholarship.posLevel", "posLevel")
|
||||||
|
.leftJoinAndSelect("developmentScholarship.posType", "posType")
|
||||||
|
.andWhere(
|
||||||
|
year !== 0 && year != null && year != undefined
|
||||||
|
? "developmentScholarship.scholarshipYear = :scholarshipYear"
|
||||||
|
: "1=1",
|
||||||
|
{ scholarshipYear: year },
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
rootId != "" && rootId != null && rootId != undefined
|
||||||
|
? "developmentScholarship.rootId = :rootId"
|
||||||
|
: "1=1",
|
||||||
|
{ rootId: rootId },
|
||||||
|
)
|
||||||
|
.orderBy("developmentScholarship.scholarshipYear", "DESC")
|
||||||
|
.addOrderBy("developmentScholarship.createdAt", "DESC")
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
const mapData = developments.map((item, idx:number) => ({
|
||||||
|
no: Extension.ToThaiNumber((idx+1).toString()),
|
||||||
|
institution: item.educationalInstitution ? item.educationalInstitution : "-",
|
||||||
|
scholarshipType: item.scholarshipType ?
|
||||||
|
item.scholarshipType == "DOMESTICE"
|
||||||
|
? "การศึกษาในประเทศ"
|
||||||
|
: item.scholarshipType == "NOABROAD"
|
||||||
|
? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"
|
||||||
|
: item.scholarshipType == "ABROAD"
|
||||||
|
? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"
|
||||||
|
: item.scholarshipType == "EXECUTIVE"
|
||||||
|
? "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"
|
||||||
|
: item.scholarshipType == "RESEARCH"
|
||||||
|
? "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ"
|
||||||
|
: "-"
|
||||||
|
: "-",
|
||||||
|
degreeLevel: item.degreeLevel ? item.degreeLevel : "-",
|
||||||
|
course: item.course ? item.course : "-",
|
||||||
|
field: item.field ? item.field : "-",
|
||||||
|
fullName: `${item.prefix}${item.firstName} ${item.lastName}`,
|
||||||
|
position: item.position ? item.position : "-",
|
||||||
|
posLevel: item.posLevel ? item.posLevel.posLevelName : "-",
|
||||||
|
totalPeriod: item.totalPeriod ? item.totalPeriod : "-",
|
||||||
|
budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) : "๐"
|
||||||
|
}));
|
||||||
|
|
||||||
|
const sum = developments
|
||||||
|
.filter(x => x.budgetApprove)
|
||||||
|
.reduce((acc, item) => acc + (Number(item.budgetApprove)), 0);
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
template: "reportFund3",
|
template: "reportFund3",
|
||||||
reportName: "reportFund3",
|
reportName: "reportFund3",
|
||||||
data: {
|
data: {
|
||||||
data: "",
|
year: year ? Extension.ToThaiNumber((year+543).toString()) : "-",
|
||||||
|
root: rootId ? developments.length > 0 ? developments.find(x => x.root != "")?.root: "-" : "-",
|
||||||
|
data: mapData.length > 0
|
||||||
|
? mapData
|
||||||
|
: [{
|
||||||
|
no: "-",
|
||||||
|
institution: "-",
|
||||||
|
scholarshipType: "-",
|
||||||
|
degreeLevel: "-",
|
||||||
|
course: "-",
|
||||||
|
field: "-",
|
||||||
|
fullName: "-",
|
||||||
|
position: "-",
|
||||||
|
posLevel: "-",
|
||||||
|
totalPeriod: "-",
|
||||||
|
budgetApprove: "-",
|
||||||
|
}],
|
||||||
|
sum: sum ? Extension.ToThaiNumber(sum.toLocaleString()): "-"
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -581,14 +654,143 @@ export class ReportController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("report4")
|
@Get("report4")
|
||||||
async report4() {
|
async report4(
|
||||||
|
@Query("year") year?: number,
|
||||||
|
) {
|
||||||
|
const developments = await AppDataSource.getRepository(DevelopmentScholarship)
|
||||||
|
.createQueryBuilder("developmentScholarship")
|
||||||
|
.andWhere(
|
||||||
|
year !== 0 && year != null && year != undefined
|
||||||
|
? "developmentScholarship.scholarshipYear = :scholarshipYear"
|
||||||
|
: "1=1",
|
||||||
|
{ scholarshipYear: year },
|
||||||
|
)
|
||||||
|
.orderBy("developmentScholarship.scholarshipYear", "DESC")
|
||||||
|
.addOrderBy("developmentScholarship.createdAt", "DESC")
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
// const _develop = await this.developmentScholarshipRepository.find({
|
||||||
|
// where: {
|
||||||
|
// scholarshipYear: year ? year : Not(IsNull())
|
||||||
|
// },
|
||||||
|
// order: { "scholarshipYear" : "DESC" }
|
||||||
|
// })
|
||||||
|
|
||||||
|
const groupDevelopment = Array.isArray(developments) && developments.length > 0
|
||||||
|
? developments.reduce((acc:any, current:any, idx:number) => {
|
||||||
|
const root = current.root || "";
|
||||||
|
if (!acc[root]) {
|
||||||
|
acc[root] = {
|
||||||
|
no: (idx+1),
|
||||||
|
root: root,
|
||||||
|
Bachelor : 0,
|
||||||
|
BachelorHight: 0,
|
||||||
|
Master: 0,
|
||||||
|
Doctor: 0,
|
||||||
|
DomesticeCourseCount: 0,
|
||||||
|
DomesticeProfileCount: 0,
|
||||||
|
DomesticeBudgetApprove: 0,
|
||||||
|
NoAbroadCourseCount: 0,
|
||||||
|
NoAbroadDProfileCount: 0,
|
||||||
|
NoAbroadBudgetApprove: 0,
|
||||||
|
AbroadCourseCount: 0,
|
||||||
|
AbroadProfileCount: 0,
|
||||||
|
AbroadBudgetApprove: 0,
|
||||||
|
ExecutiveCourseCount: 0,
|
||||||
|
ExecutiveProfileCount: 0,
|
||||||
|
ExecutiveBudgetApprove: 0,
|
||||||
|
TotalCourseCount: 0,
|
||||||
|
TotalProfileCount: 0,
|
||||||
|
TotalBudgetApprove: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (current.scholarshipType) {
|
||||||
|
case "DOMESTICE":
|
||||||
|
acc[root].DomesticeCourseCount++;
|
||||||
|
acc[root].DomesticeProfileCount++;
|
||||||
|
acc[root].DomesticeBudgetApprove += current.budgetApprove || 0;
|
||||||
|
break;
|
||||||
|
case "NOABROAD":
|
||||||
|
acc[root].NoAbroadCourseCount++;
|
||||||
|
acc[root].NoAbroadProfileCount++;
|
||||||
|
acc[root].NoAbroadBudgetApprove += current.budgetApprove || 0;
|
||||||
|
break;
|
||||||
|
case "ABROAD":
|
||||||
|
acc[root].AbroadCourseCount++;
|
||||||
|
acc[root].AbroadProfileCount++;
|
||||||
|
acc[root].AbroadBudgetApprove += current.budgetApprove || 0;
|
||||||
|
break;
|
||||||
|
case "EXECUTIVE":
|
||||||
|
acc[root].ExecutiveCourseCount++;
|
||||||
|
acc[root].ExecutiveProfileCount++;
|
||||||
|
acc[root].ExecutiveBudgetApprove += current.budgetApprove || 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
acc[root].TotalCourseCount = acc[root].DomesticeCourseCount + acc[root].NoAbroadCourseCount + acc[root].AbroadCourseCount + acc[root].ExecutiveCourseCount;
|
||||||
|
acc[root].TotalProfileCount = acc[root].DomesticeProfileCount + acc[root].NoAbroadProfileCount + acc[root].AbroadProfileCount + acc[root].ExecutiveProfileCount;
|
||||||
|
acc[root].TotalBudgetApprove = acc[root].DomesticeBudgetApprove + acc[root].NoAbroadBudgetApprove + acc[root].AbroadBudgetApprove + acc[root].ExecutiveBudgetApprove;
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const _group = Object.values(groupDevelopment);
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
template: "reportFund4",
|
template: "reportFund4",
|
||||||
reportName: "reportFund4",
|
reportName: "reportFund4",
|
||||||
data: {
|
data: {
|
||||||
data: "",
|
year: year ? Extension.ToThaiNumber((year+543).toString()) : "-",
|
||||||
|
data: Array.isArray(_group)
|
||||||
|
// ? _group
|
||||||
|
? _group.map((x:any) => ({
|
||||||
|
no: x.no ? Extension.ToThaiNumber(x.no.toString()) : "-",
|
||||||
|
root: x.root ? x.root : "-",
|
||||||
|
Bachelor : "-",
|
||||||
|
BachelorHight: "-",
|
||||||
|
Master: "-",
|
||||||
|
Doctor: "-",
|
||||||
|
DomesticeCourseCount: x.DomesticeCourseCount ? Extension.ToThaiNumber(x.DomesticeCourseCount.toLocaleString()) : "-",
|
||||||
|
DomesticeProfileCount: x.DomesticeProfileCount ? Extension.ToThaiNumber(x.DomesticeProfileCount.toLocaleString()) : "-",
|
||||||
|
DomesticeBudgetApprove: x.DomesticeBudgetApprove ? Extension.ToThaiNumber(x.DomesticeBudgetApprove.toLocaleString()) : "-",
|
||||||
|
NoAbroadCourseCount: x.NoAbroadCourseCount ? Extension.ToThaiNumber(x.NoAbroadCourseCount.toLocaleString()) : "-",
|
||||||
|
NoAbroadDProfileCount: x.NoAbroadDProfileCount ? Extension.ToThaiNumber(x.NoAbroadDProfileCount.toLocaleString()) : "-",
|
||||||
|
NoAbroadBudgetApprove: x.NoAbroadBudgetApprove ? Extension.ToThaiNumber(x.NoAbroadBudgetApprove.toLocaleString()) : "-",
|
||||||
|
AbroadCourseCount: x.AbroadCourseCount ? Extension.ToThaiNumber(x.AbroadCourseCount.toLocaleString()) : "-",
|
||||||
|
AbroadProfileCount: x.AbroadProfileCount ? Extension.ToThaiNumber(x.AbroadProfileCount.toLocaleString()) : "-",
|
||||||
|
AbroadBudgetApprove: x.AbroadBudgetApprove ? Extension.ToThaiNumber(x.AbroadBudgetApprove.toLocaleString()) : "-",
|
||||||
|
ExecutiveCourseCount: x.ExecutiveCourseCount ? Extension.ToThaiNumber(x.ExecutiveCourseCount.toLocaleString()) : "-",
|
||||||
|
ExecutiveProfileCount: x.ExecutiveProfileCount ? Extension.ToThaiNumber(x.ExecutiveProfileCount.toLocaleString()) : "-",
|
||||||
|
ExecutiveBudgetApprove: x.ExecutiveBudgetApprove ? Extension.ToThaiNumber(x.ExecutiveBudgetApprove.toLocaleString()) : "-",
|
||||||
|
TotalCourseCount: x.TotalCourseCount ? Extension.ToThaiNumber(x.TotalCourseCount.toLocaleString()) : "-",
|
||||||
|
TotalProfileCount: x.TotalProfileCount ? Extension.ToThaiNumber(x.TotalProfileCount.toLocaleString()) : "-",
|
||||||
|
TotalBudgetApprove: x.TotalBudgetApprove ? Extension.ToThaiNumber(x.TotalBudgetApprove.toLocaleString()) : "-",
|
||||||
|
}))
|
||||||
|
: [{
|
||||||
|
no: "-",
|
||||||
|
root: "-",
|
||||||
|
Bachelor : "-",
|
||||||
|
BachelorHight: "-",
|
||||||
|
Master: "-",
|
||||||
|
Doctor: "-",
|
||||||
|
DomesticeCourseCount: "-",
|
||||||
|
DomesticeProfileCount: "-",
|
||||||
|
DomesticeBudgetApprove: "-",
|
||||||
|
NoAbroadCourseCount: "-",
|
||||||
|
NoAbroadDProfileCount: "-",
|
||||||
|
NoAbroadBudgetApprove: "-",
|
||||||
|
AbroadCourseCount: "-",
|
||||||
|
AbroadProfileCount: "-",
|
||||||
|
AbroadBudgetApprove: "-",
|
||||||
|
ExecutiveCourseCount: "-",
|
||||||
|
ExecutiveProfileCount: "-",
|
||||||
|
ExecutiveBudgetApprove: "-",
|
||||||
|
TotalCourseCount: "-",
|
||||||
|
TotalProfileCount: "-",
|
||||||
|
TotalBudgetApprove: "-",
|
||||||
|
}],
|
||||||
|
totalRoot: Array.isArray(_group) ? Extension.ToThaiNumber(_group.length.toLocaleString()) : "-"
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -599,14 +801,75 @@ export class ReportController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("report5")
|
@Get("report5")
|
||||||
async report5() {
|
async report5(
|
||||||
|
@Query("year") year?: number,
|
||||||
|
// @Query("rootId") rootId: string,
|
||||||
|
) {
|
||||||
|
|
||||||
|
const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship)
|
||||||
|
.createQueryBuilder("developmentScholarship")
|
||||||
|
.leftJoinAndSelect("developmentScholarship.posLevel", "posLevel")
|
||||||
|
.leftJoinAndSelect("developmentScholarship.posType", "posType")
|
||||||
|
.leftJoinAndSelect("developmentScholarship.posLevelguarantor", "posLevelguarantor")
|
||||||
|
.leftJoinAndSelect("developmentScholarship.posTypeguarantor", "posTypeguarantor")
|
||||||
|
// .where("developmentScholarship.rootId = :rootId", { rootId: rootId })
|
||||||
|
.andWhere(
|
||||||
|
year !== 0 && year != null && year != undefined
|
||||||
|
? "developmentScholarship.scholarshipYear = :scholarshipYear"
|
||||||
|
: "1=1",
|
||||||
|
{ scholarshipYear: year },
|
||||||
|
)
|
||||||
|
.andWhere(
|
||||||
|
"developmentScholarship.scholarshipType = :scholarshipType", { scholarshipType: "RESEARCH" },
|
||||||
|
)
|
||||||
|
.orderBy("developmentScholarship.scholarshipYear", "DESC")
|
||||||
|
.addOrderBy("developmentScholarship.createdAt", "DESC")
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
|
const totalBudgetApprove = development.reduce((sum, item) => sum + Number(item.budgetApprove), 0);
|
||||||
|
const formattedData = development.map((item, index) => {
|
||||||
|
const rawPath = [
|
||||||
|
item.course == "-" ? null : item.course,
|
||||||
|
item.field == "-" ? null : item.course
|
||||||
|
];
|
||||||
|
|
||||||
|
const courseAndfield = rawPath
|
||||||
|
.filter((path) => path !== undefined && path !== null)
|
||||||
|
.join("/");
|
||||||
|
|
||||||
|
const date = [
|
||||||
|
Extension.ToThaiNumber(Extension.ToThaiShortDate(item.startDate)),
|
||||||
|
Extension.ToThaiNumber(Extension.ToThaiShortDate(item.endDate))
|
||||||
|
];
|
||||||
|
|
||||||
|
const dateDulation = date
|
||||||
|
.filter((path) => path !== undefined && path !== null)
|
||||||
|
.join(" - ");
|
||||||
|
|
||||||
|
return {
|
||||||
|
no: Extension.ToThaiNumber((index + 1).toString()),
|
||||||
|
id: item.id,
|
||||||
|
studyTopic: item.studyTopic ? item.studyTopic : "-",
|
||||||
|
fullName: item.prefix + item.firstName + " " + item.lastName,
|
||||||
|
position: item.position,
|
||||||
|
posLevel: item.posLevel ? item.posLevel.posLevelName : "-",
|
||||||
|
courseAndfield: courseAndfield ?? "-",
|
||||||
|
place: item.studyPlace ? item.studyPlace : "-",
|
||||||
|
country: item.studyCountry ? item.studyCountry : "-",
|
||||||
|
startAndendDate: dateDulation,
|
||||||
|
budgetApprove: item.budgetApprove ? Extension.ToThaiNumber(item.budgetApprove.toLocaleString()) : "-",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
template: "reportFund5",
|
template: "reportFund5",
|
||||||
reportName: "reportFund5",
|
reportName: "reportFund5",
|
||||||
data: {
|
data: {
|
||||||
data: "",
|
year: year?Extension.ToThaiNumber((year+543).toString()):"",
|
||||||
|
data: formattedData,
|
||||||
|
total: Extension.ToThaiNumber(total.toLocaleString()),
|
||||||
|
totalBudgetApprove: Extension.ToThaiNumber(totalBudgetApprove.toLocaleString()),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -617,14 +880,103 @@ export class ReportController extends Controller {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("report6")
|
@Get("report6")
|
||||||
async report6() {
|
async report6(
|
||||||
|
@Query("year") year?: number,
|
||||||
|
) {
|
||||||
|
const degree = [
|
||||||
|
"ปริญญาเอก",
|
||||||
|
"ปริญญาโท",
|
||||||
|
"ปริญญาตรี",
|
||||||
|
];
|
||||||
|
|
||||||
|
const development = await this.viewDevScholarship.find({
|
||||||
|
where: {
|
||||||
|
rootId: Not(IsNull()),
|
||||||
|
degreeLevel: In(degree),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupedData = development.reduce((acc:any, item:any) => {
|
||||||
|
const { rootId, root, degreeLevel, scholarshipType, budgetApprove } = item;
|
||||||
|
|
||||||
|
if (!acc[rootId]) {
|
||||||
|
acc[rootId] = {
|
||||||
|
root,
|
||||||
|
rootId,
|
||||||
|
degreeLevel1: {
|
||||||
|
numberOfRecords: 0,
|
||||||
|
numberOfScholarshipTypes: 0,
|
||||||
|
totalBudgetApprove: 0,
|
||||||
|
},
|
||||||
|
degreeLevel2: {
|
||||||
|
numberOfRecords: 0,
|
||||||
|
numberOfScholarshipTypes: 0,
|
||||||
|
totalBudgetApprove: 0,
|
||||||
|
},
|
||||||
|
degreeLevel3: {
|
||||||
|
numberOfRecords: 0,
|
||||||
|
numberOfScholarshipTypes: 0,
|
||||||
|
totalBudgetApprove: 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (degreeLevel === "ปริญญาตรี") {
|
||||||
|
acc[rootId].degreeLevel1.numberOfRecords += Number(item.numberOfRecords);
|
||||||
|
acc[rootId].degreeLevel1.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes);
|
||||||
|
acc[rootId].degreeLevel1.totalBudgetApprove += Number(item.totalBudgetApprove);
|
||||||
|
} else if (degreeLevel === "ปริญญาโท") {
|
||||||
|
acc[rootId].degreeLevel2.numberOfRecords += Number(item.numberOfRecords);
|
||||||
|
acc[rootId].degreeLevel2.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes);
|
||||||
|
acc[rootId].degreeLevel2.totalBudgetApprove += Number(item.totalBudgetApprove);
|
||||||
|
} else if (degreeLevel === "ปริญญาเอก") {
|
||||||
|
acc[rootId].degreeLevel3.numberOfRecords += Number(item.numberOfRecords);
|
||||||
|
acc[rootId].degreeLevel3.numberOfScholarshipTypes += Number(item.numberOfScholarshipTypes);
|
||||||
|
acc[rootId].degreeLevel3.totalBudgetApprove += Number(item.totalBudgetApprove);
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const formattedData = Object.values(groupedData).map((item: any, index: any) => {
|
||||||
|
const sumnumberOfRecords = item.degreeLevel1.numberOfRecords + item.degreeLevel2.numberOfRecords + item.degreeLevel3.numberOfRecords;
|
||||||
|
const sumnumberOfScholarshipTypes = item.degreeLevel1.numberOfScholarshipTypes + item.degreeLevel2.numberOfScholarshipTypes + item.degreeLevel3.numberOfScholarshipTypes;
|
||||||
|
const sumtotalBudgetApprove = item.degreeLevel1.totalBudgetApprove + item.degreeLevel2.totalBudgetApprove + item.degreeLevel3.totalBudgetApprove;
|
||||||
|
|
||||||
|
return {
|
||||||
|
no: index ? Extension.ToThaiNumber((index + 1).toString()) : "๑",
|
||||||
|
rootId: item.rootId ? item.rootId : "-",
|
||||||
|
root: item.root ? item.root : "-",
|
||||||
|
degreeLevel1: "ปริญญาตรี",
|
||||||
|
numberOfRecords1: item.degreeLevel1.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel1.numberOfRecords.toString()) : "-",
|
||||||
|
numberOfScholarshipTypes1: item.degreeLevel1.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel1.numberOfScholarshipTypes.toString()) : "-",
|
||||||
|
totalBudgetApprove1: item.degreeLevel1.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel1.totalBudgetApprove.toLocaleString()) : "-",
|
||||||
|
|
||||||
|
degreeLevel2: "ปริญญาโท",
|
||||||
|
numberOfRecords2: item.degreeLevel2.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel2.numberOfRecords.toString()) : "-",
|
||||||
|
numberOfScholarshipTypes2: item.degreeLevel2.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel2.numberOfScholarshipTypes.toString()) : "-",
|
||||||
|
totalBudgetApprove2: item.degreeLevel2.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel2.totalBudgetApprove.toLocaleString()) : "-",
|
||||||
|
|
||||||
|
degreeLevel3: "ปริญญาเอก",
|
||||||
|
numberOfRecords3: item.degreeLevel3.numberOfRecords ? Extension.ToThaiNumber(item.degreeLevel3.numberOfRecords.toString()) : "-",
|
||||||
|
numberOfScholarshipTypes3: item.degreeLevel3.numberOfScholarshipTypes ? Extension.ToThaiNumber(item.degreeLevel3.numberOfScholarshipTypes.toString()) : "-",
|
||||||
|
totalBudgetApprove3: item.degreeLevel3.totalBudgetApprove ? Extension.ToThaiNumber(item.degreeLevel3.totalBudgetApprove.toLocaleString()) : "-",
|
||||||
|
|
||||||
|
totalNumberOfRecords: Extension.ToThaiNumber(sumnumberOfRecords.toString()),
|
||||||
|
totalNumberOfScholarshipTypes: Extension.ToThaiNumber(sumnumberOfScholarshipTypes.toString()),
|
||||||
|
totalTotalBudgetApprove: Extension.ToThaiNumber(sumtotalBudgetApprove.toLocaleString())
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const uniqueRoots = new Set(formattedData.map(item => item.root));
|
||||||
|
const numberOfORG = uniqueRoots.size;
|
||||||
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
template: "reportFund6",
|
template: "reportFund6",
|
||||||
reportName: "reportFund6",
|
reportName: "reportFund6",
|
||||||
data: {
|
data: {
|
||||||
data: "",
|
year: year?Extension.ToThaiNumber((year+543).toString()):"",
|
||||||
|
data: formattedData,
|
||||||
|
coutOrg: numberOfORG?Extension.ToThaiNumber(numberOfORG.toString())+" หน่วยงาน":"๐ หน่วยงาน"
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
src/entities/view/viewDevScholarship.ts
Normal file
28
src/entities/view/viewDevScholarship.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { ViewColumn, ViewEntity } from "typeorm";
|
||||||
|
|
||||||
|
@ViewEntity({
|
||||||
|
expression: `SELECT MAX(\`rootId\`) AS rootId,
|
||||||
|
MAX(\`root\`) AS root,\`degreeLevel\`,
|
||||||
|
COUNT(*) AS numberOfRecords,
|
||||||
|
COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes,
|
||||||
|
SUM(\`budgetApprove\`) AS totalBudgetApprove
|
||||||
|
FROM \`developmentScholarship\`
|
||||||
|
GROUP BY \`rootId\`,\`degreeLevel\`
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
export class viewDevScholarship {
|
||||||
|
@ViewColumn()
|
||||||
|
rootId: string;
|
||||||
|
@ViewColumn()
|
||||||
|
root: string;
|
||||||
|
@ViewColumn()
|
||||||
|
degreeLevel: string;
|
||||||
|
@ViewColumn()
|
||||||
|
numberOfRecords: number;
|
||||||
|
@ViewColumn()
|
||||||
|
numberOfScholarshipTypes: number;
|
||||||
|
@ViewColumn()
|
||||||
|
totalBudgetApprove: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -30,6 +30,37 @@ class Extension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ToThaiShortMonth(value: number) {
|
||||||
|
switch (value) {
|
||||||
|
case 1:
|
||||||
|
return "ม.ค.";
|
||||||
|
case 2:
|
||||||
|
return "ก.พ.";
|
||||||
|
case 3:
|
||||||
|
return "มี.ค.";
|
||||||
|
case 4:
|
||||||
|
return "เม.ย.";
|
||||||
|
case 5:
|
||||||
|
return "พ.ค.";
|
||||||
|
case 6:
|
||||||
|
return "มิ.ย.";
|
||||||
|
case 7:
|
||||||
|
return "ก.ค.";
|
||||||
|
case 8:
|
||||||
|
return "ส.ค.";
|
||||||
|
case 9:
|
||||||
|
return "ก.ย.";
|
||||||
|
case 10:
|
||||||
|
return "ต.ค.";
|
||||||
|
case 11:
|
||||||
|
return "พ.ย.";
|
||||||
|
case 12:
|
||||||
|
return "ธ.ค.";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ToThaiYear(value: number) {
|
public static ToThaiYear(value: number) {
|
||||||
if (value < 2400) return value + 543;
|
if (value < 2400) return value + 543;
|
||||||
else return value;
|
else return value;
|
||||||
|
|
@ -86,6 +117,18 @@ class Extension {
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ToThaiShortDate(value: Date) {
|
||||||
|
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
||||||
|
return (
|
||||||
|
value.getDate() +
|
||||||
|
" " +
|
||||||
|
Extension.ToThaiShortMonth(value.getMonth() + 1) +
|
||||||
|
" " +
|
||||||
|
yy.toString().slice(-2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Extension;
|
export default Extension;
|
||||||
|
|
|
||||||
23
src/migration/1739444714910-updateView.ts
Normal file
23
src/migration/1739444714910-updateView.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class UpdateView1739444714910 implements MigrationInterface {
|
||||||
|
name = 'UpdateView1739444714910'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId,
|
||||||
|
MAX(\`root\`) AS root,\`degreeLevel\`,
|
||||||
|
COUNT(*) AS numberOfRecords,
|
||||||
|
COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes,
|
||||||
|
SUM(\`budgetApprove\`) AS totalBudgetApprove
|
||||||
|
FROM \`developmentScholarship\`
|
||||||
|
GROUP BY \`rootId\`,\`degreeLevel\`
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]);
|
||||||
|
await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
23
src/migration/1739446719623-update_viewDevScholarship.ts
Normal file
23
src/migration/1739446719623-update_viewDevScholarship.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class UpdateViewDevScholarship1739446719623 implements MigrationInterface {
|
||||||
|
name = 'UpdateViewDevScholarship1739446719623'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId,
|
||||||
|
MAX(\`root\`) AS root,\`degreeLevel\`,
|
||||||
|
COUNT(*) AS numberOfRecords,
|
||||||
|
COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes,
|
||||||
|
SUM(\`budgetApprove\`) AS totalBudgetApprove
|
||||||
|
FROM \`developmentScholarship\`
|
||||||
|
GROUP BY \`rootId\`,\`degreeLevel\`
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]);
|
||||||
|
await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue