Remove billedTo filtering to show all bills to landlord
The billedTo field indicates payment responsibility (tenant vs landlord), not viewing permissions. Landlords should see and manage ALL bills. Changes: - LocationCard: Display all bills regardless of billedTo value - LocationCard: Calculate monthlyExpense from all paid bills - HomePage: Include all paid bills in monthlyExpense aggregation - printActions: Print all bills with barcodes regardless of billedTo - locationActions: Add billedTo property to fetchAllLocations result 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -255,6 +255,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
|
|||||||
_id: "$$bill._id",
|
_id: "$$bill._id",
|
||||||
name: "$$bill.name",
|
name: "$$bill.name",
|
||||||
paid: "$$bill.paid",
|
paid: "$$bill.paid",
|
||||||
|
billedTo: "$$bill.billedTo",
|
||||||
payedAmount: "$$bill.payedAmount",
|
payedAmount: "$$bill.payedAmount",
|
||||||
hasAttachment: { $ne: ["$$bill.attachment", null] },
|
hasAttachment: { $ne: ["$$bill.attachment", null] },
|
||||||
},
|
},
|
||||||
@@ -273,6 +274,7 @@ export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:nu
|
|||||||
_id: { $toString: "$$bill._id" },
|
_id: { $toString: "$$bill._id" },
|
||||||
name: "$$bill.name",
|
name: "$$bill.name",
|
||||||
paid: "$$bill.paid",
|
paid: "$$bill.paid",
|
||||||
|
billedTo: "$$bill.billedTo",
|
||||||
payedAmount: "$$bill.payedAmount",
|
payedAmount: "$$bill.payedAmount",
|
||||||
hasAttachment: "$$bill.hasAttachment",
|
hasAttachment: "$$bill.hasAttachment",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
import { getDbClient } from '../dbClient';
|
import { getDbClient } from '../dbClient';
|
||||||
import { BilledTo, BillingLocation, Bill } from '../db-types';
|
import { BillingLocation } from '../db-types';
|
||||||
import { AuthenticatedUser } from '../types/next-auth';
|
import { AuthenticatedUser } from '../types/next-auth';
|
||||||
import { withUser } from '../auth';
|
import { withUser } from '../auth';
|
||||||
import { unstable_noStore as noStore } from 'next/cache';
|
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 location of locations) {
|
||||||
for (const bill of location.bills) {
|
for (const bill of location.bills) {
|
||||||
// Only include bills that are billed to tenant and have barcode images
|
// Only include bills that have barcode images
|
||||||
if (bill.barcodeImage && bill.barcodeImage.trim() !== "" && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) {
|
if (bill.barcodeImage && bill.barcodeImage.trim() !== "") {
|
||||||
printData.push({
|
printData.push({
|
||||||
locationName: location.name,
|
locationName: location.name,
|
||||||
billName: bill.name,
|
billName: bill.name,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { fetchAllLocations } from '@/app/lib/actions/locationActions';
|
import { fetchAllLocations } from '@/app/lib/actions/locationActions';
|
||||||
import { fetchAvailableYears } from '@/app/lib/actions/monthActions';
|
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 { FC } from 'react';
|
||||||
import { MonthLocationList } from '@/app/ui/MonthLocationList';
|
import { MonthLocationList } from '@/app/ui/MonthLocationList';
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ export const HomePage:FC<HomePageProps> = async ({ searchParams }) => {
|
|||||||
[key]: {
|
[key]: {
|
||||||
yearMonth: location.yearMonth,
|
yearMonth: location.yearMonth,
|
||||||
locations: [...locationsInMonth.locations, location],
|
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<HomePageProps> = async ({ searchParams }) => {
|
|||||||
[key]: {
|
[key]: {
|
||||||
yearMonth: location.yearMonth,
|
yearMonth: location.yearMonth,
|
||||||
locations: [location],
|
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]:{
|
}, {} as {[key:string]:{
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
import { Cog8ToothIcon, PlusCircleIcon, ShareIcon } from "@heroicons/react/24/outline";
|
import { Cog8ToothIcon, PlusCircleIcon, ShareIcon } from "@heroicons/react/24/outline";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { BillBadge } from "./BillBadge";
|
import { BillBadge } from "./BillBadge";
|
||||||
import { BilledTo, BillingLocation } from "../lib/db-types";
|
import { BillingLocation } from "../lib/db-types";
|
||||||
import { formatYearMonth } from "../lib/format";
|
import { formatYearMonth } from "../lib/format";
|
||||||
import { formatCurrency } from "../lib/formatStrings";
|
import { formatCurrency } from "../lib/formatStrings";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useLocale, useTranslations } from "next-intl";
|
import { useLocale, useTranslations } from "next-intl";
|
||||||
import { toast, useToast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
export interface LocationCardProps {
|
export interface LocationCardProps {
|
||||||
location: BillingLocation
|
location: BillingLocation
|
||||||
@@ -19,8 +19,8 @@ export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, yearM
|
|||||||
const t = useTranslations("home-page.location-card");
|
const t = useTranslations("home-page.location-card");
|
||||||
const currentLocale = useLocale();
|
const currentLocale = useLocale();
|
||||||
|
|
||||||
// sum all the billAmounts (only for bills billed to tenant)
|
// sum all the paid bill amounts (regardless of who pays)
|
||||||
const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) ? acc + (bill.payedAmount ?? 0) : acc, 0);
|
const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0);
|
||||||
|
|
||||||
const handleCopyLinkClick = () => {
|
const handleCopyLinkClick = () => {
|
||||||
// copy URL to clipboard
|
// copy URL to clipboard
|
||||||
@@ -40,7 +40,7 @@ export const LocationCard:FC<LocationCardProps> = ({location: { _id, name, yearM
|
|||||||
<h2 className="card-title mr-[2em] text-[1rem]">{formatYearMonth(yearMonth)} {name}</h2>
|
<h2 className="card-title mr-[2em] text-[1rem]">{formatYearMonth(yearMonth)} {name}</h2>
|
||||||
<div className="card-actions">
|
<div className="card-actions">
|
||||||
{
|
{
|
||||||
bills.filter(bill => (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant).map(bill => <BillBadge key={`${_id}-${bill._id}`} locationId={_id} bill={bill} />)
|
bills.map(bill => <BillBadge key={`${_id}-${bill._id}`} locationId={_id} bill={bill} />)
|
||||||
}
|
}
|
||||||
<Link href={`/bill/${_id}/add`} className="tooltip" data-tip={t("add-bill-button-tooltip")}>
|
<Link href={`/bill/${_id}/add`} className="tooltip" data-tip={t("add-bill-button-tooltip")}>
|
||||||
<PlusCircleIcon className="h-[1em] w-[1em] cursor-pointer text-2xl inline-block" /><span className="ml-1 text-xs ml-[0.2rem]">{t("add-bill-button-tooltip")}</span>
|
<PlusCircleIcon className="h-[1em] w-[1em] cursor-pointer text-2xl inline-block" /><span className="ml-1 text-xs ml-[0.2rem]">{t("add-bill-button-tooltip")}</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user