From 9e749fbbcd1fe0aa15ea2bceea54b431d9d6e35b Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 25 Apr 2024 00:53:57 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AD=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=B3?= =?UTF-8?q?=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87=E0=B9=80=E0=B8=87=E0=B8=B4?= =?UTF-8?q?=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 602 +++++++++++++----- src/entities/SalaryProfile.ts | 11 + src/entities/SalaryProfileEmployee.ts | 11 + ...pdate_table_salaryprofile_add_profileId.ts | 16 + 4 files changed, 476 insertions(+), 164 deletions(-) create mode 100644 src/migration/1713980385738-update_table_salaryprofile_add_profileId.ts diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 917e416..3f51d8a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -245,7 +245,7 @@ export class ReportController extends Controller { // }, // }); - const _salaryPeriod1 = await this.salaryProfileRepository.find({ + const _salaryPeriod1 = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { @@ -254,14 +254,14 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, group: "GROUP1", }, - type: "HAFT" + type: "HAFT", }, order: { citizenId: "ASC", isReserve: "ASC", }, }); - const _salaryPeriod2 = await this.salaryProfileRepository.find({ + const _salaryPeriod2 = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { @@ -270,14 +270,14 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, group: "GROUP1", }, - type: "FULL" + type: "FULL", }, order: { citizenId: "ASC", isReserve: "ASC", }, }); - const _salaryPeriod3 = await this.salaryProfileRepository.find({ + const _salaryPeriod3 = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { @@ -286,14 +286,14 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, group: "GROUP1", }, - type: "NONE" + type: "NONE", }, order: { citizenId: "ASC", isReserve: "ASC", }, }); - const _salaryPeriod4 = await this.salaryProfileRepository.find({ + const _salaryPeriod4 = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { @@ -302,14 +302,14 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, group: "GROUP2", }, - type: "HAFT" + type: "HAFT", }, order: { citizenId: "ASC", isReserve: "ASC", }, }); - const _salaryPeriod5 = await this.salaryProfileRepository.find({ + const _salaryPeriod5 = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { @@ -318,14 +318,14 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, group: "GROUP2", }, - type: "FULL" + type: "FULL", }, order: { citizenId: "ASC", isReserve: "ASC", }, }); - const _salaryPeriod6 = await this.salaryProfileRepository.find({ + const _salaryPeriod6 = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { @@ -334,7 +334,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, group: "GROUP2", }, - type: "NONE" + type: "NONE", }, order: { citizenId: "ASC", @@ -343,11 +343,11 @@ export class ReportController extends Controller { }); const _salaryPeriod = _salaryPeriod1.concat( - _salaryPeriod2, - _salaryPeriod3, - _salaryPeriod4, - _salaryPeriod5, - _salaryPeriod6 + _salaryPeriod2, + _salaryPeriod3, + _salaryPeriod4, + _salaryPeriod5, + _salaryPeriod6, ); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); @@ -557,10 +557,12 @@ export class ReportController extends Controller { reportName: "gov1-02", data: { // date: Extension.ToThaiNumber( - // Extension.ToThaiFullDate2(new Date(`${salaryPeriod.year}-03-01`)), + // Extension.ToThaiFullDate2(new Date(`${salaryPeriod.year}-03-01`)), // ), year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - yearSlice: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2)), + yearSlice: Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2), + ), // dateNow: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), agency: agency, data1: formattedData1, @@ -1030,7 +1032,9 @@ export class ReportController extends Controller { // Extension.ToThaiFullDate2(new Date(`${salaryPeriod.year}-03-01`)), // ), year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - yearSlice: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2)), + yearSlice: Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2), + ), // dateNow: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), agency: agency, data1: formattedData1, @@ -1276,7 +1280,11 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า salaryIncrease2: @@ -1286,7 +1294,11 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนหน้า score: null, //ผลการประเมินฯ @@ -1320,7 +1332,11 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า salaryIncrease2: @@ -1330,7 +1346,11 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนหน้า score: null, //ผลการประเมินฯ @@ -1572,7 +1592,13 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : Type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า salaryIncrease2: @@ -1582,20 +1608,37 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : Type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนหน้า salaryIncreaseAPR: salaryProfile_APR_Group1.length > 0 - ? (() => { - const filteredType = salaryProfile_APR_Group1 - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : Type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น" - })() - : null, //การเลื่อนเงินเดือนรอบเมษา - Type: item.type === "FULL" ? "หนึ่งขั้น" : item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : null, + ? (() => { + const filteredType = salaryProfile_APR_Group1 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนรอบเมษา + Type: + item.type === "FULL" + ? "หนึ่งขั้น" + : item.type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : null, score1: null, //ผลการประเมินฯ ครั้งที่ 1 score2: null, //ผลการประเมินฯ ครั้งที่ 2 })), @@ -1627,7 +1670,13 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : Type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า salaryIncrease2: @@ -1637,20 +1686,37 @@ export class ReportController extends Controller { .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.type); const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : Type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น" + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; })() : null, //การเลื่อนเงินเดือนปีก่อนหน้า salaryIncreaseAPR: salaryProfile_APR_Group2.length > 0 - ? (() => { - const filteredType = salaryProfile_APR_Group2 - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" ? "ครึ่งขั้น" : Type === "FULL" ? "หนึ่งขั้น" : Type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น" - })() - : null, //การเลื่อนเงินเดือนรอบเมษา - Type: item.type === "FULL" ? "หนึ่งขั้น" : item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : null, + ? (() => { + const filteredType = salaryProfile_APR_Group2 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนรอบเมษา + Type: + item.type === "FULL" + ? "หนึ่งขั้น" + : item.type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : null, score1: null, //ผลการประเมินฯ ครั้งที่ 1 score2: null, //ผลการประเมินฯ ครั้งที่ 2 })), @@ -1896,7 +1962,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน - isRetired: salaryPeriod.period === 'APR' ? In([true, false]) : false, //กรองเฉพาะคนที่ไม่เกษียณเฉพาะรอบตุลา + isRetired: salaryPeriod.period === "APR" ? In([true, false]) : false, //กรองเฉพาะคนที่ไม่เกษียณเฉพาะรอบตุลา }, order: { salaryOrg: { @@ -2068,7 +2134,7 @@ export class ReportController extends Controller { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, - isActive: true + isActive: true, }, }); @@ -2142,13 +2208,14 @@ export class ReportController extends Controller { data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearOld: Extension.ToThaiNumber((salaryPeriod.year + 542).toString()), - date: salaryPeriod.period === "APR" - ? Extension.ToThaiNumber( - Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)), - ) - : Extension.ToThaiNumber( - Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), - ), + date: + salaryPeriod.period === "APR" + ? Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)), + ) + : Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), + ), agency: root, data: formattedData, }, @@ -2184,10 +2251,10 @@ export class ReportController extends Controller { rootId: rootId, salaryPeriodId: salaryPeriodId, salaryPeriod: { - period: salaryPeriod.period + period: salaryPeriod.period, }, }, - isRetired: true // เฉพาะคนที่เกษียณ + isRetired: true, // เฉพาะคนที่เกษียณ }, order: { type: "DESC", @@ -2243,7 +2310,9 @@ export class ReportController extends Controller { data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearOld: Extension.ToThaiNumber((salaryPeriod.year + 542).toString()), - date: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`))), + date: Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), + ), agency: root, data: formattedData, }, @@ -2389,13 +2458,14 @@ export class ReportController extends Controller { reportName: salaryPeriod.period === "APR" ? "gov1-08" : "gov2-09", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - date: salaryPeriod.period === "APR" - ? Extension.ToThaiNumber( - Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)), - ) - : Extension.ToThaiNumber( - Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), - ), + date: + salaryPeriod.period === "APR" + ? Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)), + ) + : Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), + ), agency: salaryOrgGroup1?.root, profileSpecial: profileSpecial, profileNoAmount: profileNoAmount, @@ -2784,9 +2854,7 @@ export class ReportController extends Controller { ? "(" + Extension.ToThaiNumber(profile.amountSpecial.toString()) + ")" : "", amountSpecial: - profile.amountSpecial > 0 - ? Extension.ToThaiNumber(profile.amountSpecial.toString()) - : "", + profile.amountSpecial > 0 ? Extension.ToThaiNumber(profile.amountSpecial.toString()) : "", score: null, //สรุปผลการประเมินฯ ระดับและคะแนน reason: null, }; @@ -3216,7 +3284,9 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, position: profile.position, - posLevel: profile.posLevel ? Extension.ToThaiNumber(String(profile.posLevel.toLocaleString())): null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(String(profile.posLevel.toLocaleString())) + : null, }; }); @@ -3466,83 +3536,83 @@ export class ReportController extends Controller { }, }); } - - /** + + /** * API 14-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ * * @summary 14-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ * */ - @Get("emp-14/{rootId}/{salaryPeriodId}") - async SalaryReportEmp1_14(@Path() rootId: string, @Path() salaryPeriodId: string) { - const salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { - id: salaryPeriodId, - }, - }); - if (!salaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); - } - const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg", "salaryOrg.salaryPeriod"], - where: { - isNext: false, - salaryOrg: { - snapshot: "SNAP2", - rootId: rootId, - salaryPeriodId: salaryPeriodId, - }, - }, - order: { - positionSalaryAmount: "ASC", - }, - }); - - if (!_salaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } - - const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; - - const formattedData = _salaryPeriod.map((profile, index) => { - const fullNameParts = [ - profile.child4, - profile.child3, - profile.child2, - profile.child1, - profile.root, - `${profile.prefix}${profile.firstName} ${profile.lastName}`, - ]; - - const fullName = fullNameParts - .filter((part) => part !== undefined && part !== null) - .join("/"); - - return { - no: Extension.ToThaiNumber((index + 1).toLocaleString()), - fullName: fullName, - position: profile.position, - posLevel: profile.posLevel - ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` - : null, - posNumber: - Extension.ToThaiNumber(profile.orgShortName) + - Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), - amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, - reason: null, // หมายเหตุ - }; - }); - - return new HttpSuccess({ - template: "emp1-14", - reportName: "emp1-14", - data: { - year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - agency: agency, - data: formattedData, - }, - }); - } + @Get("emp-14/{rootId}/{salaryPeriodId}") + async SalaryReportEmp1_14(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + isNext: false, + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + positionSalaryAmount: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.map((profile, index) => { + const fullNameParts = [ + profile.child4, + profile.child3, + profile.child2, + profile.child1, + profile.root, + `${profile.prefix}${profile.firstName} ${profile.lastName}`, + ]; + + const fullName = fullNameParts + .filter((part) => part !== undefined && part !== null) + .join("/"); + + return { + no: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + position: profile.position, + posLevel: profile.posLevel + ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` + : null, + posNumber: + Extension.ToThaiNumber(profile.orgShortName) + + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, // หมายเหตุ + }; + }); + + return new HttpSuccess({ + template: "emp1-14", + reportName: "emp1-14", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } /** * API 15-บัญชีรายละเอียดลูกจ้างประจำที่ได้รับค่าตอบแทนพิเศษ(แนบท้ายคำสั่ง) * @@ -3909,22 +3979,31 @@ export class ReportController extends Controller { totalSalary: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toLocaleString()), sixPercent: - octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toLocaleString()), + octSnap1 == null + ? "" + : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toLocaleString()), remainingAmountApr: // aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toLocaleString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย. aprSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toLocaleString()), remainingAmountOct: //octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toLocaleString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค. - octSnap2 == null ? "" : Extension.ToThaiNumber((octSnap2.sixPercentAmount - octSnap2.spentAmount).toLocaleString()), + octSnap2 == null + ? "" + : Extension.ToThaiNumber( + (octSnap2.sixPercentAmount - octSnap2.spentAmount).toLocaleString(), + ), totalOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.total.toLocaleString()), //จำนวน(คน)(โควตาเลื่อนขั้นค่าจ้าง) fifteenPercentOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.fifteenPercent.toLocaleString()), totalUseOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toLocaleString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง) full2: totalEmp2step == null ? "" : Extension.ToThaiNumber(totalEmp2step.toLocaleString()), //เลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้นจำนวน(คน) - fullHaft: fullHaftCount == null ? "" : Extension.ToThaiNumber(fullHaftCount.toLocaleString()), //จำนวน(คน)(หนึ่งขั้นครึ่ง) + fullHaft: + fullHaftCount == null ? "" : Extension.ToThaiNumber(fullHaftCount.toLocaleString()), //จำนวน(คน)(หนึ่งขั้นครึ่ง) fullHaftSalary: - fullHaftTotalAmount == null ? "" : Extension.ToThaiNumber(fullHaftTotalAmount.toLocaleString()), //ใช้เงิน(หนึ่งขั้นครึ่ง) + fullHaftTotalAmount == null + ? "" + : Extension.ToThaiNumber(fullHaftTotalAmount.toLocaleString()), //ใช้เงิน(หนึ่งขั้นครึ่ง) full: fullCount == null ? "" : Extension.ToThaiNumber(fullCount.toLocaleString()), //จำนวน(คน)(หนึ่งขั้น) fullSalary: fullTotalAmount == null ? "" : Extension.ToThaiNumber(fullTotalAmount.toLocaleString()), //ใช้เงิน(หนึ่งขั้น) @@ -5174,7 +5253,9 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, position: profile.position, - posLevel: profile.posLevel ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, }; }); @@ -5451,7 +5532,9 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, position: profile.position, - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -5562,7 +5645,9 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, position: profile.position, - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -5651,7 +5736,9 @@ export class ReportController extends Controller { (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + "/") + (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + "/") + (profile.root == undefined && profile.root == null ? "" : profile.root), - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -5738,7 +5825,9 @@ export class ReportController extends Controller { (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + "/") + (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + "/") + (profile.root == undefined && profile.root == null ? "" : profile.root), - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -5829,7 +5918,9 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, position: profile.position, - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -5936,7 +6027,9 @@ export class ReportController extends Controller { return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -6018,29 +6111,28 @@ export class ReportController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } - let perviousYearAPR:any; - let perviousYearOCT:any; - let salaryProfilePerviousAPR:any; - let salaryProfilePerviousOCT:any; + let perviousYearAPR: any; + let perviousYearOCT: any; + let salaryProfilePerviousAPR: any; + let salaryProfilePerviousOCT: any; //งวดปีก่อนหน้า - perviousYearAPR = await this.salaryPeriodRepository.findOne({ + perviousYearAPR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriodOCT.year - 1, }, }); - - perviousYearOCT = await this.salaryPeriodRepository.findOne({ + perviousYearOCT = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriodOCT.year - 1, }, }); - + //ปีก่อนหน้า - if(perviousYearAPR){ + if (perviousYearAPR) { salaryProfilePerviousAPR = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { @@ -6055,7 +6147,7 @@ export class ReportController extends Controller { }, }); } - if(perviousYearOCT){ + if (perviousYearOCT) { salaryProfilePerviousOCT = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { @@ -6120,7 +6212,7 @@ export class ReportController extends Controller { (aprProfile_old: SalaryProfile) => aprProfile_old.citizenId === profile.citizenId, ); } - + if (salaryProfilePerviousOCT && salaryProfilePerviousOCT.length > 0) { matchedOCTProfileOld = salaryProfilePerviousOCT.find( (octProfile_old: SalaryProfile) => octProfile_old.citizenId === profile.citizenId, @@ -6159,7 +6251,9 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, position: profile.position, - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):null, + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -6183,4 +6277,184 @@ export class ReportController extends Controller { }, }); } + + /** + * API ออกคำสั่ง 33 + * + * @summary ออกคำสั่ง 33 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Get("command/33/{id}") + async SalaryReport33(@Path() id: string) { + const salary = await this.salaryPeriodRepository.findOne({ + where: { id: id }, + }); + if (!salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const salaryOrgs = await this.salaryOrgRepository.find({ + where: { id: salary.id }, + }); + + const salaryRank = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In(salaryOrgs.map((x) => x.id)), + }, + }); + + const _salaryRank = salaryRank.map((item) => ({ + id: item.id, + citizenId: item.citizenId, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 34 + * + * @summary ออกคำสั่ง 34 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Get("command/34/{id}") + async SalaryReport34(@Path() id: string) { + const salary = await this.salaryPeriodRepository.findOne({ + where: { id: id }, + }); + if (!salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const salaryOrgs = await this.salaryOrgRepository.find({ + where: { id: salary.id }, + }); + + const salaryRank = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In(salaryOrgs.map((x) => x.id)), + }, + }); + + const _salaryRank = salaryRank.map((item) => ({ + id: item.id, + citizenId: item.citizenId, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 35 + * + * @summary ออกคำสั่ง 35 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Get("command/35/{id}") + async SalaryReport35(@Path() id: string) { + const salary = await this.salaryPeriodRepository.findOne({ + where: { id: id }, + }); + if (!salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const salaryOrgs = await this.salaryOrgRepository.find({ + where: { id: salary.id }, + }); + + const salaryRank = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In(salaryOrgs.map((x) => x.id)), + }, + }); + + const _salaryRank = salaryRank.map((item) => ({ + id: item.id, + citizenId: item.citizenId, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 36 + * + * @summary ออกคำสั่ง 36 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Get("command/36/{id}") + async SalaryReport36(@Path() id: string) { + const salary = await this.salaryPeriodRepository.findOne({ + where: { id: id }, + }); + if (!salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const salaryOrgs = await this.salaryOrgRepository.find({ + where: { id: salary.id }, + }); + + const salaryRank = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In(salaryOrgs.map((x) => x.id)), + }, + }); + + const _salaryRank = salaryRank.map((item) => ({ + id: item.id, + citizenId: item.citizenId, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 37 + * + * @summary ออกคำสั่ง 37 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Get("command/37/{id}") + async SalaryReport37(@Path() id: string) { + const salary = await this.salaryPeriodRepository.findOne({ + where: { id: id }, + }); + if (!salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const salaryOrgs = await this.salaryOrgRepository.find({ + where: { id: salary.id }, + }); + + const salaryRank = await this.salaryProfileRepository.find({ + where: { + salaryOrgId: In(salaryOrgs.map((x) => x.id)), + }, + }); + + const _salaryRank = salaryRank.map((item) => ({ + id: item.id, + citizenId: item.citizenId, + prefix: item.prefix, + firstName: item.firstName, + lastName: item.lastName, + })); + + return new HttpSuccess(_salaryRank); + } } diff --git a/src/entities/SalaryProfile.ts b/src/entities/SalaryProfile.ts index 7575e4c..b25a337 100644 --- a/src/entities/SalaryProfile.ts +++ b/src/entities/SalaryProfile.ts @@ -10,6 +10,14 @@ export class SalaryProfile extends EntityBase { }) salaryOrgId: string; + @Column({ + nullable: true, + length: 40, + comment: "ไอดีโปรไฟล์", + default: null, + }) + profileId: string; + @Column({ nullable: true, comment: "คำนำหน้า", @@ -313,6 +321,9 @@ export class CreateSalaryProfile { @Column() type: string; + @Column() + profileId: string; + @Column() prefix: string; diff --git a/src/entities/SalaryProfileEmployee.ts b/src/entities/SalaryProfileEmployee.ts index 7407564..ef32fc8 100644 --- a/src/entities/SalaryProfileEmployee.ts +++ b/src/entities/SalaryProfileEmployee.ts @@ -26,6 +26,14 @@ export class SalaryProfileEmployee extends EntityBase { }) salaryLevelNew: number; + @Column({ + nullable: true, + length: 40, + comment: "ไอดีโปรไฟล์", + default: null, + }) + profileId: string; + @Column({ nullable: true, comment: "คำนำหน้า", @@ -365,6 +373,9 @@ export class CreateSalaryProfileEmployee { @Column() type: string; + @Column() + profileId: string; + @Column() prefix: string; diff --git a/src/migration/1713980385738-update_table_salaryprofile_add_profileId.ts b/src/migration/1713980385738-update_table_salaryprofile_add_profileId.ts new file mode 100644 index 0000000..25883df --- /dev/null +++ b/src/migration/1713980385738-update_table_salaryprofile_add_profileId.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableSalaryprofileAddProfileId1713980385738 implements MigrationInterface { + name = 'UpdateTableSalaryprofileAddProfileId1713980385738' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` ADD \`profileId\` varchar(40) NULL COMMENT 'ไอดีโปรไฟล์'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`profileId\` varchar(40) NULL COMMENT 'ไอดีโปรไฟล์'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`profileId\``); + await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` DROP COLUMN \`profileId\``); + } + +}