@@ -40,6 +40,7 @@ import {
4040 TopcoderChallengesService ,
4141} from 'src/shared/topcoder/challenges.service' ;
4242import { TopcoderM2MHttpError } from 'src/shared/topcoder/topcoder-m2m.service' ;
43+ import { resolveChallengeMemberPaymentAmount } from 'src/shared/payments/challenge-payment-amount.util' ;
4344
4445const BUDGET_LEDGER_DECIMAL_PLACES = 4 ;
4546const PAYMENT_DECIMAL_PLACES = 2 ;
@@ -556,22 +557,25 @@ export class WinningsService {
556557 }
557558
558559 /**
559- * Sums non-cancelled persisted USD payment rows for a challenge and billing
560- * account.
560+ * Sums non-cancelled persisted USD member- payment rows for a challenge and
561+ * billing account.
561562 *
562563 * @param tx active Prisma transaction.
563564 * @param challengeId challenge external id stored on winnings.
564565 * @param billingAccountId billing account stored on payment rows.
565- * @returns Payment-scale total USD amount for active challenge payments on
566- * that billing account.
566+ * @returns Payment-scale member-payment amount for active challenge payments
567+ * on that billing account.
567568 */
568569 private async getPersistedChallengePaymentTotal (
569570 tx : Prisma . TransactionClient ,
570571 challengeId : string ,
571572 billingAccountId : number ,
572573 ) : Promise < number > {
573574 const payments = await tx . payment . findMany ( {
574- select : { total_amount : true } ,
575+ select : {
576+ gross_amount : true ,
577+ total_amount : true ,
578+ } ,
575579 where : {
576580 billing_account : String ( billingAccountId ) ,
577581 currency : PrizeType . USD ,
@@ -584,7 +588,12 @@ export class WinningsService {
584588 } ) ;
585589 const totalAmount = payments . reduce (
586590 ( sum , paymentRow ) =>
587- sum . plus ( new Prisma . Decimal ( paymentRow . total_amount ?? 0 ) ) ,
591+ sum . plus (
592+ resolveChallengeMemberPaymentAmount ( {
593+ grossAmount : paymentRow . gross_amount ,
594+ totalAmount : paymentRow . total_amount ,
595+ } ) ,
596+ ) ,
588597 new Prisma . Decimal ( 0 ) ,
589598 ) ;
590599
0 commit comments