diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index 3080bb1262b..4903231365c 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -287,7 +287,7 @@ if (!empty($search_fk_warehouse)) { } // Add fields from hooks $parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; @@ -296,7 +296,7 @@ if (!empty($search_fk_warehouse)) { } // Add fields from hooks $parameters = array(); -$reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters, $object, $action); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; if ($productid > 0) { @@ -314,8 +314,24 @@ if ($search_ref) { if ($search_nom) { $sql .= natural_search('p.label', $search_nom); } -$sql .= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price, p.pmp, p.price_ttc, p.price_base_type, p.fk_product_type, p.desiredstock, p.seuil_stock_alerte,'; -$sql .= ' p.tms, p.duration, p.tobuy, p.stock'; + +$sqlGroupBy = ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price, p.pmp, p.price_ttc, p.price_base_type, p.fk_product_type, p.desiredstock, p.seuil_stock_alerte,'; +$sqlGroupBy .= ' p.tms, p.duration, p.tobuy, p.stock'; + +$parameters = array('sqlGroupBy' => $sqlGroupBy); +$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + +if ($reshook == 0) { + // Allows the hook to add things (old behavior) + $sql .= $hookmanager->resPrint; + // Allows the hook to REPLACE the clause (new behavior) + if (!empty($hookmanager->resArray['sqlGroupBy'])) { + $sqlGroupBy = $hookmanager->resArray['sqlGroupBy']; + } +} + +$sql .= $sqlGroupBy; + // Add where from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook