Created
November 10, 2020 21:09
-
-
Save AndyDaSilva52/960907f9ca4e840b336c18edf34b1c30 to your computer and use it in GitHub Desktop.
#MegaERP - Trigger - Reescriturar e Recontabilizar Nota Fiscal Emitida (Distribuição)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace TRIGGER MGCLI.T_CLI_VEN_NOTAFISCAL | |
BEFORE INSERT OR UPDATE ON MGVEN.VEN_NOTAFISCAL | |
REFERENCING OLD AS OLD NEW AS NEW | |
FOR EACH ROW | |
BEGIN | |
IF UPDATING THEN | |
BEGIN | |
/** | |
Motivo: Macar para reescriturar após alteração | |
*/ | |
UPDATE MGGLO.GLO_ACAOMOVIMENTO | |
SET ACAOM_RE_VALORFISCALREAL = 0, ACAOM_RE_VALORCONTABILREAL = 0 | |
WHERE | |
ACAOM_DT_EXCLUSAO IS NULL | |
AND ACAOM_DT_DATAENTRADA >= ( | |
SELECT MAX(e.sis_dt_encerramento) | |
FROM MGGLO.glo_encerrasistema E | |
WHERE E.SIS_IN_CODIGO IN (6) | |
AND | |
E.ORG_IN_CODIGO = :NEW.ORG_IN_CODIGO | |
AND | |
E.FIL_IN_CODIGO = :NEW.FIL_IN_CODIGO | |
) | |
AND ACAOM_IN_SEQUENCIA = :NEW.ACAOM_IN_SEQUENCIA | |
; | |
END; | |
BEGIN | |
/** | |
Motivo: Macar para recontabilizar após alteração | |
*/ | |
UPDATE MGGLO.GLO_ACAOMOVIMENTO | |
SET ACAOM_RE_VALORCONTABILREAL = 0 | |
WHERE | |
ACAOM_DT_EXCLUSAO IS NULL | |
AND ACAOM_DT_DATAENTRADA >= ( | |
SELECT MAX(e.sis_dt_encerramento) | |
FROM MGGLO.glo_encerrasistema E | |
WHERE E.SIS_IN_CODIGO IN (4) | |
AND | |
E.ORG_IN_CODIGO = :NEW.ORG_IN_CODIGO | |
AND | |
E.FIL_IN_CODIGO = :NEW.FIL_IN_CODIGO | |
) | |
AND ACAOM_IN_SEQUENCIA IN (:NEW.ACAOM_IN_SEQUENCIA) | |
; | |
END; | |
END IF; | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment