diff --git a/app/ui/HomePage.tsx b/app/ui/HomePage.tsx index d1f152d..2932d5f 100644 --- a/app/ui/HomePage.tsx +++ b/app/ui/HomePage.tsx @@ -51,7 +51,8 @@ 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) + unpaidTotal: locationsInMonth.unpaidTotal + location.bills.reduce((acc, bill) => !bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0), + payedTotal: locationsInMonth.payedTotal + location.bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0) } }) } @@ -61,13 +62,15 @@ 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) + unpaidTotal: location.bills.reduce((acc, bill) => !bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0), + payedTotal: location.bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0) } }); }, {} as {[key:string]:{ yearMonth: YearMonth, locations: BillingLocation[], - monthlyExpense: number + unpaidTotal: number, + payedTotal: number } }); return ( diff --git a/app/ui/LocationCard.tsx b/app/ui/LocationCard.tsx index c2e88d9..0adf88d 100644 --- a/app/ui/LocationCard.tsx +++ b/app/ui/LocationCard.tsx @@ -1,6 +1,6 @@ 'use client'; -import { CheckCircleIcon, Cog8ToothIcon, PlusCircleIcon, ShareIcon, BanknotesIcon, EyeIcon, TicketIcon } from "@heroicons/react/24/outline"; +import { CheckCircleIcon, Cog8ToothIcon, PlusCircleIcon, ShareIcon, BanknotesIcon, EyeIcon, TicketIcon, ShoppingCartIcon } from "@heroicons/react/24/outline"; import { FC } from "react"; import { BillBadge } from "./BillBadge"; import { BillingLocation } from "../lib/db-types"; @@ -9,7 +9,6 @@ import { formatCurrency } from "../lib/formatStrings"; import Link from "next/link"; import { useLocale, useTranslations } from "next-intl"; import { toast } from "react-toastify"; -import { get } from "http"; import { generateShareLink } from "../lib/actions/locationActions"; export interface LocationCardProps { @@ -31,8 +30,9 @@ export const LocationCard: FC = ({ location, currency }) => { const t = useTranslations("home-page.location-card"); const currentLocale = useLocale(); - // sum all the paid bill amounts (regardless of who pays) - const monthlyExpense = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0); + // sum all the unpaid and paid bill amounts (regardless of who pays) + const totalUnpaid = bills.reduce((acc, bill) => !bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0); + const totalPayed = bills.reduce((acc, bill) => bill.paid ? acc + (bill.payedAmount ?? 0) : acc, 0); const handleCopyLinkClick = async () => { // copy URL to clipboard @@ -69,17 +69,27 @@ export const LocationCard: FC = ({ location, currency }) => { - { monthlyExpense > 0 || seenByTenantAt || utilBillsProofOfPayment?.uploadedAt ? + { totalUnpaid > 0 || totalPayed > 0 || seenByTenantAt || utilBillsProofOfPayment?.uploadedAt ? <>
{ - monthlyExpense > 0 ? + totalUnpaid > 0 ? +
+ + + {t("total-due-label")} {formatCurrency(totalUnpaid, currency ?? "EUR")} + +
+ : null + } + { + totalPayed > 0 ?
- {t("payed-total-label")} {formatCurrency(monthlyExpense, currency ?? "EUR")} + {t("total-payed-label")} {formatCurrency(totalPayed, currency ?? "EUR")}
diff --git a/app/ui/MonthCard.tsx b/app/ui/MonthCard.tsx index 4e8120e..6b7c702 100644 --- a/app/ui/MonthCard.tsx +++ b/app/ui/MonthCard.tsx @@ -9,13 +9,14 @@ import { useTranslations } from "next-intl"; export interface MonthCardProps { yearMonth: YearMonth, children?: React.ReactNode, - monthlyExpense:number, + unpaidTotal: number, + payedTotal: number, currency?: string | null, expanded?:boolean, onToggle: (yearMonth:YearMonth) => void } -export const MonthCard:FC = ({ yearMonth, children, monthlyExpense, currency, expanded, onToggle }) => { +export const MonthCard:FC = ({ yearMonth, children, unpaidTotal, payedTotal, currency, expanded, onToggle }) => { const elRef = useRef(null); const t = useTranslations("home-page.month-card"); @@ -37,9 +38,15 @@ export const MonthCard:FC = ({ yearMonth, children, monthlyExpen
{`${formatYearMonth(yearMonth)}`} { - monthlyExpense>0 ? + unpaidTotal>0 ?

- {t("payed-total-label")} { formatCurrency(monthlyExpense, currency ?? "EUR") } + {t("total-due-label")} { formatCurrency(unpaidTotal, currency ?? "EUR") } +

: null + } + { + payedTotal>0 ? +

+ {t("total-payed-label")} { formatCurrency(payedTotal, currency ?? "EUR") }

: null }
diff --git a/app/ui/MonthLocationList.tsx b/app/ui/MonthLocationList.tsx index 00668ce..ea2131e 100644 --- a/app/ui/MonthLocationList.tsx +++ b/app/ui/MonthLocationList.tsx @@ -27,7 +27,8 @@ export interface MonthLocationListProps { [key: string]: { yearMonth: YearMonth; locations: BillingLocation[]; - monthlyExpense: number; + payedTotal: number; + unpaidTotal: number; }; }; userSettings?: UserSettings | null; @@ -93,7 +94,7 @@ export const MonthLocationList:React.FC = ({ return( <> - {}} expanded={true} > + {}} expanded={true} > ) @@ -117,8 +118,8 @@ export const MonthLocationList:React.FC = ({ return(<> { - monthsArray.map(([monthKey, { yearMonth, locations, monthlyExpense }], monthIx) => - + monthsArray.map(([monthKey, { yearMonth, locations, unpaidTotal, payedTotal }], monthIx) => + { yearMonth.month === expandedMonth ? locations.map((location, ix) => ) diff --git a/app/ui/ViewLocationCard.tsx b/app/ui/ViewLocationCard.tsx index d7ed6cc..e0fd0b0 100644 --- a/app/ui/ViewLocationCard.tsx +++ b/app/ui/ViewLocationCard.tsx @@ -86,7 +86,7 @@ export const ViewLocationCard: FC = ({ location, userSett }; // 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); + const totalAmount = bills.reduce((acc, bill) => (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant ? acc + (bill.payedAmount ?? 0) : acc, 0); const { hub3aText, paymentParams } = useMemo(() => { @@ -100,7 +100,7 @@ export const ViewLocationCard: FC = ({ location, userSett const locationNameTrimmed_max20 = locationName.trimEnd().trimEnd().substring(0, 19); const paymentParams: PaymentParams = { - Iznos: (monthlyExpense / 100).toFixed(2).replace(".", ","), + Iznos: (totalAmount / 100).toFixed(2).replace(".", ","), ImePlatitelja: tenantName ?? "", AdresaPlatitelja: tenantStreet ?? "", SjedistePlatitelja: tenantTown ?? "", @@ -132,9 +132,9 @@ export const ViewLocationCard: FC = ({ location, userSett }
{ - monthlyExpense > 0 ? + totalAmount > 0 ?

- {t("payed-total-label")} {formatCurrency(monthlyExpense, userSettings?.currency)} + {t("total-due-label")} {formatCurrency(totalAmount, userSettings?.currency)}

: null } @@ -160,7 +160,7 @@ export const ViewLocationCard: FC = ({ location, userSett } { userSettings?.enableRevolutPayment && tenantPaymentMethod === "revolut" ? (() => { - const revolutPaymentUrl = `https://revolut.me/${userSettings.ownerRevolutProfileName?.replace('@', '')}?amount=${(monthlyExpense).toFixed(0)}¤cy=${userSettings.currency}`; + const revolutPaymentUrl = `https://revolut.me/${userSettings.ownerRevolutProfileName?.replace('@', '')}?amount=${(totalAmount).toFixed(0)}¤cy=${userSettings.currency}`; return ( <>

{t("payment-info-header")}

diff --git a/messages/en.json b/messages/en.json index 31d4b0c..fd95348 100644 --- a/messages/en.json +++ b/messages/en.json @@ -61,7 +61,8 @@ "location-card": { "edit-card-tooltip": "Edit realestate", "add-bill-button-tooltip": "Add a new bill", - "payed-total-label": "Payed total:", + "total-due-label": "Total due:", + "total-payed-label": "Total payed:", "link-copy-message": "Link copied to clipboard", "monthly-statement-legend": "Monthly statement", "seen-by-tenant-label": "seen by tenant", @@ -81,7 +82,8 @@ "revolut-link-text": "Pay with Revolut" }, "month-card": { - "payed-total-label": "Total monthly expenditure:", + "total-due-label": "Monthly due total:", + "total-payed-label": "Monthly payed total:", "print-codes-tooltip": "Print 2D codes", "print-codes-label": "Print codes" }, diff --git a/messages/hr.json b/messages/hr.json index a55fac4..583889d 100644 --- a/messages/hr.json +++ b/messages/hr.json @@ -61,7 +61,8 @@ "location-card": { "edit-card-tooltip": "Izmjeni nekretninu", "add-bill-button-tooltip": "Dodaj novi račun", - "payed-total-label": "Ukupno plaćeno:", + "total-due-label": "Ukupno neplaćeno:", + "total-payed-label": "Ukupno plaćeno:", "link-copy-message": "Link kopiran na clipboard", "monthly-statement-legend": "Obračun", "seen-by-tenant-label": "viđeno od strane podstanara", @@ -81,7 +82,8 @@ "revolut-link-text": "Plati pomoću Revoluta" }, "month-card": { - "payed-total-label": "Ukupni mjesečni trošak:", + "total-due-label": "Ukupno neplaćeno u mjesecu:", + "total-payed-label": "Ukupno plaćeno u mjesecu:", "print-codes-tooltip": "Ispis 2d kodova", "print-codes-label": "Ispis kodova" },