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)
    {

        **$this->load->model('invoice_groups/mdl_invoice_groups');**
        **$this->mdl_invoice_groups->generate_invoice_number($invoice_group_id,FALSE);**

        
        parent::delete($invoice_id);

        $this->load->helper('orphan');
        delete_orphans();
    }

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(
            $invoice_group->invoice_group_identifier_format,
            $invoice_group->invoice_group_next_id,
            $invoice_group->invoice_group_left_pad
        );

        if ($set_next) {
            $this->set_next_invoice_number($invoice_group_id);
        }
	  else {
		**$this->set_previous_invoice_number($invoice_group_id);**

	  }

        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!