Commit a2ed6823 authored by prane's avatar prane

sql updated

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@182752 ce508802-f39f-4f6c-b175-0d175dae99d5
parent cc446727
......@@ -10,6 +10,7 @@ select item_code, due_date, round(sum(demand)+ fn_get_sampleqty(item_code ,'@sit
( 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
......@@ -35,26 +36,9 @@ UNION ALL
( 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 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 , 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('@rundate@')) and
( invtrace.ref_ser in ('D-ISS','S-DSP') )
Group By invtrace.ref_id||'@'||invtrace.ref_line ,invtrace.ref_ser ,item.item_code__plan,invtrace.tran_date ,invtrace.site_code
UNION ALL
SELECT distorder.dist_order||'@'||distorder_det.line_no tran_id,'D-ISS' as tran_ser,
......@@ -141,7 +125,6 @@ UNION ALL
( porddet.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( porder.pord_type not in (@ordtypes@) ) and
( porddet.dlv_date >= to_date('@fromdate@')) 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
......@@ -170,13 +153,12 @@ 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('@fromdate@'))
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,
......@@ -199,7 +181,6 @@ where workorder_bill.work_order = workorder.work_order
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('@fromdate@'))
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'))
......
......@@ -10,6 +10,7 @@
( 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
......@@ -23,6 +24,7 @@
( 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
......@@ -36,23 +38,8 @@
( 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,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('@rundate@')) and
( invtrace.ref_ser in ('D-ISS','S-DSP') )
Group By item.item_code__plan,invtrace.tran_date
UNION ALL
SELECT 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 ,
......@@ -130,7 +117,6 @@ FROM indent,item
( porddet.site_code in ('@sitecode@') ) AND
( item.item_code__plan = '@itemcode@') AND
( porder.pord_type not in (@ordtypes@) ) and
( porddet.dlv_date >= to_date('@fromdate@')) AND
( porddet.dlv_date <= to_date('@todate@'))
Group By item.item_code__plan,porddet.dlv_date
......@@ -151,6 +137,7 @@ 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
and d.item_ser not in ('FG01','FG07')
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,
......@@ -164,6 +151,7 @@ UNION ALL
AND a.site_code = '@sitecode@'
AND NVL(c.plan_prod,'N') = 'Y'
AND a.item_code=d.item_code
and d.item_ser not in ('FG01','FG07')
AND a.EFF_date > to_date(fn_sysdate())) group by item_code,due_date
UNION ALL
......@@ -175,11 +163,11 @@ AND a.item_code=d.item_code
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('@fromdate@')) 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 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( 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 ,
......@@ -197,14 +185,11 @@ AND a.item_code=d.item_code
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('@fromdate@')) 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
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