import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; import { Head, useForm, Link, router } from '@inertiajs/react'; // Added Link import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/Components/ui/table'; import { Button } from '@/Components/ui/button'; import { Input } from '@/Components/ui/input'; import { Badge } from '@/Components/ui/badge'; import { Save, CheckCircle, Printer, Trash2, ClipboardCheck, ArrowLeft, RotateCcw } from 'lucide-react'; // Added ArrowLeft import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/Components/ui/alert-dialog" import { Can } from '@/Components/Permission/Can'; export default function Show({ doc }: any) { // Transform items to form data structure const { data, setData, put, delete: destroy, processing, transform } = 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) => { transform((data) => ({ ...data, action: action, })); put(route('inventory.count.update', [doc.id])); }; const handleDelete = () => { destroy(route('inventory.count.destroy', [doc.id])); }; const handleReopen = () => { router.visit(route('inventory.count.reopen', [doc.id]), { method: 'put', }); } 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}%
)}

盤點明細

請輸入每個項目的「實盤數量」。若有差異系統將自動計算。

# 商品名稱 / 代號 批號 系統庫存 實盤數量 差異 單位 備註 {!isCompleted && } {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_name} {item.product_code}
{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="備註..." /> )} {!isCompleted && ( ) }
); })}
); }