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

INVOICES_COPYSTORAGEMOVE

 

Описание

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

 

Определение

CREATE TRIGGER INVOICES_COPYSTORAGEMOVE FOR INVOICES
ACTIVE AFTER UPDATE POSITION 0
as
declare variable INVENTORYID integer;
declare variable OPERATIONID integer;
declare variable TARGETSTORAGEID integer;
declare variable PROVIDERSTORAGECLIENTID integer;
declare variable COPYINVOICEID integer;
declare variable STATE integer;

begin
  select CLIENTS.STORAGEID
    from CLIENTS
    where (CLIENTS.CLIENTID = new.SENDERID)
  into :TARGETSTORAGEID;

  if (TARGETSTORAGEID is null) then
    exit;

  select first 1 IT.INVENTORYID, IT.OPERATIONID, IT.STATE, CLIENTS.CLIENTID
    from IT
    left join CLIENTS on (CLIENTS.STORAGEID = IT.STORAGEID)
    where (IT.INVOICEID = new.INVOICEID)
  into :INVENTORYID, :OPERATIONID, :STATE, :PROVIDERSTORAGECLIENTID;

  if ((STATE = 200) or (OPERATIONID not in (1,5))) then
    exit;

  COPYINVOICEID = null;

  select first 1 IT.INVOICEID
    from IT
    where (IT.PARENTID = :INVENTORYID)
  into :COPYINVOICEID;

  if (COPYINVOICEID is null) then begin
--  Вставка делается тригерром в IT
  end
  else begin
    update INVOICES
    set INVOICENUMBER = new.INVOICENUMBER,
        INVOICEDATE = new.INVOICEDATE,
        STATIONID = new.STATIONID,
--      REGISTERID = new.REGISTERID,
--      SENDERID = new.SENDERID,
        SENDERID = :PROVIDERSTORAGECLIENTID,
        DRIVERS = new.DRIVERS
    where (INVOICEID = :COPYINVOICEID);
  end
end

 

     Previous topic Chapter index Next topic