fix command salary and query gov1-03

This commit is contained in:
AdisakKanthawilang 2025-02-25 14:59:02 +07:00
parent f703d8e9b2
commit 77678b1e40

View file

@ -1090,64 +1090,13 @@ export class ReportController extends Controller {
},
});
}
const rootName = await this.salaryOrgRepository.findOne({
where: {
rootId: rootId,
},
select: ["root"],
});
//รอบปีก่อนๆ
const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 2,
isActive: true,
},
});
// console.log(">>>>1",salaryPeriodIncrease1_APR);
let salaryOrg1_APR = null;
if (salaryPeriodIncrease1_APR) {
salaryOrg1_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_APR?.id,
// rootId: rootId,
root: rootName?.root,
snapshot: "SNAP1",
group: convertGroup,
},
});
}
// console.log(">>>>2",salaryOrg1_APR);
let salaryOrg1_OCT = null;
if (salaryPeriodIncrease1_OCT) {
salaryOrg1_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_OCT?.id,
// rootId: rootId,
root: rootName?.root,
snapshot: "SNAP1",
group: convertGroup,
},
});
}
const salaryProfile1 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]),
type: Not(In(["NONE", "PENDING"])),
},
});
// console.log(">>>>3",salaryProfile1);
// const rootName = await this.salaryOrgRepository.findOne({
// where: {
// rootId: rootId,
// },
// select: ["root"],
// });
//รอบปีก่อนหน้า
const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({
where: {
@ -1170,7 +1119,8 @@ export class ReportController extends Controller {
where: {
salaryPeriodId: salaryPeriodIncrease2_APR?.id,
// rootId: rootId,
root: rootName?.root,
// root: rootName?.root,
rootId:salaryOrg?.rootDnaId,
snapshot: "SNAP1",
group: convertGroup,
},
@ -1183,7 +1133,8 @@ export class ReportController extends Controller {
where: {
salaryPeriodId: salaryPeriodIncrease2_OCT?.id,
// rootId: rootId,
root: rootName?.root,
// root: rootName?.root,
rootId:salaryOrg?.rootDnaId,
snapshot: "SNAP1",
group: convertGroup,
},
@ -1197,6 +1148,56 @@ export class ReportController extends Controller {
},
});
//รอบปีก่อนๆ
const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 2,
isActive: true,
},
});
let salaryOrg1_APR = null;
if (salaryPeriodIncrease1_APR) {
salaryOrg1_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_APR?.id,
// rootId: rootId,
// root: rootName?.root,
rootId:salaryOrg2_APR?.rootDnaId,
snapshot: "SNAP1",
group: convertGroup,
},
});
}
let salaryOrg1_OCT = null;
if (salaryPeriodIncrease1_OCT) {
salaryOrg1_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_OCT?.id,
// rootId: rootId,
// root: rootName?.root,
rootId:salaryOrg2_APR?.rootDnaId,
snapshot: "SNAP1",
group: convertGroup,
},
});
}
const salaryProfile1 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]),
type: Not(In(["NONE", "PENDING"])),
},
});
const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)));
const yearIncrease1 = Extension.ToThaiNumber(
String(Extension.ToThaiYear(salaryPeriod.year - 2)),
@ -2504,12 +2505,132 @@ export class ReportController extends Controller {
@Path() group: string,
) {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
// period: "OCT",??
isActive: true,
},
});
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
//ปีก่อนหน้า
const salaryOldPeriod = await this.salaryPeriodRepository.findOne({
where: {
year: salaryPeriod?.year - 1,
period: "OCT",
},
});
const convertGroup = group.toUpperCase();
const salaryOrg = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodId,
rootId: rootId,
snapshot: "SNAP2",
group: convertGroup,
},
relations: ["salaryProfiles"],
});
//ปีก่อนหน้า
let salaryOrgPrevious = null;
if (salaryOldPeriod) {
salaryOrgPrevious = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryOldPeriod?.id,
rootDnaId: salaryOrg?.rootDnaId,
snapshot: "SNAP1",
group: convertGroup,
},
});
}
const salaryProfile = await this.salaryProfileRepository.find({
relations: ["salaryOrg"],
where: {
salaryOrgId: In([salaryOrg?.id]),
// amountSpecial: MoreThan(0),
},
order: {
salaryOrg: {
group: "ASC",
},
posMasterNo: "ASC",
},
});
const salaryProfilePrevious = await this.salaryProfileRepository.find({
relations: ["salaryOrg"],
where: {
salaryOrgId: In([salaryOrgPrevious?.id]),
},
order: {
salaryOrg: {
group: "ASC",
},
posMasterNo: "ASC",
},
});
const formattedData = salaryProfile.map((item, index) => ({
no: Extension.ToThaiNumber(String(index + 1)),
fullname: item.prefix + item.firstName + " " + item.lastName,
root: item.root??"-",
position: item.position??"-",
posMasterNo:
Extension.ToThaiNumber(item.orgShortName) + Extension.ToThaiNumber(String(item.posMasterNo)),
posTypeCurrent: item.posType??"-",
posLevelCurrent: item.posLevel??"-",
amountCurrent: item.amount? Extension.ToThaiNumber(item.amount.toLocaleString()):"-",
posTypePrevious: salaryProfilePrevious.length > 0
? (() => {
const filteredType = salaryProfilePrevious
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.posType);
const posType = filteredType[0];
return posType
? posType : "-";
})()
: "-",
posLevelPrevious: salaryProfilePrevious.length > 0
? (() => {
const filteredLevel = salaryProfilePrevious
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.posLevel);
const posLevel = filteredLevel[0];
return posLevel
? posLevel : "-";
})()
: "-",
amountPrevious: salaryProfilePrevious.length > 0
? (() => {
const filteredAmount = salaryProfilePrevious
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.amount);
const amount = filteredAmount[0];
return amount
? Extension.ToThaiNumber(amount.toLocaleString()):"-"
})()
: "-",
deduction: "-", //เงินปรับลด
promote: item.amountUse?Extension.ToThaiNumber(item.amountUse.toLocaleString()):"-", //เงินเลื่อนขั้น
qualification: "-", //เงินปรับวุฒิ
adjustRate: "-", //เงินปรับอัตรา
newRate: "-", //อัตราตั้งใหม่
specialPromote: "-", //ลำดับการเลื่อนกรณีพิเศษ
remark: item.remark??"-",
temporaryPayment: "-", //ถือจ่ายชั่วคราวขั้น
}))
return new HttpSuccess({
template: "gov2-10",
reportName: "gov2-10",
data: {
data: formattedData,
},
});
}
@ -7820,7 +7941,8 @@ export class ReportController extends Controller {
body: {
refIds: {
refId: string;
commandAffectDate: Date | null;
// commandAffectDate: Date | null;//เก่า
commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG)
commandNo: string | null;
commandId?: string | null;
commandYear: number;
@ -7894,11 +8016,15 @@ export class ReportController extends Controller {
body: {
refIds: {
refId: string;
commandAffectDate: Date | null;
// commandAffectDate: Date | null;//เก่า
commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG)
commandDateSign?: Date | null
commandNo: string | null;
commandId: string | null;
commandYear: number;
templateDoc: string | null;
commandCode?: string | null;
commandName?: string | null;
templateDoc?: string | null;
amount: Double | null;
amountSpecial: Double | null;
positionSalaryAmount: Double | null;
@ -7906,6 +8032,7 @@ export class ReportController extends Controller {
mpCee?: string | null;
refCommandCode?: string | null;
refCommandName?: string | null;
remark?: string | null;
}[];
},
@Request() request: RequestWithUser,