Showing posts with label Oracle Fusion Projects. Show all posts
Showing posts with label Oracle Fusion Projects. Show all posts

Thursday, 7 November 2024

Query For Payroll Run Results Custom OTBI Query

 SET VARIABLE PREFERRED_CURRENCY='User Preferred Currency 1',PREFERRED_CURRENCY='User Preferred Currency 1';SELECT 

   EMP_NUMBER saw_0,

   ASSIGNMENT_NUMBER saw_1,

   EMP_NAME saw_2,

   HIRE_DATE saw_3,

   GRADE saw_4,

   JOB saw_5,

   POSITION_NAME saw_6,

   DEPT_NAME1 saw_7,

   sector_2 saw_8,

   BU_NAME1 saw_9,

   PAYROLL_PERIOD_NAME saw_10,

   PERIOD_NAME saw_11,

   DATE_EARNED saw_12,

   RUN_TYPE saw_13,

   ELEMENT_CLASSI_NAME saw_14,

   ELEMENT_NAME saw_15,

   AMOUNT saw_16,

   CASE WHEN ELEMENT_CLASSI_NAME in ('Involuntary Deductions','Social Insurance Deductions','Voluntary Deductions') THEN (AMOUNT*(-1)) ELSE AMOUNT END saw_17,

   PROCESS_FLOW_NAME saw_18

 FROM (SELECT

   "Payroll - Payroll Run Results Real Time"."Business Unit"."Business Unit Name" BU_NAME1,

   "Payroll - Payroll Run Results Real Time"."Department"."Department Name" DEPT_NAME1,

   "Payroll - Payroll Run Results Real Time"."Element"."Element Classification Name" ELEMENT_CLASSI_NAME,

   "Payroll - Payroll Run Results Real Time"."Element"."Element Name" ELEMENT_NAME,

   "Payroll - Payroll Run Results Real Time"."Grade"."Grade Name" GRADE,

   "Payroll - Payroll Run Results Real Time"."Input Value"."Input Value Name" INPUT_VALUE_NAME,

   "Payroll - Payroll Run Results Real Time"."Input Value"."Input Value Unit of Measure" INPUT_VALUE_UOM,

   "Payroll - Payroll Run Results Real Time"."Job"."Job Name" JOB,

   "Payroll - Payroll Run Results Real Time"."Worker"."Enterprise Hire Date" HIRE_DATE,

   "Payroll - Payroll Run Results Real Time"."Payroll Period"."Period Name" PERIOD_NAME,

   "Payroll - Payroll Run Results Real Time"."Payroll Run Result Details"."Date Earned" DATE_EARNED,

   "Payroll - Payroll Run Results Real Time"."Payroll Run Results"."Run Result Value" RUN_RESULT_VALUE,

   "Payroll - Payroll Run Results Real Time"."Payroll Statutory Unit"."Payroll Statutory Unit Name" Payroll_Statutory_Unit_Name,

   "Payroll - Payroll Run Results Real Time"."Payroll"."Payroll Period Name" PAYROLL_PERIOD_NAME,

   "Payroll - Payroll Run Results Real Time"."Position"."Position Name" POSITION_NAME,

   "Payroll - Payroll Run Results Real Time"."Run Type"."Run Type Name" RUN_TYPE,

   "Payroll - Payroll Run Results Real Time"."Worker"."Assignment Number" ASSIGNMENT_NUMBER,

   "Payroll - Payroll Run Results Real Time"."Worker"."Assignment Status Code" ASSIGN_STATUS_CODE,

   "Payroll - Payroll Run Results Real Time"."Worker"."Employee Display Name" EMP_NAME,

   "Payroll - Payroll Run Results Real Time"."Worker"."Person Number" EMP_NUMBER,

    "Payroll - Payroll Run Results Real Time"."Payroll Flows"."Flow Instance Name" PROCESS_FLOW_NAME,

   "Payroll - Payroll Run Results Real Time"."Payroll Run Results"."Amount" AMOUNT

FROM "Payroll - Payroll Run Results Real Time"

WHERE

((DESCRIPTOR_IDOF("Payroll - Payroll Run Results Real Time"."Input Value"."Input Value Unit of Measure") = 'M') AND ("Payroll - Payroll Run Results Real Time"."Element"."Element Classification Name" in ('Involuntary Deductions','Social Insurance Deductions','Standard Earnings','Supplemental Earnings','Voluntary Deductions','Information') )AND ("Input Value"."Input Value Name" = 'Pay Value'))


) TABLE_A LEFT OUTER JOIN (

SELECT

   "Workforce Management - Worker Assignment Real Time"."Worker Assignment Details"."PER_ASG_DF_SECTOR_" sector_2,

   "Workforce Management - Worker Assignment Real Time"."Worker"."Person Number" person_number2

FROM "Workforce Management - Worker Assignment Real Time"

WHERE

(DESCRIPTOR_IDOF("Workforce Management - Worker Assignment Real Time"."Worker"."Assignment Status") IN (1, 2))

) TABLE_B ON TABLE_A.EMP_NUMBER = TABLE_B.person_number2

 WHERE 

(EMP_NUMBER IN ('ABC')) AND (DATE_EARNED >= ANY 

 ( 

 SELECT saw_0 FROM (SELECT 

   "Payroll Period"."Default Pay Date" saw_0

 FROM "Payroll - Payroll Run Results Real Time"

 WHERE 

"Payroll Period"."Period Name" IN ('4 2023 Monthly Calendar')


 ) nqw_1 

 )) AND (DATE_EARNED <= ANY 

 ( 

 SELECT saw_0 FROM (SELECT 

   "Payroll Period"."Default Pay Date" saw_0

 FROM "Payroll - Payroll Balances Real Time"

 WHERE 

"Payroll Period"."Period Name" IN ('4 2023 Monthly Calendar')


 ) nqw_1 

 ))

 ORDER BY saw_12 DESC

Tuesday, 8 October 2024

Active Assets Listing Report

 


WITH HIER_AREA AS 

