! -> Note
$ -> Affected files
+18-Sep-2009 Janusz Dobrowolski
++ Added currency default bank accounts used in reporting instead of manual account selector.
+$ /gl/includes/db/gl_db_bank_accounts.inc
+ /gl/manage/bank_accounts.php
+ /reporting/rep107.php
+ /reporting/rep108.php
+ /reporting/rep109.php
+ /reporting/rep111.php
+ /reporting/rep209.php
+ /reporting/reports_main.php
+ /reporting/includes/reporting.inc
+ /sql/alter2.2.sql
+ /sql/en_US-demo.sql
+ /sql/en_US-new.sql
+
17-Sep-2009 Joe Hunt
+ Added release note file for 2.2.
$ /doc/2.2-Beta.txt
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
//---------------------------------------------------------------------------------------------
+function clear_dflt_curr_account($curr_code) {
+ $sql = "UPDATE ".TB_PREF."bank_accounts SET dflt_curr_act=0 WHERE bank_curr_code="
+ .db_escape($curr_code);
+ db_query($sql, "could not update default currency account");
+}
-function add_bank_account($account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
- $bank_address, $bank_curr_code)
+function add_bank_account($account_code, $account_type, $bank_account_name,
+ $bank_name, $bank_account_number, $bank_address, $bank_curr_code,
+ $dflt_curr_act)
{
- $sql = "INSERT INTO ".TB_PREF."bank_accounts (account_code, account_type, bank_account_name, bank_name, bank_account_number, bank_address, bank_curr_code)
+ if($dflt_curr_act) // only one default account for any currency
+ clear_dflt_curr_account($bank_curr_code);
+
+ $sql = "INSERT INTO ".TB_PREF."bank_accounts (account_code, account_type,
+ bank_account_name, bank_name, bank_account_number, bank_address,
+ bank_curr_code, dflt_curr_act)
VALUES (".db_escape($account_code).", $account_type, ".db_escape($bank_account_name).", ".db_escape($bank_name).", ".db_escape($bank_account_number).",
- ".db_escape($bank_address).", '$bank_curr_code')";
+ ".db_escape($bank_address).", '$bank_curr_code', '$dflt_curr_act')";
db_query($sql, "could not add a bank account for $account_code");
}
//---------------------------------------------------------------------------------------------
-function update_bank_account($id, $account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
- $bank_address, $bank_curr_code)
+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)
{
+ if($dflt_curr_act) // only one default account for any currency
+ clear_dflt_curr_account($bank_curr_code);
+
$sql = "UPDATE ".TB_PREF."bank_accounts SET account_type = $account_type,
account_code=".db_escape($account_code).",
bank_account_name=".db_escape($bank_account_name).", bank_name=".db_escape($bank_name).",
bank_account_number=".db_escape($bank_account_number).", bank_curr_code='$bank_curr_code',
- bank_address=".db_escape($bank_address)." WHERE id = '$id'";
+ bank_address=".db_escape($bank_address).","
+ ."dflt_curr_act='$dflt_curr_act' WHERE id = '$id'";
db_query($sql, "could not update bank account for $account_code");
}
//---------------------------------------------------------------------------------------------
+function get_default_bank_account($curr)
+{
+ /* default bank account is selected as first found account from:
+ . default account in $curr if any
+ . first defined account in $curr if any
+ . default account in home currency
+ . first defined account in home currency
+ */
+ $home_curr = get_company_pref('curr_default');
+
+ $sql = "SELECT b.*, b.bank_curr_code='$home_curr' as fall_back FROM "
+ .TB_PREF."bank_accounts b"
+ ." WHERE b.bank_curr_code=".db_escape($curr)
+ ." OR b.bank_curr_code='$home_curr'
+ ORDER BY fall_back, dflt_curr_act desc";
+
+ $result = db_query($sql, "could not retreive default bank account");
+
+ return db_fetch($result);
+}
?>
\ No newline at end of file
update_bank_account($selected_id, $_POST['account_code'],
$_POST['account_type'], $_POST['bank_account_name'],
$_POST['bank_name'], $_POST['bank_account_number'],
- $_POST['bank_address'], $_POST['BankAccountCurrency']);
+ $_POST['bank_address'], $_POST['BankAccountCurrency'],
+ $_POST['dflt_curr_act']);
display_notification(_('Bank account has been updated'));
}
else
add_bank_account($_POST['account_code'], $_POST['account_type'],
$_POST['bank_account_name'], $_POST['bank_name'],
- $_POST['bank_account_number'], $_POST['bank_address'],
- $_POST['BankAccountCurrency']);
+ $_POST['bank_account_number'], $_POST['bank_address'],
+ $_POST['BankAccountCurrency'], $_POST['dflt_curr_act']);
display_notification(_('New bank account has been added'));
}
$Mode = 'RESET';
start_table("$table_style width='80%'");
$th = array(_("Account Name"), _("Type"), _("Currency"), _("GL Account"),
- _("Bank"), _("Number"), _("Bank Address"),'','');
+ _("Bank"), _("Number"), _("Bank Address"), _("Dflt"), '','');
inactive_control_column($th);
table_header($th);
label_cell($myrow["bank_name"], "nowrap");
label_cell($myrow["bank_account_number"], "nowrap");
label_cell($myrow["bank_address"]);
+ if ($myrow["dflt_curr_act"])
+ label_cell(_("Yes"));
+ else
+ label_cell(_("No"));
+
inactive_control_cell($myrow["id"], $myrow["inactive"], 'bank_accounts', 'id');
edit_button_cell("Edit".$myrow["id"], _("Edit"));
delete_button_cell("Delete".$myrow["id"], _("Delete"));
$_POST['bank_account_number'] = $myrow["bank_account_number"];
$_POST['bank_address'] = $myrow["bank_address"];
$_POST['BankAccountCurrency'] = $myrow["bank_curr_code"];
+ $_POST['dflt_curr_act'] = $myrow["dflt_curr_act"];
}
hidden('selected_id', $selected_id);
hidden('account_code');
currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
}
+yesno_list_row(_("Default currency account:"), 'dflt_curr_act');
+
if($is_editing)
label_row(_("Bank Account GL Code:"), $_POST['account_code']);
else
$ar = array(
'PARAM_0' => $doc_no,
'PARAM_1' => $doc_no,
- 'PARAM_2' => "",
- 'PARAM_3' => get_first_bank_account(),
- 'PARAM_4' => $email,
- 'PARAM_5' => "");
+ 'PARAM_2' => '',
+ 'PARAM_3' => $email,
+ 'PARAM_4' => '');
break;
case ST_SALESORDER :
$rep = 109;
$ar = array(
'PARAM_0' => $doc_no,
'PARAM_1' => $doc_no,
- 'PARAM_2' => "",
- 'PARAM_3' => get_first_bank_account(),
- 'PARAM_4' => $email,
- 'PARAM_5' => 0,
- 'PARAM_6' => "");
+ 'PARAM_2' => '',
+ 'PARAM_3' => $email,
+ 'PARAM_4' => 0,
+ 'PARAM_5' => '');
break;
case ST_CUSTDELIVERY :
$rep = 110;
$ar = array(
'PARAM_0' => $doc_no,
'PARAM_1' => $doc_no,
- 'PARAM_2' => $email,
- 'PARAM_3' => "");
+ 'PARAM_2' => $email);
break;
case ST_SALESINVOICE : // Sales Invoice
case ST_CUSTCREDIT : // Customer Credit Note
$ar = array(
'PARAM_0' => $doc_no,
'PARAM_1' => $doc_no,
- 'PARAM_2' => "",
- 'PARAM_3' => get_first_bank_account(),
- 'PARAM_4' => $email,
- 'PARAM_5' => "",
- 'PARAM_6' => "",
- 'PARAM_7' => $type_no);
+ 'PARAM_2' => '',
+ 'PARAM_3' => $email,
+ 'PARAM_4' => '',
+ 'PARAM_5' => '',
+ 'PARAM_6' => $type_no);
break;
case ST_PURCHORDER :
$rep = 209;
$ar = array(
'PARAM_0' => $doc_no,
'PARAM_1' => $doc_no,
- 'PARAM_2' => "",
- 'PARAM_3' => get_first_bank_account(),
- 'PARAM_4' => $email,
- 'PARAM_5' => "");
+ 'PARAM_2' => '',
+ 'PARAM_3' => $email,
+ 'PARAM_4' => '');
break;
// default: $ar = array();
}
return "<a target='_blank' href='$url'$id$class $pars[1]>$pars[0]</a>";
}
-function get_first_bank_account()
-{
- $sql = "SELECT ".TB_PREF."bank_accounts.id FROM ".TB_PREF."bank_accounts, ".TB_PREF."company
- WHERE bank_curr_code=curr_default LIMIT 0, 1";
- $result = db_query($sql);
- $row = db_fetch_row($result);
- return $row[0];
-}
?>
\ No newline at end of file
$from = $_POST['PARAM_0'];
$to = $_POST['PARAM_1'];
$currency = $_POST['PARAM_2'];
- $bankaccount = $_POST['PARAM_3'];
- $email = $_POST['PARAM_4'];
- $paylink = $_POST['PARAM_5'];
- $comments = $_POST['PARAM_6'];
+ $email = $_POST['PARAM_3'];
+ $paylink = $_POST['PARAM_4'];
+ $comments = $_POST['PARAM_5'];
if ($from == null)
$from = 0;
// $headers in doctext.inc
$aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
- $params = array('comments' => $comments,
- 'bankaccount' => $bankaccount);
+ $params = array('comments' => $comments);
- $baccount = get_bank_account($params['bankaccount']);
$cur = get_company_Pref('curr_default');
if ($email == 0)
continue;
$sign = $j==ST_SALESINVOICE ? 1 : -1;
$myrow = get_customer_trans($i, $j);
+ $baccount = get_default_bank_account($myrow['curr_code']);
+ $params['bankaccount'] = $baccount['id'];
+
$branch = get_branch($myrow["branch_code"]);
$branch['disable_branch'] = $paylink; // helper
if ($j == ST_SALESINVOICE)
$customer = $_POST['PARAM_0'];
$currency = $_POST['PARAM_1'];
- $bankaccount = $_POST['PARAM_2'];
- $email = $_POST['PARAM_3'];
- $comments = $_POST['PARAM_4'];
+ $email = $_POST['PARAM_2'];
+ $comments = $_POST['PARAM_3'];
$dec = user_price_dec();
$aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
- $params = array('comments' => $comments,
- 'bankaccount' => $bankaccount);
-
- $baccount = get_bank_account($params['bankaccount']);
+ $params = array('comments' => $comments);
$cur = get_company_pref('curr_default');
$PastDueDays1 = get_company_pref('past_due_days');
$myrow['order_'] = "";
$TransResult = getTransactions($myrow['debtor_no'], $date);
+ $baccount = get_default_bank_account($myrow['curr_code']);
+ $params['bankaccount'] = $baccount['id'];
if (db_num_rows($TransResult) == 0)
continue;
if ($email == 1)
$from = $_POST['PARAM_0'];
$to = $_POST['PARAM_1'];
$currency = $_POST['PARAM_2'];
- $bankaccount = $_POST['PARAM_3'];
- $email = $_POST['PARAM_4'];
- $print_as_quote = $_POST['PARAM_5'];
- $comments = $_POST['PARAM_6'];
+ $email = $_POST['PARAM_3'];
+ $print_as_quote = $_POST['PARAM_4'];
+ $comments = $_POST['PARAM_5'];
if ($from == null)
$from = 0;
// $headers in doctext.inc
$aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
- $params = array('comments' => $comments,
- 'bankaccount' => $bankaccount);
+ $params = array('comments' => $comments);
- $baccount = get_bank_account($params['bankaccount']);
$cur = get_company_Pref('curr_default');
if ($email == 0)
for ($i = $from; $i <= $to; $i++)
{
$myrow = get_sales_order_header($i, ST_SALESORDER);
+ $baccount = get_default_bank_account($myrow['curr_code']);
+ $params['bankaccount'] = $baccount['id'];
$branch = get_branch($myrow["branch_code"]);
if ($email == 1)
{
$from = $_POST['PARAM_0'];
$to = $_POST['PARAM_1'];
$currency = $_POST['PARAM_2'];
- $bankaccount = $_POST['PARAM_3'];
- $email = $_POST['PARAM_4'];
- $comments = $_POST['PARAM_5'];
+ $email = $_POST['PARAM_3'];
+ $comments = $_POST['PARAM_4'];
if ($from == null)
$from = 0;
// $headers in doctext.inc
$aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
- $params = array('comments' => $comments,
- 'bankaccount' => $bankaccount);
+ $params = array('comments' => $comments);
- $baccount = get_bank_account($params['bankaccount']);
$cur = get_company_Pref('curr_default');
if ($email == 0)
for ($i = $from; $i <= $to; $i++)
{
$myrow = get_sales_order_header($i, ST_SALESQUOTE);
+ $baccount = get_default_bank_account($myrow['curr_code']);
+ $params['bankaccount'] = $baccount['id'];
$branch = get_branch($myrow["branch_code"]);
if ($email == 1)
{
$from = $_POST['PARAM_0'];
$to = $_POST['PARAM_1'];
$currency = $_POST['PARAM_2'];
- $bankaccount = $_POST['PARAM_3'];
- $email = $_POST['PARAM_4'];
- $comments = $_POST['PARAM_5'];
+ $email = $_POST['PARAM_3'];
+ $comments = $_POST['PARAM_4'];
if ($from == null)
$from = 0;
// $headers in doctext.inc
$aligns = array('left', 'left', 'left', 'right', 'left', 'right', 'right');
- $params = array('comments' => $comments,
- 'bankaccount' => $bankaccount);
+ $params = array('comments' => $comments);
- $baccount = get_bank_account($params['bankaccount']);
$cur = get_company_Pref('curr_default');
if ($email == 0)
for ($i = $from; $i <= $to; $i++)
{
$myrow = get_po($i);
+ $baccount = get_default_bank_account($myrow['curr_code']);
+ $params['bankaccount'] = $baccount['id'];
if ($email == 1)
{
array( new ReportParam(_('From'),'INVOICE'),
new ReportParam(_('To'),'INVOICE'),
new ReportParam(_('Currency Filter'),'CURRENCY'),
- new ReportParam(_('Bank Account'),'BANK_ACCOUNTS'),
new ReportParam(_('email Customers'),'YES_NO'),
new ReportParam(_('Payment Link'),'PAYMENT_LINK'),
new ReportParam(_('Comments'),'TEXTBOX')));
$reports->addReport(_('Customer'),108,_('Print &Statements'),
array( new ReportParam(_('Customer'),'CUSTOMERS_NO_FILTER'),
new ReportParam(_('Currency Filter'),'CURRENCY'),
- new ReportParam(_('Bank Account'),'BANK_ACCOUNTS'),
new ReportParam(_('Email Customers'),'YES_NO'),
new ReportParam(_('Comments'),'TEXTBOX')));
$reports->addReport(_('Customer'),109,_('&Print Sales Orders'),
array( new ReportParam(_('From'),'ORDERS'),
new ReportParam(_('To'),'ORDERS'),
new ReportParam(_('Currency Filter'),'CURRENCY'),
- new ReportParam(_('Bank Account'),'BANK_ACCOUNTS'),
new ReportParam(_('Email Customers'),'YES_NO'),
new ReportParam(_('Print as Quote'),'YES_NO'),
new ReportParam(_('Comments'),'TEXTBOX')));
array( new ReportParam(_('From'),'QUOTATIONS'),
new ReportParam(_('To'),'QUOTATIONS'),
new ReportParam(_('Currency Filter'),'CURRENCY'),
- new ReportParam(_('Bank Account'),'BANK_ACCOUNTS'),
new ReportParam(_('Email Customers'),'YES_NO'),
new ReportParam(_('Comments'),'TEXTBOX')));
array( new ReportParam(_('From'),'PO'),
new ReportParam(_('To'),'PO'),
new ReportParam(_('Currency Filter'),'CURRENCY'),
- new ReportParam(_('Bank Account'),'BANK_ACCOUNTS'),
new ReportParam(_('Email Customers'),'YES_NO'),
new ReportParam(_('Comments'),'TEXTBOX')));
ALTER TABLE `0_sales_orders` DROP PRIMARY KEY;
ALTER TABLE `0_sales_orders` ADD PRIMARY KEY ( `trans_type` , `order_no` );
UPDATE `0_sales_orders` SET `reference`=`order_no` WHERE 1;
-INSERT INTO `0_sys_types` (`type_id`, `type_no`, `next_reference`) VALUES (32, 0, '1');
\ No newline at end of file
+INSERT INTO `0_sys_types` (`type_id`, `type_no`, `next_reference`) VALUES (32, 0, '1');
+
+ALTER TABLE `0_bank_accounts` ADD COLUMN `dflt_curr_act` TINYINT(1) NOT NULL default '0' AFTER `bank_curr_code`;
`bank_name` varchar(60) NOT NULL default '',
`bank_address` tinytext,
`bank_curr_code` char(3) NOT NULL default '',
+ `dflt_curr_act` TINYINT(1) NOT NULL default '0',
`id` smallint(6) NOT NULL auto_increment,
`last_reconciled_date` timestamp NOT NULL default '0000-00-00 00:00:00',
`ending_reconcile_balance` double NOT NULL default '0',
### Data of table `0_bank_accounts` ###
-INSERT INTO `0_bank_accounts` VALUES ('1060', '0', 'Current account', '9999999999', 'Wachovia Bank', '', 'USD', '1', '0000-00-00 00:00:00', '0', '0');
-INSERT INTO `0_bank_accounts` VALUES ('1065', '3', 'Petty Cash account', 'N/A', 'N/A', '', 'USD', '2', '0000-00-00 00:00:00', '0', '0');
+INSERT INTO `0_bank_accounts` VALUES ('1060', '0', 'Current account', '9999999999', 'Wachovia Bank', '', 'USD', '1', '1', '0000-00-00 00:00:00', '0', '0');
+INSERT INTO `0_bank_accounts` VALUES ('1065', '3', 'Petty Cash account', 'N/A', 'N/A', '', 'USD', '0', '2', '0000-00-00 00:00:00', '0', '0');
### Structure of table `0_bank_trans` ###
`bank_name` varchar(60) NOT NULL default '',
`bank_address` tinytext,
`bank_curr_code` char(3) NOT NULL default '',
+ `dflt_curr_act` TINYINT(1) NOT NULL default '0',
`id` smallint(6) NOT NULL auto_increment,
`last_reconciled_date` timestamp NOT NULL default '0000-00-00 00:00:00',
`ending_reconcile_balance` double NOT NULL default '0',
### Data of table `0_bank_accounts` ###
-INSERT INTO `0_bank_accounts` VALUES ('1060', '0', 'Current account', 'N/A', 'N/A', '', 'USD', '1', '0000-00-00 00:00:00', '0', '0');
-INSERT INTO `0_bank_accounts` VALUES ('1065', '3', 'Petty Cash account', 'N/A', 'N/A', '', 'USD', '2', '0000-00-00 00:00:00', '0', '0');
+INSERT INTO `0_bank_accounts` VALUES ('1060', '0', 'Current account', 'N/A', 'N/A', '', 'USD', '1', '1', '0000-00-00 00:00:00', '0', '0');
+INSERT INTO `0_bank_accounts` VALUES ('1065', '3', 'Petty Cash account', 'N/A', 'N/A', '', 'USD', '0', '2', '0000-00-00 00:00:00', '0', '0');
### Structure of table `0_bank_trans` ###