6 include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
7 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
9 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
13 $js .= get_js_date_picker();
14 if ($use_popup_windows)
15 $js .= get_js_open_window(900, 500);
16 page(_("Select Received Items to Add"), false, false, "", $js);
18 if (!isset($_SESSION['supp_trans']))
20 display_note("To enter supplier transactions the supplier must first be selected from the supplier selection screen, then the link to enter a supplier credit note must be clicked on.", 1, 0);;
24 //-----------------------------------------------------------------------------------------
26 display_heading($_SESSION['supp_trans']->supplier_name);
30 //-----------------------------------------------------------------------------------------
34 global $check_price_charged_vs_order_price,
35 $check_qty_charged_vs_del_qty;
36 if (!check_num('this_quantity_inv', 0) || input_num('this_quantity_inv')==0)
38 display_error( _("The quantity to invoice must be numeric and greater than zero."));
39 set_focus('this_quantity_inv');
43 if (!check_num('ChgPrice'))
45 display_error( _("The price is not numeric."));
46 set_focus('ChgPrice');
50 if ($check_price_charged_vs_order_price == True)
52 if ($_POST['order_price']!=input_num('ChgPrice')) {
53 if ($_POST['order_price']==0 ||
54 input_num('ChgPrice')/$_POST['order_price'] >
55 (1 + (sys_prefs::over_charge_allowance() / 100)))
57 display_error(_("The price being invoiced is more than the purchase order price by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.") .
58 _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
59 set_focus('ChgPrice');
65 if ($check_qty_charged_vs_del_qty == True)
67 if (input_num('this_quantity_inv') / ($_POST['qty_recd'] - $_POST['prev_quantity_inv']) >
68 (1+ (sys_prefs::over_charge_allowance() / 100)))
70 display_error( _("The quantity being invoiced is more than the outstanding quantity by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.")
71 . _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
72 set_focus('this_quantity_inv');
80 //-----------------------------------------------------------------------------------------
82 if (isset($_POST['AddGRNToTrans']))
87 if (input_num('this_quantity_inv') >= ($_POST['qty_recd'] - $_POST['prev_quantity_inv']))
96 $_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'], $_POST['po_detail_item'],
97 $_POST['item_code'], $_POST['item_description'], $_POST['qty_recd'],
98 $_POST['prev_quantity_inv'], input_num('this_quantity_inv'),
99 $_POST['order_price'], input_num('ChgPrice'), $complete,
100 $_POST['std_cost_unit'], "");
104 //-----------------------------------------------------------------------------------------
105 $id = find_submit('Delete');
108 $_SESSION['supp_trans']->remove_grn_from_trans($id);
109 $Ajax->activate('grn_items');
110 $Ajax->activate('grn_table');
113 //-----------------------------------------------------------------------------------------
114 start_form(false,true);
115 display_grn_items($_SESSION['supp_trans'], 1);
119 hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Supplier Invoice Entry"));
122 //-----------------------------------------------------------------------------------------
123 start_form(false, true); // 2008-10-18 Joe Hunt. Moved form outside function
125 function display_grn_items_for_selection()
129 div_start('grn_table'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
130 $result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, true);
132 if (db_num_rows($result) == 0)
134 display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
135 div_end(); // Changed 2008-10-18 Joe Hunt
139 /*Set up a table to show the outstanding GRN items for selection */
141 display_heading2(_("Items Received Yet to be Invoiced"));
142 //div_start('grn_table');
143 start_table("$table_style colspan=7 width=95%");
144 $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
145 _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
146 _("Uninvoiced Quantity"), _("Order Price"), _("Total"));
147 if ($_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
152 while ($myrow = db_fetch($result))
154 $grn_already_on_invoice = false;
156 foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
158 if ($entered_grn->id == $myrow["id"])
160 $grn_already_on_invoice = true;
163 if ($grn_already_on_invoice == false)
166 alt_table_row_color($k);
168 label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
169 //text_cells(null, 'grn_item_id', $myrow["id"]);
170 submit_cells('grn_item_id'.$myrow["id"], $myrow["id"], '', '', true);
171 label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
172 label_cell($myrow["item_code"]);
173 label_cell($myrow["description"]);
174 label_cell(sql2date($myrow["delivery_date"]));
175 $dec = get_qty_dec($myrow["item_code"]);
176 qty_cell($myrow["qty_recd"], false, $dec);
177 qty_cell($myrow["quantity_inv"], false, $dec);
178 qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"], false, $dec);
179 amount_cell($myrow["unit_price"]);
180 amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]),
182 if ($_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
183 submit_cells('void_item_id'.$myrow["id"], _("Remove"), '', '', true);
199 //-----------------------------------------------------------------------------------------
200 $id = find_submit('grn_item_id');
201 $id2 = find_submit('void_item_id');
202 if ($id != -1 || id2 != -1 || get_post('AddGRNToTrans'))
204 $Ajax->activate('grn_selector');
206 if (get_post('AddGRNToTrans') || $id2 != -1)
208 $Ajax->activate('grn_table');
209 $Ajax->activate('grn_items');
212 if ($_SESSION["wa_current_user"]->access == 2)
214 if ($id2 != -1) // Added section 2008-10-18 Joe Hunt for voiding delivery lines
218 $myrow = get_grn_item_detail($id2);
220 $grn = get_grn_batch($myrow['grn_batch_id']);
222 $sql = "UPDATE ".TB_PREF."purch_order_details
223 SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
224 db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
226 $sql = "UPDATE ".TB_PREF."grn_items
227 SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
228 db_query($sql, "The quantity invoiced off the items received record could not be updated");
230 update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
231 $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
233 add_stock_move(25, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
234 -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
236 commit_transaction();
240 display_grn_items_for_selection();
242 //-----------------------------------------------------------------------------------------
244 div_start('grn_selector');
246 //$id = find_submit('grn_item_id');
250 $myrow = get_grn_item_detail($id);
253 display_heading2(_("Delivery Item Selected For Adding To A Supplier Invoice"));
254 start_table("$table_style width=80%");
255 $th = array(_("Sequence #"), _("Item"), _("Description"), _("Quantity Outstanding"),
256 _("Quantity to Invoice"), _("Order Price"), _("Actual Price"));
261 label_cell($myrow['item_code']);
262 label_cell($myrow['description']);
263 $dec = get_qty_dec($myrow['item_code']);
264 qty_cell($myrow['QtyOstdg'], false, $dec);
265 qty_cells(null, 'this_quantity_inv', number_format2($myrow['QtyOstdg'], $dec), null, null, $dec);
266 amount_cell($myrow['unit_price']);
267 small_amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
271 submit_center('AddGRNToTrans', _("Add to Invoice"), true, '', true);
273 hidden('GRNNumber', $id);
274 hidden('item_code', $myrow['item_code']);
275 hidden('item_description', $myrow['description']);;
276 hidden('qty_recd', $myrow['qty_recd']);
277 hidden('prev_quantity_inv', $myrow['quantity_inv']);
278 hidden('order_price', $myrow['unit_price']);
279 hidden('std_cost_unit', $myrow['std_cost_unit']);
281 hidden('po_detail_item', $myrow['po_detail_item']);
285 //----------------------------------------------------------------------------------------
289 end_page(false, true);