Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-06-06 18:06:47 +07:00
commit 823fcb8ea8
6 changed files with 294 additions and 6 deletions

View file

@ -3019,4 +3019,29 @@ export class ProfileController extends Controller {
});
return new HttpSuccess(formattedData);
}
/**
* API
*
* @summary (ADMIN)
*
* @param {string} id Id
*/
@Put("salary/{id}")
async updateLeaveUser(
@Path() id: string,
@Body()
requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date },
) {
const profile = await this.profileRepo.findOne({
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
profile.isLeave = requestBody.isLeave;
profile.leaveReason = requestBody.leaveReason;
profile.dateLeave = requestBody.dateLeave;
await this.profileRepo.save(profile);
return new HttpSuccess();
}
}

View file

@ -27,6 +27,7 @@ import {
CreateProfileEmployee,
UpdateProfileEmployee,
ProfileEmployeeHistory,
UpdatePositionTempProfileEmployee
} from "../entities/ProfileEmployee";
import { EmployeePosLevel } from "../entities/EmployeePosLevel";
import { EmployeePosType } from "../entities/EmployeePosType";
@ -44,6 +45,11 @@ import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
import Extension from "../interfaces/extension";
import { OrgRoot } from "../entities/OrgRoot";
import { OrgChild1 } from "../entities/OrgChild1";
import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
@Route("api/v1/org/profile-employee")
@Tags("ProfileEmployee")
@ -71,6 +77,11 @@ export class ProfileEmployeeController extends Controller {
private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline);
private educationRepository = AppDataSource.getRepository(ProfileEducation);
private salaryRepository = AppDataSource.getRepository(ProfileSalary);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
private child3Repository = AppDataSource.getRepository(OrgChild3);
private child4Repository = AppDataSource.getRepository(OrgChild4);
/**
* report
@ -785,11 +796,20 @@ export class ProfileEmployeeController extends Controller {
position: _data.position,
posNo: shortName,
employeeClass: _data.employeeClass == null ? null : _data.employeeClass,
dateAppoint: _data.dateAppoint,
govAge: Extension.CalculateGovAge(_data.dateAppoint,0,0),
age: Extension.CalculateAgeStrV2(_data.birthDate,0,0),
dateAppoint: _data.dateAppoint,
dateStart: _data.dateStart,
createdAt: _data.createdAt,
createdAt: _data.createdAt,
dateRetireLaw: _data.dateRetireLaw,
draftOrgEmployeeStatus: null
draftOrganizationOrganization:
_data.nodeTemp == "0" ? _data.rootTemp :
_data.nodeTemp == "1" ? _data.child1Temp :
_data.nodeTemp == "2" ? _data.child2Temp :
_data.nodeTemp == "3" ? _data.child3Temp :
_data.nodeTemp == "4" ? _data.child4Temp : null,
draftPositionEmployee: _data.positionTemp,
draftOrgEmployeeStatus: _data.statusTemp
};
}),
);
@ -1504,6 +1524,138 @@ export class ProfileEmployeeController extends Controller {
return new HttpSuccess(formattedData);
}
/**
* API
*
* @summary (ADMIN)
*
* @param {string} id Id
*/
@Put("position/{id}")
async positionProfileEmployee(
@Request() request: RequestWithUser,
@Path() id: string,
@Body() body: UpdatePositionTempProfileEmployee,
) {
if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null;
if (body.posLevelId && !(await this.posLevelRepo.findOneBy({ id: body.posLevelId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้");
}
if (body.posTypeId && !(await this.posTypeRepo.findOneBy({ id: body.posTypeId }))) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
}
const profileEmp = await this.profileRepo.findOneBy({ id });
if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
switch (body.node) {
case 0: {
const data = await this.orgRootRepository.findOne({
where: { id: body.nodeId },
});
if (data != null) {
profileEmp.rootIdTemp = data.id;
profileEmp.rootTemp = data.orgRootName;
profileEmp.rootShortNameTemp = data.orgRootShortName;
}
}
case 1: {
const data = await this.child1Repository.findOne({
where: { id: body.nodeId },
relations: ["orgRoot"]
});
if (data != null) {
profileEmp.rootIdTemp = data.orgRoot.id;
profileEmp.rootTemp = data.orgRoot.orgRootName;
profileEmp.rootShortNameTemp = data.orgRoot.orgRootShortName;
profileEmp.child1IdTemp = data.id;
profileEmp.child1Temp = data.orgChild1Name;
profileEmp.child1ShortNameTemp = data.orgChild1ShortName;
}
}
case 2: {
const data = await this.child2Repository.findOne({
where: { id: body.nodeId },
relations: ["orgRoot", "orgChild1"]
});
if (data != null) {
profileEmp.rootIdTemp = data.orgRoot.id;
profileEmp.rootTemp = data.orgRoot.orgRootName;
profileEmp.rootShortNameTemp = data.orgRoot.orgRootShortName;
profileEmp.child1IdTemp = data.orgChild1.id;
profileEmp.child1Temp = data.orgChild1.orgChild1Name;
profileEmp.child1ShortNameTemp = data.orgChild1.orgChild1ShortName;
profileEmp.child2IdTemp = data.id;
profileEmp.child2Temp = data.orgChild2Name;
profileEmp.child2ShortNameTemp = data.orgChild2ShortName;
}
}
case 3: {
const data = await this.child3Repository.findOne({
where: { id: body.nodeId },
relations: ["orgRoot", "orgChild1", "orgChild2"]
});
if (data != null) {
profileEmp.rootIdTemp = data.orgRoot.id;
profileEmp.rootTemp = data.orgRoot.orgRootName;
profileEmp.rootShortNameTemp = data.orgRoot.orgRootShortName;
profileEmp.child1IdTemp = data.orgChild1.id;
profileEmp.child1Temp = data.orgChild1.orgChild1Name;
profileEmp.child1ShortNameTemp = data.orgChild1.orgChild1ShortName;
profileEmp.child2IdTemp = data.orgChild2.id;
profileEmp.child2Temp = data.orgChild2.orgChild2Name;
profileEmp.child2ShortNameTemp = data.orgChild2.orgChild2ShortName;
profileEmp.child3IdTemp = data.id;
profileEmp.child3Temp = data.orgChild3Name;
profileEmp.child3ShortNameTemp = data.orgChild3ShortName;
}
}
case 4: {
const data = await this.child4Repository.findOne({
where: { id: body.nodeId },
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"]
});
if (data != null) {
profileEmp.rootIdTemp = data.orgRoot.id;
profileEmp.rootTemp = data.orgRoot.orgRootName;
profileEmp.rootShortNameTemp = data.orgRoot.orgRootShortName;
profileEmp.child1IdTemp = data.orgChild1.id;
profileEmp.child1Temp = data.orgChild1.orgChild1Name;
profileEmp.child1ShortNameTemp = data.orgChild1.orgChild1ShortName;
profileEmp.child2IdTemp = data.orgChild2.id;
profileEmp.child2Temp = data.orgChild2.orgChild2Name;
profileEmp.child2ShortNameTemp = data.orgChild2.orgChild2ShortName;
profileEmp.child3IdTemp = data.orgChild3.id;
profileEmp.child3Temp = data.orgChild3.orgChild3Name;
profileEmp.child3ShortNameTemp = data.orgChild3.orgChild3ShortName;
profileEmp.child4IdTemp = data.id;
profileEmp.child4Temp = data.orgChild4Name;
profileEmp.child4ShortNameTemp = data.orgChild4ShortName;
}
}
}
profileEmp.lastUpdateUserId = request.user.sub;
profileEmp.lastUpdateFullName = request.user.name;
profileEmp.nodeTemp = String(body.node);
profileEmp.nodeIdTemp = body.nodeId;
profileEmp.orgRevisionIdTemp = body.orgRevisionId;
profileEmp.posmasterIdTemp = body.posmasterId;
profileEmp.posMasterNoTemp = body.posMasterNo;
profileEmp.positionIdTemp = body.positionId;
profileEmp.positionTemp = body.position;
profileEmp.positionFieldTemp = body.positionField;
profileEmp.posTypeIdTemp = String(body.posTypeId);
profileEmp.posTypeNameTemp = body.posTypeName;
profileEmp.posLevelIdTemp = String(body.posLevelId);
profileEmp.posLevelNameTemp = body.posLevelName;
profileEmp.statusTemp = "REPORT";
this.profileRepo.merge(profileEmp, body);
await this.profileRepo.save(profileEmp);
return new HttpSuccess();
}
/**
* API
*

View file

@ -166,6 +166,14 @@ export class Profile extends EntityBase {
})
leaveReason: string;
@Column({
nullable: true,
type: "datetime",
comment: "วันพ้นราชการ",
default: null,
})
dateLeave: Date;
@Column({
nullable: true,
type: "datetime",
@ -466,15 +474,15 @@ export class Profile extends EntityBase {
@Column({
nullable: true,
length: 40,
comment: "ไอดีรอบลงเวลาล่าสุด"
comment: "ไอดีรอบลงเวลาล่าสุด",
})
dutyTimeId : string;
dutyTimeId: string;
@Column({
nullable: true,
type: "datetime",
comment: "รอบลงเวลาล่าสุด",
default: null
default: null,
})
dutyTimeEffectiveDate: Date;
}

View file

@ -721,3 +721,18 @@ export type UpdateProfileAddressEmployee = {
currentSubDistrictId?: string | null;
currentZipCode?: string | null;
};
export type UpdatePositionTempProfileEmployee = {
posmasterId: string ;
node: number ;
nodeId: string ;
orgRevisionId: string ;
positionId: string ;
posMasterNo: string ;
position: string ;
positionField: string ;
posTypeId: string | null;
posTypeName: string ;
posLevelId: string | null;
posLevelName: string ;
};

View file

@ -171,6 +171,78 @@ class Extension {
}
return citizen;
}
public static CalculateGovAge(appointDate: Date, plusYear: number = 0, subtractYear: number = 0): number {
if (appointDate == null || appointDate == undefined) return 0
const now = new Date();
if (now.getMonth() - appointDate.getMonth() >= 6) {
return (now.getFullYear() - appointDate.getFullYear()) + 1 + plusYear - subtractYear;
}
else {
return (now.getFullYear() - appointDate.getFullYear()) + plusYear - subtractYear;
}
}
public static CalculateAge(appointDate: Date, plusYear: number = 0, subtractYear: number = 0) {
let currentDate = new Date().getTime();
let appointDateTime = new Date(appointDate).getTime();
let ageInMilliseconds = currentDate - appointDateTime;
let ageInDays = ageInMilliseconds / (1000 * 60 * 60 * 24);
let years = Math.floor(ageInDays / 365.25) + plusYear - subtractYear;
return years;
}
public static CalculateAgeStrV2(date: Date, plusYear: number = 0, subtractYear: number = 0) {
if (date == null || date == undefined) return ""
const currentDate = new Date();
if (date > currentDate) {
throw new Error("วันเกิดต้องไม่มากกว่าวันที่ปัจจุบัน");
}
let years = currentDate.getFullYear() - date.getFullYear();
let months = 0;
let days = 0;
if (currentDate.getMonth() < date.getMonth() || (currentDate.getMonth() === date.getMonth() && currentDate.getDate() < date.getDate())) {
years--;
months = 12 - date.getMonth() + currentDate.getMonth();
if (currentDate.getDate() < date.getDate()) {
months--;
let lastMonthDays = 0;
if (currentDate.getMonth() === 0) {
lastMonthDays = new Date(currentDate.getFullYear() - 1, 11, 0).getDate();
}
else {
lastMonthDays = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate();
days = lastMonthDays - date.getDate() + currentDate.getDate();
}
}
else {
days = currentDate.getDate() - date.getDate();
}
}
else {
months = currentDate.getMonth() - date.getMonth();
if (currentDate.getDate() < date.getDate()) {
months--;
let lastMonthDays = 0;
if (currentDate.getMonth() === 0) {
lastMonthDays = new Date(currentDate.getFullYear() - 1, 11, 0).getDate();
}
else {
lastMonthDays = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate();
days = lastMonthDays - date.getDate() + currentDate.getDate();
}
}
else {
days = currentDate.getDate() - date.getDate();
}
}
years += plusYear - subtractYear;
return `${years} ปี ${months} เดือน ${days} วัน`;
}
}
export default Extension;

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableProfileAddDateLeave1717671751714 implements MigrationInterface {
name = 'UpdateTableProfileAddDateLeave1717671751714'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profile\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`);
await queryRunner.query(`ALTER TABLE \`profileHistory\` ADD \`dateLeave\` datetime NULL COMMENT 'วันพ้นราชการ'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`profileHistory\` DROP COLUMN \`dateLeave\``);
await queryRunner.query(`ALTER TABLE \`profile\` DROP COLUMN \`dateLeave\``);
}
}