Populate paymentParams with actual data from database
- Updated ViewLocationCard to accept userSettings prop - Replaced all hardcoded payment values with dynamic data: * Amount calculated from monthly expenses * Payer info from tenant fields (name, street, town) * Recipient info from userSettings (name, street, town, IBAN) * Reference number and description generated from location data - Created getUserSettingsByUserId function for fetching owner settings on public pages - Updated LocationViewPage to fetch and pass userSettings to ViewLocationCard 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from "react";
|
||||
import { BilledTo, BillingLocation } from "../lib/db-types";
|
||||
import { BilledTo, BillingLocation, UserSettings } from "../lib/db-types";
|
||||
import { formatYearMonth } from "../lib/format";
|
||||
import { formatCurrency } from "../lib/formatStrings";
|
||||
import { useTranslations } from "next-intl";
|
||||
@@ -10,10 +10,13 @@ import { Pdf417Barcode } from "./Pdf417Barcode";
|
||||
import { PaymentParams } from "hub-3a-payment-encoder";
|
||||
|
||||
export interface ViewLocationCardProps {
|
||||
location: BillingLocation
|
||||
location: BillingLocation;
|
||||
userSettings: UserSettings | null;
|
||||
}
|
||||
|
||||
export const ViewLocationCard:FC<ViewLocationCardProps> = ({location: { _id, name, yearMonth, bills }}) => {
|
||||
export const ViewLocationCard:FC<ViewLocationCardProps> = ({location, userSettings}) => {
|
||||
|
||||
const { _id, name, yearMonth, bills, tenantFirstName, tenantLastName, tenantStreet, tenantTown } = location;
|
||||
|
||||
const t = useTranslations("home-page.location-card");
|
||||
|
||||
@@ -21,18 +24,18 @@ export const ViewLocationCard:FC<ViewLocationCardProps> = ({location: { _id, nam
|
||||
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",
|
||||
Iznos: (monthlyExpense/100).toFixed(2).replace(".",","),
|
||||
ImePlatitelja: (tenantFirstName && tenantLastName) ? `${tenantFirstName} ${tenantLastName}` : "",
|
||||
AdresaPlatitelja: tenantStreet ?? "",
|
||||
SjedistePlatitelja: tenantTown ?? "",
|
||||
Primatelj: (userSettings?.firstName && userSettings?.lastName) ? `${userSettings.firstName} ${userSettings.lastName}` : "",
|
||||
AdresaPrimatelja: userSettings?.street ?? "",
|
||||
SjedistePrimatelja: userSettings?.town ?? "",
|
||||
IBAN: userSettings?.iban ?? "",
|
||||
ModelPlacanja: "HR00",
|
||||
PozivNaBroj: `${yearMonth.year}-${yearMonth.month.toString().padStart(2,"0")}`,
|
||||
SifraNamjene: "",
|
||||
OpisPlacanja: `Režije-${name}-${yearMonth.month.toString().padStart(2,"0")}`,
|
||||
};
|
||||
|
||||
return(
|
||||
|
||||
Reference in New Issue
Block a user