เพิ่มตวแปรnullค้นหา dashboard
This commit is contained in:
parent
fc90b1ff4a
commit
4ff04f0dc5
2 changed files with 106 additions and 3 deletions
|
|
@ -13,7 +13,7 @@ import {
|
|||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { In, Not, MoreThan, Brackets } from "typeorm";
|
||||
import { In, Not, MoreThan, Brackets, Like } from "typeorm";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
|
|
@ -100,6 +100,108 @@ export class SalaryPeriodController extends Controller {
|
|||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ยอดใช้งานทั้งหมด
|
||||
*
|
||||
* @summary ยอดใช้งานทั้งหมด
|
||||
*
|
||||
* @param {string} id
|
||||
* @param {string} group
|
||||
* @param {string} period
|
||||
* @param {string} snapshot
|
||||
*/
|
||||
@Post("summary/all")
|
||||
async summaryUseSalary(
|
||||
@Body()
|
||||
body: {
|
||||
year: number;
|
||||
group: string;
|
||||
period: string;
|
||||
snapshot: string;
|
||||
},
|
||||
) {
|
||||
const _salaryOrg = await this.salaryOrgRepository.find({
|
||||
relations: ["salaryPeriod", "salaryProfiles"],
|
||||
where: {
|
||||
group: Like(`%${body.group}%`),
|
||||
snapshot: body.snapshot.trim().toUpperCase(),
|
||||
salaryPeriod: { period: body.period.trim().toUpperCase(), year: body.year },
|
||||
},
|
||||
});
|
||||
const salaryOrg: any[] = [];
|
||||
await Promise.all(
|
||||
_salaryOrg.map(async (item) => {
|
||||
const fullNameParts = [
|
||||
item == null || item.salaryProfiles.length == 0 || item.salaryProfiles[0].root == null
|
||||
? null
|
||||
: item.salaryProfiles[0].root,
|
||||
];
|
||||
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
|
||||
const sum = item.salaryProfiles.reduce((accumulator, object) => {
|
||||
return accumulator + object.amountSpecial;
|
||||
}, 0);
|
||||
const data = {
|
||||
org: org,
|
||||
group: item.group,
|
||||
total: item.total,
|
||||
fifteenPercent: item.fifteenPercent,
|
||||
chosen: item.quantityUsed,
|
||||
remaining: item.remainQuota,
|
||||
currentAmount: item.currentAmount,
|
||||
sixPercentAmount: item.sixPercentAmount,
|
||||
spentAmount: item.spentAmount,
|
||||
sixPercentSpentAmount: item.sixPercentAmount - item.spentAmount,
|
||||
useAmount: item.useAmount,
|
||||
remainingAmount: item.remainingAmount,
|
||||
totalAmountSpecial: sum,
|
||||
totalBackup: item.salaryProfiles.filter((x) => x.isReserve == true).length,
|
||||
};
|
||||
salaryOrg.push(data);
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess({
|
||||
salaryOrg,
|
||||
dashboard: {
|
||||
total: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.total;
|
||||
}, 0),
|
||||
fifteenPercent: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.fifteenPercent;
|
||||
}, 0),
|
||||
chosen: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.chosen;
|
||||
}, 0),
|
||||
remaining: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.remaining;
|
||||
}, 0),
|
||||
currentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.currentAmount;
|
||||
}, 0),
|
||||
sixPercentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.sixPercentAmount;
|
||||
}, 0),
|
||||
spentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.spentAmount;
|
||||
}, 0),
|
||||
sixPercentSpentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.sixPercentSpentAmount;
|
||||
}, 0),
|
||||
useAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.useAmount;
|
||||
}, 0),
|
||||
remainingAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.remainingAmount;
|
||||
}, 0),
|
||||
totalAmountSpecial: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.totalAmountSpecial;
|
||||
}, 0),
|
||||
totalBackup: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.totalBackup;
|
||||
}, 0),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API จำนวนโควตา
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue