Fixes in MoneyField, SelectForms, etc..

This commit is contained in:
Antonio de la Rosa 2017-01-16 23:18:40 +01:00
parent 6a8065d6d9
commit 49bf2ecabf
4 changed files with 61 additions and 4 deletions

View file

@ -2,8 +2,29 @@
namespace PhangoApp\PhaModels\CoreFields; namespace PhangoApp\PhaModels\CoreFields;
//Work with cents.
class MoneyField extends DoubleField{ class MoneyField extends DoubleField{
static public $dec_point=',';
static public $thousands_sep='.';
public function __construct()
{
parent::__construct(11, true, 0, 0);
$this->form='PhangoApp\PhaModels\Forms\MoneyForm';
}
function check($value)
{
$value=$value*100;
return parent::check($value);
}
function show_formatted($value) function show_formatted($value)
{ {
@ -16,8 +37,9 @@ 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).' '.$symbol_currency; return number_format($value, 2, MoneyField::$dec_point, MoneyField::$thousands_sep).' '.$symbol_currency;
} }

35
src/Forms/MoneyForm.php Normal file
View file

@ -0,0 +1,35 @@
<?php
namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaModels\Forms\BaseForm;
use PhangoApp\PhaI18n\I18n;
/**
* Basic class for create forms
*/
class MoneyForm extends BaseForm{
public function __construct($name, $value, $extra_parameters=array())
{
parent::__construct($name, $value, $extra_parameters);
$this->comment_form='€';
}
public function form()
{
$value=$this->default_value/100;
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;
}
}
?>

View file

@ -30,7 +30,7 @@ class SelectForm extends BaseForm{
ob_start(); ob_start();
?> ?>
<select name="<?php echo $this->name; ?>" id="<?php echo $this->name; ?>_field_form" class="<?php echo $this->css; ?>"> <select name="<?php echo $this->name; ?>" id="<?php echo $this->name; ?>_field_form" class="<?php echo $this->css; ?>" <?php echo $this->extra_param; ?>>
<?php <?php
foreach($this->arr_select as $value => $select) foreach($this->arr_select as $value => $select)

View file

@ -47,7 +47,7 @@ class SelectModelForm extends SelectForm{
} }
$this->model->set_conditions($this->conditions[0], $this->conditions[1]); $this->model->set_conditions($this->conditions);
$query=$this->model->select(array($this->field_name, $this->field_value), $this->raw_query); $query=$this->model->select(array($this->field_name, $this->field_value), $this->raw_query);