Old ineffective sql_trail superseded by new improved db_trail logging only calls...
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Fri, 26 Jul 2019 19:01:03 +0000 (21:01 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 19 Aug 2019 10:41:58 +0000 (12:41 +0200)
89 files changed:
admin/db/attachments_db.inc
admin/db/company_db.inc
admin/db/fiscalyears_db.inc
admin/db/maintenance_db.inc
admin/db/printers_db.inc
admin/db/security_db.inc
admin/db/shipping_db.inc
admin/db/tags_db.inc
admin/db/users_db.inc
admin/fiscalyears.php
admin/security_roles.php
config.default.php
dimensions/includes/dimensions_db.inc
fixed_assets/includes/fa_classes_db.inc
fixed_assets/includes/fixed_assets_db.inc
gl/gl_bank.php
gl/includes/db/gl_db_account_types.inc
gl/includes/db/gl_db_accounts.inc
gl/includes/db/gl_db_bank_accounts.inc
gl/includes/db/gl_db_bank_trans.inc
gl/includes/db/gl_db_banking.inc
gl/includes/db/gl_db_currencies.inc
gl/includes/db/gl_db_rates.inc
gl/includes/db/gl_db_trans.inc
gl/includes/db/gl_journal.inc
gl/includes/gl_db.inc
gl/includes/ui/gl_journal_ui.inc
includes/current_user.inc
includes/db/audit_trail_db.inc
includes/db/class.reflines_db.inc
includes/db/connect_db_mysql.inc
includes/db/connect_db_mysqli.inc
includes/db/crm_contacts_db.inc
includes/db/sql_functions.inc
inventory/includes/db/items_adjust_db.inc
inventory/includes/db/items_category_db.inc
inventory/includes/db/items_db.inc
inventory/includes/db/items_locations_db.inc
inventory/includes/db/items_prices_db.inc
inventory/includes/db/items_purchases_db.inc
inventory/includes/db/items_trans_db.inc [deleted file]
inventory/includes/db/items_transfer_db.inc
inventory/includes/db/items_units_db.inc
inventory/includes/inventory_db.inc
inventory/manage/items.php
manufacturing/includes/db/work_centres_db.inc
manufacturing/includes/db/work_order_costing_db.inc
manufacturing/includes/db/work_order_issues_db.inc
manufacturing/includes/db/work_order_produce_items_db.inc
manufacturing/includes/db/work_order_requirements_db.inc
manufacturing/includes/db/work_orders_db.inc
purchasing/allocations/supplier_allocate.php
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
purchasing/includes/db/po_db.inc
purchasing/includes/db/supp_payment_db.inc
purchasing/includes/db/suppliers_db.inc
purchasing/includes/purchasing_db.inc
purchasing/manage/suppliers.php
sales/allocations/customer_allocate.php
sales/create_recurrent_invoices.php
sales/credit_note_entry.php
sales/customer_credit_invoice.php
sales/customer_delivery.php
sales/customer_invoice.php
sales/customer_payments.php
sales/includes/db/branches_db.inc
sales/includes/db/credit_status_db.inc
sales/includes/db/customers_db.inc
sales/includes/db/payment_db.inc
sales/includes/db/recurrent_invoices_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_delivery_db.inc
sales/includes/db/sales_groups_db.inc
sales/includes/db/sales_invoice_db.inc
sales/includes/db/sales_order_db.inc
sales/includes/db/sales_points_db.inc
sales/includes/db/sales_types_db.inc
sales/includes/sales_db.inc
sales/manage/customer_branches.php
sales/manage/customers.php
sales/manage/recurrent_invoices.php
sales/sales_order_entry.php
sql/alter2.5.sql
sql/en_US-demo.sql
sql/en_US-new.sql
taxes/db/item_tax_types_db.inc
taxes/db/tax_groups_db.inc
taxes/db/tax_types_db.inc

index f3c46dc41332c28b89d32b3d2be59bf40a59efcd..561bea33f8a917f720fe6f5d7f679d94e6e77cd0 100644 (file)
@@ -15,6 +15,8 @@
 function add_attachment($filterType, $trans_no, $description,
        $filename, $unique_name, $filesize, $filetype)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $date = date2sql(Today());
        $sql = "INSERT INTO ".TB_PREF."attachments (type_no, trans_no, description, filename, unique_name,
                filesize, filetype, tran_date) VALUES (".db_escape($filterType).","
@@ -22,12 +24,16 @@ function add_attachment($filterType, $trans_no, $description,
                .db_escape($filename).", ".db_escape($unique_name).", ".db_escape($filesize)
                .", ".db_escape($filetype).", '$date')";
        db_query($sql, "Attachment could not be inserted");             
+
+       commit_transaction();
 }
 //----------------------------------------------------------------------------------------
 
 function update_attachment($selected_id, $filterType, $trans_no, $description,
        $filename, $unique_name, $filesize, $filetype)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $date = date2sql(Today());
        $sql = "UPDATE ".TB_PREF."attachments SET
                type_no=".db_escape($filterType).",
@@ -42,14 +48,20 @@ function update_attachment($selected_id, $filterType, $trans_no, $description,
        }       
        $sql .= "tran_date='$date' WHERE id=".db_escape($selected_id);
        db_query($sql, "Attachment could not be updated");              
+
+       commit_transaction();
 }
 
 //----------------------------------------------------------------------------------------
 
 function delete_attachment($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "DELETE FROM ".TB_PREF."attachments WHERE id = ".db_escape($id);
        db_query($sql, "Could not delete attachment");
+
+       commit_transaction();
 }
 
 //----------------------------------------------------------------------------------------
