How can I retrieve next usable sales order number via the SOTAMAS90 DSN?

We are running v4.50.5.0. 

I am currently using php to compile new sales orders data from Ebay, PayPal, OpenCart etc then connect to the DSN and query SO_SalesOrderHeader and AR_InvoiceHistoryHeader to retrieve the last # in the 08XXXXX range which we use to identify online orders.

This works well to obtain the next # for VI import jobs except it seems when somebody deletes a sales order and no more orders are manually entered before the VI import.

The deleted order numbers no longer appear in either table but are still unavailable as a usable SO#. Is there another table which contains a complete # history including deleted orders that I can use as a source instead?