(

   SELECT /*+ materialize */ distinct gsv.DEP29_PK1_VALUE,gsv.DEP1_PK1_VALUE,flv.description

   FROM GL_SEG_VAL_HIER_CF gsv,

   FND_TREE_NODE ftn, 

   fnd_flex_values_vl flv

   where gsv.tree_structure_code = 'GL_ACCT_FLEX' 

   and gsv.tree_code = 'xxxxxxxxxxxx' 

   and flv.FLEX_VALUE = gsv.dep29_pk1_value

        and flv.value_category = 'xxxxxxx'

   AND ((COALESCE(NULL,:P_TREE_V ) IS NULL) OR gsv.TREE_VERSION_ID IN (:P_TREE_V))


),

 

report as (

select /*+ materialize */ 

AREA_CODE_NAME

,comp_code

, facility_id

, facility_desc

,asset_id

,conversion_id

,description

,category_major 

,category_minor

,FA_LCODE

,address

, postal_code

,  city

,  county

,  state

, country

, convention

, life

, In_Service_Date

, Quantity

, dept

, product

, project

, from_curr

, sum(COST) COST

,sum(deprn) deprn

,sum(accum_deprn) accum_deprn

,(sum(ytd_dpr) + sum(ytd_pdp)) ytd_dpr

,Revaluation_Reserve

,(sum(COST) - sum(accum_deprn))NBV

,unit_number

, parent_id

, vin

, wm_ownership

, Goodwill_Ownership

, acquired_asset

,RUN_DATE

, area

,book_type_code

,transaction_type_code

, open_period

,concat_expns_acc

,case when rem_life_in_mon <= 0 then 0 else rem_life_in_mon end rem_life_in_mon

,fuel_type


from(SELECT

ftn.dep29_pk1_value||'-'||ftn.description AREA_CODE_NAME, --- Added as per ERFA-910

gcc.segment1 comp_code

, gcc.segment2   facility_id

, gl_flexfields_pkg.get_description_sql (gcc.chart_of_accounts_id,2,gcc.segment2) facility_desc

,fab.asset_number asset_id

,fab.attribute1 conversion_id

,fab.description

,fcb.segment1 category_major 

,fcb.segment2 category_minor

,fl.segment2 FA_LCODE

,hl.address_line_1 address

, hl.postal_code

, hl.town_or_city city

, hl.region_1 county

, hl.region_2 state

, hl.country

,fct.prorate_convention_code convention

,fm.life_in_months life

,TO_CHAR(fb.date_placed_in_service,'MM/DD/YYYY','nls_date_language=American') In_Service_Date

,nvl(fdh.units_assigned,0)Quantity

,gcc.segment3 dept

,gcc.segment5 product

,gcc.segment6 project

,SOB.Currency_Code from_curr

,nvl(fdd.cost,0) COST

,NVL(fdd.deprn_reserve,0) accum_deprn

,NVL(fdd.ytd_deprn,0) ytd_dpr1

,nvl((select sum(nvl(xl.accounted_cr,-1*xl.accounted_dr)) ytd_deprn

from FA_DEPRN_DETAIL fdd1, 

xla_ae_headers xh,

xla_ae_lines xl,

GL_CODE_COMBINATIONS GCC1

where fdd1.asset_id = fab.asset_id

and ROWNUM<50

and fdd1.book_type_code = fb.book_type_Code

AND FDD1.DISTRIBUTION_ID = FDD.DISTRIBUTION_ID

and fdd1.event_id = xh.event_id

and xh.ae_header_id = xl.ae_header_id

and xl.application_id = 140

and xl.accounting_class_code = 'DEPRECIATION_RESERVE'

AND GCC1.CODE_COMBINATION_ID = XL.CODE_COMBINATION_ID

and gcc1.segment2 = gcc.segment2

AND FDD1.PERIOD_COUNTER IN (select period_counter from fa_deprn_periods

where fiscal_year =  substr(sysdate,1,4)

and book_type_code = fb.book_type_Code

and period_close_date is null)

),0) deprn

, NVL((SELECT sum(nvl(xlA1.accounted_cr,-1*XLA1.accounted_dr))

      FROM 

       (select DISTINCT FDD1.EVENT_ID 

      from FA_DEPRN_DETAIL fdd1

      where fdd1.asset_id = fab.asset_id

      and fdd1.book_type_code = fb.BOOK_TYPE_CODE 

      AND FDD1.DEPRN_SOURCE_CODE = 'D'

      AND FDD1.PERIOD_COUNTER IN (SELECT PERIOD_COUNTER 

                                  FROM FA_DEPRN_PERIODS FDP1

                                  WHERE FDP1.BOOK_TYPE_CODE = fb.book_type_code 

                                  AND FDP1.FISCAL_YEAR = Extract(year from sysdate)

                                  ))FDD1, XLA_AE_HEADERS XAH1, XLA_AE_LINES XLA1, GL_CODE_COMBINATIONS GCC1

      WHERE FDD1.EVENT_ID = XAH1.EVENT_ID

      AND XAH1.AE_HEADER_ID = XLA1.AE_HEADER_ID

  and xla1.application_id = 140

      AND XLA1.ACCOUNTING_CLASS_CODE = 'DEPRECIATION_RESERVE'

      AND GCC1.CODE_COMBINATION_ID = XLA1.CODE_COMBINATION_ID

      AND GCC1.SEGMENT1 = GCC.SEGMENT1 

      AND GCC1.SEGMENT2 = GCC.SEGMENT2

      AND Extract(year from XLA1.ACCOUNTING_DATE) =  Extract(year from sysdate)

     ), 0)ytd_dpr 

,NVL((SELECT sum(nvl(xl1.accounted_dr,-1*xl1.accounted_cr))

         from  

         fa_transaction_headers ftv1, xla_ae_headers xh1,

         xla_ae_lines xl1,gl_code_combinations gcc1, fa_additions_vl fab11

         where 1=1

         and ftv1.asset_id = fab.asset_id 

         and ftv1.book_type_code = fb.book_type_code

         and ftv1.event_id = xh1.event_id

         and xl1.ae_header_id = xh1.ae_header_id

         and xl1.code_combination_id = gcc1.code_combination_id

         and gcc1.segment1= gcc.segment1

         and gcc1.segment2= gcc.segment2

         and ftv1.asset_id = fab11.asset_id

         AND EXTRACT(YEAR FROM XL1.ACCOUNTING_DATE) = Extract(year from sysdate)

         and xl1.accounting_class_code in ('DEPRECIATION_EXPENSE','UNPLANNED_DEPRECIATION_EXPENSE')

          ) ,0) AS YTD_PDP

,decode(fds.reval_reserve,0,'-',fds.reval_reserve) Revaluation_Reserve

,fab.manufacturer_name unit_number

,(case when (select count(asset_id) from fa_additions_vl where parent_asset_id = fab.asset_id) > 0

then fab.asset_number

when (select count(parent_asset_id) from fa_additions_vl where asset_id = fab.asset_id) > 0

then (select asset_number from fa_additions_vl where asset_id = fab.parent_asset_id)

when ((select count(asset_id) from fa_additions_vl where parent_asset_id = fab.asset_id) = 0 and 

(select count(parent_asset_id) from fa_additions_vl where asset_id = fab.asset_id) = 0)

then null

else null

end) parent_id

,fab.serial_number vin

,fab.attribute2 wm_ownership

,fab.attribute4 Goodwill_Ownership

,fab.attribute5 acquired_asset

,(select to_char(sysdate,'dd')||'-'||upper(period_name)

from gl_periods

where period_num = to_char(sysdate,'mm')

and period_set_name = 'xxxxxx'

and period_year = extract(year from sysdate)) RUN_DATE

,ftn.dep29_pk1_value area

,ftn.description area_name

,fb.book_type_code

,ftv.transaction_type_code

,(select substr(period_name,1,3)||'-'||substr(period_name,7,8) from fa_deprn_periods

where period_close_date is null

and book_type_code = fb.book_type_code) open_period,

gcc.segment1||'.'||gcc.segment2||'.'||gcc.segment3||'.'||gcc.segment4||'.'||gcc.segment5||'.'||gcc.segment6||'.'||gcc.segment7||'.'||gcc.segment8 concat_expns_acc

, ( (fm.life_in_months) - (((((select FISCAL_YEAR from fa_deprn_periods where period_close_date is null and book_type_code = fb.book_type_code) - EXTRACT(year FROM fb.date_placed_in_service)) * 12)  + (select PERIOD_NUM from fa_deprn_periods where period_close_date is null

and book_type_code = fb.book_type_code)) - EXTRACT(month FROM fb.date_placed_in_service))) rem_life_in_mon

,fab.model_number fuel_type

FROM 

 fa_transaction_headers ftv

,fa_additions_vl fab

,fa_books fb

,fa_retirements fr

,FA_DEPRN_SUMMARY FDS

,FA_DEPRN_DETAIL FDD

,fa_distribution_history fdh

,GL_CODE_COMBINATIONS GCC

,HIER_AREA ftn

,FA_DEPRN_PERIODS FDP

,fa_methods fm

,fa_locations fl

,hr_locations_all hl

,fa_categories_b fcb

,fa_convention_types fct

,fa_book_controls fbc

,GL_SETS_OF_BOOKS sob


WHERE 1=1 

and fab.asset_id not in (select distinct fth1.asset_id from fa_transaction_headers fth1

where fth1.transaction_type_code ='xxxxxxxx'

and fth1.date_effective = (select max(date_effective) from fa_transaction_headers 

where asset_id = fab.asset_id

and book_type_code = ftv.book_type_code)

and fth1.book_type_code = fb.book_type_code)

and fab.asset_category_id = fcb.category_id

and fab.asset_id = fb.asset_id

and fb.date_ineffective is null

and fb.convention_type_id = fct.convention_type_id

and fab.asset_id = fr.asset_id(+)

and fr.retirement_id(+) = fb.retirement_id

and fbc.book_type_code = fb.book_type_code

and fbc.set_of_books_id = sob.set_of_books_id

AND FDS.DEPRN_SOURCE_CODE = 'DEPRN'

AND FDS.ASSET_ID = FB.ASSET_ID

AND FDS.BOOK_TYPE_CODE = FB.BOOK_TYPE_CODE

AND FDP.PERIOD_COUNTER = FDS.PERIOD_COUNTER

AND FDP.BOOK_TYPE_CODE = FDS.BOOK_TYPE_CODE

AND FDD.ASSET_ID = FB.ASSET_ID

AND FDD.ASSET_ID = FDS.ASSET_ID

AND FDD.BOOK_TYPE_CODE = FB.BOOK_TYPE_CODE

AND FDD.PERIOD_COUNTER = FDS.PERIOD_COUNTER

AND FDD.PERIOD_COUNTER = FDP.PERIOD_COUNTER

and fdd.period_counter in (select max(fdpi.period_counter) 

                            from fa_deprn_detail fdpi 

                            where fdpi.book_type_code = fb.book_type_code 

and fdpi.distribution_id = fdd.distribution_id --new

                            and fdpi.asset_id = fb.asset_id)

and fb.method_id = fm.method_id

and fdd.distribution_id = fdh.distribution_id

and fdh.asset_id = fab.asset_id

and fdh.book_type_code = fb.book_type_code

and fdh.code_combination_id = gcc.code_combination_id

and fdh.date_ineffective is null

and ftn.dep1_pk1_value = gcc.segment1

AND ((COALESCE(NULL,:P_AREA ) IS NULL) OR ftn.dep29_pk1_value IN (:P_AREA)) 

AND ((COALESCE(NULL,:P_AREA_NAME) IS NULL) OR ftn.description IN (:P_AREA_NAME)) 

and fb.book_type_code = :P_BOOK_TYPE_CODE

AND ((COALESCE(NULL,:P_FACILITY ) IS NULL) OR gcc.segment2 IN (:P_FACILITY)) 

and fb.date_effective in (select max(fb1.date_effective) from fa_books fb1

where fb1.asset_id = fab.asset_id and fb1.book_type_code = fb.book_type_code)

and fl.location_id = fdh.location_id

and fl.segment2 = hl.internal_location_code

and fdh.transaction_header_id_in = ftv.transaction_header_id

and fb.asset_id = ftv.asset_id

and fb.book_type_code = ftv.book_type_code

)

group by AREA_CODE_NAME,

comp_code

, facility_id

, facility_desc

,asset_id

,conversion_id

,description

,category_major 

,category_minor

,FA_LCODE

,address

, postal_code

,  city

,  county

,  state

, country

, convention

, life

, In_Service_Date

, Quantity

, dept

, product

, project

, from_curr

,Revaluation_Reserve

,unit_number

, parent_id

, vin

, wm_ownership

, Goodwill_Ownership

, acquired_asset

,RUN_DATE

, area

,book_type_code

,transaction_type_code

, open_period

,concat_expns_acc

,rem_life_in_mon

,fuel_type

order by area,facility_id,category_major,category_minor)

