Refine purchase receipt and lot label flow
This commit is contained in:
@ -21,7 +21,14 @@ const receiptDetailInclude = {
|
||||
warehouseLocation: true
|
||||
}
|
||||
},
|
||||
lots: true
|
||||
lots: {
|
||||
include: {
|
||||
grade: true,
|
||||
unit: true,
|
||||
warehouse: true,
|
||||
warehouseLocation: true
|
||||
}
|
||||
}
|
||||
} as const;
|
||||
|
||||
export async function GET(request: Request) {
|
||||
@ -60,12 +67,8 @@ export async function POST(request: Request) {
|
||||
const purchase = await prisma.purchase.findUnique({
|
||||
where: { id: purchaseId },
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
receipts: true,
|
||||
lots: true
|
||||
}
|
||||
}
|
||||
receipts: { select: { id: true, receiptNo: true } },
|
||||
lots: { select: { id: true } }
|
||||
}
|
||||
});
|
||||
|
||||
@ -73,16 +76,13 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ message: "Purchase not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
if (purchase.status !== "SUBMITTED") {
|
||||
return NextResponse.json(
|
||||
{ message: "Purchase harus diajukan sebelum dibuatkan receipt." },
|
||||
{ status: 409 }
|
||||
);
|
||||
if (purchase.status === "CANCELLED") {
|
||||
return NextResponse.json({ message: "Purchase yang dibatalkan tidak bisa dibuatkan receipt" }, { status: 422 });
|
||||
}
|
||||
|
||||
if (purchase._count.receipts > 0 || purchase._count.lots > 0) {
|
||||
if (purchase.receipts.length > 0 || purchase.lots.length > 0) {
|
||||
return NextResponse.json(
|
||||
{ message: "Purchase sudah memiliki receipt/lot." },
|
||||
{ message: `Purchase sudah memiliki receipt/lot ${purchase.receipts[0]?.receiptNo ?? ""}`.trim() },
|
||||
{ status: 409 }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user