noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 18/33: Fix Bug : tva_code not retrieve from s


From: dwm
Subject: [Noalyss-commit] [noalyss] 18/33: Fix Bug : tva_code not retrieve from search
Date: Thu, 18 Jul 2024 12:24:47 -0400 (EDT)

sparkyx pushed a commit to branch unstable
in repository noalyss.

commit f1baf67e429f03617179a30ae606e08131d02f4b
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Jun 30 13:57:59 2024 +0200

    Fix Bug : tva_code not retrieve from search
---
 html/ajax_misc.php                       |   2 +-
 html/fid.php                             |   4 +-
 include/ajax/ajax_card.php               |   8 +-
 sql/upgrade.sql                          |   6 +-
 unit-test/include/Ajax/ajax_miscTest.php | 164 +++++++++++++++++++++++++++++++
 unit-test/include/class/followupTest.php |   2 -
 unit-test/test-complet-9.ods             | Bin 0 -> 22722 bytes
 7 files changed, 175 insertions(+), 11 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index c4d89c5e3..e111760f4 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -133,7 +133,7 @@ $html = var_export($_REQUEST, true);
 set_language();
 if ( LOGINPUT)
     {
-        
$file_loginput=fopen($_ENV['TMP'].'/scenario-'.$_SERVER['REQUEST_TIME'].'.php','a+');
+        
$file_loginput=fopen($_ENV['TMP'].'/scenario-ajax-'.$_SERVER['REQUEST_TIME'].'.php','a+');
         fwrite ($file_loginput,"<?php \n");
         fwrite ($file_loginput,'//@description:'.$op."\n");
         fwrite($file_loginput, '$_GET='.var_export($_GET,true));
diff --git a/html/fid.php b/html/fid.php
index 514405af0..63e7c31ca 100644
--- a/html/fid.php
+++ b/html/fid.php
@@ -115,7 +115,7 @@ if ( isset($_SESSION[SESSION_KEY.'isValid']) && 
$_SESSION[SESSION_KEY.'isValid']
         $filter_card=$d;
         $filter_card=noalyss_str_replace('[sql]','',$d);
     }
-    $sql="select vw_name,vw_first_name,vw_addr,vw_cp,vw_buy,vw_sell,tva_id
+    $sql="select 
vw_name,vw_first_name,vw_addr,vw_cp,vw_buy,vw_sell,tva_id,tva_code
          from vw_fiche_attr
          where quick_code=upper($1)". $filter_card;
 
@@ -133,7 +133,7 @@ if ( isset($_SESSION[SESSION_KEY.'isValid']) && 
$_SESSION[SESSION_KEY.'isValid']
     $sell=(isNumber($array[0]['vw_sell']) == 1) ? $array[0]['vw_sell'] : 0 ;
     $buy=(isNumber($array[0]['vw_buy']) == 1) ?$array[0]['vw_buy']:0;
     
-    $tva_id=$array[0]['tva_id'];
+    
$tva_id=(empty($array[0]['tva_id']))?$array[0]['tva_code']:$array[0]['tva_id'];
 
     // Check null
     $name=($name==null)?" ":noalyss_str_replace('"','',$name);
diff --git a/include/ajax/ajax_card.php b/include/ajax/ajax_card.php
index 44484287e..2bba86e82 100644
--- a/include/ajax/ajax_card.php
+++ b/include/ajax/ajax_card.php
@@ -530,9 +530,11 @@ case 'fs':
             $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
                                               $price,$amount);
         }
-        $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
-                                          $tvaid,$aFound[$i]['tva_id']);
-        $array[$i]['javascript'].="removeDiv('search_card');";
+        // if there is no TVA_ID in the view, it is possible we have a TVA_CODE
+       
$tva_code=(empty($aFound[$i]['tva_id']))?$aFound[$i]['tva_code']:$aFound[$i]['tva_id'];
+         $array[$i]['javascript'].=sprintf("set_value('%s','%s');",
+             $tvaid,$tva_code);
+         $array[$i]['javascript'].="removeDiv('search_card');";
 
     }//foreach
 
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index efaad1ec9..d68581873 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -4,9 +4,9 @@ update menu_ref set me_menu='Navigateur &#x1F9ED;' where 
me_code ~ 'NAVI';
 update menu_ref set me_menu='Configuration &#x1F527;' where me_code='CFG';
 
 
-ALTER TABLE public.tva_rate ADD CONSTRAINT tva_code_number_check CHECK 
(isnumeric(tva_code) = false);
+ALTER TABLE public.tva_rate ADD CONSTRAINT tva_code_number_check CHECK 
(tva_code::text !~ '^([0-9]+)$');
 
-drop view if exists  public.vw_fiche_attr;
+-- drop view if exists  public.vw_fiche_attr;
 
 CREATE OR REPLACE VIEW public.vw_fiche_attr
 AS SELECT a.f_id,
@@ -77,4 +77,4 @@ AS SELECT a.f_id,
                         FROM fiche_detail
                         WHERE fiche_detail.ad_id = 5) l ON a.f_id = l.f_id;
 