select * from report

order by area,facility_id,category_major,category_minor,asset_id

Friday, 11 August 2023

Query to get Negotiation , Bid and RFQ Details (RFQ Details Buyer )

 -- RFQ DETAILS

WITH LOOKUP_VALUES AS ( 

    SELECT LOOKUP_TYPE, 

           LOOKUP_CODE, 

           MEANING,

           VIEW_APPLICATION_ID

    FROM   FND_LOOKUP_VALUES_VL FLVL

    WHERE  FLVL.LOOKUP_TYPE IN ('PON_AUCTION_STATUS','PON_AWARD_STATUS','YES_NO','PON_CONTRACT_TYPE')

    AND    FLVL.ENABLED_FLAG='Y'

    AND    SYSDATE BETWEEN NVL(FLVL.START_DATE_ACTIVE,TO_DATE('01/01/1951','DD/MM/YYYY')) AND NVL(FLVL.END_DATE_ACTIVE,TO_DATE('31/12/4712','DD/MM/YYYY')))

SELECT 

      BUSINESS_UNIT,

  RFQ_NUMBER,

  NEGOTIATION_TITLE,

  NEGOTIATION_SYNOPSIS,

  NEGOTIATION_TYPE,

  NEGOTIATION_STYLE,

      NEGOTIATION_STATUS,

      NEGOTIATION_CURRENCY,

  OUTCOME_DOCUMENT_TYPE,

      NEGOTIATION_CREATION_DATE,

  NEGOTIATION_PREVIEW_DATE,

  NEGOTIATION_OPEN_DATE,

  TIME_REMAINING,

      NEGOTIATION_CLOSE_DATE ,

  BUYER, 

      AWARD,

      AWARD_DATE,

      AWARD_NUMBER,

      AWARD_STATUS,

      AWARD_APPROVED_DATE,

  AWARDED_SUPPLIER,

  PROJECT_NUMBER,

  PROJECT_NAME,

  PROJECT_MANAGER,

  RELATED_REQUISITION_NUMBER,   

  ISSUED_PO_NUMBER,  

      COUNT(TOTAL_NO_OF_BIDS) AS TOTAL_NO_OF_BIDS,   

  COUNT(NUMBER_OF_AWARDS) NUMBER_OF_AWARDS,

  COUNT(TOTAL_ISSUED_RFQ_SUPPLIERS) AS TOTAL_ISSUED_RFQ_SUPPLIERS,

  COUNT(TOTAL_ISSUED_POS) AS TOTAL_ISSUED_POS ,

  COUNT(TOTAL_NUMBER_OF_SUPPLIERS_INVITED) AS TOTAL_NUMBER_OF_SUPPLIERS_INVITED,

      COUNT(TOTAL_NUMBER_OF_SUPPLIERS_ACKNOWLEDGED) AS TOTAL_NUMBER_OF_SUPPLIERS_ACKNOWLEDGED,

  NEGOTIATION_PUBLISH_DATE,

  NEGOTIATION_CYCLE_TIME,

  NEGOTIATION_AWARDCYCLE_TIME,

  NEGOTIATION_BIDDINGCYCLE_TIME,

  NEGOTIATION_PUBLICATION_TO_COMPLETION_DAYS,

  BUYER_ENTITY,

  REQUESTER

  --SUPPLIER

  

  

