Commit 248df666 authored by prane's avatar prane

added stock related sql inside demandsupplymaterialOracle and demandsupplymaterialDetOracle

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@202734 ce508802-f39f-4f6c-b175-0d175dae99d5
parent e9877e00
select item_code,due_date, round(sum(demand),0) demand, sum(supply) supply, sum(stock_qty) stock_qty, sum(oth_supply) oth_supply, sum(pending_po) pending_po ,sum(pending_do) pending_do, sum(pending_indent) pending_indent, sum(pending_dr) pending_dr , tran_id,tran_ser from
(
SELECT distorder.dist_order||'@'||distorder_det.line_no tran_id,'Dist Order' as tran_ser, item.item_code__plan as item_code,distorder_det.due_date as due_date,
sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) as demand,
0 as supply, 0 as stock_qty, 0 as oth_supply, 0 as pending_po,
sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) as pending_do,
0 as pending_indent, 0 as pending_dr
FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code ) and
( distorder.dist_order = distorder_det.dist_order ) and
( distorder.confirmed = 'Y' ) and
( distorder.site_code__ship in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( distorder_det.due_date <= to_date('@todate@')) and
( distorder.order_type not in (@ordtypes@) ) and
( case when distorder.status is null then 'P' else distorder.status end = 'P') AND
( case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) > 0
Group By distorder.dist_order||'@'||distorder_det.line_no,'Dist Order', item.item_code__plan,distorder_det.due_date
UNION ALL
SELECT h.tran_id, 'S-FST' as tran_ser, item.item_code__plan as item_code,fn_get_prdfrdate(d.PRD_CODE__FOR) as due_date,
sum(fn_get_avgpotency('@itemcode@' ,'@sitecode@',case when d.quantity is null then 0 else d.quantity end )) as demand ,
0 as supply, 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM salesforecast_det d,salesforecast_hdr h, item
WHERE ( h.tran_id = d.tran_id ) and
( d.item_code = item.item_code ) and
( h.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( (select fr_date from period where code = d.PRD_CODE__FOR) >= to_date('@fromdate@')) AND
( (select to_date from period where code = d.PRD_CODE__FOR) <= to_date('@todate@')) AND
( 0 = @madetostock@ )
and trim(nvl((select si.mfg_type from siteitem si where si.site_code = h.site_code and si.item_code = item.item_code ),' ')) not in ('O','D')
Group By h.TRAN_ID, 'S-FST', item.item_code__plan,fn_get_prdfrdate(d.PRD_CODE__FOR)
UNION ALL
SELECT distorder.dist_order||'@'||distorder_det.line_no tran_id,'Dist Order' as tran_ser, item.item_code__plan as item_code,distorder_det.due_date as due_date,
0 as demand,
sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_received is null then 0 else qty_received end ) as supply, 0 as stock_qty, sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_received is null then 0 else qty_received end ) as oth_supply, 0 as pending_po, sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) as pending_dr, 0 as pending_indent, 0 as pending_dr
FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code ) and
( distorder.dist_order = distorder_det.dist_order ) and
( distorder.confirmed = 'Y' ) and
( distorder.site_code__dlv in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( distorder_det.due_date <= to_date('@todate@')) and
( distorder.order_type not in (@ordtypes@) ) and
( case when distorder.status is null then 'P' else distorder.status end = 'P') AND
(case when qty_confirm is null then 0 else qty_confirm end - case when qty_received is null then 0 else qty_received end ) > 0
Group By distorder.dist_order||'@'||distorder_det.line_no,'Dist Order', item.item_code__plan,distorder_det.due_date
UNION ALL
SELECT indent.ind_no tran_id ,'Indent' as tran_ser ,item.item_code__plan as item_code,indent.req_date as due_date, 0 as demand ,
sum(case when (case when indent.quantity is null then 0 else
indent.quantity end - case when
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case
when indent.quantity is null then 0 else
indent.quantity end - case when indent.ord_qty is null then 0 else
indent.ord_qty end end ) as supply,
0 as stock_qty, sum(case when (case when indent.quantity is null then 0 else
indent.quantity end - case when
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case
when indent.quantity is null then 0 else
indent.quantity end - case when indent.ord_qty is null then 0 else
indent.ord_qty end end ) as oth_supply, 0 as pending_po, 0 as pending_do,
sum(case when (case when indent.quantity is null then 0 else
indent.quantity end - case when
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case
when indent.quantity is null then 0 else
indent.quantity end - case when indent.ord_qty is null then 0 else
indent.ord_qty end end ) as pending_indent, 0 as pending_dr
FROM indent,item
WHERE ( indent.item_code = item.item_code ) and
(indent.status in ('O','A')) and
(indent.site_code in ('@sitecode@')) AND
( item.item_code__plan = '@itemcode@') AND
( indent.req_date <= to_date('@todate@'))
Group By indent.ind_no ,'Indent' ,item.item_code__plan,indent.req_date
UNION ALL
SELECT porder.purc_order||'@'||porddet.line_no as tran_id,'Purchase Order' as tran_ser, item.item_code__plan as item_code,porddet.dlv_date as due_date,
0 as demand ,
sum(case when (case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end) < 0 then 0 else case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end end ) as supply, 0 as stock_qty, sum(case when (case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end) < 0 then 0 else case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end end ) as oth_supply, sum(case when (case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end) < 0 then 0 else case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end end ) as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM porddet,porder, item
WHERE ( porddet.item_code = item.item_code ) and
(porddet.purc_order = porder.purc_order ) and
(porder.confirmed = 'Y') and
(porder.status not in('C','X')) and
(porddet.status not in('C','X')) and
(porddet.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( porder.pord_type not in (@ordtypes@) ) and
( porddet.dlv_date <= to_date('@todate@'))
Group By porder.purc_order||'@'||porddet.line_no,'Purchase Order', item.item_code__plan,porddet.dlv_date
UNION ALL
SELECT a.site_code||'@'||d.item_code||'@'||a.lot_no||'@'||a.lot_sl||'@'||a.loc_code||'@'||(case when c.alloc_pref is null then 'X' else c.alloc_pref end) as tran_id,
'STK' as tran_ser, d.item_code__plan as item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date, 0 as demand,
(a.quantity-a.alloc_qty) as supply,(a.quantity-a.alloc_qty) as stock_qty,
0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM STOCK a, INVSTAT b , LOCATION c,item d
WHERE a.loc_code = c.loc_code
AND b.inv_stat = c.inv_stat
AND NVL(b.stat_type, ' ') <> @ordtypes@
and ( a.site_code IN ('@sitecode@') )
AND ( a.item_code ) = ( '@itemcode@' )
AND NVL(b.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
UNION ALL
SELECT '' as tran_id, '' as tran_ser,item.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
0 as demand ,
DDF_INV_CLSTK_MRP('@sitecode@',item.item_code,to_date(fn_sysdate())) as supply, 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM item
WHERE item.item_code__plan= '@itemcode@'
and DDF_INV_CLSTK_MRP('@sitecode@',item.item_code,to_date(fn_sysdate())) > 0
UNION ALL
SELECT mps_order.tran_id, 'MPS-ORD' as tran_ser,item.item_code__plan as item_code, mps_order.due_date as due_date,
sum(mps_order.quantity) as demand, 0 as supply , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM mps_order, item
WHERE ( mps_order.item_code = item.item_code ) and
(mps_order.site_code in ('@sitecode@') ) AND
(item.item_code__plan = '@itemcode@' ) AND
(mps_order.due_date >= to_date('@fromdate@')) AND
(mps_order.due_date <= to_date('@todate@')) AND
( case when mps_order.status is null then 'P' else mps_order.status end in ('P','T','M'))
Group By mps_order.tran_id, 'MPS-ORD',item.item_code__plan, mps_order.due_date
)
group by item_code,due_date,tran_id,tran_ser
having sum(demand) <> 0 or sum(supply) <> 0
\ No newline at end of file
select item_code,due_date, round(sum(demand),0) demand, sum(supply) supply, sum(stock_qty) stock_qty, sum(oth_supply) oth_supply, sum(pending_po) pending_po ,sum(pending_do) pending_do, sum(pending_indent) pending_indent, sum(pending_dr) pending_dr from
(
SELECT item.item_code__plan as item_code,distorder_det.due_date as due_date,
sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) as demand,
0 as supply, 0 as stock_qty, 0 as oth_supply, 0 as pending_po,
sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) as pending_do,
0 as pending_indent, 0 as pending_dr
FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code ) and
( distorder.dist_order = distorder_det.dist_order ) and
( distorder.confirmed = 'Y' ) and
( distorder.site_code__ship in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( distorder_det.due_date <= to_date('@todate@')) and
( distorder.order_type not in (@ordtypes@) ) and
( case when distorder.status is null then 'P' else distorder.status end = 'P') AND
( case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) > 0
Group By item.item_code__plan,distorder_det.due_date
UNION ALL
SELECT item.item_code__plan as item_code,fn_get_prdfrdate(d.PRD_CODE__FOR) as due_date,
sum(fn_get_avgpotency('@itemcode@' ,'@sitecode@',case when d.quantity is null then 0 else d.quantity end )) as demand ,
0 as supply, 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM salesforecast_det d,salesforecast_hdr h, item
WHERE ( h.tran_id = d.tran_id ) and
( d.item_code = item.item_code ) and
( h.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( (select fr_date from period where code = d.PRD_CODE__FOR) >= to_date('@fromdate@')) AND
( (select to_date from period where code = d.PRD_CODE__FOR) <= to_date('@todate@')) AND
( 0 = @madetostock@ )
and trim(nvl((select si.mfg_type from siteitem si where si.site_code = h.site_code and si.item_code = item.item_code ),' ')) not in ('O','D')
Group By item.item_code__plan,fn_get_prdfrdate(d.PRD_CODE__FOR),0
UNION ALL
select item_code,due_date,sum(demand) demand,sum(supply) supply,sum(stock_qty) stock_qty,
sum(oth_supply) oth_supply,sum(pending_po) pending_po,sum(pending_do) pending_do,sum(pending_indent) pending_indent,
sum(pending_dr) pending_dr from
( SELECT d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand,
(a.quantity-a.alloc_qty) as supply,(a.quantity-a.alloc_qty) as stock_qty,
0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM STOCK a, INVSTAT b , LOCATION c,item d
WHERE a.loc_code = c.loc_code
AND b.inv_stat = c.inv_stat
AND NVL(b.stat_type, ' ') <> 'S'
AND a.site_code = '@sitecode@'
AND a.item_code = '@itemcode@'
AND NVL(b.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
UNION ALL
SELECT d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand,
NVL((eff_qty * -1),0) as supply,NVL((eff_qty * -1),0) as stock_qty,
0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM INVTRACE a, LOCATION b, INVSTAT c,item d
WHERE a.loc_code = b.loc_code
and fn_nearexp(a.item_code,a.site_code,a.loc_code,a.lot_no,a.lot_sl) = 'N'
AND b.inv_stat = c.inv_stat
AND NVL(c.stat_type, ' ') <> 'S'
AND a.item_code = '@itemcode@'
AND a.site_code = '@sitecode@'
AND NVL(c.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
AND a.EFF_date > to_date('@rundate@')) group by item_code,due_date
UNION ALL
SELECT item.item_code__plan as item_code,distorder_det.due_date as due_date,
0 as demand,
sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_received is null then 0 else qty_received end ) as supply, 0 as stock_qty, sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_received is null then 0 else qty_received end ) as oth_supply, 0 as pending_po, sum(case when qty_confirm is null then 0 else qty_confirm end - case when qty_shipped is null then 0 else qty_shipped end) as pending_dr, 0 as pending_indent, 0 as pending_dr
FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code ) and
( distorder.dist_order = distorder_det.dist_order ) and
( distorder.confirmed = 'Y' ) and
( distorder.site_code__dlv in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( distorder_det.due_date <= to_date('@todate@')) and
( distorder.order_type not in (@ordtypes@) ) and
( case when distorder.status is null then 'P' else distorder.status end = 'P') AND
(case when qty_confirm is null then 0 else qty_confirm end - case when qty_received is null then 0 else qty_received end ) > 0
Group By item.item_code__plan,distorder_det.due_date
UNION ALL
SELECT item.item_code__plan as item_code,indent.req_date as due_date,
0 as demand ,
sum(case when (case when indent.quantity is null then 0 else
indent.quantity end - case when
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case
when indent.quantity is null then 0 else
indent.quantity end - case when indent.ord_qty is null then 0 else
indent.ord_qty end end ) as supply,
0 as stock_qty, sum(case when (case when indent.quantity is null then 0 else
indent.quantity end - case when
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case
when indent.quantity is null then 0 else
indent.quantity end - case when indent.ord_qty is null then 0 else
indent.ord_qty end end ) as oth_supply, 0 as pending_po, 0 as pending_do,
sum(case when (case when indent.quantity is null then 0 else
indent.quantity end - case when
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case
when indent.quantity is null then 0 else
indent.quantity end - case when indent.ord_qty is null then 0 else
indent.ord_qty end end ) as pending_indent, 0 as pending_dr
FROM indent,item
WHERE ( indent.item_code = item.item_code ) and
(indent.status in ('O','A')) and
(indent.site_code in ('@sitecode@')) AND
( item.item_code__plan = '@itemcode@') AND
( indent.req_date <= to_date('@todate@'))
Group By item.item_code__plan,indent.req_date
UNION ALL
SELECT item.item_code__plan as item_code,porddet.dlv_date as due_date,
0 as demand ,
sum(case when (case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end) < 0 then 0 else case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end end ) as supply, 0 as stock_qty, sum(case when (case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end) < 0 then 0 else case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end end ) as oth_supply, sum(case when (case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end) < 0 then 0 else case when porddet.quantity__stduom is null then 0 else porddet.quantity__stduom end - case when porddet.dlv_qty is null then 0 else porddet.dlv_qty end end ) as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM porddet,porder, item
WHERE ( porddet.item_code = item.item_code ) and
(porddet.purc_order = porder.purc_order ) and
(porder.confirmed = 'Y') and
(porder.status not in('C','X')) and
(porddet.status not in('C','X')) and
(porddet.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( porder.pord_type not in (@ordtypes@) ) and
( porddet.dlv_date <= to_date('@todate@'))
Group By item.item_code__plan,porddet.dlv_date
UNION ALL
SELECT item.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
0 as demand ,
DDF_INV_CLSTK_MRP('@sitecode@',item.item_code,to_date(fn_sysdate())) as supply, 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM item
WHERE item.item_code__plan= '@itemcode@'
and DDF_INV_CLSTK_MRP('@sitecode@',item.item_code,to_date(fn_sysdate())) > 0
UNION ALL
SELECT item.item_code__plan as item_code, mps_order.due_date as due_date,
sum(mps_order.quantity) as demand, 0 as supply , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM mps_order, item
WHERE ( mps_order.item_code = item.item_code ) and
(mps_order.site_code in ('@sitecode@') ) AND
(item.item_code__plan = '@itemcode@' ) AND
(mps_order.due_date >= to_date('@fromdate@')) AND
(mps_order.due_date <= to_date('@todate@')) AND
( case when mps_order.status is null then 'P' else mps_order.status end in ('P','T','M'))
Group By item.item_code__plan, mps_order.due_date
)
group by item_code,due_date
having sum(demand) <> 0 or sum(supply) <> 0
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment