If advance amount has been collected before integrating ZATCA, (where there is no prepayment sequential number generated against this advance collection).
How to manage this advance amount in invoices after integration?
Shall all the collected amount be shared through prepayments first and then be applied in invoices?
No, there is no need to create a new e-invoice for this, use the invoice details that was entered in the system before integration.
Then, the retention amount should be mentioned on the human readable invoice to reduce the final payable amount. It will not be included in the XML, and it will not reduce the Tax amount. This means that you will collect from the customer a lesser amount but pay the VAT based on the full amount.
At the end of the project you will issue a Commercial Invoice to collect the Retention amount(s), and at that point there is no VAT to be paid (as this has been paid already).