andrebertoletti
9/19/2017 - 1:26 PM

Workflow

Workflow Systur

insert into systur.wfs_modulo (cd_modulo,ds_modulo,ds_icone,ds_cor,ds_tabela,ds_campo,ds_proc_request,ds_proc_view) values (1,'Marketing','wallpaper','#005E00','MKT_SOLICITACAO','CD_SOLICITACAO','pkg_mkt_solicitacao.prc_tl_inicial','pkg_mkt_solicitacao.prc_tl_export');
insert into systur.wfs_modulo (cd_modulo,ds_modulo,ds_icone,ds_cor,ds_tabela,ds_campo,ds_proc_request,ds_proc_view) values (2,'Fornecedor','public','#b85d04','FNC_SOLICITACAO','CD_SOLICITACAO','pkg_fnc_solicitacao.prc_tl_inicial','pkg_fnc_solicitacao.prc_tl_view');

insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (1,'Solicitação',1,1,'pkg_mkt_solicitacao.prc_tl_inicial'); 
insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (2,'Análise Marketing',1,2,'pkg_mkt_solicitacao.prc_tl_export');
insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (3,'Anexar Nota Fiscal',1,3,'pkg_mkt_solicitacao.prc_tl_export'); 
insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (4,'Gerar SP',1,4,'pkg_mkt_solicitacao.prc_tl_export');
insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (5,'Revisar/Finalizar',1,5,'pkg_mkt_solicitacao.prc_tl_export');
insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (6,'Solicitação',2,1,'pkg_fnc_solicitacao.prc_tl_inicial');
insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (7,'Cadastro Fornecedor',2,2,'pkg_fnc_solicitacao.prc_tl_view');
insert into systur.wfs_fase (cd_fase, ds_fase, cd_modulo, sq_fase, ds_procedure ) values (8,'Anexar Arte',1,3,'pkg_mkt_solicitacao.prc_tl_export');

insert into systur.wfs_fase_pendencia (cd_fase,id_pendencia,ds_pendencia,ds_procedure) values (2,'VFRN','Verificar Fornecedor','pkg_mkt_workflow.prc_wf_fornecedor');
insert into systur.wfs_fase_pendencia (cd_fase,id_pendencia,ds_pendencia,ds_procedure) values (3,'ATNF','Anexar Nota Fiscal','pkg_mkt_workflow.prc_wf_danf');
insert into systur.wfs_fase_pendencia (cd_fase,id_pendencia,ds_pendencia,ds_procedure) values (8,'AART','Anexar Arte','pkg_mkt_workflow.prc_wf_art');
insert into systur.wfs_fase_pendencia (cd_fase,id_pendencia,ds_pendencia,ds_procedure) values (8,'DSTN','Informar Destino','pkg_mkt_workflow.prc_wf_destino');
insert into systur.wfs_fase_pendencia (cd_fase,id_pendencia,ds_pendencia,ds_procedure) values (4,'GRSP','Gerar SP','pkg_mkt_workflow.prc_wf_sp');
insert into systur.wfs_fase_pendencia (cd_fase,id_pendencia,ds_pendencia,ds_procedure) values (7,'FRNC','Cadastrar Fornecedor','pkg_fnc_workflow.prc_wf_cadastro');

insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (2,6772910);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (3,6772910);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (4,6772910);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (5,6772910);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (6,6772910);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (7,6772910);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (1,1);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (3,1);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (5,1);
insert into systur.wfs_fase_usuario (cd_fase, cd_pessoa) values (8,1);

commit;
drop table systur.wfs_fluxo_real_pendencia; 
drop table systur.wfs_fluxo_real; 
drop table systur.wfs_fluxo_fase_pendencia; 
drop table systur.wfs_fluxo_fase; 
drop table systur.wfs_fluxo; 
drop table systur.wfs_fase_usuario; 
drop table systur.wfs_fase_pendencia; 
drop table systur.wfs_fase; 
drop table systur.wfs_modulo; 

drop sequence systur.wfs_fluxo_sq01;  

