CREATE OR REPLACE
TRIGGER USR_ATU_ED_SOLICITA_EXT
BEFORE UPDATE OF IDSOLEXTRA ON SOLICITA
FOR EACH ROW
DECLARE
  V_DSREMOTEADDR VARCHAR2(15);
  V_DSREMOTEHOST VARCHAR2(15);
  V_DSSERVERRDM  VARCHAR2(20);
  V_DSSERVMETHOD VARCHAR2(30);
  V_DSREMOTEOPER VARCHAR2(12);
  V_IDSOLEXTRA   VARCHAR2(1);
BEGIN
   WEBTUNNING(V_DSREMOTEADDR,
              V_DSREMOTEHOST,
              V_DSSERVERRDM,
              V_DSSERVMETHOD,
              V_DSREMOTEOPER);
   IF V_DSSERVERRDM LIKE 'rdmLancaSoliCmp%' THEN
      IF :NEW.IDSOLEXTRA = 'S' THEN
         UPDATE ITEMSOLI
            SET CDFILIOPELOG = NULL
          WHERE CDFILLAN     = :NEW.CDFILLANCA
            AND CDFILSOLI    = :NEW.CDFILSOLI
            AND NRSOLICMP    = :NEW.NRSOLICMP
            AND CDFILIOPELOG IS NOT NULL;
      ELSE
         UPDATE ITEMSOLI
            SET CDFILIOPELOG = (SELECT MAX(PARAMPRODSUP.CDFILIOPELOG)
                                  FROM PARAMPRODSUP
                                 WHERE PARAMPRODSUP.CDFILIAL  = ITEMSOLI.CDFILSOLI
                                   AND PARAMPRODSUP.CDPRODUTO = ITEMSOLI.CDPRODUTO
                                   AND PARAMPRODSUP.CDFILIOPELOG IS NOT NULL)
          WHERE CDFILLAN     = :NEW.CDFILLANCA
            AND CDFILSOLI    = :NEW.CDFILSOLI
            AND NRSOLICMP    = :NEW.NRSOLICMP
            AND CDFILIOPELOG IS NULL;
      END IF;
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('USR_ATU_ED_SOLICITA_EXT','6.00XXX'); END;
/
