noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 18/38: Fix cosmetic bug : duplicate operation


From: dwm
Subject: [Noalyss-commit] [noalyss] 18/38: Fix cosmetic bug : duplicate operation with autoreverse VAT has an VAT amount
Date: Sun, 18 Feb 2024 07:30:44 -0500 (EST)

sparkyx pushed a commit to branch devel
in repository noalyss.

commit 9e5079ad4d62b8ce485996b9afbc0aece0a524e0
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Fri Feb 9 20:03:53 2024 +0100

    Fix cosmetic bug : duplicate operation with autoreverse VAT has an VAT 
amount
---
 include/class/acc_operation.class.php          |  31 ++-
 unit-test/include/class/acc_operation.Test.php | 129 -------------
 unit-test/include/class/acc_operationTest.php  | 258 +++++++++++++++++++++++++
 3 files changed, 282 insertions(+), 136 deletions(-)

diff --git a/include/class/acc_operation.class.php 
b/include/class/acc_operation.class.php
index 56f22bf89..73c3d1a1c 100644
--- a/include/class/acc_operation.class.php
+++ b/include/class/acc_operation.class.php
@@ -869,13 +869,14 @@ EOF;
         return $type_operation;
     }
     /**
-     * create a form to recreate the operation and returns it, just like a 
correct
-     * 
+     * @brief create a form to recreate the operation and returns it, just 
like a correct
+     * @param $p_id string DOMID of the form
      */
     function form_clone_operation($p_id) {
         // retrieve all info about operation
         $operation = $this->get_quant();
         $array=$operation->compute_array();
+
         global $g_user;
         $a_code=$this->db->get_array("select code from v_menu_dependency vmd  
where me_code=$1 and p_id=$2",
                 array( $operation->signature,$g_user->get_profile()));
@@ -918,14 +919,30 @@ EOF;
       
         // For Misc Operation , if a card is given then there is no accounting
         if ( $operation->signature==="ODS") {
-            $nb_array=count($array);
-            for ($i=0;$i<$nb_array;$i++) {
-                if (isset ($array["qc_".$i] ) && $array["qc_".$i] != "" ) {
-                    $array["poste".$i]="";
+            $nb_array = count($array);
+            for ($i = 0; $i < $nb_array; $i++) {
+                if (isset ($array["qc_" . $i]) && $array["qc_" . $i] != "") {
+                    $array["poste" . $i] = "";
                 }
             }
         }
-        
+
+        if ( $operation->signature==="ACH" || $operation->signature=="VEN") {
+            $idx=0;
+            foreach ($operation->det->array as $item) {
+                if ( isset ($item['qs_vat_sided']) && $item['qs_vat_sided'] != 
0 ) {
+                    $array['e_march'.$idx.'_tva_amount']=0;
+                }elseif (isset ($item['qp_vat_sided']) && 
$item['qp_vat_sided'] != 0 ){
+                    $array['e_march'.$idx.'_tva_amount']=0;
+                }
+                $idx++;
+            }
+            if ( DEBUGNOALYSS>1) {
+                echo \Noalyss\Dbg::hidden_info("operation->det_array", 
$operation->det->array);
+                echo \Noalyss\Dbg::hidden_info("array", $array);
+            }
+        }
+
         // transform the operation into hidden element
         $r.=HtmlInput::simple_array_to_hidden($array);
         $r.=HtmlInput::hidden("e_comm",$operation->det->jr_comment);
diff --git a/unit-test/include/class/acc_operation.Test.php 
b/unit-test/include/class/acc_operation.Test.php
deleted file mode 100644
index a03d9af84..000000000
--- a/unit-test/include/class/acc_operation.Test.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-use PHPUnit\Framework\TestCase;
-/**
- * Generated by PHPUnit_SkeletonGenerator on 2016-02-13 at 00:41:50.
- * @backupGlobals enabled
- */
-class Acc_OperationTest extends TestCase
-{
-    /**
-     * @var Acc_OperationTest
-     */
-    protected $object;
-
-    /**
-     * Sets up the fixture, for example, opens a network connection.
-     * This method is called before a test is executed.
-     */
-    protected function setUp():void
-    {
-         include 'global.php';
-        global $g_connection,$g_user;
-        $this->object = new Acc_Operation($g_connection);
-       
-        
-    }
-
-    /**
-     * Tears down the fixture, for example, closes a network connection.
-     * This method is called after a test is executed.
-     */
-    protected function tearDown():void
-    {
-    }
-
-    /**
-     *@covers Acc_Operation::seek_group
-     */
-    public function testSeek_group()
-    {
-        $this->object->jr_id=6;
-        $r=$this->object->seek_group();
-        $this->assertEquals(8,$r);
-    }
-    /**
-     * @covers Acc_Operation::set_id
-     * 
-     */
-    public function testSet_id()
-    {
-        $this->object->set_id(1000);
-        $this->assertEquals(1000,$this->object->jr_id);
-        try {
-            $this->object->set_id('AB');
-        } catch (Exception $e) {
-            $this->assertEquals($e->getMessage(),'Acc_Operation::set_id , id 
invalide ');
-        }
-    }
-    /**
-     * @covers Acc_Operation::set_paid
-     */
-    function testSet_Paid()
-    {
-        $row=$this->object->db->get_array('select * from jrn where jr_rapt <> 
$1 limit 1',array('paid'));
-        if ( ! $row ) {
-            echo "Aucune ligne trouvée";
-            $this->assertTrue(TRUE);    
-        } else {
-            $this->object->jr_id=$row[0]['jr_id'];  
-            $this->object->set_paid();
-            $status=$this->object->db->get_value ('select jr_rapt from jrn 
where jr_id=$1',array($row[0]['jr_id']));
-            $this->assertEquals($status,'paid');
-        }
-        
-    }
-    /**
-     * @covers Acc_Operation::get_amount
-     */
-    function testGet_Amount()
-    {
-        $row=$this->object->db->get_array('select * from jrn limit 1');
-        if ( ! $row ) {
-            echo "Aucune ligne trouvée";
-            $this->assertTrue(FALSE);
-        } else {
-            $this->object->jr_id=$row[0]['jr_id'];  
-            $amount=$this->object->get_amount();
-            $this->assertEquals($amount,$row[0]['jr_montant']);
-        }
-        
-    }
-    /**
-     * provide data for testAmount_Currency
-     * @return type
-     */
-    public function data_amount_currency()
-    {
-        return array(
-            /* sale */
-            array(659,146.95),
-            array(657,146.95),
-            array(649,0),
-            /* purchase*/
-            array(680,680.33),
-            array(683,834.91),
-            array(526,0),
-            /* financial */
-            array(658,146.95),
-            array(684,200),
-            array(685,300),
-            /* misc operation */
-            array(686,25.25),
-            
-        );
-    }
-    /**
-     * @testdox acc_operation::get_amount_currency - sale-purchase-fin-misc
-     * @covers Acc_Operation::get_amount_currency
-     * @dataProvider data_amount_currency
-     */
-    function testGet_AmountCurrency($p_jrn_id,$p_amount_currency)
-    {
-        global $g_connection;
-        $acc_operation=new Acc_Detail($g_connection,$p_jrn_id);
-        $acc_operation->get();
-        $acc_operation->get_quant();
-        $actual_amount=round($acc_operation->get_currency_amount(),2);
-        $this->assertEquals($p_amount_currency,$actual_amount,"currency values 
doesn't match for $p_jrn_id");
-    }
-}
diff --git a/unit-test/include/class/acc_operationTest.php 
b/unit-test/include/class/acc_operationTest.php
new file mode 100644
index 000000000..0d9c5dfb0
--- /dev/null
+++ b/unit-test/include/class/acc_operationTest.php
@@ -0,0 +1,258 @@
+<?php
+use PHPUnit\Framework\TestCase;
+/**
+ * Generated by PHPUnit_SkeletonGenerator on 2016-02-13 at 00:41:50.
+ * @backupGlobals enabled
+ */
+class Acc_OperationTest extends TestCase
+{
+    /**
+     * @var Acc_OperationTest
+     */
+    protected $object;
+
+    /**
+     * Sets up the fixture, for example, opens a network connection.
+     * This method is called before a test is executed.
+     */
+    protected function setUp():void
+    {
+         include 'global.php';
+        global $g_connection,$g_user;
+        $this->object = new Acc_Operation($g_connection);
+       
+        
+    }
+
+    /**
+     * Tears down the fixture, for example, closes a network connection.
+     * This method is called after a test is executed.
+     */
+    protected function tearDown():void
+    {
+    }
+
+    /**
+     *@covers Acc_Operation::seek_group
+     */
+    public function testSeek_group()
+    {
+        $this->object->jr_id=6;
+        $r=$this->object->seek_group();
+        $this->assertEquals(8,$r);
+    }
+    /**
+     * @covers Acc_Operation::set_id
+     * 
+     */
+    public function testSet_id()
+    {
+        $this->object->set_id(1000);
+        $this->assertEquals(1000,$this->object->jr_id);
+        try {
+            $this->object->set_id('AB');
+        } catch (Exception $e) {
+            $this->assertEquals($e->getMessage(),'Acc_Operation::set_id , id 
invalide ');
+        }
+    }
+    /**
+     * @covers Acc_Operation::set_paid
+     */
+    function testSet_Paid()
+    {
+        $row=$this->object->db->get_array('select * from jrn where jr_rapt <> 
$1 limit 1',array('paid'));
+        if ( ! $row ) {
+            echo "Aucune ligne trouvée";
+            $this->assertTrue(TRUE);    
+        } else {
+            $this->object->jr_id=$row[0]['jr_id'];  
+            $this->object->set_paid();
+            $status=$this->object->db->get_value ('select jr_rapt from jrn 
where jr_id=$1',array($row[0]['jr_id']));
+            $this->assertEquals($status,'paid');
+        }
+        
+    }
+    /**
+     * @covers Acc_Operation::get_amount
+     */
+    function testGet_Amount()
+    {
+        $row=$this->object->db->get_array('select * from jrn limit 1');
+        if ( ! $row ) {
+            echo "Aucune ligne trouvée";
+            $this->assertTrue(FALSE);
+        } else {
+            $this->object->jr_id=$row[0]['jr_id'];  
+            $amount=$this->object->get_amount();
+            $this->assertEquals($amount,$row[0]['jr_montant']);
+        }
+        
+    }
+    /**
+     * provide data for testAmount_Currency
+     * @return type
+     */
+    public function data_amount_currency()
+    {
+        return array(
+            /* sale */
+            array(659,146.95),
+            array(657,146.95),
+            array(649,0),
+            /* purchase*/
+            array(680,680.33),
+            array(683,834.91),
+            array(526,0),
+            /* financial */
+            array(658,146.95),
+            array(684,200),
+            array(685,300),
+            /* misc operation */
+            array(686,25.25),
+            
+        );
+    }
+    /**
+     * @testdox acc_operation::get_amount_currency - sale-purchase-fin-misc
+     * @covers Acc_Operation::get_amount_currency
+     * @dataProvider data_amount_currency
+     */
+    function testGet_AmountCurrency($p_jrn_id,$p_amount_currency)
+    {
+        global $g_connection;
+        $acc_operation=new Acc_Detail($g_connection,$p_jrn_id);
+        $acc_operation->get();
+        $acc_operation->get_quant();
+        $actual_amount=round($acc_operation->get_currency_amount(),2);
+        $this->assertEquals($p_amount_currency,$actual_amount,"currency values 
doesn't match for $p_jrn_id");
+    }
+
+    /**
+     * @testDox Test form_clone_operation SALE
+     * @return void
+     */
+    function testForm_clone_operation_sale()
+    {
+        global $g_connection;
+        // use  jr_id=160 : 5 rows
+        $duplicate = new Acc_Operation($g_connection);
+        $duplicate->jr_id=160;
+        ob_start();
+
+        $result=$duplicate->form_clone_operation("test");
+        ob_end_clean();
+
+        $this->assertTrue(stripos($result,'<input type="hidden" id="nb_item" 
name="nb_item" value="5">')>0, "sale : HTML doesn't contain nb_item = 5");
+        // use  jr_id=910 : 1 rows
+        $duplicate = new Acc_Operation($g_connection);
+        $duplicate->jr_id=910;
+        ob_start();
+        $result=$duplicate->form_clone_operation("test");
+        ob_end_clean();
+        $this->assertStringContainsString(strtoupper('<input type="hidden" 
id="nb_item" name="nb_item" value="1">'), strtoupper($result));
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="e_march0" name="e_march0" 
value="DEPLAC">')
+            ,strtoupper($result));
+
+        // use jr_id=659 VAT_SIDED
+        $duplicate = new Acc_Operation($g_connection);
+        $duplicate->jr_id=659;
+        ob_start();
+        $result=$duplicate->form_clone_operation("test");
+        ob_end_clean();
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="e_march0_tva_id" 
name="e_march0_tva_id" value="5">')
+            , strtoupper($result));
+        $this->assertStringContainsString(
+        strtoupper('<input type="hidden" id="e_march0_tva_amount" 
name="e_march0_tva_amount" value="0">')
+            , strtoupper($result));
+        $this->assertStringContainsString(
+            strtoupper( '<input type="hidden" id="e_march1_tva_amount" 
name="e_march1_tva_amount" value="17.3500">')
+            , strtoupper($result));
+
+    }
+
+    /**
+     * @testDox Test form_clone_operation PURCHASE
+     * @return void
+     */
+    function testForm_clone_operation_purchase()
+    { global $g_connection;
+        // use jr_id 158 4 rows
+        $duplicate = new Acc_Operation($g_connection);
+        $duplicate->jr_id=158;
+        ob_start();
+
+        $result=$duplicate->form_clone_operation("test");
+        ob_end_clean();
+
+        $this->assertTrue(stripos($result,'<input type="hidden" id="nb_item" 
name="nb_item" value="4">')>0
+            , "purchase : HTML doesn't contain nb_item = 4 $result");
+
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="e_march0" name="e_march0" 
value="DEPLAC1">')
+            ,strtoupper($result));
+
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="e_march3" name="e_march3" 
value="DOCUME">')
+            ,strtoupper($result));
+
+        // use jr_id 680 VAT_SIDED
+        $duplicate = new Acc_Operation($g_connection);
+        $duplicate->jr_id=680;
+        ob_start();
+
+        $result=strtoupper($duplicate->form_clone_operation("test"));
+        ob_end_clean();
+
+        $this->assertStringContainsString(
+            strtoupper(        '<input type="hidden" id="e_march0_tva_amount" 
name="e_march0_tva_amount" value="0">'),
+            $result);
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="e_march0_tva_id" 
name="e_march0_tva_id" value="5">'),$result);
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="e_march1_tva_id" 
name="e_march1_tva_id" value="4">'),$result);
+
+    }
+    /**
+     * @testDox Test form_clone_operation MISC OP
+     * @return void
+     */
+    function testForm_clone_operation_ods()
+    {
+        global $g_connection;
+        // use jr_id 317 1 rows
+        $duplicate = new Acc_Operation($g_connection);
+        $duplicate->jr_id=317;
+        ob_start();
+
+        $result=strtoupper($duplicate->form_clone_operation("test"));
+        ob_end_clean();
+        $this->assertTrue(stripos($result,'<input type="hidden" id="nb_item" 
name="nb_item" value="3">')>0
+            , "MO : HTML doesn't contain nb_item = 3 ");
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="amount1" name="amount1" 
value="40.0000">')       ,
+            $result);
+
+    }
+    /**
+     * @testDox Test form_clone_operation FIN
+     * @return void
+     */
+    function testForm_clone_operation_fin()
+    {
+        // use jr_id 250 1 rows
+        global $g_connection;
+        $duplicate = new Acc_Operation($g_connection);
+        $duplicate->jr_id=250;
+        ob_start();
+
+        $result=strtoupper($duplicate->form_clone_operation("test"));
+        ob_end_clean();
+
+        $this->assertStringContainsString(
+            strtoupper('<input type="hidden" id="e_other0_amount" 
name="e_other0_amount" value="3500.7800">')       ,
+            $result);
+    }
+
+}



reply via email to

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