FROM 



SELECT DISTINCT

FBU.BU_NAME                                                                                     AS  BUSINESS_UNIT,

PAH.DOCUMENT_NUMBER                                                                             AS  RFQ_NUMBER,

PAH.AUCTION_TITLE                                                                               AS  NEGOTIATION_TITLE,

PAH.SYNOPSIS                                                                                    AS  NEGOTIATION_SYNOPSIS,

PADV.NAME                                                                                       AS NEGOTIATION_TYPE,

PNSV.STYLE_NAME                                                                                 AS NEGOTIATION_STYLE,

PAH.AUCTION_STATUS   AS NEGOTIATION_STATUS, -- COULDN'T FIND LOOKUP ENTRY FOR THIS... 

PAH.CURRENCY_CODE                                                                               AS NEGOTIATION_CURRENCY,

(SELECT MEANING 

 FROM   LOOKUP_VALUES 

 WHERE  LOOKUP_TYPE='PON_CONTRACT_TYPE'

 AND    LOOKUP_CODE=PAH.OUTCOME_STATUS ) AS OUTCOME_DOCUMENT_TYPE,

PAH.CREATION_DATE                                                                               AS NEGOTIATION_CREATION_DATE,

PAH.VIEW_BY_DATE                                                                                AS NEGOTIATION_PREVIEW_DATE,

PAH.OPEN_BIDDING_DATE                                                                           AS NEGOTIATION_OPEN_DATE,    

 ABS(TRUNC(PAH.CLOSE_DATE_PAUSE_ADJUSTED)-TRUNC(SYSDATE))  AS TIME_REMAINING,    

PAH.CLOSE_DATE_PAUSE_ADJUSTED                                                                          AS      NEGOTIATION_CLOSE_DATE,

(SELECT DISTINCT PPNF.DISPLAY_NAME     

FROM PER_PERSON_NAMES_F PPNF,

PON_BUYER_ACTIVITIES PBA

WHERE 

PBA.AUCTION_HEADER_ID = PAH.AUCTION_HEADER_ID

AND PBA.ACTIVITY_OWNER_ID = PPNF.PERSON_ID

AND PPNF.NAME_TYPE='GLOBAL'

AND PBA.ACTIVITY_CODE = 'NEW_COLLAB_TEAM_ASSIGNMENT'

AND SYSDATE BETWEEN PPNF.EFFECTIVE_START_DATE AND PPNF.EFFECTIVE_END_DATE)                                              AS BUYER, 

