Move ticket number generation code to model