BugFix: monthly expenses calculaton not taking into account unpaied bills

This commit is contained in:
2024-01-17 15:52:38 +01:00
parent 0eb11e7d02
commit e0c20374e1
2 changed files with 16 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ import { FC, Fragment } from 'react';
import Pagination from './ui/Pagination';
import { PageHeader } from './ui/PageHeader';
import { Main } from './ui/Main';
import { MontlyExpensesCard } from './ui/MonthlyExpensesCard';
const getNextYearMonth = (yearMonth:YearMonth) => {
const {year, month} = yearMonth;
@@ -86,7 +87,7 @@ const Page:FC<PageProps> = async ({ searchParams }) => {
monthlyExpense = 0;
}
monthlyExpense += location.bills.reduce((acc, bill) => acc + (bill.payedAmount ?? 0), 0);
monthlyExpense += location.bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0);
return (
<Fragment key={`location-${location._id}`}>
@@ -102,14 +103,8 @@ const Page:FC<PageProps> = async ({ searchParams }) => {
<AddLocationButton yearMonth={location.yearMonth} /> : null
}
{
isLastLocationInMonth && monthlyExpense>0 ?
<div className="card card-compact card-bordered max-w-[36em] bg-base-100 shadow-s my-1">
<span className="card-body self-center">
<p>
Total monthly expenditure: <strong>{ formatCurrency(monthlyExpense) }</strong>
</p>
</span>
</div> : null
isLastLocationInMonth ?
<MontlyExpensesCard monthlyExpense={monthlyExpense} /> : null
}
</Fragment>
)