diff --git a/include/class/currency_mtable.class.php b/include/class/currency_mtable.class.php new file mode 100644 index 000000000..acfb7aeaf --- /dev/null +++ b/include/class/currency_mtable.class.php @@ -0,0 +1,36 @@ + + +/** + * @file + * @brief Currency thanks the view v_currency_last_value + */ + +class Current_MTable extends Manage_Table_SQL +{ + function __construct(Data $p_table) + { + $this->table=$p_table; + parent::__construct($p_table); + // + + } +} \ No newline at end of file diff --git a/include/database/currency_history_sql.class.php b/include/database/currency_history_sql.class.php index e1935324f..05f35a4c9 100644 --- a/include/database/currency_history_sql.class.php +++ b/include/database/currency_history_sql.class.php @@ -58,7 +58,7 @@ class Currency_history_SQL extends Noalyss_SQL "id"=>"auto" ); - $this->date_format="DD.MM.YYYY"; + $this->date_format="YYYYMMDD"; parent::__construct($p_cn, $p_id); } diff --git a/include/database/currency_sql.class.php b/include/database/currency_sql.class.php index 0d00e0b8f..ef67bcc61 100644 --- a/include/database/currency_sql.class.php +++ b/include/database/currency_sql.class.php @@ -40,6 +40,7 @@ class Currency_SQL extends Noalyss_SQL $this->name=array( "id"=>"id" , "cr_code_iso"=>"cr_code_iso" + ,"cr_name"=>"cr_name" ); /* * Type of columns @@ -47,6 +48,7 @@ class Currency_SQL extends Noalyss_SQL $this->type=array( "id"=>"numeric" , "cr_code_iso"=>"text" + , "cr_name"=>"text" ); diff --git a/sql/upgrade.sql b/sql/upgrade.sql index 0aeb2675f..cdc851fd6 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -24,3 +24,26 @@ CREATE TABLE public.currency_history ( ; -- Ajouter commentaire sur colonne + +ALTER TABLE public.currency ADD cr_name varchar(80) NULL; + +-- Create view to manage the table +create view v_currency_last_value as +with recent_rate as +( select + currency_id,max(ch_from) as rc_from + from + currency_history + group by currency_id + ) +select + cr1.id as currency_id, + cr1.cr_name, + cr1.cr_code_iso, + ch1.id as currency_history_id, + ch1.ch_value as ch_value, + rc_from +from +currency as cr1 +join recent_rate on (currency_id=cr1.id) +join currency_history as ch1 on (recent_rate.currency_id=ch1.currency_id and rc_from=ch1.ch_from); \ No newline at end of file