(SELECT MEANING 

 FROM   LOOKUP_VALUES 

 WHERE  LOOKUP_TYPE='YES_NO'

 AND    VIEW_APPLICATION_ID=0

 AND    LOOKUP_CODE=PAIP.NO_AWARD ) AS AWARD,

PAH.AWARD_DATE                                                                                 AS   AWARD_DATE,

PAH.SOURCE_DOC_NUMBER                                                                                       AS       AWARD_NUMBER,

(SELECT MEANING 

 FROM   LOOKUP_VALUES 

 WHERE  LOOKUP_TYPE='PON_AWARD_STATUS'

 AND    LOOKUP_CODE=PAH.AWARD_STATUS ) AS AWARD_STATUS,

PAH.AWARD_APPROVAL_DATE                                                                                    AS             AWARD_APPROVED_DATE, 

CASE WHEN PAH.AWARD_STATUS='AWARDED' THEN PSV.VENDOR_NAME ELSE NULL END                        AS AWARDED_SUPPLIER,

PPV.SEGMENT1                                                                                               AS PROJECT_NUMBER,

PPV.NAME                                                                                                   AS PROJECT_NAME,

(SELECT PPNF.DISPLAY_NAME     

FROM   PJF_PROJECT_MEMBERS_V PPMV, 

       PJF_PROJ_ROLE_TYPES_VL PPRTV,

       PER_PERSON_NAMES_F PPNF                                                  

WHERE  PPNF.PERSON_ID=PPMV.PERSON_ID

AND    PPRTV.PROJECT_ROLE_ID=PPMV.PROJECT_ROLE_ID

AND    PPRTV.PROJECT_ROLE_NAME='PROJECT MANAGER'

AND    PPNF.NAME_TYPE='GLOBAL'

AND    PPMV.PROJECT_ID = PPV.PROJECT_ID

AND    SYSDATE BETWEEN PPNF.EFFECTIVE_START_DATE AND PPNF.EFFECTIVE_END_DATE

AND    SYSDATE BETWEEN PPMV.START_DATE_ACTIVE AND NVL(PPMV.END_DATE_ACTIVE,TO_DATE('31/12/4712','DD/MM/YYYY'))

AND    SYSDATE BETWEEN PPRTV.START_DATE_ACTIVE AND NVL(PPRTV.END_DATE_ACTIVE,TO_DATE('31/12/4712','DD/MM/YYYY'))


)                                                                              AS PROJECT_MANAGER,

PRHA.REQUISITION_NUMBER                                                                                            AS RELATED_REQUISITION_NUMBER,                                                                                                                                                      

POH.SEGMENT1                                                                                                        AS   ISSUED_PO_NUMBER,

PBH.BID_NUMBER                                                                                                 AS TOTAL_NO_OF_BIDS,                                                                         

PAIP.AWARDED_QUANTITY                                                                                                    AS NUMBER_OF_AWARDS,



PAIP.RECOMMENDED_AWARD_AMOUNT                                                                              AS TOTAL_ISSUED_RFQ_SUPPLIERS,

POH.SEGMENT1                                                                                                         AS TOTAL_ISSUED_POS,

PSV.VENDOR_ID                                                                             AS TOTAL_NUMBER_OF_SUPPLIERS_INVITED,

PBH.ORIGINAL_BID_NUMBER                                                                     AS TOTAL_NUMBER_OF_SUPPLIERS_ACKNOWLEDGED,

PAH.PUBLISH_DATE                                                                                 AS NEGOTIATION_PUBLISH_DATE,



ABS(TRUNC(PAH.CREATION_DATE)-TRUNC(PAH.CLOSE_DATE_PAUSE_ADJUSTED))                                  AS NEGOTIATION_CYCLE_TIME,


ABS(TRUNC(PAH.AWARD_APPROVAL_DATE)-TRUNC(PAH.AWARD_COMPLETE_DATE))                                  AS NEGOTIATION_AWARDCYCLE_TIME,


ABS(TRUNC(PAH.OPEN_BIDDING_DATE)-TRUNC(PAH.CLOSE_BIDDING_DATE))                                 AS NEGOTIATION_BIDDINGCYCLE_TIME,


ABS(TRUNC(PAH.PUBLISH_DATE)-TRUNC(PAH.CLOSE_DATE_PAUSE_ADJUSTED))                               AS  NEGOTIATION_PUBLICATION_TO_COMPLETION_DAYS, 


XLE.NAME                                                                                               AS BUYER_ENTITY,

(SELECT PPNF.DISPLAY_NAME     

FROM PER_PERSON_NAMES_F PPNF

WHERE PPNF.PERSON_ID=PRLA.REQUESTER_ID 

AND PPNF.NAME_TYPE='GLOBAL'

AND SYSDATE BETWEEN PPNF.EFFECTIVE_START_DATE AND PPNF.EFFECTIVE_END_DATE)                                               AS REQUESTER 

--PSV.VENDOR_NAME AS                                                                                                SUPPLIER

FROM 


PON_AUCTION_HEADERS_ALL PAH,

FUN_NAMES_BUSINESS_UNITS_V FBU ,

PON_BID_HEADERS PBH ,

POZ_SUPPLIERS_V PSV  ,

 PON_AUC_DOCTYPES_VL PADV ,

 PON_NEGOTIATION_STYLES_VL PNSV ,

 PO_HEADERS_ALL POH ,

 PO_DISTRIBUTIONS_ALL         PDA,

PJF_PROJECTS_ALL_VL PPV ,

PON_BID_PO_NUMBERS PBPN  ,


PON_AUCTION_ITEM_PRICES PAIP ,



POR_REQUISITION_LINES_ALL PRLA ,

POR_REQUISITION_HEADERS_ALL PRHA ,

  XLE_ENTITY_PROFILES XLE 

 

--PO_LINES_ALL PLA,  




