Agent gets boilerplate from publisher and improves contract terms. Author is usually consulted at this point. When agent is happy, contract is sent to author. Author queries agent if anything not understood. Author writes book.
Editorial process begins for fiction author who has already written book.
Author delivers on time. Publisher line edits. Queries are sent to author. Editor reviews and, if corrections, input onto disk. Publisher decides, based on advance sales, advance paid, etc. how many to print.