Quote Originally Posted by wes4dbt View Post
Hard to suggest anything without more information.

Why are you subtracting from "a" until it's "0", then start subtracting from "b", and so on...

What is the purpose of this process?
It's a FIFO as I've already mentioned, "a" is the first so it has to be "zeroed" first before moving to the next "stock" which is "b", and so on.