diff --git a/admin/gl_setup.php b/admin/gl_setup.php index aeae18d98..198a67803 100644 --- a/admin/gl_setup.php +++ b/admin/gl_setup.php @@ -13,7 +13,11 @@ $path_to_root=".."; include($path_to_root . "/includes/session.inc"); -page(_($help_context = "System and General GL Setup")); +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + +page(_($help_context = "System and General GL Setup"), false, false, "", $js); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); diff --git a/frontaccounting.php b/frontaccounting.php index 2da5fe9fe..e75ac4073 100644 --- a/frontaccounting.php +++ b/frontaccounting.php @@ -1,89 +1,97 @@ . ***********************************************************************/ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_to_root'])) die("Restricted access"); - include_once($path_to_root . '/applications/application.php'); - include_once($path_to_root . '/applications/customers.php'); - include_once($path_to_root . '/applications/suppliers.php'); - include_once($path_to_root . '/applications/inventory.php'); - include_once($path_to_root . '/applications/manufacturing.php'); - include_once($path_to_root . '/applications/dimensions.php'); - include_once($path_to_root . '/applications/generalledger.php'); - include_once($path_to_root . '/applications/setup.php'); - include_once($path_to_root . '/installed_extensions.php'); +include_once($path_to_root . '/applications/application.php'); +include_once($path_to_root . '/applications/customers.php'); +include_once($path_to_root . '/applications/suppliers.php'); +include_once($path_to_root . '/applications/inventory.php'); +include_once($path_to_root . '/applications/manufacturing.php'); +include_once($path_to_root . '/applications/dimensions.php'); +include_once($path_to_root . '/applications/generalledger.php'); +include_once($path_to_root . '/applications/setup.php'); +include_once($path_to_root . '/installed_extensions.php'); - class front_accounting - { - var $user; - var $settings; - var $applications; - var $selected_application; +class front_accounting + { + var $user; + var $settings; + var $applications; + var $selected_application; - var $menu; + var $menu; - function front_accounting() - { - } - function add_application(&$app) - { - if ($app->enabled) // skip inactive modules - $this->applications[$app->id] = &$app; - } - function get_application($id) - { - if (isset($this->applications[$id])) - return $this->applications[$id]; - return null; - } - function get_selected_application() - { - if (isset($this->selected_application)) - return $this->applications[$this->selected_application]; - foreach ($this->applications as $application) - return $application; - return null; - } - function display() - { - global $path_to_root; - - include_once($path_to_root . "/themes/".user_theme()."/renderer.php"); + function front_accounting() + { + } - $this->init(); - $rend = new renderer(); - $rend->wa_header(); + function add_application(&$app) + { + if ($app->enabled) // skip inactive modules + $this->applications[$app->id] = &$app; + } + function get_application($id) + { + if (isset($this->applications[$id])) + return $this->applications[$id]; + return null; + } - $rend->display_applications($this); + function get_selected_application() + { + if (isset($this->selected_application)) + return $this->applications[$this->selected_application]; + foreach ($this->applications as $application) + return $application; + return null; + } - $rend->wa_footer(); - $this->renderer =& $rend; - } - function init() - { + function display() + { + global $path_to_root; + + include_once($path_to_root . "/themes/".user_theme()."/renderer.php"); - $this->menu = new menu(_("Main Menu")); - $this->menu->add_item(_("Main Menu"), "index.php"); - $this->menu->add_item(_("Logout"), "/account/access/logout.php"); - $this->applications = array(); - $this->add_application(new customers_app()); - $this->add_application(new suppliers_app()); - $this->add_application(new inventory_app()); - $this->add_application(new manufacturing_app()); - $this->add_application(new dimensions_app()); - $this->add_application(new general_ledger_app()); + $this->init(); + $rend = new renderer(); + $rend->wa_header(); - hook_invoke_all('install_tabs', $this); + $rend->display_applications($this); - $this->add_application(new setup_app()); + $rend->wa_footer(); + $this->renderer =& $rend; + } + + function init() + { + # Destroy BOM session to make sure we start from empty BOM session. + if (isset($_SESSION['bom_session'])) + { + unset($_SESSION['bom_session']); } + + $this->menu = new menu(_("Main Menu")); + $this->menu->add_item(_("Main Menu"), "index.php"); + $this->menu->add_item(_("Logout"), "/account/access/logout.php"); + $this->applications = array(); + $this->add_application(new customers_app()); + $this->add_application(new suppliers_app()); + $this->add_application(new inventory_app()); + $this->add_application(new manufacturing_app()); + $this->add_application(new dimensions_app()); + $this->add_application(new general_ledger_app()); + + hook_invoke_all('install_tabs', $this); + + $this->add_application(new setup_app()); + } } -?> \ No newline at end of file diff --git a/gl/inquiry/accounts_list.php b/gl/inquiry/accounts_list.php new file mode 100644 index 000000000..2d2f7afbe --- /dev/null +++ b/gl/inquiry/accounts_list.php @@ -0,0 +1,76 @@ +activate("account_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); + +start_row(); + +text_cells(_("Description"), "description"); +submit_cells("search", _("Search"), "", _("Search GL accounts"), "default"); + +end_row(); + +end_table(); + +end_form(); +// END: Filter form + +// BEGIN: Account list +div_start("account_tbl"); + +start_table(TABLESTYLE); + +$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 = " . db_escape(get_post("description")) . " + ) + ORDER BY chart.account_code LIMIT 0, 10"; // We only display 10 items. +$result = db_query($sql, "Failed in retreiving GL account list."); + +$k = 0; //row colour counter + +while ($myrow = db_fetch_assoc($result)) { + alt_table_row_color($k); + ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "' . $_GET["client_id"] . '", "' . $myrow["account_code"] . '")'); + label_cell($myrow["account_code"]); + label_cell($myrow["account_name"]); + label_cell($myrow["name"]); + end_row(); +} + +end_table(1); + +div_end(); +// END: Account list + +end_page(); diff --git a/gl/manage/gl_accounts.php b/gl/manage/gl_accounts.php index 0d9b2c755..e3a532765 100644 --- a/gl/manage/gl_accounts.php +++ b/gl/manage/gl_accounts.php @@ -12,8 +12,12 @@ $page_security = 'SA_GLACCOUNT'; $path_to_root = "../.."; include($path_to_root . "/includes/session.inc"); - -page(_($help_context = "Chart of Accounts")); + +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + +page(_($help_context = "Chart of Accounts"), false, false, "", $js); include($path_to_root . "/includes/ui.inc"); include($path_to_root . "/gl/includes/gl_db.inc"); diff --git a/includes/db/connect_db.inc b/includes/db/connect_db.inc index bca8b86f5..a1a0b1c1f 100644 --- a/includes/db/connect_db.inc +++ b/includes/db/connect_db.inc @@ -10,218 +10,195 @@ See the License here . ***********************************************************************/ -function set_global_connection($company=-1) -{ - global $db, $transaction_level, $db_connections; - - cancel_transaction(); // cancel all aborted transactions if any - $transaction_level = 0; - - if ($company == -1) - $company = $_SESSION["wa_current_user"]->company; - - $_SESSION["wa_current_user"]->cur_con = $company; - - $connection = $db_connections[$company]; - - $db = mysql_connect($connection["host"], $connection["dbuser"], $connection["dbpassword"]); - mysql_select_db($connection["dbname"], $db); - ///// From MySql release 5.6.6 the sql_mode is no longer empty as it was prior to - ///// this release. Just for safety we set it empty for all 5.6 release and higher. - ///// This non empty sql_mode values can interphere with FA, so all is set empty during - ///// our sessions. - ///// We are, however, investigating the existing code to be compatible in the future. - ///// We are also working on a mysql/mysqli solution to go to release 2.4. - if (strncmp(mysql_get_server_info(), "5.6", 3) >= 0) - db_query("SET sql_mode = ''"); - ///// - return $db; +function set_global_connection($company = -1) { + global $db, $transaction_level, $db_connections; + + cancel_transaction(); + // cancel all aborted transactions if any + $transaction_level = 0; + + if ($company == -1) { + $company = $_SESSION["wa_current_user"]->company; + } + + $_SESSION["wa_current_user"]->cur_con = $company; + + $connection = $db_connections[$company]; + $db = mysqli_connect($connection["host"], $connection["dbuser"], $connection["dbpassword"]); + mysqli_select_db($db, $connection["dbname"]); + ///// From MySql release 5.6.6 the sql_mode is no longer empty as it was prior to + ///// this release. Just for safety we set it empty for all 5.6 release and higher. + ///// This non empty sql_mode values can interphere with FA, so all is set empty during + ///// our sessions. + ///// We are, however, investigating the existing code to be compatible in the future. + ///// We are also working on a mysql/mysqli solution to go to release 2.4. + if (strncmp(mysqli_get_server_info($db), "5.6", 3) >= 0) + db_query("SET sql_mode = ''"); + ///// + return $db; } $db_duplicate_error_code = 1062; //DB wrapper functions to change only once for whole application -function db_query($sql, $err_msg=null) -{ - global $db, $show_sql, $sql_trail, $select_trail, $go_debug, $sql_queries, $Ajax, - $db_connections, $db_last_inserted_id; - - // set current db prefix - $cur_prefix = $db_connections[$_SESSION["wa_current_user"]->cur_con]['tbpref']; - $sql = str_replace(TB_PREF, $cur_prefix, $sql); +function db_query($sql, $err_msg = null) { + global $db, $show_sql, $sql_trail, $select_trail, $go_debug, $sql_queries, $Ajax, $db_connections, $db_last_inserted_id; - if ($show_sql) - { - $Ajax->activate('footer_debug'); - $sql_queries .= "
$sql
\n
"; - } + // set current db prefix + $cur_prefix = $db_connections[$_SESSION["wa_current_user"]->cur_con]['tbpref']; + $sql = str_replace(TB_PREF, $cur_prefix, $sql); - $result = mysql_query($sql, $db); - - if($sql_trail) { - $db_last_inserted_id = mysql_insert_id($db); // preserve in case trail insert is done - if ($select_trail || (strstr($sql, 'SELECT') === false)) { - mysql_query( - "INSERT INTO ".$cur_prefix."sql_trail - (`sql`, `result`, `msg`) - VALUES(".db_escape($sql).",".($result ? 1 : 0).", - ".db_escape($err_msg).")", $db); - } - } + if ($show_sql) { + $Ajax->activate('footer_debug'); + $sql_queries .= "
$sql
\n
"; + } - if ($err_msg != null || $go_debug) { - $exit = $err_msg != null; - if (function_exists('xdebug_call_file')) - check_db_error('
At file '.xdebug_call_file().':'.xdebug_call_line().':
'.$err_msg, $sql, $exit); - else - check_db_error($err_msg, $sql, $exit); - } - return $result; -} + $result = mysqli_query($db, $sql); -function db_fetch_row ($result) -{ + if ($sql_trail) { + $db_last_inserted_id = mysqli_insert_id($db); + // preserve in case trail insert is done + if ($select_trail || (strstr($sql, 'SELECT') === false)) { + mysqli_query($db, "INSERT INTO " . $cur_prefix . "sql_trail + (`sql`, `result`, `msg`) + VALUES(" . db_escape($sql) . "," . ($result ? 1 : 0) . ", + " . db_escape($err_msg) . ")"); + } + } - return mysql_fetch_row($result); + if ($err_msg != null || $go_debug) { + $exit = $err_msg != null; + if (function_exists('xdebug_call_file')) + check_db_error('
At file ' . xdebug_call_file() . ':' . xdebug_call_line() . ':
' . $err_msg, $sql, $exit); + else + check_db_error($err_msg, $sql, $exit); + } + return $result; } -function db_fetch_assoc ($result) -{ - - return mysql_fetch_assoc($result); +function db_fetch_row($result) { + return mysqli_fetch_row($result); } -function db_fetch ($result) -{ +function db_fetch_assoc($result) { + return mysqli_fetch_assoc($result); +} - return mysql_fetch_array($result); +function db_fetch($result) { + //return mysqli_fetch_array($result); + $row = mysqli_fetch_array($result); + if ($row === NULL) + return false; + else + return $row; } -function db_seek (&$result,$record) -{ - return mysql_data_seek($result, $record); +function db_seek(&$result, $record) { + return mysqli_data_seek($result, $record); } -function db_free_result ($result) -{ - if ($result) - mysql_free_result($result); +function db_free_result($result) { + if ($result) { + mysqli_free_result($result); + } } -function db_num_rows ($result) -{ - return mysql_num_rows($result); +function db_num_rows($result) { + return mysqli_num_rows($result); } -function db_num_fields ($result) -{ - return mysql_num_fields($result); +function db_num_fields($result) { + return mysqli_num_fields($result); } -function db_escape($value = "", $nullify = false) -{ - $value = @html_entity_decode($value, ENT_QUOTES, $_SESSION['language']->encoding); - $value = @htmlspecialchars($value, ENT_QUOTES, $_SESSION['language']->encoding=='iso-8859-2' ? 'ISO-8859-1' : $_SESSION['language']->encoding); +function db_escape($value = "", $nullify = false) { + global $db; + $value = @html_entity_decode($value, ENT_QUOTES, $_SESSION['language']->encoding); + $value = @htmlspecialchars($value, ENT_QUOTES, $_SESSION['language']->encoding); - //reset default if second parameter is skipped - $nullify = ($nullify === null) ? (false) : ($nullify); + //reset default if second parameter is skipped + $nullify = ($nullify === null) ? (false) : ($nullify); - //check for null/unset/empty strings - if ((!isset($value)) || (is_null($value)) || ($value === "")) { - $value = ($nullify) ? ("NULL") : ("''"); - } else { - if (is_string($value)) { - //value is a string and should be quoted; determine best method based on available extensions - if (function_exists('mysql_real_escape_string')) { - $value = "'" . mysql_real_escape_string($value) . "'"; - } else { - $value = "'" . mysql_escape_string($value) . "'"; - } - } else if (!is_numeric($value)) { - //value is not a string nor numeric - display_error("ERROR: incorrect data type send to sql query"); - echo '

