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);
18 $js .= get_js_date_picker();
19 page(_("Enter Supplier Invoice"), false, false, "", $js);
22 //----------------------------------------------------------------------------------------
24 check_db_has_suppliers(_("There are no suppliers defined in the system."));
26 //---------------------------------------------------------------------------------------------------------------
27 if ($ret = context_restore()) {
28 // return from supplier editor
29 copy_from_trans($_SESSION['supp_trans']);
30 if(isset($ret['supplier_id']))
31 $_POST['supplier_id'] = $ret['supplier_id'];
33 if (isset($_POST['_supplier_id_editor'])) {
34 copy_to_trans($_SESSION['supp_trans']);
35 context_call($path_to_root.'/purchasing/manage/suppliers.php?supplier_id='.$_POST['supplier_id'], 'supp_trans');
38 //---------------------------------------------------------------------------------------------------------------
40 if (isset($_GET['AddedID']))
42 $invoice_no = $_GET['AddedID'];
47 display_notification_centered(_("Supplier invoice has been processed."));
48 display_note(get_trans_view_str($trans_type, $invoice_no, _("View this Invoice")));
50 display_note(get_gl_view_str($trans_type, $invoice_no, _("View the GL Journal Entries for this Invoice")), 1);
52 hyperlink_params($_SERVER['PHP_SELF'], _("Enter Another Invoice"), "New=1");
54 display_footer_exit();
57 //--------------------------------------------------------------------------------------------------
59 if (isset($_GET['New']))
61 if (isset( $_SESSION['supp_trans']))
63 unset ($_SESSION['supp_trans']->grn_items);
64 unset ($_SESSION['supp_trans']->gl_codes);
65 unset ($_SESSION['supp_trans']);
68 //session_register("SuppInv");
69 session_register("supp_trans");
70 $_SESSION['supp_trans'] = new supp_trans;
71 $_SESSION['supp_trans']->is_invoice = true;
74 //--------------------------------------------------------------------------------------------------
78 If (!$_SESSION['supp_trans']->is_valid_trans_to_post())
80 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."));
84 if (!references::is_valid($_SESSION['supp_trans']->reference))
86 display_error(_("You must enter an invoice reference."));
87 set_focus('reference');
91 if (!is_new_reference($_SESSION['supp_trans']->reference, 20))
93 display_error(_("The entered reference is already in use."));
94 set_focus('reference');
98 if (!references::is_valid($_SESSION['supp_trans']->supp_reference))
100 display_error(_("You must enter a supplier's invoice reference."));
101 set_focus('supp_reference');
105 if (!is_date( $_SESSION['supp_trans']->tran_date))
107 display_error(_("The invoice as entered cannot be processed because the invoice date is in an incorrect format."));
108 set_focus('trans_date');
111 elseif (!is_date_in_fiscalyear($_SESSION['supp_trans']->tran_date))
113 display_error(_("The entered date is not in fiscal year."));
114 set_focus('trans_date');
117 if (!is_date( $_SESSION['supp_trans']->due_date))
119 display_error(_("The invoice as entered cannot be processed because the due date is in an incorrect format."));
120 set_focus('due_date');
124 $sql = "SELECT Count(*) FROM ".TB_PREF."supp_trans WHERE supplier_id='" . $_SESSION['supp_trans']->supplier_id . "' AND supp_reference='" . $_POST['supp_reference'] . "'";
125 $result=db_query($sql,"The sql to check for the previous entry of the same invoice failed");
127 $myrow = db_fetch_row($result);
129 { /*Transaction reference already entered */
130 display_error(_("This invoice number has already been entered. It cannot be entered again." . " (" . $_POST['supp_reference'] . ")"));
137 //--------------------------------------------------------------------------------------------------
139 function handle_commit_invoice()
141 copy_to_trans($_SESSION['supp_trans']);
146 $invoice_no = add_supp_invoice($_SESSION['supp_trans']);
148 $_SESSION['supp_trans']->clear_items();
149 unset($_SESSION['supp_trans']);
151 meta_forward($_SERVER['PHP_SELF'], "AddedID=$invoice_no");
154 //--------------------------------------------------------------------------------------------------
156 if (isset($_POST['PostInvoice']))
158 handle_commit_invoice();
161 //--------------------------------------------------------------------------------------------------
163 start_form(false, true);
165 start_table("$table_style2 width=80%", 8);
166 echo "<tr><td valign=center>"; // outer table
170 invoice_header($_SESSION['supp_trans']);
171 if ($_POST['supplier_id']=='')
172 display_error('No supplier found for entered search text');
174 echo "</td></tr><tr><td valign=center>"; // outer table
178 display_grn_items($_SESSION['supp_trans']);
180 display_gl_items($_SESSION['supp_trans']);
182 //echo "</td></tr><tr><td align=center colspan=2>"; // outer table
184 invoice_totals($_SESSION['supp_trans']);
188 end_table(); // outer table
191 submit_center('PostInvoice', _("Enter Invoice"), true, '', true);
196 //--------------------------------------------------------------------------------------------------