The invoice numbering for sales seams to be flawed for suspended sales, and when in a multi-user environment.
Steps to reproduce multi-user problem:
1) create 2 users
2) in different browsers or machines start a sale
3) tick the box for create invoice on both users
4) provided both sales are active at the same time, the invoice number on both screens/browsers will be the same
5) complete the sale on one machine/browser
6) complete the sale on the second machine/browser
7) second machine will throw an error message about duplicate invoice number
steps to reproduce suspended sales error:
1) start a new sale
2) suspend the first sale
3) start a new second sale
4) suspend the second sale
5) second sale throws error about duplicate invoice number
it looks like this check for complete sale (sales.php line 234) is missing from the suspend function (sales.php line 484)
if ($this->sale_lib->is_invoice_number_enabled() && $this->Sale->invoice_number_exists($invoice_number))
As for the first problem, im thinking that the invoice number should be generated on sale completion like the POS number(sale_id) rather than at the start of sale. This then leads to the question that if the sale_id in unique and sequential, what is the need for the invoice number in the first place.
sale_id is a technical key. While invoice number can use any kind of numbering sequence. Rules for invoicing differ across countries ,eg in Europe you need to maintain a separate numbering scheme for sales to customers that don't need to pay taxes (as they pay it afterwards).
Good point on the multi user usecase Looks like your putting it to good use.