import React from "react"; import { useForm } from "@inertiajs/react"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/Components/ui/dialog"; import { Button } from "@/Components/ui/button"; import { Input } from "@/Components/ui/input"; import { Label } from "@/Components/ui/label"; import { Download, FileUp, Loader2, AlertCircle, FileSpreadsheet, Info } from "lucide-react"; import { toast } from "sonner"; import { Alert, AlertDescription } from "@/Components/ui/alert"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/Components/ui/accordion"; interface Props { open: boolean; onOpenChange: (open: boolean) => void; warehouseId: string; } export default function InventoryImportDialog({ open, onOpenChange, warehouseId }: Props) { const { data, setData, post, processing, errors, reset, clearErrors } = useForm({ file: null as File | null, inboundDate: new Date().toISOString().split('T')[0], notes: "Excel 匯入", }); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); post(route("warehouses.inventory.import", warehouseId), { forceFormData: true, onSuccess: () => { toast.success("庫存匯入完成"); onOpenChange(false); reset(); }, onError: (err) => { console.error("Import error:", err); toast.error("匯入失敗,請檢查檔案格式"); } }); }; const handleDownloadTemplate = () => { window.location.href = route("warehouses.inventory.template"); }; return ( { onOpenChange(val); if (!val) { reset(); clearErrors(); } }}> 匯入庫存資料 請先下載範本,填寫完畢後上傳檔案進行批次入庫。
{/* 步驟 1: 下載範本 */}
下載標準範本以確保資料格式正確。請勿修改標題欄位。
{/* 步驟 2: 設定資訊 */}
setData('inboundDate', e.target.value)} required className="cursor-pointer" />
setData('notes', e.target.value)} />
{/* 步驟 3: 上傳檔案 */}
setData('file', e.target.files ? e.target.files[0] : null)} required className="cursor-pointer" />
{errors.file && ( {errors.file} )}
{/* 欄位說明 */}
庫存匯入規則與提示
  • 商品匹配:優先使用「商品條碼」匹配,其次為「商品代號」。
  • 無批號模式:若 Excel 中的「批號」欄位保持空白,系統將自動累加至該商品的「通用紀錄」。(對販賣機而言,此紀錄通常對應至預設的一般庫存)。
  • 效期設定:若商品無效期概念可留空,或輸入格式如:2026/12/31。
  • 入庫單價:未填寫時將預設使用商品的「採購成本價」。
); }