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",