Cleanup in popup lists related files.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 9 Jan 2016 10:55:28 +0000 (11:55 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 9 Jan 2016 10:57:27 +0000 (11:57 +0100)
.gitignore
gl/includes/db/gl_db_accounts.inc
gl/inquiry/accounts_list.php
inventory/includes/db/items_db.inc
inventory/inquiry/stock_list.php
purchasing/includes/db/suppliers_db.inc
purchasing/inquiry/suppliers_list.php
sales/includes/db/branches_db.inc
sales/includes/db/customers_db.inc
sales/inquiry/customer_branches_list.php
sales/inquiry/customers_list.php

index ef755821e909a1506d442013d79517819beef0d0..12a5b6ddf0ec568d730a94b3d05eb834da88528a 100644 (file)
@@ -19,4 +19,3 @@ installed_extensions.php
 config.php
 config_db.php
 !index.php
-/gl/inquiry/accounts_list.php
index de487be2d4581a256929bad7e0901532c422dd9f..3244b176cfd701340d2838118dd3f5a626c12c50 100644 (file)
@@ -288,3 +288,24 @@ function is_bank_account($account_code)
        } else
                return false;
 }
+
+function get_chart_accounts_search($like)
+{
+       global $SysPrefs;
+
+       if (isset($SysPrefs->max_rows_in_search))
+               $limit = $SysPrefs->max_rows_in_search;
+       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.
+       return db_query($sql, "Failed in retreiving GL account list.");
+}
index 4c8354a18717699a86c2a9ca076423c8df8b94b6..e785557abc47e5ebf1bc4ff86e39fd50093e2415 100644 (file)
@@ -18,22 +18,17 @@ $page_security = "SA_GLACCOUNT";
 $path_to_root = "../..";
 include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/gl/includes/db/gl_db_accounts.inc");
 
 $js = get_js_select_combo_item();
 
 page(_($help_context = "GL Accounts"), true, false, "", $js);
 
-if (isset($SysPrefs->max_rows_in_search))
-       $limit = $SysPrefs->max_rows_in_search;
-else
-       $limit = 10;
-
-// Activate Ajax on form submit
 if(get_post("search")) {
        $Ajax->activate("account_tbl");
 }
 
-// BEGIN: Filter form. Use query string so the client_id will not disappear
+// Filter form. Use query string so the client_id will not disappear
 // after ajax form post.
 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
 
@@ -49,9 +44,7 @@ end_row();
 end_table();
 
 end_form();
-// END: Filter form
 
-// BEGIN: Account list
 div_start("account_tbl");
 
 start_table(TABLESTYLE);
@@ -60,19 +53,10 @@ $th = array("", _("Account Code"), _("Description"), _("Category"));
 
 table_header($th);
 
-// Query based on function gl_all_accounts_list in includes/ui/ui_lists.inc.
-$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("%" . get_post("description"). "%") . " OR
-          chart.account_code LIKE " . db_escape("%" . get_post("description"). "%") . "
-        ) 
-       ORDER BY chart.account_code LIMIT 0, $limit"; // We only display 10 items.
-$result = db_query($sql, "Failed in retreiving GL account list.");
-
-$k = 0; //row colour counter
+$k = 0;
 $name = $_GET["client_id"];
+
+$result = get_chart_accounts_search(get_post("description"));
 while ($myrow = db_fetch_assoc($result)) {
        alt_table_row_color($k);
        $value = $myrow['account_code'];
@@ -86,6 +70,4 @@ while ($myrow = db_fetch_assoc($result)) {
 end_table(1);
 
 div_end();
-// END: Account list
-
-end_page(true);
\ No newline at end of file
+end_page(true);
index b9b87b13fa21304d0b5eeda7bf17a57fb601d874..4c23ee0791c41f28b5cc7e14a7075055ac0ecc50 100644 (file)
@@ -158,7 +158,7 @@ function item_in_foreign_codes($stock_id)
                        $msg = $err; break;
                }
        }
-       if ($msg == '') {       
+       if ($msg == '') {
 
                $kits = get_where_used($stock_id);
                $num_kits = db_num_rows($kits);
@@ -178,3 +178,52 @@ function item_in_foreign_codes($stock_id)
        }
        return $msg;
 }
