From 8895eb85d4af56c742f66a7245cc58f7cf6963a9 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 17 Apr 2025 16:08:42 +0700 Subject: [PATCH] =?UTF-8?q?fix=20=E0=B8=A3=E0=B8=B0=E0=B8=9A=E0=B8=9A?= =?UTF-8?q?=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= =?UTF-8?q?>>=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=E0=B8=8A=E0=B8=B1=E0=B9=88=E0=B8=A7=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A7=20(=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B9=81=E0=B8=95=E0=B9=88=E0=B8=87?= =?UTF-8?q?=E0=B8=95=E0=B8=B1=E0=B9=89=E0=B8=87=E0=B9=80=E0=B8=9B=E0=B9=87?= =?UTF-8?q?=E0=B8=99=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3=20?= =?UTF-8?q?=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=81=E0=B8=AA=E0=B8=94=E0=B8=87?= =?UTF-8?q?)=20#1407?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 128 +++++++++++++-------------- 1 file changed, 63 insertions(+), 65 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 5e9410cd..0fd2fa49 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -2119,75 +2119,73 @@ export class CommandController extends Controller { refIds: requestBody.persons.filter((x) => x.refId != null).map((x) => x.refId), status: "REPORT", }) - .then(async (res) => { - let order = - command.commandRecives == null || command.commandRecives.length <= 0 - ? 0 - : command.commandRecives[0].order; - await Promise.all( - requestBody.persons.map(async (item) => { - const _commandRecive = await this.commandReciveRepository.findOne({ + .then(async (res) => {}) + .catch(() => {}); + let order = + command.commandRecives == null || command.commandRecives.length <= 0 + ? 0 + : command.commandRecives[0].order; + await Promise.all( + requestBody.persons.map(async (item) => { + const _commandRecive = await this.commandReciveRepository.findOne({ + where: { + commandId: command.id, + refId: item.refId, + }, + }); + if (_commandRecive) return; + order = order + 1; + let commandRecive = new CommandRecive(); + commandRecive = Object.assign(new CommandRecive(), item); + commandRecive.order = order; + let salaryData = _null; + + // const excludedCommands = ["C-PM-33", "C-PM-34", "C-PM-35", "C-PM-36", "C-PM-37"]; + // if (!excludedCommands.includes(commandCode)) { + if (item.profileId) { + salaryData = await this.profileRepository.findOne({ + where: { + id: item.profileId, + }, + }); + let _setZero: any = 0; + if (!salaryData) { + salaryData = await this.profileEmployeeRepository.findOne({ where: { - commandId: command.id, - refId: item.refId, + id: item.profileId, }, }); - if (_commandRecive) return; - order = order + 1; - let commandRecive = new CommandRecive(); - commandRecive = Object.assign(new CommandRecive(), item); - commandRecive.order = order; - let salaryData = _null; - - // const excludedCommands = ["C-PM-33", "C-PM-34", "C-PM-35", "C-PM-36", "C-PM-37"]; - // if (!excludedCommands.includes(commandCode)) { - if (item.profileId) { - salaryData = await this.profileRepository.findOne({ - where: { - id: item.profileId, - }, - }); - let _setZero: any = 0; - if (!salaryData) { - salaryData = await this.profileEmployeeRepository.findOne({ - where: { - id: item.profileId, - }, - }); - } - commandRecive.amount = item.amount ?? (salaryData ? salaryData.amount : _setZero); - commandRecive.amountSpecial = - item.amountSpecial ?? (salaryData ? salaryData.amountSpecial : _setZero); - commandRecive.positionSalaryAmount = - item.positionSalaryAmount ?? - (salaryData ? salaryData.positionSalaryAmount : _setZero); - commandRecive.mouthSalaryAmount = - item.mouthSalaryAmount ?? (salaryData ? salaryData.mouthSalaryAmount : _setZero); - } else { - commandRecive.amount = _null; - commandRecive.amountSpecial = _null; - commandRecive.positionSalaryAmount = _null; - commandRecive.mouthSalaryAmount = _null; - } - - commandRecive.remarkVertical = - item.remarkVertical == null ? _null : item.remarkVertical; - commandRecive.remarkHorizontal = - item.remarkHorizontal == null ? _null : item.remarkHorizontal; - commandRecive.order = order; - commandRecive.commandId = command.id; - commandRecive.createdUserId = request.user.sub; - commandRecive.createdFullName = request.user.name; - commandRecive.createdAt = new Date(); - commandRecive.lastUpdateUserId = request.user.sub; - commandRecive.lastUpdateFullName = request.user.name; - commandRecive.lastUpdatedAt = new Date(); - await this.commandReciveRepository.save(commandRecive); - }), - ); - }) - .catch(() => {}); + } + commandRecive.amount = item.amount ?? (salaryData ? salaryData.amount : _setZero); + commandRecive.amountSpecial = + item.amountSpecial ?? (salaryData ? salaryData.amountSpecial : _setZero); + commandRecive.positionSalaryAmount = + item.positionSalaryAmount ?? + (salaryData ? salaryData.positionSalaryAmount : _setZero); + commandRecive.mouthSalaryAmount = + item.mouthSalaryAmount ?? (salaryData ? salaryData.mouthSalaryAmount : _setZero); + } else { + commandRecive.amount = _null; + commandRecive.amountSpecial = _null; + commandRecive.positionSalaryAmount = _null; + commandRecive.mouthSalaryAmount = _null; + } + commandRecive.remarkVertical = + item.remarkVertical == null ? _null : item.remarkVertical; + commandRecive.remarkHorizontal = + item.remarkHorizontal == null ? _null : item.remarkHorizontal; + commandRecive.order = order; + commandRecive.commandId = command.id; + commandRecive.createdUserId = request.user.sub; + commandRecive.createdFullName = request.user.name; + commandRecive.createdAt = new Date(); + commandRecive.lastUpdateUserId = request.user.sub; + commandRecive.lastUpdateFullName = request.user.name; + commandRecive.lastUpdatedAt = new Date(); + await this.commandReciveRepository.save(commandRecive); + }), + ); if ( [ "C-PM-01",