Advertisement
psi_mmobile

Untitled

Oct 30th, 2019
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 4.24 KB | None | 0 0
  1.   SELECT pd.person_id,
  2.   p.company_nr,
  3.   pd.date_day,
  4.   pd.trf_dhr,
  5.   wc.short_code,
  6.   pd.ref_number,
  7.   vpc.vo_person_category_id,
  8.   pdd.is_locked,
  9.   LPAD(TO_CHAR(p.company_nr), 6, '0') -- person number
  10.  
  11.   || TO_CHAR(pd.date_day, 'YYMMDD') -- date of the activity
  12.  
  13.   || RPAD  (wc.short_code,9, ' ') ||' +'    -- work code
  14.  
  15.   || LPAD(DECODE(wc.short_code,'P',SUM(pd.TRF_DHR) OVER (PARTITION BY pd.date_day,pd.person_id) * 100,pd.TRF_DHR * 100), 9, '0')  
  16.  
  17.   || LPAD('0', 9, '0') -- unit value (always 9 x 0) + percentage (always 5 x 0)
  18.  
  19.   || LPAD('0', 5,'0') -- percentage (always 5 x 0)
  20.  
  21.   || RPAD(' ', 10, ' ') -- cost center reference
  22.  
  23.   || LPAD(' ', 6, ' ') -- project reference
  24.  
  25.   || LPAD(' ', 5, ' ') -- activity reference
  26.  
  27.   || LPAD('51101', 5,'0') -- management State level 1
  28.  
  29.   || LPAD(NVL(pd.REF_NUMBER,'0'),5,'0') -- management State level 2
  30.  
  31.   || LPAD(' ', 5,'0') -- management State level 3
  32.  
  33.   || LPAD(' ', 1, ' ')  -- reason
  34.  
  35.   || LPAD(' ', 1, ' ')  -- empty character
  36.  
  37.   || LPAD(' ', 9, ' ') -- activity code 2
  38.  
  39.   || LPAD('0', 5, '0')
  40.  
  41.   || LPAD(DECODE(wc.work_code_std_category_id,1,NVL(pdd.declared_vehicle_km,0) + NVL(pdd.declared_private_km,0),'0'), 5, '0') -- KM values
  42.  
  43.   || LPAD(DECODE(wc.work_code_std_category_id,1,NVL(pdd.declared_vehicle_km,0),'0'), 5, '0') -- frais de deplacement KM value
  44.  
  45.   || LPAD(DECODE(wc.work_code_std_category_id,1,DECODE(pdd.day_journey_role,'D','23','13'),'0'), 2, '0') -- mobility code
  46.  
  47.   || LPAD(DECODE(wc.work_code_std_category_id,1,DECODE(NVL(pdd.declared_private_km,'0'),'0','73'),'0'), 2, '0')  -- frais de deplacement code
  48.  
  49.   || LPAD(' ', 5, ' ')
  50.   || LPAD(' ',10,' ')
  51.   str
  52. FROM pd_trf_day pd,
  53.   person p,
  54.   pd_day pdd,
  55.   work_code wc,
  56.   vo_person_category vpc
  57. WHERE pd.person_id                      = pdd.person_id
  58. AND pdd.person_id = p.person_id
  59. AND p.vo_person_category_id           = vpc.vo_person_category_id
  60. AND pd.work_code_id                     = wc.work_code_id
  61. AND p_util.to_num(wc.short_code)       IS NOT NULL
  62. AND pd.trf_dhr                         IS NOT NULL
  63. AND wc.work_code_std_type_id = 1
  64. UNION
  65. SELECT pd.person_id,
  66.   p.company_nr,
  67.   pd.date_day,
  68.   pd.trf_dhr,
  69.   wc.short_code,
  70.   pd.ref_number,
  71.   vpc.vo_person_category_id,
  72.   pdd.is_locked,
  73.   LPAD(TO_CHAR(p.company_nr), 6, '0') -- person number
  74.  
  75.   || TO_CHAR(pd.date_day, 'YYMMDD') -- date of the activity
  76.  
  77.   || RPAD  (wc.short_code,9, ' ') ||' +'    -- work code
  78.  
  79.   || LPAD(NVL (7.5 * 100, 0), 9, '0')  
  80.  
  81.   || LPAD('0', 9, '0') -- unit value (always 9 x 0) + percentage (always 5 x 0)
  82.  
  83.   || LPAD('0', 5,'0') -- percentage (always 5 x 0)
  84.  
  85.   || RPAD(' ', 10, ' ') -- cost center reference
  86.  
  87.   || LPAD(' ', 6, ' ') -- project reference
  88.  
  89.   || LPAD(' ', 5, ' ') -- activity reference
  90.  
  91.   || LPAD('51101', 5,'0') -- management State level 1
  92.  
  93.   || LPAD(NVL(pd.REF_NUMBER,'0'),5,'0') -- management State level 2
  94.  
  95.   || LPAD(' ', 5,'0') -- management State level 3
  96.  
  97.   || LPAD(' ', 1, ' ')  -- reason
  98.  
  99.   || LPAD(' ', 1, ' ')  -- empty character
  100.  
  101.   || LPAD(' ', 9, ' ') -- activity code 2
  102.  
  103.   || LPAD('0', 5, '0')
  104.  
  105.   || LPAD(DECODE(wc.work_code_std_category_id,1,NVL(pdd.declared_vehicle_km,0) + NVL(pdd.declared_private_km,0),'0'), 5, '0') -- KM values
  106.  
  107.   || LPAD(DECODE(wc.work_code_std_category_id,1,NVL(pdd.declared_vehicle_km,0),'0'), 5, '0') -- frais de deplacement KM value
  108.  
  109.   || LPAD(DECODE(wc.work_code_std_category_id,1,DECODE(pdd.day_journey_role,'D','23','13'),'0'), 2, '0') -- mobility code
  110.  
  111.   || LPAD(DECODE(wc.work_code_std_category_id,1,DECODE(NVL(pdd.declared_private_km,'0'),'0','73'),'0'), 2, '0')  -- frais de deplacement code
  112.  
  113.   || LPAD(' ', 5, ' ')
  114.   || LPAD(' ',10,' ')
  115.   str
  116. FROM pd_trf_day pd,
  117.   person p,
  118.   pd_day pdd,
  119.   work_code wc,
  120.   vo_person_category vpc
  121. WHERE pd.person_id                      = pdd.person_id
  122. AND pdd.person_id = p.person_id
  123. AND p.vo_person_category_id           = vpc.vo_person_category_id
  124. AND pd.work_code_id                     = wc.work_code_id
  125. AND p_util.to_num(wc.short_code)       IS NOT NULL
  126. AND pd.trf_dhr                         IS NOT NULL
  127. AND NVL(pdd.maintenance,'N') = 'Y'
  128. AND wc.short_code = '441'
  129. AND wc.work_code_std_type_id = 1
  130. ORDER BY 1,3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement