From 912be1e1bd904fb86c18ca6920460e7c40d2b070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Sun, 17 Mar 2024 13:15:37 +0100 Subject: [PATCH 1/4] fix phan --- htdocs/expensereport/class/paymentexpensereport.class.php | 2 +- htdocs/expensereport/payment/payment.php | 6 +++--- phpstan.neon.dist | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index 5541cdc9ac3..98e4731a04c 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -189,7 +189,7 @@ class PaymentExpenseReport extends CommonObject $totalamount = 0; foreach ($this->amounts as $key => $value) { // How payment is dispatch - $newvalue = price2num($value, 'MT'); + $newvalue = (float) price2num($value, 'MT'); $this->amounts[$key] = $newvalue; $totalamount += $newvalue; } diff --git a/htdocs/expensereport/payment/payment.php b/htdocs/expensereport/payment/payment.php index e1de1f7015b..24895aa3bfa 100644 --- a/htdocs/expensereport/payment/payment.php +++ b/htdocs/expensereport/payment/payment.php @@ -1,7 +1,7 @@ * Copyright (C) 2015 Laurent Destailleur - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2024 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -91,8 +91,8 @@ if ($action == 'add_payment') { foreach ($_POST as $key => $value) { if (substr($key, 0, 7) == 'amount_') { if (GETPOST($key)) { - $amounts[$expensereport->fk_user_author] = price2num(GETPOST($key)); - $total += price2num(GETPOST($key)); + $amounts[$expensereport->fk_user_author] = (float) price2num(GETPOST($key)); + $total += (float) price2num(GETPOST($key)); } } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c354dfd5d84..4bb2cf6eaed 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,7 +9,7 @@ parameters: # minimumNumberOfJobsPerProcess: 2 # default is 2 # buffer: 134217728 # 128 MB # Not documented customRulesetUsed: true - level: 2 + level: 3 fileExtensions: - php paths: From 5e5995731da31314fba14d33b20223ce6cfbd10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Sun, 17 Mar 2024 13:17:51 +0100 Subject: [PATCH 2/4] fix phan --- .../expensereport/class/paymentexpensereport.class.php | 2 +- htdocs/expensereport/payment/payment.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index 98e4731a04c..73fb1025f80 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -193,7 +193,7 @@ class PaymentExpenseReport extends CommonObject $this->amounts[$key] = $newvalue; $totalamount += $newvalue; } - $totalamount = price2num($totalamount); + // $totalamount = (float) price2num($totalamount); // Check parameters if ($totalamount == 0) { diff --git a/htdocs/expensereport/payment/payment.php b/htdocs/expensereport/payment/payment.php index 24895aa3bfa..df91a49f3f7 100644 --- a/htdocs/expensereport/payment/payment.php +++ b/htdocs/expensereport/payment/payment.php @@ -85,14 +85,14 @@ if ($action == 'add_payment') { if (!$error) { $paymentid = 0; - $total = 0; + // $total = 0; // Read possible payments foreach ($_POST as $key => $value) { if (substr($key, 0, 7) == 'amount_') { if (GETPOST($key)) { $amounts[$expensereport->fk_user_author] = (float) price2num(GETPOST($key)); - $total += (float) price2num(GETPOST($key)); + // $total += price2num(GETPOST($key)); } } } @@ -109,8 +109,9 @@ if ($action == 'add_payment') { $payment = new PaymentExpenseReport($db); $payment->fk_expensereport = $expensereport->id; $payment->datep = $datepaid; - $payment->amounts = $amounts; // Tableau de montant - $payment->total = $total; + $payment->amounts = $amounts; // array of amounts + // total is calculated in class + // $payment->total = $total; $payment->fk_typepayment = GETPOSTINT("fk_typepayment"); $payment->num_payment = GETPOST("num_payment", 'alphanohtml'); $payment->note_public = GETPOST("note_public", 'restricthtml'); From 26303dc4d39d69599d23383716c576a74ef7045b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Sun, 17 Mar 2024 13:21:34 +0100 Subject: [PATCH 3/4] fix phan --- htdocs/expensereport/class/paymentexpensereport.class.php | 4 ++-- phpstan.neon.dist | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/expensereport/class/paymentexpensereport.class.php b/htdocs/expensereport/class/paymentexpensereport.class.php index 73fb1025f80..7a9e9171de3 100644 --- a/htdocs/expensereport/class/paymentexpensereport.class.php +++ b/htdocs/expensereport/class/paymentexpensereport.class.php @@ -160,7 +160,7 @@ class PaymentExpenseReport extends CommonObject $this->fk_expensereport = (int) $this->fk_expensereport; } if (isset($this->amount)) { - $this->amount = trim($this->amount); + $this->amount = (float) $this->amount; } if (isset($this->fk_typepayment)) { $this->fk_typepayment = (int) $this->fk_typepayment; @@ -315,7 +315,7 @@ class PaymentExpenseReport extends CommonObject $this->fk_expensereport = (int) $this->fk_expensereport; } if (isset($this->amount)) { - $this->amount = trim($this->amount); + $this->amount = (float) $this->amount; } if (isset($this->fk_typepayment)) { $this->fk_typepayment = (int) $this->fk_typepayment; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 4bb2cf6eaed..c354dfd5d84 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -9,7 +9,7 @@ parameters: # minimumNumberOfJobsPerProcess: 2 # default is 2 # buffer: 134217728 # 128 MB # Not documented customRulesetUsed: true - level: 3 + level: 2 fileExtensions: - php paths: From 049f660ea634dbea48aed0db994c84048f1ad7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Sun, 17 Mar 2024 19:10:40 +0100 Subject: [PATCH 4/4] fix phpstan --- htdocs/compta/tva/class/paymentvat.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/tva/class/paymentvat.class.php b/htdocs/compta/tva/class/paymentvat.class.php index 1c72b1ff444..1776fe56a77 100644 --- a/htdocs/compta/tva/class/paymentvat.class.php +++ b/htdocs/compta/tva/class/paymentvat.class.php @@ -189,7 +189,7 @@ class PaymentVAT extends CommonObject $this->fk_tva = (int) $this->fk_tva; } if (isset($this->amount)) { - $this->amount = trim($this->amount); + $this->amount = (float) $this->amount; } if (isset($this->fk_typepaiement)) { $this->fk_typepaiement = (int) $this->fk_typepaiement; @@ -215,11 +215,11 @@ class PaymentVAT extends CommonObject $totalamount = 0; foreach ($this->amounts as $key => $value) { // How payment is dispatch - $newvalue = price2num($value, 'MT'); + $newvalue = (float) price2num($value, 'MT'); $this->amounts[$key] = $newvalue; $totalamount += $newvalue; } - $totalamount = price2num($totalamount); + // $totalamount = price2num($totalamount); // Check parameters if ($totalamount == 0) { @@ -246,7 +246,7 @@ class PaymentVAT extends CommonObject foreach ($this->amounts as $key => $amount) { $contribid = $key; if (is_numeric($amount) && $amount != 0) { - $amount = price2num($amount); + $amount = (float) price2num($amount); // If we want to closed paid invoices if ($closepaidvat) { @@ -257,8 +257,8 @@ class PaymentVAT extends CommonObject $creditnotes = 0; //$deposits=$contrib->getSumDepositsUsed(); $deposits = 0; - $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); - $remaintopay = price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT'); + $alreadypayed = (float) price2num($paiement + $creditnotes + $deposits, 'MT'); + $remaintopay = (float) price2num($contrib->amount - $paiement - $creditnotes - $deposits, 'MT'); if ($remaintopay == 0) { $result = $contrib->setPaid($user); } else { @@ -374,7 +374,7 @@ class PaymentVAT extends CommonObject $this->fk_tva = (int) $this->fk_tva; } if (isset($this->amount)) { - $this->amount = trim($this->amount); + $this->amount = (float) $this->amount; } if (isset($this->fk_typepaiement)) { $this->fk_typepaiement = (int) $this->fk_typepaiement;