diff --git a/app/lib/actions/printActions.ts b/app/lib/actions/printActions.ts index 45616b2..2f23ecc 100644 --- a/app/lib/actions/printActions.ts +++ b/app/lib/actions/printActions.ts @@ -41,7 +41,8 @@ export const fetchBarcodeDataForPrint = withUser(async (user: AuthenticatedUser, for (const location of locations) { for (const bill of location.bills) { - if (bill.barcodeImage && bill.barcodeImage.trim() !== "") { + // Only include bills that are billed to tenant and have barcode images + if (bill.barcodeImage && bill.barcodeImage.trim() !== "" && (bill.billedToTenant ?? true)) { printData.push({ locationName: location.name, billName: bill.name, diff --git a/app/ui/HomePage.tsx b/app/ui/HomePage.tsx index df76dc6..5b0cb3a 100644 --- a/app/ui/HomePage.tsx +++ b/app/ui/HomePage.tsx @@ -49,7 +49,7 @@ export const HomePage:FC = async ({ searchParams }) => { [key]: { yearMonth: location.yearMonth, locations: [...locationsInMonth.locations, location], - monthlyExpense: locationsInMonth.monthlyExpense + location.bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0) + monthlyExpense: locationsInMonth.monthlyExpense + location.bills.reduce((acc, bill) => (bill.paid && (bill.billedToTenant ?? true)) ? acc + (bill.payedAmount ?? 0) : acc, 0) } }) } @@ -59,7 +59,7 @@ export const HomePage:FC = async ({ searchParams }) => { [key]: { yearMonth: location.yearMonth, locations: [location], - monthlyExpense: location.bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0) + monthlyExpense: location.bills.reduce((acc, bill) => (bill.paid && (bill.billedToTenant ?? true)) ? acc + (bill.payedAmount ?? 0) : acc, 0) } }); }, {} as {[key:string]:{ diff --git a/app/ui/LocationCard.tsx b/app/ui/LocationCard.tsx index 98a32d9..76c1785 100644 --- a/app/ui/LocationCard.tsx +++ b/app/ui/LocationCard.tsx @@ -19,8 +19,8 @@ export const LocationCard:FC = ({location: { _id, name, yearM const t = useTranslations("home-page.location-card"); const currentLocale = useLocale(); - // sum all the billAmounts - const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0); + // sum all the billAmounts (only for bills billed to tenant) + const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedToTenant ?? true)) ? acc + (bill.payedAmount ?? 0) : acc, 0); const handleCopyLinkClick = () => { // copy URL to clipboard @@ -40,7 +40,7 @@ export const LocationCard:FC = ({location: { _id, name, yearM

{formatYearMonth(yearMonth)} {name}

{ - bills.map(bill => ) + bills.filter(bill => bill.billedToTenant ?? true).map(bill => ) } {t("add-bill-button-tooltip")} diff --git a/app/ui/ViewLocationCard.tsx b/app/ui/ViewLocationCard.tsx index 292b533..0aeb661 100644 --- a/app/ui/ViewLocationCard.tsx +++ b/app/ui/ViewLocationCard.tsx @@ -15,8 +15,8 @@ export const ViewLocationCard:FC = ({location: { _id, nam const t = useTranslations("home-page.location-card"); - // sum all the billAmounts - const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0); + // sum all the billAmounts (only for bills billed to tenant) + const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedToTenant ?? true)) ? acc + (bill.payedAmount ?? 0) : acc, 0); return(
@@ -24,7 +24,7 @@ export const ViewLocationCard:FC = ({location: { _id, nam

{formatYearMonth(yearMonth)} {name}

{ - bills.map(bill => ) + bills.filter(bill => bill.billedToTenant ?? true).map(bill => ) }
{