修正bug
All checks were successful
Koori-ERP-Sync-Only / sync-update (push) Successful in 1m5s

This commit is contained in:
2025-12-31 17:48:36 +08:00
parent c152dc6d81
commit 8cbf73681e
5 changed files with 62 additions and 21 deletions

View File

@@ -123,11 +123,25 @@ class PurchaseOrderController extends Controller
$taxAmount = round($totalAmount * 0.05, 2);
$grandTotal = $totalAmount + $taxAmount;
// 確保有一個有效的使用者 ID
$userId = auth()->id();
if (!$userId) {
$user = \App\Models\User::first();
if (!$user) {
$user = \App\Models\User::create([
'name' => '系統管理員',
'email' => 'admin@example.com',
'password' => bcrypt('password'),
]);
}
$userId = $user->id;
}
$order = PurchaseOrder::create([
'code' => $code,
'vendor_id' => $validated['vendor_id'],
'warehouse_id' => $validated['warehouse_id'],
'user_id' => auth()->id() ?? 1, // Fallback for dev if not using auth
'user_id' => $userId,
'status' => 'draft',
'expected_delivery_date' => $validated['expected_delivery_date'],
'total_amount' => $totalAmount,

View File

@@ -1,4 +1,4 @@
import { Edit, Eye, Trash2 } from "lucide-react";
import { Pencil, Eye, Trash2 } from "lucide-react";
import { Button } from "@/Components/ui/button";
import { Link, useForm } from "@inertiajs/react";
import type { PurchaseOrder } from "@/types/purchase-order";
@@ -38,13 +38,13 @@ export function PurchaseOrderActions({
className="button-outlined-primary h-8 w-8 p-0"
title="編輯採購單"
>
<Edit className="h-4 w-4" />
<Pencil className="h-4 w-4" />
</Button>
</Link>
<Button
variant="outline"
size="sm"
className="hover:bg-red-50 hover:text-red-600 hover:border-red-200 text-gray-500 h-8 w-8 p-0 transition-colors"
className="button-outlined-error h-8 w-8 p-0"
title="刪除採購單"
onClick={handleDelete}
disabled={processing}

View File

@@ -275,7 +275,7 @@ export default function TransferOrderDialog({
key={`${product.productId}|||${product.batchNumber}`}
value={`${product.productId}|||${product.batchNumber}`}
>
{product.productName} - : {product.batchNumber} (:{" "}
{product.productName} (:{" "}
{product.availableQty})
</SelectItem>
))
@@ -300,12 +300,14 @@ export default function TransferOrderDialog({
setFormData({ ...formData, quantity: Number(e.target.value) })
}
/>
<div className="h-5">
{selectedProduct && (
<p className="text-sm text-gray-500">
: {selectedProduct.availableQty}
</p>
)}
</div>
</div>
<div className="space-y-2">
<Label htmlFor="transferDate">

View File

@@ -186,7 +186,7 @@ export default function AuthenticatedLayout({ children }: { children: React.Reac
<main className="flex-1 ml-64 overflow-auto min-h-screen bg-background">
{children}
<Toaster richColors closeButton position="top-right" />
<Toaster richColors closeButton position="top-center" />
</main>
</div>
);

View File

@@ -64,14 +64,29 @@ export default function CreatePurchaseOrder({
const isValid = validatePurchaseOrder(String(supplierId), expectedDate, items);
const handleSave = () => {
if (!isValid || !warehouseId) {
toast.error("請填寫完整的表單資訊");
if (!warehouseId) {
toast.error("請選擇入庫倉庫");
return;
}
if (!supplierId) {
toast.error("請選擇供應商");
return;
}
if (!expectedDate) {
toast.error("請選擇預計到貨日期");
return;
}
if (items.length === 0) {
toast.error("請至少新增一項採購商品");
return;
}
const validItems = filterValidItems(items);
if (validItems.length === 0) {
toast.error("請至少新增一項採購商品");
toast.error("請填寫有效的採購數量(必須大於 0");
return;
}
@@ -89,13 +104,24 @@ export default function CreatePurchaseOrder({
};
if (order) {
// Edit not implemented yet but structure is ready
router.put(`/purchase-orders/${order.id}`, data, {
onSuccess: () => toast.success("採購單已更新")
onSuccess: () => toast.success("採購單已更新"),
onError: (errors) => {
toast.error("更新失敗,請檢查輸入內容");
console.error(errors);
}
});
} else {
router.post("/purchase-orders", data, {
onSuccess: () => toast.success("採購單已成功建立")
onSuccess: () => toast.success("採購單已成功建立"),
onError: (errors) => {
if (errors.error) {
toast.error(errors.error);
} else {
toast.error("建立失敗,請檢查輸入內容");
}
console.error(errors);
}
});
}
};
@@ -284,7 +310,6 @@ export default function CreatePurchaseOrder({
size="lg"
className="bg-primary hover:bg-primary/90 text-white px-12 h-14 rounded-xl shadow-lg shadow-primary/20 text-lg font-bold transition-all hover:scale-[1.02] active:scale-[0.98]"
onClick={handleSave}
disabled={!canSave}
>
{order ? "更新採購單" : "確認發布採購單"}
</Button>