From b2aa004c7ff66659169031316872bf55c53e4fd1 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 22 Oct 2024 14:23:28 +0700 Subject: [PATCH 1/5] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1=E0=B8=A7=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B5=E0=B9=88?= =?UTF-8?q?=E0=B9=80=E0=B8=82=E0=B9=89=E0=B8=B2/=E0=B8=AD=E0=B8=AD?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B8=B2=E0=B8=81=E0=B8=A3=E0=B8=B2=E0=B8=8A?= =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 13 +++++++++++-- src/entities/ProfileSalary.ts | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 188bbcfb..26edc464 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -1707,6 +1707,7 @@ export class CommandController extends Controller { leaveReason?: string | null; dateLeave?: Date | null; commandId?: string | null; + isGovernment?: boolean | null; }[]; }, ) { @@ -1737,7 +1738,7 @@ export class CommandController extends Controller { Object.assign(data, { ...item, ...meta }); const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); - + data.dateGovernment = meta.createdAt; await this.salaryRepo.save(data, { data: req }); setLogDataDiff(req, { before, after: data }); history.profileSalaryId = data.id; @@ -1780,6 +1781,7 @@ export class CommandController extends Controller { isLeave: boolean; leaveReason?: string | null; dateLeave?: Date | null; + isGovernment?: boolean | null; }[]; }, ) { @@ -1815,7 +1817,7 @@ export class CommandController extends Controller { }); const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); - + data.dateGovernment = meta.createdAt; await this.salaryRepo.save(data, { data: req }); setLogDataDiff(req, { before, after: data }); history.profileSalaryId = data.id; @@ -1984,6 +1986,7 @@ export class CommandController extends Controller { amount?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; + isGovernment?: boolean | null; }[]; }, ) { @@ -2036,6 +2039,8 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), + dateGovernment: new Date(), + isGovernment: item.isGovernment }; Object.assign(data, meta); @@ -2181,6 +2186,7 @@ export class CommandController extends Controller { amount?: Double | null; positionSalaryAmount?: Double | null; mouthSalaryAmount?: Double | null; + isGovernment?: boolean | null; }[]; }, ) { @@ -2246,6 +2252,8 @@ export class CommandController extends Controller { lastUpdateFullName: req.user.name, createdAt: new Date(), lastUpdatedAt: new Date(), + dateGovernment: new Date(), + isGovernment: item.isGovernment }); await Promise.all([ this.profileRepository.save(_profile), @@ -2390,6 +2398,7 @@ export class CommandController extends Controller { Object.assign(salaryHistory, { ...profileSal, id: undefined }); profileSal.order = dest_item == null ? 1 : dest_item.order + 1; profileSal.profileId = profile.id; + profileSal.dateGovernment = meta.createdAt; await this.salaryRepo.save(profileSal, { data: req }); setLogDataDiff(req, { before, after: profileSal }); salaryHistory.profileSalaryId = profileSal.id; diff --git a/src/entities/ProfileSalary.ts b/src/entities/ProfileSalary.ts index 0d76a620..881dbcfc 100644 --- a/src/entities/ProfileSalary.ts +++ b/src/entities/ProfileSalary.ts @@ -197,6 +197,7 @@ export class CreateProfileSalary { commandId: string | null; // commandType?: string | null; templateDoc: string | null; + isGovernment?: boolean | null; } export class CreateProfileSalaryEmployee { From 49fe21ae94d822233df6f8455f8c142d5d43c7e1 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 22 Oct 2024 14:36:25 +0700 Subject: [PATCH 2/5] no message --- src/controllers/WorkflowController.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index ec31c40d..4fca82b1 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -418,7 +418,10 @@ export class WorkflowController extends Controller { //noti let profileNow = workflow.stateOperatorUsers .filter((x) => state.stateOperators.map((s) => s.operator).includes(x.operator)) - .map((x) => x.profile); + .map((x) => ({ + receiverUserId: x.profile, + notiLink: "", + })); await new CallAPI() .PostData(req, "/placement/noti/profiles", { subject: `รายการถูกส่ง`, @@ -435,7 +438,10 @@ export class WorkflowController extends Controller { if (_state != null) { let profileNext = workflow.stateOperatorUsers .filter((x) => _state.stateOperators.map((s) => s.operator).includes(x.operator)) - .map((x) => x.profile); + .map((x) => ({ + receiverUserId: x.profile, + notiLink: "", + })); await new CallAPI() .PostData(req, "/placement/noti/profiles", { subject: `ได้รับรายการ`, From 77d68e7096883cead2143297057b025602e4a38b Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 22 Oct 2024 14:56:14 +0700 Subject: [PATCH 3/5] no message --- src/controllers/WorkflowController.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index 4fca82b1..b877087e 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -756,7 +756,12 @@ export class WorkflowController extends Controller { actFullName: null, })); const posMasterActs = await this.posMasterActRepo.find({ - where: { posMasterId: In(posMasters.map((x) => x.id)) }, + where: { + posMasterId: In(posMasters.map((x) => x.id)), + posMasterChild: { + current_holderId: Not(In(posMasters.map((x) => x.current_holderId))), + }, + }, relations: [ "posMaster", "posMaster.current_holder", @@ -770,7 +775,7 @@ export class WorkflowController extends Controller { }); posMasterActs.map((x) => { let item: any = { - id: x.posMaster?.current_holderId || null, + id: x.posMasterChild?.current_holderId || null, prefix: x.posMasterChild?.current_holder?.prefix || "", firstName: x.posMasterChild?.current_holder?.firstName || "", lastName: x.posMasterChild?.current_holder?.lastName || "", From 0ddec18725f44a5a3ee53d618de9160bf3601fd1 Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 22 Oct 2024 15:14:42 +0700 Subject: [PATCH 4/5] add citizen --- src/controllers/PositionController.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 24672cb5..6b09e1c0 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -4123,6 +4123,8 @@ export class PositionController extends Controller { "next_holder.prefix", "next_holder.firstName", "next_holder.lastName", + "next_holder.id", + "next_holder.citizenId", ]) .getMany(); const _posMaster = posMaster.map((x) => { From ecadf565ac6d148a9edd61411d22df3ddbf232ee Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 22 Oct 2024 16:09:46 +0700 Subject: [PATCH 5/5] =?UTF-8?q?=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=B8=9C=E0=B8=B9=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=94=E0=B9=89=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B8=AA=E0=B8=B3?= =?UTF-8?q?=E0=B9=80=E0=B8=99=E0=B8=B2=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1?= =?UTF-8?q?=E0=B9=88=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandController.ts | 57 ++++++++++++++++++++++++--- src/controllers/WorkflowController.ts | 32 +++++++++++++++ 2 files changed, 84 insertions(+), 5 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 26edc464..31375858 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -18,7 +18,7 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { Command } from "../entities/Command"; -import { Brackets, LessThan, MoreThan, Double, In, Between } from "typeorm"; +import { Brackets, LessThan, MoreThan, Double, In, Between, IsNull, Not } from "typeorm"; import { CommandType } from "../entities/CommandType"; import { CommandSend } from "../entities/CommandSend"; import { Profile, CreateProfileAllFields } from "../entities/Profile"; @@ -1429,6 +1429,53 @@ export class CommandController extends Controller { ); }) .catch(() => {}); + + if (requestBody.persons != undefined && requestBody.persons.length > 0) { + const posMaster = await this.posMasterRepository.find({ + where: { + current_holderId: In(requestBody.persons.map((x) => x.profileId)), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + }, + select: ["orgRootId"], + }); + + const _posMaster = await this.posMasterRepository.find({ + where: { + orgRootId: In(posMaster.map((x) => x.orgRootId)), + orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true }, + isDirector: true, + current_holderId: Not(IsNull()), + }, + relations: ["current_holder", "orgRoot"], + }); + await Promise.all( + _posMaster.map(async (item) => { + const _commandSend = await this.commandSendRepository.findOne({ + where: { + commandId: command.id, + profileId: item.current_holder.id, + }, + }); + if (_commandSend) return; + let commandSend = new CommandSend(); + commandSend.citizenId = item.current_holder.citizenId; + commandSend.prefix = item.current_holder.prefix; + commandSend.firstName = item.current_holder.firstName; + commandSend.lastName = item.current_holder.lastName; + commandSend.position = item.current_holder.position; + commandSend.org = item.orgRoot.orgRootName; + commandSend.profileId = item.current_holder.id; + commandSend.commandId = command.id; + commandSend.createdUserId = request.user.sub; + commandSend.createdFullName = request.user.name; + commandSend.createdAt = new Date(); + commandSend.lastUpdateUserId = request.user.sub; + commandSend.lastUpdateFullName = request.user.name; + commandSend.lastUpdatedAt = new Date(); + await this.commandSendRepository.save(commandSend); + }), + ); + } return new HttpSuccess(command.id); } @@ -1487,7 +1534,7 @@ export class CommandController extends Controller { Object.assign(history, { ...data, id: undefined }); await this.salaryRepo.save(data, { data: req }); setLogDataDiff(req, { before, after: data }); - history.commandId = item.commandId??_null; + history.commandId = item.commandId ?? _null; await this.salaryHistoryRepo.save(history, { data: req }); const posMaster = await this.posMasterRepository.findOne({ @@ -2040,7 +2087,7 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - isGovernment: item.isGovernment + isGovernment: item.isGovernment, }; Object.assign(data, meta); @@ -2253,7 +2300,7 @@ export class CommandController extends Controller { createdAt: new Date(), lastUpdatedAt: new Date(), dateGovernment: new Date(), - isGovernment: item.isGovernment + isGovernment: item.isGovernment, }); await Promise.all([ this.profileRepository.save(_profile), @@ -2507,7 +2554,7 @@ export class CommandController extends Controller { profileEmployeeId: profile.id, date: new Date(), amount: item.amount, - commandId: item.commandId, + commandId: item.commandId, positionSalaryAmount: item.positionSalaryAmount, mouthSalaryAmount: item.mouthSalaryAmount, posNo: profile.posMasterNoTemp, diff --git a/src/controllers/WorkflowController.ts b/src/controllers/WorkflowController.ts index b877087e..8b334a83 100644 --- a/src/controllers/WorkflowController.ts +++ b/src/controllers/WorkflowController.ts @@ -580,9 +580,41 @@ export class WorkflowController extends Controller { where: { id: body.stateUserCommentId, }, + relations: ["state", "state.workflow", "state.stateOperators"], }); if (!stateUserComment) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ"); + stateUserComment.state.stateOperators; + + const workflow = await this.workflowRepo.findOne({ + where: { + refId: stateUserComment.state.workflow.refId, + sysName: stateUserComment.state.workflow.sysName, + }, + relations: ["stateOperatorUsers"], + }); + if (!workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้"); + let profileNow = workflow.stateOperatorUsers + .filter((x) => + stateUserComment.state.stateOperators.map((s) => s.operator).includes(x.operator), + ) + .map((x) => ({ + receiverUserId: x.profile, + notiLink: "", + })); + await new CallAPI() + .PostData(req, "/placement/noti/profiles", { + subject: `ผู้บังคับบัญชาดำเนินการ`, + body: `ผู้บังคับบัญชาดำเนินการ`, + receiverUserIds: profileNow, + payload: "", //แนบไฟล์ + isSendMail: true, + isSendInbox: true, + isSendNotification: true, + }) + .catch((error) => { + console.error("Error calling API:", error); + }); let _null: any = null; stateUserComment.isAccept = body.isAccept == null ? _null : body.isAccept; stateUserComment.isApprove = body.isApprove == null ? _null : body.isApprove;