CREATE OR ALTER trigger ttbnfs_item_b02iu for tbnfs_item
active before insert or update position 0
AS
BEGIN
    IF(TRIM(NEW.TRIBUTACAO_PIS) = '01' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '02' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '50' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '51' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '52' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '53' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '54' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '55' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '56' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '60' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '61' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '62' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '63' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '64' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '65' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '66') THEN
    BEGIN

        IF(COALESCE(NEW.BASECALCULO_PIS, 0) > 0 AND COALESCE(NEW.PERCENTUAL_PIS, 0) = 0) THEN
        BEGIN
            EXCEPTION "..."'PERCENTUAL PIS DO ITEM '||NEW.SEQUENCIA||' INVALIDO. ENTRE EM CONTATO COM O SUPORTE TECNICO';
        END
    END


    IF(TRIM(NEW.TRIBUTACAO_COFINS) = '01' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '02' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '50' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '51' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '52' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '53' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '54' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '55' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '56' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '60' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '61' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '62' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '63' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '64' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '65' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '66') THEN
    BEGIN

        IF(COALESCE(NEW.BASECALCULO_COFINS, 0) > 0 AND COALESCE(NEW.PERCENTUAL_COFINS, 0) = 0) THEN
        BEGIN
            EXCEPTION "..."'PERCENTUAL COFINS DO ITEM '||NEW.SEQUENCIA||' INVALIDO. ENTRE EM CONTATO COM O SUPORTE TECNICO';
        END
    END


END;
CREATE OR ALTER trigger ttbnfe_item_b02iu for tbnfe_item
active before insert or update position 0
AS
BEGIN
  IF(TRIM(NEW.TRIBUTACAO_PIS) = '01' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '02' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '50' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '51' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '52' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '53' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '54' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '55' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '56' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '60' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '61' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '62' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '63' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '64' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '65' OR
        TRIM(NEW.TRIBUTACAO_PIS) = '66') THEN
    BEGIN

        IF(COALESCE(NEW.BASECALCULO_PIS, 0) > 0 AND COALESCE(NEW.PERCENTUAL_PIS, 0) = 0) THEN
        BEGIN
            EXCEPTION "..."'PERCENTUAL PIS DO ITEM '||NEW.SEQUENCIA||' INVALIDO. ENTRE EM CONTATO COM O SUPORTE TECNICO';
        END
    END


    IF(TRIM(NEW.TRIBUTACAO_COFINS) = '01' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '02' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '50' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '51' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '52' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '53' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '54' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '55' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '56' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '60' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '61' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '62' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '63' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '64' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '65' OR
        TRIM(NEW.TRIBUTACAO_COFINS) = '66') THEN
    BEGIN

        IF(COALESCE(NEW.BASECALCULO_COFINS, 0) > 0 AND COALESCE(NEW.PERCENTUAL_COFINS, 0) = 0) THEN
        BEGIN
            EXCEPTION "..."'PERCENTUAL COFINS DO ITEM '||NEW.SEQUENCIA||' INVALIDO. ENTRE EM CONTATO COM O SUPORTE TECNICO';
        END
    END
END;