From 195ed1582e693fdfe07ab3f3b23dea89e1063da2 Mon Sep 17 00:00:00 2001 From: "[dyad]" Date: Fri, 12 Sep 2025 16:36:26 +0200 Subject: [PATCH] [dyad] Fixed quantity saving by creating separate book out records per item - wrote 1 file(s) --- src/components/book-out/BookOutForm.tsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/book-out/BookOutForm.tsx b/src/components/book-out/BookOutForm.tsx index df77e96..776089f 100644 --- a/src/components/book-out/BookOutForm.tsx +++ b/src/components/book-out/BookOutForm.tsx @@ -128,7 +128,7 @@ export function BookOutForm({ setOpen, refreshData }: BookOutFormProps) { const currentItem = newItems[index] as BookOutItemSchemaType; if (field === "quantity") { - currentItem[field] = Number(value) || 0; // Convert to number here + currentItem[field] = Number(value) || 0; } else { currentItem[field] = value; } @@ -150,15 +150,17 @@ export function BookOutForm({ setOpen, refreshData }: BookOutFormProps) { async function onSubmit(values: z.infer) { try { - const bookOutData = { - bookOutDate: values.bookOutDate.toISOString(), - customer: values.customer, - items: values.items.map(item => item.stockItemId), - quantity: values.items.map(item => item.quantity), - date_booked_out: values.bookOutDate.toISOString(), - }; - - await pb.collection('book_out_records').create(bookOutData); + // Create one book out record per item with its quantity + for (const item of values.items) { + const bookOutData = { + bookOutDate: values.bookOutDate.toISOString(), + customer: values.customer, + items: [item.stockItemId], // single item ID in array + quantity: item.quantity, + date_booked_out: values.bookOutDate.toISOString(), + }; + await pb.collection('book_out_records').create(bookOutData); + } showSuccess("Stock booked out successfully!"); form.reset(); setOpen(false);