create table systur.wfs_modulo
( cd_modulo               number     (10) 
, ds_modulo               varchar2   (40) 
, ds_icone                varchar2   (40) 
, ds_cor                  varchar2   (8) 
, ds_tabela               varchar2   (40) 
, ds_campo                varchar2   (40)
, ds_proc_request         varchar2   (80)
, ds_proc_view            varchar2   (80)
, dt_atualizacao          date             not null 
, cd_pessoa_mnt           number      (8)  not null 
, nm_usuario              varchar2   (30)  not null
, ip_usuario              varchar2   (50) ); 

alter table systur.wfs_modulo add constraint wfs_modulo_pk primary key (cd_modulo) using index tablespace syst_index_05; 

comment on table systur.wfs_modulo is 'Tabela de módulos de workflow.';
comment on column systur.wfs_modulo.cd_modulo       is 'Código do módulo.';
comment on column systur.wfs_modulo.ds_modulo       is 'Descrição do módulo.';
comment on column systur.wfs_modulo.ds_icone        is 'Nome do ícone utilizado pelo módulo.';
comment on column systur.wfs_modulo.ds_cor          is 'Cor utilizada no painel para identificar o módulo.'; 
comment on column systur.wfs_modulo.ds_tabela       is 'Nome da tabela que possui o campo de referência.';
comment on column systur.wfs_modulo.ds_campo        is 'Campo de referência.';
comment on column systur.wfs_modulo.ds_proc_request is 'Procedure de solicitação.';
comment on column systur.wfs_modulo.ds_proc_view    is 'Procedure de visualização.';
comment on column systur.wfs_modulo.dt_atualizacao  is 'Data Atualizacão'; 
comment on column systur.wfs_modulo.nm_usuario      is 'Nome Usuario'; 
comment on column systur.wfs_modulo.cd_pessoa_mnt   is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro'; 
comment on column systur.wfs_modulo.ip_usuario      is 'IP Usuario';

----------------------------------------------------------  
create table systur.wfs_fase 
( cd_fase        number     (10)  
, ds_fase        varchar2   (40)  
, cd_modulo      number     (10)  
, sq_fase        number      (4)  
, ds_procedure   varchar2  (100)  
, st_habilitacao char        (1)           default 'A' 
, dt_atualizacao date             not null 
, cd_pessoa_mnt  number      (8)  not null 
, nm_usuario     varchar2   (30)  not null 
, ip_usuario     varchar2   (50) ); 

alter table systur.wfs_fase add constraint wfs_fase_pk primary key (cd_fase) using index tablespace syst_index_05;

alter table systur.wfs_fase add constraint wfs_fase_fk01 foreign key (cd_modulo) references systur.wfs_modulo (cd_modulo);

comment on table systur.wfs_fase is 'Tabela com as fases de cada módulo do workflow.'; 

comment on column systur.wfs_fase.cd_fase         is 'Código da fase.';
comment on column systur.wfs_fase.ds_fase         is 'Descrição da fase.'; 
comment on column systur.wfs_fase.cd_modulo       is 'Código do módulo associado.'; 
comment on column systur.wfs_fase.sq_fase         is 'Sequencia em que a fase aparece.'; 
comment on column systur.wfs_fase.st_habilitacao  is 'Indica se a fase está ativa.'; 
comment on column systur.wfs_fase.dt_atualizacao  is 'Data Atualizacão'; 
comment on column systur.wfs_fase.nm_usuario      is 'Nome Usuario'; 
comment on column systur.wfs_fase.cd_pessoa_mnt   is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro';
comment on column systur.wfs_fase.ip_usuario      is 'IP Usuario'; 

---------------------------------------------------------- 

create table systur.wfs_fase_pendencia 
( cd_fase        number   (10)  
, id_pendencia   varchar2  (4)  
, ds_pendencia   varchar2 (40)  
, ds_procedure   varchar2 (80)  
, st_habilitacao char      (1)           default'A' 
, dt_atualizacao date           not null 
, cd_pessoa_mnt  number    (8)  not null 
, nm_usuario     varchar2 (30)  not null 
, ip_usuario     varchar2 (50) ); 

alter table systur.wfs_fase_pendencia add constraint wfs_fase_pendencia_pk primary key (cd_fase,id_pendencia) using index tablespace syst_index_05; 

