Cleanup, $SysPrefs.
authorJoe <unknown>
Sun, 28 Dec 2014 22:33:49 +0000 (23:33 +0100)
committerJoe <unknown>
Sun, 28 Dec 2014 22:33:49 +0000 (23:33 +0100)
59 files changed:
access/login.php
admin/crm_categories.php
admin/db/company_db.inc
admin/db/transactions_db.inc
admin/display_prefs.php
admin/inst_theme.php
dimensions/includes/dimensions_db.inc
dimensions/inquiry/search_dimensions.php
gl/includes/db/gl_db_accounts.inc
gl/includes/db/gl_db_bank_accounts.inc
gl/includes/db/gl_db_rates.inc
gl/manage/exchange_rates.php
includes/banking.inc
includes/current_user.inc
includes/db/crm_contacts_db.inc
includes/db/references_db.inc
includes/errors.inc
includes/lang/gettext.inc [new file with mode: 0644]
includes/lang/gettext.php [deleted file]
includes/lang/language.inc [new file with mode: 0644]
includes/lang/language.php [deleted file]
includes/main.inc
includes/page/header.inc
includes/references.inc
includes/session.inc
includes/systypes.inc [deleted file]
includes/types.inc
includes/ui/ui_view.inc
install/isession.inc
manufacturing/includes/db/work_orders_db.inc
manufacturing/inquiry/where_used_inquiry.php
manufacturing/search_work_orders.php
manufacturing/work_order_entry.php
purchasing/includes/db/po_db.inc
purchasing/includes/db/suppalloc_db.inc
purchasing/includes/db/suppliers_db.inc
purchasing/includes/ui/po_ui.inc
purchasing/inquiry/po_search.php
purchasing/inquiry/po_search_completed.php
purchasing/inquiry/supplier_allocation_inquiry.php
reporting/includes/doctext.inc
sales/credit_note_entry.php
sales/customer_credit_invoice.php
sales/customer_delivery.php
sales/customer_invoice.php
sales/includes/db/branches_db.inc
sales/includes/db/cust_trans_db.inc
sales/includes/db/customers_db.inc
sales/includes/db/sales_order_db.inc
sales/includes/sales_ui.inc
sales/inquiry/customer_inquiry.php
sales/inquiry/sales_deliveries_view.php
sales/inquiry/sales_orders_view.php
sales/manage/customer_branches.php
sales/sales_order_entry.php
sql/alter2.4.php
sql/alter2.4.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index 45294376db2c38bfc262a99fac70dd554ab62cf2..b2bad446a0ae408754c1c3f1005c6836b3bb596e 100644 (file)
@@ -43,6 +43,7 @@ function defaultCompany()
                document.getElementById('log_msg').innerHTML='$demo_text'}, 1000*$login_delay);</script>";
            $demo_text = $blocked_msg;
        }
+       flush_dir(user_js_cache());
        if (!isset($def_coy))
                $def_coy = 0;
        $def_theme = "default";
index 372faa71637995cff71b84c3f94d9658f5060d93..59166a3a3f9a91f266b04f06f340e47937d71306 100644 (file)
@@ -52,20 +52,11 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
        }
 } 
 
-function key_in_crm_contacts($id) // extra function for testing foreign concatenated key. Joe 02.09.2013.
-{
-       $row = get_crm_category($id);
-       $sql = "SELECT COUNT(*) FROM ".TB_PREF."crm_contacts WHERE type='".$row['type']."' AND action='".$row['action']."'";
-       $result = db_query($sql, "check relations for crm_contacts failed");
-       $contacts = db_fetch($result);
-       return $contacts[0];
-}
-
 if ($Mode == 'Delete')
 {
        $cancel_delete = 0;
 
-       if (key_in_crm_contacts($selected_id))
+       if (is_crm_category_used($selected_id))
        {
                $cancel_delete = 1;
                display_error(_("Cannot delete this category because there are contacts related to it."));
index 9fd2e68c27adf2931ce65aeb9bb01586bd801526..e1ff68aad48c59a6e1026a32cbfc47cda1a3b1c5 100644 (file)
@@ -82,7 +82,7 @@ function set_company_pref($pref, $category, $type, $length, $value)
 
 function refresh_sys_prefs()
 {
-       flush_dir(company_path().'/js_cache'); // clear cache
+       flush_dir(user_js_cache()); // clear cache
        unset($_SESSION['SysPrefs']);
        get_company_prefs();
 }
@@ -193,4 +193,27 @@ function key_in_foreign_table($id, $tables, $stdkey)
        return $count[0];
 }
 
+//---------------------------------------------------------------------------------------------
+//
+// Resets $theme references in users records to 'default'.
+//
+function clean_user_themes($theme)
+{
+       global $db_connections, $db, $installed_extensions;
+
+       $comp = user_company();
+
+       foreach ($db_connections as $n => $conn) {
+               $db = $_SESSION["wa_current_user"]->set_db_connection($n);
+               $sql = "UPDATE {$conn['tbpref']}users SET theme='default' WHERE theme='$theme'";
+               if (!db_query($sql, 'Cannot update user theme settings'))
+                       return false;
+       }
+       $db = $_SESSION["wa_current_user"]->set_db_connection($comp);
+
+       $_SESSION['wa_current_user']->prefs->theme = 'default';
+       return true;
+}
+
+
 ?>
\ No newline at end of file
index 19d22970c68b0c1f294f3d5bacd740735fdf7725..f59934fb8cbb9142d6725c1b7afb085111fc82d6 100644 (file)
@@ -64,4 +64,163 @@ function transaction_exists($trans_type, $trans_no)
 {
        return db_num_rows(db_query(get_sql_for_view_transactions($trans_type, $trans_no, $trans_no, $dummy)));
 }
+
+//
+//     Returns counterparty (supplier/customer) name for selected transaction.
+//
+function get_counterparty_name($trans_type, $trans_no, $full=true)
+{
+       switch($trans_type)
+       {
+               case ST_SALESORDER:
+               case ST_SALESQUOTE:
+                       $sql = "SELECT order.customer_id as person_id, debtor.name as name
+                       FROM ".TB_PREF."sales_orders order, ".TB_PREF."debtors_master debtor
+                       WHERE order_no=".db_escape($trans_no)." AND trans_type=".db_escape($trans_type)
+                       ." AND order.debtor_no=debtor.debtor_no";
+                       break;
+
+               case ST_RECEIPTINVOICE :
+               case ST_SALESINVOICE :
+               case ST_CUSTCREDIT :
+               case ST_CUSTPAYMENT :
+               case ST_CUSTDELIVERY :
+                       $sql = "SELECT trans.debtor_no as person_id, debtor.name as name
+                       FROM ".TB_PREF."debtor_trans trans, ".TB_PREF."debtors_master debtor
+                       WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+                       ." AND trans.debtor_no=debtor.debtor_no";
+                       break;
+
+               case ST_PURCHORDER :
+                       $sql = "SELECT order.supplier_id as person_id, supp.supp_name as name
+                       FROM ".TB_PREF."purch_orders order, ".TB_PREF."suppliers supp
+                       WHERE order_no=".db_escape($trans_no)
+                       ." AND order.supplier_id=supp.supplier_id";
+                       break;
+
+               case ST_SUPPINVOICE :
+               case ST_SUPPCREDIT :
+               case ST_SUPPAYMENT :
+                       $sql = "SELECT trans.supplier_id as person_id, supp.supp_name as name
+                       FROM ".TB_PREF."supp_trans trans, ".TB_PREF."suppliers supp
+                       WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+                       ." AND trans.supplier_id=supp.supplier_id";
+                       break;
+
+               case ST_SUPPRECEIVE :
+                       $sql = "SELECT trans.supplier_id as person_id, supp.supp_name as name
+                       FROM ".TB_PREF."grn_batch trans, ".TB_PREF."suppliers supp
+                       WHERE id=".db_escape($trans_no)
+                       ." AND trans.supplier_id=supp.supplier_id";
+                       break;
+
+               case ST_BANKPAYMENT :
+               case ST_BANKDEPOSIT :
+                       $sql = "SELECT trans.debtor_no as person_id, debtor.name as name
+                       FROM ".TB_PREF."debtor_trans trans, ".TB_PREF."debtors_master debtor
+                       WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+                       ." AND trans.debtor_no=debtor.debtor_no
+                       UNION
+                               SELECT trans.supplier_id as person_id, supp.supp_name as name
+                       FROM ".TB_PREF."supp_trans trans, ".TB_PREF."suppliers supp
+                       WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type)
+                       ." AND trans.supplier_id=supp.supplier_id";
+                       break;
+
+               case ST_JOURNAL:        // FIXME - this one can have multiply counterparties of various types depending on person_type_id
+
+               default: 
+               /*      // internal operations
+               case ST_WORKORDER :
+               case ST_INVADJUST : // GRN/DN returns ?
+               case ST_BANKTRANSFER :
+               case ST_LOCTRANSFER :
+               case ST_MANUISSUE :
+               case ST_MANURECEIVE :
+               case ST_COSTUPDATE :
+               */
+                       return null;
+       }
+
+       $result = db_query($sql, 'cannot retrieve counterparty name');
+       if (db_num_rows($result))
+       {
+               $row = db_fetch($result);
+               return sprintf("[%05s] %s", $row['person_id'], $row['name']);
+       }
+
+       return '';
+}
+
+
+//-----------------------------------------------------------------------------------------
+//     Returns next transaction number.
+//     Used only for transactions stored in tables without autoincremented key.
+//
+
+function get_next_trans_no ($trans_type){
+
+       $st = get_systype_db_info($trans_type);
+
+       if (!($st && $st[0] && $st[2])) {
+               // this is in fact internal error condition.
+               display_error('Internal error: invalid type passed to get_next_trans_no()');
+               return 0;
+       }
+       $sql1 = "SELECT MAX(`$st[2]`) as last_no FROM $st[0]";
+       if ($st[1] != null)
+                $sql1 .= " WHERE `$st[1]`=".db_escape($trans_type);
+
+       // check also in voided transactions (some transactions like location transfer are removed completely)
+       $sql2 = "SELECT MAX(`id`) as last_no FROM ".TB_PREF."voided WHERE `type`=".db_escape($trans_type);
+
+       $sql = "SELECT max(last_no) last_no FROM ($sql1 UNION $sql2) a";
+    $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved");
+    $myrow = db_fetch_row($result);
+
+    return $myrow[0] + 1;
+}
+
+//-----------------------------------------------------------------------------
+
+function get_systype_db_info($type)
+{
+       switch ($type)
+       {
+        case     ST_JOURNAL      : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
+        case     ST_BANKPAYMENT  : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
+        case     ST_BANKDEPOSIT  : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
+        case     3               : return null;
+        case     ST_BANKTRANSFER : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
+        case     ST_SALESINVOICE : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+        case     ST_CUSTCREDIT   : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+        case     ST_CUSTPAYMENT  : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+        case     ST_CUSTDELIVERY : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
+        case     ST_LOCTRANSFER  : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
+        case     ST_INVADJUST    : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
+        case     ST_PURCHORDER   : return array("".TB_PREF."purch_orders", null, "order_no", "reference", "ord_date");
+        case     ST_SUPPINVOICE  : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
+        case     ST_SUPPCREDIT   : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
+        case     ST_SUPPAYMENT   : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
+        case     ST_SUPPRECEIVE  : return array("".TB_PREF."grn_batch", null, "id", "reference", "delivery_date");
+        case     ST_WORKORDER    : return array("".TB_PREF."workorders", null, "id", "wo_ref", "released_date");
+        case     ST_MANUISSUE    : return array("".TB_PREF."wo_issues", null, "issue_no", "reference", "issue_date");
+        case     ST_MANURECEIVE  : return array("".TB_PREF."wo_manufacture", null, "id", "reference", "date_");
+        case     ST_SALESORDER   : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
+        case     31              : return array("".TB_PREF."service_orders", null, "order_no", "cust_ref", "date");
+        case     ST_SALESQUOTE   : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
+        case    ST_DIMENSION    : return array("".TB_PREF."dimensions", null, "id", "reference", "date_");
+        case     ST_COSTUPDATE   : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
+       }
+
+       display_db_error("invalid type ($type) sent to get_systype_db_info", "", true);
+}
+
+function get_systypes()
+{
+       $sql = "SELECT * FROM ".TB_PREF."sys_types";
+       $result = db_query($sql, "could not query systypes table");
+       return $result;
+}
+
 ?>
index 85406a8c3b7aeaee4c4fcfc62714f49de21444d6..9b60dc55949b2fd56575bc12e42655058c8e006d 100644 (file)
@@ -76,9 +76,9 @@ number_list_row(_("Quantities:"), 'qty_dec', user_qty_dec(), 0, 10);
 number_list_row(_("Exchange Rates:"), 'rates_dec', user_exrate_dec(), 0, 10);
 number_list_row(_("Percentages:"), 'percent_dec', user_percent_dec(), 0, 10);
 
-table_section_title(_("Dateformat and Separators"));
+table_section_title(_("Date Format and Separators"));
 
-dateformats_list_row(_("Dateformat:"), "date_format", user_date_format());
+dateformats_list_row(_("Date Format:"), "date_format", user_date_format());
 
 dateseps_list_row(_("Date Separator:"), "date_sep", user_date_sep());
 
index af640e883b915f30f86348804f2aeb85334ce8e9..01f6ca1ad698fc5db76aa888313db82c3d32ee8e 100644 (file)
@@ -25,28 +25,9 @@ include_once($path_to_root . "/admin/db/maintenance_db.inc");
 include_once($path_to_root . "/includes/ui.inc");
 
 //---------------------------------------------------------------------------------------------
-// If theme is used in customer record set to default
-//
-function clean_user_themes($id)
-{
-       global $db_connections, $db, $installed_extensions;
-
-       $theme = $installed_extensions[$id]['package'];
-       $comp = user_company();
-
-       foreach ($db_connections as $n => $conn) {
-               $db = $_SESSION["wa_current_user"]->set_db_connection($n);
-               $sql = "UPDATE {$conn['tbpref']}users SET theme='default' WHERE theme='$theme'";
-               if (!db_query($sql, 'Cannot update user theme settings'))
-                       return false;
-       }
-       $db = $_SESSION["wa_current_user"]->set_db_connection($comp);
-
-       $_SESSION['wa_current_user']->prefs->theme = 'default';
-       return true;
-}
 
