Skip to content

Commit

Permalink
[Coupons] - Cashback totals in order table displaying row with "0" af…
Browse files Browse the repository at this point in the history
…ter cashback has been removed (#143)

* fix: remove cashback entries with zero total amount to clean up breakdown

* 4.44.7

* fix: streamline cashback removal process to eliminate empty entries from breakdown

* 4.44.8

* fix: update cashback filtering to use Dinero for amount comparison

* 4.44.9

* fix: enhance cashback calculation by adding coupon validation and simplifying filter logic

* 4.44.10
  • Loading branch information
JoFont authored Dec 7, 2024
1 parent 3910e3c commit 98a893b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@epilot/pricing",
"version": "4.44.6",
"version": "4.44.10",
"description": "Pricing Library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
9 changes: 8 additions & 1 deletion src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ const recomputeDetailTotals = (
? toDineroFromInteger(priceItemToAppend.cashback_amount!)
: undefined;

const coupon = (priceItemToAppend as PriceItemDto)?._coupons?.[0];

const cashbackPeriod = priceItemToAppend.cashback_period;
const priceBeforeDiscountAmountTotal =
typeof priceItemToAppend.before_discount_amount_total !== 'undefined'
Expand Down Expand Up @@ -579,7 +581,7 @@ const recomputeDetailTotals = (
}

// Cashback totals
if (priceCashBackAmount && cashbackPeriod !== undefined) {
if (priceCashBackAmount && cashbackPeriod !== undefined && Boolean(coupon)) {
const cashbackMatchIndex = cashbacks.findIndex((cashback) => cashback.cashback_period === cashbackPeriod);

if (cashbackMatchIndex !== -1) {
Expand All @@ -594,6 +596,11 @@ const recomputeDetailTotals = (
}
}

// Remove empty cashbacks from the breakdown
if (cashbacks.length > 0) {
cashbacks.filter((cashback) => cashback.amount_total > 0);
}

return {
amount_subtotal: subtotal.add(priceSubtotal).getAmount(),
amount_total: total.add(priceTotal).getAmount(),
Expand Down

0 comments on commit 98a893b

Please sign in to comment.