(bugfix) ViewLocationCard: hub3a string was calculated even if this option was disabled
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC, useState } from "react";
|
import { FC, useEffect, useMemo, useState } from "react";
|
||||||
import { BillAttachment, BilledTo, BillingLocation, UserSettings } from "../lib/db-types";
|
import { BillAttachment, BilledTo, BillingLocation, UserSettings } from "../lib/db-types";
|
||||||
import { formatYearMonth } from "../lib/format";
|
import { formatYearMonth } from "../lib/format";
|
||||||
import { formatCurrency } from "../lib/formatStrings";
|
import { formatCurrency } from "../lib/formatStrings";
|
||||||
@@ -74,24 +74,30 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettin
|
|||||||
// sum all the billAmounts (only for bills billed to tenant)
|
// 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 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 = {
|
const locationNameTrimmed_max20 = locationName.trimEnd().trimEnd().substring(0,19);
|
||||||
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 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(
|
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">
|
||||||
|
|||||||
Reference in New Issue
Block a user