WHERE 1=1

AND PAH.PRC_BU_ID = FBU.BU_ID

AND PAH.AUCTION_HEADER_ID = PBH.AUCTION_HEADER_ID(+)

AND PBH.VENDOR_ID = PSV.VENDOR_ID(+) 

AND PAH.DOCTYPE_ID  = PADV.DOCTYPE_ID(+) 

AND PADV.NAME='RFQ'  

AND PAH.STYLE_ID=PNSV.STYLE_ID(+) 

AND PAH.AUCTION_HEADER_ID=POH.PO_HEADER_ID(+)

AND POH.PO_HEADER_ID = PDA.PO_HEADER_ID(+)

AND PDA.PJC_PROJECT_ID = PPV.PROJECT_ID(+) 

--AND PAH.PROJECT_ID = PPV.PROJECT_ID(+)

AND PAH.AUCTION_HEADER_ID = PBPN.AUCTION_HEADER_ID(+) 

AND PAH.AUCTION_HEADER_ID(+) = PAIP.AUCTION_HEADER_ID

AND PAH.AUCTION_HEADER_ID = PRLA.AUCTION_HEADER_ID(+)

AND PRLA.BID_NUMBER (+) = PBH.BID_NUMBER 

AND PRLA.REQUISITION_HEADER_ID = PRHA.REQUISITION_HEADER_ID(+)

AND PRLA.PO_HEADER_ID = POH.PO_HEADER_ID(+) 

AND PBPN.PO_HEADER_ID = POH.PO_HEADER_ID(+)

AND POH.SOLDTO_LE_ID = XLE.LEGAL_ENTITY_ID(+) 

--AND POH.PO_HEADER_ID=PLA.PO_HEADER_ID

--AND PBH.BID_NUMBER = PAIP.BEST_BID_BID_NUMBER(+)

--AND PAH.DOCUMENT_NUMBER ='ITNEG10021,1'

AND TRUNC(NVL(PAH.CREATION_DATE,SYSDATE)) BETWEEN NVL(:P_RFQ_CREATION_DATE_FROM,TRUNC(SYSDATE-999)) AND NVL(:P_RFQ_CREATION_DATE_TO,TRUNC(SYSDATE+999))

AND (FBU.BU_ID IN (:P_BUSINESS_UNIT_ID) OR COALESCE(:P_BUSINESS_UNIT_ID,NULL) IS NULL)

AND (PSV.VENDOR_ID IN (:P_VENDOR_ID) OR COALESCE(:P_VENDOR_ID,NULL) IS NULL)

AND (PPV.PROJECT_ID IN (:P_PROJECT_ID) OR COALESCE (:P_PROJECT_ID,NULL) IS NULL) 

AND (PAH.AUCTION_HEADER_ID IN (:P_AUCTION_HEADER_ID) OR COALESCE(:P_AUCTION_HEADER_ID,NULL) IS NULL)

AND (PRHA.REQUISITION_HEADER_ID IN (:P_REQUISITION_HEADER_ID) OR COALESCE(:P_REQUISITION_HEADER_ID,NULL) IS NULL)

AND  (XLE.LEGAL_ENTITY_ID IN (:P_LEGAL_ENTITY_ID) OR COALESCE (:P_LEGAL_ENTITY_ID,NULL) IS NULL)


)

WHERE 1=1

AND (PROJECT_MANAGER IN (:P_PROJECT_MANAGER_SOURCE_ID) OR COALESCE (:P_PROJECT_MANAGER_SOURCE_ID,NULL) IS NULL)

AND (BUYER IN (:P_ACTIVITY_OWNER_ID) OR COALESCE (:P_ACTIVITY_OWNER_ID,NULL) IS NULL)


GROUP BY

      BUSINESS_UNIT,

  RFQ_NUMBER,

  NEGOTIATION_TITLE,

  NEGOTIATION_SYNOPSIS,

  NEGOTIATION_TYPE,

  NEGOTIATION_STYLE,

      NEGOTIATION_STATUS,

      NEGOTIATION_CURRENCY,

  OUTCOME_DOCUMENT_TYPE,

      NEGOTIATION_CREATION_DATE,

  NEGOTIATION_PREVIEW_DATE,

  NEGOTIATION_OPEN_DATE,

  TIME_REMAINING,

      NEGOTIATION_CLOSE_DATE,

  BUYER, 

      AWARD,

      AWARD_DATE,      

      AWARD_NUMBER,

      AWARD_STATUS,

      AWARD_APPROVED_DATE,

  AWARDED_SUPPLIER,

  PROJECT_NUMBER,

  PROJECT_NAME,

  PROJECT_MANAGER,

  RELATED_REQUISITION_NUMBER,   

  ISSUED_PO_NUMBER,  

  NEGOTIATION_PUBLISH_DATE,

  NEGOTIATION_CYCLE_TIME,

  NEGOTIATION_AWARDCYCLE_TIME,

  NEGOTIATION_BIDDINGCYCLE_TIME,

  NEGOTIATION_PUBLICATION_TO_COMPLETION_DAYS,

  BUYER_ENTITY,

  REQUESTER

  --SUPPLIER

ORDER BY

  BUSINESS_UNIT,

  RFQ_NUMBER

Query to get Payables and Receivables Project Details (Project Cash Flow Report)

with gl_period_dates as ( 

       select period_name, 

              year_start_date, 

              add_months(year_start_date,12)-1 year_end_date, 

              quarter_start_date, 

              add_months(quarter_start_date,3)-1 quarter_end_date,

              start_date period_start_date, 

              end_date period_end_date

       from   gl_periods 

       where  period_set_name='Global Calendar'

       and    period_year=:p_year 

       and   (quarter_num IN (:p_quarter) OR coalesce(:p_quarter, NULL) IS NULL)

       and   (period_name IN (:p_month) OR coalesce(:p_month, NULL) IS NULL)),

