Skip to content

Commit 63b4923

Browse files
authored
Merge pull request #83 from atlp-rwanda/fix-discount-on-invoice
Fix: Correct Discount Application in Invoice Generation
2 parents 8ac7857 + 8834a2b commit 63b4923

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/services/invoiceService.tsx

+17-3
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,20 @@ const InvoiceDocument: React.FC<{ data: InvoiceData }> = ({ data }) => (
121121
<Image style={styles.productImage} src={product.image} />
122122
</View>
123123
<Text style={styles.tableCell}>{product.name}</Text>
124-
<Text style={styles.tableCell}>{product.price.toFixed(2)} Rwf</Text>
124+
<Text style={styles.tableCell}>
125+
{(
126+
product.price -
127+
(product.price * product.discount) / 100
128+
).toFixed(2)}{" "}
129+
Rwf
130+
</Text>
125131
<Text style={styles.tableCell}>{product.quantity}</Text>
126132
<Text style={styles.tableCell}>
127-
{(product.price * product.quantity).toFixed(2)} Rwf
133+
{(
134+
(product.price - (product.price * product.discount) / 100) *
135+
product.quantity
136+
).toFixed(2)}{" "}
137+
Rwf
128138
</Text>
129139
</View>
130140
))}
@@ -135,7 +145,11 @@ const InvoiceDocument: React.FC<{ data: InvoiceData }> = ({ data }) => (
135145
<Text style={styles.totalText}>Total:</Text>
136146
<Text style={styles.totalAmount}>
137147
{data.products
138-
.reduce((sum, product) => sum + product.price * product.quantity, 0)
148+
.reduce((sum, product) => {
149+
const discountedPrice =
150+
product.price - (product.price * product.discount) / 100;
151+
return sum + discountedPrice * product.quantity;
152+
}, 0)
139153
.toFixed(2)}{" "}
140154
Rwf
141155
</Text>

0 commit comments

Comments
 (0)