Loop on each contract. If it is a paid contract, and there is no unpaid invoice for contract, and line not suspended and end date <= today - 1 day (so expired, we must be sure to make renewal after generation of invoice with 2 chances of invoice generation to not make renewal if payment error), we update qty on contract + qty on linked template invoice + the running contract service end date to end at next period