@@ -434,13 +434,31 @@ export default class FinanceServices {
434434 } ,
435435 select : {
436436 reimbursementStatuses : true ,
437- totalCost : true
437+ totalCost : true ,
438+ reimbursementProducts : {
439+ where : {
440+ reimbursementProductReason : {
441+ wbsElement : {
442+ project : {
443+ projectId
444+ }
445+ }
446+ }
447+ } ,
448+ select : {
449+ cost : true
450+ }
451+ }
438452 }
439453 } ) ;
440454
441455 const { pendingFinance, pendingLeadership, submittedToSabo, reimbursed } = computeRRTotals ( reimbursementRequests ) ;
442456
443- const totalBalance = reimbursementRequests . reduce ( ( acc , curr ) => acc + curr . totalCost , 0 ) / 100 ;
457+ const totalBalance =
458+ reimbursementRequests . reduce ( ( acc , curr ) => {
459+ const projectProductsCost = curr . reimbursementProducts . reduce ( ( prodAcc , prod ) => prodAcc + prod . cost , 0 ) ;
460+ return acc + projectProductsCost ;
461+ } , 0 ) / 100 ;
444462
445463 const available = project . budget - totalBalance ;
446464
@@ -507,15 +525,37 @@ export default class FinanceServices {
507525 } ,
508526 select : {
509527 reimbursementStatuses : true ,
510- totalCost : true
528+ totalCost : true ,
529+ reimbursementProducts : {
530+ where : {
531+ reimbursementProductReason : {
532+ wbsElement : {
533+ project : {
534+ teams : {
535+ some : {
536+ teamId
537+ }
538+ }
539+ }
540+ }
541+ }
542+ } ,
543+ select : {
544+ cost : true
545+ }
546+ }
511547 }
512548 } ) ;
513549
514550 const totalBudget = team . projects . reduce ( ( acc , curr ) => acc + curr . budget , 0 ) ;
515551
516552 const { pendingFinance, pendingLeadership, submittedToSabo, reimbursed } = computeRRTotals ( reimbursementRequests ) ;
517553
518- const totalBalance = reimbursementRequests . reduce ( ( acc , curr ) => acc + curr . totalCost , 0 ) / 100 ;
554+ const totalBalance =
555+ reimbursementRequests . reduce ( ( acc , curr ) => {
556+ const teamProductsCost = curr . reimbursementProducts . reduce ( ( prodAcc , prod ) => prodAcc + prod . cost , 0 ) ;
557+ return acc + teamProductsCost ;
558+ } , 0 ) / 100 ;
519559
520560 const available = totalBudget - totalBalance ;
521561
@@ -910,7 +950,17 @@ export default class FinanceServices {
910950 } ,
911951 select : {
912952 reimbursementStatuses : true ,
913- totalCost : true
953+ totalCost : true ,
954+ reimbursementProducts : {
955+ where : {
956+ reimbursementProductReason : {
957+ otherReasonId
958+ }
959+ } ,
960+ select : {
961+ cost : true
962+ }
963+ }
914964 }
915965 } ) ;
916966
@@ -935,7 +985,8 @@ export default class FinanceServices {
935985 const lastStatus = req . reimbursementStatuses . at ( - 1 ) ?. type ;
936986
937987 if ( lastStatus && totals [ lastStatus ] !== undefined ) {
938- totals [ lastStatus ] += req . totalCost ;
988+ const categoryProductsCost = req . reimbursementProducts . reduce ( ( prodAcc , prod ) => prodAcc + prod . cost , 0 ) ;
989+ totals [ lastStatus ] += categoryProductsCost ;
939990 }
940991 } ) ;
941992
@@ -944,7 +995,10 @@ export default class FinanceServices {
944995 const submittedToSabo = totals [ Reimbursement_Status_Type . SABO_SUBMITTED ] ?? 0 ;
945996 const reimbursed = totals [ Reimbursement_Status_Type . REIMBURSED ] ?? 0 ;
946997
947- const totalBalance = reimbursementRequests . reduce ( ( acc , curr ) => acc + curr . totalCost , 0 ) ;
998+ const totalBalance = reimbursementRequests . reduce ( ( acc , curr ) => {
999+ const categoryProductsCost = curr . reimbursementProducts . reduce ( ( prodAcc , prod ) => prodAcc + prod . cost , 0 ) ;
1000+ return acc + categoryProductsCost ;
1001+ } , 0 ) ;
9481002
9491003 const available = totalBudget - totalBalance ;
9501004
0 commit comments