14b4e7949bffe050d0665ce7fcec2951d53135b1
[fa-stable.git] / gl / manage / bank_accounts.php
1 <?php
2
3 $page_security = 10;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("Bank Accounts"));
8
9 include($path_to_root . "/includes/ui.inc");
10
11 if (isset($_GET['selected_id'])) 
12 {
13         $selected_id = $_GET['selected_id'];
14
15 elseif (isset($_POST['selected_id'])) 
16 {
17         $selected_id = $_POST['selected_id'];
18 }
19
20 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
21 {
22
23         //initialise no input errors assumed initially before we test
24         $input_error = 0;
25
26         //first off validate inputs sensible
27         if (strlen($_POST['bank_account_name']) == 0) 
28         {
29                 $input_error = 1;
30                 display_error(_("The bank account name cannot be empty."));
31         } 
32         
33         if ($input_error != 1)
34         {
35         if (isset($selected_id)) 
36         {
37                 
38                 update_bank_account($selected_id, $_POST['account_type'], $_POST['bank_account_name'], $_POST['bank_name'], 
39                         $_POST['bank_account_number'], 
40                         $_POST['bank_address'], $_POST['BankAccountCurrency']);         
41         } 
42         else 
43         {
44     
45                 add_bank_account($_POST['account_code'], $_POST['account_type'], $_POST['bank_account_name'], $_POST['bank_name'], 
46                         $_POST['bank_account_number'], 
47                         $_POST['bank_address'], $_POST['BankAccountCurrency']);
48         }
49                 
50                 meta_forward($_SERVER['PHP_SELF']); 
51         }
52
53
54 elseif (isset($_GET['delete'])) 
55 {
56         //the link to delete a selected record was clicked instead of the submit button
57
58         $cancel_delete = 0;
59
60         // PREVENT DELETES IF DEPENDENT RECORDS IN 'bank_trans'
61
62         $sql= "SELECT COUNT(*) FROM ".TB_PREF."bank_trans WHERE bank_act='$selected_id'";
63         $result = db_query($sql,"check failed");
64         $myrow = db_fetch_row($result);
65         if ($myrow[0] > 0) 
66         {
67                 $cancel_delete = 1;
68                 display_error(_("Cannot delete this bank account because transactions have been created using this account."));
69         }
70         if (!$cancel_delete) 
71         {
72                 delete_bank_account($selected_id);
73                 meta_forward($_SERVER['PHP_SELF']);
74         } //end if Delete bank account
75 }
76
77 /* Always show the list of accounts */
78
79 $sql = "SELECT ".TB_PREF."bank_accounts.*, ".TB_PREF."chart_master.account_name FROM ".TB_PREF."bank_accounts, ".TB_PREF."chart_master 
80         WHERE ".TB_PREF."bank_accounts.account_code = ".TB_PREF."chart_master.account_code";
81 $result = db_query($sql,"could not get bank accounts");
82
83 check_db_error("The bank accounts set up could not be retreived", $sql);
84
85 start_table("$table_style width='80%'");
86
87 $th = array(_("GL Account"), _("Bank"), _("Account Name"),
88         _("Type"), _("Number"), _("Currency"), _("Bank Address"));
89 table_header($th);      
90
91 $k = 0; 
92 while ($myrow = db_fetch($result)) 
93 {
94         
95         alt_table_row_color($k);
96
97     label_cell($myrow["account_code"] . " " . $myrow["account_name"], "nowrap");
98     label_cell($myrow["bank_name"], "nowrap");
99     label_cell($myrow["bank_account_name"], "nowrap");
100         label_cell(bank_account_types::name($myrow["account_type"]), "nowrap");
101     label_cell($myrow["bank_account_number"], "nowrap");
102     label_cell($myrow["bank_curr_code"], "nowrap");
103     label_cell($myrow["bank_address"]);
104     edit_link_cell("selected_id=" . $myrow["account_code"]);
105     delete_link_cell("selected_id=" . $myrow["account_code"]. "&delete=1");
106     end_row(); 
107 }
108 //END WHILE LIST LOOP
109
110
111 end_table();
112
113 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Bank Account"));
114
115 start_form();
116
117 $is_editing = (isset($selected_id) && !isset($_GET['delete'])); 
118
119 start_table($table_style2);
120
121 if ($is_editing) 
122 {
123         
124         $myrow = get_bank_account($selected_id);
125
126         $_POST['account_code'] = $myrow["account_code"];
127         $_POST['account_type'] = $myrow["account_type"];
128         $_POST['bank_name']  = $myrow["bank_name"];
129         $_POST['bank_account_name']  = $myrow["bank_account_name"];
130         $_POST['bank_account_number'] = $myrow["bank_account_number"];
131         $_POST['bank_address'] = $myrow["bank_address"];
132         $_POST['BankAccountCurrency'] = $myrow["bank_curr_code"];
133
134         hidden('selected_id', $selected_id);
135         hidden('account_code', $_POST['account_code']);
136         hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);   
137         label_row(_("Bank Account GL Code:"), $_POST['account_code']);
138
139 else 
140 {
141         gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null, true);       
142 }
143
144 bank_account_types_list_row(_("Account Type:"), 'account_type', null); 
145
146 text_row(_("Bank Name:"), 'bank_name', null, 50, 50);
147 text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 50);
148 text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 30);
149
150 if ($is_editing) 
151 {
152         label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']);
153
154 else 
155 {
156         currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
157 }       
158
159 textarea_row(_("Bank Address:"), 'bank_address', null, 40, 5);
160 //text_row(_("Bank Address:"), 'bank_address', null, 70, 70);
161
162 end_table(1);
163
164 submit_add_or_update_center(!isset($selected_id));
165
166 end_form();
167
168 end_page();
169 ?>