How to correct wrong amount in intercompany stock transfer invoice that already GRN in other company?

Problem simulation:
1st January
Company A create an intercompany stock transfer invoice to Company B, invoice was auto GRN to Company B as normal purchase.

7th March
User found that invoice amount is wrong, the selling amount should be Y instead of X.
What system have recorded:

1) Company A issue intercompany Invoice to company B
Company A INV amount is X
Company B GRN amount is X
in both company P/L has posted X in COGS, hence the GP/margin is
margin X

2) Vincent found the selling amount X is wrong, it should be Y
hence margin X is wrong, correct margin should be Y as well
Hence the solution
Company A reissue an new intercompany invoice to company B
Company A new INV amount is Y
company B new GRN amount is Y
in both company P/L will post Y in COGS, hence the GP/margin will be margin (X + Y)

3) Perform reversal of act 1)
Both companies do saler return and purchase return of invoice and GRN X respectively
So Company A issue sales return of INV X
company B issue purchase return of GRN X
thus both company P/L will post this reversal on, so now the margin will become margin (X + Y - X), then margin is corrected

The sequence for 2) and 3) has to be careful as INVENTORY WILL BE AFFECTED.
You shall follow this sequence:

Company A perform Sales return of INV X, and reissue new invoice INV Y, then company B perform GRN Y, and then purchase return of GRN X
In this way it will ease your reference as well(company A INV Y to company B GRN Y, then sales return of INV X to purchase return of GRN X)

Last but not least

4) Contra credit memo X to invoice/GRN Y
So both customer and supplier would not have extra outstanding.

Private & Confidential