Are you using the new method of pattern based document numbering or is it based on the old v2.3 method?
File: admin/db/transactions_db.inc line 183+:
function get_systype_db_info($type)
{
switch ($type)
{
case ST_JOURNAL : return array(TB_PREF."journal", "type", "trans_no", "reference", "tran_date");
case ST_BANKPAYMENT : return array(TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
..
..
File: includes/references.inc Line 183:
$db_info = get_systype_db_info($type);
## For a Journal entry, it will be:
## $_db_info = array(TB_PREF."journal", "type", "trans_no", "reference", "tran_date");
Line 170+ in the same file:
$sql = "SELECT MAX(CAST(SUBSTR($ref_fld, ".(strlen($prefix)+1).",LENGTH($ref_fld)-".(strlen($postfix)+strlen($prefix)).") AS UNSIGNED))"
." FROM `$trans_table` tbl
LEFT JOIN ".TB_PREF."voided v ON tbl.`$tno_fld`=v.id AND v.type=$type"
." WHERE ISNULL(v.id)"
.($type_fld ? " AND tbl.`$type_fld`=$type" : '')
." AND `$ref_fld` REGEXP ".db_escape('^'.preg_quote($prefix).'[0-9]*'.preg_quote($postfix).'$');
@joe: anything wrong here?