Bug #0002219: Compatibilité PHP 8.2 , 8.1 , 8.0

This commit is contained in:
sparkyx 2023-02-15 19:41:45 +01:00
parent 034b93b6f4
commit 9e2a63c718
4 changed files with 48 additions and 23 deletions

View file

@ -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;

View file

@ -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

View file

@ -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');
}

View file

@ -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()
{