import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
import { Head, useForm } from '@inertiajs/react';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/Components/ui/table';
import { Button } from '@/Components/ui/button';
import { Input } from '@/Components/ui/input';
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/Components/ui/card';
import { Badge } from '@/Components/ui/badge';
import { Save, CheckCircle, Printer, Trash2, ClipboardCheck, Eye, Pencil } from 'lucide-react';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/Components/ui/alert-dialog"
import { Can } from '@/Components/Permission/Can';
import { Link } from '@inertiajs/react';
export default function Show({ doc }: any) {
// Transform items to form data structure
const { data, setData, put, delete: destroy, processing } = useForm({
items: doc.items.map((item: any) => ({
id: item.id,
counted_qty: item.counted_qty,
notes: item.notes || '',
})),
action: 'save', // 'save' or 'complete'
});
// Helper to update local form data
const updateItem = (index: number, field: string, value: any) => {
const newItems = [...data.items];
newItems[index][field] = value;
setData('items', newItems);
};
const handleSubmit = (action: string) => {
setData('action', action);
put(route('inventory.count.update', [doc.id]), {
onSuccess: () => {
// Handle success if needed
}
});
};
const handleDelete = () => {
destroy(route('inventory.count.destroy', [doc.id]));
};
const isCompleted = doc.status === 'completed';
// Calculate progress
const totalItems = doc.items.length;
const countedItems = data.items.filter((i: any) => i.counted_qty !== '' && i.counted_qty !== null).length;
const progress = Math.round((countedItems / totalItems) * 100) || 0;
return (
倉庫: {doc.warehouse_name} | 建立人: {doc.created_by} | 快照時間: {doc.snapshot_date}
資料會自動保存盤點人與時間。若尚未盤點完,您可以點擊「暫存進度」稍後繼續。 確認所有項目資料正確後,請點擊「完成盤點並過帳」正式生效庫存調整。