"localhost:/firebird/data/ILICHEVSK2.FDB". Триггеры Previous topic Chapter index Next topic

UWORDERS_ClearActInIT

 

Описание

(Нет описания для триггера UWORDERS_ClearActInIT)

 

Определение

CREATE TRIGGER "UWORDERS_ClearActInIT" FOR UWORDERS
ACTIVE AFTER UPDATE POSITION 0
as
declare WRITING_OFF integer;

begin
  select UWTYPES.WRITING_OFF
    from UWTYPES
    where (UWTYPES.UWTYPEID = old.UWTYPEID)
  into WRITING_OFF;
  
  if ((old.STATE <> -1) and (new.STATE = -1)) then begin
    delete from IT
      where (IT.OPERATIONID in (4,9)) and (IT.UWORDERID = new.UWORDERID) and (IT.STATE = -999);

    if (WRITING_OFF = 1) then begin
      update IT
        set IT.STATE = -1
      where (IT.UWORDERID = new.UWORDERID) and (IT.OPERATIONID in (4,22)) and (old.UWTYPEID = 3);

      if (new.UWTYPEID = 2) then
        update IT
          set IT.STATE = -1
        where (IT.UWORDERID = new.UWORDERID) and (IT.OPERATIONID = 9);
    end

    if (new.UWTYPEID in (90,91)) then begin
      if (new.UWTYPEID = 90) then
        update IT
          set IT.SUWORDERID = null
        where (IT.SUWORDERID = new.UWORDERID) and (not (IT.OPERATIONID in (9,22)));
      else
        if (new.UWTYPEID = 91) then
          update IT
            set IT.RELATIONID = null
          where (IT.RELATIONID = new.UWORDERID) and (not (IT.OPERATIONID in (9,22)));

      update IT
        set IT.UWORDERID = null
      where (IT.UWORDERID = new.UWORDERID) and (IT.OPERATIONID = 5);
    end
    else
      update IT
        set IT.UWORDERID = null
      where (IT.UWORDERID = new.UWORDERID) and (not (IT.OPERATIONID in (9,22)));
  end
end

 

     Previous topic Chapter index Next topic