add discount
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user