2 /**********************************************************************
3 Copyright (C) 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 ***********************************************************************/
13 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_("Quick Entries"));
18 include($path_to_root . "/gl/includes/gl_db.inc");
20 include($path_to_root . "/includes/ui.inc");
22 simple_page_mode(true);
23 simple_page_mode2(true);
25 function simple_page_mode2($numeric_id = true)
27 global $Ajax, $Mode2, $selected_id2;
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');
35 $selected_id2 = $default;
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');
54 function submit_add_or_update_center2($add=true, $title=false, $async=false)
58 submit('ADD_ITEM2', _("Add new"), true, $title, $async);
60 submit('UPDATE_ITEM2', _("Update"), true, $title, $async);
61 submit('RESET2', _("Cancel"), true, $title, $async);
66 //-----------------------------------------------------------------------------------
68 function can_process()
71 if (strlen($_POST['description']) == 0)
73 display_error( _("The Quick Entry description cannot be empty."));
74 set_focus('description');
81 //-----------------------------------------------------------------------------------
83 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
89 if ($selected_id != -1)
91 update_quick_entry($selected_id, $_POST['description'], $_POST['deposit'], $_POST['bank_only']);
92 display_notification(_('Selected quick entry has been updated'));
96 add_quick_entry($_POST['description'], $_POST['deposit'], $_POST['bank_only']);
97 display_notification(_('New quick entry has been added'));
103 if ($Mode2=='ADD_ITEM2' || $Mode2=='UPDATE_ITEM2')
105 if ($selected_id2 != -1)
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'));
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'));
120 //-----------------------------------------------------------------------------------
122 if ($Mode == 'Delete')
124 if (!has_quick_entry_lines($selected_id))
126 delete_quick_entry($selected_id);
127 display_notification(_('Selected quick entry has been deleted'));
132 display_error( _("The Quick Entry has Quick Entry Lines. Cannot be deleted."));
133 set_focus('description');
137 if ($Mode2 == 'BDel')
139 delete_quick_entry_line($selected_id2);
140 display_notification(_('Selected quick entry line has been deleted'));
143 //-----------------------------------------------------------------------------------
144 if ($Mode == 'RESET')
147 $_POST['description'] = $_POST['deposit'] = $_POST['bank_only'] = '';
149 if ($Mode2 == 'RESET2')
152 $_POST['account'] = $_POST['tax_acc'] = $_POST['pct'] = $_POST['amount'] = $_POST['dimension_id'] = $_POST['dimension2_id'] = '';
154 //-----------------------------------------------------------------------------------
156 $result = get_quick_entries();
158 start_table($table_style);
159 $th = array(_("Description"), _("Deposit"), _("Bank Only"), "", "");
163 while ($myrow = db_fetch($result))
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"));
178 //-----------------------------------------------------------------------------------
182 start_table($table_style2);
184 if ($selected_id != -1)
186 //if ($Mode == 'Edit')
188 //editing an existing status code
189 $myrow = get_quick_entry($selected_id);
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);
199 text_row_ex(_("Description:"), 'description', 50, 60);
201 yesno_list_row(_("Deposit:"), 'deposit', null, "", "", false);
203 yesno_list_row(_("Bank Only:"), 'bank_only', null, "", "", false);
207 submit_add_or_update_center($selected_id == -1, '', true);
211 if ($selected_id != -1)
213 display_heading(_("Quick Entry Lines") . " - " . $_POST['description']);
214 $result = get_quick_entry_lines($selected_id);
216 start_table($table_style2);
217 $dim = get_company_pref('use_dimension');
219 $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", "");
221 $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), "", "");
223 $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), "", "");
226 while ($myrow = db_fetch($result))
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']);
236 label_cell(get_dimension_string($myrow['dimension_id'], true));
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"));
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']);
252 start_table($table_style2);
254 if ($selected_id2 != -1)
258 //editing an existing status code
259 $myrow = get_quick_entry_line($selected_id2);
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"];
271 gl_all_accounts_list_row(_("Account"), 'account', null);
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);
276 dimensions_list_row(_("Dimension"), 'dimension_id', null, true, " ", false, 1);
278 dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
282 hidden('dimension2_id', 0);
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']);
291 submit_add_or_update_center2($selected_id2 == -1, '', true);
295 //------------------------------------------------------------------------------------