SELECT *
FROM (SELECT CWO.CST_WORK_ORDER_ID,
CWO.WORK_ORDER_NUMBER,
MNW.WORK_ORDER_DESCRIPTION,
-- CACT.TRANSACTION_DATE,
DECODE (CWO.WORK_ORDER_TYPE, 'CORRECTIVE', 'CM', 'PM') WO_TYPE,
MNW.WORK_ORDER_PRIORITY,
(SELECT NAME
FROM HR_ORGANIZATION_UNITS
WHERE ORGANIZATION_ID = CACT.INVENTORY_ORG_ID)
RIG_OPERATING_ORG,
NULL WORK_GROUP,
NVL (
(SELECT SUM (QUANTITY * UNIT_COST * WIP_TXN_SIGN)
FROM CST_WORK_ORDER_COSTS CWOS
WHERE CWOS.COST_ORG_ID = CACT.COST_ORG_ID
AND CWOS.COST_BOOK_ID = CACT.COST_BOOK_ID
AND CWOS.CST_WORK_ORDER_ID = CACT.CST_WORK_ORDER_ID
AND CWOS.WIP_COST_TYPE = 'COMPONENT'),
0)
MATERIAL_ACTUAL,
NVL (
(SELECT SUM (QUANTITY * UNIT_COST * WIP_TXN_SIGN)
FROM CST_WORK_ORDER_COSTS CWOS
WHERE CWOS.COST_ORG_ID = CACT.COST_ORG_ID
AND CWOS.COST_BOOK_ID = CACT.COST_BOOK_ID
AND CWOS.CST_WORK_ORDER_ID = CACT.CST_WORK_ORDER_ID
AND CWOS.WIP_COST_TYPE = 'RESOURCE'),
0)
SERVICE_ACTUAL,
NVL (
(SELECT SUM (QUANTITY * UNIT_COST * WIP_TXN_SIGN)
FROM CST_WORK_ORDER_COSTS CWOS
WHERE CWOS.COST_ORG_ID = CACT.COST_ORG_ID
AND CWOS.COST_BOOK_ID = CACT.COST_BOOK_ID
AND CWOS.CST_WORK_ORDER_ID =
CACT.CST_WORK_ORDER_ID
AND CWOS.WIP_COST_TYPE = 'COMPONENT'),
0)
+ NVL (
(SELECT SUM (QUANTITY * UNIT_COST * WIP_TXN_SIGN)
FROM CST_WORK_ORDER_COSTS CWOS
WHERE CWOS.COST_ORG_ID = CACT.COST_ORG_ID
AND CWOS.COST_BOOK_ID = CACT.COST_BOOK_ID
AND CWOS.CST_WORK_ORDER_ID =
CACT.CST_WORK_ORDER_ID
AND CWOS.WIP_COST_TYPE = 'RESOURCE'),
0)
TOTAL_COST,
CACT.COST_ORG_ID,
CACT.COST_BOOK_ID,
CACT.INVENTORY_ORG_ID
FROM CST_WORK_ORDERS CWO,
wie_work_orders_vl MNW,
CST_ALL_COST_TRANSACTIONS_V CACT
WHERE CWO.WORK_METHOD_ID = MNW.WORK_METHOD_ID
AND CWO.WORK_ORDER_NUMBER = MNW.WORK_ORDER_NUMBER
AND CACT.CST_WORK_ORDER_ID = CWO.CST_WORK_ORDER_ID
AND CACT.TXN_SOURCE_REF_DOC_NUMBER = CWO.WORK_ORDER_NUMBER
AND TRUNC (CACT.TRANSACTION_DATE) >=
TRUNC (NVL (:p_from_date, CACT.TRANSACTION_DATE))
AND TRUNC (CACT.TRANSACTION_DATE) <=
TRUNC (NVL (:p_to_date, CACT.TRANSACTION_DATE))
AND CACT.INVENTORY_ORG_ID =
NVL (:p_org, CACT.INVENTORY_ORG_ID)
AND CWO.WORK_ORDER_TYPE= NVL(:p_work_type,CWO.WORK_ORDER_TYPE)
) X
GROUP BY CST_WORK_ORDER_ID,
WORK_ORDER_NUMBER,
WORK_ORDER_DESCRIPTION,
-- TRANSACTION_DATE,
WO_TYPE,
RIG_OPERATING_ORG,
WORK_GROUP,
WORK_ORDER_PRIORITY,
MATERIAL_ACTUAL,
SERVICE_ACTUAL,
TOTAL_COST,
COST_ORG_ID,
COST_BOOK_ID,
INVENTORY_ORG_ID
ORDER BY WORK_ORDER_NUMBER
No comments:
Post a Comment