Calculate the cost of goods sold automatically