alter table systur.wfs_fase_pendencia add constraint wfs_fase_pendencia_fk01 foreign key (cd_fase) references systur.wfs_fase (cd_fase); 

comment on table systur.wfs_fase_pendencia is 'Tabela com as fases de cada módulo do workflow.'; 

comment on column systur.wfs_fase_pendencia.cd_fase        is 'Código da fase.';
comment on column systur.wfs_fase_pendencia.id_pendencia   is 'Identificador da pendência.'; 
comment on column systur.wfs_fase_pendencia.ds_pendencia   is 'Descrição da pendência.';  
comment on column systur.wfs_fase_pendencia.ds_procedure   is 'Sequencia em que a fase aparece.'; 
comment on column systur.wfs_fase_pendencia.st_habilitacao is 'Indica se a pendência está ativa.'; 
comment on column systur.wfs_fase_pendencia.dt_atualizacao is 'Data Atualizacão'; 
comment on column systur.wfs_fase_pendencia.nm_usuario     is 'Nome Usuario'; 
comment on column systur.wfs_fase_pendencia.cd_pessoa_mnt  is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro'; 
comment on column systur.wfs_fase_pendencia.ip_usuario     is 'IP Usuario'; 

---------------------------------------------------------- 

create table systur.wfs_fase_usuario 
( cd_fase        number   (10)  
, cd_pessoa      number   (10)  
, dt_atualizacao date           not null 
, cd_pessoa_mnt  number    (8)  not null 
, nm_usuario     varchar2 (30)  not null 
, ip_usuario     varchar2 (50) ); 

alter table systur.wfs_fase_usuario add constraint wfs_fase_usuario_pk primary key (cd_fase,cd_pessoa) using index tablespace syst_index_05;

alter table systur.wfs_fase_usuario add constraint wfs_fase_usuario_fk01 foreign key (cd_fase) references systur.wfs_fase (cd_fase);
alter table systur.wfs_fase_usuario add constraint wfs_fase_usuario_fk02 foreign key (cd_pessoa) references systur.gen_pes_usuario (cd_pessoa);

comment on table systur.wfs_fase_usuario is 'Tabela com os usuários que podem acessar cada fase do workflow.';

comment on column systur.wfs_fase_usuario.cd_fase        is 'Código da fase.';
comment on column systur.wfs_fase_usuario.cd_pessoa      is 'Código da pessoa.'; 
comment on column systur.wfs_fase_usuario.dt_atualizacao is 'Data Atualizacão'; 
comment on column systur.wfs_fase_usuario.nm_usuario     is 'Nome Usuario'; 
comment on column systur.wfs_fase_usuario.cd_pessoa_mnt  is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro'; 
comment on column systur.wfs_fase_usuario.ip_usuario     is 'IP Usuario'; 

----------------------------------------------------------- 
create sequence systur.wfs_fluxo_sq01 minvalue 1 maxvalue 9999999999 start with 1 increment by 1 nocache;

create table systur.wfs_fluxo 
( cd_fluxo              number    (10)            default systur.wfs_fluxo_sq01.nextval
, cd_modulo             number    (10)
, dt_solicitacao        date                      default sysdate
, id_status             char       (1)            default 'A' 
, cd_pessoa_solicitante number    (10)  
, cd_campo              number    (20)  
, ds_titulo             varchar2  (40)
, ds_mensagem           varchar2 (800)  
, dt_atualizacao        date            not null 
, cd_pessoa_mnt         number     (8)  not null 
, nm_usuario            varchar2  (30)  not null 
, ip_usuario            varchar2  (50) ); 

alter table systur.wfs_fluxo add constraint wfs_fluxo_pk primary key (cd_fluxo) using index tablespace syst_index_05;

alter table systur.wfs_fluxo add constraint wfs_fluxo_fk01 foreign key (cd_pessoa_solicitante) references systur.gen_pes_usuario (cd_pessoa); 
alter table systur.wfs_fluxo add constraint wfs_fluxo_fk02 foreign key (cd_modulo) references systur.wfs_modulo (cd_modulo); 

