คำนวนเงินเดือนย้อนหลัง
This commit is contained in:
parent
bbe3ee2906
commit
97551dc096
4 changed files with 215 additions and 65 deletions
|
|
@ -121,10 +121,14 @@ export class SalaryPeriodController extends Controller {
|
|||
const data = {
|
||||
total: salaryOrg.total,
|
||||
fifteenPercent: salaryOrg.fifteenPercent,
|
||||
chosen: salaryOrg.salaryProfiles.filter((x) => x.posType == "FULL").length,
|
||||
remaining:
|
||||
salaryOrg.fifteenPercent -
|
||||
salaryOrg.salaryProfiles.filter((x) => x.posType == "FULL").length,
|
||||
chosen: salaryOrg.quantityUsed,
|
||||
remaining: salaryOrg.remainQuota,
|
||||
currentAmount: salaryOrg.currentAmount,
|
||||
sixPercentAmount: salaryOrg.sixPercentAmount,
|
||||
spentAmount: salaryOrg.spentAmount,
|
||||
sixPercentSpentAmount: salaryOrg.sixPercentAmount - salaryOrg.spentAmount,
|
||||
useAmount: salaryOrg.useAmount,
|
||||
remainingAmount: salaryOrg.remainingAmount,
|
||||
};
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
|
@ -888,14 +892,96 @@ export class SalaryPeriodController extends Controller {
|
|||
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
if (salaryPeriod.period == "OCT") {
|
||||
const salaryPeriodAPROld = await this.salaryPeriodRepository.findOne({
|
||||
where: {
|
||||
year: salaryPeriod.year,
|
||||
period: "APR",
|
||||
},
|
||||
});
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
let totalAmount = 0;
|
||||
if (salaryPeriodAPROld != null) {
|
||||
const salaryOrgSnap2Old: any = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriodAPROld.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP2",
|
||||
},
|
||||
relations: ["salaryProfiles"],
|
||||
});
|
||||
totalAmount =
|
||||
salaryOrgSnap2Old == null
|
||||
? 0
|
||||
: Extension.sumObjectValues(salaryOrgSnap2Old.salaryProfiles, "amountUse");
|
||||
}
|
||||
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP1",
|
||||
},
|
||||
});
|
||||
if (salaryOrgSnap1 == null) {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
_salaryOrg.spentAmount = totalAmount;
|
||||
} else {
|
||||
_salaryOrg.currentAmount = salaryOrgSnap1.currentAmount;
|
||||
_salaryOrg.sixPercentAmount = salaryOrgSnap1.sixPercentAmount;
|
||||
_salaryOrg.spentAmount = salaryOrgSnap1.spentAmount;
|
||||
_salaryOrg.useAmount = salaryOrgSnap1.useAmount;
|
||||
_salaryOrg.remainingAmount = salaryOrgSnap1.remainingAmount;
|
||||
}
|
||||
} else {
|
||||
const totalProfile = Extension.sumObjectValues(_salaryOrg.salaryProfiles, "amount");
|
||||
_salaryOrg.currentAmount = totalProfile;
|
||||
_salaryOrg.sixPercentAmount = totalProfile * 0.06;
|
||||
_salaryOrg.spentAmount = totalAmount;
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
await Promise.all(
|
||||
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
|
||||
if (snapshot == "SNAP2") {
|
||||
const salaryOrgSnap1 = await this.salaryOrgRepository.findOne({
|
||||
where: {
|
||||
salaryPeriodId: salaryPeriod.id,
|
||||
rootId: _salaryOrg.rootId,
|
||||
group: _salaryOrg.group,
|
||||
snapshot: "SNAP1",
|
||||
},
|
||||
});
|
||||
if (salaryOrgSnap1 == null) {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
} else {
|
||||
_salaryOrg.total = salaryOrgSnap1.total;
|
||||
_salaryOrg.fifteenPercent = salaryOrgSnap1.fifteenPercent;
|
||||
_salaryOrg.fifteenPoint = salaryOrgSnap1.fifteenPoint;
|
||||
_salaryOrg.quantityUsed = salaryOrgSnap1.quantityUsed;
|
||||
_salaryOrg.remainQuota = salaryOrgSnap1.remainQuota;
|
||||
}
|
||||
} else {
|
||||
_salaryOrg.total = _salaryOrg.salaryProfiles.length;
|
||||
_salaryOrg.fifteenPercent = Math.floor((_salaryOrg.salaryProfiles.length * 15) / 100);
|
||||
_salaryOrg.fifteenPoint = (_salaryOrg.salaryProfiles.length * 15) % 100;
|
||||
}
|
||||
|
||||
await this.salaryOrgRepository.save(_salaryOrg);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,34 +235,39 @@ export class SalaryProfile extends EntityBase {
|
|||
child4: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ผลการประเมิน",
|
||||
default: false,
|
||||
default: null,
|
||||
})
|
||||
result: boolean;
|
||||
result: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ระยะเวลา",
|
||||
default: false,
|
||||
default: null,
|
||||
})
|
||||
duration: boolean;
|
||||
duration: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "การลงโทษ",
|
||||
default: false,
|
||||
default: null,
|
||||
})
|
||||
punish: boolean;
|
||||
punish: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "พักราชการ",
|
||||
default: false,
|
||||
default: null,
|
||||
})
|
||||
retired: boolean;
|
||||
retired: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ขาดราชการ",
|
||||
default: false,
|
||||
default: null,
|
||||
})
|
||||
retired2: boolean;
|
||||
retired2: string;
|
||||
|
||||
@ManyToOne(() => SalaryOrg, (salaryOrg) => salaryOrg.salaryProfiles)
|
||||
@JoinColumn({ name: "salaryOrgId" })
|
||||
|
|
|
|||
|
|
@ -1,54 +1,81 @@
|
|||
class Extension {
|
||||
|
||||
public static ToThaiMonth(value: number) {
|
||||
switch (value) {
|
||||
case 1: return "มกราคม";
|
||||
case 2: return "กุมภาพันธ์";
|
||||
case 3: return "มีนาคม";
|
||||
case 4: return "เมษายน";
|
||||
case 5: return "พฤษภาคม";
|
||||
case 6: return "มิถุนายน";
|
||||
case 7: return "กรกฎาคม";
|
||||
case 8: return "สิงหาคม";
|
||||
case 9: return "กันยายน";
|
||||
case 10: return "ตุลาคม";
|
||||
case 11: return "พฤศจิกายน";
|
||||
case 12: return "ธันวาคม";
|
||||
default: return "";
|
||||
}
|
||||
public static ToThaiMonth(value: number) {
|
||||
switch (value) {
|
||||
case 1:
|
||||
return "มกราคม";
|
||||
case 2:
|
||||
return "กุมภาพันธ์";
|
||||
case 3:
|
||||
return "มีนาคม";
|
||||
case 4:
|
||||
return "เมษายน";
|
||||
case 5:
|
||||
return "พฤษภาคม";
|
||||
case 6:
|
||||
return "มิถุนายน";
|
||||
case 7:
|
||||
return "กรกฎาคม";
|
||||
case 8:
|
||||
return "สิงหาคม";
|
||||
case 9:
|
||||
return "กันยายน";
|
||||
case 10:
|
||||
return "ตุลาคม";
|
||||
case 11:
|
||||
return "พฤศจิกายน";
|
||||
case 12:
|
||||
return "ธันวาคม";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static ToThaiYear(value: number) {
|
||||
if (value < 2400)
|
||||
return value + 543;
|
||||
else return value;
|
||||
}
|
||||
public static ToThaiYear(value: number) {
|
||||
if (value < 2400) return value + 543;
|
||||
else return value;
|
||||
}
|
||||
|
||||
public static ToCeYear(value: number) {
|
||||
if (value >= 2400)
|
||||
return value - 543;
|
||||
else return value;
|
||||
}
|
||||
public static ToCeYear(value: number) {
|
||||
if (value >= 2400) return value - 543;
|
||||
else return value;
|
||||
}
|
||||
|
||||
public static ToThaiNumber(value: string) {
|
||||
let arabicNumbers = "0123456789";
|
||||
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
|
||||
let result = "";
|
||||
for (let digit of value) {
|
||||
let index = arabicNumbers.indexOf(digit);
|
||||
if (index >= 0) {
|
||||
result += thaiNumbers[index];
|
||||
} else {
|
||||
result += digit;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
public static ToThaiNumber(value: string) {
|
||||
let arabicNumbers = "0123456789";
|
||||
let thaiNumbers = "๐๑๒๓๔๕๖๗๘๙";
|
||||
let result = "";
|
||||
for (let digit of value) {
|
||||
let index = arabicNumbers.indexOf(digit);
|
||||
if (index >= 0) {
|
||||
result += thaiNumbers[index];
|
||||
} else {
|
||||
result += digit;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ToThaiFullDate(value: Date) {
|
||||
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
||||
return "วันที่ "+ value.getDate() +" เดือน "+ Extension.ToThaiMonth(value.getMonth() + 1)+ " พ.ศ. " + yy;
|
||||
public static ToThaiFullDate(value: Date) {
|
||||
let yy = value.getFullYear() < 2400 ? value.getFullYear() + 543 : value.getFullYear();
|
||||
return (
|
||||
"วันที่ " +
|
||||
value.getDate() +
|
||||
" เดือน " +
|
||||
Extension.ToThaiMonth(value.getMonth() + 1) +
|
||||
" พ.ศ. " +
|
||||
yy
|
||||
);
|
||||
}
|
||||
|
||||
public static sumObjectValues(array: any, propertyName: any) {
|
||||
let sum = 0;
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i][propertyName] !== undefined) {
|
||||
sum += array[i][propertyName];
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
export default Extension;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableSalaryProfileAddRetired31709113262974 implements MigrationInterface {
|
||||
name = 'UpdateTableSalaryProfileAddRetired31709113262974'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`result\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`result\` varchar(255) NULL COMMENT 'ผลการประเมิน'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`duration\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`duration\` varchar(255) NULL COMMENT 'ระยะเวลา'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`punish\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`punish\` varchar(255) NULL COMMENT 'การลงโทษ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`retired\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`retired\` varchar(255) NULL COMMENT 'พักราชการ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`retired2\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`retired2\` varchar(255) NULL COMMENT 'ขาดราชการ'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`retired2\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`retired2\` tinyint NOT NULL COMMENT 'ขาดราชการ' DEFAULT '0'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`retired\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`retired\` tinyint NOT NULL COMMENT 'พักราชการ' DEFAULT '0'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`punish\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`punish\` tinyint NOT NULL COMMENT 'การลงโทษ' DEFAULT '0'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`duration\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`duration\` tinyint NOT NULL COMMENT 'ระยะเวลา' DEFAULT '0'`);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP COLUMN \`result\``);
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD \`result\` tinyint NOT NULL COMMENT 'ผลการประเมิน' DEFAULT '0'`);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue