diff --git a/app/lib/db-types.ts b/app/lib/db-types.ts index d9d6cc8..bf2caef 100644 --- a/app/lib/db-types.ts +++ b/app/lib/db-types.ts @@ -38,6 +38,8 @@ export interface Bill { name: string; /** is the bill paid */ paid: boolean; + /** true if tenant to cover the bill */ + billedToTenant: boolean; /** payed amount amount in cents */ payedAmount?: number | null; /** attached document (optional) */ diff --git a/app/ui/BillEditForm.tsx b/app/ui/BillEditForm.tsx index 29a61a1..09581d3 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, attachment, notes, payedAmount: initialPayedAmount, barcodeImage: initialBarcodeImage } = bill ?? { _id:undefined, name:"", paid:false, notes:"" }; + const { _id: billID, name, paid, billedToTenant, attachment, notes, payedAmount: initialPayedAmount, barcodeImage: initialBarcodeImage } = bill ?? { _id:undefined, name:"", paid:false, billedToTenant:true, notes:"" }; const { yearMonth:{year: billYear, month: billMonth}, _id: locationID } = location; @@ -40,10 +40,16 @@ export const BillEditForm:FC = ({ location, bill }) => { const [ isScanningPDF, setIsScanningPDF ] = React.useState(false); const [ state, dispatch ] = useFormState(handleAction, initialState); const [ isPaid, setIsPaid ] = React.useState(paid); + const [ isBilledToTenant, setIsBilledToTenant ] = React.useState(billedToTenant); const [ payedAmount, setPayedAmount ] = React.useState(initialPayedAmount ? `${initialPayedAmount/100}` : "" ); const [ barcodeImage, setBarcodeImage ] = React.useState(initialBarcodeImage); const [ barcodeResults, setBarcodeResults ] = React.useState | null>(null); + + const billedToTenant_handleChange = (event: React.ChangeEvent) => { + setIsBilledToTenant(event.target.checked); + } + const billPaid_handleChange = (event: React.ChangeEvent) => { setIsPaid(event.target.checked); } @@ -202,9 +208,16 @@ export const BillEditForm:FC = ({ location, bill }) => { ))} +
+ +
+ {/* Show toggle only when adding a new bill (not editing) */} {!bill && ( -
+