feat: add sales return functionality
- Introduced Sales Return types and interfaces in the frontend for managing sales returns. - Implemented SalesReturnsController in the backend to handle sales return endpoints. - Created SalesReturn and SalesReturnLine entities to represent sales return data. - Added DTOs for sales return responses and requests. - Configured Entity Framework for SalesReturn and SalesReturnLine entities. - Developed ISalesReturnService interface and its implementation for business logic. - Added API methods for listing sales returns, creating new returns, and fetching remaining returnable quantities. - Created frontend components for creating and listing sales returns, including validation logic. - Implemented UI for selecting invoices, reason codes, and managing return lines.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// Client-side UX validation only — required fields, format/range checks the
|
||||
// browser can already see. Server-authoritative rules (referential existence,
|
||||
// concurrency, reason-code context) are never re-implemented here. Same
|
||||
// pattern as lib/validations/procurement.ts's validateReturnLine.
|
||||
|
||||
export function validateSalesReturnLine(input: { salesInvoiceLineId: number | null; qty: string; maxQty: number | null }): Record<string, string> {
|
||||
const errors: Record<string, string> = {}
|
||||
if (!input.salesInvoiceLineId) errors.salesInvoiceLineId = "Select an invoiced line"
|
||||
const qty = Number(input.qty)
|
||||
if (!input.qty || Number.isNaN(qty) || qty <= 0) errors.qty = "Quantity must be greater than 0"
|
||||
// Client-side sanity bound on the remaining returnable qty — the server remains authoritative.
|
||||
if (input.maxQty !== null && qty > input.maxQty) {
|
||||
errors.qty = input.maxQty <= 0
|
||||
? "This line has already been fully returned"
|
||||
: `Insufficient quantity — only ${input.maxQty} remain returnable`
|
||||
}
|
||||
return errors
|
||||
}
|
||||
Reference in New Issue
Block a user