index 39108db831f22d408f41f2344c3a1c3b9371f96a..8e788532362e67bbcfaf57be34a72f3d94397e79 100644 (file)
@@ -14,6 +14,8 @@
 */
 function update_company_prefs($params)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."sys_prefs SET value = ";
        foreach($params as $name => $value) {
                if (!db_query($sql. db_escape($value). " WHERE name=".db_escape($name),
@@ -22,6 +24,8 @@ function update_company_prefs($params)
                // update cached value
                $_SESSION['SysPrefs']->prefs[$name] = $value;
        }
+
+       commit_transaction();
        return true;
 }
 /*
@@ -55,9 +59,15 @@ function get_company_prefs()
 
 function set_company_pref($pref, $category, $type, $length, $value)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "REPLACE `".TB_PREF."sys_prefs` SET `name`=".db_escape($pref).", `category`=".db_escape($category)
                .", `type`=".db_escape($type).", `length`=".db_escape($length).", `value`=".db_escape($value);
-       return db_query($sql, "cannot set company pref");
+       $result = db_query($sql, "cannot set company pref");
+
+       commit_transaction();
+       return $result;
+
 }
 
 function get_base_sales_type()
@@ -78,6 +88,8 @@ function get_company_extensions($id = -1) {
 
 function add_payment_terms($daysOrFoll, $terms, $dayNumber)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        if ($daysOrFoll) 
        {
                $sql = "INSERT INTO ".TB_PREF."payment_terms (terms,
@@ -93,10 +105,14 @@ function add_payment_terms($daysOrFoll, $terms, $dayNumber)
                        0, " . db_escape($dayNumber) . ")";
        }
        db_query($sql,"The payment term could not be added");
+
+       commit_transaction();
 }
 
 function update_payment_terms($selected_id, $daysOrFoll, $terms, $dayNumber)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        if ($daysOrFoll) 
        {
                $sql = "UPDATE ".TB_PREF."payment_terms SET terms=" . db_escape($terms) . ",
@@ -112,12 +128,18 @@ function update_payment_terms($selected_id, $daysOrFoll, $terms, $dayNumber)
                        WHERE terms_indicator = " .db_escape($selected_id);
        }
        db_query($sql,"The payment term could not be updated");
+
+       commit_transaction();
 }
 
 function delete_payment_terms($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql="DELETE FROM ".TB_PREF."payment_terms WHERE terms_indicator=".db_escape($selected_id);
        db_query($sql,"could not delete a payment terms");
+
+       commit_transaction();
 }
 
 function get_payment_terms($selected_id)
@@ -161,7 +183,7 @@ function key_in_foreign_table($id, $tables, $stdkey)
        $sql = "SELECT sum(cnt) FROM (". implode(' UNION ', $sqls).") as counts";
 
        $result = db_query($sql, "check relations for ".implode(',',$tables)." failed");
-       $count =  db_fetch($result);
+       $count = db_fetch($result);
 
        return $count[0];
 }
@@ -174,6 +196,8 @@ function clean_user_themes($theme)
 {
        global $db_connections, $db;
 
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $comp = user_company();
 
        $connections = $db_connections; // do not use db_connections directly here, or script will hang due to db_connections usage inside the loop
@@ -185,5 +209,7 @@ function clean_user_themes($theme)
        }
        $db = $_SESSION["wa_current_user"]->set_db_connection($comp);
        $_SESSION['wa_current_user']->prefs->theme = 'default';
+
+       commit_transaction();
        return true;
 }
index 1d1d94a843aac8fdb4d490e8739ec9537d12bec2..d93b3341d635145977df3c6c6714256c4d915814 100644 (file)
@@ -14,6 +14,8 @@ require_once($path_to_root. "/includes/ui/items_cart.inc");
 // fiscal year routines
 function add_fiscalyear($from_date, $to_date, $closed)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $from = date2sql($from_date);
        $to = date2sql($to_date);
 
@@ -21,14 +23,19 @@ function add_fiscalyear($from_date, $to_date, $closed)
                VALUES (".db_escape($from).",".db_escape($to).", ".db_escape($closed).")";
 
        db_query($sql, "could not add fiscal year");
+
+       commit_transaction();
 }
 
 function update_fiscalyear($id, $closed)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."fiscal_year SET closed=".db_escape($closed)."
                WHERE id=".db_escape($id);
-
        db_query($sql, "could not update fiscal year");
+
+       commit_transaction();
 }
 
 function get_all_fiscalyears()
@@ -61,7 +68,7 @@ function get_current_fiscalyear()
 
 function delete_fiscalyear($id)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $sql="DELETE FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($id);
 
@@ -131,19 +138,7 @@ function close_year($year)
 {
        global $Refs;
 
-       $co = get_company_prefs();
-       if (get_gl_account($co['retained_earnings_act']) == false || get_gl_account($co['profit_loss_year_act']) == false)
-       {
-               display_error(_("The Retained Earnings Account or the Profit and Loss Year Account has not been set in System and General GL Setup"));
-               return false;
-       }
-       if (!is_account_balancesheet($co['retained_earnings_act']) || is_account_balancesheet($co['profit_loss_year_act']))
-       {
-               display_error(_("The Retained Earnings Account should be a Balance Account or the Profit and Loss Year Account should be an Expense Account (preferred the last one in the Expense Class)"));
-               return false;
-       }
-
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $myrow = get_fiscalyear($year);
        $to = $myrow['end'];
@@ -177,11 +172,13 @@ function close_year($year)
 
 function open_year($year)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $myrow = get_fiscalyear($year);
        $from = sql2date($myrow['begin']);
 
-       begin_transaction();
        close_transactions(add_days($from, -1));
+
        commit_transaction();
 }
 
@@ -216,7 +213,9 @@ function delete_this_fiscalyear($selected_id)
        global $db_connections;
        
        db_backup($db_connections[user_company()], 'Security backup before Fiscal Year Removal');
-       begin_transaction();
+
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $ref = _("Open Balance");
        $myrow = get_fiscalyear($selected_id);
        $to = $myrow['end'];
index 9fa78b999af3c8c4160d4e929298ac88a24da3e4..880a4384d099c16127a4141e19ff5d5abc149895 100644 (file)
@@ -268,8 +268,8 @@ function db_import($filename, $connection, $force=true, $init=true, $protect=fal
 {
        global $db, $SysPrefs;
 
-       $trail = $SysPrefs->sql_trail;
-       $SysPrefs->sql_trail = false;
+       $trail = $SysPrefs->db_trail;
+       $SysPrefs->db_trail = false;
 
        $allowed_commands = array(
                "create"  => 'table_queries', 
@@ -476,7 +476,7 @@ function db_import($filename, $connection, $force=true, $init=true, $protect=fal
        if ($system)
                $SysPrefs->go_debug = $save_debug;
 
-       $SysPrefs->sql_trail = $trail;
+       $SysPrefs->db_trail = $trail;
 
        db_query("SET foreign_key_checks=1");
        if ($delimiter != ';') db_query("delimiter ;"); // just for any case
index 28c98a56b4b5d56c190d7634e76daca481fb2f64..0932b92f09b611240ed7974d70092ef4ca74d8ba 100644 (file)
 
 function write_printer_def($id, $name, $descr, $queue, $host, $port, $timeout)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        if ($id>0)
                $sql = "UPDATE ".TB_PREF."printers SET description=".db_escape($descr)
                .",name=".db_escape($name).",queue=".db_escape($queue)
                .",host=".db_escape($host).",port=".db_escape($port).",timeout=".db_escape($timeout)
                ." WHERE id=".db_escape($id);
-       else 
+       else
                $sql = "INSERT INTO ".TB_PREF."printers ("
                        ."name,description,queue,host,port,timeout) "
                        ."VALUES (".db_escape($name).",".db_escape($descr).","
                        .db_escape($queue).",".db_escape($host).",".db_escape($port).",".db_escape($timeout).")";
 
-       return db_query($sql,"could not write printer definition");
+       $result = db_query($sql,"could not write printer definition");
+
+       commit_transaction();
+       return  $result ? ($id ? $id : db_insert_id()) : false;
 }
 
 function get_all_printers() 
@@ -43,14 +48,20 @@ function get_printer($id)
 
 function delete_printer($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql="DELETE FROM ".TB_PREF."printers WHERE id=".db_escape($id);
        db_query($sql,"could not delete printer definition");
+
+       commit_transaction();
 }
 //============================================================================
 // printer profiles functions
 //
 function update_printer_profile($name, $dest)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        foreach( $dest as $rep => $printer) {
                if ($printer != '' || $rep == '') {
                        $sql = "REPLACE INTO ".TB_PREF."print_profiles "
@@ -68,6 +79,8 @@ function update_printer_profile($name, $dest)
                        return false;
                }
        }
+
+       commit_transaction();
        return true;
 }
 //
@@ -94,8 +107,13 @@ function get_report_printer($profile, $report)
 
 function delete_printer_profile($name)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql="DELETE FROM ".TB_PREF."print_profiles WHERE profile=".db_escape($name);
-       return db_query($sql,"could not delete printing profile");
+       $result = db_query($sql,"could not delete printing profile");
+
+       commit_transaction();
+       return $result;
 }
 //
 // Get all report destinations for given profile.
index 70027c2e7c3b489f161edbf05e23dea6b1b18815..67cbd625ac139bc14fe847a9ad2af9a1f79e8100 100644 (file)
@@ -27,6 +27,7 @@ function get_security_role($id)
 
 function add_security_role($name, $description, $sections, $areas)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."security_roles (role, description, sections, areas)
        VALUES ("
        .db_escape($name).","
@@ -35,26 +36,31 @@ function add_security_role($name, $description, $sections, $areas)
        .db_escape(implode(';', $areas)).")";
 
        db_query($sql, "could not add new security role");
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------------------
 
 function update_security_role($id, $name, $description, $sections, $areas)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."security_roles SET role=".db_escape($name)
        .",description=".db_escape($description)
        .",sections=".db_escape(implode(';', $sections))
        .",areas=".db_escape(implode(';', $areas))
        ." WHERE id=".(int)$id;
        db_query($sql, "could not update role");
+       commit_transaction();
 }
 //--------------------------------------------------------------------------------------------------
 
 function delete_security_role($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "DELETE FROM ".TB_PREF."security_roles WHERE id=".(int)$id;
 
        db_query($sql, "could not delete role");
+       commit_transaction();
 }
 //--------------------------------------------------------------------------------------------------
 
@@ -64,3 +70,17 @@ function check_role_used($id) {
        $row = db_fetch($ret);
        return $row[0];
 }
+
+function write_security_role($id, $name, $description, $sections, $areas, $inactive)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+               $sections = array_values($sections);
+
+       if ($id == '') 
+                       add_security_role($name, $description, $sections, $areas); 
+               else {
+                       update_security_role($id, $name, $description, $sections, $areas);
+                       update_record_status($id, $inactive, 'security_roles', 'id');
+               }
+       commit_transaction();
+}
index 6eca60deab2d3c71dc38459940d0d38e20c3452e..6d46e250863aa1ceb825d70097e0063c9c2b26b3 100644 (file)
@@ -14,6 +14,8 @@
 
 function add_shipper($shipper_name, $contact, $phone, $phone2, $address)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."shippers (shipper_name, contact, phone, phone2, address)
                VALUES (" . db_escape($shipper_name) . ", " .
                db_escape($contact). ", " .
@@ -22,12 +24,18 @@ function add_shipper($shipper_name, $contact, $phone, $phone2, $address)
                db_escape($address) . ")";
 
        db_query($sql,"The Shipping Company could not be added");
+       $result = db_insert_id();
+
+       commit_transaction();
+       return $result;
 }
 
 //--------------------------------------------------------------------------------------
 
 function update_shipper($selected_id, $shipper_name, $contact, $phone, $phone2, $address)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."shippers SET shipper_name=" . db_escape($shipper_name). " ,
                contact =" . db_escape($contact). " ,
                phone =" . db_escape($phone). " ,
@@ -36,15 +44,21 @@ function update_shipper($selected_id, $shipper_name, $contact, $phone, $phone2,
                WHERE shipper_id = ".db_escape($selected_id);
 
        db_query($sql,"The shipping company could not be updated");
+
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
 
 function delete_shipper($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql="DELETE FROM ".TB_PREF."shippers WHERE shipper_id=".db_escape($selected_id);
        
        db_query($sql,"could not delete shipper");
+
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
index 08cb13c6eda1f37906c6a5d79297ecefd71bfae0..c5b0e45a9c2a226b871c6d3918f82efae9501629 100644 (file)
 
 function add_tag($type, $name, $description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."tags (type, name, description)
                VALUES (".db_escape($type).", ".db_escape($name).", ".db_escape($description).")";
 
-       return db_query($sql);
+       $result = db_query($sql);
+       commit_transaction();
+       return $result;
 }
 
 //--------------------------------------------------------------------------------------
 
 function update_tag($id, $name, $description, $type=null)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."tags SET name=".db_escape($name).", 
                                        description=".db_escape($description);
        if ($type != null)
@@ -29,7 +34,9 @@ function update_tag($id, $name, $description, $type=null)
 
        $sql .= " WHERE id = ".db_escape($id);
 
-       return db_query($sql);
+       $result = db_query($sql);
+       commit_transaction();
+       return $result;
 }
 
 //--------------------------------------------------------------------------------------
@@ -112,15 +119,20 @@ function get_tag_description($id)
 
 function delete_tag($id)
 {
-       $sql = "DELETE FROM ".TB_PREF."tags WHERE id = ".db_escape($id);
+       begin_transaction(__FUNCTION__, func_get_args());
 
+       $sql = "DELETE FROM ".TB_PREF."tags WHERE id = ".db_escape($id);
        db_query($sql, "could not delete tag");
+
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
 
 function add_tag_associations($recordid, $tagids)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        foreach($tagids as $tagid) {
                if (!$tagid) continue;
                $sql = "INSERT INTO ".TB_PREF."tag_associations (record_id, tag_id)
@@ -128,16 +140,22 @@ function add_tag_associations($recordid, $tagids)
 
                db_query($sql, "could not add tag association");
        }
+
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
 
 function update_tag_associations($type, $recordid, $tagids)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        // Delete the old associations
        delete_tag_associations($type, $recordid, false);
        // Add the new associations
        add_tag_associations($recordid, $tagids);
+
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
@@ -146,6 +164,7 @@ function update_tag_associations($type, $recordid, $tagids)
 //
 function delete_tag_associations($type, $recordid, $all=false)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
 /* multiply table DELETE syntax available since MySQL 4.0.0:
        $sql = "DELETE ta FROM ".TB_PREF."tag_associations ta 
                                INNER JOIN ".TB_PREF."tags tags ON tags.id = ta.tag_id 
@@ -164,6 +183,8 @@ function delete_tag_associations($type, $recordid, $all=false)
                        record_id = '".$ta['record_id']."' AND tag_id=".$ta['tag_id'];
                db_query($sql2, "could not delete tag associations");
        }
+
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
index 52b02411ffde046fb3a9f38b0e3ef83c97163d66..1040930591988465f9a24a09e45d53a3e8eefced 100644 (file)
@@ -13,6 +13,7 @@
 function add_user($user_id, $real_name, $password, $phone, $email, $role_id, 
        $language, $profile, $rep_popup, $pos)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."users (user_id, real_name, password"
                .", phone, email, role_id, language, pos, print_profile, rep_popup)
                VALUES (".db_escape($user_id).", 
@@ -21,17 +22,23 @@ function add_user($user_id, $real_name, $password, $phone, $email, $role_id,
                .", ".db_escape($pos).",".db_escape($profile).",".db_escape($rep_popup)
                ." )";
 
-       return db_query($sql, "could not add user for $user_id");
+       $result = db_query($sql, "could not add user for $user_id");
+       commit_transaction();
+       return $result;
 }
 
 //-----------------------------------------------------------------------------------------------
 
 function update_user_password($id, $user_id, $password)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."users SET password=".db_escape($password) . ",
                user_id = ".db_escape($user_id). " WHERE id=".db_escape($id);
+       $result = db_query($sql, "could not update user password for $user_id");
 
-       return db_query($sql, "could not update user password for $user_id");
+       commit_transaction();
+       return $result;
 }
 
 //-----------------------------------------------------------------------------------------------
@@ -39,6 +46,7 @@ function update_user_password($id, $user_id, $password)
 function update_user($id, $user_id, $real_name, $phone, $email, $role_id, 
        $language, $profile, $rep_popup, $pos)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."users SET real_name=".db_escape($real_name).
        ", phone=".db_escape($phone).",
                email=".db_escape($email).",
@@ -50,19 +58,25 @@ function update_user($id, $user_id, $real_name, $phone, $email, $role_id,
                user_id = " . db_escape($user_id)
                . " WHERE id=" . db_escape($id);
        return db_query($sql, "could not update user for $user_id");
+       commit_transaction();
 }
 
 //-----------------------------------------------------------------------------------------------
 
 function update_user_prefs($id, $prefs)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."users SET ";
        foreach($prefs as $name => $value) {
                $prefs[$name] = $name.'='. db_escape($value);
        }
        $sql .= implode(',', $prefs) . " WHERE id=".db_escape($id);
 
-       return db_query($sql, "could not update user display prefs for $id");
+       $result = db_query($sql, "could not update user display prefs for $id");
+
+       commit_transaction();
+       return $result;
 }
 
 //-----------------------------------------------------------------------------------------------
@@ -117,9 +131,13 @@ function get_user_by_email($email)
 
 function delete_user($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql="DELETE FROM ".TB_PREF."users WHERE id=".db_escape($id);
 
        db_query($sql, "could not delete user $id");
+
+       commit_transaction();
 }
 
 //-----------------------------------------------------------------------------------------------
@@ -134,13 +152,19 @@ function get_user_auth($user_id, $password)
 }
 
 //-----------------------------------------------------------------------------------------------
-
-function update_user_visitdate($user_id)
+//
+//     Record user login. When logging is on also current FA state is recorded.
+//
+function update_user_visitdate($user_id, $src_version, $db_version, $extensions)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."users SET last_visit_date='". date("Y-m-d H:i:s") ."'
                WHERE user_id=".db_escape($user_id);
 
        db_query($sql, "could not update last visit date for user $user_id");
+
+       commit_transaction();
 }
 
 //-----------------------------------------------------------------------------------------------
index d6d05c5a14153a643c25e7fc4c924adcd66c32cc..8874ea7de99dd0a848a5151dd243cdadc111ad89 100644 (file)
@@ -71,6 +71,18 @@ function handle_submit()
                                set_focus('closed');
                                return false;
                        }       
+                       $co = get_company_prefs();
+                       if (get_gl_account($co['retained_earnings_act']) == false || get_gl_account($co['profit_loss_year_act']) == false)
+                       {
+                               display_error(_("The Retained Earnings Account or the Profit and Loss Year Account has not been set in System and General GL Setup"));
+                               return false;
+                       }
+                       if (!is_account_balancesheet($co['retained_earnings_act']) || is_account_balancesheet($co['profit_loss_year_act']))
+                       {
+                               display_error(_("The Retained Earnings Account should be a Balance Account or the Profit and Loss Year Account should be an Expense Account (preferred the last one in the Expense Class)"));
+                               return false;
+                       }
+
                        $ok = close_year($selected_id);
                }       
                else
index 4b438091f237794d6cfce657ea247aed74b7f2a1..7e68d3734854b6c45f647f021bfce8f9c1fec8cb 100644 (file)
@@ -97,21 +97,13 @@ if (get_post('addupdate'))
                }
 //             $areas = sort_areas($areas);
 
-               $sections = array_values($sections);
-
-       if ($new_role) 
-               {
-                       add_security_role($_POST['name'], $_POST['description'], $sections, $areas); 
-                       display_notification(_("New security role has been added."));
-               } else
-               {
-                       update_security_role($_POST['role'], $_POST['name'], $_POST['description'], 
-                               $sections, $areas); 
-                       update_record_status($_POST['role'], get_post('inactive'),
-                               'security_roles', 'id');
-
-                       display_notification(_("Security role has been updated."));
-               }
+       write_security_role($_POST['role'], $_POST['name'], $_POST['description'], 
+               $sections, $areas, get_post('inactive'));
+
+       if ($new_role) 
+               display_notification(_("New security role has been added."));
+       else
+               display_notification(_("Security role has been updated."));
        $new_role = true;
        clear_data();
        $Ajax->activate('_page_body');
index acd3ddc62b4d6bec2a5ea0b3539bcc78d5b71627..3630dfc7c0870635febee67be314aac7615b6f12 100644 (file)
@@ -35,13 +35,11 @@ if (!isset($path_to_root) || isset($_GET['path_to_root']) || isset($_POST['path_
        $show_sql               = 0;    // show all sql queries in page footer for debugging purposes
        $go_debug               = 0;    // set to 1 for basic debugging, or 2 to see also backtrace after failure.
        $pdf_debug              = 0;    // display pdf source instead reports for debugging when $go_debug!=0
-       // set $sql_trail to 1 only if you want to perform bugtracking sql trail
-       // Warning: this produces huge amount of data in sql_trail table.
-       // Don't forget switch the option off and flush the table manually after 
-       // trail, or your future backup files are overloaded with unneeded data.
-       //
-       $sql_trail              = 0; // save all sql queries in sql_trail
-       $select_trail   = 0; // track also SELECT queries
+       // set $db_trail when you need full log of database changes for debugging purposes
+       // Warning: this option can produce huge amount of data either in backups or error log file.
+       // 1 - log to db_trail table
+       // 2 - log to error file
+       $db_trail               = 0;
 
        // Main Title
        $app_title = "FrontAccounting";
index 13c91fd41c3956ad194114d386f95cc1013b9dfa..dd7edad131ac86448711ac37a4c8d4e501d8f1ba 100644 (file)
@@ -13,7 +13,7 @@ function add_dimension($reference, $name, $type_, $date_, $due_date, $memo_)
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $date = date2sql($date_);
        $duedate = date2sql($due_date);
@@ -35,7 +35,7 @@ function add_dimension($reference, $name, $type_, $date_, $due_date, $memo_)
 
 function update_dimension($id, $name, $type_, $date_, $due_date, $memo_)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $date = date2sql($date_);
        $duedate = date2sql($due_date);
@@ -57,7 +57,7 @@ function update_dimension($id, $name, $type_, $date_, $due_date, $memo_)
 
 function delete_dimension($id)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        // delete the actual dimension
        $sql="DELETE FROM ".TB_PREF."dimensions WHERE id=".db_escape($id);
@@ -139,16 +139,20 @@ function dimension_is_closed($id)
 
 function close_dimension($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."dimensions SET closed='1' WHERE id = ".db_escape($id);
        db_query($sql, "could not close dimension");
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
 
 function reopen_dimension($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."dimensions SET closed='0' WHERE id = ".db_escape($id);
        db_query($sql, "could not reopen dimension");
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
index 37fb5cebb082753cb18c81ada98940e8c03c71b4..2b5420e3ea2d0e59ddde0071c6c63f2a76f69384 100644 (file)
@@ -32,6 +32,7 @@ function get_fixed_asset_classname($class)
 
 function update_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_rate)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."stock_fa_class SET
                parent_id=".db_escape($parent_id).",
                description=".db_escape($description).",
@@ -40,10 +41,12 @@ function update_fixed_asset_class($fa_class_id, $parent_id, $description, $long_
     WHERE fa_class_id=".db_escape($fa_class_id);
 
        db_query($sql, "The fixed asset class could not be updated");
+       commit_transaction();
 }
 
 function add_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_rate)
 {
+  begin_transaction(__FUNCTION__, func_get_args());
   $sql = "INSERT INTO ".TB_PREF."stock_fa_class (fa_class_id, parent_id, description, long_description,
      depreciation_rate) VALUES ("
     .db_escape($fa_class_id).", ".db_escape($parent_id).", "
@@ -51,11 +54,14 @@ function add_fixed_asset_class($fa_class_id, $parent_id, $description, $long_des
     .db_escape($depreciation_rate).")";
 
        db_query($sql, "The fixed asset class could not be added");
+       commit_transaction();
 }
 
 function delete_fixed_asset_class($fa_class_id)
 {
-  $sql = "DELETE FROM ".TB_PREF."stock_fa_class WHERE fa_class_id=".db_escape($fa_class_id);
+       begin_transaction(__FUNCTION__, func_get_args());
+       $sql = "DELETE FROM ".TB_PREF."stock_fa_class WHERE fa_class_id=".db_escape($fa_class_id);
 
        db_query($sql, "The fixed asset class could not be deleted");
+       commit_transaction();
 }
index 11c9c027d50662f5d85d8fbf5c87174f9ca21750..b74dd0017bde111b317c46a314e28102604382e0 100644 (file)
@@ -17,7 +17,7 @@ function process_fixed_asset_depreciation($stock_id, $gl_rows, $refline, $memo_)
   $row = get_item($stock_id);
   $old_cost = $row['material_cost'];
 
-  begin_transaction();
+  begin_transaction(__FUNCTION__, func_get_args());
 
   $date_ = Today();
   if (!is_date_in_fiscalyear($date_))
index b11111530a0129d852f60ddf27f84096382c36fd..2ff551c708d8984b8ccb5f70231323f121498ceb 100644 (file)
@@ -342,8 +342,6 @@ function check_item_data()
        return true;
 }
 
-//-----------------------------------------------------------------------------------------------
-
 function handle_update_item()
 {
        $amount = ($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? 1:-1) * input_num('amount');
@@ -355,16 +353,12 @@ function handle_update_item()
        line_start_focus();
 }
 
-//-----------------------------------------------------------------------------------------------
-
 function handle_delete_item($id)
 {
        $_SESSION['pay_items']->remove_gl_item($id);
        line_start_focus();
 }
 
-//-----------------------------------------------------------------------------------------------
-
 function handle_new_item()
 {
        if (!check_item_data())
@@ -375,7 +369,9 @@ function handle_new_item()
                $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
        line_start_focus();
 }
+
 //-----------------------------------------------------------------------------------------------
+
 $id = find_submit('Delete');
 if ($id != -1)
        handle_delete_item($id);
@@ -418,7 +414,5 @@ submit_center_last('Process', $_SESSION['pay_items']->trans_type==ST_BANKPAYMENT
 
 end_form();
 
-//------------------------------------------------------------------------------------------------
-
 end_page();
 
index 4d6d58e876039aa5a7d29ee5fd82280f4323731f..3a9d2af8b36fde9a36b93a320602bb7e615122c9 100644 (file)
 ***********************************************************************/
 function add_account_type($id, $name, $class_id, $parent)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."chart_types (id, name, class_id, parent)
                VALUES (".db_escape($id).", ".db_escape($name).", ".db_escape($class_id).", ".db_escape($parent).")";
+       $result = db_query($sql);
 
-       return db_query($sql);
+       commit_transaction();
+       return $result ? db_insert_id($sql) : false;
 }
 
 function update_account_type($id, $name, $class_id, $parent, $old_id)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
+
        if ($old_id !== $id)
        {
                $sql = "SELECT id 
@@ -54,6 +59,7 @@ function update_account_type($id, $name, $class_id, $parent, $old_id)
                ." WHERE id = ".db_escape($old_id);
 
        $ret = db_query($sql, "could not update account type");
+
        commit_transaction();
        return $ret;
 }
@@ -103,25 +109,36 @@ function get_account_type_name($id)
 
 function delete_account_type($id)
 {
-       $sql = "DELETE FROM ".TB_PREF."chart_types WHERE id = ".db_escape($id);
+       begin_transaction(__FUNCTION__, func_get_args());
 
+       $sql = "DELETE FROM ".TB_PREF."chart_types WHERE id = ".db_escape($id);
        db_query($sql, "could not delete account type");
+
+       commit_transaction();
 }
 
 function add_account_class($id, $name, $ctype)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."chart_class (cid, class_name, ctype)
                VALUES (".db_escape($id).", ".db_escape($name).", ".db_escape($ctype).")";
+       $result = db_query($sql);
 
-       return db_query($sql);
+       commit_transaction();
+       return $result;
 }
 
 function update_account_class($id, $name, $ctype)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
     $sql = "UPDATE ".TB_PREF."chart_class SET class_name=".db_escape($name).",
                ctype=".db_escape($ctype)." WHERE cid = ".db_escape($id);
+       $result = db_query($sql);
 
-       return db_query($sql);
+       commit_transaction();
+       return $result;
 }
 
 function get_account_classes($all=false, $balance=-1)
@@ -160,8 +177,12 @@ function get_account_class_name($id)
 
 function delete_account_class($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "DELETE FROM ".TB_PREF."chart_class WHERE cid = ".db_escape($id);
 
        db_query($sql, "could not delete account type");
+       commit_transaction();
+
 }
 
index 6bc73abd9d03234c437d1f6932a85885f83015dc..a9f309b8de7c9301ec723ade86c330cb635ec556 100644 (file)
 ***********************************************************************/
 function add_gl_account($account_code, $account_name, $account_type, $account_code2)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."chart_master (account_code, account_code2, account_name, account_type)
                VALUES (".db_escape($account_code).", ".db_escape($account_code2).", "
                        .db_escape($account_name).", ".db_escape($account_type).")";
 
-       return db_query($sql);
+       $result = db_query($sql);
+       commit_transaction();
+       return $result;
 }
 
 function update_gl_account($account_code, $account_name, $account_type, $account_code2)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
     $sql = "UPDATE ".TB_PREF."chart_master SET account_name=".db_escape($account_name)
     .",account_type=".db_escape($account_type).", account_code2=".db_escape($account_code2)
                ." WHERE account_code = ".db_escape($account_code);
 
-       return db_query($sql);
+       $result = db_query($sql);
+
+       commit_transaction();
+       return $result;
 }
 
 function delete_gl_account($code)
 {
-       $sql = "DELETE FROM ".TB_PREF."chart_master WHERE account_code=".db_escape($code);
+       begin_transaction(__FUNCTION__, func_get_args());
 
+       $sql = "DELETE FROM ".TB_PREF."chart_master WHERE account_code=".db_escape($code);
        db_query($sql, "could not delete gl account");
+
+       commit_transaction();
 }
 
 function get_gl_accounts($from=null, $to=null, $type=null)
index ea9a83ac08ce06ca699cfe2a49c97185f335cf15..01feb5d1f165f5230858df4ec889940ee72851ca 100644 (file)
@@ -20,6 +20,7 @@ function add_bank_account($account_code, $account_type, $bank_account_name,
        $bank_name, $bank_account_number, $bank_address, $bank_curr_code, 
        $dflt_curr_act, $bank_charge_act)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        if($dflt_curr_act)      // only one default account for any currency
          clear_dflt_curr_account($bank_curr_code);
 
@@ -32,6 +33,9 @@ function add_bank_account($account_code, $account_type, $bank_account_name,
                ", ".db_escape($bank_curr_code).", ".db_escape($dflt_curr_act).", ".db_escape($bank_charge_act).")";
 
        db_query($sql, "could not add a bank account for $account_code");
+       $result =  db_insert_id();
+       commit_transaction();
+       return $result;
 }
 
 //---------------------------------------------------------------------------------------------
