Commit 39223d05 authored by msalla's avatar msalla

Project Estimation to be updated in demad/supply summary for MRP

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@216970 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 6cc39859
select item_code, due_date, sum(demand) demand , sum(supply) supply, tran_id,line_no,tran_ser ,site_code from select item_code, due_date, sum(demand) demand , sum(supply) supply, tran_id,line_no,tran_ser ,site_code from
( (
SELECT independent_demand.tran_id,' ' as line_no, 'I-DEM' as tran_ser,item.item_code__plan as item_code,independent_demand.due_date as due_date, SELECT independent_demand.tran_id,' ' as line_no, 'I-DEM' as tran_ser,item.item_code__plan as item_code,independent_demand.due_date as due_date,
sum(case when independent_demand.quantity__std_uom is null then 0 else independent_demand.quantity__std_uom end) as demand, sum(case when independent_demand.quantity__std_uom is null then 0 else independent_demand.quantity__std_uom end) as demand,
0 as supply , independent_demand.site_code 0 as supply , independent_demand.site_code
FROM independent_demand, item FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) WHERE ( independent_demand.item_code = item.item_code )
AND ( independent_demand.site_code >= ( '@sitecodeFr@' )) AND ( independent_demand.site_code >= ( '@sitecodeFr@' ))
AND ( independent_demand.site_code <= ( '@sitecodeTo@' )) AND ( independent_demand.site_code <= ( '@sitecodeTo@' ))
AND ( item.item_code__plan ) >= ( '@itemcodeFr@' ) AND ( item.item_code__plan ) >= ( '@itemcodeFr@' )
AND ( item.item_code__plan ) <= ( '@itemcodeTo@' ) AND ( item.item_code__plan ) <= ( '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( independent_demand.due_date >= to_date('@fromdate@')) AND ( independent_demand.due_date >= to_date('@fromdate@'))
AND ( independent_demand.due_date <= to_date('@todate@')) AND ( independent_demand.due_date <= to_date('@todate@'))
AND ( case when independent_demand.status is null then 'C' else independent_demand.status end <> 'P') AND ( case when independent_demand.status is null then 'C' else independent_demand.status end <> 'P')
AND trim(nvl((select si.mfg_type from siteitem si where si.site_code = independent_demand.site_code and si.item_code = item.item_code ),' ')) not in ('O','D') AND trim(nvl((select si.mfg_type from siteitem si where si.site_code = independent_demand.site_code and si.item_code = item.item_code ),' ')) not in ('O','D')
GROUP BY independent_demand.tran_id,'I-DEM',item.item_code__plan,independent_demand.due_date , independent_demand.site_code GROUP BY independent_demand.tran_id,'I-DEM',item.item_code__plan,independent_demand.due_date , independent_demand.site_code
UNION ALL UNION ALL
SELECT dist_demand.tran_id,' ' as line_no, 'D-DEM' as tran_ser, item.item_code__plan as item_code,dist_demand.due_date as due_date, SELECT dist_demand.tran_id,' ' as line_no, 'D-DEM' as tran_ser, item.item_code__plan as item_code,dist_demand.due_date as due_date,
sum(case when dist_demand.qty_required is null then 0 else dist_demand.qty_required end ) as demand , sum(case when dist_demand.qty_required is null then 0 else dist_demand.qty_required end ) as demand ,
0 as supply, dist_demand.site_code 0 as supply, dist_demand.site_code
FROM dist_demand, item FROM dist_demand, item
WHERE ( dist_demand.item_code = item.item_code ) WHERE ( dist_demand.item_code = item.item_code )
AND ( dist_demand.site_code__source >= ('@sitecodeFr@') ) AND ( dist_demand.site_code__source >= ('@sitecodeFr@') )
AND ( dist_demand.site_code__source <= ('@sitecodeTo@') ) AND ( dist_demand.site_code__source <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@') AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@') AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( dist_demand.due_date >= to_date('@fromdate@')) AND ( dist_demand.due_date >= to_date('@fromdate@'))
AND ( dist_demand.due_date <= to_date('@todate@')) AND ( dist_demand.due_date <= to_date('@todate@'))
GROUP BY dist_demand.tran_id ,'D-DEM' ,item.item_code__plan,dist_demand.due_date ,dist_demand.site_code GROUP BY dist_demand.tran_id ,'D-DEM' ,item.item_code__plan,dist_demand.due_date ,dist_demand.site_code
UNION ALL UNION ALL
SELECT h.TRAN_ID, ' ' as line_no, 'S-FST' as tran_ser, item.item_code__plan as item_code,fn_get_prdfrdate(d.PRD_CODE__FOR) as due_date, SELECT h.TRAN_ID, ' ' as line_no, 'S-FST' as tran_ser, item.item_code__plan as item_code,fn_get_prdfrdate(d.PRD_CODE__FOR) as due_date,
sum(case when d.quantity is null then 0 else d.quantity end ) as demand , sum(case when d.quantity is null then 0 else d.quantity end ) as demand ,
0 as supply, h.SITE_CODE 0 as supply, h.SITE_CODE
FROM salesforecast_det d,salesforecast_hdr h, item FROM salesforecast_det d,salesforecast_hdr h, item
WHERE ( h.tran_id = d.tran_id ) WHERE ( h.tran_id = d.tran_id )
AND ( d.item_code = item.item_code ) AND ( d.item_code = item.item_code )
AND ( h.site_code >= ('@sitecodeFr@') ) AND ( h.site_code >= ('@sitecodeFr@') )
AND ( h.site_code <= ('@sitecodeTo@') ) AND ( h.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@') AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@') AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( (select fr_date from period where code = d.PRD_CODE__FOR) >= to_date('@fromdate@')) 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 ( (select to_date from period where code = d.PRD_CODE__FOR) <= to_date('@todate@'))
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') 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),0, h.SITE_CODE GROUP BY h.TRAN_ID, 'S-FST', item.item_code__plan,fn_get_prdfrdate(d.PRD_CODE__FOR),0, h.SITE_CODE
UNION ALL UNION ALL
SELECT sales_demand.tran_id, ' ' as line_no, 'S-DEM' as tran_ser, item.item_code__plan as item_code, sales_demand.due_date as due_date, SELECT sales_demand.tran_id, ' ' as line_no, 'S-DEM' as tran_ser, item.item_code__plan as item_code, sales_demand.due_date as due_date,
sum(case when sales_demand.quantity__std_uom is null then 0 else sales_demand.quantity__std_uom end - case when sales_demand.consumed_qty is null then 0 else sales_demand.consumed_qty end ) as demand, sum(case when sales_demand.quantity__std_uom is null then 0 else sales_demand.quantity__std_uom end - case when sales_demand.consumed_qty is null then 0 else sales_demand.consumed_qty end ) as demand,
0 as supply, sales_demand.site_code 0 as supply, sales_demand.site_code
FROM sales_demand, item FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) WHERE ( sales_demand.item_code = item.item_code )
AND ( sales_demand.site_code >= ('@sitecodeFr@') ) AND ( sales_demand.site_code >= ('@sitecodeFr@') )
AND ( sales_demand.site_code <= ('@sitecodeTo@') ) AND ( sales_demand.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan ) >= ( '@itemcodeFr@' ) AND ( item.item_code__plan ) >= ( '@itemcodeFr@' )
AND ( item.item_code__plan ) <= ( '@itemcodeTo@' ) AND ( item.item_code__plan ) <= ( '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( sales_demand.due_date >= to_date('@fromdate@')) AND ( sales_demand.due_date >= to_date('@fromdate@'))
AND ( sales_demand.due_date <= to_date('@todate@')) AND ( sales_demand.due_date <= to_date('@todate@'))
AND trim(nvl((select si.mfg_type from siteitem si where si.site_code = sales_demand.site_code and si.item_code = item.item_code ),' ')) not in ('O','D') AND trim(nvl((select si.mfg_type from siteitem si where si.site_code = sales_demand.site_code and si.item_code = item.item_code ),' ')) not in ('O','D')
GROUP BY sales_demand.tran_id,'S-DEM',item.item_code__plan,sales_demand.due_date , sales_demand.site_code GROUP BY sales_demand.tran_id,'S-DEM',item.item_code__plan,sales_demand.due_date , sales_demand.site_code
UNION ALL UNION ALL
SELECT distorder.dist_order tran_id, TO_CHAR (distorder_det.line_no),'D-ORDI' 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, SELECT distorder.dist_order tran_id, TO_CHAR (distorder_det.line_no),'D-ORDI' 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, distorder.site_code__ship as site_code 0 as supply, distorder.site_code__ship as site_code
FROM distorder,distorder_det, item FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code ) WHERE ( distorder_det.item_code = item.item_code )
AND ( distorder.dist_order = distorder_det.dist_order ) AND ( distorder.dist_order = distorder_det.dist_order )
AND ( distorder.confirmed = 'Y' ) AND ( distorder.confirmed = 'Y' )
AND ( distorder.site_code__ship >= ('@sitecodeFr@') ) AND ( distorder.site_code__ship >= ('@sitecodeFr@') )
AND ( distorder.site_code__ship <= ('@sitecodeTo@') ) AND ( distorder.site_code__ship <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@') AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@') AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( distorder_det.due_date >= to_date('@fromdate@')) AND ( distorder_det.due_date >= to_date('@fromdate@'))
AND ( distorder_det.due_date <= to_date('@todate@')) AND ( distorder_det.due_date <= to_date('@todate@'))
AND ( distorder.order_type not in ('@ordtypes@') ) AND ( distorder.order_type not in ('@ordtypes@') )
AND ( case when distorder.status is null then 'P' else distorder.status end = 'P') 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 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,'D-ISS',item.item_code__plan,distorder_det.due_date , distorder.site_code__ship GROUP BY distorder.dist_order, distorder_det.line_no,'D-ISS',item.item_code__plan,distorder_det.due_date , distorder.site_code__ship
UNION ALL UNION ALL
SELECT distorder.dist_order tran_id, TO_CHAR (distorder_det.line_no),'D-ORDR' as tran_ser,item.item_code__plan as item_code, distorder_det.due_date as due_date, SELECT distorder.dist_order tran_id, TO_CHAR (distorder_det.line_no),'D-ORDR' 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, distorder.site_code__dlv as site_code 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, distorder.site_code__dlv as site_code
FROM distorder,distorder_det, item FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code ) WHERE ( distorder_det.item_code = item.item_code )
AND ( distorder.dist_order = distorder_det.dist_order ) AND ( distorder.dist_order = distorder_det.dist_order )
AND ( distorder.confirmed = 'Y' ) AND ( distorder.confirmed = 'Y' )
AND ( distorder.site_code__dlv >= ('@sitecodeFr@') ) AND ( distorder.site_code__dlv >= ('@sitecodeFr@') )
AND ( distorder.site_code__dlv <= ('@sitecodeTo@') ) AND ( distorder.site_code__dlv <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@') AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@') AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( distorder_det.due_date >= to_date('@fromdate@')) AND ( distorder_det.due_date >= to_date('@fromdate@'))
AND ( distorder_det.due_date <= to_date('@todate@')) AND ( distorder_det.due_date <= to_date('@todate@'))
AND ( distorder.order_type not in ('@ordtypes@') ) AND ( distorder.order_type not in ('@ordtypes@') )
AND ( case when distorder.status is null then 'P' else distorder.status end = 'P') 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 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,'D-RCP',item.item_code__plan,distorder_det.due_date , distorder.site_code__dlv GROUP BY distorder.dist_order, distorder_det.line_no,'D-RCP',item.item_code__plan,distorder_det.due_date , distorder.site_code__dlv
UNION ALL UNION ALL
SELECT IND_NO tran_id, ' ' as line_no, 'IND' as tran_ser ,item.item_code__plan as item_code,indent.req_date as due_date, 0 as demand , SELECT IND_NO tran_id, ' ' as line_no, 'IND' 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 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, indent.site_code as site_code 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, indent.site_code as site_code
FROM indent,item FROM indent,item
WHERE ( indent.item_code = item.item_code ) WHERE ( indent.item_code = item.item_code )
AND ( indent.status in ('O','A')) AND ( indent.status in ('O','A'))
AND ( indent.site_code >= ('@sitecodeFr@')) AND ( indent.site_code >= ('@sitecodeFr@'))
AND ( indent.site_code <= ('@sitecodeTo@')) AND ( indent.site_code <= ('@sitecodeTo@'))
AND ( item.item_code__plan >= '@itemcodeFr@') AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@') AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( indent.req_date >= to_date('@fromdate@')) AND ( indent.req_date >= to_date('@fromdate@'))
AND ( indent.req_date <= to_date('@todate@')) AND ( indent.req_date <= to_date('@todate@'))
GROUP BY IND_NO , 'IND' ,item.item_code__plan,indent.req_date,indent.site_code GROUP BY IND_NO , 'IND' ,item.item_code__plan,indent.req_date,indent.site_code
UNION ALL UNION ALL
SELECT porder.purc_order tran_id, porddet.line_no,'P-ORD' as tran_ser,item.item_code__plan as item_code, porddet.dlv_date as due_date, 0 as demand, SELECT porder.purc_order tran_id, porddet.line_no,'P-ORD' 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 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) < 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 , porddet.site_code else porddet.dlv_qty end end ) as supply , porddet.site_code
FROM porddet,porder, item FROM porddet,porder, item
WHERE ( porddet.item_code = item.item_code ) WHERE ( porddet.item_code = item.item_code )
AND ( porddet.purc_order = porder.purc_order ) AND ( porddet.purc_order = porder.purc_order )
AND ( porder.confirmed = 'Y') AND ( porder.confirmed = 'Y')
AND ( porder.status not in('C','X')) AND ( porder.status not in('C','X'))
AND ( porddet.status not in('C','X')) AND ( porddet.status not in('C','X'))
AND ( porddet.site_code >= ('@sitecodeFr@') ) AND ( porddet.site_code >= ('@sitecodeFr@') )
AND ( porddet.site_code <= ('@sitecodeTo@') ) AND ( porddet.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@') AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@') AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( porder.pord_type not in ('@ordtypes@') ) AND ( porder.pord_type not in ('@ordtypes@') )
AND ( porddet.dlv_date <= to_date('@todate@') ) AND ( porddet.dlv_date <= to_date('@todate@') )
GROUP BY porder.purc_order, porddet.line_no,'P-ORD',item.item_code__plan,porddet.dlv_date, porddet.site_code GROUP BY porder.purc_order, porddet.line_no,'P-ORD',item.item_code__plan,porddet.dlv_date, porddet.site_code
UNION ALL UNION ALL
SELECT 'NA' as tran_id, ' ' as line_no, 'STK' as tran_ser, case when d.item_code__plan is null then d.item_code else d.item_code__plan end as item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date, 0 as demand, SELECT 'NA' as tran_id, ' ' as line_no, 'STK' as tran_ser, case when d.item_code__plan is null then d.item_code else d.item_code__plan end as item_code, FN_MRP_DUEDATE(to_date('01-JAN-20')) as due_date, 0 as demand,
(a.quantity-a.alloc_qty) as supply, a.site_code (a.quantity-a.alloc_qty) as supply, a.site_code
FROM STOCK a, INVSTAT b , LOCATION c,item d FROM STOCK a, INVSTAT b , LOCATION c,item d
WHERE a.loc_code = c.loc_code WHERE a.loc_code = c.loc_code
AND b.inv_stat = c.inv_stat AND b.inv_stat = c.inv_stat
AND NVL(b.stat_type, ' ') <> ('@ordtypes@') AND NVL(b.stat_type, ' ') <> '@ordtypes@'
AND ( a.site_code >= ('@sitecodeFr@') ) AND ( a.site_code >= ('@sitecodeFr@') )
AND ( a.site_code <= ('@sitecodeTo@') ) AND ( a.site_code <= ('@sitecodeTo@') )
AND ( a.item_code ) >= ( '@itemcodeFr@' ) AND ( a.item_code ) >= ( '@itemcodeFr@' )
AND ( a.item_code ) <= ( '@itemcodeTo@' ) AND ( a.item_code ) <= ( '@itemcodeTo@' )
AND ( d.Item_Ser >= '@itemserFr@') AND ( d.Item_Ser >= '@itemserFr@')
AND ( d.Item_Ser <= '@itemserTo@') AND ( d.Item_Ser <= '@itemserTo@')
AND NVL(b.plan_prod,'N') = 'Y' AND NVL(b.plan_prod,'N') = 'Y'
AND ( a.item_code=d.item_code ) AND ( a.item_code=d.item_code )
UNION ALL UNION ALL
SELECT workorder.work_order as tran_id,' ' as line_no, 'W-ORD' as tran_ser,item.item_code__plan as item_code, SELECT workorder.work_order as tran_id,' ' as line_no, 'W-ORD' as tran_ser,item.item_code__plan as item_code,
workorder.due_date as due_date, 0 as demand, workorder.due_date as due_date, 0 as demand,
sum((case when workorder.current_batch_qty is null then 0 else workorder.current_batch_qty end * case when workorder.yield_perc is null then 100 else workorder.yield_perc end / 100 ) - case when workorder.quantity__rcvd is null then 0 else workorder.quantity__rcvd end ) as supply, workorder.site_code sum((case when workorder.current_batch_qty is null then 0 else workorder.current_batch_qty end * case when workorder.yield_perc is null then 100 else workorder.yield_perc end / 100 ) - case when workorder.quantity__rcvd is null then 0 else workorder.quantity__rcvd end ) as supply, workorder.site_code
FROM workorder, item FROM workorder, item
WHERE ( workorder.item_code = item.item_code ) WHERE ( workorder.item_code = item.item_code )
AND ( workorder.site_code >= ('@sitecodeFr@')) AND ( workorder.site_code >= ('@sitecodeFr@'))
AND ( workorder.site_code <= ('@sitecodeTo@')) AND ( workorder.site_code <= ('@sitecodeTo@'))
AND ( item.item_code__plan >= '@itemcodeFr@') AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@') AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND ( workorder.due_date <= to_date('@todate@')) AND ( workorder.due_date <= to_date('@todate@'))
AND workorder.SALE_ORDER IS NULL AND workorder.SALE_ORDER IS NULL
AND (case when workorder.status is null then 'P' else workorder.status end in ('R','F')) AND (case when workorder.status is null then 'P' else workorder.status end in ('R','F'))
AND (case when workorder.consider_wip is null then 'O' else workorder.consider_wip end = 'O') AND (case when workorder.consider_wip is null then 'O' else workorder.consider_wip end = 'O')
GROUP BY workorder.work_order, ' ','W-ORD',item.item_code__plan, workorder.due_date, workorder.site_code GROUP BY workorder.work_order, ' ','W-ORD',item.item_code__plan, workorder.due_date, workorder.site_code
HAVING sum((case when workorder.current_batch_qty is null then 0 else workorder.current_batch_qty end * HAVING sum((case when workorder.current_batch_qty is null then 0 else workorder.current_batch_qty end *
case when workorder.yield_perc is null then 100 else workorder.yield_perc end / 100 ) - case when workorder.quantity__rcvd is null then 0 else workorder.quantity__rcvd end ) > 0 case when workorder.yield_perc is null then 100 else workorder.yield_perc end / 100 ) - case when workorder.quantity__rcvd is null then 0 else workorder.quantity__rcvd end ) > 0
UNION ALL UNION ALL
SELECT workorder_bill.work_order as tran_id,' ' as line_no,case when rtrim(siteitem.supp_sour) = 'M' then 'W-BIL' when rtrim(siteitem.supp_sour) = 'P' then 'Indend' else '???' end as tran_ser, workorder_bill.item_code as item_code, workorder.due_date as due_date, SELECT workorder_bill.work_order as tran_id,' ' as line_no,case when rtrim(siteitem.supp_sour) = 'M' then 'W-BIL' when rtrim(siteitem.supp_sour) = 'P' then 'Indend' else '???' end as tran_ser, workorder_bill.item_code as item_code, workorder.due_date as due_date,
sum(case when workorder_bill.QUANTITY is null then 0 else workorder_bill.QUANTITY end - case when (case when workorder_bill.ALLOC_QTY is null then 0 else workorder_bill.ALLOC_QTY end - case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end) < 0 sum(case when workorder_bill.QUANTITY is null then 0 else workorder_bill.QUANTITY end - case when (case when workorder_bill.ALLOC_QTY is null then 0 else workorder_bill.ALLOC_QTY end - case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end) < 0
then case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end else case when workorder_bill.ALLOC_QTY is null then 0 else workorder_bill.ALLOC_QTY end end ) as demand, then case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end else case when workorder_bill.ALLOC_QTY is null then 0 else workorder_bill.ALLOC_QTY end end ) as demand,
0 as supply, workorder.site_code 0 as supply, workorder.site_code
FROM workorder_bill, workorder, item, siteitem FROM workorder_bill, workorder, item, siteitem
WHERE workorder_bill.work_order = workorder.work_order WHERE workorder_bill.work_order = workorder.work_order
AND workorder_bill.item_code = item.item_code AND workorder_bill.item_code = item.item_code
AND workorder_bill.line_type <> 'B' AND workorder_bill.line_type <> 'B'
AND workorder_bill.item_code = siteitem.item_code AND workorder_bill.item_code = siteitem.item_code
AND workorder.site_code = siteitem.site_code AND workorder.site_code = siteitem.site_code
AND case when workorder_bill.QUANTITY is null then 0 AND case when workorder_bill.QUANTITY is null then 0
else workorder_bill.QUANTITY end - case when (case when workorder_bill.ALLOC_QTY is null then 0 else workorder_bill.QUANTITY end - case when (case when workorder_bill.ALLOC_QTY is null then 0
else workorder_bill.ALLOC_QTY end - case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end)<0 else workorder_bill.ALLOC_QTY end - case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end)<0
then ( case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end) then ( case when workorder_bill.ISS_QTY is null then 0 else workorder_bill.ISS_QTY end)
else (case when workorder_bill.ALLOC_QTY is null then 0 else workorder_bill.ALLOC_QTY end) end > 0 else (case when workorder_bill.ALLOC_QTY is null then 0 else workorder_bill.ALLOC_QTY end) end > 0
and workorder.work_order in ( and workorder.work_order in (
SELECT workorder.work_order FROM workorder , item item1 SELECT workorder.work_order FROM workorder , item item1
WHERE item1.item_code = workorder.item_code WHERE item1.item_code = workorder.item_code
AND ( workorder.site_code >= ('@sitecodeFr@') ) AND ( workorder.site_code >= ('@sitecodeFr@') )
AND ( workorder.site_code <= ('@sitecodeTo@') ) AND ( workorder.site_code <= ('@sitecodeTo@') )
AND ( item1.item_code__plan >= '@itemcodeFr@' ) AND ( item1.item_code__plan >= '@itemcodeFr@' )
AND ( item1.item_code__plan <= '@itemcodeTo@' ) AND ( item1.item_code__plan <= '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@') AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@') AND ( item.Item_Ser <= '@itemserTo@')
AND (workorder.due_date <= to_date('@todate@')) AND (workorder.due_date <= to_date('@todate@'))
AND workorder.SALE_ORDER IS NULL AND workorder.SALE_ORDER IS NULL
AND (case when workorder.status is null then 'P' else workorder.status end in ('R','F')) AND (case when workorder.status is null then 'P' else workorder.status end in ('R','F'))
AND (case when workorder.consider_wip is null then 'O' else workorder.consider_wip end = 'O') ) AND (case when workorder.consider_wip is null then 'O' else workorder.consider_wip end = 'O') )
GROUP BY workorder_bill.work_order,case when rtrim(siteitem.supp_sour) = 'M' then 'W-BIL' when rtrim(siteitem.supp_sour) = 'P' then 'Indend' else '???' end, workorder_bill.item_code, workorder.due_date, workorder.site_code GROUP BY workorder_bill.work_order,case when rtrim(siteitem.supp_sour) = 'M' then 'W-BIL' when rtrim(siteitem.supp_sour) = 'P' then 'Indend' else '???' end, workorder_bill.item_code, workorder.due_date, workorder.site_code
UNION ALL UNION ALL
select proj_est_bsl_item.tran_id, TO_CHAR(proj_est_bsl_item.line_no), 'PRJBSL' as tran_ser, proj_est_bsl_item.item_code,
select proj_est_bsl_item.tran_id, TO_CHAR(proj_est_bsl_item.line_no), 'PRJBSL' as tran_ser, proj_est_bsl_item.item_code,
proj_est_bsl_item.start_date as due_date, sum(case when proj_est_bsl_item.quantity is null then 0 else proj_est_bsl_item.quantity end ) as demand , proj_est_bsl_item.start_date as due_date, sum(case when proj_est_bsl_item.quantity is null then 0 else proj_est_bsl_item.quantity end ) as demand ,
0 as supply, floor_mst.site_code 0 as supply, floor_mst.site_code
from proj_est_bsl_item, floor_mst from proj_est_bsl_item, floor_mst
...@@ -235,12 +234,11 @@ AND ( floor_mst.site_code >= '@sitecodeFr@' ) ...@@ -235,12 +234,11 @@ AND ( floor_mst.site_code >= '@sitecodeFr@' )
AND ( floor_mst.site_code <= '@sitecodeTo@' ) AND ( floor_mst.site_code <= '@sitecodeTo@' )
AND ( proj_est_bsl_item.item_code >= '@itemcodeFr@') AND ( proj_est_bsl_item.item_code >= '@itemcodeFr@')
AND ( proj_est_bsl_item.item_code <= '@itemcodeTo@') AND ( proj_est_bsl_item.item_code <= '@itemcodeTo@')
AND ( proj_est_bsl_item.start_date >= to_date('@fromdate@')) AND ( proj_est_bsl_item.start_date >= to_date('01-Jan-20'))
AND ( proj_est_bsl_item.start_date <= to_date('@todate@')) AND ( proj_est_bsl_item.start_date <= to_date('@todate@'))
GROUP BY GROUP BY
proj_est_bsl_item.tran_id, TO_CHAR(proj_est_bsl_item.line_no),'PRJBSL', proj_est_bsl_item.item_code, proj_est_bsl_item.start_date, proj_est_bsl_item.tran_id, TO_CHAR(proj_est_bsl_item.line_no),'PRJBSL', proj_est_bsl_item.item_code, proj_est_bsl_item.start_date,
floor_mst.site_code floor_mst.site_code
) ALIAS ) ALIAS
GROUP BY item_code,due_date ,tran_id,line_no,tran_ser,site_code GROUP BY item_code,due_date ,tran_id,line_no,tran_ser,site_code
HAVING sum(demand) <> 0 or sum(supply) <> 0 HAVING sum(demand) <> 0 or sum(supply) <> 0;
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