A Work Permit means the employee is working for a specific company, and the company is liable for the employee as long as it is valid. When a foreign employee leaves, the work permit technically must be cancelled by the employer. Once the Work Permit Certificate of Cancellation is done, the employee must submit this to his new employer so the new work permit can be processed.
Once the work permit is cancelled, and your visa is about to expire, the employee (or with the help of the employer) can apply for a one (1) month exit visa. The purpose of this is to give the foreigner enough time to prepare to exit China.
Alternatively, if your visa is expiring and you've got a new legal employer in China...
When your new employer processes your work permit, they can also assist in getting you a temporary 30 day visa. This visa can be renewed until your work permit process is done.
If a residence permit (visa) is far from expiring, will cancelling the work permit also cancel the visa? I'm not sure. Some say visa stays valid until expiry date. Double check with your HR, these rules keep changing. If you know any info on this, contact us.