Cost Centre on PO forms now shows only Vessels (plain vesselId field). Sites are a separate concept and not selectable as cost centres. - PurchaseOrder.vesselId is required again (NOT NULL restored) - Vessel.siteId and vessel->site relation removed from schema - DB migration: drops Vessel.siteId column, restores PO.vesselId NOT NULL - All PO forms (new/edit/import/manager-edit): plain vessel <select> with code-prefixed labels (e.g. "HNR1 — HNR 1") - History, approvals, dashboard, my-orders, payments: back to vesselId filter params and po.vessel.name display - Admin vessels: removed Site column and site-assignment dropdown - Admin sites detail page: removed "Assigned Vessels" section - Sites table: removed Vessels count column (no longer linked) - seed-prod.ts and seed.ts: vessels created without siteId - SearchableSelect accounting code picker retained from previous commit Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
22 lines
876 B
TypeScript
22 lines
876 B
TypeScript
/**
|
||
* Builds grouped accounting codes for the SearchableSelect component.
|
||
* Only returns leaf items (no children), grouped by sub-category.
|
||
*/
|
||
export function buildAccountGroups(
|
||
leafAccounts: {
|
||
id: string;
|
||
code: string;
|
||
name: string;
|
||
parent: { name: string; code: string; parent: { name: string; code: string } | null } | null;
|
||
}[]
|
||
) {
|
||
const map = new Map<string, { id: string; code: string; name: string }[]>();
|
||
for (const a of leafAccounts) {
|
||
const subLabel = a.parent ? `${a.parent.code} — ${a.parent.name}` : "Uncategorised";
|
||
const topLabel = a.parent?.parent ? `${a.parent.parent.name} › ` : "";
|
||
const key = `${topLabel}${subLabel}`;
|
||
if (!map.has(key)) map.set(key, []);
|
||
map.get(key)!.push({ id: a.id, code: a.code, name: a.name });
|
||
}
|
||
return Array.from(map.entries()).map(([group, items]) => ({ group, items }));
|
||
}
|