Replace billedToTenant boolean with billedTo enum
Migrated from boolean checkbox to enum-based radio buttons for better flexibility and clarity in tracking bill payment responsibility. Changes: - Added BilledTo enum with values 'tenant' and 'landlord' - Replaced Bill.billedToTenant (boolean) with Bill.billedTo (enum) - Updated BillEditForm to use radio buttons instead of checkbox - Updated billActions to handle billedTo enum values - Updated all display filtering to use enum comparison - Updated printActions barcode filtering - Updated translations for radio button labels (en/hr) The billedTo property is optional for backward compatibility - undefined values default to BilledTo.Tenant, maintaining current behavior where only tenant bills are displayed and calculated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { z } from 'zod';
|
||||
import { getDbClient } from '../dbClient';
|
||||
import { Bill, BillAttachment, BillingLocation, YearMonth } from '../db-types';
|
||||
import { Bill, BilledTo, BillAttachment, BillingLocation, YearMonth } from '../db-types';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { withUser } from '@/app/lib/auth';
|
||||
import { AuthenticatedUser } from '../types/next-auth';
|
||||
@@ -145,7 +145,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
} = validatedFields.data;
|
||||
|
||||
const billPaid = formData.get('billPaid') === 'on';
|
||||
const billedToTenant = formData.get('billedToTenant') === 'on';
|
||||
const billedTo = (formData.get('billedTo') as BilledTo) ?? BilledTo.Tenant;
|
||||
const barcodeImage = formData.get('barcodeImage')?.valueOf() as string;
|
||||
|
||||
// update the bill in the mongodb
|
||||
@@ -160,7 +160,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
const mongoDbSet = billAttachment ? {
|
||||
"bills.$[elem].name": billName,
|
||||
"bills.$[elem].paid": billPaid,
|
||||
"bills.$[elem].billedToTenant": billedToTenant,
|
||||
"bills.$[elem].billedTo": billedTo,
|
||||
"bills.$[elem].attachment": billAttachment,
|
||||
"bills.$[elem].notes": billNotes,
|
||||
"bills.$[elem].payedAmount": payedAmount,
|
||||
@@ -169,7 +169,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
}: {
|
||||
"bills.$[elem].name": billName,
|
||||
"bills.$[elem].paid": billPaid,
|
||||
"bills.$[elem].billedToTenant": billedToTenant,
|
||||
"bills.$[elem].billedTo": billedTo,
|
||||
"bills.$[elem].notes": billNotes,
|
||||
"bills.$[elem].payedAmount": payedAmount,
|
||||
"bills.$[elem].barcodeImage": barcodeImage,
|
||||
@@ -194,7 +194,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
_id: (new ObjectId()).toHexString(),
|
||||
name: billName,
|
||||
paid: billPaid,
|
||||
billedToTenant: billedToTenant,
|
||||
billedTo: billedTo,
|
||||
attachment: billAttachment,
|
||||
notes: billNotes,
|
||||
payedAmount,
|
||||
@@ -258,7 +258,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI
|
||||
_id: (new ObjectId()).toHexString(),
|
||||
name: billName,
|
||||
paid: false, // New bills in subsequent months are unpaid
|
||||
billedToTenant: true, // Default to true for subsequent months
|
||||
billedTo: BilledTo.Tenant, // Default to tenant for subsequent months
|
||||
attachment: null, // No attachment for subsequent months
|
||||
notes: billNotes,
|
||||
payedAmount: null,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use server';
|
||||
|
||||
import { getDbClient } from '../dbClient';
|
||||
import { BillingLocation, Bill } from '../db-types';
|
||||
import { BilledTo, BillingLocation, Bill } from '../db-types';
|
||||
import { AuthenticatedUser } from '../types/next-auth';
|
||||
import { withUser } from '../auth';
|
||||
import { unstable_noStore as noStore } from 'next/cache';
|
||||
@@ -42,7 +42,7 @@ export const fetchBarcodeDataForPrint = withUser(async (user: AuthenticatedUser,
|
||||
for (const location of locations) {
|
||||
for (const bill of location.bills) {
|
||||
// Only include bills that are billed to tenant and have barcode images
|
||||
if (bill.barcodeImage && bill.barcodeImage.trim() !== "" && (bill.billedToTenant ?? true)) {
|
||||
if (bill.barcodeImage && bill.barcodeImage.trim() !== "" && (bill.billedTo ?? BilledTo.Tenant) === BilledTo.Tenant) {
|
||||
printData.push({
|
||||
locationName: location.name,
|
||||
billName: bill.name,
|
||||
|
||||
@@ -31,6 +31,11 @@ export interface BillingLocation {
|
||||
notes: string|null;
|
||||
};
|
||||
|
||||
export enum BilledTo {
|
||||
Tenant = "tenant",
|
||||
Landlord = "landlord"
|
||||
}
|
||||
|
||||
/** Bill basic data */
|
||||
export interface Bill {
|
||||
_id: string;
|
||||
@@ -38,8 +43,8 @@ export interface Bill {
|
||||
name: string;
|
||||
/** is the bill paid */
|
||||
paid: boolean;
|
||||
/** true if tenant to cover the bill */
|
||||
billedToTenant: boolean;
|
||||
/** who is billed for the bill */
|
||||
billedTo?: BilledTo;
|
||||
/** payed amount amount in cents */
|
||||
payedAmount?: number | null;
|
||||
/** attached document (optional) */
|
||||
|
||||
Reference in New Issue
Block a user