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).","
.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).",
}
$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();
}
//----------------------------------------------------------------------------------------
*/
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),
// update cached value
$_SESSION['SysPrefs']->prefs[$name] = $value;
}
+
+ commit_transaction();
return true;
}
/*
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()
function add_payment_terms($daysOrFoll, $terms, $dayNumber)
{
+ begin_transaction(__FUNCTION__, func_get_args());
+
if ($daysOrFoll)
{
$sql = "INSERT INTO ".TB_PREF."payment_terms (terms,
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) . ",
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)
$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];
}
{
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
}
$db = $_SESSION["wa_current_user"]->set_db_connection($comp);
$_SESSION['wa_current_user']->prefs->theme = 'default';
+
+ commit_transaction();
return true;
}
// 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);
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()
function delete_fiscalyear($id)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$sql="DELETE FROM ".TB_PREF."fiscal_year WHERE id=".db_escape($id);
{
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'];
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();
}
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'];
{
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',
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
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()
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 "
return false;
}
}
+
+ commit_transaction();
return true;
}
//
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.
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).","
.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();
}
//--------------------------------------------------------------------------------------------------
$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();
+}
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). ", " .
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). " ,
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();
}
//--------------------------------------------------------------------------------------
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)
$sql .= " WHERE id = ".db_escape($id);
- return db_query($sql);
+ $result = db_query($sql);
+ commit_transaction();
+ return $result;
}
//--------------------------------------------------------------------------------------
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)
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();
}
//--------------------------------------------------------------------------------------
//
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
record_id = '".$ta['record_id']."' AND tag_id=".$ta['tag_id'];
db_query($sql2, "could not delete tag associations");
}
+
+ commit_transaction();
}
//--------------------------------------------------------------------------------------
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).",
.", ".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;
}
//-----------------------------------------------------------------------------------------------
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).",
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;
}
//-----------------------------------------------------------------------------------------------
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();
}
//-----------------------------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------------------------
-
-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();
}
//-----------------------------------------------------------------------------------------------
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
}
// $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');
$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";
{
global $Refs;
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$date = date2sql($date_);
$duedate = date2sql($due_date);
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);
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);
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();
}
//--------------------------------------------------------------------------------------
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).",
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).", "
.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();
}
$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_))
return true;
}
-//-----------------------------------------------------------------------------------------------
-
function handle_update_item()
{
$amount = ($_SESSION['pay_items']->trans_type==ST_BANKPAYMENT ? 1:-1) * input_num('amount');
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())
$_POST['dimension2_id'], $amount, $_POST['LineMemo']);
line_start_focus();
}
+
//-----------------------------------------------------------------------------------------------
+
$id = find_submit('Delete');
if ($id != -1)
handle_delete_item($id);
end_form();
-//------------------------------------------------------------------------------------------------
-
end_page();
***********************************************************************/
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
." WHERE id = ".db_escape($old_id);
$ret = db_query($sql, "could not update account type");
+
commit_transaction();
return $ret;
}
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)
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();
+
}
***********************************************************************/
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)
$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);
", ".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;
}
//---------------------------------------------------------------------------------------------
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);
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();
}
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
".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)
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();
}
//---------------------------------------------------------------------------------------------
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);
WHERE id=".db_escape($bank_account);
db_query($sql2,"Error updating reconciliation information");
+
+ commit_transaction();
}
//---------------------------------------------------------------------------------------------
{
if (!$nested)
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$sql = "UPDATE ".TB_PREF."bank_trans
SET amount=0
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";
{
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);
$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);
$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;
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)
." WHERE curr_abrev = ".db_escape($curr_abrev);
db_query($sql, "could not update currency for $curr_abrev");
+ commit_transaction();
}
//---------------------------------------------------------------------------------------------
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).", "
.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();
}
//---------------------------------------------------------------------------------------------
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();
}
//---------------------------------------------------------------------------------------------
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();
}
//---------------------------------------------------------------------------------------------
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();
}
//-----------------------------------------------------------------------------
***********************************************************************/
//--------------------------------------------------------------------------------
-// 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
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))
.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)
." 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)
//----------------------------------------------------------------------------------------
-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)
{
$trans_type = $cart->trans_type;
$new = $cart->order_id == 0;
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
if (!$new)
{
//----------------------------------------------------------------------------------------
-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);
void_bank_trans($type, $type_no, true);
- if ($use_transaction)
- commit_transaction();
+ commit_transaction();
}
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);
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);
}
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);
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;
$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();
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"
*/
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
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 ";
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;
}
}
$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;
{
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()
$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;
{
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()
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 ("
.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))
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) . ", "
."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))
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);
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");
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);
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) . ", "
.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) . ",";
."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)
// 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++;
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");
}
}
{
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;
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();
}
//-------------------------------------------------------------------------------------------------------------
$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,
.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,
$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).","
."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)
$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).",
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,
$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,
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");
db_query($sql, "could not delete stock item bom");
delete_item_kit($stock_id);
+ commit_transaction();
}
function get_item($stock_id)
***********************************************************************/
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).", "
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();
}
//------------------------------------------------------------------------------------
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).",
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();
}
//------------------------------------------------------------------------------------
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();
}
//------------------------------------------------------------------------------------
***********************************************************************/
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)
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). ", "
.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 . ",
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)
+++ /dev/null
-<?php
-/**********************************************************************
- Copyright (C) FrontAccounting, LLC.
- Released under the terms of the GNU General Public License, GPL,
- as published by the Free Software Foundation, either version 3
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
-***********************************************************************/
-//-------------------------------------------------------------------------------------------------------------
-
-function stock_cost_update($stock_id, $material_cost, $labour_cost, $overhead_cost,
- $last_cost, $refline, $memo_)
-{
- $mb_flag = get_mb_flag($stock_id);
-
- $update_no = -1;
-
- if (is_service($mb_flag))
- {
- $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
- WHERE stock_id=".db_escape($stock_id);
-
- db_query($sql,"The cost details for the inventory item could not be updated");
-
- return $update_no;
- }
-
- begin_transaction();
-
- $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost).",
- labour_cost=".db_escape($labour_cost).",
- overhead_cost=".db_escape($overhead_cost)."
- WHERE stock_id=".db_escape($stock_id);
- db_query($sql,"The cost details for the inventory item could not be updated");
-
- $qoh = get_qoh_on_date($stock_id);
-
- $date_ = Today();
- if (!is_date_in_fiscalyear($date_))
- $date_ = end_fiscalyear();
-
- if ($qoh > 0)
- {
- $new_cost = $material_cost + $labour_cost + $overhead_cost;
-
- $value_of_change = round2($qoh * ($new_cost - $last_cost), user_price_dec());
-
- if ($value_of_change != 0)
- {
- global $Refs;
- $stock_gl_code = get_stock_gl_code($stock_id);
-
- $cart = new items_cart(ST_COSTUPDATE);
- $cart->tran_date = $cart->doc_date = $cart->event_date = $date_;
- if (!is_date_in_fiscalyear($cart->tran_date))
- $cart->tran_date = end_fiscalyear();
- $cart->reference = $Refs->get_next(ST_COSTUPDATE, $refline, $cart->tran_date, $date_);
-
- if (empty($memo_))
- $cart->memo_ = sprintf(_("Cost was %s changed to %s x quantity on hand of %s"),
- number_format2($last_cost, 2), number_format2($new_cost), $qoh);
- else
- $cart->memo_ = $memo_;
-
- $cart->add_gl_item($stock_gl_code["adjustment_account"],
- $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], -$value_of_change);
- $cart->add_gl_item($stock_gl_code["inventory_account"], 0, 0, $value_of_change);
-
- write_journal_entries($cart);
- }
- }
-
- if ($update_no != -1)
- add_audit_trail(ST_COSTUPDATE, $update_no, $date_);
- commit_transaction();
-
- return $update_no;
-}
{
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);
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();
}
***********************************************************************/
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).",
".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)
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");
$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();
+}
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'],
$_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'] = '';
***********************************************************************/
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)
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();
}
<?php
+
/**********************************************************************
Copyright (C) FrontAccounting, LLC.
Released under the terms of the GNU General Public License, GPL,
function add_wo_costing($workorder_id, $cost_type, $trans_type, $trans_no, $factor=1)
{
+ begin_transaction(__FUNCTION__, func_get_args());
$sql = "INSERT INTO ".TB_PREF."wo_costing (workorder_id, cost_type, trans_type, trans_no, factor)
VALUES (".db_escape($workorder_id).","
.db_escape($cost_type).",".db_escape($trans_type).","
.db_escape($trans_no).",".db_escape($factor).")";
db_query($sql, "could not add work order costing");
-
+ commit_transaction();
}
function get_wo_costing($workorder_id)
function delete_wo_costing($trans_type, $trans_no)
{
+ begin_transaction(__FUNCTION__, func_get_args());
$sql="DELETE FROM ".TB_PREF."wo_costing WHERE trans_type=".db_escape($trans_type)
." AND trans_no=".db_escape($trans_no);
db_query($sql, "could not delete work order costing");
+ commit_transaction();
}
/*
//
global $Refs, $wo_cost_types;
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$journal_id = get_next_trans_no(ST_JOURNAL);
{
global $Refs;
+ begin_transaction(__FUNCTION__, func_get_args());
$res = get_wo_costing($wo_id);
while($row = db_fetch($res))
$sql = "DELETE FROM ".TB_PREF."wo_costing WHERE workorder_id=".db_escape($wo_id);
db_query($sql, "could not delete work order costing");
+ commit_transaction();
}
{
global $Refs;
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$args = func_get_args();
$args = (object)array_combine(array('woid', 'ref', 'to_work_order', 'items', 'location',
'workcentre', 'date_', 'memo_'), $args);
function void_work_order_issue($type_no)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
hook_db_prevoid(ST_MANUISSUE, $type_no);
$void_entry = get_voided_entry(ST_MANUISSUE, $type_no);
global $Refs;
// FIXME: support for WO_UNASSEMBLY case
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$args = func_get_args();
$args = (object)array_combine(array('woid', 'ref', 'quantity', 'date_', 'memo','close_wo'),
function void_work_order_produce($type_no)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
hook_db_prevoid(ST_MANURECEIVE, $type_no);
// Skip processing already voided entry i.e. explicitly voided
function create_wo_requirements($woid, $stock_id)
{
+ begin_transaction(__FUNCTION__, func_get_args());
$sql = "INSERT INTO ".TB_PREF."wo_requirements (workorder_id, stock_id, workcentre, units_req, loc_code)
SELECT ".db_escape($woid).", component, workcentre_added, quantity, loc_code
FROM ".TB_PREF."bom WHERE parent=".db_escape($stock_id);
db_query($sql, "The work order requirements could not be added");
+ commit_transaction();
}
//--------------------------------------------------------------------------------------
function delete_wo_requirements($woid)
{
+ begin_transaction(__FUNCTION__, func_get_args());
$sql="DELETE FROM ".TB_PREF."wo_requirements WHERE workorder_id=".db_escape($woid);
db_query($sql,"The work order requirements could not be deleted");
+ commit_transaction();
}
*/
function update_wo_requirement_issued($id, $quantity, $cost)
{
+ begin_transaction(__FUNCTION__, func_get_args());
$sql = "UPDATE ".TB_PREF."wo_requirements SET
unit_cost = (units_issued*unit_cost+".$quantity*$cost.")/(units_issued+".$quantity."),
units_issued = units_issued + ".db_escape($quantity)."
WHERE id = ".db_escape($id);
db_query($sql, "The work requirements issued quantity couldn't be updated");
+ commit_transaction();
}
//--------------------------------------------------------------------------------------
function void_wo_requirements($woid)
{
+ begin_transaction(__FUNCTION__, func_get_args());
$sql = "UPDATE ".TB_PREF."wo_requirements SET units_issued = 0
WHERE workorder_id = ".db_escape($woid);
db_query($sql, "The work requirements issued quantity couldn't be voided");
+ commit_transaction();
}
{
global $Refs;
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$args = func_get_args();
$args = (object)array_combine(array('wo_ref', 'loc_code', 'units_reqd', 'stock_id',
'type', 'date_', 'required_by', 'memo_', 'costs', 'cr_acc', 'labour', 'cr_lab_acc'), $args);
function update_work_order($woid, $loc_code, $units_reqd, $stock_id,
$date_, $required_by, $memo_)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$args = func_get_args();
$args = (object)array_combine(array('woid', 'loc_code', 'units_reqd', 'stock_id',
'date_', 'required_by', 'memo_'), $args);
function delete_work_order($woid, $stock_id, $qty, $date)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
hook_db_prevoid(ST_WORKORDER, $woid);
// delete the work order requirements
function release_work_order($woid, $releaseDate, $memo_)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
$myrow = get_work_order($woid);
$stock_id = $myrow["stock_id"];
*/
function void_work_order($woid)
{
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
hook_db_prevoid(ST_WORKORDER, $woid);
$work_order = get_work_order($woid);
{
if (check_allocations())
{
- $_SESSION['alloc']->write();
+ write_supp_allocation($_SESSION['alloc']);
clear_allocations();
$_POST['Cancel'] = 1;
}
$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))
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);
$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
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);
{
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");
{
global $Refs;
- begin_transaction();
+ begin_transaction(__FUNCTION__, func_get_args());
hook_db_prewrite($po_obj, ST_PURCHORDER);
/*Insert to purchase order header record */
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 */
{
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);
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);
$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,
.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,
$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) . ",
." 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)
return $allocations;
}
+
+//------------------------------------ Backend interfaces--------------------------------------------
+
//---------------------------------------------------------------------------------------------------
//
// Add Purchase Order, GRN or Purchase Invoice with parent auto documents (if any)
{
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)
$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)
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;
+}
+
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']))
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)
{
if (check_allocations())
{
- $_SESSION['alloc']->write();
+ write_cust_allocation($_SESSION['alloc']);
clear_allocations();
$_POST['Cancel'] = 1;
}
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)
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')
if ($id != -1)
{
- /*
- whole invoiced time is <begin, end>
- invoices are issued _after_ invoiced period is gone, eg:
- begin 1.1
- end 31.3
- period: invoice ready for issue since:
- 1.1-31.1 - 1.2
- 1.2-28.2 - 1.3
- 1.3-31.3 - 1.4
- In example above, when end is set to 1.4 will generate additional invoice on 1.5 !
- */
-
$Ajax->activate('_page_body');
- $from = get_post('from');
- $to = get_post('to');
- $memo = get_post('memo');
- $date = $_POST['trans_date'];
- $myrow = get_recurrent_invoice($id);
+ $invs = create_recurrent_invoices($id, get_post('from'), get_post('to'), get_post('trans_date'), get_post('memo'));
- $invs = array();
- if (recurrent_invoice_ready($id, $date))
- {
- begin_transaction();
-
- if ($myrow['debtor_no'] == 0)
- {
- $cust = get_cust_branches_from_group($myrow['group_no']);
- while ($row = db_fetch($cust))
- {
- $invs[] = create_recurrent_invoices($row['debtor_no'], $row['branch_code'], $myrow['order_no'], $myrow['id'],
- $date, $from, $to, $memo);
- }
- }
- else
- {
- $invs[] = create_recurrent_invoices($myrow['debtor_no'], $myrow['group_no'], $myrow['order_no'], $myrow['id'],
- $date, $from, $to, $memo);
- }
- commit_transaction();
- }
if (count($invs) > 0)
{
$min = min($invs);
}
+
$id = find_submit('create');
if ($id != -1)
{
$_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."));
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."));
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)
{
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."));
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");
$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,
.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,
$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). ",
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)
***********************************************************************/
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)
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();
}
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);
{
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);
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);
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).",
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)
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;
+}
+
{
global $Refs;
+ begin_transaction(__FUNCTION__, func_get_args());
+
if (is_array($credit_note->src_docs))
{
$docs = array_keys($credit_note->src_docs);
$credit_type = $write_off_acc == 0 ? 'Return' : 'WriteOff';
- begin_transaction();
hook_db_prewrite($credit_note, ST_CUSTCREDIT);
$company_data = get_company_prefs();
$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);
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);
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)
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)
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) . ", "
$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) . ",
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)
$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();
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);
{
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);
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)
$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)
***********************************************************************/
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)
.",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)
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();
}
***********************************************************************/
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)
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();
}
return db_query($sql,"The related credit notes could not be retreived");
}
+//-------------------------------- Backend interfaces -------------------------------------
+
+
+function write_sales_trans($cart, $policy = 0)
+{
+ begin_transaction(__FUNCTION__, func_get_args());
+ $result = $cart->write($policy);
+ commit_transaction();
+ return $result;
+}
+
+function save_cust_payment($cart, $customer_id, $branch_id,
+ $bank_account, $trans_date, $ref, $amount, $discount, $memo, $charge, $bank_amount)
+{
+ begin_transaction(__FUNCTION__, func_get_args());
+
+ $payment_no = write_customer_payment($cart->trans_no, $customer_id, $branch_id,
+ $bank_account, $trans_date, $ref, $amount, $discount, $memo, 0, $charge, $bank_amount);
+
+ $cart->trans_no = $payment_no;
+ $cart->date_ = $trans_date;
+ $cart->write();
+
+ commit_transaction();
+ return $payment_no;
+}
+
+function create_recurrent_invoices($id, $from, $to, $date, $memo)
+{
+ /*
+ whole invoiced time is <begin, end>
+ invoices are issued _after_ invoiced period is gone, eg:
+ begin 1.1
+ end 31.3
+ period: invoice ready for issue since:
+ 1.1-31.1 - 1.2
+ 1.2-28.2 - 1.3
+ 1.3-31.3 - 1.4
+ In example above, when end is set to 1.4 will generate additional invoice on 1.5 !
+ */
+ log_user();
+
+ $myrow = get_recurrent_invoice($id);
+
+ $invs = array();
+ if (recurrent_invoice_ready($id, $date))
+ {
+
+ begin_transaction(__FUNCTION__, func_get_args());
+ if ($myrow['debtor_no'] == 0)
+ {
+ $cust = get_cust_branches_from_group($myrow['group_no']);
+ while ($row = db_fetch($cust))
+ {
+ $invs[] = create_template_invoice($row['debtor_no'], $row['branch_code'], $myrow['order_no'], $myrow['id'],
+ $date, $from, $to, $memo);
+ }
+ }
+ else
+ {
+ $invs[] = create_template_invoice($myrow['debtor_no'], $myrow['group_no'], $myrow['order_no'], $myrow['id'],
+ $date, $from, $to, $memo);
+ }
+ commit_transaction();
+ }
+ return $invs;
+}
+
+function write_recurrent_invoice($invoice_id, $description, $order_no, $debtor_no, $group_no,
+ $days, $monthly, $begin, $end, $last_sent)
+{
+ begin_transaction(__FUNCTION__, func_get_args());
+
+ if ($invoice_id != -1)
+ {
+ update_recurrent_invoice($invoice_id, $description, $order_no, $debtor_no, $group_no,
+ $days, $monthly, $begin, $end);
+ if (isset($last_sent))
+ update_last_sent_recurrent_invoice($invoice_id, $last_sent);
+ }
+ else
+ {
+ add_recurrent_invoice($description, $order_no, $debtor_no, $group_no,
+ $days, $monthly, $begin, $end);
+ }
+ commit_transaction();
+}
+
+function write_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status,
+ $payment_terms, $discount, $pymt_discount, $credit_limit, $sales_type, $notes, $inactive, $salesman, $area,
+ $tax_group, $location, $address, $ship_via, $notes, $bank_account, $address, $phone, $phone2, $fax, $email)
+{
+ global $SysPrefs;
+
+ begin_transaction(__FUNCTION__, func_get_args());
+
+ if ($customer_id) {
+ update_customer($customer_id, $name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status,
+ $payment_terms, $discount/100, $pymt_discount/100, $credit_limit, $sales_type, $notes, $inactive);
+
+ update_record_status($customer_id, $inactive, 'debtors_master', 'debtor_no');
+
+ } else {
+ add_customer($name, $ref, $address, $tax_id, $curr_code, $dim1, $dim2, $credit_status, $payment_terms,
+ $discount / 100, $pymt_discount / 100, $credit_limit, $sales_type, $notes);
+
+ $customer_id = db_insert_id();
+
+ if (isset($SysPrefs->auto_create_branch) && $SysPrefs->auto_create_branch == 1)
+ {
+ add_branch($customer_id, $name, $ref, $address, $salesman, $area, $tax_group, '',
+ get_company_pref('default_sales_discount_act'),
+ get_company_pref('debtors_act'),
+ get_company_pref('default_prompt_payment_act'),
+ $location, $address, 0, $ship_via, $notes, $bank_account);
+
+ $selected_branch = db_insert_id();
+
+ add_crm_person($ref, $name, '', $address, $phone, $phone2, $fax, $email, '', '');
+
+ $pers_id = db_insert_id();
+ add_crm_contact('cust_branch', 'general', $selected_branch, $pers_id);
+
+ add_crm_contact('customer', 'general', $customer_id, $pers_id);
+ }
+ }
+ commit_transaction();
+
+ return $customer_id;
+}
+
+function write_cust_branch($id, $customer_id, $name, $ref, $br_address, $salesman, $area, $tax_group,
+ $sales_act, $discount_act, $ar_act, $payment_discount_act, $location, $post_address, $group_no, $ship_via, $notes, $bank_act,
+ $contact_name, $phone, $phone2,$fax, $email, $lang)
+{
+
+ begin_transaction(__FUNCTION__, func_get_args());
+
+ if ($id !== 0) {
+ update_branch($customer_id, $id, $name, $ref, $br_address, $salesman, $area, $tax_group, $sales_act,
+ $discount_act, $ar_act, $discount_act, $location, $post_address, $group_no,
+ $ship_via, $notes, $bank_act);
+ } else {
+ add_branch($customer_id, $name, $ref, $br_address, $salesman, $area, $tax_group, $sales_act,
+ $discount_act, $ar_act, $payment_discount_act, $location, $post_address, $group_no,
+ $ship_via, $notes, $bank_act);
+
+ $branch_id = db_insert_id();
+
+ add_crm_person($contact_name, $contact_name, '', $post_address, $phone, $phone2, $fax, $email, $lang, '');
+
+ add_crm_contact('cust_branch', 'general', $branch_id, db_insert_id());
+
+ }
+ commit_transaction();
+}
+
+function write_cust_allocation($cart)
+{
+ begin_transaction(__FUNCTION__, func_get_args());
+ $result = $cart->write();
+ commit_transaction();
+ return $result;
+}
+
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']) {
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."));
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')
{
$_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']);
$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."));
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;
('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`;
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`;
-- 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`;
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`;
***********************************************************************/
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).")";
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);
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);
***********************************************************************/
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");
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");
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);
***********************************************************************/
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).",
WHERE id=".db_escape($type_id);
db_query($sql, "could not update tax type");
+ commit_transaction();
}
function get_all_tax_types($all=false)
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);