Implement bill forwarding strategy with radio button persistence

Added billFwdStrategy field to store user's choice for when to forward
utility bills to tenants, with database persistence and UI updates.

Changes:
- Added billFwdStrategy field to BillingLocation interface ("when-payed" | "when-attached")
- Updated FormSchema to validate billFwdStrategy enum values
- Modified updateOrAddLocation to persist billFwdStrategy in all database operations
- Defaults to "when-payed" (first option) when no value exists in database
- Updated LocationEditForm radio buttons to use persisted database values
- Radio button selection is preserved across edits and restored from database
- Renamed autoTenantNotification to autoBillFwd throughout codebase
- Updated localization strings for bill forwarding features

Form behavior:
- New locations: "when-payed" radio selected by default
- Existing locations: Radio selection matches stored database value
- Value persisted in current, subsequent, and all month update operations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-11-18 10:10:18 +01:00
parent c5fe184f9c
commit f4e82b7314
5 changed files with 157 additions and 100 deletions

View File

@@ -20,6 +20,7 @@ export type State = {
tenantLastName?: string[]; tenantLastName?: string[];
autoBillFwd?: string[]; autoBillFwd?: string[];
tenantEmail?: string[]; tenantEmail?: string[];
billFwdStrategy?: string[];
}; };
message?:string | null; message?:string | null;
}; };
@@ -37,6 +38,7 @@ const FormSchema = (t:IntlTemplateFn) => z.object({
tenantLastName: z.string().optional().nullable(), tenantLastName: z.string().optional().nullable(),
autoBillFwd: z.boolean().optional().nullable(), autoBillFwd: z.boolean().optional().nullable(),
tenantEmail: z.string().email(t("tenant-email-invalid")).optional().or(z.literal("")).nullable(), tenantEmail: z.string().email(t("tenant-email-invalid")).optional().or(z.literal("")).nullable(),
billFwdStrategy: z.enum(["when-payed", "when-attached"]).optional().nullable(),
addToSubsequentMonths: z.boolean().optional().nullable(), addToSubsequentMonths: z.boolean().optional().nullable(),
updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(), updateScope: z.enum(["current", "subsequent", "all"]).optional().nullable(),
}) })
@@ -92,6 +94,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: formData.get('tenantLastName') || null, tenantLastName: formData.get('tenantLastName') || null,
autoBillFwd: formData.get('autoBillFwd') === 'on', autoBillFwd: formData.get('autoBillFwd') === 'on',
tenantEmail: formData.get('tenantEmail') || null, tenantEmail: formData.get('tenantEmail') || null,
billFwdStrategy: formData.get('billFwdStrategy') as "when-payed" | "when-attached" | undefined,
addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on', addToSubsequentMonths: formData.get('addToSubsequentMonths') === 'on',
updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined, updateScope: formData.get('updateScope') as "current" | "subsequent" | "all" | undefined,
}); });
@@ -112,6 +115,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName, tenantLastName,
autoBillFwd, autoBillFwd,
tenantEmail, tenantEmail,
billFwdStrategy,
addToSubsequentMonths, addToSubsequentMonths,
updateScope, updateScope,
} = validatedFields.data; } = validatedFields.data;
@@ -150,6 +154,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null, tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null, tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
} }
} }
); );
@@ -176,6 +181,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null, tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null, tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
} }
} }
); );
@@ -195,6 +201,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null, tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null, tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
} }
} }
); );
@@ -212,6 +219,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null, tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null, tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
yearMonth: yearMonth, yearMonth: yearMonth,
bills: [], bills: [],
}); });
@@ -281,6 +289,7 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
tenantLastName: tenantLastName || null, tenantLastName: tenantLastName || null,
autoBillFwd: autoBillFwd || false, autoBillFwd: autoBillFwd || false,
tenantEmail: tenantEmail || null, tenantEmail: tenantEmail || null,
billFwdStrategy: billFwdStrategy || "when-payed",
yearMonth: { year: monthData.year, month: monthData.month }, yearMonth: { year: monthData.year, month: monthData.month },
bills: [], bills: [],
}); });

