Advertisement
psi_mmobile

Untitled

Apr 22nd, 2020
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 4.04 KB | None | 0 0
  1. WITH d AS
  2.   (SELECT TO_DATE(TO_CHAR(?,'dd/MM/YYYY'),'dd/MM/YYYY') AS from_date, --from date parameter retrieved from the filter ex. 02/03/2020
  3.     TO_DATE(TO_CHAR(?,'dd/MM/YYYY'),'dd/MM/YYYY') AS TO_DATE --to date parameter retreived from the filter ex. 31/03/2020
  4.   FROM dual
  5.   )
  6. SELECT
  7. w.WBS_ID,
  8. w.r,
  9. w.PARENT_WBS_ID,
  10. w.OPERATION_CENTER_ID,
  11. w.CAN_ASSIGN_TEAM,
  12. w.LVL,
  13. w.ref_number,
  14. w.WBS_NAME_LEVEL_1,
  15. w.WBS_REF_NUMBER_LEVEL_1,
  16. w.WBS_NAME_LEVEL_2,
  17. w.WBS_REF_NUMBER_LEVEL_2,
  18. w.WBS_NAME_LEVEL_3,
  19. w.WBS_REF_NUMBER_LEVEL_3,
  20. p.DISPLAY_FIRST_DAY,
  21. p.PERIOD,
  22. p.START_DATE,
  23. p.END_DATE,
  24. DECODE (p.PERIOD, 'M', TO_CHAR ( p.DISPLAY_FIRST_DAY, 'YYYYMM'), TO_CHAR ( p.DISPLAY_FIRST_DAY, 'YYYYMMWW')) AS date_order,
  25. UPPER(w.WBS_NAME_LEVEL_1 || ' ' || w.WBS_REF_NUMBER_LEVEL_1 || ' ' || w.WBS_NAME_LEVEL_2 || ' ' || w.WBS_REF_NUMBER_LEVEL_2 || ' ' || w.WBS_NAME_LEVEL_3 || ' ' || w.WBS_REF_NUMBER_LEVEL_3) AS ID_STRING,
  26. p_wbs.sumHrDPerWBS(w.wbs_id, p.start_date, p.end_date) AS SUM_HRD,
  27. TO_CHAR(p.display_first_day,'iw') AS WEEK_OF_YEAR
  28. FROM
  29.   (SELECT DISTINCT TRUNC( from_date + LEVEL -1, 'iw') display_first_day,
  30.     'W' AS period,
  31.     CASE
  32.       WHEN TRUNC( from_date + LEVEL -1, 'iw') < from_date
  33.       THEN from_date
  34.       ELSE TRUNC( from_date + LEVEL -1, 'iw')
  35.     END AS start_date,
  36.     CASE
  37.       WHEN TRUNC( from_date + LEVEL -1, 'iw') + 6 > TO_DATE
  38.       THEN TO_DATE
  39.       ELSE TRUNC( from_date + LEVEL -1, 'iw') + 6
  40.     END AS end_date
  41.   FROM d
  42.     CONNECT BY LEVEL <= TO_DATE - from_date
  43.   UNION
  44.   SELECT DISTINCT TRUNC( from_date + LEVEL -1, 'MM') display_first_day,
  45.     'M' AS period,
  46.     CASE
  47.       WHEN TRUNC( from_date + LEVEL -1, 'MM') < from_date
  48.       THEN from_date
  49.       ELSE TRUNC( from_date + LEVEL -1, 'MM')
  50.     END AS start_date,
  51.     CASE
  52.       WHEN LAST_DAY( from_date + LEVEL -1) > TO_DATE
  53.       THEN TO_DATE
  54.       ELSE LAST_DAY( from_date + LEVEL -1)
  55.     END AS end_date
  56.   FROM d
  57.     CONNECT BY LEVEL <= TO_DATE - from_date
  58.   ORDER BY period,
  59.     display_first_day
  60.   ) p
  61. JOIN
  62.   (SELECT
  63.     ROWNUM AS r,
  64.     CASE
  65.       WHEN LEVEL = 1
  66.       THEN wbs.name
  67.       ELSE '/'
  68.     END AS wbs_name_level_1,
  69.     CASE
  70.       WHEN LEVEL = 1
  71.       THEN wbs.ref_number
  72.       ELSE '/'
  73.     END AS wbs_ref_number_level_1,
  74.     CASE
  75.       WHEN LEVEL = 2
  76.       THEN wbs.name
  77.       ELSE '/'
  78.     END AS wbs_name_level_2,
  79.     CASE
  80.       WHEN LEVEL = 2
  81.       THEN wbs.ref_number
  82.       ELSE '/'
  83.     END AS wbs_ref_number_level_2,
  84.     CASE
  85.       WHEN LEVEL = 3
  86.       THEN wbs.name
  87.       ELSE '/'
  88.     END AS wbs_name_level_3,
  89.     CASE
  90.       WHEN LEVEL = 3
  91.       THEN wbs.ref_number
  92.       ELSE '/'
  93.     END AS wbs_ref_number_level_3,
  94.     wbs.wbs_id,
  95.     parent_wbs_Id,
  96.     wbs.ref_number,
  97.     wbs.operation_center_id ,
  98.     wbs.can_assign_team,
  99.     LEVEL AS LVL
  100.   FROM wbs
  101.   WHERE LEVEL            <=3
  102.   AND operation_center_id = ? -- operation center of the WBS ex. PERRARD (101888)
  103.     START WITH wbs_id  = ? -- WBS we are looking at in WBS activity control page (HESPERANGE residence JOME with ID -> 221799)
  104.     CONNECT BY parent_wbs_id = PRIOR wbs_id
  105.   ORDER SIBLINGS BY ref_number
  106.   ) w
  107. ON 1 = 1
  108. WHERE ((? = 'true' --check box for display of MONTHLY sums ex. 'true'
  109. AND p.period  = 'M'
  110. AND (( ? = 'true' --check box for display of MONTHLY sums for level 1 ex. 'true'
  111. AND w.lvl     = 1 )
  112. OR ( ?  = 'true' --check box for display of MONTHLY sums for level 2 ex. 'true'
  113. AND w.lvl     = 2 )
  114. OR ( ?  = 'true' --check box for display of MONTHLY sums for level 3 ex. 'true'
  115. AND w.lvl     = 3 ) ) )
  116. OR ( ?   = 'true' --check box for display of WEEKLY sums ex. 'false'
  117. AND p.period  = 'W'
  118. AND ((? = 'true' --check box for display of WEEKLY sums for level 1 ex. 'false'
  119. AND w.lvl     = 1 )
  120. OR ( ?  = 'true' --check box for display of WEEKLY sums for level 2 ex. 'false'
  121. AND w.lvl     = 2 )
  122. OR ( ?   = 'true' --check box for display of WEEKLY sums for level 3 ex. 'false'
  123. AND w.lvl     = 3 ))))
  124. AND (? = 'true' OR p_wbs.sumHrDPerWBS(w.wbs_id, p.start_date, p.end_date) != 0) --check box for displaying of empty lines
  125. ORDER BY date_order, r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement