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("rootId") rootId?: string,
) {
const [development, total] = 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")
.getManyAndCount();
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 : "-",
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({
template: "reportFund3",
reportName: "reportFund3",
data: {
year: year ? Extension.ToThaiNumber(year.toString()) : "-",
root: null,
developments: development,
total: total
year: year ? Extension.ToThaiNumber((year+543).toString()) : "-",
root: developments.length > 0 ? developments[0].root : "-",
data: mapData.length > 0
? mapData
: [{
no: "-",
institution: "-",
scholarshipType: "-",
degreeLevel: "-",
course: "-",
field: "-",
fullName: "-",
position: "-",
posLevel: "-",
totalPeriod: "-",
budgetApprove: "-",
}],
sum: sum ? Extension.ToThaiNumber(sum.toString()): "-"
},
});
}