From: Janusz Dobrowolski Date: Sun, 9 Nov 2008 18:14:36 +0000 (+0000) Subject: Allowed multiply bank accounts on same gl account, removed bank trans type. X-Git-Tag: v2.4.2~19^2~1784 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=45e45a854c40a7a2f9cc8f11e07a259c6923babd Allowed multiply bank accounts on same gl account, removed bank trans type. --- diff --git a/applications/generalledger.php b/applications/generalledger.php index ecbc6b91..9b02b2a5 100644 --- a/applications/generalledger.php +++ b/applications/generalledger.php @@ -26,7 +26,6 @@ $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?"); diff --git a/gl/bank_transfer.php b/gl/bank_transfer.php index 6699a1a5..87e82c71 100644 --- a/gl/bank_transfer.php +++ b/gl/bank_transfer.php @@ -19,7 +19,6 @@ if ($use_date_picker) 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.")); //---------------------------------------------------------------------------------------- @@ -77,8 +76,6 @@ function gl_payment_controls() echo ""; // outer table echo ""; - 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); @@ -148,8 +145,7 @@ function handle_add_deposit() 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"); } diff --git a/gl/gl_bank.php b/gl/gl_bank.php index ae5b1daf..b3f1c1b7 100644 --- a/gl/gl_bank.php +++ b/gl/gl_bank.php @@ -31,8 +31,6 @@ page($_SESSION['page_title'], 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 payment types defined in the system.")); - //---------------------------------------------------------------------------------------- if ($ret = context_restore()) { if(isset($ret['supplier_id'])) @@ -55,7 +53,7 @@ if (isset($_POST['_person_id_editor'])) { // 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() { @@ -170,7 +168,7 @@ if (isset($_POST['Process'])) $_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]; diff --git a/gl/includes/db/gl_db_bank_accounts.inc b/gl/includes/db/gl_db_bank_accounts.inc index 15d524e7..620b1bc3 100644 --- a/gl/includes/db/gl_db_bank_accounts.inc +++ b/gl/includes/db/gl_db_bank_accounts.inc @@ -14,38 +14,51 @@ function add_bank_account($account_code, $account_type, $bank_account_name, $ban //--------------------------------------------------------------------------------------------- -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) diff --git a/gl/includes/db/gl_db_bank_trans.inc b/gl/includes/db/gl_db_bank_trans.inc index 200277fb..a9c3deae 100644 --- a/gl/includes/db/gl_db_bank_trans.inc +++ b/gl/includes/db/gl_db_bank_trans.inc @@ -6,7 +6,7 @@ // $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_); @@ -26,9 +26,9 @@ function add_bank_trans($type, $trans_no, $bank_act, $ref, $date_, $bank_trans_t //$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 == "") @@ -52,10 +52,9 @@ function exists_bank_trans($type, $type_no) 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) diff --git a/gl/includes/db/gl_db_banking.inc b/gl/includes/db/gl_db_banking.inc index a5fe71ad..518e73c1 100644 --- a/gl/includes/db/gl_db_banking.inc +++ b/gl/includes/db/gl_db_banking.inc @@ -1,9 +1,13 @@ gl_items_total(); @@ -93,14 +104,12 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_, } // 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) { @@ -120,9 +129,8 @@ function add_bank_transaction($trans_type, $from_account, $items, $date_, 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"); } } diff --git a/gl/includes/db/gl_db_trans.inc b/gl/includes/db/gl_db_trans.inc index 79b03d80..d44e8eac 100644 --- a/gl/includes/db/gl_db_trans.inc +++ b/gl/includes/db/gl_db_trans.inc @@ -193,6 +193,7 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null) 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, @@ -200,8 +201,8 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null) $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"); } @@ -229,8 +230,8 @@ function add_journal_entries($items, $date_, $ref, $reverse, $memo_=null) $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"); } diff --git a/gl/includes/ui/gl_bank_ui.inc b/gl/includes/ui/gl_bank_ui.inc index 8d6dd32e..303d557c 100644 --- a/gl/includes/ui/gl_bank_ui.inc +++ b/gl/includes/ui/gl_bank_ui.inc @@ -87,8 +87,6 @@ function display_bank_header(&$order) echo "
"; // 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 diff --git a/gl/inquiry/bank_inquiry.php b/gl/inquiry/bank_inquiry.php index f6ffdba7..d5147f5f 100644 --- a/gl/inquiry/bank_inquiry.php +++ b/gl/inquiry/bank_inquiry.php @@ -49,11 +49,10 @@ $date_after = date2sql($_POST['TransAfterDate']); $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"); @@ -94,7 +93,6 @@ while ($myrow = db_fetch($result)) 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); diff --git a/gl/manage/bank_accounts.php b/gl/manage/bank_accounts.php index 5081e3b5..9cb56180 100644 --- a/gl/manage/bank_accounts.php +++ b/gl/manage/bank_accounts.php @@ -30,17 +30,19 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 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'; @@ -79,8 +81,11 @@ if ($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); @@ -88,8 +93,8 @@ 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; @@ -98,15 +103,15 @@ while ($myrow = db_fetch($result)) 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(); } @@ -135,20 +140,12 @@ if ($is_editing) 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) { @@ -159,6 +156,13 @@ else 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); diff --git a/gl/view/bank_transfer_view.php b/gl/view/bank_transfer_view.php index c0a25e27..3e447a4d 100644 --- a/gl/view/bank_transfer_view.php +++ b/gl/view/bank_transfer_view.php @@ -72,7 +72,7 @@ if ($show_both_amounts) 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); diff --git a/gl/view/gl_deposit_view.php b/gl/view/gl_deposit_view.php index 02a3f7e0..eafa9469 100644 --- a/gl/view/gl_deposit_view.php +++ b/gl/view/gl_deposit_view.php @@ -60,7 +60,7 @@ label_cells(_("Date"), sql2date($to_trans['trans_date']), "class='tableheader2'" 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"); diff --git a/gl/view/gl_payment_view.php b/gl/view/gl_payment_view.php index f52dc672..520de94d 100644 --- a/gl/view/gl_payment_view.php +++ b/gl/view/gl_payment_view.php @@ -58,7 +58,7 @@ label_cells(_("Date"), sql2date($from_trans['trans_date']), "class='tableheader2 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"); diff --git a/includes/banking.inc b/includes/banking.inc index 93fcb294..54345259 100644 --- a/includes/banking.inc +++ b/includes/banking.inc @@ -3,13 +3,22 @@ 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; } //---------------------------------------------------------------------------------- @@ -35,9 +44,9 @@ function get_company_currency() //---------------------------------------------------------------------------------- -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); diff --git a/includes/data_checks.inc b/includes/data_checks.inc index 2f33cb53..0b94f932 100644 --- a/includes/data_checks.inc +++ b/includes/data_checks.inc @@ -111,22 +111,6 @@ function check_db_has_movement_types($msg) } } -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'"); diff --git a/includes/types.inc b/includes/types.inc index 73efbfe1..9003eceb 100644 --- a/includes/types.inc +++ b/includes/types.inc @@ -110,11 +110,11 @@ class systypes //---------------------------------------------------------------------------------- $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 { @@ -130,8 +130,13 @@ 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"); diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 17c61441..0d38d722 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -1137,7 +1137,7 @@ function movement_types_list_row($label, $name, $selected_id=null) } //----------------------------------------------------------------------------------------------- - +/* function bank_trans_types_list($name, $selected_id=null) { $sql = "SELECT id, name FROM ".TB_PREF."bank_trans_types"; @@ -1159,7 +1159,7 @@ function bank_trans_types_list_row($label, $name, $selected_id=null) bank_trans_types_list_cells($label, $name, $selected_id); echo "\n"; } - +*/ //----------------------------------------------------------------------------------------------- function workcenter_list($name, $selected_id=null, $all_option=false) @@ -1196,11 +1196,11 @@ function workcenter_list_row($label, $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, diff --git a/purchasing/includes/db/supp_payment_db.inc b/purchasing/includes/db/supp_payment_db.inc index 38b1d440..b82ab888 100644 --- a/purchasing/includes/db/supp_payment_db.inc +++ b/purchasing/includes/db/supp_payment_db.inc @@ -1,12 +1,13 @@ activate('_ex_rate'); @@ -103,8 +101,6 @@ function display_controls() 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); @@ -193,13 +189,12 @@ function check_inputs() 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']); diff --git a/purchasing/view/view_supp_payment.php b/purchasing/view/view_supp_payment.php index 82d190a3..756f686c 100644 --- a/purchasing/view/view_supp_payment.php +++ b/purchasing/view/view_supp_payment.php @@ -49,7 +49,7 @@ start_row(); 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) diff --git a/sales/customer_payments.php b/sales/customer_payments.php index ec98198d..03639e75 100644 --- a/sales/customer_payments.php +++ b/sales/customer_payments.php @@ -24,8 +24,6 @@ check_db_has_customers(_("There are no customers defined in the system.")); 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'])) @@ -36,7 +34,7 @@ if ($ret = context_restore()) { 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'])) { @@ -121,9 +119,8 @@ if (isset($_POST['_DateBanked_changed'])) { 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"); } @@ -201,8 +198,6 @@ function display_item_form() 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); diff --git a/sales/includes/db/payment_db.inc b/sales/includes/db/payment_db.inc index 74054b06..e1147b1c 100644 --- a/sales/includes/db/payment_db.inc +++ b/sales/includes/db/payment_db.inc @@ -3,7 +3,7 @@ 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(); @@ -12,6 +12,8 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou $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); @@ -21,7 +23,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou /* 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()) { @@ -52,7 +54,7 @@ function write_customer_payment($trans_no, $customer_id, $branch_id, $bank_accou /*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_); diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index e63ce842..d1178635 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -157,7 +157,7 @@ function write_sales_invoice(&$invoice) // 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); diff --git a/sales/view/view_receipt.php b/sales/view/view_receipt.php index 1f1fbd50..cf0ae3f8 100644 --- a/sales/view/view_receipt.php +++ b/sales/view/view_receipt.php @@ -32,7 +32,8 @@ label_cells(_("Amount"), price_format($receipt['ov_amount']), "class='tableheade 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); diff --git a/sql/alter2.1.sql b/sql/alter2.1.sql index 529f2d10..cdcdd73e 100644 --- a/sql/alter2.1.sql +++ b/sql/alter2.1.sql @@ -1,3 +1,14 @@ +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`;