ออกคำสั่ง

This commit is contained in:
kittapath 2024-10-24 10:21:24 +07:00
parent 3f3ec27abd
commit 71a9da67e8
2 changed files with 218 additions and 6 deletions

View file

@ -107,6 +107,7 @@ export class CommandController extends Controller {
@Query() year?: number,
@Query() status?: string | null,
) {
await new permission().PermissionList(request, "COMMAND");
let profilekArray: any = [];
let _profile = await this.profileRepository.findOne({
@ -286,6 +287,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionCreate(request, "COMMAND");
const command = Object.assign(new Command(), requestBody);
const commandType = await this.commandTypeRepository.findOne({
@ -319,7 +321,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab1/{id}")
async GetByIdTab1(@Path() id: string) {
async GetByIdTab1(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType", "commandType.commandTypeSys"],
@ -371,6 +374,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -392,7 +396,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab2/{id}")
async GetByIdTab2(@Path() id: string) {
async GetByIdTab2(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandSalary", "commandRecives"],
@ -443,6 +448,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -468,8 +474,9 @@ export class CommandController extends Controller {
public async swapSalary(
@Path() direction: string,
commandReciveId: string,
@Request() req: RequestWithUser,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const source_item = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
});
@ -525,6 +532,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
});
@ -549,6 +557,7 @@ export class CommandController extends Controller {
*/
@Delete("tab2/{commandReciveId}")
async DeleteTab2(@Path() commandReciveId: string, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "COMMAND");
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
relations: ["command", "command.commandType"],
@ -591,7 +600,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab3/{id}")
async GetByIdTab3(@Path() id: string) {
async GetByIdTab3(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandSends", "commandSends.commandSendCCs"],
@ -630,6 +640,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -697,6 +708,7 @@ export class CommandController extends Controller {
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -743,6 +755,7 @@ export class CommandController extends Controller {
requestBody: { reason?: string | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandSendRepository.findOne({ where: { id: commandSendId } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับสำเนาคำสั่ง");
@ -766,6 +779,7 @@ export class CommandController extends Controller {
requestBody: { commandNo?: string | null; commandYear?: number | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
});
@ -806,6 +820,7 @@ export class CommandController extends Controller {
requestBody: { reason?: string | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -832,6 +847,7 @@ export class CommandController extends Controller {
requestBody: { reason?: string | null },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -853,6 +869,7 @@ export class CommandController extends Controller {
*/
@Delete("{id}")
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives"],
@ -888,7 +905,8 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Get("tab0/{id}")
async GetByIdTab0(@Path() id: string) {
async GetByIdTab0(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
});
@ -921,6 +939,7 @@ export class CommandController extends Controller {
requestBody: { sign: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -948,6 +967,7 @@ export class CommandController extends Controller {
requestBody: { sign: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -975,6 +995,7 @@ export class CommandController extends Controller {
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -1001,6 +1022,7 @@ export class CommandController extends Controller {
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives", "commandSends", "commandSends.commandSendCCs"],
@ -1158,6 +1180,7 @@ export class CommandController extends Controller {
*/
@Get("tab4/cover/{id}")
async GetByIdTab4Cover(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType"],
@ -1231,6 +1254,7 @@ export class CommandController extends Controller {
*/
@Get("tab4/attachment/{id}")
async GetByIdTab4Attachment(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType", "commandRecives"],
@ -2951,4 +2975,192 @@ export class CommandController extends Controller {
await this.posMasterRepository.save(data);
return new HttpSuccess();
}
/**
* API tab0
*
* @summary API tab0
*
* @param {string} id Id
*/
@Get("register-tab0/{id}")
async GetByIdTab0Register(@Path() id: string) {
const command = await this.commandRepository.findOne({
where: { id },
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
const _command = {
id: command.id,
isSignature: command.isSignature,
status: command.status,
isDraft: command.isDraft,
isSign: command.isSign,
isAttachment: command.isAttachment,
};
return new HttpSuccess(_command);
}
/**
* API tab4
*
* @summary API tab4
*
* @param {string} id Id
*/
@Get("register-tab4/cover/{id}")
async GetByIdTab4CoverRegister(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
let issue =
command.isBangkok == "OFFICE"
? "สำนักปลัดกรุงเทพมหานคร"
: command.isBangkok == "BANGKOK"
? "กรุงเทพมหานคร"
: null;
if (issue == null) {
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
relations: ["posMasters", "posMasters.orgRoot"],
});
if (orgRevisionActive != null) {
const profile = await this.profileRepository.findOne({
where: {
keycloak: command.createdUserId.toString(),
},
});
if (profile != null) {
issue =
orgRevisionActive?.posMasters?.filter((x) => x.current_holderId == profile.id)[0]
?.orgRoot?.orgRootName || null;
}
}
}
if (issue == null) issue = "...................................";
const _command = {
issue: issue,
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
commandYear:
command.commandYear == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiYear(command.commandYear).toString()),
commandTitle: command.issue,
detailHeader: command.detailHeader,
detailBody: command.detailBody,
detailFooter: command.detailFooter,
commandDate:
command.commandAffectDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandAffectDate)),
commandExcecuteDate:
command.commandExcecuteDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandExcecuteDate)),
name: "...................................",
position: "...................................",
authorizedUserFullName: "...................................",
authorizedPosition: "...................................",
commandAffectDate: "...................................",
};
return new HttpSuccess({
template: command.commandType.fileCover,
reportName: "docx-report",
data: _command,
});
}
/**
* API tab4
*
* @summary API tab4
*
* @param {string} id Id
*/
@Get("register-tab4/attachment/{id}")
async GetByIdTab4AttachmentRegister(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
let _command: any = [];
const path = commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path + "/attachment", {
refIds: command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
Sequence: x.order,
CitizenId: x.citizenId,
Prefix: x.prefix,
FirstName: x.firstName,
LastName: x.lastName,
Amount: x.amount,
PositionSalaryAmount: x.positionSalaryAmount,
MouthSalaryAmount: x.mouthSalaryAmount,
RemarkHorizontal: x.remarkHorizontal,
RemarkVertical: x.remarkVertical,
CommandYear: command.commandYear,
})),
})
.then(async (res) => {
_command = res;
})
.catch(() => {});
let issue =
command.isBangkok == "OFFICE"
? "สำนักปลัดกรุงเทพมหานคร"
: command.isBangkok == "BANGKOK"
? "กรุงเทพมหานคร"
: null;
if (issue == null) {
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
relations: ["posMasters", "posMasters.orgRoot"],
});
if (orgRevisionActive != null) {
const profile = await this.profileRepository.findOne({
where: {
keycloak: command.createdUserId.toString(),
},
});
if (profile != null) {
issue =
orgRevisionActive?.posMasters?.filter((x) => x.current_holderId == profile.id)[0]
?.orgRoot?.orgRootName || null;
}
}
}
if (issue == null) issue = "...................................";
return new HttpSuccess({
template: command.commandType.fileAttachment,
reportName: "xlsx-report",
data: {
data: _command,
issuerOrganizationName: issue,
commandNo: command.commandNo == null ? "" : Extension.ToThaiNumber(command.commandNo),
commandYear:
command.commandYear == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiYear(command.commandYear).toString()),
commandExcecuteDate:
command.commandExcecuteDate == null
? ""
: Extension.ToThaiNumber(Extension.ToThaiFullDate2(command.commandExcecuteDate)),
},
});
}
}

View file

@ -1228,7 +1228,7 @@ export class ProfileController extends Controller {
*
*
*/
@Post("commander-director")
@Post("commander-director")//page searchxxxxxxxxxxxxxxxxxxxxxxxx
async getProfileCommanderDirector(
@Request() request: RequestWithUser,
@Body() body: { isDirector: boolean },