-if (($id = find_submit('Delete', false)) && clean_user_themes($id))
+if (($id = find_submit('Delete', false))
+       && clean_user_themes($installed_extensions[$id]['package']))
 {
        $extensions = get_company_extensions();
        $theme = $extensions[$id]['package'];
index 3bd30f3c6642e46cef9c6d5ac3574c653f18b18a..7331cc02a0f8d4b959dc10df21b83a71a389144c 100644 (file)
@@ -181,8 +181,8 @@ function get_dimension_balance($id, $from, $to)
 
 //--------------------------------------------------------------------------------------
 
-function get_sql_for_search_dimensions($dim)
-{      
+function get_sql_for_search_dimensions($dim, $from, $to, $order='', $type = -1, $open=false, $overdue = false)
+{
        $sql = "SELECT dim.id,
                dim.reference,
                dim.name,
@@ -192,34 +192,30 @@ function get_sql_for_search_dimensions($dim)
                dim.closed
                FROM ".TB_PREF."dimensions as dim WHERE id > 0";
 
-       if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
+       if ($order)
        {
-               $sql .= " AND reference LIKE ".db_escape("%". $_POST['OrderNumber'] . "%");
+               $sql .= " AND reference LIKE ".db_escape("%". $order . "%");
        } else {
 
                if ($dim == 1)
                        $sql .= " AND type_=1";
 
-               if (isset($_POST['OpenOnly']))
-               {
+               if ($open)
                        $sql .= " AND closed=0";
-               }
 
-               if (isset($_POST['type_']) && ($_POST['type_'] > 0))
-               {
-                       $sql .= " AND type_=".db_escape($_POST['type_']);
-               }
+               if ($type > 0)
+                       $sql .= " AND type_=".db_escape($type);
 
-               if (isset($_POST['OverdueOnly']))
+               if ($overdue)
                {
                        $today = date2sql(Today());
 
                        $sql .= " AND due_date < '$today'";
                }
 
-               $sql .= " AND date_ >= '" . date2sql($_POST['FromDate']) . "'
-                       AND date_ <= '" . date2sql($_POST['ToDate']) . "'";
+               $sql .= " AND date_ >= '" . date2sql($from) . "'
+                       AND date_ <= '" . date2sql($to) . "'";
        }
        return $sql;
-}      
+}
 ?>
\ No newline at end of file
index 8a3330467cde2bf1e85509625c61f3db5f177a89..abca12008aa77ec20ec9e965baffa63fefd2fb52 100644 (file)
@@ -121,7 +121,8 @@ function edit_link($row)
                        "/dimensions/dimension_entry.php?trans_no=" . $row["id"], ICON_EDIT);
 }
 
-$sql = get_sql_for_search_dimensions($dim);
+$sql = get_sql_for_search_dimensions($dim, $_POST['FromDate'], $_POST['ToDate'],
+       $_POST['OrderNumber'], $_POST['type_'], $_POST['OpenOnly'], $_POST['OverdueOnly']);
 
 $cols = array(
        _("#") => array('fun'=>'view_link'), 
index ce11a325607e6bfb2807ec86cc991f371e714de0..00b8fbe34698076501bd17479bf01c3a7ddda7ea 100644 (file)
@@ -227,4 +227,22 @@ function gl_account_in_bank_accounts($acc)
        $myrow = db_fetch_row($result);
        return ($myrow[0] > 0); 
 }
-?>
\ No newline at end of file
+
+//----------------------------------------------------------------------------------
+//     Check if given account is used by any bank_account. 
+//     Returns id of first bank_account using account_code, null otherwise.
+//
+//     Keep in mind that direct posting to bank account is depreciated
+//     because we have no way to select right bank account if 
+//     there is more than one using given gl account.
+//
+function is_bank_account($account_code)
+{
+       $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code=".db_escape($account_code);
+       $result = db_query($sql, "checking account is bank account");
+       if (db_num_rows($result) > 0) {
+               $acct = db_fetch($result);
+               return $acct['id'];
+       } else
+               return false;
+}
index a4ffd9862665bf2837af43fb487619d47d0453c4..5facce63e4ec10f72b3159d12ecadebe98223b4f 100644 (file)
@@ -308,7 +308,7 @@ function update_reconciled_values($reconcile_id, $reconcile_value, $reconcile_da
 }
 //---------------------------------------------------------------------------------------------
 
-function get_default_bank_account($curr)
+function get_default_bank_account($curr=null)
 {
        /* default bank account is selected as first found account from:
                . default account in $curr if any
@@ -317,6 +317,8 @@ function get_default_bank_account($curr)
                . first defined account in home currency
        */
        $home_curr = get_company_pref('curr_default');
+       if (!isset($curr))
+               $curr = $home_curr;
 
        $sql = "SELECT b.*, b.bank_curr_code='$home_curr' as fall_back FROM "
                .TB_PREF."bank_accounts b"
@@ -376,4 +378,15 @@ function identify_bank_account($account_number)
                return null;
 }
 
+//----------------------------------------------------------------------------------
+
+function get_bank_account_currency($id)
+{
+       $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
+       $result = db_query($sql, "retreive bank account currency");
+
+       $myrow = db_fetch_row($result);
+       return $myrow[0];
+}
+
 ?>
\ No newline at end of file
index 70ab230a630b3e2758ed64080b3fe675ca8cb8f8..9a64fcfa9e698d600466ecac6623e90b25891ae0 100644 (file)
@@ -33,6 +33,25 @@ function get_date_exchange_rate($curr_code, $date_)
                return $row[0];
 }
 
+/*
+       Return last exchange rate of $currency not later than $date.
+*/
+function get_last_exchange_rate($curr_code, $date_)
+{
+       $date = date2sql($date_);
+
+       $sql = "SELECT rate_buy, max(date_) as date_ FROM ".TB_PREF."exchange_rates WHERE curr_code = ".db_escape($curr_code)."
+                               AND date_ <= '$date' GROUP BY rate_buy ORDER BY date_ Desc LIMIT 1";
+
+       $result = db_query($sql, "could not query exchange rates");
+
+
+       if (db_num_rows($result) == 0)
+               return false;
+
+       return db_fetch_row($result);
+}
+
 //---------------------------------------------------------------------------------------------
 
 function update_exchange_rate($curr_code, $date_, $buy_rate, $sell_rate)
@@ -218,11 +237,11 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
 
 //-----------------------------------------------------------------------------
 
-function get_sql_for_exchange_rates()
+function get_sql_for_exchange_rates($curr)
 {
        $sql = "SELECT date_, rate_buy, id FROM "
                .TB_PREF."exchange_rates "
-               ."WHERE curr_code=".db_escape($_POST['curr_abrev'])."
+               ."WHERE curr_code=".db_escape($curr)."
                 ORDER BY date_ DESC";
        return $sql;     
 }
index 4ce1673cded0ba8d5675ef9a938dd34efc10ff7a..fab38033bd018a29d208a618f2d9f5663f46f76d 100644 (file)
@@ -189,7 +189,7 @@ if ($_POST['curr_abrev'] != get_global_curr_code())
 
 set_global_curr_code($_POST['curr_abrev']);
 
-$sql = get_sql_for_exchange_rates();
+$sql = get_sql_for_exchange_rates($_POST['curr_abrev']);
 
 $cols = array(
        _("Date to Use From") => 'date', 
index 53af3598b8580b7c3263d6fb46937a201e24a08b..515da8b0bd0d79ddea372f41c20b80d8a56c0bf6 100644 (file)
 ***********************************************************************/
 include_once($path_to_root . "/gl/includes/gl_db.inc");
 
-//----------------------------------------------------------------------------------
-//     Check if given account is used by any bank_account. 
-//     Returns id of first bank_account using account_code, null otherwise.
-//
-//     Keep in mind that direct posting to bank account is depreciated
-//     because we have no way to select right bank account if 
-//     there is more than one using given gl account.
-//
-function is_bank_account($account_code)
-{
-       $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code=".db_escape($account_code);
-       $result = db_query($sql, "checking account is bank account");
-       if (db_num_rows($result) > 0) {
-               $acct = db_fetch($result);
-               return $acct['id'];
-       } else
-               return false;
-}
-
 //----------------------------------------------------------------------------------
 
 function is_company_currency($currency)
@@ -46,54 +27,15 @@ function get_company_currency()
 
 //----------------------------------------------------------------------------------
 
-function get_bank_account_currency($id)
-{
-       $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
-       $result = db_query($sql, "retreive bank account currency");
-
-       $myrow = db_fetch_row($result);
-       return $myrow[0];
-}
-
-//----------------------------------------------------------------------------------
-
-function get_customer_currency($customer_id)
-{
-    $sql = "SELECT curr_code FROM ".TB_PREF."debtors_master WHERE debtor_no = ".db_escape($customer_id);
-
-       $result = db_query($sql, "Retreive currency of customer $customer_id");
-
-       $myrow=db_fetch_row($result);
-       return $myrow[0];
-}
-
-//----------------------------------------------------------------------------------
-
-function get_supplier_currency($supplier_id)
-{
-    $sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id = ".db_escape($supplier_id);
-
-       $result = db_query($sql, "Retreive currency of supplier $supplier_id");
-
-       $myrow=db_fetch_row($result);
-       return $myrow[0];
-}
-
-//----------------------------------------------------------------------------------
-
 function get_exchange_rate_from_home_currency($currency_code, $date_)
 {
        if ($currency_code == get_company_currency() || $currency_code == null)
                return 1.0000;
 
-       $date = date2sql($date_);
-
-       $sql = "SELECT rate_buy, max(date_) as date_ FROM ".TB_PREF."exchange_rates WHERE curr_code = ".db_escape($currency_code)."
-                               AND date_ <= '$date' GROUP BY rate_buy ORDER BY date_ Desc LIMIT 1";
 
-       $result = db_query($sql, "could not query exchange rates");
+       $rate = get_last_exchange_rate($currency_code, $date_);
 
-       if (db_num_rows($result) == 0)
+       if (!$rate)
        {
                // no stored exchange rate, just return 1
                display_error(
@@ -102,8 +44,7 @@ function get_exchange_rate_from_home_currency($currency_code, $date_)
                return 1.000;
        }
 
-       $myrow = db_fetch_row($result);
-       return $myrow[0];
+       return $rate['rate_buy'];
 }
 
 //----------------------------------------------------------------------------------
index 26b288a1e884463a22dd677521f04f205c041a25..eea6d1b9d5a423e98c49aa941bcbedbed7f5498e 100644 (file)
@@ -136,6 +136,7 @@ class current_user
                        $this->logged = true;
                                $this->last_act = time();
                                $this->timeout = session_timeout();
+                               flush_dir(user_js_cache()); // refresh cache on login
                        }
                }
                return $this->logged;
@@ -598,6 +599,18 @@ function add_user_js_data() {
   add_js_source($js);
 }
 
+function user_js_cache($id=null)
+{
+       global $path_to_root;
+
+       if (!$id)
+               $id = @$_SESSION['wa_current_user']->user;
+
+       if (!$id)
+               $id = 0; // before login
+       return $path_to_root.'/company/'.user_company().'/js_cache/'.$id;
+}
+
 //--------------------------------------------------------------------------
 
 function session_timeout()
@@ -688,7 +701,7 @@ function recalculate_cols(&$cols)
 
 function flush_dir($path, $wipe = false) 
 {
-       $dir = opendir($path);
+       $dir = @opendir($path);
        if(!$dir)
                return;
 
index 8623c8e0043525755a07ff8a2248ef76dbc7556e..a226e496c81f3a583a0eb8c786228dd84e3bdd39 100644 (file)
@@ -300,4 +300,17 @@ function get_crm_contact($id)
        return $ret;
 }
 
+/*
+        Check for whether category is used in contacts.
+*/
+function is_crm_category_used($id)
+{
+       $row = get_crm_category($id);
+       $sql = "SELECT COUNT(*) FROM ".TB_PREF."crm_contacts WHERE type='".$row['type']."' AND action='".$row['action']."'";
+       $result = db_query($sql, "check relations for crm_contacts failed");
+       $contacts = db_fetch($result);
+       return $contacts[0];
+}
+
+
 ?>
\ No newline at end of file
index ca086541bb55ce019c778e1ab48a8eb16a7e346d..87aa6515f797b3c9719d946933d9e7b8caef0dba 100644 (file)
@@ -76,4 +76,48 @@ function get_next_reference($type)
     return $row[0];
 }
 
+//----------------------------------------------------------------------------
+//
+//     Check if reference was not used so far (for other transaction than $trans_no)
+//
+function is_new_reference($ref, $type, $trans_no=0)
+{
+       $db_info = get_systype_db_info($type);
+       $db_name = $db_info[0];
+       $db_type = $db_info[1];
+       $db_trans = $db_info[2];
+       $db_ref = $db_info[3];
+       
+       $ref = db_escape(trim($ref));
+       $type = db_escape($type);
+       
+       if ($db_ref == null) { // journal or bank trans store references in refs table
+               $db_name = TB_PREF."refs";
+               $db_type = 'type';
+               $db_trans = 'id';
+               $db_ref = 'reference';
+       }
+
+       if ($db_type != null) {
+               $sql = "SELECT $db_ref FROM $db_name tbl
+                       LEFT JOIN ".TB_PREF."voided v ON 
+                               tbl.$db_type=v.type AND tbl.$db_trans=v.id
+                       WHERE $db_ref=$ref AND ISNULL(v.id)
+                               AND tbl.$db_type=$type";
+       } else {
+               $sql = "SELECT $db_ref ref FROM $db_name tbl
+                       LEFT JOIN ".TB_PREF."voided v ON 
+                               v.type=$type AND tbl.$db_trans=v.id
+                       WHERE $db_ref=$ref AND ISNULL(v.id)";
+       }
+       if ($trans_no)
+                       $sql .= " AND tbl.`$db_trans` != ".db_escape($trans_no);
+
+       $result = db_query($sql, "could not test for unique reference");
+
+       return (db_num_rows($result) == 0);
+
+}
+
+
 ?>
\ No newline at end of file
index 1102271b658094677b6522362ce5bcf942cb7431..5deae97bfa29c8887ec878f51b9665271489b242 100644 (file)
@@ -71,9 +71,7 @@ function error_handler($errno, $errstr, $file, $line) {
                }
        }
 
-       if ($go_debug>1) {
-               $bt = get_backtrace(true, 1);
-       }
+       $bt = $go_debug>1 ? get_backtrace(true, 1) : array();
 
        // error_reporting==0 when messages are set off with @ 
        if ($errno & error_reporting()) {
@@ -196,7 +194,7 @@ function display_db_error($msg, $sql_statement=null, $exit=true)
        }
        
        $str .= "<br><br>";
