function getCurrencyData($currency_id) { Debug::Text('Getting Currency Data for ID: ' . $currency_id, __FILE__, __LINE__, __METHOD__, 10); $clf = new CurrencyListFactory(); $clf->getById($currency_id); if ($clf->getRecordCount() > 0) { $c_obj = $clf->getCurrent(); $retarr = array('id' => $c_obj->getId(), 'conversion_rate' => $c_obj->getConversionRate(), 'iso_code' => $c_obj->getISOCode()); return $retarr; } return FALSE; }
function getCurrencyObject() { if (is_object($this->currency_obj)) { return $this->currency_obj; } else { $clf = new CurrencyListFactory(); $clf->getById($this->getCurrency()); if ($clf->getRecordCount() > 0) { $this->currency_obj = $clf->getCurrent(); return $this->currency_obj; } } return FALSE; }
static function convertCurrency($src_currency_id, $dst_currency_id, $amount = 1) { //Debug::Text('Source Currency: '. $src_currency_id .' Destination Currency: '. $dst_currency_id .' Amount: '. $amount, __FILE__, __LINE__, __METHOD__,10); if ($src_currency_id == '') { return FALSE; } if ($dst_currency_id == '') { return FALSE; } if ($amount == '') { return FALSE; } if ($src_currency_id == $dst_currency_id) { return $amount; } $clf = new CurrencyListFactory(); $clf->getById($src_currency_id); if ($clf->getRecordCount() > 0) { $src_currency_obj = $clf->getCurrent(); } else { Debug::Text('Source currency does not exist.', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } $clf->getById($dst_currency_id); if ($clf->getRecordCount() > 0) { $dst_currency_obj = $clf->getCurrent(); } else { Debug::Text('Destination currency does not exist.', __FILE__, __LINE__, __METHOD__, 10); return FALSE; } if (is_object($src_currency_obj) and is_object($dst_currency_obj)) { return self::Convert($src_currency_obj->getConversionRate(), $dst_currency_obj->getConversionRate(), $amount); } return FALSE; }