5 include($path_to_root . "/includes/session.inc");
7 page(_("Bank Accounts"));
9 include($path_to_root . "/includes/ui.inc");
12 //-----------------------------------------------------------------------------------
14 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
17 //initialise no input errors assumed initially before we test
20 //first off validate inputs sensible
21 if (strlen($_POST['bank_account_name']) == 0)
24 display_error(_("The bank account name cannot be empty."));
25 set_focus('bank_account_name');
28 if ($input_error != 1)
30 if ($selected_id != -1)
33 update_bank_account($selected_id, $_POST['account_code'],
34 $_POST['account_type'], $_POST['bank_account_name'],
35 $_POST['bank_name'], $_POST['bank_account_number'],
36 $_POST['bank_address'], $_POST['BankAccountCurrency']);
37 display_notification(_('Bank account has been updated'));
42 add_bank_account($_POST['account_code'], $_POST['account_type'],
43 $_POST['bank_account_name'], $_POST['bank_name'],
44 $_POST['bank_account_number'], $_POST['bank_address'],
45 $_POST['BankAccountCurrency']);
46 display_notification(_('New bank account has been added'));
51 elseif( $Mode == 'Delete')
53 //the link to delete a selected record was clicked instead of the submit button
57 // PREVENT DELETES IF DEPENDENT RECORDS IN 'bank_trans'
59 $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_trans WHERE bank_act='$selected_id'";
60 $result = db_query($sql,"check failed");
61 $myrow = db_fetch_row($result);
65 display_error(_("Cannot delete this bank account because transactions have been created using this account."));
69 delete_bank_account($selected_id);
70 display_notification(_('Selected bank account has been deleted'));
71 } //end if Delete bank account
78 $_POST['bank_name'] = $_POST['bank_account_name'] = '';
79 $_POST['bank_account_number'] = $_POST['bank_address'] = '';
82 /* Always show the list of accounts */
84 $sql = "SELECT account.*, gl_account.account_name
85 FROM ".TB_PREF."bank_accounts account, ".TB_PREF."chart_master gl_account
86 WHERE account.account_code = gl_account.account_code"
87 ." ORDER BY account_code, bank_curr_code";
89 $result = db_query($sql,"could not get bank accounts");
91 check_db_error("The bank accounts set up could not be retreived", $sql);
94 start_table("$table_style width='80%'");
96 $th = array(_("Account Name"), _("Type"), _("Currency"), _("GL Account"),
97 _("Bank"), _("Number"), _("Bank Address"),'','');
101 while ($myrow = db_fetch($result))
104 alt_table_row_color($k);
106 label_cell($myrow["bank_account_name"], "nowrap");
107 label_cell(bank_account_types::name($myrow["account_type"]), "nowrap");
108 label_cell($myrow["bank_curr_code"], "nowrap");
109 label_cell($myrow["account_code"] . " " . $myrow["account_name"], "nowrap");
110 label_cell($myrow["bank_name"], "nowrap");
111 label_cell($myrow["bank_account_number"], "nowrap");
112 label_cell($myrow["bank_address"]);
113 edit_button_cell("Edit".$myrow["id"], _("Edit"));
114 edit_button_cell("Delete".$myrow["id"], _("Delete"));
123 $is_editing = $selected_id != -1;
125 start_table($table_style2);
129 if ($Mode == 'Edit') {
130 $myrow = get_bank_account($selected_id);
132 $_POST['account_code'] = $myrow["account_code"];
133 $_POST['account_type'] = $myrow["account_type"];
134 $_POST['bank_name'] = $myrow["bank_name"];
135 $_POST['bank_account_name'] = $myrow["bank_account_name"];
136 $_POST['bank_account_number'] = $myrow["bank_account_number"];
137 $_POST['bank_address'] = $myrow["bank_address"];
138 $_POST['BankAccountCurrency'] = $myrow["bank_curr_code"];
140 hidden('selected_id', $selected_id);
141 hidden('account_code');
142 hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);
143 set_focus('bank_account_name');
146 text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100);
148 bank_account_types_list_row(_("Account Type:"), 'account_type', null);
152 label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']);
156 currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
160 label_row(_("Bank Account GL Code:"), $_POST['account_code']);
162 gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null, false);
164 text_row(_("Bank Name:"), 'bank_name', null, 50, 60);
165 text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 60);
166 textarea_row(_("Bank Address:"), 'bank_address', null, 40, 5);
170 submit_add_or_update_center($selected_id == -1, '', true);