Enabling popup search in Customers, branches, suppliers, inventory, fixed assets...
[fa-stable.git] / sales / inquiry / customer_branches_list.php
1 <?php
2 /**********************************************************************
3   Page for searching item list and select it to item selection
4   in sales order and purchase order.
5 ***********************************************************************/
6 $page_security = "SA_SALESORDER";
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 if (isset($SysPrefs->max_rows_in_search))
14         $limit = $SysPrefs->max_rows_in_search;
15 else
16         $limit = 10;
17
18 page(_($help_context = "Customer Branches"), true, false, "", $js);
19
20 // Activate Ajax on form submit
21 if(get_post("search")) {
22   $Ajax->activate("customer_branch_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(_("Branch"), "branch");
34 submit_cells("search", _("Search"), "", _("Search branches"), "default");
35
36 end_row();
37
38 end_table();
39
40 end_form();
41 // END: Filter form
42
43 // BEGIN: Link to add new customer branch
44 // hyperlink_params($path_to_root . "/sales/manage/customer_branches.php", _("Add new"), "debtor_no=" . strip_tags($_GET["SelectedBranch"]) . "&popup=1");
45 // END: Link to add new customer branch
46
47 // BEGIN: Customer branches list
48 div_start("customer_branch_tbl");
49
50 start_table(TABLESTYLE);
51
52 $th = array("", _("Ref"), _("Branch"), _("Contact"), _("Phone"));
53
54 table_header($th);
55
56 // Query based on function get_sql_for_customer_branches in includes/db/branches_db.inc.
57 $sql = "SELECT 
58     b.branch_code,
59     b.branch_ref,
60     b.br_name,
61     p.name as contact_name,
62     p.phone
63   FROM ".TB_PREF."cust_branch b
64   LEFT JOIN ".TB_PREF."crm_contacts c
65     ON c.entity_id=b.branch_code AND c.type='cust_branch' AND c.action='general'
66   LEFT JOIN ".TB_PREF."crm_persons p
67     on c.person_id=p.id
68   WHERE b.debtor_no = ".db_escape($_GET["customer_id"])."
69     AND b.br_name LIKE " . db_escape("%" . get_post("branch"). "%") . "
70   ORDER BY b.br_name LIMIT 0, $limit"; // We only display 10 items.
71
72 $result = db_query($sql, "Failed in retreiving branches list.");
73
74 $k = 0; //row colour counter
75 $name = $_GET["client_id"];
76 while ($myrow = db_fetch_assoc($result))
77 {
78         alt_table_row_color($k);
79         $value = $myrow['branch_code'];
80         ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
81         label_cell($myrow["branch_ref"]);
82         label_cell($myrow["br_name"]);
83         label_cell($myrow["contact_name"]);
84         label_cell($myrow["phone"]);
85         end_row();
86 }
87
88 end_table(1);
89
90 div_end();
91 // END: Customer list
92
93 end_page(true);