Apply deposits to invoice

Hey

I tried to find an answer to this question online, but couldn't find anything yet. So here's the deal. I have a construction company and they collect deposits or down payments or however you want to call it. And after the job is done they get an invoice. How do I use this deposit now to "pay" the invoice? When I record an invoice, the invoice still shows as not paid, even though the customer has paid it all with the deposits he has made before.

I am using Sage 50 Accountant Edition. Let me know if you need more details. I appreciate any help! Thanks.