comment on table systur.wfs_fluxo is 'Tabela de fluxos.'; 

comment on column systur.wfs_fluxo.cd_fluxo              is 'Código do fluxo.'; 
comment on column systur.wfs_fluxo.cd_modulo             is 'Código do módulo.'; 
comment on column systur.wfs_fluxo.dt_solicitacao        is 'Data de criação do fluxo.'; 
comment on column systur.wfs_fluxo.id_status             is 'Status do fluxo.';
comment on column systur.wfs_fluxo.cd_pessoa_solicitante is 'Pessoa que fez a solicitação.'; 
comment on column systur.wfs_fluxo.cd_campo              is 'Código do campo utilizado.'; 
comment on column systur.wfs_fluxo.ds_titulo             is 'Título da solicitação.'; 
comment on column systur.wfs_fluxo.ds_mensagem           is 'Mensagem da solicitação.'; 
comment on column systur.wfs_fluxo.dt_atualizacao        is 'Data Atualizacão'; 
comment on column systur.wfs_fluxo.nm_usuario            is 'Nome Usuario'; 
comment on column systur.wfs_fluxo.cd_pessoa_mnt         is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro';
comment on column systur.wfs_fluxo.ip_usuario            is 'IP Usuario'; 

create table systur.wfs_fluxo_fase
( cd_fluxo       number   (10)  
, cd_fase        number   (10)  
, sq_fase        number    (4)  
, dt_atualizacao date           not null 
, cd_pessoa_mnt  number    (8)  not null 
, nm_usuario     varchar2 (30)  not null 
, ip_usuario     varchar2 (50) ); 

alter table systur.wfs_fluxo_fase add constraint wfs_fluxo_fase_pk primary key (cd_fluxo,cd_fase) using index tablespace syst_index_05; 

comment on table systur.wfs_fluxo_fase is 'Tabela de fases que são utilizadas no fluxo (cópia do momento da wfs_fase).'; 

comment on column systur.wfs_fluxo_fase.cd_fluxo       is 'Código do fluxo.';
comment on column systur.wfs_fluxo_fase.cd_fase        is 'Código da fase.'; 
comment on column systur.wfs_fluxo_fase.sq_fase        is 'Sequencia da fase.'; 
comment on column systur.wfs_fluxo_fase.dt_atualizacao is 'Data Atualizacão'; 
comment on column systur.wfs_fluxo_fase.nm_usuario     is 'Nome Usuario'; 
comment on column systur.wfs_fluxo_fase.cd_pessoa_mnt  is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro'; 
comment on column systur.wfs_fluxo_fase.ip_usuario     is 'IP Usuario'; 


create table systur.wfs_fluxo_fase_pendencia
( cd_fluxo       number   (10)  
, cd_fase        number   (10) 
, id_pendencia   varchar2  (4) 
, ds_procedure   varchar2 (80) 
, dt_atualizacao date           not null 
, cd_pessoa_mnt  number    (8)  not null 
, nm_usuario     varchar2 (30)  not null 
, ip_usuario     varchar2 (50)); 

alter table systur.wfs_fluxo_fase_pendencia add constraint wfs_fluxo_fase_pendencia_pk primary key (cd_fluxo,cd_fase,id_pendencia) using index tablespace syst_index_05;

comment on table systur.wfs_fluxo_fase_pendencia is 'Tabela de fases que são utilizadas no fluxo (cópia do momento da wfs_fase_pendencia).'; 

comment on column systur.wfs_fluxo_fase_pendencia.cd_fluxo       is 'Código do fluxo.';
comment on column systur.wfs_fluxo_fase_pendencia.cd_fase        is 'Código da fase.'; 
comment on column systur.wfs_fluxo_fase_pendencia.id_pendencia   is 'Código da pendência (identificador).';
comment on column systur.wfs_fluxo_fase_pendencia.ds_procedure   is 'Procedure utilizada.'; 
comment on column systur.wfs_fluxo_fase_pendencia.dt_atualizacao is 'Data Atualizacão'; 
comment on column systur.wfs_fluxo_fase_pendencia.nm_usuario     is 'Nome Usuario'; 
comment on column systur.wfs_fluxo_fase_pendencia.cd_pessoa_mnt  is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro';
comment on column systur.wfs_fluxo_fase_pendencia.ip_usuario     is 'IP Usuario'; 

