This commit is contained in:
AdisakKanthawilang 2025-01-06 14:41:25 +07:00
parent 72e3e66afe
commit 8b01454d0a
2 changed files with 51 additions and 2 deletions

View file

@ -331,6 +331,8 @@ export class EvaluationController {
posNo: null,
oc: null,
salary: null,
root: null,
orgRootId: null,
positionLevel: null,
birthDate: null,
govAge: null,

View file

@ -64,14 +64,61 @@ export class ReoportController {
const evaluation = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.where( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD })
.where('evaluation.evaluationResult NOT IN (:...evaluationResults)', { evaluationResults: ['PENDING'] })
.andWhere( yearInAD && yearInAD != null? 'YEAR(createdAt) = :year': "1=1", { year: yearInAD })
.andWhere(rootId?'orgRootId = :rootId': "1=1", { rootId: rootId })
.andWhere('evaluation.step = :step', { step: 'DONE' })
.getMany();
const groupedData = evaluation.reduce((acc:any, item) => {
const key = item.root;
if (!acc[key]) {
acc[key] = {
agency: item.root && item.root != "" ? item.root: "-",
submitter: 0,
passCount: 0,
notPassCount: 0,
};
}
if (item.evaluationResult === 'PASS') {
acc[key].passCount++;
} else if (item.evaluationResult === 'NOTPASS') {
acc[key].notPassCount++;
}
return acc;
}, {});
const result = Object.values(groupedData).map((item: any) => ({
...item ,
submitter: Extension.ToThaiNumber((item.passCount + item.notPassCount).toString()),
passCount: Extension.ToThaiNumber(item.passCount.toString()),
notPassCount: Extension.ToThaiNumber(item.notPassCount.toString()),
}));
const submitter = Object.values(groupedData).reduce((acc: number, item: any) => {
return acc + item.passCount + item.notPassCount;
}, 0);
const sumPass = Object.values(groupedData).reduce((acc: number, item: any) => {
return acc + item.passCount;
}, 0);
const sumNotPass = Object.values(groupedData).reduce((acc: number, item: any) => {
return acc + item.notPassCount;
}, 0);
return new HttpSuccess({
template: "summary-evaluation",
reportName: "xlsx-report",
data: null,
data: {
year: year?Extension.ToThaiNumber(year.toString()):Extension.ToThaiNumber(new Date().getFullYear().toString()),
date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())),
mainAgency: rootId?result[0].root:"ทุกสำนักงานเขต",
list: result,
total: Extension.ToThaiNumber(submitter.toString()),
sumPass: Extension.ToThaiNumber(sumPass.toString()),
sumNotPass: Extension.ToThaiNumber(sumNotPass.toString()),
},
});
}