+ if ($factor == 0) return 0; // 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 ".TB_PREF."prices.price,".TB_PREF."prices.curr_abrev,
+ ".TB_PREF."prices.sales_type_id
+ FROM ".TB_PREF."prices
+ WHERE ".TB_PREF."prices.stock_id = '" . $stock_id . "' "
+ ." AND (".TB_PREF."prices.sales_type_id = " . $sales_type_id
+ ." OR ".TB_PREF."prices.sales_type_id = " . $base_id.")"
+ ." AND (".TB_PREF."prices.curr_abrev = '$currency'"
+ ." OR ".TB_PREF."prices.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 = 0.00;
+
+ if (isset($prices[$sales_type_id][$home_curr]))