-       if ($go_debug)
+       if (!$go_debug)
                error_log($str);
        else {
                if($msg)
diff --git a/includes/lang/gettext.inc b/includes/lang/gettext.inc
new file mode 100644 (file)
index 0000000..72f2460
--- /dev/null
@@ -0,0 +1,572 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+//  
+//  Copyright (c) 2003 Laurent Bedubourg
+//  
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License, or (at your option) any later version.
+//  
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//  
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//  
+//  Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
+//  
+
+//require_once "PEAR.php";
+
+define('GETTEXT_NATIVE', 1);
+define('GETTEXT_PHP', 2);
+
+function get_text_init($managerType = GETTEXT_NATIVE) {
+       global $GetText;
+       if (!isset($GetText)) {
+
+        if ($managerType == GETTEXT_NATIVE) 
+        {
+            if (function_exists('gettext')) 
+            {
+                $GetText = new gettext_native_support();
+                return;
+            }
+        }
+        // fail back to php support 
+               $GetText = new gettext_php_support();
+       }
+}
+
+function raise_error($str) {
+       error_log($str);
+       return 1;
+}
+
+function is_error($err) {
+    return $err > 0;
+}
+
+/**
+* Interface to gettext native support.
+*
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+* @access private
+*/
+class gettext_native_support 
+{
+    var $_interpolation_vars = array();
+    var $domain_path;
+
+    /**
+     * Set gettext language code.
+     * @throws GetText_Error
+     */
+    function set_language($lang_code, $encoding)
+    {
+        putenv("LANG=$lang_code");
+        putenv("LC_ALL=$lang_code");
+        putenv("LANGUAGE=$lang_code");
+
+        //$set = setlocale(LC_ALL, "$lang_code");
+        //$set = setlocale(LC_ALL, "$encoding");
+
+               // cover a couple of country/encoding variants 
+               $up = strtoupper($encoding);
+               $low = strtolower($encoding);
+               $lshort = strtr($up, '-','');
+               $ushort = strtr($low, '-','');
+
+               if ($lang_code == 'C')
+                       $set = setlocale(LC_ALL,'C');
+               else
+               $set = setlocale(LC_ALL, $lang_code.".".$encoding, 
+                               $lang_code.".".$up, $lang_code.".".$low,
+                               $lang_code.".".$ushort, $lang_code.".".$lshort);
+
+        setlocale(LC_NUMERIC, 'C'); // important for numeric presentation etc.
+        if ($set === false) 
+        {
+                       if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
+                               return 0;
+            $str = sprintf('language code "%s", encoding "%s" not supported by your system',
+                $lang_code, $encoding);
+            //$err = new GetText_Error($str);
+            //return PEAR::raise_error($err);
+                       return raise_error("1 " . $str);
+        }
+               //return 0;
+    }
+    /**
+        *      Check system support for given language nedded for gettext.
+        */
+       function check_support($lang_code, $encoding)
+    {
+               if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
+                       return true;
+               $old = setlocale(LC_CTYPE, '0'); // LC_MESSAGES does not exist on Win
+               $up = strtoupper($encoding);
+               $low = strtolower($encoding);
+               $lshort = strtr($up, '-','');
+               $ushort = strtr($low, '-','');
+
+        $test = setlocale(LC_ALL,
+                       $lang_code.".".$encoding, 
+                       $lang_code.".".$up,
+                       $lang_code.".".$low,
+                       $lang_code.".".$ushort,
+                       $lang_code.".".$lshort) !== false;
+               setlocale(LC_ALL, $old);
+               setlocale(LC_NUMERIC, 'C');
+               return $test;
+       }
+    /**
+     * Add a translation domain.
+     */
+    function add_domain($domain, $path=false, $version='')
+    {
+        if ($path === false) 
+               $path = $this->domain_path;
+        if ($path === false) 
+               $path = "./locale";
+           if ($domain == "")
+               $domain = "?";
+               if ($version) {
+       // To avoid need for apache server restart after change of *.mo file
+       // we have to include file version as part of filename.
+       // This is alternative naming convention: $domain = $version.'/'.$domain;
+                       $domain .= '-'.$version;
+               }
+        bindtextdomain($domain, $path);
+        //bind_textdomain_codeset($domain, $encoding);
+        textdomain($domain);
+    }
+
+    /**
+     * Retrieve translation for specified key.
+     *
+     * @access private
+     */
+    function _get_translation($key)
+    {
+        return gettext($key);
+    }
+    
+
+    /**
+     * Reset interpolation variables.
+     */
+    function reset()
+    {
+        $this->_interpolation_vars = array();
+    }
+    
+    /**
+     * Set an interpolation variable.
+     */
+    function set_var($key, $value)
+    {
+        $this->_interpolation_vars[$key] = $value;
+    }
+
+    /**
+     * Set an associative array of interpolation variables.
+     */
+    function set_vars($hash)
+    {
+        $this->_interpolation_vars = array_merge($this->_interpolation_vars,
+                                                $hash);
+    }
+    
+    /**
+     * Retrieve translation for specified key.
+     *
+     * @param  string $key  -- gettext msgid
+     * @throws GetText_Error
+     */
+    function gettext($key)
+    {
+       $value = $this->_get_translation($key);
+        if ($value === false) {
+            $str = sprintf('Unable to locate gettext key "%s"', $key);
+            //$err = new GetText_Error($str);
+            //return PEAR::raise_error($err);
+                       return raise_error("2 " . $str);
+        }
+        
+        while (preg_match('/\$\{(.*?)\}/sm', $value, $m)) {
+            list($src, $var) = $m;
+
+            // retrieve variable to interpolate in context, throw an exception
+            // if not found.
+            $var2 = $this->_get_var($var);
+            if ($var2 === false) {
+                $str = sprintf('Interpolation error, var "%s" not set', $var);
+                //$err = new GetText_Error($str);
+                //return PEAR::raise_error($err);
+                return raise_error("3 " . $str);
+            }
+            $value = str_replace($src, $var2, $value);
+        }
+        return $value;
+    }
+
+    /**
+     * Retrieve an interpolation variable value.
+     * 
+     * @return mixed
+     * @access private
+     */
+    function _get_var($name)
+    {
+        if (!array_key_exists($name, $this->_interpolation_vars)) {
+            return false;
+        }
+        return $this->_interpolation_vars[$name];
+    }
+}
+
+
+/**
+* Implementation of get_text support for PHP.
+*
+* This implementation is abble to cache .po files into php files returning the
+* domain translation hashtable.
+*
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_php_support extends gettext_native_support
+{
+    var $_path     = 'locale/';
+    var $_lang_code = false;
+    var $_domains  = array();
+    var $_end      = -1;
+    var $_jobs     = array();
+
+    /**
+     * Set the translation domain.
+     *
+     * @param  string $lang_code -- language code
+     * @throws GetText_Error
+     */
+    function set_language($lang_code, $encoding)
+    {
+        // if language already set, try to reload domains
+        if ($this->_lang_code !== false and $this->_lang_code != $lang_code) 
+        {
+            foreach ($this->_domains as $domain) 
+            {
+                $this->_jobs[] = array($domain->name, $domain->path);
+            }
+            $this->_domains = array();
+            $this->_end = -1;
+        }
+        
+        $this->_lang_code = $lang_code;
+
+        // this allow us to set the language code after 
+        // domain list.
+        while (count($this->_jobs) > 0) 
+        {
+            list($domain, $path) = array_shift($this->_jobs);
+            $err = $this->add_domain($domain, $path);
+            // error raised, break jobs
+            /*if (PEAR::is_error($err)) {
+                return $err;
+            }*/
+                       if (is_error($err)) 
+                       {
+                return $err;
+            }            
+        }
+    }
+    /**
+        *      Check system support for given language (dummy).
+        */
+       function check_support($lang_code, $encoding)
+    {
+               return true;
+    }
+    /**
+     * Add a translation domain.
+     *
+     * @param string $domain        -- Domain name
+     * @param string $path optional -- Repository path
+     * @throws GetText_Error
+     */
+    function add_domain($domain, $path = false, $version ='')
+    {   
+        if ($path === false) 
+             $path = $this->domain_path;
+        if ($path === false) 
+               $path = "./locale";
+
+       if ($version) {
+                       $domain .= '-'.$version;
+               }
+
+        if (array_key_exists($domain, $this->_domains)) 
+        { 
+            return; 
+        }
+        
+        if (!$this->_lang_code) 
+        { 
+            $this->_jobs[] = array($domain, $path); 
+            return;
+        }
+        // Don't fill the domains with false data, it increased the error.log
+               if (strpos($domain, $this->_lang_code) === false)
+               return;
+        $err = $this->_load_domain($domain, $path);
+        if ($err != 0) 
+        {
+            return $err;
+        }
+
+        $this->_end++;
+    }
+
+    /**
+     * Load a translation domain file.
+     *
+     * This method cache the translation hash into a php file unless
+     * GETTEXT_NO_CACHE is defined.
+     * 
+     * @param  string $domain        -- Domain name
+     * @param  string $path optional -- Repository
+     * @throws GetText_Error
+     * @access private
+     */
+    function _load_domain($domain, $path = "./locale")
+    {
+        $src_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.po";
+        $php_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.php";
+        
+        if (!file_exists($src_domain)) 
+        {
+            $str = sprintf('Domain file "%s" not found.', $src_domain);
+            //$err = new GetText_Error($str);
+            //return PEAR::raise_error($err);
+                       return raise_error("4 " . $str);
+        }
+        
+        $d = new gettext_domain();
+        $d->name = $domain;
+        $d->path = $path;
+        if (!file_exists($php_domain) || (filemtime($php_domain) < filemtime($src_domain))) 
+        {
+            
+            // parse and compile translation table
+            $parser = new gettext_php_support_parser();
+            $hash   = $parser->parse($src_domain);
+            if (!defined('GETTEXT_NO_CACHE')) 
+            {
+                $comp = new gettext_php_support_compiler();
+                $err  = $comp->compile($hash, $src_domain);
+                /*if (PEAR::is_error($err)) { 
+                    return $err; 
+                }*/
+                       if (is_error($err)) 
+                       {
+                    return $err;
+                } 
+            }
+            $d->_keys = $hash;
+        } 
+        else 
+        {
+            $d->_keys = include $php_domain;
+        }
+        $this->_domains[] = &$d;
+    }
+    
+    /**
+     * Implementation of gettext message retrieval.
+     */
+    function _get_translation($key)
+    {
+        for ($i = $this->_end; $i >= 0; $i--) 
+        {
+            if ($this->_domains[$i]->has_key($key)) 
+            {
+                return $this->_domains[$i]->get($key);
+            }
+        }
+        return $key;
+    }
+}
+
+/**
+* Class representing a domain file for a specified language.
+*
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_domain
+{
+    var $name;
+    var $path;
+
+    var $_keys = array();
+
+    function has_key($key)
+    {
+        return array_key_exists($key, $this->_keys);
+    }
+
+    function get($key)
+    {
+        return $this->_keys[$key];
+    }
+}
+
+/**
+* This class is used to parse gettext '.po' files into php associative arrays.
+*
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_php_support_parser 
+{
+    var $_hash = array();
+    var $_current_key;
+    var $_current_value;
+    
+    /**
+     * Parse specified .po file.
+     *
+     * @return hashtable
+     * @throws GetText_Error
+     */
+    function parse($file)
+    {
+        $this->_hash = array();
+        $this->_current_key = false;
+        $this->_current_value = "";
+        
+        if (!file_exists($file)) 
+        {
+            $str = sprintf('Unable to locate file "%s"', $file);
+            //$err = new GetText_Error($str);
+            //return PEAR::raise_error($err);
+                       return raise_error($str);
+        }
+        $i = 0;
+        $lines = file($file);
+        foreach ($lines as $line) 
+        {
+            $this->_parse_line($line, ++$i);
+        }
+        $this->_store_key();
+
+        return $this->_hash;
+    }
+
+    /**
+     * Parse one po line.
+     *
+     * @access private
+     */
+    function _parse_line($line, $nbr)
+    {
+        $line = str_replace("\\\"", "'", $line); // Should be inside preg_match, but I couldn't find the solution. This works.
+        if (preg_match('/^\s*?#/', $line)) { return; }
+        if (preg_match('/^\s*?msgid \"(.*?)(?!<\\\)\"/', $line, $m)) {
+            $this->_store_key();
+            $this->_current_key = $m[1];
+            return;
+        }
+        if (preg_match('/^\s*?msgstr \"(.*?)(?!<\\\)\"/', $line, $m)) {
+            $this->_current_value .= $m[1];
+            return;
+        }
+        if (preg_match('/^\s*?\"(.*?)(?!<\\\)\"/', $line, $m)) {
+            $this->_current_value .= $m[1];
+            return;
+        }
+    }
+
+    /**
+     * Store last key/value pair into building hashtable.
+     *
+     * @access private
+     */
+    function _store_key()
+    {
+        if ($this->_current_key === false) return;
+        $this->_current_value = str_replace('\\n', "\n", $this->_current_value);
+        $this->_hash[$this->_current_key] = $this->_current_value;
+        $this->_current_key = false;
+        $this->_current_value = "";
+    }
+}
+
+
+/**
+* This class write a php file from a gettext hashtable.
+*
+* The produced file return the translation hashtable on include.
+* 
+* @throws GetText_Error
+* @access private
+* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
+*/
+class gettext_php_support_compiler 
+{
+    /**
+     * Write hash in an includable php file.
+     */
+    function compile(&$hash, $source_path)
+    {
+        $dest_path = preg_replace('/\.po$/', '.php', $source_path);
+        $fp = @fopen($dest_path, "w");
+        if (!$fp) 
+        {
+            $str = sprintf('Unable to open "%s" in write mode.', $dest_path);
+            //$err = new GetText_Error($str);
+            //return PEAR::raise_error($err);
+                       return raise_error($str);
+        }
+        fwrite($fp, '<?php' . "\n");
+        fwrite($fp, 'return array(' . "\n");
+        foreach ($hash as $key => $value) 
+        {
+            $key   = str_replace("'", "\\'", $key);
+            $value = str_replace("'", "\\'", $value);
+            fwrite($fp, '    \'' . $key . '\' => \'' . $value . "',\n");
+        }
+        fwrite($fp, ');' . "\n");
+        fwrite($fp, '?>');
+        fclose($fp);
+    }
+}
+
+/*
+       Set current gettext domain path
+*/
+function set_ext_domain($path='') {
+       global $path_to_root, $GetText;
+       static $domain_stack = array('');
+
+       if ($path)      // save path on domain stack
+               array_unshift($domain_stack,  $path);
+       else
+       {
+               array_shift($domain_stack);
+               $path = $domain_stack[0];
+       }
+
+       $lang_path = $path_to_root . ($path ? '/' : '') .$path.'/lang';
+       // ignore change when extension does not provide translation structure and test for valid gettext.
+       if (file_exists($lang_path) && isset($GetText))
+               $GetText->add_domain($_SESSION['language']->code,
+                       $lang_path, $path ? '' : $_SESSION['language']->version);
+}
+?>
diff --git a/includes/lang/gettext.php b/includes/lang/gettext.php
deleted file mode 100644 (file)
index 72f2460..0000000
+++ /dev/null
@@ -1,572 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-//  
-//  Copyright (c) 2003 Laurent Bedubourg
-//  
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License, or (at your option) any later version.
-//  
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
-//  
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-//  
-//  Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
-//  
-
-//require_once "PEAR.php";
-
-define('GETTEXT_NATIVE', 1);
-define('GETTEXT_PHP', 2);
-
-function get_text_init($managerType = GETTEXT_NATIVE) {
-       global $GetText;
-       if (!isset($GetText)) {
-
-        if ($managerType == GETTEXT_NATIVE) 
-        {
-            if (function_exists('gettext')) 
-            {
-                $GetText = new gettext_native_support();
-                return;
-            }
-        }
-        // fail back to php support 
-               $GetText = new gettext_php_support();
-       }
-}
-
-function raise_error($str) {
-       error_log($str);
-       return 1;
-}
-
-function is_error($err) {
-    return $err > 0;
-}
-
-/**
-* Interface to gettext native support.
-*
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-* @access private
-*/
-class gettext_native_support 
-{
-    var $_interpolation_vars = array();
-    var $domain_path;
-
-    /**
-     * Set gettext language code.
-     * @throws GetText_Error
-     */
-    function set_language($lang_code, $encoding)
-    {
-        putenv("LANG=$lang_code");
-        putenv("LC_ALL=$lang_code");
-        putenv("LANGUAGE=$lang_code");
-
-        //$set = setlocale(LC_ALL, "$lang_code");
-        //$set = setlocale(LC_ALL, "$encoding");
-
-               // cover a couple of country/encoding variants 
-               $up = strtoupper($encoding);
-               $low = strtolower($encoding);
-               $lshort = strtr($up, '-','');
-               $ushort = strtr($low, '-','');
-
-               if ($lang_code == 'C')
-                       $set = setlocale(LC_ALL,'C');
-               else
-               $set = setlocale(LC_ALL, $lang_code.".".$encoding, 
-                               $lang_code.".".$up, $lang_code.".".$low,
-                               $lang_code.".".$ushort, $lang_code.".".$lshort);
-
-        setlocale(LC_NUMERIC, 'C'); // important for numeric presentation etc.
-        if ($set === false) 
-        {
-                       if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
-                               return 0;
-            $str = sprintf('language code "%s", encoding "%s" not supported by your system',
-                $lang_code, $encoding);
-            //$err = new GetText_Error($str);
-            //return PEAR::raise_error($err);
-                       return raise_error("1 " . $str);
-        }
-               //return 0;
-    }
-    /**
-        *      Check system support for given language nedded for gettext.
-        */
-       function check_support($lang_code, $encoding)
-    {
-               if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') // don't do this test if server is WIN
-                       return true;
-               $old = setlocale(LC_CTYPE, '0'); // LC_MESSAGES does not exist on Win
-               $up = strtoupper($encoding);
-               $low = strtolower($encoding);
-               $lshort = strtr($up, '-','');
-               $ushort = strtr($low, '-','');
-
-        $test = setlocale(LC_ALL,
-                       $lang_code.".".$encoding, 
-                       $lang_code.".".$up,
-                       $lang_code.".".$low,
-                       $lang_code.".".$ushort,
-                       $lang_code.".".$lshort) !== false;
-               setlocale(LC_ALL, $old);
-               setlocale(LC_NUMERIC, 'C');
-               return $test;
-       }
-    /**
-     * Add a translation domain.
-     */
-    function add_domain($domain, $path=false, $version='')
-    {
-        if ($path === false) 
-               $path = $this->domain_path;
-        if ($path === false) 
-               $path = "./locale";
-           if ($domain == "")
-               $domain = "?";
-               if ($version) {
-       // To avoid need for apache server restart after change of *.mo file
-       // we have to include file version as part of filename.
-       // This is alternative naming convention: $domain = $version.'/'.$domain;
-                       $domain .= '-'.$version;
-               }
-        bindtextdomain($domain, $path);
-        //bind_textdomain_codeset($domain, $encoding);
-        textdomain($domain);
-    }
-
-    /**
-     * Retrieve translation for specified key.
-     *
-     * @access private
-     */
-    function _get_translation($key)
-    {
-        return gettext($key);
-    }
-    
-
-    /**
-     * Reset interpolation variables.
-     */
-    function reset()
-    {
-        $this->_interpolation_vars = array();
-    }
-    
-    /**
-     * Set an interpolation variable.
-     */
-    function set_var($key, $value)
-    {
-        $this->_interpolation_vars[$key] = $value;
-    }
-
-    /**
-     * Set an associative array of interpolation variables.
-     */
-    function set_vars($hash)
-    {
-        $this->_interpolation_vars = array_merge($this->_interpolation_vars,
-                                                $hash);
-    }
-    
-    /**
-     * Retrieve translation for specified key.
-     *
-     * @param  string $key  -- gettext msgid
-     * @throws GetText_Error
-     */
-    function gettext($key)
-    {
-       $value = $this->_get_translation($key);
-        if ($value === false) {
-            $str = sprintf('Unable to locate gettext key "%s"', $key);
-            //$err = new GetText_Error($str);
-            //return PEAR::raise_error($err);
-                       return raise_error("2 " . $str);
-        }
-        
-        while (preg_match('/\$\{(.*?)\}/sm', $value, $m)) {
-            list($src, $var) = $m;
-
-            // retrieve variable to interpolate in context, throw an exception
-            // if not found.
-            $var2 = $this->_get_var($var);
-            if ($var2 === false) {
-                $str = sprintf('Interpolation error, var "%s" not set', $var);
-                //$err = new GetText_Error($str);
-                //return PEAR::raise_error($err);
-                return raise_error("3 " . $str);
-            }
-            $value = str_replace($src, $var2, $value);
-        }
-        return $value;
-    }
-
-    /**
-     * Retrieve an interpolation variable value.
-     * 
-     * @return mixed
-     * @access private
-     */
-    function _get_var($name)
-    {
-        if (!array_key_exists($name, $this->_interpolation_vars)) {
-            return false;
-        }
-        return $this->_interpolation_vars[$name];
-    }
-}
-
-
-/**
-* Implementation of get_text support for PHP.
-*
-* This implementation is abble to cache .po files into php files returning the
-* domain translation hashtable.
-*
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_php_support extends gettext_native_support
-{
-    var $_path     = 'locale/';
-    var $_lang_code = false;
-    var $_domains  = array();
-    var $_end      = -1;
-    var $_jobs     = array();
-
-    /**
-     * Set the translation domain.
-     *
-     * @param  string $lang_code -- language code
-     * @throws GetText_Error
-     */
-    function set_language($lang_code, $encoding)
-    {
-        // if language already set, try to reload domains
-        if ($this->_lang_code !== false and $this->_lang_code != $lang_code) 
-        {
-            foreach ($this->_domains as $domain) 
-            {
-                $this->_jobs[] = array($domain->name, $domain->path);
-            }
-            $this->_domains = array();
-            $this->_end = -1;
-        }
-        
-        $this->_lang_code = $lang_code;
-
-        // this allow us to set the language code after 
-        // domain list.
-        while (count($this->_jobs) > 0) 
-        {
-            list($domain, $path) = array_shift($this->_jobs);
-            $err = $this->add_domain($domain, $path);
-            // error raised, break jobs
-            /*if (PEAR::is_error($err)) {
-                return $err;
-            }*/
-                       if (is_error($err)) 
-                       {
-                return $err;
-            }            
-        }
-    }
-    /**
-        *      Check system support for given language (dummy).
-        */
-       function check_support($lang_code, $encoding)
-    {
-               return true;
-    }
-    /**
-     * Add a translation domain.
-     *
-     * @param string $domain        -- Domain name
-     * @param string $path optional -- Repository path
-     * @throws GetText_Error
-     */
-    function add_domain($domain, $path = false, $version ='')
-    {   
-        if ($path === false) 
-             $path = $this->domain_path;
-        if ($path === false) 
-               $path = "./locale";
-
-       if ($version) {
-                       $domain .= '-'.$version;
-               }
-
-        if (array_key_exists($domain, $this->_domains)) 
-        { 
-            return; 
-        }
-        
-        if (!$this->_lang_code) 
-        { 
-            $this->_jobs[] = array($domain, $path); 
-            return;
-        }
-        // Don't fill the domains with false data, it increased the error.log
-               if (strpos($domain, $this->_lang_code) === false)
-               return;
-        $err = $this->_load_domain($domain, $path);
-        if ($err != 0) 
-        {
-            return $err;
-        }
-
-        $this->_end++;
-    }
-
-    /**
-     * Load a translation domain file.
-     *
-     * This method cache the translation hash into a php file unless
-     * GETTEXT_NO_CACHE is defined.
-     * 
-     * @param  string $domain        -- Domain name
-     * @param  string $path optional -- Repository
-     * @throws GetText_Error
-     * @access private
-     */
-    function _load_domain($domain, $path = "./locale")
-    {
-        $src_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.po";
-        $php_domain = $path . "/$this->_lang_code/LC_MESSAGES/$domain.php";
-        
-        if (!file_exists($src_domain)) 
-        {
-            $str = sprintf('Domain file "%s" not found.', $src_domain);
-            //$err = new GetText_Error($str);
-            //return PEAR::raise_error($err);
-                       return raise_error("4 " . $str);
-        }
-        
-        $d = new gettext_domain();
-        $d->name = $domain;
-        $d->path = $path;
-        if (!file_exists($php_domain) || (filemtime($php_domain) < filemtime($src_domain))) 
-        {
-            
-            // parse and compile translation table
-            $parser = new gettext_php_support_parser();
-            $hash   = $parser->parse($src_domain);
-            if (!defined('GETTEXT_NO_CACHE')) 
-            {
-                $comp = new gettext_php_support_compiler();
-                $err  = $comp->compile($hash, $src_domain);
-                /*if (PEAR::is_error($err)) { 
-                    return $err; 
-                }*/
-                       if (is_error($err)) 
-                       {
-                    return $err;
-                } 
-            }
-            $d->_keys = $hash;
-        } 
-        else 
-        {
-            $d->_keys = include $php_domain;
-        }
-        $this->_domains[] = &$d;
-    }
-    
-    /**
-     * Implementation of gettext message retrieval.
-     */
-    function _get_translation($key)
-    {
-        for ($i = $this->_end; $i >= 0; $i--) 
-        {
-            if ($this->_domains[$i]->has_key($key)) 
-            {
-                return $this->_domains[$i]->get($key);
-            }
-        }
-        return $key;
-    }
-}
-
-/**
-* Class representing a domain file for a specified language.
-*
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_domain
-{
-    var $name;
-    var $path;
-
-    var $_keys = array();
-
-    function has_key($key)
-    {
-        return array_key_exists($key, $this->_keys);
-    }
-
-    function get($key)
-    {
-        return $this->_keys[$key];
-    }
-}
-
-/**
-* This class is used to parse gettext '.po' files into php associative arrays.
-*
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_php_support_parser 
-{
-    var $_hash = array();
-    var $_current_key;
-    var $_current_value;
-    
-    /**
-     * Parse specified .po file.
-     *
-     * @return hashtable
-     * @throws GetText_Error
-     */
-    function parse($file)
-    {
-        $this->_hash = array();
-        $this->_current_key = false;
-        $this->_current_value = "";
-        
-        if (!file_exists($file)) 
-        {
-            $str = sprintf('Unable to locate file "%s"', $file);
-            //$err = new GetText_Error($str);
-            //return PEAR::raise_error($err);
-                       return raise_error($str);
-        }
-        $i = 0;
-        $lines = file($file);
-        foreach ($lines as $line) 
-        {
-            $this->_parse_line($line, ++$i);
-        }
-        $this->_store_key();
-
-        return $this->_hash;
-    }
-
-    /**
-     * Parse one po line.
-     *
-     * @access private
-     */
-    function _parse_line($line, $nbr)
-    {
-        $line = str_replace("\\\"", "'", $line); // Should be inside preg_match, but I couldn't find the solution. This works.
-        if (preg_match('/^\s*?#/', $line)) { return; }
-        if (preg_match('/^\s*?msgid \"(.*?)(?!<\\\)\"/', $line, $m)) {
-            $this->_store_key();
-            $this->_current_key = $m[1];
-            return;
-        }
-        if (preg_match('/^\s*?msgstr \"(.*?)(?!<\\\)\"/', $line, $m)) {
-            $this->_current_value .= $m[1];
-            return;
-        }
-        if (preg_match('/^\s*?\"(.*?)(?!<\\\)\"/', $line, $m)) {
-            $this->_current_value .= $m[1];
-            return;
-        }
-    }
-
-    /**
-     * Store last key/value pair into building hashtable.
-     *
-     * @access private
-     */
-    function _store_key()
-    {
-        if ($this->_current_key === false) return;
-        $this->_current_value = str_replace('\\n', "\n", $this->_current_value);
-        $this->_hash[$this->_current_key] = $this->_current_value;
-        $this->_current_key = false;
-        $this->_current_value = "";
-    }
-}
-
-
-/**
-* This class write a php file from a gettext hashtable.
-*
-* The produced file return the translation hashtable on include.
-* 
-* @throws GetText_Error
-* @access private
-* @author Laurent Bedubourg <laurent.bedubourg@free.fr>
-*/
-class gettext_php_support_compiler 
-{
-    /**
-     * Write hash in an includable php file.
-     */
-    function compile(&$hash, $source_path)
-    {
-        $dest_path = preg_replace('/\.po$/', '.php', $source_path);
-        $fp = @fopen($dest_path, "w");
-        if (!$fp) 
-        {
-            $str = sprintf('Unable to open "%s" in write mode.', $dest_path);
-            //$err = new GetText_Error($str);
-            //return PEAR::raise_error($err);
-                       return raise_error($str);
-        }
-        fwrite($fp, '<?php' . "\n");
-        fwrite($fp, 'return array(' . "\n");
-        foreach ($hash as $key => $value) 
-        {
-            $key   = str_replace("'", "\\'", $key);
-            $value = str_replace("'", "\\'", $value);
-            fwrite($fp, '    \'' . $key . '\' => \'' . $value . "',\n");
-        }
-        fwrite($fp, ');' . "\n");
-        fwrite($fp, '?>');
-        fclose($fp);
-    }
-}
-
-/*
-       Set current gettext domain path
-*/
-function set_ext_domain($path='') {
-       global $path_to_root, $GetText;
-       static $domain_stack = array('');
-
-       if ($path)      // save path on domain stack
-               array_unshift($domain_stack,  $path);
-       else
-       {
-               array_shift($domain_stack);
-               $path = $domain_stack[0];
-       }
-
-       $lang_path = $path_to_root . ($path ? '/' : '') .$path.'/lang';
-       // ignore change when extension does not provide translation structure and test for valid gettext.
-       if (file_exists($lang_path) && isset($GetText))
-               $GetText->add_domain($_SESSION['language']->code,
-                       $lang_path, $path ? '' : $_SESSION['language']->version);
-}
-?>
diff --git a/includes/lang/language.inc b/includes/lang/language.inc
new file mode 100644 (file)
index 0000000..4bc98df
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+// Prevent register_globals vulnerability
+if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
+       die("Restricted access");
+@include_once($path_to_root . "/lang/installed_languages.inc");
+include_once($path_to_root . "/includes/lang/gettext.inc");
+
+class language 
+{
+       var $name;
+       var $code;                      // eg. ar_EG, en_GB
+       var $encoding;          // eg. UTF-8, CP1256, ISO8859-1
+       var     $dir;                   // Currently support for Left-to-Right (ltr) and
+                                               // Right-To-Left (rtl)
+       var $version; // lang package version
+       var $is_locale_file;
+       
+       function language($name, $code, $encoding, $dir = 'ltr') 
+       {
+               global $dflt_lang;
+               
+               $this->name = $name;
+               $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'C');
+               $this->encoding = $encoding;
+               $this->dir = $dir;
+       }
+
+       function get_language_dir() 
+       {
+               return "lang/" . $this->code;
+       }
+
+       function get_current_language_dir() 
+       {
+               $lang = $_SESSION['language'];
+               return "lang/" . $lang->code;
+       }
+
+       function set_language($code) 
+       {
+           global $path_to_root, $installed_languages, $GetText;
+
+               $lang = array_search_value($code, $installed_languages, 'code');
+               $changed = $this->code != $code || $this->version != @$lang['version'];
+
+               if ($lang && $changed)
+               {
+                       $this->name = $lang['name'];
+                       $this->code = $lang['code'];
+                       $this->encoding = $lang['encoding'];
+                       $this->version = @$lang['version'];
+                       $this->dir = (isset($lang['rtl']) && $lang['rtl'] === true) ? 'rtl' : 'ltr';
+                       $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc";
+                       $this->is_locale_file = file_exists($locale);
+               }
+
+               $GetText->set_language($this->code, $this->encoding);
+               $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version);
+
+               // Necessary for ajax calls. Due to bug in php 4.3.10 for this 
+               // version set globally in php.ini
+               ini_set('default_charset', $this->encoding);
+
+               if (isset($_SESSION['wa_current_user']) && $_SESSION['wa_current_user']->logged_in() && isset($_SESSION['App']) && $changed)
+                       $_SESSION['App']->init(); // refresh menu
+       }
+}
+
+if (!function_exists("_")) 
+{
+       function _($text) 
+       {
+               global $GetText;
+               if (!isset($GetText)) // Don't allow using gettext if not is net.
+                       return $text;
+
+               $retVal = $GetText->gettext($text);
+               if ($retVal == "")
+                       return $text;
+               return $retVal;
+       }
+}
+?>
\ No newline at end of file
diff --git a/includes/lang/language.php b/includes/lang/language.php
deleted file mode 100644 (file)
index c090f1f..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-<?php
-/**********************************************************************
-    Copyright (C) FrontAccounting, LLC.
-       Released under the terms of the GNU General Public License, GPL, 
-       as published by the Free Software Foundation, either version 3 
-       of the License, or (at your option) any later version.
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
-    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
-***********************************************************************/
-// Prevent register_globals vulnerability
-if (isset($_GET['path_to_root']) || isset($_POST['path_to_root']))
-       die("Restricted access");
-@include_once($path_to_root . "/lang/installed_languages.inc");
-include_once($path_to_root . "/includes/lang/gettext.php");
-
-class language 
-{
-       var $name;
-       var $code;                      // eg. ar_EG, en_GB
-       var $encoding;          // eg. UTF-8, CP1256, ISO8859-1
-       var     $dir;                   // Currently support for Left-to-Right (ltr) and
-                                               // Right-To-Left (rtl)
-       var $version; // lang package version
-       var $is_locale_file;
-       
-       function language($name, $code, $encoding, $dir = 'ltr') 
-       {
-               global $dflt_lang;
-               
-               $this->name = $name;
-               $this->code = $code ? $code : ($dflt_lang ? $dflt_lang : 'C');
-               $this->encoding = $encoding;
-               $this->dir = $dir;
-       }
-
-       function get_language_dir() 
-       {
-               return "lang/" . $this->code;
-       }
-
-       function get_current_language_dir() 
-       {
-               $lang = $_SESSION['language'];
-               return "lang/" . $lang->code;
-       }
-
-       function set_language($code) 
-       {
-           global $path_to_root, $installed_languages, $GetText;
-
-               $lang = array_search_value($code, $installed_languages, 'code');
-               $changed = $this->code != $code || $this->version != @$lang['version'];
-
-               if ($lang && $changed)
-               {
-               // flush cache as we can use several languages in one account
-                       flush_dir(company_path().'/js_cache');
-
-                       $this->name = $lang['name'];
-                       $this->code = $lang['code'];
-                       $this->encoding = $lang['encoding'];
-                       $this->version = @$lang['version'];
-                       $this->dir = (isset($lang['rtl']) && $lang['rtl'] === true) ? 'rtl' : 'ltr';
-                       $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc";
-                       $this->is_locale_file = file_exists($locale);
-               }
-
-               $GetText->set_language($this->code, $this->encoding);
-               $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version);
-
-               // Necessary for ajax calls. Due to bug in php 4.3.10 for this 
-               // version set globally in php.ini
-               ini_set('default_charset', $this->encoding);
-
-               if (isset($_SESSION['wa_current_user']) && $_SESSION['wa_current_user']->logged_in() && isset($_SESSION['App']) && $changed)
-                       $_SESSION['App']->init(); // refresh menu
-       }
-}
-
-if (!function_exists("_")) 
-{
-       function _($text) 
-       {
-               global $GetText;
-               if (!isset($GetText)) // Don't allow using gettext if not is net.
-                       return $text;
-
-               $retVal = $GetText->gettext($text);
-               if ($retVal == "")
-                       return $text;
-               return $retVal;
-       }
-}
-?>
\ No newline at end of file
index 8ef038ca1f06e63e39959c250889781cebee05f1..2477a6c0f38bfba618f915960618a827783928b8 100644 (file)
@@ -12,7 +12,6 @@
 include_once($path_to_root . "/includes/db/connect_db.inc");
 
 include_once($path_to_root . "/includes/types.inc");
