clean code (#36170)

* clean code

* Update bom.class.php

* Update commondocgenerator.class.php

* fix

* fix

* fix

* fix

* fix

* fix

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Frédéric FRANCE 2025-11-09 01:19:31 +01:00 committed by GitHub
parent ca0052e82d
commit 9491d880cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 33 deletions

View file

@ -404,18 +404,23 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Confirmation of validation
if ($action == 'validate') {
$error = 0;
$numref = '';
// We check that object has a temporary ref
$ref = substr($object->ref, 1, 4);
if ($ref == 'PROV') {
$object->fetch_product();
$numref = $object->getNextNumRef($object->product);
$res = $object->fetch_product();
if ($res > 0 && $object->product instanceof Product) {
$numref = $object->getNextNumRef($object->product); // @phan-suppress-current-line PhanTypeMismatchArgumentNullable
} else {
$error++;
}
} else {
$numref = (string) $object->ref;
}
$text = $langs->trans('ConfirmValidateBom', $numref);
/*if (isModEnabled('notification'))
{
/*if (isModEnabled('notification')) {
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
$notify = new Notify($db);
$text .= '<br>';
@ -431,15 +436,18 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
);
}
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
if (!$error) {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Validate'), $text, 'confirm_validate', $formquestion, 0, 1, 220);
} else {
setEventMessage($langs->trans('Error'), 'errors');
$action = '';
}
}
// Confirmation of closing
if ($action == 'close') {
$text = $langs->trans('ConfirmCloseBom', $object->ref);
/*if (isModEnabled('notification'))
{
/*if (isModEnabled('notification')) {
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
$notify = new Notify($db);
$text .= '<br>';
@ -462,8 +470,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Confirmation of reopen
if ($action == 'reopen') {
$text = $langs->trans('ConfirmReopenBom', $object->ref);
/*if (isModEnabled('notification'))
{
/*if (isModEnabled('notification')) {
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php';
$notify = new Notify($db);
$text .= '<br>';
@ -524,12 +531,10 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Thirdparty
$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $soc->getNomUrl(1);
// Project
if (isModEnabled('project'))
{
if (isModEnabled('project')) {
$langs->load("projects");
$morehtmlref.='<br>'.$langs->trans('Project') . ' ';
if ($permissiontoadd)
{
if ($permissiontoadd) {
if ($action != 'classify')
$morehtmlref.='<a class="editfielda" href="' . dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true) . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
if ($action == 'classify') {

View file

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2019 Maxime Kohlhaas <maxime@atm-consulting.fr>
* Copyright (C) 2020-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2020-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2022 Christian Humpel <christian.humpel@live.com>
* Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
*
@ -620,17 +620,21 @@ class Boms extends DolibarrApi
private function checkRefNumbering()
{
$ref = substr($this->bom->ref, 1, 4);
if ($this->bom->status > 0 && $ref == 'PROV') {
if ($this->bom->status > BOM::STATUS_DRAFT && $ref == 'PROV') {
throw new RestException(400, "Wrong naming scheme '(PROV%)' is only allowed on 'DRAFT' status. For automatic increment use 'auto' on the 'ref' field.");
}
if (strtolower($this->bom->ref) == 'auto') {
if (empty($this->bom->id) && $this->bom->status == 0) {
if (empty($this->bom->id) && $this->bom->status == BOM::STATUS_DRAFT) {
$this->bom->ref = ''; // 'ref' will auto incremented with '(PROV' + newID + ')'
} else {
$this->bom->fetch_product();
$numref = $this->bom->getNextNumRef($this->bom->product);
$this->bom->ref = $numref;
$res = $this->bom->fetch_product();
if ($res > 0 && $this->bom->product instanceof Product) {
$numref = $this->bom->getNextNumRef($this->bom->product); // @phan-suppress-current-line PhanTypeMismatchArgumentNullable
$this->bom->ref = $numref;
} else {
throw new RestException(400, "Error when generating automatic increment on the 'ref' field.");
}
}
}
}

View file

@ -1,9 +1,9 @@
<?php
/* Copyright (C) 2019 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
* Copyright (C) 2023 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
/* Copyright (C) 2019 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
* Copyright (C) 2023 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -67,7 +67,7 @@ class BOM extends CommonObject
public $picto = 'bom';
/**
* @var Product Object product of the BOM
* @var ?Product Object product of the BOM
*/
public $product;
@ -940,7 +940,11 @@ class BOM extends CommonObject
// Define new ref
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$this->fetch_product();
$res = $this->fetch_product();
if ($res < 0 || !is_object($this->product)) {
$this->db->rollback();
return -1;
}
$num = $this->getNextNumRef($this->product);
} else {
$num = (string) $this->ref;

View file

@ -1373,6 +1373,8 @@ if ($type == Categorie::TYPE_FICHINTER) {
if ($fichinters < 0) {
dol_print_error($db, $object->error, $object->errors);
} else {
/** @var Fichinter[] $fichinters */
'@phan-var-force Fichinter[] $fichinters';
// Form to add record into a category
if ($showclassifyform) {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formintervention.class.php';
@ -1460,6 +1462,8 @@ if ($type == Categorie::TYPE_ORDER) {
if ($objects < 0) {
dol_print_error($db, $object->error, $object->errors);
} else {
/** @var Commande[] $objects */
'@phan-var-force Commande[] $objects';
// Form to add record into a category
$showclassifyform = $user->hasRight('order', 'write');
if ($showclassifyform) {

View file

@ -476,7 +476,7 @@ abstract class CommonDocGenerator
* Define array with couple substitution key => substitution value
* For example {company_name}, {company_name_alias}
*
* @param Societe $object Object
* @param ?Societe $object Object
* @param Translate $outputlangs Language object for output
* @param string $array_key Name of the key for return array
* @return array<string,mixed> Array of substitution key->code

View file

@ -304,19 +304,19 @@ abstract class CommonObject
public $contact_id;
/**
* @var Societe|null A related thirdparty object
* @var ?Societe A related thirdparty object
* @see fetch_thirdparty()
*/
public $thirdparty;
/**
* @var User A related user
* @var ?User A related user
* @see fetch_user()
*/
public $user;
/**
* @var Product Populated by fetch_product()
* @var ?Product Populated by fetch_product()
* @see fetch_product()
*/
public $product;

View file

@ -2,7 +2,7 @@
/* Copyright (C) 2018 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2023 Alexandre Janniaux <alexandre.janniaux@gmail.com>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by