- Supplier invoices on purchase orders (several per PO), global Upload invoice with search and drag-drop - PO invoice status line (red/orange/teal), week/month filter, group by supplier, drag-drop PO upload - Suppliers 2: spend, payable by terms, cash hidden by default, manual payments with surplus/shortfall - Fix multi-page PO parsing (per-page rows, header filter direction) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
24 lines
956 B
TypeScript
24 lines
956 B
TypeScript
import { revalidatePath } from "next/cache";
|
|
import { serverAuth } from "@/lib/pb";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
// DELETE /api/purchases/:id/invoices/:invoiceId — remove a supplier invoice from a PO.
|
|
export async function DELETE(
|
|
_req: Request,
|
|
{ params }: { params: Promise<{ id: string; invoiceId: string }> },
|
|
) {
|
|
const { id, invoiceId } = await params;
|
|
try {
|
|
const pb = await serverAuth();
|
|
const inv = await pb.collection("purchase_invoices").getOne(invoiceId).catch(() => null);
|
|
if (!inv || inv.purchase !== id) {
|
|
return Response.json({ ok: false, error: "Invoice not found on that purchase order" }, { status: 404 });
|
|
}
|
|
await pb.collection("purchase_invoices").delete(invoiceId);
|
|
revalidatePath("/running/purchases");
|
|
return Response.json({ ok: true });
|
|
} catch (e: any) {
|
|
return Response.json({ ok: false, error: e?.message || "Could not delete the invoice" }, { status: 500 });
|
|
}
|
|
}
|