pelagia-portal/App/app/(portal)/admin/accounts/page.tsx
Hardik 0d17672ea9 feat(accounts): hierarchical accounting codes with 6-digit format and category tree
- Account model gains parentId (self-referential, 3 levels: TopCategory → SubCategory → Item)
- DB migration: adds parentId FK column to Account table
- Code format changed from PREFIX-NNN to 6-digit numeric (e.g. 100101)
- Seeded all 300+ accounting codes from the official chart (Rev. 01/251227) across
  7 top categories: Capital Expenses, Business Development, Office Admin, Project
  Expenses, Manning, Technical, Bunker/Lubes
- Admin Accounting Code page: collapsible tree view (top category > sub-category > items),
  inline search, Add/Edit dialogs with parent selector and 6-digit code field
- All PO forms (new, edit, import, manager-edit): accounting code dropdown now shows
  only leaf items grouped in <optgroup> by sub-category, labelled "TopCat › SubCat"
- Seed data updated: old flat account codes replaced by mapped leaf codes from new hierarchy

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-30 03:27:31 +05:30

37 lines
1.2 KiB
TypeScript

import { auth } from "@/auth";
import { db } from "@/lib/db";
import { hasPermission } from "@/lib/permissions";
import { redirect } from "next/navigation";
import { AccountsTable } from "./accounts-table";
import type { Metadata } from "next";
export const metadata: Metadata = { title: "Accounting Code Management" };
export default async function AdminAccountsPage() {
const session = await auth();
if (!session?.user) redirect("/login");
if (!hasPermission(session.user.role, "manage_vessels_accounts")) redirect("/dashboard");
// Fetch full tree: top-level categories with sub-categories and their items
const topCategories = await db.account.findMany({
where: { parentId: null },
orderBy: { code: "asc" },
include: {
children: {
orderBy: { code: "asc" },
include: {
children: { orderBy: { code: "asc" } },
},
},
},
});
// Flat list of all accounts for the parent selector in forms
const allAccounts = await db.account.findMany({
orderBy: { code: "asc" },
select: { id: true, code: true, name: true, parentId: true },
});
return <AccountsTable topCategories={topCategories} allAccounts={allAccounts} />;
}