Files
star-erp/resources/js/utils/validation.ts
sky121113 b2a63bd1ed
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 44s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped
優化公共事業費:修正日期顯示、改善發票號碼輸入UX與調整介面欄位順序
2026-01-20 13:02:05 +08:00

90 lines
2.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 驗證相關工具函式
*/
/**
* 驗證撥補單表單資料
*/
export const validateTransferOrder = (formData: {
sourceWarehouseId: string;
targetWarehouseId: string;
productId: string;
quantity: number;
}): { isValid: boolean; error?: string } => {
if (!formData.sourceWarehouseId) {
return { isValid: false, error: "請選擇來源倉庫" };
}
if (!formData.targetWarehouseId) {
return { isValid: false, error: "請選擇目標倉庫" };
}
if (formData.sourceWarehouseId === formData.targetWarehouseId) {
return { isValid: false, error: "來源倉庫與目標倉庫不能相同" };
}
if (!formData.productId) {
return { isValid: false, error: "請選擇撥補商品" };
}
if (formData.quantity <= 0) {
return { isValid: false, error: "撥補數量必須大於0" };
}
return { isValid: true };
};
/**
* 驗證撥補數量是否超過可用庫存
*/
export const validateTransferQuantity = (
quantity: number,
availableQuantity: number
): { isValid: boolean; error?: string } => {
if (quantity > availableQuantity) {
return {
isValid: false,
error: `撥補數量不能超過可用庫存 (${availableQuantity})`,
};
}
return { isValid: true };
};
/**
* 驗證倉庫表單資料
*/
export const validateWarehouse = (formData: {
code: string;
name: string;
address: string;
}): { isValid: boolean; error?: string } => {
if (!formData.name.trim()) {
return { isValid: false, error: "倉庫名稱為必填欄位" };
}
if (!formData.address.trim()) {
return { isValid: false, error: "倉庫地址為必填欄位" };
}
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 };
};