@@ -24,6 +24,7 @@ import { useBackendContext } from "../../contexts/hooks/useBackendContext";
2424import { EmailSidebar } from "../email/EmailSidebar.jsx" ;
2525import Navbar from "../navbar/Navbar" ;
2626import { InvoiceView } from "./InvoiceView" ;
27+ import { getPastDue } from "../../utils/pastDueCalc" ;
2728
2829const SavedInvoiceNavBar = ( { onBack, id, invoice, payees, programName } ) => {
2930 const { isOpen, onOpen, onClose } = useDisclosure ( ) ;
@@ -160,32 +161,33 @@ export const SavedEdit = () => {
160161 // setSubtotal(subtotalResponse.data.total);
161162
162163 // ==== PAST DUE CALCULATION ====
163- const unpaidInvoicesResponse = await backend . get (
164- "/events/remaining/" + currentInvoiceResponse . data [ 0 ] [ "eventId" ]
165- ) ;
166-
167- // calculate sum of unpaid/remaining invoices
168- const unpaidTotals = await Promise . all (
169- unpaidInvoicesResponse . data . map ( ( invoice ) =>
170- backend . get ( `/invoices/total/${ invoice . id } ` )
171- )
172- ) ;
173- const partiallyPaidTotals = await Promise . all (
174- unpaidInvoicesResponse . data . map ( ( invoice ) =>
175- backend . get ( `/invoices/paid/${ invoice . id } ` )
176- )
177- ) ;
178- const unpaidTotal = unpaidTotals . reduce (
179- ( sum , res ) => sum + res . data . total ,
180- 0
181- ) ;
182- const unpaidPartiallyPaidTotal = partiallyPaidTotals . reduce (
183- ( sum , res ) => {
184- return sum + Number ( res . data . total ) ; // Had to change to number because was causing NaN
185- } ,
186- 0
187- ) ;
188- const remainingBalance = unpaidTotal - unpaidPartiallyPaidTotal ;
164+ // const unpaidInvoicesResponse = await backend.get(
165+ // "/events/remaining/" + currentInvoiceResponse.data[0]["eventId"]
166+ // );
167+
168+ // // calculate sum of unpaid/remaining invoices
169+ // const unpaidTotals = await Promise.all(
170+ // unpaidInvoicesResponse.data.map((invoice) =>
171+ // backend.get(`/invoices/total/${invoice.id}`)
172+ // )
173+ // );
174+ // const partiallyPaidTotals = await Promise.all(
175+ // unpaidInvoicesResponse.data.map((invoice) =>
176+ // backend.get(`/invoices/paid/${invoice.id}`)
177+ // )
178+ // );
179+ // const unpaidTotal = unpaidTotals.reduce(
180+ // (sum, res) => sum + res.data.total,
181+ // 0
182+ // );
183+ // const unpaidPartiallyPaidTotal = partiallyPaidTotals.reduce(
184+ // (sum, res) => {
185+ // return sum + Number(res.data.total); // Had to change to number because was causing NaN
186+ // },
187+ // 0
188+ // );
189+ // const remainingBalance = unpaidTotal - unpaidPartiallyPaidTotal;
190+ const remainingBalance = await getPastDue ( backend , id ) ;
189191 setPastDue ( remainingBalance ) ;
190192
191193 // ==== END OF PAST DUE CALCULATION ====
0 commit comments