dashboard เงินเดือน

This commit is contained in:
Kittapath 2024-03-27 16:39:45 +07:00
parent 94d0412e21
commit 76f42d1a96
3 changed files with 191 additions and 12 deletions

View file

@ -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;

View file

@ -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
*

View file

@ -22,6 +22,13 @@ export class SalaryOrg extends EntityBase {
})
rootId: string;
@Column({
nullable: true,
comment: "orgRoot",
length: 255,
})
root: string;
@Column({
nullable: true,
comment: "คีย์นอก(FK)ของตาราง orgRevision",
@ -140,6 +147,9 @@ export class CreateSalaryOrg {
@Column("uuid")
rootId: string;
@Column()
root: string;
@Column()
total: number;