Sunday, 16 August 2020

Oracle Fusion Maintenance Cloud - Work Order Maintenance Cost Details Extract Query

   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

Oracle Fusion Maintenance Cloud - Maintenance Asset Details Query

 SELECT 

  'KEY' AS "KEY",

ROWNUM SR_NO,

       CAB.ASSET_ID,

       CAB.ASSET_NUMBER,

       CAV.DESCRIPTION,

       (SELECT ASSET_NUMBER

          FROM CSE_ASSETS_B

         WHERE ASSET_ID = (SELECT PARENT_ASSET_ID

                             FROM CSE_AS_BUILT_RELATIONS_V

                            WHERE CHILD_ASSET_ID = CAB.ASSET_ID AND ROWNUM=1))

          PARENT_ASSET,

       (SELECT 

ESI.ITEM_NUMBER

FROM

EGP_SYSTEM_ITEMS_B ESI,

   EGP_SYSTEM_ITEMS_TL ESIT

WHERE

ESI.INVENTORY_ITEM_ID = ESIT.INVENTORY_ITEM_ID

AND ESI.ORGANIZATION_ID = ESIT.ORGANIZATION_ID

AND ESI.INVENTORY_ITEM_ID = CAB.ITEM_ID

AND ESIT.ORGANIZATION_ID=CAB.ITEM_ORGANIZATION_ID

)ITEM_NUMBER,

       (SELECT 

ESIT.DESCRIPTION

FROM

EGP_SYSTEM_ITEMS_B ESI,

   EGP_SYSTEM_ITEMS_TL ESIT

WHERE

ESI.INVENTORY_ITEM_ID = ESIT.INVENTORY_ITEM_ID

AND ESI.ORGANIZATION_ID = ESIT.ORGANIZATION_ID

AND ESI.INVENTORY_ITEM_ID = CAB.ITEM_ID

AND ESIT.ORGANIZATION_ID=CAB.ITEM_ORGANIZATION_ID

)     IETEM_DESC,

       CAB.SERIAL_NUMBER,

       (SELECT NAME

          FROM HR_ORGANIZATION_UNITS

         WHERE ORGANIZATION_ID=(select ITEM_ORGANIZATION_ID

from

CSE_ASSETS_HIST where TRANSACTED_ASSET_ID =

(select MIN(TRANSACTED_ASSET_ID) from CSE_ASSETS_HIST where asset_id = CAB.asset_id)) )

          MAINTANENCE_ORG,                                   --MAINTENANCE ORG

       (SELECT NAME

          FROM HR_ORGANIZATION_UNITS

         WHERE ORGANIZATION_ID = CAB.ITEM_ORGANIZATION_ID)

          OPERATING_ORG,                                       --OPERATING ORG

       CAB.CURRENT_LOCATION_CONTEXT,                          -- LOCATION TYPE

       (SELECT HP.ADDRESS1

        || ', '

        || HP.ADDRESS1

        || ', '

        || HP.ADDRESS3

        || ', '

        || HP.CITY

        || ', '

        || HP.COUNTRY FROM HZ_PARTIES HP WHERE HP.PARTY_ID=CAB.CONTACT_ID )

          LOCATION,                                               -- LOCATION,

       CAB.CONTACT_ID,

       (SELECT HP.PARTY_NAME FROM HZ_PARTIES HP WHERE HP.PARTY_ID=CAB.CONTACT_ID) CONTACT,                                     

       TO_CHAR(CAB.CREATION_DATE,'DD-MM-YY HH:MI:SS') CREATION_DATE,                              

       TO_CHAR(CAB.ACTIVE_END_DATE,'DD-MM-YY HH:MI:SS') ACTIVE_END_DATE,                                  

       CAB.ATTRIBUTE_CHAR1 ASSET_STATUS

  FROM CSE_ASSETS_B CAB,

       CSE_ASSETS_VL CAV

 WHERE     CAB.ASSET_ID = CAV.ASSET_ID

 AND ((TRUNC(CAB.LAST_UPDATE_DATE) BETWEEN TRUNC(:P_START_DT) AND TRUNC(:P_END_DT)) OR TRUNC(CAB.LAST_UPDATE_DATE)= TRUNC(SYSDATE))

Oracle Fusion Maintenance Cloud - Maintenance Asset Meter Details Extract Query

 

SELECT

'KEY' AS "KEY",

 ROWNUM SR_NO,

       CAB.ASSET_ID,

       CAB.ASSET_NUMBER,

       CAV.DESCRIPTION Asset_Description,

   (SELECT NAME

          FROM HR_ORGANIZATION_UNITS

         WHERE ORGANIZATION_ID = CAB.ITEM_ORGANIZATION_ID)

          OPERATING_ORG,

  CAB.ATTRIBUTE_CHAR2 Primary_Custodian,

CM.METER_ID, 

CM.METER_DEFINITION_ID,

CMDT.METER_NAME,

CMDB.METER_CODE,

CMDB.UOM_CODE,

CM.ACTIVE_START_DATE,

CM.ACTIVE_END_DATE,

CMDB.INITIAL_READING_VALUE,

(select READING_DATE from CSE_METER_READINGS where meter_id=CM.METER_ID and INITIAL_FLAG='Y') Intial_Reading_Date,

(select READING_VALUE from CSE_METER_READINGS where METER_ID=CM.METER_ID and METER_READING_ID

= (select MAX(METER_READING_ID) from CSE_METER_READINGS where meter_id=CM.METER_ID )

)Last_Reading,

(select READING_DATE from CSE_METER_READINGS where METER_ID=CM.METER_ID and METER_READING_ID

= (select MAX(METER_READING_ID) from CSE_METER_READINGS where meter_id=CM.METER_ID )

)Last_Reading_Date,

(select READING_VALUE from CSE_METER_READINGS where METER_ID=CM.METER_ID and METER_READING_ID

= (select MAX(METER_READING_ID) from CSE_METER_READINGS where meter_id=CM.METER_ID )

)Life_to_date_Reading,

(select WORK_ORDER_NUMBER 

from MNT_WORK_ORDERS_V where WORK_ORDER_ID =

(select WORK_ORDER_ID from CSE_METER_READINGS where METER_ID=CM.METER_ID and METER_READING_ID

= (select MAX(METER_READING_ID) from CSE_METER_READINGS where meter_id=CM.METER_ID )

) )Work_Order,

CM.DAILY_UTILIZATION_RATE Base_Utilisation_Rate,

decode(CM.ALLOW_IN_MAINT_PROGRAM_FLAG,'Y','YES','NO') Allow_Maintenance,

CM.CREATED_BY Recorded_By

FROM CSE_ASSETS_B CAB,

       CSE_ASSETS_VL CAV,

  CSE_METER_DEFINITIONS_B CMDB,

  CSE_METER_DEFINITIONS_TL CMDT,

  CSE_METERS CM

 WHERE     CAB.ASSET_ID = CAV.ASSET_ID

 AND CMDB.METER_DEFINITION_ID=CMDT.METER_DEFINITION_ID

 AND CMDT.LANGUAGE='US'

 AND CM.METER_DEFINITION_ID=CMDB.METER_DEFINITION_ID

 AND CM.meter_object_id=CAB.ASSET_ID

 AND ((TRUNC(CAB.LAST_UPDATE_DATE) BETWEEN TRUNC(:P_START_DT) AND TRUNC(:P_END_DT)) OR TRUNC(CAB.LAST_UPDATE_DATE)= TRUNC(SYSDATE))