How to apply deposit to outstanding balance

How to apply deposit to outstanding balance

Is there a way to apply the deposit to outstanding unpaid rent? This is frustrating.  I want to show that the deposit was refundable, but they skipped out on the last month of rent, therefore we applied the deposit. I would appreciate how anyone else handles this.