diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 87408be..80a59e1 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -3826,6 +3826,8 @@ export class ReportController extends Controller { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, + period: "OCT", + isActive: true }, }); if (!salaryPeriod) { @@ -3835,30 +3837,25 @@ export class ReportController extends Controller { where:{ salaryPeriodId: salaryPeriodId, rootId: rootId, - snapshot: "SNAP1", - } , - select:[ - "fifteenPoint", - "fifteenPercent" - ] - }) - + snapshot: "SNAP2", + } + }); const fifteenPercentData = - fifteenPoint?.fifteenPercent == undefined || fifteenPoint?.fifteenPercent == null - ? "๐" - : Extension.ToThaiNumber(String(fifteenPoint?.fifteenPercent)); + fifteenPoint?.fifteenPercent == undefined || fifteenPoint?.fifteenPercent == null + ? "๐" + : Extension.ToThaiNumber(String(fifteenPoint?.fifteenPercent)); const fifteenPointData = fifteenPoint?.fifteenPoint == undefined || fifteenPoint?.fifteenPoint == null ? ".๐๐" : "." + Extension.ToThaiNumber(String(fifteenPoint?.fifteenPoint)); - - const _salaryPeriodTarget = await this.salaryProfileEmployeeRepository.find({ + + const _salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { - type: "FULL", + type: Not("NONE"), salaryOrg: { - snapshot: "SNAP1", + snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, @@ -3869,30 +3866,54 @@ export class ReportController extends Controller { }, }); - if (!_salaryPeriodTarget) { + if (!_salaryProfileEmployee) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - + + const aprSalaryPeriodCurrent = await this.salaryPeriodRepository.findOne({ + where: { + period: "APR", + year: salaryPeriod.year, + isActive: true + }, + }); const octPreviousYear = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod?.year - 1, + isActive: true }, }); - const octPreviousYear2 = await this.salaryPeriodRepository.findOne({ + const aprPreviousYear2 = await this.salaryPeriodRepository.findOne({ where: { - period: "OCT", - year: salaryPeriod?.year - 2, + period: "APR", + year: salaryPeriod?.year - 1, + isActive: true }, }); - + + let aprPreviousYearProfileCurrent: SalaryProfileEmployee[] = []; + if (aprSalaryPeriodCurrent) { + aprPreviousYearProfileCurrent = await this.salaryProfileEmployeeRepository.find({ + relations: ["salaryOrg"], + where: { + type: Not("NONE"), + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: aprSalaryPeriodCurrent?.id, + }, + }, + }); + } + let octPreviousYearProfile: SalaryProfileEmployee[] = []; if (octPreviousYear) { octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { - type: "FULL", + type: Not("NONE"), salaryOrg: { snapshot: "SNAP2", rootId: rootId, @@ -3902,24 +3923,24 @@ export class ReportController extends Controller { }); } - let octPreviousYearProfile2: SalaryProfileEmployee[] = []; - if (octPreviousYear2) { - octPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ + let aprPreviousYearProfile2: SalaryProfileEmployee[] = []; + if (aprPreviousYear2) { + aprPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { - type: "FULL", + type: Not("NONE"), salaryOrg: { snapshot: "SNAP2", - salaryPeriodId: octPreviousYear2?.id, + salaryPeriodId: aprPreviousYear2?.id, rootId: rootId, }, }, }); } - const agency = _salaryPeriodTarget[0] == null ? "" : _salaryPeriodTarget[0].root; + const agency = _salaryProfileEmployee[0] == null ? "" : _salaryProfileEmployee[0].root; - const formattedData = _salaryPeriodTarget.map((profile, index) => { + const formattedData = _salaryProfileEmployee.map((profile, index) => { const fullNameParts = [ profile.child4, profile.child3, @@ -3941,28 +3962,11 @@ export class ReportController extends Controller { posNumber: profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, - typeOld2: - octPreviousYear2 && octPreviousYearProfile2.length > 0 ? (() => { - const _profile = octPreviousYearProfile2 - .filter((profileOCT2) => profileOCT2.citizenId === profile.citizenId); - if (_profile.length > 0) { - return _profile[0]?.type === "HAFT" - ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" - ? "๑ ขั้น" - : profile?.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ"; - } - return null; - })() - : null, - yearOld: octPreviousYear == null ? null : Extension.ToThaiNumber(octPreviousYear.year.toString()), - typeOld1: - octPreviousYear && octPreviousYearProfile.length > 0 ? (() => { - const _profile = octPreviousYearProfile - .filter((profileOCT) => profileOCT.citizenId === profile.citizenId); - if (_profile.length > 0) { + typeOld2: //เมษา ปีก่อนหน้า + aprPreviousYear2 && aprPreviousYearProfile2.length > 0 ? (() => { + const _profile = aprPreviousYearProfile2 + .filter((profileAPR2) => profileAPR2.citizenId === profile.citizenId); + if (_profile.length > 0) { return _profile[0]?.type === "HAFT" ? "๐.๕ ขั้น" : _profile[0]?.type === "FULL" @@ -3970,38 +3974,56 @@ export class ReportController extends Controller { : profile?.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; - } - return null; - })() - : null, - typeOld: - _salaryPeriodTarget.length > 0 - ? (() => { - const _profile = _salaryPeriodTarget - .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) - .map((profile) => ({ - type: profile.type, - })); - return _profile[0]?.type === "HAFT" - ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" - ? "๑ ขั้น" - : profile?.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ"; + } + return null; })() - : null, //เมษา ปีเดียวกัน - type: - profile.type === "HAFT" - ? "๐.๕ ขั้น" - : profile.type === "FULL" - ? "๑ ขั้น" - : profile.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ", - score1: null, - score2: null, - }; + : null, + yearOld: + octPreviousYear == null ? null : Extension.ToThaiNumber(octPreviousYear.year.toString()), + typeOld1: //ตุลา ปีก่อนหน้า + octPreviousYear && octPreviousYearProfile.length > 0 ? (() => { + const _profile = octPreviousYearProfile + .filter((profileOCT) => profileOCT.citizenId === profile.citizenId); + if (_profile.length > 0) { + return _profile[0]?.type === "HAFT" + ? "๐.๕ ขั้น" + : _profile[0]?.type === "FULL" + ? "๑ ขั้น" + : profile?.type === "FULLHAFT" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + } + return null; + })() + : null, + typeOld: + aprPreviousYearProfileCurrent.length > 0 + ? (() => { + const _profile = aprPreviousYearProfileCurrent + .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) + .map((profile) => ({ + type: profile.type, + })); + return _profile[0]?.type === "HAFT" + ? "๐.๕ ขั้น" + : _profile[0]?.type === "FULL" + ? "๑ ขั้น" + : profile?.type === "FULLHAFT" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + })() + : null, //เมษา + type: + profile.type === "HAFT" + ? "๐.๕ ขั้น" + : profile.type === "FULL" + ? "๑ ขั้น" + : profile.type === "FULLHAFT" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ", + score1: null, + score2: null, + }; }); return new HttpSuccess({ @@ -4009,14 +4031,16 @@ export class ReportController extends Controller { reportName: "emp2-03", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice(-2,), - yearShortOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1))).slice(-2,), + yearOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1))), + yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice(-2), + yearShortOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1))).slice(-2), fifteenPercent: fifteenPercentData + fifteenPointData, agency: agency, data: formattedData, }, }); } + /** * API 04-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้สมควรได้เลื่อนขั้นค่าจ้าง (แบบ ลจ.กทม.1) * diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 036e165..5d9336b 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -158,7 +158,11 @@ export class SalaryPeriodController extends Controller { org: item.root, total: item.total + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.total), fifteenPercent: - item.fifteenPercent + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.fifteenPercent), + item.fifteenPercent + + item.fifteenPoint / 100 + + (_salaryOrgGROUP2 == null + ? 0 + : _salaryOrgGROUP2.fifteenPercent + _salaryOrgGROUP2.fifteenPoint / 100), chosen: item.quantityUsed + (_salaryOrgGROUP2 == null ? 0 : _salaryOrgGROUP2.quantityUsed), remaining: @@ -1713,7 +1717,6 @@ export class SalaryPeriodController extends Controller { }); 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", { diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index e05513c..99cca8d 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -140,7 +140,7 @@ export class SalaryPeriodEmployeeController extends Controller { const data = { org: item.root, total: item.total, - fifteenPercent: item.fifteenPercent, + fifteenPercent: item.fifteenPercent + item.fifteenPoint / 100, chosen: item.quantityUsed, remaining: item.remainQuota, currentAmount: item.currentAmount,