This commit is contained in:
@@ -169,105 +169,15 @@ todo: how to add locale keys in future after release without erasing all data?
|
||||
|
||||
|
||||
|
||||
CURRENTLY DOING: PurchaseOrder
|
||||
|
||||
|
||||
|
||||
PO todo
|
||||
CURRENTLY DOING: PurchaseOrder - restock required
|
||||
|
||||
todo: restock required feature
|
||||
dialog? See notes case 3849
|
||||
|
||||
Create a view for this:
|
||||
|
||||
--VPARTSONORDER
|
||||
create view vpartsonorder as select partid, partwarehouseid, sum((coalesce(apurchaseorderitem.quantityordered,0)-coalesce(apurchaseorderitem.quantityreceived,0))) as quantityonorder
|
||||
from apurchaseorderitem
|
||||
where
|
||||
(coalesce(apurchaseorderitem.quantityordered,0)-coalesce(apurchaseorderitem.quantityreceived,0)) > 0
|
||||
group by partid, partwarehouseid
|
||||
|
||||
|
||||
|
||||
--VRESTOCKREQUIRED
|
||||
create view vrestockrequired as SELECT apart.id AS partid,
|
||||
apartwarehouse.id AS partwarehouseid,
|
||||
apart.partnumber,
|
||||
apartwarehouse.name AS displaywarehouse,
|
||||
|
||||
amanufacturer.id as manufactureid,
|
||||
amanufacturer.name as displaymanufacturer,
|
||||
awholesaler.id as wholesalerid,
|
||||
awholesaler.name as displaywholesaler,
|
||||
aalternativewholesaler.id as ayalternativewholesalerid,
|
||||
aalternativewholesaler.name as displayalternativewholesaler,
|
||||
|
||||
apartstocklevel.minimumquantity,
|
||||
vpartinventorynow.balance,
|
||||
COALESCE(vpartsonorder.quantityonorder, (0)::numeric) AS onorderquantity,
|
||||
(apartstocklevel.minimumquantity - (COALESCE(vpartinventorynow.balance, (0)::numeric) + COALESCE(vpartsonorder.quantityonorder, (0)::numeric))) AS requiredquantity
|
||||
FROM ((((vpartinventorynow
|
||||
LEFT JOIN apart ON ((vpartinventorynow.partid = apart.id)))
|
||||
LEFT JOIN apartwarehouse ON ((vpartinventorynow.partwarehouseid = apartwarehouse.id)))
|
||||
left join avendor as amanufacturer on (apart.manufacturerid = amanufacturer.id)
|
||||
left join avendor as awholesaler on (apart.wholesalerid = awholesaler.id)
|
||||
left join avendor as aalternativewholesaler on (apart.alternativewholesalerid = aalternativewholesaler.id)
|
||||
LEFT JOIN apartstocklevel ON (((vpartinventorynow.partid = apartstocklevel.partid) AND (vpartinventorynow.partwarehouseid = apartstocklevel.partwarehouseid))))
|
||||
LEFT JOIN vpartsonorder ON (((vpartinventorynow.partid = vpartsonorder.partid) AND (vpartinventorynow.partwarehouseid = vpartsonorder.partwarehouseid))))
|
||||
WHERE ((apartstocklevel.minimumquantity IS NOT NULL) AND ((apartstocklevel.minimumquantity - (COALESCE(vpartinventorynow.balance, (0)::numeric) + COALESCE(vpartsonorder.quantityonorder, (0)::numeric))) > (0)::numeric))
|
||||
ORDER BY (apartstocklevel.minimumquantity - (COALESCE(vpartinventorynow.balance, (0)::numeric) + COALESCE(vpartsonorder.quantityonorder, (0)::numeric))) DESC;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Query:
|
||||
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
|
||||
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
|
||||
--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
|
||||
Next step is to create an extension to copy to existing or new workorder for selected items
|
||||
extension then will create a po, add all the selected items and then return the po id
|
||||
client will then open the PO for editing
|
||||
also See notes case 3849
|
||||
not going to do this inside the po itself
|
||||
same process for part requests as well
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user