2006-12-02 21:12:50 +01:00
< ? php
2015-05-23 18:52:31 +02:00
/* Copyright ( C ) 2001 - 2006 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2015 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2018 Regis Houssin < regis . houssin @ inodbox . com >
2015-05-23 18:52:31 +02:00
* Copyright ( C ) 2013 Cédric Salvador < csalvador @ gpcsolutions . fr >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2019-05-11 16:53:16 +02:00
* Copyright ( C ) 2019 Juanjo Menent < jmenent @ 2 byte . es >
2006-12-02 21:12:50 +01:00
*
* 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-12-02 21:12:50 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2006-12-02 21:12:50 +01:00
*/
/**
2009-01-10 01:44:38 +01:00
* \file htdocs / product / reassort . php
* \ingroup produit
2011-01-10 21:46:21 +01:00
* \brief Page to list stocks
2009-01-10 01:44:38 +01:00
*/
2006-12-02 21:12:50 +01:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2016-04-25 15:31:49 +02:00
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php' ;
2006-12-02 21:12:50 +01:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
$langs -> loadLangs ( array ( 'products' , 'stocks' ));
2006-12-02 21:12:50 +01:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2020-04-10 10:59:32 +02:00
$sref = GETPOST ( " sref " , 'alpha' );
$snom = GETPOST ( " snom " , 'alpha' );
$sall = trim (( GETPOST ( 'search_all' , 'alphanohtml' ) != '' ) ? GETPOST ( 'search_all' , 'alphanohtml' ) : GETPOST ( 'sall' , 'alphanohtml' ));
2022-01-25 10:00:33 +01:00
$type = GETPOSTISSET ( 'type' ) ? GETPOST ( 'type' , 'int' ) : Product :: TYPE_PRODUCT ;
2020-04-10 10:59:32 +02:00
$search_barcode = GETPOST ( " search_barcode " , 'alpha' );
$toolowstock = GETPOST ( 'toolowstock' );
2012-07-24 17:52:46 +02:00
$tosell = GETPOST ( " tosell " );
$tobuy = GETPOST ( " tobuy " );
2019-01-27 11:55:16 +01:00
$fourn_id = GETPOST ( " fourn_id " , 'int' );
2021-10-23 19:09:23 +02:00
$sbarcode = GETPOST ( " sbarcode " , 'int' );
2022-01-25 10:00:33 +01:00
$search_stock_physique = GETPOST ( 'search_stock_physique' , 'alpha' );
2006-12-02 21:12:50 +01:00
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 14:25:17 +01:00
if ( empty ( $page ) || $page < 0 ) {
$page = 0 ;
}
if ( ! $sortfield ) {
$sortfield = " p.ref " ;
}
if ( ! $sortorder ) {
$sortorder = " ASC " ;
}
2019-11-14 12:09:15 +01:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2021-02-26 14:25:17 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2019-11-14 12:09:15 +01:00
$offset = $limit * $page ;
2006-12-02 21:12:50 +01:00
2011-02-20 17:20:22 +01:00
// Load sale and categ filters
$search_sale = GETPOST ( " search_sale " );
2022-01-25 10:00:33 +01:00
if ( GETPOSTISSET ( 'catid' )) {
$search_categ = GETPOST ( 'catid' , 'int' );
} else {
$search_categ = GETPOST ( 'search_categ' , 'int' );
}
2011-02-20 17:20:22 +01:00
2012-07-24 17:52:46 +02:00
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
2019-11-14 12:09:15 +01:00
$canvas = GETPOST ( " canvas " );
$objcanvas = null ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $canvas )) {
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/canvas.class.php' ;
2019-01-27 11:55:16 +01:00
$objcanvas = new Canvas ( $db , $action );
$objcanvas -> getCanvas ( 'product' , 'list' , $canvas );
2012-07-24 17:52:46 +02:00
}
2016-04-28 15:22:38 +02:00
// Define virtualdiffersfromphysical
2019-11-14 12:09:15 +01:00
$virtualdiffersfromphysical = 0 ;
2020-06-05 10:27:34 +02:00
if ( ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SHIPMENT )
|| ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER )
|| ! empty ( $conf -> global -> STOCK_CALCULATE_ON_SHIPMENT_CLOSE )
|| ! empty ( $conf -> global -> STOCK_CALCULATE_ON_RECEPTION )
|| ! empty ( $conf -> global -> STOCK_CALCULATE_ON_RECEPTION_CLOSE )
2021-02-26 14:25:17 +01:00
|| ! empty ( $conf -> mrp -> enabled )) {
2020-10-31 14:32:18 +01:00
$virtualdiffersfromphysical = 1 ; // According to increase/decrease stock options, virtual and physical stock may differs.
2016-04-28 15:22:38 +02:00
}
2020-07-27 23:58:06 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'productreassortlist' ));
2021-04-01 11:01:07 +02:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
$result = restrictedArea ( $user , 'produit|service' , 0 , 'product&product' );
2010-06-08 10:51:52 +02:00
2022-03-17 09:18:08 +01:00
$object = new Product ( $db );
2010-06-08 10:51:52 +02:00
2011-02-20 17:20:22 +01:00
/*
* Actions
*/
2021-02-26 14:25:17 +01:00
if ( GETPOST ( 'button_removefilter_x' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter' , 'alpha' )) { // All tests are required to be compatible with all browsers
2020-10-31 14:32:18 +01:00
$sref = " " ;
$snom = " " ;
$sall = " " ;
2019-11-14 12:09:15 +01:00
$tosell = " " ;
$tobuy = " " ;
2020-10-31 14:32:18 +01:00
$search_sale = " " ;
$search_categ = " " ;
$toolowstock = '' ;
2019-11-14 12:09:15 +01:00
$fourn_id = '' ;
$sbarcode = '' ;
2022-01-25 10:00:33 +01:00
$search_stock_physique = '' ;
2016-10-10 02:01:30 +02:00
}
2011-02-20 17:20:22 +01:00
2006-12-02 21:12:50 +01:00
2016-07-28 12:17:00 +02:00
2006-12-02 21:12:50 +01:00
/*
2010-06-08 10:51:52 +02:00
* View
2006-12-02 21:12:50 +01:00
*/
2019-11-14 12:09:15 +01:00
$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks' ;
2016-07-28 12:17:00 +02:00
2019-11-14 12:09:15 +01:00
$form = new Form ( $db );
$htmlother = new FormOther ( $db );
2010-06-08 10:51:52 +02:00
2016-08-02 13:36:16 +02:00
$sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,' ;
2019-11-14 12:09:15 +01:00
$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' ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
$sql .= ', u.short_label as unit_short' ;
}
2020-07-27 23:58:06 +02:00
// Add fields from hooks
2020-07-29 13:05:12 +02:00
$parameters = array ();
2022-03-17 09:18:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListSelect' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2020-07-29 13:05:12 +02:00
$sql .= $hookmanager -> resPrint ;
2019-11-14 12:09:15 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p' ;
2020-01-04 14:20:25 +01:00
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_stock as s ON p.rowid = s.fk_product' ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_units as u on p.fk_unit = u.rowid' ;
}
2019-11-14 12:09:15 +01:00
$sql .= " WHERE p.entity IN ( " . getEntity ( 'product' ) . " ) " ;
2022-01-25 10:00:33 +01:00
if ( ! empty ( $search_categ ) && $search_categ != '-1' ) {
$sql .= " AND " ;
if ( $search_categ == - 2 ) {
$sql .= " NOT EXISTS " ;
} else {
$sql .= " EXISTS " ;
}
$sql .= " ( " ;
$sql .= " SELECT cp.fk_categorie, cp.fk_product " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " categorie_product as cp " ;
$sql .= " WHERE cp.fk_product = p.rowid " ; // Join for the needed table to filter by categ
if ( $search_categ > 0 ) {
$sql .= " AND cp.fk_categorie = " . (( int ) $search_categ );
}
$sql .= " ) " ;
2021-02-26 14:25:17 +01:00
}
2023-01-12 11:48:58 +01:00
$sql .= " AND EXISTS (SELECT e.rowid FROM " . MAIN_DB_PREFIX . " entrepot as e WHERE e.rowid = s.fk_entrepot AND e.entity IN ( " . getEntity ( 'stock' ) . " )) " ;
2021-02-26 14:25:17 +01:00
if ( $sall ) {
$sql .= natural_search ( array ( 'p.ref' , 'p.label' , 'p.description' , 'p.note' ), $sall );
}
2011-09-20 12:30:56 +02:00
// if the type is not 1, we show all products (type = 0,2,3)
2021-02-26 14:25:17 +01:00
if ( dol_strlen ( $type )) {
if ( $type == 1 ) {
2020-10-31 14:32:18 +01:00
$sql .= " AND p.fk_product_type = '1' " ;
} else {
$sql .= " AND p.fk_product_type <> '1' " ;
}
2006-12-02 21:12:50 +01:00
}
2021-02-26 14:25:17 +01:00
if ( $sref ) {
$sql .= natural_search ( 'p.ref' , $sref );
}
if ( $search_barcode ) {
$sql .= natural_search ( 'p.barcode' , $search_barcode );
}
if ( $snom ) {
$sql .= natural_search ( 'p.label' , $snom );
}
if ( ! empty ( $tosell )) {
2021-03-22 13:31:06 +01:00
$sql .= " AND p.tosell = " . (( int ) $tosell );
2021-02-26 14:25:17 +01:00
}
if ( ! empty ( $tobuy )) {
2021-03-22 13:31:06 +01:00
$sql .= " AND p.tobuy = " . (( int ) $tobuy );
2021-02-26 14:25:17 +01:00
}
if ( ! empty ( $canvas )) {
$sql .= " AND p.canvas = ' " . $db -> escape ( $canvas ) . " ' " ;
}
if ( $fourn_id > 0 ) {
2021-03-22 13:31:06 +01:00
$sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = " . (( int ) $fourn_id );
2021-02-26 14:25:17 +01:00
}
2022-03-16 19:09:16 +01:00
// Add where from hooks
$parameters = array ();
2022-03-17 09:18:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListWhere' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2022-03-16 19:09:16 +01:00
$sql .= $hookmanager -> resPrint ;
2019-11-14 12:09:15 +01:00
$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 " ;
2020-07-27 23:58:06 +02:00
// Add fields from hooks
2020-07-29 13:05:12 +02:00
$parameters = array ();
2022-03-17 09:18:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldSelect' , $parameters , $object ); // Note that $action and $object may have been modified by hook
2020-07-29 13:05:12 +02:00
$sql .= $hookmanager -> resPrint ;
2022-01-25 10:00:33 +01:00
$sql_having = '' ;
2021-02-26 14:25:17 +01:00
if ( $toolowstock ) {
2022-01-25 10:00:33 +01:00
$sql_having .= " HAVING SUM( " . $db -> ifsql ( 's.reel IS NULL' , '0' , 's.reel' ) . " ) < p.seuil_stock_alerte " ;
}
if ( $search_stock_physique != '' ) {
//$natural_search_physique = natural_search('HAVING SUM(' . $db->ifsql('s.reel IS NULL', '0', 's.reel') . ')', $search_stock_physique, 1, 1);
$natural_search_physique = natural_search ( 'SUM(' . $db -> ifsql ( 's.reel IS NULL' , '0' , 's.reel' ) . ')' , $search_stock_physique , 1 , 1 );
$natural_search_physique = " " . substr ( $natural_search_physique , 1 , - 1 ); // remove first "(" and last ")" characters
if ( ! empty ( $sql_having )) {
$sql_having .= " AND " ;
} else {
$sql_having .= " HAVING " ;
}
$sql_having .= $natural_search_physique ;
}
if ( ! empty ( $sql_having )) {
$sql .= $sql_having ;
2021-02-26 14:25:17 +01:00
}
2019-11-14 12:09:15 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
2017-03-30 15:39:50 +02:00
// Count total nb of records
$nbtotalofrecords = '' ;
2021-02-26 14:25:17 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_FULL_SCANLIST )) {
2020-10-31 14:32:18 +01:00
$result = $db -> query ( $sql );
$nbtotalofrecords = $db -> num_rows ( $result );
2021-02-26 14:25:17 +01:00
if (( $page * $limit ) > $nbtotalofrecords ) { // if total resultset is smaller then paging size (filtering), goto and load page 0
2020-10-31 14:32:18 +01:00
$page = 0 ;
$offset = 0 ;
}
2017-03-30 15:39:50 +02:00
}
2019-11-14 12:09:15 +01:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2006-12-02 21:12:50 +01:00
2017-03-30 15:39:50 +02:00
$resql = $db -> query ( $sql );
2021-02-26 14:25:17 +01:00
if ( $resql ) {
2009-01-10 01:44:38 +01:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2021-02-26 14:25:17 +01:00
if ( $num == 1 && GETPOST ( 'autojumpifoneonly' ) && ( $sall || $snom || $sref )) {
2009-01-10 01:44:38 +01:00
$objp = $db -> fetch_object ( $resql );
2014-09-18 21:18:25 +02:00
header ( " Location: card.php?id= $objp->rowid " );
2009-01-10 01:44:38 +01:00
exit ;
}
2021-02-26 14:25:17 +01:00
if ( isset ( $type )) {
if ( $type == 1 ) {
$texte = $langs -> trans ( " Services " );
} else {
$texte = $langs -> trans ( " Products " );
}
2009-01-10 01:44:38 +01:00
} else {
$texte = $langs -> trans ( " ProductsAndServices " );
}
2019-11-14 12:09:15 +01:00
$texte .= ' (' . $langs -> trans ( " MenuStocks " ) . ')' ;
$param = '' ;
2021-02-26 14:25:17 +01:00
if ( $limit > 0 && $limit != $conf -> liste_limit ) {
$param .= '&limit=' . urlencode ( $limit );
}
if ( $sall ) {
$param .= " &sall= " . urlencode ( $sall );
}
if ( $tosell ) {
$param .= " &tosell= " . urlencode ( $tosell );
}
if ( $tobuy ) {
$param .= " &tobuy= " . urlencode ( $tobuy );
}
2022-01-25 10:00:33 +01:00
if ( $type != '' ) {
2021-02-26 14:25:17 +01:00
$param .= " &type= " . urlencode ( $type );
}
if ( $fourn_id ) {
$param .= " &fourn_id= " . urlencode ( $fourn_id );
}
if ( $snom ) {
$param .= " &snom= " . urlencode ( $snom );
}
if ( $sref ) {
$param .= " &sref= " . urlencode ( $sref );
}
if ( $search_sale ) {
$param .= " &search_sale= " . urlencode ( $search_sale );
}
2022-02-04 11:00:16 +01:00
if ( $search_categ > 0 ) {
2021-02-26 14:25:17 +01:00
$param .= " &search_categ= " . urlencode ( $search_categ );
}
if ( $toolowstock ) {
$param .= " &toolowstock= " . urlencode ( $toolowstock );
}
if ( $sbarcode ) {
$param .= " &sbarcode= " . urlencode ( $sbarcode );
}
2022-01-25 10:00:33 +01:00
if ( $search_stock_physique ) {
$param .= '&search_stock_physique=' . urlencode ( $search_stock_physique );
2021-02-26 14:25:17 +01:00
}
2009-01-10 01:44:38 +01:00
2016-07-28 12:17:00 +02:00
llxHeader ( " " , $texte , $helpurl );
2009-01-10 01:44:38 +01:00
2019-11-14 12:09:15 +01:00
print '<form action="' . $_SERVER [ " PHP_SELF " ] . '" method="post" name="formulaire">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-03-30 15:39:50 +02:00
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
2020-10-31 14:32:18 +01:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
2017-03-30 15:39:50 +02:00
print '<input type="hidden" name="type" value="' . $type . '">' ;
2020-04-12 21:36:57 +02:00
print_barre_liste ( $texte , $page , $_SERVER [ " PHP_SELF " ], $param , $sortfield , $sortorder , '' , $num , $nbtotalofrecords , 'product' , 0 , '' , '' , $limit );
2017-08-02 13:31:53 +02:00
2022-01-25 10:00:33 +01:00
if ( $search_categ > 0 ) {
2020-10-31 14:32:18 +01:00
print " <div id='ways'> " ;
$c = new Categorie ( $db );
2022-01-25 10:00:33 +01:00
$c -> fetch ( $search_categ );
2020-10-31 14:32:18 +01:00
$ways = $c -> print_all_ways ( ' > ' , 'product/reassort.php' );
print " > " . $ways [ 0 ] . " <br> \n " ;
print " </div><br> " ;
2009-01-10 01:44:38 +01:00
}
2017-08-02 13:31:53 +02:00
2010-06-08 10:51:52 +02:00
// Filter on categories
2021-02-26 14:25:17 +01:00
$moreforfilter = '' ;
if ( ! empty ( $conf -> categorie -> enabled )) {
$moreforfilter .= '<div class="divsearchfield">' ;
2021-03-24 01:53:08 +01:00
$moreforfilter .= img_picto ( $langs -> trans ( 'Categories' ), 'category' , 'class="pictofixedwidth"' );
2022-01-25 10:00:33 +01:00
$moreforfilter .= $htmlother -> select_categories ( Categorie :: TYPE_PRODUCT , $search_categ , 'search_categ' , 1 );
2021-02-26 14:25:17 +01:00
$moreforfilter .= '</div>' ;
2010-06-08 10:51:52 +02:00
}
2017-08-02 13:31:53 +02:00
2019-11-14 12:09:15 +01:00
$moreforfilter .= '<div class="divsearchfield">' ;
$moreforfilter .= $langs -> trans ( " StockTooLow " ) . ' <input type="checkbox" name="toolowstock" value="1"' . ( $toolowstock ? ' checked' : '' ) . '>' ;
$moreforfilter .= '</div>' ;
2017-08-02 13:31:53 +02:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $moreforfilter )) {
2020-10-31 14:32:18 +01:00
print '<div class="liste_titre liste_titre_bydiv centpercent">' ;
print $moreforfilter ;
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'printFieldPreListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
print '</div>' ;
}
2017-08-02 13:31:53 +02:00
2016-04-25 15:31:49 +02:00
$formProduct = new FormProduct ( $db );
$formProduct -> loadWarehouses ();
$warehouses_list = $formProduct -> cache_warehouses ;
$nb_warehouse = count ( $warehouses_list );
2016-05-17 02:41:06 +02:00
$colspan_warehouse = 1 ;
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> STOCK_DETAIL_ON_WAREHOUSE )) {
$colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse + 1 : 1 ;
}
2017-08-02 13:31:53 +02:00
2020-10-31 14:32:18 +01:00
print '<div class="div-table-responsive">' ;
2019-11-14 12:09:15 +01:00
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '">' ;
2017-08-02 13:31:53 +02:00
2019-07-05 21:37:25 +02:00
// Fields title search
2017-03-30 15:39:50 +02:00
print '<tr class="liste_titre_filter">' ;
2009-01-10 01:44:38 +01:00
print '<td class="liste_titre">' ;
2015-04-12 17:08:14 +02:00
print '<input class="flat" type="text" name="sref" size="6" value="' . $sref . '">' ;
2009-01-10 01:44:38 +01:00
print '</td>' ;
print '<td class="liste_titre">' ;
2015-04-12 17:08:14 +02:00
print '<input class="flat" type="text" name="snom" size="8" value="' . $snom . '">' ;
2009-01-10 01:44:38 +01:00
print '</td>' ;
2016-04-28 15:22:38 +02:00
// Duration
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> service -> enabled ) && $type == 1 ) {
2009-01-10 01:44:38 +01:00
print '<td class="liste_titre">' ;
print ' ' ;
print '</td>' ;
}
2016-04-28 15:22:38 +02:00
// Stock limit
2009-06-03 21:58:51 +02:00
print '<td class="liste_titre"> </td>' ;
2019-02-23 23:36:21 +01:00
print '<td class="liste_titre right"> </td>' ;
2022-01-25 10:00:33 +01:00
// Physical stock
print '<td class="liste_titre right">' ;
print '<input class="flat" type="text" size="5" name="search_stock_physique" value="' . dol_escape_htmltag ( $search_stock_physique ) . '">' ;
print '</td>' ;
2021-02-26 14:25:17 +01:00
if ( $virtualdiffersfromphysical ) {
print '<td class="liste_titre"> </td>' ;
}
2013-05-31 11:05:50 +02:00
print '<td class="liste_titre"> </td>' ;
2016-04-25 15:31:49 +02:00
print '<td class="liste_titre" colspan="' . $colspan_warehouse . '"> </td>' ;
2017-03-30 15:39:50 +02:00
print '<td class="liste_titre"></td>' ;
2020-07-29 13:07:02 +02:00
$parameters = array ();
2020-10-31 14:32:18 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListOption' , $parameters ); // Note that $action and $object may have been modified by hook
2020-07-27 23:58:06 +02:00
print $hookmanager -> resPrint ;
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">' ;
2021-02-26 14:25:17 +01:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
print $searchpicto ;
2016-04-25 15:31:49 +02:00
print '</td>' ;
2009-01-10 01:44:38 +01:00
print '</tr>' ;
2019-07-05 21:50:35 +02:00
//Line for column titles
2017-03-30 15:39:50 +02:00
print " <tr class= \" liste_titre \" > " ;
2022-01-25 10:00:33 +01:00
print_liste_field_titre ( " Ref " , $_SERVER [ " PHP_SELF " ], " p.ref " , '' , $param , " " , $sortfield , $sortorder );
print_liste_field_titre ( " Label " , $_SERVER [ " PHP_SELF " ], " p.label " , '' , $param , " " , $sortfield , $sortorder );
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> service -> enabled ) && $type == 1 ) {
2022-01-25 10:00:33 +01:00
print_liste_field_titre ( " Duration " , $_SERVER [ " PHP_SELF " ], " p.duration " , '' , $param , " " , $sortfield , $sortorder , 'center ' );
2021-02-26 14:25:17 +01:00
}
2022-01-25 10:00:33 +01:00
print_liste_field_titre ( " StockLimit " , $_SERVER [ " PHP_SELF " ], " p.seuil_stock_alerte " , '' , $param , " " , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( " DesiredStock " , $_SERVER [ " PHP_SELF " ], " p.desiredstock " , '' , $param , " " , $sortfield , $sortorder , 'right ' );
print_liste_field_titre ( " PhysicalStock " , $_SERVER [ " PHP_SELF " ], " stock_physique " , '' , $param , " " , $sortfield , $sortorder , 'right ' );
2017-03-30 15:39:50 +02:00
// Details per warehouse
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> STOCK_DETAIL_ON_WAREHOUSE )) { // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context)
2020-10-31 14:32:18 +01:00
if ( $nb_warehouse > 1 ) {
foreach ( $warehouses_list as & $wh ) {
print_liste_field_titre ( $wh [ 'label' ], '' , '' , '' , '' , '' , '' , '' , 'right ' );
}
}
2017-03-30 15:39:50 +02:00
}
2021-02-26 14:25:17 +01:00
if ( $virtualdiffersfromphysical ) {
2022-01-25 10:00:33 +01:00
print_liste_field_titre ( " VirtualStock " , $_SERVER [ " PHP_SELF " ], " " , '' , $param , " " , $sortfield , $sortorder , 'right ' , 'VirtualStockDesc' );
2021-02-26 14:25:17 +01:00
}
2020-10-31 14:32:18 +01:00
// Units
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
2022-01-25 10:00:33 +01:00
print_liste_field_titre ( " Unit " , $_SERVER [ " PHP_SELF " ], " unit_short " , '' , $param , 'align="right"' , $sortfield , $sortorder );
2020-10-31 14:32:18 +01:00
}
2017-03-30 15:39:50 +02:00
print_liste_field_titre ( '' );
2022-01-25 10:00:33 +01:00
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 ' );
2020-07-27 23:58:06 +02:00
// Hook fields
2020-10-31 14:32:18 +01:00
$parameters = array ( 'param' => $param , 'sortfield' => $sortfield , 'sortorder' => $sortorder );
$reshook = $hookmanager -> executeHooks ( 'printFieldListTitle' , $parameters ); // Note that $action and $object may have been modified by hook
2020-07-27 23:58:06 +02:00
print $hookmanager -> resPrint ;
2017-03-30 15:39:50 +02:00
print_liste_field_titre ( '' );
print " </tr> \n " ;
2017-08-02 13:31:53 +02:00
2021-02-26 14:25:17 +01:00
while ( $i < min ( $num , $limit )) {
2009-01-10 01:44:38 +01:00
$objp = $db -> fetch_object ( $resql );
2019-11-14 12:09:15 +01:00
$product = new Product ( $db );
2016-04-25 15:31:49 +02:00
$product -> fetch ( $objp -> rowid );
$product -> load_stock ();
2018-09-05 14:37:44 +02:00
print '<tr>' ;
print '<td class="nowrap">' ;
2019-01-27 11:55:16 +01:00
print $product -> getNomUrl ( 1 , '' , 16 );
2009-01-10 01:44:38 +01:00
//if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow"));
print '</td>' ;
2016-04-25 15:31:49 +02:00
print '<td>' . $product -> label . '</td>' ;
2009-01-10 01:44:38 +01:00
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> service -> enabled ) && $type == 1 ) {
2019-02-23 23:36:21 +01:00
print '<td class="center">' ;
2021-02-26 14:25:17 +01:00
if ( preg_match ( '/([0-9]+)y/i' , $objp -> duration , $regs )) {
print $regs [ 1 ] . ' ' . $langs -> trans ( " DurationYear " );
} elseif ( preg_match ( '/([0-9]+)m/i' , $objp -> duration , $regs )) {
print $regs [ 1 ] . ' ' . $langs -> trans ( " DurationMonth " );
} elseif ( preg_match ( '/([0-9]+)d/i' , $objp -> duration , $regs )) {
print $regs [ 1 ] . ' ' . $langs -> trans ( " DurationDay " );
} else {
print $objp -> duration ;
}
2009-01-10 01:44:38 +01:00
print '</td>' ;
}
2019-02-23 23:36:21 +01:00
//print '<td class="right">'.$objp->stock_theorique.'</td>';
print '<td class="right">' . $objp -> seuil_stock_alerte . '</td>' ;
print '<td class="right">' . $objp -> desiredstock . '</td>' ;
2016-04-28 15:22:38 +02:00
// Real stock
2019-02-23 23:36:21 +01:00
print '<td class="right">' ;
2021-02-26 14:25:17 +01:00
if ( $objp -> seuil_stock_alerte != '' && ( $objp -> stock_physique < $objp -> seuil_stock_alerte )) {
print img_warning ( $langs -> trans ( " StockTooLow " )) . ' ' ;
}
2020-10-31 14:32:18 +01:00
print price2num ( $objp -> stock_physique , 'MS' );
2011-01-10 21:46:21 +01:00
print '</td>' ;
2017-08-02 13:31:53 +02:00
2016-05-12 19:44:49 +02:00
// Details per warehouse
2021-02-26 14:25:17 +01:00
if ( ! empty ( $conf -> global -> STOCK_DETAIL_ON_WAREHOUSE )) { // TODO This should be moved into the selection of fields on page product/list (page product/stock will be removed and replaced with product/list with its own context)
2019-11-14 12:09:15 +01:00
if ( $nb_warehouse > 1 ) {
foreach ( $warehouses_list as & $wh ) {
2019-02-23 23:36:21 +01:00
print '<td class="right">' ;
2016-05-12 19:44:49 +02:00
print empty ( $product -> stock_warehouse [ $wh [ 'id' ]] -> real ) ? '0' : $product -> stock_warehouse [ $wh [ 'id' ]] -> real ;
print '</td>' ;
}
2017-08-02 13:31:53 +02:00
}
}
2016-04-28 15:22:38 +02:00
// Virtual stock
2021-02-26 14:25:17 +01:00
if ( $virtualdiffersfromphysical ) {
2019-02-23 23:36:21 +01:00
print '<td class="right">' ;
2021-02-26 14:25:17 +01:00
if ( $objp -> seuil_stock_alerte != '' && ( $product -> stock_theorique < $objp -> seuil_stock_alerte )) {
print img_warning ( $langs -> trans ( " StockTooLow " )) . ' ' ;
}
2020-09-14 10:49:44 +02:00
print price2num ( $product -> stock_theorique , 'MS' );
2018-09-05 14:37:44 +02:00
print '</td>' ;
2016-04-28 15:22:38 +02:00
}
2020-10-31 18:51:30 +01:00
// Units
if ( ! empty ( $conf -> global -> PRODUCT_USE_UNITS )) {
print '<td class="left">' . $objp -> unit_short . '</td>' ;
}
2021-03-24 01:53:08 +01:00
print '<td class="center">' ;
print img_picto ( $langs -> trans ( " StockMovement " ), 'movement' , 'class="pictofixedwidth"' );
print '<a href="' . DOL_URL_ROOT . '/product/stock/movement_list.php?idproduct=' . $product -> id . '">' . $langs -> trans ( " Movements " ) . '</a>' ;
print '</td>' ;
2019-02-23 23:36:21 +01:00
print '<td class="right nowrap">' . $product -> LibStatut ( $objp -> statut , 5 , 0 ) . '</td>' ;
2020-10-31 18:51:30 +01:00
print '<td class="right nowrap">' . $product -> LibStatut ( $objp -> tobuy , 5 , 1 ) . '</td>' ;
2020-07-27 23:58:06 +02:00
// Fields from hook
2020-07-29 13:07:02 +02:00
$parameters = array ( 'obj' => $objp );
2022-03-17 09:18:08 +01:00
$reshook = $hookmanager -> executeHooks ( 'printFieldListValue' , $parameters , $product ); // Note that $action and $object may have been modified by hook
2020-07-27 23:58:06 +02:00
print $hookmanager -> resPrint ;
2017-03-30 15:39:50 +02:00
print '<td></td>' ;
2020-10-31 18:51:30 +01:00
print " </tr> \n " ;
2009-01-10 01:44:38 +01:00
$i ++ ;
2006-12-02 21:12:50 +01:00
}
2009-01-10 01:44:38 +01:00
print " </table> " ;
2016-11-27 11:41:10 +01:00
print '</div>' ;
2017-08-02 13:31:53 +02:00
2009-01-10 01:44:38 +01:00
print '</form>' ;
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2006-12-02 21:12:50 +01:00
}
2018-08-15 12:48:13 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-07-24 17:52:46 +02:00
$db -> close ();