diff --git a/web-app/app/lib/actions/monthActions.ts b/web-app/app/lib/actions/monthActions.ts index e4b72e7..6df1b4d 100644 --- a/web-app/app/lib/actions/monthActions.ts +++ b/web-app/app/lib/actions/monthActions.ts @@ -231,16 +231,15 @@ export const updateMonth = withUser(async ( return; // Location not found } - // Check each bill update to see if it triggers forwarding - for (const update of locationUpdates) { - if (shouldUpdateBillFwdStatusWhenPayed(location, update.billId, update.paid)) { - // Update billFwdStatus to "pending" - await dbClient.collection("lokacije").updateOne( - { _id: locationId }, - { $set: { billFwdStatus: "pending" } } - ); - break; // Only need to set once per location - } + // Check if any paid bill triggers forwarding (only need to check once) + const firstPaidUpdate = locationUpdates.find(update => update.paid === true); + + if (firstPaidUpdate && shouldUpdateBillFwdStatusWhenPayed(location, firstPaidUpdate.billId, true)) { + // Update billFwdStatus to "pending" + await dbClient.collection("lokacije").updateOne( + { _id: locationId }, + { $set: { billFwdStatus: "pending" } } + ); } } );