+
+function get_items_search($description, $type)
+{
+       global $SysPrefs;
+
+       $sql = "SELECT COUNT(i.item_code) AS kit, i.item_code, i.description, c.description category
+               FROM ".TB_PREF."stock_master s, ".TB_PREF."item_codes i
+                       LEFT JOIN ".TB_PREF."stock_category c ON i.category_id=c.category_id
+               WHERE i.stock_id=s.stock_id
+                       AND !i.inactive AND !s.inactive
+                       AND (  i.item_code LIKE " . db_escape("%" . $description. "%") . " OR 
+                               i.description LIKE " . db_escape("%" . get_post("description"). "%") . " OR 
+                               c.description LIKE " . db_escape("%" . get_post("description"). "%") . ") ";
+
+       switch ($type) {
+               case "sales":
+                       $sql .= " AND !s.no_sale AND mb_flag <> 'F'";
+                       break;
+               case "manufactured":
+                       $sql .= " AND mb_flag = 'M'";
+                       break;
+       case "purchasable":
+               $sql .= " AND NOT no_purchase AND mb_flag <> 'F' AND i.item_code=i.stock_id";
+               break;
+               case "costable":
+                       $sql .= " AND mb_flag <> 'D' AND mb_flag <> 'F' AND  i.item_code=i.stock_id";
+                       break;
+               case "component":
+                       $parent = $_GET['parent'];
+                       $sql .= " AND  i.item_code=i.stock_id AND i.stock_id <> '$parent' AND mb_flag <> 'F' ";
+                       break;
+               case "kits":
+                       $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag <> 'F'";
+                       break;
+               case "all":
+                       $sql .= " AND mb_flag <> 'F' AND i.item_code=i.stock_id";
+                       break;
+       }
+
+       if (isset($SysPrefs->max_rows_in_search))
+               $limit = $SysPrefs->max_rows_in_search;
+       else
+               $limit = 10;
+
+       $sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0,".(int)($limit);
+
+       return db_query($sql, "Failed in retreiving item list.");
+}
+
index 3aa9ec69467e15d4a6b3b6cda333b96553d09760..22884885081aadf82a9fcc8ae54da7bd7aa4e874 100644 (file)
@@ -18,6 +18,7 @@ $page_security = "SA_ITEM";
 $path_to_root = "../..";
 include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/inventory/includes/db/items_db.inc");
 
 $mode = get_company_pref('no_item_list');
 if ($mode != 0)
@@ -27,18 +28,10 @@ else
 
 page(_($help_context = "Items"), true, false, "", $js);
 
-if (isset($SysPrefs->max_rows_in_search))
-       $limit = $SysPrefs->max_rows_in_search;
-else
-       $limit = 10;
-
-// Activate Ajax on form submit
 if(get_post("search")) {
   $Ajax->activate("item_tbl");
 }
 
-// BEGIN: Filter form. Use query string so the client_id will not disappear
-// after ajax form post.
 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
 
 start_table(TABLESTYLE_NOBORDER);
@@ -53,70 +46,19 @@ end_row();
 end_table();
 
 end_form();
-// END: Filter form
 
-// BEGIN: Link to add new item
-// hyperlink_params($path_to_root . "/inventory/manage/items.php", _("Add new"), "popup=1");
-// END: Link to add new item
-
-// BEGIN: Item list
 div_start("item_tbl");
-
 start_table(TABLESTYLE);
 
 $th = array("", _("Item Code"), _("Description"), _("Category"));
-
 table_header($th);
 
-// Query based on function sales_items_list in includes/ui/ui_lists.inc.
-$sql = "SELECT COUNT(i.item_code) AS kit, i.item_code, i.description, c.description category
-  FROM ".TB_PREF."stock_master s, ".TB_PREF."item_codes i
-  LEFT JOIN ".TB_PREF."stock_category c
-    ON i.category_id=c.category_id
-  WHERE i.stock_id=s.stock_id
-    AND !i.inactive AND !s.inactive
-    AND (  i.item_code LIKE " . db_escape("%" . get_post("description"). "%") . " OR 
-         i.description LIKE " . db_escape("%" . get_post("description"). "%") . " OR 
-         c.description LIKE " . db_escape("%" . get_post("description"). "%") . ") ";
-
-$type = "";
-if (isset($_GET['type'])) {
-  $type = $_GET['type'];
-}
-
-switch ($type) {
-  case "sales":
-    $sql .= " AND !s.no_sale AND mb_flag <> 'F'";
-    break;
-  case "manufactured":
-    $sql .= " AND mb_flag = 'M'";
-    break;
-  case "purchasable":
-    $sql .= " AND NOT no_purchase AND mb_flag <> 'F' AND i.item_code=i.stock_id";
-    break;
-  case "costable":
-    $sql .= " AND mb_flag <> 'D' AND mb_flag <> 'F' AND  i.item_code=i.stock_id";
-    break;
-  case "component":
-       $parent = $_GET['parent'];
-    $sql .= " AND  i.item_code=i.stock_id AND i.stock_id <> '$parent' AND mb_flag <> 'F' ";
-    break;
-  case "kits":
-       $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id AND mb_flag <> 'F'";
-       break;
-  case "all":
-    $sql .= " AND mb_flag <> 'F' AND i.item_code=i.stock_id";
-    // NOTHING TO DO.
-    break;
-}
-
-$sql .= " GROUP BY i.item_code ORDER BY i.description LIMIT 0, $limit"; // We only display 10 items.
-
-$result = db_query($sql, "Failed in retreiving item list.");
-
-$k = 0; //row colour counter
+$k = 0;
 $name = $_GET["client_id"];
