Commit 11e2ade7 authored by caluka's avatar caluka

sql updated for after deploying sun office


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@98276 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 0f1c86fe
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 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, 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(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 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,
SELECT d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand, 0 AS oth_supply, 0 AS pending_po, 0 AS pending_do, 0 AS pending_indent,
0 as supply,(a.quantity-a.alloc_qty) as stock_qty, 0 AS pending_dr,a.site_code AS site_code,0 AS qtstk
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 , LOCATION b , Invstat c
FROM STOCK a,INVSTAT b, LOCATION c,item d WHERE a.loc_code =b.loc_code
WHERE a.loc_code = c.loc_code AND b.inv_stat =c.inv_stat
AND b.inv_stat = c.inv_stat AND ( CASE WHEN c.stat_type IS NULL THEN ' ' ELSE c.stat_type END ) <> 'S'
AND b.usable = 'N' AND c.available ='Y'
AND NVL(b.stat_type, ' ') <> 'S' AND a.item_code ='@itemcode@'
AND a.site_code = '@sitecode@' AND a.site_code ='@sitecode@'
AND d.item_code__plan = '@itemcode@' AND a.quantity > 0
AND NVL(b.plan_prod,'N') = 'Y' GROUP BY a.item_code,a.site_code
AND a.item_code=d.item_code UNION ALL
UNION ALL SELECT a.item_code AS item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) AS due_date,
SELECT d.item_code__plan as item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,0 as demand, 0 AS DEMAND,0 AS supply ,0 AS stock_qty,
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 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 0 AS pending_dr,a.site_code AS site_code,SUM(a.quantity) AS qtstk
FROM STOCK a,INVSTAT b, LOCATION c,item d FROM stock a , LOCATION b , Invstat c
WHERE a.loc_code = c.loc_code WHERE a.loc_code =b.loc_code
AND b.inv_stat = c.inv_stat AND b.inv_stat =c.inv_stat
AND NVL(b.stat_type, ' ') <> 'S' AND ( CASE WHEN c.stat_type IS NULL THEN ' ' ELSE c.stat_type END ) <> 'S'
AND a.site_code = '@sitecode@' AND c.available ='N'
AND d.item_code__plan = '@itemcode@' AND a.item_code ='@itemcode@'
AND NVL(b.plan_prod,'N') = 'Y' AND a.site_code ='@sitecode@'
AND a.item_code=d.item_code AND a.quantity > 0
UNION ALL 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, UNION ALL
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 SELECT indent.item_code AS item_code,FN_MRP_DUEDATE(to_date('@fromdate@')) AS due_date,
FROM INVTRACE a, LOCATION b, INVSTAT c,item d 0 AS DEMAND , 0 AS supply, 0 AS stock_qty,
WHERE a.loc_code = b.loc_code SUM(CASE WHEN (CASE WHEN indent.quantity IS NULL THEN 0 ELSE indent.quantity END - CASE WHEN
AND b.inv_stat = c.inv_stat indent.ord_qty IS NULL THEN 0 ELSE indent.ord_qty END) < 0 THEN 0 ELSE CASE WHEN indent.quantity
AND NVL(c.stat_type, ' ') <> 'S' IS NULL THEN 0 ELSE indent.quantity END - CASE WHEN indent.ord_qty IS NULL THEN
AND a.item_code = '@itemcode@' 0 ELSE indent.ord_qty END END ) AS oth_supply, 0 AS pending_po,
AND a.site_code = '@sitecode@' 0 AS pending_do,SUM(indent.quantity) AS pending_indent, 0 AS pending_dr ,
AND NVL(c.plan_prod,'N') = 'Y' indent.site_code__dlv AS site_code, 0 AS qtstk FROM indent
AND a.item_code=d.item_code WHERE
AND a.EFF_date > to_date(fn_sysdate()) ( indent.item_code = '@itemcode@' )
UNION ALL AND (indent.status IN ('O','A'))
/* SELECT item.item_code__plan as item_code,indent.req_date as due_date, AND (indent.site_code__dlv IN ('@sitecode@'))
0 as demand , GROUP BY indent.item_code ,indent.site_code__dlv
sum(case when (case when indent.quantity is null then 0 else
indent.quantity end - case when UNION ALL
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case SELECT porddet.item_code AS item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) AS due_date,
when indent.quantity is null then 0 else 0 AS DEMAND , 0 AS supply, 0 AS stock_qty,SUM(CASE WHEN
indent.quantity end - case when indent.ord_qty is null then 0 else (CASE WHEN porddet.quantity__stduom IS NULL THEN 0 ELSE porddet.quantity__stduom END
indent.ord_qty end end ) as supply, - CASE WHEN porddet.dlv_qty IS NULL THEN 0 ELSE porddet.dlv_qty END) < 0 THEN 0
0 as stock_qty, sum(case when (case when indent.quantity is null then 0 else ELSE CASE WHEN porddet.quantity__stduom IS NULL THEN 0 ELSE porddet.quantity__stduom END
indent.quantity end - case when - CASE WHEN porddet.dlv_qty IS NULL THEN 0 ELSE porddet.dlv_qty END END ) AS oth_supply,
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case SUM(porddet.quantity - porddet.dlv_qty ) AS pending_po,
when indent.quantity is null then 0 else 0 AS pending_do, 0 AS pending_indent,
indent.quantity end - case when indent.ord_qty is null then 0 else 0 AS pending_dr,
indent.ord_qty end end ) as oth_supply, 0 as pending_po, 0 as pending_do, porder.site_code__dlv AS site_code,
sum(case when (case when indent.quantity is null then 0 else 0 AS qtstk
indent.quantity end - case when FROM porddet,porder
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case WHERE
when indent.quantity is null then 0 else ( porddet.purc_order = porder.purc_order) AND
indent.quantity end - case when indent.ord_qty is null then 0 else ( porddet.item_code = '@itemcode@') AND
indent.ord_qty end end ) as pending_indent, 0 as pending_dr ,indent.site_code as site_code, 0 as qtstk (porder.site_code__dlv IN ('@sitecode@') ) AND
FROM indent,item porddet.status = 'O' AND
WHERE ( indent.item_code = item.item_code ) and porddet.quantity - porddet.dlv_qty > 0
(indent.status in ('O','A')) and GROUP BY porder.site_code__dlv,porddet.item_code
(indent.site_code in ('@sitecode@')) AND UNION ALL
( item.item_code__plan = '@itemcode@') AND SELECT item.item_code__plan as item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
( indent.req_date <= to_date('@todate@')) 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
Group By item.item_code__plan,indent.req_date,indent.site_code FROM mps_order, item
UNION ALL WHERE ( mps_order.item_code = item.item_code ) and
SELECT item.item_code__plan as item_code,porddet.dlv_date as due_date, (mps_order.site_code in ('@sitecode@') ) AND
0 as demand , (item.item_code__plan = '@itemcode@' ) AND
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, (mps_order.due_date >= to_date('@fromdate@')) AND
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 (mps_order.due_date <= to_date('@todate@')) AND
FROM porddet,porder, item ( case when mps_order.status is null then 'P' else mps_order.status end in ('P','T','M'))
WHERE ( porddet.item_code = item.item_code ) and Group By item.item_code__plan, mps_order.due_date,mps_order.site_code
(porddet.purc_order = porder.purc_order ) and
(porder.confirmed = 'Y') and )
(porder.status not in('C','X')) and group by item_code, due_date,site_code
(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 group by item_code,site_code,due_date, site_code
( porddet.dlv_date <= to_date('@todate@')) having sum(demand) <> 0 or sum(supply) <> 0 OR SUM(pending_po) <>0 OR SUM(pending_indent) <>0
Group By 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
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