-function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,
+function add_material_cost($stock_id, $qty, $date_)
+{
+ $m_cost = 0;
+ $result = get_bom($stock_id);
+ while ($bom_item = db_fetch($result))
+ {
+ $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id = '".$bom_item['component']."'";
+ $res = db_query($sql);
+ $myrow = db_fetch($res);
+ $m_cost += ($bom_item['quantity'] * $myrow['material_cost']);
+ }
+ $sql = "SELECT material_cost FROM ".TB_PREF."stock_master WHERE stock_id = '$stock_id'";
+ $result = db_query($sql);
+ $myrow = db_fetch($result);
+ $material_cost = $myrow['material_cost'];
+ $qoh = get_qoh_on_date($stock_id, null, $date_);
+ if ($qoh + $qty <= 0)
+ $material_cost = 0;
+ else
+ $material_cost = ($qoh * $material_cost + $qty * $m_cost) / ($qoh + $qty);
+ $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost
+ WHERE stock_id='$stock_id'";
+ db_query($sql,"The cost details for the inventory item could not be updated");
+}
+
+function add_work_order($wo_ref, $loc_code, $units_reqd, $stock_id,