Currency : create view + add currency name to table currency
This commit is contained in:
parent
ab2b8ac616
commit
9733fadf91
4 changed files with 62 additions and 1 deletions
36
include/class/currency_mtable.class.php
Normal file
36
include/class/currency_mtable.class.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of NOALYSS.
|
||||
*
|
||||
* PhpCompta is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PhpCompta is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PhpCompta; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
// Copyright (2018) Author Dany De Bontridder <dany@alchimerys.be>
|
||||
|
||||
/**
|
||||
* @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);
|
||||
//
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue