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 //-----------------------------------------------------------------------------------------------
26 if (isset($_GET['AddedID']))
28 $trans_no = $_GET['AddedID'];
29 $trans_type = systypes::journal_entry();
31 display_notification_centered( _("Journal entry has been entered") . " #$trans_no");
33 display_note(get_gl_view_str($trans_type, $trans_no, _("View this Journal Entry")));
35 hyperlink_no_params($_SERVER['PHP_SELF'], _("Enter Another Journal Entry"));
37 display_footer_exit();
40 //--------------------------------------------------------------------------------------------------
44 $_SESSION['journal_items']->tran_date = $_POST['date_'];
45 $_SESSION['journal_items']->transfer_type = check_value('Reverse');
46 $_SESSION['journal_items']->memo_ = $_POST['memo_'];
49 //--------------------------------------------------------------------------------------------------
51 function copy_from_je()
53 $_POST['date_'] = $_SESSION['journal_items']->tran_date;
54 $_POST['Reverse'] = $_SESSION['journal_items']->transfer_type;
55 $_POST['memo_'] = $_SESSION['journal_items']->memo_;
58 //----------------------------------------------------------------------------------------
60 function handle_new_order()
62 if (isset($_SESSION['journal_items']))
64 $_SESSION['journal_items']->clear_items();
65 unset ($_SESSION['journal_items']);
68 session_register("journal_items");
70 $_SESSION['journal_items'] = new items_cart(systypes::journal_entry());
72 $_POST['date_'] = Today();
73 if (!is_date_in_fiscalyear($_POST['date_']))
74 $_POST['date_'] = end_fiscalyear();
75 $_SESSION['journal_items']->tran_date = $_POST['date_'];
78 //-----------------------------------------------------------------------------------------------
80 if (isset($_POST['Process']))
85 if (!is_date($_POST['date_']))
87 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."));
97 elseif (!references::is_valid($_POST['ref']))
99 display_error( _("You must enter a reference."));
103 elseif (references::exists(systypes::journal_entry(), $_POST['ref']))
105 display_error( _("The entered reference is already in use."));
110 if ($input_error == 1)
111 unset($_POST['Process']);
114 if (isset($_POST['Process']))
117 $trans_no = add_journal_entries($_SESSION['journal_items']->gl_items,
118 $_POST['date_'], $_POST['ref'], check_value('Reverse'), $_POST['memo_']);
120 $_SESSION['journal_items']->clear_items();
121 unset($_SESSION['journal_items']);
123 meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
124 } /*end of process credit note */
126 //-----------------------------------------------------------------------------------------------
128 function check_item_data()
130 if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id']))
132 display_error(_("Dimension is closed."));
133 set_focus('dimension_id');
137 if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id']))
139 display_error(_("Dimension is closed."));
140 set_focus('dimension2_id');
144 if (!(input_num('AmountDebit')!=0 ^ input_num('AmountCredit')!=0) )
146 display_error(_("You must enter either a debit amount or a credit amount."));
147 set_focus('AmountDebit');
151 if (strlen($_POST['AmountDebit']) && !check_num('AmountDebit', 0))
153 display_error(_("The debit amount entered is not a valid number or is less than zero."));
154 set_focus('AmountDebit');
156 } elseif (strlen($_POST['AmountCredit']) && !check_num('AmountCredit', 0))
158 display_error(_("The credit amount entered is not a valid number or is less than zero."));
159 set_focus('AmountCredit');
164 if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id']))
166 display_error(_("You cannot make a journal entry for a bank account. Please use one of the banking functions for bank transactions."));
167 set_focus('code_id');
174 //-----------------------------------------------------------------------------------------------
176 function handle_update_item()
178 if($_POST['UpdateItem'] != "" && check_item_data())
180 if (input_num('AmountDebit') > 0)
181 $amount = input_num('AmountDebit');
183 $amount = -input_num('AmountCredit');
185 $_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'],
186 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
190 //-----------------------------------------------------------------------------------------------
192 function handle_delete_item()
194 $_SESSION['journal_items']->remove_gl_item($_GET['Delete']);
197 //-----------------------------------------------------------------------------------------------
199 function handle_new_item()
201 if (!check_item_data())
204 if (input_num('AmountDebit') > 0)
205 $amount = input_num('AmountDebit');
207 $amount = -input_num('AmountCredit');
209 $_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'],
210 $_POST['dimension2_id'], $amount, $_POST['LineMemo']);
213 //-----------------------------------------------------------------------------------------------
214 if (isset($_GET['Edit'])) {
216 set_focus('dimension_id');
218 if (isset($_GET['Delete'])) {
220 handle_delete_item();
221 set_focus('_code_id_edit');
223 if (isset($_POST['AddItem'])) {
226 set_focus('_code_id_edit');
228 if (isset($_POST['UpdateItem'])) {
230 handle_update_item();
231 set_focus('_code_id_edit');
233 if (isset($_POST['CancelItemChanges']))
234 set_focus('_code_id_edit');
236 if (isset($_POST['EditItem']))
237 set_focus('dimension_id');
239 //-----------------------------------------------------------------------------------------------
241 if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items']))
246 //-----------------------------------------------------------------------------------------------
250 display_order_header($_SESSION['journal_items']);
252 start_table("$table_style2 width=90%", 10);
255 display_gl_items(_("Rows"), $_SESSION['journal_items']);
256 gl_options_controls();
261 if ($_SESSION['journal_items']->count_gl_items() >= 1 &&
262 abs($_SESSION['journal_items']->gl_items_total()) < 0.0001)
264 submit_center('Process', _("Process Journal Entry"));
268 display_note(_("The journal must balance (debits equal to credits) before it can be processed."), 0, 1);
273 //------------------------------------------------------------------------------------------------