{
if (strlen($details_row["grn_item_id"]) > 0) // it can be empty for GL items
{
- update_supp_received_items_for_invoice($details_row["grn_item_id"],
- $details_row["po_detail_item_id"], -$details_row["quantity"]);
+ // Changed 2008-10-17 by Joe Hunt to get the avg. material cost updated
+ /*update_supp_received_items_for_invoice($details_row["grn_item_id"],
+ $details_row["po_detail_item_id"], -$details_row["quantity"]);
+ No, this will catch the GRN for invoicing again. Better leave as is. */
+ $supp = get_supp_trans($type_no, $type);
+ $old_mat_cost = get_standard_cost($details_row["stock_id"]);
+ update_average_material_cost($supp["supplier_id"], $details_row["stock_id"],
+ $details_row["FullUnitPrice"], -$details_row["quantity"], Today());
+ $batch = get_grn_batch_from_item($details_row["grn_item_id"]);
+ $grn = get_grn_batch($batch);
+
+ add_stock_move(25, $details_row["stock_id"], $batch, $grn['loc_code'], sql2date($grn["delivery_date"]), "",
+ -$details_row["quantity"], $old_mat_cost, $supp["supplier_id"], 1, $details_row["FullUnitPrice"]);
}
}
}
echo "<hr>";
//-----------------------------------------------------------------------------------------
+start_form(false, true); // 2008-10-18 Joe Hunt. Moved form outside function
function display_grn_items_for_selection()
{
global $table_style;
+ div_start('grn_table'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
$result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, true);
if (db_num_rows($result) == 0)
{
display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
- end_page();
- exit;
+ div_end(); // Changed 2008-10-18 Joe Hunt
+ return;
}
-
+
/*Set up a table to show the outstanding GRN items for selection */
- start_form(false, true);
display_heading2(_("Items Received Yet to be Invoiced"));
- div_start('grn_table');
+ //div_start('grn_table');
start_table("$table_style colspan=7 width=95%");
$th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
_("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
_("Uninvoiced Quantity"), _("Order Price"), _("Total"));
+ if ($_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+ $th[] = "";
table_header($th);
$i = $k = 0;
amount_cell($myrow["unit_price"]);
amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]),
user_price_dec()));
+ if ($_SESSION["wa_current_user"]->access == 2) // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+ submit_cells('void_item_id'.$myrow["id"], _("Remove"), '', '', true);
end_row();
$i++;
}
//-----------------------------------------------------------------------------------------
-if (find_submit('grn_item_id') || get_post('AddGRNToTrans'))
+$id = find_submit('grn_item_id');
+$id2 = find_submit('void_item_id');
+if ($id != -1 || id2 != -1 || get_post('AddGRNToTrans'))
{
$Ajax->activate('grn_selector');
}
-if (get_post('AddGRNToTrans'))
+if (get_post('AddGRNToTrans') || $id2 != -1)
{
$Ajax->activate('grn_table');
$Ajax->activate('grn_items');
}
+if ($_SESSION["wa_current_user"]->access == 2)
+{
+ if ($id2 != -1) // Added section 2008-10-18 Joe Hunt for voiding delivery lines
+ {
+ begin_transaction();
+
+ $myrow = get_grn_item_detail($id2);
+
+ $grn = get_grn_batch($myrow['grn_batch_id']);
+
+ $sql = "UPDATE ".TB_PREF."purch_order_details
+ SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
+ db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
+
+ $sql = "UPDATE ".TB_PREF."grn_items
+ SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
+ db_query($sql, "The quantity invoiced off the items received record could not be updated");
+
+ update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
+ $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
+
+ add_stock_move(25, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
+ -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
+
+ commit_transaction();
+ }
+}
+
display_grn_items_for_selection();
//-----------------------------------------------------------------------------------------
div_start('grn_selector');
-$id = find_submit('grn_item_id');
+//$id = find_submit('grn_item_id');
if ($id != -1)
{