CREATE OR REPLACE PROCEDURE HRIS_QUEUE_REATTENDANCE(
    P_FROM_ATTENDANCE_DT HRIS_ATTENDANCE.ATTENDANCE_DT%TYPE,
    P_EMPLOYEE_ID HRIS_ATTENDANCE.EMPLOYEE_ID%TYPE:=NULL,
    P_TO_ATTENDANCE_DT DATE                       :=NULL )
AS
  V_WHAT HRIS_JOBS.WHAT%TYPE;
BEGIN
  IF P_EMPLOYEE_ID    IS NULL AND P_TO_ATTENDANCE_DT IS NOT NULL THEN
    V_WHAT            :='HRIS_REATTENDANCE(''' ||P_FROM_ATTENDANCE_DT ||''',NULL,''' || P_TO_ATTENDANCE_DT||''');';
  ELSIF P_EMPLOYEE_ID IS NULL AND P_TO_ATTENDANCE_DT IS NULL THEN
    V_WHAT            :='HRIS_REATTENDANCE(''' ||P_FROM_ATTENDANCE_DT ||''');';
  ELSIF P_EMPLOYEE_ID IS NOT NULL AND P_TO_ATTENDANCE_DT IS NULL THEN
    V_WHAT            :='HRIS_REATTENDANCE(''' ||P_FROM_ATTENDANCE_DT ||''',' ||P_EMPLOYEE_ID ||');';
  ELSIF P_EMPLOYEE_ID IS NOT NULL AND P_TO_ATTENDANCE_DT IS NOT NULL THEN
    V_WHAT            :='HRIS_REATTENDANCE(''' ||P_FROM_ATTENDANCE_DT ||''','||P_EMPLOYEE_ID||',''' || P_TO_ATTENDANCE_DT||''');';
  END IF;
  INSERT
  INTO HRIS_JOBS
    (
      JOB_ID,
      WHAT
    )
    VALUES
    (
      (SELECT NVL(MAX(JOB_ID),0)+1 FROM HRIS_JOBS
      )
      ,
      'BEGIN '
      || V_WHAT
      || ' END;'
    );
END;