+ function rate($cur, $when)
+ {
+ $this->loadRates(); // check if we have an rates.
+
+ $r = DB_DataObject::factory('core_curr_rate');
+ $r->curr = $cur;
+ $r->whereAdd("from_dt < '" . date('Y-m-d H:i:s', strtotime($when)) . "'");
+
+ $r->orderBy('to_dt ASC');
+ $r->limit(1);
+ if ($r->find(true)) {
+ return $r->rate;
+ }
+ }
+
+ function convert($val, $from, $to, $when = false)
+ {
+
+
+
+ if ($r === false) {
+ return false;
+ }
+ if (!isset($this->rates[$from]) || !isset($this->rates[$to]) ) {
+ return false;
+ }
+ //echo '<PRE>';print_R($this->rates);
+ $base = (1.0 / $this->rates[$from]) * $val;
+
+ return $this->rates[$to] * $base;