#2427 and migration

This commit is contained in:
adisak 2026-04-20 08:05:16 +07:00
parent 7f3408e2f5
commit 28b5408d5b
6 changed files with 159 additions and 5 deletions

View file

@ -68,3 +68,42 @@ export function filterPosMasters(
): PosMaster[] {
return posMasters.filter((x) => x[childLevelIdKey] == null && x.isDirector === true);
}
/**
* orgShortName posMaster ( load org relations )
*/
export function getOrgShortName(posMaster: PosMaster): string {
if (posMaster.orgChild1Id === null) {
return posMaster.orgRoot?.orgRootShortName ?? "";
} else if (posMaster.orgChild2Id === null) {
return posMaster.orgChild1?.orgChild1ShortName ?? "";
} else if (posMaster.orgChild3Id === null) {
return posMaster.orgChild2?.orgChild2ShortName ?? "";
} else if (posMaster.orgChild4Id === null) {
return posMaster.orgChild3?.orgChild3ShortName ?? "";
} else {
return posMaster.orgChild4?.orgChild4ShortName ?? "";
}
}
/**
* posMaster (join \n)
*/
export function getOrgFullName(posMaster: PosMaster): string {
const parts = [
posMaster.orgChild4?.orgChild4Name,
posMaster.orgChild3?.orgChild3Name,
posMaster.orgChild2?.orgChild2Name,
posMaster.orgChild1?.orgChild1Name,
posMaster.orgRoot?.orgRootName,
];
return parts.filter((part) => part !== undefined && part !== null).join("\n");
}
/**
* "กทม. 1234"
*/
export function getPosMasterNo(posMaster: PosMaster): string {
const orgShortName = getOrgShortName(posMaster);
return `${orgShortName} ${posMaster.posMasterNo}`;
}