5 include_once($path_to_root . "/includes/ui/items_cart.inc");
7 include_once($path_to_root . "/includes/session.inc");
9 include_once($path_to_root . "/includes/date_functions.inc");
10 include_once($path_to_root . "/includes/data_checks.inc");
12 include_once($path_to_root . "/gl/includes/ui/gl_journal_ui.inc");
13 include_once($path_to_root . "/gl/includes/gl_db.inc");
14 include_once($path_to_root . "/gl/includes/gl_ui.inc");
17 if ($use_popup_windows)
18 $js .= get_js_open_window(800, 500);
20 $js .= get_js_date_picker();
22 page(_("Journal Entry"), false, false,'', $js);
24 //--------------------------------------------------------------------------------------------------
25 function line_start_focus() {
28 $Ajax->activate('items_table');
29 set_focus('_code_id_edit');
31 //-----------------------------------------------------------------------------------------------
33 if (isset($_GET['AddedID']))
35 $trans_no = $_GET['AddedID'];
36 $trans_type = systypes::journal_entry();
38 display_notification_centered( _("Journal entry has been entered") . " #$trans_no");
40 display_note(get_gl_view_str($trans_type, $trans_no, _("View this Journal Entry")));
42 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Journal Entry"));
44 display_footer_exit();
46 //--------------------------------------------------------------------------------------------------
48 function handle_new_order()
50 if (isset($_SESSION['journal_items']))
52 $_SESSION['journal_items']->clear_items();
53 unset ($_SESSION['journal_items']);
56 session_register("journal_items");
58 $_SESSION['journal_items'] = new items_cart(systypes::journal_entry());
60 $_POST['date_'] = Today();
61 if (!is_date_in_fiscalyear($_POST['date_']))
62 $_POST['date_'] = end_fiscalyear();
63 $_SESSION['journal_items']->tran_date = $_POST['date_'];
66 //-----------------------------------------------------------------------------------------------
68 if (isset($_POST['Process']))
73 if ($_SESSION['journal_items']->count_gl_items() < 1) {
74 display_error(_("You must enter at least one journal line."));
78 if (abs($_SESSION['journal_items']->gl_items_total()) > 0.0001)
80 display_error(_("The journal must balance (debits equal to credits) before it can be processed."));
86 if (!is_date($_POST['date_']))
88 display_error(_("The entered date is invalid."));
92 elseif (!is_date_in_fiscalyear($_POST['date_']))
94 display_error(_("The entered date is not in fiscal year."));
98 if (!references::is_valid($_POST['ref']))
100 display_error( _("You must enter a reference."));
104 elseif (references::exists(systypes::journal_entry(), $_POST['ref']))
106 display_error( _("The entered reference is already in use."));
111 if ($input_error == 1)
112 unset($_POST['Process']);
115 if (isset($_POST['Process']))
118 $trans_no = add_journal_entries($_SESSION['journal_items']->gl_items,
119 $_POST['date_'], $_POST['ref'], check_value('Reverse'), $_POST['memo_']);
121 $_SESSION['journal_items']->clear_items();
122 unset($_SESSION['journal_items']);
124 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
125 } /*end of process credit note */
127 //-----------------------------------------------------------------------------------------------
129 function check_item_data()
131 if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id']))
133 display_error(_("Dimension is closed."));
134 set_focus('dimension_id');
138 if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id']))
140 display_error(_("Dimension is closed."));
141 set_focus('dimension2_id');
145 if (!(input_num('AmountDebit')!=0 ^ input_num('AmountCredit')!=0) )
147 display_error(_("You must enter either a debit amount or a credit amount."));
148 set_focus('AmountDebit');
152 if (strlen($_POST['AmountDebit']) && !check_num('AmountDebit', 0))
154 display_error(_("The debit amount entered is not a valid number or is less than zero."));
155 set_focus('AmountDebit');
157 } elseif (strlen($_POST['AmountCredit']) && !check_num('AmountCredit', 0))
159 display_error(_("The credit amount entered is not a valid number or is less than zero."));
160 set_focus('AmountCredit');
165 if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id']))
167 display_error(_("You cannot make a journal entry for a bank account. Please use one of the banking functions for bank transactions."));
168 set_focus('code_id');
175 //-----------------------------------------------------------------------------------------------
177 function handle_update_item()
179 if($_POST['UpdateItem'] != "" && check_item_data())
181 if (input_num('AmountDebit') > 0)
182 $amount = input_num('AmountDebit');
184 $amount = -input_num('AmountCredit');
186 $_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
187 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
192 //-----------------------------------------------------------------------------------------------
194 function handle_delete_item($id)
196 $_SESSION['journal_items']->remove_gl_item($id);
200 //-----------------------------------------------------------------------------------------------
202 function handle_new_item()
204 if (!check_item_data())
207 if (input_num('AmountDebit') > 0)
208 $amount = input_num('AmountDebit');
210 $amount = -input_num('AmountCredit');
212 $_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
213 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
217 //-----------------------------------------------------------------------------------------------
218 $id = find_submit('Delete');
220 handle_delete_item($id);
222 if (isset($_POST['AddItem']))
225 if (isset($_POST['UpdateItem']))
226 handle_update_item();
228 if (isset($_POST['CancelItemChanges']))
231 //-----------------------------------------------------------------------------------------------
233 if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items']))
238 //-----------------------------------------------------------------------------------------------
242 display_order_header($_SESSION['journal_items']);
244 start_table("$table_style2 width=90%", 10);
247 display_gl_items(_("Rows"), $_SESSION['journal_items']);
248 gl_options_controls();
253 submit_center('Process', _("Process Journal Entry"), true ,
254 _('Process journal entry only if debits equal to credits'), true);
257 //------------------------------------------------------------------------------------------------