統一庫存盤點與盤調 UI 及邏輯:修正狀態顯示、操作權限與列表樣式
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||
import { Head, useForm, router } from '@inertiajs/react';
|
||||
import { Head, useForm, router, Link } from '@inertiajs/react';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -20,8 +20,18 @@ import {
|
||||
DialogTitle,
|
||||
} from "@/Components/ui/dialog";
|
||||
import { Label } from "@/Components/ui/label";
|
||||
import { Plus, Search, X, Eye, Pencil, ClipboardCheck } from "lucide-react";
|
||||
import { Plus, Search, X, Eye, Pencil, ClipboardCheck, Trash2 } from "lucide-react";
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import Pagination from '@/Components/shared/Pagination';
|
||||
import { SearchableSelect } from '@/Components/ui/searchable-select';
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
@@ -63,6 +73,7 @@ export default function Index({ docs, warehouses, filters }: { docs: DocsPaginat
|
||||
const [searchQuery, setSearchQuery] = useState(filters.search || '');
|
||||
const [warehouseId, setWarehouseId] = useState(filters.warehouse_id || '');
|
||||
const [perPage, setPerPage] = useState(filters.per_page || '15');
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
|
||||
// For Count Doc Selection
|
||||
const [pendingCounts, setPendingCounts] = useState<any[]>([]);
|
||||
@@ -110,6 +121,20 @@ export default function Index({ docs, warehouses, filters }: { docs: DocsPaginat
|
||||
debouncedFilter({ search: searchQuery, warehouse_id: warehouseId, per_page: val });
|
||||
};
|
||||
|
||||
const confirmDelete = (id: string, e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
setDeleteId(id);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
router.delete(route('inventory.adjust.destroy', [deleteId]), {
|
||||
onSuccess: () => setDeleteId(null),
|
||||
onError: () => setDeleteId(null),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const { data, setData, post, processing, reset } = useForm({
|
||||
count_doc_id: null as string | null,
|
||||
warehouse_id: '',
|
||||
@@ -161,9 +186,11 @@ export default function Index({ docs, warehouses, filters }: { docs: DocsPaginat
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<ClipboardCheck className="h-6 w-6 text-primary-main" />
|
||||
庫存盤調單
|
||||
庫存盤調管理
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">針對盤點差異進行庫存調整與過帳 (盤盈、盤虧、報廢等)</p>
|
||||
<p className="text-gray-500 mt-1">
|
||||
針對盤點差異進行庫存調整與過帳 (盤盈、盤虧、報廢等)。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -229,7 +256,7 @@ export default function Index({ docs, warehouses, filters }: { docs: DocsPaginat
|
||||
<TableHead className="font-medium text-grey-600">建立者</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">建立時間</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">過帳時間</TableHead>
|
||||
<TableHead className="text-right font-medium text-grey-600">操作</TableHead>
|
||||
<TableHead className="text-center font-medium text-grey-600">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
@@ -246,30 +273,46 @@ export default function Index({ docs, warehouses, filters }: { docs: DocsPaginat
|
||||
className="hover:bg-gray-50/50 transition-colors cursor-pointer group"
|
||||
onClick={() => router.visit(route('inventory.adjust.show', [doc.id]))}
|
||||
>
|
||||
<TableCell className="text-center text-grey-400 font-medium">
|
||||
<TableCell className="text-center text-gray-500 font-medium">
|
||||
{(docs.current_page - 1) * docs.per_page + index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="font-semibold text-primary-main">
|
||||
<TableCell className="font-medium text-primary-main">
|
||||
{doc.doc_no}
|
||||
</TableCell>
|
||||
<TableCell className="text-grey-700">{doc.warehouse_name}</TableCell>
|
||||
<TableCell className="text-grey-600 max-w-[200px] truncate">{doc.reason}</TableCell>
|
||||
<TableCell>{doc.warehouse_name}</TableCell>
|
||||
<TableCell className="text-gray-500 max-w-[200px] truncate">{doc.reason}</TableCell>
|
||||
<TableCell className="text-center">{getStatusBadge(doc.status)}</TableCell>
|
||||
<TableCell className="text-grey-600 text-sm">{doc.created_by}</TableCell>
|
||||
<TableCell className="text-grey-400 text-xs">{doc.created_at}</TableCell>
|
||||
<TableCell className="text-grey-400 text-xs">{doc.posted_at}</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-primary-main hover:bg-primary-50 px-2"
|
||||
>
|
||||
{doc.status === 'posted' ? (
|
||||
<><Eye className="h-4 w-4 mr-1" /> 查閱</>
|
||||
) : (
|
||||
<><Pencil className="h-4 w-4 mr-1" /> 編輯</>
|
||||
<TableCell className="text-sm">{doc.created_by}</TableCell>
|
||||
<TableCell className="text-gray-500 text-sm">{doc.created_at}</TableCell>
|
||||
<TableCell className="text-gray-500 text-sm">{doc.posted_at || '-'}</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<div className="flex items-center justify-center gap-2" onClick={(e) => e.stopPropagation()}>
|
||||
<Link href={route('inventory.adjust.show', [doc.id])}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title={doc.status === 'posted' ? '查閱' : '編輯'}
|
||||
>
|
||||
{doc.status === 'posted' ? (
|
||||
<Eye className="w-4 h-4" />
|
||||
) : (
|
||||
<Pencil className="w-4 h-4" />
|
||||
)}
|
||||
</Button>
|
||||
</Link>
|
||||
{doc.status === 'draft' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={(e) => confirmDelete(doc.id, e)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</Button>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
@@ -300,6 +343,21 @@ export default function Index({ docs, warehouses, filters }: { docs: DocsPaginat
|
||||
</div>
|
||||
<Pagination links={docs.links} />
|
||||
</div>
|
||||
|
||||
<AlertDialog open={!!deleteId} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確定要刪除此盤調單嗎?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
此動作無法復原。刪除後請重新建立盤調單。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDelete} className="bg-red-600 hover:bg-red-700">確認刪除</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
|
||||
{/* Create Dialog */}
|
||||
|
||||
Reference in New Issue
Block a user