X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=DataObjects%2FCore_curr_rate.php;h=fddb0af7d191c98d60481df663cd8a14ce95245b;hb=f86d552f3b4c9e558e31592fe3268930fd19f796;hp=98dfa054cdb71b0a1bd2ea4a4a0c785fb7512556;hpb=7d30497752c769f6db39aae8ad4df54c7d443671;p=Pman.Core diff --git a/DataObjects/Core_curr_rate.php b/DataObjects/Core_curr_rate.php index 98dfa054..fddb0af7 100644 --- a/DataObjects/Core_curr_rate.php +++ b/DataObjects/Core_curr_rate.php @@ -48,7 +48,7 @@ class Pman_Core_DataObjects_Core_curr_rate extends DB_DataObject // how often do we need to know this..? // let's assume we do it once a week.. $x = DB_DataObject::Factory('core_curr_rate'); - $x->whereAdd('to_date > NOW()'); + $x->whereAdd('to_dt > NOW()'); if ($x->count()) { // got some data for beyond today.. @@ -78,7 +78,7 @@ class Pman_Core_DataObjects_Core_curr_rate extends DB_DataObject return false; } - $dom = simplexml_load_file($target); + $dom = simplexml_load_string($f); $rates['EUR'] = 1.0; foreach($dom->Cube->Cube->Cube as $c) { @@ -90,35 +90,30 @@ class Pman_Core_DataObjects_Core_curr_rate extends DB_DataObject foreach($rates as $cur=>$euro) { - $rate = $this->rates['USD'] * $euro; - - - - - - + $rate = $rates['USD'] * $euro; + $ov = DB_DataObject::Factory('core_curr_rate'); $ov->curr = $cur; $nl = clone($x); - $ov->orderBy('to_date DESC'); + $ov->orderBy('to_dt DESC'); $ov->limit(1); $nl->from_dt = DB_DataObject::sqlValue("NOW()"); $nl->to_dt = DB_DataObject::sqlValue("NOW() + INTERVAL 7 DAY"); if ($ov->find(true)) { - if (strtotime($ov->to_date) > time()) { + if (strtotime($ov->to_dt) > time()) { continue; } - $nl->from_dt = $ov->to_date; + $nl->from_dt = $ov->to_dt; if ($ov->rate == $rate) { // modify the old one to expire $oo = clone($ov); - $ov->to_date = $nv->to_from_dt; + $ov->to_dt = $nv->from_dt; $ov->update($oo); continue; } @@ -157,11 +152,20 @@ class Pman_Core_DataObjects_Core_curr_rate extends DB_DataObject { - $fr = $this->rate($from, $when) - //echo '
';print_R($this->rates);
-        $base = (1.0 / $this->rates[$from]) * $val;
+        $fr = $this->rate($from, $when);
+        $tr = $this->rate($to, $when);
+        
+        // crappy error handling..
+        if ($fr === false) {
+            $fr = 1;
+        }
+        if ($tr === false) {
+            $tr = 1;
+        }
+        
+        return ((1.0 / $fr) * $val) * $tr;
   
-        return $this->rates[$to] * $base;
+        
     
     }