-include_once($path_to_root . "/includes/systypes.inc");
 include_once($path_to_root . "/includes/references.inc");
 include_once($path_to_root . "/includes/db/comments_db.inc");
 include_once($path_to_root . "/includes/db/sql_functions.inc");
@@ -69,13 +68,34 @@ function cache_js_file($fpath, $text)
 
        if(!$go_debug) $text = js_compress($text);
 
-        $file = fopen($fpath, 'w');
+    $file = force_open($fpath);
        if (!$file) return false;
        if (!fwrite($file, $text)) return false;
        return fclose($file);
 
 }
 
+/*
+       Open file for writing with creration of subfolders if needed.
+*/
+function force_open($fname)
+{
+       $file = pathinfo($fname);
+
+       $path = $fname[0] == '/' ? '/' : '';
+       $tree = explode('/', $file['dirname']);
+       foreach($tree as $level) {
+               $path .= $level;
+               if (!file_exists($path)) {
+                       if (!mkdir($path)) {
+                               return null;
+                       }
+               }
+               $path .= '/';
+       }
+       return fopen($fname, 'w');
+}
+
 function add_js_file($filename) 
 {
          global $js_static;
index 0ae62638bf7570f688d1f7b85585b9060f07f602..61c155855b3f21953b69108df06ebe09ff5ef490 100644 (file)
@@ -52,7 +52,8 @@ function send_scripts()
        $js ='';
        foreach($js_static as $jsfile)
        {
-           $fpath = company_path().'/js_cache/'.$jsfile;
+               $cached_name = basename($jsfile);
+               $fpath = user_js_cache().'/'.$cached_name;
            // compress also static files
                if (!file_exists($fpath) || $go_debug)
                        cache_js_file($fpath, file_get_contents($js_path.$jsfile));
index cd01ab6c67386032182dbda57e5a962390f1bea2..38bd84cdceb541470d38674b2b4f1eb638d5c187 100644 (file)
@@ -100,48 +100,4 @@ class references
        }
 }
 
