feat: 統一採購單與操作紀錄 UI、增強各模組操作紀錄功能
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 59s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

- 統一採購單篩選列與表單樣式 (移除舊元件、標準化 Input)
- 增強操作紀錄功能 (加入篩選、快照、詳細異動比對)
- 統一刪除確認視窗與按鈕樣式
- 修復庫存編輯頁面樣式
- 實作採購單品項異動紀錄
- 實作角色分配異動紀錄
- 擴充供應商與倉庫模組紀錄
This commit is contained in:
2026-01-19 17:07:45 +08:00
parent 5c4693577a
commit 7367577f6a
16 changed files with 541 additions and 444 deletions

View File

@@ -64,6 +64,8 @@ const fieldLabels: Record<string, string> = {
phone: '電話',
address: '地址',
role_id: '角色',
email_verified_at: '電子郵件驗證時間',
remember_token: '登入權杖',
// Snapshot fields
category_name: '分類名稱',
base_unit_name: '基本單位名稱',
@@ -132,7 +134,7 @@ export default function ActivityDetailDialog({ open, onOpenChange, activity }: P
// Filter out internal keys often logged but not useful for users
const filteredKeys = allKeys
.filter(key =>
!['created_at', 'updated_at', 'deleted_at', 'id'].includes(key)
!['created_at', 'updated_at', 'deleted_at', 'id', 'remember_token'].includes(key)
)
.sort((a, b) => {
const indexA = sortOrder.indexOf(a);

View File

@@ -156,7 +156,7 @@ export default function LogTable({
<TableHead className="w-[150px]"></TableHead>
<TableHead></TableHead>
<TableHead className="w-[100px] text-center"></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="w-[100px] text-center"></TableHead>
</TableRow>
</TableHeader>

View File

@@ -1,176 +0,0 @@
/**
* 日期篩選器元件
* 支援快捷日期範圍選項和自定義日期範圍
*/
import { Calendar } from "lucide-react";
import { Label } from "@/Components/ui/label";
import { Input } from "@/Components/ui/input";
import { Button } from "@/Components/ui/button";
export interface DateRange {
start: string; // YYYY-MM-DD 格式
end: string; // YYYY-MM-DD 格式
}
interface DateFilterProps {
dateRange: DateRange | null;
onDateRangeChange: (range: DateRange | null) => void;
}
// 格式化日期為 YYYY-MM-DD
function formatDate(date: Date): string {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
}
// 獲取從今天往前 N 天的日期範圍
function getDateRange(days: number): DateRange {
const end = new Date();
const start = new Date();
start.setDate(start.getDate() - days);
return {
start: formatDate(start),
end: formatDate(end),
};
}
// 獲取本月的日期範圍
function getCurrentMonth(): DateRange {
const now = new Date();
const start = new Date(now.getFullYear(), now.getMonth(), 1);
const end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
return {
start: formatDate(start),
end: formatDate(end),
};
}
// 獲取上月的日期範圍
function getLastMonth(): DateRange {
const now = new Date();
const start = new Date(now.getFullYear(), now.getMonth() - 1, 1);
const end = new Date(now.getFullYear(), now.getMonth(), 0);
return {
start: formatDate(start),
end: formatDate(end),
};
}
// 快捷日期選項
const DATE_SHORTCUTS = [
{ label: "今天", getValue: () => getDateRange(0) },
{ label: "最近7天", getValue: () => getDateRange(7) },
{ label: "最近30天", getValue: () => getDateRange(30) },
{ label: "本月", getValue: () => getCurrentMonth() },
{ label: "上月", getValue: () => getLastMonth() },
];
export function DateFilter({ dateRange, onDateRangeChange }: DateFilterProps) {
const handleStartDateChange = (value: string) => {
if (!value) {
onDateRangeChange(null);
return;
}
onDateRangeChange({
start: value,
end: dateRange?.end || value,
});
};
const handleEndDateChange = (value: string) => {
if (!value) {
onDateRangeChange(null);
return;
}
onDateRangeChange({
start: dateRange?.start || value,
end: value,
});
};
const handleShortcutClick = (getValue: () => DateRange) => {
onDateRangeChange(getValue());
};
const handleClearClick = () => {
onDateRangeChange(null);
};
return (
<div className="space-y-4">
{/* 標題 */}
<div className="flex items-center gap-2">
<Calendar className="h-4 w-4 text-gray-500" />
<Label className="font-semibold text-gray-700"></Label>
</div>
{/* 快捷選項 */}
<div className="flex flex-wrap gap-2">
{DATE_SHORTCUTS.map((shortcut) => (
<Button
key={shortcut.label}
variant="outline"
size="sm"
onClick={() => handleShortcutClick(shortcut.getValue)}
className="button-outlined-primary border-gray-200"
>
{shortcut.label}
</Button>
))}
</div>
{/* 自定義日期範圍 */}
<div className="space-y-4 bg-gray-50/50 p-4 rounded-lg border border-dashed border-gray-200">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
{/* 開始日期 */}
<div className="space-y-2">
<Label htmlFor="start-date" className="text-sm text-gray-500">
</Label>
<Input
id="start-date"
type="date"
value={dateRange?.start || ""}
onChange={(e) => handleStartDateChange(e.target.value)}
className="border-gray-200 focus:border-primary"
/>
</div>
{/* 結束日期 */}
<div className="space-y-2">
<Label htmlFor="end-date" className="text-sm text-gray-500">
</Label>
<Input
id="end-date"
type="date"
value={dateRange?.end || ""}
onChange={(e) => handleEndDateChange(e.target.value)}
className="border-gray-200 focus:border-primary"
/>
</div>
</div>
{/* 清除按鈕 */}
{dateRange && (
<Button
variant="outline"
size="sm"
onClick={handleClearClick}
className="w-full button-outlined-primary border-gray-200"
>
</Button>
)}
</div>
</div>
);
}

View File

@@ -1,135 +0,0 @@
/**
* 採購單篩選器元件
*/
import { useState } from "react";
import { Search, X, Filter, ChevronDown, ChevronUp } from "lucide-react";
import { Button } from "@/Components/ui/button";
import { Input } from "@/Components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/Components/ui/select";
import { DateFilter, type DateRange } from "./DateFilter";
interface PurchaseOrderFiltersProps {
searchQuery: string;
statusFilter: string;
requesterFilter: string;
warehouses: { id: string | number; name: string }[];
dateRange: DateRange | null;
onSearchChange: (value: string) => void;
onStatusChange: (value: string) => void;
onRequesterChange: (value: string) => void;
onDateRangeChange: (range: DateRange | null) => void;
onClearFilters: () => void;
hasActiveFilters: boolean;
}
export function PurchaseOrderFilters({
searchQuery,
statusFilter,
requesterFilter,
warehouses,
dateRange,
onSearchChange,
onStatusChange,
onRequesterChange,
onDateRangeChange,
onClearFilters,
hasActiveFilters,
}: PurchaseOrderFiltersProps) {
const [showAdvancedFilters, setShowAdvancedFilters] = useState(false);
return (
<div className="bg-white rounded-lg border shadow-sm p-4 space-y-4">
{/* 主要篩選列 */}
<div className="flex flex-col lg:flex-row gap-4">
{/* 搜尋框 */}
<div className="flex-1 relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none" />
<Input
placeholder="搜尋採購單編號"
value={searchQuery}
onChange={(e) => onSearchChange(e.target.value)}
className="h-10 pl-10 border-gray-200 focus:border-primary"
/>
</div>
{/* 快速篩選區 */}
<div className="flex flex-wrap gap-3 items-center">
{/* 狀態篩選 */}
<div className="flex items-center gap-2">
<Filter className="h-4 w-4 text-gray-400 hidden sm:block" />
<Select value={statusFilter} onValueChange={onStatusChange}>
<SelectTrigger className="w-[160px] h-10 border-gray-200">
<SelectValue placeholder="全部狀態" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all"></SelectItem>
<SelectItem value="draft">稿</SelectItem>
<SelectItem value="pending"></SelectItem>
<SelectItem value="processing"></SelectItem>
<SelectItem value="shipping"></SelectItem>
<SelectItem value="confirming"></SelectItem>
<SelectItem value="completed"></SelectItem>
<SelectItem value="cancelled"></SelectItem>
</SelectContent>
</Select>
</div>
{/* 倉庫篩選 */}
<Select value={requesterFilter} onValueChange={onRequesterChange}>
<SelectTrigger className="w-[180px] h-10 border-gray-200">
<SelectValue placeholder="全部倉庫" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all"></SelectItem>
{warehouses.map((warehouse) => (
<SelectItem key={warehouse.id} value={String(warehouse.id)}>
{warehouse.name}
</SelectItem>
))}
</SelectContent>
</Select>
{/* 進階篩選按鈕 */}
<Button
variant="outline"
onClick={() => setShowAdvancedFilters(!showAdvancedFilters)}
className="gap-2 button-outlined-primary h-10 border-gray-200"
>
{showAdvancedFilters ? (
<ChevronUp className="h-4 w-4" />
) : (
<ChevronDown className="h-4 w-4" />
)}
<span className="hidden sm:inline"></span>
</Button>
{/* 清除篩選按鈕 */}
{hasActiveFilters && (
<Button
variant="outline"
onClick={onClearFilters}
className="gap-2 button-outlined-primary h-10 border-gray-200"
>
<X className="h-4 w-4" />
<span className="hidden sm:inline"></span>
</Button>
)}
</div>
</div>
{/* 進階篩選區 */}
{showAdvancedFilters && (
<div className="pt-4 border-t border-gray-100">
<DateFilter dateRange={dateRange} onDateRangeChange={onDateRangeChange} />
</div>
)}
</div>
);
}

View File

@@ -105,7 +105,7 @@ export function PurchaseOrderItemsTable({
onItemChange?.(index, "quantity", Math.floor(Number(e.target.value)))
}
disabled={isDisabled}
className="h-10 text-left border-gray-200 w-24"
className="text-left w-24"
/>
)}
</TableCell>
@@ -161,11 +161,11 @@ export function PurchaseOrderItemsTable({
onItemChange?.(index, "subtotal", Number(e.target.value))
}
disabled={isDisabled}
className={`h-10 text-left w-32 ${
className={`text-left w-32 ${
// 如果有數量但沒有金額,顯示錯誤樣式
item.quantity > 0 && (!item.subtotal || item.subtotal <= 0)
? "border-red-400 bg-red-50 focus-visible:ring-red-500"
: "border-gray-200"
: ""
}`}
/>
{/* 錯誤提示 */}

View File

@@ -4,9 +4,13 @@ import { Head, router } from '@inertiajs/react';
import { PageProps } from '@/types/global';
import Pagination from '@/Components/shared/Pagination';
import { SearchableSelect } from "@/Components/ui/searchable-select";
import { FileText } from 'lucide-react';
import { FileText, Search, RotateCcw, Calendar } from 'lucide-react';
import LogTable, { Activity } from '@/Components/ActivityLog/LogTable';
import ActivityDetailDialog from '@/Components/ActivityLog/ActivityDetailDialog';
import { Button } from '@/Components/ui/button';
import { Input } from '@/Components/ui/input';
import { Label } from '@/Components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/Components/ui/select";
interface PaginationLinks {
url: string | null;
@@ -27,14 +31,62 @@ interface Props extends PageProps {
per_page?: string;
sort_by?: string;
sort_order?: 'asc' | 'desc';
search?: string;
date_start?: string;
date_end?: string;
event?: string;
subject_type?: string;
causer_id?: string;
};
subject_types: { label: string; value: string }[];
users: { label: string; value: string }[];
}
export default function ActivityLogIndex({ activities, filters }: Props) {
export default function ActivityLogIndex({ activities, filters, subject_types, users }: Props) {
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
const [selectedActivity, setSelectedActivity] = useState<Activity | null>(null);
const [detailOpen, setDetailOpen] = useState(false);
// Filter States
const [search, setSearch] = useState(filters.search || '');
const [dateStart, setDateStart] = useState(filters.date_start || '');
const [dateEnd, setDateEnd] = useState(filters.date_end || '');
const [event, setEvent] = useState(filters.event || 'all');
const [subjectType, setSubjectType] = useState(filters.subject_type || 'all');
const [causer, setCauser] = useState(filters.causer_id || 'all');
const handleFilter = () => {
router.get(
route('activity-logs.index'),
{
...filters,
search: search,
date_start: dateStart,
date_end: dateEnd,
event: event === 'all' ? undefined : event,
subject_type: subjectType === 'all' ? undefined : subjectType,
causer_id: causer === 'all' ? undefined : causer,
page: 1 // Reset to first page on filter
},
{ preserveState: true, replace: true }
);
};
const handleReset = () => {
setSearch('');
setDateStart('');
setDateEnd('');
setEvent('all');
setSubjectType('all');
setCauser('all');
router.get(
route('activity-logs.index'),
{ per_page: perPage, sort_by: filters.sort_by, sort_order: filters.sort_order },
{ preserveState: true, replace: true }
);
};
const handleViewDetail = (activity: Activity) => {
setSelectedActivity(activity);
setDetailOpen(true);
@@ -91,6 +143,118 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
</div>
</div>
{/* 篩選區塊 */}
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4">
{/* 關鍵字搜尋 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
placeholder="搜尋描述、內容..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-9"
onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
/>
</div>
</div>
{/* 操作人員 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<SearchableSelect
value={causer}
onValueChange={setCauser}
options={[
{ label: "所有人員", value: "all" },
...users
]}
placeholder="選擇操作人員"
className="w-full"
/>
</div>
{/* 事件類型 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<Select value={event} onValueChange={setEvent}>
<SelectTrigger>
<SelectValue placeholder="選擇事件類型" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all"></SelectItem>
<SelectItem value="created"> (Created)</SelectItem>
<SelectItem value="updated"> (Updated)</SelectItem>
<SelectItem value="deleted"> (Deleted)</SelectItem>
</SelectContent>
</Select>
</div>
{/* 操作對象 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<SearchableSelect
value={subjectType}
onValueChange={setSubjectType}
options={[
{ label: "所有對象", value: "all" },
...subject_types
]}
placeholder="選擇操作對象"
className="w-full"
/>
</div>
{/* 日期範圍 - 開始 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
type="date"
value={dateStart}
onChange={(e) => setDateStart(e.target.value)}
className="pl-9 block w-full"
/>
</div>
</div>
{/* 日期範圍 - 結束 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
type="date"
value={dateEnd}
onChange={(e) => setDateEnd(e.target.value)}
className="pl-9 block w-full text-left"
/>
</div>
</div>
</div>
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100">
<Button
variant="outline"
onClick={handleReset}
className="flex items-center gap-2 button-outlined-primary"
>
<RotateCcw className="h-4 w-4" />
</Button>
<Button
onClick={handleFilter}
className="flex items-center gap-2 button-filled-primary"
>
<Search className="h-4 w-4" />
</Button>
</div>
</div>
<LogTable
activities={activities.data}
sortField={filters.sort_by}
@@ -100,7 +264,7 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
from={activities.from}
/>
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-gray-500">
<span></span>
<SearchableSelect
@@ -112,12 +276,14 @@ export default function ActivityLogIndex({ activities, filters }: Props) {
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[80px] h-8"
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<Pagination links={activities.links} />
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
<Pagination links={activities.links} />
</div>
</div>
</div>

View File

@@ -13,7 +13,6 @@ import {
TableRow,
} from "@/Components/ui/table";
import { format } from 'date-fns';
import { toast } from 'sonner';
import { Can } from '@/Components/Permission/Can';
import { useState } from 'react';
import {
@@ -23,6 +22,16 @@ import {
DialogHeader,
DialogTitle,
} from "@/Components/ui/dialog";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/Components/ui/alert-dialog";
interface User {
id: number;
@@ -50,11 +59,23 @@ interface Props {
export default function RoleIndex({ roles, filters = {} }: Props) {
const [selectedRole, setSelectedRole] = useState<Role | null>(null);
const [deleteId, setDeleteId] = useState<number | null>(null);
const [deleteName, setDeleteName] = useState<string>('');
const [modelOpen, setModelOpen] = useState(false);
const handleDelete = (id: number, name: string) => {
if (confirm(`確定要刪除角色「${name}」嗎?此操作無法復原。`)) {
router.delete(route('roles.destroy', id), {
onSuccess: () => toast.success('角色已刪除'),
const confirmDelete = (id: number, name: string) => {
setDeleteId(id);
setDeleteName(name);
setModelOpen(true);
};
const handleDelete = () => {
if (deleteId) {
router.delete(route('roles.destroy', deleteId), {
onSuccess: () => {
setModelOpen(false);
},
onFinish: () => setModelOpen(false),
});
}
};
@@ -212,7 +233,7 @@ export default function RoleIndex({ roles, filters = {} }: Props) {
className="button-outlined-error"
title="刪除"
disabled={role.users_count > 0}
onClick={() => handleDelete(role.id, role.display_name)}
onClick={() => confirmDelete(role.id, role.display_name)}
>
<Trash2 className="h-4 w-4" />
</Button>
@@ -274,6 +295,23 @@ export default function RoleIndex({ roles, filters = {} }: Props) {
</div>
</DialogContent>
</Dialog>
<AlertDialog open={modelOpen} onOpenChange={setModelOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle></AlertDialogTitle>
<AlertDialogDescription>
{deleteName}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} className="button-filled-error">
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</AuthenticatedLayout>
);
}

View File

@@ -12,11 +12,20 @@ import {
TableRow,
} from "@/Components/ui/table";
import { format } from 'date-fns';
import { toast } from 'sonner';
import { Can } from '@/Components/Permission/Can';
import { cn } from "@/lib/utils";
import Pagination from "@/Components/shared/Pagination";
import { SearchableSelect } from "@/Components/ui/searchable-select";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/Components/ui/alert-dialog";
interface Role {
id: number;
@@ -54,12 +63,23 @@ interface Props {
export default function UserIndex({ users, filters }: Props) {
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
const [deleteId, setDeleteId] = useState<number | null>(null);
const [deleteName, setDeleteName] = useState<string>('');
const [modelOpen, setModelOpen] = useState(false);
const handleDelete = (id: number, name: string) => {
if (confirm(`確定要刪除使用者「${name}」嗎?此操作無法復原。`)) {
router.delete(route('users.destroy', id), {
onSuccess: () => toast.success('使用者已刪除'),
onError: () => toast.error('刪除失敗,請檢查權限'),
const confirmDelete = (id: number, name: string) => {
setDeleteId(id);
setDeleteName(name);
setModelOpen(true);
};
const handleDelete = () => {
if (deleteId) {
router.delete(route('users.destroy', deleteId), {
onSuccess: () => {
setModelOpen(false);
},
onFinish: () => setModelOpen(false),
});
}
};
@@ -229,7 +249,7 @@ export default function UserIndex({ users, filters }: Props) {
size="sm"
className="button-outlined-error"
title="刪除"
onClick={() => handleDelete(user.id, user.name)}
onClick={() => confirmDelete(user.id, user.name)}
>
<Trash2 className="h-4 w-4" />
</Button>
@@ -243,7 +263,7 @@ export default function UserIndex({ users, filters }: Props) {
</div>
{/* 分頁元件 - 統一樣式 */}
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-gray-500">
<span></span>
<SearchableSelect
@@ -255,14 +275,33 @@ export default function UserIndex({ users, filters }: Props) {
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[80px] h-8"
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<Pagination links={users.links} />
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
<Pagination links={users.links} />
</div>
</div>
</div>
</AuthenticatedLayout>
<AlertDialog open={modelOpen} onOpenChange={setModelOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>使</AlertDialogTitle>
<AlertDialogDescription>
使{deleteName}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel></AlertDialogCancel>
<AlertDialogAction onClick={handleDelete} className="button-filled-error">
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</AuthenticatedLayout >
);
}

View File

@@ -260,7 +260,7 @@ export default function ProductManagement({ products, categories, units, filters
/>
{/* 分頁元件 */}
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-gray-500">
<span></span>
<SearchableSelect
@@ -272,12 +272,14 @@ export default function ProductManagement({ products, categories, units, filters
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[80px] h-8"
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<Pagination links={products.links} />
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
<Pagination links={products.links} />
</div>
</div>
<ProductDialog

View File

@@ -244,7 +244,7 @@ export default function CreatePurchaseOrder({
value={expectedDate || ""}
onChange={(e) => setExpectedDate(e.target.value)}
min={getTodayDate()}
className="h-12 border-gray-200"
className="block w-full"
/>
</div>
@@ -267,7 +267,7 @@ export default function CreatePurchaseOrder({
value={notes || ""}
onChange={(e) => setNotes(e.target.value)}
placeholder="備註這筆採購單的特殊需求..."
className="min-h-[100px] border-gray-200"
className="min-h-[100px]"
/>
</div>
</div>
@@ -293,7 +293,7 @@ export default function CreatePurchaseOrder({
onChange={(e) => setInvoiceNumber(e.target.value)}
placeholder="AB-12345678"
maxLength={11}
className="h-12 border-gray-200"
className="block w-full"
/>
<p className="text-xs text-gray-500">2 + + 8 </p>
</div>
@@ -306,7 +306,7 @@ export default function CreatePurchaseOrder({
type="date"
value={invoiceDate}
onChange={(e) => setInvoiceDate(e.target.value)}
className="h-12 border-gray-200"
className="block w-full"
/>
</div>
@@ -321,7 +321,7 @@ export default function CreatePurchaseOrder({
placeholder="0"
min="0"
step="0.01"
className="h-12 border-gray-200"
className="block w-full"
/>
{invoiceAmount && totalAmount > 0 && parseFloat(invoiceAmount) !== totalAmount && (
<p className="text-xs text-amber-600">

View File

@@ -2,20 +2,26 @@
* 採購單管理主頁面
*/
import { useState, useCallback } from "react";
import { Plus, ShoppingCart } from 'lucide-react';
import { useState, useEffect } from "react";
import { Plus, ShoppingCart, Search, RotateCcw, Calendar } from 'lucide-react';
import { Button } from "@/Components/ui/button";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { Head, router } from "@inertiajs/react";
import PurchaseOrderTable from "@/Components/PurchaseOrder/PurchaseOrderTable";
import { PurchaseOrderFilters } from "@/Components/PurchaseOrder/PurchaseOrderFilters";
import { type DateRange } from "@/Components/PurchaseOrder/DateFilter";
import type { PurchaseOrder } from "@/types/purchase-order";
import { debounce } from "lodash";
import Pagination from "@/Components/shared/Pagination";
import { getBreadcrumbs } from "@/utils/breadcrumb";
import { Can } from "@/Components/Permission/Can";
import { SearchableSelect } from "@/Components/ui/searchable-select";
import { Input } from "@/Components/ui/input";
import { Label } from "@/Components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/Components/ui/select";
interface Props {
orders: {
@@ -29,6 +35,8 @@ interface Props {
search?: string;
status?: string;
warehouse_id?: string;
date_start?: string;
date_end?: string;
sort_field?: string;
sort_direction?: string;
per_page?: string;
@@ -37,74 +45,70 @@ interface Props {
}
export default function PurchaseOrderIndex({ orders, filters, warehouses }: Props) {
const [searchQuery, setSearchQuery] = useState(filters.search || "");
const [statusFilter, setStatusFilter] = useState<string>(filters.status || "all");
const [requesterFilter, setRequesterFilter] = useState<string>(filters.warehouse_id || "all");
// 篩選狀態
const [search, setSearch] = useState(filters.search || "");
const [status, setStatus] = useState<string>(filters.status || "all");
const [warehouseId, setWarehouseId] = useState<string>(filters.warehouse_id || "all");
const [dateStart, setDateStart] = useState(filters.date_start || "");
const [dateEnd, setDateEnd] = useState(filters.date_end || "");
const [perPage, setPerPage] = useState<string>(filters.per_page || "10");
const [dateRange, setDateRange] = useState<DateRange | null>(null);
const handleFilterChange = (newFilters: any) => {
router.get("/purchase-orders", {
...filters,
...newFilters,
page: 1,
}, {
preserveState: true,
replace: true,
});
// 同步 URL 參數到 State (雖有初始值,但若由外部連結進入可確保同步)
useEffect(() => {
setSearch(filters.search || "");
setStatus(filters.status || "all");
setWarehouseId(filters.warehouse_id || "all");
setDateStart(filters.date_start || "");
setDateEnd(filters.date_end || "");
setPerPage(filters.per_page || "10");
}, [filters]);
const handleFilter = () => {
router.get(
route('purchase-orders.index'),
{
search,
status: status === 'all' ? undefined : status,
warehouse_id: warehouseId === 'all' ? undefined : warehouseId,
date_start: dateStart,
date_end: dateEnd,
per_page: perPage,
sort_field: filters.sort_field,
sort_direction: filters.sort_direction,
},
{ preserveState: true, replace: true }
);
};
const handleSearch = useCallback(
debounce((value: string) => {
handleFilterChange({ search: value });
}, 500),
[filters]
);
const handleReset = () => {
setSearch("");
setStatus("all");
setWarehouseId("all");
setDateStart("");
setDateEnd("");
const onSearchChange = (value: string) => {
setSearchQuery(value);
handleSearch(value);
};
const onStatusChange = (value: string) => {
setStatusFilter(value);
handleFilterChange({ status: value });
};
const onWarehouseChange = (value: string) => {
setRequesterFilter(value);
handleFilterChange({ warehouse_id: value });
};
const handleClearFilters = () => {
setSearchQuery("");
setStatusFilter("all");
setRequesterFilter("all");
setDateRange(null);
router.get("/purchase-orders");
};
const hasActiveFilters = searchQuery !== "" || statusFilter !== "all" || requesterFilter !== "all" || dateRange !== null;
const handleNavigateToCreateOrder = () => {
router.get("/purchase-orders/create");
router.get(route('purchase-orders.index'));
};
const handlePerPageChange = (value: string) => {
setPerPage(value);
router.get("/purchase-orders", {
...filters,
per_page: value,
page: 1,
}, {
preserveState: false,
replace: true,
});
router.get(
route("purchase-orders.index"),
{
...filters,
per_page: value,
},
{ preserveState: false, replace: true, preserveScroll: true }
);
};
const handleNavigateToCreateOrder = () => {
router.get(route('purchase-orders.create'));
};
return (
<AuthenticatedLayout breadcrumbs={getBreadcrumbs("purchaseOrders")}>
<Head title="採購管理 - 管理採購單" />
<Head title="採購管理" />
<div className="container mx-auto p-6 max-w-7xl">
<div className="flex items-center justify-between mb-6">
<div>
@@ -129,20 +133,105 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
</div>
</div>
<div className="mb-6">
<PurchaseOrderFilters
searchQuery={searchQuery}
statusFilter={statusFilter}
requesterFilter={requesterFilter}
warehouses={warehouses}
onSearchChange={onSearchChange}
onStatusChange={onStatusChange}
onRequesterChange={onWarehouseChange}
onClearFilters={handleClearFilters}
hasActiveFilters={hasActiveFilters}
dateRange={dateRange}
onDateRangeChange={setDateRange}
/>
{/* 篩選區塊 */}
<div className="bg-white p-5 rounded-lg shadow-sm border border-gray-200 mb-6">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-4">
{/* 關鍵字搜尋 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
placeholder="搜尋採購單號、廠商..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-9"
onKeyDown={(e) => e.key === 'Enter' && handleFilter()}
/>
</div>
</div>
{/* 狀態篩選 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<Select value={status} onValueChange={setStatus}>
<SelectTrigger>
<SelectValue placeholder="選擇狀態" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all"></SelectItem>
<SelectItem value="draft">稿</SelectItem>
<SelectItem value="pending"></SelectItem>
<SelectItem value="processing"></SelectItem>
<SelectItem value="shipping"></SelectItem>
<SelectItem value="confirming"></SelectItem>
<SelectItem value="completed"></SelectItem>
<SelectItem value="cancelled"></SelectItem>
</SelectContent>
</Select>
</div>
{/* 倉庫篩選 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<SearchableSelect
value={warehouseId}
onValueChange={setWarehouseId}
options={[
{ label: "全部倉庫", value: "all" },
...warehouses.map(w => ({ label: w.name, value: String(w.id) }))
]}
placeholder="選擇倉庫"
className="w-full"
/>
</div>
{/* 日期範圍 - 開始 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
type="date"
value={dateStart}
onChange={(e) => setDateStart(e.target.value)}
className="pl-9 block w-full"
/>
</div>
</div>
{/* 日期範圍 - 結束 */}
<div className="space-y-1">
<Label className="text-xs text-gray-500"></Label>
<div className="relative">
<Calendar className="absolute left-2.5 top-2.5 h-4 w-4 text-gray-400" />
<Input
type="date"
value={dateEnd}
onChange={(e) => setDateEnd(e.target.value)}
className="pl-9 block w-full text-left"
/>
</div>
</div>
</div>
<div className="flex items-center justify-end gap-3 pt-2 border-t border-gray-100">
<Button
variant="outline"
onClick={handleReset}
className="flex items-center gap-2 button-outlined-primary"
>
<RotateCcw className="h-4 w-4" />
</Button>
<Button
onClick={handleFilter}
className="flex items-center gap-2 button-filled-primary"
>
<Search className="h-4 w-4" />
</Button>
</div>
</div>
<PurchaseOrderTable
@@ -150,7 +239,7 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
/>
{/* 分頁元件 - 統一樣式 */}
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-gray-500">
<span></span>
<SearchableSelect
@@ -162,12 +251,14 @@ export default function PurchaseOrderIndex({ orders, filters, warehouses }: Prop
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[80px] h-8"
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<Pagination links={orders.links} />
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
<Pagination links={orders.links} />
</div>
</div>
</div>
</AuthenticatedLayout>

View File

@@ -202,7 +202,7 @@ export default function VendorManagement({ vendors, filters }: PageProps) {
/>
{/* 分頁元件 - 統一樣式 */}
<div className="mt-4 flex flex-col sm:flex-row items-center justify-between gap-4">
<div className="mt-4 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
<div className="flex items-center gap-2 text-sm text-gray-500">
<span></span>
<SearchableSelect
@@ -214,12 +214,14 @@ export default function VendorManagement({ vendors, filters }: PageProps) {
{ label: "50", value: "50" },
{ label: "100", value: "100" }
]}
className="w-[80px] h-8"
className="w-[100px] h-8"
showSearch={false}
/>
<span></span>
</div>
<Pagination links={vendors.links} />
<div className="w-full sm:w-auto flex justify-center sm:justify-end">
<Pagination links={vendors.links} />
</div>
</div>
</div>
</AuthenticatedLayout>

View File

@@ -146,7 +146,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
value={data.batchNumber}
onChange={(e) => setData("batchNumber", e.target.value)}
placeholder="例FL20251101"
className="button-outlined-primary"
className="border-gray-300"
// 目前後端可能尚未支援儲存,但依需求顯示
/>
</div>
@@ -172,7 +172,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
setData("quantity", parseFloat(e.target.value) || 0)
}
placeholder="0"
className={`button-outlined-primary ${errors.quantity ? "border-red-500" : ""}`}
className={`border-gray-300 ${errors.quantity ? "border-red-500" : ""}`}
/>
{errors.quantity && <p className="text-xs text-red-500">{errors.quantity}</p>}
<p className="text-sm text-gray-500">
@@ -194,7 +194,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
type="date"
value={data.expiryDate}
onChange={(e) => setData("expiryDate", e.target.value)}
className="button-outlined-primary"
className="border-gray-300"
/>
</div>
@@ -207,7 +207,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
onChange={(e) =>
setData("lastInboundDate", e.target.value)
}
className="button-outlined-primary"
className="border-gray-300"
/>
</div>
@@ -220,7 +220,7 @@ export default function EditInventory({ warehouse, inventory, transactions = []
onChange={(e) =>
setData("lastOutboundDate", e.target.value)
}
className="button-outlined-primary"
className="border-gray-300"
/>
</div>
</div>