Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndyDaSilva52/adf39a7b165b5aef554986ce4b5f35c8 to your computer and use it in GitHub Desktop.
Save AndyDaSilva52/adf39a7b165b5aef554986ce4b5f35c8 to your computer and use it in GitHub Desktop.
#MegaERP - Trigger para validações no Cadastro de Agentes (AGN_IN_CODIGO) por Tipo (AGN_TAU_ST_CODIGO) #Mega
CREATE OR REPLACE TRIGGER "MGCLI"."T_CLI_GLO_AGENTES_ID"
BEFORE UPDATE ON MGGLO.GLO_AGENTES_ID
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
FOR cMOV IN (
SELECT MOV_DT_EMISSAO, MOV_ST_TABELA FROM (
SELECT FRE_DT_EMISSAO MOV_DT_EMISSAO, 'Financeiro - Contas a Receber' MOV_ST_TABELA FROM mgfin.fin_faturareceber WHERE agn_in_codigo = :NEW.AGN_IN_CODIGO and agn_tau_st_codigo = :new.agn_tau_st_codigo AND fre_dt_emissao < :NEW.AGN_DT_INICIOMOV AND fre_dt_emissao = (SELECT MIN(fre_dt_emissao) from mgfin.fin_faturareceber where agn_in_codigo = :NEW.agn_in_codigo and agn_tau_st_codigo = :NEW.agn_tau_st_codigo) and rownum <= 1
)
) LOOP
RAISE_APPLICATION_ERROR(-20101, 'Não é permitido alterar o Agente ['|| :NEW.AGN_IN_CODIGO ||']Tipo['|| :NEW.AGN_TAU_ST_CODIGO ||'] para a Data de Inicio ['|| TO_CHAR(:NEW.AGN_DT_INICIOMOV, 'DD/MM/YYYY') ||'], pois existem movimentos do mesmo com Data ['|| TO_CHAR(cMOV.MOV_DT_EMISSAO, 'DD/MM/YYYY') ||'] anterior no cadastro ['|| cMOV.MOV_ST_TABELA ||']');
END LOOP;
END;
ALTER TRIGGER "MGCLI"."T_CLI_GLO_AGENTES_ID" ENABLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment