CREATE OR REPLACE TRIGGER USR_ATU_FORNECEDOR_NGD
BEFORE DELETE OR INSERT OR UPDATE OF NMRAZSOCFORN,
                                     NMFANTFORN,
                                     CDFORNERELAC,
                                     QTMINAUTFOT
ON FORNECEDOR  FOR EACH ROW
DECLARE
  V_CHAVE       VARCHAR2(300);
BEGIN
   IF DELETING THEN
      UPDATE USR_FORNECEDOR_NGD
         SET TPINTERFACE        = 'E',
             DTINTERFACEORI     = SYSDATE,
             DTINTERFACEDEST    = NULL,
             STATUS             = '1'
       WHERE USR_FORNECEDOR_NGD.CDFORNECED = :OLD.CDFORNECED;
      INSERT
        INTO USR_LOG_NGD(IDPROCESSO, DTLOG, STATUS, OBSSTATUS, IDPESQITEM)
      VALUES ('USR_FORNECEDOR_NGD', SYSDATE, '0', NULL, :OLD.CDFORNECED);
      UPDATE USR_REFORFIL_NGD
            SET TPINTERFACE        = 'E',
                DTINTERFACEORI     = SYSDATE,
                DTINTERFACEDEST    = NULL,
                STATUS             = '1'
          WHERE USR_REFORFIL_NGD.CDFORNECED  = :OLD.CDFORNECED;
         INSERT
           INTO USR_LOG_NGD(IDPROCESSO, DTLOG, STATUS, OBSSTATUS, IDPESQITEM)
         VALUES ('USR_REFORFIL_NGD', SYSDATE, '0', NULL, :OLD.CDFORNECED);
   ELSE
      :NEW.USR_NGD_INTEGRADO   := 'N';
      IF UPDATING THEN
         IF NVL(:NEW.QTMINAUTFOT, 0) <> NVL(:OLD.QTMINAUTFOT, 0) THEN
            :NEW.USR_NGD_INTEGRADO_1 := 'N';
         END IF;
      ELSE
         :NEW.USR_NGD_INTEGRADO_1 := 'N';
      END IF;
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('USR_ATU_FORNECEDOR_NGD','6.37.015'); END;
/