create table systur.wfs_fluxo_real 
( cd_fluxo       number   (10) 
, sq_real        number    (4)  
, cd_fase        number   (10) 
, id_status      char      (1)           default 'A'
, cd_pessoa      number   (10) 
, ds_mensagem    varchar2 (800)
, dt_atualizacao date           not null 
, cd_pessoa_mnt  number    (8)  not null
, nm_usuario     varchar2 (30)  not null 
, ip_usuario     varchar2 (50)); 

alter table systur.wfs_fluxo_real add constraint wfs_fluxo_real_pk primary key (cd_fluxo,sq_real,cd_fase) using index tablespace syst_index_05;

alter table systur.wfs_fluxo_real add constraint wfs_fluxo_real_fk01 foreign key (cd_fluxo,cd_fase) references systur.wfs_fluxo_fase (cd_fluxo,cd_fase);
alter table systur.wfs_fluxo_real add constraint wfs_fluxo_real_fk02 foreign key (cd_pessoa) references systur.gen_pes_usuario (cd_pessoa);

comment on table systur.wfs_fluxo_real is 'Fluxo real da solicitação, inclui acões que foram feitas em ordem de execução.'; 

comment on column systur.wfs_fluxo_real.cd_fluxo       is 'Código do fluxo.'; 
comment on column systur.wfs_fluxo_real.sq_real        is 'Sequencia real do fluxo.'; 
comment on column systur.wfs_fluxo_real.cd_fase        is 'Código da fase.'; 
comment on column systur.wfs_fluxo_real.id_status      is 'Status da fase.'; 
comment on column systur.wfs_fluxo_real.cd_pessoa      is 'Pessoa que fez a ação';
comment on column systur.wfs_fluxo_real.ds_mensagem    is 'Mensagem de informação.'; 
comment on column systur.wfs_fluxo_real.dt_atualizacao is 'Data Atualizacão'; 
comment on column systur.wfs_fluxo_real.nm_usuario     is 'Nome Usuario'; 
comment on column systur.wfs_fluxo_real.cd_pessoa_mnt  is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro';
comment on column systur.wfs_fluxo_real.ip_usuario     is 'IP Usuario'; 

create table systur.wfs_fluxo_real_pendencia
( cd_fluxo       number   (10)  
, sq_real        number    (4)  
, cd_fase        number   (10)  
, id_pendencia   varchar2  (4)  
, id_status      char      (1)           default 'A'  
, dt_atualizacao date           not null 
, cd_pessoa_mnt  number    (8)  not null 
, nm_usuario     varchar2 (30)  not null 
, ip_usuario     varchar2 (50) ); 

alter table systur.wfs_fluxo_real_pendencia add constraint wfs_fluxo_real_pendencia_pk primary key (cd_fluxo,sq_real,cd_fase,id_pendencia) using index tablespace syst_index_05;

alter table systur.wfs_fluxo_real_pendencia add constraint wfs_fluxo_real_pendencia_fk01 foreign key (cd_fluxo,sq_real,cd_fase) references systur.wfs_fluxo_real (cd_fluxo,sq_real,cd_fase);
alter table systur.wfs_fluxo_real_pendencia add constraint wfs_fluxo_real_pendencia_fk02 foreign key (cd_fase,id_pendencia) references systur.wfs_fase_pendencia (cd_fase,id_pendencia);

comment on table systur.wfs_fluxo_real_pendencia is 'Pendencias do fluxo real da solicitação, inclui todas as pendências que possam ser realizadas durante todo o processo.'; 

