Hi I hope someone can help me with this calculation:
I have a App with a BO call Payment and Invoice
I can receive Multiple payments for an Invoice and I can also Apply Payment to Multiple Invoices at the same time.
The problem I am have is for example:
I select 4 Invoices for a Client with different Total:
Invoice 1 = 2500
Invoice 2 = 3000
Invoice 3 = 50
Invoice 4 = 200
I begin my Payment Transaction with all 4 invoices selected and the Client send a payment of $3000.
I apply the payment the issue I am having here is I have some invoices with Invoice Total less than the payment receive, How can I apply this payment to all invoices without any negative amount. If I divide the Payment equally by the number of Invoices when the Payment Receive is more than the Invoice with the smallest amount I will get a negative.
Can someone help me with a Logic or something that will lead me in the best way to perform this calculation?