View File

@@ -53,6 +53,8 @@ export interface BillingLocation {
autoBillFwd?: boolean | null; autoBillFwd?: boolean | null;
/** (optional) tenant email */ /** (optional) tenant email */
tenantEmail?: string | null; tenantEmail?: string | null;
/** (optional) bill forwarding strategy */
billFwdStrategy?: "when-payed" | "when-attached" | null;
}; };
export enum BilledTo { export enum BilledTo {

View File

@@ -79,8 +79,10 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
</p> </p>
))} ))}
</div> </div>
<fieldset className="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4 pb-2 mt-4">
<legend className="fieldset-legend font-semibold">{t("tenant-2d-code-legend")}</legend>
<div className="form-control mt-4"> <div className="form-control mt-[-1em]">
<label className="label cursor-pointer justify-start gap-3"> <label className="label cursor-pointer justify-start gap-3">
<input <input
type="checkbox" type="checkbox"
@@ -89,7 +91,7 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
checked={generateTenantCode} checked={generateTenantCode}
onChange={(e) => setGenerateTenantCode(e.target.checked)} onChange={(e) => setGenerateTenantCode(e.target.checked)}
/> />
<span className="label-text">{t("generate-tenant-code")}</span> <span className="label-text">{t("tenant-2d-code-toggle-label")}</span>
</label> </label>
</div> </div>
@@ -142,7 +144,11 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
</div> </div>
</> </>
)} )}
</fieldset>
<fieldset className="fieldset bg-base-200 border-base-300 rounded-box w-xs border p-4 pb-2 mt-4">
<legend className="fieldset-legend font-semibold">{t("auto-utility-bill-forwarding-legend")}</legend>
<div className="form-control"> <div className="form-control">
<label className="label cursor-pointer justify-start gap-3"> <label className="label cursor-pointer justify-start gap-3">
<input <input
@@ -152,11 +158,39 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
checked={autoBillFwd} checked={autoBillFwd}
onChange={(e) => setautoBillFwd(e.target.checked)} onChange={(e) => setautoBillFwd(e.target.checked)}
/> />
<span className="label-text">{t("auto-utility-bill-forwarding")}</span> <span className="label-text">{t("auto-utility-bill-forwarding-toggle-label")}</span>
</label> </label>
</div> </div>
{autoBillFwd && ( {autoBillFwd && (
<>
<div className="form-control">
<div className="label">
<span className="label-text font-medium">{t("utility-bill-forwarding-strategy-label")}</span>
</div>
<div className="flex flex-col gap-1 ml-4">
<label className="label cursor-pointer justify-start gap-3 py-1">
<input
type="radio"
name="billFwdStrategy"
value="when-payed"
className="radio radio-primary"
defaultChecked={(location?.billFwdStrategy ?? "when-payed") === "when-payed"}
/>
<span className="label-text">{t("utility-bill-forwarding-when-payed")}</span>
</label>
<label className="label cursor-pointer justify-start gap-3 py-1">
<input
type="radio"
name="billFwdStrategy"
value="when-attached"
className="radio radio-primary"
defaultChecked={location?.billFwdStrategy === "when-attached"}
/>
<span className="label-text">{t("utility-bill-forwarding-when-attached")}</span>
</label>
</div>
</div>
<div className="form-control w-full"> <div className="form-control w-full">
<label className="label"> <label className="label">
<span className="label-text">{t("tenant-email-label")}</span> <span className="label-text">{t("tenant-email-label")}</span>
@@ -179,7 +213,9 @@ export const LocationEditForm: FC<LocationEditFormProps> = ({ location, yearMont
))} ))}
</div> </div>
</div> </div>
</>
)} )}
</fieldset>
{/* Show different options for add vs edit operations */} {/* Show different options for add vs edit operations */}
{!location ? ( {!location ? (

View File

@@ -124,14 +124,19 @@
"location-edit-form": { "location-edit-form": {
"location-name-placeholder": "Realestate name", "location-name-placeholder": "Realestate name",
"notes-placeholder": "Notes", "notes-placeholder": "Notes",
"generate-tenant-code": "generate 2D code for tenant", "tenant-2d-code-legend": "TENANT 2D CODE",
"tenant-2d-code-toggle-label": "generate 2d code",
"tenant-first-name-label": "Tenant First Name", "tenant-first-name-label": "Tenant First Name",
"tenant-first-name-placeholder": "Enter tenant's first name", "tenant-first-name-placeholder": "Enter tenant's first name",
"tenant-last-name-label": "Tenant Last Name", "tenant-last-name-label": "Tenant Last Name",
"tenant-last-name-placeholder": "Enter tenant's last name", "tenant-last-name-placeholder": "Enter tenant's last name",
"auto-utility-bill-forwarding": "automatic utility bill forwarding", "auto-utility-bill-forwarding-legend": "AUTOMATIC UTILITY BILL FORWARDING",
"auto-utility-bill-forwarding-toggle-label": "forward utility bills",
"tenant-email-label": "Tenant Email", "tenant-email-label": "Tenant Email",
"tenant-email-placeholder": "Enter tenant's email", "tenant-email-placeholder": "Enter tenant's email",
"utility-bill-forwarding-strategy-label": "Forward utility bills when ...",
"utility-bill-forwarding-when-payed": "all bills are marked as paid",
"utility-bill-forwarding-when-attached": "a bill (PDF) is attached to all items",
"warning-missing-tenant-names": "Warning: Tenant first and last name are missing. The 2D barcode will not be displayed to the tenant when they open the shared link until both fields are filled in.", "warning-missing-tenant-names": "Warning: Tenant first and last name are missing. The 2D barcode will not be displayed to the tenant when they open the shared link until both fields are filled in.",
"save-button": "Save", "save-button": "Save",
"cancel-button": "Cancel", "cancel-button": "Cancel",

View File

@@ -123,14 +123,19 @@
"location-edit-form": { "location-edit-form": {
"location-name-placeholder": "Ime nekretnine", "location-name-placeholder": "Ime nekretnine",
"notes-placeholder": "Bilješke", "notes-placeholder": "Bilješke",
"generate-tenant-code": "generiraj 2D barkod za podstanara", "tenant-2d-code-legend": "2D BARKOD ZA PODSTANARA",
"tenant-2d-code-toggle-label": "generiraj 2D barkod",
"tenant-first-name-label": "Ime podstanara", "tenant-first-name-label": "Ime podstanara",
"tenant-first-name-placeholder": "Unesite ime podstanara", "tenant-first-name-placeholder": "Unesite ime podstanara",
"tenant-last-name-label": "Prezime podstanara", "tenant-last-name-label": "Prezime podstanara",
"tenant-last-name-placeholder": "Unesite prezime podstanara", "tenant-last-name-placeholder": "Unesite prezime podstanara",
"auto-utility-bill-forwarding": "automatsko prosljeđivanje režija", "auto-utility-bill-forwarding-legend": "AUTOMATSKO PROSLJEĐIVANJE REŽIJA",
"auto-utility-bill-forwarding-toggle-label": "proslijedi režije automatski",
"tenant-email-label": "Email podstanara", "tenant-email-label": "Email podstanara",
"tenant-email-placeholder": "Unesite email podstanara", "tenant-email-placeholder": "Unesite email podstanara",
"utility-bill-forwarding-strategy-label": "Režije proslijedi kada...",
"utility-bill-forwarding-when-payed": "sve režije označim kao plaćene",
"utility-bill-forwarding-when-attached": "za sve stavke priložim račun (PDF)",
"warning-missing-tenant-names": "Upozorenje: Ime i prezime podstanara nedostaju. 2D barkod neće biti prikazan podstanaru kada otvori podijeljenu poveznicu dok oba polja ne budu popunjena.", "warning-missing-tenant-names": "Upozorenje: Ime i prezime podstanara nedostaju. 2D barkod neće biti prikazan podstanaru kada otvori podijeljenu poveznicu dok oba polja ne budu popunjena.",
"save-button": "Spremi", "save-button": "Spremi",
"cancel-button": "Odbaci", "cancel-button": "Odbaci",