feat(inventory): 統一庫存調整與調撥模組 UI,實作多選、搜尋與明細欄位重構
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, Link, router } from "@inertiajs/react";
|
||||
import { debounce } from "lodash";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -20,41 +22,94 @@ import {
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
DialogFooter,
|
||||
DialogDescription,
|
||||
} from "@/Components/ui/dialog";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/Components/ui/select";
|
||||
import { Label } from "@/Components/ui/label";
|
||||
import {
|
||||
Plus,
|
||||
Search,
|
||||
FileText,
|
||||
ArrowLeftRight,
|
||||
Loader2,
|
||||
Eye,
|
||||
Pencil,
|
||||
Trash2,
|
||||
X,
|
||||
} from "lucide-react";
|
||||
import { format } from "date-fns";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { toast } from "sonner";
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
|
||||
export default function Index({ auth, orders, warehouses, filters }) {
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
export default function Index({ warehouses, orders, filters }: any) {
|
||||
const [searchTerm, setSearchTerm] = useState(filters.search || "");
|
||||
const [warehouseFilter, setWarehouseFilter] = useState(filters.warehouse_id || "all");
|
||||
const [perPage, setPerPage] = useState(filters.per_page || "10");
|
||||
|
||||
// Sync state with props
|
||||
useEffect(() => {
|
||||
setSearchTerm(filters.search || "");
|
||||
setWarehouseFilter(filters.warehouse_id || "all");
|
||||
setPerPage(filters.per_page || "10");
|
||||
}, [filters]);
|
||||
|
||||
// Create Dialog State
|
||||
const [isCreateOpen, setIsCreateOpen] = useState(false);
|
||||
const [sourceWarehouseId, setSourceWarehouseId] = useState("");
|
||||
const [targetWarehouseId, setTargetWarehouseId] = useState("");
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
|
||||
// Handle warehouse filter change
|
||||
const handleFilterChange = (value) => {
|
||||
router.get(route('inventory.transfer.index'), { warehouse_id: value }, {
|
||||
preserveState: true,
|
||||
replace: true,
|
||||
});
|
||||
// Debounced Search Handler
|
||||
const debouncedSearch = useCallback(
|
||||
debounce((term: string, warehouse: string) => {
|
||||
router.get(
|
||||
route('inventory.transfer.index'),
|
||||
{ ...filters, search: term, warehouse_id: warehouse === "all" ? "" : warehouse },
|
||||
{ preserveState: true, replace: true, preserveScroll: true }
|
||||
);
|
||||
}, 500),
|
||||
[filters]
|
||||
);
|
||||
|
||||
const handleSearchChange = (term: string) => {
|
||||
setSearchTerm(term);
|
||||
debouncedSearch(term, warehouseFilter);
|
||||
};
|
||||
|
||||
const handleFilterChange = (value: string) => {
|
||||
setWarehouseFilter(value);
|
||||
router.get(
|
||||
route('inventory.transfer.index'),
|
||||
{ ...filters, warehouse_id: value === "all" ? "" : value },
|
||||
{ preserveState: false, replace: true, preserveScroll: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleClearSearch = () => {
|
||||
setSearchTerm("");
|
||||
router.get(
|
||||
route('inventory.transfer.index'),
|
||||
{ ...filters, search: "", warehouse_id: warehouseFilter === "all" ? "" : warehouseFilter },
|
||||
{ preserveState: true, replace: true, preserveScroll: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handlePerPageChange = (value: string) => {
|
||||
setPerPage(value);
|
||||
router.get(
|
||||
route('inventory.transfer.index'),
|
||||
{ ...filters, per_page: value },
|
||||
{ preserveState: false, replace: true, preserveScroll: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleCreate = () => {
|
||||
@@ -84,12 +139,28 @@ export default function Index({ auth, orders, warehouses, filters }) {
|
||||
});
|
||||
};
|
||||
|
||||
const getStatusBadge = (status) => {
|
||||
const confirmDelete = (id: string) => {
|
||||
setDeleteId(id);
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (deleteId) {
|
||||
router.delete(route('inventory.transfer.destroy', [deleteId]), {
|
||||
onSuccess: () => {
|
||||
setDeleteId(null);
|
||||
toast.success("已成功刪除");
|
||||
},
|
||||
onError: () => setDeleteId(null),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const getStatusBadge = (status: string) => {
|
||||
switch (status) {
|
||||
case 'draft':
|
||||
return <Badge variant="secondary">草稿</Badge>;
|
||||
case 'completed':
|
||||
return <Badge className="bg-green-600">已完成</Badge>;
|
||||
return <Badge className="bg-green-500 hover:bg-green-600">已完成</Badge>;
|
||||
case 'voided':
|
||||
return <Badge variant="destructive">已作廢</Badge>;
|
||||
default:
|
||||
@@ -99,92 +170,103 @@ export default function Index({ auth, orders, warehouses, filters }) {
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
user={auth.user}
|
||||
header={
|
||||
<div className="flex justify-between items-center">
|
||||
<h2 className="font-semibold text-xl text-gray-800 leading-tight flex items-center gap-2">
|
||||
<ArrowLeftRight className="h-5 w-5" />
|
||||
庫存調撥
|
||||
</h2>
|
||||
</div>
|
||||
}
|
||||
breadcrumbs={[
|
||||
{ label: '商品與庫存與管理', href: '#' },
|
||||
{ label: '庫存調撥', href: route('inventory.transfer.index'), isPage: true },
|
||||
]}
|
||||
>
|
||||
<Head title="庫存調撥" />
|
||||
|
||||
<div className="py-12">
|
||||
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<div className="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div className="p-6">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="w-[200px]">
|
||||
<Select
|
||||
value={filters.warehouse_id || "all"}
|
||||
onValueChange={(val) => handleFilterChange(val === "all" ? "" : val)}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="篩選倉庫..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">所有倉庫</SelectItem>
|
||||
{warehouses.map((w) => (
|
||||
<SelectItem key={w.id} value={String(w.id)}>{w.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="relative flex-1 max-w-sm">
|
||||
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-500" />
|
||||
<Input
|
||||
placeholder="搜尋調撥單號..."
|
||||
className="pl-9"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<ArrowLeftRight className="h-6 w-6 text-primary-main" />
|
||||
庫存調撥管理
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
建立與管理倉庫間的商品調撥單,追蹤庫存轉移紀錄。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<div className="bg-white rounded-lg shadow-sm border p-4 mb-6">
|
||||
<div className="flex flex-col md:flex-row gap-4">
|
||||
{/* Search */}
|
||||
<div className="flex-1 relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4" />
|
||||
<Input
|
||||
placeholder="搜尋調撥單號、備註..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => handleSearchChange(e.target.value)}
|
||||
className="pl-10 pr-10 h-9"
|
||||
/>
|
||||
{searchTerm && (
|
||||
<button
|
||||
onClick={handleClearSearch}
|
||||
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Warehouse Filter */}
|
||||
<SearchableSelect
|
||||
value={warehouseFilter}
|
||||
onValueChange={handleFilterChange}
|
||||
options={[
|
||||
{ label: "所有倉庫", value: "all" },
|
||||
...warehouses.map((w: any) => ({ label: w.name, value: w.id.toString() }))
|
||||
]}
|
||||
placeholder="選擇倉庫"
|
||||
className="w-full md:w-[200px] h-9"
|
||||
/>
|
||||
|
||||
{/* Action Buttons */}
|
||||
<div className="flex gap-2 w-full md:w-auto">
|
||||
<Can permission="inventory.view">
|
||||
<Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
<Button className="flex-1 md:flex-none button-filled-primary">
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
新增調撥單
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>建立新調撥單</DialogTitle>
|
||||
<DialogDescription>
|
||||
請選擇來源倉庫與目的倉庫。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="grid gap-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<Label>來源倉庫</Label>
|
||||
<Select onValueChange={setSourceWarehouseId} value={sourceWarehouseId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="選擇來源倉庫" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{warehouses.map(w => (
|
||||
<SelectItem key={w.id} value={String(w.id)}>{w.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<SearchableSelect
|
||||
value={sourceWarehouseId}
|
||||
onValueChange={setSourceWarehouseId}
|
||||
options={warehouses.map((w: any) => ({ label: w.name, value: w.id.toString() }))}
|
||||
placeholder="請選擇來源倉庫"
|
||||
className="h-9"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>目的倉庫</Label>
|
||||
<Select onValueChange={setTargetWarehouseId} value={targetWarehouseId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="選擇目的倉庫" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{warehouses.filter(w => String(w.id) !== sourceWarehouseId).map(w => (
|
||||
<SelectItem key={w.id} value={String(w.id)}>{w.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<SearchableSelect
|
||||
value={targetWarehouseId}
|
||||
onValueChange={setTargetWarehouseId}
|
||||
options={warehouses.filter((w: any) => w.id.toString() !== sourceWarehouseId).map((w: any) => ({ label: w.name, value: w.id.toString() }))}
|
||||
placeholder="請選擇目的倉庫"
|
||||
className="h-9"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" className="button-outlined-primary" onClick={() => setIsCreateOpen(false)}>取消</Button>
|
||||
<Button type="button" variant="outline" className="button-outlined-primary" onClick={() => setIsCreateOpen(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleCreate} className="button-filled-primary" disabled={creating || !sourceWarehouseId || !targetWarehouseId}>
|
||||
{creating && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
||||
新增
|
||||
@@ -192,63 +274,125 @@ export default function Index({ auth, orders, warehouses, filters }) {
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>單號</TableHead>
|
||||
<TableHead>狀態</TableHead>
|
||||
<TableHead>來源倉庫</TableHead>
|
||||
<TableHead>目的倉庫</TableHead>
|
||||
<TableHead>建立日期</TableHead>
|
||||
<TableHead>過帳日期</TableHead>
|
||||
<TableHead>建立人員</TableHead>
|
||||
<TableHead className="text-right">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{orders.data.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} className="text-center h-24 text-gray-500">
|
||||
尚無調撥單
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
orders.data.map((order) => (
|
||||
<TableRow key={order.id}>
|
||||
<TableCell className="font-medium">{order.doc_no}</TableCell>
|
||||
<TableCell>{getStatusBadge(order.status)}</TableCell>
|
||||
<TableCell>{order.from_warehouse_name}</TableCell>
|
||||
<TableCell>{order.to_warehouse_name}</TableCell>
|
||||
<TableCell>{order.created_at}</TableCell>
|
||||
<TableCell>{order.posted_at}</TableCell>
|
||||
<TableCell>{order.created_by}</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
asChild
|
||||
>
|
||||
<Link href={route('inventory.transfer.show', [order.id])}>
|
||||
查看
|
||||
</Link>
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<Pagination links={orders.links} />
|
||||
</div>
|
||||
</Can>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader className="bg-gray-50">
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px] text-center font-medium text-gray-600">#</TableHead>
|
||||
<TableHead className="font-medium text-gray-600">單號</TableHead>
|
||||
<TableHead className="text-center font-medium text-gray-600">狀態</TableHead>
|
||||
<TableHead className="font-medium text-gray-600">來源倉庫</TableHead>
|
||||
<TableHead className="font-medium text-gray-600">目的倉庫</TableHead>
|
||||
<TableHead className="font-medium text-gray-600">建立日期</TableHead>
|
||||
<TableHead className="font-medium text-gray-600">過帳日期</TableHead>
|
||||
<TableHead className="font-medium text-gray-600">建立人員</TableHead>
|
||||
<TableHead className="text-center font-medium text-gray-600">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{orders.data.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={9} className="text-center h-24 text-gray-500">
|
||||
尚無調撥紀錄
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
orders.data.map((order: any, index: number) => (
|
||||
<TableRow
|
||||
key={order.id}
|
||||
className="hover:bg-gray-50/50 transition-colors cursor-pointer group"
|
||||
onClick={() => router.visit(route('inventory.transfer.show', [order.id]))}
|
||||
>
|
||||
<TableCell className="text-center text-gray-500 font-medium">
|
||||
{(orders.current_page - 1) * orders.per_page + index + 1}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium text-primary-main">{order.doc_no}</TableCell>
|
||||
<TableCell className="text-center">{getStatusBadge(order.status)}</TableCell>
|
||||
<TableCell className="text-gray-700">{order.from_warehouse_name}</TableCell>
|
||||
<TableCell className="text-gray-700">{order.to_warehouse_name}</TableCell>
|
||||
<TableCell className="text-gray-500 text-sm">{order.created_at}</TableCell>
|
||||
<TableCell className="text-gray-500 text-sm">{order.posted_at || '-'}</TableCell>
|
||||
<TableCell className="text-sm">{order.created_by}</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<div className="flex items-center justify-center gap-2" onClick={(e) => e.stopPropagation()}>
|
||||
<Can permission="inventory.view">
|
||||
<Link href={route('inventory.transfer.show', [order.id])}>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
title={['completed', 'voided'].includes(order.status) ? '查閱' : '編輯'}
|
||||
>
|
||||
{['completed', 'voided'].includes(order.status) ? (
|
||||
<Eye className="w-4 h-4 ml-0.5" />
|
||||
) : (
|
||||
<Pencil className="w-4 h-4 ml-0.5" />
|
||||
)}
|
||||
</Button>
|
||||
</Link>
|
||||
{order.status === 'draft' && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-error"
|
||||
title="刪除"
|
||||
onClick={() => confirmDelete(order.id)}
|
||||
>
|
||||
<Trash2 className="w-4 h-4 ml-0.5" />
|
||||
</Button>
|
||||
)}
|
||||
</Can>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="flex items-center gap-2 text-sm text-gray-500">
|
||||
<span>每頁顯示</span>
|
||||
<SearchableSelect
|
||||
value={perPage}
|
||||
onValueChange={handlePerPageChange}
|
||||
options={[
|
||||
{ label: "10", value: "10" },
|
||||
{ label: "20", value: "20" },
|
||||
{ label: "50", value: "50" },
|
||||
{ label: "100", value: "100" }
|
||||
]}
|
||||
className="w-[100px] h-8"
|
||||
showSearch={false}
|
||||
/>
|
||||
<span>筆</span>
|
||||
</div>
|
||||
<span className="text-sm text-gray-500">共 {orders.total} 筆紀錄</span>
|
||||
</div>
|
||||
<Pagination links={orders.links} />
|
||||
</div>
|
||||
|
||||
<AlertDialog open={!!deleteId} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<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>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
import { Head, router, usePage, Link } from "@inertiajs/react";
|
||||
import { Head, router, Link } from "@inertiajs/react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import { Input } from "@/Components/ui/input";
|
||||
import { Label } from "@/Components/ui/label";
|
||||
import { Textarea } from "@/Components/ui/textarea";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -15,38 +14,49 @@ import {
|
||||
TableRow,
|
||||
} from "@/Components/ui/table";
|
||||
import { Badge } from "@/Components/ui/badge";
|
||||
import { Checkbox } from "@/Components/ui/checkbox";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
DialogFooter,
|
||||
} from "@/Components/ui/dialog";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/Components/ui/select";
|
||||
import { Plus, Save, Trash2, ArrowLeft, CheckCircle, Ban, History, Package } from "lucide-react";
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import { Plus, Save, Trash2, ArrowLeft, CheckCircle, Package, ArrowLeftRight, Printer, Search } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import axios from "axios";
|
||||
import { Can } from '@/Components/Permission/Can';
|
||||
|
||||
export default function Show({ auth, order }) {
|
||||
export default function Show({ order }: any) {
|
||||
const [items, setItems] = useState(order.items || []);
|
||||
const [remarks, setRemarks] = useState(order.remarks || "");
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
const [isPostDialogOpen, setIsPostDialogOpen] = useState(false);
|
||||
|
||||
// Product Selection
|
||||
const [isProductDialogOpen, setIsProductDialogOpen] = useState(false);
|
||||
const [availableInventory, setAvailableInventory] = useState([]);
|
||||
const [availableInventory, setAvailableInventory] = useState<any[]>([]);
|
||||
const [loadingInventory, setLoadingInventory] = useState(false);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [selectedInventory, setSelectedInventory] = useState<string[]>([]); // product_id-batch
|
||||
|
||||
useEffect(() => {
|
||||
if (isProductDialogOpen) {
|
||||
loadInventory();
|
||||
setSelectedInventory([]);
|
||||
setSearchQuery('');
|
||||
}
|
||||
}, [isProductDialogOpen]);
|
||||
|
||||
@@ -64,39 +74,75 @@ export default function Show({ auth, order }) {
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddItem = (inventoryItem) => {
|
||||
// Check if already added
|
||||
const exists = items.find(i =>
|
||||
i.product_id === inventoryItem.product_id &&
|
||||
i.batch_number === inventoryItem.batch_number
|
||||
const toggleSelect = (key: string) => {
|
||||
setSelectedInventory(prev =>
|
||||
prev.includes(key) ? prev.filter(k => k !== key) : [...prev, key]
|
||||
);
|
||||
|
||||
if (exists) {
|
||||
toast.error("該商品與批號已在列表中");
|
||||
return;
|
||||
}
|
||||
|
||||
setItems([...items, {
|
||||
product_id: inventoryItem.product_id,
|
||||
product_name: inventoryItem.product_name,
|
||||
product_code: inventoryItem.product_code,
|
||||
batch_number: inventoryItem.batch_number,
|
||||
unit: inventoryItem.unit_name,
|
||||
quantity: 1, // Default 1
|
||||
max_quantity: inventoryItem.quantity, // Max available
|
||||
notes: "",
|
||||
}]);
|
||||
setIsProductDialogOpen(false);
|
||||
};
|
||||
|
||||
const handleUpdateItem = (index, field, value) => {
|
||||
const toggleSelectAll = () => {
|
||||
const filtered = availableInventory.filter(inv =>
|
||||
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
const filteredKeys = filtered.map(inv => `${inv.product_id}-${inv.batch_number}`);
|
||||
|
||||
if (filteredKeys.length > 0 && filteredKeys.every(k => selectedInventory.includes(k))) {
|
||||
setSelectedInventory(prev => prev.filter(k => !filteredKeys.includes(k)));
|
||||
} else {
|
||||
setSelectedInventory(prev => Array.from(new Set([...prev, ...filteredKeys])));
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddSelected = () => {
|
||||
if (selectedInventory.length === 0) return;
|
||||
|
||||
const newItems = [...items];
|
||||
let addedCount = 0;
|
||||
|
||||
availableInventory.forEach(inv => {
|
||||
const key = `${inv.product_id}-${inv.batch_number}`;
|
||||
if (selectedInventory.includes(key)) {
|
||||
// Check if already added
|
||||
const exists = newItems.find((i: any) =>
|
||||
i.product_id === inv.product_id &&
|
||||
i.batch_number === inv.batch_number
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
newItems.push({
|
||||
product_id: inv.product_id,
|
||||
product_name: inv.product_name,
|
||||
product_code: inv.product_code,
|
||||
batch_number: inv.batch_number,
|
||||
unit: inv.unit_name,
|
||||
quantity: 1, // Default 1
|
||||
max_quantity: inv.quantity, // Max available
|
||||
notes: "",
|
||||
});
|
||||
addedCount++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setItems(newItems);
|
||||
setIsProductDialogOpen(false);
|
||||
|
||||
if (addedCount > 0) {
|
||||
toast.success(`已成功加入 ${addedCount} 個項目`);
|
||||
} else {
|
||||
toast.info("選取的商品已在清單中");
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdateItem = (index: number, field: string, value: any) => {
|
||||
const newItems = [...items];
|
||||
newItems[index][field] = value;
|
||||
setItems(newItems);
|
||||
};
|
||||
|
||||
const handleRemoveItem = (index) => {
|
||||
const newItems = items.filter((_, i) => i !== index);
|
||||
const handleRemoveItem = (index: number) => {
|
||||
const newItems = items.filter((_: any, i: number) => i !== index);
|
||||
setItems(newItems);
|
||||
};
|
||||
|
||||
@@ -116,32 +162,39 @@ export default function Show({ auth, order }) {
|
||||
};
|
||||
|
||||
const handlePost = () => {
|
||||
if (!confirm("確定要過帳嗎?過帳後庫存將立即轉移且無法修改。")) return;
|
||||
router.put(route('inventory.transfer.update', [order.id]), {
|
||||
action: 'post'
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
setIsPostDialogOpen(false);
|
||||
toast.success("過帳成功");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
if (!confirm("確定要刪除此草稿嗎?")) return;
|
||||
router.delete(route('inventory.transfer.destroy', [order.id]));
|
||||
router.delete(route('inventory.transfer.destroy', [order.id]), {
|
||||
onSuccess: () => {
|
||||
setDeleteId(null);
|
||||
toast.success("已成功刪除");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const isReadOnly = order.status !== 'draft';
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
user={auth.user}
|
||||
breadcrumbs={[
|
||||
{ label: '首頁', href: '/' },
|
||||
{ label: '商品與庫存管理', href: '#' },
|
||||
{ label: '庫存調撥', href: route('inventory.transfer.index') },
|
||||
{ label: order.doc_no, href: route('inventory.transfer.show', [order.id]) },
|
||||
{ label: `調撥單: ${order.doc_no}`, href: route('inventory.transfer.show', [order.id]), isPage: true },
|
||||
]}
|
||||
>
|
||||
<Head title={`調撥單 ${order.doc_no}`} />
|
||||
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<div className="mb-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.transfer.index')}>
|
||||
<Button
|
||||
variant="outline"
|
||||
@@ -152,192 +205,335 @@ export default function Show({ auth, order }) {
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex justify-between items-center">
|
||||
<h2 className="font-bold text-2xl text-gray-800 leading-tight flex items-center gap-2">
|
||||
調撥單詳情 ({order.doc_no})
|
||||
</h2>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<ArrowLeftRight className="h-6 w-6 text-primary-main" />
|
||||
調撥單: {order.doc_no}
|
||||
</h1>
|
||||
{order.status === 'completed' && <Badge className="bg-green-500 hover:bg-green-600">已完成</Badge>}
|
||||
{order.status === 'draft' && <Badge className="bg-blue-500 hover:bg-blue-600">草稿</Badge>}
|
||||
{order.status === 'voided' && <Badge variant="destructive">已作廢</Badge>}
|
||||
</div>
|
||||
<p className="text-sm text-gray-500 mt-1 font-medium">
|
||||
來源: {order.from_warehouse_name} <ArrowLeftRight className="inline-block h-3 w-3 mx-1" /> 目的: {order.to_warehouse_name} <span className="mx-2">|</span> 建立人: {order.created_by}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="button-outlined-primary"
|
||||
onClick={() => window.print()}
|
||||
>
|
||||
<Printer className="w-4 h-4 mr-2" />
|
||||
列印
|
||||
</Button>
|
||||
|
||||
{!isReadOnly && (
|
||||
<>
|
||||
<Button variant="destructive" onClick={handleDelete}>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
刪除
|
||||
</Button>
|
||||
<Button variant="outline" onClick={handleSave} disabled={isSaving}>
|
||||
<Save className="h-4 w-4 mr-2" />
|
||||
儲存草稿
|
||||
</Button>
|
||||
<Button onClick={handlePost} disabled={items.length === 0}>
|
||||
<CheckCircle className="h-4 w-4 mr-2" />
|
||||
確認過帳
|
||||
</Button>
|
||||
</>
|
||||
<div className="flex items-center gap-2">
|
||||
<Can permission="inventory.view">
|
||||
<AlertDialog open={!!deleteId} onOpenChange={(open) => !open && setDeleteId(null)}>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="button-outlined-error" onClick={() => setDeleteId(order.id)}>
|
||||
<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={handleSave}
|
||||
disabled={isSaving}
|
||||
>
|
||||
<Save className="w-4 h-4 mr-2" />
|
||||
儲存草稿
|
||||
</Button>
|
||||
|
||||
<AlertDialog open={isPostDialogOpen} onOpenChange={setIsPostDialogOpen}>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button
|
||||
size="sm"
|
||||
className="button-filled-primary"
|
||||
disabled={items.length === 0 || isSaving}
|
||||
>
|
||||
<CheckCircle className="w-4 h-4 mr-2" />
|
||||
確認過帳
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確定要過帳嗎?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
過帳後庫存將立即從「{order.from_warehouse_name}」轉移至「{order.to_warehouse_name}」,且無法再進行修改。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handlePost} className="bg-primary-600 hover:bg-primary-700">確認過帳</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</Can>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
{/* Header Info */}
|
||||
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-100 grid grid-cols-1 md:grid-cols-4 gap-6">
|
||||
<div>
|
||||
<Label className="text-gray-500">來源倉庫</Label>
|
||||
<div className="font-medium text-lg">{order.from_warehouse_name}</div>
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-gray-500 font-semibold">備註資訊</Label>
|
||||
</div>
|
||||
{isReadOnly ? (
|
||||
<div className="text-gray-700 p-2 bg-gray-50 rounded border text-sm min-h-[40px]">
|
||||
{order.remarks || '無備註'}
|
||||
</div>
|
||||
) : (
|
||||
<Input
|
||||
value={remarks}
|
||||
onChange={(e) => setRemarks(e.target.value)}
|
||||
className="h-9 focus:ring-primary-main"
|
||||
placeholder="填寫調撥單備註..."
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg shadow-sm border p-6 space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<Label className="text-gray-500">目的倉庫</Label>
|
||||
<div className="font-medium text-lg">{order.to_warehouse_name}</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-gray-500">狀態</Label>
|
||||
<div className="mt-1">
|
||||
{order.status === 'draft' && <Badge variant="secondary">草稿</Badge>}
|
||||
{order.status === 'completed' && <Badge className="bg-green-600">已完成</Badge>}
|
||||
{order.status === 'voided' && <Badge variant="destructive">已作廢</Badge>}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-gray-500">備註</Label>
|
||||
{isReadOnly ? (
|
||||
<div className="mt-1 text-gray-700">{order.remarks || '-'}</div>
|
||||
) : (
|
||||
<Input
|
||||
value={remarks}
|
||||
onChange={(e) => setRemarks(e.target.value)}
|
||||
className="mt-1"
|
||||
placeholder="填寫備註..."
|
||||
/>
|
||||
)}
|
||||
<h3 className="font-semibold text-lg text-grey-900">調撥明細</h3>
|
||||
<p className="text-sm text-grey-500">
|
||||
請選擇要調撥的商品並輸入數量。所有商品將從「{order.from_warehouse_name}」轉出。
|
||||
</p>
|
||||
</div>
|
||||
{!isReadOnly && (
|
||||
<Dialog open={isProductDialogOpen} onOpenChange={setIsProductDialogOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline" className="button-outlined-primary">
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
加入商品
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-4xl max-h-[85vh] flex flex-col p-6">
|
||||
<DialogHeader className="flex flex-row items-center justify-between space-y-0 pb-4">
|
||||
<DialogTitle className="text-xl">選擇來源庫存 ({order.from_warehouse_name})</DialogTitle>
|
||||
<div className="relative w-64">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-grey-3" />
|
||||
<Input
|
||||
placeholder="搜尋品名或代號..."
|
||||
className="pl-9 h-9 border-2 border-grey-3 focus:ring-primary-main"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
<div className="flex-1 overflow-auto pr-1">
|
||||
{loadingInventory ? (
|
||||
<div className="text-center py-12">
|
||||
<Package className="h-10 w-10 animate-bounce mx-auto text-gray-300 mb-2" />
|
||||
<p className="text-grey-2 text-sm">庫存資料載入中...</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader className="bg-gray-50/80 sticky top-0 z-10 shadow-sm">
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px] text-center">
|
||||
<Checkbox
|
||||
checked={availableInventory.length > 0 && (() => {
|
||||
const filtered = availableInventory.filter(inv =>
|
||||
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
const filteredKeys = filtered.map(inv => `${inv.product_id}-${inv.batch_number}`);
|
||||
return filteredKeys.length > 0 && filteredKeys.every(k => selectedInventory.includes(k));
|
||||
})()}
|
||||
onCheckedChange={() => toggleSelectAll()}
|
||||
/>
|
||||
</TableHead>
|
||||
<TableHead className="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 pr-6">現有庫存</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{(() => {
|
||||
const filtered = availableInventory.filter(inv =>
|
||||
inv.product_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
inv.product_code.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
|
||||
if (filtered.length === 0) {
|
||||
return (
|
||||
<TableRow>
|
||||
<TableCell colSpan={5} className="text-center py-12 text-grey-3 italic font-medium">
|
||||
{searchQuery ? `找不到與 "${searchQuery}" 相關的商品` : '尚無庫存資料'}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
|
||||
return filtered.map((inv) => {
|
||||
const key = `${inv.product_id}-${inv.batch_number}`;
|
||||
const isSelected = selectedInventory.includes(key);
|
||||
return (
|
||||
<TableRow
|
||||
key={key}
|
||||
className={`hover:bg-primary-lightest/20 cursor-pointer transition-colors ${isSelected ? 'bg-primary-lightest/40' : ''}`}
|
||||
onClick={() => toggleSelect(key)}
|
||||
>
|
||||
<TableCell className="text-center" onClick={(e) => e.stopPropagation()}>
|
||||
<Checkbox
|
||||
checked={isSelected}
|
||||
onCheckedChange={() => toggleSelect(key)}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-sm text-grey-1">{inv.product_code}</TableCell>
|
||||
<TableCell className="font-semibold text-grey-0">{inv.product_name}</TableCell>
|
||||
<TableCell className="text-sm font-mono text-grey-2">{inv.batch_number || '-'}</TableCell>
|
||||
<TableCell className="text-right font-bold text-primary-main pr-6">{inv.quantity} {inv.unit_name}</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
});
|
||||
})()}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-6 flex items-center justify-between border-t pt-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="px-3 py-1 bg-primary-lightest/50 border border-primary-light/20 rounded-full text-sm font-medium text-primary-main animate-in zoom-in duration-200">
|
||||
已選取 {selectedInventory.length} 項商品
|
||||
</div>
|
||||
{selectedInventory.length > 0 && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="text-grey-3 hover:text-red-500 hover:bg-red-50 text-xs px-2 h-7"
|
||||
onClick={() => setSelectedInventory([])}
|
||||
>
|
||||
清除全部
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
className="button-outlined-primary w-24"
|
||||
onClick={() => setIsProductDialogOpen(false)}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
className="button-filled-primary min-w-32"
|
||||
disabled={selectedInventory.length === 0}
|
||||
onClick={handleAddSelected}
|
||||
>
|
||||
確認加入選取項
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Items */}
|
||||
<div className="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div className="p-6">
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<h3 className="text-lg font-semibold">調撥明細</h3>
|
||||
{!isReadOnly && (
|
||||
<Dialog open={isProductDialogOpen} onOpenChange={setIsProductDialogOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline">
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
加入商品
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-3xl max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>選擇來源庫存 ({order.from_warehouse_name})</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="mt-4">
|
||||
{loadingInventory ? (
|
||||
<div className="text-center py-4">載入中...</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 w-32 font-medium text-grey-600">可用庫存</TableHead>
|
||||
<TableHead className="text-right w-40 font-medium text-grey-600">調撥數量</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">單位</TableHead>
|
||||
<TableHead className="font-medium text-grey-600">備註</TableHead>
|
||||
{!isReadOnly && <TableHead className="w-[50px]"></TableHead>}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={8} className="text-center h-24 text-gray-500">
|
||||
尚未加入商品
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
items.map((item: any, index: number) => (
|
||||
<TableRow key={index}>
|
||||
<TableCell className="text-center text-gray-500 font-medium">{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-semibold text-primary-main">
|
||||
{item.max_quantity} {item.unit || item.unit_name}
|
||||
</TableCell>
|
||||
<TableCell className="px-1 py-3">
|
||||
{isReadOnly ? (
|
||||
<div className="text-right font-semibold mr-2">{item.quantity}</div>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>商品代號</TableHead>
|
||||
<TableHead>品名</TableHead>
|
||||
<TableHead>批號</TableHead>
|
||||
<TableHead className="text-right">現有庫存</TableHead>
|
||||
<TableHead></TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{availableInventory.map((inv) => (
|
||||
<TableRow key={`${inv.product_id}-${inv.batch_number}`}>
|
||||
<TableCell>{inv.product_code}</TableCell>
|
||||
<TableCell>{inv.product_name}</TableCell>
|
||||
<TableCell>{inv.batch_number || '-'}</TableCell>
|
||||
<TableCell className="text-right">{inv.quantity} {inv.unit_name}</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button size="sm" onClick={() => handleAddItem(inv)}>
|
||||
選取
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div className="flex flex-col gap-1 items-end pr-2">
|
||||
<Input
|
||||
type="number"
|
||||
min="0.01"
|
||||
step="0.01"
|
||||
value={item.quantity}
|
||||
onChange={(e) => handleUpdateItem(index, 'quantity', e.target.value)}
|
||||
className="h-9 w-32 text-right font-medium focus:ring-primary-main"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead className="w-[50px]">#</TableHead>
|
||||
<TableHead>商品</TableHead>
|
||||
<TableHead>批號</TableHead>
|
||||
<TableHead className="w-[150px]">調撥數量</TableHead>
|
||||
<TableHead>單位</TableHead>
|
||||
<TableHead>備註</TableHead>
|
||||
{!isReadOnly && <TableHead className="w-[50px]"></TableHead>}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-center h-24 text-gray-500">
|
||||
尚未加入商品
|
||||
</TableCell>
|
||||
<TableCell className="text-sm text-gray-500">{item.unit || item.unit_name}</TableCell>
|
||||
<TableCell className="px-1">
|
||||
{isReadOnly ? (
|
||||
<span className="text-sm text-gray-600">{item.notes}</span>
|
||||
) : (
|
||||
<Input
|
||||
value={item.notes}
|
||||
onChange={(e) => handleUpdateItem(index, 'notes', e.target.value)}
|
||||
placeholder="備註..."
|
||||
className="h-9 text-sm"
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
{!isReadOnly && (
|
||||
<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={() => handleRemoveItem(index)}>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
items.map((item, index) => (
|
||||
<TableRow key={index}>
|
||||
<TableCell>{index + 1}</TableCell>
|
||||
<TableCell>
|
||||
<div>{item.product_name}</div>
|
||||
<div className="text-xs text-gray-500">{item.product_code}</div>
|
||||
</TableCell>
|
||||
<TableCell>{item.batch_number || '-'}</TableCell>
|
||||
<TableCell>
|
||||
{isReadOnly ? (
|
||||
item.quantity
|
||||
) : (
|
||||
<div className="flex flex-col gap-1">
|
||||
<Input
|
||||
type="number"
|
||||
min="0.01"
|
||||
step="0.01"
|
||||
value={item.quantity}
|
||||
onChange={(e) => handleUpdateItem(index, 'quantity', e.target.value)}
|
||||
/>
|
||||
{item.max_quantity && (
|
||||
<span className="text-xs text-gray-500">上限: {item.max_quantity}</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>{item.unit}</TableCell>
|
||||
<TableCell>
|
||||
{isReadOnly ? (
|
||||
item.notes
|
||||
) : (
|
||||
<Input
|
||||
value={item.notes}
|
||||
onChange={(e) => handleUpdateItem(index, 'notes', e.target.value)}
|
||||
placeholder="備註"
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
{!isReadOnly && (
|
||||
<TableCell>
|
||||
<Button variant="ghost" size="icon" onClick={() => handleRemoveItem(index)}>
|
||||
<Trash2 className="h-4 w-4 text-red-500" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
)}
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user