function cw_accounting_get_record($record_id)
{
    global $tables;
    $rec = cw_query_first("select * from {$tables['accounting_records']} where accounting_record_id='{$record_id}'");
    cw_accounting_assign_info($rec);
    return $rec;
}
}
if ($data['saldo'] == 1) {
    $where[] = "{$tables['accounting_records']}.total < 0";
} elseif ($data['saldo'] == 2) {
    $where[] = "{$tables['accounting_records']}.total >= 0";
}
if ($data['customer_id']) {
    $where[] = "{$tables['accounting_records']}.customer_id='{$data['customer_id']}'";
}
if ($data['group']) {
    $fields[] = "{$tables['accounting_categories']}.category as descr";
    $fields[] = "sum({$tables['accounting_records']}.total) as total";
    $groupbys[] = "{$tables['accounting_categories']}.accounting_category_id";
}
$orderbys[] = "{$tables['accounting_records']}.date asc";
$search_query_count = cw_db_generate_query('count(*)', $from_tbls, $query_joins, $where, $groupbys, $having, array(), 0);
$search_query = cw_db_generate_query($fields, $from_tbls, $query_joins, $where, $groupbys, $having, $orderbys);
$_res = db_query($search_query_count);
$total_items = db_num_rows($_res);
db_free_result($_res);
$navigation = cw_core_get_navigation($target, $total_items, $page);
if ($total_items > 0) {
    $search_query .= " LIMIT {$navigation['first_page']}, {$navigation['objects_per_page']}";
    $records = cw_query($search_query);
    if (is_array($records)) {
        foreach ($records as $k => $v) {
            cw_accounting_assign_info($records[$k]);
        }
    }
    $smarty->assign('records', $records);
}