เพิ่มเหตุผล posmaster

This commit is contained in:
Kittapath 2024-04-09 12:18:52 +07:00
parent 7a2ed91612
commit 013ccf60e6
7 changed files with 433 additions and 72 deletions

View file

@ -242,6 +242,7 @@ export class EmployeePositionController extends Controller {
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
reason: posMaster.reason,
positions: positions.map((position) => ({
id: position.id,
positionName: position.positionName,
@ -612,6 +613,7 @@ export class EmployeePositionController extends Controller {
posMaster.posMasterNo = requestBody.posMasterNo;
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
posMaster.reason = requestBody.reason;
posMaster.orgRootId = null;
posMaster.orgChild1Id = null;
posMaster.orgChild2Id = null;
@ -1122,6 +1124,7 @@ export class EmployeePositionController extends Controller {
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
reason: posMaster.reason,
fullNameCurrentHolder:
posMaster.current_holder == null
? null
@ -1353,6 +1356,7 @@ export class EmployeePositionController extends Controller {
posMasterNoPrefix: item.posMasterNoPrefix ? item.posMasterNoPrefix : null,
posMasterNo: item.posMasterNo ? item.posMasterNo : null,
posMasterNoSuffix: item.posMasterNoSuffix ? item.posMasterNoSuffix : null,
reason: item.reason ? item.reason : null,
}));
return new HttpSuccess(_data);
}
@ -1440,6 +1444,14 @@ export class EmployeePositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeePosMasterRepository.findOne({
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgRootId == org.id &&
posMaster.orgChild1Id == null &&
@ -1461,6 +1473,14 @@ export class EmployeePositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeePosMasterRepository.findOne({
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgChild1Id == org.id &&
posMaster.orgChild2Id == null &&
@ -1481,6 +1501,14 @@ export class EmployeePositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeePosMasterRepository.findOne({
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgChild2Id == org.id &&
posMaster.orgChild3Id == null &&
@ -1500,6 +1528,14 @@ export class EmployeePositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeePosMasterRepository.findOne({
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false;
posMaster.orgRootId = org.orgRootId;
posMaster.orgChild1Id = org.orgChild1Id;
@ -1514,6 +1550,14 @@ export class EmployeePositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.employeePosMasterRepository.findOne({
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (posMaster.orgChild4Id == org.id) change = false;
posMaster.orgRootId = org.orgRootId;
posMaster.orgChild1Id = org.orgChild1Id;
@ -1524,7 +1568,7 @@ export class EmployeePositionController extends Controller {
}
}
if (change == true) {
posMaster.posMasterNo = maxPosMasterNo += 1;
// posMaster.posMasterNo = maxPosMasterNo += 1;
posMaster.posMasterOrder = maxPosMasterOrder += 1;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;

View file

@ -471,6 +471,7 @@ export class PositionController extends Controller {
orgChild2Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild3Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild4Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
reason: "บริหาร",
positions: [
{
posDictName: "นักบริหาร",
@ -745,6 +746,7 @@ export class PositionController extends Controller {
orgChild2Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild3Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
orgChild4Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
reason: "บริหาร",
positions: [
{
posDictName: "นักบริหาร",
@ -770,6 +772,7 @@ export class PositionController extends Controller {
posMaster.posMasterNo = requestBody.posMasterNo;
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
posMaster.reason = requestBody.reason;
posMaster.orgRootId = null;
posMaster.orgChild1Id = null;
posMaster.orgChild2Id = null;
@ -982,6 +985,7 @@ export class PositionController extends Controller {
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
reason: posMaster.reason,
positions: positions.map((position) => ({
id: position.id,
positionName: position.positionName,
@ -1303,6 +1307,7 @@ export class PositionController extends Controller {
posMasterNoPrefix: posMaster.posMasterNoPrefix,
posMasterNo: posMaster.posMasterNo,
posMasterNoSuffix: posMaster.posMasterNoSuffix,
reason: posMaster.reason,
fullNameCurrentHolder:
posMaster.current_holder == null
? null
@ -1536,6 +1541,7 @@ export class PositionController extends Controller {
posMasterNoPrefix: item.posMasterNoPrefix ? item.posMasterNoPrefix : null,
posMasterNo: item.posMasterNo ? item.posMasterNo : null,
posMasterNoSuffix: item.posMasterNoSuffix ? item.posMasterNoSuffix : null,
reason: item.reason ? item.reason : null,
}));
return new HttpSuccess(_data);
}
@ -1612,7 +1618,7 @@ export class PositionController extends Controller {
...type4LastPosMasterNo,
];
let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
// let maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0);
let maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0);
posMasters.forEach(async (posMaster: any) => {
@ -1623,6 +1629,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgRootId: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgRootShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgRootId == org.id &&
posMaster.orgChild1Id == null &&
@ -1644,6 +1658,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild1Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild1ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgChild1Id == org.id &&
posMaster.orgChild2Id == null &&
@ -1664,6 +1686,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild2Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild2ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (
posMaster.orgChild2Id == org.id &&
posMaster.orgChild3Id == null &&
@ -1683,6 +1713,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild3Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild3ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (posMaster.orgChild3Id == org.id && posMaster.orgChild4Id == null) change = false;
posMaster.orgRootId = org.orgRootId;
posMaster.orgChild1Id = org.orgChild1Id;
@ -1697,6 +1735,14 @@ export class PositionController extends Controller {
where: { id: requestBody.id },
});
if (org != null) {
const _posMaster = await this.posMasterRepository.findOne({
where: { orgChild4Id: org.id, posMasterNo: posMaster.posMasterNo },
});
if (_posMaster != null)
throw new HttpError(
HttpStatusCode.NOT_FOUND,
`เลขที่ตำแหน่ง ${org.orgChild4ShortName}${posMaster.posMasterNo} มีอยู่ในระบบอยู่แล้ว`,
);
if (posMaster.orgChild4Id == org.id) change = false;
posMaster.orgRootId = org.orgRootId;
posMaster.orgChild1Id = org.orgChild1Id;
@ -1707,7 +1753,6 @@ export class PositionController extends Controller {
}
}
if (change == true) {
posMaster.posMasterNo = maxPosMasterNo += 1;
posMaster.posMasterOrder = maxPosMasterOrder += 1;
posMaster.createdUserId = request.user.sub;
posMaster.createdFullName = request.user.name;

View file

@ -27,6 +27,7 @@ import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import Extension from "../interfaces/extension";
@Route("api/v1/org/report")
@Tags("Report")
@Security("bearerAuth")
@ -174,6 +175,7 @@ export class ReportController extends Controller {
posType: posType.join(" หรือ "),
posLevel: posLevel.join(" หรือ "),
posExecutive: posExecutive.join(" หรือ "),
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -187,12 +189,15 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -214,12 +219,15 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -270,7 +278,7 @@ export class ReportController extends Controller {
posType: posType.join(" หรือ "),
posLevel: posLevel.join(" หรือ "),
posExecutive: posExecutive.join(" หรือ "),
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -284,12 +292,15 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -313,12 +324,15 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -369,7 +383,7 @@ export class ReportController extends Controller {
positionName: positionName.join(" หรือ "),
posType: posType.join(" หรือ "),
posLevel: posLevel.join(" หรือ "),
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -383,12 +397,15 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -412,13 +429,16 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -471,7 +491,7 @@ export class ReportController extends Controller {
posType: posType.join(" หรือ "),
posLevel: posLevel.join(" หรือ "),
posExecutive: posExecutive.join(" หรือ "),
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -485,12 +505,15 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -515,13 +538,16 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -572,7 +598,7 @@ export class ReportController extends Controller {
posType: posType.join(" หรือ "),
posLevel: posLevel.join(" หรือ "),
posExecutive: posExecutive.join(" หรือ "),
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -586,12 +612,15 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -616,13 +645,16 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -1047,13 +1079,16 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
@ -1094,13 +1129,16 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
@ -1335,13 +1373,16 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
@ -1384,13 +1425,16 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
@ -1625,13 +1669,19 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo:
node.profilePosMasterNo == null
? ""
: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
@ -1674,14 +1724,20 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo:
node.profilePosMasterNo == null
? ""
: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
@ -1918,13 +1974,19 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo:
node.profilePosMasterNo == null
? ""
: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
@ -1968,14 +2030,20 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo:
node.profilePosMasterNo == null
? ""
: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
@ -2211,13 +2279,19 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo:
node.profilePosMasterNo == null
? ""
: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive: node.profilePosExecutive,
profilePositionName: node.profilePositionName,
profilePosType: node.profilePosType,
@ -2261,14 +2335,20 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
posType: node.posType,
posLevel: node.posLevel,
profilePosMasterNo: node.profilePosMasterNo,
profilePosMasterNo:
node.profilePosMasterNo == null
? ""
: Extension.ToThaiNumber(node.profilePosMasterNo.toString()),
profilePosExecutive:
node.profilePosExecutive == _node.profilePosExecutive
? ""
@ -2540,7 +2620,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -2559,7 +2639,10 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive == undefined ? "" : node.posExecutive,
positionName: node.positionName,
@ -2569,7 +2652,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -2596,7 +2679,10 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
@ -2606,7 +2692,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -2670,7 +2756,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -2689,7 +2775,10 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
@ -2699,7 +2788,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -2728,7 +2817,10 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
positionName: node.positionName,
@ -2738,7 +2830,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -2801,7 +2893,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -2820,7 +2912,10 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
@ -2830,7 +2925,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -2859,7 +2954,10 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
@ -2870,7 +2968,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -2933,7 +3031,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -2952,7 +3050,10 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
@ -2962,7 +3063,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -2992,7 +3093,10 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
@ -3003,7 +3107,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(head);
}
@ -3066,7 +3170,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: posMaster.reason,
};
if (_node == null) {
const head = {
@ -3085,7 +3189,10 @@ export class ReportController extends Controller {
data.push(head);
const _head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive: node.posExecutive,
positionName: node.positionName,
@ -3095,7 +3202,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(_head);
} else {
@ -3125,7 +3232,10 @@ export class ReportController extends Controller {
}
const head = {
no: no,
posMasterNo: node.posMasterNo,
posMasterNo:
node.posMasterNo == null
? ""
: Extension.ToThaiNumber(node.posMasterNo.toString()),
profileFullname: node.profileFullname,
posExecutive:
node.posExecutive == _node.posExecutive ? "" : node.posExecutive,
@ -3136,7 +3246,7 @@ export class ReportController extends Controller {
salary: "",
positionSalaryAmount: "",
mouthSalaryAmount: "",
reason: "",
reason: node.reason,
};
data.push(head);
}

View file

@ -87,6 +87,14 @@ export class EmployeePosMaster extends EntityBase {
})
isSit: boolean;
@Column({
nullable: true,
comment: "หมายเหตุ",
type: "text",
default: null,
})
reason: string;
@Column({
nullable: true,
length: 40,
@ -214,6 +222,9 @@ export class CreateEmployeePosMaster {
@Column("uuid")
orgChild4Id?: string | null;
@Column()
reason: string;
}
export type UpdateEmployeePosMaster = Partial<EmployeePosMaster>;

View file

@ -86,6 +86,14 @@ export class PosMaster extends EntityBase {
})
isSit: boolean;
@Column({
nullable: true,
comment: "หมายเหตุ",
type: "text",
default: null,
})
reason: string;
@Column({
nullable: true,
length: 40,
@ -213,6 +221,9 @@ export class CreatePosMaster {
@Column("uuid")
orgChild4Id?: string | null;
@Column()
reason: string;
}
export type UpdatePosMaster = Partial<PosMaster>;

124
src/interfaces/extension.ts Normal file
View file

@ -0,0 +1,124 @@
class Extension {
public static ToThaiMonth(value: number) {
switch (value) {
case 1:
return "มกราคม";
case 2:
return "กุมภาพันธ์";
case 3:
return "มีนาคม";
case 4:
return "เมษายน";
case 5:
return "พฤษภาคม";
case 6:
return "มิถุนายน";
case 7:
return "กรกฎาคม";
case 8:
return "สิงหาคม";
case 9:
return "กันยายน";
case 10:
return "ตุลาคม";
case 11:
return "พฤศจิกายน";
case 12:
return "ธันวาคม";
default:
return "";
}
}
public static ToThaiShortMonth(value: number) {
switch (value) {
case 1:
return "ม.ค.";
case 2:
return "ก.พ.";
case 3:
return "มี.ค.";
case 4:
return "เม.ย.";
case 5:
return "พ.ค.";
case 6:
return "มิ.ย.";
case 7:
return "ก.ค.";
case 8:
return "ส.ค.";
case 9:
return "ก.ย.";
case 10:
return "ต.ค.";
case 11:
return "พ.ย.";
case 12:
return "ธ.ค.";
default:
return "";
}
}
public static ToThaiYear(value: number) {
if (value < 2400) return value + 543;
else return value;
}
public static ToCeYear(value: number) {
if (value >= 2400) return value - 543;
else return value;
}
public static ToThaiNumber(value: string) {
let arabicNumbers = "0123456789";
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
let result = "";
for (let digit of value) {
let index = arabicNumbers.indexOf(digit);
if (index >= 0) {
result += thaiNumbers[index];
} else {
result += digit;
}
}
return result;
}
public static ToThaiFullDate(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return (
"วันที่ " +
value.getDate() +
" เดือน " +
Extension.ToThaiMonth(value.getMonth() + 1) +
" พ.ศ. " +
yy
);
}
public static ToThaiShortDate(value: Date) {
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
return (
"วันที่ " +
value.getDate() +
" " +
Extension.ToThaiShortMonth(value.getMonth() + 1) +
" " +
yy.toString().slice(-2)
);
}
public static sumObjectValues(array: any, propertyName: any) {
let sum = 0;
for (let i = 0; i < array.length; i++) {
if (array[i][propertyName] !== undefined) {
sum += array[i][propertyName];
}
}
return sum;
}
}
export default Extension;

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTablePosmasterAddReason1712639179589 implements MigrationInterface {
name = 'UpdateTablePosmasterAddReason1712639179589'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`employeePosMaster\` ADD \`reason\` text NULL COMMENT 'หมายเหตุ'`);
await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`reason\` text NULL COMMENT 'หมายเหตุ'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`reason\``);
await queryRunner.query(`ALTER TABLE \`employeePosMaster\` DROP COLUMN \`reason\``);
}
}