Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-02-13 17:35:38 +07:00
commit 3d7b32abbd

View file

@ -567,34 +567,66 @@ export class ReportController extends Controller {
@Query("year") year: number, @Query("year") year: number,
@Query("rootId") rootId?: string, @Query("rootId") rootId?: string,
) { ) {
const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) const developments = await AppDataSource.getRepository(DevelopmentScholarship)
.createQueryBuilder("developmentScholarship") .createQueryBuilder("developmentScholarship")
.leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel")
.leftJoinAndSelect("developmentScholarship.posType", "posType") .leftJoinAndSelect("developmentScholarship.posType", "posType")
.andWhere( .andWhere(
year !== 0 && year != null && year != undefined year !== 0 && year != null && year != undefined
? "developmentScholarship.scholarshipYear = :scholarshipYear" ? "developmentScholarship.scholarshipYear = :scholarshipYear"
: "1=1", : "1=1",
{ scholarshipYear: year }, { scholarshipYear: year },
) )
.andWhere( .andWhere(
rootId != "" && rootId != null && rootId != undefined rootId != "" && rootId != null && rootId != undefined
? "developmentScholarship.rootId = :rootId" ? "developmentScholarship.rootId = :rootId"
: "1=1", : "1=1",
{ rootId: rootId }, { rootId: rootId },
) )
.orderBy("developmentScholarship.scholarshipYear", "DESC") .orderBy("developmentScholarship.scholarshipYear", "DESC")
.addOrderBy("developmentScholarship.createdAt", "DESC") .addOrderBy("developmentScholarship.createdAt", "DESC")
.getManyAndCount(); .getMany();
const mapData = developments.map((item, idx:number) => ({
no: Extension.ToThaiNumber((idx+1).toString()),
institution: item.educationalInstitution ? item.educationalInstitution : "-",
scholarshipType: item.scholarshipType ? item.scholarshipType : "-",
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.toString()) : "" //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: {
year: year ? Extension.ToThaiNumber(year.toString()) : "-", year: year ? Extension.ToThaiNumber((year+543).toString()) : "-",
root: null, root: developments.length > 0 ? developments[0].root : "-",
developments: development, data: mapData.length > 0
total: total ? mapData
: [{
no: "-",
institution: "-",
scholarshipType: "-",
degreeLevel: "-",
course: "-",
field: "-",
fullName: "-",
position: "-",
posLevel: "-",
totalPeriod: "-",
budgetApprove: "-",
}],
sum: sum ? Extension.ToThaiNumber(sum.toString()): "-"
}, },
}); });
} }