+ $stock_qty = $qoh_stock[$stock_id];
+
+ if ($qty <= $stock_qty)
+ return $demand;
+ $bom = @$bom_list[$stock_id];
+ if ($bom == NULL) {
+ $sql = "SELECT parent, component, quantity FROM "
+ .TB_PREF."bom WHERE parent = ".db_escape($stock_id);
+ if ($location != "") $sql .= " AND loc_code = ".db_escape($location);
+ $result = db_query($sql, "Could not search bom");
+ $bom = array();
+ // Even if we get no results, remember that fact
+ $bom[] = array($stock_id, '', 0);
+ while ($row = db_fetch_row($result)) {
+ $bom[] = array($row[0], $row[1], $row[2]);
+ }
+ db_free_result($result);
+ $bom_list[$stock_id] = $bom;
+ }
+ $len = count($bom);
+ $i = 0;
+ while ($i < $len) {
+ $row = $bom[$i];
+ $i++;
+ // Ignore the dummy entry
+ if ($row[1] == '') continue;
+ $q = $qty * $row[2];
+ if ($row[1] == $demand_id) $demand += $q;
+ $demand += stock_demand_manufacture($row[1], $q, $demand_id, $location, $level+1);
+ }
+ return $demand;
+}
+
+// recursion fixed by Tom Moulton
+function get_demand_asm_qty($stock_id, $location)
+{
+ $demand_qty = 0.0;
+ $sql = "SELECT line.stk_code, SUM(line.quantity-line.qty_sent) AS Demmand
+ FROM ".TB_PREF."sales_order_details line,
+ ".TB_PREF."sales_orders sorder,
+ ".TB_PREF."stock_master item
+ WHERE sorder.order_no = line.order_no
+ AND sorder.trans_type=".ST_SALESORDER
+ ." AND sorder.trans_type=line.trans_type
+ AND line.quantity-line.qty_sent > 0
+ AND item.stock_id=line.stk_code
+ AND item.mb_flag='M'";
+ if ($location != "")
+ $sql .= " AND sorder.from_stk_loc =".db_escape($location);
+ $sql .= " GROUP BY line.stk_code";
+ $result = db_query($sql, "No transactions were returned");
+ while ($row = db_fetch_row($result)) {
+ $demand_qty += stock_demand_manufacture($row[0], $row[1], $stock_id, $location);
+ }