Wednesday, August 19, 2015

Customized All Inventory Value Report

Customized Query for ALL Inventory Value Report


select 'Inventory' col_Type,
        p.* , l.creation_date ,l.ORIGINATION_DATE,
 (select min(creation_Date) from mtl_lot_numbers where lot_number=l.lot_number
and organization_id in (select organization_id from org_organization_definitions where operating_unit=:P_ORG_ID)) rec_date,
NVL(round(to_date(:P_TO_DATE)-l.creation_DATE),0) Days_on_hand,
trunc(l.EXPIRATION_DATE) expiry_date,
trunc((l.EXPIRATION_DATE) -180 ) use_by_date,
null unit_price,
null line_value
from
(select a.ORGANIZATION_ID,
c.ORGANIZATION_CODE,
c.ORGANIZATION_NAME,
a.INVENTORY_ITEM_ID,
sum(a.PRIMARY_QUANTITY) qty,
a.LOT_NUMBER,
--mmt.TRANSACTION_UOM,
b.PRIMARY_UOM_CODE TRANSACTION_UOM,
--a.ORIGINATION_DATE,
b.segment1 || '-' || b.segment2 ITEM,
b.description,
mmt.subinventory_code
from
MTL_TRANSACTION_LOT_VAL_V a,
MTL_system_items b, ORG_ORganization_definitions c,
mtl_material_transactions mmt
--where a.Organization_ID in (145, 146, 154, 147, 148, 149, 150, 151, 155, 153, 152, 182, 222, 242, 342, 362, 402, 422, 442, 462, 662, 831, 832) --DKCLLC
--where a.Organization_ID in (157, 158, 159, 160, 161, 162, 163, 164, 165, 202, 223, 322, 323) -- DKSCLLC
--where a.Organization_ID in (284, 291, 285, 289, 286, 290, 288, 302, 303, 382, 287, 542, 582, 602, 622, 642, 682, 702, 791) -- DKSG
--where a.Organization_ID in (506, 505, 507, 522, 562, 772) -- DKMY
where  TRUNC(a.Transaction_date) <= :P_TO_DATE
and a.inventory_item_id = b.Inventory_item_id
and a.ORGANIZATION_ID = b.ORGANIZATION_ID
and a.ORGANIZATION_ID = c.ORGANIZATION_ID
and a.transaction_id = mmt.transaction_id
   AND b.segment1||'-'||b.segment2 BETWEEN NVL (:p_from_item_num, b.segment1||'-'||b.segment2 )
                    AND NVL (:p_to_item_num, b.segment1||'-'||b.segment2 )
   AND c.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, c.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, c.ORGANIZATION_CODE )
   AND c.operating_unit = :P_ORG_ID    
