SELECT ITEM_CODE,
ORGANIZATION_CODE,
TRANSACTION_QUANTITY,
cost,
LCM_Value,
PO_Price,
PO_Value,
(SELECT PERIOD_NAME
FROM GL_PERIODS
WHERE PERIOD_SET_NAME = 'Accounting'
AND ADJUSTMENT_PERIOD_FLAG = 'N'
AND TRUNC (TRANSACTION_DATE) BETWEEN START_DATE AND END_DATE)
PERIOD_NAME
FROM ( SELECT inventory_item_id,
ITEM_CODE,
ORGANIZATION_CODE,
SUM (TRANSACTION_QUANTITY) TRANSACTION_QUANTITY,
MAX (ROUND (COST, 2)) cost,
SUM (ROUND (COST * TRANSACTION_QUANTITY, 2)) LCM_Value,
MAX (PO_Price) PO_Price,
SUM (ROUND (PO_Price * TRANSACTION_QUANTITY, 2)) PO_Value,
MAX (TRANSACTION_DATE) TRANSACTION_DATE
FROM (SELECT msib.inventory_item_id,
'''' || msib.segment1 || '''' item_code,
mp.ORGANIZATION_CODE,
mmt.TRANSACTION_QUANTITY TRANSACTION_QUANTITY,
cst_cost_api.get_item_cost (1,
msib.inventory_item_id,
mp.organization_id,
NULL,
NULL)
COST,
MMT.ACTUAL_COST PO_Price,
mmt.TRANSACTION_DATE TRANSACTION_DATE
FROM apps.mtl_material_transactions mmt,
apps.mtl_system_items_b msib,
apps.mtl_parameters mp,
apps.mtl_transaction_types mtt
WHERE 1 = 1
AND mtt.transaction_type_id = mmt.transaction_type_id
AND mmt.inventory_item_id = msib.inventory_item_id
AND mmt.organization_id = msib.organization_id
AND mp.organization_id = mmt.organization_id
AND mmt.transaction_type_id = mtt.transaction_type_id
AND transaction_type_name NOT IN
('Layer Cost Update', 'COGS Recognition')
-- AND msib.segment1 = 'M000000420279-1'
AND (:P_ORGANIZATION_ID IS NULL
OR :P_ORGANIZATION_ID = mmt.organization_id)
AND NVL (mmt.TRANSACTION_QUANTITY, 0) <> 0
AND TRUNC (mmt.transaction_date) <= -- :p_trx_date
TO_DATE (:p_trx_date, 'YYYY/MM/DD HH24:MI:SS'))
GROUP BY inventory_item_id, item_code, ORGANIZATION_CODE -- HAVING SUM ( TRANSACTION_QUANTITY ) <> 0
)
WHERE TRANSACTION_QUANTITY <> 0
ORGANIZATION_CODE,
TRANSACTION_QUANTITY,
cost,
LCM_Value,
PO_Price,
PO_Value,
(SELECT PERIOD_NAME
FROM GL_PERIODS
WHERE PERIOD_SET_NAME = 'Accounting'
AND ADJUSTMENT_PERIOD_FLAG = 'N'
AND TRUNC (TRANSACTION_DATE) BETWEEN START_DATE AND END_DATE)
PERIOD_NAME
FROM ( SELECT inventory_item_id,
ITEM_CODE,
ORGANIZATION_CODE,
SUM (TRANSACTION_QUANTITY) TRANSACTION_QUANTITY,
MAX (ROUND (COST, 2)) cost,
SUM (ROUND (COST * TRANSACTION_QUANTITY, 2)) LCM_Value,
MAX (PO_Price) PO_Price,
SUM (ROUND (PO_Price * TRANSACTION_QUANTITY, 2)) PO_Value,
MAX (TRANSACTION_DATE) TRANSACTION_DATE
FROM (SELECT msib.inventory_item_id,
'''' || msib.segment1 || '''' item_code,
mp.ORGANIZATION_CODE,
mmt.TRANSACTION_QUANTITY TRANSACTION_QUANTITY,
cst_cost_api.get_item_cost (1,
msib.inventory_item_id,
mp.organization_id,
NULL,
NULL)
COST,
MMT.ACTUAL_COST PO_Price,
mmt.TRANSACTION_DATE TRANSACTION_DATE
FROM apps.mtl_material_transactions mmt,
apps.mtl_system_items_b msib,
apps.mtl_parameters mp,
apps.mtl_transaction_types mtt
WHERE 1 = 1
AND mtt.transaction_type_id = mmt.transaction_type_id
AND mmt.inventory_item_id = msib.inventory_item_id
AND mmt.organization_id = msib.organization_id
AND mp.organization_id = mmt.organization_id
AND mmt.transaction_type_id = mtt.transaction_type_id
AND transaction_type_name NOT IN
('Layer Cost Update', 'COGS Recognition')
-- AND msib.segment1 = 'M000000420279-1'
AND (:P_ORGANIZATION_ID IS NULL
OR :P_ORGANIZATION_ID = mmt.organization_id)
AND NVL (mmt.TRANSACTION_QUANTITY, 0) <> 0
AND TRUNC (mmt.transaction_date) <= -- :p_trx_date
TO_DATE (:p_trx_date, 'YYYY/MM/DD HH24:MI:SS'))
GROUP BY inventory_item_id, item_code, ORGANIZATION_CODE -- HAVING SUM ( TRANSACTION_QUANTITY ) <> 0
)
WHERE TRANSACTION_QUANTITY <> 0
No comments:
Post a Comment