fix: only trigger bill forwarding for tenant-paid bills

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 <noreply@anthropic.com>
This commit is contained in:
Knee Cola
2025-12-31 09:44:55 +01:00
parent 580951b9c6
commit 7e7eb5a2d8

View File

@@ -99,14 +99,23 @@ const shouldUpdateBillFwdStatusWhenAttached = (
return false; return false;
} }
// Check billFwdStatus is null or "failed" // Check bills have already been sent or are pending -> don't sent them again
if (location.billFwdStatus !== null && location.billFwdStatus !== "failed") { if (location.billFwdStatus === "pending" || location.billFwdStatus === "sent") {
return false; return false;
} }
// Check if ALL other bills have attachments // Check if ALL other bills have attachments
const otherBills = location.bills.filter(bill => bill._id !== currentBillId); 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; return allOtherBillsHaveAttachments;
}; };
@@ -138,14 +147,23 @@ const shouldUpdateBillFwdStatusWhenPayed = (
return false; return false;
} }
// Check billFwdStatus is null or "failed" // Check bills have already been sent or are pending -> don't sent them again
if (location.billFwdStatus !== null && location.billFwdStatus !== "failed") { if (location.billFwdStatus === "pending" || location.billFwdStatus === "sent") {
return false; return false;
} }
// Check if ALL other bills are paid // Check if ALL other bills are paid
const otherBills = location.bills.filter(bill => bill._id !== currentBillId); 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; return allOtherBillsPaid;
}; };