Merge branch 'develop' into adiDev
# Conflicts: # src/controllers/SalaryController.ts # src/controllers/SalaryEmployeeController.ts # src/controllers/SalaryPeriodController.ts # src/controllers/SalaryRankController.ts # src/controllers/SalaryRankEmployeeController.ts
This commit is contained in:
commit
667e90ddbd
21 changed files with 6539 additions and 5209 deletions
|
|
@ -28,9 +28,9 @@ import { SalaryRanks } from "../entities/SalaryRanks";
|
|||
import CallAPI from "../interfaces/call-api";
|
||||
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
||||
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
||||
import { isNullOrUndefined } from "util";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/salary/period")
|
||||
@Tags("Salary")
|
||||
|
|
@ -297,7 +297,7 @@ export class SalaryPeriodController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
|
||||
}
|
||||
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: req });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -328,7 +328,10 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -382,7 +385,10 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -402,8 +408,11 @@ export class SalaryPeriodController extends Controller {
|
|||
* @param {string} amount ฐานเงินเดือน
|
||||
*/
|
||||
@Post("change/amount")
|
||||
async changeAmount(@Body() body: { profileId: string; amount: number }, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionCreate(request, "SYS_SALARY_OFFICER");
|
||||
async changeAmount(
|
||||
@Body() body: { profileId: string; amount: number },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(request, "SYS_SALARY_OFFICER");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: { id: body.profileId },
|
||||
|
|
@ -575,8 +584,12 @@ export class SalaryPeriodController extends Controller {
|
|||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = request.user.sub;
|
||||
salaryProfile.lastUpdateFullName = request.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
const before = structuredClone(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -607,7 +620,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -661,7 +678,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -679,8 +700,11 @@ export class SalaryPeriodController extends Controller {
|
|||
* @param {string} groupId groupId
|
||||
*/
|
||||
@Post("change/group")
|
||||
async changeGroup(@Body() body: { profileId: string; groupId: string } ,@Request() req: RequestWithUser) {
|
||||
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||
async changeGroup(
|
||||
@Body() body: { profileId: string; groupId: string },
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
// relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: { id: body.profileId },
|
||||
|
|
@ -695,9 +719,15 @@ export class SalaryPeriodController extends Controller {
|
|||
if (!salaryOrg) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน");
|
||||
}
|
||||
const before = null;
|
||||
|
||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = req.user.sub;
|
||||
salaryProfile.lastUpdateFullName = req.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
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 },
|
||||
|
|
@ -727,7 +757,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -781,7 +815,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -802,7 +840,7 @@ export class SalaryPeriodController extends Controller {
|
|||
@Post("change/type")
|
||||
async changeType(
|
||||
@Body() body: { profileId: string; type: string; isReserve: boolean; remark?: string | null },
|
||||
@Request() req: RequestWithUser
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
await new permission().PermissionCreate(req, "SYS_SALARY_OFFICER");
|
||||
const salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
|
|
@ -1011,7 +1049,12 @@ export class SalaryPeriodController extends Controller {
|
|||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfile);
|
||||
salaryProfile.lastUpdateUserId = req.user.sub;
|
||||
salaryProfile.lastUpdateFullName = req.user.name;
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
const before = structuredClone(salaryProfile);
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -1042,7 +1085,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -1096,7 +1143,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = req.user.sub;
|
||||
salaryOrg.lastUpdateFullName = req.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: req });
|
||||
setLogDataDiff(req, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1114,6 +1165,7 @@ export class SalaryPeriodController extends Controller {
|
|||
*/
|
||||
@Put("org/{id}")
|
||||
async GetListsSalaryProfile(
|
||||
@Request() request: RequestWithUser,
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
body: {
|
||||
|
|
@ -1124,6 +1176,7 @@ export class SalaryPeriodController extends Controller {
|
|||
isRetire?: string | null;
|
||||
},
|
||||
) {
|
||||
await new permission().PermissionList(request, "SYS_SALARY_OFFICER");
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
id: id,
|
||||
|
|
@ -1213,6 +1266,7 @@ export class SalaryPeriodController 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;
|
||||
|
|
@ -1220,7 +1274,9 @@ export class SalaryPeriodController 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();
|
||||
}
|
||||
|
||||
|
|
@ -1438,12 +1494,16 @@ export class SalaryPeriodController 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);
|
||||
salaryProfile.createdAt = new Date();
|
||||
salaryProfile.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfile, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfile });
|
||||
|
||||
const _salaryProfile = await this.salaryProfileRepository.findOne({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
|
|
@ -1474,7 +1534,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrg.quantityUsed = amountFullType;
|
||||
const calRemainQuota = salaryOrg.fifteenPercent - amountFullType;
|
||||
salaryOrg.remainQuota = calRemainQuota;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
} else if (_salaryProfile.salaryOrg.salaryPeriod.period == "OCT") {
|
||||
|
|
@ -1528,7 +1592,11 @@ export class SalaryPeriodController extends Controller {
|
|||
? 0
|
||||
: sumAmountUse.totalAmount;
|
||||
salaryOrg.remainingAmount = calRemainAmount;
|
||||
await this.salaryOrgRepository.save(salaryOrg);
|
||||
salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
salaryOrg.lastUpdateFullName = request.user.name;
|
||||
salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrg });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1554,8 +1622,14 @@ export class SalaryPeriodController extends Controller {
|
|||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||
}
|
||||
const before = structuredClone(salaryPeriod);
|
||||
salaryPeriod.isClose = !salaryPeriod.isClose;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -1591,13 +1665,16 @@ export class SalaryPeriodController 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);
|
||||
salaryPeriod.createdAt = new Date();
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
if (salaryPeriod.period == "SPECIAL") {
|
||||
const snapshot = "SNAP1";
|
||||
|
|
@ -1607,8 +1684,8 @@ export class SalaryPeriodController 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 });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -1616,14 +1693,18 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { 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);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
|
|
@ -1638,8 +1719,11 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
|
|
@ -1656,7 +1740,10 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -1702,13 +1789,15 @@ export class SalaryPeriodController 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({
|
||||
|
|
@ -1717,8 +1806,8 @@ export class SalaryPeriodController 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 });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: chk_SalaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -1726,18 +1815,25 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { 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);
|
||||
chk_SalaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
chk_SalaryPeriod.lastUpdateFullName = request.user.name;
|
||||
chk_SalaryPeriod.lastUpdatedAt = new Date();
|
||||
|
||||
await this.salaryPeriodRepository.save(chk_SalaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before: beforeChk_SalaryPeriod, after: chk_SalaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -1749,13 +1845,18 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -1767,7 +1868,10 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -1798,8 +1902,8 @@ export class SalaryPeriodController 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({
|
||||
|
|
@ -1807,7 +1911,7 @@ export class SalaryPeriodController 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1956,7 +2060,7 @@ export class SalaryPeriodController extends Controller {
|
|||
async SnapshotSalary(
|
||||
@Path() snapshot: string,
|
||||
salaryPeriodId: string,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
snapshot = snapshot.toLocaleUpperCase();
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
|
|
@ -1972,8 +2076,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfile = await this.salaryProfileRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrg.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile, { data: request });
|
||||
await this.salaryOrgRepository.remove(salaryOrg, { data: request });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -1981,8 +2085,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let total = 1000;
|
||||
let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/salary/gen", {
|
||||
|
|
@ -2043,13 +2147,20 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
const beforeSalaryPeriod = structuredClone(salaryPeriod);
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryPeriod, after: salaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
delete salaryOrgNew.id;
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -2060,12 +2171,17 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2073,6 +2189,8 @@ export class SalaryPeriodController extends Controller {
|
|||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
const beforeSalaryOrgNew = structuredClone(salaryOrgNew);
|
||||
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
|
|
@ -2084,11 +2202,16 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryOrgNew, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2118,12 +2241,17 @@ export class SalaryPeriodController extends Controller {
|
|||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
|
||||
delete salaryProfileNew.id;
|
||||
|
||||
const beforeSalaryProfileNew = structuredClone(salaryProfileNew);
|
||||
|
||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgRepository.find({
|
||||
|
|
@ -2146,7 +2274,8 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfileNew);
|
||||
await this.salaryProfileRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2164,12 +2293,16 @@ export class SalaryPeriodController extends Controller {
|
|||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfileEmployee(), profile);
|
||||
delete salaryProfileNew.id;
|
||||
const beforeSalaryProfileNew = structuredClone(salaryProfileNew);
|
||||
|
||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgEmployeeRepository.find({
|
||||
|
|
@ -2192,7 +2325,8 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2232,6 +2366,7 @@ export class SalaryPeriodController extends Controller {
|
|||
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
|
||||
}
|
||||
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2258,6 +2393,7 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
} else {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
|
|
@ -2265,12 +2401,21 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
let totalAmount = 0;
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
|
||||
if (salaryPeriodAPROld != null) {
|
||||
const salaryOrgSnap2Old: any = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2320,12 +2465,21 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
} else if (salaryPeriod.period == "APR") {
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2354,11 +2508,20 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
const before_salaryOrg = structuredClone(_salaryOrg);
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -2387,7 +2550,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before: before_salaryOrg, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -2464,8 +2634,8 @@ export class SalaryPeriodController 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 });
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
|
|
@ -2473,8 +2643,8 @@ export class SalaryPeriodController extends Controller {
|
|||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
|
||||
|
||||
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
|
||||
let total = 1000;
|
||||
|
|
@ -2534,9 +2704,13 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
}
|
||||
let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest");
|
||||
|
||||
const before = null;
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
salaryPeriod.lastUpdateUserId = request.user.sub;
|
||||
salaryPeriod.lastUpdateFullName = request.user.name;
|
||||
salaryPeriod.lastUpdatedAt = new Date();
|
||||
await this.salaryPeriodRepository.save(salaryPeriod, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryPeriod });
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
|
|
@ -2551,12 +2725,17 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2574,12 +2753,17 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.createdAt = new Date();
|
||||
salaryOrgNew.lastUpdatedAt = new Date();
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.group = "GROUP2";
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew);
|
||||
await this.salaryOrgEmployeeRepository.save(salaryOrgNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryOrgNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2638,7 +2822,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileRepository.save(salaryProfileNew);
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2684,7 +2875,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
|
||||
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
|
||||
}
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
salaryProfileNew.createdFullName = request.user.name;
|
||||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
salaryProfileNew.createdAt = new Date();
|
||||
salaryProfileNew.lastUpdatedAt = new Date();
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request });
|
||||
setLogDataDiff(request, { before, after: salaryProfileNew });
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
|
@ -2757,7 +2955,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
|
|
@ -2812,7 +3017,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
} else if (salaryPeriod.period == "APR") {
|
||||
|
|
@ -2846,7 +3058,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
|
|
@ -2879,7 +3098,14 @@ export class SalaryPeriodController extends Controller {
|
|||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
_salaryOrg.createdUserId = request.user.sub;
|
||||
_salaryOrg.createdFullName = request.user.name;
|
||||
_salaryOrg.lastUpdateUserId = request.user.sub;
|
||||
_salaryOrg.lastUpdateFullName = request.user.name;
|
||||
_salaryOrg.createdAt = new Date();
|
||||
_salaryOrg.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg, { data: request });
|
||||
setLogDataDiff(request, { before, after: _salaryOrg });
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
|
@ -2893,7 +3119,11 @@ export class SalaryPeriodController 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: ["salaryOrgs"],
|
||||
|
|
@ -2904,8 +3134,13 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITHEAD1";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2919,7 +3154,7 @@ export class SalaryPeriodController 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: ["salaryOrgs"],
|
||||
|
|
@ -2931,8 +3166,13 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITOWNER1";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2946,7 +3186,11 @@ export class SalaryPeriodController 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: ["salaryOrgs"],
|
||||
|
|
@ -2958,8 +3202,13 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "REPORT";
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -2994,9 +3243,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "WAITHEAD2";
|
||||
x.ownerRecommend = body.titleRecommend;
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
@ -3031,9 +3285,14 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryPeriod.salaryOrgs
|
||||
.filter((x) => x.rootId == rootId)
|
||||
.map(async (x) => {
|
||||
const before = structuredClone(x);
|
||||
x.status = "REPORT";
|
||||
x.ownerRecommend = body.titleRecommend;
|
||||
await this.salaryOrgRepository.save(x);
|
||||
x.lastUpdateUserId = request.user.sub;
|
||||
x.lastUpdateFullName = request.user.name;
|
||||
x.lastUpdatedAt = new Date();
|
||||
await this.salaryOrgRepository.save(x, { data: request });
|
||||
setLogDataDiff(request, { before, after: x });
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue