dashboard เงินเดือน
This commit is contained in:
parent
94d0412e21
commit
76f42d1a96
3 changed files with 191 additions and 12 deletions
|
|
@ -1213,6 +1213,15 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
|
||||
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 revisionId = await new CallAPI().GetData(request, "org/unauthorize/revision/latest");
|
||||
|
||||
|
|
@ -1220,11 +1229,29 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
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);
|
||||
}),
|
||||
);
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
|
|
@ -1295,6 +1322,15 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
|
||||
const salaryOrgEmployee = await this.salaryOrgEmployeeRepository.find({
|
||||
where: { salaryPeriodId: chk_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 revisionId = await new CallAPI().GetData(request, "org/unauthorize/revision/latest");
|
||||
|
||||
|
|
@ -1302,11 +1338,30 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryPeriodRepository.save(chk_SalaryPeriod);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
salaryOrgNew.revisionId = chk_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);
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
salaryOrgNew.salaryPeriodId = chk_SalaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
salaryOrgNew.revisionId = chk_SalaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
|
|
@ -1591,12 +1646,13 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
delete salaryOrgNew.id;
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
|
|
@ -1614,11 +1670,12 @@ export class SalaryPeriodController extends Controller {
|
|||
);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
|
|
@ -2004,6 +2061,15 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryOrgRepository.remove(salaryOrg);
|
||||
await this.salaryProfileRepository.remove(salaryProfile);
|
||||
|
||||
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", {
|
||||
|
|
@ -2067,11 +2133,12 @@ export class SalaryPeriodController extends Controller {
|
|||
await this.salaryPeriodRepository.save(salaryPeriod);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrg());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
|
|
@ -2089,11 +2156,12 @@ export class SalaryPeriodController extends Controller {
|
|||
);
|
||||
|
||||
await Promise.all(
|
||||
orgs.map(async (rootId: string) => {
|
||||
orgs.map(async (root: any) => {
|
||||
let salaryOrgNew = Object.assign(new SalaryOrgEmployee());
|
||||
salaryOrgNew.salaryPeriodId = salaryPeriod.id;
|
||||
salaryOrgNew.status = "PENDING";
|
||||
salaryOrgNew.rootId = rootId;
|
||||
salaryOrgNew.rootId = root.rootId;
|
||||
salaryOrgNew.root = root.root;
|
||||
salaryOrgNew.revisionId = salaryPeriod.revisionId;
|
||||
salaryOrgNew.snapshot = snapshot;
|
||||
salaryOrgNew.createdUserId = request.user.sub;
|
||||
|
|
|
|||
|
|
@ -101,6 +101,107 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ยอดใช้งานทั้งหมด
|
||||
*
|
||||
* @summary ยอดใช้งานทั้งหมด
|
||||
*
|
||||
* @param {string} id
|
||||
* @param {string} group
|
||||
* @param {string} period
|
||||
* @param {string} snapshot
|
||||
*/
|
||||
@Post("summary/all")
|
||||
async summaryUseSalary(
|
||||
@Body()
|
||||
body: {
|
||||
year: number;
|
||||
group: string;
|
||||
period: string;
|
||||
snapshot: string;
|
||||
},
|
||||
) {
|
||||
const _salaryOrg = await this.salaryOrgRepository.find({
|
||||
relations: ["salaryPeriod", "salaryProfiles"],
|
||||
where: {
|
||||
group: body.group,
|
||||
snapshot: body.snapshot.trim().toUpperCase(),
|
||||
salaryPeriod: { period: body.period.trim().toUpperCase(), year: body.year },
|
||||
},
|
||||
});
|
||||
const salaryOrg: any[] = [];
|
||||
await Promise.all(
|
||||
_salaryOrg.map(async (item) => {
|
||||
const fullNameParts = [
|
||||
item == null || item.salaryProfiles.length == 0 || item.salaryProfiles[0].root == null
|
||||
? null
|
||||
: item.salaryProfiles[0].root,
|
||||
];
|
||||
const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/");
|
||||
const sum = item.salaryProfiles.reduce((accumulator, object) => {
|
||||
return accumulator + object.amountSpecial;
|
||||
}, 0);
|
||||
const data = {
|
||||
org: org,
|
||||
total: item.total,
|
||||
fifteenPercent: item.fifteenPercent,
|
||||
chosen: item.quantityUsed,
|
||||
remaining: item.remainQuota,
|
||||
currentAmount: item.currentAmount,
|
||||
sixPercentAmount: item.sixPercentAmount,
|
||||
spentAmount: item.spentAmount,
|
||||
sixPercentSpentAmount: item.sixPercentAmount - item.spentAmount,
|
||||
useAmount: item.useAmount,
|
||||
remainingAmount: item.remainingAmount,
|
||||
totalAmountSpecial: sum,
|
||||
totalBackup: item.salaryProfiles.filter((x) => x.isReserve == true).length,
|
||||
};
|
||||
salaryOrg.push(data);
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess({
|
||||
salaryOrg,
|
||||
dashboard: {
|
||||
total: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.total;
|
||||
}, 0),
|
||||
fifteenPercent: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.fifteenPercent;
|
||||
}, 0),
|
||||
chosen: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.chosen;
|
||||
}, 0),
|
||||
remaining: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.remaining;
|
||||
}, 0),
|
||||
currentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.currentAmount;
|
||||
}, 0),
|
||||
sixPercentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.sixPercentAmount;
|
||||
}, 0),
|
||||
spentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.spentAmount;
|
||||
}, 0),
|
||||
sixPercentSpentAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.sixPercentSpentAmount;
|
||||
}, 0),
|
||||
useAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.useAmount;
|
||||
}, 0),
|
||||
remainingAmount: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.remainingAmount;
|
||||
}, 0),
|
||||
totalAmountSpecial: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.totalAmountSpecial;
|
||||
}, 0),
|
||||
totalBackup: salaryOrg.reduce((accumulator, object) => {
|
||||
return accumulator + object.totalBackup;
|
||||
}, 0),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* API จำนวนโควตา
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue