From 4ff04f0dc54a4d78404b2596dbf78c5cd5b76119 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 27 Mar 2024 17:08:28 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=95=E0=B8=A7=E0=B9=81=E0=B8=9B=E0=B8=A3null=E0=B8=84?= =?UTF-8?q?=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2=20dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 104 +++++++++++++++++- .../SalaryPeriodEmployeeController.ts | 5 +- 2 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index b0762bb..dc6b671 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -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 จำนวนโควตา * diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index e49373a..7fdfeae 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -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"; @@ -124,7 +124,7 @@ export class SalaryPeriodEmployeeController extends Controller { const _salaryOrg = await this.salaryOrgRepository.find({ relations: ["salaryPeriod", "salaryProfiles"], where: { - group: body.group, + group: Like(`%${body.group}%`), snapshot: body.snapshot.trim().toUpperCase(), salaryPeriod: { period: body.period.trim().toUpperCase(), year: body.year }, }, @@ -143,6 +143,7 @@ export class SalaryPeriodEmployeeController extends Controller { }, 0); const data = { org: org, + group: item.group, total: item.total, fifteenPercent: item.fifteenPercent, chosen: item.quantityUsed,