diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 240b307..c6d122b 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -15,7 +15,7 @@ import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; -import { In, Not, IsNull, MoreThan } from "typeorm"; +import { In, Not, IsNull, MoreThan, Double } from "typeorm"; import { Salarys } from "../entities/Salarys"; import { SalaryRanks } from "../entities/SalaryRanks"; import { PosType } from "../entities/PosType"; @@ -6268,7 +6268,7 @@ export class ReportController extends Controller { @Post("command/33/resume") async SalaryReport33Resume( @Body() - body: { result: { id: string; refCommandNo: string; templateDoc: string; }[] }, + body: { result: { id: string; refCommandNo: string; templateDoc: string }[] }, @Request() request: RequestWithUser, ) { await Promise.all( @@ -6322,7 +6322,7 @@ export class ReportController extends Controller { @Post("command/34/resume") async SalaryReport34Resume( @Body() - body: { result: { id: string; refCommandNo: string; templateDoc: string; }[] }, + body: { result: { id: string; refCommandNo: string; templateDoc: string }[] }, @Request() request: RequestWithUser, ) { await Promise.all( @@ -6375,7 +6375,7 @@ export class ReportController extends Controller { @Post("command/35/resume") async SalaryReport35Resume( @Body() - body: { result: { id: string; refCommandNo: string; templateDoc: string; }[] }, + body: { result: { id: string; refCommandNo: string; templateDoc: string }[] }, @Request() request: RequestWithUser, ) { await Promise.all( @@ -6428,7 +6428,7 @@ export class ReportController extends Controller { @Post("command/36/resume") async SalaryReport36Resume( @Body() - body: { result: { id: string; refCommandNo: string; templateDoc: string; }[] }, + body: { result: { id: string; refCommandNo: string; templateDoc: string }[] }, @Request() request: RequestWithUser, ) { await Promise.all( @@ -6481,7 +6481,7 @@ export class ReportController extends Controller { @Post("command/37/resume") async SalaryReport37Resume( @Body() - body: { result: { id: string; refCommandNo: string; templateDoc: string; }[] }, + body: { result: { id: string; refCommandNo: string; templateDoc: string }[] }, @Request() request: RequestWithUser, ) { await Promise.all( @@ -6726,4 +6726,164 @@ export class ReportController extends Controller { return new HttpSuccess(_salaryRank); } + + /** + * API ออกคำสั่ง + * + * @summary ออกคำสั่ง + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/officer/report/excecute") + async SalaryReportExcecute( + @Body() + body: { + refIds: { + refId: string; + commandAffectDate: Date | null; + commandNo: string | null; + commandYear: number; + templateDoc: string | null; + amount: Double | null; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | null; + }[]; + }, + @Request() request: RequestWithUser, + ) { + await Promise.all( + body.refIds.map(async (v) => { + const salary = await this.salaryProfileRepository.findOne({ + where: { + id: v.refId, + }, + }); + + if (salary != null) { + await new CallAPI() + .PostData(request, "/org/profile/salary", { + profileId: salary.profileId, + date: new Date(), + amount: salary.positionSalaryAmount, + positionSalaryAmount: salary.amountSpecial, + mouthSalaryAmount: null, + posNo: salary.orgShortName + salary.posMasterNo, + position: salary.position, + positionLine: null, + positionPathSide: null, + positionExecutive: salary.posExecutive, + positionType: salary.posType, + positionLevel: salary.posLevel, + refCommandNo: `${v.commandNo}/${Extension.ToThaiYear(v.commandYear)}`, + templateDoc: v.templateDoc, + }) + .then(async () => { + const before = null; + salary.status = "DONE"; + salary.lastUpdateUserId = request.user.sub; + salary.lastUpdateFullName = request.user.name; + salary.lastUpdatedAt = new Date(); + await this.salaryProfileRepository.save(salary, { data: request }); + setLogDataDiff(request, { before, after: salary }); + }); + } + }), + ); + return new HttpSuccess(); + } + + /** + * API ออกคำสั่ง + * + * @summary ออกคำสั่ง + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/employee/report/excecute") + async SalaryEmployeeReportExcecute( + @Body() + body: { + refIds: { + refId: string; + commandAffectDate: Date | null; + commandNo: string | null; + commandYear: number; + templateDoc: string | null; + amount: Double | null; + positionSalaryAmount: Double | null; + mouthSalaryAmount: Double | null; + }[]; + }, + @Request() request: RequestWithUser, + ) { + await Promise.all( + body.refIds.map(async (v) => { + const salary = await this.salaryProfileEmployeeRepository.findOne({ + where: { + id: v.refId, + }, + }); + if (salary != null) { + await new CallAPI() + .PostData(request, "/org/profile-employee/salary", { + profileEmployeeId: salary.profileId, + date: new Date(), + amount: salary.positionSalaryAmount, + positionSalaryAmount: salary.amountSpecial, + mouthSalaryAmount: null, + posNo: salary.orgShortName + salary.posMasterNo, + position: salary.position, + positionType: salary.posType, + positionLevel: salary.posLevel ? String(salary.posLevel) : null, + refCommandNo: `${v.commandNo}/${Extension.ToThaiYear(v.commandYear)}`, + templateDoc: v.templateDoc, + }) + .then(async () => { + const before = null; + salary.status = "DONE"; + salary.lastUpdateUserId = request.user.sub; + salary.lastUpdateFullName = request.user.name; + salary.lastUpdatedAt = new Date(); + await this.salaryProfileEmployeeRepository.save(salary, { data: request }); + setLogDataDiff(request, { before, after: salary }); + }); + } + }), + ); + return new HttpSuccess(); + } + /** + * API ออกคำสั่ง + * + * @summary ออกคำสั่ง + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/officer/report") + async SalaryOfficerReportCommand( + @Body() + body: { + refIds: string[]; + }, + @Request() request: RequestWithUser, + ) { + return new HttpSuccess(); + } + /** + * API ออกคำสั่ง + * + * @summary ออกคำสั่ง + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/employee/report") + async SalaryEmployeeReportCommand( + @Body() + body: { + refIds: string[]; + }, + @Request() request: RequestWithUser, + ) { + return new HttpSuccess(); + } }