From 89e8ca2be9235215ac2e2bf5e58d7eedd2dda84d Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Fri, 26 Jul 2019 21:01:03 +0200 Subject: [PATCH] Old ineffective sql_trail superseded by new improved db_trail logging only calls changing database content. --- admin/db/attachments_db.inc | 12 ++ admin/db/company_db.inc | 30 +++- admin/db/fiscalyears_db.inc | 33 ++-- admin/db/maintenance_db.inc | 6 +- admin/db/printers_db.inc | 24 ++- admin/db/security_db.inc | 20 +++ admin/db/shipping_db.inc | 14 ++ admin/db/tags_db.inc | 27 ++- admin/db/users_db.inc | 34 +++- admin/fiscalyears.php | 12 ++ admin/security_roles.php | 22 +-- config.default.php | 12 +- dimensions/includes/dimensions_db.inc | 10 +- fixed_assets/includes/fa_classes_db.inc | 8 +- fixed_assets/includes/fixed_assets_db.inc | 2 +- gl/gl_bank.php | 10 +- gl/includes/db/gl_db_account_types.inc | 31 +++- gl/includes/db/gl_db_accounts.inc | 18 +- gl/includes/db/gl_db_bank_accounts.inc | 36 +++- gl/includes/db/gl_db_bank_trans.inc | 2 +- gl/includes/db/gl_db_banking.inc | 12 +- gl/includes/db/gl_db_currencies.inc | 12 ++ gl/includes/db/gl_db_rates.inc | 10 ++ gl/includes/db/gl_db_trans.inc | 24 +-- gl/includes/db/gl_journal.inc | 10 +- gl/includes/gl_db.inc | 4 +- gl/includes/ui/gl_journal_ui.inc | 1 + includes/current_user.inc | 4 +- includes/db/audit_trail_db.inc | 4 +- includes/db/class.reflines_db.inc | 6 +- includes/db/connect_db_mysql.inc | 16 +- includes/db/connect_db_mysqli.inc | 15 +- includes/db/crm_contacts_db.inc | 30 +++- includes/db/sql_functions.inc | 28 ++- inventory/includes/db/items_adjust_db.inc | 4 +- inventory/includes/db/items_category_db.inc | 6 + inventory/includes/db/items_db.inc | 6 + inventory/includes/db/items_locations_db.inc | 8 + inventory/includes/db/items_prices_db.inc | 6 + inventory/includes/db/items_purchases_db.inc | 6 + inventory/includes/db/items_trans_db.inc | 81 --------- inventory/includes/db/items_transfer_db.inc | 4 +- inventory/includes/db/items_units_db.inc | 5 + inventory/includes/inventory_db.inc | 96 +++++++++- inventory/manage/items.php | 26 +-- manufacturing/includes/db/work_centres_db.inc | 6 + .../includes/db/work_order_costing_db.inc | 10 +- .../includes/db/work_order_issues_db.inc | 4 +- .../db/work_order_produce_items_db.inc | 4 +- .../db/work_order_requirements_db.inc | 8 + manufacturing/includes/db/work_orders_db.inc | 10 +- purchasing/allocations/supplier_allocate.php | 2 +- purchasing/includes/db/grn_db.inc | 4 +- purchasing/includes/db/invoice_db.inc | 4 +- purchasing/includes/db/po_db.inc | 6 +- purchasing/includes/db/supp_payment_db.inc | 4 +- purchasing/includes/db/suppliers_db.inc | 6 + purchasing/includes/purchasing_db.inc | 47 ++++- purchasing/manage/suppliers.php | 32 +--- sales/allocations/customer_allocate.php | 3 +- sales/create_recurrent_invoices.php | 77 +------- sales/credit_note_entry.php | 2 +- sales/customer_credit_invoice.php | 3 +- sales/customer_delivery.php | 2 +- sales/customer_invoice.php | 2 +- sales/customer_payments.php | 12 +- sales/includes/db/branches_db.inc | 6 + sales/includes/db/credit_status_db.inc | 9 + sales/includes/db/customers_db.inc | 2 +- sales/includes/db/payment_db.inc | 4 +- sales/includes/db/recurrent_invoices_db.inc | 46 +++++ sales/includes/db/sales_credit_db.inc | 3 +- sales/includes/db/sales_delivery_db.inc | 4 +- sales/includes/db/sales_groups_db.inc | 21 +++ sales/includes/db/sales_invoice_db.inc | 4 +- sales/includes/db/sales_order_db.inc | 6 +- sales/includes/db/sales_points_db.inc | 8 +- sales/includes/db/sales_types_db.inc | 13 +- sales/includes/sales_db.inc | 165 ++++++++++++++++++ sales/manage/customer_branches.php | 28 +-- sales/manage/customers.php | 43 +---- sales/manage/recurrent_invoices.php | 17 +- sales/sales_order_entry.php | 3 +- sql/alter2.5.sql | 12 ++ sql/en_US-demo.sql | 26 ++- sql/en_US-new.sql | 25 ++- taxes/db/item_tax_types_db.inc | 6 +- taxes/db/tax_groups_db.inc | 6 +- taxes/db/tax_types_db.inc | 6 +- 89 files changed, 995 insertions(+), 503 deletions(-) delete mode 100644 inventory/includes/db/items_trans_db.inc diff --git a/admin/db/attachments_db.inc b/admin/db/attachments_db.inc index f3c46dc4..561bea33 100644 --- a/admin/db/attachments_db.inc +++ b/admin/db/attachments_db.inc @@ -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(); } //---------------------------------------------------------------------------------------- diff --git a/admin/db/company_db.inc b/admin/db/company_db.inc index 39108db8..8e788532 100644 --- a/admin/db/company_db.inc +++ b/admin/db/company_db.inc @@ -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; } diff --git a/admin/db/fiscalyears_db.inc b/admin/db/fiscalyears_db.inc index 1d1d94a8..d93b3341 100644 --- a/admin/db/fiscalyears_db.inc +++ b/admin/db/fiscalyears_db.inc @@ -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']; diff --git a/admin/db/maintenance_db.inc b/admin/db/maintenance_db.inc index 9fa78b99..880a4384 100644 --- a/admin/db/maintenance_db.inc +++ b/admin/db/maintenance_db.inc @@ -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 diff --git a/admin/db/printers_db.inc b/admin/db/printers_db.inc index 28c98a56..0932b92f 100644 --- a/admin/db/printers_db.inc +++ b/admin/db/printers_db.inc @@ -12,18 +12,23 @@ 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. diff --git a/admin/db/security_db.inc b/admin/db/security_db.inc index 70027c2e..67cbd625 100644 --- a/admin/db/security_db.inc +++ b/admin/db/security_db.inc @@ -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(); +} diff --git a/admin/db/shipping_db.inc b/admin/db/shipping_db.inc index 6eca60de..6d46e250 100644 --- a/admin/db/shipping_db.inc +++ b/admin/db/shipping_db.inc @@ -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(); } //-------------------------------------------------------------------------------------- diff --git a/admin/db/tags_db.inc b/admin/db/tags_db.inc index 08cb13c6..c5b0e45a 100644 --- a/admin/db/tags_db.inc +++ b/admin/db/tags_db.inc @@ -12,16 +12,21 @@ 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(); } //-------------------------------------------------------------------------------------- diff --git a/admin/db/users_db.inc b/admin/db/users_db.inc index 52b02411..10409305 100644 --- a/admin/db/users_db.inc +++ b/admin/db/users_db.inc @@ -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(); } //----------------------------------------------------------------------------------------------- diff --git a/admin/fiscalyears.php b/admin/fiscalyears.php index d6d05c5a..8874ea7d 100644 --- a/admin/fiscalyears.php +++ b/admin/fiscalyears.php @@ -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 diff --git a/admin/security_roles.php b/admin/security_roles.php index 4b438091..7e68d373 100644 --- a/admin/security_roles.php +++ b/admin/security_roles.php @@ -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'); diff --git a/config.default.php b/config.default.php index acd3ddc6..3630dfc7 100644 --- a/config.default.php +++ b/config.default.php @@ -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"; diff --git a/dimensions/includes/dimensions_db.inc b/dimensions/includes/dimensions_db.inc index 13c91fd4..dd7edad1 100644 --- a/dimensions/includes/dimensions_db.inc +++ b/dimensions/includes/dimensions_db.inc @@ -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(); } //-------------------------------------------------------------------------------------- diff --git a/fixed_assets/includes/fa_classes_db.inc b/fixed_assets/includes/fa_classes_db.inc index 37fb5ceb..2b5420e3 100644 --- a/fixed_assets/includes/fa_classes_db.inc +++ b/fixed_assets/includes/fa_classes_db.inc @@ -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(); } diff --git a/fixed_assets/includes/fixed_assets_db.inc b/fixed_assets/includes/fixed_assets_db.inc index 11c9c027..b74dd001 100644 --- a/fixed_assets/includes/fixed_assets_db.inc +++ b/fixed_assets/includes/fixed_assets_db.inc @@ -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_)) diff --git a/gl/gl_bank.php b/gl/gl_bank.php index b1111153..2ff551c7 100644 --- a/gl/gl_bank.php +++ b/gl/gl_bank.php @@ -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(); diff --git a/gl/includes/db/gl_db_account_types.inc b/gl/includes/db/gl_db_account_types.inc index 4d6d58e8..3a9d2af8 100644 --- a/gl/includes/db/gl_db_account_types.inc +++ b/gl/includes/db/gl_db_account_types.inc @@ -11,15 +11,20 @@ ***********************************************************************/ 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(); + } diff --git a/gl/includes/db/gl_db_accounts.inc b/gl/includes/db/gl_db_accounts.inc index 6bc73abd..a9f309b8 100644 --- a/gl/includes/db/gl_db_accounts.inc +++ b/gl/includes/db/gl_db_accounts.inc @@ -11,27 +11,39 @@ ***********************************************************************/ 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) diff --git a/gl/includes/db/gl_db_bank_accounts.inc b/gl/includes/db/gl_db_bank_accounts.inc index ea9a83ac..01feb5d1 100644 --- a/gl/includes/db/gl_db_bank_accounts.inc +++ b/gl/includes/db/gl_db_bank_accounts.inc @@ -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(); } //--------------------------------------------------------------------------------------------- diff --git a/gl/includes/db/gl_db_bank_trans.inc b/gl/includes/db/gl_db_bank_trans.inc index 747041b6..e8d81905 100644 --- a/gl/includes/db/gl_db_bank_trans.inc +++ b/gl/includes/db/gl_db_bank_trans.inc @@ -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 diff --git a/gl/includes/db/gl_db_banking.inc b/gl/includes/db/gl_db_banking.inc index 7817fe3f..03623b6e 100644 --- a/gl/includes/db/gl_db_banking.inc +++ b/gl/includes/db/gl_db_banking.inc @@ -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; diff --git a/gl/includes/db/gl_db_currencies.inc b/gl/includes/db/gl_db_currencies.inc index 0efa4207..b725c113 100644 --- a/gl/includes/db/gl_db_currencies.inc +++ b/gl/includes/db/gl_db_currencies.inc @@ -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(); } //--------------------------------------------------------------------------------------------- diff --git a/gl/includes/db/gl_db_rates.inc b/gl/includes/db/gl_db_rates.inc index 4118492e..924587d8 100644 --- a/gl/includes/db/gl_db_rates.inc +++ b/gl/includes/db/gl_db_rates.inc @@ -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(); } //----------------------------------------------------------------------------- diff --git a/gl/includes/db/gl_db_trans.inc b/gl/includes/db/gl_db_trans.inc index 15e2c84a..98c2e896 100644 --- a/gl/includes/db/gl_db_trans.inc +++ b/gl/includes/db/gl_db_trans.inc @@ -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) { diff --git a/gl/includes/db/gl_journal.inc b/gl/includes/db/gl_journal.inc index b3378b0c..d35024b9 100644 --- a/gl/includes/db/gl_journal.inc +++ b/gl/includes/db/gl_journal.inc @@ -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(); } diff --git a/gl/includes/gl_db.inc b/gl/includes/gl_db.inc index 951af9ee..7a9c4900 100644 --- a/gl/includes/gl_db.inc +++ b/gl/includes/gl_db.inc @@ -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); diff --git a/gl/includes/ui/gl_journal_ui.inc b/gl/includes/ui/gl_journal_ui.inc index ae8860da..0a6b4554 100644 --- a/gl/includes/ui/gl_journal_ui.inc +++ b/gl/includes/ui/gl_journal_ui.inc @@ -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); diff --git a/includes/current_user.inc b/includes/current_user.inc index c3d162e0..5d4d5f0e 100644 --- a/includes/current_user.inc +++ b/includes/current_user.inc @@ -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(); diff --git a/includes/db/audit_trail_db.inc b/includes/db/audit_trail_db.inc index c142abdb..e297d2ba 100644 --- a/includes/db/audit_trail_db.inc +++ b/includes/db/audit_trail_db.inc @@ -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 diff --git a/includes/db/class.reflines_db.inc b/includes/db/class.reflines_db.inc index 277ebe74..413d2983 100644 --- a/includes/db/class.reflines_db.inc +++ b/includes/db/class.reflines_db.inc @@ -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; } } diff --git a/includes/db/connect_db_mysql.inc b/includes/db/connect_db_mysql.inc index 4be5a295..4acf3e47 100644 --- a/includes/db/connect_db_mysql.inc +++ b/includes/db/connect_db_mysql.inc @@ -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() diff --git a/includes/db/connect_db_mysqli.inc b/includes/db/connect_db_mysqli.inc index 696fd828..ee7ad583 100644 --- a/includes/db/connect_db_mysqli.inc +++ b/includes/db/connect_db_mysqli.inc @@ -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() diff --git a/includes/db/crm_contacts_db.inc b/includes/db/crm_contacts_db.inc index e5a91fb1..463a3fde 100644 --- a/includes/db/crm_contacts_db.inc +++ b/includes/db/crm_contacts_db.inc @@ -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) diff --git a/includes/db/sql_functions.inc b/includes/db/sql_functions.inc index 66a781d2..3b4b5acd 100644 --- a/includes/db/sql_functions.inc +++ b/includes/db/sql_functions.inc @@ -16,12 +16,23 @@ // 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"); } } diff --git a/inventory/includes/db/items_adjust_db.inc b/inventory/includes/db/items_adjust_db.inc index 0085f983..07137bf2 100644 --- a/inventory/includes/db/items_adjust_db.inc +++ b/inventory/includes/db/items_adjust_db.inc @@ -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(); } //------------------------------------------------------------------------------------------------------------- diff --git a/inventory/includes/db/items_category_db.inc b/inventory/includes/db/items_category_db.inc index 48984bb6..78f7092d 100644 --- a/inventory/includes/db/items_category_db.inc +++ b/inventory/includes/db/items_category_db.inc @@ -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) diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index 57ddf316..59859003 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -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) diff --git a/inventory/includes/db/items_locations_db.inc b/inventory/includes/db/items_locations_db.inc index e85d39a1..9fd54b62 100644 --- a/inventory/includes/db/items_locations_db.inc +++ b/inventory/includes/db/items_locations_db.inc @@ -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(); } //------------------------------------------------------------------------------------ diff --git a/inventory/includes/db/items_prices_db.inc b/inventory/includes/db/items_prices_db.inc index 5a474e7c..5fee90e7 100644 --- a/inventory/includes/db/items_prices_db.inc +++ b/inventory/includes/db/items_prices_db.inc @@ -11,26 +11,32 @@ ***********************************************************************/ 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) diff --git a/inventory/includes/db/items_purchases_db.inc b/inventory/includes/db/items_purchases_db.inc index eecd9123..2e3a5e35 100644 --- a/inventory/includes/db/items_purchases_db.inc +++ b/inventory/includes/db/items_purchases_db.inc @@ -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 index dfbc5eeb..00000000 --- a/inventory/includes/db/items_trans_db.inc +++ /dev/null @@ -1,81 +0,0 @@ -. -***********************************************************************/ -//------------------------------------------------------------------------------------------------------------- - -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; -} diff --git a/inventory/includes/db/items_transfer_db.inc b/inventory/includes/db/items_transfer_db.inc index f35bf369..b4b0180e 100644 --- a/inventory/includes/db/items_transfer_db.inc +++ b/inventory/includes/db/items_transfer_db.inc @@ -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(); } diff --git a/inventory/includes/db/items_units_db.inc b/inventory/includes/db/items_units_db.inc index d90b03b3..ee9f1746 100644 --- a/inventory/includes/db/items_units_db.inc +++ b/inventory/includes/db/items_units_db.inc @@ -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) diff --git a/inventory/includes/inventory_db.inc b/inventory/includes/inventory_db.inc index 7b672fae..25e60d36 100644 --- a/inventory/includes/inventory_db.inc +++ b/inventory/includes/inventory_db.inc @@ -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(); +} diff --git a/inventory/manage/items.php b/inventory/manage/items.php index fb3905a5..f0644a98 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -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'] = ''; diff --git a/manufacturing/includes/db/work_centres_db.inc b/manufacturing/includes/db/work_centres_db.inc index 1d15d7c2..cd6bc7c3 100644 --- a/manufacturing/includes/db/work_centres_db.inc +++ b/manufacturing/includes/db/work_centres_db.inc @@ -11,18 +11,22 @@ ***********************************************************************/ 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(); } diff --git a/manufacturing/includes/db/work_order_costing_db.inc b/manufacturing/includes/db/work_order_costing_db.inc index 3641d8f7..f610356b 100644 --- a/manufacturing/includes/db/work_order_costing_db.inc +++ b/manufacturing/includes/db/work_order_costing_db.inc @@ -1,4 +1,5 @@ write(); + write_supp_allocation($_SESSION['alloc']); clear_allocations(); $_POST['Cancel'] = 1; } diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index fbf231f4..f5df6084 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -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); diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 07e87eb0..d59e0af5 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -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); diff --git a/purchasing/includes/db/po_db.inc b/purchasing/includes/db/po_db.inc index e7257e00..6b74c67c 100644 --- a/purchasing/includes/db/po_db.inc +++ b/purchasing/includes/db/po_db.inc @@ -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 */ diff --git a/purchasing/includes/db/supp_payment_db.inc b/purchasing/includes/db/supp_payment_db.inc index 40bafa3f..62f56a79 100644 --- a/purchasing/includes/db/supp_payment_db.inc +++ b/purchasing/includes/db/supp_payment_db.inc @@ -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); diff --git a/purchasing/includes/db/suppliers_db.inc b/purchasing/includes/db/suppliers_db.inc index d66c89fc..2648ff60 100644 --- a/purchasing/includes/db/suppliers_db.inc +++ b/purchasing/includes/db/suppliers_db.inc @@ -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) diff --git a/purchasing/includes/purchasing_db.inc b/purchasing/includes/purchasing_db.inc index eb4a1ac4..f7fe7a5d 100644 --- a/purchasing/includes/purchasing_db.inc +++ b/purchasing/includes/purchasing_db.inc @@ -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; +} + diff --git a/purchasing/manage/suppliers.php b/purchasing/manage/suppliers.php index 9cab778f..3b0bab66 100644 --- a/purchasing/manage/suppliers.php +++ b/purchasing/manage/suppliers.php @@ -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'])) diff --git a/sales/allocations/customer_allocate.php b/sales/allocations/customer_allocate.php index 8c051386..68a1ff43 100644 --- a/sales/allocations/customer_allocate.php +++ b/sales/allocations/customer_allocate.php @@ -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; } diff --git a/sales/create_recurrent_invoices.php b/sales/create_recurrent_invoices.php index 989c7d03..043bbf8b 100644 --- a/sales/create_recurrent_invoices.php +++ b/sales/create_recurrent_invoices.php @@ -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 - 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) { diff --git a/sales/credit_note_entry.php b/sales/credit_note_entry.php index 2a3077b4..2f3bff18 100644 --- a/sales/credit_note_entry.php +++ b/sales/credit_note_entry.php @@ -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.")); diff --git a/sales/customer_credit_invoice.php b/sales/customer_credit_invoice.php index e482386b..c0a48eb1 100644 --- a/sales/customer_credit_invoice.php +++ b/sales/customer_credit_invoice.php @@ -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.")); diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index d0895890..1bec9393 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -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) { diff --git a/sales/customer_invoice.php b/sales/customer_invoice.php index ba0c8a41..20af722a 100644 --- a/sales/customer_invoice.php +++ b/sales/customer_invoice.php @@ -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.")); diff --git a/sales/customer_payments.php b/sales/customer_payments.php index 907f789e..30d5151c 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -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"); diff --git a/sales/includes/db/branches_db.inc b/sales/includes/db/branches_db.inc index e51de6f1..ec439d12 100644 --- a/sales/includes/db/branches_db.inc +++ b/sales/includes/db/branches_db.inc @@ -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) diff --git a/sales/includes/db/credit_status_db.inc b/sales/includes/db/credit_status_db.inc index c80cdc90..81975db7 100644 --- a/sales/includes/db/credit_status_db.inc +++ b/sales/includes/db/credit_status_db.inc @@ -11,18 +11,25 @@ ***********************************************************************/ 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(); } diff --git a/sales/includes/db/customers_db.inc b/sales/includes/db/customers_db.inc index 0dfc17e2..3191e8a6 100644 --- a/sales/includes/db/customers_db.inc +++ b/sales/includes/db/customers_db.inc @@ -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); diff --git a/sales/includes/db/payment_db.inc b/sales/includes/db/payment_db.inc index 9560179f..7eb77dfb 100644 --- a/sales/includes/db/payment_db.inc +++ b/sales/includes/db/payment_db.inc @@ -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); diff --git a/sales/includes/db/recurrent_invoices_db.inc b/sales/includes/db/recurrent_invoices_db.inc index 7d74dd20..66a6a87f 100644 --- a/sales/includes/db/recurrent_invoices_db.inc +++ b/sales/includes/db/recurrent_invoices_db.inc @@ -13,17 +13,20 @@ 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; +} + diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index 998a6a20..105007bd 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -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(); diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 3c260a52..4a4a8a81 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -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); diff --git a/sales/includes/db/sales_groups_db.inc b/sales/includes/db/sales_groups_db.inc index f68a3bb6..cadae2a7 100644 --- a/sales/includes/db/sales_groups_db.inc +++ b/sales/includes/db/sales_groups_db.inc @@ -12,20 +12,27 @@ 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) diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 862df0a4..22d34e8a 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -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); diff --git a/sales/includes/db/sales_order_db.inc b/sales/includes/db/sales_order_db.inc index 968777ab..e76ea3ee 100644 --- a/sales/includes/db/sales_order_db.inc +++ b/sales/includes/db/sales_order_db.inc @@ -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) diff --git a/sales/includes/db/sales_points_db.inc b/sales/includes/db/sales_points_db.inc index b5abaef7..3f2bc409 100644 --- a/sales/includes/db/sales_points_db.inc +++ b/sales/includes/db/sales_points_db.inc @@ -11,14 +11,17 @@ ***********************************************************************/ 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(); } diff --git a/sales/includes/db/sales_types_db.inc b/sales/includes/db/sales_types_db.inc index a0279d3e..178b3d68 100644 --- a/sales/includes/db/sales_types_db.inc +++ b/sales/includes/db/sales_types_db.inc @@ -11,18 +11,25 @@ ***********************************************************************/ 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(); } diff --git a/sales/includes/sales_db.inc b/sales/includes/sales_db.inc index 26e92955..e870b833 100644 --- a/sales/includes/sales_db.inc +++ b/sales/includes/sales_db.inc @@ -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 + 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; +} + diff --git a/sales/manage/customer_branches.php b/sales/manage/customer_branches.php index 8902135a..ee33fa86 100644 --- a/sales/manage/customer_branches.php +++ b/sales/manage/customer_branches.php @@ -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']) { diff --git a/sales/manage/customers.php b/sales/manage/customers.php index 01d9fe50..e51e4b48 100644 --- a/sales/manage/customers.php +++ b/sales/manage/customers.php @@ -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.")); diff --git a/sales/manage/recurrent_invoices.php b/sales/manage/recurrent_invoices.php index fef2ddc0..036819b5 100644 --- a/sales/manage/recurrent_invoices.php +++ b/sales/manage/recurrent_invoices.php @@ -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') { diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index 77e975d4..a604af69 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -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.")); diff --git a/sql/alter2.5.sql b/sql/alter2.5.sql index 1511ff11..3994822e 100644 --- a/sql/alter2.5.sql +++ b/sql/alter2.5.sql @@ -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; diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index b6cdf6e1..b62e9675 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -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`; diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 7cfb0fc9..9e22d3cc 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -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`; diff --git a/taxes/db/item_tax_types_db.inc b/taxes/db/item_tax_types_db.inc index 8b37ddf4..cca4df02 100644 --- a/taxes/db/item_tax_types_db.inc +++ b/taxes/db/item_tax_types_db.inc @@ -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); diff --git a/taxes/db/tax_groups_db.inc b/taxes/db/tax_groups_db.inc index ef91b3ea..74c09234 100644 --- a/taxes/db/tax_groups_db.inc +++ b/taxes/db/tax_groups_db.inc @@ -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); diff --git a/taxes/db/tax_types_db.inc b/taxes/db/tax_types_db.inc index ce73935f..850b1f5b 100644 --- a/taxes/db/tax_types_db.inc +++ b/taxes/db/tax_types_db.inc @@ -11,15 +11,18 @@ ***********************************************************************/ 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); -- 2.30.2