CREATE OR REPLACE PROCEDURE HRIS_ATTENDANCE_INSERT(
    P_THUMB_ID        NUMBER,
    P_ATTENDANCE_DT   DATE,
    P_IP_ADDRESS      VARCHAR2,
    P_ATTENDANCE_FROM VARCHAR2,
    P_ATTENDANCE_TIME TIMESTAMP,
    P_REMARKS         VARCHAR2:=NULL)
AS
  V_EMPLOYEE_ID NUMBER                          :=NULL;
  V_PURPOSE HRIS_ATTD_DEVICE_MASTER.PURPOSE%TYPE:='I/0';
BEGIN
  BEGIN
    SELECT PURPOSE
    INTO V_PURPOSE
    FROM HRIS_ATTD_DEVICE_MASTER
    WHERE DEVICE_IP=P_IP_ADDRESS;
  EXCEPTION
  WHEN no_data_found THEN
    NULL;
  END;
  BEGIN
    SELECT EMPLOYEE_ID
    INTO V_EMPLOYEE_ID
    FROM HRIS_EMPLOYEES
    WHERE ID_THUMB_ID=P_THUMB_ID;
  EXCEPTION
  WHEN NO_DATA_FOUND THEN
    NULL;
  WHEN too_many_rows THEN
    NULL;
  END;
  INSERT
  INTO HRIS_ATTENDANCE
    (
      EMPLOYEE_ID,
      ATTENDANCE_DT,
      IP_ADDRESS,
      ATTENDANCE_FROM,
      ATTENDANCE_TIME,
      THUMB_ID
    )
    VALUES
    (
      V_EMPLOYEE_ID ,
      P_ATTENDANCE_DT,
      P_IP_ADDRESS,
      P_ATTENDANCE_FROM,
      P_ATTENDANCE_TIME,
      P_THUMB_ID
    );
  BEGIN
    IF V_EMPLOYEE_ID IS NOT NULL THEN
      HRIS_ATTENDANCE_AFTER_INSERT(V_EMPLOYEE_ID,P_ATTENDANCE_DT,P_ATTENDANCE_TIME,P_REMARKS);
    END IF;
  END;
EXCEPTION
WHEN OTHERS THEN
  DBMS_OUTPUT.PUT_LINE('THUMB_ID: '||P_THUMB_ID||'ATTENDANCE_DT:'||P_ATTENDANCE_DT||'IP_ADDRESS: '||P_IP_ADDRESS||'P_ATTENDANCE_FROM: '||P_ATTENDANCE_FROM);
END;