diff --git a/include/class/acc_currency.class.php b/include/class/acc_currency.class.php index 7c170920c..21e4eb3a2 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 486943753..d22da1eed 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 50a1bc1f5..e6495ef1d 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("

rate %s

",$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 95011438d..01f2e4750 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