This fixes #8384.  I now check to see if the payperiod is marked done before setting the param, and I also wrap the delete/insert pair in a transaction, so that they both get done at the same time.