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");
16 $js = get_js_form_entry("CodeID2", "code_id", "AmountDebit");
17 if ($use_popup_windows)
18 $js .= get_js_open_window(800, 500);
20 $js .= get_js_date_picker();
21 $js .= get_js_set_focus('CodeID2');
23 page(_("Journal Entry"), false, false, "setFocus()", $js);
25 //-----------------------------------------------------------------------------------------------
27 if (isset($_GET['AddedID']))
29 $trans_no = $_GET['AddedID'];
30 $trans_type = systypes::journal_entry();
32 display_notification_centered( _("Journal entry has been entered") . " #$trans_no");
34 display_note(get_gl_view_str($trans_type, $trans_no, _("View this Journal Entry")));
36 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Journal Entry"));
38 display_footer_exit();
41 //--------------------------------------------------------------------------------------------------
45 $_SESSION['journal_items']->tran_date = $_POST['date_'];
46 $_SESSION['journal_items']->transfer_type = check_value('Reverse');
47 $_SESSION['journal_items']->memo_ = $_POST['memo_'];
50 //--------------------------------------------------------------------------------------------------
52 function copy_from_je()
54 $_POST['date_'] = $_SESSION['journal_items']->tran_date;
55 $_POST['Reverse'] = $_SESSION['journal_items']->transfer_type;
56 $_POST['memo_'] = $_SESSION['journal_items']->memo_;
59 //----------------------------------------------------------------------------------------
61 function handle_new_order()
63 if (isset($_SESSION['journal_items']))
65 $_SESSION['journal_items']->clear_items();
66 unset ($_SESSION['journal_items']);
69 session_register("journal_items");
71 $_SESSION['journal_items'] = new items_cart;
73 $_POST['date_'] = Today();
74 if (!is_date_in_fiscalyear($_POST['date_']))
75 $_POST['date_'] = end_fiscalyear();
76 $_SESSION['journal_items']->tran_date = $_POST['date_'];
79 //-----------------------------------------------------------------------------------------------
81 if (isset($_POST['Process']))
86 if (!is_date($_POST['date_']))
88 display_error(_("The entered date is invalid."));
91 elseif (!is_date_in_fiscalyear($_POST['date_']))
93 display_error(_("The entered date is not in fiscal year."));
96 elseif (!references::is_valid($_POST['ref']))
98 display_error( _("You must enter a reference."));
101 elseif (references::exists(systypes::journal_entry(), $_POST['ref']))
103 display_error( _("The entered reference is already in use."));
107 if ($input_error == 1)
108 unset($_POST['Process']);
111 if (isset($_POST['Process']))
114 $trans_no = add_journal_entries($_SESSION['journal_items']->gl_items,
115 $_POST['date_'], $_POST['ref'], check_value('Reverse'), $_POST['memo_']);
117 $_SESSION['journal_items']->clear_items();
118 unset($_SESSION['journal_items']);
120 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
121 } /*end of process credit note */
123 //-----------------------------------------------------------------------------------------------
125 function check_item_data()
127 if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id']))
129 display_error(_("Dimension is closed."));
133 if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id']))
135 display_error(_("Dimension is closed."));
139 if (!(!strlen($_POST['AmountDebit']) ^ !strlen($_POST['AmountCredit'])))
141 display_error(_("You must enter either a debit amount or a credit amount."));
145 if (strlen($_POST['AmountDebit']) && !check_num('AmountDebit', 0))
147 display_error(_("The debit amount entered is not a valid number or is less than zero."));
149 } elseif (strlen($_POST['AmountCredit']) && !check_num('AmountCredit', 0))
151 display_error(_("The credit amount entered is not a valid number or is less than zero."));
156 if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id']))
158 display_error(_("You cannot make a journal entry for a bank account. Please use one of the banking functions for bank transactions."));
165 //-----------------------------------------------------------------------------------------------
167 function handle_update_item()
169 if($_POST['UpdateItem'] != "" && check_item_data())
171 if (input_num('AmountDebit') > 0)
172 $amount = input_num('AmountDebit');
174 $amount = -input_num('AmountCredit');
176 $_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
177 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
181 //-----------------------------------------------------------------------------------------------
183 function handle_delete_item()
185 $_SESSION['journal_items']->remove_gl_item($_GET['Delete']);
188 //-----------------------------------------------------------------------------------------------
190 function handle_new_item()
192 if (!check_item_data())
195 if (input_num('AmountDebit') > 0)
196 $amount = input_num('AmountDebit');
198 $amount = -input_num('AmountCredit');
200 $_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
201 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
204 //-----------------------------------------------------------------------------------------------
206 if (isset($_GET['Delete']) || isset($_GET['Edit']))
209 if (isset($_GET['Delete']))
210 handle_delete_item();
212 if (isset($_POST['AddItem']) || isset($_POST['UpdateItem']))
215 if (isset($_POST['AddItem']))
218 if (isset($_POST['UpdateItem']))
219 handle_update_item();
221 //-----------------------------------------------------------------------------------------------
223 if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items']))
228 //-----------------------------------------------------------------------------------------------
232 display_order_header($_SESSION['journal_items']);
234 start_table("$table_style2 width=90%", 10);
237 display_gl_items(_("Rows"), $_SESSION['journal_items']);
238 gl_options_controls();
243 if ($_SESSION['journal_items']->count_gl_items() >= 1 &&
244 abs($_SESSION['journal_items']->gl_items_total()) < 0.0001)
246 submit_center('Process', _("Process Journal Entry"));
250 display_note(_("The journal must balance (debits equal to credits) before it can be processed."), 0, 1);
255 //------------------------------------------------------------------------------------------------