From: Janusz Dobrowolski Date: Sat, 9 Jan 2016 10:55:28 +0000 (+0100) Subject: Cleanup in popup lists related files. X-Git-Tag: v2.4.2~19^2~79 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=6ae3ba12f80c3bc2f55eec4483d5c3d6bf00c558 Cleanup in popup lists related files. --- diff --git a/.gitignore b/.gitignore index ef755821..12a5b6dd 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,3 @@ installed_extensions.php config.php config_db.php !index.php -/gl/inquiry/accounts_list.php diff --git a/gl/includes/db/gl_db_accounts.inc b/gl/includes/db/gl_db_accounts.inc index de487be2..3244b176 100644 --- a/gl/includes/db/gl_db_accounts.inc +++ b/gl/includes/db/gl_db_accounts.inc @@ -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."); +} diff --git a/gl/inquiry/accounts_list.php b/gl/inquiry/accounts_list.php index 4c8354a1..e785557a 100644 --- a/gl/inquiry/accounts_list.php +++ b/gl/inquiry/accounts_list.php @@ -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); diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index b9b87b13..4c23ee07 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -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."); +} + diff --git a/inventory/inquiry/stock_list.php b/inventory/inquiry/stock_list.php index 3aa9ec69..22884885 100644 --- a/inventory/inquiry/stock_list.php +++ b/inventory/inquiry/stock_list.php @@ -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); diff --git a/purchasing/includes/db/suppliers_db.inc b/purchasing/includes/db/suppliers_db.inc index 733f5b15..e0a15150 100644 --- a/purchasing/includes/db/suppliers_db.inc +++ b/purchasing/includes/db/suppliers_db.inc @@ -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."); +} + diff --git a/purchasing/inquiry/suppliers_list.php b/purchasing/inquiry/suppliers_list.php index 764ab7c9..75c13959 100644 --- a/purchasing/inquiry/suppliers_list.php +++ b/purchasing/inquiry/suppliers_list.php @@ -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); diff --git a/sales/includes/db/branches_db.inc b/sales/includes/db/branches_db.inc index 48cd417d..e51de6f1 100644 --- a/sales/includes/db/branches_db.inc +++ b/sales/includes/db/branches_db.inc @@ -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."); +} + diff --git a/sales/includes/db/customers_db.inc b/sales/includes/db/customers_db.inc index 7e2eb891..3b6ac631 100644 --- a/sales/includes/db/customers_db.inc +++ b/sales/includes/db/customers_db.inc @@ -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."); +} diff --git a/sales/inquiry/customer_branches_list.php b/sales/inquiry/customer_branches_list.php index 77f16bfd..e5199def 100644 --- a/sales/inquiry/customer_branches_list.php +++ b/sales/inquiry/customer_branches_list.php @@ -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); diff --git a/sales/inquiry/customers_list.php b/sales/inquiry/customers_list.php index 99a80c40..b6c7df97 100644 --- a/sales/inquiry/customers_list.php +++ b/sales/inquiry/customers_list.php @@ -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);