Fixes in moneyfield

This commit is contained in:
Antonio de la Rosa 2017-01-31 05:29:15 +01:00
parent 1a848c1baa
commit be28b150ac
2 changed files with 15 additions and 5 deletions

View file

@ -19,10 +19,13 @@ class MoneyField extends DoubleField{
function check($value) function check($value)
{ {
$value=$value*100;
return parent::check($value); $value=str_replace('.', '', $value);
$value=str_replace(',', '.', $value);
$value=parent::check($value);
return round($value, 2);
} }
@ -37,8 +40,6 @@ class MoneyField extends DoubleField{
static function currency_format($value, $symbol_currency='€') static function currency_format($value, $symbol_currency='€')
{ {
$value=$value/100;
return number_format($value, 2, MoneyField::$dec_point, MoneyField::$thousands_sep).' '.$symbol_currency; return number_format($value, 2, MoneyField::$dec_point, MoneyField::$thousands_sep).' '.$symbol_currency;
} }

View file

@ -20,10 +20,19 @@ class MoneyForm extends BaseForm{
} }
public function setform($value)
{
settype($value, 'double');
return number_format($value, 2, ',', '.');
}
public function form() public function form()
{ {
$value=$this->default_value/100; $value=$this->default_value;
return '<input type="'.$this->type.'" id="'.$this->name.'_field_form" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($value).'" '.$this->extra_param.'> '.$this->comment_form; return '<input type="'.$this->type.'" id="'.$this->name.'_field_form" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($value).'" '.$this->extra_param.'> '.$this->comment_form;