no message

This commit is contained in:
kittapath 2025-01-30 13:48:23 +07:00
parent a796deb763
commit ca9e79d1a4

View file

@ -1853,7 +1853,7 @@ export class CommandController extends Controller {
) {
let command = new Command();
let commandCode: string = "";
let null_: any = null;
let _null: any = null;
if (
requestBody.commandId != undefined &&
requestBody.commandId != null &&
@ -1895,10 +1895,10 @@ export class CommandController extends Controller {
command.issue = commandType.name;
(command.commandAffectDate = requestBody.commandAffectDate
? new Date(requestBody.commandAffectDate)
: null_),
: _null),
(command.commandExcecuteDate = requestBody.commandExcecuteDate
? new Date(requestBody.commandExcecuteDate)
: null_),
: _null),
(command.createdUserId = request.user.sub);
command.createdFullName = request.user.name;
command.createdAt = new Date();
@ -1932,7 +1932,7 @@ export class CommandController extends Controller {
let commandRecive = new CommandRecive();
commandRecive = Object.assign(new CommandRecive(), item);
commandRecive.order = order;
let salaryData = null_;
let salaryData = _null;
// const excludedCommands = ["C-PM-33", "C-PM-34", "C-PM-35", "C-PM-36", "C-PM-37"];
// if (!excludedCommands.includes(commandCode)) {
@ -1942,7 +1942,7 @@ export class CommandController extends Controller {
id: item.profileId,
},
});
let null_: any = 0;
let _setZero: any = 0;
if (!salaryData) {
salaryData = await this.profileEmployeeRepository.findOne({
where: {
@ -1950,30 +1950,25 @@ export class CommandController extends Controller {
},
});
}
commandRecive.amount = item.amount ?? (salaryData ? salaryData.amount : null_);
commandRecive.amount = item.amount ?? (salaryData ? salaryData.amount : _setZero);
commandRecive.amountSpecial =
item.amountSpecial ?? (salaryData ? salaryData.amountSpecial : null_);
item.amountSpecial ?? (salaryData ? salaryData.amountSpecial : _setZero);
commandRecive.positionSalaryAmount =
item.positionSalaryAmount ?? (salaryData ? salaryData.positionSalaryAmount : null_);
item.positionSalaryAmount ??
(salaryData ? salaryData.positionSalaryAmount : _setZero);
commandRecive.mouthSalaryAmount =
item.mouthSalaryAmount ?? (salaryData ? salaryData.mouthSalaryAmount : null_);
item.mouthSalaryAmount ?? (salaryData ? salaryData.mouthSalaryAmount : _setZero);
} else {
commandRecive.amount = null_;
commandRecive.amountSpecial = null_;
commandRecive.positionSalaryAmount = null_;
commandRecive.mouthSalaryAmount = null_;
commandRecive.amount = _null;
commandRecive.amountSpecial = _null;
commandRecive.positionSalaryAmount = _null;
commandRecive.mouthSalaryAmount = _null;
}
// } else {
// commandRecive.amount = item.amount ?? null_;
// commandRecive.amountSpecial = item.amountSpecial ?? null_;
// commandRecive.positionSalaryAmount = item.positionSalaryAmount ?? null_;
// commandRecive.mouthSalaryAmount = item.mouthSalaryAmount ?? null_;
// }
commandRecive.remarkVertical =
item.remarkVertical == null ? null_ : item.remarkVertical;
item.remarkVertical == null ? _null : item.remarkVertical;
commandRecive.remarkHorizontal =
item.remarkHorizontal == null ? null_ : item.remarkHorizontal;
item.remarkHorizontal == null ? _null : item.remarkHorizontal;
commandRecive.order = order;
commandRecive.commandId = command.id;
commandRecive.createdUserId = request.user.sub;
@ -1987,129 +1982,70 @@ export class CommandController extends Controller {
);
})
.catch(() => {});
if (requestBody.persons != undefined && requestBody.persons.length > 0) {
let posMaster: any;
if (["C-PM-36", "C-PM-37"].includes(commandCode)) {
posMaster = await this.employeePosMasterRepository.find({
where: {
current_holderId: In(requestBody.persons.map((x) => x.profileId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
select: ["orgRootId"],
});
} else {
var posMasterOfficer = await this.posMasterRepository.find({
where: {
current_holderId: In(requestBody.persons.map((x) => x.profileId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
select: ["orgRootId"],
});
var posMasterEmployee = await this.employeePosMasterRepository.find({
where: {
current_holderId: In(requestBody.persons.map((x) => x.profileId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
select: ["orgRootId"],
});
posMaster = [...posMasterOfficer, ...posMasterEmployee];
}
let _posMaster: any;
if (["C-PM-38", "C-PM-40"].includes(commandCode)) {
_posMaster = await this.posMasterRepository.find({
where: {
orgRootId: In(posMaster.map((x: any) => x.orgRootId)),
orgChild1: IsNull(),
orgChild2: IsNull(),
orgChild3: IsNull(),
orgChild4: IsNull(),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
} else {
_posMaster = await this.posMasterRepository.find({
where: {
orgRootId: In(posMaster.map((x: any) => x.orgRootId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
}
await Promise.all(
_posMaster.map(async (item: any) => {
const _commandSend = await this.commandSendRepository.findOne({
if (!["C-PM-10"].includes(commandCode)) {
if (requestBody.persons != undefined && requestBody.persons.length > 0) {
let posMaster: any;
if (["C-PM-36", "C-PM-37"].includes(commandCode)) {
posMaster = await this.employeePosMasterRepository.find({
where: {
commandId: command.id,
profileId: item.current_holder.id,
current_holderId: In(requestBody.persons.map((x) => x.profileId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
select: ["orgRootId"],
});
if (_commandSend) return;
let commandSend = new CommandSend();
commandSend.citizenId = item.current_holder.citizenId;
commandSend.prefix = item.current_holder.prefix;
commandSend.firstName = item.current_holder.firstName;
commandSend.lastName = item.current_holder.lastName;
commandSend.position = item.current_holder.position;
commandSend.org = item.orgRoot.orgRootName;
commandSend.profileId = item.current_holder.id;
commandSend.commandId = command.id;
commandSend.createdUserId = request.user.sub;
commandSend.createdFullName = request.user.name;
commandSend.createdAt = new Date();
commandSend.lastUpdateUserId = request.user.sub;
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
createdUserId: request.user.sub,
createdFullName: request.user.name,
createdAt: new Date(),
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
});
}
await this.commandSendCCRepository.save(_dataSendCC);
}
}),
);
const _posMasterNext = await this.posMasterRepository.find({
where: {
orgRootId: In(
requestBody.persons
.filter((x) => x.rootId != undefined && x.rootId != null && x.rootId != "")
.map((x) => x.rootId),
),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
await Promise.all(
_posMasterNext.map(async (item) => {
const _commandSend = await this.commandSendRepository.findOne({
} else {
var posMasterOfficer = await this.posMasterRepository.find({
where: {
commandId: command.id,
profileId: item.current_holder.id,
current_holderId: In(requestBody.persons.map((x) => x.profileId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
select: ["orgRootId"],
});
// if (_commandSend) return;
if (!_commandSend) {
var posMasterEmployee = await this.employeePosMasterRepository.find({
where: {
current_holderId: In(requestBody.persons.map((x) => x.profileId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
},
select: ["orgRootId"],
});
posMaster = [...posMasterOfficer, ...posMasterEmployee];
}
let _posMaster: any;
if (["C-PM-38", "C-PM-40"].includes(commandCode)) {
_posMaster = await this.posMasterRepository.find({
where: {
orgRootId: In(posMaster.map((x: any) => x.orgRootId)),
orgChild1: IsNull(),
orgChild2: IsNull(),
orgChild3: IsNull(),
orgChild4: IsNull(),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
} else {
_posMaster = await this.posMasterRepository.find({
where: {
orgRootId: In(posMaster.map((x: any) => x.orgRootId)),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
}
await Promise.all(
_posMaster.map(async (item: any) => {
const _commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: item.current_holder.id,
},
});
if (_commandSend) return;
let commandSend = new CommandSend();
commandSend.citizenId = item.current_holder.citizenId;
commandSend.prefix = item.current_holder.prefix;
@ -2143,9 +2079,69 @@ export class CommandController extends Controller {
}
await this.commandSendCCRepository.save(_dataSendCC);
}
}
}),
);
}),
);
const _posMasterNext = await this.posMasterRepository.find({
where: {
orgRootId: In(
requestBody.persons
.filter((x) => x.rootId != undefined && x.rootId != null && x.rootId != "")
.map((x) => x.rootId),
),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
isDirector: true,
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot"],
});
await Promise.all(
_posMasterNext.map(async (item) => {
const _commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: item.current_holder.id,
},
});
// if (_commandSend) return;
if (!_commandSend) {
let commandSend = new CommandSend();
commandSend.citizenId = item.current_holder.citizenId;
commandSend.prefix = item.current_holder.prefix;
commandSend.firstName = item.current_holder.firstName;
commandSend.lastName = item.current_holder.lastName;
commandSend.position = item.current_holder.position;
commandSend.org = item.orgRoot.orgRootName;
commandSend.profileId = item.current_holder.id;
commandSend.commandId = command.id;
commandSend.createdUserId = request.user.sub;
commandSend.createdFullName = request.user.name;
commandSend.createdAt = new Date();
commandSend.lastUpdateUserId = request.user.sub;
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
createdUserId: request.user.sub,
createdFullName: request.user.name,
createdAt: new Date(),
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
});
}
await this.commandSendCCRepository.save(_dataSendCC);
}
}
}),
);
}
if (["C-PM-10"].includes(commandCode)) {
await Promise.all(
@ -2161,7 +2157,7 @@ export class CommandController extends Controller {
const _commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: item.profileId ?? null_,
profileId: item.profileId ?? _null,
},
});
if (!_commandSend) {
@ -2170,14 +2166,11 @@ export class CommandController extends Controller {
commandSend.prefix = item.prefix;
commandSend.firstName = item.firstName;
commandSend.lastName = item.lastName;
commandSend.position =
_posMasterDirector && _posMasterDirector.positions.length > 0
? _posMasterDirector.positions[0].positionName
: null_;
commandSend.position = _posMasterDirector?.current_holder.position ?? _null;
commandSend.org =
_posMasterDirector && _posMasterDirector.orgRoot
? _posMasterDirector.orgRoot.orgRootName
: null_;
: _null;
commandSend.profileId = item.profileId;
commandSend.commandId = command.id;
commandSend.createdUserId = request.user.sub;
@ -2208,6 +2201,196 @@ export class CommandController extends Controller {
}),
);
}
if (
[
"C-PM-01",
"C-PM-02",
"C-PM-03",
"C-PM-04",
"C-PM-05",
"C-PM-07",
"C-PM-08",
"C-PM-09",
"C-PM-13",
"C-PM-14",
"C-PM-15",
"C-PM-16",
"C-PM-21",
"C-PM-22",
"C-PM-24",
"C-PM-39",
].includes(commandCode)
) {
const _posMasterCommission = await this.posMasterRepository.findOne({
where: {
orgRoot: {
isCommission: true,
},
isDirector: true,
orgChild1: IsNull(),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot", "positions"],
});
let _commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: _posMasterCommission?.current_holder.id ?? _null,
},
});
if (!_commandSend && _posMasterCommission != null) {
let commandSend = new CommandSend();
commandSend.citizenId = _posMasterCommission?.current_holder.citizenId ?? _null;
commandSend.prefix = _posMasterCommission?.current_holder.prefix ?? _null;
commandSend.firstName = _posMasterCommission?.current_holder.firstName ?? _null;
commandSend.lastName = _posMasterCommission?.current_holder.lastName ?? _null;
commandSend.position = _posMasterCommission?.current_holder.position ?? _null;
commandSend.org =
_posMasterCommission && _posMasterCommission.orgRoot
? _posMasterCommission.orgRoot.orgRootName
: _null;
commandSend.profileId = _posMasterCommission?.current_holderId ?? _null;
commandSend.commandId = command.id;
commandSend.createdUserId = request.user.sub;
commandSend.createdFullName = request.user.name;
commandSend.createdAt = new Date();
commandSend.lastUpdateUserId = request.user.sub;
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
createdUserId: request.user.sub,
createdFullName: request.user.name,
createdAt: new Date(),
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
});
}
await this.commandSendCCRepository.save(_dataSendCC);
}
}
const _posMasterInformation = await this.posMasterRepository.findOne({
where: {
orgChild1: {
isInformation: true,
},
isDirector: true,
orgChild2: IsNull(),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot", "positions"],
});
_commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: _posMasterInformation?.current_holder.id ?? _null,
},
});
if (!_commandSend && _posMasterInformation != null) {
let commandSend = new CommandSend();
commandSend.citizenId = _posMasterInformation?.current_holder.citizenId ?? _null;
commandSend.prefix = _posMasterInformation?.current_holder.prefix ?? _null;
commandSend.firstName = _posMasterInformation?.current_holder.firstName ?? _null;
commandSend.lastName = _posMasterInformation?.current_holder.lastName ?? _null;
commandSend.position = _posMasterInformation?.current_holder.position ?? _null;
commandSend.org =
_posMasterInformation && _posMasterInformation.orgRoot
? _posMasterInformation.orgRoot.orgRootName
: _null;
commandSend.profileId = _posMasterInformation?.current_holderId ?? _null;
commandSend.commandId = command.id;
commandSend.createdUserId = request.user.sub;
commandSend.createdFullName = request.user.name;
commandSend.createdAt = new Date();
commandSend.lastUpdateUserId = request.user.sub;
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
createdUserId: request.user.sub,
createdFullName: request.user.name,
createdAt: new Date(),
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
});
}
await this.commandSendCCRepository.save(_dataSendCC);
}
}
const _posMasterOfficer = await this.posMasterRepository.findOne({
where: {
orgChild1: {
isOfficer: true,
},
isDirector: true,
orgChild2: IsNull(),
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
current_holderId: Not(IsNull()),
},
relations: ["current_holder", "orgRoot", "positions"],
});
_commandSend = await this.commandSendRepository.findOne({
where: {
commandId: command.id,
profileId: _posMasterOfficer?.current_holder.id ?? _null,
},
});
if (!_commandSend && _posMasterOfficer != null) {
let commandSend = new CommandSend();
commandSend.citizenId = _posMasterOfficer?.current_holder.citizenId ?? _null;
commandSend.prefix = _posMasterOfficer?.current_holder.prefix ?? _null;
commandSend.firstName = _posMasterOfficer?.current_holder.firstName ?? _null;
commandSend.lastName = _posMasterOfficer?.current_holder.lastName ?? _null;
commandSend.position = _posMasterOfficer?.current_holder.position ?? _null;
commandSend.org =
_posMasterOfficer && _posMasterOfficer.orgRoot
? _posMasterOfficer.orgRoot.orgRootName
: _null;
commandSend.profileId = _posMasterOfficer?.current_holderId ?? _null;
commandSend.commandId = command.id;
commandSend.createdUserId = request.user.sub;
commandSend.createdFullName = request.user.name;
commandSend.createdAt = new Date();
commandSend.lastUpdateUserId = request.user.sub;
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
createdUserId: request.user.sub,
createdFullName: request.user.name,
createdAt: new Date(),
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
});
}
await this.commandSendCCRepository.save(_dataSendCC);
}
}
}
}
return new HttpSuccess(command.id);
}
@ -2596,7 +2779,7 @@ export class CommandController extends Controller {
if (item.isGovernment == true) {
const returnWork = await checkReturnCommandType(String(item.commandId));
if (returnWork) {
profile.leaveReason = _null;
profile.leaveReason = _null;
profile.leaveCommandId = _null;
profile.leaveCommandNo = _null;
profile.leaveRemark = _null;
@ -3133,7 +3316,7 @@ export class CommandController extends Controller {
if (item.isLeave == true) {
await removeProfileInOrganize(_profile.id, "OFFICER");
const exceptClear = await checkExceptCommandType(String(item.commandId));
if(exceptClear.status){
if (exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = item.refCommandNo ?? _null;
@ -3324,7 +3507,7 @@ export class CommandController extends Controller {
if (item.isLeave == true) {
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
const exceptClear = await checkExceptCommandType(String(item.commandId));
if(exceptClear.status) {
if (exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = item.refCommandNo ?? _null;
@ -3551,7 +3734,7 @@ export class CommandController extends Controller {
if (item.isLeave == true) {
await removeProfileInOrganize(_profile.id, "EMPLOYEE");
const exceptClear = await checkExceptCommandType(String(item.commandId));
if(exceptClear.status) {
if (exceptClear.status) {
_profile.leaveReason = item.leaveReason ?? _null;
_profile.leaveCommandId = item.commandId ?? _null;
_profile.leaveCommandNo = item.refCommandNo ?? _null;
@ -3945,7 +4128,7 @@ export class CommandController extends Controller {
const roleKeycloak = await this.roleKeycloakRepo.findOne({
where: { name: Like("USER") },
});
const null_: any = null;
const _null: any = null;
await Promise.all(
body.data.map(async (item) => {
const before = null;
@ -4027,32 +4210,32 @@ export class CommandController extends Controller {
});
profile.registrationProvinceId = registrationProvinceId
? registrationProvinceId.id
: null_;
: _null;
let registrationDistrictId = await this.districtRepo.findOneBy({
id: profile.registrationDistrictId,
});
profile.registrationDistrictId = registrationDistrictId
? registrationDistrictId.id
: null_;
: _null;
let registrationSubDistrictId = await this.subDistrictRepo.findOneBy({
id: profile.registrationSubDistrictId,
});
profile.registrationSubDistrictId = registrationSubDistrictId
? registrationSubDistrictId.id
: null_;
: _null;
let currentProvinceId = await this.provinceRepo.findOneBy({
id: profile.currentProvinceId,
});
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : null_;
profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : _null;
let currentDistrictId = await this.districtRepo.findOneBy({
id: profile.currentDistrictId,
});
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : null_;
profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : _null;
let currentSubDistrictId = await this.subDistrictRepo.findOneBy({
id: profile.currentSubDistrictId,
});
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : null_;
profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : _null;
profile.email = item.bodyProfile.email;
profile.dateStart = item.bodyProfile.dateStart;
profile.amount = item.bodyProfile.amount ?? null;