diff --git a/app/Models/UtilityFee.php b/app/Models/UtilityFee.php index 9e1d6c7..9917f13 100644 --- a/app/Models/UtilityFee.php +++ b/app/Models/UtilityFee.php @@ -20,7 +20,7 @@ class UtilityFee extends Model ]; protected $casts = [ - 'transaction_date' => 'date', + 'transaction_date' => 'date:Y-m-d', 'amount' => 'decimal:2', ]; diff --git a/resources/js/Components/UtilityFee/UtilityFeeDialog.tsx b/resources/js/Components/UtilityFee/UtilityFeeDialog.tsx index d888899..124fc1b 100644 --- a/resources/js/Components/UtilityFee/UtilityFeeDialog.tsx +++ b/resources/js/Components/UtilityFee/UtilityFeeDialog.tsx @@ -16,6 +16,7 @@ import { useForm } from "@inertiajs/react"; import { toast } from "sonner"; import { Calendar } from "lucide-react"; import { getCurrentDate } from "@/utils/format"; +import { validateInvoiceNumber } from "@/utils/validation"; export interface UtilityFee { id: number; @@ -84,9 +85,9 @@ export default function UtilityFeeDialog({ e.preventDefault(); if (fee) { - // Validate invoice number format if present - if (data.invoice_number && !/^[A-Z]{2}-\d{8}$/.test(data.invoice_number)) { - toast.error("發票號碼格式錯誤,應為:AB-12345678"); + const validation = validateInvoiceNumber(data.invoice_number); + if (!validation.isValid) { + toast.error(validation.error); return; } @@ -101,9 +102,9 @@ export default function UtilityFeeDialog({ } }); } else { - // Validate invoice number format if present - if (data.invoice_number && !/^[A-Z]{2}-\d{8}$/.test(data.invoice_number)) { - toast.error("發票號碼格式錯誤,應為:AB-12345678"); + const validation = validateInvoiceNumber(data.invoice_number); + if (!validation.isValid) { + toast.error(validation.error); return; } @@ -189,8 +190,9 @@ export default function UtilityFeeDialog({ setData("invoice_number", e.target.value)} + onChange={(e) => setData("invoice_number", e.target.value.toUpperCase())} placeholder="例:AB-12345678" + maxLength={11} />

格式範例:AB-12345678

{errors.invoice_number &&

{errors.invoice_number}

} diff --git a/resources/js/Pages/UtilityFee/Index.tsx b/resources/js/Pages/UtilityFee/Index.tsx index 3439f12..8c6d4af 100644 --- a/resources/js/Pages/UtilityFee/Index.tsx +++ b/resources/js/Pages/UtilityFee/Index.tsx @@ -15,6 +15,7 @@ import { ArrowUp, ArrowDown } from 'lucide-react'; +import { Label } from "@/Components/ui/label"; import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout"; import { Head, router } from "@inertiajs/react"; import Pagination from "@/Components/shared/Pagination"; @@ -200,57 +201,69 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }:
{/* Search */} -
- - setSearchTerm(e.target.value)} - onKeyDown={(e) => e.key === "Enter" && handleSearch()} - className="pl-10" - /> - {searchTerm && ( - - )} +
+ +
+ + setSearchTerm(e.target.value)} + onKeyDown={(e) => e.key === "Enter" && handleSearch()} + className="pl-10" + /> + {searchTerm && ( + + )} +
- {/* Category Filter */} - ({ label: c, value: c })) - ]} - placeholder="篩選類別" - /> - {/* Date Range Start */} -
- - setDateStart(e.target.value)} - className="pl-9 bg-white block w-full" - placeholder="開始日期" - /> +
+ +
+ + setDateStart(e.target.value)} + className="pl-9 bg-white block w-full" + placeholder="開始日期" + /> +
{/* Date Range End */} -
- - setDateEnd(e.target.value)} - className="pl-9 bg-white block w-full" - placeholder="結束日期" +
+ +
+ + setDateEnd(e.target.value)} + className="pl-9 bg-white block w-full" + placeholder="結束日期" + /> +
+
+ + {/* Category Filter */} +
+ + ({ label: c, value: c })) + ]} + placeholder="篩選類別" />
@@ -259,13 +272,13 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }: @@ -294,6 +307,14 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }: 費用類別 + + +
- - - 說明 / 備註 操作 @@ -340,12 +353,12 @@ export default function UtilityFeeIndex({ fees, availableCategories, filters }: {fee.category} - - $ {Number(fee.amount).toLocaleString()} - {formatInvoiceNumber(fee.invoice_number)} + + $ {Number(fee.amount).toLocaleString()} + {fee.description || '-'} diff --git a/resources/js/utils/validation.ts b/resources/js/utils/validation.ts index d99f991..a9bba3e 100644 --- a/resources/js/utils/validation.ts +++ b/resources/js/utils/validation.ts @@ -70,3 +70,20 @@ export const validateWarehouse = (formData: { return { isValid: true }; }; + +/** + * 驗證發票號碼格式 (AA-12345678) + */ +export const validateInvoiceNumber = (invoiceNumber?: string): { isValid: boolean; error?: string } => { + if (!invoiceNumber) return { isValid: true }; + + const regex = /^[A-Z]{2}-\d{8}$/; + if (!regex.test(invoiceNumber)) { + return { + isValid: false, + error: "發票號碼格式錯誤,應為:AB-12345678", + }; + } + + return { isValid: true }; +};