SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_preco_b03u for tbmodelo_preco
active before update position 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(4000);
BEGIN
    HISTORICO = '';

    IF(OLD.TABELA_ID <> NEW.TABELA_ID) THEN
    BEGIN
       HISTORICO = HISTORICO||' TABELA:'||OLD.TABELA_ID||'->'||NEW.TABELA_ID;
    END

    IF(OLD.QUANTIDADE_MINIMA IS DISTINCT FROM NEW.QUANTIDADE_MINIMA) THEN
    BEGIN
       HISTORICO = HISTORICO||' QTD.MINIMA: '||COALESCE(OLD.QUANTIDADE_MINIMA, 0)||'->'||COALESCE(NEW.QUANTIDADE_MINIMA, 0);
    END

    IF(OLD.PRECO_VENDA <> NEW.PRECO_VENDA) THEN
    BEGIN
       HISTORICO = HISTORICO||' PR.NF:'||OLD.PRECO_VENDA||'->'||NEW.PRECO_VENDA;
    END

    IF(OLD.PRECO_CF <> NEW.PRECO_CF) THEN
    BEGIN
       HISTORICO = HISTORICO||' PR.CF:'||OLD.PRECO_CF||'->'||NEW.PRECO_CF;
    END

    IF(OLD.PERCENTUAL_CUSTO <> NEW.PERCENTUAL_CUSTO) THEN
    BEGIN
       HISTORICO = HISTORICO||' PR.CC:'||OLD.PERCENTUAL_CUSTO||'->'||NEW.PERCENTUAL_CUSTO;
    END

    IF(OLD.PR_NF_01 <> NEW.PR_NF_01) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T01:'||OLD.PR_NF_01||'->'||NEW.PR_NF_01;
    END

    IF(OLD.PR_NF_02 <> NEW.PR_NF_02) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T02:'||OLD.PR_NF_02||'->'||NEW.PR_NF_02;
    END

    IF(OLD.PR_NF_03 <> NEW.PR_NF_03) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T03:'||OLD.PR_NF_03||'->'||NEW.PR_NF_03;
    END

    IF(OLD.PR_NF_04 <> NEW.PR_NF_04) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T04:'||OLD.PR_NF_04||'->'||NEW.PR_NF_04;
    END

    IF(OLD.PR_NF_05 <> NEW.PR_NF_05) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T05:'||OLD.PR_NF_05||'->'||NEW.PR_NF_05;
    END

    IF(OLD.PR_NF_06 <> NEW.PR_NF_06) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T06:'||OLD.PR_NF_06||'->'||NEW.PR_NF_06;
    END

    IF(OLD.PR_NF_07 <> NEW.PR_NF_07) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T07:'||OLD.PR_NF_07||'->'||NEW.PR_NF_07;
    END

    IF(OLD.PR_NF_08 <> NEW.PR_NF_08) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T08:'||OLD.PR_NF_08||'->'||NEW.PR_NF_08;
    END
    
    IF(OLD.PR_NF_09 <> NEW.PR_NF_09) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T09:'||OLD.PR_NF_09||'->'||NEW.PR_NF_09;
    END
    
    IF(OLD.PR_NF_10 <> NEW.PR_NF_10) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T10:'||OLD.PR_NF_10||'->'||NEW.PR_NF_10;
    END
    
    IF(OLD.PR_NF_11 <> NEW.PR_NF_11) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T11:'||OLD.PR_NF_11||'->'||NEW.PR_NF_11;
    END
    
    IF(OLD.PR_NF_12 <> NEW.PR_NF_12) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T12:'||OLD.PR_NF_12||'->'||NEW.PR_NF_12;
    END
    
    IF(OLD.PR_NF_13 <> NEW.PR_NF_13) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T13:'||OLD.PR_NF_13||'->'||NEW.PR_NF_13;
    END
    
    IF(OLD.PR_NF_14 <> NEW.PR_NF_14) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T14:'||OLD.PR_NF_14||'->'||NEW.PR_NF_14;
    END
    
    IF(OLD.PR_NF_15 <> NEW.PR_NF_15) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T15:'||OLD.PR_NF_15||'->'||NEW.PR_NF_15;
    END
    
    IF(OLD.PR_NF_16 <> NEW.PR_NF_16) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T16:'||OLD.PR_NF_16||'->'||NEW.PR_NF_16;
    END
    
    IF(OLD.PR_NF_17 <> NEW.PR_NF_17) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T17:'||OLD.PR_NF_17||'->'||NEW.PR_NF_17;
    END
    
    IF(OLD.PR_NF_18 <> NEW.PR_NF_18) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T18:'||OLD.PR_NF_18||'->'||NEW.PR_NF_18;
    END

    IF(OLD.PR_NF_19 <> NEW.PR_NF_19) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T19:'||OLD.PR_NF_19||'->'||NEW.PR_NF_19;
    END

    IF(OLD.PR_NF_20 <> NEW.PR_NF_20) THEN
    BEGIN
       HISTORICO = HISTORICO||' NF.T20:'||OLD.PR_NF_20||'->'||NEW.PR_NF_20;
    END

    
    IF(OLD.PR_CF_01 <> NEW.PR_CF_01) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T01:'||OLD.PR_CF_01||'->'||NEW.PR_CF_01;
    END

    IF(OLD.PR_CF_02 <> NEW.PR_CF_02) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T02:'||OLD.PR_CF_02||'->'||NEW.PR_CF_02;
    END

    IF(OLD.PR_CF_03 <> NEW.PR_CF_03) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T03:'||OLD.PR_CF_03||'->'||NEW.PR_CF_03;
    END

    IF(OLD.PR_CF_04 <> NEW.PR_CF_04) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T04:'||OLD.PR_CF_04||'->'||NEW.PR_CF_04;
    END

    IF(OLD.PR_CF_05 <> NEW.PR_CF_05) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T05:'||OLD.PR_CF_05||'->'||NEW.PR_CF_05;
    END

    IF(OLD.PR_CF_06 <> NEW.PR_CF_06) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T06:'||OLD.PR_CF_06||'->'||NEW.PR_CF_06;
    END

    IF(OLD.PR_CF_07 <> NEW.PR_CF_07) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T07:'||OLD.PR_CF_07||'->'||NEW.PR_CF_07;
    END

    IF(OLD.PR_CF_08 <> NEW.PR_CF_08) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T08:'||OLD.PR_CF_08||'->'||NEW.PR_CF_08;
    END
    
    IF(OLD.PR_CF_09 <> NEW.PR_CF_09) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T09:'||OLD.PR_CF_09||'->'||NEW.PR_CF_09;
    END
    
    IF(OLD.PR_CF_10 <> NEW.PR_CF_10) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T10:'||OLD.PR_CF_10||'->'||NEW.PR_CF_10;
    END
    
    IF(OLD.PR_CF_11 <> NEW.PR_CF_11) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T11:'||OLD.PR_CF_11||'->'||NEW.PR_CF_11;
    END
    
    IF(OLD.PR_CF_12 <> NEW.PR_CF_12) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T12:'||OLD.PR_CF_12||'->'||NEW.PR_CF_12;
    END
    
    IF(OLD.PR_CF_13 <> NEW.PR_CF_13) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T13:'||OLD.PR_CF_13||'->'||NEW.PR_CF_13;
    END
    
    IF(OLD.PR_CF_14 <> NEW.PR_CF_14) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T14:'||OLD.PR_CF_14||'->'||NEW.PR_CF_14;
    END
    
    IF(OLD.PR_CF_15 <> NEW.PR_CF_15) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T15:'||OLD.PR_CF_15||'->'||NEW.PR_CF_15;
    END
    
    IF(OLD.PR_CF_16 <> NEW.PR_CF_16) THEN
    BEGIN
       HISTORICO = HISTORICO||'CF.T16:'||OLD.PR_CF_16||'->'||NEW.PR_CF_16;
    END
    
    IF(OLD.PR_CF_17 <> NEW.PR_CF_17) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T17:'||OLD.PR_CF_17||'->'||NEW.PR_CF_17;
    END
    
    IF(OLD.PR_CF_18 <> NEW.PR_CF_18) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T18:'||OLD.PR_CF_18||'->'||NEW.PR_CF_18;
    END

    IF(OLD.PR_CF_19 <> NEW.PR_CF_19) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T19:'||OLD.PR_CF_19||'->'||NEW.PR_CF_19;
    END

    IF(OLD.PR_CF_20 <> NEW.PR_CF_20) THEN
    BEGIN
       HISTORICO = HISTORICO||' CF.T20:'||OLD.PR_CF_20||'->'||NEW.PR_CF_20;
    END

    IF(HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO_PRECO',NEW.ID,FN_ELIPSES(HISTORICO,500));
    END
END
^

SET TERM ; ^

