From f0ccac3f689c238b6a0dc258de207874f5656b37 Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Mon, 17 Nov 2025 13:36:42 +0100 Subject: [PATCH] Filter bills display to show only billedToTenant bills MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated all components to respect the billedToTenant flag: - LocationCard: Filter bills display and monthlyExpense calculation - ViewLocationCard: Filter bills display and monthlyExpense calculation - HomePage: Update monthlyExpense calculations for month grouping - printActions: Filter barcode print data to only include tenant bills All filtering uses (bill.billedToTenant ?? true) for backward compatibility with existing bills that don't have this property set. This ensures users only see and calculate expenses for bills that are the tenant's responsibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/lib/actions/printActions.ts | 3 ++- app/ui/HomePage.tsx | 4 ++-- app/ui/LocationCard.tsx | 6 +++--- app/ui/ViewLocationCard.tsx | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) 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 => ) }
{