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