Currency : financial use the rate depending of the operation date

This commit is contained in:
Dany De Bontridder 2018-11-28 10:00:09 +01:00
parent c155f87b65
commit 23b60f92ea
2 changed files with 20 additions and 2 deletions

View file

@ -133,6 +133,23 @@ class Acc_Currency
return $sum;
}
/**
* Return the rate used at a certain date or -1 if date if not in the format DD.MM.YYYY or -2 if no value is found
* @param date $p_date
*/
function get_rate_date($p_date)
{
global $cn;
if (isDate($p_date) == null ) return -1;
$sql="select ch_value from currency_history
where
ch_from=(select max(ch_from) from currency_history where ch_from <= to_date($1,'DD.MM.YYYY') and currency_id=$2)
and currency_id=$2";
$value=$cn->get_value($sql,[$p_date,$this->get_id()]);
if ($value == "") return -2;
return $value;
}
}

View file

@ -630,7 +630,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$r.="</TABLE>";
$acc_currency=$this->get_currency();
$cur=$acc_currency->get_code();
$cur_rate=$acc_currency->get_rate();
$cur_rate=$acc_currency->get_rate_date($e_date);
$default_currency=new Acc_Currency($this->db , 0);
// saldo
$r.='<br>'.sprintf(_("Ancien solde = %d %s"),$solde, $cur);
@ -639,6 +639,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
if ( $acc_currency->get_id() != 0)
{
$r.='<br>'.sprintf(_("Taux = %s"),$cur_rate);
$r.='<br>'.sprintf(_("Nouveau solde = %d %s"),bcmul($new_solde,$cur_rate),$default_currency->get_code());
}
$r.='<br>'.sprintf(_("Difference = %d %s"), $tot_amount, $cur);
@ -756,7 +757,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$get_solde=true;
$acc_currency=new Acc_Currency($this->db,$this->currency_id);
$currency_rate=$acc_currency->get_rate();
$currency_rate=$acc_currency->get_rate_date($e_date);
// for each item
for ($i = 0; $i < $nb_item; $i++)