From 7280da0b0519d4eafbdd484a1d16323b755659d3 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 28 Mar 2024 16:57:13 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87=E0=B8=81?= =?UTF-8?q?=E0=B8=A5=E0=B8=B8=E0=B9=88=E0=B8=A1=E0=B8=97=E0=B8=B1=E0=B9=89?= =?UTF-8?q?=E0=B8=87=E0=B8=AB=E0=B8=A1=E0=B8=94=E0=B9=83=E0=B8=99dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 74 +++++++++++++------ .../SalaryPeriodEmployeeController.ts | 15 ++-- src/entities/SalaryOrgEmployee.ts | 7 ++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index dc6b671..036e165 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -123,38 +123,68 @@ export class SalaryPeriodController extends Controller { const _salaryOrg = await this.salaryOrgRepository.find({ relations: ["salaryPeriod", "salaryProfiles"], where: { - group: Like(`%${body.group}%`), + group: Like( + `%${body.group.trim().toUpperCase() == "GROUP1" ? "GROUP1" : body.group.trim().toUpperCase() == "GROUP2" ? "GROUP2" : "GROUP1"}%`, + ), snapshot: body.snapshot.trim().toUpperCase(), - salaryPeriod: { period: body.period.trim().toUpperCase(), year: body.year }, + salaryPeriod: { id: body.period }, }, }); + 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 _salaryOrgGROUP2 = await this.salaryOrgRepository.findOne({ + relations: ["salaryPeriod", "salaryProfiles"], + where: { + group: Like( + `%${body.group.trim().toUpperCase() != "GROUP1" && body.group.trim().toUpperCase() != "GROUP2" ? "GROUP2" : "ZXCASD"}%`, + ), + rootId: item.rootId, + snapshot: body.snapshot.trim().toUpperCase(), + salaryPeriod: { id: body.period }, + }, + }); const sum = item.salaryProfiles.reduce((accumulator, object) => { return accumulator + object.amountSpecial; }, 0); + const sumGROUP2 = + _salaryOrgGROUP2 == null + ? 0 + : _salaryOrgGROUP2.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, + org: item.root, + total: item.total + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.total), + fifteenPercent: + item.fifteenPercent + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.fifteenPercent), + chosen: + item.quantityUsed + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.quantityUsed), + remaining: + item.remainQuota + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.remainQuota), + currentAmount: + item.currentAmount + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.currentAmount), + sixPercentAmount: + item.sixPercentAmount + + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.sixPercentAmount), + spentAmount: + item.spentAmount + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.spentAmount), + sixPercentSpentAmount: + item.sixPercentAmount - + item.spentAmount + + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.sixPercentAmount) - + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.spentAmount), + useAmount: item.useAmount + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.useAmount), + remainingAmount: + item.remainingAmount + + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.remainingAmount), + totalAmountSpecial: sum + sumGROUP2, + totalBackup: + item.salaryProfiles.filter((x) => x.isReserve == true).length + + (_salaryOrgGROUP2 == null + ? 0 + : _salaryOrgGROUP2.salaryProfiles.filter((x) => x.isReserve == true).length), }; salaryOrg.push(data); }), diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index 3491f55..e05513c 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -124,26 +124,21 @@ export class SalaryPeriodEmployeeController extends Controller { const _salaryOrg = await this.salaryOrgRepository.find({ relations: ["salaryPeriod", "salaryProfiles"], where: { - group: Like(`%${body.group.trim().toUpperCase()}%`), + group: Like( + `%${body.group.trim().toUpperCase() == "GROUP1" ? "GROUP1" : body.group.trim().toUpperCase() == "GROUP2" ? "GROUP2" : "GROUP1"}%`, + ), snapshot: body.snapshot.trim().toUpperCase(), - salaryPeriod: { period: body.period.trim().toUpperCase(), year: body.year }, + salaryPeriod: { id: body.period }, }, }); 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, + org: item.root, total: item.total, fifteenPercent: item.fifteenPercent, chosen: item.quantityUsed, diff --git a/src/entities/SalaryOrgEmployee.ts b/src/entities/SalaryOrgEmployee.ts index a2d09bd..24e5b62 100644 --- a/src/entities/SalaryOrgEmployee.ts +++ b/src/entities/SalaryOrgEmployee.ts @@ -22,6 +22,13 @@ export class SalaryOrgEmployee extends EntityBase { }) rootId: string; + @Column({ + nullable: true, + comment: "orgRoot", + length: 255, + }) + root: string; + @Column({ nullable: true, comment: "คีย์นอก(FK)ของตาราง orgRevision",