Hello everyone,
I have always wanted to know how developers go about solving certain issues that do not have one specific or standard solution, so I wanted to know how better it could have been done, differently than the way I did.
Now I have one issue about inventory and items added to storage in different shipments (Transactions In) by indicating the cost of each batch.
When items are accumulated from multiple shipments/batches the cost is not necessarily the same. So let's say we have ItemA, adding batch-I of 150 items at the cost $1800 ($12 each), then later, batch-II of 250 items at the cost $3,625 (14.5 each), then batch-III of 100 items at the cost $1300 (13 each).
I know there are inventory methods (FIFO/LIFO/Average), but that is not the issue.
My question is, considering FIFO method is used, how do I record and calculate the Transactions Out?
For instance, when all the items of Batch-I fully consumed and then Batch-II is used, how does the cost get calculated programmatically:
Transactions In:
Qty | Unit Cost $
Batch-I 150 | 12
Batch-II 250 | 14.5
Batch-III 100 | 13
Transactions Out:
Qty | Total Cost $
Operation-I 200 | 2,525 (150X12 + 50X14.5)
Operation-II 100 | 1,450 (remaining 100 items of Batch-II)
and so on...
What I am currently doing is recalculating Operations out of the Batches every time I need to show the balance, by looping through Operations and subtract from the batches until the most recent operation, but there is something that does not feel right.
Then I start thinking may be I need to improve some how, MAY BE, by record the remaining of item balance as static value and start calculating from that point, but this creates problem when editing the amounts/Qty of old Batches/Operations?
So has anyone got any experience in a way that better works on such systems?
Thanks in advance.