SET TERM ^ ;

CREATE OR ALTER trigger ttbconciliacao_cartao_b02i for tbconciliacao_cartao
active before insert position 2
AS
BEGIN
  IF(TRIM(NEW.CODIGO_AUTORIZACAO) = '' OR TRIM(NEW.CODIGO_AUTORIZACAO) = '0' OR COALESCE(NEW.CODIGO_AUTORIZACAO,'') = '')THEN
  BEGIN
     NEW.CODIGO_AUTORIZACAO = NEW.NSU;
  END

  IF(coalesce(NEW.valor_original,0.0000) = 0.0000)THEN
  BEGIN
     NEW.VALOR_ORIGINAL = NEW.valor;
  END

  IF(coalesce(NEW.tarifa_original,0.0000) = 0.0000)THEN
  BEGIN
     NEW.tarifa_original = NEW.desconto1;
  END
END^

CREATE OR ALTER trigger ttbconcil_cartao_parcelas_b01i for tbconciliacao_cartao_parcelas
active before insert position 0
as
begin
  if (new.id is null) then
  BEGIN
    new.id = gen_id(gtbconcili_cartao_parcela,1);
  END

  IF(coalesce(NEW.valor_original,0.0000) = 0.0000)THEN
  BEGIN
     NEW.VALOR_ORIGINAL = NEW.valor;
  END

  IF(coalesce(NEW.tarifa_original,0.0000) = 0.0000)THEN
  BEGIN
     NEW.tarifa_original = NEW.desconto1;
  END

  IF(coalesce(NEW.valor_liq_original,0.0000) = 0.0000)THEN
  BEGIN
     NEW.valor_liq_original = NEW.valor_liquido;
  END
end
^ SET TERM ; ^