$this->add_module(_("Maintenance"));
$this->add_lapp_function(2, _("Bank &Accounts"),"gl/manage/bank_accounts.php?");
- $this->add_lapp_function(2, _("Payment, Deposit and Transfer &Types"),"gl/manage/bank_trans_types.php?");
$this->add_lapp_function(2, _("Quick Entries"),"gl/manage/gl_quick_entries.php?");
$this->add_lapp_function(2, "","");
$this->add_lapp_function(2, _("&Currencies"),"gl/manage/currencies.php?");
page(_("Transfer between Bank Accounts"), false, false, "", $js);
check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
-check_db_has_bank_trans_types(_("There are no bank transfer types defined in the system."));
//----------------------------------------------------------------------------------------
echo "</td><td valign=top class='tableseparator'>"; // outer table
echo "<table>";
- bank_trans_types_list_row(_("Transfer Type:"), 'TransferType', null);
-
ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_transfer()));
textarea_row(_("Memo:"), 'memo_', null, 40,4);
global $path_to_root;
$trans_no = add_bank_transfer($_POST['FromBankAccount'], $_POST['ToBankAccount'],
- $_POST['DatePaid'], input_num('amount'),
- $_POST['TransferType'], $_POST['ref'], $_POST['memo_']);
+ $_POST['DatePaid'], input_num('amount'), $_POST['ref'], $_POST['memo_']);
meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
}
//-----------------------------------------------------------------------------------------------
check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
-check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
-
//----------------------------------------------------------------------------------------
if ($ret = context_restore()) {
if(isset($ret['supplier_id']))
//
context_call($path_to_root.$editor.$_POST['person_id'],
array('bank_account', 'date_', 'PayType', 'person_id',
- 'PersonDetailID', 'type', 'ref', 'memo_') );
+ 'PersonDetailID', 'ref', 'memo_') );
}
//--------------------------------------------------------------------------------------------------
function line_start_focus() {
$_SESSION['pay_items']->trans_type, $_POST['bank_account'],
$_SESSION['pay_items'], $_POST['date_'],
$_POST['PayType'], $_POST['person_id'], get_post('PersonDetailID'),
- $_POST['type'], $_POST['ref'], $_POST['memo_']);
+ $_POST['ref'], $_POST['memo_']);
$trans_type = $trans[0];
$trans_no = $trans[1];
//---------------------------------------------------------------------------------------------
-function update_bank_account($account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
+function update_bank_account($id, $account_code, $account_type, $bank_account_name, $bank_name, $bank_account_number,
$bank_address, $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 account_code = '$account_code'";
+ bank_address=".db_escape($bank_address)." WHERE id = '$id'";
db_query($sql, "could not update bank account for $account_code");
}
//---------------------------------------------------------------------------------------------
-function delete_bank_account($account_code)
+function delete_bank_account($id)
{
- $sql = "DELETE FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
+ $sql = "DELETE FROM ".TB_PREF."bank_accounts WHERE id='$id'";
- db_query($sql,"could not delete bank account for $account_code");
+ db_query($sql,"could not delete bank account for $id");
}
//---------------------------------------------------------------------------------------------
-function get_bank_account($account_code)
+function get_bank_account($id)
{
- $sql = "SELECT * FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
+ $sql = "SELECT * FROM ".TB_PREF."bank_accounts WHERE id='$id'";
- $result = db_query($sql, "could not retreive bank account for $account_code");
+ $result = db_query($sql, "could not retreive bank account for $id");
return db_fetch($result);
}
+//---------------------------------------------------------------------------------------------
+function get_bank_gl_account($id)
+{
+ $sql = "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE id='$id'";
+
+ $result = db_query($sql, "could not retreive bank account for $id");
+
+ $bank_account = db_fetch($result);
+
+ return $bank_account['account_code'];
+}
+
//---------------------------------------------------------------------------------------------
function add_quick_entry($description, $deposit, $bank_only)
// $amount is in $currency
// $date_ is display date (non-sql)
-function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_, $bank_trans_type_id,
+function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_,
$amount, $person_type_id, $person_id, $currency="", $err_msg="")
{
$sqlDate = date2sql($date_);
//$BankToHomeCurrencyRate = get_exchange_rate_to_home_currency($bank_account_currency, $date_);
$sql = "INSERT INTO ".TB_PREF."bank_trans (type, trans_no, bank_act, ref,
- trans_date, bank_trans_type_id, amount, person_type_id, person_id) ";
+ trans_date, amount, person_type_id, person_id) ";
- $sql .= "VALUES ($type, $trans_no, '$bank_act', ".db_escape($ref).", '$sqlDate', '$bank_trans_type_id',
+ $sql .= "VALUES ($type, $trans_no, '$bank_act', ".db_escape($ref).", '$sqlDate',
$amount_bank, $person_type_id, ". db_escape($person_id).")";
if ($err_msg == "")
function get_bank_trans($type, $trans_no=null, $person_type_id=null, $person_id=null)
{
- $sql = "SELECT *, bank_account_name, account_code, bank_curr_code, name AS BankTransType
- FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts, ".TB_PREF."bank_trans_types
- WHERE ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
- AND ".TB_PREF."bank_accounts.account_code=".TB_PREF."bank_trans.bank_act ";
+ $sql = "SELECT *, bank_account_name, account_code, bank_curr_code
+ FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts
+ WHERE ".TB_PREF."bank_accounts.id=".TB_PREF."bank_trans.bank_act ";
if ($type != null)
$sql .= " AND type=$type ";
if ($trans_no != null)
<?php
//----------------------------------------------------------------------------------
-
+// Add bank tranfer to database.
+//
+// $from_account - source bank account id
+// $to_account - target bank account id
+//
function add_bank_transfer($from_account, $to_account, $date_,
- $amount, $payment_type, $ref, $memo_)
+ $amount, $ref, $memo_)
{
begin_transaction();
$trans_no = get_next_trans_no($trans_type);
+ $from_gl_account = get_bank_gl_account($from_account);
+ $to_gl_account = get_bank_gl_account($to_account);
+
// do the source account postings
- add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
+ add_gl_trans($trans_type, $trans_no, $date_, $from_gl_account, 0, 0, "",
-$amount, $currency);
add_bank_trans($trans_type, $trans_no, $from_account, $ref,
- $date_, $payment_type, -$amount,
+ $date_, -$amount,
payment_person_types::misc(), "", $currency,
"Cannot insert a source bank transaction");
// do the destination account postings
- add_gl_trans($trans_type, $trans_no, $date_, $to_account, 0, 0, "",
+ add_gl_trans($trans_type, $trans_no, $date_, $to_gl_account, 0, 0, "",
$amount, $currency);
add_bank_trans($trans_type, $trans_no, $to_account, $ref,
- $date_, $payment_type, $amount,
- payment_person_types::misc(), "",
- $currency,
- "Cannot insert a destination bank transaction");
+ $date_, $amount, payment_person_types::misc(), "",
+ $currency, "Cannot insert a destination bank transaction");
add_comments($trans_type, $trans_no, $date_, $memo_);
}
//----------------------------------------------------------------------------------
-
-// $amount is in $from_account's currency
-
+// Add bank payment or deposit to database.
+//
+// $from_account - bank account id
+// $item - transaction cart (line item's amounts in bank account's currency)
+// $person_type_id - defines type of $person_id identifiers
+// $person_id - supplier/customer/other id
+// $person_detail_id - customer branch id or not used
+//
// returns an array of (inserted trans type, trans no)
function add_bank_transaction($trans_type, $from_account, $items, $date_,
- $person_type_id, $person_id, $person_detail_id, $type, $ref, $memo_)
+ $person_type_id, $person_id, $person_detail_id, $ref, $memo_)
{
// we can only handle type 1 (payment)and type 2 (deposit)
if ($trans_type != systypes::bank_payment() && $trans_type != systypes::bank_deposit())
begin_transaction();
$currency = get_bank_account_currency($from_account);
+ $bank_gl_account = get_bank_gl_account($from_account);
// the gl items are already inversed/negated for type 2 (deposit)
$total_amount = $items->gl_items_total();
}
// do the source account postings
- add_gl_trans($trans_type, $trans_no, $date_, $from_account, 0, 0, "",
+ add_gl_trans($trans_type, $trans_no, $date_, $bank_gl_account, 0, 0, "",
-$total_amount, $currency, $person_type_id, $person_id);
add_bank_trans($trans_type, $trans_no, $from_account, $ref,
- $date_, $type, -$total_amount,
- $person_type_id, $person_id,
- $currency,
- "Cannot insert a source bank transaction");
+ $date_, -$total_amount, $person_type_id, $person_id,
+ $currency, "Cannot insert a source bank transaction");
foreach ($items->gl_items as $gl_item)
{
if ($is_bank_to)
{
add_bank_trans($trans_type, $trans_no, $gl_item->code_id, $ref,
- $date_, $type, $gl_item->amount,
- $person_type_id, $person_id, $currency,
- "Cannot insert a destination bank transaction");
+ $date_, $gl_item->amount, $person_type_id, $person_id,
+ $currency, "Cannot insert a destination bank transaction");
}
}
foreach ($items as $journal_item)
{
+ // post to first found bank account using given gl acount code.
$is_bank_to = is_bank_account($journal_item->code_id);
add_gl_trans($trans_type, $trans_id, $date_, $journal_item->code_id,
$journal_item->reference, $journal_item->amount);
if ($is_bank_to)
{
- add_bank_trans($trans_type, $trans_id, $journal_item->code_id, $ref,
- $date_, 3, $journal_item->amount,
+ add_bank_trans($trans_type, $trans_id, $is_bank_to, $ref,
+ $date_, $journal_item->amount,
0, "", get_company_currency(),
"Cannot insert a destination bank transaction");
}
$journal_item->reference, -$journal_item->amount);
if ($is_bank_to)
{
- add_bank_trans($trans_type, $trans_id_reverse, $journal_item->code_id, $ref,
- $reversingDate, 3, $journal_item->amount,
+ add_bank_trans($trans_type, $trans_id_reverse, $is_bank_to, $ref,
+ $reversingDate, $journal_item->amount,
0, "", get_company_currency(),
"Cannot insert a destination bank transaction");
}
echo "<table>"; // inner table
- bank_trans_types_list_row(_("Type:"), 'type', null);
-
if (isset($_GET['NewPayment']))
ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_payment()));
else
$date_to = date2sql($_POST['TransToDate']);
if (!isset($_POST['bank_account']))
$_POST['bank_account'] = "";
-$sql = "SELECT ".TB_PREF."bank_trans.*,name AS BankTransType FROM ".TB_PREF."bank_trans, ".TB_PREF."bank_trans_types
+$sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
WHERE ".TB_PREF."bank_trans.bank_act = '" . $_POST['bank_account'] . "'
AND trans_date >= '$date_after'
AND trans_date <= '$date_to'
- AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
ORDER BY trans_date,".TB_PREF."bank_trans.id";
$result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
label_cell(systypes::name($myrow["type"]));
label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
- label_cell($myrow["BankTransType"]);
label_cell($trandate);
display_debit_or_credit_cells($myrow["amount"]);
amount_cell($running_total);
if ($selected_id != -1)
{
- update_bank_account($selected_id, $_POST['account_type'], $_POST['bank_account_name'], $_POST['bank_name'],
- $_POST['bank_account_number'],
+ 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']);
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']);
+ 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']);
display_notification(_('New bank account has been added'));
}
$Mode = 'RESET';
/* Always show the list of accounts */
-$sql = "SELECT ".TB_PREF."bank_accounts.*, ".TB_PREF."chart_master.account_name FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
- WHERE ".TB_PREF."bank_accounts.account_code = ".TB_PREF."chart_master.account_code";
+$sql = "SELECT account.*, gl_account.account_name
+ FROM ".TB_PREF."bank_accounts account, ".TB_PREF."chart_master gl_account
+ WHERE account.account_code = gl_account.account_code"
+ ." ORDER BY account_code, bank_curr_code";
+
$result = db_query($sql,"could not get bank accounts");
check_db_error("The bank accounts set up could not be retreived", $sql);
start_form();
start_table("$table_style width='80%'");
-$th = array(_("GL Account"), _("Bank"), _("Account Name"),
- _("Type"), _("Number"), _("Currency"), _("Bank Address"),'','');
+$th = array(_("Account Name"), _("Type"), _("Currency"), _("GL Account"),
+ _("Bank"), _("Number"), _("Bank Address"),'','');
table_header($th);
$k = 0;
alt_table_row_color($k);
- label_cell($myrow["account_code"] . " " . $myrow["account_name"], "nowrap");
- label_cell($myrow["bank_name"], "nowrap");
label_cell($myrow["bank_account_name"], "nowrap");
label_cell(bank_account_types::name($myrow["account_type"]), "nowrap");
- label_cell($myrow["bank_account_number"], "nowrap");
label_cell($myrow["bank_curr_code"], "nowrap");
+ label_cell($myrow["account_code"] . " " . $myrow["account_name"], "nowrap");
+ label_cell($myrow["bank_name"], "nowrap");
+ label_cell($myrow["bank_account_number"], "nowrap");
label_cell($myrow["bank_address"]);
- edit_button_cell("Edit".$myrow["account_code"], _("Edit"));
- edit_button_cell("Delete".$myrow["account_code"], _("Delete"));
+ edit_button_cell("Edit".$myrow["id"], _("Edit"));
+ edit_button_cell("Delete".$myrow["id"], _("Delete"));
end_row();
}
hidden('selected_id', $selected_id);
hidden('account_code');
hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);
- label_row(_("Bank Account GL Code:"), $_POST['account_code']);
- set_focus('account_type');
+ set_focus('bank_account_name');
}
-else
-{
- gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null, true);
- set_focus('account_code');
-}
-bank_account_types_list_row(_("Account Type:"), 'account_type', null);
-
-text_row(_("Bank Name:"), 'bank_name', null, 50, 60);
text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100);
-text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 60);
+
+bank_account_types_list_row(_("Account Type:"), 'account_type', null);
if ($is_editing)
{
currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
}
+if($is_editing)
+ label_row(_("Bank Account GL Code:"), $_POST['account_code']);
+else
+ gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null, false);
+
+text_row(_("Bank Name:"), 'bank_name', null, 50, 60);
+text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 60);
textarea_row(_("Bank Address:"), 'bank_address', null, 40, 5);
end_table(1);
end_row();
start_row();
label_cells(_("Date"), sql2date($from_trans['trans_date']), "class='tableheader2'");
-label_cells(_("Transfer Type"), $from_trans['BankTransType'], "class='tableheader2'");
+label_cells(_("Transfer Type"), bank_account_types::transfer_type($from_trans['account_type']), "class='tableheader2'");
label_cells(_("Reference"), $from_trans['ref'], "class='tableheader2'");
end_row();
comments_display_row(systypes::bank_transfer(), $trans_no);
end_row();
start_row();
label_cells(_("From"), payment_person_types::person_name($to_trans['person_type_id'], $to_trans['person_id']), "class='tableheader2'", "colspan=$colspan1");
-label_cells(_("Deposit Type"), $to_trans['BankTransType'], "class='tableheader2'");
+label_cells(_("Deposit Type"), bank_account_types::transfer_type($to_trans['account_type']), "class='tableheader2'");
end_row();
start_row();
label_cells(_("Reference"), $to_trans['ref'], "class='tableheader2'", "colspan=$colspan2");
end_row();
start_row();
label_cells(_("Pay To"), payment_person_types::person_name($from_trans['person_type_id'], $from_trans['person_id']), "class='tableheader2'", "colspan=$colspan1");
-label_cells(_("Payment Type"), $from_trans['BankTransType'], "class='tableheader2'");
+label_cells(_("Payment Type"),bank_account_types::transfer_type($from_trans['account_type']), "class='tableheader2'");
end_row();
start_row();
label_cells(_("Reference"), $from_trans['ref'], "class='tableheader2'", "colspan=$colspan2");
include_once($path_to_root . "/gl/includes/gl_db.inc");
//----------------------------------------------------------------------------------
-
+// Check if given account is used by any bank_account.
+// Returns id of first bank_account using account_code, null otherwise.
+//
+// Keep in mind that direct posting to bank account is depreciated
+// because we have no way to select right bank account if
+// there is more than one using given gl account.
+//
function is_bank_account($account_code)
{
- $sql= "SELECT account_code FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
- $result = db_query($sql, "retreive bank account currency");
-
- return (db_num_rows($result) > 0);
+ $sql= "SELECT id FROM ".TB_PREF."bank_accounts WHERE account_code='$account_code'";
+ $result = db_query($sql, "checking account is bank account");
+ if (db_num_rows($result) > 0) {
+ $acct = db_fetch($result);
+ return $acct['id'];
+ } else
+ return false;
}
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
-function get_bank_account_currency($bankAccount)
+function get_bank_account_currency($id)
{
- $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE account_code='$bankAccount'";
+ $sql= "SELECT bank_curr_code FROM ".TB_PREF."bank_accounts WHERE id='$id'";
$result = db_query($sql, "retreive bank account currency");
$myrow = db_fetch_row($result);
}
}
-function db_has_bank_trans_types()
-{
- return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_trans_types");
-}
-
-function check_db_has_bank_trans_types($msg)
-{
- global $path_to_root;
- if (!db_has_bank_trans_types())
- {
- display_error($msg, true);
- end_page();
- exit;
- }
-}
-
function db_customer_has_branches($customer_id)
{
return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE debtor_no='$customer_id'");
//----------------------------------------------------------------------------------
$bank_account_types_array = array (
- 0=> array ('id' => 0, 'name' => _("Savings Account")),
- 1=> array ('id' => 1, 'name' => _("Chequing Account")),
- 2=> array ('id' => 2, 'name' => _("Credit Account")),
- 3=> array ('id' => 3, 'name' => _("Cash Account"))
- );
+ 0=> array ('id' => 0, 'name' => _("Savings Account"), 'ptype' => _("Transfer")),
+ 1=> array ('id' => 1, 'name' => _("Chequing Account"),'ptype' => _("Cheque")),
+ 2=> array ('id' => 2, 'name' => _("Credit Account"), 'ptype' => _("Credit")),
+ 3=> array ('id' => 3, 'name' => _("Cash Account"), 'ptype' => _("Cash"))
+ );
class bank_account_types
{
global $bank_account_types_array;
return $bank_account_types_array[$index]['name'];
}
+
+ function transfer_type($index)
+ {
+ global $bank_account_types_array;
+ return $bank_account_types_array[$index]['ptype'];
+ }
}
-
//----------------------------------------------------------------------------------
include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
}
//-----------------------------------------------------------------------------------------------
-
+/*
function bank_trans_types_list($name, $selected_id=null)
{
$sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types";
bank_trans_types_list_cells($label, $name, $selected_id);
echo "</tr>\n";
}
-
+*/
//-----------------------------------------------------------------------------------------------
function workcenter_list($name, $selected_id=null, $all_option=false)
function bank_accounts_list($name, $selected_id=null, $submit_on_change=false)
{
- $sql = "SELECT ".TB_PREF."bank_accounts.account_code, bank_account_name, bank_curr_code
+ $sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code
FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
WHERE ".TB_PREF."bank_accounts.account_code=".TB_PREF."chart_master.account_code";
- return combo_input($name, $selected_id, $sql, 'account_code', 'bank_account_name',
+ return combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
array(
'format' => '_format_add_curr',
'select_submit'=> $submit_on_change,
<?php
-function add_supp_payment($supplier_id, $date_, $payment_type, $bank_account,
+function add_supp_payment($supplier_id, $date_, $bank_account,
$amount, $discount, $ref, $memo_)
{
begin_transaction();
$supplier_currency = get_supplier_currency($supplier_id);
$bank_account_currency = get_bank_account_currency($bank_account);
+ $bank_gl_account = get_bank_gl_account($bank_account);
$supp_amount = exchange_from_to($amount, $bank_account_currency, $supplier_currency, $date_);
$supp_discount = exchange_from_to($discount, $bank_account_currency, $supplier_currency, $date_);
if ($supp_amount != 0)
{
- add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_account, 0, 0,
+ add_gl_trans_supplier($trans_type, $payment_id, $date_, $bank_gl_account, 0, 0,
-$supp_amount, $supplier_id);
}
/*now enter the bank_trans entry */
add_bank_trans($trans_type, $payment_id, $bank_account, $ref,
- $date_, $payment_type, -($amount), payment_person_types::supplier(),
+ $date_, -($amount), payment_person_types::supplier(),
$supplier_id, $bank_account_currency,
"Could not add the supplier payment bank transaction");
{
// it's a payment so also get the bank account
$sql .= ", ".TB_PREF."bank_accounts.bank_name, ".TB_PREF."bank_accounts.bank_account_name, ".TB_PREF."bank_accounts.bank_curr_code,
- ".TB_PREF."bank_trans_types.name AS BankTransType, ".TB_PREF."bank_trans.amount AS BankAmount,
+ ".TB_PREF."bank_accounts.account_type AS BankTransType, ".TB_PREF."bank_trans.amount AS BankAmount,
".TB_PREF."bank_trans.ref ";
}
if ($trans_type == 22)
{
// it's a payment so also get the bank account
- $sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts, ".TB_PREF."bank_trans_types ";
+ $sql .= ", ".TB_PREF."bank_trans, ".TB_PREF."bank_accounts";
}
$sql .= " WHERE ".TB_PREF."supp_trans.trans_no=$trans_no
// it's a payment so also get the bank account
$sql .= " AND ".TB_PREF."bank_trans.trans_no =$trans_no
AND ".TB_PREF."bank_trans.type=$trans_type
- AND ".TB_PREF."bank_trans_types.id = ".TB_PREF."bank_trans.bank_trans_type_id
- AND ".TB_PREF."bank_accounts.account_code=".TB_PREF."bank_trans.bank_act ";
+ AND ".TB_PREF."bank_accounts.id=".TB_PREF."bank_trans.bank_act ";
}
$result = db_query($sql, "Cannot retreive a supplier transaction");
check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
-check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
-
//----------------------------------------------------------------------------------------
if ($ret = context_restore()) {
if(isset($ret['supplier_id']))
}
if (isset($_POST['_supplier_id_editor'])) {
context_call($path_to_root.'/purchasing/manage/suppliers.php?supplier_id='.$_POST['supplier_id'],
- array( 'supplier_id', 'bank_account', 'DatePaid',
- 'PaymentType', 'ref', 'amount', 'discount', 'memo_') );
+ array( 'supplier_id', 'bank_account', 'DatePaid', 'ref', 'amount',
+ 'discount', 'memo_') );
}
if (isset($_POST['_DatePaid_changed'])) {
$Ajax->activate('_ex_rate');
exchange_rate_display($bank_currency, $supplier_currency, $_POST['DatePaid']);
}
- bank_trans_types_list_row(_("Payment Type:"), 'PaymentType', null);
-
ref_row(_("Reference:"), 'ref', '', references::get_next(22));
text_row(_("Memo:"), 'memo_', null, 52,50);
function handle_add_payment()
{
$payment_id = add_supp_payment($_POST['supplier_id'], $_POST['DatePaid'],
- $_POST['PaymentType'], $_POST['bank_account'],
- input_num('amount'), input_num('discount'), $_POST['ref'], $_POST['memo_']);
+ $_POST['bank_account'], input_num('amount'), input_num('discount'),
+ $_POST['ref'], $_POST['memo_']);
//unset($_POST['supplier_id']);
unset($_POST['bank_account']);
unset($_POST['DatePaid']);
- unset($_POST['PaymentType']);
unset($_POST['currency']);
unset($_POST['memo_']);
unset($_POST['amount']);
if ($show_currencies)
label_cells(_("Payment Currency"), $receipt['bank_curr_code'], "class='tableheader2'");
label_cells(_("Amount"), number_format2(-$receipt['BankAmount'], user_price_dec()), "class='tableheader2'");
-label_cells(_("Payment Type"), $receipt['BankTransType'], "class='tableheader2'");
+label_cells(_("Payment Type"), bank_account_types::transfer_type($receipt['BankTransType']), "class='tableheader2'");
end_row();
start_row();
if ($show_currencies)
check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
-check_db_has_bank_trans_types(_("There are no bank payment types defined in the system."));
-
//----------------------------------------------------------------------------------------
if ($ret = context_restore()) {
if(isset($ret['customer_id']))
if (isset($_POST['_customer_id_editor'])) {
context_call($path_to_root.'/sales/manage/customers.php?debtor_no='.$_POST['customer_id'],
array( 'customer_id', 'BranchID', 'bank_account', 'DateBanked',
- 'ReceiptType', 'ref', 'amount', 'discount', 'memo_') );
+ 'ref', 'amount', 'discount', 'memo_') );
}
if (isset($_GET['AddedID'])) {
if (isset($_POST['AddPaymentItem'])) {
$payment_no = write_customer_payment(0, $_POST['customer_id'], $_POST['BranchID'],
- $_POST['bank_account'], $_POST['DateBanked'], $_POST['ReceiptType'], $_POST['ref'],
+ $_POST['bank_account'], $_POST['DateBanked'], $_POST['ref'],
input_num('amount'), input_num('discount'), $_POST['memo_']);
-
meta_forward($_SERVER['PHP_SELF'], "AddedID=$payment_no");
}
exchange_rate_display($cust_currency, $bank_currency, $_POST['DateBanked']);
}
- bank_trans_types_list_row(_("Type:"), 'ReceiptType', null);
-
text_row(_("Reference:"), 'ref', null, 20, 40);
textarea_row(_("Memo:"), 'memo_', null, 22, 4);
Write/update customer payment.
*/
function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_account,
- $date_, $receipt_type, $ref, $amount, $discount, $memo_)
+ $date_, $ref, $amount, $discount, $memo_)
{
begin_transaction();
$payment_no = write_customer_trans(12, $trans_no,
$customer_id, $branch_id, $date_, $ref, $amount, $discount);
+ $bank_gl_account = get_bank_gl_account($bank_account);
+
if ($trans_no != 0) {
delete_comments(12, $trans_no);
void_bank_trans(12, $trans_no, true);
/* Bank account entry first */
add_gl_trans_customer(12, $payment_no, $date_,
- $bank_account, 0, 0, $amount, $customer_id,
+ $bank_gl_account, 0, 0, $amount, $customer_id,
"Cannot insert a GL transaction for the bank account debit");
if ($branch_id != reserved_words::get_any_numeric()) {
/*now enter the bank_trans entry */
add_bank_trans(12, $payment_no, $bank_account, $ref,
- $date_, $receipt_type, $amount, payment_person_types::customer(), $customer_id,
+ $date_, $amount, payment_person_types::customer(), $customer_id,
get_customer_currency($customer_id));
add_comments(12, $payment_no, $date_, $memo_);
// and change line below.
$discount = 0; // $invoice->cash_discount*$amount;
$pmtno = write_customer_payment(0, $invoice->customer_id,
- $invoice->Branch, $invoice->cash_account, $date_, 1,
+ $invoice->Branch, $invoice->cash_account, $date_,
references::get_next(12), $amount-$discount, $discount,
_('Cash invoice').' '.$invoice->trans_no);
add_cust_allocation($amount, 12, $pmtno, 10, $invoice_no);
label_cells(_("Discount"), price_format($receipt['ov_discount']), "class='tableheader2'");
end_row();
start_row();
-label_cells(_("Payment Type"), $receipt['BankTransType'], "class='tableheader2'");
+label_cells(_("Payment Type"),
+ bank_account_types::transfer_type($receipt['BankTransType']), "class='tableheader2'");
label_cells(_("Reference"), $receipt['reference'], "class='tableheader2'", "colspan=4");
end_row();
comments_display_row(systypes::cust_payment(), $trans_id);
+ALTER TABLE `0_bank_accounts` DROP PRIMARY KEY;
+ALTER TABLE `0_bank_accounts` ADD `id` SMALLINT(6) AUTO_INCREMENT PRIMARY KEY;
+ALTER TABLE `0_bank_accounts` ADD KEY (`account_code`);
+
+# Version for any MySQL but usable with digital only gl account codes:
+# UPDATE 0_bank_accounts SET id = account_code;
+# For any Applicable only to MySQL >=4.0.4 :
+UPDATE `0_bank_trans`, `0_bank_accounts` SET 0_bank_trans.bank_act=0_bank_accounts.id
+ WHERE 0_bank_trans.bank_act=0_bank_accounts.account_code; */
+
+
ALTER TABLE `0_users` ADD `query_size` TINYINT(1) DEFAULT '10';
DROP TABLE IF EXISTS `0_sales_pos`;