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();
24 page(_("Journal Entry"), false, false,'', $js);
26 //-----------------------------------------------------------------------------------------------
28 if (isset($_GET['AddedID']))
30 $trans_no = $_GET['AddedID'];
31 $trans_type = systypes::journal_entry();
33 display_notification_centered( _("Journal entry has been entered") . " #$trans_no");
35 display_note(get_gl_view_str($trans_type, $trans_no, _("View this Journal Entry")));
37 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Journal Entry"));
39 display_footer_exit();
42 //--------------------------------------------------------------------------------------------------
46 $_SESSION['journal_items']->tran_date = $_POST['date_'];
47 $_SESSION['journal_items']->transfer_type = check_value('Reverse');
48 $_SESSION['journal_items']->memo_ = $_POST['memo_'];
51 //--------------------------------------------------------------------------------------------------
53 function copy_from_je()
55 $_POST['date_'] = $_SESSION['journal_items']->tran_date;
56 $_POST['Reverse'] = $_SESSION['journal_items']->transfer_type;
57 $_POST['memo_'] = $_SESSION['journal_items']->memo_;
60 //----------------------------------------------------------------------------------------
62 function handle_new_order()
64 if (isset($_SESSION['journal_items']))
66 $_SESSION['journal_items']->clear_items();
67 unset ($_SESSION['journal_items']);
70 session_register("journal_items");
72 $_SESSION['journal_items'] = new items_cart;
74 $_POST['date_'] = Today();
75 if (!is_date_in_fiscalyear($_POST['date_']))
76 $_POST['date_'] = end_fiscalyear();
77 $_SESSION['journal_items']->tran_date = $_POST['date_'];
80 //-----------------------------------------------------------------------------------------------
82 if (isset($_POST['Process']))
87 if (!is_date($_POST['date_']))
89 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."));
97 elseif (!references::is_valid($_POST['ref']))
99 display_error( _("You must enter a reference."));
102 elseif (references::exists(systypes::journal_entry(), $_POST['ref']))
104 display_error( _("The entered reference is already in use."));
108 if ($input_error == 1)
109 unset($_POST['Process']);
112 if (isset($_POST['Process']))
115 $trans_no = add_journal_entries($_SESSION['journal_items']->gl_items,
116 $_POST['date_'], $_POST['ref'], check_value('Reverse'), $_POST['memo_']);
118 $_SESSION['journal_items']->clear_items();
119 unset($_SESSION['journal_items']);
121 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
122 } /*end of process credit note */
124 //-----------------------------------------------------------------------------------------------
126 function check_item_data()
128 if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id']))
130 display_error(_("Dimension is closed."));
134 if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id']))
136 display_error(_("Dimension is closed."));
140 // if (!(!strlen($_POST['AmountDebit']) ^ !strlen($_POST['AmountCredit'])))
141 if (input_num('AmountDebit')!=0 && input_num('AmountCredit')!=0)
143 display_error(_("You must enter either a debit amount or a credit amount."));
147 if (strlen($_POST['AmountDebit']) && !check_num('AmountDebit', 0))
149 display_error(_("The debit amount entered is not a valid number or is less than zero."));
151 } elseif (strlen($_POST['AmountCredit']) && !check_num('AmountCredit', 0))
153 display_error(_("The credit amount entered is not a valid number or is less than zero."));
158 if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id']))
160 display_error(_("You cannot make a journal entry for a bank account. Please use one of the banking functions for bank transactions."));
167 //-----------------------------------------------------------------------------------------------
169 function handle_update_item()
171 if($_POST['UpdateItem'] != "" && check_item_data())
173 if (input_num('AmountDebit') > 0)
174 $amount = input_num('AmountDebit');
176 $amount = -input_num('AmountCredit');
178 $_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
179 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
183 //-----------------------------------------------------------------------------------------------
185 function handle_delete_item()
187 $_SESSION['journal_items']->remove_gl_item($_GET['Delete']);
190 //-----------------------------------------------------------------------------------------------
192 function handle_new_item()
194 if (!check_item_data())
197 if (input_num('AmountDebit') > 0)
198 $amount = input_num('AmountDebit');
200 $amount = -input_num('AmountCredit');
202 $_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
203 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
206 //-----------------------------------------------------------------------------------------------
208 if (isset($_GET['Delete']) || isset($_GET['Edit']))
211 if (isset($_GET['Delete']))
212 handle_delete_item();
214 if (isset($_POST['AddItem']) || isset($_POST['UpdateItem']))
217 if (isset($_POST['AddItem']))
220 if (isset($_POST['UpdateItem']))
221 handle_update_item();
223 //-----------------------------------------------------------------------------------------------
225 if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items']))
230 //-----------------------------------------------------------------------------------------------
234 display_order_header($_SESSION['journal_items']);
236 start_table("$table_style2 width=90%", 10);
239 display_gl_items(_("Rows"), $_SESSION['journal_items']);
240 gl_options_controls();
245 if ($_SESSION['journal_items']->count_gl_items() >= 1 &&
246 abs($_SESSION['journal_items']->gl_items_total()) < 0.0001)
248 submit_center('Process', _("Process Journal Entry"));
252 display_note(_("The journal must balance (debits equal to credits) before it can be processed."), 0, 1);
257 //------------------------------------------------------------------------------------------------