Create Orders, and Invoices in 15.1.3

I'm using version 15.1.3 and trying to create an order and an invoice but not very familiar with these iBO's for the CINVOICE , how does it generate the next REFERENCE_NUM and save?  Also, I was not sure which iBO to use to write to the Orders table, I've looked at COrder and CStandardOrder but still not sure how I would generate the next ORDER_NUMBER. 

 

Thanks in advance!