My answer is not what you expect, but I have to make it.
In most countries around the world, the invoice number has to be unique, but only within the emitting company.
In some countries, invoice numbers are strongly regulated (especially with regard to sequentiality and absence of unused numbers between consecutive invoices). In some other countries it is not, but in case of a tax control, the controller will be very suspicious about holes within one company.
This is why it is completely normal to have duplicates if you only look at the invoice numbers. Uniqueness is only to be guaranteed for a pair of
invoice_number. So in reports, you either need to display both with the appropriate sorting, or ask the user for which company the report is.
If you want to work internally with a globally unique number, just use your existing
id field and let it be populated automatically by your db.
Another approach can be used for ensuring unique numbers globally: use different number ranges for different companies. This is usually well understood by tax controllers, as long as numbers are still sequential within one range. A variant thereof is to implicitly determine the number range based on the
company_id * 1000000 + sequential counter). Then you need to ensure that no number range is overflown. (Again, tax controllers usually understand if there's one break in the numbering if the numbering scheme is changed and the change is well documented).