From 05e09ccc17bd713d5ae2af13c31f79d8c7b00d22 Mon Sep 17 00:00:00 2001 From: altairis-noe Date: Fri, 16 Jul 2021 17:46:21 +0200 Subject: [PATCH 1/3] Filter reassortlot with warehouse tags --- htdocs/product/reassortlot.php | 53 ++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index ea9901a3794..bc93503a3c7 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -6,6 +6,7 @@ * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2016 Ferran Marcet * Copyright (C) 2019 Juanjo Menent + * Copyright (C) 2021 Noé Cendrier * * 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 @@ -72,6 +73,7 @@ $offset = $limit * $page; // Load sale and categ filters $search_sale = GETPOST("search_sale"); $search_categ = GETPOST("search_categ"); +$search_warehouse_categ = GETPOST("search_warehouse_categ"); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = GETPOST("canvas"); @@ -101,6 +103,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $tobuy = ""; $search_sale = ""; $search_categ = ""; + $search_warehouse_categ = ""; $type = ""; $catid = ''; $toolowstock = ''; @@ -132,16 +135,17 @@ $sql .= ' SUM(pb.qty) as stock_physique, COUNT(pb.rowid) as nbinbatchtable'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as ps on p.rowid = ps.fk_product'; // Detail for each warehouse $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e on ps.fk_entrepot = e.rowid'; // Link on unique key +$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_warehouse as cw on e.rowid = cw.fk_warehouse'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = ps.rowid'; // Detail for each lot on each warehouse $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch'; // Link on unique key // We'll need this table joined to the select in order to filter by categ if ($search_categ) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_product as cp"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; } $sql .= " WHERE p.entity IN (".getEntity('product').")"; -if ($search_categ) { - $sql .= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ -} +// if ($search_categ) { +// $sql .= " AND "; // Join for the needed table to filter by categ +// } if ($sall) { $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); } @@ -178,9 +182,13 @@ if ($fourn_id > 0) { $sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".((int) $fourn_id); } // Insert categ filter -if ($search_categ) { +if ($search_categ > 0) { $sql .= " AND cp.fk_categorie = ".((int) $search_categ); } +if ($search_warehouse_categ > 0) { + // $sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_WAREHOUSE, "e.rowid", $search_warehouse_categ); + $sql .= " AND cw.fk_categorie = " . (int) $search_warehouse_categ; +} if ($search_warehouse) { $sql .= natural_search("e.ref", $search_warehouse); } @@ -280,6 +288,9 @@ if ($resql) { if ($search_categ) { $param .= "&search_categ=".urlencode($search_categ); } + if ($search_warehouse_categ) { + $param .= "&search_warehouse_categ=".urlencode($search_warehouse_categ); + } /*if ($eatby) $param.="&eatby=".$eatby; if ($sellby) $param.="&sellby=".$sellby;*/ @@ -303,28 +314,32 @@ if ($resql) { print "
"; } - // Filter on categories + // Filter on product categories $moreforfilter = ''; if (!empty($conf->categorie->enabled)) { - $moreforfilter .= '
'; - $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); - $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ'); - $moreforfilter .= '
'; + $moreforfilter .= ''; + $moreforfilter .= ''.img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); + $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ').''; + + // Filter on warehouse categories + $moreforfilter .= ''.img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); + $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_WAREHOUSE, $search_warehouse_categ, 'search_warehouse_categ').''; + $moreforfilter .= ''; } //$moreforfilter.=$langs->trans("StockTooLow").' '; - if (!empty($moreforfilter)) { - print '
'; - print $moreforfilter; - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - print '
'; - } - print '
'; print ''; + if (!empty($moreforfilter)) { + // print '
'; + print $moreforfilter; + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // print '
'; + } + // Fields title search print ''; From d8551da83f77eab4998f9b732d937dcdb953c427 Mon Sep 17 00:00:00 2001 From: altairis-noe Date: Mon, 19 Jul 2021 09:36:58 +0200 Subject: [PATCH 2/3] correction after review --- htdocs/product/reassortlot.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index bc93503a3c7..751c47fd2d2 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -135,17 +135,16 @@ $sql .= ' SUM(pb.qty) as stock_physique, COUNT(pb.rowid) as nbinbatchtable'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as ps on p.rowid = ps.fk_product'; // Detail for each warehouse $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e on ps.fk_entrepot = e.rowid'; // Link on unique key -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_warehouse as cw on e.rowid = cw.fk_warehouse'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = ps.rowid'; // Detail for each lot on each warehouse $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch'; // Link on unique key // We'll need this table joined to the select in order to filter by categ -if ($search_categ) { +if ($search_categ > 0) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; } +if ($search_warehouse_categ > 0) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_warehouse as cw on e.rowid = cw.fk_warehouse'; +} $sql .= " WHERE p.entity IN (".getEntity('product').")"; -// if ($search_categ) { -// $sql .= " AND "; // Join for the needed table to filter by categ -// } if ($sall) { $sql .= natural_search(array('p.ref', 'p.label', 'p.description', 'p.note'), $sall); } @@ -186,7 +185,6 @@ if ($search_categ > 0) { $sql .= " AND cp.fk_categorie = ".((int) $search_categ); } if ($search_warehouse_categ > 0) { - // $sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_WAREHOUSE, "e.rowid", $search_warehouse_categ); $sql .= " AND cw.fk_categorie = " . (int) $search_warehouse_categ; } if ($search_warehouse) { @@ -285,10 +283,10 @@ if ($resql) { if ($search_sale) { $param .= "&search_sale=".urlencode($search_sale); } - if ($search_categ) { + if ($search_categ > 0) { $param .= "&search_categ=".urlencode($search_categ); } - if ($search_warehouse_categ) { + if ($search_warehouse_categ > 0) { $param .= "&search_warehouse_categ=".urlencode($search_warehouse_categ); } /*if ($eatby) $param.="&eatby=".$eatby; @@ -332,12 +330,10 @@ if ($resql) { print '
'; print '
'; if (!empty($moreforfilter)) { - // print '
'; print $moreforfilter; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - // print '
'; } From fdbef33d9c24e3127a694d6f43c84b1013a44c15 Mon Sep 17 00:00:00 2001 From: altairis-noe Date: Mon, 19 Jul 2021 11:22:41 +0200 Subject: [PATCH 3/3] indet linter --- htdocs/product/reassortlot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index 751c47fd2d2..7558597057f 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -319,7 +319,7 @@ if ($resql) { $moreforfilter .= ''; - // Filter on warehouse categories + // Filter on warehouse categories $moreforfilter .= ''; $moreforfilter .= '';
'.img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_PRODUCT, $search_categ, 'search_categ').''.img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"'); $moreforfilter .= $htmlother->select_categories(Categorie::TYPE_WAREHOUSE, $search_warehouse_categ, 'search_warehouse_categ').'