Skip to content

Commit 6419b69

Browse files
committed
Fixes for 4 decimal place markup calculations
1 parent 4f1106c commit 6419b69

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

src/billing-accounts/billing-accounts.service.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,9 @@ export class BillingAccountsService {
13531353
*
13541354
* Billing rows that store member payments plus their markup fee can be
13551355
* reversed with this helper while keeping raw markup math on the server. A
1356-
* zero markup means the full amount is a member payment.
1356+
* zero markup means the full amount is a member payment. Billing-account
1357+
* markup is stored as the direct multiplier used by finance and ledger math,
1358+
* so values greater than `1` are valid and are not percentage-normalized.
13571359
*
13581360
* @param billingAccountAmount Billing ledger amount that includes markup.
13591361
* @param markup Billing or challenge markup from persistence.
@@ -1370,24 +1372,22 @@ export class BillingAccountsService {
13701372
return undefined;
13711373
}
13721374

1373-
const normalizedMarkup = rawMarkup > 1 ? rawMarkup / 100 : rawMarkup;
1374-
1375-
if (normalizedMarkup < 0) {
1375+
if (rawMarkup < 0) {
13761376
return undefined;
13771377
}
13781378

1379-
if (normalizedMarkup === 0) {
1379+
if (rawMarkup === 0) {
13801380
return Number(amount.toFixed(2));
13811381
}
13821382

1383-
return Number((amount / (1 + normalizedMarkup)).toFixed(2));
1383+
return Number((amount / (1 + rawMarkup)).toFixed(2));
13841384
}
13851385

13861386
/**
13871387
* Calculates the copilot-safe member-payment capacity for a billing account.
13881388
*
1389-
* Remaining capacity applies the markup as a direct reduction from the
1390-
* current remaining budget: total remaining - (total remaining * markup).
1389+
* Remaining capacity reverses the billing-account markup from the current
1390+
* remaining budget using the same multiplier contract as line items.
13911391
*
13921392
* @param totalBudgetRemaining Current remaining billing-account budget.
13931393
* @param markup Billing-account markup from persistence.
@@ -1404,15 +1404,11 @@ export class BillingAccountsService {
14041404
return undefined;
14051405
}
14061406

1407-
const normalizedMarkup = rawMarkup > 1 ? rawMarkup / 100 : rawMarkup;
1408-
1409-
if (normalizedMarkup < 0) {
1407+
if (rawMarkup < 0) {
14101408
return undefined;
14111409
}
14121410

1413-
return Number(
1414-
(totalRemaining - totalRemaining * normalizedMarkup).toFixed(2),
1415-
);
1411+
return this.calculateMemberPaymentAmount(totalRemaining, rawMarkup);
14161412
}
14171413

14181414
/**

0 commit comments

Comments
 (0)