refactor: changes to inventory status (approved/unapprove)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||
import { Head, useForm } from '@inertiajs/react';
|
||||
import { Head, useForm, Link } from '@inertiajs/react'; // Added Link
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import { Input } from '@/Components/ui/input';
|
||||
import { Badge } from '@/Components/ui/badge';
|
||||
import { Save, CheckCircle, Printer, Trash2, ClipboardCheck } from 'lucide-react';
|
||||
import { Save, CheckCircle, Printer, Trash2, ClipboardCheck, ArrowLeft, RotateCcw } from 'lucide-react'; // Added ArrowLeft
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
@@ -55,6 +55,14 @@ export default function Show({ doc }: any) {
|
||||
destroy(route('inventory.count.destroy', [doc.id]));
|
||||
};
|
||||
|
||||
const handleReopen = () => {
|
||||
if (confirm('確定要取消核准嗎?單據將回復為盤點中狀態,且庫存異動將被撤回(若已過帳)。')) {
|
||||
router.visit(route('inventory.count.reopen', [doc.id]), {
|
||||
method: 'put',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const isCompleted = doc.status === 'completed';
|
||||
|
||||
// Calculate progress
|
||||
@@ -72,28 +80,62 @@ export default function Show({ doc }: any) {
|
||||
>
|
||||
<Head title={`盤點單 ${doc.doc_no}`} />
|
||||
|
||||
<div className="container mx-auto p-6 max-w-7xl animate-in fade-in duration-500">
|
||||
<div className="space-y-6">
|
||||
<div className="container mx-auto p-6 max-w-7xl animate-in fade-in duration-500 space-y-6">
|
||||
<div>
|
||||
<Link href={route('inventory.count.index')}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="gap-2 button-outlined-primary mb-6"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回盤點單列表
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-4">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<ClipboardCheck className="h-6 w-6 text-primary-main" />
|
||||
盤點單: {doc.doc_no}
|
||||
</h1>
|
||||
{doc.status === 'completed' ? (
|
||||
<Badge className="bg-green-500 hover:bg-green-600">已完成</Badge>
|
||||
) : (
|
||||
<Badge className="bg-blue-500 hover:bg-blue-600">盤點中</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-gray-500 mt-1 font-medium">
|
||||
倉庫: {doc.warehouse_name} <span className="mx-2">|</span> 建立人: {doc.created_by} <span className="mx-2">|</span> 快照時間: {doc.snapshot_date}
|
||||
</p>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<ClipboardCheck className="h-6 w-6 text-primary-main" />
|
||||
盤點單: {doc.doc_no}
|
||||
</h1>
|
||||
{doc.status === 'completed' ? (
|
||||
<Badge className="bg-green-500 hover:bg-green-600">已核准</Badge>
|
||||
) : (
|
||||
<Badge className="bg-blue-500 hover:bg-blue-600">盤點中</Badge>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-gray-500 mt-1 font-medium">
|
||||
倉庫: {doc.warehouse_name} <span className="mx-2">|</span> 建立人: {doc.created_by} <span className="mx-2">|</span> 快照時間: {doc.snapshot_date}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
onClick={() => window.open(route('inventory.count.print', [doc.id]), '_blank')}
|
||||
>
|
||||
<Printer className="w-4 h-4 mr-2" />
|
||||
列印
|
||||
</Button>
|
||||
|
||||
{isCompleted && (
|
||||
<Can permission="inventory.adjust">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
onClick={handleReopen}
|
||||
disabled={processing}
|
||||
>
|
||||
<RotateCcw className="w-4 h-4 mr-2" />
|
||||
取消核准
|
||||
</Button>
|
||||
</Can>
|
||||
)}
|
||||
|
||||
{!isCompleted && (
|
||||
<div className="flex items-center gap-2">
|
||||
<Can permission="inventory.view">
|
||||
@@ -101,7 +143,7 @@ export default function Show({ doc }: any) {
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" disabled={processing} className="button-outlined-error">
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
作廢盤點單
|
||||
作廢
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
@@ -126,7 +168,7 @@ export default function Show({ doc }: any) {
|
||||
disabled={processing}
|
||||
>
|
||||
<Save className="w-4 h-4 mr-2" />
|
||||
暫存進度
|
||||
更新
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
@@ -135,142 +177,142 @@ export default function Show({ doc }: any) {
|
||||
disabled={processing}
|
||||
>
|
||||
<CheckCircle className="w-4 h-4 mr-2" />
|
||||
完成盤點
|
||||
完成
|
||||
</Button>
|
||||
</Can>
|
||||
</div>
|
||||
)}
|
||||
{isCompleted && (
|
||||
<Button variant="outline" size="sm" onClick={() => window.print()}>
|
||||
<Printer className="w-4 h-4 mr-2" />
|
||||
列印報表
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!isCompleted && (
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="text-gray-500 font-medium">盤點進度: {countedItems} / {totalItems} 項目</span>
|
||||
<span className="font-bold text-primary-main">{progress}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-gray-200 rounded-full h-2">
|
||||
<div className="bg-primary-main h-2 rounded-full transition-all duration-300" style={{ width: `${progress}%` }}></div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="font-semibold text-lg text-grey-900">盤點明細</h3>
|
||||
<p className="text-sm text-grey-500">
|
||||
請輸入每個項目的「實盤數量」。若有差異系統將自動計算。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader className="bg-gray-50">
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px] text-center 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-right w-32 font-medium text-grey-600">實盤數量</TableHead>
|
||||
<TableHead className="text-right font-medium text-grey-600">差異</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">單位</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">備註</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{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 (
|
||||
<TableRow key={item.id} className={hasDiff && formItem.counted_qty !== '' ? "bg-red-50/30" : ""}>
|
||||
<TableCell className="text-gray-500 font-medium text-center">
|
||||
{index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="py-3">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-semibold text-gray-900">{item.product_name}</span>
|
||||
<span className="text-xs text-gray-500 font-mono">{item.product_code}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm font-mono">{item.batch_number || '-'}</TableCell>
|
||||
<TableCell className="text-right font-medium">{item.system_qty.toFixed(2)}</TableCell>
|
||||
<TableCell className="text-right px-1 py-3">
|
||||
{isCompleted ? (
|
||||
<span className="font-semibold mr-2">{item.counted_qty}</span>
|
||||
) : (
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
value={formItem.counted_qty ?? ''}
|
||||
onChange={(e) => 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="盤點..."
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<span className={`font-bold ${!hasDiff
|
||||
? 'text-gray-400'
|
||||
: diff > 0
|
||||
? 'text-green-600'
|
||||
: 'text-red-600'
|
||||
}`}>
|
||||
{formItem.counted_qty !== '' && formItem.counted_qty !== null
|
||||
? diff.toFixed(2)
|
||||
: '-'}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm text-gray-500">{item.unit || item.unit_name}</TableCell>
|
||||
<TableCell className="px-1">
|
||||
{isCompleted ? (
|
||||
<span className="text-sm text-gray-600">{item.notes}</span>
|
||||
) : (
|
||||
<Input
|
||||
value={formItem.notes}
|
||||
onChange={(e) => updateItem(index, 'notes', e.target.value)}
|
||||
disabled={processing}
|
||||
className="h-9 text-sm"
|
||||
placeholder="備註..."
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="bg-gray-50/80 border border-dashed border-grey-200 rounded-lg p-4 flex items-start gap-3">
|
||||
<div className="bg-blue-100 p-2 rounded-lg">
|
||||
<Save className="w-5 h-5 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="font-semibold text-gray-900 mb-1 text-sm">操作導引</h4>
|
||||
<p className="text-xs text-gray-500 leading-relaxed">
|
||||
資料會自動保存盤點人與時間。若尚未盤點完,您可以點擊「暫存進度」稍後繼續。
|
||||
確認所有項目資料正確後,請點擊「完成盤點」結束盤點作業。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!isCompleted && (
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<span className="text-gray-500 font-medium">盤點進度: {countedItems} / {totalItems} 項目</span>
|
||||
<span className="font-bold text-primary-main">{progress}%</span>
|
||||
</div>
|
||||
<div className="w-full bg-gray-200 rounded-full h-2">
|
||||
<div className="bg-primary-main h-2 rounded-full transition-all duration-300" style={{ width: `${progress}%` }}></div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 className="font-semibold text-lg text-grey-900">盤點明細</h3>
|
||||
<p className="text-sm text-grey-500">
|
||||
請輸入每個項目的「實盤數量」。若有差異系統將自動計算。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader className="bg-gray-50">
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px] text-center 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-right w-32 font-medium text-grey-600">實盤數量</TableHead>
|
||||
<TableHead className="text-right font-medium text-grey-600">差異</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">單位</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">備註</TableHead>
|
||||
{!isCompleted && <TableHead className="w-[50px]"></TableHead>}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{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 (
|
||||
<TableRow key={item.id} className={hasDiff && formItem.counted_qty !== '' ? "bg-red-50/30" : ""}>
|
||||
<TableCell className="text-gray-500 font-medium text-center">
|
||||
{index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="py-3">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-semibold text-gray-900">{item.product_name}</span>
|
||||
<span className="text-xs text-gray-500 font-mono">{item.product_code}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm font-mono">{item.batch_number || '-'}</TableCell>
|
||||
<TableCell className="text-right font-medium">{item.system_qty.toFixed(2)}</TableCell>
|
||||
<TableCell className="text-right px-1 py-3">
|
||||
{isCompleted ? (
|
||||
<span className="font-semibold mr-2">{item.counted_qty}</span>
|
||||
) : (
|
||||
<Input
|
||||
type="number"
|
||||
step="0.01"
|
||||
value={formItem.counted_qty ?? ''}
|
||||
onChange={(e) => 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="盤點..."
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<span className={`font-bold ${!hasDiff
|
||||
? 'text-gray-400'
|
||||
: diff > 0
|
||||
? 'text-green-600'
|
||||
: 'text-red-600'
|
||||
}`}>
|
||||
{formItem.counted_qty !== '' && formItem.counted_qty !== null
|
||||
? diff.toFixed(2)
|
||||
: '-'}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-sm text-gray-500">{item.unit || item.unit_name}</TableCell>
|
||||
<TableCell className="px-1">
|
||||
{isCompleted ? (
|
||||
<span className="text-sm text-gray-600">{item.notes}</span>
|
||||
) : (
|
||||
<Input
|
||||
value={formItem.notes}
|
||||
onChange={(e) => updateItem(index, 'notes', e.target.value)}
|
||||
disabled={processing}
|
||||
className="h-9 text-sm"
|
||||
placeholder="備註..."
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
{!isCompleted && (
|
||||
<TableCell className="text-center">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-8 w-8 text-red-400 hover:text-red-600 hover:bg-red-50 p-0"
|
||||
onClick={() => {
|
||||
updateItem(index, 'counted_qty', '');
|
||||
}}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
)
|
||||
}
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
|
||||
</AuthenticatedLayout >
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user