diff --git a/app/lib/actions/locationActions.ts b/app/lib/actions/locationActions.ts index d85c9f3..490924c 100644 --- a/app/lib/actions/locationActions.ts +++ b/app/lib/actions/locationActions.ts @@ -255,6 +255,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu _id: "$$bill._id", name: "$$bill.name", paid: "$$bill.paid", + billedTo: "$$bill.billedTo", payedAmount: "$$bill.payedAmount", hasAttachment: { $ne: ["$$bill.attachment", null] }, }, @@ -273,6 +274,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu _id: { $toString: "$$bill._id" }, name: "$$bill.name", paid: "$$bill.paid", + billedTo: "$$bill.billedTo", payedAmount: "$$bill.payedAmount", hasAttachment: "$$bill.hasAttachment", }, diff --git a/app/lib/actions/printActions.ts b/app/lib/actions/printActions.ts index 6a3756f..60fdfbc 100644 --- a/app/lib/actions/printActions.ts +++ b/app/lib/actions/printActions.ts @@ -1,7 +1,7 @@ 'use server'; import { getDbClient } from '../dbClient'; -import { BilledTo, BillingLocation, Bill } from '../db-types'; +import { BillingLocation } from '../db-types'; import { AuthenticatedUser } from '../types/next-auth'; import { withUser } from '../auth'; import { unstable_noStore as noStore } from 'next/cache'; @@ -41,8 +41,8 @@ export const fetchBarcodeDataForPrint = withUser(async (user: AuthenticatedUser, for (const location of locations) { for (const bill of location.bills) { - // Only include bills that are billed to tenant and have barcode images - if (bill.barcodeImage && bill.barcodeImage.trim() !== "" && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) { + // Only include bills that have barcode images + if (bill.barcodeImage && bill.barcodeImage.trim() !== "") { printData.push({ locationName: location.name, billName: bill.name, diff --git a/app/ui/HomePage.tsx b/app/ui/HomePage.tsx index 51584c3..df76dc6 100644 --- a/app/ui/HomePage.tsx +++ b/app/ui/HomePage.tsx @@ -1,6 +1,6 @@ import { fetchAllLocations } from '@/app/lib/actions/locationActions'; import { fetchAvailableYears } from '@/app/lib/actions/monthActions'; -import { BilledTo, BillingLocation, YearMonth } from '@/app/lib/db-types'; +import { BillingLocation, YearMonth } from '@/app/lib/db-types'; import { FC } from 'react'; import { MonthLocationList } from '@/app/ui/MonthLocationList'; @@ -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 && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) ? acc + (bill.payedAmount ?? 0) : acc, 0) + monthlyExpense: locationsInMonth.monthlyExpense + location.bills.reduce((acc, bill) => bill.paid ? 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 && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) ? acc + (bill.payedAmount ?? 0) : acc, 0) + monthlyExpense: location.bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0) } }); }, {} as {[key:string]:{ diff --git a/app/ui/LocationCard.tsx b/app/ui/LocationCard.tsx index bb40638..1d4558b 100644 --- a/app/ui/LocationCard.tsx +++ b/app/ui/LocationCard.tsx @@ -3,12 +3,12 @@ import { Cog8ToothIcon, PlusCircleIcon, ShareIcon } from "@heroicons/react/24/outline"; import { FC } from "react"; import { BillBadge } from "./BillBadge"; -import { BilledTo, BillingLocation } from "../lib/db-types"; +import { BillingLocation } from "../lib/db-types"; import { formatYearMonth } from "../lib/format"; import { formatCurrency } from "../lib/formatStrings"; import Link from "next/link"; import { useLocale, useTranslations } from "next-intl"; -import { toast, useToast } from "react-toastify"; +import { toast } from "react-toastify"; export interface LocationCardProps { location: BillingLocation @@ -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 (only for bills billed to tenant) - const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) ? acc + (bill.payedAmount ?? 0) : acc, 0); + // sum all the paid bill amounts (regardless of who pays) + const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? 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.filter(bill => (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant).map(bill => ) + bills.map(bill => ) } {t("add-bill-button-tooltip")}