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.doc_no}

{doc.status === 'completed' ? ( 已完成 ) : ( 盤點中 )}

倉庫: {doc.warehouse_name} | 建立人: {doc.created_by} | 快照時間: {doc.snapshot_date}

{!isCompleted && (
確定要作廢此盤點單嗎? 此動作無法復原。作廢後請重新建立盤點單。 取消 確認作廢
)} {isCompleted && ( )}
{!isCompleted && (
盤點進度: {countedItems} / {totalItems} 項目 {progress}%
)} 盤點明細 請輸入每個項目的「實盤數量」。若有差異系統將自動計算。 # 商品代號 / 名稱 批號 系統庫存 實盤數量 差異 單位 備註 {doc.items.map((item: any, index: number) => { const formItem = data.items[index]; const diff = formItem.counted_qty !== '' && formItem.counted_qty !== null ? (parseFloat(formItem.counted_qty) - item.system_qty) : 0; const hasDiff = Math.abs(diff) > 0.0001; return ( {index + 1}
{item.product_code} {item.product_name}
{item.batch_number || '-'} {item.system_qty.toFixed(2)} {isCompleted ? ( {item.counted_qty} ) : ( updateItem(index, 'counted_qty', e.target.value)} onWheel={(e: any) => e.target.blur()} disabled={processing} className="h-9 text-right font-medium focus:ring-primary-main" placeholder="盤點..." /> )} 0 ? 'text-green-600' : 'text-red-600' }`}> {formItem.counted_qty !== '' && formItem.counted_qty !== null ? diff.toFixed(2) : '-'} {item.unit || item.unit_name} {isCompleted ? ( {item.notes} ) : ( updateItem(index, 'notes', e.target.value)} disabled={processing} className="h-9 text-sm" placeholder="備註..." /> )}
); })}

操作導引

資料會自動保存盤點人與時間。若尚未盤點完,您可以點擊「暫存進度」稍後繼續。 確認所有項目資料正確後,請點擊「完成盤點並過帳」正式生效庫存調整。

); }