เงินเดือนลูกจ้าง
This commit is contained in:
parent
6950954268
commit
fa79bb5b7a
8 changed files with 2893 additions and 270 deletions
|
|
@ -113,7 +113,11 @@ export class Report2Controller extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get("report2/{rootId}/{salaryPeriodId}/{salaryOrgId}")
|
||||
async SalaryReport2(@Path() rootId: string, @Path() salaryPeriodId: string, @Path() salaryOrgId: string) {
|
||||
async SalaryReport2(
|
||||
@Path() rootId: string,
|
||||
@Path() salaryPeriodId: string,
|
||||
@Path() salaryOrgId: string,
|
||||
) {
|
||||
// const counts = await AppDataSource.getRepository(SalaryProfile)
|
||||
// .createQueryBuilder("salaryProfile")
|
||||
// .leftJoin("salaryProfile.salaryOrg", "salaryOrg")
|
||||
|
|
@ -243,35 +247,38 @@ export class Report2Controller extends Controller {
|
|||
// },
|
||||
// select: ["posType", "posLevel"],
|
||||
// });
|
||||
|
||||
const statistics = await this.salaryProfileRepository.find({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: {
|
||||
salaryOrg: {
|
||||
id:salaryOrgId,
|
||||
snapshot: "SNAP1",
|
||||
group: "GROUP2",
|
||||
rootId: rootId,
|
||||
salaryPeriod: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
},
|
||||
|
||||
const statistics = await this.salaryProfileRepository.find({
|
||||
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
|
||||
where: {
|
||||
salaryOrg: {
|
||||
id: salaryOrgId,
|
||||
snapshot: "SNAP1",
|
||||
group: "GROUP2",
|
||||
rootId: rootId,
|
||||
salaryPeriod: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const notPromoSum = (statistics[0]?.salaryOrg?.total ?? 0) - (statistics[0]?.salaryOrg?.fifteenPercent ?? 0);
|
||||
const haftCount = statistics?.filter(item => item.type === "HAFT").length ?? 0;
|
||||
const data = {
|
||||
group: statistics[0]?.salaryOrg.total?"กลุ่ม 2":"",
|
||||
total: statistics[0]?.salaryOrg.total?statistics[0]?.salaryOrg.total:"",
|
||||
fifteenPercent: statistics[0]?.salaryOrg.fifteenPercent?statistics[0]?.salaryOrg.fifteenPercent:"",
|
||||
full: statistics[0]?.salaryOrg.quantityUsed?statistics[0]?.salaryOrg.quantityUsed:"",
|
||||
remaining: statistics[0]?.salaryOrg.remainQuota?statistics[0]?.salaryOrg.remainQuota:"",
|
||||
haft: haftCount,
|
||||
notPromoted: notPromoSum,
|
||||
reason: null,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const notPromoSum =
|
||||
(statistics[0]?.salaryOrg?.total ?? 0) - (statistics[0]?.salaryOrg?.fifteenPercent ?? 0);
|
||||
const haftCount = statistics?.filter((item) => item.type === "HAFT").length ?? 0;
|
||||
const data = {
|
||||
group: statistics[0]?.salaryOrg.total ? "กลุ่ม 2" : "",
|
||||
total: statistics[0]?.salaryOrg.total ? statistics[0]?.salaryOrg.total : "",
|
||||
fifteenPercent: statistics[0]?.salaryOrg.fifteenPercent
|
||||
? statistics[0]?.salaryOrg.fifteenPercent
|
||||
: "",
|
||||
full: statistics[0]?.salaryOrg.quantityUsed ? statistics[0]?.salaryOrg.quantityUsed : "",
|
||||
remaining: statistics[0]?.salaryOrg.remainQuota ? statistics[0]?.salaryOrg.remainQuota : "",
|
||||
haft: haftCount,
|
||||
notPromoted: notPromoSum,
|
||||
reason: null,
|
||||
};
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import { In, IsNull, Not, MoreThan } from "typeorm";
|
|||
import { SalaryProfile } from "../entities/SalaryProfile";
|
||||
import { SalaryPeriod } from "../entities/SalaryPeriod";
|
||||
import { SalaryOrg } from "../entities/SalaryOrg";
|
||||
import Extension from "../interfaces/extension";
|
||||
import Extension from "../interfaces/extension";
|
||||
|
||||
@Route("api/v1/salary/report/1")
|
||||
@Tags("Report")
|
||||
|
|
@ -43,213 +43,258 @@ export class Report_1_Controller extends Controller {
|
|||
* API รายงานแบบ 1 กท รอบเมษายน
|
||||
*
|
||||
* @summary รายงานแบบ 1 กท รอบเมษายน
|
||||
*
|
||||
*
|
||||
* @param {string} rootId Guid, *Id Root
|
||||
* @param {string} salaryPeriodId Guid, *Id Period
|
||||
*/
|
||||
@Get("03/{rootId}/{salaryPeriodId}")
|
||||
async SalaryReport3(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId : string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true
|
||||
},
|
||||
});
|
||||
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC"
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
async SalaryReport3(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId: string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC",
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
|
||||
const salaryProfile = await this.salaryProfile.find({
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
type: "FULL", //หนึ่งขั้น
|
||||
},
|
||||
select: [
|
||||
"id", "prefix" , "firstName", "lastName", "root",
|
||||
"position", "posType", "posLevel", "orgShortName",
|
||||
"posMasterNo", "amount", "amountSpecial"
|
||||
]
|
||||
"id",
|
||||
"prefix",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"root",
|
||||
"position",
|
||||
"posType",
|
||||
"posLevel",
|
||||
"orgShortName",
|
||||
"posMasterNo",
|
||||
"amount",
|
||||
"amountSpecial",
|
||||
],
|
||||
});
|
||||
|
||||
const mapData = {
|
||||
effectiveDate : salaryPeriod?.effectiveDate,
|
||||
effectiveDate: salaryPeriod?.effectiveDate,
|
||||
// root: salaryProfile[0]?.root,
|
||||
profile: salaryProfile.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index+1)),
|
||||
fullname: item.prefix + item.firstName +" "+ item.lastName,
|
||||
position: item.position + "/" +
|
||||
(item.child4==undefined && item.child4==null ? "" : item.child4+"/")+
|
||||
(item.child3==undefined && item.child3==null ? "" : item.child3+"/")+
|
||||
(item.child2==undefined && item.child2==null ? "" : item.child2+"/")+
|
||||
(item.child1==undefined && item.child1==null ? "" : item.child1+"/")+
|
||||
(item.root==undefined && item.root==null ? "" : item.root),
|
||||
no: Extension.ToThaiNumber(String(index + 1)),
|
||||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||||
position:
|
||||
item.position +
|
||||
"/" +
|
||||
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
|
||||
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
|
||||
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
|
||||
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
|
||||
(item.root == undefined && item.root == null ? "" : item.root),
|
||||
posLevel: item.posLevel,
|
||||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||||
amount: item.amount == undefined || item.amount == null ? "๐" : Extension.ToThaiNumber(String(item.amount)),
|
||||
amount:
|
||||
item.amount == undefined || item.amount == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.amount)),
|
||||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||||
remark: null //หมายเหตุ
|
||||
}))
|
||||
}
|
||||
return mapData
|
||||
remark: null, //หมายเหตุ
|
||||
})),
|
||||
};
|
||||
return mapData;
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายงานแบบ 1 กท รอบเมษายน
|
||||
*
|
||||
* @summary รายงานแบบ 1 กท รอบเมษายน
|
||||
*
|
||||
*
|
||||
* @param {string} rootId Guid, *Id Root
|
||||
* @param {string} salaryPeriodId Guid, *Id Period
|
||||
*/
|
||||
@Get("04/{rootId}/{salaryPeriodId}")
|
||||
async SalaryReport4(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId : string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true
|
||||
},
|
||||
});
|
||||
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC"
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
async SalaryReport4(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId: string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC",
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
|
||||
const salaryProfile = await this.salaryProfile.find({
|
||||
where: { salaryOrgId: salaryOrg?.id},
|
||||
where: { salaryOrgId: salaryOrg?.id },
|
||||
select: [
|
||||
"id", "prefix" , "firstName", "lastName", "root",
|
||||
"position", "posType", "posLevel", "orgShortName",
|
||||
"posMasterNo", "amount", "amountSpecial"
|
||||
]
|
||||
"id",
|
||||
"prefix",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"root",
|
||||
"position",
|
||||
"posType",
|
||||
"posLevel",
|
||||
"orgShortName",
|
||||
"posMasterNo",
|
||||
"amount",
|
||||
"amountSpecial",
|
||||
],
|
||||
});
|
||||
|
||||
const mapData = {
|
||||
effectiveDate : salaryPeriod?.effectiveDate,
|
||||
root: salaryProfile[0]?.root,
|
||||
effectiveDate: salaryPeriod?.effectiveDate,
|
||||
root: salaryProfile[0]?.root,
|
||||
profile: salaryProfile.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index+1)),
|
||||
fullname: item.prefix + item.firstName +" "+ item.lastName,
|
||||
position: item.position + "/" +
|
||||
(item.child4==undefined && item.child4==null ? "" : item.child4+"/")+
|
||||
(item.child3==undefined && item.child3==null ? "" : item.child3+"/")+
|
||||
(item.child2==undefined && item.child2==null ? "" : item.child2+"/")+
|
||||
(item.child1==undefined && item.child1==null ? "" : item.child1+"/")+
|
||||
(item.root==undefined && item.root==null ? "" : item.root),
|
||||
no: Extension.ToThaiNumber(String(index + 1)),
|
||||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||||
position:
|
||||
item.position +
|
||||
"/" +
|
||||
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
|
||||
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
|
||||
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
|
||||
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
|
||||
(item.root == undefined && item.root == null ? "" : item.root),
|
||||
posLevel: item.posLevel,
|
||||
orgShortName: item.orgShortName+Extension.ToThaiNumber(String(item.posMasterNo)),
|
||||
amount: item.amount == undefined || item.amount == null ? "๐" : Extension.ToThaiNumber(String(item.amount)),
|
||||
amountSpecial: item.amountSpecial == undefined || item.amountSpecial == null ? "๐" : Extension.ToThaiNumber(String(item.amountSpecial)),
|
||||
orgShortName: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
|
||||
amount:
|
||||
item.amount == undefined || item.amount == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.amount)),
|
||||
amountSpecial:
|
||||
item.amountSpecial == undefined || item.amountSpecial == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.amountSpecial)),
|
||||
score: null, //สรุปผลการประเมินฯ ระดับและคะแนน
|
||||
remark: null //หมายเหตุ
|
||||
}))
|
||||
}
|
||||
return mapData
|
||||
remark: null, //หมายเหตุ
|
||||
})),
|
||||
};
|
||||
return mapData;
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายงานคำสั่งเลื่อนเงินเดือน รอบเมษายน
|
||||
*
|
||||
* @summary รายงานคำสั่งเลื่อนเงินเดือน รอบเมษายน
|
||||
*
|
||||
*
|
||||
* @param {string} rootId Guid, *Id Root
|
||||
* @param {string} salaryPeriodId Guid, *Id Period
|
||||
*/
|
||||
@Get("07/{rootId}/{salaryPeriodId}")
|
||||
async SalaryReport7(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId : string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true
|
||||
},
|
||||
});
|
||||
async SalaryReport7(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId: string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC"
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC",
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
|
||||
const salaryProfile = await this.salaryProfile.find({
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
amountSpecial: IsNull() || 0,
|
||||
amountUse: MoreThan(1),
|
||||
},
|
||||
select: [
|
||||
"id", "prefix" , "firstName", "lastName", "root",
|
||||
"position", "posType", "posLevel", "orgShortName", "posMasterNo",
|
||||
"amount", "amountUse", "positionSalaryAmount"
|
||||
],
|
||||
order: {
|
||||
posMasterNo: "ASC"
|
||||
}
|
||||
});
|
||||
|
||||
const mapData = salaryProfile.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index+1)),
|
||||
fullname: item.prefix + item.firstName +" "+ item.lastName,
|
||||
const salaryProfile = await this.salaryProfile.find({
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
amountSpecial: IsNull() || 0,
|
||||
amountUse: MoreThan(1),
|
||||
},
|
||||
select: [
|
||||
"id",
|
||||
"prefix",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"root",
|
||||
"position",
|
||||
"posType",
|
||||
"posLevel",
|
||||
"orgShortName",
|
||||
"posMasterNo",
|
||||
"amount",
|
||||
"amountUse",
|
||||
"positionSalaryAmount",
|
||||
],
|
||||
order: {
|
||||
posMasterNo: "ASC",
|
||||
},
|
||||
});
|
||||
|
||||
const mapData = salaryProfile.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index + 1)),
|
||||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||||
position: item.position,
|
||||
posType: item.posType,
|
||||
posLevel: item.posLevel,
|
||||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||||
amount: item.amount == undefined || item.amount == null ? "๐" : Extension.ToThaiNumber(String(item.amount)),
|
||||
positionSalaryAmount: item.positionSalaryAmount == undefined || item.positionSalaryAmount == null ? "๐" : Extension.ToThaiNumber(String(item.positionSalaryAmount)),
|
||||
remark: null
|
||||
amount:
|
||||
item.amount == undefined || item.amount == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.amount)),
|
||||
positionSalaryAmount:
|
||||
item.positionSalaryAmount == undefined || item.positionSalaryAmount == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.positionSalaryAmount)),
|
||||
remark: null,
|
||||
}));
|
||||
|
||||
return mapData;
|
||||
|
|
@ -259,100 +304,125 @@ export class Report_1_Controller extends Controller {
|
|||
* API รายงานคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน
|
||||
*
|
||||
* @summary รายงานคำสั่งคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน
|
||||
*
|
||||
*
|
||||
* @param {string} rootId Guid, *Id Root
|
||||
* @param {string} salaryPeriodId Guid, *Id Period
|
||||
*/
|
||||
@Get("08/{rootId}/{salaryPeriodId}")
|
||||
async SalaryReport8(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId : string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true
|
||||
},
|
||||
});
|
||||
async SalaryReport8(
|
||||
// @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37",
|
||||
// @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2",
|
||||
@Path() rootId: string,
|
||||
@Path() salaryPeriodId: string,
|
||||
) {
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
id: salaryPeriodId,
|
||||
period: "APR",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
|
||||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC"
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
const salaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodId,
|
||||
rootId: rootId,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
order: {
|
||||
group: "ASC",
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
|
||||
const salaryProfileSpecial = await this.salaryProfile.find({
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
amountSpecial: MoreThan(1),
|
||||
},
|
||||
select: [
|
||||
"id", "prefix" , "firstName", "lastName", "root",
|
||||
"position", "posType", "posLevel", "orgShortName",
|
||||
"posMasterNo", "amount", "amountSpecial",
|
||||
],
|
||||
order: {
|
||||
posMasterNo: "ASC"
|
||||
}
|
||||
});
|
||||
const salaryProfileSpecial = await this.salaryProfile.find({
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
amountSpecial: MoreThan(1),
|
||||
},
|
||||
select: [
|
||||
"id",
|
||||
"prefix",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"root",
|
||||
"position",
|
||||
"posType",
|
||||
"posLevel",
|
||||
"orgShortName",
|
||||
"posMasterNo",
|
||||
"amount",
|
||||
"amountSpecial",
|
||||
],
|
||||
order: {
|
||||
posMasterNo: "ASC",
|
||||
},
|
||||
});
|
||||
|
||||
const salaryProfileNoAmount = await this.salaryProfile.find({
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
amountUse: IsNull() || 0,
|
||||
positionSalaryAmount: IsNull() || 0,
|
||||
},
|
||||
select: [
|
||||
"id", "prefix" , "firstName", "lastName", "root",
|
||||
"position", "posType", "posLevel", "orgShortName",
|
||||
"posMasterNo", "amount",
|
||||
],
|
||||
order: {
|
||||
posMasterNo: "ASC"
|
||||
}
|
||||
});
|
||||
const salaryProfileNoAmount = await this.salaryProfile.find({
|
||||
where: {
|
||||
salaryOrgId: salaryOrg?.id,
|
||||
amountUse: IsNull() || 0,
|
||||
positionSalaryAmount: IsNull() || 0,
|
||||
},
|
||||
select: [
|
||||
"id",
|
||||
"prefix",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"root",
|
||||
"position",
|
||||
"posType",
|
||||
"posLevel",
|
||||
"orgShortName",
|
||||
"posMasterNo",
|
||||
"amount",
|
||||
],
|
||||
order: {
|
||||
posMasterNo: "ASC",
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
const profileSpecial = salaryProfileSpecial.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index+1)),
|
||||
fullname: item.prefix + item.firstName +" "+ item.lastName,
|
||||
const profileSpecial = salaryProfileSpecial.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index + 1)),
|
||||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||||
position: item.position,
|
||||
posType: item.posType,
|
||||
posLevel: item.posLevel,
|
||||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||||
amount: item.amount == undefined || item.amount == null ? "๐" : Extension.ToThaiNumber(String(item.amount)),
|
||||
amountSpecial: item.amountSpecial == undefined || item.amountSpecial == null ? "๐" : Extension.ToThaiNumber(String(item.amountSpecial)),
|
||||
remark: null
|
||||
amount:
|
||||
item.amount == undefined || item.amount == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.amount)),
|
||||
amountSpecial:
|
||||
item.amountSpecial == undefined || item.amountSpecial == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.amountSpecial)),
|
||||
remark: null,
|
||||
}));
|
||||
|
||||
const profileNoAmount = salaryProfileNoAmount.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index+1)),
|
||||
fullname: item.prefix + item.firstName +" "+ item.lastName,
|
||||
const profileNoAmount = salaryProfileNoAmount.map((item, index) => ({
|
||||
no: Extension.ToThaiNumber(String(index + 1)),
|
||||
fullname: item.prefix + item.firstName + " " + item.lastName,
|
||||
position: item.position,
|
||||
posType: item.posType,
|
||||
posLevel: item.posLevel,
|
||||
posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)),
|
||||
amount: item.amount == undefined || item.amount == null ? "๐" : Extension.ToThaiNumber(String(item.amount)),
|
||||
remark: null
|
||||
amount:
|
||||
item.amount == undefined || item.amount == null
|
||||
? "๐"
|
||||
: Extension.ToThaiNumber(String(item.amount)),
|
||||
remark: null,
|
||||
}));
|
||||
|
||||
const mapData = {
|
||||
profileSpecial,
|
||||
profileNoAmount
|
||||
}
|
||||
profileSpecial,
|
||||
profileNoAmount,
|
||||
};
|
||||
return mapData;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import { PosLevel } from "../entities/PosLevel";
|
|||
import { Salarys } from "../entities/Salarys";
|
||||
import { SalaryRanks } from "../entities/SalaryRanks";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee";
|
||||
import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee";
|
||||
|
||||
@Route("api/v1/salary/period")
|
||||
@Tags("Salary")
|
||||
|
|
@ -33,7 +35,9 @@ import CallAPI from "../interfaces/call-api";
|
|||
export class SalaryPeriodController extends Controller {
|
||||
private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod);
|
||||
private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg);
|
||||
private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee);
|
||||
private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile);
|
||||
private salaryProfileEmployeeRepository = AppDataSource.getRepository(SalaryProfileEmployee);
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
private salaryRepository = AppDataSource.getRepository(Salarys);
|
||||
|
|
@ -1466,6 +1470,16 @@ export class SalaryPeriodController extends Controller {
|
|||
});
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
});
|
||||
const salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({
|
||||
where: { salaryOrgId: In(salaryOrgEmployee.map((x) => x.id)) },
|
||||
});
|
||||
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee);
|
||||
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee);
|
||||
|
||||
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", {
|
||||
|
|
@ -1493,6 +1507,37 @@ export class SalaryPeriodController extends Controller {
|
|||
});
|
||||
}
|
||||
}
|
||||
total = 1000;
|
||||
let orgProfileEmployees: any;
|
||||
let _orgProfileEmployees = await new CallAPI().PostData(
|
||||
request,
|
||||
"org/unauthorize/profile/salary/employee/gen",
|
||||
{
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
year: salaryPeriod.year,
|
||||
period: salaryPeriod.period,
|
||||
},
|
||||
);
|
||||
orgProfileEmployees = _orgProfileEmployees.data;
|
||||
total = _orgProfileEmployees.total;
|
||||
if (total > 1000) {
|
||||
const page = Math.ceil(total / 1000);
|
||||
for (let index = 2; index <= page; index++) {
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/unauthorize/profile/salary/orgProfileEmployees/gen", {
|
||||
page: index,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
year: salaryPeriod.year,
|
||||
period: salaryPeriod.period,
|
||||
})
|
||||
.then((x) => {
|
||||
Array.prototype.push.apply(orgProfileEmployees, x.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
let revisionId = await new CallAPI().GetData(request, "org/unauthorize/revision/latest");
|
||||
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
|
|
@ -1520,6 +1565,28 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
// if (salaryPeriod.period != "SPECIAL") {
|
||||
// delete salaryOrgNew.id;
|
||||
// salaryOrgNew.group = "GROUP2";
|
||||
// await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
// }
|
||||
}),
|
||||
);
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
await Promise.all(
|
||||
orgProfiles.map(async (profile: any) => {
|
||||
|
|
@ -1575,12 +1642,58 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
orgProfiles.map(async (profile: any) => {
|
||||
const salaryOrgNew = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: profile.rootId,
|
||||
snapshot: snapshot,
|
||||
group: "GROUP1",
|
||||
},
|
||||
});
|
||||
|
||||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfileEmployee(), profile);
|
||||
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;
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
|
||||
});
|
||||
const salaryOld = await this.salaryProfileEmployeeRepository.findOne({
|
||||
where: {
|
||||
citizenId: salaryProfileNew.citizenId,
|
||||
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
|
||||
},
|
||||
});
|
||||
salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type;
|
||||
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
|
||||
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
|
||||
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
|
||||
salaryProfileNew.positionSalaryAmount =
|
||||
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
|
||||
salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext;
|
||||
}
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const salaryOrgNew = await this.salaryOrgRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
const salaryOrgEmployeeNew = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
if (salaryPeriod.period == "OCT") {
|
||||
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -1640,6 +1753,58 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
let totalAmount = 0;
|
||||
if (salaryPeriodAPROld != null) {
|
||||
const salaryOrgSnap2Old: any = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodAPROld.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
totalAmount =
|
||||
salaryOrgSnap2Old == null
|
||||
? 0
|
||||
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
|
||||
}
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP1",
|
||||
},
|
||||
});
|
||||
if (salaryOrgSnap1 == null) {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
_salaryOrg.spentAmount = totalAmount;
|
||||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
} else {
|
||||
_salaryOrg.currentAmount = salaryOrgSnap1.currentAmount;
|
||||
_salaryOrg.sixPercentAmount = salaryOrgSnap1.sixPercentAmount;
|
||||
_salaryOrg.spentAmount = salaryOrgSnap1.spentAmount;
|
||||
_salaryOrg.useAmount = salaryOrgSnap1.useAmount;
|
||||
_salaryOrg.remainingAmount = salaryOrgSnap1.remainingAmount;
|
||||
}
|
||||
} else {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
_salaryOrg.spentAmount = totalAmount;
|
||||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
} else if (salaryPeriod.period == "APR") {
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
|
|
@ -1674,6 +1839,39 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP1",
|
||||
},
|
||||
});
|
||||
if (salaryOrgSnap1 == null) {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
} else {
|
||||
_salaryOrg.total = salaryOrgSnap1.total;
|
||||
_salaryOrg.fifteenPercent = salaryOrgSnap1.fifteenPercent;
|
||||
_salaryOrg.fifteenPoint = salaryOrgSnap1.fifteenPoint;
|
||||
_salaryOrg.quantityUsed = salaryOrgSnap1.quantityUsed;
|
||||
_salaryOrg.remainQuota = salaryOrgSnap1.remainQuota;
|
||||
}
|
||||
} else {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
@ -1754,25 +1952,23 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
|
||||
let orgs = await new CallAPI().GetData(request, "org/unauthorize/active/root/id");
|
||||
let orgProfiles: any;
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/unauthorize/profile/salary/gen", {
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
keyword: "",
|
||||
year: salaryPeriod.year,
|
||||
period: salaryPeriod.period,
|
||||
})
|
||||
.then((x) => {
|
||||
orgProfiles = x.data;
|
||||
});
|
||||
if (orgProfiles.total > 100) {
|
||||
const page = Math.ceil(orgProfiles.total.length / 100);
|
||||
let total = 1000;
|
||||
let _orgProfiles = await new CallAPI().PostData(request, "org/unauthorize/salary/gen", {
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
year: salaryPeriod.year,
|
||||
period: salaryPeriod.period,
|
||||
});
|
||||
let orgProfiles = _orgProfiles.data;
|
||||
total = _orgProfiles.total;
|
||||
if (total > 1000) {
|
||||
const page = Math.ceil(total / 1000);
|
||||
for (let index = 2; index <= page; index++) {
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/unauthorize/profile/salary/gen", {
|
||||
page: index,
|
||||
pageSize: 100,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
year: salaryPeriod.year,
|
||||
period: salaryPeriod.period,
|
||||
|
|
@ -1782,6 +1978,37 @@ export class SalaryPeriodController extends Controller {
|
|||
});
|
||||
}
|
||||
}
|
||||
total = 1000;
|
||||
let orgProfileEmployees: any;
|
||||
let _orgProfileEmployees = await new CallAPI().PostData(
|
||||
request,
|
||||
"org/unauthorize/profile/salary/employee/gen",
|
||||
{
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
year: salaryPeriod.year,
|
||||
period: salaryPeriod.period,
|
||||
},
|
||||
);
|
||||
orgProfileEmployees = _orgProfileEmployees.data;
|
||||
total = _orgProfileEmployees.total;
|
||||
if (total > 1000) {
|
||||
const page = Math.ceil(total / 1000);
|
||||
for (let index = 2; index <= page; index++) {
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/unauthorize/profile/salary/orgProfileEmployees/gen", {
|
||||
page: index,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
year: salaryPeriod.year,
|
||||
period: salaryPeriod.period,
|
||||
})
|
||||
.then((x) => {
|
||||
Array.prototype.push.apply(orgProfileEmployees, x.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
let revisionId = await new CallAPI().GetData(request, "org/unauthorize/revision/latest");
|
||||
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
|
|
@ -1809,6 +2036,28 @@ export class SalaryPeriodController extends Controller {
|
|||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
salaryOrgNew.createdFullName = request.user.name;
|
||||
salaryOrgNew.lastUpdateUserId = request.user.sub;
|
||||
salaryOrgNew.lastUpdateFullName = request.user.name;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
// if (salaryPeriod.period != "SPECIAL") {
|
||||
// delete salaryOrgNew.id;
|
||||
// salaryOrgNew.group = "GROUP2";
|
||||
// await this.salaryOrgRepository.save(salaryOrgNew);
|
||||
// }
|
||||
}),
|
||||
);
|
||||
|
||||
if (salaryPeriod.period != "SPECIAL") {
|
||||
await Promise.all(
|
||||
orgProfiles.map(async (profile: any) => {
|
||||
|
|
@ -1863,12 +2112,58 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
orgProfiles.map(async (profile: any) => {
|
||||
const salaryOrgNew = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: profile.rootId,
|
||||
snapshot: snapshot,
|
||||
group: "GROUP1",
|
||||
},
|
||||
});
|
||||
|
||||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfileEmployee(), profile);
|
||||
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;
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
|
||||
});
|
||||
const salaryOld = await this.salaryProfileEmployeeRepository.findOne({
|
||||
where: {
|
||||
citizenId: salaryProfileNew.citizenId,
|
||||
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
|
||||
},
|
||||
});
|
||||
salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type;
|
||||
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
|
||||
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
|
||||
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
|
||||
salaryProfileNew.positionSalaryAmount =
|
||||
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
|
||||
salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext;
|
||||
}
|
||||
await this.salaryProfileEmployeeRepository.save(salaryProfileNew);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const salaryOrgNew = await this.salaryOrgRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
const salaryOrgEmployeeNew = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
if (salaryPeriod.period == "OCT") {
|
||||
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -1928,6 +2223,58 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
let totalAmount = 0;
|
||||
if (salaryPeriodAPROld != null) {
|
||||
const salaryOrgSnap2Old: any = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodAPROld.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
totalAmount =
|
||||
salaryOrgSnap2Old == null
|
||||
? 0
|
||||
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
|
||||
}
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP1",
|
||||
},
|
||||
});
|
||||
if (salaryOrgSnap1 == null) {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
_salaryOrg.spentAmount = totalAmount;
|
||||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
} else {
|
||||
_salaryOrg.currentAmount = salaryOrgSnap1.currentAmount;
|
||||
_salaryOrg.sixPercentAmount = salaryOrgSnap1.sixPercentAmount;
|
||||
_salaryOrg.spentAmount = salaryOrgSnap1.spentAmount;
|
||||
_salaryOrg.useAmount = salaryOrgSnap1.useAmount;
|
||||
_salaryOrg.remainingAmount = salaryOrgSnap1.remainingAmount;
|
||||
}
|
||||
} else {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
_salaryOrg.spentAmount = totalAmount;
|
||||
_salaryOrg.remainingAmount = totalProfile * 0.06 - totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
} else if (salaryPeriod.period == "APR") {
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
|
|
@ -1962,6 +2309,39 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
salaryOrgEmployeeNew.map(async (_salaryOrg: SalaryOrgEmployee) => {
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgEmployeeRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP1",
|
||||
},
|
||||
});
|
||||
if (salaryOrgSnap1 == null) {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
} else {
|
||||
_salaryOrg.total = salaryOrgSnap1.total;
|
||||
_salaryOrg.fifteenPercent = salaryOrgSnap1.fifteenPercent;
|
||||
_salaryOrg.fifteenPoint = salaryOrgSnap1.fifteenPoint;
|
||||
_salaryOrg.quantityUsed = salaryOrgSnap1.quantityUsed;
|
||||
_salaryOrg.remainQuota = salaryOrgSnap1.remainQuota;
|
||||
}
|
||||
} else {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
_salaryOrg.remainQuota = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
}
|
||||
|
||||
await this.salaryOrgEmployeeRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
1595
src/controllers/SalaryPeriodEmployeeController.ts
Normal file
1595
src/controllers/SalaryPeriodEmployeeController.ts
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue