From 7eb4644cf0a6359b86617ce2adf0989459a64f53 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 20 Oct 2018 14:05:13 +0200 Subject: [PATCH] Currency : financial ledger can be set to a specific currency --- include/class/acc_ledger.class.php | 37 ++++++++++++++++++++++ include/database/jrn_def_sql.class.php | 43 ++++++++++++++++---------- include/template/param_jrn.php | 19 +++++++++++- sql/upgrade.sql | 10 +++++- 4 files changed, 91 insertions(+), 18 deletions(-) diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 10eaae9c3..51adc9853 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -82,6 +82,7 @@ class Acc_Ledger extends jrn_def_sql $this->db=$p_cn; $this->row=null; $this->nb=MAX_ARTICLE; + $this->currency_id=0; } function get_last_pj() @@ -2277,9 +2278,27 @@ class Acc_Ledger extends jrn_def_sql ["label"=>_("Désactivé"),"value"=>0] ]; $actif->selected=$this->jrn_enable; + // -- default currency used : only for financial ledgers + $default_currency=$this->select_default_currency(); require_once NOALYSS_TEMPLATE.'/param_jrn.php'; } + /** + * @brief create a select button to set the default currency for a ledger + * used only for empty financial ledger + * @return ISelect object + */ + function select_default_currency() + { + $default_currency=new ISelect("defaultCurrency"); + $default_currency->value=$this->db->make_array("select id,cr_code_iso from public.currency order by 1 "); + $default_currency->selected=$this->currency_id; + $nb_operation=$this->db->get_value("select count(*) from jrn where jr_def_id=$1",[$this->id]); + if ( $nb_operation > 0) { + $default_currency->setReadOnly(TRUE); + } + return $default_currency; + } /** * Verify before update * @@ -2357,6 +2376,7 @@ class Acc_Ledger extends jrn_def_sql $this->jrn_deb_max_line=($min_row<1)?1:$min_row; $this->jrn_def_description=$p_description; $this->jrn_enable=$jrn_enable; + $this->currency_id=0; switch ($this->jrn_def_type) { case 'ACH': @@ -2389,6 +2409,18 @@ class Acc_Ledger extends jrn_def_sql if ($result==-1) throw new Exception(_("Aucun compte en banque n'est donné")); $this->jrn_def_num_op=(isset($numb_operation))?1:0; + // if nb operation == 0 then update currency_id + $nb_operation = $this->db->get_value("select count(*) from jrn where jr_def_id=$1", + [$this->jrn_def_id]); + /* + * Set the default currency except if there are already operation + */ + if ( $nb_operation == 0 ){ + $this->currency_id=$defaultCurrency; + } else { + $this->currency_id=$this->db->get_value("select currency_id from jrn_def where jrn_def_id=$1", + [$this->jrn_def_id]); + } break; } @@ -2513,6 +2545,8 @@ class Acc_Ledger extends jrn_def_sql $cn=$this->db; $min_row=new INum("min_row", MAX_ARTICLE); $min_row->prec=0; + // -- default currency used : only for financial ledgers + $default_currency=$this->select_default_currency(); require_once NOALYSS_TEMPLATE.'/param_jrn.php'; } @@ -2536,6 +2570,8 @@ class Acc_Ledger extends jrn_def_sql trim(substr($this->jrn_def_type, 0, 1)), Acc_Ledger::next_number($this->db, $this->jrn_def_type)); $this->jrn_def_description=$p_description; + $this->currency_id=0; + switch ($this->jrn_def_type) { case 'ACH': @@ -2567,6 +2603,7 @@ class Acc_Ledger extends jrn_def_sql if ($result==-1) throw new Exception(_("Aucun compte en banque n'est donné")); $this->jrn_def_num_op=(isset($numb_operation))?1:0; + $this->currency_id=$defaultCurrency; break; } diff --git a/include/database/jrn_def_sql.class.php b/include/database/jrn_def_sql.class.php index 4840fbc34..818248f6d 100644 --- a/include/database/jrn_def_sql.class.php +++ b/include/database/jrn_def_sql.class.php @@ -55,6 +55,7 @@ class Jrn_Def_sql , "jrn_def_bank" => "jrn_def_bank" , "jrn_def_num_op" => "jrn_def_num_op" , "jrn_def_description" => "jrn_def_description" + , "currency_id"=>"currency_id" ); function __construct(& $p_cn, $p_id=-1) @@ -213,6 +214,7 @@ class Jrn_Def_sql ,jrn_def_bank ,jrn_def_num_op ,jrn_def_description +,currency_id ) values ($1 ,$2 ,$3 @@ -228,6 +230,7 @@ class Jrn_Def_sql ,$13 ,$14 ,$15 +,$16 ) returning jrn_def_id"; $this->jrn_def_id = $this->db->get_value( @@ -246,6 +249,7 @@ class Jrn_Def_sql , $this->jrn_def_bank , $this->jrn_def_num_op , strip_tags($this->jrn_def_description) + , $this->currency_id ) ); } @@ -284,25 +288,29 @@ jrn_enable) values ($1 ,$15 ,$16 ,1 +,$17 ) returning jrn_def_id"; $this->jrn_def_id = $this->db->get_value( - $sql, array($this->jrn_def_name - , $this->jrn_def_class_deb - , $this->jrn_def_class_cred - , $this->jrn_def_fiche_deb - , $this->jrn_def_fiche_cred - , $this->jrn_deb_max_line - , $this->jrn_cred_max_line - , $this->jrn_def_ech - , $this->jrn_def_ech_lib - , $this->jrn_def_type - , $this->jrn_def_code - , $this->jrn_def_pj_pref - , $this->jrn_def_bank - , $this->jrn_def_num_op - , $this->jrn_def_id - , strip_tags($this->jrn_def_description)) + $sql, array( + $this->jrn_def_name // 1 + , $this->jrn_def_class_deb // 2 + , $this->jrn_def_class_cred // 3 + , $this->jrn_def_fiche_deb // 4 + , $this->jrn_def_fiche_cred // 5 + , $this->jrn_deb_max_line // 6 + , $this->jrn_cred_max_line // 7 + , $this->jrn_def_ech // 8 + , $this->jrn_def_ech_lib // 9 + , $this->jrn_def_type // 10 + , $this->jrn_def_code // 11 + , $this->jrn_def_pj_pref // 12 + , $this->jrn_def_bank // 13 + , $this->jrn_def_num_op // 14 + , $this->jrn_def_id // 15 + , strip_tags($this->jrn_def_description)) // 16 + , $this->currency_id // 17 + ); } } @@ -328,6 +336,7 @@ jrn_enable) values ($1 ,jrn_def_num_op = $14 ,jrn_def_description = $15 ,jrn_enable=$17 +, currency_id = $18 where jrn_def_id= $16"; $res = $this->db->exec_sql( $sql, array($this->jrn_def_name @@ -347,6 +356,7 @@ jrn_enable) values ($1 , strip_tags($this->jrn_def_description) , $this->jrn_def_id , $this->jrn_enable + , $this->currency_id ) ); } @@ -374,6 +384,7 @@ jrn_enable) values ($1 ,jrn_def_num_op ,jrn_def_description ,jrn_enable +,currency_id from public.jrn_def where jrn_def_id=$1"; /* please adapt */ $res = $this->db->get_array( diff --git a/include/template/param_jrn.php b/include/template/param_jrn.php index 5da5c8808..d3e428205 100644 --- a/include/template/param_jrn.php +++ b/include/template/param_jrn.php @@ -1,7 +1,7 @@ +?>
@@ -128,7 +128,22 @@ echo $str_add_button; input()?> + + + + + +
+ + + input();?> +