2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 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/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_QUICKENTRY';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_($help_context = "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');
77 $bal_type = get_post('bal_type');
78 if ($bal_type == 1 && $_POST['type'] != QE_JOURNAL)
80 display_error( _("You can only use Balance Based together with Journal Entries."));
81 set_focus('base_desc');
84 if (!$bal_type && strlen($_POST['base_desc']) == 0)
86 display_error( _("The base amount description cannot be empty."));
87 set_focus('base_desc');
94 //-----------------------------------------------------------------------------------
96 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
102 if ($selected_id != -1)
104 update_quick_entry($selected_id, $_POST['description'], $_POST['type'],
105 input_num('base_amount'), $_POST['base_desc'], get_post('bal_type'));
106 display_notification(_('Selected quick entry has been updated'));
110 add_quick_entry($_POST['description'], $_POST['type'],
111 input_num('base_amount'), $_POST['base_desc'], get_post('bal_type'));
112 display_notification(_('New quick entry has been added'));
118 if ($Mode2=='ADD_ITEM2' || $Mode2=='UPDATE_ITEM2')
120 if ($selected_id2 != -1)
122 update_quick_entry_line($selected_id2, $selected_id, $_POST['actn'], $_POST['dest_id'], input_num('amount', 0),
123 $_POST['dimension_id'], $_POST['dimension2_id']);
124 display_notification(_('Selected quick entry line has been updated'));
128 add_quick_entry_line($selected_id, $_POST['actn'], $_POST['dest_id'], input_num('amount', 0),
129 $_POST['dimension_id'], $_POST['dimension2_id']);
130 display_notification(_('New quick entry line has been added'));
135 //-----------------------------------------------------------------------------------
137 if ($Mode == 'Delete')
139 if (!has_quick_entry_lines($selected_id))
141 delete_quick_entry($selected_id);
142 display_notification(_('Selected quick entry has been deleted'));
147 display_error( _("The Quick Entry has Quick Entry Lines. Cannot be deleted."));
148 set_focus('description');
152 if ($Mode2 == 'BDel')
154 delete_quick_entry_line($selected_id2);
155 display_notification(_('Selected quick entry line has been deleted'));
158 //-----------------------------------------------------------------------------------
159 if ($Mode == 'RESET')
162 $_POST['description'] = $_POST['type'] = '';
163 $_POST['base_desc']= _('Base Amount');
164 $_POST['base_amount'] = price_format(0);
165 $_POST['bal_type'] = 0;
167 if ($Mode2 == 'RESET2')
170 $_POST['actn'] = $_POST['dest_id'] = $_POST['amount'] =
171 $_POST['dimension_id'] = $_POST['dimension2_id'] = '';
173 //-----------------------------------------------------------------------------------
175 $result = get_quick_entries();
177 start_table(TABLESTYLE);
178 $th = array(_("Description"), _("Type"), "", "");
182 while ($myrow = db_fetch($result))
184 alt_table_row_color($k);
185 $type_text = $quick_entry_types[$myrow["type"]];
186 label_cell($myrow['description']);
187 label_cell($type_text);
188 edit_button_cell("Edit".$myrow["id"], _("Edit"));
189 delete_button_cell("Delete".$myrow["id"], _("Delete"));
195 //-----------------------------------------------------------------------------------
197 if (list_updated('type') || (isset($_POST['bal_type']) && list_updated('bal_type')))
199 $Ajax->activate('qe');
203 start_table(TABLESTYLE2);
205 if ($selected_id != -1)
207 $myrow = get_quick_entry($selected_id);
209 $_POST['id'] = $myrow["id"];
210 $_POST['description'] = $myrow["description"];
211 $_POST['type'] = $myrow["type"];
212 $_POST['base_desc'] = $myrow["base_desc"];
213 $_POST['base_amount'] = price_format($myrow["base_amount"]);
214 $_POST['bal_type'] = $myrow["bal_type"];
215 hidden('selected_id', $selected_id);
218 text_row_ex(_("Description").':', 'description', 50, 60);
220 quick_entry_types_list_row(_("Entry Type").':', 'type', null, $selected_id == -1);
222 if (get_post('type') == QE_JOURNAL)
223 yesno_list_row(_("Balance Based"), 'bal_type', null, _("Yes"), _("No"), true);
224 if (get_post('bal_type') == 1)
226 yesno_list_row(_("Period"), 'base_amount', null, _("Monthly"), _("Yearly"));
227 gl_all_accounts_list_row(_("Account"), 'base_desc', null, true);
231 if ($selected_id == -1)
232 $_POST['base_desc'] = _("Base Amount");
233 text_row_ex(_("Base Amount Description").':', 'base_desc', 50, 60, '',_('Base Amount'));
234 amount_row(_("Default Base Amount").':', 'base_amount', price_format(0));
237 submit_add_or_update_center($selected_id == -1, '', 'both');
243 if ($selected_id != -1)
245 display_heading(_("Quick Entry Lines") . " - " . $_POST['description']);
246 $result = get_quick_entry_lines($selected_id);
248 start_table(TABLESTYLE2);
249 $dim = get_company_pref('use_dimension');
251 $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", "");
253 $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), "", "");
255 $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), "", "");
259 while ($myrow = db_fetch($result))
261 alt_table_row_color($k);
263 label_cell($quick_actions[$myrow['action']]);
265 $act_type = strtolower(substr($myrow['action'], 0, 1));
267 if ($act_type == 't')
269 label_cells($myrow['tax_name'], '');
273 label_cell($myrow['dest_id'].' '.$myrow['account_name']);
274 if ($act_type == '=')
276 elseif ($act_type == '%')
277 label_cell(number_format2($myrow['amount'], user_exrate_dec()), "nowrap align=right ");
279 amount_cell($myrow['amount']);
282 label_cell(get_dimension_string($myrow['dimension_id'], true));
284 label_cell(get_dimension_string($myrow['dimension2_id'], true));
285 edit_button_cell("BEd".$myrow["id"], _("Edit"));
286 delete_button_cell("BDel".$myrow["id"], _("Delete"));
290 hidden('selected_id', $selected_id);
291 hidden('selected_id2', $selected_id2);
292 hidden('description', $_POST['description']);
293 hidden('type', $_POST['type']);
297 div_start('edit_line');
298 start_table(TABLESTYLE2);
300 if ($selected_id2 != -1)
304 //editing an existing status code
305 $myrow = get_quick_entry_line($selected_id2);
307 $_POST['id'] = $myrow["id"];
308 $_POST['dest_id'] = $myrow["dest_id"];
309 $_POST['actn'] = $myrow["action"];
310 $_POST['amount'] = $myrow["amount"];
311 $_POST['dimension_id'] = $myrow["dimension_id"];
312 $_POST['dimension2_id'] = $myrow["dimension2_id"];
316 quick_actions_list_row(_("Posted").":",'actn', null, true);
317 if (list_updated('actn'))
318 $Ajax->activate('edit_line');
320 $actn = strtolower(substr($_POST['actn'],0,1));
324 //item_tax_types_list_row(_("Item Tax Type").":",'dest_id', null);
325 tax_types_list_row(_("Tax Type").":", 'dest_id', null);
329 gl_all_accounts_list_row(_("Account").":", 'dest_id', null, $_POST['type'] == QE_DEPOSIT || $_POST['type'] == QE_PAYMENT);
333 small_amount_row(_("Part").":", 'amount', price_format(0), null, "%", user_exrate_dec());
335 amount_row(_("Amount").":", 'amount', price_format(0));
339 dimensions_list_row(_("Dimension").":", 'dimension_id', null, true, " ", false, 1);
341 dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
345 hidden('dimension2_id', 0);
347 hidden('dimension_id', 0);
350 hidden('selected_id', $selected_id);
351 hidden('selected_id2', $selected_id2);
352 hidden('description', $_POST['description']);
353 hidden('type', $_POST['type']);
355 submit_add_or_update_center2($selected_id2 == -1, '', true);
359 //------------------------------------------------------------------------------------