Pull-in Customer Ledger Balance Into New Invoice

I’m not sure exactly how to write the custom script to get a customer’s ledger balance into a new Sales Invoice. Is there a function/hook for doing this?