Inventory Aging Report Using Oracle Discoverer Desktop
CREATE OR REPLACE FUNCTION XX_convert_to_number ( p_char IN Varchar2 ) RETURN Number IS
x Varchar2(250) := '
QWERTYUIOPASDFGHJKLZXCVBNM[];,/<>?:"}{|×+=_-)(*&^%$#@!~ i `' ;
y Varchar2(15) := '0123456789';
BEGIN
RETURN TRANSLATE( UPPER(p_char),x,y);
EXCEPTION WHEN others THEN RETURN '';
END;
-----------------------------
CREATE OR REPLACE function APPS.XX_SET_CLIENT_INFO (x in varchar2) return number is
BEGIN
mo_global.set_policy_context('S', 7871); -- Operating Unit Code
mo_global.init('ONT');
DBMS_APPLICATION_INFO.SET_CLIENT_INFO( x );
return 1;
END;
------------------------------
select 1 from dual where
XX_SET_CLIENT_INFO(:to_date||' '||:INV_ORG_ID)=1;
XX_SET_CLIENT_INFO(:To Date||' '||:Inventory Org)
--MBCC_SET_CLIENT_INFO(:From Date||' '||:To Date||' '||:Employee Number);
SELECT
TO_DATE (RTRIM (SUBSTR (USERENV ('CLIENT_INFO'), 1, 10)), 'dd-mm-rrrr') Tdate,
RTRIM (SUBSTR (USERENV ('CLIENT_INFO'), 12, 35)) INV_ORG_ID
FROM DUAL;
------------------------------------------------------------------
SELECT org,
org_name,
SUB_CODE,
I_code,
I_Desc,
UOM,
XX_convert_to_number (period_name) period_name,
on_hand,
item_cost,
Tot_Cost
FROM (SELECT CASE
WHEN (tdate - TRX_DATE - 1) BETWEEN 0 AND 30
THEN
'30'
WHEN (tdate - TRX_DATE - 1) BETWEEN 31 AND 60
THEN
'60'
WHEN (tdate - TRX_DATE - 1) BETWEEN 61 AND 90
THEN
'90'
WHEN (tdate - TRX_DATE - 1) BETWEEN 91 AND 180
THEN
'180'
WHEN (tdate - TRX_DATE - 1) BETWEEN 181 AND 360
THEN
'360'
WHEN (tdate - TRX_DATE - 1) BETWEEN 361 AND 999999999999999
THEN
'361'
END
period_name,
ITEM_ID,
I_code,
I_Desc,
UOM,
SUB_CODE,
(SELECT NVL (SUM (ONHAND_D.primary_transaction_quantity), 0)
FROM inv.mtl_onhand_quantities_detail ONHAND_D
WHERE 1 = 1
AND ONHAND_D.inventory_item_id = ITEM_ID
AND ONHAND_D.organization_id = org
AND (ONHAND_D.subinventory_code = SUB_CODE)
)
on_hand,
(SELECT ROUND (SUM (NVL (item_cost, 0)), 5)
FROM bom.cst_item_cost_details ITM_COST
WHERE organization_id = org
AND inventory_item_id = ITEM_ID
AND cost_type_id = 2)
item_cost,
ROUND (
( (SELECT NVL (
SUM (ONHAND_D.primary_transaction_quantity),
0)
FROM inv.mtl_onhand_quantities_detail ONHAND_D
WHERE 1 = 1
AND ONHAND_D.inventory_item_id = ITEM_ID
AND ONHAND_D.organization_id = org
AND (ONHAND_D.subinventory_code = SUB_CODE)
)
* (SELECT SUM (NVL (item_cost, 0))
FROM bom.cst_item_cost_details ITM_COST
WHERE organization_id = org
AND inventory_item_id = ITEM_ID
AND cost_type_id = 2)),
2)
Tot_Cost,
org,
org_name
FROM ( SELECT Mmt.inventory_item_id ITEM_ID,
TO_DATE (
RTRIM (SUBSTR (USERENV ('CLIENT_INFO'), 1, 10)),
'dd-mm-rrrr')
tdate,
Mmt.ORGANIZATION_ID org,
org_inf.Organization_name org_name,
item.segment1 I_code,
item.description I_Desc,
item.primary_unit_of_measure UOM,
TRUNC (MAX (Mmt.Transaction_date)) Trx_date,
Mmt.SUBINVENTORY_CODE SUB_CODE
FROM inv.Mtl_material_transactions Mmt,
Org_organization_definitions org_inf,
inv.mtl_system_items_b item
WHERE 1 = 1
AND org_inf.Organization_id = Mmt.Organization_id
AND org_inf.Organization_name LIKE
'%'
|| RTRIM (
SUBSTR (USERENV ('CLIENT_INFO'), 12, 35))
|| '%'
AND TRUNC (Transaction_date) <=
TO_DATE (
RTRIM (
SUBSTR (USERENV ('CLIENT_INFO'), 1, 10)),
'dd-mm-rrrr')
AND item.inventory_item_id = Mmt.inventory_item_id
AND item.Organization_id = Mmt.Organization_id
AND Mmt.Transaction_source_type_id != 11
-- AND (Mmt.primary_quantity < 0)
AND ( Mmt.Transaction_source_type_id != 13
OR Mmt.Transaction_type_id != 80)
-- and mmt.inventory_item_id=24668
GROUP BY MMT.ORGANIZATION_ID,
Mmt.inventory_item_id,
item.segment1,
item.description,
item.primary_unit_of_measure,
SUBINVENTORY_CODE,
org_inf.Organization_name))
WHERE 1 = 1 AND on_hand <> 0
ORDER BY XX_convert_to_number (period_name);
Inventory aging report using oracle discoverer desktop

