! -> Note
$ -> Affected files
+08-Dec-2008 Joe Hunt
+! Better support for purchasing data (automatic updating from PO receive)
+$ /purchasing/includes/db/grn_db.inc
+ /purchasing/includes/db/invoice_db.inc
+ /purchasing/includes/db/po_db.inc
+ /purchasing/includes/ui/invoice_ui.inc
+ /purchasing/includes/purchasing_db.inc
+ /reporting/rep209.php
+
07-Dec-2008 Janusz Dobrowolski
+ Added list category grouping.
$ /includes/ui/ui_lists.inc
/*Need to get the standard cost as it is now so we can process GL jorunals later*/
$order_line->standard_cost = get_standard_cost($order_line->stock_id);
}
-
+ // added 2008-12-08 Joe Hunt. Update the purchase data table
+ add_or_update_purchase_data($po->supplier_id, $order_line->stock_id, $order_line->price,
+ $order_line->item_description);
/*Need to insert a grn item */
// only update the diff (last parameter, adj_only is set to true).
$mat_cost = update_average_material_cost($supp_trans->supplier_id, $entered_grn->item_code,
$diff, $entered_grn->this_quantity_inv, $old_date, true);
+ // added 2008-12-08 Joe Hunt. Update the purchase data table
+ add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price);
+
// function just above this
$deliveries = get_deliveries_between($entered_grn->item_code, $old_date, $date_);
if ($deliveries[0] != 0) // have deliveries been done during the period?
while ($myrow = db_fetch($result))
{
+ $data = get_purchase_data($order->supplier_id, $myrow['item_code']);
+ if ($data !== false)
+ {
+ if ($data['supplier_description'] != "")
+ $myrow['description'] = $data['supplier_description'];
+ if ($data['suppliers_uom'] != "")
+ $myrow['units'] = $data['suppliers_uon'];
+ }
if (is_null($myrow["units"]))
{
$units = "";
//----------------------------------------------------------------------------------------
+function get_purchase_data($supplier_id, $stock_id)
+{
+ $sql = "SELECT * FROM ".TB_PREF."purch_data
+ WHERE supplier_id = '" . $supplier_id . "'
+ AND stock_id = '". $stock_id . "'";
+ $result = db_query($sql, "The supplier pricing details for " . $stock_id . " could not be retrieved");
+
+ return db_fetch($result);
+}
+
+function add_or_update_purchase_data($supplier_id, $stock_id, $price, $description="", $uom="")
+{
+ $data = get_purchase_data($supplier_id, $stock_id);
+ if ($data === false)
+ {
+ $sql = "INSERT INTO ".TB_PREF."purch_data (supplier_id, stock_id, price, suppliers_uom,
+ conversion_factor, supplier_description) VALUES ('$supplier_id', '$stock_id',
+ $price, '$uom', 1, '$description')";
+ db_query($sql,"The supplier purchasing details could not be added");
+ return;
+ }
+ $price = round($price * $data['conversion_factor'], user_price_dec());
+ $sql = "UPDATE ".TB_PREF."purch_data SET price=$price";
+ if ($uom != "")
+ $sql .= ",suppliers_uom='$uom'";
+ if ($description != "")
+ $sql .= ",supplier_description='$description'";
+ $sql .= " WHERE stock_id='$stock_id' AND supplier_id='$supplier_id'";
+ db_query($sql,"The supplier purchasing details could not be updated");
+ return true;
+}
?>
\ No newline at end of file
{
if ($heading2 != "")
{
+ //br();
display_note($heading2, 0, 0, "class='overduefg'");
- echo "</td>";
}
- submit_cells('InvGRNAll', _("Add All Items"), "align=right",false,true);
+ echo "</td><td align='right'>";
+ submit('InvGRNAll', _("Add All Items"), true, false,true);
}
end_outer_table(0, false);
$SubTotal = 0;
while ($myrow2=db_fetch($result))
{
+ $data = get_purchase_data($myrow['supplier_id'], $myrow2['item_code']);
+ if ($data !== false)
+ {
+ if ($data['supplier_description'] != "")
+ $myrow2['description'] = $data['supplier_description'];
+ if ($data['suppliers_uom'] != "")
+ $myrow2['units'] = $data['suppliers_uom'];
+ if ($data['conversion_factor'] != 1)
+ {
+ $myrow2['unit_price'] = round($myrow2['unit_price'] / $data['conversion_factor'], user_price_dec());
+ $myrow2['quantiry_ordered'] = round($myrow2['quantiry_ordered'] / $data['conversion_factor'], user_qty_dec());
+ }
+ }
$Net = round(($myrow2["unit_price"] * $myrow2["quantity_ordered"]),
user_price_dec());
$SubTotal += $Net;