diff --git a/app/ui/ViewLocationCard.tsx b/app/ui/ViewLocationCard.tsx index 3f1043f..0cceb9a 100644 --- a/app/ui/ViewLocationCard.tsx +++ b/app/ui/ViewLocationCard.tsx @@ -1,6 +1,6 @@ 'use client'; -import { FC, useState } from "react"; +import { FC, useEffect, useMemo, useState } from "react"; import { BillAttachment, BilledTo, BillingLocation, UserSettings } from "../lib/db-types"; import { formatYearMonth } from "../lib/format"; import { formatCurrency } from "../lib/formatStrings"; @@ -74,24 +74,30 @@ export const ViewLocationCard:FC = ({location, userSettin // 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 locationNameTrimmed_max20 = locationName.trimEnd().trimEnd().substring(0,19); + const hub3a_text = useMemo(() => { + if(!userSettings?.show2dCodeInMonthlyStatement || !generateTenantCode) { + return ""; + } - const paymentParams:PaymentParams = { - Iznos: (monthlyExpense/100).toFixed(2).replace(".",","), - ImePlatitelja: tenantName ?? "", - AdresaPlatitelja: tenantStreet ?? "", - SjedistePlatitelja: tenantTown ?? "", - Primatelj: userSettings?.ownerName ?? "", - AdresaPrimatelja: userSettings?.ownerStreet ?? "", - SjedistePrimatelja: userSettings?.ownerTown ?? "", - IBAN: userSettings?.ownerIBAN ?? "", - ModelPlacanja: "HR00", - PozivNaBroj: formatYearMonth(yearMonth), - SifraNamjene: "", - OpisPlacanja: `Režije-${locationNameTrimmed_max20}-${formatYearMonth(yearMonth)}`, // max length 35 = "Režije-" (7) + locationName (20) + "-" (1) + "YYYY-MM" (7) - }; + const locationNameTrimmed_max20 = locationName.trimEnd().trimEnd().substring(0,19); - const hub3a_text = EncodePayment(paymentParams); + const paymentParams:PaymentParams = { + Iznos: (monthlyExpense/100).toFixed(2).replace(".",","), + ImePlatitelja: tenantName ?? "", + AdresaPlatitelja: tenantStreet ?? "", + SjedistePlatitelja: tenantTown ?? "", + Primatelj: userSettings?.ownerName ?? "", + AdresaPrimatelja: userSettings?.ownerStreet ?? "", + SjedistePrimatelja: userSettings?.ownerTown ?? "", + IBAN: userSettings?.ownerIBAN ?? "", + ModelPlacanja: "HR00", + PozivNaBroj: formatYearMonth(yearMonth), + SifraNamjene: "", + OpisPlacanja: `Režije-${locationNameTrimmed_max20}-${formatYearMonth(yearMonth)}`, // max length 35 = "Režije-" (7) + locationName (20) + "-" (1) + "YYYY-MM" (7) + }; + + return(EncodePayment(paymentParams)); + }, [userSettings?.show2dCodeInMonthlyStatement, generateTenantCode, locationName, tenantName, tenantStreet, tenantTown, userSettings, monthlyExpense, yearMonth]); return(