Advertisement
psi_mmobile

Untitled

Mar 17th, 2021
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 3.70 KB | None | 0 0
  1. CREATE OR REPLACE FORCE EDITIONABLE VIEW "OF_OWNER"."V_EXPORT_EBLOX_HOOYBERGHS" ("PERSON_ID", "VO_PERSON_CATEGORY_ID", "IS_LOCKED", "DATE_DAY", "Nummer werkgever", "Nummer werknemer", "Naam werkgever", "Naam werknemer", "Looncode", "Werf", "Datum", "Uren", "Minuten","Commentaar", "Gerapporteerde Km", "Prive Km","SHORT_CODE") AS
  2. WITH hr AS
  3.   (SELECT pd.person_id,
  4.     pd.date_day,
  5.     pd.is_locked,
  6.     DECODE(wc.short_code,'P',DECODE(pdd.day_journey_role,'P','P','D ','CH','DA','CH','P'),wc.short_code) AS looncode,
  7.     wc.short_code,
  8.     wc.work_code_std_category_id,
  9.     pd.wbs_id,
  10.     SUM(pd.TRF_DHR) declared_hr_sum,
  11.     listagg (pd.user_comment, '; ' ) user_comment
  12.   FROM pd_trf_day pd,
  13.     pd_day pdd,
  14.     work_code wc
  15.   WHERE pd.person_id                = pdd.person_id
  16.   AND pd.date_day                   = pdd.date_day
  17.   AND pd.work_code_id               = wc.work_code_id
  18.   AND wc.work_code_std_category_id IN (1,2)
  19.   AND NVL(pd.TRF_DHR,0)             > 0
  20.   AND wc.vehicle_owner_id           = 101404
  21.   GROUP BY pd.person_id,
  22.     pd.date_day,
  23.     pd.is_locked,
  24.     DECODE(wc.short_code,'P',DECODE(pdd.day_journey_role,'P','P','D ','CH','DA','CH','P'),wc.short_code),
  25.     wc.short_code,
  26.     wc.work_code_std_category_id,
  27.     pd.wbs_id
  28.   )
  29. SELECT hr.person_id,
  30.   p.vo_person_category_id,
  31.   hr.is_locked,
  32.   hr.date_day,
  33.   vo.contact_msisdn                        AS "Nummer werkgever",
  34.   LTRIM(REPLACE(p.company_nr,'HBB'),'0') AS "Nummer werknemer",
  35.   vo.company_name                          AS "Naam werkgever",
  36.   p.last_name
  37.   || ' '
  38.   || p.first_name                                                                                  AS "Naam werknemer",
  39.   hr.looncode                                                                                      AS "Looncode",
  40.   DECODE(hr.work_code_std_category_id,1,p_wbs.getlvl0WbsRefNumber(hr.wbs_id),2,'AFWEZIG')          AS "Werf",
  41.   TO_CHAR ( pd.date_day, 'dd/MM/yyyy' )                                                            AS "Datum",
  42.   REPLACE(TO_CHAR(EXTRACT (HOUR FROM NUMTODSINTERVAL(hr.declared_hr_sum, 'HOUR' )),'00'),' ','')   AS "Uren",
  43.   REPLACE(TO_CHAR(EXTRACT (MINUTE FROM NUMTODSINTERVAL(hr.declared_hr_sum, 'HOUR' )),'00'),' ','') AS "Minuten",
  44.   hr.user_comment                                                                                  AS "Commentaar",
  45.   CASE
  46.     WHEN (short_code                                                                                                                          = 'P'
  47.     OR short_code                                                                                                                             = 'GWH')
  48.     AND (ROW_NUMBER() over (PARTITION BY hr.person_id, hr.date_day ORDER BY DECODE (hr.short_code, 'P', 1, 'GWH', 2, 3), hr.declared_hr_sum ) = 1 )
  49.     THEN NVL(pd.declared_vehicle_km,0)
  50.     ELSE 0
  51.   END AS "Gerapporteerde Km",
  52.   CASE
  53.     WHEN (short_code                                                                                                                         = 'P'
  54.     OR short_code                                                                                                                            = 'GWH')
  55.     AND (ROW_NUMBER() over (PARTITION BY hr.person_id, hr.date_day ORDER BY DECODE (hr.short_code, 'P', 1, 'GWH', 2, 3), hr.declared_hr_sum )= 1)
  56.     THEN NVL(pd.declared_private_km,0)
  57.     ELSE 0
  58.   END "Prive Km",
  59.   hr.short_code
  60. FROM hr,
  61.   pd_day pd,
  62.   person p,
  63.   vo_person_category vpc,
  64.   vehicle_owner vo
  65. WHERE hr.date_day           = pd.date_day
  66. AND hr.person_id            = pd.person_id
  67. AND p.person_id             = pd.person_id
  68. AND p.vo_person_category_id = vpc.vo_person_category_id
  69. AND vpc.vehicle_owner_id    =vo.vehicle_owner_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement