first commit
This commit is contained in:
@@ -0,0 +1,350 @@
|
||||
/**
|
||||
* 付款對話框組件
|
||||
*/
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { DollarSign } from "lucide-react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "../ui/dialog";
|
||||
import { Button } from "../ui/button";
|
||||
import { Label } from "../ui/label";
|
||||
import { Input } from "../ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "../ui/select";
|
||||
import { Switch } from "../ui/switch";
|
||||
import { PAYMENT_METHODS, INVOICE_TYPES } from "../../constants/purchase-order";
|
||||
import type { PurchaseOrder, PaymentMethod, InvoiceType, PaymentInfo } from "../../types/purchase-order";
|
||||
|
||||
interface PaymentDialogProps {
|
||||
order: PurchaseOrder;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onConfirm: (orderId: string, paymentInfo: PaymentInfo) => void;
|
||||
}
|
||||
|
||||
export function PaymentDialog({
|
||||
order,
|
||||
open,
|
||||
onOpenChange,
|
||||
onConfirm,
|
||||
}: PaymentDialogProps) {
|
||||
// 付款資訊
|
||||
const [paymentMethod, setPaymentMethod] = useState<PaymentMethod>("bank_transfer");
|
||||
const [paymentDate, setPaymentDate] = useState(
|
||||
new Date().toISOString().split("T")[0]
|
||||
);
|
||||
const [actualAmount, setActualAmount] = useState(order.totalAmount.toString());
|
||||
|
||||
// 發票資訊
|
||||
const [hasInvoice, setHasInvoice] = useState(false);
|
||||
const [invoiceNumber, setInvoiceNumber] = useState("");
|
||||
const [invoiceAmount, setInvoiceAmount] = useState(order.totalAmount.toString());
|
||||
const [invoiceDate, setInvoiceDate] = useState(
|
||||
new Date().toISOString().split("T")[0]
|
||||
);
|
||||
const [invoiceType, setInvoiceType] = useState<InvoiceType>("duplicate");
|
||||
const [companyName, setCompanyName] = useState("");
|
||||
const [taxId, setTaxId] = useState("");
|
||||
|
||||
// 當訂單變更時重置表單
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setActualAmount(order.totalAmount.toString());
|
||||
setInvoiceAmount(order.totalAmount.toString());
|
||||
}
|
||||
}, [order.totalAmount, open]);
|
||||
|
||||
const handleConfirm = () => {
|
||||
const paymentInfo: PaymentInfo = {
|
||||
paymentMethod,
|
||||
paymentDate,
|
||||
actualAmount: parseFloat(actualAmount),
|
||||
paidBy: "付款人名稱", // 實際應從登入使用者取得
|
||||
paidAt: new Date().toLocaleString("zh-TW"),
|
||||
hasInvoice,
|
||||
};
|
||||
|
||||
if (hasInvoice) {
|
||||
paymentInfo.invoice = {
|
||||
invoiceNumber,
|
||||
invoiceAmount: parseFloat(invoiceAmount),
|
||||
invoiceDate,
|
||||
invoiceType,
|
||||
};
|
||||
|
||||
if (invoiceType === "triplicate") {
|
||||
paymentInfo.invoice.companyName = companyName;
|
||||
paymentInfo.invoice.taxId = taxId;
|
||||
}
|
||||
}
|
||||
|
||||
onConfirm(order.id, paymentInfo);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
// 重置表單
|
||||
setPaymentMethod("bank_transfer");
|
||||
setPaymentDate(new Date().toISOString().split("T")[0]);
|
||||
setActualAmount(order.totalAmount.toString());
|
||||
setHasInvoice(false);
|
||||
setInvoiceNumber("");
|
||||
setInvoiceAmount(order.totalAmount.toString());
|
||||
setInvoiceDate(new Date().toISOString().split("T")[0]);
|
||||
setInvoiceType("duplicate");
|
||||
setCompanyName("");
|
||||
setTaxId("");
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const isValid = () => {
|
||||
// 驗證付款資訊
|
||||
if (!paymentMethod || !paymentDate || !actualAmount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const amount = parseFloat(actualAmount);
|
||||
if (isNaN(amount) || amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果有發票,驗證發票資訊
|
||||
if (hasInvoice) {
|
||||
if (!invoiceNumber || !invoiceDate || !invoiceType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const invAmount = parseFloat(invoiceAmount);
|
||||
if (isNaN(invAmount) || invAmount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 如果是三聯式,必須填寫公司抬頭和統編
|
||||
if (invoiceType === "triplicate") {
|
||||
if (!companyName || !taxId) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
<DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<DollarSign className="h-5 w-5" />
|
||||
標記為已付款
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
採購單編號:{order.poNumber}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-6 py-4">
|
||||
{/* 採購單資訊摘要 */}
|
||||
<div className="bg-muted p-4 rounded-lg space-y-2">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">廠商:</span>
|
||||
<span className="font-medium">{order.supplierName}</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">採購總金額:</span>
|
||||
<span className="font-medium">
|
||||
${order.totalAmount.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 付款資訊區塊 */}
|
||||
<div className="space-y-4">
|
||||
<h3 className="font-medium">付款資訊</h3>
|
||||
|
||||
{/* 付款方式 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="payment-method">付款方式 *</Label>
|
||||
<Select value={paymentMethod} onValueChange={(value) => setPaymentMethod(value as PaymentMethod)}>
|
||||
<SelectTrigger
|
||||
id="payment-method"
|
||||
className="h-11 border-2 border-input"
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{Object.entries(PAYMENT_METHODS).map(([key, label]) => (
|
||||
<SelectItem key={key} value={key}>
|
||||
{label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 付款日期 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="payment-date">付款日期 *</Label>
|
||||
<Input
|
||||
id="payment-date"
|
||||
type="date"
|
||||
value={paymentDate}
|
||||
onChange={(e) => setPaymentDate(e.target.value)}
|
||||
className="h-11 border-2 border-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 實際付款金額 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="actual-amount">實際付款金額 *</Label>
|
||||
<Input
|
||||
id="actual-amount"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
value={actualAmount}
|
||||
onChange={(e) => setActualAmount(e.target.value)}
|
||||
className="h-11 border-2 border-input"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 發票資訊區塊 */}
|
||||
<div className="space-y-4 pt-4 border-t">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-1">
|
||||
<h3 className="font-medium">是否有發票</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
請選擇此筆採購是否有開立發票
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={hasInvoice}
|
||||
onCheckedChange={setHasInvoice}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 發票欄位(條件顯示) */}
|
||||
{hasInvoice && (
|
||||
<div className="space-y-4 bg-muted p-4 rounded-lg">
|
||||
{/* 發票號碼 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="invoice-number">發票號碼 *</Label>
|
||||
<Input
|
||||
id="invoice-number"
|
||||
value={invoiceNumber}
|
||||
onChange={(e) => setInvoiceNumber(e.target.value)}
|
||||
placeholder="例:AA-12345678"
|
||||
className="h-11 border-2 border-input bg-background"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 發票金額 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="invoice-amount">發票金額 *</Label>
|
||||
<Input
|
||||
id="invoice-amount"
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
value={invoiceAmount}
|
||||
onChange={(e) => setInvoiceAmount(e.target.value)}
|
||||
className="h-11 border-2 border-input bg-background"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 發票日期 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="invoice-date">發票日期 *</Label>
|
||||
<Input
|
||||
id="invoice-date"
|
||||
type="date"
|
||||
value={invoiceDate}
|
||||
onChange={(e) => setInvoiceDate(e.target.value)}
|
||||
className="h-11 border-2 border-input bg-background"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 發票類型 */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="invoice-type">發票類型 *</Label>
|
||||
<Select value={invoiceType} onValueChange={(value) => setInvoiceType(value as InvoiceType)}>
|
||||
<SelectTrigger
|
||||
id="invoice-type"
|
||||
className="h-11 border-2 border-input bg-background"
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{Object.entries(INVOICE_TYPES).map(([key, label]) => (
|
||||
<SelectItem key={key} value={key}>
|
||||
{label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 三聯式專用欄位 */}
|
||||
{invoiceType === "triplicate" && (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="company-name">公司抬頭 *</Label>
|
||||
<Input
|
||||
id="company-name"
|
||||
value={companyName}
|
||||
onChange={(e) => setCompanyName(e.target.value)}
|
||||
placeholder="請輸入公司抬頭"
|
||||
className="h-11 border-2 border-input bg-background"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="tax-id">統一編號 *</Label>
|
||||
<Input
|
||||
id="tax-id"
|
||||
value={taxId}
|
||||
onChange={(e) => setTaxId(e.target.value)}
|
||||
placeholder="請輸入統一編號"
|
||||
maxLength={8}
|
||||
className="h-11 border-2 border-input bg-background"
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleClose}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleConfirm}
|
||||
disabled={!isValid()}
|
||||
className="button-filled-primary"
|
||||
>
|
||||
確認付款
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 採購單操作按鈕元件
|
||||
*/
|
||||
|
||||
import { Edit, Eye } from "lucide-react";
|
||||
import { Button } from "../ui/button";
|
||||
import type { PurchaseOrder } from "../../types/purchase-order";
|
||||
|
||||
interface PurchaseOrderActionsProps {
|
||||
order: PurchaseOrder;
|
||||
onEdit: (order: PurchaseOrder) => void;
|
||||
onView: (order: PurchaseOrder) => void;
|
||||
}
|
||||
|
||||
export function PurchaseOrderActions({
|
||||
order,
|
||||
onEdit,
|
||||
onView,
|
||||
}: PurchaseOrderActionsProps) {
|
||||
return (
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onView(order)}
|
||||
className="button-outlined-primary"
|
||||
title="查看採購單"
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onEdit(order)}
|
||||
className="button-outlined-primary"
|
||||
title="編輯採購單"
|
||||
>
|
||||
<Edit className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* 採購單篩選器元件 - 獨立區塊設計
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { Search, X, Filter, ChevronDown, ChevronUp } from "lucide-react";
|
||||
import { Button } from "../ui/button";
|
||||
import { Input } from "../ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "../ui/select";
|
||||
import { DateFilter, type DateRange } from "../filters/DateFilter";
|
||||
|
||||
interface PurchaseOrderFiltersProps {
|
||||
searchQuery: string;
|
||||
statusFilter: string;
|
||||
requesterFilter: string;
|
||||
stores: string[];
|
||||
warehouses: 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,
|
||||
stores,
|
||||
warehouses,
|
||||
dateRange,
|
||||
onSearchChange,
|
||||
onStatusChange,
|
||||
onRequesterChange,
|
||||
onDateRangeChange,
|
||||
onClearFilters,
|
||||
hasActiveFilters,
|
||||
}: PurchaseOrderFiltersProps) {
|
||||
const [showAdvancedFilters, setShowAdvancedFilters] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="bg-card rounded-lg border-2 border-border p-4 space-y-4">
|
||||
{/* 主要篩選列:搜尋 + 快速篩選 */}
|
||||
<div className="flex flex-col md: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-muted-foreground pointer-events-none" />
|
||||
<Input
|
||||
placeholder="搜尋採購單編號"
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
className="h-11 pl-10 border-2 border-input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 右側篩選區 - 水平排列 */}
|
||||
<div className="flex flex-wrap gap-4 items-center">
|
||||
{/* 狀態篩選 */}
|
||||
<div className="flex items-center gap-2">
|
||||
<Filter className="h-4 w-4 text-muted-foreground hidden sm:block" />
|
||||
<Select value={statusFilter} onValueChange={onStatusChange}>
|
||||
<SelectTrigger className="w-[180px] h-11 border-2 border-input">
|
||||
<SelectValue placeholder="全部類型" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">全部狀態</SelectItem>
|
||||
<SelectItem value="draft">草稿</SelectItem>
|
||||
<SelectItem value="review_pending">待審核</SelectItem>
|
||||
<SelectItem value="processing">處理中</SelectItem>
|
||||
<SelectItem value="shipping">運送中</SelectItem>
|
||||
<SelectItem value="pending_confirm">待確認</SelectItem>
|
||||
<SelectItem value="completed">已完成</SelectItem>
|
||||
<SelectItem value="rejected">已退回</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 申請單位篩選 */}
|
||||
<Select value={requesterFilter} onValueChange={onRequesterChange}>
|
||||
<SelectTrigger className="w-[180px] h-11 border-2 border-input">
|
||||
<SelectValue placeholder="全部申請單位" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">全部申請單位</SelectItem>
|
||||
|
||||
{/* 全部門市 */}
|
||||
{stores.length > 0 && (
|
||||
<SelectItem value="all_stores">全部門市</SelectItem>
|
||||
)}
|
||||
|
||||
{/* 全部倉庫 */}
|
||||
{warehouses.length > 0 && (
|
||||
<SelectItem value="all_warehouses">全部倉庫</SelectItem>
|
||||
)}
|
||||
|
||||
{/* 分隔線 */}
|
||||
{(stores.length > 0 || warehouses.length > 0) && (
|
||||
<div className="h-px bg-border my-1" />
|
||||
)}
|
||||
|
||||
{/* 各別門市 */}
|
||||
{stores.length > 0 && (
|
||||
<>
|
||||
<div className="px-2 py-1.5 text-xs text-muted-foreground">
|
||||
門市
|
||||
</div>
|
||||
{stores.map((store) => (
|
||||
<SelectItem key={store} value={store}>
|
||||
{store}
|
||||
</SelectItem>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 各別倉庫 */}
|
||||
{warehouses.length > 0 && (
|
||||
<>
|
||||
{stores.length > 0 && <div className="h-px bg-border my-1" />}
|
||||
<div className="px-2 py-1.5 text-xs text-muted-foreground">
|
||||
倉庫
|
||||
</div>
|
||||
{warehouses.map((warehouse) => (
|
||||
<SelectItem key={warehouse} value={warehouse}>
|
||||
{warehouse}
|
||||
</SelectItem>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{/* 進階篩選按鈕 */}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setShowAdvancedFilters(!showAdvancedFilters)}
|
||||
className="gap-2 button-outlined-primary h-11"
|
||||
>
|
||||
{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-11"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">清除篩選</span>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 進階篩選區 - 可展開/收合 */}
|
||||
{showAdvancedFilters && (
|
||||
<div className="pt-4 border-t-2 border-border">
|
||||
<DateFilter dateRange={dateRange} onDateRangeChange={onDateRangeChange} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
* 採購單商品表格元件
|
||||
*/
|
||||
|
||||
import { Trash2, Plus } from "lucide-react";
|
||||
import { Button } from "../ui/button";
|
||||
import { Input } from "../ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "../ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "../ui/table";
|
||||
import type { PurchaseOrderItem, Supplier } from "../../types/purchase-order";
|
||||
import { isPriceAlert, formatCurrency } from "../../utils/purchase-order";
|
||||
|
||||
interface PurchaseOrderItemsTableProps {
|
||||
items: PurchaseOrderItem[];
|
||||
supplier?: Supplier;
|
||||
isReadOnly?: boolean;
|
||||
isDisabled?: boolean;
|
||||
onAddItem?: () => void;
|
||||
onRemoveItem?: (index: number) => void;
|
||||
onItemChange?: (index: number, field: keyof PurchaseOrderItem, value: string | number) => void;
|
||||
}
|
||||
|
||||
export function PurchaseOrderItemsTable({
|
||||
items,
|
||||
supplier,
|
||||
isReadOnly = false,
|
||||
isDisabled = false,
|
||||
onAddItem,
|
||||
onRemoveItem,
|
||||
onItemChange,
|
||||
}: PurchaseOrderItemsTableProps) {
|
||||
return (
|
||||
<>
|
||||
{/* 商品表格 */}
|
||||
<div className={`border-2 border-border rounded-lg overflow-hidden ${isDisabled ? "opacity-50 pointer-events-none" : ""}`}>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow className="bg-muted/50">
|
||||
<TableHead className="w-[200px]">商品</TableHead>
|
||||
<TableHead className="w-[100px]">數量</TableHead>
|
||||
<TableHead className="w-[80px]">單位</TableHead>
|
||||
<TableHead className="w-[120px]">單價</TableHead>
|
||||
<TableHead className="w-[120px]">小計</TableHead>
|
||||
{!isReadOnly && <TableHead className="w-[60px]"></TableHead>}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{items.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={isReadOnly ? 5 : 6}
|
||||
className="text-center text-muted-foreground py-12"
|
||||
>
|
||||
{isDisabled ? "請先選擇供應商後才能新增商品" : "尚未新增商品"}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
items.map((item, index) => (
|
||||
<TableRow key={index}>
|
||||
{/* 商品選擇 */}
|
||||
<TableCell>
|
||||
{isReadOnly ? (
|
||||
<span>{item.productName}</span>
|
||||
) : (
|
||||
<Select
|
||||
value={item.productId}
|
||||
onValueChange={(value) =>
|
||||
onItemChange?.(index, "productId", value)
|
||||
}
|
||||
disabled={isDisabled}
|
||||
>
|
||||
<SelectTrigger className="h-11 border-2 border-input">
|
||||
<SelectValue placeholder="選擇商品" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{supplier?.commonProducts.map((product) => (
|
||||
<SelectItem key={product.productId} value={product.productId}>
|
||||
{product.productName}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
{/* 數量 */}
|
||||
<TableCell>
|
||||
{isReadOnly ? (
|
||||
<span>{item.quantity}</span>
|
||||
) : (
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
value={item.quantity || ""}
|
||||
onChange={(e) =>
|
||||
onItemChange?.(index, "quantity", Number(e.target.value))
|
||||
}
|
||||
disabled={isDisabled}
|
||||
className="h-11 border-2 border-input"
|
||||
/>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
{/* 單位 */}
|
||||
<TableCell>
|
||||
<span className="text-muted-foreground">{item.unit}</span>
|
||||
</TableCell>
|
||||
|
||||
{/* 單價 */}
|
||||
<TableCell>
|
||||
{isReadOnly ? (
|
||||
<span>{formatCurrency(item.unitPrice)}</span>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
<Input
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
value={item.unitPrice || ""}
|
||||
onChange={(e) =>
|
||||
onItemChange?.(index, "unitPrice", Number(e.target.value))
|
||||
}
|
||||
disabled={isDisabled}
|
||||
className={`h-11 border-2 ${
|
||||
isPriceAlert(item.unitPrice, item.previousPrice)
|
||||
? "border-warning"
|
||||
: "border-input"
|
||||
}`}
|
||||
/>
|
||||
{isPriceAlert(item.unitPrice, item.previousPrice) && (
|
||||
<p className="caption text-warning">
|
||||
⚠️ 上次: {formatCurrency(item.previousPrice || 0)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</TableCell>
|
||||
|
||||
{/* 小計 */}
|
||||
<TableCell>
|
||||
<span>{formatCurrency(item.subtotal)}</span>
|
||||
</TableCell>
|
||||
|
||||
{/* 刪除按鈕 */}
|
||||
{!isReadOnly && onRemoveItem && (
|
||||
<TableCell>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onRemoveItem(index)}
|
||||
className="button-outlined-error"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
)}
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* 審核對話框組件
|
||||
*/
|
||||
|
||||
import { useState } from "react";
|
||||
import { Check, X } from "lucide-react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "../ui/dialog";
|
||||
import { Button } from "../ui/button";
|
||||
import { Label } from "../ui/label";
|
||||
import { Textarea } from "../ui/textarea";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "../ui/select";
|
||||
import { REJECTION_REASONS } from "../../constants/purchase-order";
|
||||
import type { PurchaseOrder } from "../../types/purchase-order";
|
||||
|
||||
interface ReviewDialogProps {
|
||||
order: PurchaseOrder;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onApprove: (orderId: string) => void;
|
||||
onReject: (orderId: string, reason: string) => void;
|
||||
}
|
||||
|
||||
export function ReviewDialog({
|
||||
order,
|
||||
open,
|
||||
onOpenChange,
|
||||
onApprove,
|
||||
onReject,
|
||||
}: ReviewDialogProps) {
|
||||
const [action, setAction] = useState<"approve" | "reject" | null>(null);
|
||||
const [rejectionReason, setRejectionReason] = useState("");
|
||||
const [customReason, setCustomReason] = useState("");
|
||||
|
||||
const handleConfirm = () => {
|
||||
if (action === "approve") {
|
||||
onApprove(order.id);
|
||||
} else if (action === "reject") {
|
||||
const finalReason =
|
||||
rejectionReason === "其他" ? customReason : rejectionReason;
|
||||
if (finalReason) {
|
||||
onReject(order.id, finalReason);
|
||||
}
|
||||
}
|
||||
handleClose();
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
setAction(null);
|
||||
setRejectionReason("");
|
||||
setCustomReason("");
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
const isValid = () => {
|
||||
if (action === "approve") return true;
|
||||
if (action === "reject") {
|
||||
if (rejectionReason === "其他") {
|
||||
return customReason.trim().length > 0;
|
||||
}
|
||||
return rejectionReason.length > 0;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
<DialogContent className="sm:max-w-[500px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>審核採購單</DialogTitle>
|
||||
<DialogDescription>
|
||||
採購單編號:{order.poNumber}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-6 py-4">
|
||||
{/* 採購單資訊摘要 */}
|
||||
<div className="bg-muted p-4 rounded-lg space-y-2">
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">申請人:</span>
|
||||
<span className="font-medium">{order.createdBy}</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">申請單位:</span>
|
||||
<span className="font-medium">{order.department}</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">廠商:</span>
|
||||
<span className="font-medium">{order.supplierName}</span>
|
||||
</div>
|
||||
<div className="flex justify-between text-sm">
|
||||
<span className="text-muted-foreground">總金額:</span>
|
||||
<span className="font-medium">
|
||||
${order.totalAmount.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 選擇審核動作 */}
|
||||
{!action && (
|
||||
<div className="space-y-3">
|
||||
<p className="text-sm text-muted-foreground">請選擇審核動作:</p>
|
||||
<div className="flex gap-3">
|
||||
<Button
|
||||
onClick={() => setAction("approve")}
|
||||
className="flex-1 gap-2 button-filled-primary"
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
審核通過
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => setAction("reject")}
|
||||
className="flex-1 gap-2 button-filled-error"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
退回
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 審核通過確認 */}
|
||||
{action === "approve" && (
|
||||
<div className="bg-green-50 border-2 border-green-200 p-4 rounded-lg">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<Check className="h-5 w-5 text-green-600" />
|
||||
<span className="font-medium text-green-900">審核通過</span>
|
||||
</div>
|
||||
<p className="text-sm text-green-700">
|
||||
通過後,此採購單將進入「已核准」狀態,可以開始進行採購作業。
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 退回原因選擇 */}
|
||||
{action === "reject" && (
|
||||
<div className="space-y-4">
|
||||
<div className="bg-red-50 border-2 border-red-200 p-4 rounded-lg">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<X className="h-5 w-5 text-red-600" />
|
||||
<span className="font-medium text-red-900">退回採購單</span>
|
||||
</div>
|
||||
<p className="text-sm text-red-700">
|
||||
退回後,申請人需要修改後重新送審。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="rejection-reason">退回原因 *</Label>
|
||||
<Select value={rejectionReason} onValueChange={setRejectionReason}>
|
||||
<SelectTrigger
|
||||
id="rejection-reason"
|
||||
className="h-11 border-2 border-input"
|
||||
>
|
||||
<SelectValue placeholder="請選擇退回原因" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{REJECTION_REASONS.map((reason) => (
|
||||
<SelectItem key={reason.value} value={reason.value}>
|
||||
{reason.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{rejectionReason === "其他" && (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="custom-reason">請說明原因 *</Label>
|
||||
<Textarea
|
||||
id="custom-reason"
|
||||
value={customReason}
|
||||
onChange={(e) => setCustomReason(e.target.value)}
|
||||
placeholder="請輸入退回原因..."
|
||||
className="border-2 border-input min-h-[100px]"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleClose}
|
||||
className="button-outlined-primary"
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
{action && (
|
||||
<Button
|
||||
onClick={handleConfirm}
|
||||
disabled={!isValid()}
|
||||
className={
|
||||
action === "approve"
|
||||
? "button-filled-primary"
|
||||
: "button-filled-error"
|
||||
}
|
||||
>
|
||||
確認{action === "approve" ? "通過" : "退回"}
|
||||
</Button>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* 狀態流程條組件
|
||||
*/
|
||||
|
||||
import { Check } from "lucide-react";
|
||||
import type { PurchaseOrderStatus } from "../../types/purchase-order";
|
||||
|
||||
interface StatusProgressBarProps {
|
||||
currentStatus: PurchaseOrderStatus;
|
||||
}
|
||||
|
||||
// 流程步驟定義(包含草稿和已退回)
|
||||
const STANDARD_FLOW_STEPS = [
|
||||
{ key: "draft", label: "草稿" },
|
||||
{ key: "review_pending", label: "待審核" },
|
||||
{ key: "approved", label: "已核准" },
|
||||
{ key: "in_transit", label: "待到貨" },
|
||||
{ key: "need_check", label: "待驗收" },
|
||||
{ key: "received", label: "已驗收" },
|
||||
{ key: "pending_payment", label: "待付款" },
|
||||
{ key: "done", label: "已完成" },
|
||||
];
|
||||
|
||||
export function StatusProgressBar({ currentStatus }: StatusProgressBarProps) {
|
||||
// 找到當前狀態在流程中的位置
|
||||
const currentIndex = STANDARD_FLOW_STEPS.findIndex((step) => step.key === currentStatus);
|
||||
|
||||
return (
|
||||
<div className="bg-card rounded-lg border-2 border-border p-6">
|
||||
<h3 className="text-sm font-medium mb-4">採購單流程</h3>
|
||||
<div className="relative">
|
||||
{/* 進度條背景 */}
|
||||
<div className="absolute top-5 left-0 right-0 h-0.5 bg-border" />
|
||||
|
||||
{/* 進度條進度 */}
|
||||
{currentIndex >= 0 && (
|
||||
<div
|
||||
className="absolute top-5 left-0 h-0.5 bg-primary-main transition-all duration-500"
|
||||
style={{
|
||||
width: `${(currentIndex / (STANDARD_FLOW_STEPS.length - 1)) * 100}%`,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 步驟標記 */}
|
||||
<div className="relative flex justify-between">
|
||||
{STANDARD_FLOW_STEPS.map((step, index) => {
|
||||
const isCompleted = index < currentIndex;
|
||||
const isCurrent = index === currentIndex;
|
||||
const isPending = index > currentIndex;
|
||||
|
||||
return (
|
||||
<div key={step.key} className="flex flex-col items-center flex-1">
|
||||
{/* 圓點 */}
|
||||
<div
|
||||
className={`w-10 h-10 rounded-full flex items-center justify-center border-2 transition-all duration-300 ${
|
||||
isCompleted
|
||||
? "bg-primary-main border-primary-main text-white"
|
||||
: isCurrent
|
||||
? "bg-white border-primary-main text-primary-main ring-4 ring-primary-main/20"
|
||||
: "bg-white border-border text-muted-foreground"
|
||||
}`}
|
||||
>
|
||||
{isCompleted ? (
|
||||
<Check className="h-5 w-5" />
|
||||
) : (
|
||||
<span className="text-sm font-medium">{index + 1}</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 標籤 */}
|
||||
<div className="mt-2 text-center">
|
||||
<p
|
||||
className={`text-xs whitespace-nowrap transition-colors ${
|
||||
isCompleted || isCurrent
|
||||
? "text-foreground font-medium"
|
||||
: "text-muted-foreground"
|
||||
}`}
|
||||
>
|
||||
{step.label}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Binary file not shown.
Reference in New Issue
Block a user