Outstanding amount per item per period - SQL Query

You don’t want to “think” its right, you MUST KNOW that it’s right.

DO NOT start programming until you know exactly what it is that you need as a result and where the data will come from.