noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 12/12: Improve #0002196: Comptes Alphanumériq


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 12/12: Improve #0002196: Comptes Alphanumériques calculés trop longs
Date: Sat, 17 Sep 2022 08:40:58 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit f1d3862e176a3ee82d4cb07dec6caf440efcb56d
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Sep 17 12:08:06 2022 +0200

    Improve #0002196: Comptes Alphanumériques calculés trop longs
---
 include/constant.php                             |  2 +-
 include/sql/patch/upgrade179.sql                 | 77 ++++++++++++++++++++++++
 sql/upgrade.sql                                  |  1 -
 unit-test/include/class/acc_ledgerTest.php       |  2 +-
 unit-test/include/class/contactTest.php          |  6 +-
 unit-test/include/class/ficheTest.php            | 18 +++---
 unit-test/include/class/followup_detail.Test.php |  2 +-
 unit-test/test-file.sh                           |  6 +-
 8 files changed, 95 insertions(+), 19 deletions(-)

diff --git a/include/constant.php b/include/constant.php
index 9a3da9063..0fec75759 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -115,7 +115,7 @@ if (!defined("NOALYSS_PACKAGE_REPOSITORY")) {
 if (!defined("SYSINFO_DISPLAY")) {
     define("SYSINFO_DISPLAY", TRUE);
 }
-define("DBVERSION", 179);
+define("DBVERSION", 180);
 define("MONO_DATABASE", 25);
 define("DBVERSIONREPO", 20);
 define('NOTFOUND', '--not found--');
diff --git a/include/sql/patch/upgrade179.sql b/include/sql/patch/upgrade179.sql
new file mode 100644
index 000000000..961f128da
--- /dev/null
+++ b/include/sql/patch/upgrade179.sql
@@ -0,0 +1,77 @@
+begin;
+CREATE OR REPLACE FUNCTION comptaproc.account_compute_alpha(p_class text, 
p_name text)
+    RETURNS account_type
+AS $function$
+declare
+    sResult account_type;
+    sAccount account_type;
+    sFormatedAccount account_type;
+    nCount int;
+    idx int :=0;
+begin
+    sFormatedAccount := comptaproc.format_account(p_name);
+
+    sAccount := p_class||substring(sFormatedAccount for 5);
+    nCount := 0;
+    loop
+        select count(*) into nCount from tmp_pcmn where pcm_val = 
comptaproc.format_account(sAccount);
+
+        exit when nCount = 0;
+        idx := idx + 1;
+        sAccount := p_class || substring(sFormatedAccount for 5)||idx::text;
+    end loop;
+    sResult := comptaproc.format_account(sAccount);
+    return sResult;
+end;
+$function$
+LANGUAGE plpgsql;
+
+
+
+CREATE OR REPLACE FUNCTION comptaproc.account_compute(p_f_id integer)
+    RETURNS account_type
+AS $function$
+declare
+    class_base fiche_def.fd_class_base%type;
+    maxcode numeric;
+    sResult account_type;
+    bAlphanum bool;
+    sName text;
+begin
+    select fd_class_base into class_base
+    from
+        fiche_def join fiche using (fd_id)
+    where
+            f_id=p_f_id;
+
+    bAlphanum := account_alphanum();
+    if bAlphanum = false  then
+        select count (pcm_val) into maxcode from tmp_pcmn where pcm_val_parent 
= class_base;
+        if maxcode = 0 then
+            maxcode:=class_base::numeric;
+        else
+            select max (pcm_val) into maxcode from tmp_pcmn where 
pcm_val_parent = class_base;
+            maxcode:=maxcode::numeric;
+        end if;
+        if maxcode::text = class_base then
+            maxcode:=class_base::numeric*1000;
+        end if;
+        maxcode:=maxcode+1;
+
+        sResult:=maxcode::account_type;
+    else
+        -- if alphanum, use name
+        select ad_value into sName from fiche_detail where f_id=p_f_id and 
ad_id=1;
+        if sName is null then
+            raise exception 'Cannot compute an accounting without the name of 
the card for %',p_f_id;
+        end if;
+        sResult := account_compute_alpha(class_base,sName);
+    end if;
+    return sResult;
+end;
+$function$
+LANGUAGE plpgsql
+;
+
+insert into version (val,v_description) values (180,'Shorten Aphanumeric 
account');
+commit;
\ No newline at end of file
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index 8b1378917..e69de29bb 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -1 +0,0 @@
-
diff --git a/unit-test/include/class/acc_ledgerTest.php 
b/unit-test/include/class/acc_ledgerTest.php
index 61087b87a..b3284196a 100644
--- a/unit-test/include/class/acc_ledgerTest.php
+++ b/unit-test/include/class/acc_ledgerTest.php
@@ -851,7 +851,7 @@ class Acc_LedgerTest extends TestCase
         \Noalyss\Facility::save_file(__DIR__."/file", 
"acc_ledger-input_new.html", $result);
         $size=filesize(__DIR__."/file/acc_ledger-input_new.html");
                 
-        $this->assertEquals(16325,$size," output input_new is not what it is 
expected");
+        $this->assertEquals(15649,$size," output input_new is not what it is 
expected");
     }
 
     /**
diff --git a/unit-test/include/class/contactTest.php 
b/unit-test/include/class/contactTest.php
index f6b792687..2024c5b1a 100644
--- a/unit-test/include/class/contactTest.php
+++ b/unit-test/include/class/contactTest.php
@@ -180,7 +180,7 @@ class ContactTest extends TestCase
         $filename="contact-summary-1.html";
         \Noalyss\Facility::save_file($path,$filename,$r);
         print "File saved into $path/$filename";
-        $this->assertEquals(4983, filesize ($path."/".$filename)," File not 
valide (1)");
+        $this->assertEquals(4988, filesize ($path."/".$filename)," File not 
valide (1)");
         $this->assertEquals(5 , preg_match_all('/<tr class="/',$r)," 1. 
Missing card");
         $contact->filter_company(' fourni ');
         ob_start();
@@ -191,7 +191,7 @@ class ContactTest extends TestCase
         \Noalyss\Facility::save_file($path,$filename,$r);
 
         print "File saved into $path/$filename";
-        $this->assertEquals(3457,filesize ($path."/".$filename)," File not 
valide (2)");
+        $this->assertEquals(3460,filesize ($path."/".$filename)," File not 
valide (2)");
         $this->assertEquals(3 , preg_match_all('/<tr class="/',$r), 'not found 
all the contacts from FOURNI');
 
 
@@ -202,7 +202,7 @@ class ContactTest extends TestCase
         $filename="contact-summary-3.html";
         \Noalyss\Facility::save_file($path,$filename,$r);
         print "File saved into $path/$filename";
-        $this->assertEquals(2018,filesize ($path."/".$filename)," File not 
valide (3)");
+        $this->assertEquals(2019,filesize ($path."/".$filename)," File not 
valide (3)");
         $this->assertEquals(1, preg_match_all('/<tr class="/',$r), 'Search 
does not filter');
         
     }
diff --git a/unit-test/include/class/ficheTest.php 
b/unit-test/include/class/ficheTest.php
index d39c7445c..43b0da2f9 100644
--- a/unit-test/include/class/ficheTest.php
+++ b/unit-test/include/class/ficheTest.php
@@ -629,14 +629,16 @@ where
         $fiche->setAttribut(ATTR_DEF_ACCOUNT, "");
         Card_Property::update($fiche);
         $fiche->load();
-        
$this->assertEquals('600CARDFORPHPUNIT',$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account
 not properly created');
+        
$this->assertEquals('600CARDF1',$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account 
not properly created');
 
-        for ( $i=600002; $i < 600999;$i++) {
+        for ( $i=600002; $i < 600099;$i++) {
             $fiche->setAttribut(ATTR_DEF_NAME,'Card for testing '.$i);
             $fiche->setAttribut(ATTR_DEF_ACCOUNT, "");
             Card_Property::update($fiche);
             $fiche->load();
-            
$this->assertEquals("600CARDFORTESTING".$i,$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account
 not properly created');
+
+            $idx=$i-600000;
+            
$this->assertEquals("600CARDF".$idx,$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account
 not properly created');
 
 
         }
@@ -655,15 +657,13 @@ where
         $fiche_def->save_class_base('600');
         $first=true;
 
-        for ( $i=1; $i <  1000;$i++) {
+        for ( $i=1; $i <  100;$i++) {
             $fiche=new Fiche($this->g_connection);
             $fiche->insert(2,['av_text1'=>substr($i.' PHPUNIT 
'.__FUNCTION__,0,35)],);
-            if ( $first ) {
-                $first=false;
-                $start=$fiche->id;
-            }
+
             $fiche->load();
-            
$this->assertEquals(substr("600".$i."PHPUNITTESTAUTOMATICACCOUNTINGIN",0,36),$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account
 not properly created');
+            $expected="600".substr($i."PHPU",0,5);
+            
$this->assertEquals($expected,$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account 
not properly created');
 
         }
 
diff --git a/unit-test/include/class/followup_detail.Test.php 
b/unit-test/include/class/followup_detail.Test.php
index 7b64b8640..74e3520ec 100644
--- a/unit-test/include/class/followup_detail.Test.php
+++ b/unit-test/include/class/followup_detail.Test.php
@@ -71,7 +71,7 @@ class Follow_Up_DetailTest extends TestCase
      */
     public static function setUpBeforeClass():void
     {
-
+        require DIRTEST.'/global.php';
         global $g_connection;
         $g_connection->exec_sql('delete from action_detail');
 
diff --git a/unit-test/test-file.sh b/unit-test/test-file.sh
index 5693f6bf4..dd5de8c9a 100755
--- a/unit-test/test-file.sh
+++ b/unit-test/test-file.sh
@@ -54,7 +54,7 @@ fi
 
 if [ ! -z "$FOLDERTEST" -a  -d "$FOLDERTEST" ] ; then
 
-       $PHPINI $PHPUNIT --globals-backup --bootstrap bootstrap.php $COVERAGE 
--testdox --color $FOLDERTEST
+       $PHPINI $PHPUNIT --bootstrap bootstrap.php $COVERAGE --testdox --color 
$FOLDERTEST
        exit $?
 fi
 
@@ -65,12 +65,12 @@ fi
 
 if [ ! -z "$FUNCTION" ] ; then
        echo "testing $FILETOTEST $FUNCTION"
-       $PHPINI $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php --globals-backup 
--verbose --color --filter $FUNCTION $FILETOTEST
+       $PHPINI $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php --verbose --color 
--filter $FUNCTION $FILETOTEST
 else
 
        # $PHPUNIT --bootstrap bootstrap.php --whitelist $FILETOTEST 
--coverage-text=${FILETOTEST%.php}.txt  --color $FILETOTEST 
        # $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php 
--whitelist=$CUR_DIR/../include/class --coverage-html=coverage --color 
$FILETOTEST 
        $PHPINI $PHPUNIT --bootstrap bootstrap.php $COVERAGE $FILETOTEST 
--testdox --color $FILETOTEST 
-       #$PHPUNIT --bootstrap bootstrap.php --whitelist=../include 
--globals-backup --coverage-html=coverage $FILETOTEST --testdox-html 
${FILETOTEST%.php}-testdox.html --color $FILETOTEST 
+       #$PHPUNIT --bootstrap bootstrap.php --whitelist=../include 
--coverage-html=coverage $FILETOTEST --testdox-html 
${FILETOTEST%.php}-testdox.html --color $FILETOTEST 
 fi
 



reply via email to

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