I'm having great difficulty understanding how you reach your Table-2 figures.
So the following is a guess: I'm taking your invoices in date order, earliest first, then I'm looking for payments made after that invoice date and using them to pay that invoice, using as many payments as is needed to pay it fully, even if new invoices come in the meantime. Only when that first invoice is fully paid do I move onto the next invoice and use any overpayment and perhaps later payments as necessary to pay that invoice until it too is fully paid, then go onto the next invoice?
Is the following narrative an accurate description of what you're looking to happen? (where there is no 'Payment Used:' for an invoice means that only the overpayment was needed to cover the invoice)
Dealing with Invoice 19,ABC, for 90098,21/03/2022:
Payment used: NA,ABC,-106376,03/11/2022
Invoice no. 19 of 21/03/2022 for 90098 was fully paid by 03/11/2022 with an overpayment of -16278
Dealing with Invoice 11,ABC, for 1467993,14/11/2022:
Payment used: NA,ABC,-56872,16/06/2023
Payment used: NA,ABC,-1595,11/07/2023
Payment used: NA,ABC,-63823,31/03/2024
Payment used: NA,ABC,-2146000,28/10/2024
Invoice no. 11 of 14/11/2022 for 1467993 was fully paid by 28/10/2024 with an overpayment of -816575
Dealing with Invoice 3,ABC, for 50951006,25/09/2023:
Payment used: NA,ABC,-3426118,06/03/2025
Payment used: NA,ABC,-115506,11/03/2025
Payment used: NA,ABC,-132126482,22/03/2025
Invoice no. 3 of 25/09/2023 for 50951006 was fully paid by 22/03/2025 with an overpayment of -85533675
Dealing with Invoice 16,ABC, for 724260,30/05/2024:
Invoice no. 16 of 30/05/2024 for 724260 was fully paid by 22/03/2025 with an overpayment of -84809415
Dealing with Invoice 8,ABC, for 2897040,30/05/2024:
Invoice no. 8 of 30/05/2024 for 2897040 was fully paid by 22/03/2025 with an overpayment of -81912375
Dealing with Invoice 6,ABC, for 15120000,16/08/2024:
Invoice no. 6 of 16/08/2024 for 15120000 was fully paid by 22/03/2025 with an overpayment of -66792375
Dealing with Invoice 18,ABC, for 531000,07/10/2024:
Invoice no. 18 of 07/10/2024 for 531000 was fully paid by 22/03/2025 with an overpayment of -66261375
Dealing with Invoice 10,ABC, for 1622500,07/10/2024:
Invoice no. 10 of 07/10/2024 for 1622500 was fully paid by 22/03/2025 with an overpayment of -64638875
Dealing with Invoice 15,ABC, for 1396588,11/12/2024:
Invoice no. 15 of 11/12/2024 for 1396588 was fully paid by 22/03/2025 with an overpayment of -63242287
Dealing with Invoice 14,ABC, for 1396588,11/12/2024:
Invoice no. 14 of 11/12/2024 for 1396588 was fully paid by 22/03/2025 with an overpayment of -61845699
Dealing with Invoice 2,ABC, for 116237115,23/12/2024:
Invoice no. 2 of 23/12/2024 for 116237115 was partially paid by 22/03/2025 with an unpaid balance of 54391416
Dealing with Invoice 17,ABC, for 531000,25/01/2025:
Invoice no. 17 of 25/01/2025 for 531000 was not paid at all, leaving an unpaid balance of 54922416
Dealing with Invoice 9,ABC, for 1622500,25/01/2025:
Invoice no. 9 of 25/01/2025 for 1622500 was not paid at all, leaving an unpaid balance of 56544916
Dealing with Invoice 13,ABC, for 1396588,07/03/2025:
Invoice no. 13 of 07/03/2025 for 1396588 was not paid at all, leaving an unpaid balance of 57941504
Dealing with Invoice 7,ABC, for 3090198,09/03/2025:
Invoice no. 7 of 09/03/2025 for 3090198 was not paid at all, leaving an unpaid balance of 61031702
Dealing with Invoice 5,ABC, for 27374879,12/03/2025:
Invoice no. 5 of 12/03/2025 for 27374879 was not paid at all, leaving an unpaid balance of 88406581
Dealing with Invoice 4,ABC, for 27374879,12/03/2025:
Invoice no. 4 of 12/03/2025 for 27374879 was not paid at all, leaving an unpaid balance of 115781460
Dealing with Invoice 1,ABC, for 355086691,15/03/2025:
Invoice no. 1 of 15/03/2025 for 355086691 was not paid at all, leaving an unpaid balance of 470868151
Dealing with Invoice 12,ABC, for 1396588,18/03/2025:
Invoice no. 12 of 18/03/2025 for 1396588 was not paid at all, leaving an unpaid balance of 472264739