How to calculate fifo and lifo