create or replace TRIGGER TRIG_COMPANY_GROUP_SYNC 
AFTER INSERT OR UPDATE
ON HRIS_COMPANY
FOR EACH ROW
DECLARE

BEGIN
IF INSERTING 
THEN

INSERT INTO hris_salary_sheet_group
( 
GROUP_ID,
GROUP_CODE,
GROUP_NAME
)
VALUES
( 
:new.COMPANY_ID,
:new.COMPANY_CODE,
:new.COMPANY_NAME
);
END IF;

IF UPDATING
THEN
if :new.status = 'D'
then 
DELETE FROM hris_salary_sheet_group WHERE GROUP_ID = :OLD.COMPANY_ID;
END IF;

UPDATE hris_salary_sheet_group SET GROUP_CODE = :new.COMPANY_CODE, GROUP_NAME = :new.COMPANY_NAME
WHERE GROUP_ID = :OLD.COMPANY_ID;
END IF;

END;