add interest
This commit is contained in:
@@ -57,6 +57,7 @@ import {
|
||||
InputGroupButton,
|
||||
InputGroupInput
|
||||
} from '@repo/ui/components/ui/input-group'
|
||||
import { calcInterest } from './payment'
|
||||
|
||||
type ReviewProps = {
|
||||
state: WizardState
|
||||
@@ -79,6 +80,13 @@ export function Review({ state, onSubmit }: ReviewProps) {
|
||||
? applyDiscount(subtotal, coupon.amount, coupon.type) * -1
|
||||
: 0
|
||||
const total = subtotal > 0 ? subtotal + discount : 0
|
||||
const installments = state.installments
|
||||
const interest_amount =
|
||||
state.payment_method === 'CREDIT_CARD' &&
|
||||
typeof installments === 'number' &&
|
||||
installments > 1
|
||||
? calcInterest(total, installments) - total
|
||||
: 0
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -117,6 +125,8 @@ export function Review({ state, onSubmit }: ReviewProps) {
|
||||
)
|
||||
})}
|
||||
</TableBody>
|
||||
|
||||
{/* Summary */}
|
||||
<TableFooter>
|
||||
<TableRow>
|
||||
<TableCell className="text-right" colSpan={3}>
|
||||
@@ -126,6 +136,7 @@ export function Review({ state, onSubmit }: ReviewProps) {
|
||||
<Currency>{subtotal}</Currency>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/* Discount */}
|
||||
<TableRow>
|
||||
<TableCell className="text-right" colSpan={3}>
|
||||
Descontos
|
||||
@@ -134,12 +145,26 @@ export function Review({ state, onSubmit }: ReviewProps) {
|
||||
<Currency>{discount}</Currency>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/* Interest */}
|
||||
{interest_amount ? (
|
||||
<TableRow>
|
||||
<TableCell className="text-right" colSpan={3}>
|
||||
Juros
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Currency>{interest_amount}</Currency>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
{/* Total */}
|
||||
<TableRow>
|
||||
<TableCell className="text-right" colSpan={3}>
|
||||
Total
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Currency>{total}</Currency>
|
||||
<Currency>{total + interest_amount}</Currency>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableFooter>
|
||||
|
||||
Reference in New Issue
Block a user