noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 01/11: NEW #0002395: C0TVA : pouvoir choisir


From: dwm
Subject: [Noalyss-commit] [noalyss] 01/11: NEW #0002395: C0TVA : pouvoir choisir la contrepartie pour l'autoliquidation
Date: Sun, 15 Dec 2024 09:51:24 -0500 (EST)

sparkyx pushed a commit to branch stable
in repository noalyss.

commit 2b2a21f7b6ad37f2a7b4bb49c114a9200beffa16
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Fri Dec 6 17:32:17 2024 +0100

    NEW #0002395: C0TVA : pouvoir choisir la contrepartie pour l'autoliquidation
---
 include/class/acc_ledger_purchase.class.php        |  11 +-
 include/class/acc_ledger_sale.class.php            |   6 +-
 include/class/acc_tva.class.php                    |  11 +-
 include/class/tva_rate_mtable.class.php            |  65 +++++++-
 include/database/tva_rate_sql.class.php            |   2 +
 include/database/v_tva_rate_sql.class.php          |   2 +
 include/lib/message_javascript.php                 |   2 +
 sql/upgrade.sql                                    |  20 +++
 .../include/class/acc_ledger_purchaseTest.php      | 172 +++++++++++++++++++++
 unit-test/include/class/acc_ledger_saleTest.php    | 172 +++++++++++++++++++++
 10 files changed, 452 insertions(+), 11 deletions(-)

diff --git a/include/class/acc_ledger_purchase.class.php 
b/include/class/acc_ledger_purchase.class.php
index ad114e14f..253756d8b 100644
--- a/include/class/acc_ledger_purchase.class.php
+++ b/include/class/acc_ledger_purchase.class.php
@@ -26,7 +26,9 @@ require_once NOALYSS_INCLUDE.'/lib/user_common.php';
 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
 
 
-/*!\brief Handle the ledger of purchase,
+/*!
+ * \class Acc_Ledger_Purchase
+ * \brief Handle the ledger of purchase,
  *
  *
  */
@@ -39,7 +41,8 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
         parent::__construct($p_cn,$p_init);
         $this->payment_operation=-1;
     }
