Security Deposit Confusion

I am confused how the security deposits work because it keeps messing up my balance per unit. For whatever reason when i track the security deposit as returned it gives me a negative balance. Im obviously doing this wrong. Ive noticed that when I enter in the security deposit in the box it gives me a charge # but not a payment number.

What are the correct steps in taking deposit and returning deposit ?