From 1325b249b0473d74135f4e489ee26e00075ddb08 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 1 Apr 2025 09:36:36 +0200 Subject: [PATCH] Clean code to fix some phan warnings --- ChangeLog | 1 + htdocs/api/class/api.class.php | 1 - htdocs/core/class/commonobject.class.php | 17 ++-- htdocs/core/class/commonobjectline.class.php | 10 +++ .../doc/pdf_standard_myobject.modules.php | 84 ++++++++++--------- 5 files changed, 60 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index ccc028cf949..968f03b5689 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,7 @@ The following changes may create regressions for some external modules, but were * The behavior of constant STOCK_ALLOW_NEGATIVE_TRANSFER has been reversed. It has been renamed to STOCK_DISALLOW_NEGATIVE_TRANSFER. * Method Categoie->getObjectsInCateg() is deprecated. Try by using instead getListForItem() or containing(). * Global variables $bctag, $conffiletoshowshort, $type2label has been removed. +* Deprecatedproperty ->fk_departement that was replaced by ->state_id has been completely removed. * If you setup the API to update multicurrency rate from internet, you may need to re-enter your API key (so API key will be crypted in database). diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index d707562f3b8..640f07376b1 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -273,7 +273,6 @@ class DolibarrApi unset($object->country); unset($object->state); unset($object->state_code); - unset($object->fk_departement); unset($object->departement); unset($object->departement_code); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6b12db559a5..cc9bde1ce21 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -391,12 +391,6 @@ abstract class CommonObject */ public $state_id; - /** - * @var int State ID - * @deprecated Use $state_id. We can remove this property when the field 'fk_departement' have been renamed into 'state_id' in all tables - */ - public $fk_departement; - /** * @var string State code * @see getFullAddress(), $state @@ -529,11 +523,6 @@ abstract class CommonObject */ public $multicurrency_total_tva; - /** - * @var float Multicurrency total amount including taxes (TTC = "Toutes Taxes Comprises" in French) - */ - public $multicurrency_total_ttc; - /** * @var float|string Multicurrency total localtax1 */ @@ -544,6 +533,12 @@ abstract class CommonObject */ public $multicurrency_total_localtax2; // not in database + /** + * @var float Multicurrency total amount including taxes (TTC = "Toutes Taxes Comprises" in French) + */ + public $multicurrency_total_ttc; + + /** * @var ?string * @see SetDocModel() diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 2d846af6547..1cc807a21e6 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -268,6 +268,16 @@ abstract class CommonObjectLine extends CommonObject */ public $multicurrency_total_tva; + /** + * @var float|string Multicurrency total localtax1 + */ + public $multicurrency_total_localtax1; // not in database + + /** + * @var float|string Multicurrency total localtax2 + */ + public $multicurrency_total_localtax2; // not in database + /** * @var float Multicurrency total with tax */ diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php index 9dda3480a4d..7a3e74595ff 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php @@ -666,52 +666,54 @@ class pdf_standard_myobject extends ModelePDFMyObject $sign = 1; - // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva - $prev_progress = $object->lines[$i]->get_prev_progress($object->id); - if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation - if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) { - $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; + // Collection of totals by value of VAT in $this->tva["taux"]=total_tva + if ($object->lines instanceof CommonInvoiceLine) { + $prev_progress = $object->lines[$i]->get_prev_progress($object->id); + if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { // Compute progress from previous situation + if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) { + $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; + } else { + $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; + } } else { - $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; + if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) { + $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva; + } else { + $tvaligne = $sign * $object->lines[$i]->total_tva; + } } - } else { - if (isModEnabled("multicurrency") && $object->multicurrency_tx != 1) { - $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva; - } else { - $tvaligne = $sign * $object->lines[$i]->total_tva; + + $localtax1ligne = $object->lines[$i]->total_localtax1; + $localtax2ligne = $object->lines[$i]->total_localtax2; + $localtax1_rate = $object->lines[$i]->localtax1_tx; + $localtax2_rate = $object->lines[$i]->localtax2_tx; + $localtax1_type = $object->lines[$i]->localtax1_type; + $localtax2_type = $object->lines[$i]->localtax2_type; + + $vatrate = (string) $object->lines[$i]->tva_tx; + + // Retrieve type from database for backward compatibility with old records + if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined + && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax + $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } - } - $localtax1ligne = $object->lines[$i]->total_localtax1; - $localtax2ligne = $object->lines[$i]->total_localtax2; - $localtax1_rate = $object->lines[$i]->localtax1_tx; - $localtax2_rate = $object->lines[$i]->localtax2_tx; - $localtax1_type = $object->lines[$i]->localtax1_type; - $localtax2_type = $object->lines[$i]->localtax2_type; - - $vatrate = (string) $object->lines[$i]->tva_tx; - - // Retrieve type from database for backward compatibility with old records - if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined - && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax - $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; - $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; - } - - // retrieve global local tax - if ($localtax1_type && $localtax1ligne != 0) { - if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) { - $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne; - } else { - $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne; + // retrieve global local tax + if ($localtax1_type && $localtax1ligne != 0) { + if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) { + $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne; + } else { + $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne; + } } - } - if ($localtax2_type && $localtax2ligne != 0) { - if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) { - $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne; - } else { - $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne; + if ($localtax2_type && $localtax2ligne != 0) { + if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) { + $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne; + } else { + $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne; + } } }