What happens if there is no invoices in the system? (you should use $this->InvoiceID = ($obj) ? $obj->InvoiceID+1: 1);
Also this way you've implemented will not check for duplicates of anything like that. You could just just the automatic primary $ID key that is defined on every DataObject. Check your php error logs for any other syntax issues that could be causing an issue.