All checks were successful
ERP-Deploy-Demo / deploy-demo (push) Successful in 1m8s
1. 新增 AccountPayable (應付帳款) 模組,包含 Migration、Model、Service 與 Controller 2. 修改 GoodsReceipt (進貨單) 流程,在確認進貨時自動產生對應的應付帳款單 (AP-YYYYMMDD-XX) 3. 實作應付帳款詳細頁面 (Show.tsx),包含發票登記與標記付款功能 4. 修正應付帳款 Show 頁面的排版,將發票資訊套用標準的綠色背景區塊,並調整按鈕位置 5. 更新相關的 Service Provider 與 Routes
108 lines
3.7 KiB
TypeScript
108 lines
3.7 KiB
TypeScript
import { useState } from "react";
|
||
import { Eye, Trash2 } from "lucide-react";
|
||
import { Button } from "@/Components/ui/button";
|
||
import { Link, useForm } from "@inertiajs/react";
|
||
import { toast } from "sonner";
|
||
import { Can } from "@/Components/Permission/Can";
|
||
import {
|
||
AlertDialog,
|
||
AlertDialogAction,
|
||
AlertDialogCancel,
|
||
AlertDialogContent,
|
||
AlertDialogDescription,
|
||
AlertDialogFooter,
|
||
AlertDialogHeader,
|
||
AlertDialogTitle,
|
||
} from "@/Components/ui/alert-dialog";
|
||
|
||
export interface GoodsReceipt {
|
||
id: number;
|
||
code: string;
|
||
warehouse_id: number;
|
||
warehouse?: { name: string };
|
||
vendor_id?: number;
|
||
vendor?: { name: string };
|
||
received_date: string;
|
||
status: string;
|
||
type?: string;
|
||
items_sum_total_amount?: number;
|
||
user?: { name: string };
|
||
}
|
||
|
||
export default function GoodsReceiptActions({
|
||
receipt,
|
||
}: { receipt: GoodsReceipt }) {
|
||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||
|
||
const { delete: destroy, processing } = useForm({});
|
||
|
||
const handleConfirmDelete = () => {
|
||
// @ts-ignore
|
||
destroy(route('goods-receipts.destroy', receipt.id), {
|
||
onSuccess: () => {
|
||
toast.success("進貨單已成功刪除");
|
||
setShowDeleteDialog(false);
|
||
},
|
||
onError: (errors: any) => toast.error(errors.error || "刪除過程中發生錯誤"),
|
||
});
|
||
};
|
||
|
||
|
||
|
||
return (
|
||
<div className="flex justify-center gap-2">
|
||
<Link href={route('goods-receipts.show', receipt.id)}>
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
className="button-outlined-primary"
|
||
title="查看詳情"
|
||
>
|
||
<Eye className="h-4 w-4" />
|
||
</Button>
|
||
</Link>
|
||
|
||
{/* 只允許刪除草稿或已退回的進貨單 */}
|
||
{(receipt.status === 'draft' || receipt.status === 'rejected') && (
|
||
<Can permission="goods_receipts.delete">
|
||
<Button
|
||
variant="outline"
|
||
size="sm"
|
||
className="button-outlined-error"
|
||
title="刪除"
|
||
onClick={() => setShowDeleteDialog(true)}
|
||
disabled={processing}
|
||
>
|
||
<Trash2 className="h-4 w-4" />
|
||
</Button>
|
||
</Can>
|
||
)}
|
||
|
||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||
<AlertDialogContent>
|
||
<AlertDialogHeader>
|
||
<AlertDialogTitle>確認刪除進貨單</AlertDialogTitle>
|
||
<AlertDialogDescription>
|
||
確定要刪除進貨單 「{receipt.code}」 嗎?
|
||
<br />
|
||
<span className="text-red-500 font-bold mt-2 block">
|
||
注意:刪除動作無法復原!
|
||
</span>
|
||
</AlertDialogDescription>
|
||
</AlertDialogHeader>
|
||
<AlertDialogFooter>
|
||
<AlertDialogCancel className="button-outlined-primary">取消</AlertDialogCancel>
|
||
<AlertDialogAction
|
||
onClick={handleConfirmDelete}
|
||
className="button-filled-error"
|
||
>
|
||
確認刪除
|
||
</AlertDialogAction>
|
||
</AlertDialogFooter>
|
||
</AlertDialogContent>
|
||
</AlertDialog>
|
||
|
||
</div>
|
||
);
|
||
}
|