X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fdb%2Fcompany_db.inc;h=0948546cb1f15f8554cfe26673759403a3fabbc9;hb=0079bcececc5700a07b4bffb546f4ef5870d4ea9;hp=fde84cfe29b2a69ccd04a8807659f9faa0e8c9cd;hpb=06b2ced510cc44239e267d50b7007d98f686da55;p=fa-stable.git diff --git a/admin/db/company_db.inc b/admin/db/company_db.inc index fde84cfe..0948546c 100644 --- a/admin/db/company_db.inc +++ b/admin/db/company_db.inc @@ -1,169 +1,159 @@ . +***********************************************************************/ +/* + Update main or gl company setup. +*/ +function update_company_prefs( $params ) { - 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 "); + $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 get_company_prefs($tbpref = TB_PREF) +/* + 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) { - $sql = "SELECT * FROM ".$tbpref."company WHERE coy_code=1"; + global $SysPrefs, $core_version; - $result = db_query($sql, "The company preferences could not be retrieved"); + if (!isset($_SESSION['SysPrefs']->prefs)) { // cached preferences - if (db_num_rows($result) == 0) - display_db_error("FATAL : Could not find company prefs", $sql); + $_SESSION['SysPrefs'] = new sys_prefs(); - return db_fetch($result); + $sql = "SELECT name, value FROM ".$tbpref."sys_prefs"; + $result = @db_query($sql); // supress errors before 2.3 db structure upgrade + + if(!$result) + return null; + + while($pref = db_fetch_assoc($result)) { + $_SESSION['SysPrefs']->prefs[$pref['name']] = $pref['value']; + } + + $SysPrefs = &$_SESSION['SysPrefs']; + + // update current db status for info in log file + $SysPrefs->db_ok = $SysPrefs->prefs['version_id'] == $core_version; + } + + $all = $_SESSION['SysPrefs']->prefs; + + if (!$prefs) + return $all; + elseif (is_string($prefs)) + return $all[$prefs]; + + $ret = array(); + foreach($prefs as $name) + $ret[$name] = $all[$name]; + + return $ret; } -function get_company_pref($pref_name, $tbpref = TB_PREF) +function get_company_prefs($tbpref = TB_PREF) { - $prefs = get_company_prefs($tbpref); - return $prefs[$pref_name]; + return get_company_pref(null, $tbpref); } -// fiscal year routines -function add_fiscalyear($from_date, $to_date, $closed) +function get_base_sales_type() { - $from = date2sql($from_date); - $to = date2sql($to_date); + return get_company_pref('base_sales'); +} - $sql = "INSERT INTO ".TB_PREF."fiscal_year (begin, end, closed) - VALUES (".db_escape($from).",".db_escape($to).", $closed)"; +function get_company_extensions($id = -1) { + global $path_to_root; - db_query($sql, "could not add 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; } -function update_fiscalyear($id, $closed) +function add_payment_terms($daysOrFoll, $terms, $dayNumber) { - $sql = "UPDATE ".TB_PREF."fiscal_year SET closed=$closed - WHERE id=".db_escape($id); - - db_query($sql, "could not update fiscal year"); + 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_all_fiscalyears() +function update_payment_terms($selected_id, $daysOrFoll, $terms, $dayNumber) { - $sql = "SELECT * FROM ".TB_PREF."fiscal_year ORDER BY begin"; - - return db_query($sql, "could not get all fiscal years"); + 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"); } -function get_fiscalyear($id) +function delete_payment_terms($selected_id) { - $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($id); - - $result = db_query($sql, "could not get fiscal year"); - - return db_fetch($result); + $sql="DELETE FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($selected_id); + db_query($sql,"could not delete a payment terms"); } -function get_current_fiscalyear() +function get_payment_terms($selected_id) { - $year = get_company_pref('f_year'); - - $sql = "SELECT * FROM ".TB_PREF."fiscal_year WHERE id=$year"; - - $result = db_query($sql, "could not get current fiscal year"); + $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($id) +function get_payment_terms_all($show_inactive) { - begin_transaction(); - - $sql="DELETE FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($id); - - 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