How to calculate and record cost of goods sold