noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 01/02: Correct Bug : receipt not computed wit


From: dwm
Subject: [Noalyss-commit] [noalyss] 01/02: Correct Bug : receipt not computed with extourne
Date: Sat, 9 Mar 2024 07:42:44 -0500 (EST)

sparkyx pushed a commit to branch unstable
in repository noalyss.

commit 4e8ec132f3e5b760481a47d19914ef3633234e13
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Mar 9 13:23:28 2024 +0100

    Correct Bug : receipt not computed with extourne
---
 include/class/acc_ledger.class.php         | 21 ++++++++++++++++-----
 include/class/acc_operation.class.php      | 13 +++++++++----
 unit-test/include/class/acc_ledgerTest.php |  5 +++++
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/include/class/acc_ledger.class.php 
b/include/class/acc_ledger.class.php
index 69e22667c..b715c242b 100644
--- a/include/class/acc_ledger.class.php
+++ b/include/class/acc_ledger.class.php
@@ -353,6 +353,7 @@ class Acc_Ledger  extends jrn_def_sql
 
 
             }
+            $old_receipt=$this->db->get_row("select jr_pj_number,jr_def_id 
from jrn where jr_id=$1",[$this->jr_id]);
             $sql="insert into jrn (
               jr_id,
               jr_def_id,
@@ -373,14 +374,24 @@ class Acc_Ledger  extends jrn_def_sql
               $5, true,'EXT',currency_id,currency_rate,currency_rate_ref
               from
               jrn
-              where   jr_id=$6";
-            $Res=$this->db->exec_sql($sql,
+              where   jr_id=$6 returning jr_id";
+            try {
+
+                $reverse_id=$this->db->get_value($sql,
                     array($seq, $p_date, $grp_new, $p_internal, $per->p_id, 
$this->jr_id,$p_label));
+                $reverse_accOp=new Acc_Operation($this->db);
+                $reverse_accOp->set_id($reverse_id);
+                $reverse_accOp->pj=$old_receipt['jr_pj_number'];
+                $reverse_accOp->jrn=$old_receipt['jr_def_id'];
+                $reverse_accOp->set_pj();
             // Check return code
-            if ($Res==false)
-            {
-                throw (new Exception(__FILE__.__LINE__."SQL ERROR [ $sql ]"));
+            } catch (\Exception $e){
+                throw new \Exception('Echec extourne');
+
             }
+
+
+
             // reverse in QUANT_FIN table
             $Res=$this->db->exec_sql("  INSERT INTO quant_fin(
                                  qf_bank,  qf_other, qf_amount,jr_id,j_id)
diff --git a/include/class/acc_operation.class.php 
b/include/class/acc_operation.class.php
index 73c3d1a1c..f2b144f30 100644
--- a/include/class/acc_operation.class.php
+++ b/include/class/acc_operation.class.php
@@ -266,15 +266,19 @@ EOF;
     {
         if ( noalyss_strlentrim($this->pj) == 0 )
         {
+            echo __LINE__."debug {$this->pj} est vide";
             $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
             $this->db->exec_sql($sql,array(null,$this->jr_id));
             return '';
         }
         /* is pj uniq ? */
-        if ( $this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 
and jr_def_id=$2",
-                                  array($this->pj,$this->jrn)
+        if ( $this->db->count_sql("select jr_id from jrn
+             where jr_pj_number=$1 and jr_def_id=$2
+                and jr_id !=$3",
+                                  array($this->pj,$this->jrn,$this->jr_id)
                                  ) == 0 )
         {
+            echo __LINE__."debug {$this->pj} est unique";
             $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
             $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
         }
@@ -300,8 +304,9 @@ EOF;
                 $this->pj=$pref.$seq;
 
                 /* check if the new pj numb exist */
-                $c=$this->db->count_sql("select jr_id from jrn where 
jr_pj_number=$1 and jr_def_id=$2",
-                                        array($this->pj,$this->jrn)
+                $c=$this->db->count_sql("select jr_id from jrn where 
jr_pj_number=$1 and jr_def_id=$2
+                                            and jr_id !=$3",
+                                        
array($this->pj,$this->jrn,$this->jr_id)
                                        );
                 if ( $c == 0 )
                 {
diff --git a/unit-test/include/class/acc_ledgerTest.php 
b/unit-test/include/class/acc_ledgerTest.php
index be2aa1ce6..a236e316a 100644
--- a/unit-test/include/class/acc_ledgerTest.php
+++ b/unit-test/include/class/acc_ledgerTest.php
@@ -198,6 +198,11 @@ class Acc_LedgerTest extends TestCase
         $this->object->reverse($date,'unit test'.$date);
         $check=$g_connection->get_value("select jr_id from jrn where 
jr_comment=$1",["unit test".$date]);
         $this->assertFalse(empty($check),"NOT REVERSED" );
+        // check that the receipt number is correct
+        $receipt=$g_connection->get_value("select jr_pj_number from jrn where 
jr_id=$1",[$check]);
+        $this->assertFalse(empty($receipt)," no receipt number computed");
+        $orig_receipt=$g_connection->get_value("select jr_pj_number from jrn 
where jr_id=$1",[$this->object->jr_id]);
+        $this->assertNotEquals($receipt, $orig_receipt,"Wrong Receipt number 
");
         $this->object->jr_id=$check;
         $this->object->delete();
     }



reply via email to

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