6 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
8 include_once($path_to_root . "/includes/session.inc");
10 include_once($path_to_root . "/includes/banking.inc");
11 include_once($path_to_root . "/includes/data_checks.inc");
13 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
15 if ($use_popup_windows)
16 $js .= get_js_open_window(900, 500);
17 page(_("Enter Supplier Invoice"), false, false, "", $js);
20 //----------------------------------------------------------------------------------------
22 check_db_has_suppliers(_("There are no suppliers defined in the system."));
24 //---------------------------------------------------------------------------------------------------------------
26 if (isset($_GET['AddedID']))
28 $invoice_no = $_GET['AddedID'];
33 display_notification_centered(_("Supplier invoice has been processed."));
34 display_note(get_trans_view_str($trans_type, $invoice_no, _("View this Invoice")));
36 display_note(get_gl_view_str($trans_type, $invoice_no, _("View the GL Journal Entries for this Invoice")), 1);
38 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Invoice"), "New=1");
40 display_footer_exit();
43 //--------------------------------------------------------------------------------------------------
45 if (isset($_GET['New']))
47 if (isset( $_SESSION['supp_trans']))
49 unset ($_SESSION['supp_trans']->grn_items);
50 unset ($_SESSION['supp_trans']->gl_codes);
51 unset ($_SESSION['supp_trans']);
54 //session_register("SuppInv");
55 session_register("supp_trans");
56 $_SESSION['supp_trans'] = new supp_trans;
57 $_SESSION['supp_trans']->is_invoice = true;
60 //--------------------------------------------------------------------------------------------------
64 If (!$_SESSION['supp_trans']->is_valid_trans_to_post())
66 display_error(_("The invoice cannot be processed because the there are no items or values on the invoice. Invoices are expected to have a charge."));
70 if (!references::is_valid($_SESSION['supp_trans']->reference))
72 display_error(_("You must enter an invoice reference."));
76 if (!is_new_reference($_SESSION['supp_trans']->reference, 20))
78 display_error(_("The entered reference is already in use."));
82 if (!references::is_valid($_SESSION['supp_trans']->supp_reference))
84 display_error(_("You must enter a supplier's invoice reference."));
88 if (!is_date( $_SESSION['supp_trans']->tran_date))
90 display_error(_("The invoice as entered cannot be processed because the invoice date is in an incorrect format."));
93 elseif (!is_date_in_fiscalyear($_SESSION['supp_trans']->tran_date))
95 display_error(_("The entered date is not in fiscal year."));
98 if (!is_date( $_SESSION['supp_trans']->due_date))
100 display_error(_("The invoice as entered cannot be processed because the due date is in an incorrect format."));
104 $sql = "SELECT Count(*) FROM ".TB_PREF."supp_trans WHERE supplier_id='" . $_SESSION['supp_trans']->supplier_id . "' AND supp_reference='" . $_POST['supp_reference'] . "'";
105 $result=db_query($sql,"The sql to check for the previous entry of the same invoice failed");
107 $myrow = db_fetch_row($result);
109 { /*Transaction reference already entered */
110 display_error(_("This invoice number has already been entered. It cannot be entered again." . " (" . $_POST['supp_reference'] . ")"));
117 //--------------------------------------------------------------------------------------------------
119 function handle_commit_invoice()
121 copy_to_trans($_SESSION['supp_trans']);
126 $invoice_no = add_supp_invoice($_SESSION['supp_trans']);
128 $_SESSION['supp_trans']->clear_items();
129 unset($_SESSION['supp_trans']);
131 meta_forward($_SERVER['PHP_SELF'], "AddedID=$invoice_no");
134 //--------------------------------------------------------------------------------------------------
136 if (isset($_POST['PostInvoice']))
138 handle_commit_invoice();
141 //--------------------------------------------------------------------------------------------------
143 start_form(false, true);
145 start_table("$table_style2 width=80%", 8);
146 echo "<tr><td valign=center>"; // outer table
150 invoice_header($_SESSION['supp_trans']);
152 echo "</td></tr><tr><td valign=center>"; // outer table
156 display_grn_items($_SESSION['supp_trans']);
158 display_gl_items($_SESSION['supp_trans']);
160 //echo "</td></tr><tr><td align=center colspan=2>"; // outer table
162 invoice_totals($_SESSION['supp_trans']);
166 end_table(); // outer table
169 submit_center('PostInvoice', _("Enter Invoice"));
174 //--------------------------------------------------------------------------------------------------