From 63e929d59c55fa7e4997aceec947cd02e95e43d1 Mon Sep 17 00:00:00 2001 From: William Mead Date: Mon, 22 Jan 2024 12:38:29 +0100 Subject: [PATCH] Added type casting. Cleaned usage of defineBuyPrice. --- htdocs/contrat/class/contrat.class.php | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index af33d41ec37..251589d3d37 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -965,9 +965,9 @@ class Contrat extends CommonObject // Now set the global properties on contract not stored into database. $this->nbofservices = count($this->lines); - $this->total_ttc = price2num($total_ttc); - $this->total_tva = price2num($total_vat); - $this->total_ht = price2num($total_ht); + $this->total_ttc = (float) price2num($total_ttc); + $this->total_tva = (float) price2num($total_vat); + $this->total_ht = (float) price2num($total_ht); return $this->lines; } @@ -1586,8 +1586,9 @@ class Contrat extends CommonObject // if buy price not defined, define buyprice as configured in margin admin if ($pa_ht == 0) { - if (($result = $this->defineBuyPrice($pu_ht, $remise_percent, $fk_product)) < 0) { - return $result; + $result = $this->defineBuyPrice($pu_ht, $remise_percent, $fk_product); + if ($result < 0) { + return -1; } else { $pa_ht = $result; } @@ -1783,8 +1784,9 @@ class Contrat extends CommonObject // if buy price not defined, define buyprice as configured in margin admin if ($pa_ht == 0) { - if (($result = $this->defineBuyPrice($pu, $remise_percent)) < 0) { - return $result; + $result = $this->defineBuyPrice($pu, $remise_percent); + if ($result < 0) { + return -1; } else { $pa_ht = $result; } @@ -3430,11 +3432,11 @@ class ContratLigne extends CommonObjectLine $this->fk_remise_except = (int) $this->fk_remise_except; $this->subprice = price2num($this->subprice); $this->price_ht = price2num($this->price_ht); - $this->total_ht = trim($this->total_ht); - $this->total_tva = trim($this->total_tva); - $this->total_localtax1 = trim($this->total_localtax1); - $this->total_localtax2 = trim($this->total_localtax2); - $this->total_ttc = trim($this->total_ttc); + $this->total_ht = (float) trim($this->total_ht); + $this->total_tva = (float) trim($this->total_tva); + $this->total_localtax1 = (float) trim($this->total_localtax1); + $this->total_localtax2 = (float) trim($this->total_localtax2); + $this->total_ttc = (float) trim($this->total_ttc); $this->info_bits = trim($this->info_bits); $this->fk_user_author = (int) $this->fk_user_author; $this->fk_user_ouverture = (int) $this->fk_user_ouverture; @@ -3496,8 +3498,9 @@ class ContratLigne extends CommonObjectLine // if buy price not defined, define buyprice as configured in margin admin if ($this->pa_ht == 0) { - if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { - return $result; + $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product); + if ($result < 0) { + return -1; } else { $this->pa_ht = $result; }