group by
a.ORGANIZATION_ID,
c.ORGANIZATION_CODE,
c.ORGANIZATION_NAME,
a.INVENTORY_ITEM_ID,
a.LOT_NUMBER,
b.PRIMARY_UOM_CODE,
b.segment1,
mmt.subinventory_code,
b.segment2,
b.description
order by
a.ORGANIZATION_ID,
a.INVENTORY_ITEM_ID,
a.LOT_NUMBER
--a.ORIGINATION_DATE
asc) p,
mtl_lot_numbers l
where l.lot_number=p.lot_number
--l.inventory_item_id = p.Inventory_item_id
and p.ORGANIZATION_ID = l.ORGANIZATION_ID
--and l.LOT_NUMBER=p.LOT_NUMBER
and l.creation_date = (select min(creation_Date) from mtl_lot_numbers where lot_number=l.lot_number and organization_id=l.ORGANIZATION_ID)
and p.qty <>0
union all
select 'Inventory' col_Type , p.* ,
null creation_date,null ORIGINATION_DATE,
null rec_date,
0 days_on_hand,
null expire_date,
null use_by_date,
null unit_price,
null line_value
from
(select
mmt.ORGANIZATION_ID,
c.ORGANIZATION_CODE,
c.ORGANIZATION_NAME,
mmt.INVENTORY_ITEM_ID,
sum(mmt.PRIMARY_QUANTITY) qty,
a.LOT_NUMBER,
--mmt.TRANSACTION_UOM,
b.PRIMARY_UOM_CODE TRANSACTION_UOM,
--a.ORIGINATION_DATE,
b.segment1 || '-' || b.segment2 ITEM,
b.description ,
null subinventory_code
from
MTL_TRANSACTION_LOT_VAL_V a,
MTL_system_items b, ORG_ORganization_definitions c,
mtl_material_transactions mmt
--where a.Organization_ID in (145, 146, 154, 147, 148, 149, 150, 151, 155, 153, 152, 182, 222, 242, 342, 362, 402, 422, 442, 462, 662, 831, 832) --DKCLLC
--where a.Organization_ID in (157, 158, 159, 160, 161, 162, 163, 164, 165, 202, 223, 322, 323) -- DKSCLLC
--where a.Organization_ID in (284, 291, 285, 289, 286, 290, 288, 302, 303, 382, 287, 542, 582, 602, 622, 642, 682, 702, 791) -- DKSG
--where a.Organization_ID in (506, 505, 507, 522, 562, 772) -- DKMY
where  TRUNC(mmt.Transaction_date) <= :P_TO_DATE
and mmt.inventory_item_id = b.Inventory_item_id
and mmt.ORGANIZATION_ID = b.ORGANIZATION_ID
and mmt.ORGANIZATION_ID = c.ORGANIZATION_ID
and mmt.transaction_id = a.transaction_id(+)
--and mmt.organization_id =702
and mmt.transaction_type_id not in ( 10008,76,100002,59,60,65)
   AND b.segment1||'-'||b.segment2 BETWEEN NVL (:p_from_item_num, b.segment1||'-'||b.segment2 )
                    AND NVL (:p_to_item_num, b.segment1||'-'||b.segment2 )
   AND c.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, c.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, c.ORGANIZATION_CODE )
   AND c.operating_unit in (283,482)-- :P_ORG_ID
AND c.operating_unit = :p_org_id
   group by
mmt.ORGANIZATION_ID,
c.ORGANIZATION_CODE,
c.ORGANIZATION_NAME,
mmt.INVENTORY_ITEM_ID,
a.LOT_NUMBER,
trunc (a.EXPIRATION_DATE),
b.PRIMARY_UOM_CODE,
b.segment1,
b.segment2,
b.description ) p
  where p.qty<>0
   and p.lot_number is null  
union all
Select 'Intransit' col_Type, org.organization_id,org.organization_code,org.organization_name,
b.inventory_item_id,sum(rsl.QUANTITY_SHIPPED) qty,lot.LOT_NUMBER,'KG' Transaction_UOM, b.segment1||'-'||b.segment2 Item,b.description,
null subinventory_code,
null creation_date,
null ORIGINATION_DATE,
null rec_date,
0 days_on_hand,
trunc (lot.EXPIRATION_DATE) expire_date,
trunc((lot.EXPIRATION_DATE) -180 ) use_by_date,
null unit_price,
null line_value
from rcv_msh_v ve,
rcv_shipment_lines  rsl ,
mtl_system_items b,
rcv_transactions rcv,
mtl_transaction_lot_val_v lot,
org_organization_definitions org
where  ve.shipment_headeR_id=rsl.shipment_headeR_id
and b.inventory_item_id=rsl.item_id
and org.organization_id=ve.SHIP_TO_ORG_ID
and rsl.mmt_transaction_id=lot.transaction_id
and rcv.shipment_line_id (+) =rsl.shipment_line_id
and rcv.shipment_header_id (+) =rsl.shipment_header_id
and rsl.FROM_ORGANIZATION_ID=b.organization_id
and RECEIPT_NUM is  null
and trunc(ve.shipped_date) <= :P_TO_DATE
  AND b.segment1||'-'||b.segment2 BETWEEN NVL (:p_from_item_num, b.segment1||'-'||b.segment2 )
                    AND NVL (:p_to_item_num, b.segment1||'-'||b.segment2 )
   AND ORG.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, ORG.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, ORG.ORGANIZATION_CODE )
   AND ORG.operating_unit = :P_ORG_ID  