-    /*!\brief verify that the data are correct before inserting or confirming
+    /*!
+    * \brief verify that the data are correct before inserting or confirming
      *\param an array (usually $_POST)
      *\return String
      *\throw Exception if an error occurs
@@ -872,7 +875,9 @@ class  Acc_Ledger_Purchase extends Acc_Ledger
                     
                     if ( $oTva->get_parameter("both_side")==1 )
                     {
-                        $poste_vat=$oTva->get_side('c');
+                        // $x temp variable is the tva_reverse_account and 
will be used to check $poste_vat
+                        $x=$oTva->get_parameter("tva_reverse_account");
+                        $poste_vat =(trim($x??"")=="")? 
$oTva->get_side('c'):$x;
                         if ( $poste_vat == '#')
                         {
                             $poste_vat=$oTva->get_side('d');
diff --git a/include/class/acc_ledger_sale.class.php 
b/include/class/acc_ledger_sale.class.php
index 2f57664fe..f7b662a84 100644
--- a/include/class/acc_ledger_sale.class.php
+++ b/include/class/acc_ledger_sale.class.php
@@ -585,7 +585,11 @@ class Acc_Ledger_Sale extends Acc_Ledger {
                     }
                     // if TVA is on both side, we deduce it immediately
                     if ($oTva->get_parameter("both_side") == 1) {
-                        $poste_vat = $oTva->get_side('d');
+                        // $x temp variable is the tva_reverse_account and 
will be used to check $poste_vat
+                        $x=$oTva->get_parameter("tva_reverse_account");
+
+                        $poste_vat =(trim($x??"")=="")? 
$oTva->get_side('d'):$x;
+                        if ($poste_vat == '#') $poste_vat=$oTva->get_side('c');
                         $cust_amount = bcadd($tot_amount, $tot_tva);
                         $acc_operation = new Acc_Operation($this->db);
                         $acc_operation->date = $e_date;
diff --git a/include/class/acc_tva.class.php b/include/class/acc_tva.class.php
index d9fcf4d28..43a66b9b7 100644
--- a/include/class/acc_tva.class.php
+++ b/include/class/acc_tva.class.php
@@ -41,13 +41,17 @@ class Acc_Tva
                                    "comment"=>"tva_comment",
                                    "account"=>"tva_poste",
                                     "both_side"=>'tva_both_side',
-                                    'tva_code');
+                                    
'tva_reverse_account'=>'tva_reverse_account',
+                                    'tva_code'=>'tva_code');
     public $tva_id,
         $tva_label,
         $tva_rate,
         $tva_comment,
         $tva_poste,
-        $tva_both_side,$tva_code;
+        $tva_both_side,
+        $tva_code,
+        $tva_reverse_account;
+
     private $cn; //!< Database connection
 
     private Tva_Rate_SQL $tva_rate_sql;
@@ -63,6 +67,7 @@ class Acc_Tva
         $this->tva_poste=&$this->tva_rate_sql->tva_poste;
         $this->tva_both_side=&$this->tva_rate_sql->tva_both_side;
         $this->tva_code=&$this->tva_rate_sql->tva_code;
+        $this->tva_reverse_account=&$this->tva_rate_sql->tva_reverse_account;
 
     }
     /**
@@ -90,7 +95,7 @@ class Acc_Tva
             return $this->$idx;
         }
 
-        echo  (__FILE__.":".__LINE__.'Erreur attribut inexistant');
+        echo  (__FILE__.":".__LINE__."AT97:Erreur attribut inexistant 
[$p_string]");
     }
     public function set_parameter($p_string,$p_value)
     {
diff --git a/include/class/tva_rate_mtable.class.php 
b/include/class/tva_rate_mtable.class.php
index 95552c4dd..ac7db2a46 100644
--- a/include/class/tva_rate_mtable.class.php
+++ b/include/class/tva_rate_mtable.class.php
@@ -36,7 +36,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
 
     //!< previous tva_id, used to know if we update or insert,
     private $previous_id;
-
+    private $a_comment; //!< Supplemental explanation
 
     /**
      * 
@@ -52,15 +52,18 @@ class Tva_Rate_MTable extends Manage_Table_SQL
         $this->set_col_label("tva_rate", _("taux"));
         $this->set_col_label("tva_comment", _("Description"));
         $this->set_col_label("tva_both_side", _("Autoliquidation"));
+        $this->set_col_label("tva_reverse_account", _('Poste comptable 
autoliquidation'));
         $this->set_col_label("tva_sale", _("TVA Vente (C)"));
         $this->set_col_label("tva_purchase", _("TVA Achat (D)"));
 
+        $this->set_property_visible('tva_reverse_account', false);
 
         $this->set_col_type("tva_both_side", "select",
                 array(
             ["value"=>0, "label"=>_("Non")],
             ["value"=>1, "label"=>_("Oui")]
         ));
+        $this->set_col_type("tva_reverse_account", 'custom');
         $this->set_property_updatable("tva_id", true);
         $this->set_col_label("tva_payment_purchase",_("Exigible achat"));
         $this->set_col_type("tva_payment_purchase","select",
@@ -76,9 +79,18 @@ class Tva_Rate_MTable extends Manage_Table_SQL
                     array("value"=>'P',"label"=>"Paiement")
                     )
                 );
-        $this->a_info=["tva_purchase"=>44,"tva_both_side"=>43,"tva_sale"=>45
-            ,"tva_payment_sale"=>74,"tva_payment_purchase"=>74];
+        $this->a_info=[
+            "tva_purchase"=>44,"tva_both_side"=>43,"tva_sale"=>45
+            
,"tva_payment_sale"=>74,"tva_payment_purchase"=>74,'tva_reverse_account'=>88];
         $this->previous_id=null;
+        $this->a_comment=array(
+            'tva_purchase'=>_("Ne donnez pas ce poste comptable si ce code 
n'est pas utilisé à l'achat"),
+            'tva_both_side'=>_("Autoliquidation : Utilisé en même temps au 
crédit et au débit"),
+            'tva_sale'=>_("Ne donnez pas ce poste comptable si ce code n'est 
pas utilisé  à la vente"),
+            'tva_payment_purchase'=>_('TVA due ou récupérable quand 
l\'opération est payée ou exécutée'),
+            'tva_payment_sale'=>_('TVA due ou récupérable quand l\'opération 
est payée ou exécutée'),
+            'tva_reverse_account'=>_("Forcer ce poste comptable pour 
autoliquidation : par défault, le poste d'autoliquidation est calculé : soit 
celui qui est en contrepartie, soit le même (voir manuel)")
+        );
     }
 
     /**
@@ -107,6 +119,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
     function input()
     {
         $nb_order=count($this->a_order);
+        $this->set_property_visible('tva_reverse_account', true);
         echo "<table>";
         for ($i=0; $i<$nb_order; $i++)
         {
@@ -181,6 +194,16 @@ class Tva_Rate_MTable extends Manage_Table_SQL
                         echo $inum->input();
                         echo \HtmlInput::hidden("old_tva_id",$value);
 
+                    } elseif ($key=='tva_reverse_account')
+                    {
+                        $text=new IPoste("tva_reverse_account");
+                        $text->value=$value;
+                        $min_size=10;
+                        $text->set_attribute('gDossier', Dossier::id());
+                        $text->set_attribute('jrn', 0);
+                        $text->set_attribute('account', 'tva_reverse_account');
+                        $text->size=$min_size;
+                        echo $text->input();
                     }
                     echo "</td>";
                 }
@@ -190,12 +213,28 @@ class Tva_Rate_MTable extends Manage_Table_SQL
                             HtmlInput::hidden($key, $value)
                     );
                 }
+                echo '<td class="text-muted">';
+                if (isset ($this->a_comment[$key])) {
+                    echo $this->a_comment[$key];
+                }
+                echo '</td>';
             }
             echo "</tr>";
         }
         echo "</table>";
     }
 
+    /**
+     * @brief add the TVA_REVERSE_ACCOUNT
+     * @return void
+     */
+    function from_request()
+    {
+        parent::from_request();
+        $http=new \HttpInput();
+        
$this->table->tva_reverse_account=$http->request('tva_reverse_account');
+    }
+
     /**
      * @brief save the data in TVA_RATE
      * if tva_both_side is 1 and tva_purchase or tva_sale is empty then
@@ -230,6 +269,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
         $tva_rate->setp("tva_label", $this->table->tva_label);
         $tva_rate->setp("tva_comment", $this->table->tva_comment);
         $tva_rate->setp("tva_both_side", $this->table->tva_both_side);
+        $tva_rate->setp("tva_reverse_account", 
$this->table->tva_reverse_account);
 
         // TVA accounting must be joined and separated with a comma
         
$tva_purchase=(trim($this->table->tva_purchase)=="")?"#":$this->table->tva_purchase;
@@ -249,7 +289,7 @@ class Tva_Rate_MTable extends Manage_Table_SQL
 
     }
     /**
-     * Check data are valid 
+     * @brief Check data are valid
      *   1. tva_rate between 0 & 1
      *   2. label is uniq
      *   3. accounting must exist
@@ -340,6 +380,23 @@ class Tva_Rate_MTable extends Manage_Table_SQL
         if (isNumber($this->table->tva_code) == 1){
             $this->set_error("tva_code", _("code tva : doit aussi contenir des 
lettres"));
         }
+        /**
+         * auto reverse VAT : check that the accounting is used
+         */
+        if ( $this->table->tva_both_side==0 && 
trim($this->table->tva_reverse_account??"") != "")
+        {
+            $this->set_error("tva_reverse_account", _("Pas d'autoliquidation 
demandé"));
+        }
+        if ( $this->table->tva_both_side==1 && 
trim($this->table->tva_reverse_account??"") != "")
+        {
+            $count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val 
= $1",
+                [$this->table->tva_reverse_account]);
+            if ($count==0)
+            {
+                $this->set_error("tva_reverse_account", _("Poste comptable 
inexistant"));
+            }
+        }
+
         if ($this->count_error()!=0)
             return false;
         return true;
diff --git a/include/database/tva_rate_sql.class.php 
b/include/database/tva_rate_sql.class.php
index 5fc0593da..78bb589b4 100644
--- a/include/database/tva_rate_sql.class.php
+++ b/include/database/tva_rate_sql.class.php
@@ -51,6 +51,7 @@ class Tva_Rate_SQL extends Table_Data_SQL
             ,"tva_payment_purchase"=>"tva_payment_purchase"
             ,"tva_payment_sale"=>"tva_payment_sale"
             ,"tva_code"=>"tva_code"
+            ,'tva_reverse_account'=>'tva_reverse_account'
         );
         /*
          * Type of columns
@@ -65,6 +66,7 @@ class Tva_Rate_SQL extends Table_Data_SQL
             ,"tva_payment_purchase"=>"text"
             ,"tva_payment_sale"=>"text"
             ,"tva_code"=>"text"
+            ,'tva_reverse_account'=>'text'
         );
 
 
diff --git a/include/database/v_tva_rate_sql.class.php 
b/include/database/v_tva_rate_sql.class.php
index f336b6433..5d74a662b 100644
--- a/include/database/v_tva_rate_sql.class.php
+++ b/include/database/v_tva_rate_sql.class.php
@@ -49,6 +49,7 @@ class V_Tva_Rate_SQL extends Table_Data_SQL
             , "tva_purchase"=>"tva_purchase"
             , "tva_sale"=>"tva_sale"
             , "tva_both_side"=>"tva_both_side"
+            ,'tva_reverse_account'=>'tva_reverse_account'
             ,'tva_payment_purchase'=>'tva_payment_purchase'
             ,'tva_payment_sale'=>'tva_payment_sale'
 
@@ -65,6 +66,7 @@ class V_Tva_Rate_SQL extends Table_Data_SQL
             , "tva_purchase"=>"text"
             , "tva_sale"=>"text"
             , "tva_both_side"=>"numeric"
+            ,'tva_reverse_account'=>'text'
             , 'tva_payment_purchase'=>'text'
             , 'tva_payment_sale'=>'text'
         );
diff --git a/include/lib/message_javascript.php 
b/include/lib/message_javascript.php
index 75b38033c..a42c4bfdf 100644
--- a/include/lib/message_javascript.php
+++ b/include/lib/message_javascript.php
@@ -121,4 +121,6 @@ content[84]="<?php echo htmlspecialchars(_("En Belgique, 
l'exercice commence par
 content[85]="<?php echo htmlspecialchars(_("Solde créditeur au lieu de 
débiteur"),ENT_QUOTES)?>";
 content[86]="<?php echo htmlspecialchars(_("Solde débiteur au lieu de 
créditeur"),ENT_QUOTES)?>";
 content[87]="<?php echo htmlspecialchars(_("Uniquement pour les choix, séparer 
les valeurs possibles par un |"),ENT_QUOTES)?>";
+content[88]="<?php echo htmlspecialchars(_("Par défault, le poste 
d'autoliquidation est celui qui est au débit pour les ventes et au crédit pour 
les achats"),ENT_QUOTES)?>";
+
 </script>
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 139597f9c..8b8805772 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -1,2 +1,22 @@
 
 
+alter table tva_rate add column tva_reverse_account account_type;
+alter table tva_rate add constraint fk_tva_reverse_account foreign key 
(tva_reverse_account) references tmp_pcmn(pcm_val) on delete set null  on 
update cascade ;
+
+comment on column tva_rate.tva_reverse_account is 'Accouting for reversed VAT';
+
+drop VIEW public.v_tva_rate;
+
+CREATE OR REPLACE VIEW public.v_tva_rate
+AS SELECT tva_id,
+          tva_rate,
+          tva_code,
+          tva_label,
+          tva_comment,
+          tva_reverse_account,
+          split_part(tva_poste, ','::text, 1) AS tva_purchase,
+          split_part(tva_poste, ','::text, 2) AS tva_sale,
+          tva_both_side,
+          tva_payment_purchase,
+          tva_payment_sale
+   FROM tva_rate;
\ No newline at end of file
diff --git a/unit-test/include/class/acc_ledger_purchaseTest.php 
b/unit-test/include/class/acc_ledger_purchaseTest.php
index e7c13a162..a84754c45 100644
--- a/unit-test/include/class/acc_ledger_purchaseTest.php
+++ b/unit-test/include/class/acc_ledger_purchaseTest.php
@@ -65,6 +65,11 @@ class Acc_Ledger_PurchaseTest extends TestCase
            "p_currency_code"=>1
             
         );
+        // create accounting for reversed VAT
+        $g_connection->exec_sql("
+        INSERT INTO public.tmp_pcmn 
(pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use) VALUES
+        ('4119999','TVA Test UNIT','411','ACT','Y') on conflict  do nothing");
+
     }
 
     /**
@@ -458,6 +463,9 @@ class Acc_Ledger_PurchaseTest extends TestCase
         $g_connection->exec_sql("delete from jrn where jr_mt=$1", 
[$p_internal]);
         $g_connection->exec_sql("delete from jrnx where j_grpt not in (select 
jr_grpt_id from jrn)");
         $g_connection->exec_sql("alter sequence  s_jrn_pj3 restart with 52");
+        // set TVA_RATE by default
+        $g_connection->exec_sql("update tva_rate set tva_poste='41142,45142' 
where tva_id=5");
+        $g_connection->exec_sql("update tva_rate set tva_reverse_account=null 
where tva_id=5");
 
     }
     /**
@@ -476,4 +484,168 @@ class Acc_Ledger_PurchaseTest extends TestCase
         $ret=$this->object->get_detail_purchase(92,103,'unpaid');
         $this->assertEquals(5,Database::num_row($ret),'only unpaid 
operations');
     }
+
+    /**
+     * @testdox Reverse VAT1 : find out the accounting when there is 2 
accountings
+     * and column tva_reverse_account is null
+     * @covers Acc_Ledger_Sale::insert
+     */
+    public function testInsertReverseVAT1()
+    {
+        global $g_connection;
+
+        $array=$this->array;
+        // item 0 uses the tva_id = 5
+        $array['e_march0_tva_id']=5;
+        $array["pa_id"]=array(2);
+        $array["op"]=array(0, 1);
+        $array["amount_t0"]=24.2;
+        $array["hplan"]=array(array(-1), array(-1));
+        $array["val"]=array(array(24, 2), array(1212.5));
+        $array["mt"]="1572704002.1732";
+        $this->clean_operation();
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",[$array["mt"]]);
+        $this->assertEquals(0,$cnt);
+        $this->object->insert($array);
+
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",[$array["mt"]]);
+        $this->assertEquals(1,$cnt);
+        // check that the accounting for reverse VAT is 41142 and 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572704002.1732'
+        and j1.j_poste ='41142'
+        and j1.j_debit ='t'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account debit is wrong');
+
+        // check that the accounting for reverse VAT is 41142 and 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572704002.1732'
+        and j1.j_poste ='45142'
+        and j1.j_debit ='f'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        $this->clean_operation();
+
+
+    }
+    /**
+     * @testdox Reverse VAT2 : find out the accounting when there is only 1 
accounting
+     * and column tva_reverse_account is null
+     * @covers Acc_Ledger_Sale::insert
+     */
+    public function testInsertReverseVAT2()
+    {
+        global $g_connection;
+
+        $array=$this->array;
+        // item 0 uses the tva_id = 5
+        $array['e_march0_tva_id']=5;
+
+
+        $array["pa_id"]=array(2);
+        $array["op"]=array(0, 1);
+        $array["amount_t0"]=24.2;
+        $array["hplan"]=array(array(-1), array(-1));
+        $array["val"]=array(array(24, 2), array(1212.5));
+        $array["mt"]="1572704002.1732";
+        $this->clean_operation();
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",[$array["mt"]]);
+        $this->assertEquals(0,$cnt);
+
+        $g_connection->exec_sql("update tva_rate set tva_poste='41142,#' where 
tva_id=5");
+        $this->object->insert($array);
+
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",[$array["mt"]]);
+        $this->assertEquals(1,$cnt);
+
+
+        // check that the accounting for reverse VAT is only 41142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572704002.1732'
+        and j1.j_poste ='41142'
+        and j1.j_debit ='f'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        // check that the accounting for reverse VAT is only 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572704002.1732'
+        and j1.j_poste ='41142'
+        and j1.j_debit ='t'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        $this->clean_operation();
+
+
+    }
+    /**
+     * @testdox Reverse VAT3 : use value from column tva_reverse_account is 
null
+     * @covers Acc_Ledger_Purchase::insert
+     */
+    public function testInsertReverseVAT3()
+    {
+        global $g_connection;
+
+        $array=$this->array;
+        // item 0 uses the tva_id = 5
+        $array['e_march0_tva_id']=5;
+
+
+        $array["pa_id"]=array(2);
+        $array["op"]=array(0, 1);
+        $array["amount_t0"]=24.2;
+        $array["hplan"]=array(array(-1), array(-1));
+        $array["val"]=array(array(24, 2), array(1212.5));
+        $array["mt"]="1572704002.1732";
+        $this->clean_operation();
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",array($array["mt"]));
+        $this->assertEquals(0,$cnt);
+
+        $g_connection->exec_sql("update tva_rate set 
tva_reverse_account='4119999' where tva_id=5");
+        $this->object->insert($array);
+
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",array($array["mt"]));
+        $this->assertEquals(1,$cnt);
+
+
+        // check that the accounting for reverse VAT is only 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572704002.1732'
+        and j1.j_poste ='4119999'
+        and j1.j_debit ='f'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        // check that the accounting for reverse VAT is only 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572704002.1732'
+        and j1.j_poste ='41142'
+        and j1.j_debit ='t'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        $this->clean_operation();
+
+    }
 }
diff --git a/unit-test/include/class/acc_ledger_saleTest.php 
b/unit-test/include/class/acc_ledger_saleTest.php
index a9965efe2..e29e5f6f9 100644
--- a/unit-test/include/class/acc_ledger_saleTest.php
+++ b/unit-test/include/class/acc_ledger_saleTest.php
@@ -70,6 +70,12 @@ class Acc_Ledger_SaleTest extends TestCase
             "p_currency_rate"=>1,
             "p_currency_code"=>0,
             "view_invoice"=>"Enregistrer");
+        // create accounting for reversed VAT
+        $g_connection->exec_sql("
+        INSERT INTO public.tmp_pcmn 
(pcm_val,pcm_lib,pcm_val_parent,pcm_type,pcm_direct_use) VALUES
+        ('4119999','TVA Test UNIT','411','ACT','Y') on conflict  do nothing");
+
+
     }
 
     /**
@@ -101,6 +107,11 @@ class Acc_Ledger_SaleTest extends TestCase
         $g_connection->exec_sql("delete from jrnx where j_grpt not in (select 
jr_grpt_id from jrn)");
 
         $g_connection->exec_sql("alter sequence  s_jrn_pj2 restart with 40");
+        // set TVA_RATE by default
+        $g_connection->exec_sql("update tva_rate set tva_poste='41142,45142' 
where tva_id=5");
+        $g_connection->exec_sql("update tva_rate set tva_reverse_account=null 
where tva_id=5");
+
+
     }
     /**
      * @covers Acc_Ledger_Sale::verify
@@ -182,8 +193,169 @@ class Acc_Ledger_SaleTest extends TestCase
         $this->clean_operation();
         
     }
+    /**
+     * @testdox Reverse VAT1 : find out the accounting when there is 2 
accountings
+     * and column tva_reverse_account is null
+     * @covers Acc_Ledger_Sale::insert
+     */
+    public function testInsertReverseVAT1()
+    {
+        global $g_connection;
 
+        $array=$this->array;
+        // item 0 uses the tva_id = 5
+        $array['e_march0_tva_id']=5;
+        $array["pa_id"]=array(2);
+        $array["op"]=array(0, 1);
+        $array["amount_t0"]=24.2;
+        $array["hplan"]=array(array(-1), array(-1));
+        $array["val"]=array(array(24, 2), array(1212.5));
+        $array["mt"]="1572714478.3155";
+        $this->clean_operation();
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",["1572714478.3155"]);
+        $this->assertEquals(0,$cnt);
+        $this->object->insert($array);
 
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",["1572714478.3155"]);
+        $this->assertEquals(1,$cnt);
+        // check that the accounting for reverse VAT is 41142 and 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572714478.3155'
+        and j1.j_poste ='41142'
+        and j1.j_debit ='t'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account debit is wrong');
+
+        // check that the accounting for reverse VAT is 41142 and 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572714478.3155'
+        and j1.j_poste ='45142'
+        and j1.j_debit ='f'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        $this->clean_operation();
+
+
+    }
+    /**
+     * @testdox Reverse VAT2 : find out the accounting when there is only 1 
accounting
+     * and column tva_reverse_account is null
+     * @covers Acc_Ledger_Sale::insert
+     */
+    public function testInsertReverseVAT2()
+    {
+        global $g_connection;
+
+        $array=$this->array;
+        // item 0 uses the tva_id = 5
+        $array['e_march0_tva_id']=5;
+
+
+        $array["pa_id"]=array(2);
+        $array["op"]=array(0, 1);
+        $array["amount_t0"]=24.2;
+        $array["hplan"]=array(array(-1), array(-1));
+        $array["val"]=array(array(24, 2), array(1212.5));
+        $array["mt"]="1572714478.3155";
+        $this->clean_operation();
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",["1572714478.3155"]);
+        $this->assertEquals(0,$cnt);
+
+        $g_connection->exec_sql("update tva_rate set tva_poste='#,45142' where 
tva_id=5");
+        $this->object->insert($array);
+
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",["1572714478.3155"]);
+        $this->assertEquals(1,$cnt);
+
+
+        // check that the accounting for reverse VAT is only 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572714478.3155'
+        and j1.j_poste ='45142'
+        and j1.j_debit ='f'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        // check that the accounting for reverse VAT is only 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572714478.3155'
+        and j1.j_poste ='45142'
+        and j1.j_debit ='t'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        $this->clean_operation();
+
+
+    }
+    /**
+     * @testdox Reverse VAT3 : use value from column tva_reverse_account is 
null
+     * @covers Acc_Ledger_Sale::insert
+     */
+    public function testInsertReverseVAT3()
+    {
+        global $g_connection;
+
+        $array=$this->array;
+        // item 0 uses the tva_id = 5
+        $array['e_march0_tva_id']=5;
+
+
+        $array["pa_id"]=array(2);
+        $array["op"]=array(0, 1);
+        $array["amount_t0"]=24.2;
+        $array["hplan"]=array(array(-1), array(-1));
+        $array["val"]=array(array(24, 2), array(1212.5));
+        $array["mt"]="1572714478.3155";
+        $this->clean_operation();
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",["1572714478.3155"]);
+        $this->assertEquals(0,$cnt);
+
+        $g_connection->exec_sql("update tva_rate set 
tva_reverse_account='4119999' where tva_id=5");
+        $this->object->insert($array);
+
+        $cnt=$g_connection->get_value("select count(*) from jrn where 
jr_mt=$1",["1572714478.3155"]);
+        $this->assertEquals(1,$cnt);
+
+
+        // check that the accounting for reverse VAT is only 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572714478.3155'
+        and j1.j_poste ='4119999'
+        and j1.j_debit ='t'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        // check that the accounting for reverse VAT is only 45142
+        $sql="
+        select count(*)
+        from jrnx j1 join jrn j2 on (j1.j_grpt=j2.jr_grpt_id)
+        where 
+        j2.jr_mt ='1572714478.3155'
+        and j1.j_poste ='45142'
+        and j1.j_debit ='f'
+        ";
+        $this->assertEquals(1, $g_connection->get_value($sql),'fails : 
reversed account credit is wrong');
+
+        $this->clean_operation();
+
+    }
     /**
      * @covers Acc_Ledger_Sale::insert
      */



reply via email to

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