CREATE OR ALTER trigger ttbmodelo_fluxo_producao_b05iu for tbmodelo_fluxo_producao
active before insert or update position 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(3000);
DECLARE VARIABLE Grade Integer;
DECLARE VARIABLE G01 VarChar(10); DECLARE VARIABLE G02 VarChar(10);
DECLARE VARIABLE G03 VarChar(10); DECLARE VARIABLE G04 VarChar(10);
DECLARE VARIABLE G05 VarChar(10); DECLARE VARIABLE G06 VarChar(10);
DECLARE VARIABLE G07 VarChar(10); DECLARE VARIABLE G08 VarChar(10);
DECLARE VARIABLE G09 VarChar(10); DECLARE VARIABLE G10 VarChar(10);
DECLARE VARIABLE G11 VarChar(10); DECLARE VARIABLE G12 VarChar(10);
DECLARE VARIABLE G13 VarChar(10); DECLARE VARIABLE G14 VarChar(10);
DECLARE VARIABLE G15 VarChar(10); DECLARE VARIABLE G16 VarChar(10);
DECLARE VARIABLE G17 VarChar(10); DECLARE VARIABLE G18 VarChar(10);
DECLARE VARIABLE G19 VarChar(10); DECLARE VARIABLE G20 VarChar(10);
BEGIN

    HISTORICO = '';
    IF(INSERTING) THEN
    BEGIN
       IF((SELECT FIRST 1 C.MODELO_ID FROM TBMODELO_FLUXO_PRODUCAO C WHERE C.MODELO_ID = NEW.MODELO_ID
       AND C.FLUXO_ID = NEW.FLUXO_ID AND C.COR_ID = NEW.COR_ID) IS NOT NULL) THEN
       BEGIN
            IF(NEW.TAMANHO = 0 AND NEW.TEMPO > 0)THEN
                BEGIN HISTORICO = HISTORICO||' T00(min):'||0||'->'||NEW.TEMPO;
            END
            IF(NEW.TAMANHO = 0 AND NEW.TM > 0)THEN
                BEGIN HISTORICO = HISTORICO||' T00(seg):'||0||'->'||NEW.TEMPO;
            END
            For
            Select FIRST 1 Coalesce(G.CODIGO,0),
                 Coalesce(G.T01,'T01'), Coalesce(G.T02,'T02'), Coalesce(G.T03,'T03'), Coalesce(G.T04,'T03'),
                 Coalesce(G.T05,'T05'), Coalesce(G.T06,'T06'), Coalesce(G.T07,'T07'), Coalesce(G.T08,'T07'),
                 Coalesce(G.T09,'T09'), Coalesce(G.T10,'T10'), Coalesce(G.T11,'T11'), Coalesce(G.T12,'T11'),
                 Coalesce(G.T13,'T13'), Coalesce(G.T14,'T14'), Coalesce(G.T15,'T15'), Coalesce(G.T16,'T15'),
                 Coalesce(G.T17,'T17'), Coalesce(G.T18,'T18'), Coalesce(G.T19,'T19'), Coalesce(G.T20,'T19')
            From TbGrade G WHERE G.Codigo = coalesce((select first 1 z.grade_codigo from tbmodelo z where z.codigo = new.MODELO_ID),0)
            Into :Grade,:G01,:G02,:G03,:G04,:G05,:G06,:G07,:G08,:G09,
             :G10,:G11,:G12,:G13,:G14,:G15,:G16,:G17,:G18,:G19,:G20
            DO
            BEGIN
            IF(NEW.TAMANHO = 1 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G01||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 2 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G02||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 3 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G03||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 4 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G04||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 5 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G05||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 6 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G06||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 7 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G07||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 8 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G08||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 9 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G09||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 10 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G10||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 11 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G11||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 12 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G12||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 13 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G13||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 14 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G14||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 15 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G15||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 16 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G16||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 17 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G17||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 18 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G18||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 19 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G19||'(min):'||0||'->'||NEW.TEMPO||']'; END
            IF(NEW.TAMANHO = 20 AND NEW.TEMPO > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G20||'(min):'||0||'->'||NEW.TEMPO||']'; END
            
            IF(NEW.TAMANHO = 1 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G01||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 2 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G02||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 3 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G03||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 4 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G04||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 5 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G05||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 6 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G06||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 7 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G07||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 8 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G08||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 9 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G09||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 10 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G10||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 11 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G11||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 12 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G12||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 13 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G13||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 14 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G14||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 15 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G15||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 16 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G16||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 17 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G17||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 18 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G18||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 19 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G19||'(seg):'||0||'->'||NEW.TM||']'; END
            IF(NEW.TAMANHO = 20 AND NEW.TM > 0) THEN BEGIN HISTORICO = HISTORICO||' ['||:G20||'(seg):'||0||'->'||NEW.TM||']'; END
            END

            IF (HISTORICO <> '') THEN
            BEGIN
               HISTORICO = ' FLUXO DE PRODUCAO:'||new.FLUXO_ID||', COR: '||IIF(NEW.COR_ID > 0,(select first 1 NEW.COR_ID||' - '||a.descricao from TBCOR a where a.CODIGO = new.COR_ID),'*** PADRÃO ***')||' ALTERADO '||HISTORICO;
               EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO', NEW.MODELO_ID, HISTORICO);
            END
       END
       --ELSE
       --BEGIN
          -- HISTORICO = HISTORICO||' FLUXO DE PRODUCAO:'||new.FLUXO_ID||', COR: '||IIF(NEW.COR_ID > 0,(select first 1 NEW.COR_ID||' - '||a.descricao from TBCOR a where a.CODIGO = new.COR_ID),'*** PADRÃO ***')||' INCLUIDA.';
          -- EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO', NEW.MODELO_ID, HISTORICO);
       --END
    END

    IF(UPDATING) THEN
    BEGIN
        IF(NEW.TAMANHO = 0 AND OLD.TEMPO <> NEW.TEMPO)THEN
            BEGIN HISTORICO = HISTORICO||' T00(min):'||OLD.TEMPO||'->'||NEW.TEMPO;
        END
        IF(NEW.TAMANHO = 0 AND OLD.TM <> NEW.TM)THEN
            BEGIN HISTORICO = HISTORICO||' T00(seg):'||OLD.TM||'->'||NEW.TM;
        END
        IF(OLD.PECA <> NEW.PECA)THEN
            BEGIN HISTORICO = HISTORICO||' PEÇA:'||OLD.PECA||'->'||NEW.PECA;
        END
       For
        Select FIRST 1 Coalesce(G.CODIGO,0),
             Coalesce(G.T01,'T01'), Coalesce(G.T02,'T02'), Coalesce(G.T03,'T03'), Coalesce(G.T04,'T03'),
             Coalesce(G.T05,'T05'), Coalesce(G.T06,'T06'), Coalesce(G.T07,'T07'), Coalesce(G.T08,'T07'),
             Coalesce(G.T09,'T09'), Coalesce(G.T10,'T10'), Coalesce(G.T11,'T11'), Coalesce(G.T12,'T11'),
             Coalesce(G.T13,'T13'), Coalesce(G.T14,'T14'), Coalesce(G.T15,'T15'), Coalesce(G.T16,'T15'),
             Coalesce(G.T17,'T17'), Coalesce(G.T18,'T18'), Coalesce(G.T19,'T19'), Coalesce(G.T20,'T19')
        From TbGrade G WHERE G.Codigo =  coalesce((select first 1 z.grade_codigo from tbmodelo z where z.codigo = new.MODELO_ID),0)
        Into :Grade,:G01,:G02,:G03,:G04,:G05,:G06,:G07,:G08,:G09,
         :G10,:G11,:G12,:G13,:G14,:G15,:G16,:G17,:G18,:G19,:G20
        DO
        BEGIN
        IF(NEW.TAMANHO = 1 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G01||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 2 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G02||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 3 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G03||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 4 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G04||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 5 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G05||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 6 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G06||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 7 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G07||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 8 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G08||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 9 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G09||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 10 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G10||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 11 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G11||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 12 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G12||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 13 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G13||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 14 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G14||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 15 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G15||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 16 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G16||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 17 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G17||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 18 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G18||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 19 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G19||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END
        IF(NEW.TAMANHO = 20 AND NEW.TEMPO <> OLD.TEMPO) THEN BEGIN HISTORICO = HISTORICO||' ['||:G20||'(min):'||OLD.TEMPO||'->'||NEW.TEMPO||']'; END

        IF(NEW.TAMANHO = 1 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G01||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 2 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G02||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 3 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G03||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 4 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G04||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 5 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G05||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 6 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G06||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 7 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G07||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 8 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G08||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 9 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G09||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 10 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G10||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 11 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G11||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 12 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G12||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 13 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G13||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 14 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G14||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 15 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G15||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 16 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G16||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 17 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G17||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 18 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G18||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 19 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G19||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        IF(NEW.TAMANHO = 20 AND NEW.TM <> OLD.TM) THEN BEGIN HISTORICO = HISTORICO||' ['||:G20||'(seg):'||OLD.TM||'->'||NEW.TM||']'; END
        END
        IF(HISTORICO <> '') THEN
        BEGIN
           HISTORICO = ' FLUXO DE PRODUCAO:'||new.FLUXO_ID||', COR: '||IIF(NEW.COR_ID > 0,(select first 1 NEW.COR_ID||' - '||a.descricao from TBCOR a where a.CODIGO = new.COR_ID),'*** PADRÃO ***')||' ALTERADO '||HISTORICO;
           EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO', NEW.MODELO_ID, HISTORICO);
        END
    END


END;

