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 ***********************************************************************/
14 include_once($path_to_root . "/includes/ui/items_cart.inc");
16 include_once($path_to_root . "/includes/session.inc");
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
21 include_once($path_to_root . "/gl/includes/ui/gl_journal_ui.inc");
22 include_once($path_to_root . "/gl/includes/gl_db.inc");
23 include_once($path_to_root . "/gl/includes/gl_ui.inc");
26 if ($use_popup_windows)
27 $js .= get_js_open_window(800, 500);
29 $js .= get_js_date_picker();
31 page(_("Journal Entry"), false, false,'', $js);
33 //--------------------------------------------------------------------------------------------------
34 function line_start_focus() {
37 $Ajax->activate('items_table');
38 set_focus('_code_id_edit');
40 //-----------------------------------------------------------------------------------------------
42 if (isset($_GET['AddedID']))
44 $trans_no = $_GET['AddedID'];
45 $trans_type = systypes::journal_entry();
47 display_notification_centered( _("Journal entry has been entered") . " #$trans_no");
49 display_note(get_gl_view_str($trans_type, $trans_no, _("&View this Journal Entry")));
51 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter &Another Journal Entry"));
53 display_footer_exit();
55 //--------------------------------------------------------------------------------------------------
57 function handle_new_order()
59 if (isset($_SESSION['journal_items']))
61 $_SESSION['journal_items']->clear_items();
62 unset ($_SESSION['journal_items']);
65 session_register("journal_items");
67 $_SESSION['journal_items'] = new items_cart(systypes::journal_entry());
69 $_POST['date_'] = new_doc_date();
70 if (!is_date_in_fiscalyear($_POST['date_']))
71 $_POST['date_'] = end_fiscalyear();
72 $_SESSION['journal_items']->tran_date = $_POST['date_'];
75 //-----------------------------------------------------------------------------------------------
77 if (isset($_POST['Process']))
82 if ($_SESSION['journal_items']->count_gl_items() < 1) {
83 display_error(_("You must enter at least one journal line."));
87 if (abs($_SESSION['journal_items']->gl_items_total()) > 0.0001)
89 display_error(_("The journal must balance (debits equal to credits) before it can be processed."));
95 if (!is_date($_POST['date_']))
97 display_error(_("The entered date is invalid."));
101 elseif (!is_date_in_fiscalyear($_POST['date_']))
103 display_error(_("The entered date is not in fiscal year."));
107 if (!references::is_valid($_POST['ref']))
109 display_error( _("You must enter a reference."));
113 elseif (references::exists(systypes::journal_entry(), $_POST['ref']))
115 display_error( _("The entered reference is already in use."));
120 if ($input_error == 1)
121 unset($_POST['Process']);
124 if (isset($_POST['Process']))
127 $trans_no = add_journal_entries($_SESSION['journal_items']->gl_items,
128 $_POST['date_'], $_POST['ref'], check_value('Reverse'), $_POST['memo_']);
130 $_SESSION['journal_items']->clear_items();
131 new_doc_date($_POST['date_']);
132 unset($_SESSION['journal_items']);
134 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
135 } /*end of process credit note */
137 //-----------------------------------------------------------------------------------------------
139 function check_item_data()
141 if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id']))
143 display_error(_("Dimension is closed."));
144 set_focus('dimension_id');
148 if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id']))
150 display_error(_("Dimension is closed."));
151 set_focus('dimension2_id');
155 if (!(input_num('AmountDebit')!=0 ^ input_num('AmountCredit')!=0) )
157 display_error(_("You must enter either a debit amount or a credit amount."));
158 set_focus('AmountDebit');
162 if (strlen($_POST['AmountDebit']) && !check_num('AmountDebit', 0))
164 display_error(_("The debit amount entered is not a valid number or is less than zero."));
165 set_focus('AmountDebit');
167 } elseif (strlen($_POST['AmountCredit']) && !check_num('AmountCredit', 0))
169 display_error(_("The credit amount entered is not a valid number or is less than zero."));
170 set_focus('AmountCredit');
175 if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id']))
177 display_error(_("You cannot make a journal entry for a bank account. Please use one of the banking functions for bank transactions."));
178 set_focus('code_id');
185 //-----------------------------------------------------------------------------------------------
187 function handle_update_item()
189 if($_POST['UpdateItem'] != "" && check_item_data())
191 if (input_num('AmountDebit') > 0)
192 $amount = input_num('AmountDebit');
194 $amount = -input_num('AmountCredit');
196 $_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
197 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
202 //-----------------------------------------------------------------------------------------------
204 function handle_delete_item($id)
206 $_SESSION['journal_items']->remove_gl_item($id);
210 //-----------------------------------------------------------------------------------------------
212 function handle_new_item()
214 if (!check_item_data())
217 if (input_num('AmountDebit') > 0)
218 $amount = input_num('AmountDebit');
220 $amount = -input_num('AmountCredit');
222 $_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
223 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
227 //-----------------------------------------------------------------------------------------------
228 $id = find_submit('Delete');
230 handle_delete_item($id);
232 if (isset($_POST['AddItem']))
235 if (isset($_POST['UpdateItem']))
236 handle_update_item();
238 if (isset($_POST['CancelItemChanges']))
241 if (isset($_POST['go']))
243 display_quick_entries($_SESSION['journal_items'], $_POST['person_id'], input_num('totamount'), QE_JOURNAL);
244 $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
247 //-----------------------------------------------------------------------------------------------
249 if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items']))
254 //-----------------------------------------------------------------------------------------------
258 display_order_header($_SESSION['journal_items']);
260 start_table("$table_style2 width=90%", 10);
263 display_gl_items(_("Rows"), $_SESSION['journal_items']);
264 gl_options_controls();
269 submit_center('Process', _("Process Journal Entry"), true ,
270 _('Process journal entry only if debits equal to credits'), 'default');
273 //------------------------------------------------------------------------------------------------