5 include($path_to_root . "/includes/session.inc");
7 page(_("Bank Accounts"));
9 include($path_to_root . "/includes/ui.inc");
11 if (isset($_GET['selected_id']))
13 $selected_id = $_GET['selected_id'];
15 elseif (isset($_POST['selected_id']))
17 $selected_id = $_POST['selected_id'];
20 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
23 //initialise no input errors assumed initially before we test
26 //first off validate inputs sensible
27 if (strlen($_POST['bank_account_name']) == 0)
30 display_error(_("The bank account name cannot be empty."));
31 set_focus('bank_account_name');
34 if ($input_error != 1)
36 if (isset($selected_id))
39 update_bank_account($selected_id, $_POST['account_type'], $_POST['bank_account_name'], $_POST['bank_name'],
40 $_POST['bank_account_number'],
41 $_POST['bank_address'], $_POST['BankAccountCurrency']);
46 add_bank_account($_POST['account_code'], $_POST['account_type'], $_POST['bank_account_name'], $_POST['bank_name'],
47 $_POST['bank_account_number'],
48 $_POST['bank_address'], $_POST['BankAccountCurrency']);
51 meta_forward($_SERVER['PHP_SELF']);
55 elseif (isset($_GET['delete']))
57 //the link to delete a selected record was clicked instead of the submit button
61 // PREVENT DELETES IF DEPENDENT RECORDS IN 'bank_trans'
63 $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_trans WHERE bank_act='$selected_id'";
64 $result = db_query($sql,"check failed");
65 $myrow = db_fetch_row($result);
69 display_error(_("Cannot delete this bank account because transactions have been created using this account."));
73 delete_bank_account($selected_id);
74 meta_forward($_SERVER['PHP_SELF']);
75 } //end if Delete bank account
78 /* Always show the list of accounts */
80 $sql = "SELECT ".TB_PREF."bank_accounts.*, ".TB_PREF."chart_master.account_name FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master
81 WHERE ".TB_PREF."bank_accounts.account_code = ".TB_PREF."chart_master.account_code";
82 $result = db_query($sql,"could not get bank accounts");
84 check_db_error("The bank accounts set up could not be retreived", $sql);
86 start_table("$table_style width='80%'");
88 $th = array(_("GL Account"), _("Bank"), _("Account Name"),
89 _("Type"), _("Number"), _("Currency"), _("Bank Address"));
93 while ($myrow = db_fetch($result))
96 alt_table_row_color($k);
98 label_cell($myrow["account_code"] . " " . $myrow["account_name"], "nowrap");
99 label_cell($myrow["bank_name"], "nowrap");
100 label_cell($myrow["bank_account_name"], "nowrap");
101 label_cell(bank_account_types::name($myrow["account_type"]), "nowrap");
102 label_cell($myrow["bank_account_number"], "nowrap");
103 label_cell($myrow["bank_curr_code"], "nowrap");
104 label_cell($myrow["bank_address"]);
105 edit_link_cell("selected_id=" . $myrow["account_code"]);
106 delete_link_cell("selected_id=" . $myrow["account_code"]. "&delete=1");
109 //END WHILE LIST LOOP
114 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Bank Account"));
118 $is_editing = (isset($selected_id) && !isset($_GET['delete']));
120 start_table($table_style2);
125 $myrow = get_bank_account($selected_id);
127 $_POST['account_code'] = $myrow["account_code"];
128 $_POST['account_type'] = $myrow["account_type"];
129 $_POST['bank_name'] = $myrow["bank_name"];
130 $_POST['bank_account_name'] = $myrow["bank_account_name"];
131 $_POST['bank_account_number'] = $myrow["bank_account_number"];
132 $_POST['bank_address'] = $myrow["bank_address"];
133 $_POST['BankAccountCurrency'] = $myrow["bank_curr_code"];
135 hidden('selected_id', $selected_id);
136 hidden('account_code', $_POST['account_code']);
137 hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);
138 label_row(_("Bank Account GL Code:"), $_POST['account_code']);
142 gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null, true);
145 bank_account_types_list_row(_("Account Type:"), 'account_type', null);
147 text_row(_("Bank Name:"), 'bank_name', null, 50, 50);
148 text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 50);
149 text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 30);
153 label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']);
157 currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
160 textarea_row(_("Bank Address:"), 'bank_address', null, 40, 5);
161 //text_row(_("Bank Address:"), 'bank_address', null, 70, 70);
165 submit_add_or_update_center(!isset($selected_id));