add function leave/{id} with profile/salary

This commit is contained in:
AdisakKanthawilang 2024-06-18 15:43:25 +07:00
parent e2d5f7e13d
commit 2a4c3e745f

View file

@ -47,10 +47,11 @@ import { ProfileCertificate } from "../entities/ProfileCertificate";
import { ProfileTraining } from "../entities/ProfileTraining";
import { ProfileDiscipline } from "../entities/ProfileDiscipline";
import { ProfileEducation } from "../entities/ProfileEducation";
import { ProfileSalary } from "../entities/ProfileSalary";
import { CreateProfileSalary, ProfileSalary } from "../entities/ProfileSalary";
import { ProfileFamilyCouple } from "../entities/ProfileFamilyCouple";
import { ProfileFamilyMother } from "../entities/ProfileFamilyMother";
import { ProfileFamilyFather } from "../entities/ProfileFamilyFather";
import CallAPI from "../interfaces/call-api";
import Extension from "../interfaces/extension";
@Route("api/v1/org/profile")
@ -460,7 +461,9 @@ export class ProfileController extends Controller {
});
const Salary = salarys.map((item) => ({
SalaryDate: item.date ? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.date)) : null,
SalaryDate: item.date
? Extension.ToThaiNumber(Extension.ToThaiShortDate_noPrefix(item.date))
: null,
Position: item.position ?? null,
PosNo: item.posNo ?? null,
Salary: item.amount ?? null,
@ -754,16 +757,17 @@ export class ProfileController extends Controller {
@Post("command11/{profileId}")
async ExecuteCommand11Async(
@Request() req: RequestWithUser,
@Body() body: {
profileId: string,
date: Date | null,
refCommandNo: string | null,
salaryRef: string | null
}
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ['profileSalary'],
where: { id: body.profileId }
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
@ -771,7 +775,7 @@ export class ProfileController extends Controller {
// const posType = await this.posTypeRepo.findOneBy({ id: String(profile.posTypeId) })
// const posLevel = await this.posLevelRepo.findOneBy({ id: String(profile.posLevelId) })
if(profile.isProbation != false) {
if (profile.isProbation != false) {
profile.isProbation = false;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
@ -781,36 +785,48 @@ export class ProfileController extends Controller {
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
position: profile.position,
positionType: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionType
: null,
positionLevel: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionLevel
: null,
posNo: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].posNo
: null,
positionLine: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionLine
: null,
positionPathSide: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionPathSide
: null,
positionExecutive: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionExecutive
: null,
amount: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].amount
: null,
positionSalaryAmount: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionSalaryAmount
: null,
mouthSalaryAmount: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].mouthSalaryAmount
: null,
order: profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary[profile.profileSalary.length-1].order + 1 : 1
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
@ -823,7 +839,7 @@ export class ProfileController extends Controller {
}
return new HttpSuccess();
}
/**
* API
*
@ -833,23 +849,25 @@ export class ProfileController extends Controller {
@Post("command12/{profileId}")
async ExecuteCommand12Async(
@Request() req: RequestWithUser,
@Body() body: {
profileId: string,
date: Date | null,
refCommandNo: string | null,
salaryRef: string | null
}
@Body()
body: {
profileId: string;
date: Date | null;
refCommandNo: string | null;
salaryRef: string | null;
},
) {
const profile = await this.profileRepo.findOne({
relations: ['profileSalary'],
where: { id: body.profileId }
relations: ["profileSalary"],
where: { id: body.profileId },
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
let dateLeave_: any = body.date
let dateLeave_: any = body.date;
profile.isLeave = true;
profile.leaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
profile.leaveReason =
"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด";
profile.dateLeave = dateLeave_;
profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name;
@ -859,45 +877,54 @@ export class ProfileController extends Controller {
refCommandNo: body.refCommandNo,
templateDoc: body.salaryRef,
position: profile.position,
positionType: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionType
: null,
positionLevel: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionLevel
: null,
posNo: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].posNo
: null,
positionLine: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionLine
: null,
positionPathSide: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionPathSide
: null,
positionExecutive: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionExecutive
: null,
amount: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].amount
: null,
positionSalaryAmount: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].positionSalaryAmount
: null,
mouthSalaryAmount: profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length-1].mouthSalaryAmount
: null,
order: profile.profileSalary.length >= 0
? profile.profileSalary.length > 0 ? profile.profileSalary[profile.profileSalary.length-1].order + 1 : 1
: null,
positionType:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionType
: null,
positionLevel:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLevel
: null,
posNo:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].posNo
: null,
positionLine:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionLine
: null,
positionPathSide:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionPathSide
: null,
positionExecutive:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionExecutive
: null,
amount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].amount
: null,
positionSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].positionSalaryAmount
: null,
mouthSalaryAmount:
profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].mouthSalaryAmount
: null,
order:
profile.profileSalary.length >= 0
? profile.profileSalary.length > 0
? profile.profileSalary[profile.profileSalary.length - 1].order + 1
: 1
: null,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
lastUpdateFullName: req.user.name,
});
await Promise.all([
this.profileRepo.save(profile),
this.salaryRepository.save(profileSalary),
]);
await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]);
return new HttpSuccess();
}
@ -3283,6 +3310,7 @@ export class ProfileController extends Controller {
@Path() id: string,
@Body()
requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date },
@Request() request: { user: Record<string, any> },
) {
const profile = await this.profileRepo.findOne({
where: { id: id },
@ -3293,6 +3321,29 @@ export class ProfileController extends Controller {
profile.leaveReason = requestBody.leaveReason;
profile.dateLeave = requestBody.dateLeave;
await this.profileRepo.save(profile);
const profileSalary = await this.salaryRepository.findOne({
where: { profileId: id },
order: { createdAt: "DESC" },
});
await new CallAPI().PostData(request, "org/profile/salary", {
profileId: profile.id,
date: requestBody.dateLeave,
amount: profileSalary?.amount,
positionSalaryAmount: profileSalary?.positionSalaryAmount,
mouthSalaryAmount: profileSalary?.mouthSalaryAmount,
posNo: profileSalary?.posNo,
position: profileSalary?.position,
positionLine: profileSalary?.positionLine,
positionPathSide: profileSalary?.positionPathSide,
positionExecutive: profileSalary?.positionExecutive,
positionType: profileSalary?.positionType,
positionLevel: profileSalary?.positionLevel,
refCommandNo: null,
templateDoc: requestBody.leaveReason,
});
return new HttpSuccess();
}