import { PosMaster } from "../entities/PosMaster"; export interface PosMasterFormatted { posmasterId: string; posNo: string; orgTreeId: string; orgLevel: number; fullNameCurrentHolder: string | null; } export interface OrgTreeNode { orgTreeId: string; orgLevel: number; orgName: string; orgTreeName: string; orgTreeShortName: string; orgTreeCode: string; orgCode: string; orgRootName: string; labelName: string; posMaster: PosMasterFormatted[]; children?: OrgTreeNode[]; } export function formatPosMaster( posMaster: PosMaster, orgShortName: string, orgTreeId: string, orgLevel: number, ): PosMasterFormatted { return { posmasterId: posMaster.id, posNo: `${orgShortName} ${posMaster.posMasterNo}`, orgTreeId, orgLevel, fullNameCurrentHolder: posMaster.current_holder ? `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}` : null, }; } export function generateLabelName( nodeName: string, nodeCode: string, nodeShortName: string, rootName: string, rootCode: string, rootShortName: string, parentNames?: string[], parentCodes?: string[], parentShortNames?: string[], ): string { const parts = [nodeName, " ", rootCode, nodeCode, " ", nodeShortName]; if (parentNames) { for (let i = 0; i < parentNames.length; i++) { parts.push("/", parentNames[i], " ", rootCode, parentCodes![i], " ", parentShortNames![i]); } } parts.push("/", rootName, " ", rootCode, "00", " ", rootShortName); return parts.join(""); } export function filterPosMasters( posMasters: PosMaster[], childLevelIdKey: keyof PosMaster, ): PosMaster[] { return posMasters.filter((x) => x[childLevelIdKey] == null && x.isDirector === true); }