Task #448 : currency_id = 0 for the default currency + display currency rate in confirm operation

This commit is contained in:
Dany De Bontridder 2018-05-11 20:46:40 +02:00
parent ca620cb2b8
commit 05305dfeab
5 changed files with 30 additions and 13 deletions

View file

@ -108,8 +108,7 @@ class Acc_Currency
function select_currency()
{
$select=new ISelect('p_currency_code');
$a_currency[0]=["value"=>-1,"label"=>"EUR"];
$a_currency+=$this->cn->make_array("select currency_id,cr_code_iso from v_currency_last_value order by cr_code_iso");
$a_currency=$this->cn->make_array("select currency_id,cr_code_iso from v_currency_last_value order by cr_code_iso");
$select->value=$a_currency;
$select->selected=$this->currency->cr_code_iso;

View file

@ -1367,7 +1367,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
// Currency
$currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
$currency_select->selected=$http->request('p_currency_code','string',-1);
$currency_select->selected=$http->request('p_currency_code','string',0);
$currency_input=new INum("p_currency_rate");
$currency_input->id="p_currency_rate";
@ -1662,7 +1662,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger
// Get currency code
$str_code='EUR';
if ( $p_currency_code != -1 ) {
if ( $p_currency_code != 0 ) {
$acc_currency=new Acc_Currency($this->db);
$acc_currency->set_id($p_currency_code);
$str_code=$acc_currency->get_code();
@ -1688,6 +1688,10 @@ class Acc_Ledger_Purchase extends Acc_Ledger
{$tot} {$str_code}
</td>
</tr>
EOF;
if ($p_currency_code !=0) {
$rate=_("Taux ");
$r.=<<<EOF
<tr class="highlight">
{$decalage}
<td>
@ -1697,14 +1701,15 @@ class Acc_Ledger_Purchase extends Acc_Ledger
</td>
<td class="num">
{$rate} {$p_currency_rate}
</td>
<td class="num">
{$tot_eur} EUR
</td>
</tr>
EOF;
} else {
}
}else {
$r.=<<<EOF
<tr class="highlight">
{$decalage}

View file

@ -923,7 +923,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
// Get currency code
$str_code='EUR';
if ( $p_currency_code != -1 ) {
if ( $p_currency_code != 0 ) {
$acc_currency=new Acc_Currency($this->db);
$acc_currency->set_id($p_currency_code);
$str_code=$acc_currency->get_code();
@ -949,7 +949,11 @@ if ( $g_parameter->MY_TVA_USE=="Y") {
{$tot} {$str_code}
</td>
</tr>
<tr class="highlight">
EOF;
if ($p_currency_code !=0) {
$rate=_("Taux ");
$r.=<<<EOF
<tr class="highlight">
{$decalage}
<td>
@ -958,13 +962,15 @@ if ( $g_parameter->MY_TVA_USE=="Y") {
</td>
<td class="num">
{$rate} {$p_currency_rate}
</td>
<td class="num">
{$tot_eur} EUR
</td>
</tr>
EOF;
}
} else {
$r.=<<<EOF
<tr class="highlight">
@ -987,8 +993,10 @@ EOF;
<td>
</td>
<td>
</td>
<td>
{$rate} {$p_currency_rate}
</td>
<td class="num">
{$tot} {$str_code}
@ -1453,7 +1461,7 @@ EOF;
// Currency
$currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
$currency_select->selected=$http->request('p_currency_code','string',-1);
$currency_select->selected=$http->request('p_currency_code','string',0);
$currency_input=new INum("p_currency_rate");
$currency_input->id="p_currency_rate";

View file

@ -30,6 +30,7 @@ require_once NOALYSS_INCLUDE.'/database/currency_history_sql.class.php';
/**
* Manage the configuration of currency , add currency, rate, remove and update
* Concerned tables are v_currency_last_value _SQL , Currency_SQL , Currency_History_SQL
* currency_id = 0 for the default currency , -1 for a new one
*/
class Currency_MTable extends Manage_Table_SQL
{
@ -110,13 +111,17 @@ class Currency_MTable extends Manage_Table_SQL
* - Date of the rate
* - code iso is max 10 char
* - name is max 80
*
* Default currency (id=0) cannot be changed
*/
function check()
{
global $cn;
$table=$this->get_table();
$is_error=0;
if ( $table->currency_id == 0) {
$is_error++;
$this->set_error("cr_code_iso", _("Devise par défaut ne peut être changée"));
}
// ------ cr_code_iso can not be empty
if (trim($table->cr_code_iso)=="")
{
@ -292,7 +297,7 @@ class Currency_MTable extends Manage_Table_SQL
*/
function display_row($p_row)
{
if ($p_row['currency_id']==-1)
if ($p_row['currency_id']==0)
{
return;
}

View file

@ -94,7 +94,7 @@ COMMENT ON COLUMN public.operation_currency.oc_vat_amount IS 'vat amount in curr
COMMENT ON COLUMN public.operation_currency.oc_price_unit IS 'unit price in currency' ;
COMMENT ON COLUMN public.operation_currency.j_id IS 'fk to jrnx' ;
alter table jrn add currency_id bigint default -1;
alter table jrn add currency_id bigint default 0;
alter table jrn add currency_rate numeric (20,6) default 1;
alter table jrn add currency_rate_ref numeric(20,6) default 1;
ALTER TABLE public.jrn ADD CONSTRAINT jrn_currency_fk FOREIGN KEY (currency_id) REFERENCES public.currency(id) ON DELETE RESTRICT ON UPDATE RESTRICT;