This commit is contained in:
@@ -181,7 +181,26 @@ todo: restock required feature
|
||||
Create a view for this:
|
||||
|
||||
Query:
|
||||
create view arestock_required as select apartwarehouse.name, apartstocklevel.minimumquantity, apart.partnumber, vpartinventorynow.balance, apurchaseorderitem.quantityordered,
|
||||
create view vrestockrequired on
|
||||
|
||||
|
||||
/*
|
||||
This is mostly right except for quantiy on order value which, here, assumes only one poitem for this partid/warehouseid combo when in reality there could be many.
|
||||
It needs to have a subquery or another view with totals of same partid / warehouseid quantity on order
|
||||
maybe a view that then can be joined in.
|
||||
|
||||
This is because there could be any number of poitems for that same warehouse / partid potentially on order not just one as in this test here
|
||||
vpartinventorynow pulls in real time inventory
|
||||
need similar for real time quantity on order value
|
||||
|
||||
Supposedly it's most efficient and best to make a view that summarizes *all* partid / warehouse id / quantity on order values then join it in here
|
||||
and add a WHERE clause for it to limit to partid / warehouse id combo
|
||||
*/
|
||||
--query:
|
||||
|
||||
select
|
||||
apart.partnumber, apartwarehouse.name as displaywarehouse, apartstocklevel.minimumquantity, vpartinventorynow.balance,
|
||||
(coalesce(apurchaseorderitem.quantityordered,0)-coalesce(apurchaseorderitem.quantityreceived,0)) as quantityonorder,
|
||||
apartstocklevel.minimumquantity - (coalesce(vpartinventorynow.balance, 0) + (coalesce(apurchaseorderitem.quantityordered, 0))) as requiredquantity
|
||||
from
|
||||
vpartinventorynow
|
||||
@@ -189,7 +208,21 @@ left join apart on vpartinventorynow.partid=apart.id
|
||||
left join apartwarehouse on vpartinventorynow.partwarehouseid = apartwarehouse.id
|
||||
left join apartstocklevel on vpartinventorynow.partid=apartstocklevel.partid and vpartinventorynow.partwarehouseid=apartstocklevel.partwarehouseid
|
||||
left join apurchaseorderitem on vpartinventorynow.partid=apurchaseorderitem.partid and vpartinventorynow.partwarehouseid=apurchaseorderitem.partwarehouseid
|
||||
where apartstocklevel.minimumquantity is not null
|
||||
where
|
||||
apartstocklevel.minimumquantity is not null
|
||||
--and
|
||||
--quantity on order
|
||||
--coalesce(apurchaseorderitem.quantityordered,0)-coalesce(apurchaseorderitem.quantityreceived,0) > 0
|
||||
|
||||
|
||||
and
|
||||
apartstocklevel.minimumquantity -
|
||||
(
|
||||
coalesce(vpartinventorynow.balance, 0) + (coalesce(apurchaseorderitem.quantityordered,0)-coalesce(apurchaseorderitem.quantityreceived,0))
|
||||
) >0
|
||||
order by
|
||||
requiredquantity desc
|
||||
|
||||
|
||||
Then apply where clause to view at runtime to select vendor:
|
||||
select * from arestock_required where apart.wholesalerid=8 or apart.manufacturerid=8 or apart.alternativewholesalerid=8
|
||||
|
||||
Reference in New Issue
Block a user