-//----------------------------------------------------------------------------
-//
-//     Check if reference was not used so far (for other transaction than $trans_no)
-//
-function is_new_reference($ref, $type, $trans_no=0)
-{
-       $db_info = get_systype_db_info($type);
-       $db_name = $db_info[0];
-       $db_type = $db_info[1];
-       $db_trans = $db_info[2];
-       $db_ref = $db_info[3];
-       
-       $ref = db_escape(trim($ref));
-       $type = db_escape($type);
-       
-       if ($db_ref == null) { // journal or bank trans store references in refs table
-               $db_name = TB_PREF."refs";
-               $db_type = 'type';
-               $db_trans = 'id';
-               $db_ref = 'reference';
-       }
-
-       if ($db_type != null) {
-               $sql = "SELECT $db_ref FROM $db_name tbl
-                       LEFT JOIN ".TB_PREF."voided v ON 
-                               tbl.$db_type=v.type AND tbl.$db_trans=v.id
-                       WHERE $db_ref=$ref AND ISNULL(v.id)
-                               AND tbl.$db_type=$type";
-       } else {
-               $sql = "SELECT $db_ref ref FROM $db_name tbl
-                       LEFT JOIN ".TB_PREF."voided v ON 
-                               v.type=$type AND tbl.$db_trans=v.id
-                       WHERE $db_ref=$ref AND ISNULL(v.id)";
-       }
-       if ($trans_no)
-                       $sql .= " AND tbl.`$db_trans` != ".db_escape($trans_no);
-
-       $result = db_query($sql, "could not test for unique reference");
-
-       return (db_num_rows($result) == 0);
-
-}
-
-
 ?>
\ No newline at end of file
index 697bb48da6823fed173a4c44d391f7715abe1d2c..15d21d84951f357d99d48a19f8e1d0a5979c5b4f 100644 (file)
@@ -219,7 +219,7 @@ function write_login_filelog($login, $result)
 
        $filename = $path_to_root."/tmp/faillog.php";
 
-       if ((!file_exists($filename) && is_writable($path_to_root)) || is_writable($filename))
+       if ((!file_exists($filename) && is_writable($path_to_root.'/tmp')) || is_writable($filename))
        {
                file_put_contents($filename, $msg);
        }
@@ -363,7 +363,7 @@ set_error_handler('error_handler' /*, errtypes */);
 include_once($path_to_root . "/includes/current_user.inc");
 include_once($path_to_root . "/frontaccounting.php");
 include_once($path_to_root . "/admin/db/security_db.inc");
-include_once($path_to_root . "/includes/lang/language.php");
+include_once($path_to_root . "/includes/lang/language.inc");
 include_once($path_to_root . "/config_db.php");
 include_once($path_to_root . "/includes/ajax.inc");
 include_once($path_to_root . "/includes/ui/ui_msgs.inc");
diff --git a/includes/systypes.inc b/includes/systypes.inc
deleted file mode 100644 (file)
index c1c17a4..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-<?php
-/**********************************************************************
-    Copyright (C) FrontAccounting, LLC.
-       Released under the terms of the GNU General Public License, GPL, 
-       as published by the Free Software Foundation, either version 3 
-       of the License, or (at your option) any later version.
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
-    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
-***********************************************************************/
-
-//-----------------------------------------------------------------------------------------
-//     Returns next transaction number.
-//     Used only for transactions stored in tables without autoincremented key.
-//
-
-function get_next_trans_no ($trans_type){
-
-       $st = get_systype_db_info($trans_type);
-
-       if (!($st && $st[0] && $st[2])) {
-               // this is in fact internal error condition.
-               display_error('Internal error: invalid type passed to get_next_trans_no()');
-               return 0;
-       }
-       $sql1 = "SELECT MAX(`$st[2]`) as last_no FROM $st[0]";
-       if ($st[1] != null)
-                $sql1 .= " WHERE `$st[1]`=".db_escape($trans_type);
-
-       // check also in voided transactions (some transactions like location transfer are removed completely)
-       $sql2 = "SELECT MAX(`id`) as last_no FROM ".TB_PREF."voided WHERE `type`=".db_escape($trans_type);
-
-       $sql = "SELECT max(last_no) last_no FROM ($sql1 UNION $sql2) a";
-    $result = db_query($sql,"The next transaction number for $trans_type could not be retrieved");
-    $myrow = db_fetch_row($result);
-
-    return $myrow[0] + 1;
-}
-
-//-----------------------------------------------------------------------------
-
-function get_systype_db_info($type)
-{
-       switch ($type)
-       {
-        case     ST_JOURNAL      : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
-        case     ST_BANKPAYMENT  : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
-        case     ST_BANKDEPOSIT  : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
-        case     3               : return null;
-        case     ST_BANKTRANSFER : return array("".TB_PREF."bank_trans", "type", "trans_no", "ref", "trans_date");
-        case     ST_SALESINVOICE : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
-        case     ST_CUSTCREDIT   : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
-        case     ST_CUSTPAYMENT  : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
-        case     ST_CUSTDELIVERY : return array("".TB_PREF."debtor_trans", "type", "trans_no", "reference", "tran_date");
-        case     ST_LOCTRANSFER  : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
-        case     ST_INVADJUST    : return array("".TB_PREF."stock_moves", "type", "trans_no", "reference", "tran_date");
-        case     ST_PURCHORDER   : return array("".TB_PREF."purch_orders", null, "order_no", "reference", "ord_date");
-        case     ST_SUPPINVOICE  : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
-        case     ST_SUPPCREDIT   : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
-        case     ST_SUPPAYMENT   : return array("".TB_PREF."supp_trans", "type", "trans_no", "reference", "tran_date");
-        case     ST_SUPPRECEIVE  : return array("".TB_PREF."grn_batch", null, "id", "reference", "delivery_date");
-        case     ST_WORKORDER    : return array("".TB_PREF."workorders", null, "id", "wo_ref", "released_date");
-        case     ST_MANUISSUE    : return array("".TB_PREF."wo_issues", null, "issue_no", "reference", "issue_date");
-        case     ST_MANURECEIVE  : return array("".TB_PREF."wo_manufacture", null, "id", "reference", "date_");
-        case     ST_SALESORDER   : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
-        case     31              : return array("".TB_PREF."service_orders", null, "order_no", "cust_ref", "date");
-        case     ST_SALESQUOTE   : return array("".TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date");
-        case    ST_DIMENSION    : return array("".TB_PREF."dimensions", null, "id", "reference", "date_");
-        case     ST_COSTUPDATE   : return array("".TB_PREF."gl_trans", "type", "type_no", null, "tran_date");
-       }
-
-       display_db_error("invalid type ($type) sent to get_systype_db_info", "", true);
-}
-
-function get_systypes()
-{
-       $sql = "SELECT * FROM ".TB_PREF."sys_types";
-       $result = db_query($sql, "could not query systypes table");
-       return $result;
-}
-
-?>
\ No newline at end of file
index cd4e3dc3d18fd055c040c9177c033dbf2634c244..5b7b4a7af73588413e2e91cf46f2ae24af19a430 100644 (file)
@@ -140,7 +140,7 @@ function payment_person_name($type, $person_id, $full=true) {
 //
 //     Returns counterparty (supplier/customer) name for selected transaction.
 //
-function get_counterparty_name($trans_type, $trans_no, $full=true)
+function get_counterparty_name($trans_type, $trans_no)
 {
        switch($trans_type)
        {
index 8c8bae8db127b0e5982b3b46c392593debad1336..768447bca9083fce1d48698a0ff4808be494762e 100644 (file)
@@ -889,7 +889,7 @@ function reset_focus()
 function get_js_date_picker()
 {
     global $go_debug;
-    $fpath = company_path().'/js_cache/'.'date_picker.js';
+    $fpath = user_js_cache().'/'.'date_picker.js';
 
     if (!file_exists($fpath) || $go_debug) {
 
index 5a9f912e7bfb5b213ff17de2c593de20d2c236e8..339c92735549298cc0ba600595f651ca901eb813 100644 (file)
@@ -70,7 +70,7 @@ include_once($path_to_root . "/includes/errors.inc");
 set_error_handler('error_handler' /*, errtypes */);
 
 include_once($path_to_root . "/includes/current_user.inc");
-include_once($path_to_root . "/includes/lang/language.php");
+include_once($path_to_root . "/includes/lang/language.inc");
 include_once($path_to_root . "/includes/ajax.inc");
 include_once($path_to_root . "/includes/ui/ui_msgs.inc");
 include_once($path_to_root . "/includes/prefs/sysprefs.inc");
index 24bf6e944724a28bb5e9fb8a23bc26c554c69d3e..a2c302b6fe4021964070aa90c13832c66b312cdf 100644 (file)
@@ -53,7 +53,7 @@ function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
 //--------------------------------------------------------------------------------------
 
 function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
-                                       $date_, $required_by, $memo_)
+                                       $date_, $required_by, $memo_, $old_stock_id, $old_qty)
 {
        begin_transaction();
        $args = func_get_args();
@@ -61,7 +61,7 @@ function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
                'date_', 'required_by', 'memo_'), $args);
        hook_db_prewrite($args, ST_WORKORDER);
 
-       add_material_cost($_POST['old_stk_id'], -$_POST['old_qty'], $date_);
+       add_material_cost($old_stock_id, -$old_qty, $date_);
        add_material_cost($stock_id, $units_reqd, $date_);
 
        $date = date2sql($date_);
@@ -82,12 +82,12 @@ function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
        commit_transaction();
 }
 
-function delete_work_order($woid)
+function delete_work_order($woid, $stock_id, $qty, $date)
 {
        begin_transaction();
        hook_db_prevoid(ST_WORKORDER, $woid);
 
-       add_material_cost($_POST['stock_id'], -$_POST['quantity'], $_POST['date_']);
+       add_material_cost($stock_id, -$qty, $date);
 
        // delete the work order requirements
        delete_wo_requirements($woid);
@@ -97,7 +97,7 @@ function delete_work_order($woid)
        db_query($sql,"The work order could not be deleted");
 
        delete_comments(ST_WORKORDER, $woid);
-       add_audit_trail(ST_WORKORDER, $woid, $_POST['date_'], _("Canceled."));
+       add_audit_trail(ST_WORKORDER, $woid, $date, _("Canceled."));
 
        commit_transaction();
 }
@@ -297,7 +297,7 @@ function void_work_order($woid)
        commit_transaction();
 }
 
-function get_sql_for_work_orders($outstanding_only, $all_items)
+function get_sql_for_work_orders($outstanding_only, $stock_id, $location = ALL_TEXT, $order = '', $overdue = false)
 {
        $sql = "SELECT
                workorder.id,
@@ -327,22 +327,22 @@ function get_sql_for_work_orders($outstanding_only, $all_items)
                $sql .= " AND workorder.closed=0";
        }
 
-       if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
+       if ($location != ALL_TEXT)
        {
-               $sql .= " AND workorder.loc_code=".db_escape($_POST['StockLocation']);
+               $sql .= " AND workorder.loc_code=".db_escape($location);
        }
 
-       if (isset($_POST['OrderNumber']) && $_POST['OrderNumber'] != "")
+       if ($order != '')
        {
-               $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$_POST['OrderNumber'].'%');
+               $sql .= " AND workorder.wo_ref LIKE ".db_escape('%'.$order.'%');
        }
 
