noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 33/73: CURRENCY : conversion problem


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 33/73: CURRENCY : conversion problem
Date: Fri, 28 May 2021 05:26:30 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 58cc7c7c04bbf071bee733fbb730b077cd086806
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Mon Apr 19 11:34:48 2021 +0200

    CURRENCY : conversion problem
---
 include/class/acc_currency.class.php   |  9 +++++++--
 include/class/acc_ledger.class.php     |  3 +++
 include/class/acc_ledger_fin.class.php | 14 ++++++++++++--
 include/compta_fin.inc.php             |  2 ++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/include/class/acc_currency.class.php 
b/include/class/acc_currency.class.php
index 7c17092..21e4eb3 100644
--- a/include/class/acc_currency.class.php
+++ b/include/class/acc_currency.class.php
@@ -140,15 +140,20 @@ class Acc_Currency
      */
     function get_rate_date($p_date)
     {
+        if ( $this->get_id() == 0 ) { return 1;}
         
-        if (isDate($p_date) == null ) return -1;
+        if (isDate($p_date) == null ) {
+            throw new Exception(_("Date invalide"));
+        }
         
         $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=$this->cn->get_value($sql,[$p_date,$this->get_id()]);
-        if ($value == "") return -2;
+        if ($value == "") {
+            throw new Exception(_("Aucun taux à cette date , aller sur 
CFGCURRENCY"));
+        }
         return $value;
     }
     
diff --git a/include/class/acc_ledger.class.php 
b/include/class/acc_ledger.class.php
index 4869437..d22da1e 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -3210,6 +3210,9 @@ class Acc_Ledger  extends jrn_def_sql
     function get_currency()
     {
         $cr=new Acc_Currency($this->db,$this->currency_id);
+        if ( $cr->get_id() < 0 ) {
+            throw new Exception("ACL.3214"._("Taux invalide"));
+        }
         return $cr;
     }
     /**
diff --git a/include/class/acc_ledger_fin.class.php 
b/include/class/acc_ledger_fin.class.php
index 50a1bc1..e6495ef 100644
--- a/include/class/acc_ledger_fin.class.php
+++ b/include/class/acc_ledger_fin.class.php
@@ -806,8 +806,14 @@ 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_date($e_date);
                         
+                        // get the currency_rate when we have one date for all 
the operations
+                        if ( $chdate != 2 ) {
+                            
$currency_rate=$acc_currency->get_rate_date($e_date);
+                        }
+                        if (DEBUGNOALYSS > 1) {
+                            printf("<p> rate %s </p>",$currency_rate);
+                        }
                         // for each item
                        for ($i = 0; $i < $nb_item; $i++)
                        {
@@ -816,7 +822,11 @@ class Acc_Ledger_Fin extends Acc_Ledger
                                if (strlen(trim(${"e_other$i"})) == 0)
                                        continue;
 
-                               if ( $chdate == 2 ) $e_date=${'dateop'.$i};
+                                // get the currency_rate when each  operation 
has its own date 
+                               if ( $chdate == 2 ) {
+                                    $e_date=${'dateop'.$i};
+                                     
$currency_rate=$acc_currency->get_rate_date($e_date);
+                                }
                                // if date is date of operation
                                if ($chdate == 2 && $get_solde )
                                {
diff --git a/include/compta_fin.inc.php b/include/compta_fin.inc.php
index 9501143..01f2e47 100644
--- a/include/compta_fin.inc.php
+++ b/include/compta_fin.inc.php
@@ -60,6 +60,8 @@ if ( $jrn_priv == 'X')
        NoAccess();
        exit -1;
 }
+$Ledger->set_currency_id();
+
 $p_msg="";
 //----------------------------------------
 // Confirm the operations



reply via email to

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