更新採購單跟商品資料一些bug
This commit is contained in:
@@ -60,8 +60,8 @@ export default function CreatePurchaseOrder({
|
||||
setStatus,
|
||||
} = usePurchaseOrderForm({ order, suppliers });
|
||||
|
||||
|
||||
const totalAmount = calculateTotalAmount(items);
|
||||
const isValid = validatePurchaseOrder(String(supplierId), expectedDate, items);
|
||||
|
||||
const handleSave = () => {
|
||||
if (!warehouseId) {
|
||||
@@ -84,9 +84,23 @@ export default function CreatePurchaseOrder({
|
||||
return;
|
||||
}
|
||||
|
||||
// 檢查是否有數量大於 0 的項目
|
||||
const itemsWithQuantity = items.filter(item => item.quantity > 0);
|
||||
if (itemsWithQuantity.length === 0) {
|
||||
toast.error("請填寫有效的採購數量(必須大於 0)");
|
||||
return;
|
||||
}
|
||||
|
||||
// 檢查有數量的項目是否都有填寫單價
|
||||
const itemsWithoutPrice = itemsWithQuantity.filter(item => !item.unitPrice || item.unitPrice <= 0);
|
||||
if (itemsWithoutPrice.length > 0) {
|
||||
toast.error("請填寫所有商品的預估單價(必須大於 0)");
|
||||
return;
|
||||
}
|
||||
|
||||
const validItems = filterValidItems(items);
|
||||
if (validItems.length === 0) {
|
||||
toast.error("請填寫有效的採購數量(必須大於 0)");
|
||||
toast.error("請確保所有商品都有填寫數量和單價");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,7 +121,14 @@ export default function CreatePurchaseOrder({
|
||||
router.put(`/purchase-orders/${order.id}`, data, {
|
||||
onSuccess: () => toast.success("採購單已更新"),
|
||||
onError: (errors) => {
|
||||
toast.error("更新失敗,請檢查輸入內容");
|
||||
// 顯示更詳細的錯誤訊息
|
||||
if (errors.items) {
|
||||
toast.error("商品資料有誤,請檢查數量和單價是否正確填寫");
|
||||
} else if (errors.error) {
|
||||
toast.error(errors.error);
|
||||
} else {
|
||||
toast.error("更新失敗,請檢查輸入內容");
|
||||
}
|
||||
console.error(errors);
|
||||
}
|
||||
});
|
||||
@@ -115,10 +136,12 @@ export default function CreatePurchaseOrder({
|
||||
router.post("/purchase-orders", data, {
|
||||
onSuccess: () => toast.success("採購單已成功建立"),
|
||||
onError: (errors) => {
|
||||
if (errors.error) {
|
||||
if (errors.items) {
|
||||
toast.error("商品資料有誤,請檢查數量和單價是否正確填寫");
|
||||
} else if (errors.error) {
|
||||
toast.error(errors.error);
|
||||
} else {
|
||||
toast.error("建立失敗,請檢查輸入內容");
|
||||
toast.error("建立失敗,請檢查輸入內容");
|
||||
}
|
||||
console.error(errors);
|
||||
}
|
||||
@@ -127,7 +150,6 @@ export default function CreatePurchaseOrder({
|
||||
};
|
||||
|
||||
const hasSupplier = !!supplierId;
|
||||
const canSave = isValid && !!warehouseId && items.length > 0;
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout>
|
||||
|
||||
Reference in New Issue
Block a user