How to Calculate Ending Inventory: A Comprehensive Guide