pelagia-portal/App/app/(portal)/payments/page.tsx
Hardik cc7251e6b7 feat: Cost Centre covers vessels and sites, vessel codes, Accounting Code rename, vessel-site assignment
- Undo Vessel→Cost Centre rename in admin (admin shows "Vessel Management" again)
- Sidebar: "Cost Centres"→"Vessels", "Accounts"→"Accounting Codes"
- PO forms (new/edit/import/manager-edit) now show both Vessels (with code) and Sites in the
  Cost Centre dropdown, encoded as v:<id> / s:<id> via a costCentreRef field
- vesselId on PurchaseOrder is now nullable; siteId is set when a site is the cost centre
- History, approvals, dashboard, my-orders, payments display vessel.name ?? site.name as Cost Centre
- History and approvals cost centre filters use costCentreRef URL param supporting both types
- Admin vessel form: adds Site assignment dropdown
- Admin accounts: renamed to "Accounting Code" throughout (pages, forms, sidebar)
- PO detail and exports: "Account" label renamed to "Accounting Code"
- Site detail: "Assigned Vessels (Cost Centres)" heading; vessel detail breadcrumb fixed
- Create PO links from vessel/site detail use ?costCentreRef= param
- Export routes handle costCentreRef filter param (with legacy vesselId fallback)
- DB migration: ALTER TABLE PurchaseOrder ALTER COLUMN vesselId DROP NOT NULL
- CLAUDE.md updated with Cost Centre Model documentation

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

115 lines
5 KiB
TypeScript

import { auth } from "@/auth";
import { db } from "@/lib/db";
import { hasPermission } from "@/lib/permissions";
import { redirect } from "next/navigation";
import Link from "next/link";
import { formatCurrency, formatDate, PO_STATUS_LABELS } from "@/lib/utils";
import { PaymentActions } from "./payment-actions";
import type { Metadata } from "next";
export const metadata: Metadata = { title: "Payments" };
export default async function PaymentsPage() {
const session = await auth();
if (!session?.user) redirect("/login");
if (!hasPermission(session.user.role, "process_payment")) redirect("/dashboard");
const queue = await db.purchaseOrder.findMany({
where: { status: { in: ["MGR_APPROVED", "SENT_FOR_PAYMENT", "PARTIALLY_PAID", "PARTIALLY_CLOSED"] } },
include: { submitter: true, vessel: true, site: { select: { name: true } }, account: true, vendor: true },
orderBy: { approvedAt: "asc" },
});
return (
<div>
<div className="mb-6">
<h1 className="text-2xl font-semibold text-neutral-900">Payment Queue</h1>
<p className="mt-1 text-sm text-neutral-500">
{queue.length} order{queue.length !== 1 ? "s" : ""} in the payment pipeline
</p>
</div>
{queue.length === 0 ? (
<div className="rounded-lg border border-neutral-200 bg-white p-12 text-center">
<p className="text-neutral-500">No orders in the payment queue.</p>
</div>
) : (
<div className="space-y-4">
{queue.map((po) => (
<div key={po.id} className="rounded-lg border border-neutral-200 bg-white p-5">
<div className="flex items-start justify-between gap-4">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-1">
<span className="font-mono text-xs text-neutral-500">{po.poNumber}</span>
</div>
<h3 className="font-medium text-neutral-900 truncate">{po.title}</h3>
<div className="mt-1 flex flex-wrap gap-3 text-sm text-neutral-500">
<span>{po.vessel?.name ?? po.site?.name ?? "—"}</span>
<span>·</span>
<span>{po.submitter.name}</span>
{po.vendor && (
<>
<span>·</span>
<span>{po.vendor.name}</span>
</>
)}
{po.approvedAt && (
<>
<span>·</span>
<span>Approved {formatDate(po.approvedAt)}</span>
</>
)}
</div>
</div>
<div className="text-right shrink-0">
<div className="text-lg font-semibold text-neutral-900 font-mono">
{formatCurrency(Number(po.totalAmount), po.currency)}
</div>
<Link
href={`/po/${po.id}`}
className="text-xs text-neutral-400 hover:text-primary-600"
>
View PO
</Link>
</div>
</div>
<div className="mt-4 border-t border-neutral-100 pt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3">
<div className="flex flex-col gap-1">
<span className={`text-xs font-medium rounded-full px-2.5 py-0.5 self-start ${
po.status === "SENT_FOR_PAYMENT"
? "bg-primary-50 text-primary-700"
: po.status === "PARTIALLY_PAID"
? "bg-warning-50 text-warning-700"
: po.status === "PARTIALLY_CLOSED"
? "bg-warning-50 text-warning-700"
: "bg-warning-50 text-warning-700"
}`}>
{po.status === "SENT_FOR_PAYMENT"
? "Processing — awaiting confirmation"
: po.status === "PARTIALLY_PAID"
? "Partially paid — additional payment needed"
: po.status === "PARTIALLY_CLOSED"
? "Partially received — awaiting more payments"
: "Ready for payment"}
</span>
{(po.status === "PARTIALLY_PAID" || po.status === "PARTIALLY_CLOSED") && po.paidAmount != null && (
<span className="text-xs text-neutral-500">
Paid {formatCurrency(Number(po.paidAmount), po.currency)} of {formatCurrency(Number(po.totalAmount), po.currency)}
</span>
)}
</div>
<PaymentActions
poId={po.id}
poStatus={po.status}
totalAmount={Number(po.totalAmount)}
paidAmount={po.paidAmount != null ? Number(po.paidAmount) : 0}
/>
</div>
</div>
))}
</div>
)}
</div>
);
}