Filter bills display to show only billedToTenant bills
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 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +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) {
|
||||||
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({
|
printData.push({
|
||||||
locationName: location.name,
|
locationName: location.name,
|
||||||
billName: bill.name,
|
billName: bill.name,
|
||||||
|
|||||||
@@ -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 ? 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<HomePageProps> = async ({ searchParams }) => {
|
|||||||
[key]: {
|
[key]: {
|
||||||
yearMonth: location.yearMonth,
|
yearMonth: location.yearMonth,
|
||||||
locations: [location],
|
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]:{
|
}, {} as {[key:string]:{
|
||||||
|
|||||||
@@ -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
|
// sum all the billAmounts (only for bills billed to tenant)
|
||||||
const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0);
|
const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedToTenant ?? true)) ? 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.map(bill => <BillBadge key={`${_id}-${bill._id}`} locationId={_id} bill={bill} />)
|
bills.filter(bill => bill.billedToTenant ?? true).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>
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location: { _id, nam
|
|||||||
|
|
||||||
const t = useTranslations("home-page.location-card");
|
const t = useTranslations("home-page.location-card");
|
||||||
|
|
||||||
// sum all the billAmounts
|
// sum all the billAmounts (only for bills billed to tenant)
|
||||||
const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0);
|
const monthlyExpense = bills.reduce((acc, bill) => (bill.paid && (bill.billedToTenant ?? true)) ? acc + (bill.payedAmount ?? 0) : acc, 0);
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div data-key={_id } className="card card-compact card-bordered max-w-[30em] min-w-[350px] bg-base-100 border-1 border-neutral my-1">
|
<div data-key={_id } className="card card-compact card-bordered max-w-[30em] min-w-[350px] bg-base-100 border-1 border-neutral my-1">
|
||||||
@@ -24,7 +24,7 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location: { _id, nam
|
|||||||
<h2 className="card-title mr-[2em] text-[1.3rem]">{formatYearMonth(yearMonth)} {name}</h2>
|
<h2 className="card-title mr-[2em] text-[1.3rem]">{formatYearMonth(yearMonth)} {name}</h2>
|
||||||
<div className="card-actions mt-[1em] mb-[1em]">
|
<div className="card-actions mt-[1em] mb-[1em]">
|
||||||
{
|
{
|
||||||
bills.map(bill => <ViewBillBadge key={`${_id}-${bill._id}`} locationId={_id} bill={bill} />)
|
bills.filter(bill => bill.billedToTenant ?? true).map(bill => <ViewBillBadge key={`${_id}-${bill._id}`} locationId={_id} bill={bill} />)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user