From 59d3734184e796e3d247e38a8845923935134787 Mon Sep 17 00:00:00 2001 From: Bright Date: Mon, 12 Feb 2024 15:00:30 +0700 Subject: [PATCH] =?UTF-8?q?posMasterOrder=20=E0=B9=80=E0=B8=9E=E0=B8=B4?= =?UTF-8?q?=E0=B9=88=E0=B8=A1=E0=B8=95=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99?= =?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/PositionController.ts | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 83a0cebb..6dc4d7c0 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -335,6 +335,13 @@ export class PositionController extends Controller { if (!orgChild4) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง"); } else { + const order:any = await this.posMasterRepository.findOne({ + where: { + orgChild4Id: orgChild4.id + }, + order: { posMasterNo: "DESC" } + }) + posMaster.posMasterOrder = order.posMasterOrder == null ? 1: order.posMasterOrder+1 posMaster.orgRootId = orgChild4.orgRootId; posMaster.orgChild1Id = orgChild4.orgChild1Id; posMaster.orgChild2Id = orgChild4.orgChild2Id; @@ -343,6 +350,14 @@ export class PositionController extends Controller { posMaster.orgRevisionId = orgChild4.orgRevisionId; } } else { + const order:any = await this.posMasterRepository.findOne({ + where: { + orgChild3Id: orgChild3.id, + orgChild4Id: IsNull() || "" + }, + order: { posMasterNo: "DESC" } + }) + posMaster.posMasterOrder = order.posMasterOrder == null ? 1: order.posMasterOrder+1 posMaster.orgRootId = orgChild3.orgRootId; posMaster.orgChild1Id = orgChild3.orgChild1Id; posMaster.orgChild2Id = orgChild3.orgChild2Id; @@ -350,17 +365,47 @@ export class PositionController extends Controller { posMaster.orgRevisionId = orgChild3.orgRevisionId; } } else { + const order:any = await this.posMasterRepository.findOne({ + where: { + orgChild2Id: orgChild2.id, + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", + }, + order: { posMasterNo: "DESC" } + }) + posMaster.posMasterOrder = order.posMasterOrder == null ? 1: order.posMasterOrder+1 posMaster.orgRootId = orgChild2.orgRootId; posMaster.orgChild1Id = orgChild2.orgChild1Id; posMaster.orgChild2Id = orgChild2.id; posMaster.orgRevisionId = orgChild2.orgRevisionId; } } else { + const order:any = await this.posMasterRepository.findOne({ + where: { + orgChild1Id: orgChild1.id, + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", + }, + order: { posMasterNo: "DESC" } + }) + posMaster.posMasterOrder = order.posMasterOrder == null ? 1: order.posMasterOrder+1 posMaster.orgRootId = orgChild1.orgRootId; posMaster.orgChild1Id = orgChild1.id; posMaster.orgRevisionId = orgChild1.orgRevisionId; } } else { + const order:any = await this.posMasterRepository.findOne({ + where: { + orgRootId: orgRoot.id, + orgChild1Id: IsNull() || "", + orgChild2Id: IsNull() || "", + orgChild3Id: IsNull() || "", + orgChild4Id: IsNull() || "", + }, + order: { posMasterNo: "DESC" } + }) + posMaster.posMasterOrder = order.posMasterOrder == null ? 1: order.posMasterOrder+1 posMaster.orgRootId = orgRoot.id; posMaster.orgRevisionId = orgRoot.orgRevisionId; }