receivables as (

select fnbuv.bu_id, 

              xlp.legal_entity_id,

              ppavl.project_id,

              ppavl.carrying_out_organization_id,

              pcpl.contract_id,

              fnbuv.bu_name,

              xlp.name le_name,

              ppavl.name, 

              ppavl.segment1,

OCH.contract_number,

              SUM(NVL(aps.amount_applied,0)) cash_in,

-- SUM(NVL(xal.ACCOUNTED_DR, 0)-NVL(xal.ACCOUNTED_CR, 0)) billing_amt

(SELECT sum(NVL(PROJECT_CURR_BILLED_AMT,0)) 

          FROM

          pjb_inv_line_dists idl

          

          WHERE 1=1

          and idl.CONTRACT_ID = och.id

          and  invoice_id in ( select invoice_id from pjb_invoice_headers 

  where

          contract_id = idl.contract_id  

  and invoice_status_code = 'ACCEPTED')

          ) billing_amt

FROM   ra_customer_trx_all rct,

okc_k_headers_all_b och,

xla_transaction_entities xlate,

xla_events xet,

xla_ae_headers xah,

xla_ae_lines xal,

ar_payment_schedules_all aps,

fun_names_business_units_v fnbuv,

xle_entity_profiles xlp,

gl_period_dates gpd,

              pjf_projects_all_vl ppavl,

              (select distinct project_id, 

                      contract_id, 

                      major_version

               from   pjb_cntrct_proj_links ) pcpl

WHERE to_char(rct.interface_header_attribute1) = to_char(och.contract_number)

AND   to_char(rct.interface_header_attribute2) = to_char(och.id)

AND   rct.set_of_books_id = xah.ledger_id

       and   pcpl.contract_id=och.id

       and   pcpl.project_id=ppavl.project_id

       --and   och.version_type='C'

AND   och.major_version = (

         SELECT max(och1.major_version)

         FROM okc_k_headers_all_b och1

         WHERE och1.id = OCH.id)

       AND   pcpl.major_version = och.major_version  

       AND   xet.entity_id = xlate.entity_id

       AND   xet.application_id = xlate.application_id

       AND   rct.customer_trx_id = xlate.source_id_int_1

       AND   xal.ae_header_id = xah.ae_header_id

       AND   xet.event_id = xah.event_id

       AND   xah.ledger_id = Xal.ledger_id

   AND   xlp.LEGAL_EMPLOYER_FLAG='Y'

       AND   xal.accounting_class_code = 'RECEIVABLE'

       AND   rct.customer_trx_id = aps.customer_trx_id

       AND   fnbuv.bu_id = rct.org_id

       AND   xlp.legal_entity_id = rct.legal_entity_id

       and   xal.period_name = gpd.period_name

   AND   xlate.entity_code='TRANSACTIONS'

   and   xlate.ledger_id=xah.ledger_id

       and   trunc(xal.accounting_date) between gpd.period_start_date and gpd.period_end_date

       /* --- Prompts --- */

       and  (ppavl.project_id IN (:p_project_id) OR COALESCE(:p_project_id, NULL) IS NULL)

       and  (ppavl.carrying_out_organization_id IN (:p_carrying_out_organization_id) OR COALESCE(:p_carrying_out_organization_id, NULL) IS NULL)

       and  (fnbuv.bu_id IN (:p_business_unit_id) OR COALESCE(:p_business_unit_id, NULL) IS NULL)

       and  (xlp.legal_entity_id IN (:p_legal_entity_id) OR COALESCE(:p_legal_entity_id, NULL) IS NULL)

       and  (och.id IN (:p_contract_id) OR COALESCE(:p_contract_id, NULL) IS NULL)

and exists ( 

              select 'Y'

              from   gl_seg_val_hier_cf cf,

                     fnd_tree_version_vl ftvvl,

                     xla_mapping_set_values xmsv

              where  cf.tree_structure_code='GL_ACCT_FLEX'

              and    ftvvl.tree_code=cf.tree_code

              and    xmsv.enabled_flag='Y'

              and    ftvvl.tree_version_id=cf.tree_version_id

              and    xmsv.value_constant=cf.dep0_pk1_value

              and    xmsv.input_value_constant1=TO_CHAR(ppavl.carrying_out_organization_id)

              and    exists (

                     select 'Y'

                     from   xla_mapping_set_flavors xmsf, 

                            fnd_id_flex_structures fifs

                     where  xmsf.stripe_id=fifs.id_flex_num

                     and    fifs.id_flex_code='GL#'

                     and    fifs.id_flex_structure_code='xxxx' 

                     and    xmsf.mapping_set_code=xmsv.mapping_set_code

                     and    xmsf.mapping_set_flavor_id=xmsv.mapping_set_flavor_id)

              and    sysdate between ftvvl.effective_start_date and ftvvl.effective_end_date

              and    sysdate between xmsv.effective_start_date and xmsv.effective_end_date

              /* --- Prompts --- */

              and   (cf.dep0_pk1_value in (:p_lob_profit_centre) or coalesce(:p_lob_profit_centre,null) is null)

              and   (cf.dep27_pk1_value in (:p_lob_sub_business_group) or coalesce(:p_lob_sub_business_group,null) is null)

              and   (cf.dep28_pk1_value in (:p_lob_business_group) or coalesce(:p_lob_business_group,null) is null)

              and   (cf.dep29_pk1_value in (:p_lob_service_bundle) or coalesce(:p_lob_service_bundle,null) is null)

              and   (cf.dep30_pk1_value in (:p_lob_division) or coalesce(:p_lob_division,null) is null)

              /* --- End Prompts --- */

              and    cf.tree_code='XXXXX'

              and    xmsv.mapping_set_code ='WDAP_LOB_POO'

              union all 

              select 'Y' 

              from   dual 

              where  coalesce(:p_lob_profit_centre,null) is null

              and    coalesce(:p_lob_sub_business_group,null) is null

              and    coalesce(:p_lob_business_group,null) is null

              and    coalesce(:p_lob_service_bundle,null) is null

              and    coalesce(:p_lob_division,null) is null)

       /* --- End Prompts --- */ 

       and    1=1

GROUP BY fnbuv.bu_id, 

          och.id,

              xlp.legal_entity_id,

              ppavl.project_id,

              ppavl.carrying_out_organization_id,

              pcpl.contract_id,

              fnbuv.bu_name,

              xlp.name,

              ppavl.name, 

              ppavl.segment1,

OCH.contract_number),

