From a4427bd2d214071b22955b6715b4dc9130b95f09 Mon Sep 17 00:00:00 2001
From: Marc DLL <68746600@users.noreply.github.com>
Date: Mon, 27 Jul 2020 23:58:06 +0200
Subject: [PATCH 1/2] FIX: product stock/reassort list: add hooks
---
htdocs/product/reassort.php | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php
index 6ee13633139..86019c78b00 100644
--- a/htdocs/product/reassort.php
+++ b/htdocs/product/reassort.php
@@ -83,6 +83,9 @@ if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global
$virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs.
}
+// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
+$hookmanager->initHooks(array('productreassortlist'));
+
/*
@@ -121,6 +124,10 @@ $sql.= ' p.fk_product_type, p.tms as datem,';
$sql.= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
$sql.= ' SUM(s.reel) as stock_physique';
if (! empty($conf->global->PRODUCT_USE_UNITS)) $sql.= ', u.short_label as unit_short';
+// Add fields from hooks
+$parameters=array();
+$reshook=$hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
+$sql.=$hookmanager->resPrint;
$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e on s.fk_entrepot = e.rowid AND e.entity IN ('.getEntity('entrepot').')';
@@ -152,8 +159,16 @@ if($catid) $sql.= " AND cp.fk_categorie = ".$catid;
if ($fourn_id > 0) $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id;
// Insert categ filter
if ($search_categ) $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ);
+// Add where from hooks
+$parameters=array();
+$reshook=$hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
+$sql.=$hookmanager->resPrint;
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,";
$sql.= " p.fk_product_type, p.tms, p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock";
+// Add fields from hooks
+$parameters=array();
+$reshook=$hookmanager->executeHooks('printFieldSelect', $parameters); // Note that $action and $object may have been modified by hook
+$sql.=$hookmanager->resPrint;
if ($toolowstock) $sql.= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte";
$sql.= $db->order($sortfield, $sortorder);
@@ -298,6 +313,9 @@ if ($resql)
print '
| ';
print ' | ';
print ' | ';
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
+ print $hookmanager->resPrint;
print '';
$searchpicto=$form->showFilterAndCheckAddButtons(0);
print $searchpicto;
@@ -329,6 +347,10 @@ if ($resql)
print_liste_field_titre('');
print_liste_field_titre("ProductStatusOnSell", $_SERVER["PHP_SELF"], "p.tosell", $param, "", '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("ProductStatusOnBuy", $_SERVER["PHP_SELF"], "p.tobuy", $param, "", '', $sortfield, $sortorder, 'right ');
+ // Hook fields
+ $parameters=array('param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
+ $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
+ print $hookmanager->resPrint;
print_liste_field_titre('');
print "\n";
@@ -393,6 +415,10 @@ if ($resql)
print ' | '.$langs->trans("Movements").' | ';
print ''.$product->LibStatut($objp->statut, 5, 0).' | ';
print ''.$product->LibStatut($objp->tobuy, 5, 1).' | ';
+ // Fields from hook
+ $parameters=array('obj'=>$objp);
+ $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
+ print $hookmanager->resPrint;
print ' | ';
print "\n";
$i++;
From af177f2833202b096c2034221c521729f32c53cc Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Wed, 29 Jul 2020 13:07:02 +0200
Subject: [PATCH 2/2] Update reassort.php
---
htdocs/product/reassort.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php
index c0591e79062..90c616fcd6b 100644
--- a/htdocs/product/reassort.php
+++ b/htdocs/product/reassort.php
@@ -311,8 +311,8 @@ if ($resql)
print ' | ';
print ' | ';
print ' | ';
- $parameters=array();
- $reshook=$hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
+ $parameters = array();
+ $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print '';
$searchpicto = $form->showFilterAndCheckAddButtons(0);
@@ -346,8 +346,8 @@ if ($resql)
print_liste_field_titre("ProductStatusOnSell", $_SERVER["PHP_SELF"], "p.tosell", $param, "", '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("ProductStatusOnBuy", $_SERVER["PHP_SELF"], "p.tobuy", $param, "", '', $sortfield, $sortorder, 'right ');
// Hook fields
- $parameters=array('param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
- $reshook=$hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
+ $parameters = array('param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
+ $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print_liste_field_titre('');
print "\n";
@@ -413,8 +413,8 @@ if ($resql)
print ' | '.$product->LibStatut($objp->statut, 5, 0).' | ';
print ''.$product->LibStatut($objp->tobuy, 5, 1).' | ';
// Fields from hook
- $parameters=array('obj'=>$objp);
- $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
+ $parameters = array('obj'=>$objp);
+ $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
print ' | ';
print "\n";