mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-09 09:22:36 +01:00
Fix : Add 'printFieldListGroupBy' hook to stockatdate.php for module flexibility (#35996)
* Refactor stock SQL query logic to enhance readability, support hook extensibility, and maintain DRY principles. * Pass `$object` and `$action` to hookmanager in stock listing queries for improved hook extensibility.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user