! -> Note
$ -> Affected files
+14-Jan-2010 Joe Hunt
+# A couple of small bugs were fixed in average material cost
+$ /purchasing/includes/db/grn_db.inc
+ /purchasing/includes/db/invoice_db.inc
+ /manufacturing/includes/db/work_orders_db.inc
+
13-Jan-2010 Joe Hunt
! Changed so also Item Adjustment and Cost Update allow more than 2 dec in price
$ /inventory/cost_update.php
$standard_cost = get_standard_cost($bom_item['component']);
$m_cost += ($bom_item['quantity'] * $standard_cost);
}
+ $dec = user_price_dec();
+ $m_cost = price_decimal_format($m_cost, $dec);
$sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
.db_escape($stock_id);
$result = db_query($sql);
$material_cost = 0;
else
$material_cost = ($qoh * $material_cost + $qty * $m_cost) / ($qoh + $qty);
+ $material_cost = round2($material_cost, $dec);
$sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost
WHERE stock_id=".db_escape($stock_id);
db_query($sql,"The cost details for the inventory item could not be updated");
function add_overhead_cost($stock_id, $qty, $date_, $costs)
{
+ $dec = user_price_dec();
+ $costs = price_decimal_format($costs, $dec);
if ($qty != 0)
$costs /= $qty;
$sql = "SELECT overhead_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
$overhead_cost = 0;
else
$overhead_cost = ($qoh * $overhead_cost + $qty * $costs) / ($qoh + $qty);
+ $overhead_cost = round2($overhead_cost, $dec);
$sql = "UPDATE ".TB_PREF."stock_master SET overhead_cost=".db_escape($overhead_cost)."
WHERE stock_id=".db_escape($stock_id);
db_query($sql,"The cost details for the inventory item could not be updated");
function add_labour_cost($stock_id, $qty, $date_, $costs)
{
+ $dec = user_price_dec();
+ $costs = price_decimal_format($costs, $dec);
if ($qty != 0)
$costs /= $qty;
$sql = "SELECT labour_cost FROM ".TB_PREF."stock_master WHERE stock_id = "
$labour_cost = 0;
else
$labour_cost = ($qoh * $labour_cost + $qty * $costs) / ($qoh + $qty);
+ $labour_cost = round2($labour_cost, $dec);
$sql = "UPDATE ".TB_PREF."stock_master SET labour_cost=".db_escape($labour_cost)."
WHERE stock_id=".db_escape($stock_id);
db_query($sql,"The cost details for the inventory item could not be updated");
$result = db_query($sql);
$myrow = db_fetch($result);
$material_cost = $myrow['material_cost'];
+ $dec = user_price_dec();
+ $material_cost = price_decimal_format($material_cost, $dec);
$qoh = get_qoh_on_date($stock_id, null, $date_);
if ($qoh + $qty <= 0)
$material_cost = 0;
else
$material_cost = ($qty * $costs) / ($qoh + $qty);
+ $material_cost = round2($material_cost, $dec);
$sql = "UPDATE ".TB_PREF."stock_master SET material_cost=material_cost+"
.db_escape($material_cost)
." WHERE stock_id=".db_escape($stock_id);
$currency = get_supplier_currency($supplier);
else
$currency = null;
+ $dec = user_price_dec();
+ $price = price_decimal_format($price, $dec);
if ($currency != null)
- $price_in_home_currency = to_home_currency($price, $currency, $date);
+ {
+ $ex_rate = get_exchange_rate_to_home_currency($currency, $date_);
+ $price_in_home_currency = $price / $ex_rate;
+ //$price_in_home_currency = to_home_currency($price, $currency, $date);
+ }
else
$price_in_home_currency = $price;
$sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id);
$result = db_query($sql);
$myrow = db_fetch($result);
$material_cost = $myrow['material_cost'];
+ if ($price > -0.0001 && $price < 0.0001)
+ return $material_cost;
if ($adj_only)
$exclude = ST_CUSTDELIVERY;
else
$exclude = 0;
$qoh = get_qoh_on_date($stock_id, null, $date, $exclude);
-
if ($adj_only)
{
if ($qoh <= 0)
elseif ($qoh + $qty <= 0)
$material_cost = 0;
else
+ {
+ if ($qoh < 0)
+ $qoh = 0;
$material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) / ($qoh + $qty);
+ }
+ $material_cost = round2($material_cost, $dec);
$sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)."
WHERE stock_id=".db_escape($stock_id);
{
/*Update sales_order_details for the new quantity received and the standard cost used for postings to GL and recorded in the stock movements for FIFO/LIFO stocks valuations*/
-
//------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008
update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price,
$order_line->receive_qty, $date_);
function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amount2)
{
+ $dec = user_price_dec();
+ price_decimal_format($amount2, $dec);
$currency = get_supplier_currency($supplier);
- $amount1 = to_home_currency($amount1, $currency, $old_date);
- $amount2 = to_home_currency($amount2, $currency, $date);
- return $amount2 - $amount1;
+ $ex_rate = get_exchange_rate_to_home_currency($currency, $old_date);
+ $amount1 = $amount1 / $ex_rate;
+ $ex_rate = get_exchange_rate_to_home_currency($currency, $date_);
+ $amount2 = $amount2 / $ex_rate;
+ $diff = $amount2 - $amount1;
+ return round2($diff, $dec);
}
//----------------------------------------------------------------------------------------
$entered_grn->this_quantity_inv = -$entered_grn->this_quantity_inv;
set_grn_item_credited($entered_grn, $supp_trans->supplier_id, $invoice_id, $date_);
}
-
$line_taxfree = $entered_grn->taxfree_charge_price($supp_trans->tax_group_id);
$line_tax = $entered_grn->full_charge_price($supp_trans->tax_group_id) - $line_taxfree;
$stock_gl_code = get_stock_gl_code($entered_grn->item_code);