noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 26/32: Fix bug : for new TVA id not taken int


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 26/32: Fix bug : for new TVA id not taken into account but auto-computed
Date: Thu, 5 Jan 2023 14:18:32 -0500 (EST)

sparkyx pushed a commit to branch devel
in repository noalyss.

commit a76d9d1162bb185a3757ab80bf9e49084d65492a
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Tue Dec 27 16:41:22 2022 +0100

    Fix bug : for new TVA id not taken into account but auto-computed
---
 include/class/tva_rate_mtable.class.php | 17 ++++++++++-------
 include/lib/data_sql.class.php          |  2 +-
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/include/class/tva_rate_mtable.class.php 
b/include/class/tva_rate_mtable.class.php
index cc22b1233..b1e5ab62f 100644
--- a/include/class/tva_rate_mtable.class.php
+++ b/include/class/tva_rate_mtable.class.php
@@ -220,7 +220,8 @@ class Tva_Rate_MTable extends Manage_Table_SQL
             }
         }
         $new_tva_id=$this->table->tva_id;
-        $tva_rate=new Tva_rate_SQL($cn, $this->previous_id);
+        $tva_rate=new Tva_rate_SQL($cn);
+        $tva_rate->setp("tva_id",$new_tva_id);
         $tva_rate->setp("tva_rate", $this->table->tva_rate);
         $tva_rate->setp("tva_label", $this->table->tva_label);
         $tva_rate->setp("tva_comment", $this->table->tva_comment);
@@ -232,13 +233,15 @@ class Tva_Rate_MTable extends Manage_Table_SQL
         $tva_rate->setp("tva_poste", $tva_purchase.",".$tva_sale);
         $tva_rate->setp("tva_payment_sale", $this->table->tva_payment_sale);
         $tva_rate->setp("tva_payment_purchase", 
$this->table->tva_payment_purchase);
-        $tva_rate->save();
-        if ($this->previous_id != $new_tva_id) {
+        if ( $this->previous_id == -1 ) {
+            $tva_rate->insert();
+        } else {
+            $tva_rate->update();
+        }
+        if ( $this->previous_id != - 1 && $this->previous_id != $new_tva_id) {
             $cn->exec_sql("update tva_rate set tva_id = $1 where tva_id = 
$2",[$new_tva_id,$this->previous_id]);
-            $tva_rate->setp("tva_id",$new_tva_id);
-        }else
-            $this->table->setp("tva_id",$tva_rate->getp("tva_id"));
-        $this->table->load();
+            $this->table->setp("tva_id",$new_tva_id);
+        }else        $this->table->setp("tva_id",$tva_rate->getp("tva_id"));
 
     }
     /**
diff --git a/include/lib/data_sql.class.php b/include/lib/data_sql.class.php
index e79860cf2..0333a9696 100644
--- a/include/lib/data_sql.class.php
+++ b/include/lib/data_sql.class.php
@@ -112,7 +112,7 @@ abstract class Data_SQL
             $this->$key=null;
         }
         $this->$pk=$p_id;
-        /* load it */
+        /* load it , if the pk id doesn't exist, it will be turned into -1  */
         if ($p_id != -1 )$this->load();
         if ( empty($this->date_format) )         
$this->date_format="DD.MM.YYYY";
     }



reply via email to

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