feat(inventory): 優化盤點顯示與權限設定
This commit is contained in:
@@ -137,7 +137,7 @@ class CountDocController extends Controller
|
|||||||
if ($request->input('action') === 'complete') {
|
if ($request->input('action') === 'complete') {
|
||||||
$this->countService->complete($doc, auth()->id());
|
$this->countService->complete($doc, auth()->id());
|
||||||
return redirect()->route('inventory.count.index')
|
return redirect()->route('inventory.count.index')
|
||||||
->with('success', '盤點已完成並過帳');
|
->with('success', '盤點單已完成');
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->with('success', '暫存成功');
|
return redirect()->back()->with('success', '暫存成功');
|
||||||
|
|||||||
@@ -75,55 +75,8 @@ class CountService
|
|||||||
public function complete(InventoryCountDoc $doc, int $userId): void
|
public function complete(InventoryCountDoc $doc, int $userId): void
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($doc, $userId) {
|
DB::transaction(function () use ($doc, $userId) {
|
||||||
foreach ($doc->items as $item) {
|
// 僅更新單據狀態為「已完成」,不執行庫存入庫/調整
|
||||||
// 如果沒有輸入實盤數量,預設跳過或是視為 0?
|
// 盤點單僅作為記錄,後續調整由盤調單 (AdjustDoc) 執行
|
||||||
// 安全起見:如果 counted_qty 是 null,表示沒盤到,跳過不處理 (或者依業務邏輯視為0)
|
|
||||||
// 這裡假設前端會確保有送出資料,若 null 則不做異動
|
|
||||||
if (is_null($item->counted_qty)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$diff = $item->counted_qty - $item->system_qty;
|
|
||||||
|
|
||||||
// 如果無差異,更新 item 狀態即可 (diff_qty 已經是 computed field 或在儲存時計算)
|
|
||||||
// 這裡 update 一下 diff_qty 以防萬一
|
|
||||||
$item->update(['diff_qty' => $diff]);
|
|
||||||
|
|
||||||
if (abs($diff) > 0.0001) {
|
|
||||||
// 找回原本的 Inventory
|
|
||||||
$inventory = Inventory::where('warehouse_id', $doc->warehouse_id)
|
|
||||||
->where('product_id', $item->product_id)
|
|
||||||
->where('batch_number', $item->batch_number)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (!$inventory) {
|
|
||||||
// 如果原本沒庫存紀錄 (例如是新增的盤點項目),需要新建 Inventory
|
|
||||||
// 但目前 snapshot 邏輯只抓現有。若允許 "盤盈" (發現不在帳上的),需要額外邏輯
|
|
||||||
// 暫時略過 "新增 Inventory" 的複雜邏輯,假設只能針對 existing batch 調整
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$oldQty = $inventory->quantity;
|
|
||||||
$newQty = $oldQty + $diff;
|
|
||||||
|
|
||||||
$inventory->quantity = $newQty;
|
|
||||||
$inventory->total_value = $inventory->unit_cost * $newQty;
|
|
||||||
$inventory->save();
|
|
||||||
|
|
||||||
// 寫入 Transaction
|
|
||||||
$inventory->transactions()->create([
|
|
||||||
'type' => '盤點調整',
|
|
||||||
'quantity' => $diff,
|
|
||||||
'unit_cost' => $inventory->unit_cost,
|
|
||||||
'balance_before' => $oldQty,
|
|
||||||
'balance_after' => $newQty,
|
|
||||||
'reason' => "盤點單 {$doc->doc_no} 過帳",
|
|
||||||
'actual_time' => now(),
|
|
||||||
'user_id' => $userId,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$doc->update([
|
$doc->update([
|
||||||
'status' => 'completed',
|
'status' => 'completed',
|
||||||
'completed_at' => now(),
|
'completed_at' => now(),
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ class PermissionSeeder extends Seeder
|
|||||||
'inventory.view',
|
'inventory.view',
|
||||||
'inventory.view_cost', // 查看成本與價值
|
'inventory.view_cost', // 查看成本與價值
|
||||||
'inventory.adjust',
|
'inventory.adjust',
|
||||||
'inventory.transfer',
|
'inventory.count', // 庫存盤點
|
||||||
|
'inventory.transfer', // 庫存調撥
|
||||||
'inventory.delete',
|
'inventory.delete',
|
||||||
|
|
||||||
// 進貨單管理
|
// 進貨單管理
|
||||||
@@ -132,7 +133,7 @@ class PermissionSeeder extends Seeder
|
|||||||
// warehouse-manager 管理庫存與倉庫
|
// warehouse-manager 管理庫存與倉庫
|
||||||
$warehouseManager->givePermissionTo([
|
$warehouseManager->givePermissionTo([
|
||||||
'products.view',
|
'products.view',
|
||||||
'inventory.view', 'inventory.adjust', 'inventory.transfer', 'inventory.delete',
|
'inventory.view', 'inventory.adjust', 'inventory.count', 'inventory.transfer', 'inventory.delete',
|
||||||
'goods_receipts.view', 'goods_receipts.create', 'goods_receipts.edit', 'goods_receipts.delete',
|
'goods_receipts.view', 'goods_receipts.create', 'goods_receipts.edit', 'goods_receipts.delete',
|
||||||
'production_orders.view', 'production_orders.create', 'production_orders.edit',
|
'production_orders.view', 'production_orders.create', 'production_orders.edit',
|
||||||
'warehouses.view', 'warehouses.create', 'warehouses.edit',
|
'warehouses.view', 'warehouses.create', 'warehouses.edit',
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ export default function Show({ doc }: { auth: any, doc: AdjDoc }) {
|
|||||||
action: 'save',
|
action: 'save',
|
||||||
});
|
});
|
||||||
|
|
||||||
const [newItemOpen, setNewItemOpen] = useState(false);
|
|
||||||
|
|
||||||
// Helper to add new item
|
// Helper to add new item
|
||||||
const addItem = (product: any, batchNumber: string | null) => {
|
const addItem = (product: any, batchNumber: string | null) => {
|
||||||
@@ -107,7 +106,6 @@ export default function Show({ doc }: { auth: any, doc: AdjDoc }) {
|
|||||||
notes: '',
|
notes: '',
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
setNewItemOpen(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeItem = (index: number) => {
|
const removeItem = (index: number) => {
|
||||||
@@ -294,96 +292,99 @@ export default function Show({ doc }: { auth: any, doc: AdjDoc }) {
|
|||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card className="border border-gray-200 shadow-sm overflow-hidden gap-0">
|
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||||
<CardHeader className="bg-white border-b flex flex-row items-center justify-between py-4 px-6">
|
<div className="flex flex-row items-center justify-between">
|
||||||
<CardTitle className="text-lg font-medium text-grey-900">調整項目清單</CardTitle>
|
<h3 className="text-lg font-medium text-grey-900">調整項目清單</h3>
|
||||||
{isDraft && (
|
{isDraft && (
|
||||||
<ProductSearchDialog
|
<ProductSearchDialog
|
||||||
warehouseId={doc.warehouse_id}
|
warehouseId={doc.warehouse_id}
|
||||||
onSelect={(product, batch) => addItem(product, batch)}
|
onSelect={(product, batch) => addItem(product, batch)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</CardHeader>
|
</div>
|
||||||
<Table>
|
<div className="border rounded-lg overflow-hidden">
|
||||||
<TableHeader className="bg-gray-50">
|
<Table>
|
||||||
<TableRow>
|
<TableHeader className="bg-gray-50">
|
||||||
<TableHead className="w-[60px] text-center font-medium text-grey-600">#</TableHead>
|
|
||||||
<TableHead className="pl-4 font-medium text-grey-600">商品資訊</TableHead>
|
|
||||||
<TableHead className="font-medium text-grey-600">批號</TableHead>
|
|
||||||
<TableHead className="w-24 text-center font-medium text-grey-600">單位</TableHead>
|
|
||||||
<TableHead className="w-32 text-right font-medium text-grey-600 text-primary-main">調整前庫存</TableHead>
|
|
||||||
<TableHead className="w-40 text-right font-medium text-grey-600">調整數量 (+/-)</TableHead>
|
|
||||||
<TableHead className="font-medium text-grey-600">備註說明</TableHead>
|
|
||||||
{isDraft && <TableHead className="w-[80px]"></TableHead>}
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{data.items.length === 0 ? (
|
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={isDraft ? 8 : 7} className="h-32 text-center text-grey-400">
|
<TableHead className="w-[60px] text-center font-medium text-grey-600">#</TableHead>
|
||||||
尚未載入任何調整項目
|
<TableHead className="pl-4 font-medium text-grey-600">商品資訊</TableHead>
|
||||||
</TableCell>
|
<TableHead className="font-medium text-grey-600">批號</TableHead>
|
||||||
|
<TableHead className="w-24 text-center font-medium text-grey-600">單位</TableHead>
|
||||||
|
<TableHead className="w-32 text-right font-medium text-grey-600 text-primary-main">調整前庫存</TableHead>
|
||||||
|
<TableHead className="w-40 text-right font-medium text-grey-600">調整數量 (+/-)</TableHead>
|
||||||
|
<TableHead className="font-medium text-grey-600">備註說明</TableHead>
|
||||||
|
{isDraft && <TableHead className="w-[80px]"></TableHead>}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
</TableHeader>
|
||||||
data.items.map((item, index) => (
|
<TableBody>
|
||||||
<TableRow
|
{data.items.length === 0 ? (
|
||||||
key={`${item.product_id}-${item.batch_number}-${index}`}
|
<TableRow>
|
||||||
className="group hover:bg-gray-50/50 transition-colors"
|
<TableCell colSpan={isDraft ? 8 : 7} className="h-32 text-center text-grey-400">
|
||||||
>
|
尚未載入任何調整項目
|
||||||
<TableCell className="text-center text-grey-400 font-medium">{index + 1}</TableCell>
|
|
||||||
<TableCell className="pl-4">
|
|
||||||
<div className="font-bold text-grey-900">{item.product_name}</div>
|
|
||||||
<div className="text-xs text-grey-500 font-mono">{item.product_code}</div>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="text-grey-600">{item.batch_number || '-'}</TableCell>
|
|
||||||
<TableCell className="text-center text-grey-500">{item.unit}</TableCell>
|
|
||||||
<TableCell className="text-right font-medium text-grey-400">
|
|
||||||
{item.qty_before}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-right">
|
|
||||||
{isDraft ? (
|
|
||||||
<Input
|
|
||||||
type="number"
|
|
||||||
className="text-right h-9 border-grey-200 focus:ring-primary-main"
|
|
||||||
value={item.adjust_qty}
|
|
||||||
onChange={e => updateItem(index, 'adjust_qty', e.target.value)}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<span className={`font-bold ${Number(item.adjust_qty) > 0 ? 'text-green-600' : 'text-red-600'}`}>
|
|
||||||
{Number(item.adjust_qty) > 0 ? '+' : ''}{item.adjust_qty}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
{isDraft ? (
|
|
||||||
<Input
|
|
||||||
className="h-9 border-grey-200 focus:ring-primary-main"
|
|
||||||
value={item.notes || ''}
|
|
||||||
onChange={e => updateItem(index, 'notes', e.target.value)}
|
|
||||||
placeholder="輸入備註..."
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<span className="text-grey-600 text-sm">{item.notes || '-'}</span>
|
|
||||||
)}
|
|
||||||
</TableCell>
|
|
||||||
{isDraft && (
|
|
||||||
<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={() => removeItem(index)}
|
|
||||||
>
|
|
||||||
<X className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</TableCell>
|
|
||||||
)}
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))
|
) : (
|
||||||
)}
|
data.items.map((item, index) => (
|
||||||
</TableBody>
|
<TableRow
|
||||||
</Table>
|
key={`${item.product_id}-${item.batch_number}-${index}`}
|
||||||
</Card>
|
className="group hover:bg-gray-50/50 transition-colors"
|
||||||
|
>
|
||||||
|
<TableCell className="text-center text-grey-400 font-medium">{index + 1}</TableCell>
|
||||||
|
<TableCell className="pl-4">
|
||||||
|
<div className="font-bold text-grey-900">{item.product_name}</div>
|
||||||
|
<div className="text-xs text-grey-500 font-mono">{item.product_code}</div>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-grey-600">{item.batch_number || '-'}</TableCell>
|
||||||
|
<TableCell className="text-center text-grey-500">{item.unit}</TableCell>
|
||||||
|
<TableCell className="text-right font-medium text-grey-400">
|
||||||
|
{item.qty_before}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
{isDraft ? (
|
||||||
|
<Input
|
||||||
|
type="number"
|
||||||
|
className="text-right h-9 border-grey-200 focus:ring-primary-main"
|
||||||
|
value={item.adjust_qty}
|
||||||
|
onChange={e => updateItem(index, 'adjust_qty', e.target.value)}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className={`font-bold ${Number(item.adjust_qty) > 0 ? 'text-green-600' : 'text-red-600'}`}>
|
||||||
|
{Number(item.adjust_qty) > 0 ? '+' : ''}{item.adjust_qty}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{isDraft ? (
|
||||||
|
<Input
|
||||||
|
className="h-9 border-grey-200 focus:ring-primary-main"
|
||||||
|
value={item.notes || ''}
|
||||||
|
onChange={e => updateItem(index, 'notes', e.target.value)}
|
||||||
|
placeholder="輸入備註..."
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span className="text-grey-600 text-sm">{item.notes || '-'}</span>
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
{isDraft && (
|
||||||
|
<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={() => removeItem(index)}
|
||||||
|
>
|
||||||
|
<X className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</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-gray-50/80 border border-dashed border-grey-200 rounded-lg p-4 flex items-start gap-3">
|
||||||
<CheckCircle className="h-5 w-5 text-primary-main mt-0.5 shrink-0" />
|
<CheckCircle className="h-5 w-5 text-primary-main mt-0.5 shrink-0" />
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ import {
|
|||||||
} from '@/Components/ui/table';
|
} from '@/Components/ui/table';
|
||||||
import { Button } from '@/Components/ui/button';
|
import { Button } from '@/Components/ui/button';
|
||||||
import { Input } from '@/Components/ui/input';
|
import { Input } from '@/Components/ui/input';
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/Components/ui/card';
|
|
||||||
import { Badge } from '@/Components/ui/badge';
|
import { Badge } from '@/Components/ui/badge';
|
||||||
import { Save, CheckCircle, Printer, Trash2, ClipboardCheck, Eye, Pencil } from 'lucide-react';
|
import { Save, CheckCircle, Printer, Trash2, ClipboardCheck } from 'lucide-react';
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
@@ -25,11 +24,10 @@ import {
|
|||||||
AlertDialogTrigger,
|
AlertDialogTrigger,
|
||||||
} from "@/Components/ui/alert-dialog"
|
} from "@/Components/ui/alert-dialog"
|
||||||
import { Can } from '@/Components/Permission/Can';
|
import { Can } from '@/Components/Permission/Can';
|
||||||
import { Link } from '@inertiajs/react';
|
|
||||||
|
|
||||||
export default function Show({ doc }: any) {
|
export default function Show({ doc }: any) {
|
||||||
// Transform items to form data structure
|
// Transform items to form data structure
|
||||||
const { data, setData, put, delete: destroy, processing } = useForm({
|
const { data, setData, put, delete: destroy, processing, transform } = useForm({
|
||||||
items: doc.items.map((item: any) => ({
|
items: doc.items.map((item: any) => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
counted_qty: item.counted_qty,
|
counted_qty: item.counted_qty,
|
||||||
@@ -46,12 +44,11 @@ export default function Show({ doc }: any) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = (action: string) => {
|
const handleSubmit = (action: string) => {
|
||||||
setData('action', action);
|
transform((data) => ({
|
||||||
put(route('inventory.count.update', [doc.id]), {
|
...data,
|
||||||
onSuccess: () => {
|
action: action,
|
||||||
// Handle success if needed
|
}));
|
||||||
}
|
put(route('inventory.count.update', [doc.id]));
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
@@ -75,186 +72,190 @@ export default function Show({ doc }: any) {
|
|||||||
>
|
>
|
||||||
<Head title={`盤點單 ${doc.doc_no}`} />
|
<Head title={`盤點單 ${doc.doc_no}`} />
|
||||||
|
|
||||||
<div className="container mx-auto p-6 max-w-7xl">
|
<div className="container mx-auto p-6 max-w-7xl animate-in fade-in duration-500">
|
||||||
<div className="flex items-center justify-between mb-6">
|
<div className="space-y-6">
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||||
<div>
|
<div className="flex items-center gap-4">
|
||||||
<div className="flex items-center gap-2">
|
<div>
|
||||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<ClipboardCheck className="h-6 w-6 text-primary-main" />
|
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||||
盤點單: {doc.doc_no}
|
<ClipboardCheck className="h-6 w-6 text-primary-main" />
|
||||||
</h1>
|
盤點單: {doc.doc_no}
|
||||||
{doc.status === 'completed' ? (
|
</h1>
|
||||||
<Badge className="bg-green-500 hover:bg-green-600">已完成</Badge>
|
{doc.status === 'completed' ? (
|
||||||
) : (
|
<Badge className="bg-green-500 hover:bg-green-600">已完成</Badge>
|
||||||
<Badge className="bg-blue-500 hover:bg-blue-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>
|
||||||
<p className="text-sm text-gray-500 mt-1">
|
</div>
|
||||||
倉庫: {doc.warehouse_name} | 建立人: {doc.created_by} | 快照時間: {doc.snapshot_date}
|
<div className="flex items-center gap-2">
|
||||||
</p>
|
{!isCompleted && (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Can permission="inventory.view">
|
||||||
|
<AlertDialog>
|
||||||
|
<AlertDialogTrigger asChild>
|
||||||
|
<Button variant="outline" size="sm" disabled={processing} className="button-outlined-error">
|
||||||
|
<Trash2 className="w-4 h-4 mr-2" />
|
||||||
|
作廢盤點單
|
||||||
|
</Button>
|
||||||
|
</AlertDialogTrigger>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="button-outlined-primary"
|
||||||
|
onClick={() => handleSubmit('save')}
|
||||||
|
disabled={processing}
|
||||||
|
>
|
||||||
|
<Save className="w-4 h-4 mr-2" />
|
||||||
|
暫存進度
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
className="button-filled-primary"
|
||||||
|
onClick={() => handleSubmit('complete')}
|
||||||
|
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>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
{!isCompleted && (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Can permission="inventory.view">
|
|
||||||
<AlertDialog>
|
|
||||||
<AlertDialogTrigger asChild>
|
|
||||||
<Button variant="outline" size="sm" disabled={processing} className="button-outlined-error">
|
|
||||||
<Trash2 className="w-4 h-4 mr-2" />
|
|
||||||
作廢盤點單
|
|
||||||
</Button>
|
|
||||||
</AlertDialogTrigger>
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
className="button-outlined-primary"
|
|
||||||
onClick={() => handleSubmit('save')}
|
|
||||||
disabled={processing}
|
|
||||||
>
|
|
||||||
<Save className="w-4 h-4 mr-2" />
|
|
||||||
暫存進度
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
className="button-filled-primary"
|
|
||||||
onClick={() => handleSubmit('complete')}
|
|
||||||
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>
|
|
||||||
|
|
||||||
<div className="max-w-7xl mx-auto space-y-6">
|
|
||||||
{!isCompleted && (
|
{!isCompleted && (
|
||||||
<Card className="border-none shadow-sm overflow-hidden">
|
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||||
<CardContent className="py-4">
|
<div className="flex items-center justify-between text-sm">
|
||||||
<div className="flex items-center justify-between text-sm mb-2">
|
<span className="text-gray-500 font-medium">盤點進度: {countedItems} / {totalItems} 項目</span>
|
||||||
<span className="text-gray-500">盤點進度: {countedItems} / {totalItems} 項目</span>
|
<span className="font-bold text-primary-main">{progress}%</span>
|
||||||
<span className="font-semibold text-primary-main">{progress}%</span>
|
</div>
|
||||||
</div>
|
<div className="w-full bg-gray-200 rounded-full h-2">
|
||||||
<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 className="bg-primary-main h-2 rounded-full transition-all duration-300" style={{ width: `${progress}%` }}></div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Card className="border border-gray-200 shadow-sm overflow-hidden gap-0">
|
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||||
<CardHeader className="bg-white border-b px-6 py-4">
|
<div className="flex items-center justify-between">
|
||||||
<CardTitle className="text-lg font-medium">盤點明細</CardTitle>
|
<div>
|
||||||
<CardDescription>
|
<h3 className="font-semibold text-lg text-grey-900">盤點明細</h3>
|
||||||
請輸入每個項目的「實盤數量」。若有差異系統將自動計算。
|
<p className="text-sm text-grey-500">
|
||||||
</CardDescription>
|
請輸入每個項目的「實盤數量」。若有差異系統將自動計算。
|
||||||
</CardHeader>
|
</p>
|
||||||
<Table>
|
</div>
|
||||||
<TableHeader className="bg-gray-50">
|
</div>
|
||||||
<TableRow>
|
|
||||||
<TableHead className="w-[50px] text-center">#</TableHead>
|
<div className="border rounded-lg overflow-hidden">
|
||||||
<TableHead>商品代號 / 名稱</TableHead>
|
<Table>
|
||||||
<TableHead>批號</TableHead>
|
<TableHeader className="bg-gray-50">
|
||||||
<TableHead className="text-right">系統庫存</TableHead>
|
<TableRow>
|
||||||
<TableHead className="text-right w-32">實盤數量</TableHead>
|
<TableHead className="w-[50px] text-center font-medium text-grey-600">#</TableHead>
|
||||||
<TableHead className="text-right">差異</TableHead>
|
<TableHead className="font-medium text-grey-600">商品名稱 / 代號</TableHead>
|
||||||
<TableHead>單位</TableHead>
|
<TableHead className="font-medium text-grey-600">批號</TableHead>
|
||||||
<TableHead>備註</TableHead>
|
<TableHead className="text-right font-medium text-grey-600">系統庫存</TableHead>
|
||||||
</TableRow>
|
<TableHead className="text-right w-32 font-medium text-grey-600">實盤數量</TableHead>
|
||||||
</TableHeader>
|
<TableHead className="text-right font-medium text-grey-600">差異</TableHead>
|
||||||
<TableBody>
|
<TableHead className="font-medium text-grey-600">單位</TableHead>
|
||||||
{doc.items.map((item: any, index: number) => {
|
<TableHead className="font-medium text-grey-600">備註</TableHead>
|
||||||
const formItem = data.items[index];
|
</TableRow>
|
||||||
const diff = formItem.counted_qty !== '' && formItem.counted_qty !== null
|
</TableHeader>
|
||||||
? (parseFloat(formItem.counted_qty) - item.system_qty)
|
<TableBody>
|
||||||
: 0;
|
{doc.items.map((item: any, index: number) => {
|
||||||
const hasDiff = Math.abs(diff) > 0.0001;
|
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>
|
||||||
|
|
||||||
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>
|
|
||||||
<div className="flex flex-col">
|
|
||||||
<span className="font-medium text-gray-900">{item.product_code}</span>
|
|
||||||
<span className="text-xs text-gray-500">{item.product_name}</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">
|
|
||||||
{isCompleted ? (
|
|
||||||
<span className="font-medium 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>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<div className="bg-gray-50/80 border border-dashed border-grey-200 rounded-lg p-4 flex items-start gap-3">
|
<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">
|
<div className="bg-blue-100 p-2 rounded-lg">
|
||||||
@@ -264,7 +265,7 @@ export default function Show({ doc }: any) {
|
|||||||
<h4 className="font-semibold text-gray-900 mb-1 text-sm">操作導引</h4>
|
<h4 className="font-semibold text-gray-900 mb-1 text-sm">操作導引</h4>
|
||||||
<p className="text-xs text-gray-500 leading-relaxed">
|
<p className="text-xs text-gray-500 leading-relaxed">
|
||||||
資料會自動保存盤點人與時間。若尚未盤點完,您可以點擊「暫存進度」稍後繼續。
|
資料會自動保存盤點人與時間。若尚未盤點完,您可以點擊「暫存進度」稍後繼續。
|
||||||
確認所有項目資料正確後,請點擊「完成盤點並過帳」正式生效庫存調整。
|
確認所有項目資料正確後,請點擊「完成盤點」結束盤點作業。
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user