eb8b0e2b6d507400534c28cdfbc245508490b5e9
[fa-stable.git] / gl / inquiry / accounts_list.php
1 <?php
2 /**********************************************************************
3   Page for searching GL account list and select it to GL account
4   selection in page that has GL account dropdown list.
5 ***********************************************************************/
6 $page_security = "SA_GLACCOUNT";
7 $path_to_root = "../..";
8 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/ui.inc");
10
11 $js = get_js_select_combo_item();
12
13 page(_($help_context = "GL Accounts"), true, false, "", $js);
14
15 if (isset($SysPrefs->max_rows_in_search))
16         $limit = $SysPrefs->max_rows_in_search;
17 else
18         $limit = 10;
19
20 // Activate Ajax on form submit
21 if(get_post("search")) {
22         $Ajax->activate("account_tbl");
23 }
24
25 // BEGIN: Filter form. Use query string so the client_id will not disappear
26 // after ajax form post.
27 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
28
29 start_table(TABLESTYLE_NOBORDER);
30
31 start_row();
32
33 text_cells(_("Description"), "description");
34 submit_cells("search", _("Search"), "", _("Search GL accounts"), "default");
35
36 end_row();
37
38 end_table();
39
40 end_form();
41 // END: Filter form
42
43 // BEGIN: Account list
44 div_start("account_tbl");
45
46 start_table(TABLESTYLE);
47
48 $th = array("", _("Account Code"), _("Description"), _("Category"));
49
50 table_header($th);
51
52 // Query based on function gl_all_accounts_list in includes/ui/ui_lists.inc.
53 $sql = "SELECT chart.account_code, chart.account_name, type.name
54                         FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
55                         WHERE chart.account_type=type.id
56         AND (
57           chart.account_name LIKE " . db_escape("%" . get_post("description"). "%") . " OR
58           chart.account_code LIKE " . db_escape("%" . get_post("description"). "%") . "
59         ) 
60         ORDER BY chart.account_code LIMIT 0, $limit"; // We only display 10 items.
61 $result = db_query($sql, "Failed in retreiving GL account list.");
62
63 $k = 0; //row colour counter
64 $name = $_GET["client_id"];
65 while ($myrow = db_fetch_assoc($result)) {
66         alt_table_row_color($k);
67         $value = $myrow['account_code'];
68         ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
69         label_cell($myrow["account_code"]);
70         label_cell($myrow["account_name"]);
71         label_cell($myrow["name"]);
72         end_row();
73 }
74
75 end_table(1);
76
77 div_end();
78 // END: Account list
79
80 end_page(true);