[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 95/218: currency : adapt for FIN
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 95/218: currency : adapt for FIN |
Date: |
Thu, 12 Sep 2019 15:58:47 -0400 (EDT) |
sparkyx pushed a commit to branch entreprise
in repository noalyss.
commit fc4b24f9fd673a017d1f63b8ba9001542897537c
Author: Dany De Bontridder <address@hidden>
Date: Tue Nov 27 17:30:09 2018 +0100
currency : adapt for FIN
---
include/class/acc_ledger.class.php | 34 ++++++++++-------
include/class/acc_ledger_fin.class.php | 67 ++++++++++++++++++++++++----------
include/compta_fin.inc.php | 26 +++++++------
include/template/form_ledger_fin.php | 60 ++++++++++++++++++++++--------
4 files changed, 128 insertions(+), 59 deletions(-)
diff --git a/include/class/acc_ledger.class.php
b/include/class/acc_ledger.class.php
index 35380e9..b0dbeba 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -61,15 +61,13 @@ require_once NOALYSS_INCLUDE.'/class/pre_op_ods.class.php';
class Acc_Ledger extends jrn_def_sql
{
- var $id; /* * < jrn_def.jrn_def_id */
- var $name; /* * < jrn_def.jrn_def_name */
- var $db; /* * < database connextion */
- var $row; /* * < row of the ledger */
- var $type; /* * < type of the ledger ACH ODS FIN
- VEN or GL */
- var $nb; /* * < default number of rows by
- default 10 */
-
+ var $id; /**< jrn_def.jrn_def_id */
+ var $name; /**< jrn_def.jrn_def_name */
+ var $db; /**< database connextion */
+ var $row; /**< row of the ledger */
+ var $type; /**< type of the ledger ACH ODS FIN VEN or GL */
+ var $nb; /**< default number of rows by default 10 */
+ var $currency_id;
/**
* @param $p_cn database connexion
* @param $p_id jrn.jrn_def_id
@@ -82,9 +80,19 @@ class Acc_Ledger extends jrn_def_sql
$this->db=$p_cn;
$this->row=null;
$this->nb=MAX_ARTICLE;
- $this->currency_id=0;
+ $this->currency_id=$this->set_currency_id();
+ }
+ /**
+ * retrieve currency_id from database
+ */
+ function set_currency_id()
+ {
+ $this->db->get_value("select currency_id from jrn_def where
jrn_def_id=$1",
+ [$this->id]);
+ if ( $this->currency_id == "") {
+ $this->currency_id=0;
+ }
}
-
function get_last_pj()
{
if (isNumber($this->id)==0)
@@ -2938,8 +2946,8 @@ class Acc_Ledger extends jrn_def_sql
*/
function get_currency()
{
- $cr_iso_code=$this->db->get_value("select cr_code_iso from
public.currency where id=$1",[$this->currency_id]);
- return $cr_iso_code;
+ $cr=new Acc_Currency($this->db,$this->currency_id);
+ return $cr;
}
}
diff --git a/include/class/acc_ledger_fin.class.php
b/include/class/acc_ledger_fin.class.php
index bff5467..74a0427 100644
--- a/include/class/acc_ledger_fin.class.php
+++ b/include/class/acc_ledger_fin.class.php
@@ -38,12 +38,12 @@ require_once
NOALYSS_INCLUDE.'/class/acc_reconciliation.class.php';
class Acc_Ledger_Fin extends Acc_Ledger
{
-
+
function __construct($p_cn, $p_init)
{
parent::__construct($p_cn, $p_init);
$this->type = 'FIN';
- }
+ }
/**
* Verify that the data are correct before inserting or confirming
@@ -315,8 +315,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$wLedger->javascript = $add_js;
- $label = " Journal " . Icon_Action::infobulle(2);
- $f_jrn = $label . $wLedger->input();
+ $label_ledger = _("Journal") ." ". Icon_Action::infobulle(2);
// retrieve bank name, code and account from the
jrn_def.jrn_def_bank
@@ -629,12 +628,25 @@ class Acc_Ledger_Fin extends Acc_Ledger
$r.='</TR>';
}
$r.="</TABLE>";
-
+ $acc_currency=$this->get_currency();
+ $cur=$acc_currency->get_code();
+ $cur_rate=$acc_currency->get_rate();
+ $default_currency=new Acc_Currency($this->db , 0);
// saldo
- $r.='<br>'.sprintf(_("Ancien solde = %d"), $solde);
- $new_solde+=$tot_amount;
- $r.='<br>'.sprintf(_("Nouveau solde = %d"),$new_solde);
- $r.='<br>'.sprintf(_("Difference = %d"), $tot_amount);
+ $r.='<br>'.sprintf(_("Ancien solde = %d %s"),$solde, $cur);
+ $new_solde=bcadd($new_solde,$tot_amount);
+ $r.='<br>'.sprintf(_("Nouveau solde = %d %s"),$new_solde,
$cur);
+ if ( $acc_currency->get_id() != 0)
+ {
+
+ $r.='<br>'.sprintf(_("Nouveau solde = %d
%s"),bcmul($new_solde,$cur_rate),$default_currency->get_code());
+ }
+ $r.='<br>'.sprintf(_("Difference = %d %s"), $tot_amount, $cur);
+
+ if ( $acc_currency->get_id() != 0)
+ {
+ $r.='<br>'.sprintf(_("Difference = %d %s"),
bcmul($tot_amount,$cur_rate), $default_currency->get_code());
+ }
// check for upload piece
$file = new IFile();
@@ -742,6 +754,11 @@ class Acc_Ledger_Fin extends Acc_Ledger
$ret.=tr(th('Date').th('n° interne') . th('Quick Code')
. th('Nom') . th('Libellé') . th('Montant', ' style="text-align:right"'));
// Credit = goods
$get_solde=true;
+
+ $acc_currency=new
Acc_Currency($this->db,$this->currency_id);
+ $currency_rate=$acc_currency->get_rate();
+
+ // for each item
for ($i = 0; $i < $nb_item; $i++)
{
// insert it into the database
@@ -770,13 +787,15 @@ class Acc_Ledger_Fin extends Acc_Ledger
}
$fPoste = new Fiche($this->db);
$fPoste->get_by_qcode(${"e_other$i"});
-
- // round it
- ${"e_other$i" . "_amount"} =
round(${"e_other$i" . "_amount"}, 2);
+
+ // convert to EUR if needed and round it
+ $amount_input=${"e_other$i" . "_amount"} =
round(${"e_other$i" . "_amount"}, 2);
+
$amount_eur=bcmul($amount_input,$currency_rate);
- $amount+=${"e_other$i" . "_amount"};
+ $amount=bcadd($amount,$amount_input);
+
// Record a line for the bank
// Compute the j_grpt
$seq = $this->db->get_next_seq('s_grpt');
@@ -800,7 +819,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$acc_operation->poste = $poste_val;
- $acc_operation->amount = ${"e_other$i" .
"_amount"} * (-1);
+ $acc_operation->amount = bcmul($amount_eur,-1);
$acc_operation->grpt = $seq;
$acc_operation->jrn = $p_jrn;
$acc_operation->type = 'd';
@@ -816,6 +835,13 @@ class Acc_Ledger_Fin extends Acc_Ledger
$acc_operation->qcode = ${"e_other" . $i};
$j_id = $acc_operation->insert_jrnx();
+ // -- Insert into Operation Currency
+ $operation_currency = new
Operation_currency_SQL($this->db);
+ $operation_currency->oc_amount=$amount_input;
+
$operation_currency->oc_price_unit=$amount_input;
+ $operation_currency->j_id=$j_id;
+ $operation_currency->insert();
+
$acc_operation = new Acc_Operation($this->db);
$acc_operation->date = $e_date;
$sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
@@ -835,7 +861,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
}
$acc_operation->poste = $poste_val;
- $acc_operation->amount = ${"e_other$i" .
"_amount"};
+ $acc_operation->amount = $amount_eur;
$acc_operation->grpt = $seq;
$acc_operation->jrn = $p_jrn;
$acc_operation->type = 'd';
@@ -858,7 +884,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$acc_operation = new Acc_Operation($this->db);
$acc_operation->jrn = $p_jrn;
- $acc_operation->amount = abs(${"e_other$i" .
"_amount"});
+ $acc_operation->amount = abs($amount_eur);
$acc_operation->date = $e_date;
$acc_operation->desc = $comment;
$acc_operation->grpt = $seq;
@@ -878,7 +904,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
$this->db->exec_sql('update jrn set
jr_pj_number=$1 where jr_id=$2', array($acc_operation->pj, $jr_id));
$internal = $this->compute_internal_code($seq);
-
+
if (trim(${"e_concerned" . $i}) != "")
{
if (strpos(${"e_concerned" . $i}, ',')
!= 0)
@@ -931,12 +957,13 @@ class Acc_Ledger_Fin extends Acc_Ledger
/**
* save also into quant_fin
*/
- $this->insert_quant_fin($fBank->id, $jr_id,
$fPoste->id, ${"e_other$i" . "_amount"});
+ $this->insert_quant_fin($fBank->id, $jr_id,
$fPoste->id, $amount_eur);
if ($g_parameter->MY_ANALYTIC != "nu")
{
// for each item, insert into
operation_analytique */
$op = new Anc_Operation($this->db);
+ $op->set_currency_rate($currency_rate);
$op->oa_group =
$this->db->get_next_seq("s_oa_group"); /* for analytic */
$op->j_id = $j_id;
$op->oa_date = $e_date;
@@ -991,9 +1018,9 @@ class Acc_Ledger_Fin extends Acc_Ledger
}
$this->db->commit();
$r = "";
- $r.="<br>Ancien solde " . nbm($solde);
+ $r.=sprintf("<br>"._("Ancien solde %s %s"),
nbm($solde),$acc_currency->get_code());
$new_solde = bcadd($new_solde, $amount);
- $r.="<br>Nouveau solde " . nbm($new_solde);
+ $r.=sprintf("<br>"._("Nouveau solde %s %s"),
nbm($new_solde),$acc_currency->get_code());
$ret.=$r;
return $ret;
}
diff --git a/include/compta_fin.inc.php b/include/compta_fin.inc.php
index 54fe66c..2dce3f6 100644
--- a/include/compta_fin.inc.php
+++ b/include/compta_fin.inc.php
@@ -33,26 +33,30 @@ $gDossier=dossier::id();
$cn=Dossier::connect();
$menu_action="?ledger_type=fin&ac=".$_REQUEST['ac']."&".dossier::get();
-$Ledger=new Acc_Ledger_Fin($cn,0);
+$http=new HttpInput();
+$ledger_id=$http->request("p_jrn","number",0);
//--------------------------------------------------------------------------------
// Encode a new financial operation
//--------------------------------------------------------------------------------
-if ( isset($_REQUEST['p_jrn']))
- $Ledger->id=$_REQUEST['p_jrn'];
-else
+if ( $ledger_id == 0)
{
- $def_ledger=$Ledger->get_first('fin');
- if ( empty ($def_ledger))
- {
- exit('Pas de journal disponible');
- }
- $Ledger->id=$def_ledger['jrn_def_id'];
+ $Ledger=new Acc_Ledger_Fin($cn,0);
+ $def_ledger=$Ledger->get_first('fin');
+ if ( empty ($def_ledger))
+ {
+ exit('Pas de journal disponible');
+ }
+ $ledger_id=$def_ledger['jrn_def_id'];
}
+
+$Ledger=new Acc_Ledger_Fin($cn,$ledger_id);
+$Ledger->load();
+
$jrn_priv=$g_user->get_ledger_access($Ledger->id);
// Check privilege
-if ( isset($_REQUEST['p_jrn']) && ( $jrn_priv == 'X'))
+if ( $jrn_priv == 'X')
{
NoAccess();
exit -1;
diff --git a/include/template/form_ledger_fin.php
b/include/template/form_ledger_fin.php
index 7a0d7fd..020756f 100644
--- a/include/template/form_ledger_fin.php
+++ b/include/template/form_ledger_fin.php
@@ -6,11 +6,6 @@
<h2 id="jrn_name"> <?php echo $this->get_name()?></h2>
</div>
<legend><?php echo $f_legend ?> </legend>
-<p>
-
-<?php echo $f_jrn?>
- <?php echo _('Banque')?><?php echo $f_bank ?>
-
<?php
$wchdate=new ISelect('chdate');
$wchdate->value=array(
@@ -20,12 +15,51 @@
$wchdate->selected=(isset($chdate))?$chdate:1;
$wchdate->javascript='onchange="show_fin_chdate(\'chdate\');"';
?>
- <br>
-<?php echo _("Style de date")." ".$wchdate->input();?>
- <br>
-<span id="chdate_ext">
- <?php echo _('Date').' '.$f_date ?>
-</span>
+<table>
+ <tr>
+ <td>
+ <?php echo $label_ledger; ?>
+ </td>
+ <td>
+ <?php echo $wLedger->input()?>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <?php echo _('Banque')?>
+ </td>
+ <td>
+ <?php echo $f_bank ?>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <?php echo _("Style de date"); ?>
+
+ </td>
+ <td>
+ <?php echo $wchdate->input();?>
+
+ </td>
+ </tr>
+ <tr id="chdate_ext">
+ <td>
+ <?php echo _('Date'); ?>
+
+ </td>
+ <td>
+ <?php echo $f_date ?>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <?php echo _("Devise")?>
+ </td>
+ <td id="ledger_currency">
+ <?php echo $this->get_currency()->get_code();?>
+ </td>
+ </tr>
+</table>
</p>
<?php if ( $f_period <> "") :?>
@@ -35,10 +69,6 @@
</p>
<?php endif;?>
- <?php echo _("Devise")?>
- <span id="ledger_currency">
- <?php echo $this->get_currency();?>
- </span>
</fieldset>
<fieldset>
- [Noalyss-commit] [noalyss] 216/218: Version set to 7.1, (continued)
- [Noalyss-commit] [noalyss] 216/218: Version set to 7.1, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 202/218: Merge branch 'dev7109' into entreprise, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 162/218: Currency - fix view, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 178/218: Mantis #1665: Pouvoir modifier l'ordre dans les listing de compta analytique, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 78/218: Bug : ajax fails if wait_box does not exist, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 105/218: Background color, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 92/218: Merge branch 'master' into r700-currency, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 98/218: Fin currency : detail operation show currency , rate and amount, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 97/218: Fin : currency , add missing info into Operation_Currency, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 113/218: change background, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 95/218: currency : adapt for FIN,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 122/218: Currency : display correctly the saldo at the end / beginning operation, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 136/218: Translation, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 115/218: Currency : ledger printing for FIN + detail operation, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 143/218: Currency : precision 6, display default currency , protect used currency against delete, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 149/218: Currency : purchase, save all detail also in currency, fix problem with the advance payment, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 151/218: Task #1660 : place the button for the inventory on the top, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 157/218: Merge branch 'r700-currency' of gitlab.noalyss.eu:noalyss/noalyss into r700-currency, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 75/218: Improve waiting box, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 171/218: Mantis #0001666: Export CSV depuis histo ne filtre pas par journal, Dany De Bontridder, 2019/09/12
- [Noalyss-commit] [noalyss] 175/218: mantis #1690: Bug : impossible d'utiliser < dans Inplace_Edit Use base64_decode to protect the string in serialize, Dany De Bontridder, 2019/09/12