[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 17/23: Bug #0002219: Compatibilité PHP 8.2 ,
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 17/23: Bug #0002219: Compatibilité PHP 8.2 , 8.1 , 8.0 |
Date: |
Sun, 26 Feb 2023 14:47:30 -0500 (EST) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 9e2a63c718e4ed0df9c71ec2dab316086ce13956
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Wed Feb 15 19:41:45 2023 +0100
Bug #0002219: Compatibilité PHP 8.2 , 8.1 , 8.0
---
include/class/document.class.php | 41 +++++++++++-----------
include/lib/ac_common.php | 25 +++++++++++--
.../class/acc_ledger_history_purchase.Test.php | 2 +-
unit-test/include/lib/ac_commonTest.php | 3 ++
4 files changed, 48 insertions(+), 23 deletions(-)
diff --git a/include/class/document.class.php b/include/class/document.class.php
index 51a4b2b86..d8fbf5c6e 100644
--- a/include/class/document.class.php
+++ b/include/class/document.class.php
@@ -1165,8 +1165,8 @@ class Document
$oTva=new Acc_Tva($this->db, $p_array[$tva]);
if ($oTva->load()==-1)
return "";
- $r=round($p_array[$price], 2)*$oTva->get_parameter('rate');
- $r=round($r, 2);
+ $r=noalyss_round($p_array[$price],
2)*$oTva->get_parameter('rate');
+ $r=noalyss_round($r, 2);
break;
case 'VEN_ART_TVAC':
@@ -1184,11 +1184,11 @@ class Document
$tva=new Acc_Tva($this->db,
$p_array['e_march'.$this->counter.'_tva_id']);
if ($tva->load()==-1)
{
- $r=round($p_array[$price], 2);
+ $r=noalyss_round($p_array[$price], 2);
}
else
{
-
$r=round($p_array[$price]*$tva->get_parameter('rate')+$p_array[$price], 2);
+
$r=noalyss_round($p_array[$price]*$tva->get_parameter('rate')+$p_array[$price],
2);
}
break;
@@ -1213,8 +1213,8 @@ class Document
if
($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0||noalyss_strlentrim($p_array['e_march'.$this->counter.'_price'])==0||noalyss_strlentrim($p_array['e_quant'.$this->counter])==0)
return "";
bcscale(4);
- $r=bcmul($p_array[$id], $p_array[$quant]);
- $r=round($r, 2);
+ $r=noalyss_bcmul($p_array[$id], $p_array[$quant]);
+ $r=noalyss_round($r, 2);
break;
case 'VEN_TVAC':
@@ -1233,13 +1233,13 @@ class Document
bcscale(4);
// if TVA not exist
if (!isset($p_array[$id]))
- $r=bcmul($p_array[$price], $p_array[$quant]);
+ $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
else
{
- $r=bcmul($p_array[$price], $p_array[$quant]);
- $r=bcadd($r, $p_array[$id]);
+ $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
+ $r=noalyss_bcadd($r, $p_array[$id]);
}
- $r=round($r, 2);
+ $r=noalyss_round($r, 2);
return $r;
break;
@@ -1260,10 +1260,10 @@ class Document
noalyss_strlentrim($p_array[$qt])==0||
$p_array[$qt]==0||$p_array[$sell]==0)
continue;
- $tmp1=bcmul($p_array[$sell], $p_array[$qt]);
- $sum=bcadd($sum, $tmp1);
+ $tmp1=noalyss_bcmul($p_array[$sell], $p_array[$qt]);
+ $sum=noalyss_bcadd($sum, $tmp1);
}
- $r=round($sum, 2);
+ $r=noalyss_round($sum, 2);
break;
case 'TOTAL_VEN_TVAC':
if (!isset($p_array["nb_item"]))
@@ -1279,15 +1279,16 @@ class Document
{
$tva_amount=$p_array[$tva];
}
+
$sell=$p_array['e_march'.$i.'_price'];
$qt=$p_array['e_quant'.$i];
- $tot=bcmul($sell, $qt);
- $tva_amount=round($tva_amount,2);
- $tot=round($tot,2);
- $tot=bcadd($tot, $tva_amount);
- $sum=bcadd($sum, $tot);
+ $tot=noalyss_bcmul($sell, $qt);
+ $tva_amount=noalyss_round($tva_amount,2);
+ $tot=noalyss_round($tot,2);
+ $tot=noalyss_bcadd($tot, $tva_amount);
+ $sum=noalyss_bcadd($sum, $tot??0);
}
- $r=round($sum, 2);
+ $r=noalyss_round($sum??0, 2);
break;
case 'TOTAL_TVA':
@@ -1305,7 +1306,7 @@ class Document
$tva_amount=($tva_amount=="")?0:$tva_amount;
}
$sum+=$tva_amount;
- $sum=round($sum, 2);
+ $sum=noalyss_round($sum, 2);
}
$r=$sum;
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index c7ed8dd2d..1268bebda 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -1403,7 +1403,14 @@ function is_msie()
*/
function record_log($p_message)
{
- error_log("noalyss".var_export($p_message,true),0);
+ if ( gettype ($p_message) == "object" &&
method_exists($p_message,"getTraceAsString") == 1) {
+
+ error_log("noalyss exception ".$p_message->getMessage(),0);
+ error_log("noalyss exception".$p_message->getTraceAsString(),0);
+ } else {
+ error_log("noalyss".var_export($p_message,true),0);
+
+ }
error_log("noalyss GET [".json_encode($_GET,0,10)."]");
error_log("_POST [".json_encode($_POST,0,10)."]",0);
}
@@ -1473,7 +1480,9 @@ function generate_random_string($p_length)
{
$string="";
$chaine="abcdefghijklmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY0123456789*/+-=";
- srand((float) microtime(true)*1020030);
+ $microtime=microtime(true)*microtime(true)*100;
+ srand(0);
+ srand((int)$microtime);
for ($i=0; $i<$p_length; $i++)
{
$string .= $chaine[rand()%strlen($chaine)];
@@ -1618,6 +1627,18 @@ function noalyss_strip_tags($p_string)
if ($p_string===null) return "";
return strip_tags($p_string);
}
+function noalyss_bcmul($p_first,$p_second)
+{
+ $p_first=(empty($p_first))?0:$p_first;
+ $p_second=(empty($p_second))?0:$p_second;
+ return bcmul($p_first??0,$p_second??0);
+}
+function noalyss_round($p_first,$p_second)
+{
+ $p_first=(empty($p_first))?0:$p_first;
+ $p_second=(empty($p_second))?0:$p_second;
+ return round($p_first??0,$p_second??0);
+}
/**
* to avoid deprecated in PHP8.1 : explode cannot use a null
diff --git a/unit-test/include/class/acc_ledger_history_purchase.Test.php
b/unit-test/include/class/acc_ledger_history_purchase.Test.php
index 8d5ed6988..5781dff72 100644
--- a/unit-test/include/class/acc_ledger_history_purchase.Test.php
+++ b/unit-test/include/class/acc_ledger_history_purchase.Test.php
@@ -39,7 +39,7 @@ class Acc_Ledger_History_PurchaseTest extends TestCase
*/
protected function setUp():void
{
- include 'global.php';
+ include DIRTEST.'/global.php';
global $g_connection;
$this->object=new Acc_Ledger_History_Purchase($g_connection, [3], 92,
131, 'L');
}
diff --git a/unit-test/include/lib/ac_commonTest.php
b/unit-test/include/lib/ac_commonTest.php
index 97646ca4b..10483089a 100644
--- a/unit-test/include/lib/ac_commonTest.php
+++ b/unit-test/include/lib/ac_commonTest.php
@@ -296,6 +296,9 @@ class Ac_CommonTest extends TestCase
$this->assertEquals(8,strlen(generate_random_string(8)));
$this->assertEquals(12,strlen(generate_random_string(12)));
$this->assertEquals(16,strlen(generate_random_string(16)));
+ $generate=generate_random_string(12);
+ $generateOther=generate_random_string(12);
+ $this->assertNotEquals($generate,$generateOther , __FUNCTION__.'
Generate 2 in a row the same string');
}
function testDatabase_Escape_String()
{
- [Noalyss-commit] [noalyss] 10/23: Color : waiting box experiment, (continued)
- [Noalyss-commit] [noalyss] 10/23: Color : waiting box experiment, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 12/23: manage table : the TR attribute ctl_pk_id is not set when inserting new Row, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 13/23: improve logo, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 15/23: Waiting box look, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 20/23: php81, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 02/23: Fix cosmetic, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 07/23: manage table : the TR attribute ctl_pk_id is not set when inserting new Row, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 08/23: Merge branch 'master' into devel, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 05/23: missing semi-colon, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 14/23: Waiting box, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 17/23: Bug #0002219: Compatibilité PHP 8.2 , 8.1 , 8.0,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 19/23: Improve DEBUG, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 03/23: Fix CFGTVA : id cannot be a float, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 01/23: Last detail : logo , fix unit test file, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 11/23: missing semi-colon, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 18/23: Improve DEBUG, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 22/23: Merge branch 'devel', Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 23/23: Documentation and CSS, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 16/23: Bug : date for payment incorrect, Dany De Bontridder, 2023/02/26
- [Noalyss-commit] [noalyss] 21/23: DOCUMENT : generate : new tag = NOTE, Dany De Bontridder, 2023/02/26