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);
19 $js .= get_js_set_focus('CodeID2');
21 page(_("Journal Entry"), false, false, "setFocus()", $js);
23 //-----------------------------------------------------------------------------------------------
25 if (isset($_GET['AddedID']))
27 $trans_no = $_GET['AddedID'];
28 $trans_type = systypes::journal_entry();
30 display_notification_centered( _("Journal entry has been entered") . " #$trans_no");
32 display_note(get_gl_view_str($trans_type, $trans_no, _("View this Journal Entry")));
34 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Journal Entry"));
36 display_footer_exit();
39 //--------------------------------------------------------------------------------------------------
43 $_SESSION['journal_items']->tran_date = $_POST['date_'];
44 $_SESSION['journal_items']->transfer_type = check_value('Reverse');
45 $_SESSION['journal_items']->memo_ = $_POST['memo_'];
48 //--------------------------------------------------------------------------------------------------
50 function copy_from_je()
52 $_POST['date_'] = $_SESSION['journal_items']->tran_date;
53 $_POST['Reverse'] = $_SESSION['journal_items']->transfer_type;
54 $_POST['memo_'] = $_SESSION['journal_items']->memo_;
57 //----------------------------------------------------------------------------------------
59 function handle_new_order()
61 if (isset($_SESSION['journal_items']))
63 $_SESSION['journal_items']->clear_items();
64 unset ($_SESSION['journal_items']);
67 session_register("journal_items");
69 $_SESSION['journal_items'] = new items_cart;
71 $_POST['date_'] = Today();
72 if (!is_date_in_fiscalyear($_POST['date_']))
73 $_POST['date_'] = end_fiscalyear();
74 $_SESSION['journal_items']->tran_date = $_POST['date_'];
77 //-----------------------------------------------------------------------------------------------
79 if (isset($_POST['Process']))
84 if (!is_date($_POST['date_']))
86 display_error(_("The entered date is invalid."));
89 elseif (!is_date_in_fiscalyear($_POST['date_']))
91 display_error(_("The entered date is not in fiscal year."));
94 elseif (!references::is_valid($_POST['ref']))
96 display_error( _("You must enter a reference."));
99 elseif (references::exists(systypes::journal_entry(), $_POST['ref']))
101 display_error( _("The entered reference is already in use."));
105 if ($input_error == 1)
106 unset($_POST['Process']);
109 if (isset($_POST['Process']))
112 $trans_no = add_journal_entries($_SESSION['journal_items']->gl_items,
113 $_POST['date_'], $_POST['ref'], check_value('Reverse'), $_POST['memo_']);
115 $_SESSION['journal_items']->clear_items();
116 unset($_SESSION['journal_items']);
118 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
119 } /*end of process credit note */
121 //-----------------------------------------------------------------------------------------------
123 function check_item_data()
125 if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id']))
127 display_error(_("Dimension is closed."));
131 if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id']))
133 display_error(_("Dimension is closed."));
137 if (strlen($_POST['AmountDebit']) && strlen($_POST['AmountCredit']))
139 display_error(_("You cannot enter both a debit amount and a credit amount."));
143 if ((!isset($_POST['AmountDebit']) && !isset($_POST['AmountCredit']))
144 || ($_POST['AmountDebit'] == "" && $_POST['AmountCredit'] == ""))
146 display_error(_("You must enter either a debit amount or a credit amount."));
150 if (isset($_POST['AmountDebit']) && $_POST['AmountDebit'] != "")
153 if (!is_numeric($_POST['AmountDebit']))
155 display_error(_("The debit amount entered is not a valid number."));
159 if ($_POST['AmountDebit'] <= 0)
161 display_error(_("The debit amount entered cannot be zero or negative."));
166 if (isset($_POST['AmountCredit']) && $_POST['AmountCredit'] != "")
169 if (!is_numeric($_POST['AmountCredit']))
171 display_error(_("The credit amount entered is not a valid number."));
175 if ($_POST['AmountCredit'] <= 0)
177 display_error(_("The credit amount entered cannot be zero or negative."));
182 if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id']))
184 display_error(_("You cannot make a journal entry for a bank account. Please use one of the banking functions for bank transactions."));
191 //-----------------------------------------------------------------------------------------------
193 function handle_update_item()
195 if($_POST['UpdateItem'] != "" && check_item_data())
197 if ($_POST['AmountDebit'] > 0)
198 $amount = $_POST['AmountDebit'];
200 $amount = -$_POST['AmountCredit'];
202 $_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
203 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
207 //-----------------------------------------------------------------------------------------------
209 function handle_delete_item()
211 $_SESSION['journal_items']->remove_gl_item($_GET['Delete']);
214 //-----------------------------------------------------------------------------------------------
216 function handle_new_item()
218 if (!check_item_data())
221 if ($_POST['AmountDebit'] > 0)
222 $amount = $_POST['AmountDebit'];
224 $amount = -$_POST['AmountCredit'];
226 $_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
227 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
230 //-----------------------------------------------------------------------------------------------
232 if (isset($_GET['Delete']) || isset($_GET['Edit']))
235 if (isset($_GET['Delete']))
236 handle_delete_item();
238 if (isset($_POST['AddItem']) || isset($_POST['UpdateItem']))
241 if (isset($_POST['AddItem']))
244 if (isset($_POST['UpdateItem']))
245 handle_update_item();
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 if (!isset($_POST['Process']))
271 if ($_SESSION['journal_items']->count_gl_items() >= 1 &&
272 abs($_SESSION['journal_items']->gl_items_total()) < 0.0001)
274 submit_center('Process', _("Process Journal Entry"));
278 display_note(_("The journal must balance (debits equal to credits) before it can be processed."), 0, 1);
284 //------------------------------------------------------------------------------------------------