tran_date = $_POST['date_']; $_SESSION['journal_items']->transfer_type = check_value('Reverse'); $_SESSION['journal_items']->memo_ = $_POST['memo_']; } //-------------------------------------------------------------------------------------------------- function copy_from_je() { $_POST['date_'] = $_SESSION['journal_items']->tran_date; $_POST['Reverse'] = $_SESSION['journal_items']->transfer_type; $_POST['memo_'] = $_SESSION['journal_items']->memo_; } //---------------------------------------------------------------------------------------- function handle_new_order() { if (isset($_SESSION['journal_items'])) { $_SESSION['journal_items']->clear_items(); unset ($_SESSION['journal_items']); } session_register("journal_items"); $_SESSION['journal_items'] = new items_cart; $_POST['date_'] = Today(); if (!is_date_in_fiscalyear($_POST['date_'])) $_POST['date_'] = end_fiscalyear(); $_SESSION['journal_items']->tran_date = $_POST['date_']; } //----------------------------------------------------------------------------------------------- if (isset($_POST['Process'])) { $input_error = 0; if (!is_date($_POST['date_'])) { display_error(_("The entered date is invalid.")); $input_error = 1; } elseif (!is_date_in_fiscalyear($_POST['date_'])) { display_error(_("The entered date is not in fiscal year.")); $input_error = 1; } elseif (!references::is_valid($_POST['ref'])) { display_error( _("You must enter a reference.")); $input_error = 1; } elseif (references::exists(systypes::journal_entry(), $_POST['ref'])) { display_error( _("The entered reference is already in use.")); $input_error = 1; } if ($input_error == 1) unset($_POST['Process']); } if (isset($_POST['Process'])) { $trans_no = add_journal_entries($_SESSION['journal_items']->gl_items, $_POST['date_'], $_POST['ref'], check_value('Reverse'), $_POST['memo_']); $_SESSION['journal_items']->clear_items(); unset($_SESSION['journal_items']); meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no"); } /*end of process credit note */ //----------------------------------------------------------------------------------------------- function check_item_data() { if (isset($_POST['dimension_id']) && $_POST['dimension_id'] != 0 && dimension_is_closed($_POST['dimension_id'])) { display_error(_("Dimension is closed.")); return false; } if (isset($_POST['dimension2_id']) && $_POST['dimension2_id'] != 0 && dimension_is_closed($_POST['dimension2_id'])) { display_error(_("Dimension is closed.")); return false; } if (strlen($_POST['AmountDebit']) && strlen($_POST['AmountCredit'])) { display_error(_("You cannot enter both a debit amount and a credit amount.")); return false; } if ((!isset($_POST['AmountDebit']) && !isset($_POST['AmountCredit'])) || ($_POST['AmountDebit'] == "" && $_POST['AmountCredit'] == "")) { display_error(_("You must enter either a debit amount or a credit amount.")); return false; } if (isset($_POST['AmountDebit']) && $_POST['AmountDebit'] != "") { if (!is_numeric($_POST['AmountDebit'])) { display_error(_("The debit amount entered is not a valid number.")); return false; } if ($_POST['AmountDebit'] <= 0) { display_error(_("The debit amount entered cannot be zero or negative.")); return false; } } if (isset($_POST['AmountCredit']) && $_POST['AmountCredit'] != "") { if (!is_numeric($_POST['AmountCredit'])) { display_error(_("The credit amount entered is not a valid number.")); return false; } if ($_POST['AmountCredit'] <= 0) { display_error(_("The credit amount entered cannot be zero or negative.")); return false; } } if ($_SESSION["wa_current_user"]->access != 2 && is_bank_account($_POST['code_id'])) { display_error(_("You cannot make a journal entry for a bank account. Please use one of the banking functions for bank transactions.")); return false; } return true; } //----------------------------------------------------------------------------------------------- function handle_update_item() { if($_POST['UpdateItem'] != "" && check_item_data()) { if ($_POST['AmountDebit'] > 0) $amount = $_POST['AmountDebit']; else $amount = -$_POST['AmountCredit']; $_SESSION['journal_items']->update_gl_item($_POST['Index'], $_POST['dimension_id'], $_POST['dimension2_id'], $amount, $_POST['LineMemo']); } } //----------------------------------------------------------------------------------------------- function handle_delete_item() { $_SESSION['journal_items']->remove_gl_item($_GET['Delete']); } //----------------------------------------------------------------------------------------------- function handle_new_item() { if (!check_item_data()) return; if ($_POST['AmountDebit'] > 0) $amount = $_POST['AmountDebit']; else $amount = -$_POST['AmountCredit']; $_SESSION['journal_items']->add_gl_item($_POST['code_id'], $_POST['dimension_id'], $_POST['dimension2_id'], $amount, $_POST['LineMemo']); } //----------------------------------------------------------------------------------------------- if (isset($_GET['Delete']) || isset($_GET['Edit'])) copy_from_je(); if (isset($_GET['Delete'])) handle_delete_item(); if (isset($_POST['AddItem']) || isset($_POST['UpdateItem'])) copy_to_je(); if (isset($_POST['AddItem'])) handle_new_item(); if (isset($_POST['UpdateItem'])) handle_update_item(); //----------------------------------------------------------------------------------------------- if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items'])) { handle_new_order(); } //----------------------------------------------------------------------------------------------- start_form(); display_order_header($_SESSION['journal_items']); start_table("$table_style2 width=90%", 10); start_row(); echo ""; display_gl_items(_("Rows"), $_SESSION['journal_items']); gl_options_controls(); echo ""; end_row(); end_table(1); if (!isset($_POST['Process'])) { if ($_SESSION['journal_items']->count_gl_items() >= 1 && abs($_SESSION['journal_items']->gl_items_total()) < 0.0001) { submit_center('Process', _("Process Journal Entry")); } else { display_note(_("The journal must balance (debits equal to credits) before it can be processed."), 0, 1); } } end_form(); //------------------------------------------------------------------------------------------------ end_page(); ?>