comment on column systur.wfs_fluxo_real_pendencia.cd_fluxo       is 'Código do fluxo.'; 
comment on column systur.wfs_fluxo_real_pendencia.sq_real        is 'Sequencia real do fluxo.'; 
comment on column systur.wfs_fluxo_real_pendencia.cd_fase        is 'Código da fase.'; 
comment on column systur.wfs_fluxo_real_pendencia.id_status      is 'Status da fase.';
comment on column systur.wfs_fluxo_real_pendencia.id_pendencia   is 'Código da pendência (identificador)'; 
comment on column systur.wfs_fluxo_real_pendencia.dt_atualizacao is 'Data Atualizacão'; 
comment on column systur.wfs_fluxo_real_pendencia.nm_usuario     is 'Nome Usuario'; 
comment on column systur.wfs_fluxo_real_pendencia.cd_pessoa_mnt  is 'Codigo que identifica a pessoa que fez a ultima atualizacão no registro';
comment on column systur.wfs_fluxo_real_pendencia.ip_usuario     is 'IP Usuario';
create or replace trigger systur.wfs_fase_usu
  before insert or update on systur.wfs_fase for each row
declare
  vcd_pessoa_mnt wfs_fase.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fase.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fase.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/

create or replace trigger systur.wfs_fase_usuario_usu
  before insert or update on systur.wfs_fase_usuario for each row
declare
  vcd_pessoa_mnt wfs_fase_usuario.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fase_usuario.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fase_usuario.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/

create or replace trigger systur.wfs_fluxo_usu
  before insert or update on systur.wfs_fluxo for each row
declare
  vcd_pessoa_mnt wfs_fluxo.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fluxo.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fluxo.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/

create or replace trigger systur.wfs_fluxo_fase_usu
  before insert or update on systur.wfs_fluxo_fase for each row
declare
  vcd_pessoa_mnt wfs_fluxo_fase.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fluxo_fase.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fluxo_fase.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/

create or replace trigger systur.wfs_fluxo_real_usu
  before insert or update on systur.wfs_fluxo_real for each row
declare
  vcd_pessoa_mnt wfs_fluxo_real.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fluxo_real.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fluxo_real.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/

create or replace trigger systur.wfs_modulo_usu
  before insert or update on systur.wfs_modulo for each row
declare
  vcd_pessoa_mnt wfs_modulo.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_modulo.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_modulo.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/


create or replace trigger systur.wfs_fase_pendencia_usu
  before insert or update on systur.wfs_fase_pendencia for each row
declare
  vcd_pessoa_mnt wfs_fase_pendencia.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fase_pendencia.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fase_pendencia.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/

create or replace trigger systur.wfs_fluxo_real_pendencia_usu
  before insert or update on systur.wfs_fluxo_real_pendencia for each row
declare
  vcd_pessoa_mnt wfs_fluxo_real_pendencia.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fluxo_real_pendencia.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fluxo_real_pendencia.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/

create or replace trigger systur.wfs_fluxo_fase_pendencia_usu
  before insert or update on systur.wfs_fluxo_fase_pendencia for each row
declare
  vcd_pessoa_mnt wfs_fluxo_fase_pendencia.cd_pessoa_mnt%type := nvl(upper(trim(wsgsec.get_cd_pessoa_user)),0);
  vip_usuario    wfs_fluxo_fase_pendencia.ip_usuario%type := sys_context('userenv','ip_address');
  vnm_usuario    wfs_fluxo_fase_pendencia.nm_usuario%type := nvl(upper(trim(wsgsec.get_user)),user);
begin
  if owa.num_cgi_vars > 0 then
    vip_usuario := owa_util.get_cgi_env('remote_addr');
  end if;
  case
    when inserting then
      :new.dt_atualizacao := nvl(:new.dt_atualizacao,sysdate);
      :new.cd_pessoa_mnt  := nvl(:new.cd_pessoa_mnt,vcd_pessoa_mnt);
      :new.ip_usuario     := nvl(:new.ip_usuario,vip_usuario);
      :new.nm_usuario     := nvl(:new.nm_usuario,vnm_usuario);
    when updating then
      if not updating('dt_atualizacao') then
        :new.dt_atualizacao := sysdate;
      end if;
      if not updating('cd_pessoa_mnt') then
        :new.cd_pessoa_mnt := vcd_pessoa_mnt;
      end if;
      if not updating('ip_usuario') then
        :new.ip_usuario := vip_usuario;
      end if;
      if not updating('nm_usuario') then
          :new.nm_usuario := vnm_usuario;
      end if;
    else
      null;
  end case;
end;
/