function install($pref, $force) { global $db, $systypes_array; if (!$this->preconf) { return false; } // Until 2.2 sanitizing text input with db_escape was not // consequent enough. To avoid comparision problems we have to // fix this now. sanitize_database($pref); if ($this->beta) { // nothing more to be done on upgrade from 2.2beta return true; } // set item category dflt accounts to values from company GL setup $prefs = get_company_prefs(); $sql = "UPDATE {$pref}stock_category SET " . "dflt_sales_act = '" . $prefs['default_inv_sales_act'] . "'," . "dflt_cogs_act = '" . $prefs['default_cogs_act'] . "'," . "dflt_inventory_act = '" . $prefs['default_inventory_act'] . "'," . "dflt_adjustment_act = '" . $prefs['default_adj_act'] . "'," . "dflt_assembly_act = '" . $prefs['default_assembly_act'] . "'"; if (db_query($sql) == false) { display_error("Cannot update category default GL accounts" . ':<br>' . db_error_msg($db)); return false; } // add all references to refs table for easy searching via journal interface foreach ($systypes_array as $typeno => $typename) { $info = get_systype_db_info($typeno); if ($info == null || $info[3] == null) { continue; } $tbl = str_replace(TB_PREF, $pref, $info[0]); $sql = "SELECT DISTINCT {$info[2]} as id,{$info[3]} as ref FROM {$tbl}"; if ($info[1]) { $sql .= " WHERE {$info[1]}={$typeno}"; } $result = db_query($sql); if (db_num_rows($result)) { while ($row = db_fetch($result)) { $res2 = db_query("INSERT INTO {$pref}refs VALUES(" . $row['id'] . "," . $typeno . ",'" . $row['ref'] . "')"); if (!$res2) { display_error(_("Cannot copy references from {$tbl}") . ':<br>' . db_error_msg($db)); return false; } } } } if (!($ret = db_query("SELECT MAX(`order_no`) FROM `{$pref}sales_orders`")) || !db_num_rows($ret)) { display_error(_('Cannot query max sales order number.')); return false; } $row = db_fetch($ret); $max_order = $row[0]; $next_ref = $max_order + 1; $sql = "UPDATE `{$pref}sys_types` \n\t\t\tSET `type_no`='{$max_order}',`next_reference`='{$next_ref}'\n\t\t\tWHERE `type_id`=30"; if (!db_query($sql)) { display_error(_('Cannot store next sales order reference.')); return false; } return convert_roles($pref); }
function handle_search() { global $table_style; if (check_valid_entries() == true) { $db_info = get_systype_db_info($_POST['filterType']); if ($db_info == null) { return; } $table_name = $db_info[0]; $type_name = $db_info[1]; $trans_no_name = $db_info[2]; $trans_ref = $db_info[3]; $sql = "SELECT DISTINCT {$trans_no_name} "; if ($trans_ref) { $sql .= " ,{$trans_ref} "; } $sql .= " FROM {$table_name}\n\t\t\tWHERE {$trans_no_name} >= " . $_POST['FromTransNo'] . "\n\t\t\tAND {$trans_no_name} <= " . $_POST['ToTransNo']; if ($type_name != null) { $sql .= " AND {$type_name} = " . $_POST['filterType']; } $sql .= " ORDER BY {$trans_no_name}"; $result = db_query($sql, "could not query transactions on {$table_name}"); if (db_num_rows($result) == 0) { echo tr("There are no transactions for the given parameters."); return; } $print_type = $_POST['filterType']; $print_out = $print_type == 10 || $print_type == 11 || $print_type == systypes::cust_dispatch() || $print_type == systypes::po() || $print_type == systypes::sales_order(); if ($print_out) { print_hidden_script($print_type); if ($trans_ref) { $th = array(tr("#"), tr("Reference"), tr("View"), tr("Print"), tr("GL")); } else { $th = array(tr("#"), tr("View"), tr("Print"), tr("GL")); } } else { if ($trans_ref) { $th = array(tr("#"), tr("Reference"), tr("View"), tr("GL")); } else { $th = array(tr("#"), tr("View"), tr("GL")); } } start_table($table_style); table_header($th); $k = 0; while ($line = db_fetch($result)) { alt_table_row_color($k); label_cell($line[$trans_no_name]); if ($trans_ref) { label_cell($line[$trans_ref]); } label_cell(get_trans_view_str($_POST['filterType'], $line[$trans_no_name], tr("View"))); if ($print_out) { label_cell(print_document_link($line[$trans_no_name], tr("Print"), true, $print_type)); } label_cell(get_gl_view_str($_POST['filterType'], $line[$trans_no_name], tr("View GL"))); end_row(); } end_table(); } }