Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH ptd AS (
- SELECT pd.person_id,
- pd.date_day,
- pd.is_locked,
- pd.work_code_id,
- pd.REF_NUMBER,
- SUM(pd.TRF_DHR) SUM
- FROM pd_trf_day pd
- WHERE pd.trf_dhr IS NOT NULL
- AND pd.trf_dhr != 0
- AND pd.date_day BETWEEN SYSDATE - 1 AND SYSDATE
- GROUP BY pd.person_id,
- pd.date_day,
- pd.is_locked,
- pd.work_code_id,
- pd.person_id,
- pd.REF_NUMBER
- )
- SELECT
- z.person_id,
- z.date_day,
- p.vo_person_category_id,
- z.is_locked,
- LPAD(NVL(p.company_nr,'0'), 6, '0') -- person number
- || TO_CHAR(z.date_day, 'YYMMDD') -- date of the activity
- || RPAD (wc.short_code,9, ' ') ||' +' -- work code
- || LPAD(z.SUM * 100, 9, '0')
- || LPAD('0', 9, '0') -- unit value (always 9 x 0) + percentage (always 5 x 0)
- || LPAD(NVL(wc.COST_PER_HOUR_COEFICIENT, 0)*10000, 5, '0') -- percentage (always 5 x 0)
- || RPAD(' ', 10, ' ') -- cost center reference
- || LPAD(' ', 6, ' ') -- project reference
- || LPAD(' ', 5, ' ') -- activity reference
- || LPAD('51101', 5,'0') -- management State level 1
- || LPAD(NVL(regexp_replace(z.REF_NUMBER, '[A-Za-z]', ''),'0'),5,'0') -- management State level 2
- || LPAD('0', 5,'0') -- management State level 3
- || LPAD(' ', 1, ' ') -- reason
- || LPAD(' ', 1, ' ') -- empty character
- || LPAD(' ', 9, ' ') -- activity code 2
- || LPAD(DECODE(ROW_NUMBER() OVER (PARTITION BY pdd.pd_day_id ORDER BY wc.work_code_std_category_id ASC, z.date_day, z.person_id), 1,
- DECODE(wc.work_code_std_category_id,1,NVL(pdd.declared_vehicle_km,0) + NVL(pdd.declared_private_km,0), '0'),
- '0'), 5, '0') -- KM values
- || LPAD(DECODE(ROW_NUMBER() OVER (PARTITION BY pdd.pd_day_id ORDER BY wc.work_code_std_category_id ASC, z.date_day, z.person_id), 1,
- DECODE(wc.work_code_std_category_id,1,NVL(pdd.DECLARED_PRIVATE_KM,0), '0'),
- '0'), 5, '0') -- frais de deplacement KM value
- || LPAD(DECODE(ROW_NUMBER() OVER (PARTITION BY pdd.pd_day_id ORDER BY wc.work_code_std_category_id ASC, z.date_day, z.person_id), 1,
- DECODE(wc.work_code_std_category_id,1, DECODE(pdd.day_journey_role,'DA','43', 'D ', '23','13'), '0'),
- '0'), 2, '0') -- mobility code
- || LPAD(DECODE(ROW_NUMBER() OVER (PARTITION BY pdd.pd_day_id ORDER BY wc.work_code_std_category_id ASC, z.date_day, z.person_id), 1,
- DECODE(wc.work_code_std_category_id,1, NVL2(NULLIF (pdd.declared_private_km, 0),'73','0'), '0'),
- '0'), 2, '0') -- frais de deplacement code
- || LPAD(' ', 5, ' ')
- || LPAD(' ',10,' ') str
- FROM ptd z,
- person p,
- pd_day pdd,
- work_code wc
- WHERE z.person_id = p.person_id
- AND z.date_day = pdd.date_day
- AND z.person_id = pdd.person_id
- AND z.work_code_id = wc.work_code_id
- AND wc.work_code_std_type_id = 1
- UNION ALL
- SELECT pd.person_id,
- pd.date_day,
- p.vo_person_category_id,
- pd.is_locked,
- LPAD(NVL(p.company_nr,'0'), 6, '0') -- person number
- || TO_CHAR(pd.date_day, 'YYMMDD') -- date of the activity
- || RPAD ('441',9, ' ') ||' +' -- work code
- || LPAD(NVL (7.5 * 100, 0), 9, '0')
- || LPAD('0', 9, '0') -- unit value (always 9 x 0) + percentage (always 5 x 0)
- || LPAD('0', 5,'0') -- percentage (always 5 x 0)
- || RPAD(' ', 10, ' ') -- cost center reference
- || LPAD(' ', 6, ' ') -- project reference
- || LPAD(' ', 5, ' ') -- activity reference
- || LPAD('51101', 5,'0') -- management State level 1
- || LPAD(NVL(regexp_replace(pd.REF_NUMBER, '[A-Za-z]', ''),'0'),5,'0') -- management State level 2
- || LPAD('0', 5,'0') -- management State level 3
- || LPAD(' ', 1, ' ') -- reason
- || LPAD(' ', 1, ' ') -- empty character
- || LPAD(' ', 9, ' ') -- activity code 2
- || LPAD('0', 5, '0') -- KM values
- || LPAD('0', 5, '0') -- frais de deplacement KM value
- || LPAD('0', 2, '0') -- mobility code
- || LPAD('0', 2, '0') -- frais de deplacement code
- || LPAD(' ', 5, ' ')
- || LPAD(' ',10,' ') str
- FROM ptd pd,
- person p,
- pd_day pdd,
- work_code wc
- WHERE pd.person_id = pdd.person_id
- AND pd.date_day = pdd.date_day
- AND pdd.person_id = p.person_id
- AND pd.work_code_id = wc.work_code_id
- AND NVL(pdd.maintenance,'N') = 'Y'
- AND wc.work_code_std_type_id = 1
- UNION ALL
- SELECT pd.person_id,
- pd.date_day,
- p.vo_person_category_id,
- pd.is_locked,
- LPAD(NVL(p.company_nr,'0'), 6, '0') -- person number
- || TO_CHAR(pd.date_day, 'YYMMDD') -- date of the activity
- || RPAD ('438',9, ' ') ||' +' -- work code
- || LPAD(NVL (0.5 * 100, 0), 9, '0') --activity value
- || LPAD('0', 9, '0') -- unit value (always 9 x 0) + percentage (always 5 x 0)
- || LPAD('0', 5,'0') -- percentage (always 5 x 0)
- || RPAD(' ', 10, ' ') -- cost center reference
- || LPAD(' ', 6, ' ') -- project reference
- || LPAD(' ', 5, ' ') -- activity reference
- || LPAD('51101', 5,'0') -- management State level 1
- || LPAD(NVL(regexp_replace(pd.REF_NUMBER, '[A-Za-z]', ''),'0'),5,'0') -- management State level 2
- || LPAD('0', 5,'0') -- management State level 3
- || LPAD(' ', 1, ' ') -- reason
- || LPAD(' ', 1, ' ') -- empty character
- || LPAD(' ', 9, ' ') -- activity code 2
- || LPAD('0', 5, '0') -- KM values
- || LPAD('0', 5, '0') -- frais de deplacement KM value
- || LPAD('0', 2, '0') -- mobility code
- || LPAD('0', 2, '0') -- frais de deplacement code
- || LPAD(' ', 5, ' ')
- || LPAD(' ',10,' ') str
- FROM pd_trf_day pd,
- person p,
- pd_day pdd,
- work_code wc,
- wbs w
- WHERE pd.person_id = pdd.person_id
- AND pd.date_day = pdd.date_day
- AND pdd.person_id = p.person_id
- AND pd.work_code_id = wc.work_code_id
- AND ('N' = (SELECT LAUNDRY_IS_NEVER_PAID FROM WBS WHERE WBS_ID =P_WBS.getlvl0WbsID(pd.wbs_id)) OR (SELECT LAUNDRY_IS_NEVER_PAID FROM WBS WHERE WBS_ID =P_WBS.getlvl0WbsID(pd.wbs_id)) IS NULL)
- AND wc.work_code_std_type_id = 1
- UNION ALL
- SELECT pd.person_id,
- pd.date_day,
- p.vo_person_category_id,
- pd.is_locked,
- LPAD(NVL(p.company_nr,'0'), 6, '0') -- person number
- || TO_CHAR(pd.date_day, 'YYMMDD') -- date of the activity
- || RPAD ('440',9, ' ') ||' +' -- work code
- || LPAD(NVL (p.transport_allowance * 100, 0), 9, '0') --activity value
- || LPAD('0', 9, '0') -- unit value (always 9 x 0) + percentage (always 5 x 0)
- || LPAD('0', 5,'0') -- percentage (always 5 x 0)
- || RPAD(' ', 10, ' ') -- cost center reference
- || LPAD(' ', 6, ' ') -- project reference
- || LPAD(' ', 5, ' ') -- activity reference
- || LPAD('51101', 5,'0') -- management State level 1
- || LPAD(NVL(regexp_replace(pd.REF_NUMBER, '[A-Za-z]', ''),'0'),5,'0') -- management State level 2
- || LPAD('0', 5,'0') -- management State level 3
- || LPAD(' ', 1, ' ') -- reason
- || LPAD(' ', 1, ' ') -- empty character
- || LPAD(' ', 9, ' ') -- activity code 2
- || LPAD('0', 5, '0') -- KM values
- || LPAD('0', 5, '0') -- frais de deplacement KM value
- || LPAD('0', 2, '0') -- mobility code
- || LPAD('0', 2, '0') -- frais de deplacement code
- || LPAD(' ', 5, ' ')
- || LPAD(' ',10,' ') str
- FROM pd_trf_day pd,
- person p,
- pd_day pdd,
- work_code wc,
- wbs w
- WHERE pd.person_id = pdd.person_id
- AND pd.date_day = pdd.date_day
- AND pdd.person_id = p.person_id
- AND pd.work_code_id = wc.work_code_id
- AND NVL(pdd.public_transport,'N') = 'Y'
- AND wc.work_code_std_type_id = 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement