hrms-api-org/src/controllers/ReportController.ts

1622 lines
81 KiB
TypeScript
Raw Normal View History

import {
Controller,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Body,
Path,
Request,
Example,
SuccessResponse,
Response,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
2024-02-07 21:20:04 +07:00
import { In } from "typeorm";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
@Route("api/v1/org/report")
2024-02-07 21:20:04 +07:00
@Tags("Report")
2024-02-03 13:09:44 +07:00
// @Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class ReportController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
/**
* API
*
* @summary ORG_029 - (ADMIN) #32
*
*/
@Get("position")
async findPosition() {
try {
2024-02-03 13:09:44 +07:00
const orgRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
relations: ["orgRoots"],
});
if (!orgRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
2024-02-07 11:08:55 +07:00
const orgRootData = await this.orgRootRepository.find({
where: {
orgRevisionId: orgRevision.id,
},
order: { orgRootOrder: "ASC" },
relations: [
"posMasters",
2024-02-08 19:46:18 +07:00
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
"posMasters.next_holder",
"posMasters.next_holder",
2024-02-07 11:08:55 +07:00
"posMasters.next_holder",
2024-02-07 12:43:49 +07:00
"posMasters.next_holder.posLevel",
"posMasters.next_holder.posType",
"posMasters.next_holder.current_holders",
"posMasters.next_holder.current_holders.positions",
2024-02-07 21:20:04 +07:00
"posMasters.next_holder.current_holders.orgRoot",
"posMasters.next_holder.current_holders.orgChild1",
"posMasters.next_holder.current_holders.orgChild2",
"posMasters.next_holder.current_holders.orgChild3",
"posMasters.next_holder.current_holders.orgChild4",
2024-02-07 11:08:55 +07:00
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
2024-02-07 18:53:15 +07:00
"posMasters.positions.posExecutive",
2024-02-07 11:08:55 +07:00
],
});
2024-02-03 13:09:44 +07:00
const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null;
2024-02-07 21:20:04 +07:00
const orgChild1Data = await this.child1Repository.find({
where: {
2024-02-08 19:46:18 +07:00
orgRootId: In(orgRootIds),
2024-02-07 21:20:04 +07:00
},
order: { orgChild1Order: "ASC" },
relations: [
"posMasters",
2024-02-08 19:46:18 +07:00
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
2024-02-07 21:20:04 +07:00
"posMasters.next_holder",
"posMasters.next_holder.posLevel",
"posMasters.next_holder.posType",
"posMasters.next_holder.current_holders",
"posMasters.next_holder.current_holders.positions",
"posMasters.next_holder.current_holders.orgRoot",
"posMasters.next_holder.current_holders.orgChild1",
"posMasters.next_holder.current_holders.orgChild2",
"posMasters.next_holder.current_holders.orgChild3",
"posMasters.next_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
2024-02-03 13:09:44 +07:00
const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null;
2024-02-07 21:20:04 +07:00
const orgChild2Data = await this.child2Repository.find({
where: {
2024-02-08 19:46:18 +07:00
orgChild1: In(orgChild1Ids),
2024-02-07 21:20:04 +07:00
},
order: { orgChild2Order: "ASC" },
relations: [
"posMasters",
2024-02-08 19:46:18 +07:00
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
2024-02-07 21:20:04 +07:00
"posMasters.next_holder",
"posMasters.next_holder.posLevel",
"posMasters.next_holder.posType",
"posMasters.next_holder.current_holders",
"posMasters.next_holder.current_holders.positions",
"posMasters.next_holder.current_holders.orgRoot",
"posMasters.next_holder.current_holders.orgChild1",
"posMasters.next_holder.current_holders.orgChild2",
"posMasters.next_holder.current_holders.orgChild3",
"posMasters.next_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
2024-02-03 13:09:44 +07:00
const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null;
2024-02-07 21:20:04 +07:00
const orgChild3Data = await this.child3Repository.find({
where: {
2024-02-08 19:46:18 +07:00
orgChild2: In(orgChild2Ids),
},
2024-02-07 21:20:04 +07:00
order: { orgChild3Order: "ASC" },
relations: [
"posMasters",
2024-02-08 19:46:18 +07:00
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
2024-02-07 21:20:04 +07:00
"posMasters.next_holder",
"posMasters.next_holder.posLevel",
"posMasters.next_holder.posType",
"posMasters.next_holder.current_holders",
"posMasters.next_holder.current_holders.positions",
"posMasters.next_holder.current_holders.orgRoot",
"posMasters.next_holder.current_holders.orgChild1",
"posMasters.next_holder.current_holders.orgChild2",
"posMasters.next_holder.current_holders.orgChild3",
"posMasters.next_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
});
2024-02-07 21:20:04 +07:00
const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null;
const orgChild4Data = await this.child4Repository.find({
2024-02-03 13:09:44 +07:00
where: {
2024-02-08 19:46:18 +07:00
orgChild3: In(orgChild3Ids),
2024-02-03 13:09:44 +07:00
},
2024-02-07 21:20:04 +07:00
order: { orgChild4Order: "ASC" },
relations: [
"posMasters",
2024-02-08 19:46:18 +07:00
"posMasters.orgRoot",
"posMasters.orgChild1",
"posMasters.orgChild2",
"posMasters.orgChild3",
"posMasters.orgChild4",
2024-02-07 21:20:04 +07:00
"posMasters.next_holder",
"posMasters.next_holder.posLevel",
"posMasters.next_holder.posType",
"posMasters.next_holder.current_holders",
"posMasters.next_holder.current_holders.positions",
"posMasters.next_holder.current_holders.orgRoot",
"posMasters.next_holder.current_holders.orgChild1",
"posMasters.next_holder.current_holders.orgChild2",
"posMasters.next_holder.current_holders.orgChild3",
"posMasters.next_holder.current_holders.orgChild4",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
"posMasters.positions.posExecutive",
],
2024-02-03 13:09:44 +07:00
});
2024-02-07 21:20:04 +07:00
2024-02-06 11:30:21 +07:00
let orgRevisionActive: any = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
2024-02-07 14:01:39 +07:00
relations: [
"posMasters",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
2024-02-07 18:53:15 +07:00
"posMasters.positions.posExecutive",
2024-02-07 14:01:39 +07:00
],
2024-02-06 11:30:21 +07:00
});
if (orgRevisionActive == null) {
const _orgRevisionActive = await this.orgRevisionRepository.find({
order: { orgRevisionCreatedAt: "DESC" },
skip: 1,
2024-02-07 14:01:39 +07:00
relations: [
"posMasters",
"posMasters.positions",
"posMasters.positions.posLevel",
"posMasters.positions.posType",
2024-02-07 18:53:15 +07:00
"posMasters.positions.posExecutive",
2024-02-07 14:01:39 +07:00
],
2024-02-06 11:30:21 +07:00
});
if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0];
}
2024-02-03 13:09:44 +07:00
let data = new Array();
2024-02-07 21:20:04 +07:00
let _node: any;
2024-02-08 19:46:18 +07:00
let no = 1;
2024-02-07 11:08:55 +07:00
for (let orgRoot of orgRootData) {
2024-02-07 21:20:04 +07:00
await Promise.all(
orgRoot.posMasters
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
.map(async (posMaster) => {
2024-02-08 18:04:54 +07:00
if (posMaster.orgChild1 == null) {
2024-02-07 14:01:39 +07:00
const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))];
const posType = [...new Set(posMaster.positions.map((x) => x.posType.posTypeName))];
const posLevel = [
...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)),
];
2024-02-07 18:53:15 +07:00
const posExecutive = [
...new Set(posMaster.positions.map((x) => x.posExecutive.posExecutiveName)),
];
2024-02-07 14:01:39 +07:00
let positionMasterProfileOld: any = null;
if (posMaster.next_holder != null) {
positionMasterProfileOld = posMaster.next_holder.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive.id,
);
}
let positionMasterOld: any = null;
let profilePositionName: any = [];
let profilePosType: any = [];
let profilePosLevel: any = [];
2024-02-07 18:53:15 +07:00
let profilePosExecutive: any = [];
2024-02-07 14:01:39 +07:00
if (posMaster.ancestorDNA != null) {
positionMasterOld = orgRevisionActive.posMasters.find(
(x: any) =>
x.orgRevisionId == orgRevisionActive.id &&
x.ancestorDNA == posMaster.ancestorDNA,
);
profilePositionName = [
...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
];
profilePosType = [
...new Set(positionMasterOld.positions.map((x: any) => x.posType.posTypeName)),
];
profilePosLevel = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName),
),
];
2024-02-07 18:53:15 +07:00
profilePosExecutive = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posExecutive.posExecutiveName),
),
];
2024-02-07 14:01:39 +07:00
}
2024-02-07 21:20:04 +07:00
let node = {
posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, //
2024-02-08 18:04:54 +07:00
orgTreeName: orgRoot.orgRootName,
orgTreeShortName: orgRoot.orgRootShortName,
2024-02-07 14:01:39 +07:00
posMasterNo: posMaster.posMasterNo,
2024-02-07 21:20:04 +07:00
positionName:
posMaster.next_holder == null
? positionName.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.positionName
: posMaster.next_holder.position,
posType:
posMaster.next_holder == null
? posType.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posType
?.posTypeName
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posType.posTypeName,
posLevel:
posMaster.next_holder == null
? posLevel.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posLevel
?.posLevelName
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posLevel.posLevelName,
posExecutive:
posMaster.next_holder == null
? posExecutive.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posExecutive
?.posExecutiveName
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.positions.find((x: any) => (x.isSit = true))
?.posExecutive?.posExecutiveName,
2024-02-07 18:53:15 +07:00
2024-02-07 21:20:04 +07:00
profileOrgName:
posMaster.next_holder == null
2024-02-08 18:04:54 +07:00
? orgRoot.orgRootName
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4Name
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3Name
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2Name
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1Name
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootName
2024-02-08 19:46:18 +07:00
: "-",
2024-02-07 21:20:04 +07:00
profileOrgShortName:
posMaster.next_holder == null
2024-02-08 18:04:54 +07:00
? orgRoot.orgRootShortName
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4ShortName
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3ShortName
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2ShortName
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1ShortName
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootShortName
2024-02-08 19:46:18 +07:00
: "-",
2024-02-07 14:01:39 +07:00
profileFullname:
posMaster.next_holder == null
? "- ว่าง -"
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
profilePosMasterNo:
2024-02-07 18:53:15 +07:00
posMaster.next_holder == null
2024-02-07 14:01:39 +07:00
? positionMasterOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 14:01:39 +07:00
: positionMasterOld.posMasterNo
2024-02-07 18:53:15 +07:00
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 18:53:15 +07:00
: positionMasterProfileOld.posMasterNo,
2024-02-07 14:01:39 +07:00
profilePositionName:
posMaster.next_holder == null
2024-02-07 18:53:15 +07:00
? positionMasterOld == null
? positionName.join(" หรือ ")
: profilePositionName.join(" หรือ ")
2024-02-07 14:01:39 +07:00
: posMaster.next_holder.position,
profilePosType:
posMaster.next_holder == null
2024-02-07 18:53:15 +07:00
? positionMasterOld == null
? posType.join(" หรือ ")
: profilePosType.join(" หรือ ")
2024-02-07 14:01:39 +07:00
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 14:01:39 +07:00
: posMaster.next_holder.posType.posTypeName,
profilePosLevel:
posMaster.next_holder == null
2024-02-07 18:53:15 +07:00
? positionMasterOld == null
? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ")
2024-02-07 14:01:39 +07:00
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 14:01:39 +07:00
: posMaster.next_holder.posLevel.posLevelName,
2024-02-07 18:53:15 +07:00
profilePosExecutive:
2024-02-07 14:01:39 +07:00
posMaster.next_holder == null
2024-02-07 18:53:15 +07:00
? positionMasterOld == null
? posExecutive.join(" หรือ ")
: profilePosExecutive.join(" หรือ ")
2024-02-07 14:01:39 +07:00
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 14:01:39 +07:00
: positionMasterProfileOld.positions.find(
(x: any) => (x.positionIsSelected = true),
2024-02-07 18:53:15 +07:00
)?.posExecutive?.posExecutiveName,
2024-02-07 14:01:39 +07:00
};
2024-02-08 18:04:54 +07:00
if (_node == null) {
const head = {
posMasterNo: node.orgTreeShortName,
2024-02-08 19:46:18 +07:00
profileFullname: node.profileOrgName,
posExecutive: node.orgTreeName,
2024-02-08 18:04:54 +07:00
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo: node.profileOrgShortName,
2024-02-08 19:46:18 +07:00
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
const _head = {
2024-02-08 19:46:18 +07:00
no: no,
2024-02-08 18:04:54 +07:00
posMasterNo: node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
profilePosLevel: node.profilePosLevel,
};
data.push(_head);
} else {
if (
2024-02-08 19:46:18 +07:00
node.orgTreeShortName != _node.orgTreeShortName ||
node.orgTreeName != _node.orgTreeName ||
node.profileOrgShortName != _node.profileOrgShortName ||
2024-02-08 18:04:54 +07:00
node.profileOrgName != _node.profileOrgName
) {
const head = {
posMasterNo:
node.orgTreeShortName == _node.orgTreeShortName
? ""
: node.orgTreeShortName,
profileFullname:
2024-02-08 19:46:18 +07:00
node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName,
posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
2024-02-08 18:04:54 +07:00
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo:
node.profileOrgShortName == _node.profileOrgShortName
? ""
: node.profileOrgShortName,
2024-02-08 19:46:18 +07:00
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
_node == null;
}
const head = {
2024-02-08 19:46:18 +07:00
no: no,
2024-02-08 18:04:54 +07:00
posMasterNo: node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName == _node.positionName ? "" : node.positionName,
posType: node.posType == _node.posType ? "" : node.posType,
posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel,
profilePosMasterNo:
node.profilePosMasterNo == _node.profilePosMasterNo
? ""
: node.profilePosMasterNo,
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
: node.profilePosExecutive,
profilePositionName:
node.profilePositionName == _node.profilePositionName
? ""
: node.profilePositionName,
profilePosType:
node.profilePosType == _node.profilePosType ? "" : node.profilePosType,
profilePosLevel:
node.profilePosLevel == _node.profilePosLevel ? "" : node.profilePosLevel,
};
data.push(head);
2024-02-07 21:20:04 +07:00
}
2024-02-08 19:46:18 +07:00
no += 1;
2024-02-07 21:20:04 +07:00
_node = node;
2024-02-08 18:04:54 +07:00
}
}),
);
_node = null;
for (let orgChild1 of orgChild1Data.filter(
(orgChild1) => orgChild1.orgRootId === orgRoot.id,
)) {
await Promise.all(
orgChild1.posMasters
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
.map(async (posMaster) => {
if (posMaster.orgChild2Id == null) {
const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))];
const posType = [
...new Set(posMaster.positions.map((x) => x.posType.posTypeName)),
];
const posLevel = [
...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)),
];
const posExecutive = [
...new Set(posMaster.positions.map((x) => x.posExecutive.posExecutiveName)),
];
let positionMasterProfileOld: any = null;
if (posMaster.next_holder != null) {
positionMasterProfileOld = posMaster.next_holder.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive.id,
);
}
let positionMasterOld: any = null;
let profilePositionName: any = [];
let profilePosType: any = [];
let profilePosLevel: any = [];
let profilePosExecutive: any = [];
if (posMaster.ancestorDNA != null) {
positionMasterOld = orgRevisionActive.posMasters.find(
(x: any) =>
x.orgRevisionId == orgRevisionActive.id &&
x.ancestorDNA == posMaster.ancestorDNA,
);
profilePositionName = [
...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
];
profilePosType = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posType.posTypeName),
),
];
profilePosLevel = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName),
),
];
profilePosExecutive = [
...new Set(
positionMasterOld.positions.map(
(x: any) => x.posExecutive.posExecutiveName,
),
),
];
}
let node = {
posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, //
orgTreeName: orgChild1.orgChild1Name,
orgTreeShortName: orgChild1.orgChild1ShortName,
posMasterNo: posMaster.posMasterNo,
positionName:
posMaster.next_holder == null
? positionName.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.positionName
: posMaster.next_holder.position,
posType:
posMaster.next_holder == null
? posType.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posType
?.posTypeName
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: posMaster.next_holder.posType.posTypeName,
posLevel:
posMaster.next_holder == null
? posLevel.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posLevel
?.posLevelName
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: posMaster.next_holder.posLevel.posLevelName,
posExecutive:
posMaster.next_holder == null
? posExecutive.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posExecutive
?.posExecutiveName
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: positionMasterProfileOld.positions.find((x: any) => (x.isSit = true))
?.posExecutive?.posExecutiveName,
profileOrgName:
posMaster.next_holder == null
? orgChild1.orgChild1Name
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4Name
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3Name
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2Name
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1Name
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootName
2024-02-08 19:46:18 +07:00
: "-",
2024-02-08 18:04:54 +07:00
profileOrgShortName:
posMaster.next_holder == null
? orgChild1.orgChild1ShortName
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4ShortName
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3ShortName
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2ShortName
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1ShortName
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootShortName
2024-02-08 19:46:18 +07:00
: "-",
2024-02-08 18:04:54 +07:00
profileFullname:
posMaster.next_holder == null
? "- ว่าง -"
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
profilePosMasterNo:
posMaster.next_holder == null
? positionMasterOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: positionMasterOld.posMasterNo
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: positionMasterProfileOld.posMasterNo,
profilePositionName:
posMaster.next_holder == null
? positionMasterOld == null
? positionName.join(" หรือ ")
: profilePositionName.join(" หรือ ")
: posMaster.next_holder.position,
profilePosType:
posMaster.next_holder == null
? positionMasterOld == null
? posType.join(" หรือ ")
: profilePosType.join(" หรือ ")
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: posMaster.next_holder.posType.posTypeName,
profilePosLevel:
posMaster.next_holder == null
? positionMasterOld == null
? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: posMaster.next_holder.posLevel.posLevelName,
profilePosExecutive:
posMaster.next_holder == null
? positionMasterOld == null
? posExecutive.join(" หรือ ")
: profilePosExecutive.join(" หรือ ")
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-08 18:04:54 +07:00
: positionMasterProfileOld.positions.find(
(x: any) => (x.positionIsSelected = true),
)?.posExecutive?.posExecutiveName,
};
if (_node == null) {
const head = {
posMasterNo: node.orgTreeShortName,
2024-02-08 19:46:18 +07:00
profileFullname: node.profileOrgName,
posExecutive: node.orgTreeName,
2024-02-08 18:04:54 +07:00
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo: node.profileOrgShortName,
2024-02-08 19:46:18 +07:00
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
const _head = {
2024-02-08 19:46:18 +07:00
no: no,
2024-02-08 18:04:54 +07:00
posMasterNo: node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
profilePosLevel: node.profilePosLevel,
};
data.push(_head);
} else {
if (
2024-02-08 19:46:18 +07:00
node.orgTreeShortName != _node.orgTreeShortName ||
node.orgTreeName != _node.orgTreeName ||
node.profileOrgShortName != _node.profileOrgShortName ||
2024-02-08 18:04:54 +07:00
node.profileOrgName != _node.profileOrgName
) {
const head = {
posMasterNo:
node.orgTreeShortName == _node.orgTreeShortName
? ""
: node.orgTreeShortName,
profileFullname:
2024-02-08 19:46:18 +07:00
node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName,
posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
2024-02-08 18:04:54 +07:00
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo:
node.profileOrgShortName == _node.profileOrgShortName
? ""
: node.profileOrgShortName,
2024-02-08 19:46:18 +07:00
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
_node == null;
}
const head = {
2024-02-08 19:46:18 +07:00
no: no,
2024-02-08 18:04:54 +07:00
posMasterNo: node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName:
node.positionName == _node.positionName ? "" : node.positionName,
posType: node.posType == _node.posType ? "" : node.posType,
posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel,
profilePosMasterNo:
node.profilePosMasterNo == _node.profilePosMasterNo
? ""
: node.profilePosMasterNo,
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
: node.profilePosExecutive,
profilePositionName:
node.profilePositionName == _node.profilePositionName
? ""
: node.profilePositionName,
profilePosType:
node.profilePosType == _node.profilePosType ? "" : node.profilePosType,
profilePosLevel:
node.profilePosLevel == _node.profilePosLevel ? "" : node.profilePosLevel,
};
data.push(head);
}
2024-02-08 19:46:18 +07:00
no += 1;
2024-02-08 18:04:54 +07:00
_node = node;
}
2024-02-07 14:01:39 +07:00
}),
2024-02-07 21:20:04 +07:00
);
_node = null;
for (let orgChild2 of orgChild2Data.filter(
(orgChild2) => orgChild2.orgChild1Id === orgChild1.id,
)) {
await Promise.all(
orgChild2.posMasters
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
.map(async (posMaster) => {
2024-02-08 19:46:18 +07:00
if (posMaster.orgChild3 == null) {
const positionName = [
...new Set(posMaster.positions.map((x) => x.positionName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
const posType = [
...new Set(posMaster.positions.map((x) => x.posType.posTypeName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
const posLevel = [
...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
const posExecutive = [
...new Set(posMaster.positions.map((x) => x.posExecutive.posExecutiveName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
let positionMasterProfileOld: any = null;
if (posMaster.next_holder != null) {
positionMasterProfileOld = posMaster.next_holder.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive.id,
);
}
2024-02-07 21:20:04 +07:00
2024-02-08 19:46:18 +07:00
let positionMasterOld: any = null;
let profilePositionName: any = [];
let profilePosType: any = [];
let profilePosLevel: any = [];
let profilePosExecutive: any = [];
if (posMaster.ancestorDNA != null) {
positionMasterOld = orgRevisionActive.posMasters.find(
(x: any) =>
x.orgRevisionId == orgRevisionActive.id &&
x.ancestorDNA == posMaster.ancestorDNA,
);
profilePositionName = [
...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
];
profilePosType = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posType.posTypeName),
),
];
profilePosLevel = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName),
),
];
profilePosExecutive = [
...new Set(
positionMasterOld.positions.map(
(x: any) => x.posExecutive.posExecutiveName,
),
),
];
}
let node = {
posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, //
orgTreeName: orgChild2.orgChild2Name,
orgTreeShortName: orgChild2.orgChild2ShortName,
posMasterNo: posMaster.posMasterNo,
positionName:
posMaster.next_holder == null
? positionName.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.positionName
: posMaster.next_holder.position,
posType:
posMaster.next_holder == null
? posType.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posType
?.posTypeName
: posMaster.next_holder.posType == null
? "-"
: posMaster.next_holder.posType.posTypeName,
posLevel:
posMaster.next_holder == null
? posLevel.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posLevel
?.posLevelName
: posMaster.next_holder.posLevel == null
? "-"
: posMaster.next_holder.posLevel.posLevelName,
posExecutive:
posMaster.next_holder == null
? posExecutive.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posExecutive
?.posExecutiveName
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.positions.find(
(x: any) => (x.isSit = true),
)?.posExecutive?.posExecutiveName,
profileOrgName:
posMaster.next_holder == null
? orgChild2.orgChild2Name
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4Name
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3Name
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2Name
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1Name
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootName
: "-",
profileOrgShortName:
posMaster.next_holder == null
? orgChild2.orgChild2ShortName
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4ShortName
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3ShortName
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2ShortName
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1ShortName
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootShortName
: "-",
profileFullname:
posMaster.next_holder == null
? "- ว่าง -"
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
profilePosMasterNo:
posMaster.next_holder == null
? positionMasterOld == null
? "-"
: positionMasterOld.posMasterNo
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.posMasterNo,
profilePositionName:
posMaster.next_holder == null
? positionMasterOld == null
? positionName.join(" หรือ ")
: profilePositionName.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.position,
2024-02-08 19:46:18 +07:00
profilePosType:
posMaster.next_holder == null
? positionMasterOld == null
? posType.join(" หรือ ")
: profilePosType.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posType.posTypeName,
2024-02-08 19:46:18 +07:00
profilePosLevel:
posMaster.next_holder == null
? positionMasterOld == null
? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posLevel.posLevelName,
2024-02-08 19:46:18 +07:00
profilePosExecutive:
posMaster.next_holder == null
? positionMasterOld == null
? posExecutive.join(" หรือ ")
: profilePosExecutive.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
: positionMasterProfileOld.positions.find(
(x: any) => (x.positionIsSelected = true),
)?.posExecutive?.posExecutiveName,
2024-02-08 18:04:54 +07:00
};
2024-02-08 19:46:18 +07:00
if (_node == null) {
2024-02-08 18:04:54 +07:00
const head = {
2024-02-08 19:46:18 +07:00
posMasterNo: node.orgTreeShortName,
profileFullname: node.profileOrgName,
posExecutive: node.orgTreeName,
2024-02-08 18:04:54 +07:00
positionName: "",
posType: "",
posLevel: "",
2024-02-08 19:46:18 +07:00
profilePosMasterNo: node.profileOrgShortName,
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
2024-02-08 19:46:18 +07:00
const _head = {
no: no,
posMasterNo: node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
profilePosLevel: node.profilePosLevel,
};
data.push(_head);
} else {
if (
node.orgTreeShortName != _node.orgTreeShortName ||
node.orgTreeName != _node.orgTreeName ||
node.profileOrgShortName != _node.profileOrgShortName ||
node.profileOrgName != _node.profileOrgName
) {
const head = {
posMasterNo:
node.orgTreeShortName == _node.orgTreeShortName
? ""
: node.orgTreeShortName,
profileFullname:
node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName,
posExecutive:
node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo:
node.profileOrgShortName == _node.profileOrgShortName
? ""
: node.profileOrgShortName,
profilePosExecutive: "",
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
_node == null;
}
const head = {
no: no,
posMasterNo: node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName:
node.positionName == _node.positionName ? "" : node.positionName,
posType: node.posType == _node.posType ? "" : node.posType,
posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel,
profilePosMasterNo:
node.profilePosMasterNo == _node.profilePosMasterNo
? ""
: node.profilePosMasterNo,
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
: node.profilePosExecutive,
profilePositionName:
node.profilePositionName == _node.profilePositionName
? ""
: node.profilePositionName,
profilePosType:
node.profilePosType == _node.profilePosType ? "" : node.profilePosType,
profilePosLevel:
node.profilePosLevel == _node.profilePosLevel ? "" : node.profilePosLevel,
};
data.push(head);
2024-02-08 18:04:54 +07:00
}
2024-02-08 19:46:18 +07:00
no += 1;
_node = node;
2024-02-07 21:20:04 +07:00
}
}),
);
_node = null;
for (let orgChild3 of orgChild3Data.filter(
(orgChild3) => orgChild3.orgChild2Id === orgChild2.id,
)) {
await Promise.all(
orgChild3.posMasters
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
.map(async (posMaster) => {
2024-02-08 19:46:18 +07:00
if (posMaster.orgChild3 == null) {
const positionName = [
...new Set(posMaster.positions.map((x) => x.positionName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
const posType = [
...new Set(posMaster.positions.map((x) => x.posType.posTypeName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
const posLevel = [
...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
const posExecutive = [
...new Set(posMaster.positions.map((x) => x.posExecutive.posExecutiveName)),
2024-02-07 21:20:04 +07:00
];
2024-02-08 19:46:18 +07:00
let positionMasterProfileOld: any = null;
if (posMaster.next_holder != null) {
positionMasterProfileOld = posMaster.next_holder.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive.id,
);
}
2024-02-07 21:20:04 +07:00
2024-02-08 19:46:18 +07:00
let positionMasterOld: any = null;
let profilePositionName: any = [];
let profilePosType: any = [];
let profilePosLevel: any = [];
let profilePosExecutive: any = [];
if (posMaster.ancestorDNA != null) {
positionMasterOld = orgRevisionActive.posMasters.find(
(x: any) =>
x.orgRevisionId == orgRevisionActive.id &&
x.ancestorDNA == posMaster.ancestorDNA,
);
profilePositionName = [
...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
];
profilePosType = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posType.posTypeName),
),
];
profilePosLevel = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName),
),
];
profilePosExecutive = [
...new Set(
positionMasterOld.positions.map(
(x: any) => x.posExecutive.posExecutiveName,
),
),
];
}
let node = {
posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, //
orgTreeName: orgChild3.orgChild3Name,
orgTreeShortName: orgChild3.orgChild3ShortName,
posMasterNo: posMaster.posMasterNo,
positionName:
posMaster.next_holder == null
? positionName.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.positionName
: posMaster.next_holder.position,
posType:
posMaster.next_holder == null
? posType.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posType
?.posTypeName
: posMaster.next_holder.posType == null
? "-"
: posMaster.next_holder.posType.posTypeName,
posLevel:
posMaster.next_holder == null
? posLevel.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posLevel
?.posLevelName
: posMaster.next_holder.posLevel == null
? "-"
: posMaster.next_holder.posLevel.posLevelName,
posExecutive:
posMaster.next_holder == null
? posExecutive.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posExecutive
?.posExecutiveName
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.positions.find(
(x: any) => (x.isSit = true),
)?.posExecutive?.posExecutiveName,
profileOrgName:
posMaster.next_holder == null
? orgChild3.orgChild3Name
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4Name
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3Name
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2Name
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1Name
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootName
: "-",
profileOrgShortName:
posMaster.next_holder == null
? orgChild3.orgChild3ShortName
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4ShortName
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3ShortName
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2ShortName
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1ShortName
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootShortName
: "-",
profileFullname:
posMaster.next_holder == null
? "- ว่าง -"
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
profilePosMasterNo:
posMaster.next_holder == null
? positionMasterOld == null
? "-"
: positionMasterOld.posMasterNo
: positionMasterProfileOld == null
? "-"
: positionMasterProfileOld.posMasterNo,
profilePositionName:
posMaster.next_holder == null
? positionMasterOld == null
? positionName.join(" หรือ ")
: profilePositionName.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.position,
2024-02-08 19:46:18 +07:00
profilePosType:
posMaster.next_holder == null
? positionMasterOld == null
? posType.join(" หรือ ")
: profilePosType.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posType.posTypeName,
2024-02-08 19:46:18 +07:00
profilePosLevel:
posMaster.next_holder == null
? positionMasterOld == null
? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posLevel.posLevelName,
2024-02-08 19:46:18 +07:00
profilePosExecutive:
posMaster.next_holder == null
? positionMasterOld == null
? posExecutive.join(" หรือ ")
: profilePosExecutive.join(" หรือ ")
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.positions.find(
2024-02-08 19:46:18 +07:00
(x: any) => (x.positionIsSelected = true),
2024-02-07 21:20:04 +07:00
)?.posExecutive?.posExecutiveName,
2024-02-08 18:04:54 +07:00
};
2024-02-08 19:46:18 +07:00
if (_node == null) {
2024-02-08 18:04:54 +07:00
const head = {
2024-02-08 19:46:18 +07:00
posMasterNo: node.orgTreeShortName,
profileFullname: node.profileOrgName,
posExecutive: node.orgTreeName,
2024-02-08 18:04:54 +07:00
positionName: "",
posType: "",
posLevel: "",
2024-02-08 19:46:18 +07:00
profilePosMasterNo: node.profileOrgShortName,
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
2024-02-08 19:46:18 +07:00
const _head = {
no: no,
posMasterNo: node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
profilePosLevel: node.profilePosLevel,
};
data.push(_head);
} else {
if (
node.orgTreeShortName != _node.orgTreeShortName ||
node.orgTreeName != _node.orgTreeName ||
node.profileOrgShortName != _node.profileOrgShortName ||
node.profileOrgName != _node.profileOrgName
) {
const head = {
posMasterNo:
node.orgTreeShortName == _node.orgTreeShortName
? ""
: node.orgTreeShortName,
profileFullname:
node.profileOrgName == _node.profileOrgName
? ""
: node.profileOrgName,
posExecutive:
node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo:
node.profileOrgShortName == _node.profileOrgShortName
? ""
: node.profileOrgShortName,
profilePosExecutive: "",
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
_node == null;
}
const head = {
no: no,
posMasterNo:
node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName:
node.positionName == _node.positionName ? "" : node.positionName,
posType: node.posType == _node.posType ? "" : node.posType,
posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel,
profilePosMasterNo:
node.profilePosMasterNo == _node.profilePosMasterNo
? ""
: node.profilePosMasterNo,
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
: node.profilePosExecutive,
profilePositionName:
node.profilePositionName == _node.profilePositionName
? ""
: node.profilePositionName,
profilePosType:
node.profilePosType == _node.profilePosType ? "" : node.profilePosType,
profilePosLevel:
node.profilePosLevel == _node.profilePosLevel
? ""
: node.profilePosLevel,
};
data.push(head);
2024-02-08 18:04:54 +07:00
}
2024-02-08 19:46:18 +07:00
no += 1;
_node = node;
2024-02-07 21:20:04 +07:00
}
}),
);
_node = null;
for (let orgChild4 of orgChild4Data.filter(
(orgChild4) => orgChild4.orgChild3Id === orgChild3.id,
)) {
await Promise.all(
orgChild4.posMasters
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
.map(async (posMaster) => {
const positionName = [
...new Set(posMaster.positions.map((x) => x.positionName)),
];
const posType = [
...new Set(posMaster.positions.map((x) => x.posType.posTypeName)),
];
const posLevel = [
...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)),
];
const posExecutive = [
...new Set(posMaster.positions.map((x) => x.posExecutive.posExecutiveName)),
];
let positionMasterProfileOld: any = null;
if (posMaster.next_holder != null) {
positionMasterProfileOld = posMaster.next_holder.current_holders.find(
(x) => x.orgRevisionId == orgRevisionActive.id,
);
}
let positionMasterOld: any = null;
let profilePositionName: any = [];
let profilePosType: any = [];
let profilePosLevel: any = [];
let profilePosExecutive: any = [];
if (posMaster.ancestorDNA != null) {
positionMasterOld = orgRevisionActive.posMasters.find(
(x: any) =>
x.orgRevisionId == orgRevisionActive.id &&
x.ancestorDNA == posMaster.ancestorDNA,
);
profilePositionName = [
...new Set(positionMasterOld.positions.map((x: any) => x.positionName)),
];
profilePosType = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posType.posTypeName),
),
];
profilePosLevel = [
...new Set(
positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName),
),
];
profilePosExecutive = [
...new Set(
positionMasterOld.positions.map(
(x: any) => x.posExecutive.posExecutiveName,
),
),
];
}
let node = {
posMasterOrder: posMaster.posMasterOrder, //
isSit: posMaster.isSit, //
orgTreeName: orgChild4.orgChild4Name,
orgTreeShortName: orgChild4.orgChild4ShortName,
posMasterNo: posMaster.posMasterNo,
positionName:
posMaster.next_holder == null
? positionName.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.positionName
: posMaster.next_holder.position,
posType:
posMaster.next_holder == null
? posType.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posType
?.posTypeName
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posType.posTypeName,
posLevel:
posMaster.next_holder == null
? posLevel.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posLevel
?.posLevelName
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posLevel.posLevelName,
posExecutive:
posMaster.next_holder == null
? posExecutive.join(" หรือ ")
: posMaster.isSit == false
? posMaster.positions.find((x: any) => (x.isSit = true))?.posExecutive
?.posExecutiveName
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.positions.find(
(x: any) => (x.isSit = true),
)?.posExecutive?.posExecutiveName,
profileOrgName:
posMaster.next_holder == null
? orgChild4.orgChild4Name
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4Name
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3Name
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2Name
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1Name
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootName
2024-02-08 19:46:18 +07:00
: "-",
2024-02-07 21:20:04 +07:00
profileOrgShortName:
posMaster.next_holder == null
? orgChild4.orgChild4ShortName
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.orgChild4 != null
? positionMasterProfileOld.orgChild4.orgChild4ShortName
: positionMasterProfileOld.orgChild3 != null
? positionMasterProfileOld.orgChild3.orgChild3ShortName
: positionMasterProfileOld.orgChild2 != null
? positionMasterProfileOld.orgChild2.orgChild2ShortName
: positionMasterProfileOld.orgChild1 != null
? positionMasterProfileOld.orgChild1.orgChild1ShortName
: positionMasterProfileOld.orgRoot != null
? positionMasterProfileOld.orgRoot.orgRootShortName
2024-02-08 19:46:18 +07:00
: "-",
2024-02-07 21:20:04 +07:00
profileFullname:
posMaster.next_holder == null
? "- ว่าง -"
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
profilePosMasterNo:
posMaster.next_holder == null
? positionMasterOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterOld.posMasterNo
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.posMasterNo,
profilePositionName:
posMaster.next_holder == null
? positionMasterOld == null
? positionName.join(" หรือ ")
: profilePositionName.join(" หรือ ")
: posMaster.next_holder.position,
profilePosType:
posMaster.next_holder == null
? positionMasterOld == null
? posType.join(" หรือ ")
: profilePosType.join(" หรือ ")
: posMaster.next_holder.posType == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posType.posTypeName,
profilePosLevel:
posMaster.next_holder == null
? positionMasterOld == null
? posLevel.join(" หรือ ")
: profilePosLevel.join(" หรือ ")
: posMaster.next_holder.posLevel == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: posMaster.next_holder.posLevel.posLevelName,
profilePosExecutive:
posMaster.next_holder == null
? positionMasterOld == null
? posExecutive.join(" หรือ ")
: profilePosExecutive.join(" หรือ ")
: positionMasterProfileOld == null
2024-02-08 19:46:18 +07:00
? "-"
2024-02-07 21:20:04 +07:00
: positionMasterProfileOld.positions.find(
(x: any) => (x.positionIsSelected = true),
)?.posExecutive?.posExecutiveName,
};
2024-02-08 18:04:54 +07:00
if (_node == null) {
const head = {
posMasterNo: node.orgTreeShortName,
2024-02-08 19:46:18 +07:00
profileFullname: node.profileOrgName,
posExecutive: node.orgTreeName,
2024-02-08 18:04:54 +07:00
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo: node.profileOrgShortName,
2024-02-08 19:46:18 +07:00
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
const _head = {
2024-02-08 19:46:18 +07:00
no: no,
2024-02-08 18:04:54 +07:00
posMasterNo: node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
profilePosLevel: node.profilePosLevel,
};
data.push(_head);
} else {
if (
2024-02-08 19:46:18 +07:00
node.orgTreeShortName != _node.orgTreeShortName ||
node.orgTreeName != _node.orgTreeName ||
node.profileOrgShortName != _node.profileOrgShortName ||
2024-02-08 18:04:54 +07:00
node.profileOrgName != _node.profileOrgName
) {
const head = {
posMasterNo:
node.orgTreeShortName == _node.orgTreeShortName
? ""
: node.orgTreeShortName,
profileFullname:
2024-02-08 19:46:18 +07:00
node.profileOrgName == _node.profileOrgName
? ""
: node.profileOrgName,
posExecutive:
2024-02-08 18:04:54 +07:00
node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName,
positionName: "",
posType: "",
posLevel: "",
profilePosMasterNo:
node.profileOrgShortName == _node.profileOrgShortName
? ""
: node.profileOrgShortName,
2024-02-08 19:46:18 +07:00
profilePosExecutive: "",
2024-02-08 18:04:54 +07:00
profilePositionName: "",
profilePosType: "",
profilePosLevel: "",
};
data.push(head);
_node == null;
}
const head = {
2024-02-08 19:46:18 +07:00
no: no,
2024-02-08 18:04:54 +07:00
posMasterNo:
node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo,
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName:
node.positionName == _node.positionName ? "" : node.positionName,
posType: node.posType == _node.posType ? "" : node.posType,
posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel,
profilePosMasterNo:
node.profilePosMasterNo == _node.profilePosMasterNo
? ""
: node.profilePosMasterNo,
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
: node.profilePosExecutive,
profilePositionName:
node.profilePositionName == _node.profilePositionName
? ""
: node.profilePositionName,
profilePosType:
node.profilePosType == _node.profilePosType ? "" : node.profilePosType,
profilePosLevel:
node.profilePosLevel == _node.profilePosLevel
? ""
: node.profilePosLevel,
};
data.push(head);
2024-02-07 21:20:04 +07:00
}
2024-02-08 19:46:18 +07:00
no += 1;
2024-02-07 21:20:04 +07:00
_node = node;
}),
);
_node = null;
}
}
}
}
2024-02-07 11:08:55 +07:00
}
2024-02-07 21:20:04 +07:00
return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } });
} catch (error) {
return error;
}
}
}