From 82a5e780205ca7d7818922b0788a6e13685a676e Mon Sep 17 00:00:00 2001 From: thibdrev Date: Wed, 24 Jan 2024 21:01:04 +0100 Subject: [PATCH 1/5] qual: phpstan for htdocs/compta/facture/class/facture.class.php --- htdocs/compta/facture/class/facture.class.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e9eb5ec753e..85f19b5f5f2 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4424,7 +4424,7 @@ class Facture extends CommonInvoice * Set percent discount * * @param User $user User that set discount - * @param double $remise Discount + * @param float $remise Discount * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int Return integer <0 if KO, >0 if OK * @deprecated remise_percent is a deprecated field for object parent @@ -4433,18 +4433,18 @@ class Facture extends CommonInvoice { // Clean parameters if (empty($remise)) { - $remise = 0; + $remise = 0.0; } if ($user->hasRight('facture', 'creer')) { - $remise = price2num($remise, 2); + $remise = (float) price2num($remise, 2); $error = 0; $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; - $sql .= ' SET remise_percent = '.((float) $remise); + $sql .= ' SET remise_percent = '.$remise; $sql .= " WHERE rowid = ".((int) $this->id); $sql .= ' AND fk_statut = '.self::STATUS_DRAFT; @@ -6295,7 +6295,8 @@ class FactureLigne extends CommonInvoiceLine // if buy price not defined, define buyprice as configured in margin admin if ($this->pa_ht == 0 && $pa_ht_isemptystring) { - if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { + ($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) + if ($result < 0) { return $result; } else { $this->pa_ht = $result; @@ -6734,7 +6735,7 @@ class FactureLigne extends CommonInvoiceLine * * @param int $invoiceid Invoice id * @param bool $include_credit_note Include credit note or not - * @return int >= 0 + * @return float|int Reurrn previous situation percent, 0 or -1 if error */ public function get_prev_progress($invoiceid, $include_credit_note = true) { From 3f7e51f4489659fa7e708ed365bd4c56a7ec4df6 Mon Sep 17 00:00:00 2001 From: thibdrev Date: Wed, 24 Jan 2024 21:04:02 +0100 Subject: [PATCH 2/5] Update commonobject.class.php - defineBuyPrice() return type --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index fb41245579d..6dfaffff681 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8964,7 +8964,7 @@ abstract class CommonObject * @param float $unitPrice Product unit price * @param float $discountPercent Line discount percent * @param int $fk_product Product id - * @return float Return integer <0 if KO, buyprice if OK + * @return float|int Return buy price if OK, integer <0 if KO */ public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) { From 53c296caa81bf5a2fec074b16f92b276235e6c88 Mon Sep 17 00:00:00 2001 From: thibdrev Date: Wed, 24 Jan 2024 21:27:22 +0100 Subject: [PATCH 3/5] typo --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 85f19b5f5f2..6cceb507144 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -6295,7 +6295,7 @@ class FactureLigne extends CommonInvoiceLine // if buy price not defined, define buyprice as configured in margin admin if ($this->pa_ht == 0 && $pa_ht_isemptystring) { - ($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) + $result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product); if ($result < 0) { return $result; } else { From c8e11e114562c3b0240da2f1e482938ac56243db Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Jan 2024 02:26:26 +0100 Subject: [PATCH 4/5] Update facture.class.php --- htdocs/compta/facture/class/facture.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 6cceb507144..33b8952e9f0 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4443,10 +4443,10 @@ class Facture extends CommonInvoice $this->db->begin(); - $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; - $sql .= ' SET remise_percent = '.$remise; + $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; + $sql .= " SET remise_percent = ".((float) $remise); $sql .= " WHERE rowid = ".((int) $this->id); - $sql .= ' AND fk_statut = '.self::STATUS_DRAFT; + $sql .= " AND fk_statut = ".((int) self::STATUS_DRAFT); dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); From 06a90b5d1b053fa2f725034298dc1e0c60b41920 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 26 Jan 2024 02:27:09 +0100 Subject: [PATCH 5/5] Update facture.class.php --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 33b8952e9f0..b1047c84903 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4433,7 +4433,7 @@ class Facture extends CommonInvoice { // Clean parameters if (empty($remise)) { - $remise = 0.0; + $remise = 0; } if ($user->hasRight('facture', 'creer')) {