Thank you so much @Mohammad_Ahmad_Zulfi.
It works with me and creates adjusting entries successfully. But I have one big problem with cancelling invoices.
When I try to cancel a purchase invoice, I get a message to device to cancel the adjusting entry as below:
But when I click to cancel, nothing happen, and I get a message that the Journal entry is linked.
I can’t also cancel the entry as it is linked with the invoice.
What part of the code can I check to solve this issue?