@@ -39,6 +43,8 @@ function add_bank_account($account_code, $account_type, $bank_account_name,
 function update_bank_account($id, $account_code, $account_type, $bank_account_name, 
        $bank_name, $bank_account_number, $bank_address, $bank_curr_code, $dflt_curr_act, $bank_charge_act)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        if($dflt_curr_act)      // only one default account for any currency
          clear_dflt_curr_account($bank_curr_code);
 
@@ -51,15 +57,19 @@ function update_bank_account($id, $account_code, $account_type, $bank_account_na
                WHERE id = ".db_escape($id);
 
        db_query($sql, "could not update bank account for $account_code");
+
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
 
 function delete_bank_account($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "DELETE FROM ".TB_PREF."bank_accounts WHERE id=".db_escape($id);
 
        db_query($sql,"could not delete bank account for $id");
+       commit_transaction();
 }
 
 
@@ -117,38 +127,49 @@ function get_bank_charge_account($id)
 
 function add_quick_entry($description, $type, $base_amount, $base_desc, $bal_type, $usage)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."quick_entries (description, type, base_amount, base_desc, bal_type, `usage`) 
        VALUES (".db_escape($description).", ".db_escape($type).", "
                .db_escape($base_amount).", ".db_escape($base_desc).", ".db_escape($bal_type).", ".db_escape($usage).")";
 
        db_query($sql, "could not insert quick entry for $description");
+
+       $result = db_insert_id();
+       commit_transaction();
+       return $result;
 }
 
 //---------------------------------------------------------------------------------------------
 
 function update_quick_entry($selected_id, $description, $type, $base_amount, $base_desc, $bal_type, $usage)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."quick_entries SET description = ".db_escape($description).",
                type=".db_escape($type).", base_amount=".db_escape($base_amount)
                .", base_desc=".db_escape($base_desc).", bal_type=".db_escape($bal_type).", `usage`=".db_escape($usage)."
                WHERE id = ".db_escape($selected_id);
 
        db_query($sql, "could not update quick entry for $selected_id");
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
 
 function delete_quick_entry($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "DELETE FROM ".TB_PREF."quick_entries WHERE id=".db_escape($selected_id);
 
        db_query($sql,"could not delete quick entry $selected_id");
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
 
 function add_quick_entry_line($qid, $action, $dest_id, $amount, $dim, $dim2, $memo)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."quick_entry_lines 
                (qid, action, dest_id, amount, dimension_id, dimension2_id, memo) 
        VALUES 
@@ -156,12 +177,16 @@ function add_quick_entry_line($qid, $action, $dest_id, $amount, $dim, $dim2, $me
                        ".db_escape($amount).", ".db_escape($dim).", ".db_escape($dim2).", ".db_escape($memo).")";
 
        db_query($sql, "could not insert quick entry line for $qid");
+
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
 
 function update_quick_entry_line($selected_id, $qid, $action, $dest_id, $amount, $dim, $dim2, $memo)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."quick_entry_lines SET qid = ".db_escape($qid)
                .", action=".db_escape($action).",
                dest_id=".db_escape($dest_id).", amount=".db_escape($amount)
@@ -169,15 +194,20 @@ function update_quick_entry_line($selected_id, $qid, $action, $dest_id, $amount,
                WHERE id = ".db_escape($selected_id);
 
        db_query($sql, "could not update quick entry line for $selected_id");
+
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
 
 function delete_quick_entry_line($selected_id)
 {
-       $sql = "DELETE FROM ".TB_PREF."quick_entry_lines WHERE id=".db_escape($selected_id);
+       begin_transaction(__FUNCTION__, func_get_args());
 
+       $sql = "DELETE FROM ".TB_PREF."quick_entry_lines WHERE id=".db_escape($selected_id);
        db_query($sql,"could not delete quick entry line $selected_id");
+
+       commit_transaction();
 }
 //---------------------------------------------------------------------------------------------
 
@@ -293,6 +323,8 @@ function get_sql_for_bank_account_reconcile($bank_account, $date)
 
 function update_reconciled_values($reconcile_id, $reconcile_value, $reconcile_date, $end_balance, $bank_account)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."bank_trans SET reconciled=$reconcile_value"
                ." WHERE id=".db_escape($reconcile_id);
 
@@ -304,6 +336,8 @@ function update_reconciled_values($reconcile_id, $reconcile_value, $reconcile_da
                        WHERE id=".db_escape($bank_account);
 
        db_query($sql2,"Error updating reconciliation information");
+
+       commit_transaction();
 }
 //---------------------------------------------------------------------------------------------
 
index 747041b614a542fa4a67dcbe970d1530dd55cc0a..e8d8190552051b7b6bf51e698245de56f014cb72 100644 (file)
@@ -140,7 +140,7 @@ function void_bank_trans($type, $type_no, $nested=false)
 {
 
        if (!$nested)
-               begin_transaction();
+               begin_transaction(__FUNCTION__, func_get_args());
 
        $sql = "UPDATE ".TB_PREF."bank_trans 
                        SET amount=0
index 7817fe3f8b12e3c391172ee6a1c692fc0307c2cc..03623b6e3ec1233890aaa85c2619e2f538a4ddf9 100644 (file)
@@ -135,7 +135,9 @@ function get_account_home_balance($person_id, $person_type, $rec_account, $to_da
 function add_exchange_variation_all($date=null, $ref="", $memo)
 {
        global $Refs;
-       begin_transaction();
+
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $exchanged = false;
        $trans_no = get_next_trans_no(ST_JOURNAL);
        $sql = "SELECT * FROM ".TB_PREF."bank_accounts";
@@ -209,7 +211,8 @@ function add_bank_transfer($from_account, $to_account, $date_,
 {
        global $Refs, $SysPrefs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $args = func_get_args(); if (count($args) < 8) $args[] = 0;
        $args = (object)array_combine(array('from_account', 'to_account', 'date_', 'amount',
                'ref', 'memo_', 'charge', 'target_amount'), $args);
@@ -353,7 +356,7 @@ function update_bank_transfer(
        $trans_no, $from_account, $to_account, $date_,
        $amount, $ref, $memo_, $charge=0, $target_amount=0)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        delete_comments(ST_BANKTRANSFER, $trans_no);
        void_transaction(ST_BANKTRANSFER, $trans_no, Today(), _("Document reentered."));
        void_gl_trans(ST_BANKTRANSFER, $trans_no, true);
@@ -393,9 +396,8 @@ function write_bank_transaction(&$cart)
        $do_exchange_variance = false;
        $exchanged = false;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, $args = func_get_args());
 
-       $args = func_get_args();
        hook_db_prewrite($args, $trans_type);
 
        $aid = 0;
index 0efa42076564cf2773919ae73a172399e70a77a8..b725c11318e2dec7300ad6247cdacbc91c89574e 100644 (file)
@@ -14,6 +14,7 @@
 function update_currency($curr_abrev, $symbol, $currency, $country, 
        $hundreds_name, $auto_update)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."currencies SET currency=".db_escape($currency)
                .", curr_symbol=".db_escape($symbol).", country=".db_escape($country)
                .", hundreds_name=".db_escape($hundreds_name)
@@ -21,6 +22,7 @@ function update_currency($curr_abrev, $symbol, $currency, $country,
                        ." WHERE curr_abrev = ".db_escape($curr_abrev);
 
        db_query($sql, "could not update currency for $curr_abrev");
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
@@ -28,6 +30,8 @@ function update_currency($curr_abrev, $symbol, $currency, $country,
 function add_currency($curr_abrev, $symbol, $currency, $country, 
        $hundreds_name, $auto_update)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."currencies (curr_abrev, curr_symbol, currency, 
                        country, hundreds_name, auto_update)
                VALUES (".db_escape($curr_abrev).", ".db_escape($symbol).", "
@@ -35,17 +39,25 @@ function add_currency($curr_abrev, $symbol, $currency, $country,
                .db_escape($hundreds_name).",".db_escape($auto_update).")";
 
        db_query($sql, "could not add currency for $curr_abrev");
+
+       $result = db_insert_id();
+       commit_transaction();
+       return $result;
 }
 
 //---------------------------------------------------------------------------------------------
 
 function delete_currency($curr_code)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql="DELETE FROM ".TB_PREF."currencies WHERE curr_abrev=".db_escape($curr_code);
        db_query($sql, "could not delete currency       $curr_code");
 
        $sql="DELETE FROM ".TB_PREF."exchange_rates WHERE curr_code='$curr_code'";
        db_query($sql, "could not delete exchange rates for currency $curr_code");
+
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
index 4118492ef7e7cdd7e56e4323954e2aa95942eab5..924587d8ab9da210f814e004d718732e79837c50 100644 (file)
@@ -63,12 +63,16 @@ function update_exchange_rate($curr_code, $date_, $buy_rate, $sell_rate)
        if (is_company_currency($curr_code))
                display_db_error("Exchange rates cannot be set for company currency", "", true);
                        
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $date = date2sql($date_);
                
        $sql = "UPDATE ".TB_PREF."exchange_rates SET rate_buy=$buy_rate, rate_sell=".db_escape($sell_rate)
        ." WHERE curr_code=".db_escape($curr_code)." AND date_='$date'";
                                
        db_query($sql, "could not add exchange rate for $curr_code");
+
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
@@ -78,12 +82,14 @@ function add_exchange_rate($curr_code, $date_, $buy_rate, $sell_rate)
        if (is_company_currency($curr_code))
                display_db_error("Exchange rates cannot be set for company currency", "", true);
 
+       begin_transaction(__FUNCTION__, func_get_args());
        $date = date2sql($date_);
                
        $sql = "INSERT INTO ".TB_PREF."exchange_rates (curr_code, date_, rate_buy, rate_sell)
                VALUES (".db_escape($curr_code).", '$date', ".db_escape($buy_rate)
                .", ".db_escape($sell_rate).")";
        db_query($sql, "could not add exchange rate for $curr_code");
+       commit_transaction();
 }
 
 //---------------------------------------------------------------------------------------------
@@ -101,8 +107,12 @@ function add_new_exchange_rate($curr_code, $date_, $ex_rate)
 
 function delete_exchange_rate($rate_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "DELETE FROM ".TB_PREF."exchange_rates WHERE id=".db_escape($rate_id);
        db_query($sql, "could not delete exchange rate $rate_id");
+
+       commit_transaction();
 }
 
 //-----------------------------------------------------------------------------
index 15e2c84a36f2f023e46454b2d84e8dd16bd89c2d..98c2e896c36351aff0969ee94de969d6469430af 100644 (file)
@@ -11,7 +11,7 @@
 ***********************************************************************/
 //--------------------------------------------------------------------------------
 
-// Base function for adding a GL transaction
+// Base function for adding a GL transaction line
 // $date_ is display date (non-sql)
 // $amount is in $currency currency
 // if $currency is not set, then defaults to no conversion
@@ -378,6 +378,8 @@ function exists_gl_budget($date_, $account, $dimension, $dimension2)
 
 function add_update_gl_budget_trans($date_, $account, $dimension, $dimension2, $amount)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $date = date2sql($date_);
 
        if (exists_gl_budget($date, $account, $dimension, $dimension2))
@@ -393,10 +395,14 @@ function add_update_gl_budget_trans($date_, $account, $dimension, $dimension2, $
                        .db_escape($dimension2).", ".db_escape($amount).", '')";
 
        db_query($sql, "The GL budget transaction could not be saved");
+
+       commit_transaction();
 }
 
 function delete_gl_budget_trans($date_, $account, $dimension, $dimension2)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $date = date2sql($date_);
 
        $sql = "DELETE FROM ".TB_PREF."budget_trans WHERE account=".db_escape($account)
@@ -404,6 +410,8 @@ function delete_gl_budget_trans($date_, $account, $dimension, $dimension2)
        ." AND dimension2_id=".db_escape($dimension2)
        ." AND tran_date='$date'";
        db_query($sql, "The GL budget transaction could not be deleted");
+
+       commit_transaction();
 }
 
 function get_only_budget_trans_from_to($from_date, $to_date, $account, $dimension=0, $dimension2=0)
@@ -593,20 +601,6 @@ function void_gl_trans($type, $trans_id, $nested=false)
 
 //----------------------------------------------------------------------------------------
 
-function clear_gl_trans($type, $trans_id, $nested=false)
-{
-       if (!$nested)
-               begin_transaction();
-
-       $sql = "DELETE FROM ".TB_PREF."gl_trans WHERE type=".db_escape($type)
-       ." AND type_no=".db_escape($trans_id);
-
-       db_query($sql, "could not clear gl transactions for type=$type and trans_no=$trans_id");
-
-       if (!$nested)
-               commit_transaction();
-}
-
 function get_sql_for_journal_inquiry($filter, $from, $to, $ref='', $memo='', $alsoclosed=false,
          $user_id=null)
 {
index b3378b0ce5f3cae9e7a51b860d0de3e5ad76a3a4..d35024b9a9e518d992ec43b2bb0e6736fdfdd504 100644 (file)
@@ -107,7 +107,7 @@ function write_journal_entries(&$cart)
        $trans_type = $cart->trans_type;
        $new = $cart->order_id == 0;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        if (!$new)
        {
@@ -146,10 +146,9 @@ function write_journal_entries(&$cart)
 
 //----------------------------------------------------------------------------------------
 
-function void_journal_trans($type, $type_no, $use_transaction=true)
+function void_journal_trans($type, $type_no)
 {
-       if ($use_transaction)
-               begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $sql = "UPDATE ".TB_PREF."journal SET amount=0
                WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
@@ -158,7 +157,6 @@ function void_journal_trans($type, $type_no, $use_transaction=true)
 
        void_bank_trans($type, $type_no, true);
 
-       if ($use_transaction)
-               commit_transaction();
+       commit_transaction();
 }
 
index 951af9ee9832214c4666e36b9038b3d810e85473..7a9c49002b7198914918fa9ab7dbf90b166fdddb 100644 (file)
@@ -24,7 +24,7 @@ include_once($path_to_root . "/gl/includes/db/gl_db_account_types.inc");
 
 function add_budget($account, $dim1, $dim2, $amounts)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        foreach($amounts as $date => $amount) {
                add_update_gl_budget_trans($date, $account, $dim1, $dim2, $amount);
@@ -34,7 +34,7 @@ function add_budget($account, $dim1, $dim2, $amounts)
 
 function delete_budget($account, $dim1, $dim2, $dates)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        foreach($amounts as $date) {
                delete_gl_budget_trans($date, $account, $dim1, $dim2);
index ae8860da624e0ffc7e9661a9694306b42a7765a6..0a6b45545470989f68634cec8fb16891bd13940a 100644 (file)
@@ -79,6 +79,7 @@ function display_order_header(&$Order)
        }
 
        check_row(_('Include in tax register:'), 'taxable_trans', null, true);
+
         // Query the user to retain the reconciled status
     if (!$new && $Order->reconcile_date) {
        check_row(_('Reconciled:'), 'reconciled', 1, true);
index c3d162e037e1d440175cfd6f6118f0a6c2b01d46..5d4d5f0e3282b3da3e4235949765154cbb5270f9 100644 (file)
@@ -59,7 +59,7 @@ class current_user
 
        function login($company, $loginname, $password)
        {
-               global $security_areas, $security_groups, $security_headings, $path_to_root, $dflt_lang, $SysPrefs;
+               global $security_areas, $security_groups, $security_headings, $path_to_root, $dflt_lang, $SysPrefs, $src_version, $db_version, $installed_extensions;
 
                $this->set_company($company);
            $this->logged = false;
@@ -132,7 +132,7 @@ class current_user
                    $this->prefs = new user_prefs($myrow);
                    $this->user = @$myrow["id"];
                 $this->email = @$myrow["email"];
-                       update_user_visitdate($this->username);
+                       update_user_visitdate($this->username, $src_version, $db_version, $installed_extensions);
                        $this->logged = true;
                                $this->last_act = time();
                                $this->timeout = session_timeout();
index c142abdb9fbad020fb1ccaa1e5dce447d15552ce..e297d2ba1f54d7983e27b9446c7a708dfbc8e0fe 100644 (file)
@@ -13,7 +13,7 @@
 function add_audit_trail($trans_type, $trans_no, $trans_date, $descr='')
 {
        $descr = substr($descr, 0, 60);
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $date = date2sql($trans_date);
        $sql = "INSERT INTO ".TB_PREF."audit_trail"
@@ -63,7 +63,7 @@ function get_audit_trail_last($trans_type, $trans_no)
 */
 function close_transactions($todate) {
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $errors = 0;
        // select only those audit trail records which produce any GL postings
index 277ebe74dbe2f8dce456f6fc8d0adf9510d9bfff..413d2983fa443b30aeb2b7e8c3388f57a9c1625e 100644 (file)
@@ -167,6 +167,8 @@ class reflines_db extends data_set {
 
        function save_next($type, $reference, $line=null)
        {
+               begin_transaction(__CLASS__.':'.__METHOD__, func_get_args());
+
            $sql = "UPDATE ".TB_PREF."reflines SET pattern=SUBSTRING(" . db_escape(trim($reference)) .", LENGTH(`prefix`)+1)"
                . " WHERE trans_type = ".db_escape($type)." AND ";
 
@@ -175,6 +177,8 @@ class reflines_db extends data_set {
                else
                        $sql .= "`default`";
 
-               return db_query($sql, "The next transaction ref for $type could not be updated");
+               $result = db_query($sql, "The next transaction ref for $type could not be updated");
+               commit_transaction();
+               return $result;
        }
 }
index 4be5a295e5481a280d2dd1d6611e18eb4c497de3..4acf3e4776a071f2c816055645f0c385e7075fab 100644 (file)
@@ -71,18 +71,10 @@ function db_query($sql, $err_msg=null)
                        $retry = 0;
        } while ($retry);
 
-       db_profile($sql);
+       if($SysPrefs->db_trail == 1)
+               $db_last_inserted_id = mysql_insert_id($db);    // cache to avoid trail overwrite
 
-       if($SysPrefs->sql_trail) {
-               $db_last_inserted_id = mysql_insert_id($db);    // preserve in case trail insert is done
-               if ($SysPrefs->select_trail || (strstr($sql, 'SELECT') === false)) {
-                       mysql_query(
-                       "INSERT INTO ".$cur_prefix."sql_trail
-                               (`sql`, `result`, `msg`)
-                               VALUES(".db_escape($sql).",".($result ? 1 : 0).",
-                               ".db_escape($err_msg).")", $db);
-               }
-       }
+       db_profile($sql);
 
        if ($err_msg != null || $SysPrefs->go_debug) {
                $exit = $err_msg != null;
@@ -176,7 +168,7 @@ function db_insert_id()
 {
        global $db_last_inserted_id, $SysPrefs, $db;
 
-       return $SysPrefs->sql_trail ? $db_last_inserted_id : mysql_insert_id($db);
+       return $SysPrefs->db_trail == 1 ? $db_last_inserted_id : mysql_insert_id($db);
 }
 
 function db_num_affected_rows()
index 696fd8285a1646bc49aa406a41ff8ae4e7a32923..ee7ad583b8108f5411311e6af28134f8577b6275 100644 (file)
@@ -72,17 +72,10 @@ function db_query($sql, $err_msg=null)
                        $retry = 0;
        } while ($retry);
 
-       db_profile($sql);
+       if($SysPrefs->db_trail == 1)
+               $db_last_inserted_id = mysqli_insert_id($db);   // cache to avoid trail overwrite
 
-       if($SysPrefs->sql_trail) {
-               $db_last_inserted_id = mysqli_insert_id($db);   // preserve in case trail insert is done
-               if ($SysPrefs->select_trail || (strstr($sql, 'SELECT') === false)) {
-                       mysqli_query($db, "INSERT INTO ".$cur_prefix."sql_trail
-                               (`sql`, `result`, `msg`)
-                               VALUES(".db_escape($sql).",".($result ? 1 : 0).",
-                               ".db_escape($err_msg).")");
-               }
-       }
+       db_profile($sql);
 
        if ($err_msg != null || $SysPrefs->go_debug) {
                $exit = $err_msg != null;
@@ -174,7 +167,7 @@ function db_insert_id()
 {
        global $db_last_inserted_id, $SysPrefs, $db;
 
-       return $SysPrefs->sql_trail ? $db_last_inserted_id : mysqli_insert_id($db);
+       return $SysPrefs->db_trail == 1 ? $db_last_inserted_id : mysqli_insert_id($db);
 }
 
 function db_num_affected_rows()
index e5a91fb1be4561bbca0c811b37074ab15ef63402..463a3fde1cf25a59351332eb70995a468a356547 100644 (file)
@@ -13,6 +13,7 @@
 function add_crm_person($ref, $name, $name2, $address, $phone, $phone2, $fax, $email, $lang, $notes,
        $cat_ids=null, $entity=null)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."crm_persons (ref, name, name2, address,
                phone, phone2, fax, email, lang, notes)
                VALUES ("
@@ -27,10 +28,8 @@ function add_crm_person($ref, $name, $name2, $address, $phone, $phone2, $fax, $e
                  .db_escape($lang) . ", "
                  .db_escape($notes)
                .")";
-
-       begin_transaction();
-
        $ret = db_query($sql, "Can't insert crm person");
+
        $id = db_insert_id();
        if ($ret && $cat_ids) {
                if(!update_person_contacts($id, $cat_ids, $entity))
@@ -43,6 +42,8 @@ function add_crm_person($ref, $name, $name2, $address, $phone, $phone2, $fax, $e
 function update_crm_person($id, $ref, $name, $name2, $address, $phone, $phone2, $fax, $email, 
        $lang, $notes, $cat_ids, $entity=null, $type=null)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."crm_persons SET "
                  ."ref=".db_escape($ref) . ", "
                  ."name=".db_escape($name) . ", "
@@ -56,8 +57,6 @@ function update_crm_person($id, $ref, $name, $name2, $address, $phone, $phone2,
                  ."notes=".db_escape($notes)
                  ." WHERE id = ".db_escape($id);
 
-       begin_transaction();
-
        $ret = db_query($sql, "Can't update crm person");
        if ($ret) {
                if(!update_person_contacts($id, $cat_ids, $entity, $type))
@@ -69,7 +68,7 @@ function update_crm_person($id, $ref, $name, $name2, $address, $phone, $phone2,
 
 function delete_crm_person($person, $with_contacts=false)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        if ($with_contacts) {
                $sql = "DELETE FROM ".TB_PREF."crm_contacts WHERE person_id=".db_escape($person);
@@ -149,11 +148,12 @@ function get_person_contacts($id)
 
 function update_person_contacts($id, $cat_ids, $entity_id=null, $type=null)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "DELETE FROM ".TB_PREF."crm_contacts WHERE person_id=".db_escape($id);
        if ($type)
                $sql .= " AND type=".db_escape($type);
 
-       begin_transaction();
 
        $ret = db_query($sql, "Can't delete person contacts");
 
@@ -175,6 +175,8 @@ function update_person_contacts($id, $cat_ids, $entity_id=null, $type=null)
 
 function delete_entity_contacts($class, $entity)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        delete_crm_contacts(null, $class, $entity);
        // cleanup
        $res = get_crm_persons($class, null, $entity, null, true);
@@ -184,12 +186,16 @@ function delete_entity_contacts($class, $entity)
                        delete_crm_person($person['id']);
                }
        }
+
+       commit_transaction();
 }
 
 //-----------------------------------------------------------------------------------------------
 
 function add_crm_category($type, $action, $name, $description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."crm_categories (type, action, name, description)
                VALUES (".db_escape($type) . ", "
                  .db_escape($action) . ", "
@@ -197,10 +203,14 @@ function add_crm_category($type, $action, $name, $description)
                  .db_escape($description)
                .")";
        db_query($sql,"The insert of the crm category failed");
+
+       commit_transaction();
 }
 
 function update_crm_category($selected_id, $type, $action, $name, $description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "UPDATE ".TB_PREF."crm_categories SET ";
        if ($type)
                $sql .= "type=".db_escape($type) . ",";
@@ -210,13 +220,19 @@ function update_crm_category($selected_id, $type, $action, $name, $description)
                        ."description=".db_escape($description)
                        ." WHERE id = ".db_escape($selected_id);
        db_query($sql,"The update of the crm category failed");
+
+       commit_transaction();
 }
 
 function delete_crm_category($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        // preserve system categories
        $sql="DELETE FROM ".TB_PREF."crm_categories WHERE system=0 AND id=".db_escape($selected_id);
        db_query($sql,"could not delete crm category");
+
+       commit_transaction();
 }
 
 function get_crm_categories($show_inactive)
index 66a781d25d868c21286076411c8f559df3394ff4..3b4b5acd499511998fd0ef9ba80c8d6a10d355d7 100644 (file)
 // Multilevel transaction control.
 //
 $transaction_level = 0;
+$transaction_data = null;
 
-function begin_transaction()
+function begin_transaction($func=null, $args=null)
 {
-       global $transaction_level;
+       global $transaction_level, $transaction_data, $SysPrefs;
 
        if (!$transaction_level) {
+               if ($SysPrefs->db_trail) {
+                       $bt = debug_backtrace();
+                       $user = $_SESSION["wa_current_user"]->user;
+                       $transaction_data = array(
+                               'user' => $_SESSION["wa_current_user"]->user,
+                               'msg'=> basename($bt[count($bt)-1]['file']).'@'.$bt[count($bt)-1]['line'], // call start point
+                               'entry' => $func,
+                               'data' => serialize($args),
+                       );
+               }
                db_query("BEGIN", "could not start a transaction");
        }
        $transaction_level++;
@@ -29,11 +40,22 @@ function begin_transaction()
 
 function commit_transaction()
 {
-       global $transaction_level;
+       global $transaction_level, $transaction_data, $SysPrefs, $db_last_inserted_id, $db;
 
        $transaction_level--;
 
        if (!$transaction_level) {
+               // FIXME: if logged to table remember to preserve last_insert_id!
+               if ($SysPrefs->db_trail == 1) {
+                       $last_insert = $db_last_inserted_id;
+                       $db_last_inserted_id = mysqli_insert_id($db);   // preserve in case trail insert is done
+                       $sql = "INSERT INTO ".TB_PREF."db_trail (user, msg, entry, data) VALUES ("
+                                       ."'".$transaction_data['user']."','".$transaction_data['msg']."','".$transaction_data['entry']."',"
+                                       .db_escape($transaction_data['data']).")";
+                       db_query($sql, 'cannot log user operation');
+                       $db_last_inserted_id = $last_insert;
+               } elseif ($SysPrefs->db_trail == 2)
+                       error_log($transaction_data['msg'].'|'.$transaction_data['user'].'|'.$transaction_data['entry'].'|'.$transaction_data['data']);
                db_query("COMMIT", "could not commit a transaction");
        }
 }
index 0085f98360b7b702b226bccd3421fc836ef3dc86..07137bf246f97593e344837a1de5733c7bb4f8c9 100644 (file)
@@ -14,7 +14,7 @@ function add_stock_adjustment($items, $location, $date_, $reference, $memo_)
 {
        global $SysPrefs, $path_to_root, $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args();
        $args = (object)array_combine(array('items', 'location', 'date_', 'reference', 'memo_'), $args);
        $args->trans_no = 0;
@@ -61,9 +61,11 @@ function add_stock_adjustment($items, $location, $date_, $reference, $memo_)
 
 function void_stock_adjustment($type_no)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid(ST_INVADJUST, $type_no);
        void_gl_trans(ST_INVADJUST, $type_no);
        void_stock_move(ST_INVADJUST, $type_no);
+       commit_transaction();
 }
 
 //-------------------------------------------------------------------------------------------------------------
index 48984bb665a9844c0724166efef9859bfc6071c2..78f7092dc910f1986ebdc4b8943ef55403a84151 100644 (file)
@@ -13,6 +13,7 @@ function add_item_category($description, $tax_type_id, $sales_account,
        $cogs_account, $inventory_account, $adjustment_account, $wip_account, 
        $units, $mb_flag, $dim1, $dim2, $no_sale, $no_purchase, $vat_category)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."stock_category (description, dflt_tax_type,
                        dflt_units, dflt_mb_flag, dflt_sales_act, dflt_cogs_act, 
                        dflt_inventory_act, dflt_adjustment_act, dflt_wip_act, 
@@ -34,6 +35,7 @@ function add_item_category($description, $tax_type_id, $sales_account,
                .db_escape($vat_category).")";
 
        db_query($sql,"an item category could not be added");
+       commit_transaction();
 }
 
 function update_item_category($id, $description, $tax_type_id, 
@@ -41,6 +43,7 @@ function update_item_category($id, $description, $tax_type_id,
        $wip_account, $units, $mb_flag, $dim1, $dim2, $no_sale, $no_purchase, $vat_category)
 
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."stock_category SET "
                ."description = ".db_escape($description).","
                ."dflt_tax_type = ".db_escape($tax_type_id).","
@@ -59,13 +62,16 @@ function update_item_category($id, $description, $tax_type_id,
         ."WHERE category_id = ".db_escape($id);
 
        db_query($sql,"an item category could not be updated");
+       commit_transaction();
 }
 
 function delete_item_category($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."stock_category WHERE category_id=".db_escape($id);
 
        db_query($sql,"an item category could not be deleted");
+       commit_transaction();
 }
 
 function get_item_categories($show_inactive, $fixed_asset=false)
index 57ddf3162d33b562d558318e12e023fb79bd9a4b..59859003b8f9908e6d1484ddebdab708d049b3ec 100644 (file)
@@ -16,6 +16,7 @@ function update_item($stock_id, $description, $long_description, $category_id,
        $depreciation_method = 'D', $depreciation_rate=100, $depreciation_factor=1,
        $depreciation_start=null, $fa_class_id=null, $vat_category='', $shipper_id=0)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).",
                description=".db_escape($description).",
                category_id=".db_escape($category_id).",
@@ -55,6 +56,7 @@ function update_item($stock_id, $description, $long_description, $category_id,
        db_query($sql, "The item could not be updated");
 
        update_item_code(-1, $stock_id, $stock_id, $description, $category_id, 1, 0);
+       commit_transaction();
 }
 
 function add_item($stock_id, $description, $long_description, $category_id, 
@@ -64,6 +66,7 @@ function add_item($stock_id, $description, $long_description, $category_id,
        $depreciation_method='D', $depreciation_rate=100,  $depreciation_factor=1, $depreciation_start=null,
        $fa_class_id=null, $vat_category=0, $shipper_id=0)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."stock_master (stock_id, description, long_description, category_id,
                tax_type_id, units, mb_flag, sales_account, inventory_account, cogs_account,
                adjustment_account, wip_account, dimension_id, dimension2_id, no_sale, no_purchase, editable, vat_category,
@@ -92,10 +95,12 @@ function add_item($stock_id, $description, $long_description, $category_id,
        db_query($sql, "The item locstock could not be added");
 
        add_item_code($stock_id, $stock_id, $description, $category_id, 1, 0);
+       commit_transaction();
 }
 
 function delete_item($stock_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id);
        db_query($sql, "could not delete stock item");
 
@@ -116,6 +121,7 @@ function delete_item($stock_id)
        db_query($sql, "could not delete stock item bom");
 
        delete_item_kit($stock_id);
+       commit_transaction();
 }
 
 function get_item($stock_id)
index e85d39a1ce97164f5379d37574e2b3220b04b684..9fd54b62bd1d1e802d94884325c61635c64288e6 100644 (file)
@@ -11,6 +11,7 @@
 ***********************************************************************/
 function add_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact, $fixed_asset = 0)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."locations (loc_code, location_name, delivery_address, phone, phone2, fax, email, contact, fixed_asset)
                VALUES (".db_escape($loc_code).", ".db_escape($location_name).", ".db_escape($delivery_address).", "
                        .db_escape($phone).", ".db_escape($phone2).", ".db_escape($fax).", ".db_escape($email).", "
@@ -23,6 +24,7 @@ function add_item_location($loc_code, $location_name, $delivery_address, $phone,
                SELECT ".db_escape($loc_code).", ".TB_PREF."stock_master.stock_id, 0 FROM ".TB_PREF."stock_master";
 
        db_query($sql,"a location could not be added");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
@@ -30,6 +32,7 @@ function add_item_location($loc_code, $location_name, $delivery_address, $phone,
 function update_item_location($loc_code, $location_name, $delivery_address, $phone, $phone2, $fax, $email, $contact, $fixed_asset = 0)
 
 {
+       begin_transaction(__FUNCTION__, func_get_args());
     $sql = "UPDATE ".TB_PREF."locations SET location_name=".db_escape($location_name).",
        delivery_address=".db_escape($delivery_address).",
        phone=".db_escape($phone).", phone2=".db_escape($phone2).", fax=".db_escape($fax).",
@@ -38,17 +41,20 @@ function update_item_location($loc_code, $location_name, $delivery_address, $pho
        WHERE loc_code = ".db_escape($loc_code);
 
        db_query($sql,"a location could not be updated");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
 
 function delete_item_location($item_location)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."locations WHERE loc_code=".db_escape($item_location);
        db_query($sql,"a location could not be deleted");
 
        $sql = "DELETE FROM ".TB_PREF."loc_stock WHERE loc_code =".db_escape($item_location);
        db_query($sql,"a location could not be deleted");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
@@ -75,10 +81,12 @@ function get_item_locations($show_inactive, $fixed_asset = 0)
 
 function set_reorder_level($stock_id, $loc_code, $reorder_level)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."loc_stock SET reorder_level = $reorder_level
                WHERE stock_id = ".db_escape($stock_id)." AND loc_code = ".db_escape($loc_code);
 
        db_query($sql,"an item reorder could not be set");
+       commit_transaction();
 }
 
 //------------------------------------------------------------------------------------
index 5a474e7c1bbcec34d67e4a117eaf8a64ddbd0afe..5fee90e7c7f47d872e8d86aafdc7452543f0fcc0 100644 (file)
 ***********************************************************************/
 function add_item_price($stock_id, $sales_type_id, $curr_abrev, $price)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."prices (stock_id, sales_type_id, curr_abrev, price) 
                VALUES (".db_escape($stock_id).", ".db_escape($sales_type_id)
                .", ".db_escape($curr_abrev).", ".db_escape($price).")";
 
        db_query($sql,"an item price could not be added");
+       commit_transaction();
 }
 
 function update_item_price($price_id, $sales_type_id, $curr_abrev, $price)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."prices SET sales_type_id=".db_escape($sales_type_id).", 
                curr_abrev=".db_escape($curr_abrev).", 
                price=".db_escape($price)." WHERE id=".db_escape($price_id);
 
        db_query($sql,"an item price could not be updated");
+       commit_transaction();
 }
 
 function delete_item_price($price_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."prices WHERE id= ".db_escape($price_id);
        db_query($sql,"an item price could not be deleted");
+       commit_transaction();
 }
 
 function get_prices($stock_id)
index eecd91239de1df8c9805419fa92c78495976c601..2e3a5e354c7fb3f8d2a567f9f9a4414150f664bf 100644 (file)
@@ -13,6 +13,7 @@
 function add_item_purchasing_data($supplier_id, $stock_id, $price,
        $suppliers_uom, $conversion_factor, $supplier_description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
                conversion_factor, supplier_description) VALUES (";
        $sql .= db_escape($supplier_id).", ".db_escape($stock_id). ", "
@@ -21,11 +22,13 @@ function add_item_purchasing_data($supplier_id, $stock_id, $price,
                .db_escape($supplier_description) . ")";
 
        db_query($sql,"The supplier purchasing details could not be added");
+       commit_transaction();
 }
 
 function update_item_purchasing_data($selected_id, $stock_id, $price,
        $suppliers_uom, $conversion_factor, $supplier_description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."purch_data SET price=" . $price . ",
                suppliers_uom=".db_escape($suppliers_uom) . ",
                conversion_factor=" . $conversion_factor . ",
@@ -33,13 +36,16 @@ function update_item_purchasing_data($selected_id, $stock_id, $price,
                WHERE stock_id=".db_escape($stock_id) . " AND
                supplier_id=".db_escape($selected_id);
        db_query($sql,"The supplier purchasing details could not be updated");
+       commit_transaction();
 }
 
 function delete_item_purchasing_data($selected_id, $stock_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "DELETE FROM ".TB_PREF."purch_data WHERE supplier_id=".db_escape($selected_id)."
                AND stock_id=".db_escape($stock_id);
        db_query($sql,"could not delete purchasing data");
+       commit_transaction();
 }
 
 function get_items_purchasing_data($stock_id)
diff --git a/inventory/includes/db/items_trans_db.inc b/inventory/includes/db/items_trans_db.inc
deleted file mode 100644 (file)
index dfbc5ee..0000000
+++ /dev/null
@@ -1,81 +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>.
-***********************************************************************/
-//-------------------------------------------------------------------------------------------------------------
-
-function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_cost,
-       $last_cost, $refline, $memo_)
-{
-       $mb_flag = get_mb_flag($stock_id);
-
-       $update_no = -1;
-
-    if (is_service($mb_flag))
-    {
-               $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
-               WHERE stock_id=".db_escape($stock_id);
-
-               db_query($sql,"The cost details for the inventory item could not be updated");
-
-               return $update_no;
-    }
-
-       begin_transaction();
-
-       $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost).", 
-               labour_cost=".db_escape($labour_cost).",
-               overhead_cost=".db_escape($overhead_cost)."
-               WHERE stock_id=".db_escape($stock_id);
-       db_query($sql,"The cost details for the inventory item could not be updated");
-
-       $qoh = get_qoh_on_date($stock_id);
-
-       $date_ = Today();
-       if (!is_date_in_fiscalyear($date_))
-               $date_ = end_fiscalyear();
-
-       if ($qoh > 0)
-       {
-               $new_cost = $material_cost + $labour_cost + $overhead_cost;
-
-               $value_of_change = round2($qoh * ($new_cost - $last_cost), user_price_dec());
-
-               if ($value_of_change != 0)
-               {
-                       global $Refs;
-                       $stock_gl_code = get_stock_gl_code($stock_id);
-
-                       $cart = new items_cart(ST_COSTUPDATE);
-                       $cart->tran_date = $cart->doc_date = $cart->event_date = $date_;
-                       if (!is_date_in_fiscalyear($cart->tran_date))
-                               $cart->tran_date = end_fiscalyear();
-                       $cart->reference = $Refs->get_next(ST_COSTUPDATE, $refline, $cart->tran_date, $date_);
-                       if (empty($memo_))
-                               $cart->memo_ = sprintf(_("Cost was %s changed to %s x quantity on hand of %s"),
-                                       number_format2($last_cost, 2), number_format2($new_cost), $qoh);
-                       else
-                               $cart->memo_ = $memo_;
-
-                       $cart->add_gl_item($stock_gl_code["adjustment_account"],
-                               $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], -$value_of_change);
-                       $cart->add_gl_item($stock_gl_code["inventory_account"], 0, 0, $value_of_change);
-
-                       write_journal_entries($cart);
-               }
-       }
-
-       if ($update_no != -1)
-               add_audit_trail(ST_COSTUPDATE, $update_no, $date_);
-       commit_transaction();
-
-       return $update_no;
-}
index f35bf3696c43439ca0bfcb6c26ba574a960e2a04..b4b0180e0ecfaa1ab1ee25d5ae6d9a469fd65728 100644 (file)
@@ -15,7 +15,7 @@ function add_stock_transfer($Items, $location_from, $location_to, $date_, $refer
 {
        global $SysPrefs, $path_to_root, $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args();
        $args = (object)array_combine(array('Items', 'location_from', 'location_to', 
        'date_', 'reference', 'memo_'), $args);
@@ -118,7 +118,9 @@ function get_stock_transfer_items($trans_no)
 
 function void_stock_transfer($type_no)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid(ST_LOCTRANSFER, $type_no);
        void_stock_move(ST_LOCTRANSFER, $type_no);
+       commit_transaction();
 }
 
index d90b03b39e18944493aa4819da6826d756e49cb2..ee9f17464cfc363330d0832a6bb7a4bebc766e50 100644 (file)
@@ -11,6 +11,8 @@
 ***********************************************************************/
 function write_item_unit($selected, $abbr, $description, $decimals)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
     if($selected!='')
                $sql = "UPDATE ".TB_PREF."item_units SET
                abbr = ".db_escape($abbr).",
@@ -23,13 +25,16 @@ function write_item_unit($selected, $abbr, $description, $decimals)
                        ".db_escape($description).", ".db_escape($decimals).")";
 
        db_query($sql,"an item unit could not be updated");
+       commit_transaction();
 }
 
 function delete_item_unit($unit)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."item_units WHERE abbr=".db_escape($unit);
 
        db_query($sql,"an unit of measure could not be deleted");
+       commit_transaction();
 }
 
 function get_item_unit($unit)
index 7b672fae8a3609d517ab1d659e9988b4e3e0bb6d..25e60d3662f00be49dadb07188e116d2be578b5a 100644 (file)
@@ -14,7 +14,6 @@ include_once($path_to_root . "/includes/banking.inc");
 include_once($path_to_root . "/includes/inventory.inc");
 
 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
-include_once($path_to_root . "/inventory/includes/db/items_trans_db.inc");
 include_once($path_to_root . "/inventory/includes/db/items_prices_db.inc");
 include_once($path_to_root . "/inventory/includes/db/items_purchases_db.inc");
 include_once($path_to_root . "/inventory/includes/db/items_codes_db.inc");
@@ -106,3 +105,98 @@ function send_reorder_email($loc, $st_ids, $st_names, $st_num, $st_reorder)
        $mail->text($msg);
        return $mail->send();
 }
+
+//----------------------------------------- Backend interfaces ----------------------------------------------------
+
+function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_cost,
+       $last_cost, $refline, $memo_)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+
+       $mb_flag = get_mb_flag($stock_id);
+
+       $update_no = -1;
+
+    if (is_service($mb_flag))
+    {
+               $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
+               WHERE stock_id=".db_escape($stock_id);
+
+               db_query($sql,"The cost details for the inventory item could not be updated");
+
+               commit_transaction();
+               return $update_no;
+    }
+
+       $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost).", 
+               labour_cost=".db_escape($labour_cost).",
+               overhead_cost=".db_escape($overhead_cost)."
+               WHERE stock_id=".db_escape($stock_id);
+       db_query($sql,"The cost details for the inventory item could not be updated");
+
+       $qoh = get_qoh_on_date($stock_id);
+
+       $date_ = Today();
+       if (!is_date_in_fiscalyear($date_))
+               $date_ = end_fiscalyear();
+
+       if ($qoh > 0)
+       {
+               $new_cost = $material_cost + $labour_cost + $overhead_cost;
+
+               $value_of_change = round2($qoh * ($new_cost - $last_cost), user_price_dec());
+
+               if ($value_of_change != 0)
+               {
+                       global $Refs;
+                       $stock_gl_code = get_stock_gl_code($stock_id);
+
+                       $cart = new items_cart(ST_COSTUPDATE);
+                       $cart->tran_date = $cart->doc_date = $cart->event_date = $date_;
+                       if (!is_date_in_fiscalyear($cart->tran_date))
+                               $cart->tran_date = end_fiscalyear();
+                       $cart->reference = $Refs->get_next(ST_COSTUPDATE, $refline, $cart->tran_date, $date_);
+                       if (empty($memo_))
+                               $cart->memo_ = sprintf(_("Cost was %s changed to %s x quantity on hand of %s"),
+                                       number_format2($last_cost, 2), number_format2($new_cost), $qoh);
+                       else
+                               $cart->memo_ = $memo_;
+
+                       $cart->add_gl_item($stock_gl_code["adjustment_account"],
+                               $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], -$value_of_change);
+                       $cart->add_gl_item($stock_gl_code["inventory_account"], 0, 0, $value_of_change);
+
+                       write_journal_entries($cart);
+               }
+       }
+
+       if ($update_no != -1)
+               add_audit_trail(ST_COSTUPDATE, $update_no, $date_);
+
+       commit_transaction();
+       return $update_no;
+}
+
+function write_item($id, $NewStockID, $description, $long_description, $category_id, $tax_type_id, $units, 
+       $mb_flag, $sales_account, $inventory_account, $cogs_account, $adjustment_account, $wip_account, 
+       $dim1, $dim2, $no_sale, $editable, $no_purchase, $depreciation_method, $depreciation_rate, $depreciation_factor, $depreciation_start,
+       $fa_class_id, $vat_category, $shipper, $inactive)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+       if ($id != '')
+       {
+               update_item($NewStockID, $description, $long_description, $category_id, $tax_type_id, $units, 
+                       $mb_flag, $sales_account, $inventory_account, $cogs_account, $adjustment_account, $wip_account, 
+                       $dim1, $dim2, $no_sale, $editable, $no_purchase, $depreciation_method, $depreciation_rate, $depreciation_factor, $depreciation_start,
+                       $fa_class_id, $vat_category, $shipper);
+               update_record_status($NewStockID, $inactive, 'stock_master', 'stock_id');
+               update_record_status($NewStockID, $inactive, 'item_codes', 'item_code');
+       } else {
+               add_item($NewStockID, $description, $long_description, $category_id, $tax_type_id, $units, 
+                       $mb_flag, $sales_account, $inventory_account, $cogs_account, $adjustment_account, $wip_account, 
+                       $dim1, $dim2, $no_sale, $editable, $no_purchase, $depreciation_method, $depreciation_rate, $depreciation_factor, $depreciation_start,
+                       $fa_class_id, $vat_category, $shipper);
+       }
+       commit_transaction();
+}
index fb3905a5ce3fa6047a53b1a2681cc94d494c6caa..f0644a98a53a4ac8711ae43e809086000018768c 100644 (file)
@@ -232,10 +232,9 @@ if (isset($_POST['addupdate']))
                        if (file_exists($filename))
                                unlink($filename);
                }
-               
-               if (!$new_item) 
-               { /*so its an existing one */
-                       update_item($_POST['NewStockID'], $_POST['description'],
+
+                       write_item(get_post('stock_id'),
+                               $_POST['NewStockID'], $_POST['description'],
                                $_POST['long_description'], $_POST['category_id'], 
                                $_POST['tax_type_id'], get_post('units'), 
                                get_post('mb_flag'), $_POST['sales_account'],
@@ -244,29 +243,16 @@ if (isset($_POST['addupdate']))
                                $_POST['dimension_id'], $_POST['dimension2_id'],
                                check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
                                get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start', null),
-                               get_post('fa_class_id'), get_post('vat_category'), get_post('shipper'));
+                               get_post('fa_class_id'), get_post('vat_category'), get_post('shipper', 0), check_value('inactive'));
 
-                       update_record_status($_POST['NewStockID'], $_POST['inactive'],
-                               'stock_master', 'stock_id');
-                       update_record_status($_POST['NewStockID'], $_POST['inactive'],
-                               'item_codes', 'item_code');
+               if (!$new_item) 
+               { /*so its an existing one */
                        set_focus('stock_id');
                        $Ajax->activate('stock_id'); // in case of status change
                        display_notification(_("Item has been updated."));
                } 
                else 
                { //it is a NEW part
-
-                       add_item($_POST['NewStockID'], $_POST['description'],
-                               $_POST['long_description'], $_POST['category_id'], $_POST['tax_type_id'],
-                               $_POST['units'], get_post('mb_flag'), $_POST['sales_account'],
-                               $_POST['inventory_account'], $_POST['cogs_account'],
-                               $_POST['adjustment_account'], $_POST['wip_account'], 
-                               $_POST['dimension_id'], $_POST['dimension2_id'],
-                               check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
-                               get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start', null),
-                               get_post('fa_class_id'), get_post('vat_category'), get_post('shipper'));
-
                        display_notification(_("A new item has been added."));
                        $_POST['stock_id'] = $_POST['NewStockID'] = 
                        $_POST['description'] = $_POST['long_description'] = '';
index 1d15d7c2882368bec063416a800667acc768a029..cd6bc7c3cbec9ca3b1aef2d20fe41931988efeb6 100644 (file)
 ***********************************************************************/
 function add_work_centre($name, $description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."workcentres (name, description)
                VALUES (".db_escape($name).",".db_escape($description).")";
 
        db_query($sql, "could not add work centre");
+       commit_transaction();
 }
 
 function update_work_centre($type_id, $name, $description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."workcentres SET name=".db_escape($name).", description=".db_escape($description)."
                WHERE id=".db_escape($type_id);
 
        db_query($sql, "could not update work centre");
+       commit_transaction();
 }
 
 function get_all_work_centres($all=false)
@@ -44,8 +48,10 @@ function get_work_centre($type_id)
 
 function delete_work_centre($type_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."workcentres WHERE id=".db_escape($type_id);
 
        db_query($sql, "could not delete work centre");
+       commit_transaction();
 }
 
index 3641d8f7465de7585959b69bc6de21d54b12a990..f610356b92d601836259a44ae47849131364cb0b 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**********************************************************************
     Copyright (C) FrontAccounting, LLC.
        Released under the terms of the GNU General Public License, GPL, 
 
 function add_wo_costing($workorder_id, $cost_type, $trans_type, $trans_no, $factor=1)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."wo_costing (workorder_id, cost_type, trans_type, trans_no, factor)
                VALUES (".db_escape($workorder_id).","
                .db_escape($cost_type).",".db_escape($trans_type).","
                .db_escape($trans_no).",".db_escape($factor).")";
 
        db_query($sql, "could not add work order costing");
-
+       commit_transaction();
 }
 
 function get_wo_costing($workorder_id)
@@ -35,10 +37,12 @@ function get_wo_costing($workorder_id)
 
 function delete_wo_costing($trans_type, $trans_no)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."wo_costing WHERE trans_type=".db_escape($trans_type)
                ." AND trans_no=".db_escape($trans_no);
 
        db_query($sql, "could not delete work order costing");
+       commit_transaction();
 }
 
 /*
@@ -120,7 +124,7 @@ function add_wo_costs_journal($wo_id, $amount, $cost_type, $cr_acc, $date, $dim1
 //
        global $Refs, $wo_cost_types;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
     $journal_id = get_next_trans_no(ST_JOURNAL);
 
@@ -224,6 +228,7 @@ function void_wo_costing($wo_id)
 {
        global $Refs;
 
+       begin_transaction(__FUNCTION__, func_get_args());
        $res = get_wo_costing($wo_id);
 
        while($row = db_fetch($res))
@@ -241,4 +246,5 @@ function void_wo_costing($wo_id)
 
        $sql = "DELETE FROM ".TB_PREF."wo_costing WHERE workorder_id=".db_escape($wo_id);
        db_query($sql, "could not delete work order costing");
+       commit_transaction();
 }
index 422e0019beea4f0959ee1d045d89ad2ab3d16e82..9501b87b00b63d8446d6303a42decab0a1ab04fd 100644 (file)
@@ -16,7 +16,7 @@ function add_work_order_issue($woid, $ref, $to_work_order, $items, $location, $w
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args();
        $args = (object)array_combine(array('woid', 'ref', 'to_work_order', 'items', 'location', 
                'workcentre', 'date_', 'memo_'), $args);
@@ -162,7 +162,7 @@ function check_void_wo_issue($issue_no)
 
 function void_work_order_issue($type_no)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid(ST_MANUISSUE, $type_no);
 
        $void_entry = get_voided_entry(ST_MANUISSUE, $type_no);
index c05bac96c7b2d214be113e23972643394e404e02..608e75a0f4f2b9a79140bb57fed9cbaf6e9a40b8 100644 (file)
@@ -14,7 +14,7 @@ function work_order_produce($woid, $ref, $quantity, $date_, $memo, $close_wo)
        global $Refs;
 
 // FIXME: support for WO_UNASSEMBLY case
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $args = func_get_args();
        $args = (object)array_combine(array('woid', 'ref', 'quantity', 'date_', 'memo','close_wo'),
@@ -147,7 +147,7 @@ function check_void_wo_production($prod_no)
 
 function void_work_order_produce($type_no)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid(ST_MANURECEIVE, $type_no);
 
        // Skip processing already voided entry i.e. explicitly voided
index 090c8c548abc3a0dc0089833631ef132b2641691..8560831757c2c824c4d4ea8ff4439afef31786ab 100644 (file)
@@ -43,19 +43,23 @@ function get_requirements_costs($woid)
 
 function create_wo_requirements($woid, $stock_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code)
                SELECT ".db_escape($woid).", component, workcentre_added, quantity, loc_code
                FROM ".TB_PREF."bom WHERE parent=".db_escape($stock_id);
 
     db_query($sql, "The work order requirements could not be added");
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
 
 function delete_wo_requirements($woid)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."wo_requirements WHERE workorder_id=".db_escape($woid);
        db_query($sql,"The work order requirements could not be deleted");      
+       commit_transaction();
 }
 
 
@@ -65,21 +69,25 @@ function delete_wo_requirements($woid)
 */
 function update_wo_requirement_issued($id, $quantity, $cost)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."wo_requirements SET 
                                unit_cost = (units_issued*unit_cost+".$quantity*$cost.")/(units_issued+".$quantity."),
                                units_issued = units_issued + ".db_escape($quantity)."
                        WHERE id = ".db_escape($id);
 
        db_query($sql, "The work requirements issued quantity couldn't be updated");
+       commit_transaction();
 }
 
 //--------------------------------------------------------------------------------------
 
 function void_wo_requirements($woid)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0
                WHERE workorder_id = ".db_escape($woid);
 
        db_query($sql, "The work requirements issued quantity couldn't be voided");     
+       commit_transaction();
 }
 
index 2cd0ced36f3da48546b330fd0ce43de06d5dbe24..2e602a6f574c47cd3fdf6ad881f0180e8337b686 100644 (file)
@@ -17,7 +17,7 @@ function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args();
        $args = (object)array_combine(array('wo_ref', 'loc_code', 'units_reqd', 'stock_id',
                'type', 'date_', 'required_by', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args);
@@ -74,7 +74,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_)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args();
        $args = (object)array_combine(array('woid', 'loc_code', 'units_reqd', 'stock_id',
                'date_', 'required_by', 'memo_'), $args);
@@ -100,7 +100,7 @@ function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
 
 function delete_work_order($woid, $stock_id, $qty, $date)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid(ST_WORKORDER, $woid);
 
        // delete the work order requirements
@@ -179,7 +179,7 @@ function work_order_has_payments($woid)
 
 function release_work_order($woid, $releaseDate, $memo_)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $myrow = get_work_order($woid);
        $stock_id = $myrow["stock_id"];
@@ -259,7 +259,7 @@ function reopen_work_order($woid)
 */
 function void_work_order($woid)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid(ST_WORKORDER, $woid);
 
        $work_order = get_work_order($woid);
index d26ed61bf796ce02c4e51dbf09c0f11c22ea8bd1..10942e7affc529f4c8d4b7a29bcd85f4f5c1a72f 100644 (file)
@@ -92,7 +92,7 @@ if (isset($_POST['Process']))
 {
        if (check_allocations())
        {
-               $_SESSION['alloc']->write();
+               write_supp_allocation($_SESSION['alloc']);
                clear_allocations();
                $_POST['Cancel'] = 1;
        }
index fbf231f47eac6352aa6aa3eb42aedfa6383ca5a9..f5df6084db51c0fe3de9086b7d70470bbf0b642c 100644 (file)
@@ -89,7 +89,7 @@ function write_grn(&$po)
        $date_ = $po->tran_date;
        $grn = $po->grn_id;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prewrite($po, ST_SUPPRECEIVE);
 
        if (!is_company_currency($po->curr_code))
@@ -448,7 +448,7 @@ function void_grn($grn_batch)
        if (exists_grn_on_invoices($grn_batch))
                return false;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid(ST_SUPPRECEIVE, $grn_batch);
 
        void_bank_trans(ST_SUPPRECEIVE, $grn_batch, true);
index 07e87eb0810620fb56026ba7ad657a0ae06a6216..d59e0af538119136ad26e99d341a39c85521c11a 100644 (file)
@@ -132,7 +132,7 @@ function add_supp_invoice(&$supp_trans)  //, $already_voided=false, $allocs=null
        $supplier = get_supplier($supp_trans->supplier_id);
        $dec = user_price_dec();
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prewrite($supp_trans, $trans_type);
 
        if ($trans_no) {        // void old transaction
@@ -514,7 +514,7 @@ function get_matching_invoice_item($stock_id, $po_item_id)
 
 function void_supp_invoice($type, $type_no)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        hook_db_prevoid($type, $type_no);
        $trans = get_supp_trans($type_no, $type);
index e7257e00183af926618210051d0797df1df9492b..6b74c67c555049fe1e07c2cfdce1e5b6612782bb 100644 (file)
@@ -49,7 +49,7 @@ function delete_po($po)
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid($po, ST_PURCHORDER);
        $sql = "DELETE FROM ".TB_PREF."purch_orders WHERE order_no=".db_escape($po);
        db_query($sql, "The order header could not be deleted");
@@ -67,7 +67,7 @@ function add_po(&$po_obj)
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prewrite($po_obj, ST_PURCHORDER);
 
      /*Insert to purchase order header record */
@@ -115,7 +115,7 @@ function add_po(&$po_obj)
 
 function update_po(&$po_obj)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prewrite($po_obj, ST_PURCHORDER);
 
     /*Update the purchase order header with any changes */
index 40bafa3f16ffc8a70858252cad37f6089d2a07a6..62f56a79c88253967b7503045c03755d26b7efc3 100644 (file)
@@ -14,7 +14,7 @@ function write_supp_payment($trans_no, $supplier_id, $bank_account,
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args(); while (count($args) < 10) $args[] = 0;
        $args = (object)array_combine(array('trans_no', 'supplier_id', 'bank_account', 'date_',
                 'ref', 'bank_amount', 'supp_amount', 'supp_discount', 'memo_', 'bank_charge'), $args);
@@ -98,7 +98,7 @@ function write_supp_payment($trans_no, $supplier_id, $bank_account,
 
 function void_supp_payment($type, $type_no)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid($type, $type_no);
 
        void_bank_trans($type, $type_no, true);
index d66c89fc7941fb20c3912d1175eb0413b366fb2a..2648ff60e0a635667a1e009157d82bfdad5ff74f 100644 (file)
@@ -15,6 +15,7 @@ function add_supplier($supp_name, $supp_ref, $address, $supp_address, $gst_no,
        $curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account, 
        $notes, $tax_group_id, $tax_included)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, supp_ref, address, supp_address, gst_no, website,
                supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
                payment_terms, payable_account, purchase_account, payment_discount_account, notes, 
@@ -40,6 +41,7 @@ function add_supplier($supp_name, $supp_ref, $address, $supp_address, $gst_no,
                .db_escape($tax_included). ")";
 
        db_query($sql,"The supplier could not be added");
+       commit_transaction();
 }
 
 function update_supplier($supplier_id, $supp_name, $supp_ref, $address, $supp_address, $gst_no, 
@@ -47,6 +49,7 @@ function update_supplier($supplier_id, $supp_name, $supp_ref, $address, $supp_ad
        $curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account, 
        $notes, $tax_group_id, $tax_included)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."suppliers SET supp_name=".db_escape($supp_name) . ",
                supp_ref=".db_escape($supp_ref) . ",
                address=".db_escape($address) . ",
@@ -69,12 +72,15 @@ function update_supplier($supplier_id, $supp_name, $supp_ref, $address, $supp_ad
                ." WHERE supplier_id = ".db_escape($supplier_id);
 
        db_query($sql,"The supplier could not be updated");
+       commit_transaction();
 }
 
 function delete_supplier($supplier_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."suppliers WHERE supplier_id=".db_escape($supplier_id);
        db_query($sql,"check failed");
+       commit_transaction();
 }
 
 function get_supplier_details($supplier_id, $to=null, $all=true)
index eb4a1ac47057284908b04e82a7e4f79c7e3a7be8..f7fe7a5d5115d83bd9b1666779ea23f8c4610ca5 100644 (file)
@@ -139,6 +139,9 @@ function get_po_prepayments($supp_trans)
        return $allocations;
 }
 
+
+//------------------------------------ Backend interfaces--------------------------------------------
+
 //---------------------------------------------------------------------------------------------------
 //
 //     Add Purchase Order, GRN or Purchase Invoice with parent auto documents (if any)
@@ -147,6 +150,8 @@ function add_direct_supp_trans($cart)
 {
        global $Refs, $type_shortcuts;
 
+       begin_transaction(__FUNCTION__, func_get_args());
+
        if ($cart->trans_type != ST_PURCHORDER) {
                // for direct grn/invoice set same dates for lines as for whole document
                foreach ($cart->line_items as $line_no =>$line)
@@ -156,13 +161,14 @@ function add_direct_supp_trans($cart)
        $ref = $cart->reference;
        if ($cart->trans_type != ST_PURCHORDER) {
                $cart->reference = 'auto';
-               begin_transaction();    // all db changes as single transaction for direct document
        }
        $order_no = add_po($cart);
        $cart->order_no = $order_no;
 
-       if ($cart->trans_type == ST_PURCHORDER)
+       if ($cart->trans_type == ST_PURCHORDER) {
+               commit_transaction();
                return $order_no;
+       }
 
        //Direct GRN
        if ($cart->trans_type == ST_SUPPRECEIVE)
@@ -219,3 +225,40 @@ function add_direct_supp_trans($cart)
        return $inv_no;
 }
 
+function write_supplier($supplier_id, $supp_name, $ref, $address, $supp_address, $gst_no,
+                               $website, $supp_account_no, $bank_account, $credit_limit = 0, $dim1, $dim2, $curr_code,
+                               $payment_terms, $payable_account, $purchase_account, $payment_discount_account,
+                               $notes, $tax_group_id, $tax_included, $contact, $phone, $phone2, $fax, $email, $lang, $inactive=null)
+{
+               begin_transaction(__FUNCTION__, func_get_args());
+               if ($supplier_id) {
+                       update_supplier($supplier_id, $supp_name, $ref, $address, $supp_address, $gst_no,
+                                       $website, $supp_account_no, $bank_account, $credit_limit = 0, $dim1, $dim2, $curr_code,
+                                       $payment_terms, $payable_account, $purchase_account, $payment_discount_account,
+                                       $notes, $tax_group_id, $tax_included);
+
+                       if ( isset($inactive) )
+                               update_record_status($supplier_id, $inactive, 'suppliers', 'supplier_id');
+               } else {
+                       add_supplier($supp_name, $ref, $address, $supp_address, $gst_no,
+                                       $website, $supp_account_no, $bank_account, $credit_limit = 0, $dim1, $dim2, $curr_code,
+                                       $payment_terms, $payable_account, $purchase_account, $payment_discount_account,
+                                       $notes, $tax_group_id, $tax_included);
+                       $supplier_id = db_insert_id();
+
+                       add_crm_person($ref, $contact, '', $address, $phone, $phone2, $fax, $email, $lang, '');
+
+                       add_crm_contact('supplier', 'general', $supplier_id, db_insert_id());
+               }
+               commit_transaction();
+               return $supplier_id;
+}
+
+function write_supp_allocation($cart)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+               $result = $cart->write();
+       commit_transaction();
+       return $result;
+}
+
index 9cab778f183faccc850ebbeb39be035dbde9f8ba..3b0bab666d66635ebb3fea68ef8d3b83678fe4b2 100644 (file)
@@ -62,41 +62,25 @@ function handle_submit(&$supplier_id)
        
        if (!can_process())
                return;
-       begin_transaction();
-       if ($supplier_id) 
-       {
-               update_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'],
-                       $_POST['supp_address'], $_POST['gst_no'],
-                       $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], 
+
+       $supp_id = write_supplier($_POST['supplier_id'], $_POST['supp_name'], $_POST['supp_ref'], $_POST['address'],
+                       $_POST['supp_address'], $_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], 
                        input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'],
                        $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'],
-                       $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
-               update_record_status($_POST['supplier_id'], $_POST['inactive'],
-                       'suppliers', 'supplier_id');
+                       $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'),
+                       get_post('contact'), get_post('phone'), get_post('phone2'), get_post('fax'), get_post('email'), get_post('lang'), check_value('inactive'));
 
+       if ($_POST['supplier_id']) 
+       {
                $Ajax->activate('supplier_id'); // in case of status change
                display_notification(_("Supplier has been updated."));
        } 
        else 
        {
-               add_supplier($_POST['supp_name'], $_POST['supp_ref'], $_POST['address'], $_POST['supp_address'],
-                       $_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'], 
-                       input_num('credit_limit',0), $_POST['dimension_id'], $_POST['dimension2_id'],
-                       $_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'],
-                       $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
-
-               $supplier_id = $_POST['supplier_id'] = db_insert_id();
-
-               add_crm_person($_POST['supp_ref'], $_POST['contact'], '', $_POST['address'], 
-                       $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], 
-                       $_POST['rep_lang'], '');
-
-               add_crm_contact('supplier', 'general', $supplier_id, db_insert_id());
-
+//                     $_POST['supplier_id = $supp_id;
                display_notification(_("A new supplier has been added."));
                $Ajax->activate('_page_body');
        }
-       commit_transaction();
 }
 
 if (isset($_POST['submit'])) 
index 8c051386dfe81bd5f3c340780d66f123c5b82447..68a1ff43102285dcda74ec46604f8f2f2e220d90 100644 (file)
@@ -17,7 +17,6 @@ include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root . "/includes/data_checks.inc");
 include_once($path_to_root . "/sales/includes/sales_ui.inc");
 include_once($path_to_root . "/sales/includes/sales_db.inc");
-//include_once($path_to_root . "/sales/includes/ui/cust_alloc_ui.inc");
 
 $js = "";
 if ($SysPrefs->use_popup_windows)
@@ -95,7 +94,7 @@ if (isset($_POST['Process']))
 {
        if (check_allocations())
        {
-               $_SESSION['alloc']->write();
+               write_cust_allocation($_SESSION['alloc']);
                clear_allocations();
                $_POST['Cancel'] = 1;
        }
index 989c7d0310fbf5ad9cc1ae62bb2780d113a25c05..043bbf8b1901947dbe110cf7f1e63ea592eb3322 100644 (file)
@@ -16,6 +16,7 @@ include_once($path_to_root . "/includes/session.inc");
 include_once($path_to_root . "/sales/includes/ui/sales_order_ui.inc");
 include_once($path_to_root . "/includes/ui.inc");
 include_once($path_to_root . "/reporting/includes/reporting.inc");
+include_once($path_to_root . "/sales/includes/sales_db.inc");
 
 $js = "";
 if ($SysPrefs->use_popup_windows)
@@ -25,42 +26,6 @@ if (user_use_date_picker())
 
 page(_($help_context = "Create and Print Recurrent Invoices"), false, false, "", $js);
 
-function create_recurrent_invoices($customer_id, $branch_id, $order_no, $tmpl_no, $date, $from, $to, $memo)
-{
-       global $Refs;
-
-       update_last_sent_recurrent_invoice($tmpl_no, $to);
-
-       $doc = new Cart(ST_SALESORDER, array($order_no));
-
-       get_customer_details_to_order($doc, $customer_id, $branch_id);
-
-       $doc->trans_type = ST_SALESORDER;
-       $doc->trans_no = 0;
-       $doc->document_date = $date;
-
-       $doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
-
-       $doc->reference = $Refs->get_next($doc->trans_type, null, array('customer' => $customer_id, 'branch' => $branch_id,
-               'date' => $date));
-       $doc->Comments = $memo;
-
-       foreach ($doc->line_items as $line_no=>$item) {
-               $line = &$doc->line_items[$line_no];
-               $new_price = get_price($line->stock_id, $doc->customer_currency,
-                       $doc->sales_type, $doc->price_factor, $doc->document_date);
-               if ($new_price != 0)    // use template price if no price is currently set for the item.
-                       $line->price = $new_price;
-       }       
-       $cart = $doc;
-       $cart->trans_type = ST_SALESINVOICE;
-       $cart->reference = $Refs->get_next($cart->trans_type);
-       $cart->payment_terms['cash_sale'] = false; // no way to register cash payment with recurrent invoice at once
-       $invno = $cart->write(1);
-
-       return $invno;
-}
-
 function calculate_from($myrow)
 {
        if ($myrow["last_sent"] == '0000-00-00')
@@ -92,46 +57,9 @@ if ($id != -1 && is_date_closed($_POST['trans_date']))
 
 if ($id != -1)
 {
-       /*
-               whole invoiced time is <begin, end>
-               invoices are issued _after_ invoiced period is gone, eg:
-               begin 1.1
-               end   31.3
-               period:    invoice ready for issue since:
-               1.1-31.1 -  1.2
-               1.2-28.2 -  1.3
-               1.3-31.3 -  1.4
-               In example above, when end is set to 1.4 will generate additional invoice on 1.5 !
-       */
-
        $Ajax->activate('_page_body');
-       $from = get_post('from');
-       $to = get_post('to');
-       $memo = get_post('memo');
-       $date = $_POST['trans_date'];
-       $myrow = get_recurrent_invoice($id);
+       $invs = create_recurrent_invoices($id, get_post('from'), get_post('to'), get_post('trans_date'), get_post('memo'));
 
-       $invs = array();
-       if (recurrent_invoice_ready($id, $date))
-       {
-                       begin_transaction();
-
-                       if ($myrow['debtor_no'] == 0)
-                       {
-                               $cust = get_cust_branches_from_group($myrow['group_no']);
-                               while ($row = db_fetch($cust))
-                               {
-                                       $invs[] = create_recurrent_invoices($row['debtor_no'], $row['branch_code'], $myrow['order_no'], $myrow['id'],
-                                               $date, $from, $to, $memo);
-                               }
-                       }
-                       else
-                       {
-                               $invs[] = create_recurrent_invoices($myrow['debtor_no'], $myrow['group_no'], $myrow['order_no'], $myrow['id'],
-                                       $date, $from, $to, $memo);
-                       }
-                       commit_transaction();
-       }
        if (count($invs) > 0)
        {
                $min = min($invs);
@@ -151,6 +79,7 @@ if ($id != -1)
 }
 
 
+
 $id = find_submit('create');
 if ($id != -1)
 {
index 2a3077b4c5787b5e6c9680d26e92b50fae916284..2f3bff18240f895d9188c4dc119254b536e9efa0 100644 (file)
@@ -175,7 +175,7 @@ if (isset($_POST['ProcessCredit']) && can_process()) {
                $_POST['WriteOffGLCode'] = 0;
        }
        copy_to_cn();
-       $credit_no = $_SESSION['Items']->write($_POST['WriteOffGLCode']);
+       $credit_no = write_sales_trans($_SESSION['Items'], $_POST['WriteOffGLCode']);
        if ($credit_no == -1)
        {
                display_error(_("The entered reference is already in use."));
index e482386b971a7f9f14998fca9fd46cc814b75e6b..c0a48eb17aa5181d96ac1aa9b65f413c15c2f0b5 100644 (file)
@@ -198,7 +198,8 @@ if (isset($_POST['ProcessCredit']) && can_process()) {
        copy_to_cart();
        if ($new_credit) 
                new_doc_date($_SESSION['Items']->document_date);
-       $credit_no = $_SESSION['Items']->write($_POST['WriteOffGLCode']);
+
+       $credit_no = write_sales_trans($_SESSION['Items'], $_POST['WriteOffGLCode']);
        if ($credit_no == -1)
        {
                display_error(_("The entered reference is already in use."));
index d0895890936e4cb72fa09da451cbd1f6ca0a85e0..1bec9393a2cfedb7c76171f43d0c5a1cb9034118 100644 (file)
@@ -291,7 +291,7 @@ if (isset($_POST['process_delivery']) && check_data()) {
        if ($newdelivery)
                new_doc_date($dn->document_date);
 
-       $delivery_no = $dn->write($bo_policy);
+       $delivery_no = write_sales_trans($dn, $bo_policy);
 
        if ($delivery_no == -1)
        {
index ba0c8a413ffe7618c0311f3713bb6847f1864186..20af722a3ce0603ee77064c449cb4af573231b80 100644 (file)
@@ -358,7 +358,7 @@ if (isset($_POST['process_invoice']) && check_data()) {
        if ($newinvoice) 
                new_doc_date($_SESSION['Items']->document_date);
 
-       $invoice_no = $_SESSION['Items']->write();
+       $invoice_no = write_sales_trans($_SESSION['Items']);
        if ($invoice_no == -1)
        {
                display_error(_("The entered reference is already in use."));
index 907f789eca8499fd7dd1e9014fe0be406779c6b4..30d5151cca6e43e6bce3ea45e83977570af49d4c 100644 (file)
@@ -238,14 +238,10 @@ if (get_post('AddPaymentItem') && can_process()) {
        new_doc_date($_POST['DateBanked']);
 
        $new_pmt = !$_SESSION['alloc']->trans_no;
-       //Chaitanya : 13-OCT-2011 - To support Edit feature
-       $payment_no = write_customer_payment($_SESSION['alloc']->trans_no, $_POST['customer_id'], $_POST['BranchID'],
-               $_POST['bank_account'], $_POST['DateBanked'], $_POST['ref'],
-               input_num('amount'), input_num('discount'), $_POST['memo_'], 0, input_num('charge'), input_num('bank_amount', input_num('amount')));
-
-       $_SESSION['alloc']->trans_no = $payment_no;
-       $_SESSION['alloc']->date_ = $_POST['DateBanked'];
-       $_SESSION['alloc']->write();
+
+       $payment_no =  save_cust_payment($_SESSION['alloc'], get_post('customer_id'), get_post('BranchID'), get_post('bank_account'),
+                get_post('DateBanked'), get_post('ref'), input_num('amount'), input_num('discount'), get_post('memo_'),
+                input_num('charge'), input_num('bank_amount', input_num('amount')));
 
        unset($_SESSION['alloc']);
        meta_forward($_SERVER['PHP_SELF'], $new_pmt ? "AddedID=$payment_no" : "UpdatedID=$payment_no");
index e51de6f149234bd8004084fa8545d0f0919025ae..ec439d121e271cc1a4a766d71be46ccd9d1493cf 100644 (file)
@@ -14,6 +14,7 @@ function add_branch($customer_id, $br_name, $br_ref, $br_address, $salesman, $ar
        $payment_discount_account, $default_location, $br_post_address, $group_no,
        $default_ship_via, $notes, $bank_account)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."cust_branch (debtor_no, br_name, branch_ref, br_address,
                salesman, area, tax_group_id, sales_account, receivables_account, payment_discount_account, 
                sales_discount_account, default_location,
@@ -34,6 +35,7 @@ function add_branch($customer_id, $br_name, $br_ref, $br_address, $salesman, $ar
                        .db_escape($notes). ", "
                        .db_escape($bank_account, true).")";
        db_query($sql,"The branch record could not be added");
+       commit_transaction();
 }
 
 function update_branch($customer_id, $branch_code, $br_name, $br_ref, $br_address,
@@ -41,6 +43,7 @@ function update_branch($customer_id, $branch_code, $br_name, $br_ref, $br_addres
        $payment_discount_account, $default_location, $br_post_address, $group_no,
        $default_ship_via, $notes, $bank_account)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."cust_branch SET br_name = " . db_escape($br_name) . ",
                branch_ref = " . db_escape($br_ref) . ",
                br_address = ".db_escape($br_address). ",
@@ -60,14 +63,17 @@ function update_branch($customer_id, $branch_code, $br_name, $br_ref, $br_addres
                WHERE branch_code =".db_escape($branch_code) . "
                AND debtor_no=".db_escape($customer_id);
        db_query($sql,"The branch record could not be updated");
+       commit_transaction();
 }
 
 function delete_branch($customer_id, $branch_code)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        delete_entity_contacts('cust_branch', $branch_code);
 
        $sql="DELETE FROM ".TB_PREF."cust_branch WHERE branch_code=".db_escape($branch_code)." AND debtor_no=".db_escape($customer_id);
        db_query($sql,"could not delete branch");
+       commit_transaction();
 }
 
 function branch_in_foreign_table($customer_id, $branch_code, $table)
index c80cdc906fdf1fe0a96b1f3b71496951a35c3e1b..81975db77a44ec1a248b527e1df9aa8deff81954 100644 (file)
 ***********************************************************************/
 function add_credit_status($description, $disallow_invoicing)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."credit_status (reason_description, dissallow_invoices) 
                VALUES (".db_escape($description).",".db_escape($disallow_invoicing).")";
 
        db_query($sql, "could not add credit status");
+       $result = db_insert_id();
+
+       commit_transaction();
+       return $result;
 }
 
 function update_credit_status($status_id, $description, $disallow_invoicing)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."credit_status SET reason_description=".db_escape($description).",
                dissallow_invoices=".db_escape($disallow_invoicing)." WHERE id=".db_escape($status_id);
 
        db_query($sql, "could not update credit status");
+       commit_transaction();
 }
 
 function get_all_credit_status($all=false)
@@ -44,8 +51,10 @@ function get_credit_status($status_id)
 
 function delete_credit_status($status_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."credit_status WHERE id=".db_escape($status_id);
 
        db_query($sql, "could not delete credit status");
+       commit_transaction();
 }
 
index 0dfc17e28e85fa9ddf1ad0de89fa026fb6b9b700..3191e8a676cefc2a516bcebbaacc8104009f8b20 100644 (file)
@@ -52,7 +52,7 @@ function update_customer($customer_id, $CustName, $cust_ref, $address, $tax_id,
 
 function delete_customer($customer_id)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        delete_entity_contacts('customer', $customer_id);
 
        $sql = "DELETE FROM ".TB_PREF."debtors_master WHERE debtor_no=".db_escape($customer_id);
index 9560179f1b7131e2b7e82c1144604f319a392289..7eb77dfb2dfcc42d161d692c3ba2f1845f230a3e 100644 (file)
@@ -25,7 +25,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 {
        global $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $args = func_get_args(); while (count($args) < 12) $args[] = 0;
        $args = (object)array_combine(array('trans_no', 'customer_id', 'branch_id', 'bank_account', 
                'date_', 'ref', 'amount', 'discount', 'memo_','rate','charge', 'bank_amount'), $args);
@@ -121,7 +121,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou
 
 function void_customer_payment($type, $type_no)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        hook_db_prevoid($type, $type_no);
        void_bank_trans($type, $type_no, true);
index 7d74dd20d8675bd915394e7511596129a04516ae..66a6a87f40581aefea23b568fd4426f62ff36f1d 100644 (file)
 function add_recurrent_invoice($description, $order_no, $debtor_no, $group_no, $days, $monthly,
        $begin, $end)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."recurrent_invoices (description, order_no, debtor_no,
                group_no, days, monthly, begin, end, last_sent) VALUES (".db_escape($description) . ", "
                .db_escape($order_no).", ".db_escape($debtor_no).", "
                .db_escape($group_no).", ".$days.", ".$monthly.", '"
                .date2sql($begin)."', '".date2sql($end)."', '0000-00-00')";
        db_query($sql,"The recurrent invoice could not be added");
+       commit_transaction();
 }
 
 function update_recurrent_invoice($selected_id, $description, $order_no, $debtor_no, $group_no, $days, $monthly,
        $begin, $end)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."recurrent_invoices SET 
                description=".db_escape($description).", 
                order_no=".db_escape($order_no).", 
@@ -35,20 +38,25 @@ function update_recurrent_invoice($selected_id, $description, $order_no, $debtor
                end='".date2sql($end)."' 
                WHERE id = ".db_escape($selected_id);
        db_query($sql,"The recurrent invoice could not be updated");
+       commit_transaction();
 }
 
 function update_last_sent_recurrent_invoice($id, $date)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $date = date2sql($date);
        $sql = "UPDATE ".TB_PREF."recurrent_invoices SET last_sent='$date' WHERE id=".db_escape($id);
 
        db_query($sql,"The recurrent invoice could not be updated");
+       commit_transaction();
 }
 
 function delete_recurrent_invoice($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."recurrent_invoices WHERE id=".db_escape($selected_id);
        db_query($sql,"could not delete recurrent invoice");
+       commit_transaction();
 }
 
 function get_recurrent_invoices($date=null)
@@ -171,3 +179,41 @@ function check_sales_order_type($order_no)
 
        return !$myrow['prepaid'];
 }
+
+function create_template_invoice($customer_id, $branch_id, $order_no, $tmpl_no, $date, $from, $to, $memo)
+{
+       global $Refs;
+
+       update_last_sent_recurrent_invoice($tmpl_no, $to);
+
+       $doc = new Cart(ST_SALESORDER, array($order_no));
+
+       get_customer_details_to_order($doc, $customer_id, $branch_id);
+
+       $doc->trans_type = ST_SALESORDER;
+       $doc->trans_no = 0;
+       $doc->document_date = $date;
+
+       $doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
+
+       $doc->reference = $Refs->get_next($doc->trans_type, null, array('customer' => $customer_id, 'branch' => $branch_id,
+               'date' => $date));
+       $doc->Comments = $memo;
+
+       foreach ($doc->line_items as $line_no=>$item) {
+               $line = &$doc->line_items[$line_no];
+               $new_price = get_price($line->stock_id, $doc->customer_currency,
+                       $doc->sales_type, $doc->price_factor, $doc->document_date);
+               if ($new_price != 0)    // use template price if no price is currently set for the item.
+                       $line->price = $new_price;
+       }       
+       $cart = $doc;
+       $cart->trans_type = ST_SALESINVOICE;
+       $cart->reference = $Refs->get_next($cart->trans_type);
+       $cart->payment_terms['cash_sale'] = false; // no way to register cash payment with recurrent invoice at once
+
+       $invno = $cart->write(1);
+
+       return $invno;
+}
+
index 998a6a204a2828b35441ad8a2ac488b2ba6f599e..105007bdb06bb616159fd6dd867b55507bbe354d 100644 (file)
@@ -17,6 +17,8 @@ function write_credit_note(&$credit_note, $write_off_acc)
 {
        global $Refs;
 
+       begin_transaction(__FUNCTION__, func_get_args());
+
        if (is_array($credit_note->src_docs))
        {
                $docs = array_keys($credit_note->src_docs);
@@ -35,7 +37,6 @@ function write_credit_note(&$credit_note, $write_off_acc)
 
        $credit_type = $write_off_acc == 0 ? 'Return' : 'WriteOff';
 
-       begin_transaction();
        hook_db_prewrite($credit_note, ST_CUSTCREDIT);
 
        $company_data = get_company_prefs();
index 3c260a52c142ee7d5bdb9ca34e7aaae4a6713cb7..4a4a8a81edd9b54e483424a012f1bafd96edc0f9 100644 (file)
@@ -19,7 +19,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
        $trans_no = $delivery->trans_no;
        if (is_array($trans_no)) $trans_no = key($trans_no);
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        $delivery->bo_policy = $bo_policy;
        hook_db_prewrite($delivery, ST_CUSTDELIVERY);
 
@@ -215,7 +215,7 @@ function adjust_shipping_charge(&$delivery, $trans_no)
 function void_sales_delivery($type, $type_no, $transactions=true)
 {
        if ($transactions)
-               begin_transaction();
+               begin_transaction(__FUNCTION__, func_get_args());
 
        hook_db_prevoid($type, $type_no);
        
index f68a3bb6ec95d33693a0299d06dc00072d18adae..cadae2a7675321064953e4526d8bd4e19c0da736 100644 (file)
 
 function add_sales_group($description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."groups (description) VALUES (".db_escape($description) . ")";
        db_query($sql,"The sales group could not be added");
+       commit_transaction();
+       return db_insert_id();
 }
 
 function update_sales_group($selected_id, $description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."groups SET description=".db_escape($description)." WHERE id = ".db_escape($selected_id);
        db_query($sql,"The sales group could not be updated");
+       commit_transaction();
 }
 
 function delete_sales_group($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."groups WHERE id=".db_escape($selected_id);
        db_query($sql,"could not delete sales group");
+       commit_transaction();
 }
 
 function get_sales_groups($show_inactive)
@@ -54,20 +61,28 @@ function get_sales_group_name($group_no)
 
 function add_sales_area($description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."areas (description) VALUES (".db_escape($description) . ")";
        db_query($sql,"The sales area could not be added");
+       $result =  db_insert_id();
+       commit_transaction();
+       return $result;
 }
 
 function update_sales_area($selected_id, $description)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."areas SET description=".db_escape($description)." WHERE area_code = ".db_escape($selected_id);
        db_query($sql,"The sales area could not be updated");
+       commit_transaction();
 }
 
 function delete_sales_area($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."areas WHERE area_code=".db_escape($selected_id);
        db_query($sql,"could not delete sales area");
+       commit_transaction();
 }
 
 function get_sales_areas($show_inactive)
@@ -98,6 +113,7 @@ function get_area_name($id)
 function add_salesman($salesman_name, $salesman_phone, $salesman_fax,
        $salesman_email, $provision, $break_pt, $provision2)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."salesman (salesman_name, salesman_phone, salesman_fax, salesman_email,
                provision, break_pt, provision2)
                VALUES (".db_escape($salesman_name) . ", "
@@ -107,11 +123,13 @@ function add_salesman($salesman_name, $salesman_phone, $salesman_fax,
                $provision.", ".$break_pt.", "
                .$provision2.")";
        db_query($sql,"The insert of the sales person failed");
+       commit_transaction();
 }
 
 function update_salesman($selected_id, $salesman_name, $salesman_phone, $salesman_fax,
        $salesman_email, $provision, $break_pt, $provision2)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."salesman SET salesman_name=".db_escape($salesman_name) . ",
                salesman_phone=".db_escape($salesman_phone) . ",
                salesman_fax=".db_escape($salesman_fax) . ",
@@ -121,12 +139,15 @@ function update_salesman($selected_id, $salesman_name, $salesman_phone, $salesma
                provision2=".$provision2."
                WHERE salesman_code = ".db_escape($selected_id);
        db_query($sql,"The update of the sales person failed");
+       commit_transaction();
 }
 
 function delete_salesman($selected_id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."salesman WHERE salesman_code=".db_escape($selected_id);
        db_query($sql,"The sales-person could not be deleted");
+       commit_transaction();
 }
 
 function get_salesmen($show_inactive)
index 862df0a4cbb9439dbb270cff37ad879ddb241ddb..22d34e8a646537848ed67d652f815137ac1b1371 100644 (file)
@@ -23,7 +23,7 @@ function write_sales_invoice(&$invoice)
        $date_ = $invoice->document_date;
        $charge_shipping =$invoice->freight_cost;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        hook_db_prewrite($invoice, ST_SALESINVOICE);
        $company_data = get_company_prefs();
@@ -216,7 +216,7 @@ function write_sales_invoice(&$invoice)
 
 function void_sales_invoice($type, $type_no)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        hook_db_prevoid($type, $type_no);
        void_bank_trans($type, $type_no, true);
index 968777ab8c0360fb4f8c438cc96c4db1bb3c29a7..e76ea3eee2c60b563bb4e288dee218fb3b2f6eae 100644 (file)
@@ -14,7 +14,7 @@ function add_sales_order(&$order)
 {
        global $SysPrefs, $path_to_root, $Refs;
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prewrite($order, $order->trans_type);
        $order_no = get_next_trans_no($order->trans_type);
        $del_date = date2sql($order->due_date);
@@ -86,7 +86,7 @@ function add_sales_order(&$order)
 
 function delete_sales_order($order_no, $trans_type)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prevoid($trans_type, $order_no);
 
        $sql = "DELETE FROM ".TB_PREF."sales_orders WHERE order_no=" . db_escape($order_no) 
@@ -126,7 +126,7 @@ function update_sales_order($order)
        $version= current($order->trans_no);
        $total = $order->get_trans_total();
 
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        hook_db_prewrite($order, $order->trans_type);
 
        if ($order->trans_type == ST_SALESORDER)
index b5abaef7f7f631bb1775bdaa5f9e42bf6b6b3679..3f2bc4092a204096ee9ada36400198c28a09689f 100644 (file)
 ***********************************************************************/
 function add_sales_point($name, $location, $account, $cash, $credit)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."sales_pos (pos_name, pos_location, pos_account, cash_sale, credit_sale) VALUES (".db_escape($name)
                        . ",".db_escape($location).",".db_escape($account)
                        . ",$cash,$credit)";
        db_query($sql, "could not add point of sale");
+       commit_transaction();
 }
 
 function update_sales_point($id, $name, $location, $account, $cash, $credit)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $sql = "UPDATE ".TB_PREF."sales_pos SET pos_name=".db_escape($name)
                                .",pos_location=".db_escape($location)
@@ -27,7 +30,8 @@ function update_sales_point($id, $name, $location, $account, $cash, $credit)
                                .",credit_sale =$credit"
                                ." WHERE id = ".db_escape($id);
        
-       db_query($sql, "could not update sales type");                  
+       db_query($sql, "could not update sales type");
+       commit_transaction();
 }
 
 function get_all_sales_points($all=false)
@@ -66,7 +70,9 @@ function get_sales_point_name($id)
 
 function delete_sales_point($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."sales_pos WHERE id=".db_escape($id);
        db_query($sql,"The point of sale record could not be deleted");
+       commit_transaction();
 }
 
index a0279d3e5045f0947e71d9a5c3bd7e33f174793d..178b3d68505a97fd4bd82a99b92275f2c23b061c 100644 (file)
 ***********************************************************************/
 function add_sales_type($name, $tax_included, $factor)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
+
        $sql = "INSERT INTO ".TB_PREF."sales_types (sales_type,tax_included,factor) VALUES (".db_escape($name).","
                .db_escape($tax_included).",".db_escape($factor).")";
-       db_query($sql, "could not add sales type");             
+       db_query($sql, "could not add sales type");
+       $result = db_insert_id();
+
+       commit_transaction();
+       return $result;
 }
 
 function update_sales_type($id, $name, $tax_included, $factor)
 {
-
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."sales_types SET sales_type = ".db_escape($name).",
        tax_included =".db_escape($tax_included).", factor=".db_escape($factor)." WHERE id = ".db_escape($id);
        
        db_query($sql, "could not update sales type");                  
+       commit_transaction();
 }
 
 function get_all_sales_types($all=false)
@@ -55,10 +62,12 @@ function get_sales_type_name($id)
 
 function delete_sales_type($id)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql="DELETE FROM ".TB_PREF."sales_types WHERE id=".db_escape($id);
        db_query($sql,"The Sales type record could not be deleted");
 
        $sql ="DELETE FROM ".TB_PREF."prices WHERE sales_type_id=".db_escape($id);
        db_query($sql,"The Sales type prices could not be deleted");
+       commit_transaction();
 }
 
index 26e92955d29ead94ebee3d7ee5c07bba35cc78b5..e870b83356c20110d4f03d10a6d9ed4bf5604cfb 100644 (file)
@@ -376,3 +376,168 @@ function get_sales_child_documents($trans_type, $trans_no)
        return db_query($sql,"The related credit notes could not be retreived");
 }
 
+//-------------------------------- Backend interfaces -------------------------------------
+
+
+function write_sales_trans($cart, $policy = 0)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+       $result = $cart->write($policy);
+       commit_transaction();
+       return $result;
+}
+
+function save_cust_payment($cart, $customer_id, $branch_id,
+               $bank_account, $trans_date, $ref, $amount, $discount, $memo, $charge, $bank_amount)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+
+       $payment_no = write_customer_payment($cart->trans_no, $customer_id, $branch_id,
+               $bank_account, $trans_date, $ref, $amount, $discount, $memo, 0, $charge, $bank_amount);
+
+       $cart->trans_no = $payment_no;
+       $cart->date_ = $trans_date;
+       $cart->write();
+
+       commit_transaction();
+       return $payment_no;
+}
+
+function create_recurrent_invoices($id, $from, $to, $date, $memo)
+{
+       /*
+               whole invoiced time is <begin, end>
+               invoices are issued _after_ invoiced period is gone, eg:
+               begin 1.1
+               end   31.3
+               period:    invoice ready for issue since:
+               1.1-31.1 -  1.2
+               1.2-28.2 -  1.3
+               1.3-31.3 -  1.4
+               In example above, when end is set to 1.4 will generate additional invoice on 1.5 !
+       */
+       log_user();
+
+       $myrow = get_recurrent_invoice($id);
+
+       $invs = array();
+       if (recurrent_invoice_ready($id, $date))
+       {
+
+               begin_transaction(__FUNCTION__, func_get_args());
+                       if ($myrow['debtor_no'] == 0)
+                       {
+                               $cust = get_cust_branches_from_group($myrow['group_no']);
+                               while ($row = db_fetch($cust))
+                               {
+                                       $invs[] = create_template_invoice($row['debtor_no'], $row['branch_code'], $myrow['order_no'], $myrow['id'],
+                                               $date, $from, $to, $memo);
+                               }
+                       }
+                       else
+                       {
+                               $invs[] = create_template_invoice($myrow['debtor_no'], $myrow['group_no'], $myrow['order_no'], $myrow['id'],
+                                       $date, $from, $to, $memo);
+                       }
+               commit_transaction();
+       }
+       return $invs;
+}
+
+function write_recurrent_invoice($invoice_id, $description, $order_no, $debtor_no, $group_no,
+       $days, $monthly, $begin, $end, $last_sent)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+
+               if ($invoice_id != -1) 
+       {
+               update_recurrent_invoice($invoice_id, $description, $order_no, $debtor_no, $group_no,
+                               $days, $monthly, $begin, $end);
+               if (isset($last_sent))
+                               update_last_sent_recurrent_invoice($invoice_id, $last_sent);
+       } 
+       else 
+       {
+               add_recurrent_invoice($description, $order_no, $debtor_no, $group_no,
+                       $days, $monthly, $begin, $end);
+       }
+       commit_transaction();
+}
+
+function write_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status,
+        $payment_terms, $discount, $pymt_discount, $credit_limit, $sales_type, $notes, $inactive, $salesman, $area, 
+        $tax_group, $location, $address, $ship_via, $notes, $bank_account, $address, $phone, $phone2, $fax, $email)
+{
+       global $SysPrefs;
+
+       begin_transaction(__FUNCTION__, func_get_args());
+
+       if ($customer_id) {
+               update_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status,
+                        $payment_terms, $discount/100, $pymt_discount/100, $credit_limit, $sales_type, $notes, $inactive);
+
+               update_record_status($customer_id, $inactive, 'debtors_master', 'debtor_no');
+
+       } else {
+               add_customer($name, $ref, $address,     $tax_id, $curr_code, $dim1, $dim2, $credit_status, $payment_terms,
+                       $discount / 100, $pymt_discount / 100, $credit_limit, $sales_type, $notes);
+
+               $customer_id = db_insert_id();
+
+               if (isset($SysPrefs->auto_create_branch) && $SysPrefs->auto_create_branch == 1)
+               {
+               add_branch($customer_id, $name, $ref, $address, $salesman, $area, $tax_group, '',
+                       get_company_pref('default_sales_discount_act'),
+                       get_company_pref('debtors_act'),
+                       get_company_pref('default_prompt_payment_act'),
+                $location, $address, 0, $ship_via, $notes, $bank_account);
+
+               $selected_branch = db_insert_id();
+
+                       add_crm_person($ref, $name, '', $address, $phone, $phone2, $fax, $email, '', '');
+
+                       $pers_id = db_insert_id();
+                       add_crm_contact('cust_branch', 'general', $selected_branch, $pers_id);
+
+                       add_crm_contact('customer', 'general', $customer_id, $pers_id);
+               }
+       }
+       commit_transaction();
+
+       return $customer_id;
+}
+
+function write_cust_branch($id, $customer_id, $name, $ref, $br_address, $salesman, $area, $tax_group,
+       $sales_act, $discount_act, $ar_act, $payment_discount_act, $location, $post_address, $group_no, $ship_via, $notes, $bank_act,
+       $contact_name, $phone, $phone2,$fax, $email, $lang)
+{
+
+       begin_transaction(__FUNCTION__, func_get_args());
+
+       if ($id !== 0) {
+                               update_branch($customer_id, $id, $name, $ref, $br_address, $salesman, $area, $tax_group, $sales_act,
+                                       $discount_act, $ar_act, $discount_act, $location, $post_address, $group_no,
+                                       $ship_via, $notes, $bank_act);
+       } else {
+                               add_branch($customer_id, $name, $ref, $br_address, $salesman, $area, $tax_group, $sales_act,
+                                       $discount_act, $ar_act, $payment_discount_act, $location, $post_address, $group_no,
+                                       $ship_via, $notes, $bank_act);
+
+                               $branch_id = db_insert_id();
+
+                               add_crm_person($contact_name, $contact_name, '', $post_address, $phone, $phone2, $fax, $email, $lang, '');
+
+                               add_crm_contact('cust_branch', 'general', $branch_id, db_insert_id());
+
+       }
+       commit_transaction();
+}
+
+function write_cust_allocation($cart)
+{
+       begin_transaction(__FUNCTION__, func_get_args());
+               $result = $cart->write();
+       commit_transaction();
+       return $result;
+}
+
index 8902135a7280d78ccc24a8366bac6dec91137873..ee33fa860c684fc53eb38949425aa2c64da658b3 100644 (file)
@@ -78,36 +78,18 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
        if ($input_error != 1)
        {
 
-               begin_transaction();
-       if ($selected_id != -1)
-               {
-                       update_branch($_POST['customer_id'], $_POST['branch_code'], $_POST['br_name'], $_POST['br_ref'],
+               $id = $_POST['branch_code'] == -1 ? 0 : $_POST['branch_code'];
+               write_cust_branch($id, $_POST['customer_id'], $_POST['br_name'], $_POST['br_ref'],
                                $_POST['br_address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], $_POST['sales_account'],
                                $_POST['sales_discount_account'], $_POST['receivables_account'], $_POST['payment_discount_account'],
                                $_POST['default_location'], $_POST['br_post_address'], $_POST['group_no'],
-                               $_POST['default_ship_via'], $_POST['notes'], $_POST['bank_account']);
+                               $_POST['default_ship_via'], $_POST['notes'], $_POST['bank_account'], 
+                               get_post('contact_name'), get_post('phone'), get_post('phone2'), get_post('fax'), get_post('email'), get_post('rep_lang'));
 
+               if ($selected_id != -1)
                        $note =_('Selected customer branch has been updated');
-               }
                else
-               {
-                       add_branch($_POST['customer_id'], $_POST['br_name'], $_POST['br_ref'],
-                               $_POST['br_address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], $_POST['sales_account'],
-                               $_POST['sales_discount_account'], $_POST['receivables_account'], $_POST['payment_discount_account'],
-                               $_POST['default_location'], $_POST['br_post_address'], $_POST['group_no'],
-                               $_POST['default_ship_via'], $_POST['notes'], $_POST['bank_account']);
-                       $selected_id = db_insert_id();
-
-                       add_crm_person($_POST['contact_name'], $_POST['contact_name'], '', $_POST['br_post_address'], 
-                               $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], 
-                               $_POST['rep_lang'], '');
-
-                       add_crm_contact('cust_branch', 'general', $selected_id, db_insert_id());
-
-
                        $note = _('New customer branch has been added');
-               }
-               commit_transaction();
                display_notification($note);
 
                if (@$_REQUEST['popup']) {
index 01d9fe505dbaa6c24df5edd67c32bd627bcbb344..e51e4b48bc7bd9e51e5175694b2db20dfd48a4d2 100644 (file)
@@ -84,48 +84,23 @@ function handle_submit(&$selected_id)
        if (!can_process())
                return;
                
-       if ($selected_id) 
-       {
-               update_customer($_POST['customer_id'], $_POST['CustName'], $_POST['cust_ref'], $_POST['address'],
-                       $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'],
-                       $_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100,
-                       input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
 
-               update_record_status($_POST['customer_id'], $_POST['inactive'],
-                       'debtors_master', 'debtor_no');
+       $_POST['customer_id'] = write_customer($_POST['customer_id'], $_POST['CustName'], $_POST['cust_ref'], $_POST['address'],
+                       $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'],
+                       $_POST['credit_status'], $_POST['payment_terms'], input_num('discount'), input_num('pymt_discount'),
+                       input_num('credit_limit'), $_POST['sales_type'], $_POST['notes'], @$_POST['inactive'], get_post('salesman'),
+                       get_post('area'), get_post('tax_group_id'), get_post('location'), get_post('address'), get_post('ship_via'), 
+                       get_post('notes'), get_post('bank_account'), get_post('address'), get_post('phone'), get_post('phone2'), get_post('fax'), get_post('email'));
 
+       if ($selected_id) 
+       {
                $Ajax->activate('customer_id'); // in case of status change
                display_notification(_("Customer has been updated."));
        } 
        else 
        {       //it is a new customer
 
-               begin_transaction();
-               add_customer($_POST['CustName'], $_POST['cust_ref'], $_POST['address'],
-                       $_POST['tax_id'], $_POST['curr_code'], $_POST['dimension_id'], $_POST['dimension2_id'],
-                       $_POST['credit_status'], $_POST['payment_terms'], input_num('discount') / 100, input_num('pymt_discount') / 100,
-                       input_num('credit_limit'), $_POST['sales_type'], $_POST['notes']);
-
-               $selected_id = $_POST['customer_id'] = db_insert_id();
-         
-               if (isset($SysPrefs->auto_create_branch) && $SysPrefs->auto_create_branch == 1)
-               {
-               add_branch($selected_id, $_POST['CustName'], $_POST['cust_ref'],
-                $_POST['address'], $_POST['salesman'], $_POST['area'], $_POST['tax_group_id'], '',
-                get_company_pref('default_sales_discount_act'), get_company_pref('debtors_act'), get_company_pref('default_prompt_payment_act'),
-                $_POST['location'], $_POST['address'], 0, $_POST['ship_via'], $_POST['notes'], $_POST['bank_account']);
-                
-               $selected_branch = db_insert_id();
-        
-                       add_crm_person($_POST['cust_ref'], $_POST['CustName'], '', $_POST['address'], 
-                               $_POST['phone'], $_POST['phone2'], $_POST['fax'], $_POST['email'], '', '');
-
-                       $pers_id = db_insert_id();
-                       add_crm_contact('cust_branch', 'general', $selected_branch, $pers_id);
-
-                       add_crm_contact('customer', 'general', $selected_id, $pers_id);
-               }
-               commit_transaction();
+               $selected_id = get_post('customer_id');
 
                display_notification(_("A new customer has been added."));
 
index fef2ddc06ec07e14f71e5be188b612856077fa24..036819b522cb9bbc72b44b5fef25358bab46b41b 100644 (file)
@@ -80,26 +80,21 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
 
        if ($input_error != 1)
        {
+               write_recurrent_invoice($selected_id, $_POST['description'], $_POST['order_no'], input_num('debtor_no'), 
+                       input_num('group_no'), input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end'],
+                       get_post('last_sent',null));
+
        if ($selected_id != -1) 
-       {
-               update_recurrent_invoice($selected_id, $_POST['description'], $_POST['order_no'], input_num('debtor_no'), 
-                       input_num('group_no'), input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']);
-               if (isset($_POST['last_sent'])) 
-                               update_last_sent_recurrent_invoice($selected_id, $_POST['last_sent']);
                        $note = _('Selected recurrent invoice has been updated');
-       } 
        else 
-       {
-               add_recurrent_invoice($_POST['description'], $_POST['order_no'], input_num('debtor_no'), input_num('group_no'),
-                       input_num('days', 0), input_num('monthly', 0), $_POST['begin'], $_POST['end']);
                        $note = _('New recurrent invoice has been added');
-       }
-    
+
                display_notification($note);
                $Mode = 'RESET';
        }
 } 
 
+
 if ($Mode == 'Delete')
 {
 
index 77e975d4258566c64c342b88ca9011ce993148c5..a604af695b2c3b10836fe9613ca55c025d8a0d1b 100644 (file)
@@ -63,7 +63,6 @@ if (isset($_GET['NewDelivery']) && is_numeric($_GET['NewDelivery'])) {
 
        $_SESSION['page_title'] = _($help_context = "Direct Sales Delivery");
        create_cart(ST_CUSTDELIVERY, $_GET['NewDelivery']);
-
 } elseif (isset($_GET['NewInvoice']) && is_numeric($_GET['NewInvoice'])) {
 
        create_cart(ST_SALESINVOICE, $_GET['NewInvoice']);
@@ -471,7 +470,7 @@ if (isset($_POST['ProcessOrder']) && can_process()) {
        $modified = ($_SESSION['Items']->trans_no != 0);
        $so_type = $_SESSION['Items']->so_type;
 
-       $ret = $_SESSION['Items']->write(1);
+       $ret = write_sales_trans($_SESSION['Items'], 1);
        if ($ret == -1)
        {
                display_error(_("The entered reference is already in use."));
index 1511ff1123b49565094629456dde9a352aba4aff..3994822e62871774c571db0cb834e92110b78e01 100644 (file)
@@ -59,3 +59,15 @@ UPDATE `0_cust_branch` branch
        SET branch.default_ship_via=stock.stock_id;
 
 ALTER TABLE `0_tax_group_items` DROP COLUMN `tax_shipping`;
+
+# new debug trail
+DROP TABLE `1_sql_trail`;
+CREATE TABLE `1_db_trail` (
+               `id` int(11) NOT NULL AUTO_INCREMENT,
+               `stamp` timestamp DEFAULT CURRENT_TIMESTAMP,
+               `user` tinyint(3) unsigned NOT NULL DEFAULT '0',
+               `msg`  varchar(255) DEFAULT '',
+               `entry`  varchar(255) DEFAULT '',
+               `data` text DEFAULT NULL,
+       PRIMARY KEY (`id`)
+       ) ENGINE=MyISAM;
index b6cdf6e10d14068f3589a3180e90af520fff24c1..b62e9675d6319bf1270d7fe6a92117d6e4776734 100644 (file)
@@ -578,6 +578,17 @@ INSERT INTO `0_cust_branch` VALUES
 ('1', '1', 'Donald Easter LLC', 'Donald Easter', 'N/A', '1', '1', 'DEF', '1', '', '4510', '1200', '4500', 'post-std', 'N/A', '0', '', NULL, '0'),
 ('2', '2', 'MoneyMaker Ltd.', 'MoneyMaker', '', '1', '1', 'DEF', '2', '', '4510', '1200', '4500', 'post-std', '', '0', '', NULL, '0');
 
+DROP TABLE IF EXISTS `0_sql_trail`;
+CREATE TABLE `0_db_trail` (
+               `id` int(11) NOT NULL AUTO_INCREMENT,
+               `stamp` timestamp DEFAULT CURRENT_TIMESTAMP,
+               `user` tinyint(3) unsigned NOT NULL DEFAULT '0',
+               `msg`  varchar(255) DEFAULT '',
+               `entry`  varchar(255) DEFAULT '',
+               `data` text DEFAULT NULL,
+       PRIMARY KEY (`id`)
+) ENGINE=MyISAM;
+
 -- Structure of table `0_debtor_trans` --
 
 DROP TABLE IF EXISTS `0_debtor_trans`;
@@ -1580,21 +1591,6 @@ CREATE TABLE `0_shippers` (
 INSERT INTO `0_shippers` VALUES
 ('1', 'Default', '', '', '', '', '0');
 
--- Structure of table `0_sql_trail` --
-
-DROP TABLE IF EXISTS `0_sql_trail`;
-
-CREATE TABLE `0_sql_trail` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
-  `sql` text NOT NULL,
-  `result` tinyint(1) NOT NULL,
-  `msg` varchar(255) NOT NULL,
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB ;
-
--- Data of table `0_sql_trail` --
-
-
 -- Structure of table `0_stock_category` --
 
 DROP TABLE IF EXISTS `0_stock_category`;
index 7cfb0fc915b84299c0cf9c1633c54798b0e50792..9e22d3cc2579799fb7b41e0d5c3c47057c59232e 100644 (file)
@@ -494,6 +494,17 @@ CREATE TABLE `0_cust_branch` (
 
 -- Data of table `0_cust_branch` --
 
+DROP TABLE IF EXISTS `0_sql_trail`;
+CREATE TABLE `0_db_trail` (
+               `id` int(11) NOT NULL AUTO_INCREMENT,
+               `stamp` timestamp DEFAULT CURRENT_TIMESTAMP,
+               `user` tinyint(3) unsigned NOT NULL DEFAULT '0',
+               `msg`  varchar(255) DEFAULT '',
+               `entry`  varchar(255) DEFAULT '',
+               `data` text DEFAULT NULL,
+       PRIMARY KEY (`id`)
+) ENGINE=MyISAM;
+
 -- Structure of table `0_debtor_trans` --
 
 DROP TABLE IF EXISTS `0_debtor_trans`;
@@ -1293,20 +1304,6 @@ CREATE TABLE `0_shippers` (
 INSERT INTO `0_shippers` VALUES
 ('1', 'Default', '', '', '', '', '0');
 
--- Structure of table `0_sql_trail` --
-
-DROP TABLE IF EXISTS `0_sql_trail`;
-
-CREATE TABLE `0_sql_trail` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
-  `sql` text NOT NULL,
-  `result` tinyint(1) NOT NULL,
-  `msg` varchar(255) NOT NULL,
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB ;
-
--- Data of table `0_sql_trail` --
-
 -- Structure of table `0_stock_category` --
 
 DROP TABLE IF EXISTS `0_stock_category`;
index 8b37ddf4d31d4db435b32821f3ef89baea5a15ef..cca4df026ecbf63bdf378e81e9592b75b4eea09b 100644 (file)
@@ -11,7 +11,7 @@
 ***********************************************************************/
 function add_item_tax_type($name, $exempt, $exempt_from)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        
        $sql = "INSERT INTO ".TB_PREF."item_tax_types (name, exempt) 
                VALUES (".db_escape($name).",".db_escape($exempt).")";
@@ -28,7 +28,7 @@ function add_item_tax_type($name, $exempt, $exempt_from)
 
 function update_item_tax_type($id, $name, $exempt, $exempt_from)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
        
        $sql = "UPDATE ".TB_PREF."item_tax_types SET name=".db_escape($name).
        ",      exempt=".db_escape($exempt)." WHERE id=".db_escape($id);
@@ -76,7 +76,7 @@ function get_item_tax_type_for_item($stock_id)
 
 function delete_item_tax_type($id)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
                
        $sql = "DELETE FROM ".TB_PREF."item_tax_types WHERE id=".db_escape($id);
                
index ef91b3ea4f7cc5fdf8134a15d3afa764387fe417..74c0923445e294c080c49de50b10582d1d5e0af8 100644 (file)
@@ -11,7 +11,7 @@
 ***********************************************************************/
 function add_tax_group($name, $taxes, $tax_area)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $sql = "INSERT INTO ".TB_PREF."tax_groups (name, tax_area) VALUES (".db_escape($name).",".db_escape($tax_area).")";
        db_query($sql, "could not add tax group");
@@ -25,7 +25,7 @@ function add_tax_group($name, $taxes, $tax_area)
 
 function update_tax_group($id, $name, $taxes, $tax_area)
 {
-       begin_transaction();    
+       begin_transaction(__FUNCTION__, func_get_args());
 
     $sql = "UPDATE ".TB_PREF."tax_groups SET name=".db_escape($name).",tax_area=".db_escape($tax_area)." WHERE id=".db_escape($id);
        db_query($sql, "could not update tax group");
@@ -55,7 +55,7 @@ function get_tax_group($type_id)
 
 function delete_tax_group($id)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
                
        $sql = "DELETE FROM ".TB_PREF."tax_groups WHERE id=".db_escape($id);
                
index ce73935f61b95c17756865ac824b3ebf605b211c..850b1f5b1372ac6a281d64ed58217bf64f7e7252 100644 (file)
 ***********************************************************************/
 function add_tax_type($name, $sales_gl_code, $purchasing_gl_code, $rate)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "INSERT INTO ".TB_PREF."tax_types (name, sales_gl_code, purchasing_gl_code, rate)
                VALUES (".db_escape($name).", ".db_escape($sales_gl_code)
                .", ".db_escape($purchasing_gl_code).", $rate)";
 
        db_query($sql, "could not add tax type");
+       commit_transaction();
 }
 
 function update_tax_type($type_id, $name, $sales_gl_code, $purchasing_gl_code, $rate)
 {
+       begin_transaction(__FUNCTION__, func_get_args());
        $sql = "UPDATE ".TB_PREF."tax_types SET name=".db_escape($name).",
                sales_gl_code=".db_escape($sales_gl_code).",
                purchasing_gl_code=".db_escape($purchasing_gl_code).",
@@ -27,6 +30,7 @@ function update_tax_type($type_id, $name, $sales_gl_code, $purchasing_gl_code, $
                WHERE id=".db_escape($type_id);
 
        db_query($sql, "could not update tax type");
+       commit_transaction();
 }
 
 function get_all_tax_types($all=false)
@@ -78,7 +82,7 @@ function get_tax_type_rate($type_id)
 
 function delete_tax_type($type_id)
 {
-       begin_transaction();
+       begin_transaction(__FUNCTION__, func_get_args());
 
        $sql = "DELETE FROM ".TB_PREF."tax_types WHERE id=".db_escape($type_id);