From 7e7eb5a2d89ee8870abf41b358deb987ece86820 Mon Sep 17 00:00:00 2001 From: Knee Cola Date: Wed, 31 Dec 2025 09:44:55 +0100 Subject: [PATCH] fix: only trigger bill forwarding for tenant-paid bills MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified bill forwarding logic to only consider bills marked as "billed to tenant" when determining if all bills are ready for forwarding. Bills billed to landlord should not affect the forwarding trigger. Changes: - Filter out landlord bills before checking if all bills are paid/attached - Improved status check to explicitly look for "pending" or "sent" status - Added edge case handling when no tenant bills exist 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- web-app/app/lib/actions/billActions.ts | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/web-app/app/lib/actions/billActions.ts b/web-app/app/lib/actions/billActions.ts index fd405bc..ef7ee0b 100644 --- a/web-app/app/lib/actions/billActions.ts +++ b/web-app/app/lib/actions/billActions.ts @@ -99,14 +99,23 @@ const shouldUpdateBillFwdStatusWhenAttached = ( return false; } - // Check billFwdStatus is null or "failed" - if (location.billFwdStatus !== null && location.billFwdStatus !== "failed") { + // Check bills have already been sent or are pending -> don't sent them again + if (location.billFwdStatus === "pending" || location.billFwdStatus === "sent") { return false; } // Check if ALL other bills have attachments const otherBills = location.bills.filter(bill => bill._id !== currentBillId); - const allOtherBillsHaveAttachments = otherBills.every(bill => bill.attachment !== null); + // filter only bills billed to tenant + // because bills billed to landlord should not trigger forwarding + const billsPayedByTenant = otherBills.filter(bill => bill.billedTo === BilledTo.Tenant); + + if(billsPayedByTenant.length === 0) { + // No other bills billed to tenant exist, so do not trigger forwarding + return false; + } + + const allOtherBillsHaveAttachments = billsPayedByTenant.every(bill => bill.attachment !== null); return allOtherBillsHaveAttachments; }; @@ -138,14 +147,23 @@ const shouldUpdateBillFwdStatusWhenPayed = ( return false; } - // Check billFwdStatus is null or "failed" - if (location.billFwdStatus !== null && location.billFwdStatus !== "failed") { + // Check bills have already been sent or are pending -> don't sent them again + if (location.billFwdStatus === "pending" || location.billFwdStatus === "sent") { return false; } // Check if ALL other bills are paid const otherBills = location.bills.filter(bill => bill._id !== currentBillId); - const allOtherBillsPaid = otherBills.every(bill => bill.paid === true); + // filter only bills billed to tenant + // because bills billed to landlord should not trigger forwarding + const billsPayedByTenant = otherBills.filter(bill => bill.billedTo === BilledTo.Tenant); + + if(billsPayedByTenant.length === 0) { + // No other bills billed to tenant exist, so do not trigger forwarding + return false; + } + + const allOtherBillsPaid = billsPayedByTenant.every(bill => bill.paid === true); return allOtherBillsPaid; };