How to Inert new record to specific doctype using custom script or server side script

I am writing two different cashbook and bankbook entries separately but I want them to be something like if I enter bank book entry it also create opposite entry in cashbook and if write cashbook entry then it writes bankbook entry with opposite parameters.