feat: 實作銷售單匯入管理、貨道扣庫優化及 UI 細節調整
This commit is contained in:
@@ -140,15 +140,15 @@ export default function ViewGoodsReceiptPage({ receipt }: Props) {
|
||||
</div>
|
||||
|
||||
{/* 品項清單卡片 */}
|
||||
<div className="bg-white rounded-lg border shadow-sm overflow-hidden">
|
||||
<div className="p-6 border-b border-gray-100">
|
||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||
<div className="p-6 border-b border-gray-100 bg-gray-50/30">
|
||||
<h2 className="text-lg font-bold text-gray-900">進貨品項清單</h2>
|
||||
</div>
|
||||
<div className="p-0">
|
||||
<div className="overflow-x-auto">
|
||||
<div className="p-6">
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="bg-gray-50/50">
|
||||
<TableRow className="bg-gray-50 hover:bg-gray-50">
|
||||
<TableHead className="w-[80px] text-center">#</TableHead>
|
||||
<TableHead>商品名稱</TableHead>
|
||||
<TableHead className="text-right">進貨數量</TableHead>
|
||||
|
||||
90
resources/js/Pages/Sales/Import/Create.tsx
Normal file
90
resources/js/Pages/Sales/Import/Create.tsx
Normal file
@@ -0,0 +1,90 @@
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||
import { Head, useForm, Link } from '@inertiajs/react';
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import { Input } from '@/Components/ui/input';
|
||||
import { Label } from '@/Components/ui/label';
|
||||
import { Upload, ArrowLeft, FileSpreadsheet } from 'lucide-react';
|
||||
import React from 'react';
|
||||
|
||||
export default function SalesImportCreate() {
|
||||
const { data, setData, post, processing, errors } = useForm({
|
||||
file: null as File | null,
|
||||
});
|
||||
|
||||
const submit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
post(route('sales-imports.store'));
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
breadcrumbs={[
|
||||
{ label: '銷售管理', href: '#' },
|
||||
{ label: '銷售單匯入', href: route('sales-imports.index') },
|
||||
{ label: '新增匯入', href: route('sales-imports.create'), isPage: true },
|
||||
]}
|
||||
>
|
||||
<Head title="新增銷售匯入" />
|
||||
|
||||
<div className="container mx-auto p-6 max-w-3xl">
|
||||
<div className="mb-6">
|
||||
<Link href={route('sales-imports.index')}>
|
||||
<Button variant="outline" type="button" className="gap-2 mb-4">
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回列表
|
||||
</Button>
|
||||
</Link>
|
||||
<h1 className="text-2xl font-bold text-gray-900 flex items-center gap-2">
|
||||
<FileSpreadsheet className="h-6 w-6 text-primary-main" />
|
||||
新增銷售匯入
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg border shadow-sm p-8">
|
||||
<form onSubmit={submit} className="space-y-6">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="file" className="text-lg font-medium">上傳 Excel 檔案</Label>
|
||||
<div className="border-2 border-dashed border-gray-300 rounded-xl p-10 flex flex-col items-center justify-center bg-gray-50 hover:bg-gray-100 transition-colors cursor-pointer relative">
|
||||
<Input
|
||||
id="file"
|
||||
type="file"
|
||||
accept=".xlsx,.xls,.csv"
|
||||
onChange={(e) => setData('file', e.target.files ? e.target.files[0] : null)}
|
||||
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
||||
/>
|
||||
<Upload className="h-10 w-10 text-gray-400 mb-4" />
|
||||
<div className="text-center">
|
||||
<p className="text-sm font-medium text-gray-700">
|
||||
{data.file ? data.file.name : '點擊或拖曳檔案至此'}
|
||||
</p>
|
||||
<p className="text-xs text-gray-500 mt-1">支援 .xlsx, .xls, .csv</p>
|
||||
</div>
|
||||
</div>
|
||||
{errors.file && <p className="text-red-500 text-sm">{errors.file}</p>}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end pt-4">
|
||||
<Button
|
||||
type="submit"
|
||||
size="lg"
|
||||
className="button-filled-primary w-full md:w-auto px-8"
|
||||
disabled={processing}
|
||||
>
|
||||
{processing ? '處理中...' : '開始匯入'}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div className="mt-8 bg-blue-50 p-6 rounded-lg border border-blue-100">
|
||||
<h3 className="font-bold text-blue-800 mb-2">匯入說明</h3>
|
||||
<ul className="list-disc list-inside text-sm text-blue-700 space-y-1">
|
||||
<li>請使用統一的 Excel 格式(商品銷貨單)。</li>
|
||||
<li>系統將自動解析機台編號、商品代號與交易時間。</li>
|
||||
<li>匯入後請至「待確認」清單檢查內容,確認無誤後再執行扣庫。</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
}
|
||||
203
resources/js/Pages/Sales/Import/Index.tsx
Normal file
203
resources/js/Pages/Sales/Import/Index.tsx
Normal file
@@ -0,0 +1,203 @@
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/Components/ui/table';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import { Badge } from "@/Components/ui/badge";
|
||||
import { Plus, FileUp, Eye, Trash2 } from 'lucide-react';
|
||||
import { useState, useEffect } from "react";
|
||||
import { format } from 'date-fns';
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import { router } from "@inertiajs/react";
|
||||
|
||||
interface ImportBatch {
|
||||
id: number;
|
||||
import_date: string;
|
||||
status: 'pending' | 'confirmed';
|
||||
total_quantity: number;
|
||||
total_amount: number;
|
||||
importer?: {
|
||||
name: string;
|
||||
};
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
batches: {
|
||||
data: ImportBatch[];
|
||||
links: any[]; // Pagination links
|
||||
};
|
||||
filters?: { // Add filters prop if not present, though we main need per_page state
|
||||
per_page?: string;
|
||||
}
|
||||
}
|
||||
|
||||
export default function SalesImportIndex({ batches, filters = {} }: Props) {
|
||||
const [perPage, setPerPage] = useState(filters?.per_page?.toString() || "10");
|
||||
|
||||
useEffect(() => {
|
||||
if (filters?.per_page) {
|
||||
setPerPage(filters.per_page.toString());
|
||||
}
|
||||
}, [filters?.per_page]);
|
||||
|
||||
const handlePerPageChange = (value: string) => {
|
||||
setPerPage(value);
|
||||
router.get(
|
||||
route("sales-imports.index"),
|
||||
{ per_page: value },
|
||||
{ preserveState: true, preserveScroll: true, replace: true }
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
breadcrumbs={[
|
||||
{ label: '銷售管理', href: '#' },
|
||||
{ label: '銷售單匯入', href: route('sales-imports.index'), isPage: true },
|
||||
]}
|
||||
>
|
||||
<Head title="銷售單匯入管理" />
|
||||
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900 flex items-center gap-2">
|
||||
<FileUp className="h-6 w-6 text-primary-main" />
|
||||
銷售單匯入管理
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">
|
||||
匯入並管理銷售出貨紀錄
|
||||
</p>
|
||||
</div>
|
||||
<Link href={route('sales-imports.create')}>
|
||||
<Button className="button-filled-primary gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
新增匯入
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="bg-white rounded-lg border shadow-sm overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader className="bg-gray-50">
|
||||
<TableRow>
|
||||
<TableHead className="w-[100px]">ID</TableHead>
|
||||
<TableHead>匯入日期</TableHead>
|
||||
<TableHead>匯入人員</TableHead>
|
||||
<TableHead className="text-center w-[120px]">總數量</TableHead>
|
||||
<TableHead className="text-right w-[150px]">總金額</TableHead>
|
||||
<TableHead className="text-center w-[100px]">狀態</TableHead>
|
||||
<TableHead className="text-center w-[120px]">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{batches.data.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-center py-8 text-gray-500">
|
||||
尚無匯入紀錄
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
batches.data.map((batch) => (
|
||||
<TableRow key={batch.id} className="hover:bg-gray-50/50">
|
||||
<TableCell className="font-medium">#{batch.id}</TableCell>
|
||||
<TableCell>
|
||||
{format(new Date(batch.created_at), 'yyyy/MM/dd HH:mm')}
|
||||
</TableCell>
|
||||
<TableCell>{batch.importer?.name || '--'}</TableCell>
|
||||
<TableCell className="text-center font-bold text-gray-900">
|
||||
{Math.floor(batch.total_quantity || 0).toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-bold text-primary-main">
|
||||
NT$ {Number(batch.total_amount || 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}
|
||||
</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<Badge variant={batch.status === 'confirmed' ? 'default' : 'secondary'}>
|
||||
{batch.status === 'confirmed' ? '已確認' : '待確認'}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex justify-center gap-2">
|
||||
<Link href={route('sales-imports.show', batch.id)}>
|
||||
<Button variant="outline" size="sm" className="button-outlined-primary" title="查看詳情">
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
</Link>
|
||||
{batch.status === 'pending' && (
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button variant="outline" size="sm" className="button-outlined-error" title="刪除">
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除匯入紀錄</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確定要刪除此筆匯入紀錄(#{batch.id})嗎?此操作將會移除所有相關的明細資料且無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
onClick={() => router.delete(route('sales-imports.destroy', batch.id), { preserveScroll: true })}
|
||||
>
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
)}
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between 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>
|
||||
<Pagination links={batches.links} />
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
}
|
||||
338
resources/js/Pages/Sales/Import/Show.tsx
Normal file
338
resources/js/Pages/Sales/Import/Show.tsx
Normal file
@@ -0,0 +1,338 @@
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
|
||||
import { Head, Link, useForm, router } from '@inertiajs/react'; // Add router import
|
||||
import { useState, useEffect } from "react";
|
||||
import { SearchableSelect } from "@/Components/ui/searchable-select";
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from '@/Components/ui/table';
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
} from "@/Components/ui/alert-dialog";
|
||||
import { Badge } from "@/Components/ui/badge";
|
||||
import { ArrowLeft, CheckCircle, Trash2, Printer } from 'lucide-react';
|
||||
import { format } from 'date-fns';
|
||||
import Pagination from "@/Components/shared/Pagination";
|
||||
|
||||
interface ImportItem {
|
||||
id: number;
|
||||
transaction_serial: string;
|
||||
machine_id: string;
|
||||
slot: string | null;
|
||||
product_code: string;
|
||||
product_id: number | null;
|
||||
product?: {
|
||||
name: string;
|
||||
};
|
||||
quantity: number;
|
||||
amount: number;
|
||||
transaction_at: string;
|
||||
original_status: string;
|
||||
warehouse?: {
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface ImportBatch {
|
||||
id: number;
|
||||
import_date: string;
|
||||
status: 'pending' | 'confirmed';
|
||||
total_quantity: number;
|
||||
total_amount: number;
|
||||
items: ImportItem[]; // Note: items might be paginated in props, handled below
|
||||
created_at: string;
|
||||
confirmed_at?: string;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
import: ImportBatch;
|
||||
items: {
|
||||
data: ImportItem[];
|
||||
links: any[];
|
||||
current_page: number;
|
||||
per_page: number;
|
||||
total: number;
|
||||
};
|
||||
filters?: {
|
||||
per_page?: string;
|
||||
};
|
||||
flash?: {
|
||||
success?: string;
|
||||
error?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default function SalesImportShow({ import: batch, items, filters = {} }: Props) {
|
||||
const { post, processing } = useForm({});
|
||||
const [perPage, setPerPage] = useState(filters?.per_page?.toString() || "10");
|
||||
|
||||
// Sync state with prop if it changes via navigation
|
||||
useEffect(() => {
|
||||
if (filters?.per_page) {
|
||||
setPerPage(filters.per_page.toString());
|
||||
}
|
||||
}, [filters?.per_page]);
|
||||
|
||||
const handlePerPageChange = (value: string) => {
|
||||
setPerPage(value);
|
||||
router.get(
|
||||
route("sales-imports.show", batch.id),
|
||||
{ per_page: value },
|
||||
{ preserveState: true, preserveScroll: true, replace: true }
|
||||
);
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
post(route('sales-imports.confirm', batch.id));
|
||||
};
|
||||
|
||||
const handleDelete = () => {
|
||||
router.delete(route('sales-imports.destroy', batch.id));
|
||||
};
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
breadcrumbs={[
|
||||
{ label: '銷售管理', href: '#' },
|
||||
{ label: '銷售單匯入', href: route('sales-imports.index') },
|
||||
{ label: '匯入明細', href: '#', isPage: true },
|
||||
]}
|
||||
>
|
||||
<Head title={`匯入批次 #${batch.id}`} />
|
||||
|
||||
<div className="container mx-auto p-6 max-w-7xl">
|
||||
{/* Header */}
|
||||
<div className="mb-6">
|
||||
<Link href={route('sales-imports.index')}>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="gap-2 button-outlined-primary mb-6"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
返回銷售匯入列表
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
|
||||
<CheckCircle className="h-6 w-6 text-primary-main" />
|
||||
銷售匯入詳情
|
||||
</h1>
|
||||
<p className="text-gray-500 mt-1">批次編號:#{batch.id} | 匯入時間:{format(new Date(batch.created_at), 'yyyy/MM/dd HH:mm')}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Badge variant={batch.status === 'confirmed' ? 'default' : 'secondary'}>
|
||||
{batch.status === 'confirmed' ? '已確認' : '待確認'}
|
||||
</Badge>
|
||||
{batch.status === 'pending' && (
|
||||
<>
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="gap-2 button-outlined-error"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
刪除批次
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認刪除匯入紀錄</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確定要刪除此筆匯入紀錄(#{batch.id})嗎?此操作將會移除所有相關的明細資料且無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-red-600 hover:bg-red-700"
|
||||
onClick={handleDelete}
|
||||
>
|
||||
確認刪除
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
<AlertDialog>
|
||||
<AlertDialogTrigger asChild>
|
||||
<Button
|
||||
className="button-filled-primary gap-2"
|
||||
disabled={processing}
|
||||
>
|
||||
<CheckCircle className="h-4 w-4" />
|
||||
{processing ? '處理中...' : '確認並扣庫'}
|
||||
</Button>
|
||||
</AlertDialogTrigger>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>確認執行庫存扣取</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
確認要執行扣庫嗎?系統將會根據此匯入內容減少對應倉庫的商品庫存。此操作無法復原。
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>取消</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="button-filled-primary"
|
||||
onClick={handleConfirm}
|
||||
>
|
||||
確認執行
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
)}
|
||||
{batch.status === 'confirmed' && (
|
||||
<Button variant="outline" className="gap-2 button-outlined-primary">
|
||||
<Printer className="h-4 w-4" />
|
||||
列印報表
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-8">
|
||||
{/* 統計資訊卡片 */}
|
||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm p-6">
|
||||
<h2 className="text-lg font-bold text-gray-900 mb-6 border-b pb-4">統計資訊</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-x-8 gap-y-6">
|
||||
<div>
|
||||
<span className="text-sm text-gray-500 block mb-1 font-medium">總筆數</span>
|
||||
<span className="text-2xl font-bold text-gray-900">{Math.floor(batch.total_quantity || 0).toLocaleString()}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-sm text-gray-500 block mb-1 font-medium">總金額</span>
|
||||
<span className="text-2xl font-bold text-primary-main">
|
||||
NT$ {Number(batch.total_amount || 0).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-sm text-gray-500 block mb-1 font-medium">確認時間</span>
|
||||
<span className="text-2xl font-bold text-gray-900">
|
||||
{batch.confirmed_at ? format(new Date(batch.confirmed_at), 'yyyy/MM/dd HH:mm') : '--'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 匯入明細清單 */}
|
||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||
<div className="p-6 border-b border-gray-100 bg-gray-50/30">
|
||||
<h2 className="text-lg font-bold text-gray-900">匯入明細清單</h2>
|
||||
</div>
|
||||
<div className="p-6">
|
||||
<div className="border rounded-lg overflow-hidden">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="bg-gray-50 hover:bg-gray-50">
|
||||
<TableHead className="w-[80px] text-center">#</TableHead>
|
||||
<TableHead>交易序號 / 時間</TableHead>
|
||||
<TableHead>倉庫 (機台編號)</TableHead>
|
||||
<TableHead>商品代碼</TableHead>
|
||||
<TableHead>商品名稱</TableHead>
|
||||
<TableHead className="w-[120px] text-center">機台 / 貨道</TableHead>
|
||||
<TableHead className="text-center">原始狀態</TableHead>
|
||||
<TableHead className="text-right w-[100px]">數量</TableHead>
|
||||
<TableHead className="text-right">金額</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items.data.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={9} className="h-24 text-center text-gray-500">
|
||||
無匯入明細資料
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
items.data.map((item, index) => (
|
||||
<TableRow key={item.id}>
|
||||
<TableCell className="text-center text-gray-500">
|
||||
{(items.current_page - 1) * items.per_page + index + 1}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col">
|
||||
<span className="font-mono text-sm font-bold text-gray-900">{item.transaction_serial}</span>
|
||||
<span className="text-[10px] text-gray-400">
|
||||
{format(new Date(item.transaction_at), 'yyyy/MM/dd HH:mm:ss')}
|
||||
</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-sm font-medium text-gray-900">{item.warehouse?.name || '--'}</span>
|
||||
<span className="font-mono text-[10px] text-gray-400">{item.machine_id}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="font-mono text-sm font-bold text-gray-900">{item.product_code}</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="text-sm text-gray-600 truncate max-w-[200px]" title={item.product?.name}>
|
||||
{item.product?.name || '--'}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-center font-bold">
|
||||
{item.slot || '--'}
|
||||
</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<Badge variant="outline" className={item.original_status === '已出貨' ? "text-green-600 border-green-200 bg-green-50" : "text-gray-500"}>
|
||||
{item.original_status}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-medium">{Math.floor(item.quantity)}</TableCell>
|
||||
<TableCell className="text-right font-bold text-primary">
|
||||
NT$ {Number(item.amount).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
<div className="mt-6 flex flex-col sm:flex-row items-center justify-between 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>
|
||||
<Pagination links={items.links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useMemo } from "react";
|
||||
import { useState, useMemo, useEffect } from "react";
|
||||
import { ArrowLeft, PackagePlus, AlertTriangle, Shield, Boxes, FileUp } from "lucide-react";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
|
||||
@@ -36,11 +36,31 @@ export default function WarehouseInventoryPage({
|
||||
safetyStockSettings,
|
||||
availableProducts,
|
||||
}: Props) {
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [typeFilter, setTypeFilter] = useState<string>("all");
|
||||
// 從 URL 讀取初始狀態
|
||||
const queryParams = new URLSearchParams(window.location.search);
|
||||
const [searchTerm, setSearchTerm] = useState(queryParams.get("search") || "");
|
||||
const [typeFilter, setTypeFilter] = useState<string>(queryParams.get("type") || "all");
|
||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||
const [importDialogOpen, setImportDialogOpen] = useState(false);
|
||||
|
||||
// 當搜尋或篩選變更時,同步到 URL (使用 replace: true 避免產生過多歷史紀錄)
|
||||
useEffect(() => {
|
||||
const params: any = {};
|
||||
if (searchTerm) params.search = searchTerm;
|
||||
if (typeFilter !== "all") params.type = typeFilter;
|
||||
|
||||
router.get(
|
||||
route("warehouses.inventory.index", warehouse.id),
|
||||
params,
|
||||
{
|
||||
preserveState: true,
|
||||
preserveScroll: true,
|
||||
replace: true,
|
||||
only: ["inventories"], // 僅重新拉取數據,避免全頁重新渲染 (如有後端過濾)
|
||||
}
|
||||
);
|
||||
}, [searchTerm, typeFilter]);
|
||||
|
||||
// 篩選庫存列表
|
||||
const filteredInventories = useMemo(() => {
|
||||
return inventories.filter((group) => {
|
||||
|
||||
Reference in New Issue
Block a user