Quickbooks online has a good example of how this can work. You can see it in their demo.
I really need a clean way to apply a single check to multiple invoices. And keep track of over payments for future credit.
In Quickbooks they have a couple ways of handling that. Each customer’s account has summary of their balance along with a dedicated transaction showing all invoices, payments, quotes, etc. with a running balance.That lets you see open and closed invoices and payments with an extra unapplied balance.
Second they have the payment screen where you can enter the customer name, payment amount, etc. and it will bring up a list of invoices for that customer. You can check boxes next to each invoice, change the amount to apply to each, and save. If you made a mistake, it is easy enough to go back into that payment and uncheck and invoice to apply to another.
If a payment was too much for the open invoices then it just has a positive balance and it can be saved for the next invoice or generate a payment back to the customer. If the balance stays on their account it is simple to open the payment again and apply it to a new invoice after one is created.
Having a way to keep track of these scenarios is fairly important in the grand scheme of book keeping and customer management.