$trans_ref = $db_info[3];
$trans_date = $db_info[4];
- $sql = "SELECT DISTINCT t.$trans_no_name as trans_no";
+ $sql = "SELECT t.$trans_no_name as trans_no";
if ($trans_ref)
$sql .= " ,t.$trans_ref as ref ";
}
elseif ($type_name != null)
$sql .= " AND t.`$type_name` = ".db_escape($filtertype);
-
- $sql .= " ORDER BY t.$trans_no_name";
+ // the ugly hack below is necessary to exclude old gl_trans records lasting after edition,
+ // otherwise old data transaction can be retrieved instead of current one.
+ if ($table_name==TB_PREF.'gl_trans')
+ $sql .= " AND t.`amount` <> 0";
+
+ $sql .= " GROUP BY ".($type_name ? "t.$type_name," : '')." t.$trans_no_name";
+ $sql .= " ORDER BY t.$trans_no_name";
return $sql;
}