noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 07/30: Add __toString function for debugging


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 07/30: Add __toString function for debugging purpose Improve DBG tools: print out or return a string
Date: Sat, 3 Dec 2022 08:35:07 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 0fbc7bfdfaee1dbf5ba43756955e8ab98f018ac8
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Nov 19 18:27:45 2022 +0100

    Add __toString  function for debugging purpose
    Improve DBG tools: print out or return a string
---
 include/class/acc_currency.class.php  |   5 ++
 include/class/acc_operation.class.php |  22 +++++++
 include/class/anc_operation.class.php | 108 +++++++++++++++++++++++++++++++---
 include/class/periode.class.php       |  15 +++++
 include/lib/dbg.php                   |  36 +++++++-----
 5 files changed, 162 insertions(+), 24 deletions(-)

diff --git a/include/class/acc_currency.class.php 
b/include/class/acc_currency.class.php
index bd58afe45..e1ebf3a62 100644
--- a/include/class/acc_currency.class.php
+++ b/include/class/acc_currency.class.php
@@ -42,6 +42,11 @@ class Acc_Currency
         $this->currency=new V_Currency_Last_Value_SQL($p_cn, $p_id);
     }
 
+    public function __toString(): string
+    {
+        return "Acc_Currency [".$this->currency->__toString()."]";
+    }
+
     /**
      * Retrieve a V_Currency_Last_Value_SQL thanks its iso_code
      * @param string $p_iso
diff --git a/include/class/acc_operation.class.php 
b/include/class/acc_operation.class.php
index 676953b9c..07701c5b9 100644
--- a/include/class/acc_operation.class.php
+++ b/include/class/acc_operation.class.php
@@ -66,6 +66,28 @@ class Acc_Operation
         $this->currency_rate_ref=1;
         $this->currency_id=NULL;
     }
+
+    function __toString(): string
+    {
+        $r=<<<EOF
+   Acc_Operation Object 
+     [   
+        db {$this->db} 
+        qcode {$this->qcode}
+        user {$this->user}
+        periode {$this->periode}
+        jr_id {$this->jr_id}
+        jr_optype {$this->jr_optype}
+        amount  {$this->amount}
+        currency_rate {$this->amount}
+        currency_rate_ref {$this->amount}
+        currency_id {$this->amount}
+    ]
+EOF;
+        return $r;
+        
+    }
+
     /**
      *@brief retrieve the grpt_id from jrn for a jr_id
      *@return jrn.jr_grpt_id or an empty string if not found
diff --git a/include/class/anc_operation.class.php 
b/include/class/anc_operation.class.php
index 48d574ba1..6bd88313f 100644
--- a/include/class/anc_operation.class.php
+++ b/include/class/anc_operation.class.php
@@ -58,6 +58,29 @@ class Anc_Operation
         return $this->currency_rate;
     }
 
+    public function __toString(): string
+    {
+     $r=<<<EOF
+Object Anc_Operation [
+     \$row=>$this->row,        
+     \$list=> $this->list,     
+     \$id  => $this->id,       
+     \$po_id => $this->po_id,
+     \$oa_amount $this->oa_amount,
+     \$oa_description => $this->oa_description,        
+     \$oa_debit => $this->oa_debit,    
+     \$j_id => $this->j_id,    
+     \$oa_group => $this->oa_group,  
+     \$oa_date => $this->oa_date,      
+     \$pa_id => $this->pa_id,
+     \$card => $this->card , 
+    private \$currency_rate => $this->currency_rate,
+    ]    
+EOF;
+     return $r;
+
+    }
+
     public function set_currency_rate($currency_rate)
     {
         $this->currency_rate=$currency_rate;
@@ -778,20 +801,87 @@ class Anc_Operation
      * \param $p_item if the item nb for each item (purchase or selling
      *  merchandise)
      * \param $p_array structure
-     * \verbatim
-      nb_tA A is the number of the item it contains the number of
+
+      nb_tx x is the number of the item it contains the number of
               rows of CA for this card
-      valAlR amount for the CA (item A row R)
+      <h1>val double array :   amount for the CA row ACC => sub row ANC </h1>
+            here Operation 0 has 2 row for a total of 10.31 and 1
+            here Operation 1 has 1 row for a total of 430
+    \verbatim
+    [val] => Array
+        (
+            [0] => Array
+                (
+                    [0] => 10.31
+                    [1] => 1
+                )
+
+            [1] => Array
+                (
+                    [0] => 430
+                )
+
+        )
+\endverbatim
+     <h1>amount_tx the amount for each row</h1>
+    It is the amount to split per accounting, it is possible that it is 
different from the sum of the given amount (<i>
+    see val</i>) per row
+    \verbatim
+      [amount_t0] => 11.31
+      [amount_t1] => 430
+    \endverbatim
       ta_AoCrow_R contains the value of the pa_id and po_id for this
                   row with the form pa_id_po_id %d_%d
+     <h1>  hplan = Double array operation</h1>
+   <p> Double array operation => all the amount but in linear form</p>
+
+    <p>Example if the amount of the operation 0 is splitted in 2 rows and 2 
cols (because 2 analytic plan, means 2 cols)
+     we have an array of 4 values for operation 0, it gives the 
poste_analytique.po_id (from DB).</p>
+    <p> Here is the operation 0
+    (one row of the accounting) is splitted in  po_id = 1 (pa_id see in tables 
or array pa_id) and po_id=5 (second pa_id)
+    for 10.31 (<i>see array val</i>) and for 1 is set for po_id 1 and 4, p
+    </p>
+    \verbatim
+        [hplan] => Array
+        (
+            [0] => Array
+                (
+                    [0] => 1
+                    [1] => 5
+                    [2] => 1
+                    [3] => 4
+                )
+
+            [1] => Array
+                (
+                    [0] => 1
+                    [1] => 6
+                )
+
+        )
+    \endverbatim
+
+     <h1>   pa_id </h1>
+    pa_id array of plan_analytic.pa_id (1 per column), always ordered  by pa_id
+
+    \verbatim
+    [pa_id] => Array
+        (
+            [0] => 1
+            [1] => 2
+        )
+
      *\endverbatim
+     *
      * \attention The idea is one j_id matches several oa_id,
-     *  serveral data are set before the call :
-     *   -j_id
-     *   -oa_debit
-     *   -oa_group
-     *   -oa_date
-     *   -oa_description
+     *  serveral data <b>must be </b>set before the call :
+     *
+     *    <ul><li>  j_id</li>
+     *    <li>oa_debit</li>
+     *    <li>oa_group</li>
+     *    <li>oa_date</li>
+     *    <li>oa_description</li>
+     * </ul>
      *
      */
     function save_form_plan($p_array,$p_item,$p_j_id)
