4811: magnifying glass select on deposits/payments erroneously shows bank account...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 19 Dec 2018 10:56:34 +0000 (11:56 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 19 Dec 2018 10:56:34 +0000 (11:56 +0100)
gl/includes/db/gl_db_accounts.inc
gl/inquiry/accounts_list.php
includes/ui/ui_lists.inc

index 6ee9938236531c36167bf7882ddfbe117a03d053..6bc73abd9d03234c437d1f6932a85885f83015dc 100644 (file)
@@ -289,7 +289,7 @@ function is_bank_account($account_code)
                return false;
 }
 
-function get_chart_accounts_search($like)
+function get_chart_accounts_search($like, $skip=false)
 {
        global $SysPrefs;
 
@@ -298,14 +298,20 @@ function get_chart_accounts_search($like)
        else
                $limit = 10;
 
-
-       $sql = "SELECT chart.account_code, chart.account_name, type.name
-                       FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
-                       WHERE chart.account_type=type.id
-        AND (
-          chart.account_name LIKE " . db_escape("%" . $like. "%") . " OR
-          chart.account_code LIKE " . db_escape("%" . $like. "%") . "
-        ) 
-       ORDER BY chart.account_code LIMIT 0,".(int)($limit); // We only display 10 items.
+       if ($skip)
+               $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
+                       FROM (".TB_PREF."chart_master chart,".TB_PREF."chart_types type) "
+                       ."LEFT JOIN ".TB_PREF."bank_accounts acc "
+                       ."ON chart.account_code=acc.account_code
+                               WHERE acc.account_code  IS NULL
+                       AND chart.account_type=type.id ";
+       else            
+               $sql = "SELECT chart.account_code, chart.account_name, type.name, chart.inactive, type.id
+                       FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type WHERE chart.account_type=type.id ";
+       $sql .= "AND (
+               chart.account_name LIKE " . db_escape("%" . $like. "%") . " OR
+               chart.account_code LIKE " . db_escape("%" . $like. "%") . "
+               ) 
+               ORDER BY chart.account_code LIMIT 0,".(int)($limit); // We only display 10 items.
        return db_query($sql, "Failed in retreiving GL account list.");
 }
index e785557abc47e5ebf1bc4ff86e39fd50093e2415..a9174c58fd3c8cc2ae70bb64488028a374e3131a 100644 (file)
@@ -55,8 +55,9 @@ table_header($th);
 
 $k = 0;
 $name = $_GET["client_id"];
+$skip = $_GET["skip"];
 
-$result = get_chart_accounts_search(get_post("description"));
+$result = get_chart_accounts_search(get_post("description"), $skip);
 while ($myrow = db_fetch_assoc($result)) {
        alt_table_row_color($k);
        $value = $myrow['account_code'];
index 0bc9ca0b92f7264bf116843358655e6d1c5b7504..5b6387f644dc4fe37eabdf5f10903ee99f1ed90e 100644 (file)
@@ -345,7 +345,9 @@ $opts = array(              // default options
                                $img_title = _("Search suppliers");
                                break;
                        case "account":
-                               $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&client_id=" . $id;
+                       case "account2";
+                               $skip = strtolower($type) == "account" ? false : true;
+                               $link = $path_to_root . "/gl/inquiry/accounts_list.php?popup=1&skip=".$skip."&client_id=" . $id;
                                $img_title = _("Search GL accounts");
                                break;
                }
@@ -1822,7 +1824,7 @@ function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=fals
                        FROM ".TB_PREF."chart_master chart,".TB_PREF."chart_types type
                        WHERE chart.account_type=type.id";
        if ($type_id ) $sql .= " AND chart.account_type=".db_escape($type_id);
-
+       $account = ($skip_bank_accounts ? "account2" : "account");
        return combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name',
                array(
                        'format' => '_format_account',
@@ -1839,7 +1841,7 @@ function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=fals
                        'async' => false,
                        'category' => 2,
                        'show_inactive' => $all
-               ), "account" );
+               ), $account );
 }
 
 function _format_account($row)