Credited forum user bogeyman2007 for popup search lists and making it GPL3
[fa-stable.git] / sales / inquiry / customer_branches_list.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 /**********************************************************************
13   Page for searching customer branch list and select it to customer
14   branch selection in pages that have the customer branch dropdown lists.
15   Author: bogeyman2007 from Discussion Forum. Modified by Joe Hunt
16 ***********************************************************************/
17 $page_security = "SA_SALESORDER";
18 $path_to_root = "../..";
19 include_once($path_to_root . "/includes/session.inc");
20 include_once($path_to_root . "/includes/ui.inc");
21
22 $js = get_js_select_combo_item();
23
24 if (isset($SysPrefs->max_rows_in_search))
25         $limit = $SysPrefs->max_rows_in_search;
26 else
27         $limit = 10;
28
29 page(_($help_context = "Customer Branches"), true, false, "", $js);
30
31 // Activate Ajax on form submit
32 if(get_post("search")) {
33   $Ajax->activate("customer_branch_tbl");
34 }
35
36 // BEGIN: Filter form. Use query string so the client_id will not disappear
37 // after ajax form post.
38 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
39
40 start_table(TABLESTYLE_NOBORDER);
41
42 start_row();
43
44 text_cells(_("Branch"), "branch");
45 submit_cells("search", _("Search"), "", _("Search branches"), "default");
46
47 end_row();
48
49 end_table();
50
51 end_form();
52 // END: Filter form
53
54 // BEGIN: Link to add new customer branch
55 // hyperlink_params($path_to_root . "/sales/manage/customer_branches.php", _("Add new"), "debtor_no=" . strip_tags($_GET["SelectedBranch"]) . "&popup=1");
56 // END: Link to add new customer branch
57
58 // BEGIN: Customer branches list
59 div_start("customer_branch_tbl");
60
61 start_table(TABLESTYLE);
62
63 $th = array("", _("Ref"), _("Branch"), _("Contact"), _("Phone"));
64
65 table_header($th);
66
67 // Query based on function get_sql_for_customer_branches in includes/db/branches_db.inc.
68 $sql = "SELECT 
69     b.branch_code,
70     b.branch_ref,
71     b.br_name,
72     p.name as contact_name,
73     p.phone
74   FROM ".TB_PREF."cust_branch b
75   LEFT JOIN ".TB_PREF."crm_contacts c
76     ON c.entity_id=b.branch_code AND c.type='cust_branch' AND c.action='general'
77   LEFT JOIN ".TB_PREF."crm_persons p
78     on c.person_id=p.id
79   WHERE b.debtor_no = ".db_escape($_GET["customer_id"])."
80     AND b.br_name LIKE " . db_escape("%" . get_post("branch"). "%") . "
81   ORDER BY b.br_name LIMIT 0, $limit"; // We only display 10 items.
82
83 $result = db_query($sql, "Failed in retreiving branches list.");
84
85 $k = 0; //row colour counter
86 $name = $_GET["client_id"];
87 while ($myrow = db_fetch_assoc($result))
88 {
89         alt_table_row_color($k);
90         $value = $myrow['branch_code'];
91         ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "'.$name.'", "'.$value.'")');
92         label_cell($myrow["branch_ref"]);
93         label_cell($myrow["br_name"]);
94         label_cell($myrow["contact_name"]);
95         label_cell($myrow["phone"]);
96         end_row();
97 }
98
99 end_table(1);
100
101 div_end();
102 // END: Customer list
103
104 end_page(true);