f0fd7edbdfd3e02352af63bd398044f390d5d5ec
[fa-stable.git] / gl / manage / gl_account_classes.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("GL Account Classes"));
8
9 include($path_to_root . "/gl/includes/gl_db.inc");
10
11 include($path_to_root . "/includes/ui.inc");
12
13 if (isset($_GET['selected_id']))
14 {
15         $selected_id = $_GET['selected_id'];
16
17 elseif(isset($_POST['selected_id']))
18 {
19         $selected_id = $_POST['selected_id'];
20 }
21 else
22         $selected_id = -1;
23 //-----------------------------------------------------------------------------------
24
25 function can_process() 
26 {
27
28         if (strlen($_POST['name']) == 0) 
29         {
30                 display_error( _("The account class name cannot be empty."));
31                 set_focus('name');
32                 return false;
33         }
34
35         return true;
36 }
37
38 //-----------------------------------------------------------------------------------
39
40 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
41 {
42
43         if (can_process()) 
44         {
45
46         if ($selected_id != -1) 
47         {
48
49                 update_account_class($selected_id, $_POST['name'], $_POST['Balance']);
50
51         } 
52         else 
53         {
54
55                 add_account_class($_POST['id'], $_POST['name'], $_POST['Balance']);
56         }
57                 meta_forward($_SERVER['PHP_SELF']);
58         }
59 }
60
61 //-----------------------------------------------------------------------------------
62
63 function can_delete($selected_id)
64 {
65         if ($selected_id == -1)
66                 return false;
67         $sql= "SELECT COUNT(*) FROM ".TB_PREF."chart_types
68                 WHERE class_id=$selected_id";
69         $result = db_query($sql, "could not query chart master");
70         $myrow = db_fetch_row($result);
71         if ($myrow[0] > 0) 
72         {
73                 display_error(_("Cannot delete this account class because GL account types have been created referring to it."));
74                 return false;
75         }
76
77         return true;
78 }
79
80
81 //-----------------------------------------------------------------------------------
82
83 if (isset($_GET['delete'])) 
84 {
85
86         if (can_delete($selected_id))
87         {
88                 delete_account_class($selected_id);
89                 meta_forward($_SERVER['PHP_SELF']);
90         }
91 }
92
93 //-----------------------------------------------------------------------------------
94
95 $result = get_account_classes();
96
97 start_table($table_style);
98 $th = array(_("Class ID"), _("Class Name"), _("Balance Sheet"), "", "");
99 table_header($th);
100
101 $k = 0;
102 while ($myrow = db_fetch($result)) 
103 {
104
105         alt_table_row_color($k);
106
107         if ($myrow["balance_sheet"] == 0) 
108         {
109                 $bs_text = _("No");
110         } 
111         else 
112         {
113                 $bs_text = _("Yes");
114         }
115         label_cell($myrow["cid"]);
116         label_cell($myrow['class_name']);
117         label_cell($bs_text);
118         edit_link_cell("selected_id=" . $myrow["cid"]);
119         delete_link_cell("selected_id=" . $myrow["cid"]. "&delete=1");
120         end_row();
121 }
122
123 end_table();
124
125 //-----------------------------------------------------------------------------------
126
127 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Account Class"));
128
129 start_form();
130
131 start_table($table_style2);
132
133 if ($selected_id != -1) 
134 {
135         //editing an existing status code
136
137         $myrow = get_account_class($selected_id);
138
139         $_POST['id']  = $myrow["cid"];
140         $_POST['name']  = $myrow["class_name"];
141         $_POST['Balance']  = $myrow["balance_sheet"];
142         hidden('selected_id', $selected_id);
143         label_row(_("Class ID:"), $_POST['id']);
144
145
146 else 
147 {
148
149         text_row_ex(_("Class ID:"), 'id', 3);
150 }
151
152 text_row_ex(_("Class Name:"), 'name', 50);
153
154 yesno_list_row(_("Balance Sheet:"), 'Balance', null, "", "", false);
155
156 end_table(1);
157
158 submit_add_or_update_center($selected_id == -1);
159
160 end_form();
161
162 //------------------------------------------------------------------------------------
163
164 end_page();
165
166 ?>