diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 887d12c..4eef2ad 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -10,6 +10,11 @@ jobs: steps: - name: 1. Checkout Code uses: actions/checkout@v3 + with: + # --- 關鍵:直接指定 Gitea 的伺服器網址為 IP --- + github-server-url: http://192.168.0.103:3000 + repository: ${{ gitea.repository }} + # ------------------------------------------ - name: 2. Create .env from Secrets run: echo "${{ secrets.DOT_ENV }}" > .env diff --git a/app/Http/Controllers/PurchaseOrderController.php b/app/Http/Controllers/PurchaseOrderController.php index 1eebef2..8e2f750 100644 --- a/app/Http/Controllers/PurchaseOrderController.php +++ b/app/Http/Controllers/PurchaseOrderController.php @@ -256,4 +256,24 @@ class PurchaseOrderController extends Controller return back()->withErrors(['error' => '更新失敗:' . $e->getMessage()]); } } + + public function destroy($id) + { + try { + DB::beginTransaction(); + + $order = PurchaseOrder::findOrFail($id); + + // Delete associated items first (due to FK constraints if not cascade) + $order->items()->delete(); + $order->delete(); + + DB::commit(); + + return redirect()->route('purchase-orders.index')->with('success', '採購單已刪除'); + } catch (\Exception $e) { + DB::rollBack(); + return back()->withErrors(['error' => '刪除失敗:' . $e->getMessage()]); + } + } } diff --git a/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx b/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx index 0129b98..8f16d2f 100644 --- a/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx +++ b/resources/js/Components/PurchaseOrder/PurchaseOrderActions.tsx @@ -1,11 +1,24 @@ -import { Edit, Eye } from "lucide-react"; +import { Edit, Eye, Trash2 } from "lucide-react"; import { Button } from "@/Components/ui/button"; -import { Link } from "@inertiajs/react"; +import { Link, useForm } from "@inertiajs/react"; import type { PurchaseOrder } from "@/types/purchase-order"; +import { toast } from "sonner"; export function PurchaseOrderActions({ order, }: { order: PurchaseOrder }) { + const { delete: destroy, processing } = useForm({}); + + const handleDelete = () => { + if (confirm(`確定要刪除採購單 ${order.poNumber} 嗎?`)) { + // @ts-ignore + destroy(route('purchase-orders.destroy', order.id), { + onSuccess: () => toast.success("採購單已成功刪除"), + onError: (errors: any) => toast.error(errors.error || "刪除過程中發生錯誤"), + }); + } + }; + return (