I want to make a receivable aging report for a customer using a SQL Server 2017 database.
This is the screenshot of the ledger table:
Ledger Table
As can be seen the sales # 10/9/8/7 are fully included in the total balance while the sales # 6 is partially included. The amount still due for payment from the sale # 6 is 345.
Now I want my aging report to look like this as on 25th April 2024
Required Aging Report
What script should I write to get this report in output?
I tried some scripts but could not get the required output. So I need the solution from scratch.