-       if (isset($_POST['SelectedStockItem']) && $_POST['SelectedStockItem'] != $all_items)
+       if ($stock_id != '')
        {
-               $sql .= " AND workorder.stock_id=".db_escape($_POST['SelectedStockItem']);
+               $sql .= " AND workorder.stock_id=".db_escape($stock_id);
        }
 
-       if (check_value('OverdueOnly'))
+       if ($overdue)
        {
                $Today = date2sql(Today());
 
@@ -351,7 +351,7 @@ function get_sql_for_work_orders($outstanding_only, $all_items)
        return $sql;
 }
 
-function get_sql_for_where_used()
+function get_sql_for_where_used($stock_id)
 {
        $sql = "SELECT 
                        bom.parent,
@@ -366,8 +366,8 @@ function get_sql_for_where_used()
                        WHERE bom.parent = parent.stock_id 
                                AND bom.workcentre_added = workcentre.id
                                AND bom.loc_code = location.loc_code
-                               AND bom.component=".db_escape($_POST['stock_id']);
-       return $sql;                    
+                               AND bom.component=".db_escape($stock_id);
+       return $sql;
 }
 //--------------------------------------------------------------------------------------
 function get_gl_wo_cost($woid, $cost_type)
index 10fce898a820d658f5c2cf3649634a8ccb798f55..dc510cec22ca748fa1e1b3dcf384a158f9ef673e 100644 (file)
@@ -37,7 +37,7 @@ function select_link($row)
                "/manufacturing/manage/bom_edit.php?stock_id=" . $row["parent"]);
 }
 
-$sql = get_sql_for_where_used();
+$sql = get_sql_for_where_used($_POST['stock_id']);
 
    $cols = array(
        _("Parent Item") => array('fun'=>'select_link'), 
index 7610a1cb9f867edf565748d17e4271cea9dd02b3..e276261f1362eae55a2ef66fcb5bac6f565155d0 100644 (file)
@@ -153,7 +153,8 @@ function dec_amount($row, $amount)
        return number_format2($amount, $row['decimals']);
 }
 
-$sql = get_sql_for_work_orders($outstanding_only, $all_items);
+$sql = get_sql_for_work_orders($outstanding_only, $_POST['SelectedStockItem'], $_POST['StockLocation'],
+       $_POST['OrderNumber'], check_value('OverdueOnly'));
 
 $cols = array(
        _("#") => array('fun'=>'view_link', 'ord'=>''), 
index 5c27369bbe1846796f821b36cddaed9930a8af88..4466355d610df8577d2d3133383791537364683e 100644 (file)
@@ -275,7 +275,8 @@ if (isset($_POST['UPDATE_ITEM']) && can_process())
 {
 
        update_work_order($selected_id, $_POST['StockLocation'], input_num('quantity'),
-               $_POST['stock_id'],  $_POST['date_'], $_POST['RequDate'], $_POST['memo_']);
+               $_POST['stock_id'],  $_POST['date_'], $_POST['RequDate'], $_POST['memo_'],
+               $_POST['old_stk_id'], $_POST['old_qty']);
        new_doc_date($_POST['date_']);
        meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$selected_id");
 }
@@ -301,7 +302,7 @@ if (isset($_POST['delete']))
        { //ie not cancelled the delete as a result of above tests
 
                // delete the actual work order
-               delete_work_order($selected_id);
+               delete_work_order($selected_id, $_POST['stock_id'], $_POST['quantity'], $_POST['date_']);
                meta_forward($_SERVER['PHP_SELF'], "DeletedID=$selected_id");
        }
 }
@@ -423,24 +424,23 @@ else
     date_row(_("Date") . ":", 'date_', '', true);
        hidden('RequDate', '');
 
-       $sql = "SELECT DISTINCT account_code FROM ".TB_PREF."bank_accounts";
-       $rs = db_query($sql,"could not get bank accounts");
-       $r = db_fetch_row($rs);
+       $bank_act = get_default_bank_account();
        if (!isset($_POST['Labour']))
        {
                $_POST['Labour'] = price_format(0);
-               $_POST['cr_lab_acc'] = $r[0];
+               $_POST['cr_lab_acc'] = $bank_act['account_code'];
        }
+
        amount_row($wo_cost_types[WO_LABOUR], 'Labour');
        gl_all_accounts_list_row(_("Credit Labour Account"), 'cr_lab_acc', null);
        if (!isset($_POST['Costs']))
        {
                $_POST['Costs'] = price_format(0);
-               $_POST['cr_acc'] = $r[0];
+               $_POST['cr_acc'] = $bank_act['account_code'];
        }
        amount_row($wo_cost_types[WO_OVERHEAD], 'Costs');
        gl_all_accounts_list_row(_("Credit Overhead Account"), 'cr_acc', null);
-       
+
 }
 
 if (get_post('released'))
index a097db4617c4bb4b63817b7fa34bc9cdda8b31a2..dac2ed5e211506560c03145cf4c2045b00b07dd4 100644 (file)
@@ -9,6 +9,38 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
 ***********************************************************************/
+// ------------------------------------------------------------------------------
+
+function get_supplier_details_to_order(&$order, $supplier_id)
+{
+       $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, supp.tax_algorithm,
+                       supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1) 
+                               * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
+                               terms.terms, terms.days_before_due, terms.day_in_following_month
+               FROM ".TB_PREF."suppliers supp
+                        LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
+                        LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.terms_indicator
+               WHERE supp.supplier_id = ".db_escape($supplier_id)."
+               GROUP BY
+                         supp.supp_name";
+
+       $result = db_query($sql, "The supplier details could not be retreived");
+       $myrow = db_fetch($result);
+
+       $order->credit = $myrow["cur_credit"];
+       $order->terms = array( 
+               'description' => $myrow['terms'],
+               'days_before_due' => $myrow['days_before_due'], 
+               'day_in_following_month' => $myrow['day_in_following_month'] );
+
+       $_POST['supplier_id'] = $supplier_id;
+       $_POST['supplier_name'] = $myrow["supp_name"];
+       $_POST['curr_code'] = $myrow["curr_code"];
+
+       $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"], 
+               $myrow["tax_group_id"], $myrow["tax_included"], $myrow["tax_algorithm"]);
+}
+
 //----------------------------------------------------------------------------------------
 
 function delete_po($po)
@@ -258,9 +290,9 @@ function get_short_info($stock_id)
        return db_query($sql,"The stock details for " . $stock_id . " could not be retrieved");
 }
 
-function get_sql_for_po_search_completed($supplier_id=ALL_TEXT)
+function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT,
+       $order_number = '', $stock_id = '')
 {
-       global $order_number, $selected_stock_item;;
 
        $sql = "SELECT 
                porder.order_no, 
@@ -280,8 +312,8 @@ function get_sql_for_po_search_completed($supplier_id=ALL_TEXT)
                AND porder.supplier_id = supplier.supplier_id
                AND location.loc_code = porder.into_stock_location ";
 
-       if (isset($_GET['supplier_id']))
-               $sql .= "AND supplier.supplier_id=".@$_GET['supplier_id']." ";
+       if ($supplier_id != ALL_TEXT)
+               $sql .= "AND supplier.supplier_id=".$supplier_id." ";
        if (isset($order_number) && $order_number != "")
        {
                $sql .= "AND porder.reference LIKE ".db_escape('%'. $order_number . '%');
@@ -289,30 +321,30 @@ function get_sql_for_po_search_completed($supplier_id=ALL_TEXT)
        else
        {
 
-               $data_after = date2sql($_POST['OrdersAfterDate']);
-               $date_before = date2sql($_POST['OrdersToDate']);
+               $data_after = date2sql($from);
+               $date_before = date2sql($to);
 
                $sql .= " AND porder.ord_date >= '$data_after'";
                $sql .= " AND porder.ord_date <= '$date_before'";
 
-               if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT)
+               if ($location != ALL_TEXT)
                {
-                       $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']);
+                       $sql .= " AND porder.into_stock_location = ".db_escape($location);
                }
                if (isset($selected_stock_item))
                {
-                       $sql .= " AND line.item_code=".db_escape($selected_stock_item);
+                       $sql .= " AND line.item_code=".db_escape($stock_id);
                }
                if ($supplier_id != ALL_TEXT)
                        $sql .= " AND supplier.supplier_id=".db_escape($supplier_id);
-               
-       } //end not order number selected
+
+       }
 
        $sql .= " GROUP BY porder.order_no";
        return $sql;
-}      
+}
 
-function get_sql_for_po_search($supplier_id=ALL_TEXT)
+function get_sql_for_po_search($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT)
 {
        global $all_items, $order_number, $selected_stock_item;;
        
@@ -343,15 +375,15 @@ function get_sql_for_po_search($supplier_id=ALL_TEXT)
        }
        else
        {
-               $data_after = date2sql($_POST['OrdersAfterDate']);
-               $data_before = date2sql($_POST['OrdersToDate']);
+               $data_after = date2sql($from);
+               $data_before = date2sql($to);
 
                $sql .= "  AND porder.ord_date >= '$data_after'";
                $sql .= "  AND porder.ord_date <= '$data_before'";
 
-               if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != $all_items)
+               if ($location != ALL_TEXT)
                {
-                       $sql .= " AND porder.into_stock_location = ".db_escape($_POST['StockLocation']);
+                       $sql .= " AND porder.into_stock_location = ".db_escape($location);
                }
 
                if (isset($selected_stock_item))
index dc7119db05f739722c2efd5b76c46ad1abe79175..b095de774744bbdd73377acc484afac4a8ecba3d 100644 (file)
@@ -252,10 +252,10 @@ function get_allocatable_from_supp_transactions($supplier_id, $trans_no=null, $t
 }
 
 
-function get_sql_for_supplier_allocation_inquiry()
+function get_sql_for_supplier_allocation_inquiry($from, $to, $filter, $supplier_id, $all=false)
 {
-       $date_after = date2sql($_POST['TransAfterDate']);
-       $date_to = date2sql($_POST['TransToDate']);
+       $date_after = date2sql($from);
+       $date_to = date2sql($to);
 
     $sql = "SELECT 
                trans.type, 
@@ -277,31 +277,32 @@ function get_sql_for_supplier_allocation_inquiry()
        AND trans.tran_date >= '$date_after'
        AND trans.tran_date <= '$date_to'";
 
-       if ($_POST['supplier_id'] != ALL_TEXT)
-               $sql .= " AND trans.supplier_id = ".db_escape($_POST['supplier_id']);
-       if (isset($_POST['filterType']) && $_POST['filterType'] != ALL_TEXT)
+       if ($supplier_id != ALL_TEXT)
+               $sql .= " AND trans.supplier_id = ".db_escape($supplier_id);
+
+       if ($filter != ALL_TEXT)
        {
-               if (($_POST['filterType'] == '1') || ($_POST['filterType'] == '2'))
+               if (($filter == '1') || ($filter == '2'))
                {
                        $sql .= " AND trans.type = ".ST_SUPPINVOICE." ";
                }
-               elseif ($_POST['filterType'] == '3')
+               elseif ($filter == '3')
                {
                        $sql .= " AND trans.type = ".ST_SUPPAYMENT." ";
                }
-               elseif (($_POST['filterType'] == '4') || ($_POST['filterType'] == '5'))
+               elseif (($filter == '4') || ($filter == '5'))
                {
                        $sql .= " AND trans.type = ".ST_SUPPCREDIT." ";
                }
 
-               if (($_POST['filterType'] == '2') || ($_POST['filterType'] == '5'))
+               if (($filter == '2') || ($filter == '5'))
                {
                        $today =  date2sql(Today());
                        $sql .= " AND trans.due_date < '$today' ";
                }
        }
 
-       if (!check_value('showSettled'))
+       if (!$all)
        {
                $sql .= " AND (round(abs(ov_amount + ov_gst + ov_discount) - alloc,6) != 0) ";
        }
index 61cf2bdce8a8194ab8e4bdda72024cbffa38679d..6b7d0cde787265665cfc21c5a188a0bf6f5f0f43 100644 (file)
@@ -19,7 +19,7 @@ function add_supplier($supp_name, $supp_ref, $address, $supp_address, $gst_no,
                supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
                payment_terms, payable_account, purchase_account, payment_discount_account, notes, 
                tax_group_id, tax_included, tax_algorithm)
-               VALUES (".db_escape($_POST['supp_name']). ", "
+               VALUES (".db_escape($supp_name). ", "
                .db_escape($supp_ref). ", "
                .db_escape($address) . ", "
                .db_escape($supp_address) . ", "
@@ -187,3 +187,14 @@ function update_supp_tax_algorithm($supplier_id, $tax_algorithm)
                . " WHERE supplier_id=".db_escape($supplier_id);
        return db_query($sql, "cannot update supplier's tax calculation algorithm");
 }
+
+function get_supplier_currency($supplier_id)
+{
+    $sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id = ".db_escape($supplier_id);
+
+       $result = db_query($sql, "Retreive currency of supplier $supplier_id");
+
+       $myrow=db_fetch_row($result);
+       return $myrow[0];
+}
+
index ba60460976fd8ad4037f84e2f1939df18c1db7e4..152df8f2059344d9319a6460746f89c5f2344799 100644 (file)
@@ -60,37 +60,6 @@ function copy_to_cart()
                        $cart->tax_overrides[$id] = user_numeric($_POST['mantax'][$id]); }
        }
 }
