CREATE OR REPLACE TRIGGER HRIS_AFTER_LEAVE_DEDUCTION
AFTER INSERT OR UPDATE OR DELETE ON HRIS_EMPLOYEE_LEAVE_DEDUCTION

FOR EACH ROW

BEGIN
    IF
        INSERTING
    THEN
        INSERT INTO HRIS_EMPLOYEE_PENALTY_DAYS (EMPLOYEE_ID, ATTENDANCE_DT, LEAVE_ID, NO_OF_DAYS, REMARKS, CREATED_DATE, LD_ID)
        values (:new.employee_id, :new.DEDUCTION_DT, :new.LEAVE_ID, :new.NO_OF_DAYS, :new.REMARKS, :new.CREATED_DT, :new.ID);

    END IF;

    IF
        DELETING
    THEN
        DELETE FROM HRIS_EMPLOYEE_PENALTY_DAYS WHERE LD_ID = :old.ID;

    END IF;
    
    IF
        UPDATING
    THEN
        IF :new.status not in ('AP')
        THEN
        DELETE FROM HRIS_EMPLOYEE_PENALTY_DAYS WHERE LD_ID = :old.ID;
    END IF;
    END IF;

END;
