Invoice sequence help

Hello! I have a running instance of Invoice Plane. Whenever the latest invoice is deleted, I would like to subtract one so that when a new invoice is created it has the same id as the deleted one.

On mdl_invoices I have changed:

    public function delete($invoice_id)




and on mdl_invoice_groups:

        public function generate_invoice_number($invoice_group_id, $set_next = TRUE)
        $invoice_group = $this->get_by_id($invoice_group_id);

        $invoice_identifier = $this->parse_identifier_format(

        if ($set_next) {
	  else {


        return $invoice_identifier;

What am I doing wrong? Any ideas and/or suggestions?

Another valid solution would be chosing the highest existing id+1 as next id, but I have no idea how to do it.

Thanks in advance!