X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Fcompany_db.inc;h=0948546cb1f15f8554cfe26673759403a3fabbc9;hb=0079bcececc5700a07b4bffb546f4ef5870d4ea9;hp=5108f3aa4049905ae02531af1d676e983b9f4965;hpb=921b0e7df6265ed280080b7810105fa4d93d9aa6;p=fa-stable.git diff --git a/admin/db/company_db.inc b/admin/db/company_db.inc index 5108f3aa..0948546c 100644 --- a/admin/db/company_db.inc +++ b/admin/db/company_db.inc @@ -1,177 +1,159 @@ . +***********************************************************************/ +/* + Update main or gl company setup. +*/ +function update_company_prefs( $params ) { - $sql = "UPDATE ".TB_PREF."company SET - debtors_act=".db_escape($debtors_act).", pyt_discount_act=".db_escape($pyt_discount_act).", - creditors_act=".db_escape($creditors_act).", grn_act=".db_escape($grn_act).", - exchange_diff_act=".db_escape($exchange_diff_act).", - purch_exchange_diff_act=".db_escape($purch_exchange_diff_act).", - retained_earnings_act=".db_escape($retained_earnings_act).", - freight_act=".db_escape($freight_act).", - default_sales_act=".db_escape($default_sales_act).", - default_sales_discount_act=".db_escape($default_sales_discount_act).", - default_prompt_payment_act=".db_escape($default_prompt_payment_act).", - default_inventory_act=".db_escape($default_inventory_act).", - default_cogs_act=".db_escape($default_cogs_act).", - default_adj_act=".db_escape($default_adj_act).", - default_inv_sales_act=".db_escape($default_inv_sales_act).", - default_assembly_act=".db_escape($default_assembly_act).", - payroll_act=".db_escape($payroll_act).", - allow_negative_stock=$allow_negative_stock, - po_over_receive=$po_over_receive, - po_over_charge=$po_over_charge, - past_due_days=$past_due_days, - default_credit_limit=$default_credit_limit, - default_workorder_required=$default_workorder_required, - default_dim_required=$default_dim_required - WHERE coy_code=1"; - - db_query($sql, "The company gl setup could not be updated "); + $sql = "UPDATE ".TB_PREF."sys_prefs SET value = "; + foreach($params as $name => $value) { + if (!db_query($sql. db_escape($value). " WHERE name=".db_escape($name), + "The company prefferences could not be updated ")) + return false; + } + return true; } - -function update_company_setup($coy_name, $coy_no, $gst_no, $tax_prd, $tax_last, $postal_address, $phone, $fax, $email, - $coy_logo, $domicile, $Dimension, $custom1_name, $custom2_name, $custom3_name, - $custom1_value, $custom2_value, $custom3_value, $curr_default, $f_year, $no_item_list, $no_customer_list, - $no_supplier_list, $base_sales) +/* + Get company preferences. Returns cached values from global variable SysPrefs + or retrieved from database if SysPrefs values are not set. + $prefs can be preference name, array of names, or null for all preferences. + +*/ +function get_company_pref($prefs = null, $tbpref = TB_PREF) { - if ($f_year == null) - $f_year = 0; - $sql = "UPDATE ".TB_PREF."company SET coy_name=".db_escape($coy_name).", - coy_no = ".db_escape($coy_no).", - gst_no=".db_escape($gst_no).", - tax_prd=$tax_prd, - tax_last=$tax_last, - postal_address =".db_escape($postal_address).", - phone=".db_escape($phone).", fax=".db_escape($fax).", - email=".db_escape($email).", - coy_logo=".db_escape($coy_logo).", - domicile=".db_escape($domicile).", - use_dimension=$Dimension, - no_item_list=$no_item_list, - no_customer_list=$no_customer_list, - no_supplier_list=$no_supplier_list, - custom1_name=".db_escape($custom1_name).", - custom2_name=".db_escape($custom2_name).", - custom3_name=".db_escape($custom3_name).", - custom1_value=".db_escape($custom1_value).", - custom2_value=".db_escape($custom2_value).", - custom3_value=".db_escape($custom3_value).", - curr_default=".db_escape($curr_default).", - f_year=$f_year, - base_sales=$base_sales - WHERE coy_code=1"; - - db_query($sql, "The company setup could not be updated "); -} + global $SysPrefs, $core_version; + + if (!isset($_SESSION['SysPrefs']->prefs)) { // cached preferences -function get_company_prefs() -{ - $sql = "SELECT * FROM ".TB_PREF."company WHERE coy_code=1"; - $result = db_query($sql, "The company preferences could not be retrieved"); + $_SESSION['SysPrefs'] = new sys_prefs(); - if (db_num_rows($result) == 0) - display_db_error("FATAL : Could not find company prefs", $sql); + $sql = "SELECT name, value FROM ".$tbpref."sys_prefs"; + $result = @db_query($sql); // supress errors before 2.3 db structure upgrade - return db_fetch($result); -} + if(!$result) + return null; -function get_company_pref($pref_name) -{ - $prefs = get_company_prefs(); - return $prefs[$pref_name]; -} + while($pref = db_fetch_assoc($result)) { + $_SESSION['SysPrefs']->prefs[$pref['name']] = $pref['value']; + } -// fiscal year routines -function add_fiscalyear($from_date, $to_date, $closed) -{ - $from = date2sql($from_date); - $to = date2sql($to_date); + $SysPrefs = &$_SESSION['SysPrefs']; - $sql = "INSERT INTO ".TB_PREF."fiscal_year (begin, end, closed) - VALUES (".db_escape($from).",".db_escape($to).", $closed)"; + // update current db status for info in log file + $SysPrefs->db_ok = $SysPrefs->prefs['version_id'] == $core_version; + } - db_query($sql, "could not add fiscal year"); -} + $all = $_SESSION['SysPrefs']->prefs; -function update_fiscalyear($from_date, $closed) -{ - $from = date2sql($from_date); + if (!$prefs) + return $all; + elseif (is_string($prefs)) + return $all[$prefs]; - $sql = "UPDATE ".TB_PREF."fiscal_year SET closed=$closed - WHERE begin=".db_escape($from); + $ret = array(); + foreach($prefs as $name) + $ret[$name] = $all[$name]; - db_query($sql, "could not update fiscal year"); + return $ret; } -function get_all_fiscalyears() +function get_company_prefs($tbpref = TB_PREF) { - $sql = "SELECT * FROM ".TB_PREF."fiscal_year ORDER BY begin"; - - return db_query($sql, "could not get all fiscal years"); + return get_company_pref(null, $tbpref); } -function get_fiscalyear($from_date) +function get_base_sales_type() { - $from = date2sql($from_date); + return get_company_pref('base_sales'); +} - $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE begin=".db_escape($from); +function get_company_extensions($id = -1) { + global $path_to_root; - $result = db_query($sql, "could not get fiscal year"); + $file = $path_to_root.($id == -1 ? '' : '/company/'.$id).'/installed_extensions.php'; + $installed_extensions = array(); + if (is_file($file)) { + include($file); + } + return $installed_extensions; +} - return db_fetch($result); +function add_payment_terms($daysOrFoll, $terms, $dayNumber) +{ + if ($daysOrFoll) + { + $sql = "INSERT INTO ".TB_PREF."payment_terms (terms, + days_before_due, day_in_following_month) + VALUES (" . + db_escape($terms) . ", " . db_escape($dayNumber) . ", 0)"; + } + else + { + $sql = "INSERT INTO ".TB_PREF."payment_terms (terms, + days_before_due, day_in_following_month) + VALUES (" . db_escape($terms) . ", + 0, " . db_escape($dayNumber) . ")"; + } + db_query($sql,"The payment term could not be added"); } -function get_current_fiscalyear() +function update_payment_terms($selected_id, $daysOrFoll, $terms, $dayNumber) { - $year = get_company_pref('f_year'); + if ($daysOrFoll) + { + $sql = "UPDATE ".TB_PREF."payment_terms SET terms=" . db_escape($terms) . ", + day_in_following_month=0, + days_before_due=" . db_escape($dayNumber) . " + WHERE terms_indicator = " .db_escape($selected_id); + } + else + { + $sql = "UPDATE ".TB_PREF."payment_terms SET terms=" . db_escape($terms) . ", + day_in_following_month=" . db_escape($dayNumber) . ", + days_before_due=0 + WHERE terms_indicator = " .db_escape($selected_id); + } + db_query($sql,"The payment term could not be updated"); +} - $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=$year"; +function delete_payment_terms($selected_id) +{ + $sql="DELETE FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($selected_id); + db_query($sql,"could not delete a payment terms"); +} - $result = db_query($sql, "could not get current fiscal year"); +function get_payment_terms($selected_id) +{ + $sql = "SELECT * FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($selected_id); + $result = db_query($sql,"could not get payment term"); return db_fetch($result); } -function delete_fiscalyear($from_date) +function get_payment_terms_all($show_inactive) { - $from = date2sql($from_date); - begin_transaction(); - - $sql="DELETE FROM ".TB_PREF."fiscal_year WHERE begin=".db_escape($from); - - db_query($sql, "could not delete fiscal year"); - - commit_transaction(); + $sql = "SELECT * FROM ".TB_PREF."payment_terms"; + if (!$show_inactive) $sql .= " WHERE !inactive"; + return db_query($sql,"could not get payment terms"); } -function get_base_sales_type() +function key_in_foreign_table($id, $table, $key, $escaped=false) { - $sql = "SELECT base_sales FROM ".TB_PREF."company WHERE coy_code=1"; - - $result = db_query($sql, "could not get base sales type"); - $myrow = db_fetch($result); - return $myrow[0]; + if (!$escaped) + $id = db_escape($id); + $sql= "SELECT COUNT(*) FROM ".TB_PREF."$table WHERE $key = $id"; + $result = db_query($sql,"check $table relations failed"); + $myrow = db_fetch_row($result); + return ($myrow[0] > 0); } - ?> \ No newline at end of file