How to cancel journal entry programatically

i did the same as the following

which i need now if i delete the Doctype which name is Tracking for which the journal entry was created i want to cancel the journal entry.
how this could be done?
thank you

which part of the script that show this message