normally what my plugin do , my plugin store the last proforma ID generated in a row table , and every timea proforma is created it increment it with +1 . when new proforma is created , my plugin check if the proforma ID is the same as stored in database , if yes it increment the last proforma ID to +1 . is the proforma generated has ID not the same as the last stored ID , it correct it and increment the last proforma ID +1 .
is so simple , if the proforma created has returned to 0 , there two probability .
1- the last proforma invoice row are not exist
1- you have changed the value for this row in the admin tools setting .