Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions class/actions_subtotal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,12 @@ function beforePDFCreation($parameters=array(), &$object, &$action)
*/
global $pdf,$conf, $langs;

// Guard: ignore non-commercial objects (e.g., equipement alarm/video) to avoid incompatibilities
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

définition de la liste $allowedElements en dur à 3 endroits différents (beforePDFCreation, afterPDFCreation, defineColumnField).
Si demain on doit ajouter reception ou un autre objet, il faudra modifier 3 blocs de code

Copy link
Contributor

@atm-jpb atm-jpb Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le mieux est de passer par la classe Tsubtotal

/**
* List of Dolibarr elements compatible with Subtotal logic
* @var array
*/
public const ALLOWED_COMMERCIAL_ELEMENTS = array(
'propal',
'commande',
'facture',
'order_supplier',
'invoice_supplier',
'supplier_proposal',
'shipping',
'delivery'
); et de faire un appel dans ce genre là : if (empty($object->element) || !in_array($object->element, TSubtotal::ALLOWED_COMMERCIAL_ELEMENTS, true)) {
return 0;
}

$allowedElements = array('propal','commande','facture','order_supplier','invoice_supplier','supplier_proposal','shipping','delivery');
if (empty($object->element) || !in_array($object->element, $allowedElements, true)) {
return 0;
}

if (TSubtotal::showQtyForObject($object) === true) {
$this->subtotal_sum_qty_enabled = true;
$this->subtotal_show_qty_by_default = true;
Expand Down Expand Up @@ -3810,6 +3816,12 @@ function afterPDFCreation($parameters, &$pdf, &$action, $hookmanager)

$object = $parameters['object'];

// Guard: ignore non-commercial objects
$allowedElements = array('propal','commande','facture','order_supplier','invoice_supplier','supplier_proposal','shipping','delivery');
if (empty($object->element) || !in_array($object->element, $allowedElements, true)) {
return 0;
}

if ((getDolGlobalString('SUBTOTAL_PROPAL_ADD_RECAP') && $object->element == 'propal') || (getDolGlobalString('SUBTOTAL_COMMANDE_ADD_RECAP') && $object->element == 'commande') || (getDolGlobalString('SUBTOTAL_INVOICE_ADD_RECAP') && $object->element == 'facture'))
{
if (GETPOST('subtotal_add_recap', 'none')) {
Expand Down Expand Up @@ -4088,6 +4100,12 @@ function handleExpeditionTitleAndTotal($parameters, &$object, &$action, $hookman
*/
public function defineColumnField($parameters, &$pdfDoc, &$action, $hookmanager)
{
// Guard: ignore non-commercial objects
if (empty($parameters['object']) || empty($parameters['object']->element)) return 0;
$allowedElements = array('propal','commande','facture','order_supplier','invoice_supplier','supplier_proposal','shipping','delivery');
if (!in_array($parameters['object']->element, $allowedElements, true)) {
return 0;
}

// If this model is column field compatible it will add info to change subtotal behavior
$parameters['object']->context['subtotalPdfModelInfo']->cols = $pdfDoc->cols;
Expand All @@ -4100,8 +4118,8 @@ public function defineColumnField($parameters, &$pdfDoc, &$action, $hookmanager)
$parameters['object']->context['subtotalPdfModelInfo']->page_hauteur = $pdfDoc->page_hauteur;
$parameters['object']->context['subtotalPdfModelInfo']->format = $pdfDoc->format;
if (property_exists($pdfDoc, 'context') && array_key_exists('subtotalPdfModelInfo', $pdfDoc->context) && is_object($pdfDoc->context['subtotalPdfModelInfo'])) {
$parameters['object']->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle;
$parameters['object']->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle;
$parameters['object']->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultTitlesFieldsStyle;
$parameters['object']->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle = $pdfDoc->context['subtotalPdfModelInfo']->defaultContentsFieldsStyle;
}
return 0;
}
Expand Down