noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 16/73: Currency : add a check , upgrade versi


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 16/73: Currency : add a check , upgrade version of DB
Date: Fri, 28 May 2021 05:26:23 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 47bf11652f3ba0cd4a25f196eecab6544dafd159
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Apr 11 12:22:24 2021 +0200

    Currency : add a check , upgrade version of DB
---
 include/class/acc_ledger.class.php          | 63 +++++++++++++++++------------
 include/class/acc_ledger_purchase.class.php |  1 +
 include/class/acc_ledger_sold.class.php     |  1 +
 include/constant.php                        |  2 +-
 include/sql/patch/upgrade155.sql            | 55 +++++++++++++++++++++++++
 5 files changed, 96 insertions(+), 26 deletions(-)

diff --git a/include/class/acc_ledger.class.php 
b/include/class/acc_ledger.class.php
index 6a2dee0..4869437 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -1094,30 +1094,7 @@ class Acc_Ledger  extends jrn_def_sql
         $currency_code=$http->extract($p_array,"p_currency_code","number");
         $currency=new Acc_Currency($this->db,$currency_code);
 
-        if ( $p_currency_code == -1 )
-        {
-            throw new Exception(_('Devise inconnue'), 3);
-        }
-        
-        /* -- check the accounting for error of exchange -*/
-        if ($p_currency_code >  0 )
-        {
-            $poste=new 
Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB);
-            if ($poste->get_parameter("id") == -1 )
-            {
-                throw new Exception(
-                        sprintf(_("Dans COMPANY, vous n'avez pas paramétré 
correctement ".
-                                " le compte de débit %s pour les erreurs de 
conversion"),$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB), 3);
-            }
-            $poste=new 
Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED);
-            if ($poste->get_parameter("id") == -1 )
-            {
-                throw new Exception(
-                        sprintf(_("Dans COMPANY, vous n'avez pas paramétré 
correctement ".
-                                " le compte de crédit %s pour les erreurs de 
conversion"),$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED), 3);
-            }
-
-        }        
+        $this->check_currency_setting($currency_code);
         
         /* check if we can write into this ledger */
         if ($g_user->check_jrn($p_jrn)!='W')
@@ -1751,7 +1728,43 @@ class Acc_Ledger  extends jrn_def_sql
             return false;
         throw new Exception("Valeur invalid ".__FILE__.':'.__LINE__);
     }
-    
+    /**
+     * Check that the currency code  does exist and the setting of the folder 
is correct
+     * 
+     * @param int $p_currency_code
+     * @throws Exception
+     */
+    function check_currency_setting ($p_currency_code)
+    {
+        global $g_parameter;
+          if ( $p_currency_code == -1 )
+        {
+            throw new Exception(_('Devise inconnue'), 3);
+        }
+        /* -- check the accounting for error of exchange -*/
+        if ($p_currency_code >  0 )
+        {
+            $poste=new 
Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_DEB);
+           
+            if ($poste->get_parameter("id") == -1 )
+            {
+                throw new Exception(
+                        sprintf(_("Dans COMPANY, vous n'avez pas paramétré 
correctement ".
+                                " le compte de débit %s pour les erreurs de 
conversion"),
+                                $g_parameter->MY_DEFAULT_ROUND_ERROR_DEB), 3);
+            }
+            
+            $poste=new 
Acc_Account($this->db,$g_parameter->MY_DEFAULT_ROUND_ERROR_CRED);
+            if ($poste->get_parameter("id") == -1 )
+            {
+                throw new Exception(
+                        sprintf(_("Dans COMPANY, vous n'avez pas paramétré 
correctement ".
+                                " le compte de crédit %s pour les erreurs de 
conversion"),
+                                $g_parameter->MY_DEFAULT_ROUND_ERROR_CRED), 3);
+            }
+
+        }        
+    }
     /**
      * When we write a record for the payment at the same time as a sale or a 
purchase, to have a 
      * bank saldo reliable , all the bank operation must be in the same 
currency
diff --git a/include/class/acc_ledger_purchase.class.php 
b/include/class/acc_ledger_purchase.class.php
index b3d9ebf..b6164ca 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -287,6 +287,7 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
         if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
             throw new Exception(_('Taux devise invalide'),15);
         }
+        $this->check_currency_setting($p_currency_code);
     }
     /**
      * Compute the ND amount thanks the attribute of the concerned card. The 
object 
diff --git a/include/class/acc_ledger_sold.class.php 
b/include/class/acc_ledger_sold.class.php
index 4d49624..ae42b10 100644
--- a/include/class/acc_ledger_sold.class.php
+++ b/include/class/acc_ledger_sold.class.php
@@ -245,6 +245,7 @@ class Acc_Ledger_Sold extends Acc_Ledger {
         if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
             throw new Exception(_('Taux devise invalide'),15);
         }
+        $this->check_currency_setting($p_currency_code);
     }
 
     /*!\brief insert into the database, it calls first the verify function,
diff --git a/include/constant.php b/include/constant.php
index 75363be..8a19d10 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -110,7 +110,7 @@ if ( !defined ("NOALYSS_PACKAGE_REPOSITORY")) {
 if ( ! defined ("SYSINFO_DISPLAY")) {
     define ("SYSINFO_DISPLAY",TRUE);
 }
-define ("DBVERSION",155);
+define ("DBVERSION",156);
 define ("MONO_DATABASE",25);
 define ("DBVERSIONREPO",19);
 define ('NOTFOUND','--not found--');
diff --git a/include/sql/patch/upgrade155.sql b/include/sql/patch/upgrade155.sql
new file mode 100644
index 0000000..d6063bc
--- /dev/null
+++ b/include/sql/patch/upgrade155.sql
@@ -0,0 +1,55 @@
+begin;
+
+create or replace function tmp_1 () returns void
+as 
+$fct$
+declare 
+       sCountry text;
+        nOhada int;
+begin
+       
+-- set my_country for OHADA
+select count(*) into nOhada from tmp_pcmn where pcm_val='886' ;
+
+if nOhada = 1 then 
+    update parameter set pr_value='AF' where pr_id='MY_COUNTRY';
+end if;
+
+select pr_value into sCountry from parameter where pr_id='MY_COUNTRY';
+
+if sCountry = 'BE' then
+    insert into tmp_pcmn 
(pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
+values ('755','Ecart de conversion','75','PRO','Y') on conflict do nothing;
+    insert into tmp_pcmn 
(pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
+values ('655','Ecart de conversion','65','CHA','Y') on conflict do nothing;
+
+    update  public."parameter"  set pr_value = '755' where pr_id= 
'MY_DEFAULT_ROUND_ERROR_CRED';
+    update  public."parameter"  set pr_value =  '655' where pr_id= 
'MY_DEFAULT_ROUND_ERROR_DEB';
+    
+
+end if;        
+
+if sCountry = 'FR' then 
+    insert into tmp_pcmn 
(pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
+values ('758','Ecart de conversion','75','PRO','Y') on conflict do nothing;
+    insert into tmp_pcmn 
(pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use)
+values ('658','Ecart de conversion ','65','CHA','Y') on conflict do nothing;
+
+    update  public."parameter"  set pr_value = '758' where pr_id= 
'MY_DEFAULT_ROUND_ERROR_CRED';
+    update  public."parameter"  set pr_value =  '658' where pr_id= 
'MY_DEFAULT_ROUND_ERROR_DEB';
+    
+end if;
+
+
+
+end;
+$fct$
+language plpgsql;
+
+select tmp_1();
+
+drop function tmp_1;
+insert into version (val,v_description) values (156,'insert default 
accounting');
+
+
+commit;
\ No newline at end of file



reply via email to

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