noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 100/238: Currency : financial use the rate de


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 100/238: Currency : financial use the rate depending of the operation date
Date: Sat, 26 Oct 2019 04:40:43 -0400 (EDT)

sparkyx pushed a commit to annotated tag rel7110
in repository noalyss.

commit 23b60f92ea2580e382d32dc144a0c6c3cd9c2375
Author: Dany De Bontridder <address@hidden>
Date:   Wed Nov 28 10:00:09 2018 +0100

    Currency : financial use the rate depending of the operation date
---
 include/class/acc_currency.class.php   | 17 +++++++++++++++++
 include/class/acc_ledger_fin.class.php |  5 +++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/include/class/acc_currency.class.php 
b/include/class/acc_currency.class.php
index 3012916..7470957 100644
--- a/include/class/acc_currency.class.php
+++ b/include/class/acc_currency.class.php
@@ -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;
+    }
     
 
 }
diff --git a/include/class/acc_ledger_fin.class.php 
b/include/class/acc_ledger_fin.class.php
index 8ae133f..30206fa 100644
--- a/include/class/acc_ledger_fin.class.php
+++ b/include/class/acc_ledger_fin.class.php
@@ -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++)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]