+ if ($factor == 0) return false; // auto price calculations off
+
+ $base_id = get_base_sales_type();
+ $home_curr = get_company_currency();
+
+ // get all prices which we can use to guess the price.
+ // alternative is make up to 2 additional sql queries
+ $sql = "SELECT price, curr_abrev, sales_type_id
+ FROM ".TB_PREF."prices
+ WHERE stock_id = '" . $stock_id . "' "
+ ." AND (sales_type_id = " . $sales_type_id
+ ." OR sales_type_id = " . $base_id.")"
+ ." AND (curr_abrev = '$currency'"
+ ." OR curr_abrev = '$home_curr')";
+
+ $result = db_query($sql, $msg);
+
+ $prices = array();
+ while($myrow = db_fetch($result))
+ {
+ $prices[$myrow['sales_type_id']][$myrow['curr_abrev']] = $myrow['price'];
+ }
+
+ $rate = round(get_exchange_rate_from_home_currency($currency, $date),
+ user_exrate_dec());
+ $price = false;
+
+ if (isset($prices[$sales_type_id][$home_curr]))