Get customer balance in sales invoice with multiple cost centers

Hello dear helpers
i want to get customer balance while creating new sales invoice and i have multiple cost center,
for example, i have a customer Rafique when i select Rafique in sales invoice the both cost center outstanding balance will show up in the form and when i change the cost center to specific one then the outstanding balance should change to the desired cost center,
is it possible using custom script