add report temp

This commit is contained in:
kittapath 2025-02-20 15:36:26 +07:00
parent 5d185ee60e
commit 3edc66081f
3 changed files with 190 additions and 84 deletions

View file

@ -328,8 +328,8 @@ export class ImportDataController extends Controller {
.createQueryBuilder("profile") .createQueryBuilder("profile")
.select(["profile.citizenId", "profile.id"]) .select(["profile.citizenId", "profile.id"])
.orderBy("profile.citizenId", "ASC") .orderBy("profile.citizenId", "ASC")
// .skip(0) .skip(0)
// .take(1000) .take(10000)
.getManyAndCount(); .getManyAndCount();
// for (var i = 1; i <= total / BATCH_SIZE; i++) { // for (var i = 1; i <= total / BATCH_SIZE; i++) {
// const profiles = await AppDataSource.getRepository(Profile) // const profiles = await AppDataSource.getRepository(Profile)
@ -342,6 +342,7 @@ export class ImportDataController extends Controller {
await Promise.all( await Promise.all(
profiles.map(async (_item) => { profiles.map(async (_item) => {
console.log(">>>>>>>>>>>>>>>>>>>" + _item.citizenId);
const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ const existingProfile = await this.HR_POSITION_OFFICERRepo.find({
where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" }, where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" },
select: [ select: [

View file

@ -1671,7 +1671,7 @@ export class ProfileEmployeeTempController extends Controller {
} }
const [profiles, total] = await this.profileRepo const [profiles, total] = await this.profileRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.next_holders", "next_holders") .leftJoinAndSelect("profileEmployee.next_holderTemps", "next_holderTemps")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
.leftJoinAndSelect("profileEmployee.posType", "posType") .leftJoinAndSelect("profileEmployee.posType", "posType")
.where( .where(
@ -1682,6 +1682,7 @@ export class ProfileEmployeeTempController extends Controller {
position: `%${requestBody.position}%`, position: `%${requestBody.position}%`,
}, },
) )
.andWhere("profileEmployee.isLeave IS FALSE")
.andWhere( .andWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.where( qb.where(
@ -1738,17 +1739,17 @@ export class ProfileEmployeeTempController extends Controller {
new Brackets((qb) => { new Brackets((qb) => {
qb.where("profileEmployee.id NOT IN (:...ids)", { qb.where("profileEmployee.id NOT IN (:...ids)", {
ids: ids:
orgRevision.employeePosMasters orgRevision.employeeTempPosMasters
.filter((x) => x.next_holderId != null) .filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId).length == 0 .map((x) => x.next_holderId).length == 0
? ["zxc"] ? ["zxc"]
: orgRevision.employeePosMasters : orgRevision.employeeTempPosMasters
.filter((x) => x.next_holderId != null) .filter((x) => x.next_holderId != null)
.map((x) => x.next_holderId), .map((x) => x.next_holderId),
}); });
}), }),
) )
.andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "PERM" }) .andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "TEMP" })
.skip((requestBody.page - 1) * requestBody.pageSize) .skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize) .take(requestBody.pageSize)
.getManyAndCount(); .getManyAndCount();

View file

@ -30,6 +30,7 @@ import HttpStatus from "../interfaces/http-status";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer";
import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee";
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
@Route("api/v1/org/report") @Route("api/v1/org/report")
@Tags("Report") @Tags("Report")
@Security("bearerAuth") @Security("bearerAuth")
@ -49,6 +50,7 @@ export class ReportController extends Controller {
private posMasterRepository = AppDataSource.getRepository(PosMaster); private posMasterRepository = AppDataSource.getRepository(PosMaster);
private profileRepository = AppDataSource.getRepository(Profile); private profileRepository = AppDataSource.getRepository(Profile);
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster); private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
private empTempPosMasterRepository = AppDataSource.getRepository(EmployeeTempPosMaster);
/** /**
* API . * API .
@ -85,12 +87,12 @@ export class ReportController extends Controller {
// }); // });
// const rawdataProfile = await this.posMasterRepository // const rawdataProfile = await this.posMasterRepository
// .createQueryBuilder('posMaster') // .createQueryBuilder('posMaster')
// .leftJoinAndSelect('posMaster.current_holder', 'current_holder') // .leftJoinAndSelect('posMaster.current_holder', 'current_holder')
// .leftJoinAndSelect('posMaster.positions', 'positions') // .leftJoinAndSelect('posMaster.positions', 'positions')
// .leftJoinAndSelect('posMaster.orgRoot', 'orgRoot') // .leftJoinAndSelect('posMaster.orgRoot', 'orgRoot')
// .leftJoinAndSelect('positions.posExecutive', 'posExecutive') // .leftJoinAndSelect('positions.posExecutive', 'posExecutive')
// .leftJoinAndSelect('current_holder.posType', 'posType') // .leftJoinAndSelect('current_holder.posType', 'posType')
// .leftJoinAndSelect('current_holder.posLevel', 'posLevel') // .leftJoinAndSelect('current_holder.posLevel', 'posLevel')
// .leftJoinAndSelect('current_holder.profileEducations', 'profileEducations') // .leftJoinAndSelect('current_holder.profileEducations', 'profileEducations')
// .where('posMaster.orgRevisionId = :currentRevisionId', { currentRevisionId: currentRevision?.id }) // .where('posMaster.orgRevisionId = :currentRevisionId', { currentRevisionId: currentRevision?.id })
// .andWhere(rootId?'posMaster.orgRootId = :rootId': "1=1", { rootId: rootId }) // .andWhere(rootId?'posMaster.orgRootId = :rootId': "1=1", { rootId: rootId })
@ -187,7 +189,7 @@ export class ReportController extends Controller {
@Query() isRetire?: boolean, @Query() isRetire?: boolean,
@Query() retireType?: string, @Query() retireType?: string,
@Query() sortBy: string = "posMasterNo", @Query() sortBy: string = "posMasterNo",
@Query() sort: "ASC"|"DESC" = "ASC", @Query() sort: "ASC" | "DESC" = "ASC",
) { ) {
if (ageMin && (ageMin < 18 || ageMin > 60)) { if (ageMin && (ageMin < 18 || ageMin > 60)) {
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60"); throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60");
@ -195,7 +197,7 @@ export class ReportController extends Controller {
if (ageMax && (ageMax < 18 || ageMax > 60)) { if (ageMax && (ageMax < 18 || ageMax > 60)) {
throw new HttpError(HttpStatus.NOT_FOUND, "ageMax must be between 18 and 60"); throw new HttpError(HttpStatus.NOT_FOUND, "ageMax must be between 18 and 60");
} }
if (ageMin && ageMax && (ageMin > ageMax)) { if (ageMin && ageMax && ageMin > ageMax) {
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax"); throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax");
} }
ageMin = ageMin ?? 18; ageMin = ageMin ?? 18;
@ -204,22 +206,19 @@ export class ReportController extends Controller {
let nodeCondition = "1=1"; let nodeCondition = "1=1";
if (node === 0 && nodeId) { if (node === 0 && nodeId) {
nodeCondition = "registryOfficer.orgRootId = :nodeId"; nodeCondition = "registryOfficer.orgRootId = :nodeId";
} } else if (node === 1 && nodeId) {
else if (node === 1 && nodeId) {
nodeCondition = "registryOfficer.orgChild1Id = :nodeId"; nodeCondition = "registryOfficer.orgChild1Id = :nodeId";
} } else if (node === 2 && nodeId) {
else if (node === 2 && nodeId) {
nodeCondition = "registryOfficer.orgChild2Id = :nodeId"; nodeCondition = "registryOfficer.orgChild2Id = :nodeId";
} } else if (node === 3 && nodeId) {
else if (node === 3 && nodeId) {
nodeCondition = "registryOfficer.orgChild3Id = :nodeId"; nodeCondition = "registryOfficer.orgChild3Id = :nodeId";
} } else if (node === 4 && nodeId) {
else if (node === 4 && nodeId) {
nodeCondition = "registryOfficer.orgChild4Id = :nodeId"; nodeCondition = "registryOfficer.orgChild4Id = :nodeId";
} }
let dateAppointCondition = "1=1"; let dateAppointCondition = "1=1";
if (startDateAppoint && endDateAppoint) { if (startDateAppoint && endDateAppoint) {
dateAppointCondition = "DATE(registryOfficer.dateAppoint) >= :startDateAppoint AND DATE(registryOfficer.dateAppoint) <= :endDateAppoint"; dateAppointCondition =
"DATE(registryOfficer.dateAppoint) >= :startDateAppoint AND DATE(registryOfficer.dateAppoint) <= :endDateAppoint";
} else if (startDateAppoint) { } else if (startDateAppoint) {
dateAppointCondition = "DATE(registryOfficer.dateAppoint) >= :startDateAppoint"; dateAppointCondition = "DATE(registryOfficer.dateAppoint) >= :startDateAppoint";
} else if (endDateAppoint) { } else if (endDateAppoint) {
@ -236,15 +235,16 @@ export class ReportController extends Controller {
const [lists, total] = await AppDataSource.getRepository(viewRegistryOfficer) const [lists, total] = await AppDataSource.getRepository(viewRegistryOfficer)
.createQueryBuilder("registryOfficer") .createQueryBuilder("registryOfficer")
.where(nodeCondition, { .where(nodeCondition, {
nodeId: nodeId nodeId: nodeId,
}) })
.andWhere("registryOfficer.age BETWEEN :ageMin AND :ageMax", { .andWhere("registryOfficer.age BETWEEN :ageMin AND :ageMax", {
ageMin, ageMax ageMin,
ageMax,
}) })
.andWhere(dateAppointCondition, { .andWhere(dateAppointCondition, {
startDateAppoint: startDateAppoint?.toISOString().split("T")[0], startDateAppoint: startDateAppoint?.toISOString().split("T")[0],
endDateAppoint: endDateAppoint?.toISOString().split("T")[0] endDateAppoint: endDateAppoint?.toISOString().split("T")[0],
}) })
.andWhere("registryOfficer.isProbation = :isProbation", { .andWhere("registryOfficer.isProbation = :isProbation", {
isProbation: isProbation, isProbation: isProbation,
@ -259,7 +259,7 @@ export class ReportController extends Controller {
{ {
posTypeName: `%${posTypeName}%`, posTypeName: `%${posTypeName}%`,
}, },
) );
qb.orWhere( qb.orWhere(
posLevelName != null && posLevelName != "" posLevelName != null && posLevelName != ""
? "registryOfficer.posLevelName LIKE :posLevelName" ? "registryOfficer.posLevelName LIKE :posLevelName"
@ -267,15 +267,13 @@ export class ReportController extends Controller {
{ {
posLevelName: `%${posLevelName}%`, posLevelName: `%${posLevelName}%`,
}, },
) );
qb.orWhere( qb.orWhere(
position != null && position != "" position != null && position != "" ? "registryOfficer.position LIKE :position" : "1=1",
? "registryOfficer.position LIKE :position"
: "1=1",
{ {
position: `%${position}%`, position: `%${position}%`,
}, },
) );
qb.orWhere( qb.orWhere(
posExecutiveName != null && posExecutiveName != "" posExecutiveName != null && posExecutiveName != ""
? "registryOfficer.posExecutiveName LIKE :posExecutiveName" ? "registryOfficer.posExecutiveName LIKE :posExecutiveName"
@ -283,15 +281,13 @@ export class ReportController extends Controller {
{ {
posExecutiveName: `%${posExecutiveName}%`, posExecutiveName: `%${posExecutiveName}%`,
}, },
) );
qb.orWhere( qb.orWhere(
gender != null && gender != "" gender != null && gender != "" ? "registryOfficer.gender LIKE :gender" : "1=1",
? "registryOfficer.gender LIKE :gender"
: "1=1",
{ {
gender: `%${gender}%`, gender: `%${gender}%`,
}, },
) );
qb.orWhere( qb.orWhere(
relationship != null && relationship != "" relationship != null && relationship != ""
? "registryOfficer.relationship LIKE :relationship" ? "registryOfficer.relationship LIKE :relationship"
@ -299,20 +295,18 @@ export class ReportController extends Controller {
{ {
relationship: `%${relationship}%`, relationship: `%${relationship}%`,
}, },
) );
qb.orWhere( qb.orWhere(
degree != null && degree != "" degree != null && degree != "" ? "registryOfficer.degree LIKE :degree" : "1=1",
? "registryOfficer.degree LIKE :degree"
: "1=1",
{ {
degree: `%${degree}%`, degree: `%${degree}%`,
}, },
) );
}), }),
) )
.orderBy(`registryOfficer.${sortBy}`, sort) .orderBy(`registryOfficer.${sortBy}`, sort)
.getManyAndCount(); .getManyAndCount();
const mapData = lists.map(x => ({ const mapData = lists.map((x) => ({
profileId: x.profileId, profileId: x.profileId,
citizenId: x.citizenId, citizenId: x.citizenId,
prefix: x.prefix, prefix: x.prefix,
@ -350,7 +344,7 @@ export class ReportController extends Controller {
})); }));
return new HttpSuccess({ return new HttpSuccess({
data: mapData, data: mapData,
total: total total: total,
}); });
} }
@ -434,7 +428,7 @@ export class ReportController extends Controller {
// }); // });
// const groupedData = mapData.reduce((acc: any, item) => { // const groupedData = mapData.reduce((acc: any, item) => {
// const key = `${item.affiliation} - ${item.gender} - ${item.degree || "ไม่พบข้อมูล"} - ${item.status || "ไม่พบข้อมูล"} - ${item.posType} - ${item.positionName} - ${item.posLevel} // const key = `${item.affiliation} - ${item.gender} - ${item.degree || "ไม่พบข้อมูล"} - ${item.status || "ไม่พบข้อมูล"} - ${item.posType} - ${item.positionName} - ${item.posLevel}
// `; // `;
// if (!acc[key]) { // if (!acc[key]) {
// acc[key] = { // acc[key] = {
@ -489,7 +483,7 @@ export class ReportController extends Controller {
@Query() ageMin?: number, @Query() ageMin?: number,
@Query() ageMax?: number, @Query() ageMax?: number,
@Query() sortBy: string = "posMasterNo", @Query() sortBy: string = "posMasterNo",
@Query() sort: "ASC"|"DESC" = "ASC", @Query() sort: "ASC" | "DESC" = "ASC",
) { ) {
if (ageMin && (ageMin < 18 || ageMin > 60)) { if (ageMin && (ageMin < 18 || ageMin > 60)) {
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60"); throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60");
@ -497,7 +491,7 @@ export class ReportController extends Controller {
if (ageMax && (ageMax < 18 || ageMax > 60)) { if (ageMax && (ageMax < 18 || ageMax > 60)) {
throw new HttpError(HttpStatus.NOT_FOUND, "ageMax must be between 18 and 60"); throw new HttpError(HttpStatus.NOT_FOUND, "ageMax must be between 18 and 60");
} }
if (ageMin && ageMax && (ageMin > ageMax)) { if (ageMin && ageMax && ageMin > ageMax) {
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax"); throw new HttpError(HttpStatus.NOT_FOUND, "ageMin cannot be greater than ageMax");
} }
ageMin = ageMin ?? 18; ageMin = ageMin ?? 18;
@ -506,22 +500,19 @@ export class ReportController extends Controller {
let nodeCondition = "1=1"; let nodeCondition = "1=1";
if (node === 0 && nodeId) { if (node === 0 && nodeId) {
nodeCondition = "registryEmployee.orgRootId = :nodeId"; nodeCondition = "registryEmployee.orgRootId = :nodeId";
} } else if (node === 1 && nodeId) {
else if (node === 1 && nodeId) {
nodeCondition = "registryEmployee.orgChild1Id = :nodeId"; nodeCondition = "registryEmployee.orgChild1Id = :nodeId";
} } else if (node === 2 && nodeId) {
else if (node === 2 && nodeId) {
nodeCondition = "registryEmployee.orgChild2Id = :nodeId"; nodeCondition = "registryEmployee.orgChild2Id = :nodeId";
} } else if (node === 3 && nodeId) {
else if (node === 3 && nodeId) {
nodeCondition = "registryEmployee.orgChild3Id = :nodeId"; nodeCondition = "registryEmployee.orgChild3Id = :nodeId";
} } else if (node === 4 && nodeId) {
else if (node === 4 && nodeId) {
nodeCondition = "registryEmployee.orgChild4Id = :nodeId"; nodeCondition = "registryEmployee.orgChild4Id = :nodeId";
} }
let dateAppointCondition = "1=1"; let dateAppointCondition = "1=1";
if (startDateAppoint && endDateAppoint) { if (startDateAppoint && endDateAppoint) {
dateAppointCondition = "DATE(registryEmployee.dateAppoint) >= :startDateAppoint AND DATE(registryEmployee.dateAppoint) <= :endDateAppoint"; dateAppointCondition =
"DATE(registryEmployee.dateAppoint) >= :startDateAppoint AND DATE(registryEmployee.dateAppoint) <= :endDateAppoint";
} else if (startDateAppoint) { } else if (startDateAppoint) {
dateAppointCondition = "DATE(registryEmployee.dateAppoint) >= :startDateAppoint"; dateAppointCondition = "DATE(registryEmployee.dateAppoint) >= :startDateAppoint";
} else if (endDateAppoint) { } else if (endDateAppoint) {
@ -537,15 +528,16 @@ export class ReportController extends Controller {
} }
const [lists, total] = await AppDataSource.getRepository(viewRegistryEmployee) const [lists, total] = await AppDataSource.getRepository(viewRegistryEmployee)
.createQueryBuilder("registryEmployee") .createQueryBuilder("registryEmployee")
.where(nodeCondition, { .where(nodeCondition, {
nodeId: nodeId nodeId: nodeId,
}) })
.andWhere("registryEmployee.age BETWEEN :ageMin AND :ageMax", { .andWhere("registryEmployee.age BETWEEN :ageMin AND :ageMax", {
ageMin, ageMax ageMin,
ageMax,
}) })
.andWhere(dateAppointCondition, { .andWhere(dateAppointCondition, {
startDateAppoint: startDateAppoint?.toISOString().split("T")[0], startDateAppoint: startDateAppoint?.toISOString().split("T")[0],
endDateAppoint: endDateAppoint?.toISOString().split("T")[0] endDateAppoint: endDateAppoint?.toISOString().split("T")[0],
}) })
.andWhere("registryEmployee.isProbation = :isProbation", { .andWhere("registryEmployee.isProbation = :isProbation", {
isProbation: isProbation, isProbation: isProbation,
@ -561,7 +553,7 @@ export class ReportController extends Controller {
{ {
posTypeName: `%${posTypeName}%`, posTypeName: `%${posTypeName}%`,
}, },
) );
qb.orWhere( qb.orWhere(
posLevelName != null && posLevelName != "" posLevelName != null && posLevelName != ""
? "registryEmployee.posLevelName LIKE :posLevelName" ? "registryEmployee.posLevelName LIKE :posLevelName"
@ -569,23 +561,19 @@ export class ReportController extends Controller {
{ {
posLevelName: `%${posLevelName}%`, posLevelName: `%${posLevelName}%`,
}, },
) );
qb.orWhere( qb.orWhere(
position != null && position != "" position != null && position != "" ? "registryEmployee.position LIKE :position" : "1=1",
? "registryEmployee.position LIKE :position"
: "1=1",
{ {
position: `%${position}%`, position: `%${position}%`,
}, },
) );
qb.orWhere( qb.orWhere(
gender != null && gender != "" gender != null && gender != "" ? "registryEmployee.gender LIKE :gender" : "1=1",
? "registryEmployee.gender LIKE :gender"
: "1=1",
{ {
gender: `%${gender}%`, gender: `%${gender}%`,
}, },
) );
qb.orWhere( qb.orWhere(
relationship != null && relationship != "" relationship != null && relationship != ""
? "registryEmployee.relationship LIKE :relationship" ? "registryEmployee.relationship LIKE :relationship"
@ -593,20 +581,18 @@ export class ReportController extends Controller {
{ {
relationship: `%${relationship}%`, relationship: `%${relationship}%`,
}, },
) );
qb.orWhere( qb.orWhere(
degree != null && degree != "" degree != null && degree != "" ? "registryEmployee.degree LIKE :degree" : "1=1",
? "registryEmployee.degree LIKE :degree"
: "1=1",
{ {
degree: `%${degree}%`, degree: `%${degree}%`,
}, },
) );
}), }),
) )
.orderBy(`registryEmployee.${sortBy}`, sort) .orderBy(`registryEmployee.${sortBy}`, sort)
.getManyAndCount(); .getManyAndCount();
const mapData = lists.map(x => ({ const mapData = lists.map((x) => ({
profileId: x.profileEmployeeId, profileId: x.profileEmployeeId,
citizenId: x.citizenId, citizenId: x.citizenId,
prefix: x.prefix, prefix: x.prefix,
@ -643,7 +629,7 @@ export class ReportController extends Controller {
})); }));
return new HttpSuccess({ return new HttpSuccess({
data: mapData, data: mapData,
total: total total: total,
}); });
} }
@ -7091,4 +7077,122 @@ export class ReportController extends Controller {
}, },
}); });
} }
@Get("report4-employee-temp/{rootId}")
async findReportEmp4Temp(@Path() rootId: string) {
const orgRootData = await this.orgRootRepository.findOne({
where: { id: rootId },
});
if (!orgRootData) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
const posMaster = await this.empTempPosMasterRepository
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.positions", "position")
.leftJoinAndSelect("position.posType", "posType")
.leftJoinAndSelect("position.posLevel", "posLevel")
.where("posMaster.orgRootId = :rootId", { rootId })
.orderBy("posType.posTypeRank", "ASC")
.addOrderBy("posLevel.posLevelRank", "ASC")
.getMany();
const _posMaster = posMaster.map((x) => ({
type: [...new Set(x.positions.flatMap((y) => y.posType.posTypeName))].join(","),
typeRank: [...new Set(x.positions.flatMap((y) => y.posType.posTypeRank))].join(""),
level: [...new Set(x.positions.flatMap((y) => y.posLevel.posLevelName))].join(","),
levelRank: [
...new Set(
x.positions.flatMap((y) => `${y.posType.posTypeRank}${y.posLevel.posLevelRank}`),
),
].join(""),
positions: [...new Set(x.positions.flatMap((y) => y.positionName))].join(""),
}));
const groupedData = _posMaster.reduce((acc: any, curr: any) => {
const key = `${curr.type}|${curr.typeRank}|${curr.level}|${curr.levelRank}`;
if (!acc[key]) {
acc[key] = { ...curr, total: 1 };
} else {
acc[key].total += 1;
}
return acc;
}, {});
let result = Object.values(groupedData)
.map((x: any) => ({
type: x.type,
typeRank: parseInt(x.typeRank),
level: x.level,
levelRank: parseInt(x.levelRank),
total: x.total,
remark: x.positions,
}))
.sort((x, y) => {
if (x.typeRank !== y.typeRank) {
return x.typeRank - y.typeRank;
}
return x.levelRank - y.levelRank;
});
let tmpType: string = "";
let allTotal: number = 0;
let total: number = 0;
let _total: number = 0;
let _reslut = new Array();
result.forEach((x: any, idx: number) => {
allTotal += x.total;
total += x.total;
if (x.type === tmpType) {
_reslut.push({
...x,
type: "",
});
} else {
if (x.type !== tmpType && tmpType != "") {
_total = total - x.total;
_reslut.push({
type: "",
typeRank: "",
level: "รวม",
levelRank: "",
total: _total,
remark: "",
});
total = x.total;
_total = 0;
}
_reslut.push({
...x,
});
}
tmpType = x.type;
});
_reslut.push({
type: "",
typeRank: "",
level: "รวม",
levelRank: "",
total: total,
remark: "",
});
_reslut.push({
type: "",
typeRank: "",
level: "รวมทั้งสิ้น",
levelRank: "",
total: allTotal,
remark: "",
});
return new HttpSuccess({
template: "report4",
reportName: "report4",
data: {
dateCurrent: Extension.ToThaiShortDate(new Date()),
rootName: orgRootData ? orgRootData.orgRootName : "-",
data: _reslut,
},
});
}
} }