CREATE OR REPLACE TRIGGER TRGCARGA_FORNECEDOR
AFTER INSERT OR UPDATE OR DELETE
ON FORNECEDOR FOR EACH ROW
BEGIN
   IF INSERTING THEN
      INSERT INTO USR_CARGA_FORNECEDOR (ID_FORNECEDOR, NM_FORNECEDOR, TX_CGC, TX_INSCRICAO, TX_CONTATO, TX_EMAIL,
                                        TX_BANCO, TX_AGENCIA, TX_CONTA, OP_PAGTO, TX_ENDERECO, TX_BAIRRO, TX_CIDADE,
                                        TX_UF, TX_CEP, TP_ATUALIZACAO, OP_IMP)
      VALUES (0,  :NEW.NMRAZSOCFORN, SUBSTR(:NEW.CDFORNECED, 2, 30), :NEW.NRINSESTFORN, '', '',
              '', '', '', '', '', '', '', '', '', 'I', 'N');

   ELSIF UPDATING THEN
      UPDATE USR_CARGA_FORNECEDOR
      SET NM_FORNECEDOR = :NEW.NMRAZSOCFORN,
          TX_INSCRICAO  = :NEW.NRINSESTFORN,
          TP_ATUALIZACAO = 'A'
      WHERE TX_CGC = SUBSTR(:OLD.CDFORNECED, 2, 30);

   ELSIF DELETING THEN
      UPDATE USR_CARGA_FORNECEDOR
      SET TP_ATUALIZACAO = 'E'
      WHERE TX_CGC = SUBSTR(:OLD.CDFORNECED, 2, 30);

   END IF;
END;
/


-- VERSAO --
BEGIN ATUVEROBJ('TRGCARGA_FORNECEDOR','4.11.033'); END;
/

