Skip to content

Commit fdfd564

Browse files
authored
MPDX-9617 Fix Credit Card Fees formula percent precision in PDS Goal Calculator (#1796)
* Fix Credit Card Fees formula percent precision in PDS Goal Calculator
1 parent 4a5f134 commit fdfd564

3 files changed

Lines changed: 68 additions & 10 deletions

File tree

.claude/rules/code-review.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,13 @@ MPDX displays and calculates donation/partner-giving aggregations across dozens
130130
**Trigger conditions:**
131131

132132
- Any file under `src/components/Reports/**`
133-
- Any file under `src/components/Reports/GoalCalculator/**` or `src/components/Reports/PdsGoalCalculator/**`
134-
- Any file under `src/components/Reports/SalaryCalculator/**`
133+
- Any file under `src/components/HrTools/**`
134+
- Any file under `src/components/Reports/GoalCalculator/**`, `src/components/HrTools/GoalCalculator/**`, or `src/components/HrTools/PdsGoalCalculator/**`
135+
- Any file under `src/components/Reports/SalaryCalculator/**` or `src/components/HrTools/SalaryCalculator/**`
135136
- Any file under `src/components/EditDonationModal/**`
136-
- Any file under `src/components/Reports/AdditionalSalaryRequest/**`, `src/components/Reports/MinisterHousingAllowance/**`
137+
- Any file under `src/components/Reports/AdditionalSalaryRequest/**`, `src/components/HrTools/AdditionalSalaryRequest/**`, or `src/components/HrTools/MinisterHousingAllowance/**`
137138
- Any file under `src/components/Dashboard/MonthlyGoal/**`, `src/components/Dashboard/DonationHistories/**`
138-
- Diff content contains any of: `amount`, `currency`, `convertedAmount`, `pledgeAmount`, `goal`, `balance`, `total`, `sum(`, `reduce((`, `.toFixed(`, `Math.round(`, `Number(`, `parseFloat(`, `parseInt(` inside `src/components/Reports/**` or goal/donation components
139+
- Diff content contains any of: `amount`, `currency`, `convertedAmount`, `pledgeAmount`, `goal`, `balance`, `total`, `sum(`, `reduce((`, `.toFixed(`, `Math.round(`, `Number(`, `parseFloat(`, `parseInt(` inside `src/components/Reports/**`, `src/components/HrTools/**`, or other goal/donation components
139140

140141
**Focus areas:**
141142

src/components/HrTools/PdsGoalCalculator/SupportItem/otherBreakdown.test.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,51 @@ describe('buildOtherBreakdownRows', () => {
157157
]);
158158
});
159159

160+
it('renders the credit-card-fees formula with the configured fee rate, not a rounded percent', () => {
161+
const fractionalRateConstants: OtherExpensesConstants = {
162+
...constants,
163+
creditCardFeeRate: 0.006,
164+
};
165+
166+
const rows = buildOtherBreakdownRows(
167+
fullTimeCalculation,
168+
fractionalRateConstants,
169+
'en-US',
170+
i18n.t,
171+
);
172+
173+
const creditCardFees = rows.find((row) => row.id === 'credit-card-fees');
174+
expect(creditCardFees?.formula).toBe(
175+
'(Subtotal + Attrition) ÷ (1 - 0.60%) - (Subtotal + Attrition)',
176+
);
177+
});
178+
179+
it('renders the attrition formula with the rate as a decimal value', () => {
180+
const rows = buildOtherBreakdownRows(
181+
fullTimeCalculation,
182+
{ ...constants, attritionRate: 0.06 },
183+
'en-US',
184+
i18n.t,
185+
);
186+
187+
const attrition = rows.find((row) => row.id === 'attrition');
188+
expect(attrition?.formula).toBe('Subtotal × 0.06%');
189+
});
190+
191+
it('renders the assessment formula with the admin rate as a decimal value', () => {
192+
const rows = buildOtherBreakdownRows(
193+
fullTimeCalculation,
194+
{ ...constants, adminRate: 0.12 },
195+
'en-US',
196+
i18n.t,
197+
);
198+
199+
const assessment = rows.find((row) => row.id === 'assessment');
200+
expect(assessment?.formula).toBe(
201+
'(Subtotal + Attrition + Credit Card Fees) ÷ (1 − 0.12%) − (Subtotal + Attrition + Credit Card Fees)',
202+
);
203+
});
204+
160205
it('uses a subtotal formula without reimbursable/403b in Simple form', () => {
161206
const simpleCalculation: OtherExpensesFields = {
162207
...fullTimeCalculation,

src/components/HrTools/PdsGoalCalculator/SupportItem/otherBreakdown.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import {
77
DesignationSupportFormType,
88
DesignationSupportStatus,
99
} from 'src/graphql/types.generated';
10-
import { currencyFormat, percentageFormat } from 'src/lib/intlFormat';
10+
import {
11+
currencyFormat,
12+
numberFormat,
13+
percentageFormat,
14+
} from 'src/lib/intlFormat';
1115
import {
1216
OtherExpensesConstants,
1317
OtherExpensesFields,
@@ -106,8 +110,11 @@ export const buildOtherBreakdownRows = (
106110
{
107111
id: 'attrition',
108112
category: t('Attrition'),
109-
formula: t('Subtotal × {{rate}}', {
110-
rate: percentageFormat(constants.attritionRate, locale),
113+
formula: t('Subtotal × {{rate}}%', {
114+
rate: numberFormat(constants.attritionRate, locale, {
115+
minimumFractionDigits: 2,
116+
maximumFractionDigits: 4,
117+
}),
111118
}),
112119
amount: totals.attrition,
113120
testId: 'other-attrition',
@@ -119,7 +126,9 @@ export const buildOtherBreakdownRows = (
119126
formula: t(
120127
'(Subtotal + Attrition) ÷ (1 - {{rate}}) - (Subtotal + Attrition)',
121128
{
122-
rate: percentageFormat(constants.creditCardFeeRate, locale),
129+
rate: percentageFormat(constants.creditCardFeeRate, locale, {
130+
fractionDigits: 2,
131+
}),
123132
},
124133
),
125134
amount: totals.creditCardFees,
@@ -130,9 +139,12 @@ export const buildOtherBreakdownRows = (
130139
id: 'assessment',
131140
category: t('Assessment'),
132141
formula: t(
133-
'(Subtotal + Attrition + Credit Card Fees) ÷ (1 − {{rate}}) − (Subtotal + Attrition + Credit Card Fees)',
142+
'(Subtotal + Attrition + Credit Card Fees) ÷ (1 − {{rate}}%) − (Subtotal + Attrition + Credit Card Fees)',
134143
{
135-
rate: percentageFormat(constants.adminRate, locale),
144+
rate: numberFormat(constants.adminRate, locale, {
145+
minimumFractionDigits: 2,
146+
maximumFractionDigits: 4,
147+
}),
136148
},
137149
),
138150
amount: totals.assessment,

0 commit comments

Comments
 (0)