payables as (

SELECT fnbuv.bu_id, 

              xlp.legal_entity_id,

              ppavl.project_id,

              ppavl.carrying_out_organization_id,

              aia.invoice_id,              

              fnbuv.bu_name,

              xlp.name le_name,

              ppavl.name, 

              ppavl.segment1, 

SUM(NVL(aipa.INVOICE_BASE_AMOUNT, 0)) cash_out,

SUM(NVL(xal.ACCOUNTED_DR, 0)) liability_amt

FROM   ap_invoices_all aia,

ap_invoice_payments_all aipa,

fun_names_business_units_v fnbuv,

xla_transaction_entities xte,

xla_events xe,

xla_ae_headers xah,

xla_ae_lines xal,

xle_entity_profiles xlp,

gl_period_dates gpd,

              pjf_projects_all_vl ppavl

WHERE  1 = 1

AND   aipa.invoice_id = aia.invoice_id

       and   aia.project_id=ppavl.project_id

AND   fnbuv.bu_id = aia.org_id

AND   aia.invoice_id = xte.source_id_int_1

AND   aia.set_of_books_id = xah.ledger_id

AND   xe.entity_id = xah.entity_id

AND   xte.entity_id = xe.entity_id

AND   xal.ae_header_id = xah.ae_header_id

AND   xte.application_id = xah.application_id

and   xte.ledger_id=xah.ledger_id

    AND   xte.entity_code='TRANSACTIONS'

AND   xal.accounting_class_code = 'LIABILITY'

AND   xlp.legal_entity_id = aia.legal_entity_id

       and   xal.period_name = gpd.period_name

       and   trunc(xal.accounting_date) between gpd.period_start_date and gpd.period_end_date

       /* --- Prompts --- */

       and  (fnbuv.bu_id IN (:p_business_unit_id) OR COALESCE(:p_business_unit_id, NULL) IS NULL)

       and  (xlp.legal_entity_id IN (:p_legal_entity_id) OR COALESCE(:p_legal_entity_id, NULL) IS NULL)

       and  (ppavl.project_id IN (:p_project_id) OR COALESCE(:p_project_id, NULL) IS NULL)

       and  (ppavl.carrying_out_organization_id IN (:p_carrying_out_organization_id) OR COALESCE(:p_carrying_out_organization_id, NULL) IS NULL)

       and exists ( 

              select 'Y'

              from   gl_seg_val_hier_cf cf,

                     fnd_tree_version_vl ftvvl,

                     xla_mapping_set_values xmsv

              where  cf.tree_structure_code='GL_ACCT_FLEX'

              and    ftvvl.tree_code=cf.tree_code

              and    xmsv.enabled_flag='Y'

              and    ftvvl.tree_version_id=cf.tree_version_id

              and    xmsv.value_constant=cf.dep0_pk1_value

              and    xmsv.input_value_constant1=TO_CHAR(ppavl.carrying_out_organization_id) 

              and    exists (

                     select 'Y'

                     from   xla_mapping_set_flavors xmsf, 

                            fnd_id_flex_structures fifs

                     where  xmsf.stripe_id=fifs.id_flex_num

                     and    fifs.id_flex_code='GL#'

                     and    fifs.id_flex_structure_code='xxxxx' 

                     and    xmsf.mapping_set_code=xmsv.mapping_set_code

                     and    xmsf.mapping_set_flavor_id=xmsv.mapping_set_flavor_id)

              and    sysdate between ftvvl.effective_start_date and ftvvl.effective_end_date

              and    sysdate between xmsv.effective_start_date and xmsv.effective_end_date

              /* --- Prompts --- */

              and   (cf.dep0_pk1_value in (:p_lob_profit_centre) or coalesce(:p_lob_profit_centre,null) is null)

              and   (cf.dep27_pk1_value in (:p_lob_sub_business_group) or coalesce(:p_lob_sub_business_group,null) is null)

              and   (cf.dep28_pk1_value in (:p_lob_business_group) or coalesce(:p_lob_business_group,null) is null)

              and   (cf.dep29_pk1_value in (:p_lob_service_bundle) or coalesce(:p_lob_service_bundle,null) is null)

              and   (cf.dep30_pk1_value in (:p_lob_division) or coalesce(:p_lob_division,null) is null)

              /* --- End Prompts --- */

              and    cf.tree_code='XXXXX'

              and    xmsv.mapping_set_code ='WDAP_LOB_POO'

              union all 

              select 'Y' 

              from   dual 

              where  coalesce(:p_lob_profit_centre,null) is null

              and    coalesce(:p_lob_sub_business_group,null) is null

              and    coalesce(:p_lob_business_group,null) is null

              and    coalesce(:p_lob_service_bundle,null) is null

              and    coalesce(:p_lob_division,null) is null)

       /* --- End Prompts --- */ 

       and    1=1

GROUP BY fnbuv.bu_id, 

              xlp.legal_entity_id,

              ppavl.project_id,

              ppavl.carrying_out_organization_id,

              aia.invoice_id,              

              fnbuv.bu_name,

              xlp.name,

              ppavl.name, 

              ppavl.segment1)

SELECT ar.carrying_out_organization_id,

       ar.bu_name,  

       ar.le_name,        

ar.segment1, 

       ar.name project_name, 

       nvl(ar.cash_in,0) cash_in,

nvl(ar.billing_amt,0) billing_amt,

nvl(ap.cash_out,0) cash_out,

nvl(ap.liability_amt,0) liability_amt,

(nvl(ar.cash_in,0)-nvl(ap.cash_out,0)) cash_flow,

(nvl(ar.billing_amt,0)-nvl(ar.cash_in,0)) receivable_amt,

(nvl(ap.liability_amt,0)-nvl(ap.cash_out,0)) payable_amt

FROM   receivables ar, 

       payables ap 

WHERE  ar.bu_id=ap.bu_id(+)

AND    ar.legal_entity_id=ap.legal_entity_id(+)

AND    ar.project_id=ap.project_id (+)

order by ar.segment1,

       ar.bu_name, 

       ar.le_name