-while ($myrow = db_fetch_assoc($result)) {
+$result = get_items_search(get_post("description"), @$_GET['type']);
+
+while ($myrow = db_fetch_assoc($result))
+{
        alt_table_row_color($k);
        $value = $myrow['item_code'];
        if ($mode != 0) {
@@ -135,6 +77,4 @@ while ($myrow = db_fetch_assoc($result)) {
 end_table(1);
 
 div_end();
-// END: Item list
-
 end_page(true);
index 733f5b159b44e85a533abd245fa02dcabd893a0a..e0a1515042ac1f8cf6262cb93715428e953fa137 100644 (file)
@@ -190,3 +190,23 @@ function get_supplier_currency($supplier_id)
        return $myrow[0];
 }
 
+function get_suppliers_search($supplier)
+{
+       global $SysPrefs;
+
+       if (isset($SysPrefs->max_rows_in_search))
+               $limit = $SysPrefs->max_rows_in_search;
+       else
+               $limit = 10;
+
+       $sql = "SELECT supplier_id, supp_name, supp_ref, address, gst_no
+               FROM ".TB_PREF."suppliers
+               WHERE (supp_name LIKE " . db_escape("%" . $supplier. "%") . " OR 
+                       supp_ref LIKE " . db_escape("%" . $supplier. "%") . " OR 
+                       address LIKE " . db_escape("%" . $supplier. "%") . " OR 
+                       gst_no LIKE " . db_escape("%" . $supplier. "%") . ")
+               ORDER BY supp_name LIMIT 0,".(int)($limit);
+
+       return db_query($sql, "Failed in retreiving supplier list.");
+}
+
index 764ab7c9608964eeca0d81fbe2d8f39c4391185c..75c1395921d6839e003a5a9ceff9e9828e05522b 100644 (file)
@@ -18,6 +18,7 @@ $page_security = "SA_PURCHASEORDER";
 $path_to_root = "../..";
 include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/purchasing/includes/db/suppliers_db.inc");
 
 $mode = get_company_pref('no_supplier_list');
 if ($mode != 0)
@@ -27,18 +28,10 @@ else
 
 page(_($help_context = "Suppliers"), true, false, "", $js);
 
-if (isset($SysPrefs->max_rows_in_search))
-       $limit = $SysPrefs->max_rows_in_search;
-else
-       $limit = 10;
-
-// Activate Ajax on form submit
 if(get_post("search")) {
   $Ajax->activate("supplier_tbl");
 }
 
-// BEGIN: Filter form. Use query string so the client_id will not disappear
-// after ajax form post.
 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
 
 start_table(TABLESTYLE_NOBORDER);
@@ -53,13 +46,6 @@ end_row();
 end_table();
 
 end_form();
-// END: Filter form
-
-// BEGIN: Link to add new supplier
-// hyperlink_params($path_to_root . "/purchasing/manage/suppliers.php", _("Add new"), "popup=1");
-// END: Link to add new supplier
-
-// BEGIN: Supplier list
 div_start("supplier_tbl");
 
 start_table(TABLESTYLE);
@@ -68,17 +54,9 @@ $th = array("", _("Supplier"), _("Short Name"), _("Address"), _("Tax ID"));
 
 table_header($th);
 
-// Query based on function supplier_list in includes/ui/ui_lists.inc.
-$sql = "SELECT supplier_id, supp_name, supp_ref, address, gst_no FROM ".TB_PREF."suppliers
-  WHERE (supp_name LIKE " . db_escape("%" . get_post("supplier"). "%") . " OR 
-          supp_ref LIKE " . db_escape("%" . get_post("supplier"). "%") . " OR 
-           address LIKE " . db_escape("%" . get_post("supplier"). "%") . " OR 
-            gst_no LIKE " . db_escape("%" . get_post("supplier"). "%") . ")
-  ORDER BY supp_name LIMIT 0, $limit"; // We only display 10 items.
-$result = db_query($sql, "Failed in retreiving supplier list.");
-
-$k = 0; //row colour counter
+$k = 0;
 $name = $_GET["client_id"];
+$result = get_suppliers_search(get_post("supplier"));
 while ($myrow = db_fetch_assoc($result)) {
        alt_table_row_color($k);
        $value = $myrow['supplier_id'];
@@ -97,8 +75,5 @@ while ($myrow = db_fetch_assoc($result)) {
 }
 
 end_table(1);
-
 div_end();
-// END: Supplier list
-
 end_page(true);
index 48cd417de703c7b24330c604020ca15fb49c885f..e51de6f149234bd8004084fa8545d0f0919025ae 100644 (file)
@@ -267,3 +267,29 @@ function get_default_branch($customer_id, $ar_account=null)
        return db_fetch($result);
 }
 
+function  get_branches_search($customer, $branch)
+{
+       global $SysPrefs;
+
+       if (isset($SysPrefs->max_rows_in_search))
+               $limit = $SysPrefs->max_rows_in_search;
+       else
+               $limit = 10;
+
+       $sql = "SELECT 
+                   b.branch_code,
+               b.branch_ref,
+               b.br_name,
+               p.name as contact_name,
+                   p.phone
+               FROM ".TB_PREF."cust_branch b
+               LEFT JOIN ".TB_PREF."crm_contacts c
+                       ON c.entity_id=b.branch_code AND c.type='cust_branch' AND c.action='general'
+               LEFT JOIN ".TB_PREF."crm_persons p ON c.person_id=p.id
+               WHERE b.debtor_no = ".db_escape($customer)."
+                       AND b.br_name LIKE " . db_escape("%" . $branch. "%") . "
+               ORDER BY b.br_name LIMIT 0,".(int)($limit);
+
+       return db_query($sql, "Failed in retreiving branches list.");
+}
+
index 7e2eb891c8248a952981641a54acb095aa1daf8c..3b6ac6315cd0f86fce9f4fe26413520e8318f040 100644 (file)
@@ -195,3 +195,21 @@ function get_customer_currency($customer_id=null, $branch_id=null)
        return $myrow[0];
 }
 
+function get_customers_search($customer)
+{
+       global $SysPrefs;
+
+       if (isset($SysPrefs->max_rows_in_search))
+               $limit = $SysPrefs->max_rows_in_search;
+       else
+               $limit = 10;
+
+       $sql = "SELECT debtor_no, name, debtor_ref, address, tax_id FROM ".TB_PREF."debtors_master 
+         WHERE (  name LIKE " . db_escape("%" . $customer. "%") . " OR 
+                debtor_ref LIKE " . db_escape("%" . $customer. "%") . " OR 
+               address LIKE " . db_escape("%" . $customer. "%") . " OR 
+            tax_id LIKE " . db_escape("%" . $customer. "%").")
+         ORDER BY name LIMIT 0,".(int)($limit);
+
+       return db_query($sql, "Failed in retreiving customer list.");
+}
index 77f16bfd82fd7f10d9cae2843b446e5c3c660229..e5199def055133fb61804c91c6fdc5c975b3416b 100644 (file)
@@ -18,23 +18,16 @@ $page_security = "SA_SALESORDER";
 $path_to_root = "../..";
 include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/sales/includes/db/branches_db.inc");
 
 $js = get_js_select_combo_item();
 
-if (isset($SysPrefs->max_rows_in_search))
-       $limit = $SysPrefs->max_rows_in_search;
-else
-       $limit = 10;
-
 page(_($help_context = "Customer Branches"), true, false, "", $js);
 
-// Activate Ajax on form submit
 if(get_post("search")) {
   $Ajax->activate("customer_branch_tbl");
 }
 
-// BEGIN: Filter form. Use query string so the client_id will not disappear
-// after ajax form post.
 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
 
 start_table(TABLESTYLE_NOBORDER);
@@ -49,41 +42,17 @@ end_row();
 end_table();
 
 end_form();
-// END: Filter form
-
-// BEGIN: Link to add new customer branch
-// hyperlink_params($path_to_root . "/sales/manage/customer_branches.php", _("Add new"), "debtor_no=" . strip_tags($_GET["SelectedBranch"]) . "&popup=1");
-// END: Link to add new customer branch
 
-// BEGIN: Customer branches list
 div_start("customer_branch_tbl");
-
 start_table(TABLESTYLE);
 
 $th = array("", _("Ref"), _("Branch"), _("Contact"), _("Phone"));
 
 table_header($th);
 
-// Query based on function get_sql_for_customer_branches in includes/db/branches_db.inc.
-$sql = "SELECT 
-    b.branch_code,
-    b.branch_ref,
-    b.br_name,
-    p.name as contact_name,
-    p.phone
-  FROM ".TB_PREF."cust_branch b
-  LEFT JOIN ".TB_PREF."crm_contacts c
-    ON c.entity_id=b.branch_code AND c.type='cust_branch' AND c.action='general'
-  LEFT JOIN ".TB_PREF."crm_persons p
-    on c.person_id=p.id
-  WHERE b.debtor_no = ".db_escape($_GET["customer_id"])."
-    AND b.br_name LIKE " . db_escape("%" . get_post("branch"). "%") . "
-  ORDER BY b.br_name LIMIT 0, $limit"; // We only display 10 items.
-
-$result = db_query($sql, "Failed in retreiving branches list.");
-
-$k = 0; //row colour counter
+$k = 0;
 $name = $_GET["client_id"];
+$result = get_branches_search($_GET["customer_id"], get_post("branch"));
 while ($myrow = db_fetch_assoc($result))
 {
        alt_table_row_color($k);
@@ -99,6 +68,4 @@ while ($myrow = db_fetch_assoc($result))
 end_table(1);
 
 div_end();
-// END: Customer list
-
 end_page(true);
index 99a80c40ea1bda859f29236ceadcbc07332f9585..b6c7df97221dce08e08899db9ab317aaedb7b140 100644 (file)
@@ -18,6 +18,7 @@ $page_security = "SA_SALESORDER";
 $path_to_root = "../..";
 include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/sales/includes/db/customers_db.inc");
 
 $mode = get_company_pref('no_customer_list');
 if ($mode != 0)
@@ -27,18 +28,10 @@ else
 
 page(_($help_context = "Customers"), true, false, "", $js);
 
-if (isset($SysPrefs->max_rows_in_search))
-       $limit = $SysPrefs->max_rows_in_search;
-else
-       $limit = 10;
-
-// Activate Ajax on form submit
 if(get_post("search")) {
   $Ajax->activate("customer_tbl");
 }
 
-// BEGIN: Filter form. Use query string so the client_id will not disappear
-// after ajax form post.
 start_form(false, false, $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);
 
 start_table(TABLESTYLE_NOBORDER);
@@ -53,13 +46,7 @@ end_row();
 end_table();
 
 end_form();
-// END: Filter form
-
-// BEGIN: Link to add new customer
-// hyperlink_params($path_to_root . "/sales/manage/customers.php", _("Add new"), "popup=1");
-// END: Link to add new customer
 
-// BEGIN: Customer list
 div_start("customer_tbl");
 
 start_table(TABLESTYLE);
@@ -68,18 +55,9 @@ $th = array("", _("Customer"), _("Short Name"), _("Address"), _("Tax ID"));
 
 table_header($th);
 
-// Query based on function customer_list in includes/ui/ui_lists.inc.
-
-$sql = "SELECT debtor_no, name, debtor_ref, address, tax_id FROM ".TB_PREF."debtors_master 
-  WHERE (  name LIKE " . db_escape("%" . get_post("customer"). "%") . " OR 
-     debtor_ref LIKE " . db_escape("%" . get_post("customer"). "%") . " OR 
-        address LIKE " . db_escape("%" . get_post("customer"). "%") . " OR 
-         tax_id LIKE " . db_escape("%" . get_post("customer") . "%").")
-  ORDER BY name LIMIT 0, $limit"; // We only display 10 items.
-$result = db_query($sql, "Failed in retreiving customer list.");
-
-$k = 0; //row colour counter
+$k = 0;
 $name = $_GET["client_id"];
+$result = get_customers_search(get_post("customer"));
 while ($myrow = db_fetch_assoc($result)) {
        alt_table_row_color($k);
        $value = $myrow['debtor_no'];
@@ -100,6 +78,5 @@ while ($myrow = db_fetch_assoc($result)) {
 end_table(1);
 
 div_end();
-// END: Customer list
 
 end_page(true);