This commit is contained in:
adisak 2025-09-18 17:08:38 +07:00
parent 489b67945b
commit d58464ce91

View file

@ -1,6 +1,7 @@
import { AppDataSource } from "../database/data-source";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster";
import { OrgRevision } from "../entities/OrgRevision";
import { PosMaster } from "../entities/PosMaster";
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
import { PosMasterEmployeeTempHistory } from "../entities/PosMasterEmployeeTempHistory";
@ -17,6 +18,7 @@ export async function CreatePosMasterHistoryOfficer(
await AppDataSource.transaction(async (manager) => {
const repoPosmaster = manager.getRepository(PosMaster);
const repoHistory = manager.getRepository(PosMasterHistory);
const repoOrgRevision = manager.getRepository(OrgRevision);
const pm = await repoPosmaster.findOne({
where: { id: posMasterId },
@ -31,11 +33,20 @@ export async function CreatePosMasterHistoryOfficer(
"orgChild3",
"orgChild4",
"current_holder",
"next_holder",
],
});
if (!pm) return false;
if (!pm.ancestorDNA) return false;
const checkCurrentRevision = await repoOrgRevision.findOne({
where:{
id: pm.orgRevisionId,
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false
}
})
const _null: any = null;
const h = new PosMasterHistory();
const selectedPosition =
@ -44,9 +55,15 @@ export async function CreatePosMasterHistoryOfficer(
: null;
h.ancestorDNA = pm.ancestorDNA ? pm.ancestorDNA : _null;
if(!type || type != "DELETE"){
h.prefix = pm.current_holder?.prefix || _null;
h.firstName = pm.current_holder?.firstName || _null;
h.lastName = pm.current_holder?.lastName || _null;
if(checkCurrentRevision){
h.prefix = pm.current_holder?.prefix || _null;
h.firstName = pm.current_holder?.firstName || _null;
h.lastName = pm.current_holder?.lastName || _null;
}else{
h.prefix = pm.next_holder?.prefix || _null;
h.firstName = pm.next_holder?.firstName || _null;
h.lastName = pm.next_holder?.lastName || _null;
}
h.position = selectedPosition?.positionName ?? _null;
h.posType = selectedPosition?.posType?.posTypeName ?? _null;
h.posLevel = selectedPosition?.posLevel?.posLevelName ?? _null;