-COMMENT ON VIEW public.vw_fiche_attr IS 'Some attribute for all cards';
\ No newline at end of file
+COMMENT ON VIEW public.vw_fiche_attr IS 'Some attribute for all cards';
diff --git a/unit-test/include/Ajax/ajax_miscTest.php 
b/unit-test/include/Ajax/ajax_miscTest.php
new file mode 100644
index 000000000..dc8204a80
--- /dev/null
+++ b/unit-test/include/Ajax/ajax_miscTest.php
@@ -0,0 +1,164 @@
+<?php
+
+/*
+ * * Copyright (C) 2022 Dany De Bontridder <dany@alchimerys.be>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * 
+ * Author : Dany De Bontridder danydb@noalyss.eu $(DATE)
+ */
+
+/**
+ * @file
+ * @brief noalyss
+ */
+
+use PHPUnit\Framework\TestCase;
+
+require DIRTEST . '/global.php';
+
+/**
+ * @testdox Class Ajax_MiscTest : used for testing the AJAX calls from 
ajax_misc
+ * @backupGlobals enabled
+ */
+class Ajax_MiscTest extends TestCase
+{
+
+    /**
+     * @var Fiche
+     */
+//    protected $object;
+//    protected $connection;
+
+    /**
+     * Sets up the fixture, for example, opens a network connection.
+     * This method is called before a test method is executed.
+     */
+//    protected function setUp(): void
+//    {
+//
+//
+//    }
+
+    /**
+     * Tears down the fixture, for example, closes a network connection.
+     * This method is called after a test method is executed.
+     */
+//    protected function tearDown(): void
+//    {
+//        /**
+//         * example
+//         * if ( ! is_object($this->object->fiche_def)) return;
+//         * include_once DIRTEST.'/global.php';
+//         * $g_connection=Dossier::connect();
+//         * $sql=new ArrayObject();
+//         * $sql->append("delete from fiche_detail where f_id in (select f_id 
from fiche where fd_id =\$1 )");
+//         * $sql->append("delete from fiche where f_id not in (select f_id 
from fiche_detail where \$1=\$1)");
+//         * $sql->append("delete from jnt_fic_attr where fd_id  = \$1 ");
+//         * $sql->append("delete from fiche_def where fd_id = \$1");
+//         * foreach ($sql as $s) {
+//         * $g_connection->exec_sql($s,[$this->object->fiche_def->id]);
+//         * }
+//         */
+//    }
+
+    /**
+     * the setUpBeforeClass() template methods is called before the first test 
of the test case
+     *  class is run
+     */
+//    public static function setUpBeforeClass(): void
+//    {
+//        //        include 'global.php';
+//    }
+
+    /**
+     *  tearDownAfterClass() template methods is calleafter the last test of 
the test case class is run,
+     *
+     */
+//    static function tearDownAfterClass(): void
+//    {
+//        //        include 'global.php';
+//    }
+
+    private function createCard_MA1()
+    {
+        global $g_user, $g_connection;
+
+        $fiche_id = $g_connection->get_value("select f_id from fiche_detail 
where ad_id=$1 and ad_value=$2",
+            array(ATTR_DEF_QUICKCODE, 'MA1'));
+        if (!empty ($fiche_id)) {
+           $this->cleanCard($fiche_id);
+        }
+
+
+        $g_user = new Noalyss_User($g_connection);
+        //insert a card
+        $fiche = new Fiche($g_connection);
+        // card for Merchandise
+        $fiche->set_fiche_def(1);
+        Card_Property::load($fiche);
+        $fiche->setAttribut(1, "Inserted by PHPUNIT-" . __CLASS__ . ":" . 
__FUNCTION__);
+        $fiche->setAttribut(ATTR_DEF_TVA, '210A');
+        $fiche->setAttribut(ATTR_DEF_QUICKCODE, 'MA1');
+        $fiche->insert(1, $fiche->to_array());
+        return $fiche;
+    }
+
+    private function cleanCard($fiche_id)
+    {
+        global  $g_connection;
+        $g_connection->exec_sql("delete from fiche_detail where f_id = $1", 
array($fiche_id));
+        $g_connection->exec_sql("delete from fiche where f_id = $1", 
array($fiche_id));
+    }
+    /**
+     * @testdox Call fid.php
+     * @covers       ajax call to fid.php
+     * @backupGlobals enabled
+     */
+    public function testAJAX_retrieveCard()
+    {
+        global $g_user, $g_connection;
+        $fiche=$this->createCard_MA1();
+
+        $query = array(
+            'gDossier' => DOSSIER,
+            'FID' => 'MA1',
+            'l' => 'e_march4_label',
+            't' => 'e_march4_tva_id',
+            'p' => 'e_march4_price',
+            'b' => 'e_march4_price',
+            'd' => 'deb',
+            'j' => '3',
+            'ctl' => 'undefined'
+        );
+
+        $_REQUEST = $_POST = $_GET = $query;
+        ob_start();
+        require NOALYSS_HOME . '/fid.php';
+        $content = ob_get_contents();
+        ob_end_clean();
+
+        $expected = <<<EOF
+{"flabel":"e_march4_label","name":"Inserted by 
PHPUNIT-Ajax_MiscTest:createCard_MA1 
","ftva_id":"e_march4_tva_id","tva_id":"210A","fPrice_sale":"e_march4_price","sell":"0","fPrice_purchase":"e_march4_price","buy":"0","answer":"ok"}
+EOF;
+
+        $this->assertEquals($expected, $content, "Incorrect answer");
+
+        // clean card
+        $this->cleanCard($fiche->id);
+    }
+
+}
\ No newline at end of file
diff --git a/unit-test/include/class/followupTest.php 
b/unit-test/include/class/followupTest.php
index c1fabef38..becff0b7d 100644
--- a/unit-test/include/class/followupTest.php
+++ b/unit-test/include/class/followupTest.php
@@ -150,8 +150,6 @@ class FollowupTest extends TestCase
     {
         global $g_user;
         $g_user=new Noalyss_User($this->connection);
-        $array_search=
-
         $query=Follow_Up::create_query($this->connection,array(
             "ag_dest_query" => "-2",
             "qcode" => "CLIENT1",
diff --git a/unit-test/test-complet-9.ods b/unit-test/test-complet-9.ods
new file mode 100644
index 000000000..d2365bb30
Binary files /dev/null and b/unit-test/test-complet-9.ods differ



reply via email to

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