Inventory aging report using oracle discoverer desktop

  • 1.
    Inventory Aging ReportUsing Oracle Discoverer Desktop CREATE OR REPLACE FUNCTION XX_convert_to_number ( p_char IN Varchar2 ) RETURN Number IS x Varchar2(250) := ' QWERTYUIOPASDFGHJKLZXCVBNM[];,/<>?:"}{|×+=_-)(*&^%$#@!~ i `' ; y Varchar2(15) := '0123456789'; BEGIN RETURN TRANSLATE( UPPER(p_char),x,y); EXCEPTION WHEN others THEN RETURN ''; END; ----------------------------- CREATE OR REPLACE function APPS.XX_SET_CLIENT_INFO (x in varchar2) return number is BEGIN mo_global.set_policy_context('S', 7871); -- Operating Unit Code mo_global.init('ONT'); DBMS_APPLICATION_INFO.SET_CLIENT_INFO( x ); return 1; END; ------------------------------ select 1 from dual where XX_SET_CLIENT_INFO(:to_date||' '||:INV_ORG_ID)=1; XX_SET_CLIENT_INFO(:To Date||' '||:Inventory Org) --MBCC_SET_CLIENT_INFO(:From Date||' '||:To Date||' '||:Employee Number); SELECT TO_DATE (RTRIM (SUBSTR (USERENV ('CLIENT_INFO'), 1, 10)), 'dd-mm-rrrr') Tdate, RTRIM (SUBSTR (USERENV ('CLIENT_INFO'), 12, 35)) INV_ORG_ID FROM DUAL; ------------------------------------------------------------------ SELECT org, org_name, SUB_CODE, I_code, I_Desc, UOM, XX_convert_to_number (period_name) period_name, on_hand, item_cost, Tot_Cost FROM (SELECT CASE WHEN (tdate - TRX_DATE - 1) BETWEEN 0 AND 30 THEN '30' WHEN (tdate - TRX_DATE - 1) BETWEEN 31 AND 60 THEN '60' WHEN (tdate - TRX_DATE - 1) BETWEEN 61 AND 90 THEN '90' WHEN (tdate - TRX_DATE - 1) BETWEEN 91 AND 180 THEN '180' WHEN (tdate - TRX_DATE - 1) BETWEEN 181 AND 360 THEN '360' WHEN (tdate - TRX_DATE - 1) BETWEEN 361 AND 999999999999999 THEN '361' END period_name, ITEM_ID,
  • 2.
    I_code, I_Desc, UOM, SUB_CODE, (SELECT NVL (SUM(ONHAND_D.primary_transaction_quantity), 0) FROM inv.mtl_onhand_quantities_detail ONHAND_D WHERE 1 = 1 AND ONHAND_D.inventory_item_id = ITEM_ID AND ONHAND_D.organization_id = org AND (ONHAND_D.subinventory_code = SUB_CODE) ) on_hand, (SELECT ROUND (SUM (NVL (item_cost, 0)), 5) FROM bom.cst_item_cost_details ITM_COST WHERE organization_id = org AND inventory_item_id = ITEM_ID AND cost_type_id = 2) item_cost, ROUND ( ( (SELECT NVL ( SUM (ONHAND_D.primary_transaction_quantity), 0) FROM inv.mtl_onhand_quantities_detail ONHAND_D WHERE 1 = 1 AND ONHAND_D.inventory_item_id = ITEM_ID AND ONHAND_D.organization_id = org AND (ONHAND_D.subinventory_code = SUB_CODE) ) * (SELECT SUM (NVL (item_cost, 0)) FROM bom.cst_item_cost_details ITM_COST WHERE organization_id = org AND inventory_item_id = ITEM_ID AND cost_type_id = 2)), 2) Tot_Cost, org, org_name FROM ( SELECT Mmt.inventory_item_id ITEM_ID, TO_DATE ( RTRIM (SUBSTR (USERENV ('CLIENT_INFO'), 1, 10)), 'dd-mm-rrrr') tdate, Mmt.ORGANIZATION_ID org, org_inf.Organization_name org_name, item.segment1 I_code, item.description I_Desc, item.primary_unit_of_measure UOM, TRUNC (MAX (Mmt.Transaction_date)) Trx_date, Mmt.SUBINVENTORY_CODE SUB_CODE FROM inv.Mtl_material_transactions Mmt, Org_organization_definitions org_inf, inv.mtl_system_items_b item WHERE 1 = 1 AND org_inf.Organization_id = Mmt.Organization_id AND org_inf.Organization_name LIKE '%' || RTRIM ( SUBSTR (USERENV ('CLIENT_INFO'), 12, 35)) || '%' AND TRUNC (Transaction_date) <= TO_DATE ( RTRIM ( SUBSTR (USERENV ('CLIENT_INFO'), 1, 10)), 'dd-mm-rrrr')
  • 3.
    AND item.inventory_item_id =Mmt.inventory_item_id AND item.Organization_id = Mmt.Organization_id AND Mmt.Transaction_source_type_id != 11 -- AND (Mmt.primary_quantity < 0) AND ( Mmt.Transaction_source_type_id != 13 OR Mmt.Transaction_type_id != 80) -- and mmt.inventory_item_id=24668 GROUP BY MMT.ORGANIZATION_ID, Mmt.inventory_item_id, item.segment1, item.description, item.primary_unit_of_measure, SUBINVENTORY_CODE, org_inf.Organization_name)) WHERE 1 = 1 AND on_hand <> 0 ORDER BY XX_convert_to_number (period_name);