Topic: [SOLVED]: sales_orders.type=0 not in Template Invoice listing
Sales => Template Invoice
If we had earlier entered a Direct Invoice, then sales_orders.type=0 and will not display it in the Invoice Template listing.
This is due to line 503-504 in sales/includes/db/sales_order_db.inc:
elseif ($filter=='InvoiceTemplates' || $filter=='DeliveryTemplates')
$sql .= " AND sorder.type=1";
Is this the intended functionality?
What are the possible values of the sales_orders.type field and what do they indicate?
Even a fresh sales order results in sales_orders.type field being 0.
Also if a direct invoice is entered, the Invoice id is incremented but the Sales Order number is not incremented as seen in the Setup => Forms Setup screen. When the next sales order entry is made, the Sales Order number is incremented from it's old wrong value and hence remains wrong in the Setup => Forms Setup display.
Hence the next_reference field in the sys_types table can easily become out of sync with actuals. Instead of incrementing the values in the next_reference field, it is better to use the last_insert_id() + 1 or take max of field from appropriate table's primary key.