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
...@@ -5,92 +5,72 @@ ...@@ -5,92 +5,72 @@
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,
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
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
UNION ALL
SELECT a.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,a.site_code AS site_code,SUM(a.quantity) AS qtstk
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 a.item_code,a.site_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 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,(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 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 UNION ALL
/* SELECT item.item_code__plan as item_code,indent.req_date as due_date, SELECT porddet.item_code 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,SUM(CASE WHEN
sum(case when (case when indent.quantity is null then 0 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) < 0 THEN 0
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case ELSE CASE WHEN porddet.quantity__stduom IS NULL THEN 0 ELSE porddet.quantity__stduom END
when indent.quantity is null then 0 else - CASE WHEN porddet.dlv_qty IS NULL THEN 0 ELSE porddet.dlv_qty END END ) AS oth_supply,
indent.quantity end - case when indent.ord_qty is null then 0 else SUM(porddet.quantity - porddet.dlv_qty ) AS pending_po,
indent.ord_qty end end ) as supply, 0 AS pending_do, 0 AS pending_indent,
0 as stock_qty, sum(case when (case when indent.quantity is null then 0 else 0 AS pending_dr,
indent.quantity end - case when porder.site_code__dlv AS site_code,
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case 0 AS qtstk
when indent.quantity is null then 0 else FROM porddet,porder
indent.quantity end - case when indent.ord_qty is null then 0 else WHERE
indent.ord_qty end end ) as oth_supply, 0 as pending_po, 0 as pending_do, ( porddet.purc_order = porder.purc_order) AND
sum(case when (case when indent.quantity is null then 0 else ( porddet.item_code = '@itemcode@') AND
indent.quantity end - case when (porder.site_code__dlv IN ('@sitecode@') ) AND
indent.ord_qty is null then 0 else indent.ord_qty end) < 0 then 0 else case porddet.status = 'O' AND
when indent.quantity is null then 0 else porddet.quantity - porddet.dlv_qty > 0
indent.quantity end - case when indent.ord_qty is null then 0 else GROUP BY porder.site_code__dlv,porddet.item_code
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 UNION ALL
SELECT item.item_code__plan as item_code,porddet.dlv_date as due_date, SELECT item.item_code__plan as item_code, FN_MRP_DUEDATE(to_date('@fromdate@')) as due_date,
0 as demand , 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
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, 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 FROM mps_order, item
WHERE ( mps_order.item_code = item.item_code ) and WHERE ( mps_order.item_code = item.item_code ) and
(mps_order.site_code in ('@sitecode@') ) AND (mps_order.site_code in ('@sitecode@') ) AND
...@@ -106,4 +86,4 @@ Group By item.item_code__plan, mps_order.due_date,mps_order.site_code ...@@ -106,4 +86,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 group by item_code,site_code,due_date, site_code
having sum(demand) <> 0 or sum(supply) <> 0 having sum(demand) <> 0 or sum(supply) <> 0 OR SUM(pending_po) <>0 OR SUM(pending_indent) <>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