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";
import { usePermission } from "@/hooks/usePermission";
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 { can } = usePermission();
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 (
批次編號:#{batch.id} | 匯入時間:{format(new Date(batch.created_at), 'yyyy/MM/dd HH:mm')}
注意:此操作無法復原,請確保匯入資料正確無誤。