group by org.organization_id,org.organization_code,
org.organization_name,
b.inventory_item_id,
trunc (lot.EXPIRATION_DATE) ,
trunc((lot.EXPIRATION_DATE) -180 ),
lot.LOT_NUMBER, b.segment1||'-'||b.segment2,
b.description
union all
Select 'Intransit' col_Type , org.organization_id,org.organization_code,org.organization_name,
b.inventory_item_id,sum(lot.TRANSACTION_QUANTITY  * (-1)) qty,lot.LOT_NUMBER,'KG' Transaction_UOM, b.segment1||'-'||b.segment2 Item,b.description,
null subinventory_code,
null creation_date,
null ORIGINATION_DATE,
null rec_date,
0 days_on_hand,
trunc (lot.EXPIRATION_DATE) expire_date,
trunc((lot.EXPIRATION_DATE) -180 ) use_by_date,
null unit_price,
null line_value
from rcv_msh_v ve,
rcv_shipment_lines  rsl ,
mtl_system_items b,
rcv_transactions rcv,
mtl_transaction_lot_val_v lot,
org_organization_definitions org
where ve.shipment_headeR_id=rsl.shipment_headeR_id
and b.inventory_item_id=rsl.item_id
and org.organization_id=ve.SHIP_TO_ORG_ID
and rsl.mmt_transaction_id=lot.transaction_id
and rcv.shipment_line_id=rsl.shipment_line_id
and rcv.shipment_header_id=rsl.shipment_header_id
and rsl.FROM_ORGANIZATION_ID=b.organization_id
and RECEIPT_NUM is not null
and rcv.TRANSACTION_TYPE='DELIVER' and trunc(rcv.TRANSACTION_DATE) > :P_TO_DATE and trunc(ve.shipped_date) <= :P_TO_DATE
 AND b.segment1||'-'||b.segment2 BETWEEN NVL (:p_from_item_num, b.segment1||'-'||b.segment2 )
                    AND NVL (:p_to_item_num, b.segment1||'-'||b.segment2 )
   AND ORG.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, ORG.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, ORG.ORGANIZATION_CODE )
   AND ORG.operating_unit = :P_ORG_ID
group by org.organization_id,org.organization_code,
org.organization_name,
b.inventory_item_id,
trunc (lot.EXPIRATION_DATE) ,
trunc((lot.EXPIRATION_DATE) -180 ),
lot.LOT_NUMBER, b.segment1||'-'||b.segment2,
b.description
UNION  ALL
Select 'Intransit' col_Type , org.organization_id,org.organization_code,org.organization_name,
b.inventory_item_id,sum(rsl.QUANTITY_SHIPPED) qty,lot.LOT_NUMBER,'KG' Transaction_UOM, b.segment1||'-'||b.segment2 Item,b.description,
null subinventory_code,
null creation_date,
null ORIGINATION_DATE,
null rec_date,
0 days_on_hand,
trunc (lot.EXPIRATION_DATE) expire_date,
trunc((lot.EXPIRATION_DATE) -180 ) use_by_date,
null unit_price,
null line_value
from rcv_msh_v ve,
rcv_shipment_lines  rsl ,
mtl_system_items b,
rcv_transactions rcv,
mtl_transaction_lot_val_v lot,
org_organization_definitions org
where ve.shipment_headeR_id=rsl.shipment_headeR_id
and rsl.mmt_transaction_id=lot.transaction_id
and b.inventory_item_id=rsl.item_id
and org.organization_id=ve.SHIP_TO_ORG_ID
and rcv.shipment_line_id (+)=rsl.shipment_line_id
and rcv.shipment_header_id(+)=rsl.shipment_header_id
and rsl.FROM_ORGANIZATION_ID=b.organization_id
and RECEIPT_NUM is not null
AND rcv.TRANSACTION_DATE IS NULL
AND trunc(ve.shipped_date) <= :P_TO_DATE
 AND b.segment1||'-'||b.segment2 BETWEEN NVL (:p_from_item_num, b.segment1||'-'||b.segment2 )
                    AND NVL (:p_to_item_num, b.segment1||'-'||b.segment2 )
   AND ORG.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, ORG.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, ORG.ORGANIZATION_CODE )
   AND ORG.operating_unit = :P_ORG_ID
