diff --git a/app/lib/actions/billActions.ts b/app/lib/actions/billActions.ts index 3a5de12..48155fc 100644 --- a/app/lib/actions/billActions.ts +++ b/app/lib/actions/billActions.ts @@ -145,6 +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 barcodeImage = formData.get('barcodeImage')?.valueOf() as string; // update the bill in the mongodb @@ -159,6 +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].attachment": billAttachment, "bills.$[elem].notes": billNotes, "bills.$[elem].payedAmount": payedAmount, @@ -167,6 +169,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI }: { "bills.$[elem].name": billName, "bills.$[elem].paid": billPaid, + "bills.$[elem].billedToTenant": billedToTenant, "bills.$[elem].notes": billNotes, "bills.$[elem].payedAmount": payedAmount, "bills.$[elem].barcodeImage": barcodeImage, @@ -191,6 +194,7 @@ export const updateOrAddBill = withUser(async (user:AuthenticatedUser, locationI _id: (new ObjectId()).toHexString(), name: billName, paid: billPaid, + billedToTenant: billedToTenant, attachment: billAttachment, notes: billNotes, payedAmount, @@ -254,6 +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 attachment: null, // No attachment for subsequent months notes: billNotes, payedAmount: null, diff --git a/app/ui/BillEditForm.tsx b/app/ui/BillEditForm.tsx index 09581d3..7586b66 100644 --- a/app/ui/BillEditForm.tsx +++ b/app/ui/BillEditForm.tsx @@ -29,7 +29,7 @@ export const BillEditForm:FC = ({ location, bill }) => { const t = useTranslations("bill-edit-form"); const locale = useLocale(); - const { _id: billID, name, paid, billedToTenant, attachment, notes, payedAmount: initialPayedAmount, barcodeImage: initialBarcodeImage } = bill ?? { _id:undefined, name:"", paid:false, billedToTenant:true, notes:"" }; + const { _id: billID, name, paid, billedToTenant = true, attachment, notes, payedAmount: initialPayedAmount, barcodeImage: initialBarcodeImage } = bill ?? { _id:undefined, name:"", paid:false, notes:"" }; const { yearMonth:{year: billYear, month: billMonth}, _id: locationID } = location;