-// ------------------------------------------------------------------------------
-
-function get_supplier_details_to_order(&$order, $supplier_id)
-{
-       $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, supp.tax_algorithm,
-                       supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1) 
-                               * (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
-                               terms.terms, terms.days_before_due, terms.day_in_following_month
-               FROM ".TB_PREF."suppliers supp
-                        LEFT JOIN ".TB_PREF."supp_trans trans ON supp.supplier_id = trans.supplier_id
-                        LEFT JOIN ".TB_PREF."payment_terms terms ON supp.payment_terms=terms.terms_indicator
-               WHERE supp.supplier_id = ".db_escape($supplier_id)."
-               GROUP BY
-                         supp.supp_name";
-
-       $result = db_query($sql, "The supplier details could not be retreived");
-
-       $myrow = db_fetch($result);
-       $order->credit = $myrow["cur_credit"];
-       $order->terms = array( 
-               'description' => $myrow['terms'],
-               'days_before_due' => $myrow['days_before_due'], 
-               'day_in_following_month' => $myrow['day_in_following_month'] );
-
-       $_POST['supplier_id'] = $supplier_id;
-       $_POST['supplier_name'] = $myrow["supp_name"];
-       $_POST['curr_code'] = $myrow["curr_code"];
-
-       $order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"], 
-               $myrow["tax_group_id"], $myrow["tax_included"], $myrow["tax_algorithm"]);
-}
 
 //---------------------------------------------------------------------------------------------------
 