group by org.organization_id,org.organization_code,
org.organization_name,
b.inventory_item_id,
trunc (lot.EXPIRATION_DATE) ,
trunc((lot.EXPIRATION_DATE) -180 ),
lot.LOT_NUMBER, b.segment1||'-'||b.segment2,
b.description
union all
Select 'Intransit' col_Type, org.organization_id,org.organization_code,org.organization_name,
b.inventory_item_id,sum(rsl.QUANTITY_SHIPPED) qty,lot.LOT_NUMBER,'KG' Transaction_UOM, b.segment1||'-'||b.segment2 Item,b.description,
null subinventory_code,
null creation_date,
null ORIGINATION_DATE,
null rec_date,
0 days_on_hand,
trunc (lot.EXPIRATION_DATE) expire_date,
trunc((lot.EXPIRATION_DATE) -180 ) use_by_date,
null unit_price,
null line_value
from rcv_msh_v ve,
rcv_shipment_lines  rsl ,
mtl_system_items b,
rcv_transactions rcv,
mtl_transaction_lot_val_v lot,
org_organization_definitions org
where ve.shipment_headeR_id=rsl.shipment_headeR_id
and org.organization_id=ve.SHIP_TO_ORG_ID
and rsl.mmt_transaction_id=lot.transaction_id
and b.inventory_item_id=rsl.item_id
and rcv.shipment_line_id (+)=rsl.shipment_line_id
and rcv.shipment_header_id(+)=rsl.shipment_header_id
and rsl.FROM_ORGANIZATION_ID=b.organization_id
and RECEIPT_NUM is not null
AND rcv.TRANSACTION_DATE IS not NULL
and rcv.shipment_line_id NOT IN (
                                    SELECT shipment_line_id
                                      FROM rcv_transactions rcv1, rcv_shipment_headers rsh1
                                     WHERE rcv1.shipment_header_id = rsh1.shipment_header_id
                                       AND rcv1.transaction_type IN ('ACCEPT', 'DELIVER','RETURN TO VENDOR'))
AND trunc(ve.shipped_date) <= :P_TO_DATE
 AND b.segment1||'-'||b.segment2 BETWEEN NVL (:p_from_item_num, b.segment1||'-'||b.segment2 )
                    AND NVL (:p_to_item_num, b.segment1||'-'||b.segment2 )
   AND ORG.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, ORG.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, ORG.ORGANIZATION_CODE )
   AND ORG.operating_unit = :P_ORG_ID
group by org.organization_id,org.organization_code,
org.organization_name,
b.inventory_item_id,
trunc (lot.EXPIRATION_DATE),
trunc((lot.EXPIRATION_DATE) -180 ),
lot.LOT_NUMBER, b.segment1||'-'||b.segment2,
b.description
union all
SELECT   'Receiving' Col_Type,
           rsh.ship_to_org_id organization_id,
          org.organization_code organization_code,
          org.organization_name organization_name,
            pla.item_id inventory_item_id,
         rcv.quantity qty,
         null lot_number,
         pla.unit_meas_lookup_code  Transaction_UOM,
         mtl.segment1 || '-' || mtl.segment2 item,
         pla.item_description description,
null subinventory_code,
null creation_date,
null ORIGINATION_DATE,
null rec_date,
0 days_on_hand,
null expire_date,
null use_by_date,
         pla.unit_price * nvl(rcv.CURRENCY_CONVERSION_RATE,1) unit_price,
         round((pla.unit_price *  nvl(rcv.CURRENCY_CONVERSION_RATE,1)* rcv.quantity),2) line_value
    FROM rcv_transactions rcv,
         rcv_shipment_headers rsh,
         rcv_shipment_lines rsl,
         po_lines_all pla,
         po_headers_all pha,
          mtl_system_items mtl,
         org_organization_definitions org,
         (select distinct ship_to_organization_id,pll1.po_header_id, pll1.po_line_id from po_line_locations_all pll1) pll
      --   po_line_locations_all pll
   WHERE rcv.shipment_line_id NOT IN (
                                    SELECT shipment_line_id
                                      FROM rcv_transactions rcv1, rcv_shipment_headers rsh1
                                     WHERE rcv1.shipment_header_id = rsh1.shipment_header_id
                                       AND rcv1.transaction_type IN ('ACCEPT', 'DELIVER','RETURN TO VENDOR')
                                       AND trunc(rcv.transaction_date) <= :p_to_date)
     AND rsh.shipment_header_id = rcv.shipment_header_id
     AND rsh.shipment_header_id = rsl.shipment_header_id
     AND rsl.shipment_line_id = rcv.shipment_line_id
     AND pla.po_header_id = pha.po_header_id
     AND pha.po_header_id = rcv.po_header_id
     AND pla.po_line_id = rcv.po_line_id
     AND mtl.inventory_item_id = pla.item_id
     AND mtl.organization_id = rsh.ship_to_org_id
     AND pll.po_line_id=pla.po_line_id
     AND pll.po_header_id=pha.po_header_id
     AND pll.ship_to_organization_id=rsh.ship_to_org_id
     AND rsh.ship_to_org_id=org.organization_id
     AND pla.item_id=rsl.item_id
       AND rcv.transaction_type IN ('RECEIVE')
     AND rsl.source_document_code = 'PO'
  --    AND rsh.ship_to_org_id in (726)
    AND trunc(rcv.transaction_date) <= :p_to_date
     AND mtl.segment1||'-'||mtl.segment2 BETWEEN NVL (:p_from_item_num, mtl.segment1||'-'||mtl.segment2 )
                    AND NVL (:p_to_item_num, mtl.segment1||'-'||mtl.segment2 )
   AND ORG.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, ORG.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, ORG.ORGANIZATION_CODE )
