I know it can happen that way, I was just curious in your case. It can also happen because of a couple of bugs in A2B . One is if the account is prepaid, then it will authenticate even when it is out of credit effectively creating negative. that is described here:
viewtopic.php?f=34&t=9308 it still exists in 2.0.1.
Two, another issue with DID to DID calls that are not free, the timeout is calculated incorrectly and allows more call time resulting in negative balance.
I've reposted a script which incorporates what you've mentioned in your post. It will work on a single machine only, not in a distributed environment where a particular account can be active anywhere.
viewtopic.php?f=35&t=9302&p=35751