add discount

This commit is contained in:
2025-12-25 12:03:13 -03:00
parent 82ab691fbb
commit d0625546c8
4 changed files with 179 additions and 192 deletions

View File

@@ -134,3 +134,20 @@ export function Discount({ onChange, ...props }: DiscountProps) {
</Popover>
)
}
export function applyDiscount(
subtotal: number,
discountAmount: number,
discountType: 'FIXED' | 'PERCENT'
) {
if (subtotal <= 0) {
return 0
}
const amount =
discountType === 'PERCENT'
? (subtotal * discountAmount) / 100
: discountAmount
return Math.min(amount, subtotal)
}