'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"; import { PaymentParams } from "hub-3a-payment-encoder"; 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); const paymentParams:PaymentParams = { Iznos:"123,66", // NOTE: use comma, not period! ImePlatitelja:"Ivan Horvat", AdresaPlatitelja:"Ilica 23", SjedistePlatitelja:"10000 Zagreb", Primatelj:"Nikola Derežić", AdresaPrimatelja:"Divka Budaka 17", SjedistePrimatelja:"Zagreb", IBAN:"HR8924020061100679445", ModelPlacanja: "HR00", // MUST contain "HR" prefix! PozivNaBroj:"2025-05", SifraNamjene:"", OpisPlacanja:"Režije-Budakova-05", }; return(

{formatYearMonth(yearMonth)} {name}

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

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

: null }

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

  • {t("payment-amount-label")}
    {paymentParams.Iznos}
  • {t("payment-recipient-label")}
    {paymentParams.Primatelj}
  • {t("payment-recipient-address-label")}
    {paymentParams.AdresaPrimatelja}
  • {t("payment-recipient-city-label")}
    {paymentParams.SjedistePrimatelja}
  • {t("payment-iban-label")}
    {paymentParams.IBAN}
  • {t("payment-model-label")}
    {paymentParams.ModelPlacanja}
  • {t("payment-reference-label")}
    {paymentParams.PozivNaBroj}
  • {t("payment-purpose-code-label")}
    {paymentParams.SifraNamjene}
  • {t("payment-description-label")}
    {paymentParams.OpisPlacanja}
); };