@@ -209,13 +178,9 @@ function display_po_header(&$order)
     {
        /*If this is the first time the form loaded set up defaults */
 
-        //$_POST['StkLocation'] = $_SESSION['UserStockLocation'];
-        $sql = "SELECT delivery_address, phone FROM ".TB_PREF."locations WHERE loc_code=".db_escape($_POST['StkLocation']);
-        $result = db_query($sql,"could not get location info");
-
-        if (db_num_rows($result) == 1)
+               $loc_row = get_item_location(get_post('StkLocation'));
+        if ($loc_row)
         {
-               $loc_row = db_fetch($result);
                $_POST['delivery_address'] = $loc_row["delivery_address"];
                        $Ajax->activate('delivery_address');
                $_SESSION['PO']->Location = $_POST['StkLocation'];
index 399e3e8691c3199290e193a827ea0b4820c12567..cf9a80b6dac6ebe1230ba1c9ae345fbe9442f67f 100644 (file)
@@ -112,18 +112,9 @@ if (isset($_POST['order_number']) && ($_POST['order_number'] != ""))
        $order_number = $_POST['order_number'];
 }
 
-if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
-       ($_POST['SelectStockFromList'] != $all_items))
-{
-       $selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
-{
-       unset($selected_stock_item);
-}
-
 //figure out the sql required from the inputs available
-$sql = get_sql_for_po_search($_POST['supplier_id']);
+$sql = get_sql_for_po_search($_POST['OrdersAfterDate'], $_POST['OrdersToDate'], $_POST['supplier_id'],
+       $_POST['StockLocation']);
 
 //$result = db_query($sql,"No orders were returned");
 
index 31c774263c967f2a834a326f8fa21cbe02699bbc..6a40d9e775d2cdb7b97f04f70422ab977c3ee4a9 100644 (file)
@@ -25,7 +25,7 @@ page(_($help_context = "Search Purchase Orders"), false, false, "", $js);
 
 if (isset($_GET['order_number']))
 {
-       $order_number = $_GET['order_number'];
+       $_POST['order_number'] = $_GET['order_number'];
 }
 
 //-----------------------------------------------------------------------------------
@@ -78,22 +78,7 @@ submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
 end_row();
 end_table(1);
 //---------------------------------------------------------------------------------------------
-if (isset($_POST['order_number']))
-{
-       $order_number = $_POST['order_number'];
-}
-
-if (isset($_POST['SelectStockFromList']) &&    ($_POST['SelectStockFromList'] != "") &&
-       ($_POST['SelectStockFromList'] != ALL_TEXT))
-{
-       $selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
-{
-       unset($selected_stock_item);
-}
 
-//---------------------------------------------------------------------------------------------
 function trans_view($trans)
 {
        return get_trans_view_str(ST_PURCHORDER, $trans["order_no"]);
@@ -117,7 +102,9 @@ function prt_link($row)
 
 //---------------------------------------------------------------------------------------------
 
-$sql = get_sql_for_po_search_completed(!@$_GET['popup'] ? $_POST['supplier_id'] : ALL_TEXT);
+$sql = get_sql_for_po_search_completed(get_post('OrdersAfterDate'), get_post('OrdersToDate'),
+       @$_GET['popup'] ? ALL_TEXT : get_post('supplier_id'),
+       get_post('StockLocation'), get_post('order_number'), get_post('SelectStockFromList'));
 
 $cols = array(
                _("#") => array('fun'=>'trans_view', 'ord'=>''), 
index 6e4bcf88419e7a019b2463e98eb749c29a65c377..eea7418d7f45ef52a4bfbcf1b1135bfcf2acbbd2 100644 (file)
@@ -120,7 +120,8 @@ function fmt_credit($row)
 }
 //------------------------------------------------------------------------------------------------
 
-$sql = get_sql_for_supplier_allocation_inquiry();
+$sql = get_sql_for_supplier_allocation_inquiry($_POST['TransAfterDate'],$_POST['TransToDate'],
+       $_POST['filterType'], $_POST['supplier_id'], check_value('showSettled'));
 
 $cols = array(
        _("Type") => array('fun'=>'systype_name'),
index de3082a9e1eadd6dfe906313b37786ac1219ccad..be391fde7392bb3905c77ca602327c691b11f678 100644 (file)
 
        if (!in_array($this->formData['doctype'], array(ST_STATEMENT, ST_WORKORDER)))
        {
-               $id = $this->formData['payment_terms'];
-               $sql = "SELECT terms, days_before_due FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($id);
-               $result = db_query($sql,"could not get paymentterms");
-               $row = db_fetch($result);
+               $row = get_payment_terms($this->formData['payment_terms']);
                $Payment_Terms = _("Payment Terms") . ': ' . $row["terms"];
                if ($this->formData['doctype'] == ST_SALESINVOICE && $this->formData['prepaid'])
                        $this->formData['prepaid'] = ($row['days_before_due'] >= 0) ? 'final' : 'partial';
index 5fa56cc3e5b1af02e32b2d2e89c8c242bde3e158..7ef6ea7435801fa3502251f92f00e720e8c8758d 100644 (file)
@@ -78,7 +78,7 @@ if (isset($_GET['AddedID'])) {
 
        display_footer_exit();
 } else
-       check_edit_conflicts();
+       check_edit_conflicts(get_post('cart_id'));
 
 //--------------------------------------------------------------------------------
 
index 2b31654aeef630beb912828470aad615deb39e82..2bb122dd9a438820c77d12a7d6fc61fb1cc30714 100644 (file)
@@ -78,7 +78,7 @@ if (isset($_GET['AddedID'])) {
 
        display_footer_exit();
 } else
-       check_edit_conflicts();
+       check_edit_conflicts(get_post('cart_id'));
 
 
 //-----------------------------------------------------------------------------
index fa7fc581e7d9ebbca0e24ba85e0976df8c8dd05d..605df69188fd200ccc48b3635975c51a4477d648 100644 (file)
@@ -138,7 +138,7 @@ if (isset($_GET['OrderNumber']) && $_GET['OrderNumber'] > 0) {
        exit;
 
 } else {
-       check_edit_conflicts();
+       check_edit_conflicts(get_post('cart_id'));
 
        if (!check_quantities()) {
                display_error(_("Selected quantity cannot be less than quantity invoiced nor more than quantity not dispatched on sales order."));
index 66f676e6cd00c36f0ea6fd2b4ce7b3dc31a5f519..09d405eb415493cff7b6c09e33ada35ae7538f97 100644 (file)
@@ -48,7 +48,7 @@ page($_SESSION['page_title'], false, false, "", $js);
 
 //-----------------------------------------------------------------------------
 
-check_edit_conflicts();
+check_edit_conflicts(get_post('cart_id'));
 
 if (isset($_GET['AddedID'])) {
 
@@ -66,12 +66,7 @@ if (isset($_GET['AddedID'])) {
 
        hyperlink_params("$path_to_root/sales/inquiry/sales_deliveries_view.php", _("Select Another &Delivery For Invoicing"), "OutstandingOnly=1");
 
-       $sql = "SELECT trans_type_from, trans_no_from FROM ".TB_PREF."cust_allocations
-                       WHERE trans_type_to=".ST_SALESINVOICE." AND trans_no_to=".db_escape($invoice_no);
-       $result = db_query($sql, "could not retrieve customer allocation");
-       $row = db_fetch($result);
-
-       if ($row === false)
+       if (!db_num_rows(get_allocatable_from_cust_transactions(null, $invoice_no, $trans_type)))
                hyperlink_params("$path_to_root/sales/customer_payments.php", _("Entry &customer payment for this invoice"),
                "SInvoice=".$invoice_no);
 
index 09b1fbe4f28af171c013cd574c5bbc028b5bdf9c..c0da80db44ed68949447e34e9e3328e521afc3ee 100644 (file)
@@ -139,7 +139,7 @@ function get_default_info_for_branch($customer_id)
        return db_fetch($result);
 }
 
-function get_sql_for_customer_branches()
+function get_sql_for_customer_branches($customer_id)
 {
        $sql = "SELECT "
                ."b.branch_code, "
@@ -163,7 +163,7 @@ function get_sql_for_customer_branches()
                WHERE b.tax_group_id=t.id
                AND b.area=a.area_code
                AND b.salesman=s.salesman_code
-               AND b.debtor_no = ".db_escape($_POST['customer_id']);
+               AND b.debtor_no = ".db_escape($customer_id);
 
        if (!get_post('show_inactive')) $sql .= " AND !b.inactive";
        $sql .= " GROUP BY b.branch_code ORDER BY branch_ref";
index b63ff123c5fb5ddbe1e9cf2e21caddda97c6b250..fd52d9ce1e1b7d508f17fe32ba4f34f618015279 100644 (file)
@@ -285,11 +285,10 @@ function post_void_customer_trans($type, $type_no)
 }
 
 //----------------------------------------------------------------------------------------
-
-function get_sql_for_customer_inquiry()
+function get_sql_for_customer_inquiry($from, $to, $cust_id = ALL_TEXT, $filter = ALL_TEXT)
 {
-    $date_after = date2sql($_POST['TransAfterDate']);
-    $date_to = date2sql($_POST['TransToDate']);
+    $date_after = date2sql($from);
+    $date_to = date2sql($to);
 
        $sql = "SELECT 
                trans.type, 
@@ -303,7 +302,7 @@ function get_sql_for_customer_inquiry()
                debtor.curr_code,
                (trans.ov_amount + trans.ov_gst + trans.ov_freight 
                        + trans.ov_freight_tax + trans.ov_discount)     AS TotalAmount, "; 
-       if ($_POST['filterType'] != ALL_TEXT)
+       if ($filter != ALL_TEXT)
                $sql .= "@bal := @bal+(trans.ov_amount + trans.ov_gst + trans.ov_freight + trans.ov_freight_tax + trans.ov_discount), ";
 
 //     else
@@ -325,34 +324,34 @@ function get_sql_for_customer_inquiry()
                        AND trans.tran_date <= '$date_to'
                        AND trans.branch_code = branch.branch_code";
 
-       if ($_POST['customer_id'] != ALL_TEXT)
-               $sql .= " AND trans.debtor_no = ".db_escape($_POST['customer_id']);
+       if ($cust_id != ALL_TEXT)
+               $sql .= " AND trans.debtor_no = ".db_escape($cust_id);
 
-       if ($_POST['filterType'] != ALL_TEXT)
+       if ($filter != ALL_TEXT)
        {
-               if ($_POST['filterType'] == '1')
+               if ($filter == '1')
                {
                        $sql .= " AND (trans.type = ".ST_SALESINVOICE.") ";
                }
-               elseif ($_POST['filterType'] == '2')
+               elseif ($filter == '2')
                {
                        $sql .= " AND (trans.type = ".ST_SALESINVOICE.") ";
                }
-               elseif ($_POST['filterType'] == '3')
+               elseif ($filter == '3')
                {
                        $sql .= " AND (trans.type = " . ST_CUSTPAYMENT 
                                        ." OR trans.type = ".ST_BANKDEPOSIT." OR trans.type = ".ST_BANKPAYMENT.") ";
                }
-               elseif ($_POST['filterType'] == '4')
+               elseif ($filter == '4')
                {
                        $sql .= " AND trans.type = ".ST_CUSTCREDIT." ";
                }
-               elseif ($_POST['filterType'] == '5')
+               elseif ($filter == '5')
                {
                        $sql .= " AND trans.type = ".ST_CUSTDELIVERY." ";
                }
 
-       if ($_POST['filterType'] == '2')
+       if ($filter == '2')
        {
                $today =  date2sql(Today());
                $sql .= " AND trans.due_date < '$today'
@@ -365,7 +364,7 @@ function get_sql_for_customer_inquiry()
        return $sql;
 }
 
-function get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_item=null, $customer_id=ALL_TEXT)
+function get_sql_for_sales_deliveries_view($from, $to, $customer_id, $stock_item, $location, $delivery, $outstanding=false)
 {
        $sql = "SELECT trans.trans_no,
                        debtor.name,
@@ -395,33 +394,29 @@ function get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_i
                                AND trans.branch_code = branch.branch_code
                                AND trans.debtor_no = branch.debtor_no ";
 
-       if ($_POST['OutstandingOnly'] == true) {
+       if ($outstanding == true) {
                 $sql .= " AND line.qty_done < line.quantity ";
        }
 
        //figure out the sql required from the inputs available
-       if (isset($_POST['DeliveryNumber']) && $_POST['DeliveryNumber'] != "")
+       if ($delivery)
        {
-               $delivery = "%".$_POST['DeliveryNumber'];
-               $sql .= " AND trans.trans_no LIKE ".db_escape($delivery);
+               $sql .= " AND trans.trans_no LIKE %".db_escape($delivery);
                $sql .= " GROUP BY trans.trans_no";
        }
        else
        {
-               $sql .= " AND trans.tran_date >= '".date2sql($_POST['DeliveryAfterDate'])."'";
-               $sql .= " AND trans.tran_date <= '".date2sql($_POST['DeliveryToDate'])."'";
+               $sql .= " AND trans.tran_date >= '".date2sql($from)."'";
+               $sql .= " AND trans.tran_date <= '".date2sql($to)."'";
 
-               if ($selected_customer != -1)
-                       $sql .= " AND trans.debtor_no=".db_escape($selected_customer)." ";
+               if ($stock_item)
+                       $sql .= " AND line.stock_id=".db_escape($stock_item)." ";
 
-               if (isset($selected_stock_item))
-                       $sql .= " AND line.stock_id=".db_escape($selected_stock_item)." ";
+               if ($location != ALL_TEXT)
+                       $sql .= " AND sorder.from_stk_loc = ".db_escape($location)." ";
 
-               if (isset($_POST['StockLocation']) && $_POST['StockLocation'] != ALL_TEXT)
-                       $sql .= " AND sorder.from_stk_loc = ".db_escape($_POST['StockLocation'])." ";
-               
                if ($customer_id != ALL_TEXT)
-                       $sql .= " AND trans.debtor_no = ".db_escape($customer_id);              
+                       $sql .= " AND trans.debtor_no = ".db_escape($customer_id);
 
                $sql .= " GROUP BY trans.trans_no ";
 
index 3b936a33e9388125b2b8033e79c4958a9566d529..61425b212937aff357fb3b99b274457784f2248b 100644 (file)
@@ -186,4 +186,15 @@ function get_customer_by_ref($reference)
        return db_fetch($result);
 }
 
-?>
\ No newline at end of file
+//----------------------------------------------------------------------------------
+
+function get_customer_currency($customer_id)
+{
+    $sql = "SELECT curr_code FROM ".TB_PREF."debtors_master WHERE debtor_no = ".db_escape($customer_id);
+
+       $result = db_query($sql, "Retreive currency of customer $customer_id");
+
+       $myrow=db_fetch_row($result);
+       return $myrow[0];
+}
+
index d02df7bd48e441a08373709a4893cb17c6f48e29..6ac1e9ddb02b04e658f56480cd8c725d79bc5e9f 100644 (file)
@@ -596,3 +596,13 @@ function is_sales_order_started($order_no)
        $result = db_fetch(db_query($sql, "cannot retrieve sales invoices for sales order"));
        return $result[0];
 }
+
+//---------------------------------------------------------------------------------------------
+//
+// Mark/unmark sales order as template.
+//
+function sales_order_set_template($id, $status)
+{
+       $sql = "UPDATE ".TB_PREF."sales_orders SET type = ".db_escape($status)." WHERE order_no=".db_escape($id);
+       db_query($sql, "Can't change sales order type");
+}
index 8c56d4d3fea02ffa1fba2fcd29d07608f8afc9f0..9a5cc40316485ed5679038d9b6ce59a69fc1fb2d 100644 (file)
@@ -42,11 +42,11 @@ function processing_active()
        Check if the cart was not destroyed during opening the edition page in
        another browser tab.
 */
-function check_edit_conflicts($cartname='Items')
+function check_edit_conflicts($cart_id, $cartname='Items')
 {
        global $Ajax, $no_check_edit_conflicts;
 
-       if ((!isset($no_check_edit_conflicts) || $no_check_edit_conflicts==0) && get_post('cart_id') && $_POST['cart_id'] != $_SESSION[$cartname]->cart_id) {
+       if ((!isset($no_check_edit_conflicts) || $no_check_edit_conflicts==0) && get_post('cart_id') && $cart_id != $_SESSION[$cartname]->cart_id) {
                display_error(_('This edit session has been abandoned by opening sales document in another browser tab. You cannot edit more than one sales document at once.'));
                $Ajax->activate('_page_body');
                display_footer_exit();
index 4356121379971c0cb2bc167657ab9162d08fb5aa..5687d0fcdbe47ed800870410a82b2263f5551981 100644 (file)
@@ -191,7 +191,8 @@ function check_overdue($row)
                && floatcmp($row["TotalAmount"], $row["Allocated"]) != 0;
 }
 //------------------------------------------------------------------------------------------------
-$sql = get_sql_for_customer_inquiry();
+$sql = get_sql_for_customer_inquiry(get_post('TransAfterDate'), get_post('TransToDate'),
+       get_post('customer_id'), get_post('filterType'));
 
 //------------------------------------------------------------------------------------------------
 db_query("set @bal:=0");
index 91787385f11d953dbb273880ba6cae309d7741c3..b4d9924b94c087276f35be06a2831d759139f7b1 100644 (file)
@@ -36,14 +36,12 @@ else
 
 if (isset($_GET['selected_customer']))
 {
-       $selected_customer = $_GET['selected_customer'];
+       $_POST['customer_id'] = $_GET['selected_customer'];
 }
 elseif (isset($_POST['selected_customer']))
 {
-       $selected_customer = $_POST['selected_customer'];
+       $_POST['customer_id'] = $_POST['selected_customer'];
 }
-else
-       $selected_customer = -1;
 
 if (isset($_POST['BatchInvoice']))
 {
@@ -124,17 +122,6 @@ end_row();
 end_table(1);
 //---------------------------------------------------------------------------------------------
 
-if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
-       ($_POST['SelectStockFromList'] != ALL_TEXT))
-{
-       $selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
-{
-       $selected_stock_item = null;
-}
-
-//---------------------------------------------------------------------------------------------
 function trans_view($trans, $trans_no)
 {
        return get_customer_trans_view_str(ST_CUSTDELIVERY, $trans['trans_no']);
@@ -175,7 +162,8 @@ function check_overdue($row)
                        $row["Outstanding"]!=0;
 }
 //------------------------------------------------------------------------------------------------
-$sql = get_sql_for_sales_deliveries_view($selected_customer, $selected_stock_item, $_POST['customer_id']);
+$sql = get_sql_for_sales_deliveries_view(get_post('DeliveryAfterDate'), get_post('DeliveryToDate'), get_post('customer_id'),
+       get_post('SelectStockFromList'), get_post('StockLocation'), get_post('DeliveryNumber'), get_post('OutstandingOnly'));
 
 $cols = array(
                _("Delivery #") => array('fun'=>'trans_view'), 
index ae9a666ea6a17d04eaca5e0bb13ccf3c792e7ef2..7955d6c41e44b861d6d6c55a5fbbbb809ae75947 100644 (file)
@@ -201,27 +201,17 @@ function invoice_prep_link($row)
                "/sales/customer_invoice.php?InvoicePrepayments=" .$row['order_no'], ICON_DOC) : '';
 }
 
-//---------------------------------------------------------------------------------------------
-// Update db record if respective checkbox value has changed.
-//
-function change_tpl_flag($id)
+$id = find_submit('_chgtpl');
+if ($id != -1)
 {
-       global  $Ajax;
-       
-       $sql = "UPDATE ".TB_PREF."sales_orders SET type = !type WHERE order_no=$id";
-
-       db_query($sql, "Can't change sales order type");
+       sales_order_set_template($id, check_value('chgtpl'.$id));
        $Ajax->activate('orders_tbl');
 }
 
-$id = find_submit('_chgtpl');
-if ($id != -1)
-       change_tpl_flag($id);
-
 if (isset($_POST['Update']) && isset($_POST['last'])) {
        foreach($_POST['last'] as $id => $value)
                if ($value != check_value('chgtpl'.$id))
-                       change_tpl_flag($id);
+                       sales_order_set_template($id, !check_value('chgtpl'.$id));
 }
 
 $show_dates = !in_array($_POST['order_view_mode'], array('OutstandingOnly', 'InvoiceTemplates', 'DeliveryTemplates'));
index 374d2f57d74fc1512645f382fd976d5b2658b1b9..d11915c657c88b8de7523493aed2a06c07b27ddb 100644 (file)
@@ -283,9 +283,9 @@ echo "<center>" . _("Select a customer: ") . "&nbsp;&nbsp;";
 echo customer_list('customer_id', null, false, true);
 echo "</center><br>";
 
-$num_branches = db_customer_has_branches($_POST['customer_id']);
+$num_branches = db_customer_has_branches(get_post('customer_id'));
 
-$sql = get_sql_for_customer_branches();
+$sql = get_sql_for_customer_branches(get_post('customer_id'));
 
 //------------------------------------------------------------------------------------------------
 if ($num_branches)
index 7dbf471b2bc40e1412c1661853b2c021eb54bf42..30fdc0d4858991fd128c5135ab673e717e80c09c 100644 (file)
@@ -220,13 +220,10 @@ if (isset($_GET['AddedID'])) {
        submenu_print(_("&Print Sales Invoice"), ST_SALESINVOICE, $invoice."-".ST_SALESINVOICE, 'prtopt');
        submenu_print(_("&Email Sales Invoice"), ST_SALESINVOICE, $invoice."-".ST_SALESINVOICE, null, 1);
        set_focus('prtopt');
-       
-       $sql = "SELECT trans_type_from, trans_no_from FROM ".TB_PREF."cust_allocations
-                       WHERE trans_type_to=".ST_SALESINVOICE." AND trans_no_to=".db_escape($invoice);
-       $result = db_query($sql, "could not retrieve customer allocation");
-       $row = db_fetch($result);
+
+       $row = db_fetch(get_allocatable_from_cust_transactions(null, $invoice, ST_SALESINVOICE));
        if ($row !== false)
-               submenu_print(_("Print &Receipt"), $row['trans_type_from'], $row['trans_no_from']."-".$row['trans_type_from'], 'prtopt');
+               submenu_print(_("Print &Receipt"), $row['type'], $row['trans_no']."-".$row['type'], 'prtopt');
 
        display_note(get_gl_view_str(ST_SALESINVOICE, $invoice, _("View the GL &Journal Entries for this Invoice")),0, 1);
 
@@ -244,7 +241,7 @@ if (isset($_GET['AddedID'])) {
 
        display_footer_exit();
 } else
-       check_edit_conflicts();
+       check_edit_conflicts(get_post('cart_id'));
 //-----------------------------------------------------------------------------
 
 function copy_to_cart()
@@ -517,7 +514,7 @@ function check_item_data()
                display_error( _("The item could not be updated because you are attempting to set the quantity ordered to less than 0, or the discount percent to more than 100."));
                set_focus('qty');
                return false;
-       } elseif (!check_num('price', 0) && (!$SysPrefs->$allow_negative_prices() || $is_inventory_item)) {
+       } elseif (!check_num('price', 0) && (!$SysPrefs->allow_negative_prices() || $is_inventory_item)) {
                display_error( _("Price for inventory item must be entered and can not be less than 0"));
                set_focus('price');
                return false;
index 0a2584d346a77ebd6f7dc3294959224d081e7f53..481ea817756507284cb1c66328abc1402b61b21f 100644 (file)
@@ -32,54 +32,20 @@ class fa2_4 {
                if (get_company_pref('grn_clearing_act') === null) { // available form 2.3.1, can be not defined on pre-2.4 installations
                        set_company_pref('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0);
                }
-               if (get_company_pref('default_receival_required') === null) { // new in 2.4 installations
-                       set_company_pref('default_receival_required', 'glsetup.purchase', 'smallint', 6, 10);
-               }
                if (get_company_pref('default_quote_valid_days') === null) { // new in 2.3.23 installations
                        set_company_pref('default_quote_valid_days', 'glsetup.sales', 'smallint', 6, 30);
                }
-               if (get_company_pref('no_zero_lines_amount') === null) { // new in 2.4 installations
-                       set_company_pref('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1');
-                       refresh_sys_prefs();
-               }
-               if (get_company_pref('show_po_item_codes') === null) { // new in 2.4 installations
-                       set_company_pref('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0');
-                       refresh_sys_prefs();
-               }
-               if (get_company_pref('accounts_alpha') === null) { // new in 2.4 installations
-                       set_company_pref('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0');
-                       refresh_sys_prefs();
-               }
-               if (get_company_pref('loc_notification') === null) { // new in 2.4 installations
-                       set_company_pref('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0');
-                       refresh_sys_prefs();
-               }
-               if (get_company_pref('print_invoice_no') === null) { // new in 2.4 installations
-                       set_company_pref('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0');
-                       refresh_sys_prefs();
-               }
-               if (get_company_pref('allow_negative_prices') === null) { // new in 2.4 installations
-                       set_company_pref('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1');
-                       refresh_sys_prefs();
-               }
-               if (get_company_pref('print_item_images_on_quote') === null) { // new in 2.4 installations
-                       set_company_pref('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0');
-                       refresh_sys_prefs();
-               }
                if (get_company_pref('bcc_email') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
                        set_company_pref('bcc_email', 'setup.company', 'varchar', 100, '');
-                       refresh_sys_prefs();
                }
                if (get_company_pref('alternative_tax_include_on_docs') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
                        set_company_pref('alternative_tax_include_on_docs', 'setup.company', 'tinyint', 1, '0');
-                       refresh_sys_prefs();
                }
                if (get_company_pref('suppress_tax_rates') === null) { // available from 2.3.14, can be not defined on pre-2.4 installations
                        set_company_pref('suppress_tax_rates', 'setup.company', 'tinyint', 1, '0');
-                       refresh_sys_prefs();
                }
 
-$result = $this->update_workorders()  && $this->update_grn_rates() && $this->switch_database_to_utf($pref);
+               $result = $this->update_workorders()  && $this->update_grn_rates() && $this->switch_database_to_utf($pref);
 
                if ($result)
                        $result = $this->do_cleanup();
index dd300d2cd5c474d9aa043122811dc4e4da0239e5..e8c2d3d02909bcc52a6a6f56cb26614b5d7af75e 100644 (file)
@@ -88,3 +88,12 @@ ALTER TABLE `0_users` ADD `save_report_selections` SMALLINT( 6 ) NOT NULL defaul
 ALTER TABLE `0_users` ADD `use_date_picker` TINYINT(1) NOT NULL default '1' COMMENT 'Use Date Picker for all Date Values' AFTER `save_report_selections`;
 ALTER TABLE `0_users` ADD `def_print_destination` TINYINT(1) NOT NULL default '0' COMMENT 'Default Report Destination' AFTER `use_date_picker`;
 ALTER TABLE `0_users` ADD `def_print_orientation` TINYINT(1) NOT NULL default '0' COMMENT 'Default Report Orientation' AFTER `def_print_destination`;
+
+INSERT INTO `0_sys_prefs` VALUES('no_zero_lines_amount', 'glsetup.sales', 'tinyint', 1, '1');
+INSERT INTO `0_sys_prefs` VALUES('show_po_item_codes', 'glsetup.purchase', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('accounts_alpha', 'glsetup.general', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('loc_notification', 'glsetup.inventory', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('print_invoice_no', 'glsetup.sales', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('allow_negative_prices', 'glsetup.inventory', 'tinyint', 1, '1');
+INSERT INTO `0_sys_prefs` VALUES('print_item_images_on_quote', 'glsetup.inventory', 'tinyint', 1, '0');
+INSERT INTO `0_sys_prefs` VALUES('default_receival_required', 'glsetup.purchase', 'smallint', 6, '10');
index fcef56ab510178b332bfb213359ec7f6cea9c829..f067dbe54c9b69cebdc368cf93bd1255fe57a540 100644 (file)
@@ -2341,10 +2341,10 @@ CREATE TABLE IF NOT EXISTS `0_users` (
   `sticky_doc_date` tinyint(1) default '0',
   `startup_tab` varchar(20) NOT NULL default '',
   `transaction_days` smallint(6) NOT NULL default '30',
-  'save_report_selections' smallint(6) NOT NULL default '0',
-  'use_date_picker' tinyint(1) NOT NULL default '1',
-  'def_print_destination' tinyint(1) NOT NULL default '0',
-  'def_print_orientation' tinyint(1) NOT NULL default '0',
+  `save_report_selections` smallint(6) NOT NULL default '0',
+  `use_date_picker` tinyint(1) NOT NULL default '1',
+  `def_print_destination` tinyint(1) NOT NULL default '0',
+  `def_print_orientation` tinyint(1) NOT NULL default '0',
   `inactive` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`id`),
   UNIQUE KEY `user_id` (`user_id`)
index d46b8906441ea849e0be04fe896d4f5ae105ea4f..a83dbc2674a8cef4a053e180849689ecb55a7935 100644 (file)
@@ -2090,10 +2090,10 @@ CREATE TABLE IF NOT EXISTS `0_users` (
   `sticky_doc_date` tinyint(1) default '0',
   `startup_tab` varchar(20) NOT NULL default '',
   `transaction_days` smallint(6) NOT NULL default '30',
-  'save_report_selections' smallint(6) NOT NULL default '0',
-  'use_date_picker' tinyint(1) NOT NULL default '1',
-  'def_print_destination' tinyint(1) NOT NULL default '0',
-  'def_print_orientation' tinyint(1) NOT NULL default '0',
+  `save_report_selections` smallint(6) NOT NULL default '0',
+  `use_date_picker` tinyint(1) NOT NULL default '1',
+  `def_print_destination` tinyint(1) NOT NULL default '0',
+  `def_print_orientation` tinyint(1) NOT NULL default '0',
   `inactive` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`id`),
   UNIQUE KEY `user_id` (`user_id`)