Friday, September 5, 2014

HRMS API: Create Person Absence

CREATE OR REPLACE PROCEDURE apps.xx_insert_summer_leave (
   err_buf                        OUT      VARCHAR2,
   retcode                        OUT      VARCHAR2,
   p_payroll_id                   IN       NUMBER,

  
   p_people_group_type_code       IN       VARCHAR2,
   p_person_id                    IN       NUMBER,
   p_absence_attendance_type_id   IN       NUMBER,
   p_start_date                   IN       VARCHAR2,
   p_end_date                     IN       VARCHAR2
)
AS
   v_start_date                  DATE;
   v_end_date                    DATE;
   v_person_type_name            VARCHAR2 (500);
---------------------- API Out Parameters -------------
   p_absence_days                NUMBER;
   p_absence_hours               NUMBER;
   p_absence_attendance_id       NUMBER;
   p_object_version_number       NUMBER;
   p_occurrence                  NUMBER;
   p_dur_dys_less_warning        BOOLEAN;
   p_dur_hrs_less_warning        BOOLEAN;
   p_exceeds_pto_entit_warning   BOOLEAN;
   p_exceeds_run_total_warning   BOOLEAN;
   p_abs_overlap_warning         BOOLEAN;
   p_abs_day_after_warning       BOOLEAN;
   p_dur_overwritten_warning     BOOLEAN;
BEGIN
   v_start_date := TRIM (TO_DATE (p_start_date, 'RRRR/MM/DD HH24:MI:SS'));
   v_end_date := TRIM (TO_DATE (p_end_date, 'RRRR/MM/DD HH24:MI:SS'));
-------------------------------------------------
   FOR i IN (SELECT DISTINCT pap.person_id, paa.assignment_id,
                             paa.business_group_id
                        FROM per_all_people_f pap,
                             per_all_assignments_f paa,
                             pay_people_groups ppg
                       WHERE pap.effective_end_date =
                                          TO_DATE ('12/31/4712', 'MM/DD/RRRR')
                         AND pap.person_id = paa.person_id
                         AND paa.effective_end_date =
                                          TO_DATE ('12/31/4712', 'MM/DD/RRRR')
                         AND paa.people_group_id = ppg.people_group_id
--------------------------------------------------
                         AND (   paa.payroll_id = p_payroll_id
                              OR p_payroll_id IS NULL
                             )
                         AND (   paa.person_id = p_person_id
                              OR p_person_id IS NULL
                             )
                         AND (   ppg.segment2 = p_people_group_type_code
                              OR p_people_group_type_code IS NULL
                             ))
   LOOP
      BEGIN
         SELECT ppt.user_person_type
           INTO v_person_type_name
           FROM per_person_type_usages_f pptu, per_person_types ppt
          WHERE pptu.person_type_id = ppt.person_type_id
            AND pptu.effective_end_date = TO_DATE ('12/31/4712', 'MM/DD/RRRR')
            AND pptu.person_id = i.person_id;
         IF v_person_type_name = 'Contractor Employee'
         THEN
            BEGIN
               hr_person_absence_api.create_person_absence
                  (p_effective_date                    => TRIM (SYSDATE),
                   p_person_id                         => i.person_id,
                   p_business_group_id                 => i.business_group_id,
                   p_absence_attendance_type_id        => p_absence_attendance_type_id,
                   p_date_notification                 => ADD_MONTHS
                                                                (v_start_date,
                                                                 -1
                                                                ),
                   p_date_projected_start              => v_start_date,
                   p_date_projected_end                => v_end_date,
                   p_date_start                        => v_start_date,
                   p_date_end                          => v_end_date,
                   p_absence_days                      => p_absence_days,
                   p_absence_hours                     => p_absence_hours,
                   p_attribute1                        => 'Y',
                   p_ssp1_issued                       => 'N',
                   p_pregnancy_related_illness         => 'N',
                   p_accept_late_notification_fla      => 'N',
                   p_absence_attendance_id             => p_absence_attendance_id,
                   p_object_version_number             => p_object_version_number,
                   p_occurrence                        => p_occurrence,
                   p_dur_dys_less_warning              => p_dur_dys_less_warning,
                   p_dur_hrs_less_warning              => p_dur_hrs_less_warning,
                   p_exceeds_pto_entit_warning         => p_exceeds_pto_entit_warning,
                   p_exceeds_run_total_warning         => p_exceeds_run_total_warning,
                   p_abs_overlap_warning               => p_abs_overlap_warning,
                   p_abs_day_after_warning             => p_abs_day_after_warning,
                   p_dur_overwritten_warning           => p_dur_overwritten_warning
                  );
            EXCEPTION
               WHEN OTHERS
               THEN
                  p_absence_days := NULL;
                  p_absence_hours := NULL;
                  p_absence_attendance_id := NULL;
                  p_object_version_number := NULL;
                  p_occurrence := NULL;
                  p_dur_dys_less_warning := NULL;
                  p_dur_hrs_less_warning := NULL;
                  p_exceeds_pto_entit_warning := NULL;
                  p_exceeds_run_total_warning := NULL;
                  p_abs_overlap_warning := NULL;
                  p_abs_day_after_warning := NULL;
                  p_dur_overwritten_warning := NULL;
            END;
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            v_person_type_name := NULL;
      END;
   END LOOP;
   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;