How to programatically reorganize payment schedule

We have hundreds of transactions that we need to reorganize. Normally to do this, you go in :
“Accounts Receivable/Customers”, select a Customer and click on “Invoice/Settle Open Transactions”, then you check the “Mark” of the transaction you want to reorganize, then click on “Transaction reorganizing” button, then enter the new payment Schedule with the amounts or percentage, then click the “Accept” button.

I have the list of all transactions with due date and amounts to reschedule. I need to write X++ code to reschedule all transactions, because it’s going to take days to do this manually. I’ve started looking at different tables and classes used for this procedure like TmpCustVendTransReorg and CustVendTransReorg, but I’m unable to find the correct way to do it.

If anyone has a piece of code or a link that could help me with this. Would be much appreciated.