Commit 6b392db2 authored by prane's avatar prane

Merged all mrp related atest all sql in one location

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@212611 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 055b5726
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_drfrom (
SELECT 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 , 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 independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) and
( independent_demand.site_code in ('@sitecode@') ) AND
( independent_demand.item_code = '@itemcode@') AND
( independent_demand.due_date >= timestamp('@fromdate@-00.00.00')) AND
( independent_demand.due_date <= timestamp('@todate@-00.00.00')) and
( case when independent_demand.status is null then 'C' else independent_demand.status end <> 'P')
Group By item.item_code__plan,independent_demand.due_date
UNION ALL
SELECT 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 , 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code in ('@sitecode@') ) AND
( sales_demand.item_code = '@itemcode@' ) AND
( sales_demand.due_date >= timestamp('@fromdate@-00.00.00')) AND
( sales_demand.due_date <= timestamp('@todate@-00.00.00')) AND ( 0 = @madetostock@ )
Group By item.item_code__plan,sales_demand.due_date
UNION ALL
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
( distorder_det.item_code = '@itemcode@') AND
( distorder_det.due_date <= timestamp('@todate@-00.00.00')) 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, sorditem.due_date as due_date, sum((case when sorditem.quantity is null then 0 else sorditem.quantity end - case when sorditem.qty_alloc is null then 0
else sorditem.qty_alloc end - case when sorditem.qty_desp is null then 0
else sorditem.qty_desp end ) * case when sorditem.conv__qty_stdqty is null then 1 else sorditem.conv__qty_stdqty end ) as demand, 0 as supply ,
0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM sorder,sorditem, item
WHERE ( sorditem.item_code = item.item_code ) and(sorder.sale_order = sorditem.sale_order ) and
(case when sorder.confirmed is null then 'N' else sorder.confirmed end = 'Y' ) and
(case when sorditem.consume_fc is null then 'Y' else sorditem.consume_fc end = 'N' ) and (sorditem.site_code in ('@sitecode@') ) AND
(sorditem.item_code = '@itemcode@') and (sorditem.due_date <= timestamp('@todate@-00.00.00')) and
( case when sorder.status is null then 'P' else sorder.status end = 'P') and
( sorder.order_type not in (@ordtypes@) ) and ( 0 = @madetoorder@ )
Group By item.item_code__plan,sorditem.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 ( distorder_det.item_code = '@itemcode@')
AND ( distorder_det.due_date <= timestamp('@todate@-00.00.00'))
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, 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 ( porddet.item_code = '@itemcode@' )
and ( porder.pord_type not in (@ordtypes@) )
and ( porddet.dlv_date <= timestamp('@todate@-00.00.00'))
Group By item.item_code__plan,porddet.dlv_date
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(timestamp('@fromdate@-00.00.00')) 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(timestamp(('@fromdate@-00.00.00')) 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 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 > timestamp(fn_sysdate())) group by item_code,due_date
UNION ALL
SELECT item.item_code__plan as item_code, timestamp('@fromdate@-00.00.00') 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 ,
0 as stock_qty, 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 oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
FROM workorder, item
WHERE ( workorder.item_code = item.item_code )
and ( workorder.site_code in ('@sitecode@') )
AND ( workorder.item_code = '@itemcode@' )
AND ( workorder.due_date <= timestamp('@todate@-00.00.00'))
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 item.item_code__plan, timestamp('@fromdate@-00.00.00')
UNION ALL
SELECT workorder_bill.item_code as item_code, timestamp('@fromdate@-00.00.00') 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 , 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 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 WHERE (workorder.site_code in ('@sitecode@') )
AND (workorder.item_code = '@itemcode@' )
AND (workorder.due_date <= timestamp('@todate@-00.00.00'))
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.item_code, timestamp('@fromdate@-00.00.00')
) alias
group by item_code,due_date
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_drfrom (
select item_code, due_date, round(sum(demand),0) demand, sum(supply) supply
, sum(0) stock_qty, sum(0) oth_supply, sum(0) pending_po ,sum(0) pending_do, sum(0) pending_indent, sum(0) pending_dr from (
SELECT 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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
as demand, 0 as supply
FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) and
( independent_demand.site_code in ('@sitecode@') ) AND
......@@ -12,7 +13,7 @@ SELECT item.item_code__plan as item_code,independent_demand.due_date as due_date
UNION ALL
SELECT 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 , 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
when sales_demand.consumed_qty is null then 0 else sales_demand.consumed_qty end ) as demand, 0 as supply
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code in ('@sitecode@') ) AND
......@@ -22,8 +23,7 @@ UNION ALL
Group By item.item_code__plan,sales_demand.due_date
UNION ALL
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
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
FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code ) and
( distorder.dist_order = distorder_det.dist_order ) and
......@@ -38,8 +38,7 @@ UNION ALL
UNION ALL
SELECT item.item_code__plan as item_code, sorditem.due_date as due_date, sum((case when sorditem.quantity is null then 0 else sorditem.quantity end - case when sorditem.qty_alloc is null then 0
else sorditem.qty_alloc end - case when sorditem.qty_desp is null then 0
else sorditem.qty_desp end ) * case when sorditem.conv__qty_stdqty is null then 1 else sorditem.conv__qty_stdqty end ) as demand, 0 as supply ,
0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
else sorditem.qty_desp end ) * case when sorditem.conv__qty_stdqty is null then 1 else sorditem.conv__qty_stdqty end ) as demand, 0 as supply
FROM sorder,sorditem, item
WHERE ( sorditem.item_code = item.item_code ) and(sorder.sale_order = sorditem.sale_order ) and
(case when sorder.confirmed is null then 'N' else sorder.confirmed end = 'Y' ) and
......@@ -51,8 +50,7 @@ Group By item.item_code__plan,sorditem.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
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
FROM distorder,distorder_det, item
WHERE ( distorder_det.item_code = item.item_code )
and ( distorder.dist_order = distorder_det.dist_order )
......@@ -70,7 +68,6 @@ UNION ALL
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 )
......@@ -82,43 +79,18 @@ WHERE ( porddet.item_code = item.item_code )
and ( porder.pord_type not in (@ordtypes@) )
and ( porddet.dlv_date <= timestamp('@todate@-00.00.00'))
Group By item.item_code__plan,porddet.dlv_date
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(timestamp('@fromdate@-00.00.00')) 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(timestamp(('@fromdate@-00.00.00')) 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 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 > timestamp(fn_sysdate())) group by item_code,due_date
SELECT item.item_code__plan as item_code, FN_MRP_DUEDATE(timestamp('@fromdate@-00.00.00')) as due_date,
0 as demand ,
DDF_INV_CLSTK_MRP('@sitecode@',
item.item_code,
timestamp(fn_sysdate())) as supply
FROM item
WHERE item.item_code = '@itemcode@'
and DDF_INV_CLSTK_MRP('@sitecode@',item.item_code,timestamp(fn_sysdate())) > 0
UNION ALL
SELECT item.item_code__plan as item_code, timestamp('@fromdate@-00.00.00') 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 ,
0 as stock_qty, 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 oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
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
FROM workorder, item
WHERE ( workorder.item_code = item.item_code )
and ( workorder.site_code in ('@sitecode@') )
......@@ -131,7 +103,7 @@ UNION ALL
SELECT workorder_bill.item_code as item_code, timestamp('@fromdate@-00.00.00') 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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr
0 as supply
from workorder_bill, workorder, item, siteitem
where workorder_bill.work_order = workorder.work_order
and workorder_bill.item_code = item.item_code
......
select item_code, due_date, round(sum(demand)+ fn_get_sampleqty(item_code ,'@sitecode@' ),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 ,site_code from
(
SELECT independent_demand.tran_id,'I-DEM' as tran_ser,item.item_code__plan as item_code,independent_demand.due_date as due_date,
sum(fn_get_avgpotency('@itemcode@' ,'@sitecode@' ,case when independent_demand.quantity__std_uom is null then 0 else independent_demand.quantity__std_uom 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 , independent_demand.site_code
FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) and
( independent_demand.site_code IN ( '@sitecode@' )) AND
( item.item_code__plan ) = ( '@itemcode@' ) 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 ,'D-DEM' as tran_ser, item.item_code__plan as item_code,dist_demand.due_date as due_date,
sum(fn_get_avgpotency('@itemcode@' ,'@sitecode@' ,case when dist_demand.qty_required is null then 0 else dist_demand.qty_required 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 ,dist_demand.site_code
FROM dist_demand, item
WHERE ( dist_demand.item_code = item.item_code ) and
( dist_demand.site_code__source in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( dist_demand.due_date >= to_date('@fromdate@')) AND
( dist_demand.due_date <= to_date('@todate@')) AND
( 0 = @madetostock@ )
Group By dist_demand.tran_id ,'D-DEM' ,item.item_code__plan,dist_demand.due_date ,dist_demand.site_code
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, h.SITE_CODE
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),0, h.SITE_CODE
UNION ALL
select invtrace.tran_id||'@'||invtrace.ref_id||'@'||invtrace.ref_line tran_id,invtrace.ref_ser as tran_ser, item.item_code__plan as item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
0 as demand, sum(invtrace.eff_qty) * -1 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 , invtrace.SITE_CODE
from invtrace, item, location, invstat
where ( invtrace.item_code = item.item_code ) and
( location.loc_code = invtrace.loc_code) and
( invstat.inv_stat = location.inv_stat) and
( invstat.stat_type <> 'S' ) and
nvl( invstat.plan_prod,'N') = 'Y' and
( invtrace.site_code in ('@sitecode@') ) and
( item.item_code__plan = '@itemcode@') and
( invtrace.tran_date >= to_date('@fromdate@')) and
( invtrace.tran_date <= to_date('@todate@')) and
( invtrace.ref_ser in ('D-ISS','S-DSP') ) and
trim(nvl((select si.mfg_type from siteitem si where si.site_code = invtrace.site_code and si.item_code = invtrace.item_code ),' ')) not in ('O','D')
group by invtrace.tran_id||'@'||invtrace.ref_id||'@'||invtrace.ref_line,invtrace.ref_ser ,item.item_code__plan,invtrace.tran_date,invtrace.SITE_CODE
UNION ALL
SELECT sales_demand.tran_id,'S-DEM' as tran_ser, item.item_code__plan as item_code, sales_demand.due_date as due_date,
sum(fn_get_avgpotency('@itemcode@' ,'@sitecode@',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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , sales_demand.site_code
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code IN ('@sitecode@') ) AND
( item.item_code__plan ) = ( '@itemcode@' ) AND
( sales_demand.due_date >= to_date('@fromdate@')) AND
( sales_demand.due_date <= to_date('@todate@')) AND ( 0 = @madetostock@)
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||'@'||distorder_det.line_no tran_id,'D-ISS' as tran_ser,
item.item_code__plan as item_code, distorder_det.due_date as due_date,
sum( fn_get_avgpotency('@itemcode@' ,'@sitecode@' ,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 , 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 IN ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') 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||'@'||distorder_det.line_no tran_id,'D-RCP' 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_do,
0 as pending_indent, 0 as pending_dr , 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 in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') 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 , '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,
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 ,
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 in ('@sitecode@')) AND
( item.item_code__plan = '@itemcode@') 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||'@'||porddet.line_no as tran_id,'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 , 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, 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 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,'P-ORD',item.item_code__plan,porddet.dlv_date , porddet.site_code
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 , 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 ( 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 workorder.work_order||'@'||'1' as tran_id,'W-ORD' as tran_ser,item.item_code__plan as item_code,
to_date('@fromdate@') 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,
0 as stock_qty, 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 oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , workorder.site_code
FROM workorder, item
WHERE ( workorder.item_code = item.item_code )
and ( workorder.site_code IN ('@sitecode@') )
AND ( item.item_code__plan = '@itemcode@')
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||'@'||'1','W-ORD',item.item_code__plan, to_date('@fromdate@') , 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
UNION ALL
SELECT workorder_bill.work_order||'@'||'1' as tran_id,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, to_date('@fromdate@') 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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , 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 IN ('@sitecode@') )
AND ( item1.item_code__plan = '@itemcode@' )
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, to_date('@fromdate@') , workorder.site_code
) alias
group by item_code,due_date ,tran_id,tran_ser,site_code
having sum(demand) <> 0 or sum(supply) <> 0
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 ,site_code from
(
SELECT independent_demand.tran_id,'I-REQ' 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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , independent_demand.site_code
FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) and
( independent_demand.site_code || item.item_code__plan ) IN ( '@itemcode@' ) AND
( independent_demand.due_date >= timestamp('@fromdate@-00.00.00')) AND
( independent_demand.due_date <= timestamp('@todate@-00.00.00')) and
( case when independent_demand.status is null then 'C' else independent_demand.status end <> 'P')
Group By independent_demand.tran_id,'I-REQ',item.item_code__plan,independent_demand.due_date , independent_demand.site_code
UNION ALL
SELECT sales_demand.tran_id,'S-FCT' 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 ,
0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , sales_demand.site_code
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code || sales_demand.item_code ) IN ( '@itemcode@' ) AND
( sales_demand.due_date >= timestamp('@fromdate@-00.00.00')) AND
( sales_demand.due_date <= timestamp('@todate@-00.00.00')) AND ( 0 = @madetostock@)
Group By sales_demand.tran_id,'S-FCT',item.item_code__plan,sales_demand.due_date , sales_demand.site_code
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,
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 , 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 || distorder_det.item_code ) IN ( '@itemcode@' ) AND
( distorder_det.due_date <= timestamp('@todate@-00.00.00')) 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 , distorder.site_code__ship
UNION ALL
SELECT sorder.sale_order||'@'||sorditem.line_no tran_id,'S-ITEM' as tran_ser,
item.item_code__plan as item_code, sorditem.due_date as due_date,
sum((case when sorditem.quantity is null then 0 else sorditem.quantity end - case when sorditem.qty_alloc is null then 0 else sorditem.qty_alloc end - case when sorditem.qty_desp is null then 0 else sorditem.qty_desp end ) * case when sorditem.conv__qty_stdqty is null then 1 else sorditem.conv__qty_stdqty 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 , sorditem.site_code
FROM sorder,sorditem, item
WHERE
( sorditem.item_code = item.item_code ) and
( sorder.sale_order = sorditem.sale_order ) and
( case when sorder.confirmed is null then 'N' else sorder.confirmed end = 'Y' ) and
( case when sorditem.consume_fc is null then 'Y' else sorditem.consume_fc end = 'N' ) and
( sorditem.site_code || sorditem.item_code ) IN ( '@itemcode@' ) AND
( sorditem.due_date <= timestamp('@todate@-00.00.00')) and
( case when sorder.status is null then 'P' else sorder.status end = 'P') and
( sorder.order_type not in (@ordtypes@) ) and ( 0 = @madetostock@)
Group By sorder.sale_order||'@'||sorditem.line_no ,'S-ITEM',
item.item_code__plan,sorditem.due_date , sorditem.site_code
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_do,
0 as pending_indent, 0 as pending_dr , 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 || distorder_det.item_code ) IN ( '@itemcode@' )
AND ( distorder_det.due_date <= timestamp('@todate@-00.00.00'))
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 , distorder.site_code__dlv
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, 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 || porddet.item_code ) IN ( '@itemcode@' )
and ( porder.pord_type not in (@ordtypes@) )
and ( porddet.dlv_date <= timestamp('@todate@-00.00.00'))
Group By porder.purc_order||'@'||porddet.line_no,'Purchase Order',item.item_code__plan,porddet.dlv_date , porddet.site_code
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,
'Stock' as tran_ser, d.item_code__plan as item_code,
FN_MRP_DUEDATE(timestamp('@fromdate@-00.00.00')) as due_date,
......@@ -9,8 +107,47 @@ SELECT a.site_code||'@'||d.item_code||'@'||a.lot_no||'@'||a.lot_sl||'@'||a.loc_c
WHERE a.loc_code = c.loc_code
AND b.inv_stat = c.inv_stat
AND NVL(b.stat_type, ' ') <> @ordtypes@
and a.site_code = '@sitecode@' and d.item_code__plan = '@itemcode@'
and ( a.site_code || d.item_code__plan ) IN ( '@itemcode@' )
AND NVL(b.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
UNION ALL
SELECT workorder.work_order||'@'||'1' as tran_id,'Work Order' as tran_ser,item.item_code__plan as item_code,
timestamp('@fromdate@-00.00.00') 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,
0 as stock_qty, 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 oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , workorder.site_code
FROM workorder, item
WHERE ( workorder.item_code = item.item_code )
and ( workorder.site_code || workorder.item_code ) IN ( '@itemcode@' )
AND ( workorder.due_date <= timestamp('@todate@-00.00.00'))
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||'@'||'1','Work Order',item.item_code__plan, timestamp('@fromdate@-00.00.00') , workorder.site_code
UNION ALL
SELECT workorder_bill.work_order||'@'||'1' as tran_id,case when rtrim(siteitem.supp_sour) = 'M' then 'Work Order' when rtrim(siteitem.supp_sour) = 'P' then 'Indent' else '???' end as tran_ser, workorder_bill.item_code as item_code, timestamp('@fromdate@-00.00.00') 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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , 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 WHERE
( workorder.site_code || workorder.item_code ) IN ( '@itemcode@' )
AND (workorder.due_date <= timestamp('@todate@-00.00.00'))
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 'Work Order' when rtrim(siteitem.supp_sour) = 'P' then 'Indent' else '???' end,workorder_bill.item_code, timestamp('@fromdate@-00.00.00') , workorder.site_code
) alias
group by item_code,due_date ,tran_id,tran_ser,site_code
having sum(demand) <> 0 or sum(supply) <> 0
select item_code, due_date, 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 ,site_code from
(
SELECT independent_demand.tran_id,'I-REQ' 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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , independent_demand.site_code
FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) and
( independent_demand.site_code || item.item_code__plan ) IN ( '@itemcode@' ) 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')
Group By independent_demand.tran_id,'I-REQ',item.item_code__plan,independent_demand.due_date , independent_demand.site_code
UNION ALL
SELECT sales_demand.tran_id,'S-FCT' 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 ,
0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , sales_demand.site_code
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code || sales_demand.item_code ) IN ( '@itemcode@' ) AND
( sales_demand.due_date >= to_date('@fromdate@')) AND
( sales_demand.due_date <= to_date('@todate@')) AND ( 0 = @madetostock@)
Group By sales_demand.tran_id,'S-FCT',item.item_code__plan,sales_demand.due_date , sales_demand.site_code
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,
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 , 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 || distorder_det.item_code ) IN ( '@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 , distorder.site_code__ship
UNION ALL
SELECT sorder.sale_order||'@'||sorditem.line_no tran_id,'S-ITEM' as tran_ser,
item.item_code__plan as item_code, sorditem.due_date as due_date,
sum((case when sorditem.quantity is null then 0 else sorditem.quantity end - case when sorditem.qty_alloc is null then 0 else sorditem.qty_alloc end - case when sorditem.qty_desp is null then 0 else sorditem.qty_desp end ) * case when sorditem.conv__qty_stdqty is null then 1 else sorditem.conv__qty_stdqty 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 , sorditem.site_code
FROM sorder,sorditem, item
WHERE
( sorditem.item_code = item.item_code ) and
( sorder.sale_order = sorditem.sale_order ) and
( case when sorder.confirmed is null then 'N' else sorder.confirmed end = 'Y' ) and
( case when sorditem.consume_fc is null then 'Y' else sorditem.consume_fc end = 'N' ) and
( sorditem.site_code || sorditem.item_code ) IN ( '@itemcode@' ) AND
( sorditem.due_date <= to_date('@todate@')) and
( case when sorder.status is null then 'P' else sorder.status end = 'P') and
( sorder.order_type not in (@ordtypes@) ) and ( 0 = @madetostock@)
Group By sorder.sale_order||'@'||sorditem.line_no ,'S-ITEM',
item.item_code__plan,sorditem.due_date , sorditem.site_code
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_do,
0 as pending_indent, 0 as pending_dr , 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 || distorder_det.item_code ) IN ( '@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 , distorder.site_code__dlv
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, 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 || porddet.item_code ) IN ( '@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 , porddet.site_code
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,
'Stock' as tran_ser, d.item_code__plan as item_code,
FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
......@@ -8,8 +107,47 @@ SELECT a.site_code||'@'||d.item_code||'@'||a.lot_no||'@'||a.lot_sl||'@'||a.loc_c
WHERE a.loc_code = c.loc_code
AND b.inv_stat = c.inv_stat
AND NVL(b.stat_type, ' ') <> @ordtypes@
and a.site_code='@sitecode@' and d.item_code__plan='@itemcode@'
and ( a.site_code || d.item_code__plan ) IN ( '@itemcode@' )
AND NVL(b.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
UNION ALL
SELECT workorder.work_order||'@'||'1' as tran_id,'Work Order' as tran_ser,item.item_code__plan as item_code,
to_date('@fromdate@') 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,
0 as stock_qty, 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 oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , workorder.site_code
FROM workorder, item
WHERE ( workorder.item_code = item.item_code )
and ( workorder.site_code || workorder.item_code ) IN ( '@itemcode@' )
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||'@'||'1','Work Order',item.item_code__plan, to_date('@fromdate@') , 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
UNION ALL
SELECT workorder_bill.work_order||'@'||'1' as tran_id,case when rtrim(siteitem.supp_sour) = 'M' then 'Work Order' when rtrim(siteitem.supp_sour) = 'P' then 'Indend' else '???' end as tran_ser, workorder_bill.item_code as item_code, to_date('@fromdate@') 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 , 0 as stock_qty, 0 as oth_supply, 0 as pending_po, 0 as pending_do, 0 as pending_indent, 0 as pending_dr , 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 WHERE
( workorder.site_code || workorder.item_code ) IN ( '@itemcode@' )
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 'Work Order' when rtrim(siteitem.supp_sour) = 'P' then 'Indend' else '???' end,workorder_bill.item_code, to_date('@fromdate@') , workorder.site_code
) alias
group by item_code,due_date ,tran_id,tran_ser,site_code
having sum(demand) <> 0 or sum(supply) <> 0
select distinct item_code from (
select distinct item.item_code__plan as item_code
FROM independent_demand, item ,siteitem
where ( independent_demand.item_code = item.item_code )
and ( independent_demand.site_code in ('@sitecode@') )
and ( item.item_code__plan >= '@itemcodefr@')
and ( item.item_code__plan <= '@itemcodeto@')
and (siteitem.site_code = independent_demand.site_code))
and (siteitem.site_code = independent_demand.site_code)
and siteitem.item_code = case when item.item_code__plan is null then item.item_code else item.item_code__plan end
and case when siteitem.master_sch is null then 'Y' else siteitem.master_sch end <> 'N'
and (siteitem.mfg_type not in ('O','D') )
......@@ -12,4 +14,15 @@ select distinct item.item_code__plan as item_code
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 ( independent_demand.quantity__std_uom <> 0)
\ No newline at end of file
union all
SELECT distinct item.item_code__plan as item_code
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 >= '@itemcodefr@')
and ( item.item_code__plan <= '@itemcodeto@')
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') )
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_code,due_date, round(sum(demand)+ fn_get_sampleqty(item_code ,'@sitecode@' ),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,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(fn_get_avgpotency('@itemcode@' ,'@sitecode@' ,case when independent_demand.quantity__std_uom is null then 0 else independent_demand.quantity__std_uom 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 independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) and
......@@ -10,11 +10,12 @@
( 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 item.item_code__plan,independent_demand.due_date
UNION ALL
SELECT 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(fn_get_avgpotency('@itemcode@' ,'@sitecode@' ,case when dist_demand.qty_required is null then 0 else dist_demand.qty_required 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 dist_demand, item
WHERE ( dist_demand.item_code = item.item_code ) and
......@@ -23,38 +24,55 @@
( dist_demand.due_date >= to_date('@fromdate@')) AND
( dist_demand.due_date <= to_date('@todate@')) AND
( 0 = @madetostock@ )
and trim(nvl((select si.mfg_type from siteitem si where si.site_code = dist_demand.site_code and si.item_code = item.item_code ),' ')) not in ('O','D')
Group By item.item_code__plan,dist_demand.due_date
UNION ALL
SELECT 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, 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 sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( sales_demand.due_date >= to_date('@fromdate@')) AND
( sales_demand.due_date <= to_date('@todate@')) AND
( 0 = @madetostock@ )
Group By item.item_code__plan,sales_demand.due_date
UNION ALL
SELECT item.item_code__plan as item_code,invtrace.tran_date as due_date,
sum(invtrace.eff_qty) 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
SELECT item.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
0 as demand,
sum(invtrace.eff_qty) *-1 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 invtrace, item, location, invstat
WHERE ( invtrace.item_code = item.item_code ) and
( location.loc_code = invtrace.loc_code) and
( invstat.inv_stat = location.inv_stat) and
( invstat.stat_type <> 'S' ) and
NVL( invstat.plan_prod,'N') = 'Y' and
( invtrace.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( invtrace.tran_date >= to_date('@fromdate@')) and
( invtrace.tran_date <= to_date('@rundate@')) and
( invtrace.ref_ser in ('D-ISS','S-DSP') )
( invtrace.ref_ser in ('D-ISS','S-DSP') ) and
trim(nvl((select si.mfg_type from siteitem si where si.site_code = invtrace.site_code and si.item_code = invtrace.item_code ),' ')) not in ('O','D')
Group By item.item_code__plan,invtrace.tran_date
UNION ALL
SELECT item.item_code__plan as item_code,sales_demand.due_date as due_date,
sum(fn_get_avgpotency('@itemcode@' ,'@sitecode@',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, 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 sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( sales_demand.due_date >= to_date('@fromdate@')) AND
( sales_demand.due_date <= to_date('@todate@')) AND
( 0 = @madetostock@ )
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 item.item_code__plan,sales_demand.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.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,
sum( fn_get_avgpotency('@itemcode@' ,'@sitecode@' ,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
......@@ -62,6 +80,7 @@ UNION ALL
( distorder.confirmed = 'Y' ) and
( distorder.site_code__ship in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') 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
......@@ -78,10 +97,11 @@ UNION ALL
( distorder.confirmed = 'Y' ) and
( distorder.site_code__dlv in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') 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
( 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,
......@@ -106,9 +126,10 @@ 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
( indent.status in ('O','A')) and
( indent.site_code in ('@sitecode@')) AND
( item.item_code__plan = '@itemcode@') AND
( indent.req_date >= to_date('@fromdate@')) AND
( indent.req_date <= to_date('@todate@'))
Group By item.item_code__plan,indent.req_date
UNION ALL
......@@ -119,11 +140,11 @@ FROM indent,item
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
( 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@'))
......@@ -145,19 +166,21 @@ sum(pending_dr) pending_dr from
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(fn_sysdate())) group by item_code,due_date
AND a.EFF_date > to_date('@rundate@')) group by item_code,due_date
UNION ALL
SELECT item.item_code__plan as item_code,to_date('@fromdate@') as due_date,
......@@ -172,30 +195,26 @@ AND a.item_code=d.item_code
(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 item.item_code__plan ,to_date('@fromdate@')
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
UNION ALL
SELECT workorder_bill.item_code as item_code,to_date('@fromdate@') 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,
sum( fn_get_avgpotency('@itemcode@' ,'@sitecode@' ,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, 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 workorder_bill, workorder, item, siteitem
from workorder_bill, workorder, item, siteitem , ITEM ITEM1
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 in ('@sitecode@') ) AND
( item1.item_code__plan = '@itemcode@' ) AND
(workorder.due_date <= to_date('@todate@')) 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.item_code,to_date('@fromdate@')
and item1.item_code = workorder.item_code
and (workorder.site_code in ('@sitecode@') )
AND ( item1.item_code__plan = '@itemcode@' )
AND (workorder.due_date <= to_date('@todate@'))
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.item_code,to_date('@fromdate@')
)
group by item_code,due_date
having sum(demand) <> 0 or sum(supply) <> 0
select item_code,due_date, round(sum(demand),0) demand, sum(supply) supply ,tran_id,tran_ser from
(
SELECT independent_demand.tran_id,'I-REQ' 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
FROM independent_demand, item
WHERE ( independent_demand.item_code = item.item_code ) and
( independent_demand.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') 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')
Group By independent_demand.tran_id,'I-REQ',item.item_code__plan,independent_demand.due_date
UNION ALL
SELECT sales_demand.tran_id,'S-FCT' 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
FROM sales_demand, item
WHERE ( sales_demand.item_code = item.item_code ) and
( sales_demand.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( sales_demand.due_date >= to_date('@fromdate@')) AND
( sales_demand.due_date <= to_date('@todate@')) AND
( 0 = @madetostock@ )
Group By sales_demand.tran_id,'S-FCT',item.item_code__plan,sales_demand.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
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,
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
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 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
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 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
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 '' 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
FROM item
WHERE item.item_code__plan= '@itemcode@'
and DDF_INV_CLSTK_MRP('@sitecode@',item.item_code,to_date(fn_sysdate())) > 0
)
group by item_code,due_date ,tran_id,tran_ser
having sum(demand) <> 0 or sum(supply) <> 0
\ No newline at end of file
......@@ -11,7 +11,9 @@
( independent_demand.due_date <= to_date('@todate@')) and
( case when independent_demand.status is null then 'C' else independent_demand.status end <> 'P')
Group By item.item_code__plan,independent_demand.due_date
UNION ALL
SELECT 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
......@@ -23,6 +25,23 @@
( sales_demand.due_date <= to_date('@todate@')) AND
( 0 = @madetostock@ )
Group By item.item_code__plan,sales_demand.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
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.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 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 invtrace.tran_id||'@'||invtrace.ref_id||'@'||invtrace.ref_line tran_id,invtrace.ref_ser as tran_ser, item.item_code__plan as item_code, invtrace.tran_date as due_date, sum(invtrace.eff_qty) 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 invtrace, item, location, invstat
where ( invtrace.item_code = item.item_code ) and
( location.loc_code = invtrace.loc_code) and
( invstat.inv_stat = location.inv_stat) and
( invstat.stat_type <> 'S' ) and
nvl( invstat.plan_prod,'N') = 'Y' and
( invtrace.site_code in ('@sitecode@') ) and
( item.item_code__plan = '@itemcode@') and
( invtrace.tran_date >= to_date('@fromdate@')) and
( invtrace.tran_date <= to_date('@todate@')) and
( invtrace.ref_ser in ('D-ISS','S-DSP') ) and
trim(nvl((select si.mfg_type from siteitem si where si.site_code = invtrace.site_code and si.item_code = invtrace.item_code ),' ')) not in ('O','D')
group by invtrace.tran_id||'@'||invtrace.ref_id||'@'||invtrace.ref_line,invtrace.ref_ser ,item.item_code__plan,invtrace.tran_date
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
......@@ -16,6 +16,71 @@
( 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 item.item_code__plan as item_code,invtrace.tran_date as due_date,
0 as demand,
sum(invtrace.eff_qty * -1) 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 invtrace, item, location, invstat
WHERE ( invtrace.item_code = item.item_code ) and
( location.loc_code = invtrace.loc_code) and
( invstat.inv_stat = location.inv_stat) and
( invstat.stat_type <> 'S' ) and
NVL( invstat.plan_prod,'N') = 'Y' and
( invtrace.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( invtrace.tran_date >= to_date('@fromdate@')) and
( invtrace.tran_date <= to_date('@rundate@')) and
( invtrace.ref_ser in ('D-ISS','S-DSP') ) and
trim(nvl((select si.mfg_type from siteitem si where si.site_code = invtrace.site_code and si.item_code = invtrace.item_code ),' ')) not in ('O','D')
Group By item.item_code__plan,invtrace.tran_date
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,
......@@ -75,13 +140,7 @@ indent.ord_qty end end ) as pending_indent, 0 as pending_dr
( 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
......
select item_code,due_date 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,site_code,sum(qtstk) qtstk, tran_id, tran_ser from
(
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,site_code,sum(qtstk) qtstk from
(
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,
'Stock' as tran_ser, d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand,
0 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,a.site_code as site_code,(a.quantity-a.alloc_qty) as qtstk
FROM STOCK a,INVSTAT b, LOCATION c,item d
WHERE a.loc_code = c.loc_code
AND b.inv_stat = c.inv_stat
AND b.usable = 'N'
AND NVL(b.stat_type, ' ') <> 'S'
AND a.site_code = '@sitecode@'
AND d.item_code__plan = '@itemcode@'
AND NVL(b.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
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,
'Stock' as tran_ser, d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand,
0 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,a.site_code as site_code,(a.quantity-a.alloc_qty) as qtstk
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 d.item_code__plan = '@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,
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,a.site_code as site_code ,NVL((eff_qty * -1),0) as qtstk
FROM INVTRACE a, LOCATION b, INVSTAT c,item d
WHERE a.loc_code = b.loc_code
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(fn_sysdate())
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 ,indent.site_code as site_code, 0 as qtstk
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,indent.site_code
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,porddet.site_code as site_code ,0 as qtstk
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,porddet.site_code
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,mps_order.site_code as site_code, 0 as qtstk
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,mps_order.site_code
)
group by item_code, due_date,site_code
)
group by item_code,site_code,due_date, site_code
having sum(demand) <> 0 or sum(supply) <> 0
select item_code,due_date 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,site_code,sum(qtstk) qtstk ,sum(hold_qty) hold_qty from
select item_code,due_date 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,site_code,sum(qtstk) qtstk from
(
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,site_code,sum(qtstk) qtstk ,sum(hold_qty) hold_qty from
sum(pending_dr) pending_dr,site_code,sum(qtstk) qtstk from
(
SELECT a.item_code AS item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) AS due_date,
0 AS DEMAND,SUM(a.quantity) 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,a.site_code AS site_code,0 AS qtstk,CASE WHEN sum(a.hold_qty) IS NULL THEN 0 ELSE sum(a.hold_qty) END AS hold_qty
FROM stock a , LOCATION b , Invstat c
WHERE a.loc_code =b.loc_code
AND b.inv_stat =c.inv_stat
AND ( CASE WHEN c.stat_type IS NULL THEN ' ' ELSE c.stat_type END ) <> 'S'
AND c.available ='Y'
AND a.item_code ='@itemcode@'
AND a.site_code ='@sitecode@'
AND a.quantity > 0
GROUP BY a.item_code,a.site_code
SELECT d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand,
0 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,a.site_code as site_code,(a.quantity-a.alloc_qty) as qtstk
FROM STOCK a,INVSTAT b, LOCATION c,item d
WHERE a.loc_code = c.loc_code
AND b.inv_stat = c.inv_stat
AND b.usable = 'N'
AND NVL(b.stat_type, ' ') <> 'S'
AND a.site_code = '@sitecode@'
AND d.item_code__plan = '@itemcode@'
AND NVL(b.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
UNION ALL
SELECT qord.item_code as item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
0 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,qord.site_code as site_code,
CASE WHEN sum(qord.quantity) IS NULL THEN 0 ELSE sum(qord.quantity) END AS qtstk,0 AS hold_qty
FROM qc_order qord WHERE qord.item_code ='@itemcode@'
AND qord.site_code ='@sitecode@'
AND qord.status NOT IN('C')
and exists (select 1 from stock a , LOCATION b , Invstat c WHERE a.loc_code =b.loc_code
AND b.inv_stat =c.inv_stat
AND ( CASE WHEN c.stat_type IS NULL THEN ' ' ELSE c.stat_type END ) <> 'S'
AND c.available ='N' AND a.item_code ='@itemcode@' AND a.site_code ='@sitecode@'
AND a.quantity > 0 )
GROUP BY qord.item_code,qord.site_code
SELECT d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand,
0 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,a.site_code as site_code,(a.quantity-a.alloc_qty) as qtstk
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 d.item_code__plan = '@itemcode@'
AND NVL(b.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
UNION ALL
SELECT indent.item_code AS item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) AS due_date,
0 AS DEMAND , 0 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(indent.quantity) AS pending_indent, 0 AS pending_dr ,
indent.site_code__dlv AS site_code, 0 AS qtstk ,0 AS hold_qty FROM indent
WHERE
( indent.item_code = '@itemcode@' )
AND (indent.status IN ('O','A'))
AND (indent.site_code__dlv IN ('@sitecode@'))
GROUP BY indent.item_code ,indent.site_code__dlv
SELECT d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand,
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,a.site_code as site_code ,NVL((eff_qty * -1),0) as qtstk
FROM INVTRACE a, LOCATION b, INVSTAT c,item d
WHERE a.loc_code = b.loc_code
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(fn_sysdate())
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 ,indent.site_code as site_code, 0 as qtstk
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,indent.site_code
UNION ALL
SELECT porddet.item_code AS item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) AS due_date,
0 AS DEMAND , 0 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(porddet.quantity - porddet.dlv_qty ) AS pending_po,
0 AS pending_do, 0 AS pending_indent,
0 AS pending_dr,
porder.site_code__dlv AS site_code,
0 AS qtstk ,0 AS hold_qty
FROM porddet,porder
WHERE
( porddet.purc_order = porder.purc_order) AND
( porddet.item_code = '@itemcode@') AND
(porder.site_code__dlv IN ('@sitecode@') ) AND
porddet.status = 'O' AND
porddet.quantity - porddet.dlv_qty > 0
GROUP BY porder.site_code__dlv,porddet.item_code
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,porddet.site_code as site_code ,0 as qtstk
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,porddet.site_code
UNION ALL
SELECT item.item_code__plan as item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) 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,mps_order.site_code as site_code, 0 as qtstk,0 AS hold_qty
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,mps_order.site_code as site_code, 0 as qtstk
FROM mps_order, item
WHERE ( mps_order.item_code = item.item_code ) and
(mps_order.site_code in ('@sitecode@') ) AND
......@@ -87,4 +106,4 @@ Group By item.item_code__plan, mps_order.due_date,mps_order.site_code
)
group by item_code,site_code,due_date, site_code
having sum(demand) <> 0 or sum(supply) <> 0 OR SUM(pending_po) <>0 OR SUM(pending_indent) <>0
having sum(demand) <> 0 or sum(supply) <> 0
SELECT item.item_code__plan as item_code,sorditem.due_date as due_date,
((case when sorditem.quantity is null then 0 else sorditem.quantity end - case when sorditem.qty_alloc is null then 0 else sorditem.qty_alloc end - case when sorditem.qty_desp is null then 0 else sorditem.qty_desp end ) * case when sorditem.conv__qty_stdqty is null then 1 else sorditem.conv__qty_stdqty 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 , sorditem.sale_order||'@'||sorditem.line_no as tran_id, 'Sord' as tran_ser,sorditem.site_code as site_code
FROM sorder,sorditem, item
WHERE (sorditem.item_code = item.item_code ) and
(sorder.sale_order = sorditem.sale_order ) and
(case when sorder.confirmed is null then 'N' else sorder.confirmed end = 'Y' ) and
(case when sorditem.consume_fc is null then 'Y' else sorditem.consume_fc end = 'N' ) and
(sorditem.site_code in ('@sitecode@') ) AND
(item.item_code__plan = '@itemcode@') AND
(sorditem.due_date >= to_date('@fromdate@')) and
(sorditem.due_date <= to_date('@todate@')) and
(case when sorder.status is null then 'P' else sorder.status end = 'P') and
(sorder.order_type not in ('S') )
......@@ -17,4 +17,4 @@
and ( case when sorder.status is null then 'P' else sorder.status end = 'P')
and ( sorder.order_type not in (@ordtypes@) )
and trim(nvl((select si.mfg_type from siteitem si where si.site_code = sorditem.site_code and si.item_code = item.item_code ),' ')) in ('O','D')
and ((CASE WHEN SORDITEM.QUANTITY IS NULL THEN 0 ELSE SORDITEM.QUANTITY END - CASE WHEN SORDITEM.QTY_ALLOC IS NULL THEN 0 ELSE SORDITEM.QTY_ALLOC END - CASE WHEN SORDITEM.QTY_DESP IS NULL THEN 0 ELSE SORDITEM.QTY_DESP END ) * CASE WHEN SORDITEM.CONV__QTY_STDQTY IS NULL THEN 1 ELSE SORDITEM.CONV__QTY_STDQTY END ) > 0 ;
and ((CASE WHEN SORDITEM.QUANTITY IS NULL THEN 0 ELSE SORDITEM.QUANTITY END - CASE WHEN SORDITEM.QTY_ALLOC IS NULL THEN 0 ELSE SORDITEM.QTY_ALLOC END - CASE WHEN SORDITEM.QTY_DESP IS NULL THEN 0 ELSE SORDITEM.QTY_DESP END ) * CASE WHEN SORDITEM.CONV__QTY_STDQTY IS NULL THEN 1 ELSE SORDITEM.CONV__QTY_STDQTY END ) > 0
......@@ -10,20 +10,14 @@ select sale_order,line_no,item_code,due_date, demand, 0 supply, 0 stock_qty, 0
(case when sorder.confirmed is null then 'N' else sorder.confirmed end = 'Y' ) and
(case when sorditem.consume_fc is null then 'Y' else sorditem.consume_fc end = 'N' ) and
(sorditem.site_code in ('@sitecode@') ) AND
(item.item_code__plan = '@itemcode@') AND
(sorditem.item_code = '@itemcode@') AND
(sorditem.due_date >= to_date('@fromdate@')) and
(sorditem.due_date <= to_date('@todate@')) and
( case when sorder.status is null then 'P' else sorder.status end = 'P') and
( sorder.order_type not in ('S') )
UNION ALL
select mps_order.tran_id as sale_order,'1' as line_no,
item.item_code__plan as item_code,mps_order.due_date due_date,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 ,mps_order.site_code as site_code
from mps_order,item where
mps_order.item_code=item.item_code
and (item.item_code__plan='@itemcode@')
and ( case when mps_order.status is null then 'P' else
mps_order.status end in ('P','T','M'))
and mps_order.site_code in ('@sitecode@') and
(mps_order.due_date >= to_date('@fromdate@')) and
(mps_order.due_date <= to_date('@todate@'))
and trim(nvl((select si.mfg_type from siteitem si where si.site_code = sorditem.site_code and si.item_code = item.item_code ),' ')) in ('O','D')
and ((CASE WHEN SORDITEM.QUANTITY IS NULL THEN 0 ELSE SORDITEM.QUANTITY END
- CASE WHEN SORDITEM.QTY_ALLOC IS NULL THEN 0 ELSE SORDITEM.QTY_ALLOC END
- CASE WHEN SORDITEM.QTY_DESP IS NULL THEN 0 ELSE SORDITEM.QTY_DESP END )
* CASE WHEN SORDITEM.CONV__QTY_STDQTY IS NULL THEN 1 ELSE SORDITEM.CONV__QTY_STDQTY END ) >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