2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* Represents a decimal field containing a currency amount.
|
2007-07-19 12:40:28 +02:00
|
|
|
* Currency the currency class only supports single currencies.
|
2009-04-02 19:17:04 +02:00
|
|
|
*
|
2009-05-05 10:10:51 +02:00
|
|
|
* @deprecated 2.5 Use Money class
|
2009-04-02 19:17:04 +02:00
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Currency extends Decimal {
|
2008-04-22 04:12:26 +02:00
|
|
|
protected static $currencySymbol = '$';
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
function Nice() {
|
|
|
|
// return "<span title=\"$this->value\">$" . number_format($this->value, 2) . '</span>';
|
2008-04-22 04:12:26 +02:00
|
|
|
$val = self::$currencySymbol . number_format(abs($this->value), 2);
|
2008-03-17 03:10:23 +01:00
|
|
|
if($this->value < 0) return "($val)";
|
|
|
|
else return $val;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function Whole() {
|
2008-04-22 04:12:26 +02:00
|
|
|
$val = self::$currencySymbol . number_format(abs($this->value), 0);
|
2008-03-17 03:10:23 +01:00
|
|
|
if($this->value < 0) return "($val)";
|
|
|
|
else return $val;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setValue($value) {
|
2008-03-17 04:03:43 +01:00
|
|
|
$matches = null;
|
|
|
|
if(is_numeric($value)) {
|
|
|
|
$this->value = $value;
|
|
|
|
|
|
|
|
} else if(preg_match('/-?\$?[0-9,]+(.[0-9]+)?([Ee][0-9]+)?/', $value, $matches)) {
|
2008-04-22 04:12:26 +02:00
|
|
|
$this->value = str_replace(array('$',',',self::$currencySymbol),'',$matches[0]);
|
2008-03-17 04:03:43 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->value = 0;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-04-22 04:12:26 +02:00
|
|
|
|
|
|
|
static function setCurrencySymbol($value) {
|
|
|
|
self::$currencySymbol = $value;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|