This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-08-23 14:10:34 +07:00
parent ce8bb41bda
commit 0f79425d65
17 changed files with 611 additions and 202 deletions

View file

@ -32,6 +32,7 @@ import { SalaryRankEmployee } from "../entities/SalaryRankEmployee";
import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/salary/period-employee")
@Tags("SalaryEmployee")
@ -258,7 +259,7 @@ export class SalaryPeriodEmployeeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
await this.salaryProfileRepository.remove(salaryProfile);
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
@ -289,7 +290,7 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: request });
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
@ -343,7 +344,7 @@ export class SalaryPeriodEmployeeController extends Controller {
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: request });
}
}
}
@ -712,7 +713,9 @@ export class SalaryPeriodEmployeeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}
await this.salaryProfileRepository.save(salaryProfile);
const before = null;
await this.salaryProfileRepository.save(salaryProfile, { data: req });
setLogDataDiff(req, { before, after: salaryProfile });
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
@ -743,7 +746,8 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: req });
setLogDataDiff(req, { before, after: salaryOrg });
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
@ -797,7 +801,8 @@ export class SalaryPeriodEmployeeController extends Controller {
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: req });
setLogDataDiff(req, { before, after: salaryOrg });
}
}
}
@ -835,9 +840,10 @@ export class SalaryPeriodEmployeeController extends Controller {
if (!salaryOrg) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
}
const before = null;
salaryProfile.salaryOrgId = salaryOrg.id;
await this.salaryProfileRepository.save(salaryProfile);
await this.salaryProfileRepository.save(salaryProfile, { data: req });
setLogDataDiff(req, { before, after: salaryProfile });
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: { id: salaryProfile.id },
@ -867,7 +873,8 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: req });
setLogDataDiff(req, { before, after: salaryOrg });
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
@ -921,7 +928,8 @@ export class SalaryPeriodEmployeeController extends Controller {
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: req });
setLogDataDiff(req, { before, after: salaryOrg });
}
}
}
@ -1326,7 +1334,9 @@ export class SalaryPeriodEmployeeController extends Controller {
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}
await this.salaryProfileRepository.save(salaryProfile);
const before = null;
await this.salaryProfileRepository.save(salaryProfile, { data: req });
setLogDataDiff(req, { before, after: salaryProfile });
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
@ -1357,7 +1367,8 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: req });
setLogDataDiff(req, { before, after: salaryOrg });
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
@ -1411,7 +1422,8 @@ export class SalaryPeriodEmployeeController extends Controller {
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: req });
setLogDataDiff(req, { before, after: salaryOrg });
}
}
}
@ -1583,6 +1595,7 @@ export class SalaryPeriodEmployeeController extends Controller {
if (!salaryProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเพิ่มเงินเดือนของบุคคลนี้");
}
const before = structuredClone(salaryProfile);
salaryProfile.isPunish = body.isPunish;
salaryProfile.isSuspension = body.isSuspension;
salaryProfile.isAbsent = body.isAbsent;
@ -1590,7 +1603,9 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryProfile.lastUpdateUserId = request.user.sub;
salaryProfile.lastUpdateFullName = request.user.name;
salaryProfile.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salaryProfile);
await this.salaryProfileRepository.save(salaryProfile, { data: request });
setLogDataDiff(request, { before, after: salaryProfile });
return new HttpSuccess();
}
@ -1982,12 +1997,14 @@ export class SalaryPeriodEmployeeController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}
const before = null;
salaryProfile.salaryOrgId = salaryOrg.id;
salaryProfile.createdUserId = request.user.sub;
salaryProfile.createdFullName = request.user.name;
salaryProfile.lastUpdateUserId = request.user.sub;
salaryProfile.lastUpdateFullName = request.user.name;
await this.salaryProfileRepository.save(salaryProfile);
await this.salaryProfileRepository.save(salaryProfile, { data: request });
setLogDataDiff(request, { before, after: salaryProfile });
const _salaryProfile = await this.salaryProfileRepository.findOne({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
@ -2018,7 +2035,8 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryOrg.quantityUsed = amountFullType;
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
salaryOrg.remainQuota = calRemainQuota;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: request });
setLogDataDiff(request, { before, after: salaryOrg });
}
}
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
@ -2072,7 +2090,8 @@ export class SalaryPeriodEmployeeController extends Controller {
? 0
: sumAmountUse.totalAmount;
salaryOrg.remainingAmount = calRemainAmount;
await this.salaryOrgRepository.save(salaryOrg);
await this.salaryOrgRepository.save(salaryOrg, { data: request });
setLogDataDiff(request, { before, after: salaryOrg });
}
}
}
@ -2091,15 +2110,17 @@ export class SalaryPeriodEmployeeController extends Controller {
* @param {string} id Guid, *Id
*/
@Get("close/{id}")
async closeSalaryPeriod_ById(@Path() id: string) {
async closeSalaryPeriod_ById(@Path() id: string, @Request() request: RequestWithUser) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: id },
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
}
const before = structuredClone(salaryPeriod);
salaryPeriod.isClose = !salaryPeriod.isClose;
await this.salaryPeriodRepository.save(salaryPeriod);
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
setLogDataDiff(request, { before, after: salaryPeriod });
return new HttpSuccess();
}
@ -2135,13 +2156,14 @@ export class SalaryPeriodEmployeeController extends Controller {
"ประเภทผังปี " + Extension.ToThaiYear(salaryPeriod.year) + " ซ้ำ",
);
}
const before = null;
salaryPeriod.period = salaryPeriod.period.toUpperCase();
salaryPeriod.createdUserId = request.user.sub;
salaryPeriod.createdFullName = request.user.name;
salaryPeriod.lastUpdateUserId = request.user.sub;
salaryPeriod.lastUpdateFullName = request.user.name;
await this.salaryPeriodRepository.save(salaryPeriod);
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
setLogDataDiff(request, { before, after: salaryPeriod });
if (salaryPeriod.period == "SPECIAL") {
const snapshot = "SNAP1";
@ -2151,14 +2173,15 @@ export class SalaryPeriodEmployeeController extends Controller {
const salaryProfile = await this.salaryProfileRepository.find({
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
});
await this.salaryOrgRepository.remove(salaryOrg);
await this.salaryProfileRepository.remove(salaryProfile);
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
salaryPeriod.revisionId = revisionId;
await this.salaryPeriodRepository.save(salaryPeriod);
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
setLogDataDiff(request, { before, after: salaryPeriod });
await Promise.all(
orgs.map(async (rootId: string) => {
@ -2173,7 +2196,8 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryOrgNew.lastUpdateUserId = request.user.sub;
salaryOrgNew.lastUpdateFullName = request.user.name;
salaryOrgNew.group = "GROUP1";
await this.salaryOrgRepository.save(salaryOrgNew);
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
setLogDataDiff(request, { before, after: salaryOrgNew });
}),
);
}
@ -2219,13 +2243,15 @@ export class SalaryPeriodEmployeeController extends Controller {
"ประเภทผังปี " + (requestBody.effectiveDate.getFullYear() + 543) + " ซ้ำ",
);
}
const beforechk_SalaryPeriod = structuredClone(chk_SalaryPeriod);
chk_SalaryPeriod.period = requestBody.period.toUpperCase();
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
chk_SalaryPeriod.lastUpdatedAt = new Date();
this.salaryPeriodRepository.merge(chk_SalaryPeriod, requestBody);
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
await this.salaryPeriodRepository.save(chk_SalaryPeriod, { data: request });
setLogDataDiff(request, { before: beforechk_SalaryPeriod, after: chk_SalaryPeriod });
if (chk_SalaryPeriod.period == "SPECIAL") {
const snapshot = "SNAP1";
const salaryOrg = await this.salaryOrgRepository.find({
@ -2234,18 +2260,20 @@ export class SalaryPeriodEmployeeController extends Controller {
const salaryProfile = await this.salaryProfileRepository.find({
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
});
await this.salaryOrgRepository.remove(salaryOrg);
await this.salaryProfileRepository.remove(salaryProfile);
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
chk_SalaryPeriod.revisionId = revisionId;
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
await this.salaryPeriodRepository.save(chk_SalaryPeriod, { data: request });
setLogDataDiff(request, { before: beforechk_SalaryPeriod, after: chk_SalaryPeriod });
await Promise.all(
orgs.map(async (rootId: string) => {
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
const before = structuredClone(salaryOrgNew);
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
salaryOrgNew.status = "PENDING";
salaryOrgNew.rootId = rootId;
@ -2256,7 +2284,8 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryOrgNew.lastUpdateUserId = request.user.sub;
salaryOrgNew.lastUpdateFullName = request.user.name;
salaryOrgNew.group = "GROUP1";
await this.salaryOrgRepository.save(salaryOrgNew);
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
setLogDataDiff(request, { before, after: salaryOrgNew });
}),
);
}
@ -2287,8 +2316,8 @@ export class SalaryPeriodEmployeeController extends Controller {
const salaryProfile = SalaryOrg.find((x) => x.salaryProfiles.length > 0);
if (salaryProfile) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
await this.salaryOrgRepository.remove(SalaryOrg);
await this.salaryPeriodRepository.remove(SalaryPeriod);
await this.salaryOrgRepository.remove(SalaryOrg, { data: request });
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
return new HttpSuccess();
} else {
const SalaryOrg = await this.salaryOrgRepository.findOne({
@ -2296,7 +2325,7 @@ export class SalaryPeriodEmployeeController extends Controller {
});
if (SalaryOrg) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้");
await this.salaryPeriodRepository.remove(SalaryPeriod);
await this.salaryPeriodRepository.remove(SalaryPeriod, { data: request });
return new HttpSuccess();
}
}
@ -2405,7 +2434,11 @@ export class SalaryPeriodEmployeeController extends Controller {
* @param {string} rootId Guid, *Id
*/
@Get("officer/approve/{periodId}/{rootId}")
async OfficerApprove(@Path() periodId: string, rootId: string) {
async OfficerApprove(
@Path() periodId: string,
rootId: string,
@Request() request: RequestWithUser,
) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgEmployees"],
@ -2416,8 +2449,10 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryPeriod.salaryOrgEmployees
.filter((x) => x.rootId == rootId)
.map(async (x: any) => {
const before = structuredClone(x);
x.status = "WAITHEAD1";
await this.salaryOrgRepository.save(x);
await this.salaryOrgRepository.save(x, { data: request });
setLogDataDiff(request, { before, after: x });
}),
);
return new HttpSuccess();
@ -2431,7 +2466,7 @@ export class SalaryPeriodEmployeeController extends Controller {
* @param {string} rootId Guid, *Id
*/
@Get("head/approve/{periodId}/{rootId}")
async HeadApprove(@Path() periodId: string, rootId: string) {
async HeadApprove(@Path() periodId: string, rootId: string, @Request() request: RequestWithUser) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgEmployees"],
@ -2443,8 +2478,10 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryPeriod.salaryOrgEmployees
.filter((x) => x.rootId == rootId)
.map(async (x: any) => {
const before = structuredClone(x);
x.status = "WAITOWNER1";
await this.salaryOrgRepository.save(x);
await this.salaryOrgRepository.save(x, { data: request });
setLogDataDiff(request, { before, after: x });
}),
);
return new HttpSuccess();
@ -2458,7 +2495,11 @@ export class SalaryPeriodEmployeeController extends Controller {
* @param {string} rootId Guid, *Id
*/
@Get("owner/approve/{periodId}/{rootId}")
async OwnerApprove(@Path() periodId: string, rootId: string) {
async OwnerApprove(
@Path() periodId: string,
rootId: string,
@Request() request: RequestWithUser,
) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: { id: periodId },
relations: ["salaryOrgEmployees"],
@ -2470,8 +2511,10 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryPeriod.salaryOrgEmployees
.filter((x) => x.rootId == rootId)
.map(async (x: any) => {
const before = structuredClone(x);
x.status = "REPORT";
await this.salaryOrgRepository.save(x);
await this.salaryOrgRepository.save(x, { data: request });
setLogDataDiff(request, { before, after: x });
}),
);
return new HttpSuccess();
@ -2506,9 +2549,11 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryPeriod.salaryOrgEmployees
.filter((x) => x.rootId == rootId)
.map(async (x: any) => {
const before = structuredClone(x);
x.status = "WAITHEAD2";
x.ownerRecommend = body.titleRecommend;
await this.salaryOrgRepository.save(x);
await this.salaryOrgRepository.save(x, { data: request });
setLogDataDiff(request, { before, after: x });
}),
);
return new HttpSuccess();
@ -2543,9 +2588,11 @@ export class SalaryPeriodEmployeeController extends Controller {
salaryPeriod.salaryOrgEmployees
.filter((x) => x.rootId == rootId)
.map(async (x: any) => {
const before = structuredClone(x);
x.status = "REPORT";
x.ownerRecommend = body.titleRecommend;
await this.salaryOrgRepository.save(x);
await this.salaryOrgRepository.save(x, { data: request });
setLogDataDiff(request, { before, after: x });
}),
);
return new HttpSuccess();