Bug fixing in distinct function on gates, appointments and invoices