--and rsh.receipt_num=:rec
--and rsh.ship_to_org_id=122
--and rsh.receipt_num=:p_rec
     AND pha.org_id = :p_org_id    
UNION ALL
SELECT   'Receiving' Col_Type,
           rsh.ship_to_org_id organization_id,
           org.organization_code organization_code,
           org.organization_name organization_name,
            pla.item_id inventory_item_id,
         rcv.quantity qty,
         null lot_number,
         pla.unit_meas_lookup_code  Transaction_UOM,
         mtl.segment1 || '-' || mtl.segment2 item,
         pla.item_description description,
null subinventory_code,
null creation_date,
null ORIGINATION_DATE,
null rec_date,
0 days_on_hand,
null expire_date,
null use_by_date,
         pla.unit_price * nvl(rcv.CURRENCY_CONVERSION_RATE,1) unit_price,
         round((pla.unit_price *  nvl(rcv.CURRENCY_CONVERSION_RATE,1)* rcv.quantity),2) line_value
    FROM rcv_transactions rcv,
         rcv_shipment_headers rsh,
         rcv_shipment_lines rsl,
         po_lines_all pla,
         po_headers_all pha,
         mtl_system_items mtl,
         org_organization_definitions org,
          (select distinct ship_to_organization_id,pll1.po_header_id, pll1.po_line_id from po_line_locations_all pll1) pll
      --   po_line_locations_all pll
   WHERE rcv.shipment_line_id NOT IN (
                                    SELECT shipment_line_id
                                      FROM rcv_transactions rcv1, rcv_shipment_headers rsh1
                                     WHERE rcv1.shipment_header_id = rsh1.shipment_header_id
                                       AND rcv1.transaction_type IN ('DELIVER','RETURN TO VENDOR')
                                       AND trunc(rcv.transaction_date) <= :p_date)
     and rsh.shipment_header_id = rcv.shipment_header_id
     AND rsh.shipment_header_id = rsl.shipment_header_id
     AND rsl.shipment_line_id = rcv.shipment_line_id
     AND pla.po_header_id = pha.po_header_id
     AND pha.po_header_id = rcv.po_header_id
     AND pla.po_line_id = rcv.po_line_id
     AND pll.po_line_id=pla.po_line_id
     AND pll.po_header_id=pha.po_header_id
     AND pll.ship_to_organization_id=rsh.ship_to_org_id
     AND rsh.ship_to_org_id=org.organization_id
     AND mtl.inventory_item_id = pla.item_id
     AND mtl.organization_id = rsh.ship_to_org_id
     AND pla.item_id=rsl.item_id
    AND rcv.transaction_type IN ('ACCEPT')
     AND rsl.source_document_code = 'PO'
    AND trunc(rcv.transaction_date) <= :p_to_date
         AND mtl.segment1||'-'||mtl.segment2 BETWEEN NVL (:p_from_item_num, mtl.segment1||'-'||mtl.segment2 )
                    AND NVL (:p_to_item_num, mtl.segment1||'-'||mtl.segment2 )
        AND ORG.ORGANIZATION_CODE BETWEEN NVL (:p_from_inv_org, ORG.ORGANIZATION_CODE)
                             AND NVL (:p_to_inv_org, ORG.ORGANIZATION_CODE )              
     AND pha.org_id = :p_org_id
order by 3,9,7

1 comment:

Clear BNE Cache for WebADI Changes

It Sometime happens that WebAdi Changes doesn't reflect once migrated in controlled instances. Here are the quick steps(Generally perfor...