Hello,
I am trying to calculate the inventory value based on the available stock .
For example
| Product | Purchase date | quantity | total cost |
|---|
| Iphone 6 | 1st Jan 2018 | 3 | $ 3000 |
| 1st Feb 2018 | 2 | $2200 |
| Iphone 6 | 1st Mar 2018 | 3 | $2700 |
| Product | Sale Date | Quantity | total sale price |
|---|
| Iphone 6 | 5th Feb 2018 | 2 | $4000 |
| 6th Mar | 2 | $3900 |
Now calculating the inventory balance
select nvl(p.branch_id,s.branch_id)Branch_id,nvl(p.prod_id,s.prod_id) product_id,
nvl(p.quantity,0) - nvl(s.quantity_sold,0) Stock_Quantity
from (
select branch_id,prod_id,sum(quantity) quantity
from costs
group by prod_id,branch_id
) p
full outer join
(select Branch_id,prod_id,
sum(quantity_sold) quantity_sold
from sales
group by branch_id,prod_id
) s
on p.prod_id = s.prod_id
and p.branch_id=s.branch_id;
will give me
Total inventory balance = 4
But calculating the inventory value seems to be troublesome for me ...
1 piece at $1100 and other 3 at $900 = $3800.
Thank you very much for any helps