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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user