ปรับ report 2 3 4
This commit is contained in:
parent
aa38645561
commit
4fd22aac36
1 changed files with 206 additions and 9 deletions
|
|
@ -3487,9 +3487,70 @@ export class ReportController extends Controller {
|
|||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
// (async () => {
|
||||
let nodeId:string = reqBody.nodeId ? reqBody.nodeId : "";
|
||||
let node:number = reqBody.node ? reqBody.node : 0;
|
||||
if(nodeId === "" || node < 0 || node > 4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
// ดึงแค่ rootId ก่อน ถ้าลูกค้า confirm ค่อยปรับ
|
||||
switch (node) {
|
||||
case 0: {
|
||||
const orgRoot = await this.orgRootRepository.findOne({
|
||||
select: ["id"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgRoot)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgRoot.id;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
const orgChild1 = await this.child1Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild1)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild1.orgRootId;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
const orgChild2 = await this.child2Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild2)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild2.orgRootId;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
const orgChild3 = await this.child3Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild3)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild3.orgRootId;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
const orgChild4 = await this.child4Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild4)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild4.orgRootId;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const orgRootData = await this.orgRootRepository.find({
|
||||
where: {
|
||||
id: reqBody.nodeId,
|
||||
id: nodeId,
|
||||
// id: rootId,
|
||||
// orgRevisionId: orgRevision.id,
|
||||
},
|
||||
|
|
@ -7848,10 +7909,70 @@ export class ReportController extends Controller {
|
|||
// if (!orgRevision) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
let nodeId:string = reqBody.nodeId ? reqBody.nodeId : "";
|
||||
let node:number = reqBody.node ? reqBody.node : 0;
|
||||
if(nodeId === "" || node < 0 || node > 4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
// ดึงแค่ rootId ก่อน ถ้าลูกค้า confirm ค่อยปรับ
|
||||
switch (node) {
|
||||
case 0: {
|
||||
const orgRoot = await this.orgRootRepository.findOne({
|
||||
select: ["id"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgRoot)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgRoot.id;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
const orgChild1 = await this.child1Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild1)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild1.orgRootId;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
const orgChild2 = await this.child2Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild2)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild2.orgRootId;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
const orgChild3 = await this.child3Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild3)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild3.orgRootId;
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
const orgChild4 = await this.child4Repository.findOne({
|
||||
select: ["id", "orgRootId"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild4)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
nodeId = orgChild4.orgRootId;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const orgRootData = await this.orgRootRepository.find({
|
||||
where: {
|
||||
id: reqBody.nodeId,
|
||||
id: nodeId,
|
||||
// orgRevisionId: orgRevision.id,
|
||||
},
|
||||
order: { orgRootOrder: "ASC" },
|
||||
|
|
@ -9090,17 +9211,93 @@ export class ReportController extends Controller {
|
|||
) {
|
||||
// @Get("report4/{rootId}")
|
||||
// async findReport4(@Path() rootId: string) {
|
||||
const orgRootData = await this.orgRootRepository.findOne({
|
||||
where: { id: reqBody.nodeId },
|
||||
});
|
||||
if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
let rootId:string = reqBody.nodeId;
|
||||
|
||||
let nodeId:string = reqBody.nodeId ? reqBody.nodeId : "";
|
||||
let node:number = reqBody.node ? reqBody.node : 0;
|
||||
let rootName:string = "";
|
||||
let whereCase: string = "";
|
||||
let params: any = {};
|
||||
|
||||
if(nodeId === "" || node < 0 || node > 4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
switch (node) {
|
||||
case 0: {
|
||||
const orgRoot = await this.orgRootRepository.findOne({
|
||||
select: ["id", "orgRootName"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgRoot)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
rootName = orgRoot.orgRootName;
|
||||
whereCase = "posMaster.orgRootId = :nodeId";
|
||||
params = { nodeId };
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
const orgChild1 = await this.child1Repository.findOne({
|
||||
select: ["id", "orgChild1Name"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild1)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
rootName = orgChild1.orgChild1Name;
|
||||
whereCase = "posMaster.orgChild1Id = :nodeId";
|
||||
params = { nodeId };
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
const orgChild2 = await this.child2Repository.findOne({
|
||||
select: ["id", "orgChild2Name"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild2)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
rootName = orgChild2.orgChild2Name;
|
||||
whereCase = "posMaster.orgChild2Id = :nodeId";
|
||||
params = { nodeId };
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
const orgChild3 = await this.child3Repository.findOne({
|
||||
select: ["id", "orgChild3Name"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild3)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
rootName = orgChild3.orgChild3Name;
|
||||
whereCase = "posMaster.orgChild3Id = :nodeId";
|
||||
params = { nodeId };
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
const orgChild4 = await this.child4Repository.findOne({
|
||||
select: ["id", "orgChild4Name"],
|
||||
where: { id: nodeId }
|
||||
});
|
||||
if (!orgChild4)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
rootName = orgChild4.orgChild4Name;
|
||||
whereCase = "posMaster.orgChild4Id = :nodeId";
|
||||
params = { nodeId };
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
// const orgRootData = await this.orgRootRepository.findOne({
|
||||
// where: { id: reqBody.nodeId },
|
||||
// });
|
||||
// if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// let rootId:string = reqBody.nodeId;
|
||||
const posMaster = await this.posMasterRepository
|
||||
.createQueryBuilder("posMaster")
|
||||
.leftJoinAndSelect("posMaster.positions", "position")
|
||||
.leftJoinAndSelect("position.posType", "posType")
|
||||
.leftJoinAndSelect("position.posLevel", "posLevel")
|
||||
.where("posMaster.orgRootId = :rootId", { rootId })
|
||||
// .where("posMaster.orgRootId = :rootId", { rootId })
|
||||
.where(whereCase, params)
|
||||
.orderBy("posType.posTypeRank", "ASC")
|
||||
.addOrderBy("posLevel.posLevelRank", "ASC")
|
||||
.getMany();
|
||||
|
|
@ -9199,7 +9396,7 @@ export class ReportController extends Controller {
|
|||
reportName: "report4",
|
||||
data: {
|
||||
dateCurrent: Extension.ToThaiShortDate(new Date()),
|
||||
rootName: orgRootData ? orgRootData.orgRootName : "-",
|
||||
rootName: rootName ? rootName : "-",
|
||||
data: _reslut,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue