Merge branch 'develop' into adiDev
This commit is contained in:
commit
6fd1a8170e
11 changed files with 212 additions and 69 deletions
|
|
@ -27,6 +27,8 @@ import { PosType } from "../entities/PosType";
|
|||
import { PosLevel } from "../entities/PosLevel";
|
||||
import { Salarys } from "../entities/Salarys";
|
||||
import { SalaryRanks } from "../entities/SalaryRanks";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { Int32 } from "typeorm/browser";
|
||||
|
||||
@Route("api/v1/salary/period")
|
||||
@Tags("Salary")
|
||||
|
|
@ -478,7 +480,8 @@ export class SalaryPeriodController extends Controller {
|
|||
);
|
||||
}
|
||||
|
||||
const salaryProfile = Object.assign(new SalaryProfile(), requestBody);
|
||||
let salaryProfile: any = Object.assign(new SalaryProfile(), requestBody);
|
||||
delete salaryProfile.id;
|
||||
salaryProfile.type = salaryProfile.type.toUpperCase();
|
||||
//Type & Level
|
||||
const type = await this.posTypeRepository.findOne({
|
||||
|
|
@ -555,7 +558,9 @@ export class SalaryPeriodController extends Controller {
|
|||
: salaryRanks.salaryFullHalf - salaryProfile.amount;
|
||||
salaryProfile.positionSalaryAmount = salaryRanks == null ? 0 : salaryRanks.salaryFullHalf;
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
|
||||
salaryProfile.amountSpecial = 0;
|
||||
salaryProfile.amountUse = 0;
|
||||
salaryProfile.positionSalaryAmount = 0;
|
||||
}
|
||||
|
||||
salaryProfile.salaryOrgId = salaryOrg.id;
|
||||
|
|
@ -625,7 +630,7 @@ export class SalaryPeriodController extends Controller {
|
|||
where: { id: id },
|
||||
});
|
||||
if (!chk_SalaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||
}
|
||||
|
||||
const chk_toUpper = ["SPECIAL", "APR", "OCT"];
|
||||
|
|
@ -669,7 +674,7 @@ export class SalaryPeriodController extends Controller {
|
|||
where: { id: id },
|
||||
});
|
||||
if (!SalaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||
}
|
||||
const SalaryOrg = await this.salaryOrgRepository.findOne({
|
||||
where: { salaryPeriodId: SalaryPeriod.id },
|
||||
|
|
@ -704,7 +709,7 @@ export class SalaryPeriodController extends Controller {
|
|||
],
|
||||
});
|
||||
if (!salaryPeriod) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้");
|
||||
}
|
||||
return new HttpSuccess(salaryPeriod);
|
||||
}
|
||||
|
|
@ -751,13 +756,13 @@ export class SalaryPeriodController extends Controller {
|
|||
* @summary snapshot salary
|
||||
*
|
||||
*/
|
||||
@Get("snapshot/{snaphot}/{salaryPeriodId}")
|
||||
@Get("snapshot/{snapshot}/{salaryPeriodId}")
|
||||
async SnapshotSalary(
|
||||
@Path() snaphot: string,
|
||||
@Path() snapshot: string,
|
||||
salaryPeriodId: string,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
snaphot = snaphot.toLocaleUpperCase();
|
||||
snapshot = snapshot.toLocaleUpperCase();
|
||||
const salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: { id: salaryPeriodId },
|
||||
});
|
||||
|
|
@ -766,17 +771,38 @@ export class SalaryPeriodController extends Controller {
|
|||
}
|
||||
|
||||
const salaryOrg = await this.salaryOrgRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot },
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
});
|
||||
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);
|
||||
|
||||
let orgs: any;
|
||||
let orgProfiles: any;
|
||||
let revisionId: any;
|
||||
let orgs = await new CallAPI().GetData(request, "org/active/root/id");
|
||||
let total = 1000;
|
||||
let _orgProfiles = await new CallAPI().PostData(request, "org/profile/salary/gen", {
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
});
|
||||
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/profile/salary/gen", {
|
||||
page: index,
|
||||
pageSize: 1000,
|
||||
keyword: "",
|
||||
})
|
||||
.then((x) => {
|
||||
Array.prototype.push.apply(orgProfiles, x.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
let revisionId = await new CallAPI().GetData(request, "org/revision/latest");
|
||||
|
||||
salaryPeriod.revisionId = revisionId;
|
||||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
|
|
@ -784,11 +810,12 @@ export class SalaryPeriodController extends Controller {
|
|||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snaphot;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.group = "GROUP1";
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
salaryOrgNew.createdFullName = request.user.name;
|
||||
|
|
@ -802,9 +829,9 @@ export class SalaryPeriodController extends Controller {
|
|||
);
|
||||
|
||||
let salaryProfileOld: SalaryProfile[] = [];
|
||||
if (snaphot == "SNAP2") {
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgOld = await this.salaryOrgRepository.findOne({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot },
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
if (salaryOrgOld != null) salaryProfileOld = salaryOrgOld.salaryProfiles;
|
||||
|
|
@ -827,13 +854,14 @@ export class SalaryPeriodController extends Controller {
|
|||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: profile.rootId,
|
||||
snapshot: snaphot,
|
||||
snapshot: snapshot,
|
||||
group: group,
|
||||
},
|
||||
});
|
||||
|
||||
if (salaryOrgNew != null) {
|
||||
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
|
||||
delete profile.id;
|
||||
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
|
||||
salaryProfileNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryProfileNew.createdUserId = request.user.sub;
|
||||
|
|
@ -841,7 +869,7 @@ export class SalaryPeriodController extends Controller {
|
|||
salaryProfileNew.lastUpdateUserId = request.user.sub;
|
||||
salaryProfileNew.lastUpdateFullName = request.user.name;
|
||||
|
||||
if (snaphot == "SNAP2") {
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOld = salaryProfileOld.find(
|
||||
(x) => x.citizenId == salaryProfileNew.citizenId,
|
||||
);
|
||||
|
|
@ -857,7 +885,7 @@ export class SalaryPeriodController extends Controller {
|
|||
);
|
||||
|
||||
const salaryOrgNew = await this.salaryOrgRepository.find({
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snaphot },
|
||||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
await Promise.all(
|
||||
|
|
@ -871,4 +899,46 @@ export class SalaryPeriodController extends Controller {
|
|||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cronjob SalaryPeriod
|
||||
*/
|
||||
async CronjobSalaryPeriod() {
|
||||
const current = new Date();
|
||||
let salaryPeriod: any;
|
||||
// console.log(current.getDate(), current.getMonth() , current.getFullYear())
|
||||
if (current.getDate() == 1 && current.getMonth() == 2) {
|
||||
salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
year: current.getFullYear(),
|
||||
period: "MAR",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
} else if (current.getDate() == 1 && current.getMonth() == 3) {
|
||||
salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
year: current.getFullYear(),
|
||||
period: "APR",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
} else if (current.getDate() == 1 && current.getMonth() == 8) {
|
||||
salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
year: current.getFullYear(),
|
||||
period: "SEP",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
} else if (current.getDate() == 1 && current.getMonth() == 9) {
|
||||
salaryPeriod = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
year: current.getFullYear(),
|
||||
period: "OCT",
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue