'use client'; import { FC } from "react"; import { BilledTo, BillingLocation } from "../lib/db-types"; import { formatYearMonth } from "../lib/format"; import { formatCurrency } from "../lib/formatStrings"; import { useTranslations } from "next-intl"; import { ViewBillBadge } from "./ViewBillBadge"; import { Pdf417Barcode } from "./Pdf417Barcode"; export interface ViewLocationCardProps { location: BillingLocation } export const ViewLocationCard:FC = ({location: { _id, name, yearMonth, bills }}) => { const t = useTranslations("home-page.location-card"); // 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); return(

{formatYearMonth(yearMonth)} {name}

{ bills.filter(bill => (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant).map(bill => ) }
{ monthlyExpense > 0 ?

{ t("payed-total-label") } ${formatCurrency(monthlyExpense)}

: null }
); };