*** empty log message ***
[fa-stable.git] / gl / manage / gl_quick_entries.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("Quick Entries"));
8
9 include($path_to_root . "/gl/includes/gl_db.inc");
10
11 include($path_to_root . "/includes/ui.inc");
12
13 simple_page_mode(true);
14 simple_page_mode2(true);
15
16 function simple_page_mode2($numeric_id = true)
17 {
18         global $Ajax, $Mode2, $selected_id2;
19
20         $default = $numeric_id ? -1 : '';
21         $selected_id2 = get_post('selected_id2', $default);
22         foreach (array('ADD_ITEM2', 'UPDATE_ITEM2', 'RESET2') as $m) {
23                 if (isset($_POST[$m])) {
24                         $Ajax->activate('_page_body');
25                         if ($m == 'RESET2') 
26                                 $selected_id2 = $default;
27                         $Mode2 = $m; return;
28                 }
29         }
30         foreach (array('BEd', 'BDel') as $m) {
31                 foreach ($_POST as $p => $pvar) {
32                         if (strpos($p, $m) === 0) {
33 //                              $selected_id2 = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
34                                 unset($_POST['_focus']); // focus on first form entry
35                                 $selected_id2 = quoted_printable_decode(substr($p, strlen($m)));
36                                 $Ajax->activate('_page_body');
37                                 $Mode2 = $m;
38                                 return;
39                         }
40                 }
41         }
42         $Mode2 = '';
43 }
44
45 function submit_add_or_update_center2($add=true, $title=false, $async=false)
46 {
47         echo "<center>";
48         if ($add)
49                 submit('ADD_ITEM2', _("Add new"), true, $title, $async);
50         else {
51                 submit('UPDATE_ITEM2', _("Update"), true, $title, $async);
52                 submit('RESET2', _("Cancel"), true, $title, $async);
53         }
54         echo "</center>";
55 }
56
57 //-----------------------------------------------------------------------------------
58
59 function can_process() 
60 {
61
62         if (strlen($_POST['description']) == 0) 
63         {
64                 display_error( _("The Quick Entry description cannot be empty."));
65                 set_focus('description');
66                 return false;
67         }
68
69         return true;
70 }
71
72 //-----------------------------------------------------------------------------------
73
74 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
75 {
76
77         if (can_process())      
78         {       
79
80                 if ($selected_id != -1) 
81                 {
82                         update_quick_entry($selected_id, $_POST['description'], $_POST['deposit'], $_POST['bank_only']);
83                         display_notification(_('Selected quick entry has been updated'));
84                 } 
85                 else 
86                 {
87                         add_quick_entry($_POST['description'], $_POST['deposit'], $_POST['bank_only']);
88                         display_notification(_('New quick entry has been added'));
89                 }
90                 $Mode = 'RESET';
91         }
92 }
93
94 if ($Mode2=='ADD_ITEM2' || $Mode2=='UPDATE_ITEM2') 
95 {
96         if ($selected_id2 != -1) 
97         {
98                 update_quick_entry_line($selected_id2, $selected_id, $_POST['account'], $_POST['tax_acc'], $_POST['pct'], input_num('amount', 0), 
99                         $_POST['dimension_id'], $_POST['dimension2_id']);
100                 display_notification(_('Selected quick entry line has been updated'));
101         } 
102         else 
103         {
104                 add_quick_entry_line($selected_id, $_POST['account'], $_POST['tax_acc'], $_POST['pct'], input_num('amount', 0), 
105                         $_POST['dimension_id'], $_POST['dimension2_id']);
106                 display_notification(_('New quick entry line has been added'));
107         }
108         $Mode2 = 'RESET2';
109 }
110
111 //-----------------------------------------------------------------------------------
112
113 if ($Mode == 'Delete')
114 {
115         if (!has_quick_entry_lines($selected_id))
116         {
117                 delete_quick_entry($selected_id);
118                 display_notification(_('Selected quick entry has been deleted'));
119                 $Mode = 'RESET';
120         }
121         else
122         {
123                 display_error( _("The Quick Entry has Quick Entry Lines. Cannot be deleted."));
124                 set_focus('description');
125         }
126 }
127
128 if ($Mode2 == 'BDel')
129 {
130         delete_quick_entry_line($selected_id2);
131         display_notification(_('Selected quick entry line has been deleted'));
132         $Mode2 = 'RESET2';
133 }
134 //-----------------------------------------------------------------------------------
135 if ($Mode == 'RESET')
136 {
137         $selected_id = -1;
138         $_POST['description'] = $_POST['deposit'] = $_POST['bank_only'] = '';
139 }
140 if ($Mode2 == 'RESET2')
141 {
142         $selected_id2 = -1;
143         $_POST['account'] = $_POST['tax_acc'] = $_POST['pct'] = $_POST['amount'] = $_POST['dimension_id'] = $_POST['dimension2_id'] = '';
144 }
145 //-----------------------------------------------------------------------------------
146
147 $result = get_quick_entries();
148 start_form();
149 start_table($table_style);
150 $th = array(_("Description"), _("Deposit"), _("Bank Only"), "", "");
151 table_header($th);
152
153 $k = 0;
154 while ($myrow = db_fetch($result)) 
155 {
156         alt_table_row_color($k);
157         $deposit_text = ($myrow["deposit"] == 0 ? _("No") : _("Yes"));
158         $bank_text = ($myrow["bank_only"] == 0 ? _("No") : _("Yes"));
159         label_cell($myrow['description']);
160         label_cell($deposit_text);
161         label_cell($bank_text);
162         edit_button_cell("Edit".$myrow["id"], _("Edit"));
163         edit_button_cell("Delete".$myrow["id"], _("Delete"));
164         end_row();
165 }
166
167 end_table();
168 end_form();
169 //-----------------------------------------------------------------------------------
170
171 start_form();
172
173 start_table($table_style2);
174
175 if ($selected_id != -1) 
176 {
177         //if ($Mode == 'Edit') 
178         //{
179                 //editing an existing status code
180                 $myrow = get_quick_entry($selected_id);
181
182                 $_POST['id']  = $myrow["id"];
183                 $_POST['description']  = $myrow["description"];
184                 $_POST['deposit']  = $myrow["deposit"];
185                 $_POST['bank_only']  = $myrow["bank_only"];
186                 hidden('selected_id', $selected_id);
187         //}
188
189
190 text_row_ex(_("Description:"), 'description', 50, 60);
191
192 yesno_list_row(_("Deposit:"), 'deposit', null, "", "", false);
193
194 yesno_list_row(_("Bank Only:"), 'bank_only', null, "", "", false);
195
196 end_table(1);
197
198 submit_add_or_update_center($selected_id == -1, '', true);
199
200 end_form();
201
202 if ($selected_id != -1)
203 {
204         display_heading(_("Quick Entry Lines") . " - " . $_POST['description']);
205         $result = get_quick_entry_lines($selected_id);
206         start_form();
207         start_table($table_style2);
208         $dim = get_company_pref('use_dimension');
209         if ($dim == 2)
210                 $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", "");
211         else if ($dim == 1)     
212                 $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), "", "");
213         else    
214                 $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), "", "");
215         table_header($th);
216         $k = 0;
217         while ($myrow = db_fetch($result)) 
218         {
219                 alt_table_row_color($k);
220                 label_cell($myrow['account']." ".$myrow['account_name']);
221                 $tax_text = ($myrow['tax_acc'] == 0 ? _("No") : _("Yes"));
222                 label_cell($tax_text);
223                 $pct_text = ($myrow['pct'] == 0 ? _("No") : _("Yes"));
224                 label_cell($pct_text);
225                 amount_cell($myrow['amount']);
226                 if ($dim >= 1)
227                         label_cell(get_dimension_string($myrow['dimension_id'], true));
228                 if ($dim > 1)
229                         label_cell(get_dimension_string($myrow['dimension2_id'], true));
230                 edit_button_cell("BEd".$myrow["id"], _("Edit"));
231                 edit_button_cell("BDel".$myrow["id"], _("Delete"));
232                 end_row();
233         }
234         end_table();
235         hidden('selected_id', $selected_id);
236         hidden('selected_id2', $selected_id2);
237         hidden('description', $_POST['description']);
238         hidden('deposit', $_POST['deposit']);
239         hidden('bank_only', $_POST['bank_only']);
240         end_form();
241         start_form();
242
243         start_table($table_style2);
244
245         if ($selected_id2 != -1) 
246         {
247                 if ($Mode2 == 'BEd') 
248                 {
249                         //editing an existing status code
250                         $myrow = get_quick_entry_line($selected_id2);
251
252                         $_POST['id']  = $myrow["id"];
253                         $_POST['account']  = $myrow["account"];
254                         $_POST['tax_acc']  = $myrow["tax_acc"];
255                         $_POST['pct']  = $myrow["pct"];
256                         $_POST['amount']  = $myrow["amount"];
257                         $_POST['dimension_id']  = $myrow["dimension_id"];
258                         $_POST['dimension2_id']  = $myrow["dimension2_id"];
259                 }
260         } 
261
262         gl_all_accounts_list_row(_("Account"), 'account', null, true);
263         yesno_list_row(_("Use Tax:"), 'tax_acc', null, "", "", false);
264         yesno_list_row(_("Use Percent:"), 'pct', null, "", "", false);
265         amount_row(_("Amount"), 'amount', null);
266         if ($dim >= 1) 
267                 dimensions_list_row(_("Dimension"), 'dimension_id', null, true, " ", false, 1);
268         if ($dim > 1) 
269                 dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
270         
271         end_table(1);
272         if ($dim < 2)
273                 hidden('dimension2_id', 0);
274         if ($dim < 1)
275                 hidden('dimension_id', 0);
276         hidden('selected_id', $selected_id);
277         hidden('selected_id2', $selected_id2);
278         hidden('description', $_POST['description']);
279         hidden('deposit', $_POST['deposit']);
280         hidden('bank_only', $_POST['bank_only']);
281
282         submit_add_or_update_center2($selected_id2 == -1, '', true);
283
284         end_form();
285 }               
286 //------------------------------------------------------------------------------------
287
288 end_page();
289
290 ?>