$myrow[0] -= $myrow2[0];
}
- return $myrow[0];
+ $qoh = $myrow[0];
+ return $qoh ? $qoh : 0;
}
//--------------------------------------------------------------------------------------
$negative_trans_id = $myrow['trans_id'];
}
if ($qty >= 0)
- $flag = 0;
+ $flag = 0;
}
-
+
if ($flag == 1)
return $negative_trans_id;
else
." AND trans_id ='$from'";
$result = db_query($sql, "The deliveries could not be updated");
$cost = db_fetch_row($result);
-
+
// Adjusting QOH valuation
$sql = "SELECT SUM(qty) FROM ".TB_PREF."stock_moves
WHERE stock_id=".db_escape($stock_id)." AND
trans_id<'$from' GROUP BY stock_id";
$result = db_query($sql, "The deliveries could not be updated");
$qoh = db_fetch_row($result);
-
+
$qty = $row[0] - $qoh[0]; //QOH prior to -ve stock is subtracted
$final_cost = $row[1] - $qoh[0]*$cost[0];
$new_purchase_cost = $row[0] * $material_cost;
$purchase_diff = $new_purchase_cost - $old_purchase_cost;
}
-
+
$diff = $sales_diff - $purchase_diff;
if ($diff != 0)
function void_stock_move($type, $type_no)
{
$sql = "SELECT * from ".TB_PREF."stock_moves WHERE type=".db_escape($type)." AND trans_no=".db_escape($type_no);
+
$result = db_query($sql, "Could not void stock moves");
while ($row = db_fetch($result))
{
// The cost has to be adjusted.
// Transaction rates are stored either as price or standard_cost depending on types
$types = array(ST_SUPPCREDIT, ST_SUPPRECEIVE);
- if (in_array($type,$types))
- $trans_rate = $row["price"];
+ if (in_array($type, $types))
+ $unit_cost = $row["price"];
else
- $trans_rate = $row["standard_cost"];
+ $unit_cost = $row["standard_cost"];
- update_average_material_cost(0, $row["stock_id"],
- $trans_rate, -$row["qty"], sql2date($row["tran_date"]));
+ update_average_material_cost($row["person_id"], $row["stock_id"],
+ $unit_cost, -$row["qty"], sql2date($row["tran_date"]));
}
}
display_db_error("could not retreive the location name for $loc_code", $sql, true);
}
-
-//--------------------------------------------------------------------------------------------------
-
-
-?>
\ No newline at end of file