[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 85/218: Currency : financial ledger can be se
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 85/218: Currency : financial ledger can be set to a specific currency |
Date: |
Thu, 12 Sep 2019 15:58:45 -0400 (EDT) |
sparkyx pushed a commit to branch entreprise
in repository noalyss.
commit 7eb4644cf0a6359b86617ce2adf0989459a64f53
Author: Dany De Bontridder <address@hidden>
Date: Sat Oct 20 14:05:13 2018 +0200
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 10eaae9..51adc98 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,10 +2278,28 @@ 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
*
* @param type $array
@@ -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 4840fbc..818248f 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 5da5c88..d3e4282 100644
--- a/include/template/param_jrn.php
+++ b/include/template/param_jrn.php
@@ -1,7 +1,7 @@
<?php
//This file is part of NOALYSS and is under GPL
//see licence.txt
-?><TABLE style="width: auto">
+?><TABLE style="width: auto" class="nowrap">
<TR>
<TD><?php echo _('Nom journal')?> </TD>
@@ -128,7 +128,22 @@ echo $str_add_button;
<?=$actif->input()?>
</td>
<?php endif; ?>
+<?php
+ // if the ledger is financial and has no operation let choose the currency
+ if ( $new == 1 || $type == 'FIN'):
+?>
+<tr id="type_fin3">
+ <td>
+ <?php echo _("Devise")?>
+ </td>
+ <td>
+ <?php echo $default_currency->input();?>
+ </td>
+</tr>
+<?php
+endif;
+?>
</TABLE>
<hr>
<?php
@@ -363,6 +378,7 @@ echo $str_add_button;
$('type_ods').style.display='none';
$('type_fin').style.display='none';
$('type_fin2').style.display='none';
+ $('type_fin3').style.display='none';
}
function show_ledger_div()
{
@@ -374,6 +390,7 @@ echo $str_add_button;
hide_row();
$('type_fin').style.display='table-row';
$('type_fin2').style.display='table-row';
+ $('type_fin3').style.display='table-row';
break;
case 'ODS':
hide_row();
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 153179a..9a554f1 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -19,4 +19,12 @@ EXCEPTION WHEN others THEN
RETURN FALSE;
END;
$$
-LANGUAGE plpgsql;
\ No newline at end of file
+LANGUAGE plpgsql;
+
+ALTER TABLE public.jrn_def ADD currency_id int NULL;
+ALTER TABLE public.jrn_def ALTER COLUMN currency_id SET DEFAULT 0;
+update public.jrn_def set currency_id = 0 ;
+ALTER TABLE public.jrn_def ALTER COLUMN currency_id SET NOT NULL;
+ALTER TABLE public.jrn_def ADD CONSTRAINT jrn_def_currency_fk FOREIGN KEY
(currency_id) REFERENCES public.currency(id);
+
+COMMENT ON COLUMN public.jrn_def.currency_id IS 'Default currency for
financial ledger';
- [Noalyss-commit] [noalyss] 87/218: translate, (continued)
- [Noalyss-commit] [noalyss] 87/218: translate, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 82/218: adapt to 7.2 , error with count, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 96/218: Merge branch 'master' into r700-currency, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 73/218: Merge branch 'r700-currency' of gitlab.noalyss.eu:noalyss/noalyss into r700-currency, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 74/218: Merge branch 'r700-currency' of gitlab.noalyss.eu:noalyss/noalyss into r700-currency, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 76/218: Bug : cannot set group, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 69/218: Create lib for Tabs, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 77/218: Manage_Table : issue with the type select, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 80/218: Improve debug info, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 88/218: FIN : cosmetic : bug due the currency feature in the input there are 2 supplementary rows for total in EUR and CURRENCY. Those rows don't exist for FIN, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 85/218: Currency : financial ledger can be set to a specific currency,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 102/218: Version DB 131, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 101/218: Currency : SQL quant_fin is adapted, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 103/218: reverse for quant_fin, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 100/218: Currency : financial use the rate depending of the operation date, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 94/218: acc_ledger_fin : cosmetic : input, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 99/218: Modify quant_fin , we add a column j_id to have a fk to jrnx and operation_currency, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 108/218: acc_ledger_fin . translation, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 111/218: Currency : sales in listing mode, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 106/218: Currency : adapt for bank saldo, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 112/218: currency : sale extended html , csv, Dany De Bontridder, 2019/09/12