create or replace TRIGGER HRIS_CONTRACT_EMP_UPDATE
AFTER INSERT OR UPDATE OR DELETE 
   ON HRIS_CONTRACT_EMP_ASSIGN
    FOR EACH ROW
  BEGIN

  IF INSERTING  THEN



  DBMS_OUTPUT.PUT_LINE ('No Admin is defined!!!' );

  END IF;


   IF UPDATING THEN
   BEGIN

   IF(:new.STATUS='D') THEN

  DELETE FROM  HRIS_CONTRACT_EMP_ATTENDANCE
  WHERE  EMPLOYEE_ID      = :old.EMPLOYEE_ID 
  AND CUSTOMER_ID      = :old.CUSTOMER_ID 
  AND CONTRACT_ID      = :old.CONTRACT_ID 
  AND LOCATION_ID      = :old.LOCATION_ID 
  AND DUTY_TYPE_ID      = :old.DUTY_TYPE_ID
  AND EMP_ASSIGN_ID = :old.EMP_ASSIGN_ID
  AND ATTENDANCE_DATE BETWEEN :old.START_DATE AND :old.END_DATE;

   ELSE
    UPDATE   HRIS_CONTRACT_EMP_ATTENDANCE
     SET 
     EMPLOYEE_ID      = :new.EMPLOYEE_ID,
     CUSTOMER_ID      = :new.CUSTOMER_ID,
     CONTRACT_ID      = :new.CONTRACT_ID,
     LOCATION_ID      = :new.LOCATION_ID,
     DUTY_TYPE_ID      = :new.DUTY_TYPE_ID,
     EMP_ASSIGN_ID     = :new.EMP_ASSIGN_ID
  WHERE  EMPLOYEE_ID      = :old.EMPLOYEE_ID 
  AND CUSTOMER_ID      = :old.CUSTOMER_ID 
  AND CONTRACT_ID      = :old.CONTRACT_ID 
  AND LOCATION_ID      = :old.LOCATION_ID 
  AND DUTY_TYPE_ID     = :old.DUTY_TYPE_ID
  AND EMP_ASSIGN_ID    = :old.EMP_ASSIGN_ID
  AND ATTENDANCE_DATE BETWEEN :new.START_DATE AND :new.END_DATE;

   END IF;


   END;
   END IF;


   IF DELETING THEN


  DELETE FROM  HRIS_CONTRACT_EMP_ATTENDANCE
  WHERE  EMPLOYEE_ID      = :old.EMPLOYEE_ID 
  AND CUSTOMER_ID      = :old.CUSTOMER_ID 
  AND CONTRACT_ID      = :old.CONTRACT_ID 
  AND LOCATION_ID      = :old.LOCATION_ID 
  AND DUTY_TYPE_ID      = :old.DUTY_TYPE_ID
  AND EMP_ASSIGN_ID    = :old.EMP_ASSIGN_ID
  AND ATTENDANCE_DATE BETWEEN :old.START_DATE AND :old.END_DATE;

   END IF;



  END;