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