SELECT MSI.SEGMENT1 ITEM,
MSI.INVENTORY_ITEM_ID ITEM_ID,
substr(MSI.DESCRIPTION,1,45) description,
SUM(MMT.PRIMARY_QUANTITY) QTY,
MAX(MMT.TRANSACTION_DATE),
msi.PRIMARY_UOM_CODE PRIUOM,
MP.ORGANIZATION_CODE ORG,
MP.ORGANIZATION_ID,
sum(DECODE(MMT.TRANSACTION_TYPE_ID,80,(SELECT BASE_TRANSACTION_VALUE
FROM MTL_TRANSACTION_ACCOUNTS
WHERE ORGANIZATION_ID=MMT.ORGANIZATION_ID
AND ACCOUNTING_LINE_TYPE=1 -- Inv valuation
AND TRANSACTION_ID=MMT.TRANSACTION_ID)
,18,(MMT.PRIMARY_QUANTITY*MMT.ACTUAL_COST)-mmt.variance_amount
,(MMT.PRIMARY_QUANTITY*MMT.ACTUAL_COST)-mmt.variance_amount )) VALUE
FROM MTL_MATERIAL_TRANSACTIONS MMT,
MTL_SYSTEM_ITEMS_B MSI,
MTL_PARAMETERS MP
WHERE NVL(MMT.SUBINVENTORY_CODE,'A') not in (select mi.secondary_inventory_name from
mtl_secondary_inventories mi
where mi.organization_id=mmt.organization_id
and mi.asset_inventory=2)
AND MMT.INVENTORY_ITEM_ID=MSI.INVENTORY_ITEM_ID
AND MMT.ORGANIZATION_ID=MSI.ORGANIZATION_ID
AND MMT.ORGANIZATION_ID=MP.ORGANIZATION_ID
AND MP.PM_COST_COLLECTION_ENABLED=1
and mmt.OWNING_ORGANIZATION_ID is not null
AND MP.ORGANIZATION_ID=NVL(:P_ORG,MP.ORGANIZATION_ID)
AND TRUNC(MMT.TRANSACTION_DATE) BETWEEN '01-jan-09' AND last_day(:P_DATE_TO)
GROUP BY MSI.SEGMENT1,
MSI.INVENTORY_ITEM_ID,
MSI.DESCRIPTION,
msi.PRIMARY_UOM_CODE,
MP.ORGANIZATION_CODE,
MP.ORGANIZATION_ID
HAVING SUM(MMT.PRIMARY_QUANTITY)>0 AND MAX(MMT.TRANSACTION_DATE)<(last_day(:P_DATE_TO)-360)
MSI.INVENTORY_ITEM_ID ITEM_ID,
substr(MSI.DESCRIPTION,1,45) description,
SUM(MMT.PRIMARY_QUANTITY) QTY,
MAX(MMT.TRANSACTION_DATE),
msi.PRIMARY_UOM_CODE PRIUOM,
MP.ORGANIZATION_CODE ORG,
MP.ORGANIZATION_ID,
sum(DECODE(MMT.TRANSACTION_TYPE_ID,80,(SELECT BASE_TRANSACTION_VALUE
FROM MTL_TRANSACTION_ACCOUNTS
WHERE ORGANIZATION_ID=MMT.ORGANIZATION_ID
AND ACCOUNTING_LINE_TYPE=1 -- Inv valuation
AND TRANSACTION_ID=MMT.TRANSACTION_ID)
,18,(MMT.PRIMARY_QUANTITY*MMT.ACTUAL_COST)-mmt.variance_amount
,(MMT.PRIMARY_QUANTITY*MMT.ACTUAL_COST)-mmt.variance_amount )) VALUE
FROM MTL_MATERIAL_TRANSACTIONS MMT,
MTL_SYSTEM_ITEMS_B MSI,
MTL_PARAMETERS MP
WHERE NVL(MMT.SUBINVENTORY_CODE,'A') not in (select mi.secondary_inventory_name from
mtl_secondary_inventories mi
where mi.organization_id=mmt.organization_id
and mi.asset_inventory=2)
AND MMT.INVENTORY_ITEM_ID=MSI.INVENTORY_ITEM_ID
AND MMT.ORGANIZATION_ID=MSI.ORGANIZATION_ID
AND MMT.ORGANIZATION_ID=MP.ORGANIZATION_ID
AND MP.PM_COST_COLLECTION_ENABLED=1
and mmt.OWNING_ORGANIZATION_ID is not null
AND MP.ORGANIZATION_ID=NVL(:P_ORG,MP.ORGANIZATION_ID)
AND TRUNC(MMT.TRANSACTION_DATE) BETWEEN '01-jan-09' AND last_day(:P_DATE_TO)
GROUP BY MSI.SEGMENT1,
MSI.INVENTORY_ITEM_ID,
MSI.DESCRIPTION,
msi.PRIMARY_UOM_CODE,
MP.ORGANIZATION_CODE,
MP.ORGANIZATION_ID
HAVING SUM(MMT.PRIMARY_QUANTITY)>0 AND MAX(MMT.TRANSACTION_DATE)<(last_day(:P_DATE_TO)-360)
No comments:
Post a Comment