CREATE OR ALTER TRIGGER TBPDV_CONFERENCIA_B03I FOR TBPDV_CONFERENCIA
ACTIVE BEFORE INSERT POSITION 3
AS

BEGIN

    /* MODO ONLINE */
    IF(NEW.AMBIENTE = 1) THEN
    BEGIN
        NEW.SINCRONIZADO = 1;
        NEW.AMBIENTE = 1;

        IF(COALESCE(NEW.IMP_CODIGO, '') = '') THEN
        BEGIN
           NEW.IMP_CODIGO = FN_LPAD(NEW.ID, 10, '0')||'_I';
        END

    END

END;


CREATE OR ALTER TRIGGER TTBPDV_CONFERENCIA_BIUD998 FOR TBPDV_CONFERENCIA
ACTIVE AFTER INSERT OR UPDATE OR DELETE POSITION 998
AS
BEGIN
  IF(INSERTING) THEN
  BEGIN
    IF(NEW.AMBIENTE = 1) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_CONFERENCIA', NEW.ID, 2);
    END

  END ELSE
  BEGIN
    IF(OLD.AMBIENTE = 1) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_CONFERENCIA', OLD.ID, 2);
    END
  END

END;