diff --git a/include/class/periode.class.php b/include/class/periode.class.php
index 1e18583b9..d42d5dc41 100644
--- a/include/class/periode.class.php
+++ b/include/class/periode.class.php
@@ -47,6 +47,21 @@ class Periode
         $this->jrn_def_id=0;
     }
 
+    public function __toString(): string
+    {
+      $r=<<<EOF
+Object Periode [
+    \$jrn_def_id=>$jrn_def_id,
+     \$p_id=>$p_id,
+     \$status => $status,
+     \$p_start => $p_start,
+     \$p_end => $p_end,
+] 
+EOF;
+      return $r;
+
+    }
+
     function set_ledger($p_jrn)
     {
         $this->jrn_def_id=$p_jrn;
diff --git a/include/lib/dbg.php b/include/lib/dbg.php
index e17af5121..f71bba927 100644
--- a/include/lib/dbg.php
+++ b/include/lib/dbg.php
@@ -5,39 +5,45 @@ require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 
 class Dbg
 {
-    public static function echo_var($n_level, $msg)
+    public static function echo_var($n_level, $msg,$print=true)
     {
         if (DEBUGNOALYSS > $n_level) {
-            echo '<span 
style="font-size:12px;color:orangered;background-color:lightyellow;">';
+            $r= '<span 
style="font-size:12px;color:orangered;background-color:lightyellow;">';
             $type = gettype($msg);
             if (in_array($type, ["string", "integer", "double"])) {
-                echo $msg;
+                $r.= $msg;
             } else {
 
-                echo "<pre>DBG";
-                var_export($msg);
-                echo '</pre>';
+                $r.= "<pre>DBG";
+                $r.=print_r($msg,true);
+                $r.='</pre>';
             }
-            echo '</span>';
+            $r.='</span>';
+            if ($print) { echo $r;}
+            return $r;
         }
     }
 
-    public static function echo_function($msg)
+    public static function echo_function($msg,$print=true)
     {
         if (DEBUGNOALYSS > 1) {
-            echo '<span 
style="font-size:12px;color:lightgreen;background-color:lightyellow;">';
-            echo "[FILE: $msg]";
+            $r =  '<span 
style="font-size:12px;color:lightgreen;background-color:lightyellow;">';
+            $r.="[FILE: $msg]";
 
-            echo '</span>';
+            $r.= '</span>';
+            if ($print) { echo $r;}
+            return $r;
         }
     }
-    public static function echo_file($msg)
+    public static function echo_file($msg,$print=true)
     {
         if (DEBUGNOALYSS > 1) {
-            echo '<span 
style="font-size:12px;color:brown;background-color:lightyellow;">';
-            echo "[FILE: $msg]";
+            $r =  '<span 
style="font-size:12px;color:brown;background-color:lightyellow;">';
+            $r.="[FILE: $msg]";
 
-            echo '</span>';
+            $r.= '</span>';
+            if ($print) { echo $r;}
+            return $r;
         }
     }
 



reply via email to

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