'; - exit(); - } - } - return $value; -} + //check for null/unset/empty strings + if ((!isset($value)) || (is_null($value)) || ($value === "")) { + $value = ($nullify) ? ("NULL") : ("''"); + } else { + if (is_string($value)) { -function db_error_no () -{ - global $db; - return mysql_errno($db); + $value = "'" . mysqli_real_escape_string($db, $value) . "'"; + } else if (!is_numeric($value)) { + //value is not a string nor numeric + display_error("ERROR: incorrect data type send to sql query"); + echo '

'; + exit(); + } + } + return $value; } -function db_error_msg($conn) -{ - return mysql_error($conn); +function db_error_no() { + return mysqli_connect_errno(); } -function db_insert_id() -{ - global $db_last_inserted_id, $sql_trail, $db; +function db_error_msg($db) { + return mysqli_error($db); +} - return $sql_trail ? $db_last_inserted_id : mysql_insert_id($db); +function db_insert_id() { + global $db_last_inserted_id, $sql_trail, $db; + return $sql_trail ? $db_last_inserted_id : mysqli_insert_id($db); } -function db_num_affected_rows() -{ - global $db; - return mysql_affected_rows($db); +function db_num_affected_rows() { + global $db; + return mysqli_affected_rows($db); } -function db_field_name($result, $n) -{ - return mysql_field_name($result, $n); +function db_field_name($result, $n) { + //return mysqli_field_name($result, $n); + $fieldinfo = mysqli_fetch_field_direct($result, $n); + return $fieldinfo->name; } -function db_create_db($connection) -{ - $db = mysql_connect($connection["host"] , - $connection["dbuser"], $connection["dbpassword"]); - if (!mysql_select_db($connection["dbname"], $db)) - { - $sql = "CREATE DATABASE IF NOT EXISTS " . $connection["dbname"] . ""; - if (!mysql_query($sql) || !mysql_select_db($connection["dbname"], $db)) - return 0; - } - return $db; +function db_create_db($connection) { + $db = mysqli_connect($connection["host"], $connection["dbuser"], $connection["dbpassword"]); + if (!mysqli_select_db($db, $connection["dbname"])) { + $sql = "CREATE DATABASE IF NOT EXISTS " . $connection["dbname"] . ""; + if (!mysqli_query($db, $sql) || !mysqli_select_db($db, $connection["dbname"])) { + return 0; + } + } + return $db; } -function db_drop_db($connection) -{ +function db_drop_db($connection) { - if ($connection["tbpref"] == "") - { - $sql = "DROP DATABASE IF EXISTS " . $connection["dbname"] . ""; - return mysql_query($sql); - } - else - { - $res = db_query("show table status"); - $all_tables = array(); - while($row = db_fetch($res)) - $all_tables[] = $row; + if ($connection["tbpref"] == "") { + $sql = "DROP DATABASE IF EXISTS " . $connection["dbname"] . ""; + return mysqli_query($db, $sql); + } else { + $res = db_query("show table status"); + $all_tables = array(); + while ($row = db_fetch($res)) { + $all_tables[] = $row; + } // get table structures - foreach ($all_tables as $table) - { - if (strpos($table['Name'], $connection["tbpref"]) === 0) - db_query("DROP TABLE `".$table['Name'] . "`"); - } - //deleting the tables, how?? - return true; - } -} - -function db_close($dbase = null) -{ - global $db; - - if (!$dbase) - $dbase = $db; - return mysql_close($dbase); -} - -?> \ No newline at end of file + foreach ($all_tables as $table) { + if (strpos($table['Name'], $connection["tbpref"]) === 0) { + db_query("DROP TABLE `" . $table['Name'] . "`"); + } + } + //deleting the tables, how?? + return true; + } +} + +function db_close($dbase = null) { + global $db; + + if (!$dbase) { + $dbase = $db; + } + return mysqli_close($dbase); +} diff --git a/includes/ui/ui_input.inc b/includes/ui/ui_input.inc index 400e3be0a..2c82cd0c2 100644 --- a/includes/ui/ui_input.inc +++ b/includes/ui/ui_input.inc @@ -962,4 +962,12 @@ function bank_balance_row($bank_acc, $parms='') ."", $parms); } -?> \ No newline at end of file +function ahref($label, $href, $target="", $onclick="") { + echo "$label"; +} + +function ahref_cell($label, $href, $target="", $onclick="") { + echo "  "; + ahref($label, $href, $target, $onclick); + echo "  "; +} diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 2cc16888e..7293b7d09 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -1,12 +1,12 @@ . ***********************************************************************/ include_once($path_to_root . "/includes/banking.inc"); @@ -27,44 +27,44 @@ $all_items = ALL_TEXT; // Options are merged with defaults. function combo_input($name, $selected_id, $sql, $valfield, $namefield, - $options=null) -{ -global $Ajax; - -$opts = array( // default options - 'where'=> array(), // additional constraints - 'order' => $namefield, // list sort order - // special option parameters - 'spec_option'=>false, // option text or false - 'spec_id' => 0, // option id - // submit on select parameters - 'default' => '', // default value when $_POST is not set - 'multi' => false, // multiple select - 'select_submit' => false, //submit on select: true/false - 'async' => true, // select update via ajax (true) vs _page_body reload - // search box parameters - 'sel_hint' => null, - 'search_box' => false, // name or true/false - 'type' => 0, // type of extended selector: - // 0 - with (optional) visible search box, search by fragment inside id - // 1 - with hidden search box, search by option text - // 2 - with (optional) visible search box, search by fragment at the start of id - // 3 - TODO reverse: box with hidden selector available via enter; this - // would be convenient for optional ad hoc adding of new item - 'search_submit' => true, //search submit button: true/false - 'size' => 8, // size and max of box tag - 'max' => 50, - 'height' => false, // number of lines in select box - 'cells' => false, // combo displayed as 2 cells - 'search' => array(), // sql field names to search - 'format' => null, // format functions for regular options - 'disabled' => false, - 'box_hint' => null, // box/selectors hints; null = std see below - 'category' => false, // category column name or false - 'show_inactive' => false, // show inactive records. - 'editable' => false // false, or length of editable entry field -); -// ------ merge options with defaults ---------- + $options=null, $type=null) +{ + global $Ajax, $path_to_root, $use_popup_windows; + + $opts = array( // default options + 'where'=> array(), // additional constraints + 'order' => $namefield, // list sort order + // special option parameters + 'spec_option'=>false, // option text or false + 'spec_id' => 0, // option id + // submit on select parameters + 'default' => '', // default value when $_POST is not set + 'multi' => false, // multiple select + 'select_submit' => false, //submit on select: true/false + 'async' => true, // select update via ajax (true) vs _page_body reload + // search box parameters + 'sel_hint' => null, + 'search_box' => false, // name or true/false + 'type' => 0, // type of extended selector: + // 0 - with (optional) visible search box, search by fragment inside id + // 1 - with hidden search box, search by option text + // 2 - with (optional) visible search box, search by fragment at the start of id + // 3 - TODO reverse: box with hidden selector available via enter; this + // would be convenient for optional ad hoc adding of new item + 'search_submit' => true, //search submit button: true/false + 'size' => 8, // size and max of box tag + 'max' => 50, + 'height' => false, // number of lines in select box + 'cells' => false, // combo displayed as 2 cells + 'search' => array(), // sql field names to search + 'format' => null, // format functions for regular options + 'disabled' => false, + 'box_hint' => null, // box/selectors hints; null = std see below + 'category' => false, // category column name or false + 'show_inactive' => false, // show inactive records. + 'editable' => false // false, or length of editable entry field + ); + // ------ merge options with defaults ---------- if($options != null) $opts = array_merge($opts, $options); if (!is_array($opts['where'])) $opts['where'] = array($opts['where']); @@ -91,11 +91,11 @@ $opts = array( // default options $disabled = $opts['disabled'] ? "disabled" : ''; $multi = $opts['multi']; - + if(!count($opts['search'])) { $opts['search'] = array($by_id ? $valfield : $namefield); } - if ($opts['sel_hint'] === null) + if ($opts['sel_hint'] === null) $opts['sel_hint'] = $by_id || $search_box==false ? '' : _('Press Space tab for search pattern entry'); @@ -196,16 +196,16 @@ $opts = array( // default options if (in_array((string)$value, $selected_id, true)) { $sel = 'selected'; $found = $value; - $edit = $opts['editable'] && $contact_row['editable'] + $edit = $opts['editable'] && $contact_row['editable'] && (@$_POST[$search_box] == $value) ? $contact_row[1] : false; // get non-formatted description if ($edit) break; // selected field is editable - abandon list construction } - // show selected option even if inactive + // show selected option even if inactive if (!$opts['show_inactive'] && @$contact_row['inactive'] && $sel==='') { continue; - } else + } else $optclass = @$contact_row['inactive'] ? "class='inactive'" : ''; if ($first_id === false) { @@ -241,10 +241,10 @@ $opts = array( // default options if ($found===false) { $selected_id = array($first_id); } - + $_POST[$name] = $multi ? $selected_id : $selected_id[0]; - $selector = "\n"; @@ -276,7 +276,7 @@ $opts = array( // default options (fallback_mode() ? '' : 'display:none;'), '_'.$name.'_update')."\n"; } -// ------ make combo ---------- + // ------ make combo ---------- $edit_entry = ''; if ($search_box != false) { $edit_entry = "'; + } + if ($search_box && $opts['cells']) - $str = ($edit_entry!='' ? "$edit_entry" : '')."$selector"; + $str = ($edit_entry!='' ? "$edit_entry" : '')."$selector$img"; else - $str = $edit_entry.$selector; + $str = $edit_entry.$selector.$img; return $str; } @@ -432,7 +482,7 @@ function add_edit_combo($type) $key = $popup_editors[$type][1]; $onclick = "onclick=\"javascript:callEditor($key); return false;\""; $img = "Add/Edit"; - return "$img"; + return "$img"; } function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, @@ -446,14 +496,14 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_ if ($editkey) set_editor('supplier', $name, $editkey); - + $ret = combo_input($name, $selected_id, $sql, 'supplier_id', 'supp_name', array( 'format' => '_format_add_curr', 'order' => array('supp_ref'), 'search_box' => $mode!=0, 'type' => 1, - 'search' => array("supp_ref","supp_name","gst_no"), + 'search' => array("supp_ref","supp_name","gst_no"), 'spec_option' => $spec_option === true ? _("All Suppliers") : $spec_option, 'spec_id' => $all_items, 'select_submit'=> $submit_on_change, @@ -461,23 +511,23 @@ function supplier_list($name, $selected_id=null, $spec_option=false, $submit_on_ 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment') : _('Select supplier'), 'show_inactive'=>$all - )); + ), "supplier"); if ($editkey) - $ret .= add_edit_combo('supplier'); + $ret .= add_edit_combo('supplier'); return $ret; } -function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, +function supplier_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $all=false, $editkey = false) { if ($label != null) echo "$label\n"; - echo supplier_list($name, $selected_id, $all_option, $submit_on_change, + echo supplier_list($name, $selected_id, $all_option, $submit_on_change, $all, $editkey); echo "\n"; } -function supplier_list_row($label, $name, $selected_id=null, $all_option = false, +function supplier_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false, $all=false, $editkey = false) { echo "$label"; @@ -487,7 +537,7 @@ function supplier_list_row($label, $name, $selected_id=null, $all_option = false } //---------------------------------------------------------------------------------------------- -function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, +function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_change=false, $show_inactive=false, $editkey = false) { global $all_items; @@ -506,7 +556,7 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_ 'search_box' => $mode!=0, 'type' => 1, 'size' => 20, - 'search' => array("debtor_ref","name","tax_id"), + 'search' => array("debtor_ref","name","tax_id"), 'spec_option' => $spec_option === true ? _("All Customers") : $spec_option, 'spec_id' => $all_items, 'select_submit'=> $submit_on_change, @@ -514,13 +564,13 @@ function customer_list($name, $selected_id=null, $spec_option=false, $submit_on_ 'sel_hint' => $mode ? _('Press Space tab to filter by name fragment; F2 - entry new customer') : _('Select customer'), 'show_inactive' => $show_inactive - ) ); + ), "customer" ); if ($editkey) $ret .= add_edit_combo('customer'); return $ret; } -function customer_list_cells($label, $name, $selected_id=null, $all_option=false, +function customer_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $show_inactive=false, $editkey = false) { if ($label != null) @@ -531,7 +581,7 @@ function customer_list_cells($label, $name, $selected_id=null, $all_option=false echo "\n"; } -function customer_list_row($label, $name, $selected_id=null, $all_option = false, +function customer_list_row($label, $name, $selected_id=null, $all_option = false, $submit_on_change=false, $show_inactive=false, $editkey = false) { global $path_to_root; @@ -564,31 +614,31 @@ function customer_branches_list($customer_id, $name, $selected_id=null, 'spec_id' => $all_items, 'select_submit'=> $submit_on_change, 'sel_hint' => _('Select customer branch') - ) ); + ), "branch" ); if ($editkey) { $ret .= add_edit_combo('branch'); - } + } return $ret; } //------------------------------------------------------------------------------------------------ -function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, +function customer_branches_list_cells($label,$customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false) { if ($label != null) echo "$label\n"; echo ""; - echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, + echo customer_branches_list($customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change, $editkey); echo "\n"; } -function customer_branches_list_row($label, $customer_id, $name, $selected_id=null, +function customer_branches_list_row($label, $customer_id, $name, $selected_id=null, $all_option = true, $enabled=true, $submit_on_change=false, $editkey = false) { echo "$label"; - customer_branches_list_cells(null, $customer_id, $name, $selected_id, + customer_branches_list_cells(null, $customer_id, $name, $selected_id, $all_option, $enabled, $submit_on_change, $editkey); echo ""; } @@ -636,7 +686,7 @@ return combo_input($name, $selected_id, $sql, 'curr_abrev', 'currency', array( 'select_submit'=> $submit_on_change, 'default' => get_company_currency(), - 'async' => false + 'async' => false ) ); } @@ -740,8 +790,8 @@ function dimensions_list_row($label, $name, $selected_id=null, $no_option=false, //--------------------------------------------------------------------------------------------------- -function stock_items_list($name, $selected_id=null, $all_option=false, - $submit_on_change=false, $opts=array(), $editkey = false) +function stock_items_list($name, $selected_id=null, $all_option=false, + $submit_on_change=false, $opts=array(), $editkey = false, $type = "stock") { global $all_items; @@ -764,11 +814,11 @@ function stock_items_list($name, $selected_id=null, $all_option=false, 'select_submit'=> $submit_on_change, 'category' => 2, 'order' => array('c.description','stock_id') - ), $opts) ); + ), $opts), $type ); if ($editkey) - $ret .= add_edit_combo('item'); + $ret .= add_edit_combo('item'); return $ret; - + } function _format_stock_items($row) @@ -776,7 +826,7 @@ function _format_stock_items($row) return (user_show_codes() ? ($row[0] . " - ") : "") . $row[1]; } -function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, +function stock_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $all=false, $editkey = false) { if ($label != null) @@ -796,7 +846,7 @@ function stock_items_list_row($label, $name, $selected_id=null, $all_option=fals // // Select item via foreign code. // -function sales_items_list($name, $selected_id=null, $all_option=false, +function sales_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $type='', $opts=array()) { global $all_items; @@ -811,9 +861,9 @@ function sales_items_list($name, $selected_id=null, $all_option=false, ON i.category_id=c.category_id WHERE i.stock_id=s.stock_id"; - + if ($type == 'local') { // exclude foreign codes - $sql .= " AND !i.is_foreign"; + $sql .= " AND !i.is_foreign"; } elseif ($type == 'kits') { // sales kits $sql .= " AND !i.is_foreign AND i.item_code!=i.stock_id"; } @@ -835,7 +885,7 @@ function sales_items_list($name, $selected_id=null, $all_option=false, 'order' => array('c.description','i.item_code'), 'editable' => 30, 'max' => 255 - ), $opts) ); + ), $opts), "stock_sales" ); } function sales_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey=false) @@ -871,7 +921,7 @@ function stock_manufactured_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false) { return stock_items_list($name, $selected_id, $all_option, $submit_on_change, - array('where'=>array("mb_flag= 'M'"))); + array('where'=>array("mb_flag= 'M'")), false, "stock_manufactured"); } function stock_manufactured_items_list_cells($label, $name, $selected_id=null, @@ -900,7 +950,7 @@ function stock_component_items_list($name, $parent_stock_id, $selected_id=null, array('where'=>array("stock_id != ".db_escape($parent_stock_id))), $editkey); } -function stock_component_items_list_cells($label, $name, $parent_stock_id, +function stock_component_items_list_cells($label, $name, $parent_stock_id, $selected_id=null, $all_option=false, $submit_on_change=false, $editkey = false) { if ($label != null) @@ -915,10 +965,10 @@ function stock_costable_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false) { return stock_items_list($name, $selected_id, $all_option, $submit_on_change, - array('where'=>array("mb_flag!='D'"))); + array('where'=>array("mb_flag!='D'")), false, "stock_costable"); } -function stock_costable_items_list_cells($label, $name, $selected_id=null, +function stock_costable_items_list_cells($label, $name, $selected_id=null, $all_option=false, $submit_on_change=false) { if ($label != null) @@ -928,12 +978,12 @@ function stock_costable_items_list_cells($label, $name, $selected_id=null, } //------------------------------------------------------------------------------------ -function stock_purchasable_items_list($name, $selected_id=null, +function stock_purchasable_items_list($name, $selected_id=null, $all_option=false, $submit_on_change=false, $all=false, $editkey=false) { return stock_items_list($name, $selected_id, $all_option, $submit_on_change, - array('where'=>array("mb_flag!= 'M'"), - 'show_inactive'=>$all), $editkey); + array('where'=>array("mb_flag!= 'M'"), + 'show_inactive'=>$all), $editkey, "stock_purchased"); } // // This helper is used in PO/GRN/PI entry and supports editable descriptions. @@ -944,7 +994,7 @@ function stock_purchasable_items_list_cells($label, $name, $selected_id=null, if ($label != null) echo "$label\n"; echo stock_items_list($name, $selected_id, $all_option, $submit_on_change, - array('where'=>array("mb_flag!= 'M'"), + array('where'=>array("mb_flag!= 'M'"), 'editable' => 30, 'cells'=>true), $editkey); } @@ -969,9 +1019,9 @@ function stock_item_types_list_row($label, $name, $selected_id=null, $enabled=tr echo "$label\n"; echo ""; - echo array_selector($name, $selected_id, $stock_types, - array( - 'select_submit'=> true, + echo array_selector($name, $selected_id, $stock_types, + array( + 'select_submit'=> true, 'disabled' => !$enabled) ); echo "\n"; } @@ -1087,7 +1137,7 @@ function item_tax_types_list_row($label, $name, $selected_id=null) function shippers_list($name, $selected_id=null) { $sql = "SELECT shipper_id, shipper_name, inactive FROM ".TB_PREF."shippers"; - return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', + return combo_input($name, $selected_id, $sql, 'shipper_id', 'shipper_name', array('order'=>array('shipper_name'))); } @@ -1112,7 +1162,7 @@ function shippers_list_row($label, $name, $selected_id=null) function sales_persons_list($name, $selected_id=null, $spec_opt=false) { $sql = "SELECT salesman_code, salesman_name, inactive FROM ".TB_PREF."salesman"; - return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', + return combo_input($name, $selected_id, $sql, 'salesman_code', 'salesman_name', array('order'=>array('salesman_name'), 'spec_option' => $spec_opt, 'spec_id' => ALL_NUMERIC)); @@ -1495,7 +1545,7 @@ function pos_list_row($label, $name, $selected_id=null, $spec_option=false, $sub function sale_payment_list($name, $category, $selected_id=null, $submit_on_change=true) { $sql = "SELECT terms_indicator, terms, inactive FROM ".TB_PREF."payment_terms"; - + if ($category == PM_CASH) // only cash $sql .= " WHERE days_before_due=0 AND day_in_following_month=0"; if ($category == PM_CREDIT) // only delayed payments @@ -1644,7 +1694,7 @@ function gl_all_accounts_list($name, $selected_id=null, $skip_bank_accounts=fals 'async' => false, 'category' => 2, 'show_inactive' => $all - ) ); + ), "account" ); } @@ -1653,23 +1703,23 @@ function _format_account($row) return $row[0] . "    " . $row[1]; } -function gl_all_accounts_list_cells($label, $name, $selected_id=null, - $skip_bank_accounts=false, $cells=false, $all_option=false, +function gl_all_accounts_list_cells($label, $name, $selected_id=null, + $skip_bank_accounts=false, $cells=false, $all_option=false, $submit_on_change=false, $all=false) { if ($label != null) echo "$label\n"; echo ""; - echo gl_all_accounts_list($name, $selected_id, + echo gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $cells, $all_option, $submit_on_change, $all); echo "\n"; } -function gl_all_accounts_list_row($label, $name, $selected_id=null, +function gl_all_accounts_list_row($label, $name, $selected_id=null, $skip_bank_accounts=false, $cells=false, $all_option=false) { echo "$label"; - gl_all_accounts_list_cells(null, $name, $selected_id, + gl_all_accounts_list_cells(null, $name, $selected_id, $skip_bank_accounts, $cells, $all_option); echo "\n"; } @@ -1680,8 +1730,8 @@ function yesno_list($name, $selected_id=null, $name_yes="", $name_no="", $submit $items['0'] = strlen($name_no) ? $name_no : _("No"); $items['1'] = strlen($name_yes) ? $name_yes : _("Yes"); - return array_selector($name, $selected_id, $items, - array( + return array_selector($name, $selected_id, $items, + array( 'select_submit'=> $submit_on_change, 'async' => false ) ); // FIX? } @@ -1767,8 +1817,8 @@ function payment_person_types_list($name, $selected_id=null, $submit_on_change=f { if ($key != PT_WORKORDER) $items[$key] = $type; - } - return array_selector($name, $selected_id, $items, + } + return array_selector($name, $selected_id, $items, array( 'select_submit'=> $submit_on_change ) ); } @@ -1793,8 +1843,8 @@ function payment_person_types_list_row($label, $name, $selected_id=null, $relate function wo_types_list($name, $selected_id=null) { global $wo_types_array; - - return array_selector($name, $selected_id, $wo_types_array, + + return array_selector($name, $selected_id, $wo_types_array, array( 'select_submit'=> true, 'async' => true ) ); } @@ -1883,8 +1933,8 @@ function systypes_list($name, $value=null, $spec_opt=false, $submit_on_change=fa // emove non-voidable transactions if needed $systypes = array_diff_key($systypes_array, array_flip($exclude)); - return array_selector($name, $value, $systypes, - array( + return array_selector($name, $value, $systypes, + array( 'spec_option'=> $spec_opt, 'spec_id' => ALL_NUMERIC, 'select_submit'=> $submit_on_change, @@ -1922,9 +1972,9 @@ function journal_types_list_cells($label, $name, $value=null, $submit_on_change= // exclude quotes, orders and dimensions foreach (array(ST_PURCHORDER, ST_SALESORDER, ST_DIMENSION, ST_SALESQUOTE, ST_LOCTRANSFER) as $excl) unset($items[$excl]); - - echo array_selector($name, $value, $items, - array( + + echo array_selector($name, $value, $items, + array( 'spec_option'=> _("All"), 'spec_id' => -1, 'select_submit'=> $submit_on_change, @@ -1941,7 +1991,7 @@ function cust_allocations_list_cells($label, $name, $selected=null) if ($label != null) label_cell($label); echo "\n"; - $allocs = array( + $allocs = array( $all_items=>_("All Types"), '1'=> _("Sales Invoices"), '2'=> _("Overdue Invoices"), @@ -1958,7 +2008,7 @@ function supp_allocations_list_cell($name, $selected=null) global $all_items; echo "\n"; - $allocs = array( + $allocs = array( $all_items=>_("All Types"), '1'=> _("Invoices"), '2'=> _("Overdue Invoices"), @@ -1975,7 +2025,7 @@ function supp_transactions_list_cell($name, $selected=null) global $all_items; echo "\n"; - $allocs = array( + $allocs = array( $all_items=>_("All Types"), '6'=>_("GRNs"), '1'=> _("Invoices"), @@ -1994,7 +2044,7 @@ function policy_list_cells($label, $name, $selected=null) if ($label != null) label_cell($label); echo "\n"; - echo array_selector($name, $selected, + echo array_selector($name, $selected, array( '' => _("Automatically put balance on back order"), 'CAN' => _("Cancel any quantites not delivered")) ); echo "\n"; @@ -2012,7 +2062,7 @@ function credit_type_list_cells($label, $name, $selected=null, $submit_on_change if ($label != null) label_cell($label); echo "\n"; - echo array_selector($name, $selected, + echo array_selector($name, $selected, array( 'Return' => _("Items Returned to Inventory Location"), 'WriteOff' => _("Items Written Off")), array( 'select_submit'=> $submit_on_change ) ); @@ -2069,7 +2119,7 @@ function print_profiles_list_row($label, $name, $selected_id=null, $spec_opt=fal echo "$label\n"; echo ""; - echo array_selector($name, $selected_id, $profiles, + echo array_selector($name, $selected_id, $profiles, array( 'select_submit'=> $submit_on_change, 'spec_option'=>$spec_opt, 'spec_id' => '' @@ -2083,14 +2133,14 @@ function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_cha static $printers; // query only once for page display if (!$printers) { - $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; + $sql = "SELECT id, name, description FROM ".TB_PREF."printers"; $result = db_query($sql, 'cannot get all printers'); $printers = array(); while($myrow=db_fetch($result)) { $printers[$myrow['id']] = $myrow['name'].' - '.$myrow['description']; } } - return array_selector($name, $selected_id, $printers, + return array_selector($name, $selected_id, $printers, array( 'select_submit'=> $submit_on_change, 'spec_option'=>$spec_opt, 'spec_id' => '' @@ -2120,7 +2170,7 @@ function quick_entries_list_cells($label, $name, $selected_id=null, $type, $subm { if ($label != null) echo "$label\n"; - echo ""; + echo ""; echo quick_entries_list($name, $selected_id, $type, $submit_on_change); echo ""; } @@ -2136,10 +2186,10 @@ function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false) { global $quick_actions; - + echo "$label"; - echo array_selector($name, $selected_id, $quick_actions, - array( + echo array_selector($name, $selected_id, $quick_actions, + array( 'select_submit'=> $submit_on_change ) ); echo "\n"; @@ -2148,10 +2198,10 @@ function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_cha function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false) { global $quick_entry_types; - + echo "$label"; - echo array_selector($name, $selected_id, $quick_entry_types, - array( + echo array_selector($name, $selected_id, $quick_entry_types, + array( 'select_submit'=> $submit_on_change ) ); echo "\n"; @@ -2164,10 +2214,10 @@ function record_status_list_row($label, $name) { function class_types_list_row($label, $name, $selected_id=null, $submit_on_change=false) { global $class_types; - + echo "$label"; - echo array_selector($name, $selected_id, $class_types, - array( + echo array_selector($name, $selected_id, $class_types, + array( 'select_submit'=> $submit_on_change ) ); echo "\n"; @@ -2212,7 +2262,7 @@ function security_roles_list_row($label, $name, $selected_id=null, $new_item=fal function tab_list_row($label, $name, $selected_id=null) { global $installed_extensions; - + $tabs = array(); foreach ($_SESSION['App']->applications as $app) { $tabs[$app->id] = access_string($app->name, true); @@ -2234,7 +2284,7 @@ function tag_list($name, $height, $type, $multi=false, $all=false, $spec_opt = f while ($tag = db_fetch($results)) $tags[$tag['id']] = $tag['name']; - + if (!isset($tags)) { $tags[''] = $all ? _("No tags defined.") : _("No active tags defined."); $spec_opt = false; @@ -2255,18 +2305,18 @@ function tag_list_cells($label, $name, $height, $type, $mult=false, $all=false, echo "\n"; echo tag_list($name, $height, $type, $mult, $all, $spec_opt); echo "\n"; - + } function tag_list_row($label, $name, $height, $type, $mult=false, $all=false, $spec_opt = false) { echo "$label"; tag_list_cells(null, $name, $height, $type, $mult, $all, $spec_opt); - echo "\n"; + echo "\n"; } //--------------------------------------------------------------------------------------------- -// List of sets of active extensions +// List of sets of active extensions // function extset_list($name, $value=null, $submit_on_change=false) { @@ -2323,10 +2373,10 @@ function crm_category_types_list_row($label, $name, $selected_id=null, $filter=a function payment_type_list_row($label, $name, $selected_id=null, $submit_on_change=false) { global $pterm_types; - + echo "$label"; - echo array_selector($name, $selected_id, $pterm_types, - array( + echo array_selector($name, $selected_id, $pterm_types, + array( 'select_submit'=> $submit_on_change ) ); echo "\n"; @@ -2374,5 +2424,3 @@ function payment_services($name) 'spec_id' => '', )); } - -?> diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index cc003088d..779aad4f4 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -852,6 +852,48 @@ function get_js_open_window($width, $height) . " var top = (screen.height - $height) / 2;\n" . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n" . "}\n"; + $js .= get_js_lookup_window(); + return $js; +} + +function get_js_lookup_window() { + $js = "function lookupWindow(url, title) { + var u = url.split('#'); + if (u.length == 2) { + var element = document.getElementById(u[1]); + var options = element.options; + url = u[0] + '&' + u[1] + '=' + options[element.selectedIndex].value; + } + openWindow(url, title); + }"; + return $js; +} + +function get_js_populate_combo_item() { + $js = "function populateComboItem(element, value, text) { + var opt = document.createElement('option'); + opt.value = value; + opt.innerHTML = text; + element.appendChild(opt); + }"; + return $js; +} + +function get_js_select_combo_item() { + $js = "function selectComboItem(doc, client_id, value, text, append){ + var element = doc.getElementById(client_id); + if (append == true) { + populateComboItem(element, value, text); + } + var options = element.options; + for (var i = 0, optionsLength = options.length; i < optionsLength; i++) { + if (options[i].value == value) { + element.selectedIndex = i; + element.onchange(); + } + } + window.close(); + }"; return $js; } @@ -860,7 +902,7 @@ function get_js_open_window($width, $height) If $form<0 $name is element id. */ function set_focus($name, $form_no=0) { - global $Ajax; + global $Ajax; $Ajax->addFocus(true, $name); $_POST['_focus'] = $name; } @@ -1430,5 +1472,3 @@ function payment_link($name, $options) return strtr($link, $patterns); } - -?> \ No newline at end of file diff --git a/inventory/includes/db/items_adjust_db.inc b/inventory/includes/db/items_adjust_db.inc index 6e95c2574..841c987da 100644 --- a/inventory/includes/db/items_adjust_db.inc +++ b/inventory/includes/db/items_adjust_db.inc @@ -130,7 +130,7 @@ function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $type, update_average_material_cost(null, $stock_id, $standard_cost, $quantity, $date_); add_stock_move(ST_INVADJUST, $stock_id, $adj_id, $location, - $date_, $reference, $quantity, $standard_cost); + $date_, $reference, $quantity, $standard_cost, $type); if ($standard_cost > 0) { @@ -146,4 +146,4 @@ function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $type, //------------------------------------------------------------------------------------------------------------- -?> \ No newline at end of file +?> diff --git a/inventory/inquiry/stock_list.php b/inventory/inquiry/stock_list.php new file mode 100644 index 000000000..0143cace2 --- /dev/null +++ b/inventory/inquiry/stock_list.php @@ -0,0 +1,125 @@ +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); + +start_row(); + +text_cells(_("Description"), "description"); +submit_cells("search", _("Search"), "", _("Search items"), "default"); + +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); + +// Get the item list type. +$type = ""; +if (isset($_GET['type'])) { + $type = $_GET['type']; +} + +// For item that can be sold we should join to item_codes table so we can sell item kits. +if ($type == "sales") { + // Query based on function sales_items_list in includes/ui/ui_lists.inc. + $sql = "SELECT DISTINCT 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.description LIKE " . db_escape("%" . get_post("description"). "%"); +} +else { + // Query based on function stock_items_list( in includes/ui/ui_lists.inc. + $sql = "SELECT s.stock_id item_code, s.description, c.description category + FROM ".TB_PREF."stock_master s,".TB_PREF."stock_category c + WHERE s.category_id=c.category_id + AND !s.inactive + AND s.description LIKE " . db_escape("%" . get_post("description"). "%"); +} + +// The 'all' options have nothing to do with the SQL. +switch ($type) { + case "sales": + $sql .= " AND !s.no_sale"; + break; + case "manufactured": + $sql .= " AND mb_flag = 'M'"; + break; + case "costable": + $sql .= " AND mb_flag != 'D'"; + break; + case "purchasable": + // Has nothing to do in item for purchase. + break; +} + +$sql .= " ORDER BY s.description LIMIT 0, 10"; // We only display 10 items. + +$result = db_query($sql, "Failed in retreiving item list."); + +// Check if we should append selected option to dropdown. +// Usefull when the search item is enabled from company setup. +$append = "false"; +if (get_company_pref("no_item_list") === "1") { + $append = "true"; +} + +$k = 0; //row colour counter + +while ($myrow = db_fetch_assoc($result)) { + alt_table_row_color($k); + ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "' . $_GET["client_id"] . '", "' . $myrow["item_code"] . '", "' . $myrow["description"] . '", ' . $append . ')'); + label_cell($myrow["item_code"]); + label_cell($myrow["description"]); + label_cell($myrow["category"]); + end_row(); +} + +end_table(1); + +div_end(); +// END: Item list + +end_page(); diff --git a/inventory/inquiry/stock_status.php b/inventory/inquiry/stock_status.php index b6965d296..9e754ddf1 100644 --- a/inventory/inquiry/stock_status.php +++ b/inventory/inquiry/stock_status.php @@ -13,12 +13,16 @@ $path_to_root = "../.."; include_once($path_to_root . "/includes/session.inc"); +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + if (!@$_GET['popup']) { if (isset($_GET['stock_id'])){ - page(_($help_context = "Inventory Item Status"), true); + page(_($help_context = "Inventory Item Status"), true, false, "", $js); } else { - page(_($help_context = "Inventory Item Status")); + page(_($help_context = "Inventory Item Status"), false, false, "", $js); } } if (isset($_GET['stock_id'])) diff --git a/inventory/manage/item_categories.php b/inventory/manage/item_categories.php index c42d910ee..6a8cde429 100644 --- a/inventory/manage/item_categories.php +++ b/inventory/manage/item_categories.php @@ -13,7 +13,11 @@ $path_to_root = "../.."; include($path_to_root . "/includes/session.inc"); -page(_($help_context = "Item Categories")); +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + +page(_($help_context = "Item Categories"), false, false, "", $js); include_once($path_to_root . "/includes/ui.inc"); diff --git a/inventory/manage/item_codes.php b/inventory/manage/item_codes.php index 4ada6e3eb..edbe6bc99 100644 --- a/inventory/manage/item_codes.php +++ b/inventory/manage/item_codes.php @@ -13,7 +13,11 @@ $path_to_root = "../.."; include_once($path_to_root . "/includes/session.inc"); -page(_($help_context = "Foreign Item Codes")); +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + +page(_($help_context = "Foreign Item Codes"), false, false, "", $js); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); diff --git a/inventory/manage/items.php b/inventory/manage/items.php index ea8312514..573793990 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -1,23 +1,25 @@ . ***********************************************************************/ $page_security = 'SA_ITEM'; $path_to_root = "../.."; + include($path_to_root . "/includes/session.inc"); + $js = ""; if ($use_popup_windows) $js .= get_js_open_window(900, 500); if ($use_date_picker) $js .= get_js_date_picker(); - + page(_($help_context = "Items"), @$_REQUEST['popup'], false, "", $js); include_once($path_to_root . "/includes/date_functions.inc"); @@ -27,7 +29,8 @@ include_once($path_to_root . "/inventory/includes/inventory_db.inc"); $user_comp = user_company(); -$new_item = get_post('stock_id')=='' || get_post('cancel') || get_post('clone'); +$new_item = get_post('stock_id')=='' || get_post('cancel') || get_post('clone'); + //------------------------------------------------------------------------------------ if (isset($_GET['stock_id'])) @@ -52,7 +55,7 @@ $Ajax->activate('details'); } $upload_file = ""; -if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') +if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '') { $stock_id = $_POST['NewStockID']; $result = $_FILES['pic']['error']; @@ -61,10 +64,10 @@ if (!file_exists($filename)) { mkdir($filename); - } + } $filename .= "/".item_img_name($stock_id).".jpg"; - - //But check for the worst + + //But check for the worst if ((list($width, $height, $type, $attr) = getimagesize($_FILES['pic']['tmp_name'])) !== false) $imagetype = $type; else @@ -79,22 +82,22 @@ { display_warning(_('Only graphics files are supported - a file extension of .jpg, .png or .gif is expected')); $upload_file ='No'; - } - elseif ( $_FILES['pic']['size'] > ($max_image_size * 1024)) + } + elseif ( $_FILES['pic']['size'] > ($max_image_size * 1024)) { //File Size Check display_warning(_('The file size is over the maximum allowed. The maximum size allowed in KB is') . ' ' . $max_image_size); $upload_file ='No'; - } + } elseif (file_exists($filename)) { $result = unlink($filename); - if (!$result) + if (!$result) { display_error(_('The existing image could not be removed')); $upload_file ='No'; } } - + if ($upload_file == 'Yes') { $result = move_uploaded_file($_FILES['pic']['tmp_name'], $filename); @@ -119,31 +122,33 @@ function clear_data() unset($_POST['dimension_id']); unset($_POST['dimension2_id']); unset($_POST['no_sale']); + // Clear BOM session after clearing data. + clear_bom(); } //------------------------------------------------------------------------------------ -if (isset($_POST['addupdate'])) +if (isset($_POST['addupdate'])) { $input_error = 0; if ($upload_file == 'No') $input_error = 1; - if (strlen($_POST['description']) == 0) + if (strlen($_POST['description']) == 0) { $input_error = 1; display_error( _('The item name must be entered.')); set_focus('description'); - } - elseif (strlen($_POST['NewStockID']) == 0) + } + elseif (strlen($_POST['NewStockID']) == 0) { $input_error = 1; display_error( _('The item code cannot be empty')); set_focus('NewStockID'); } - elseif (strstr($_POST['NewStockID'], " ") || strstr($_POST['NewStockID'],"'") || - strstr($_POST['NewStockID'], "+") || strstr($_POST['NewStockID'], "\"") || - strstr($_POST['NewStockID'], "&") || strstr($_POST['NewStockID'], "\t")) + elseif (strstr($_POST['NewStockID'], " ") || strstr($_POST['NewStockID'],"'") || + strstr($_POST['NewStockID'], "+") || strstr($_POST['NewStockID'], "\"") || + strstr($_POST['NewStockID'], "&") || strstr($_POST['NewStockID'], "\t")) { $input_error = 1; display_error( _('The item code cannot contain any of the following characters - & + OR a space OR quotes')); @@ -156,7 +161,7 @@ function clear_data() display_error( _("This item code is already assigned to stock item or sale kit.")); set_focus('NewStockID'); } - + if ($input_error != 1) { if (check_value('del_image')) @@ -165,15 +170,15 @@ function clear_data() if (file_exists($filename)) unlink($filename); } - - if (!$new_item) + + if (!$new_item) { /*so its an existing one */ update_item($_POST['NewStockID'], $_POST['description'], - $_POST['long_description'], $_POST['category_id'], + $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'], get_post('units'), get_post('mb_flag'), $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], - $_POST['adjustment_account'], $_POST['assembly_account'], + $_POST['adjustment_account'], $_POST['assembly_account'], $_POST['dimension_id'], $_POST['dimension2_id'], check_value('no_sale'), check_value('editable')); update_record_status($_POST['NewStockID'], $_POST['inactive'], @@ -183,20 +188,23 @@ function clear_data() set_focus('stock_id'); $Ajax->activate('stock_id'); // in case of status change display_notification(_("Item has been updated.")); - } - else + } + else { //it is a NEW part add_item($_POST['NewStockID'], $_POST['description'], $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'], $_POST['units'], $_POST['mb_flag'], $_POST['sales_account'], $_POST['inventory_account'], $_POST['cogs_account'], - $_POST['adjustment_account'], $_POST['assembly_account'], + $_POST['adjustment_account'], $_POST['assembly_account'], $_POST['dimension_id'], $_POST['dimension2_id'], check_value('no_sale'), check_value('editable')); + // Save BOM for new item if any. + save_bom($_POST['NewStockID']); + display_notification(_("A new item has been added.")); - $_POST['stock_id'] = $_POST['NewStockID'] = + $_POST['stock_id'] = $_POST['NewStockID'] = $_POST['description'] = $_POST['long_description'] = ''; $_POST['no_sale'] = $_POST['editable'] = 0; set_focus('NewStockID'); @@ -228,7 +236,7 @@ function check_usage($stock_id, $dispmsg=true) //------------------------------------------------------------------------------------ -if (isset($_POST['delete']) && strlen($_POST['delete']) > 1) +if (isset($_POST['delete']) && strlen($_POST['delete']) > 1) { if (check_usage($_POST['NewStockID'])) { @@ -247,7 +255,7 @@ function check_usage($stock_id, $dispmsg=true) } } -function item_settings(&$stock_id) +function item_settings(&$stock_id) { global $SysPrefs, $path_to_root, $new_item, $pic_height; @@ -258,13 +266,13 @@ function item_settings(&$stock_id) table_section_title(_("Item")); //------------------------------------------------------------------------------------ - if ($new_item) + if ($new_item) { text_row(_("Item Code:"), 'NewStockID', null, 21, 20); $_POST['inactive'] = 0; - } - else + } + else { // Must be modifying an existing item if (get_post('NewStockID') != get_post('stock_id') || get_post('addupdate')) { // first item display @@ -287,7 +295,7 @@ function item_settings(&$stock_id) $_POST['dimension_id'] = $myrow['dimension_id']; $_POST['dimension2_id'] = $myrow['dimension2_id']; $_POST['no_sale'] = $myrow['no_sale']; - $_POST['del_image'] = 0; + $_POST['del_image'] = 0; $_POST['inactive'] = $myrow["inactive"]; $_POST['editable'] = $myrow["editable"]; } @@ -320,13 +328,22 @@ function item_settings(&$stock_id) $_POST['editable'] = 0; } - $fresh_item = !isset($_POST['NewStockID']) || $new_item + $fresh_item = !isset($_POST['NewStockID']) || $new_item || check_usage($_POST['stock_id'],false); item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null); stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item); + // When editing manufactured item, provide the link to open popup window for managing its bill of materials. + if (is_manufactured($_POST['mb_flag'])){ + $link = $path_to_root . '/manufacturing/manage/bom_edit.php?popup=1&use_session=1'; + if (!$new_item) { + $link = $path_to_root . '/manufacturing/manage/bom_edit.php?popup=1&stock_id=' . get_post('NewStockID'); + } + label_row(_("Bills of Material:"), '' . _("Manage Bills of Material") . ''); + } + stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item); check_row(_("Editable description:"), 'editable'); @@ -353,13 +370,13 @@ function item_settings(&$stock_id) gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']); - if (!is_service($_POST['mb_flag'])) + if (!is_service($_POST['mb_flag'])) { gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']); gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']); gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']); } - else + else { gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']); hidden('inventory_account', $_POST['inventory_account']); @@ -380,15 +397,15 @@ function item_settings(&$stock_id) $stock_img_link = ""; $check_remove_image = false; if (isset($_POST['NewStockID']) && file_exists(company_path().'/images/' - .item_img_name($_POST['NewStockID']).".jpg")) + .item_img_name($_POST['NewStockID']).".jpg")) { // 31/08/08 - rand() call is necessary here to avoid caching problems. Thanks to Peter D. $stock_img_link .= "[".$_POST["; $check_remove_image = true; - } - else + } + else { $stock_img_link .= _("No image"); } @@ -398,18 +415,19 @@ function item_settings(&$stock_id) check_row(_("Delete Image:"), 'del_image'); record_status_list_row(_("Item status:"), 'inactive'); + end_outer_table(1); div_start('controls'); - if (!isset($_POST['NewStockID']) || $new_item) + if (!isset($_POST['NewStockID']) || $new_item) { submit_center('addupdate', _("Insert New Item"), true, '', 'default'); - } - else + } + else { - submit_center_first('addupdate', _("Update Item"), '', + submit_center_first('addupdate', _("Update Item"), '', @$_REQUEST['popup'] ? true : 'default'); - submit_return('select', get_post('stock_id'), + submit_return('select', get_post('stock_id'), _("Select this items and return to document entry."), 'default'); submit('clone', _("Clone This Item"), true, '', true); submit('delete', _("Delete This Item"), true, '', true); @@ -419,11 +437,30 @@ function item_settings(&$stock_id) div_end(); } -//-------------------------------------------------------------------------------------------- +function clear_bom() { + // Destroy BOM session to make sure we start from empty BOM session. + if (isset($_SESSION['bom_session'])) { + unset($_SESSION['bom_session']); + } +} + +function save_bom($parent) { + // Save BOM from session to database. + if (isset($_SESSION['bom_session']['list'])) { + foreach ($_SESSION['bom_session']['list'] as $myrow) { + add_bom($parent, $myrow['component'], $myrow['workcentre_added'], + $myrow['location'], $myrow['quantity']); + } + } + // Clear it after that. + clear_bom(); +} + +//-------------------------------------------------------------------------------------------- start_form(true); -if (db_has_stock_items()) +if (db_has_stock_items()) { start_table(TABLESTYLE_NOBORDER); start_row(); @@ -459,11 +496,11 @@ function item_settings(&$stock_id) 'movement' => array(_('&Transactions'), $stock_id), 'status' => array(_('&Status'), $stock_id), )); - + switch (get_post('_tabs_sel')) { default: case 'settings': - item_settings($stock_id); + item_settings($stock_id); break; case 'sales_pricing': $_GET['stock_id'] = $stock_id; @@ -484,7 +521,7 @@ function item_settings(&$stock_id) if (!is_inventory_item($stock_id)) { break; - } + } $_GET['stock_id'] = $stock_id; $_GET['popup'] = 1; include_once($path_to_root."/inventory/reorder_level.php"); @@ -512,4 +549,3 @@ function item_settings(&$stock_id) //------------------------------------------------------------------------------------ end_page(@$_REQUEST['popup']); -?> diff --git a/inventory/manage/sales_kits.php b/inventory/manage/sales_kits.php index a327de2d3..fbc0c494a 100644 --- a/inventory/manage/sales_kits.php +++ b/inventory/manage/sales_kits.php @@ -13,7 +13,11 @@ $path_to_root = "../.."; include_once($path_to_root . "/includes/session.inc"); -page(_($help_context = "Sales Kits & Alias Codes")); +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + +page(_($help_context = "Sales Kits & Alias Codes"), false, false, "", $js); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); diff --git a/inventory/prices.php b/inventory/prices.php index 650728ca4..7f0bec4b1 100644 --- a/inventory/prices.php +++ b/inventory/prices.php @@ -22,8 +22,12 @@ include_once($path_to_root . "/includes/data_checks.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); -if (!@$_GET['popup']) - page(_($help_context = "Inventory Item Sales prices")); +if (!@$_GET['popup']) { + $js = ""; + if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + page(_($help_context = "Inventory Item Sales prices"), false, false, "", $js); +} //--------------------------------------------------------------------------------------------------- @@ -213,4 +217,3 @@ end_form(); end_page(@$_GET['popup'], false, false); } -?> diff --git a/inventory/purchasing_data.php b/inventory/purchasing_data.php index 96b205e07..02ce50df1 100644 --- a/inventory/purchasing_data.php +++ b/inventory/purchasing_data.php @@ -21,8 +21,12 @@ include_once($path_to_root . "/includes/manufacturing.inc"); include_once($path_to_root . "/includes/data_checks.inc"); -if (!@$_GET['popup']) - page(_($help_context = "Supplier Purchasing Data")); +if (!@$_GET['popup']) { + $js = ""; + if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + page(_($help_context = "Supplier Purchasing Data"), false, false, "", $js); +} check_db_has_purchasable_items(_("There are no purchasable inventory items defined in the system.")); check_db_has_suppliers(_("There are no suppliers defined in the system.")); @@ -232,4 +236,3 @@ end_form(); end_page(@$_GET['popup'], false, false); } -?> diff --git a/inventory/reorder_level.php b/inventory/reorder_level.php index c34ba6728..48d539dc0 100644 --- a/inventory/reorder_level.php +++ b/inventory/reorder_level.php @@ -21,8 +21,12 @@ include_once($path_to_root . "/includes/data_checks.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); -if (!@$_GET['popup']) - page(_($help_context = "Reorder Levels")); +if (!@$_GET['popup']) { + $js = ""; + if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + page(_($help_context = "Reorder Levels"), false, false, "", $js); +} check_db_has_costable_items(_("There are no inventory items defined in the system (Purchased or manufactured items).")); @@ -115,4 +119,3 @@ end_form(); end_page(@$_GET['popup'], false, false); } -?> diff --git a/js/inserts.js b/js/inserts.js index 0dd141650..c1af82669 100644 --- a/js/inserts.js +++ b/js/inserts.js @@ -527,12 +527,13 @@ function setHotKeys() { document.onkeydown = function(ev) { ev = ev||window.event; key = ev.keyCode||ev.which; - if (key == 18 && !ev.ctrlKey) { // start selection, skip Win AltGr - _hotkeys.alt = true; + if (key == 27 && !ev.altKey) { // cancel selection + _hotkeys.alt = false; _hotkeys.focus = -1; return stopEv(ev); } - else if (ev.altKey && !ev.ctrlKey && ((key>47 && key<58) || (key>64 && key<91))) { + else if (ev.altKey && !ev.ctrlKey && ((key>47 && key<58) || (key>64 && key<91))) { + _hotkeys.alt = true; key = String.fromCharCode(key); var n = _hotkeys.focus; var l = document.getElementsBySelector('[accesskey='+key+']'); diff --git a/manufacturing/manage/bom_edit.php b/manufacturing/manage/bom_edit.php index f69abf5f3..838a07eca 100644 --- a/manufacturing/manage/bom_edit.php +++ b/manufacturing/manage/bom_edit.php @@ -1,19 +1,24 @@ . ***********************************************************************/ $page_security = 'SA_BOM'; $path_to_root = "../.."; + include_once($path_to_root . "/includes/session.inc"); -page(_($help_context = "Bill Of Materials")); +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + +page(_($help_context = "Bill Of Materials"), @$_REQUEST['popup'], false, "", $js); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); @@ -21,6 +26,10 @@ include_once($path_to_root . "/includes/manufacturing.inc"); +// Add inventory database library. We need this to load the item data. +include_once($path_to_root . "/inventory/includes/db/items_db.inc"); +include_once($path_to_root . "/inventory/includes/db/items_locations_db.inc"); + check_db_has_bom_stock_items(_("There are no manufactured or kit items defined in the system.")); check_db_has_workcentres(_("There are no work centres defined in the system. BOMs require at least one work centre be defined.")); @@ -39,6 +48,13 @@ $selected_parent = $_GET['stock_id']; } +// Check if we should store BOM in session temporarily. +// This is very usefull when adding new item and its BOM. +if (isset($_GET['use_session'])) +{ + $_SESSION['bom_session']['flag'] = 1; +} + /* selected_parent could come from a post or a get */ /*if (isset($_GET["selected_parent"])) { @@ -72,22 +88,44 @@ function display_bom_items($selected_parent) table_header($th); $k = 0; - while ($myrow = db_fetch($result)) - { - alt_table_row_color($k); + // Check if we will read BOM from session or database. + if (isset($_SESSION['bom_session']['flag'])) { + if (isset($_SESSION['bom_session']['list'])) { + foreach ($_SESSION['bom_session']['list'] as $myrow) + { + alt_table_row_color($k); + + label_cell($myrow["component"]); + label_cell($myrow["description"]); + label_cell($myrow["location_name"]); + label_cell($myrow["WorkCentreDescription"]); + qty_cell($myrow["quantity"], false, get_qty_dec($myrow["component"])); + label_cell($myrow["units"]); + edit_button_cell("Edit".$myrow['component'], _("Edit")); + delete_button_cell("Delete".$myrow['component'], _("Delete")); + end_row(); + } // END FOREACH LOOP + } + } + else { + while ($myrow = db_fetch($result)) + { + + alt_table_row_color($k); - label_cell($myrow["component"]); - label_cell($myrow["description"]); - label_cell($myrow["location_name"]); - label_cell($myrow["WorkCentreDescription"]); - qty_cell($myrow["quantity"], false, get_qty_dec($myrow["component"])); - label_cell($myrow["units"]); - edit_button_cell("Edit".$myrow['id'], _("Edit")); - delete_button_cell("Delete".$myrow['id'], _("Delete")); - end_row(); + label_cell($myrow["component"]); + label_cell($myrow["description"]); + label_cell($myrow["location_name"]); + label_cell($myrow["WorkCentreDescription"]); + qty_cell($myrow["quantity"], false, get_qty_dec($myrow["component"])); + label_cell($myrow["units"]); + edit_button_cell("Edit".$myrow['id'], _("Edit")); + delete_button_cell("Delete".$myrow['id'], _("Delete")); + end_row(); - } //END WHILE LIST LOOP + } //END WHILE LIST LOOP + } end_table(); div_end(); } @@ -105,8 +143,26 @@ function on_submit($selected_parent, $selected_component=-1) if ($selected_component != -1) { - update_bom($selected_parent, $selected_component, $_POST['workcentre_added'], $_POST['loc_code'], - input_num('quantity')); + // Check if we will update BOM in session or database. + if (isset($_SESSION['bom_session']['flag'])) { + $row1 = get_item($selected_component); + $row2 = get_work_centre($_POST['workcentre_added']); + $row3 = get_item_location($_POST['loc_code']); + $_SESSION['bom_session']['list'][$selected_component] = array( + 'component' => $selected_component, + 'description' => $row1['description'], + 'workcentre_added' => $_POST['workcentre_added'], + 'WorkCentreDescription' => $row2['name'], + 'location' => $_POST['loc_code'], + 'location_name' => $row3['location_name'], + 'quantity' => input_num('quantity'), + 'units' => $row1['units'], + ); + } + else { + update_bom($selected_parent, $selected_component, $_POST['workcentre_added'], $_POST['loc_code'], + input_num('quantity')); + } display_notification(_('Selected component has been updated')); $Mode = 'RESET'; } @@ -125,8 +181,26 @@ function on_submit($selected_parent, $selected_component=-1) if (!is_component_already_on_bom($_POST['component'], $_POST['workcentre_added'], $_POST['loc_code'], $selected_parent)) { - add_bom($selected_parent, $_POST['component'], $_POST['workcentre_added'], - $_POST['loc_code'], input_num('quantity')); + // Check if we will insert BOM in session or database. + if (isset($_SESSION['bom_session']['flag'])) { + $row1 = get_item($_POST['component']); + $row2 = get_work_centre($_POST['workcentre_added']); + $row3 = get_item_location($_POST['loc_code']); + $_SESSION['bom_session']['list'][$_POST['component']] = array( + 'component' => $_POST['component'], + 'description' => $row1['description'], + 'workcentre_added' => $_POST['workcentre_added'], + 'WorkCentreDescription' => $row2['name'], + 'location' => $_POST['loc_code'], + 'location_name' => $row3['location_name'], + 'quantity' => input_num('quantity'), + 'units' => $row1['units'], + ); + } + else { + add_bom($selected_parent, $_POST['component'], $_POST['workcentre_added'], + $_POST['loc_code'], input_num('quantity')); + } display_notification(_("A new component part has been added to the bill of material for this item.")); $Mode = 'RESET'; } @@ -148,7 +222,13 @@ function on_submit($selected_parent, $selected_component=-1) if ($Mode == 'Delete') { - delete_bom($selected_id); + // Check if we will delete BOM from session or database. + if (isset($_SESSION['bom_session']['flag']) && isset($_SESSION['bom_session']['list'])) { + unset($_SESSION['bom_session']['list'][$selected_id]); + } + else { + delete_bom($selected_id); + } display_notification(_("The component item has been deleted from this bom")); $Mode = 'RESET'; @@ -167,7 +247,13 @@ function on_submit($selected_parent, $selected_component=-1) start_form(false, true); start_table(TABLESTYLE_NOBORDER); start_row(); -stock_manufactured_items_list_cells(_("Select a manufacturable item:"), 'stock_id', null, false, true); + +// If we use session for storing BOM, don't display the list for choosing manufacturable items. +// Because that means the parent item is not existed yet. +if (!isset($_SESSION['bom_session']['flag'])) { + stock_manufactured_items_list_cells(_("Select a manufacturable item:"), 'stock_id', null, false, true); +} + end_row(); if (list_updated('stock_id')) $Ajax->activate('_page_body'); @@ -177,14 +263,14 @@ function on_submit($selected_parent, $selected_component=-1) end_form(); //-------------------------------------------------------------------------------------------------- -if (get_post('stock_id') != '') +if (get_post('stock_id') != '' || isset($_SESSION['bom_session']['flag'])) { //Parent Item selected so display bom or edit component $selected_parent = $_POST['stock_id']; if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') on_submit($selected_parent, $selected_id); //-------------------------------------------------------------------------------------- -start_form(); + start_form(); display_bom_items($selected_parent); //-------------------------------------------------------------------------------------- echo '
'; @@ -195,7 +281,14 @@ function on_submit($selected_parent, $selected_component=-1) { if ($Mode == 'Edit') { //editing a selected component from the link to the line item - $myrow = get_component_from_bom($selected_id); + + // Check if we will load the BOM from session or database. + if (isset($_SESSION['bom_session']['flag']) && isset($_SESSION['bom_session']['list'][$selected_id])) { + $myrow = $_SESSION['bom_session']['list'][$selected_id]; + } + else { + $myrow = get_component_from_bom($selected_id); + } $_POST['loc_code'] = $myrow["loc_code"]; $_POST['component'] = $myrow["component"]; // by Tom Moulton @@ -212,7 +305,7 @@ function on_submit($selected_parent, $selected_component=-1) echo ""; echo stock_component_items_list('component', $selected_parent, null, false, true); - if (get_post('_component_update')) + if (get_post('_component_update')) { $Ajax->activate('quantity'); } @@ -234,5 +327,3 @@ function on_submit($selected_parent, $selected_component=-1) // ---------------------------------------------------------------------------------- end_page(); - -?> diff --git a/purchasing/inquiry/suppliers_list.php b/purchasing/inquiry/suppliers_list.php new file mode 100644 index 000000000..b85fa37bd --- /dev/null +++ b/purchasing/inquiry/suppliers_list.php @@ -0,0 +1,81 @@ +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); + +start_row(); + +text_cells(_("Supplier"), "supplier"); +submit_cells("search", _("Search"), "", _("Search suppliers"), "default"); + +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); + +$th = array("", _("Supplier"), _("Address")); + +table_header($th); + +// Query based on function supplier_list in includes/ui/ui_lists.inc. +$sql = "SELECT supplier_id, supp_name, address FROM ".TB_PREF."suppliers + WHERE supp_name LIKE " . db_escape("%" . get_post("supplier"). "%") . " + ORDER BY supp_name LIMIT 0, 10"; // We only display 10 items. +$result = db_query($sql, "Failed in retreiving supplier list."); + +// Check if we should append selected option to dropdown. +// Usefull when the search supplier is enabled from company setup. +$append = "false"; +if (get_company_pref("no_supplier_list") === "1") { + $append = "true"; +} + +$k = 0; //row colour counter + +while ($myrow = db_fetch_assoc($result)) { + alt_table_row_color($k); + ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "' . $_GET["client_id"] . '", "' . $myrow["supplier_id"] . '", "' . $myrow["supp_name"] . '", ' . $append . ')'); + label_cell($myrow["supp_name"]); + label_cell($myrow["address"]); + end_row(); +} + +end_table(1); + +div_end(); +// END: Supplier list + +end_page(); diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index 1c5753411..cac74968e 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -441,7 +441,10 @@ function check_quantities() // Skip line if needed if($q_class === 'skip') continue; - if(is_array($q_class)) { + // Mark the insufficient qty in row only for new delivery. + // The already done shouldn't have mark on it even if the qty is not enough anymore + // because it has been delivered. + if(is_array($q_class) && $new) { list($ln_itm->qty_dispatched, $row_classes) = $q_class; $has_marked = true; } diff --git a/sales/inquiry/customer_branches_list.php b/sales/inquiry/customer_branches_list.php new file mode 100644 index 000000000..df13cb212 --- /dev/null +++ b/sales/inquiry/customer_branches_list.php @@ -0,0 +1,88 @@ +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); + +start_row(); + +text_cells(_("Branch"), "branch"); +submit_cells("search", _("Search"), "", _("Search branches"), "default"); + +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["cbo_customer_id"])." + AND b.br_name LIKE " . db_escape("%" . get_post("branch"). "%") . " + ORDER BY b.br_name LIMIT 0, 10"; // We only display 10 items. + +$result = db_query($sql, "Failed in retreiving branches list."); + +$k = 0; //row colour counter + +while ($myrow = db_fetch_assoc($result)) +{ + alt_table_row_color($k); + ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "' . $_GET["client_id"] . '", "' . $myrow["branch_code"] . '", "", false)'); + label_cell($myrow["branch_ref"]); + label_cell($myrow["br_name"]); + label_cell($myrow["contact_name"]); + label_cell($myrow["phone"]); + end_row(); +} + +end_table(1); + +div_end(); +// END: Customer branches list + +end_page(); diff --git a/sales/inquiry/customers_list.php b/sales/inquiry/customers_list.php new file mode 100644 index 000000000..2e95bad26 --- /dev/null +++ b/sales/inquiry/customers_list.php @@ -0,0 +1,81 @@ +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); + +start_row(); + +text_cells(_("Customer"), "customer"); +submit_cells("search", _("Search"), "", _("Search customers"), "default"); + +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); + +$th = array("", _("Customer"), _("Address")); + +table_header($th); + +// Query based on function customer_list in includes/ui/ui_lists.inc. +$sql = "SELECT debtor_no, name, address FROM ".TB_PREF."debtors_master + WHERE name LIKE " . db_escape("%" . get_post("customer"). "%") . " + ORDER BY name LIMIT 0, 10"; // We only display 10 items. +$result = db_query($sql, "Failed in retreiving customer list."); + +// Check if we should append selected option to dropdown. +// Usefull when the search customer is enabled from company setup. +$append = "false"; +if (get_company_pref("no_customer_list") === "1") { + $append = "true"; +} + +$k = 0; //row colour counter + +while ($myrow = db_fetch_assoc($result)) { + alt_table_row_color($k); + ahref_cell(_("Select"), 'javascript:void(0)', '', 'selectComboItem(window.opener.document, "' . $_GET["client_id"] . '", "' . $myrow["debtor_no"] . '", "' . $myrow["name"] . '", ' . $append . ')'); + label_cell($myrow["name"]); + label_cell($myrow["address"]); + end_row(); +} + +end_table(1); + +div_end(); +// END: Customer list + +end_page(); diff --git a/sales/manage/customer_branches.php b/sales/manage/customer_branches.php index e3b1565fb..f11e8aebf 100644 --- a/sales/manage/customer_branches.php +++ b/sales/manage/customer_branches.php @@ -15,7 +15,11 @@ include($path_to_root . "/includes/db_pager.inc"); include($path_to_root . "/includes/session.inc"); -page(_($help_context = "Customer Branches"), @$_REQUEST['popup']); +$js = ""; +if ($use_popup_windows) + $js .= get_js_open_window(900, 500); + +page(_($help_context = "Customer Branches"), @$_REQUEST['popup'], false, "", $js); include($path_to_root . "/includes/ui.inc"); include($path_to_root . "/includes/ui/contacts_view.inc");