I have table invoice which looks like this:

And I have 2000 as amount of money that I want to reduce it from these invoices one by one and when the amount of money is over I want the query to stop like this:
invoice with id = 2 --> 1500 < 2000 --> so the paid_money becomes 0
and the rest of amount of money is: 2000 - 1500 = 500 (still > 0 so we continue to the next invoice)
invoice with id = 1 -->1500.2 > 500 --> so the paid_money becomes 1500.2 - 500 = 1000.2
and the rest of the amount of money = 0 (this is the condition where I want to stop the update query)
The order of update is ORDER BY id DESC.
And thnx for your help.