noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 102/162: Currency : adapt for bank saldo


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 102/162: Currency : adapt for bank saldo
Date: Sat, 11 Jul 2020 13:23:52 -0400 (EDT)

sparkyx pushed a commit to annotated tag E-4
in repository noalyss.

commit dd8bc6750f9a89dd03897655b3610d4103ea9285
Author: Dany De Bontridder <danydb@noalyss.eu>
AuthorDate: Fri Nov 30 15:19:36 2018 +0100

    Currency : adapt for bank saldo
---
 include/class/acc_ledger_fin.class.php | 11 ++++++--
 include/class/fiche.class.php          | 48 ++++++++++++++++++++++++++++++++--
 include/compta_fin_saldo.inc.php       | 27 ++++++++++++++++++-
 3 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/include/class/acc_ledger_fin.class.php 
b/include/class/acc_ledger_fin.class.php
index 30206fa..6d3c119 100644
--- a/include/class/acc_ledger_fin.class.php
+++ b/include/class/acc_ledger_fin.class.php
@@ -848,7 +848,7 @@ class Acc_Ledger_Fin extends Acc_Ledger
                                $acc_operation->date = $e_date;
                                $sposte = $fBank->strAttribut(ATTR_DEF_ACCOUNT);
 
-                               // if 2 accounts
+                               // if 2 accounts, use the first one if DEB 
otherwise the second one
                                if (strpos($sposte, ',') != 0)
                                {
                                        $array = explode(',', $sposte);
@@ -869,7 +869,14 @@ class Acc_Ledger_Fin extends Acc_Ledger
                                $acc_operation->type = 'd';
                                $acc_operation->periode = $tperiode;
                                $acc_operation->qcode = $e_bank_account;
-                               $acc_operation->insert_jrnx();
+                               $j_id=$acc_operation->insert_jrnx();
+                                
+                                $operation_currency = new 
Operation_currency_SQL($this->db);
+                                $operation_currency->oc_amount=$amount_input;
+                                $operation_currency->oc_vat_amount=0;
+                                
$operation_currency->oc_price_unit=$amount_input;
+                                $operation_currency->j_id=$j_id;
+                                $operation_currency->insert();
 
 
                                if (sql_string(${"e_other$i" . "_comment"}) == 
null)
diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php
index 00d1a00..8cf6ac6 100644
--- a/include/class/fiche.class.php
+++ b/include/class/fiche.class.php
@@ -29,6 +29,7 @@ require_once NOALYSS_INCLUDE.'/class/fiche_def.class.php';
 require_once NOALYSS_INCLUDE.'/lib/iposte.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_operation.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_account.class.php';
+require_once NOALYSS_INCLUDE.'/class/acc_ledger_fin.class.php';
 
 /*! \file
  * \brief define Class fiche, this class are using
@@ -77,7 +78,7 @@ class Fiche
         global $g_user;
       $sql_ledger=$g_user->get_ledger_sql('FIN',3);
       $avail=$this->cn->get_array("select jrn_def_id,jrn_def_name,"
-              . "jrn_def_bank,jrn_def_description from jrn_def where 
jrn_def_type='FIN' and $sql_ledger
+              . "jrn_def_bank,jrn_def_description,currency_id from jrn_def 
where jrn_def_type='FIN' and $sql_ledger
                             order by jrn_def_name");
 
       if ( count($avail) == 0 )
@@ -1664,7 +1665,32 @@ class Fiche
                      'solde'=>abs($r['sum_deb']-$r['sum_cred']));
     }
     /**
-     *get the bank balance with receipt or not
+     * Get the sum in Currency
+     * @param string $p_cond
+     * @return type
+     * @throws Exception
+     */
+    function get_bk_balance_currency($p_cond="")
+    {
+        if ( $this->id == 0 ) throw  new Exception('fiche->id est nul');
+
+        if ( $p_cond != "") $p_cond=" and ".$p_cond;
+        
+        $sql = "
+              select sum(oc_amount) 
+              from 
+              Operation_currency
+              join jrnx using (j_id) 
+              join jrn on (jr_grpt_id=j_grpt)  
+              where f_id=$1
+                $p_cond";
+        $val=$this->cn->get_value($sql,[$this->id]);
+        
+        return $val;
+                
+    }
+    /**
+     *get the bank balance with receipt or not in Euro
      *
      */
     function get_bk_balance($p_cond="")
@@ -2238,6 +2264,24 @@ class Fiche
     function filter_history($p_table_id) {
         return _('Cherche').' '.HtmlInput::filter_table($p_table_id, 
'0,1,2,3,4,5,6,7,8,9,10', 1);
     }
+    /**
+     * Returns the Acc_Ledger_Fin ledger for which the card is the default 
bank account or null if no ledger is found.
+     */
+    function get_bank_ledger()
+    {
+        try {
+            $id=$this->cn->get_value("select jrn_def_id from jrn_def where 
jrn_def_bank = $1 ",[$this->id]);
+            if ($id == "") { return NULL;}
+            $ledger=new Acc_Ledger_Fin($this->cn,$id);
+            $ledger->load();
+            return $ledger;
+        }        
+        catch (Exception $e) {
+            record_log(__FILE__.":".__LINE__);
+            record_log($e->getMessage());
+            throw $e;
+        }
+    }
 }
 
 ?>
diff --git a/include/compta_fin_saldo.inc.php b/include/compta_fin_saldo.inc.php
index 42b6e9b..520b9f4 100644
--- a/include/compta_fin_saldo.inc.php
+++ b/include/compta_fin_saldo.inc.php
@@ -48,6 +48,8 @@ echo tr(th('Quick Code', ' class=" sorttable_sorted"',
         .th(_('Compte en banque'), ' style="text-align:left"')
         .th(_('Journal'), ' style="text-align:center"')
         .th(_('Description'), ' style="text-align:center"')
+        .th(_("Devise"))
+        .th(_("Montant Devise"))
         .th(_('solde opération'),
                 ' style="text-align:right" class="sorttable_numeric"')
         .th(_('solde extrait/relevé'),
@@ -74,17 +76,36 @@ for ($i=0; $i<count($array); $i++)
         echo '</tr>';
         continue;
     }
+    
+    
     // get the saldo
     $m=$array[$i]->get_solde_detail($filter_year);
 
-    $solde=$m['debit']-$m['credit'];
+    $solde=bcsub($m['debit'],$m['credit']);
 
     // print the result if the saldo is not equal to 0
     if ($m['debit']!=0.0||$m['credit']!=0.0)
     {
+        // Get it in currency
+        $ledger=$array[$i]->get_bank_ledger();
+        $currency_code=$ledger->get_currency()->get_code();
+        
+        /**
+         * if we don't use the defaut currency
+         */
+        if ( $ledger->get_currency()->get_id() == 0)
+        {
+            $currency_amount=$solde;    
+        }
+        else
+        {
+            $currency_amount=$array[$i]->get_bk_balance_currency();
+            
+        }
         /*  get saldo for not reconcilied operations  */
         $saldo_not_reconcilied=$array[$i]->get_bk_balance($filter_year." and 
(trim(jr_pj_number) ='' or jr_pj_number is null)");
 
+
         /*  get saldo for reconcilied operation  */
 
         $saldo_reconcilied=$array[$i]->get_bk_balance($filter_year." and ( 
trim(jr_pj_number) != '' and jr_pj_number is not null)");
@@ -110,6 +131,10 @@ for ($i=0; $i<count($array); $i++)
         "</TD>".
         td(h($array[$i]->ledger_name)).
         td(h($array[$i]->ledger_description)).
+        td($currency_code).
+        '<TD class="sorttable_numeric" 
sorttable_customkey="'.$currency_amount.'"  style="text-align:right">'.
+                nbm($currency_amount).
+                '</td>'.
         '<TD class="sorttable_numeric" sorttable_customkey="'.$solde.'"  
style="text-align:right">'.
         nbm($solde).
         "</TD>".



reply via email to

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