How to calculate ending inventory