Schema: - New Company model (name, gstNumber, address, telephone, mobile, email, invoiceAddress, isActive) - PurchaseOrder.companyId FK (optional, SET NULL on company delete) - Migration: 20260530000003_add_company Admin: - /admin/companies page with full CRUD (create, edit, deactivate, delete) - Companies table shows name, GST, contact details, status - Companies link added to Admin section of sidebar (Briefcase icon) PO forms (new / edit / import / manager-edit): - Company dropdown appears at the top of Order Information when companies exist - Pre-populated with first active company; selection persisted to DB via companyId Import form: - parseSheet() now extracts companyName from Excel row 1 (col A) - Import preview auto-matches detected company name against known companies - Shows detected name as a hint; user can override before saving Export (PDF + XLSX): - Company constants (CO_NAME, CO_ADDR, CO_TEL, INV_ADDR, INV_GST) are now derived from the linked Company record when present, falling back to the original Pelagia Marine hardcoded defaults when no company is set Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
34 lines
972 B
TypeScript
34 lines
972 B
TypeScript
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
import { hasPermission } from "@/lib/permissions";
|
|
import { redirect } from "next/navigation";
|
|
import { CompaniesTable } from "./companies-table";
|
|
import type { Metadata } from "next";
|
|
|
|
export const metadata: Metadata = { title: "Company Management" };
|
|
|
|
export default async function AdminCompaniesPage() {
|
|
const session = await auth();
|
|
if (!session?.user) redirect("/login");
|
|
if (!hasPermission(session.user.role, "manage_vessels_accounts")) redirect("/dashboard");
|
|
|
|
const companies = await db.company.findMany({
|
|
orderBy: { name: "asc" },
|
|
});
|
|
|
|
return (
|
|
<CompaniesTable
|
|
companies={companies.map((c) => ({
|
|
id: c.id,
|
|
name: c.name,
|
|
gstNumber: c.gstNumber,
|
|
address: c.address,
|
|
telephone: c.telephone,
|
|
mobile: c.mobile,
|
|
email: c.email,
|
|
invoiceAddress: c.invoiceAddress,
|
|
isActive: c.isActive,
|
|
}))}
|
|
/>
|
|
);
|
|
}
|