Module gl sealed against XSS Attacks
[fa-stable.git] / purchasing / includes / db / grn_db.inc
index 910cf9a6f30af6e43fb2cbb91ddf7b0436cc10f3..81b11bb97ed22c8b755f510e8d5bd6ca2862e480 100644 (file)
@@ -34,8 +34,11 @@ function add_grn(&$po, $date_, $reference, $location)
                        $myrow = db_fetch($result);
                        $material_cost = $myrow['material_cost'];
                        $qoh = get_qoh_on_date($order_line->stock_id, null, $date_);
-                       $material_cost = ($qoh * $material_cost + $order_line->receive_qty * $price_in_home_currency) /
-                               ($qoh + $order_line->receive_qty);
+                       if ($qoh + $order_line->receive_qty <= 0)
+                               $material_cost = 0;
+                       else
+                               $material_cost = ($qoh * $material_cost + $order_line->receive_qty * $price_in_home_currency) /
+                                       ($qoh + $order_line->receive_qty);
                        $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost
                                WHERE stock_id='$order_line->stock_id'";
                        db_query($sql,"The cost details for the inventory item could not be updated");
@@ -56,8 +59,6 @@ function add_grn(&$po, $date_, $reference, $location)
                } /*quantity received is != 0 */
        } /*end of order_line loop */
 
-       add_forms_for_sys_type(25, $grn, $location);
-
        references::save_last($reference, 25);
 
        commit_transaction();