You can avoid this situation by selecting the Reject duplicate option in Accounts Receivable parameters. If, for any reason, the system assigns the same invoice number to different invoices, you will receive an error. In that case, you can fix the number sequence to prevent this from happening.