If a customer makes the final payment before the end of the loan schedule the loan status changes to closed, and the balance reports 0, which is correct. These loans are non-recalculating and accrue interest in line with their schedules (periodic). As such all interest portions are booked into the Interest Receivable account.
However because of the closed status the accruals batch job no longer generates the periodic accruals for this loan (query excludes any status which is not active). As a result a part of this income will remain in the Interest receivable account indefinitely, which is not the expected behaviour. We would either expect the accruals to continue in line with the schedule, or for the accrual to be generated alongside the final (closing) transaction of the loan.
The quick-fix for this is to adjust the batch job to look not just look at loan status but also at any loan where the interest accrual date is smaller than the expected maturity date.
As a permanent fix we should investigate whether new accounting types/rules need to be defined for this scenario to also book this prepaid income as a liability instead of an asset account, such as Prepaid Interest received.