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 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,
0 as supply , independent_demand.site_code
FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code )
AND ( independent_demand.site_code >= ( '@sitecodeFr@' ))
AND ( independent_demand.site_code <= ( '@sitecodeTo@' ))
AND ( item.item_code__plan ) >= ( '@itemcodeFr@' )
AND ( item.item_code__plan ) <= ( '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( independent_demand.due_date >= to_date('@fromdate@'))
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 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
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
FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code )
AND ( independent_demand.site_code >= ( '@sitecodeFr@' ))
AND ( independent_demand.site_code <= ( '@sitecodeTo@' ))
AND ( item.item_code__plan ) >= ( '@itemcodeFr@' )
AND ( item.item_code__plan ) <= ( '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( independent_demand.due_date >= to_date('@fromdate@'))
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 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
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,
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
FROM dist_demand, item
WHERE ( dist_demand.item_code = item.item_code )
AND ( dist_demand.site_code__source >= ('@sitecodeFr@') )
AND ( dist_demand.site_code__source <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( dist_demand.due_date >= to_date('@fromdate@'))
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
FROM dist_demand, item
WHERE ( dist_demand.item_code = item.item_code )
AND ( dist_demand.site_code__source >= ('@sitecodeFr@') )
AND ( dist_demand.site_code__source <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( dist_demand.due_date >= to_date('@fromdate@'))
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
UNION ALL
......@@ -40,127 +40,127 @@ select item_code, due_date, sum(demand) demand , sum(supply) supply, tran_id,lin
sum(case when d.quantity is null then 0 else d.quantity end ) as demand ,
0 as supply, h.SITE_CODE
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 ( h.site_code >= ('@sitecodeFr@') )
AND ( h.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
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 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
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,
0 as supply, sales_demand.site_code
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code )
AND ( sales_demand.site_code >= ('@sitecodeFr@') )
AND ( sales_demand.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan ) >= ( '@itemcodeFr@' )
AND ( item.item_code__plan ) <= ( '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( sales_demand.due_date >= to_date('@fromdate@'))
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')
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code )
AND ( sales_demand.site_code >= ('@sitecodeFr@') )
AND ( sales_demand.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan ) >= ( '@itemcodeFr@' )
AND ( item.item_code__plan ) <= ( '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( sales_demand.due_date >= to_date('@fromdate@'))
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')
GROUP BY sales_demand.tran_id,'S-DEM',item.item_code__plan,sales_demand.due_date , sales_demand.site_code
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,
0 as supply, distorder.site_code__ship as site_code
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 >= ('@sitecodeFr@') )
AND ( distorder.site_code__ship <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( distorder_det.due_date >= to_date('@fromdate@'))
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,'D-ISS',item.item_code__plan,distorder_det.due_date , distorder.site_code__ship
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 >= ('@sitecodeFr@') )
AND ( distorder.site_code__ship <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( distorder_det.due_date >= to_date('@fromdate@'))
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,'D-ISS',item.item_code__plan,distorder_det.due_date , distorder.site_code__ship
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,
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
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 >= ('@sitecodeFr@') )
AND ( distorder.site_code__dlv <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( distorder_det.due_date >= to_date('@fromdate@'))
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
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
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 >= ('@sitecodeFr@') )
AND ( distorder.site_code__dlv <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( distorder_det.due_date >= to_date('@fromdate@'))
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,'D-RCP',item.item_code__plan,distorder_det.due_date , distorder.site_code__dlv
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 ,
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
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
FROM indent,item
WHERE ( indent.item_code = item.item_code )
AND ( indent.status in ('O','A'))
AND ( indent.site_code >= ('@sitecodeFr@'))
AND ( indent.site_code <= ('@sitecodeTo@'))
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( indent.req_date >= to_date('@fromdate@'))
AND ( indent.req_date <= to_date('@todate@'))
GROUP BY IND_NO , 'IND' ,item.item_code__plan,indent.req_date,indent.site_code
AND ( indent.status in ('O','A'))
AND ( indent.site_code >= ('@sitecodeFr@'))
AND ( indent.site_code <= ('@sitecodeTo@'))
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( indent.req_date >= to_date('@fromdate@'))
AND ( indent.req_date <= to_date('@todate@'))
GROUP BY IND_NO , 'IND' ,item.item_code__plan,indent.req_date,indent.site_code
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,
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 , porddet.site_code
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 >= ('@sitecodeFr@') )
AND ( porddet.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( porder.pord_type not in ('@ordtypes@') )
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
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,
(a.quantity-a.alloc_qty) as supply, a.site_code
FROM STOCK a, INVSTAT b , LOCATION c,item d
WHERE a.loc_code = c.loc_code
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 , porddet.site_code
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 >= ('@sitecodeFr@') )
AND ( porddet.site_code <= ('@sitecodeTo@') )
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( porder.pord_type not in ('@ordtypes@') )
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
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('01-JAN-20')) as due_date, 0 as demand,
(a.quantity-a.alloc_qty) as supply, a.site_code
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 NVL(b.stat_type, ' ') <> '@ordtypes@'
AND ( a.site_code >= ('@sitecodeFr@') )
AND ( a.site_code <= ('@sitecodeTo@') )
AND ( a.item_code ) >= ( '@itemcodeFr@' )
......@@ -171,62 +171,61 @@ select item_code, due_date, sum(demand) demand , sum(supply) supply, tran_id,lin
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,
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
WHERE ( workorder.item_code = item.item_code )
AND ( workorder.site_code >= ('@sitecodeFr@'))
AND ( workorder.site_code <= ('@sitecodeTo@'))
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( workorder.due_date <= to_date('@todate@'))
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.consider_wip is null then 'O' else workorder.consider_wip end = 'O')
AND ( workorder.site_code >= ('@sitecodeFr@'))
AND ( workorder.site_code <= ('@sitecodeTo@'))
AND ( item.item_code__plan >= '@itemcodeFr@')
AND ( item.item_code__plan <= '@itemcodeTo@')
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND ( workorder.due_date <= to_date('@todate@'))
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.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
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,
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,
0 as supply, workorder.site_code
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,
0 as supply, workorder.site_code
FROM workorder_bill, workorder, item, siteitem
WHERE workorder_bill.work_order = workorder.work_order
AND workorder_bill.item_code = item.item_code
AND workorder_bill.line_type <> 'B'
AND workorder_bill.item_code = siteitem.item_code
AND workorder.site_code = siteitem.site_code
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.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 > 0
and workorder.work_order in (
SELECT workorder.work_order FROM workorder , item item1
WHERE item1.item_code = workorder.item_code
AND ( workorder.site_code >= ('@sitecodeFr@') )
AND ( workorder.site_code <= ('@sitecodeTo@') )
AND ( item1.item_code__plan >= '@itemcodeFr@' )
AND ( item1.item_code__plan <= '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND (workorder.due_date <= to_date('@todate@'))
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.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
AND workorder_bill.item_code = item.item_code
AND workorder_bill.line_type <> 'B'
AND workorder_bill.item_code = siteitem.item_code
AND workorder.site_code = siteitem.site_code
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.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 > 0
and workorder.work_order in (
SELECT workorder.work_order FROM workorder , item item1
WHERE item1.item_code = workorder.item_code
AND ( workorder.site_code >= ('@sitecodeFr@') )
AND ( workorder.site_code <= ('@sitecodeTo@') )
AND ( item1.item_code__plan >= '@itemcodeFr@' )
AND ( item1.item_code__plan <= '@itemcodeTo@' )
AND ( item.Item_Ser >= '@itemserFr@')
AND ( item.Item_Ser <= '@itemserTo@')
AND (workorder.due_date <= to_date('@todate@'))
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.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
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 ,
0 as supply, floor_mst.site_code
from proj_est_bsl_item, floor_mst
......@@ -235,12 +234,11 @@ AND ( floor_mst.site_code >= '@sitecodeFr@' )
AND ( floor_mst.site_code <= '@sitecodeTo@' )
AND ( proj_est_bsl_item.item_code >= '@itemcodeFr@')
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@'))
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,
floor_mst.site_code
) ALIAS
) ALIAS
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