CREATE OR REPLACE TRIGGER "BEFORE_UPDATE_PACKINGNOTE"
  BEFORE UPDATE  ON PACKINGNOTE
  FOR EACH ROW


DECLARE
  v_statusid status.status_id%type;
  v_statusid_pknote status.status_id%type;
  v_statusid_inprogress status.status_id%type;
  
BEGIN

  select s.status_id
    into v_statusid
    from status s
   where s.code = 30
     and s.statustype = 'PN';
     
  select s.status_id
    into v_statusid_pknote
    from status s
   where s.code = 10
     and s.statustype = 'PN';

  select s.status_id
    into v_statusid_inprogress
    from status s
   where s.code = 20
     and s.statustype = 'PN';

  IF :NEW.STATUS_ID = v_statusid and (:OLD.STATUS_ID = v_statusid_pknote or :OLD.STATUS_ID = v_statusid_inprogress) THEN
    :NEW.PROCESSEDSYSTEMUSER_ID := :NEW.SYSTEMUSER_ID;
    :NEW.PROCESSEDTIMESTAMP := :NEW.TIMESTAMP;
  END IF;

END BEFORE_UPDATE_PACKINGNOTE;
/
