The identation is not right, making it harder to read. Moreover, here you are changing the behaviour after completing a sale. Instead of going back to the new sale page, you are redirecting to "/sales" or "/pending_day_sales". Is this something the client asked for?