From baec6aa16916c7bdfff617b21908c24a0324e308 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 16 Aug 2021 22:45:27 +0200 Subject: [PATCH] Optimize memory and perf for list of stock movements --- htdocs/product/stock/movement_list.php | 1328 ++++++++++++------------ htdocs/product/stock/replenish.php | 7 +- 2 files changed, 678 insertions(+), 657 deletions(-) diff --git a/htdocs/product/stock/movement_list.php b/htdocs/product/stock/movement_list.php index 44e9e7ecea9..88927e94890 100644 --- a/htdocs/product/stock/movement_list.php +++ b/htdocs/product/stock/movement_list.php @@ -566,764 +566,780 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; -$sql .= $db->order($sortfield, $sortorder); +// Count total nb of records $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $result = $db->query($sql); - $nbtotalofrecords = $db->num_rows($result); + /* This old and fast method to get and count full list returns all record so use a high amount of memory. + $resql = $db->query($sql); + $nbtotalofrecords = $db->num_rows($resql); + */ + /* The slow method does not consume memory on mysql (not tested on pgsql) */ + /*$resql = $db->query($sql, 0, 'auto', 1); + while ($db->fetch_object($resql)) { + $nbtotalofrecords++; + }*/ + /* This fast and low memory method to get and count full list converts the sql into a sql count */ + $sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); + $resql = $db->query($sqlforcount); + $objforcount = $db->fetch_object($resql); + $nbtotalofrecords = $objforcount->nbtotalofrecords; if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } + $db->free($resql); } -$sql .= $db->plimit($limit + 1, $offset); +$sql .= $db->order($sortfield, $sortorder); +if ($limit) { + $sql .= $db->plimit($limit + 1, $offset); +} //print $sql; $resql = $db->query($sql); +if (!$resql) { + dol_print_error($db); + exit; +} -if ($resql) { - $product = new Product($db); - $object = new Entrepot($db); +$product = new Product($db); +$object = new Entrepot($db); - if ($idproduct > 0) { - $product->fetch($idproduct); +if ($idproduct > 0) { + $product->fetch($idproduct); +} +if ($id > 0 || $ref) { + $result = $object->fetch($id, $ref); + if ($result < 0) { + dol_print_error($db); } - if ($id > 0 || $ref) { - $result = $object->fetch($id, $ref); - if ($result < 0) { - dol_print_error($db); - } +} + +$num = $db->num_rows($resql); + +$arrayofselected = is_array($toselect) ? $toselect : array(); + + +$i = 0; +$help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; +if ($msid) { + $texte = $langs->trans('StockMovementForId', $msid); +} else { + $texte = $langs->trans("ListOfStockMovements"); + if ($id) { + $texte .= ' ('.$langs->trans("ForThisWarehouse").')'; } +} +llxHeader("", $texte, $help_url); - $num = $db->num_rows($resql); +/* + * Show tab only if we ask a particular warehouse + */ +if ($object->id > 0) { + $head = stock_prepare_head($object); - $arrayofselected = is_array($toselect) ? $toselect : array(); + print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock'); - $i = 0; - $help_url = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; - if ($msid) { - $texte = $langs->trans('StockMovementForId', $msid); - } else { - $texte = $langs->trans("ListOfStockMovements"); - if ($id) { - $texte .= ' ('.$langs->trans("ForThisWarehouse").')'; - } - } - llxHeader("", $texte, $help_url); + $linkback = ''.$langs->trans("BackToList").''; - /* - * Show tab only if we ask a particular warehouse - */ - if ($object->id > 0) { - $head = stock_prepare_head($object); + $morehtmlref = '
'; + $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; - print dol_get_fiche_head($head, 'movements', $langs->trans("Warehouse"), -1, 'stock'); - - - $linkback = ''.$langs->trans("BackToList").''; - - $morehtmlref = '
'; - $morehtmlref .= $langs->trans("LocationSummary").' : '.$object->lieu; - - // Project - if (!empty($conf->projet->enabled)) { - $langs->load("projects"); - $morehtmlref .= '
'.img_picto('', 'project').' '.$langs->trans('Project').' '; - if ($usercancreate && 1 == 2) { - if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; - } - if ($action == 'classify') { - $projectid = $object->fk_project; - $morehtmlref .= '
'; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500'); - $morehtmlref .= ''; - $morehtmlref .= '
'; - } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); - } + // Project + if (!empty($conf->projet->enabled)) { + $langs->load("projects"); + $morehtmlref .= '
'.img_picto('', 'project').' '.$langs->trans('Project').' '; + if ($usercancreate && 1 == 2) { + if ($action != 'classify') { + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; + } + if ($action == 'classify') { + $projectid = $object->fk_project; + $morehtmlref .= '
'; + $morehtmlref .= ''; + $morehtmlref .= ''; + $morehtmlref .= $formproject->select_projects(($socid > 0 ? $socid : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500'); + $morehtmlref .= ''; + $morehtmlref .= '
'; } else { - if (!empty($object->fk_project)) { - $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref .= ''; - $morehtmlref .= $proj->ref; - $morehtmlref .= ''; - } else { - $morehtmlref .= ''; - } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + } + } else { + if (!empty($object->fk_project)) { + $proj = new Project($db); + $proj->fetch($object->fk_project); + $morehtmlref .= ''; + $morehtmlref .= $proj->ref; + $morehtmlref .= ''; + } else { + $morehtmlref .= ''; } } - $morehtmlref .= '
'; + } + $morehtmlref .= '
'; - $shownav = 1; - if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { - $shownav = 0; - } - - dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); - - - print '
'; - print '
'; - print '
'; - - print ''; - - print ''; - - // Description - print ''; - - $calcproductsunique = $object->nb_different_products(); - $calcproducts = $object->nb_products(); - - // Total nb of different products - print '"; - - // Nb of products - print '"; - - print '
'.$langs->trans("Description").''.dol_htmlentitiesbr($object->description).'
'.$langs->trans("NumberOfDifferentProducts").''; - print empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb']; - print "
'.$langs->trans("NumberOfProducts").''; - $valtoshow = price2num($calcproducts['nb'], 'MS'); - print empty($valtoshow) ? '0' : $valtoshow; - print "
'; - - print '
'; - print '
'; - print '
'; - print '
'; - - print ''; - - // Value - print '"; - - // Last movement - $sql = "SELECT MAX(m.datem) as datem"; - $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; - $sql .= " WHERE m.fk_entrepot = ".((int) $object->id); - $resqlbis = $db->query($sql); - if ($resqlbis) { - $objbis = $db->fetch_object($resqlbis); - $lastmovementdate = $db->jdate($objbis->datem); - } else { - dol_print_error($db); - } - - print '"; - - // Other attributes - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; - - // Categories - if ($conf->categorie->enabled) { - print '"; - } - - print "
'.$langs->trans("EstimatedStockValueShort").''; - print price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency); - print "
'.$langs->trans("LastMovement").''; - if ($lastmovementdate) { - print dol_print_date($lastmovementdate, 'dayhour'); - } else { - print $langs->trans("None"); - } - print "
'.$langs->trans("Categories").''; - print $form->showCategories($object->id, Categorie::TYPE_WAREHOUSE, 1); - print "
"; - - print '
'; - print '
'; - print '
'; - - print '
'; - - print dol_get_fiche_end(); + $shownav = 1; + if ($user->socid && !in_array('stock', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) { + $shownav = 0; } - - /* - * Correct stock - */ - if ($action == "correction") { - include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php'; - print '
'; - } - - /* - * Transfer of units - */ - if ($action == "transfert") { - include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php'; - print '
'; - } + dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref', 'ref', $morehtmlref); - /* - * Action bar - */ - if ((empty($action) || $action == 'list') && $id > 0) { - print "
\n"; + print '
'; + print '
'; + print '
'; - if ($user->rights->stock->mouvement->creer) { - print ''.$langs->trans("CorrectStock").''; - } + print ''; - if ($user->rights->stock->mouvement->creer) { - print ''.$langs->trans("TransferStock").''; - } + print ''; - print '
'; - } + // Description + print ''; - $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { - $param .= '&contextpage='.urlencode($contextpage); - } - if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.urlencode($limit); - } - if ($id > 0) { - $param .= '&id='.urlencode($id); - } - if ($search_date_startday) { - $param .= '&search_date_startday='.urlencode($search_date_startday); - } - if ($search_date_startmonth) { - $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); - } - if ($search_date_startyear) { - $param .= '&search_date_startyear='.urlencode($search_date_startyear); - } - if ($search_date_endday) { - $param .= '&search_date_endday='.urlencode($search_date_endday); - } - if ($search_date_endmonth) { - $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); - } - if ($search_date_endyear) { - $param .= '&search_date_endyear='.urlencode($search_date_endyear); - } - if ($search_movement) { - $param .= '&search_movement='.urlencode($search_movement); - } - if ($search_inventorycode) { - $param .= '&search_inventorycode='.urlencode($search_inventorycode); - } - if ($search_type_mouvement) { - $param .= '&search_type_mouvement='.urlencode($search_type_mouvement); - } - if ($search_product_ref) { - $param .= '&search_product_ref='.urlencode($search_product_ref); - } - if ($search_product) { - $param .= '&search_product='.urlencode($search_product); - } - if ($search_batch) { - $param .= '&search_batch='.urlencode($search_batch); - } - if ($search_warehouse > 0) { - $param .= '&search_warehouse='.urlencode($search_warehouse); - } - if ($search_user) { - $param .= '&search_user='.urlencode($search_user); - } - if ($idproduct > 0) { - $param .= '&idproduct='.urlencode($idproduct); - } - // Add $param from extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + $calcproductsunique = $object->nb_different_products(); + $calcproducts = $object->nb_products(); - // List of mass actions available - $arrayofmassactions = array( - // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), - // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), - ); - // By default, we should never accept deletion of stock movement. - if (!empty($conf->global->STOCK_ALLOW_DELETE_OF_MOVEMENT) && $permissiontodelete) { - $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); - } - if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { - $arrayofmassactions = array(); - } - $massactionbutton = $form->selectMassAction('', $arrayofmassactions); + // Total nb of different products + print '"; - print ''; - if ($optioncss != '') { - print ''; - } - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($id > 0) { - print ''; - } + // Nb of products + print '"; - if ($id > 0) { - print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1); + print '
'.$langs->trans("Description").''.dol_htmlentitiesbr($object->description).'
'.$langs->trans("NumberOfDifferentProducts").''; + print empty($calcproductsunique['nb']) ? '0' : $calcproductsunique['nb']; + print "
'.$langs->trans("NumberOfProducts").''; + $valtoshow = price2num($calcproducts['nb'], 'MS'); + print empty($valtoshow) ? '0' : $valtoshow; + print "
'; + + print '
'; + print '
'; + print '
'; + print '
'; + + print ''; + + // Value + print '"; + + // Last movement + $sql = "SELECT MAX(m.datem) as datem"; + $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m"; + $sql .= " WHERE m.fk_entrepot = ".((int) $object->id); + $resqlbis = $db->query($sql); + if ($resqlbis) { + $objbis = $db->fetch_object($resqlbis); + $lastmovementdate = $db->jdate($objbis->datem); } else { - print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1); + dol_print_error($db); } - // Add code for pre mass action (confirmation or email presend form) - $topicmail = "SendStockMovement"; - $modelmail = "movementstock"; - $objecttmp = new MouvementStock($db); - $trackid = 'mov'.$object->id; - include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - - if ($sall) { - foreach ($fieldstosearchall as $key => $val) { - $fieldstosearchall[$key] = $langs->trans($val); - } - print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; - } - - $moreforfilter = ''; - - $parameters = array('arrayfields'=>&$arrayfields); - $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - if (empty($reshook)) { - $moreforfilter .= $hookmanager->resPrint; + print '"; + + // Other attributes + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; + + // Categories + if ($conf->categorie->enabled) { + print '"; } - if (!empty($moreforfilter)) { - print '
'; - print $moreforfilter; - print '
'; + print "
'.$langs->trans("EstimatedStockValueShort").''; + print price((empty($calcproducts['value']) ? '0' : price2num($calcproducts['value'], 'MT')), 0, $langs, 0, -1, -1, $conf->currency); + print "
'.$langs->trans("LastMovement").''; + if ($lastmovementdate) { + print dol_print_date($lastmovementdate, 'dayhour'); } else { - $moreforfilter = $hookmanager->resPrint; + print $langs->trans("None"); + } + print "
'.$langs->trans("Categories").''; + print $form->showCategories($object->id, Categorie::TYPE_WAREHOUSE, 1); + print "
"; + + print '
'; + print '
'; + print '
'; + + print '
'; + + print dol_get_fiche_end(); +} + + +/* + * Correct stock + */ +if ($action == "correction") { + include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stockcorrection.tpl.php'; + print '
'; +} + +/* + * Transfer of units + */ +if ($action == "transfert") { + include DOL_DOCUMENT_ROOT.'/product/stock/tpl/stocktransfer.tpl.php'; + print '
'; +} + + +/* + * Action bar + */ +if ((empty($action) || $action == 'list') && $id > 0) { + print "
\n"; + + if ($user->rights->stock->mouvement->creer) { + print ''.$langs->trans("CorrectStock").''; } - $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; - $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + if ($user->rights->stock->mouvement->creer) { + print ''.$langs->trans("TransferStock").''; + } - print '
'; - print ''."\n"; + print '
'; +} - // Fields title search - print ''; +$param = ''; +if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); +} +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +if ($id > 0) { + $param .= '&id='.urlencode($id); +} +if ($search_date_startday) { + $param .= '&search_date_startday='.urlencode($search_date_startday); +} +if ($search_date_startmonth) { + $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); +} +if ($search_date_startyear) { + $param .= '&search_date_startyear='.urlencode($search_date_startyear); +} +if ($search_date_endday) { + $param .= '&search_date_endday='.urlencode($search_date_endday); +} +if ($search_date_endmonth) { + $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); +} +if ($search_date_endyear) { + $param .= '&search_date_endyear='.urlencode($search_date_endyear); +} +if ($search_movement) { + $param .= '&search_movement='.urlencode($search_movement); +} +if ($search_inventorycode) { + $param .= '&search_inventorycode='.urlencode($search_inventorycode); +} +if ($search_type_mouvement) { + $param .= '&search_type_mouvement='.urlencode($search_type_mouvement); +} +if ($search_product_ref) { + $param .= '&search_product_ref='.urlencode($search_product_ref); +} +if ($search_product) { + $param .= '&search_product='.urlencode($search_product); +} +if ($search_batch) { + $param .= '&search_batch='.urlencode($search_batch); +} +if ($search_warehouse > 0) { + $param .= '&search_warehouse='.urlencode($search_warehouse); +} +if ($search_user) { + $param .= '&search_user='.urlencode($search_user); +} +if ($idproduct > 0) { + $param .= '&idproduct='.urlencode($idproduct); +} +// Add $param from extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; + +// List of mass actions available +$arrayofmassactions = array( +// 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), +// 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), +); +// By default, we should never accept deletion of stock movement. +if (!empty($conf->global->STOCK_ALLOW_DELETE_OF_MOVEMENT) && $permissiontodelete) { + $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); +} +if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) { + $arrayofmassactions = array(); +} +$massactionbutton = $form->selectMassAction('', $arrayofmassactions); + +print ''; +if ($optioncss != '') { + print ''; +} +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +if ($id > 0) { + print ''; +} + +if ($id > 0) { + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1); +} else { + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'movement', 0, '', '', $limit, 0, 0, 1); +} + +// Add code for pre mass action (confirmation or email presend form) +$topicmail = "SendStockMovement"; +$modelmail = "movementstock"; +$objecttmp = new MouvementStock($db); +$trackid = 'mov'.$object->id; +include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; + +if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } + print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; +} + +$moreforfilter = ''; + +$parameters = array('arrayfields'=>&$arrayfields); +$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; +} else { + $moreforfilter = $hookmanager->resPrint; +} + +if (!empty($moreforfilter)) { + print '
'; + print $moreforfilter; + print '
'; +} + +$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; +$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + +print '
'; +print '
'."\n"; + +// Fields title search +print ''; +if (!empty($arrayfields['m.rowid']['checked'])) { + // Ref + print ''; +} +if (! empty($arrayfields['m.datem']['checked'])) { + // Date + print ''; +} +if (!empty($arrayfields['p.ref']['checked'])) { + // Product Ref + print ''; +} +if (!empty($arrayfields['p.label']['checked'])) { + // Product label + print ''; +} +// Batch +if (!empty($arrayfields['m.batch']['checked'])) { + print ''; +} +if (!empty($arrayfields['pl.eatby']['checked'])) { + print ''; +} +if (!empty($arrayfields['pl.sellby']['checked'])) { + print ''; +} +// Warehouse +if (!empty($arrayfields['e.ref']['checked'])) { + print ''; +} +if (!empty($arrayfields['m.fk_user_author']['checked'])) { + // Author + print ''; +} +if (!empty($arrayfields['m.inventorycode']['checked'])) { + // Inventory code + print ''; +} +if (!empty($arrayfields['m.label']['checked'])) { + // Label of movement + print ''; +} +if (!empty($arrayfields['origin']['checked'])) { + // Origin of movement + print ''; +} +if (!empty($arrayfields['m.fk_projet']['checked'])) { + // fk_project + print ''; +} +if (!empty($arrayfields['m.type_mouvement']['checked'])) { + // Type of movement + print ''; +} +if (!empty($arrayfields['m.value']['checked'])) { + // Qty + print ''; +} +if (!empty($arrayfields['m.price']['checked'])) { + // Price + print ''; +} + +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; + +// Fields from hook +$parameters = array('arrayfields'=>$arrayfields); +$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; +// Date creation +if (!empty($arrayfields['m.datec']['checked'])) { + print ''; +} +// Date modification +if (!empty($arrayfields['m.tms']['checked'])) { + print ''; +} +// Actions +print ''; +print "\n"; + +print ''; +if (!empty($arrayfields['m.rowid']['checked'])) { + print_liste_field_titre($arrayfields['m.rowid']['label'], $_SERVER["PHP_SELF"], 'm.rowid', '', $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['m.datem']['checked'])) { + print_liste_field_titre($arrayfields['m.datem']['label'], $_SERVER["PHP_SELF"], 'm.datem', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['p.ref']['checked'])) { + print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['p.label']['checked'])) { + print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['m.batch']['checked'])) { + print_liste_field_titre($arrayfields['m.batch']['label'], $_SERVER["PHP_SELF"], 'm.batch', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['pl.eatby']['checked'])) { + print_liste_field_titre($arrayfields['pl.eatby']['label'], $_SERVER["PHP_SELF"], 'pl.eatby', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['pl.sellby']['checked'])) { + print_liste_field_titre($arrayfields['pl.sellby']['label'], $_SERVER["PHP_SELF"], 'pl.sellby', '', $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['e.ref']['checked'])) { + // We are on a specific warehouse card, no filter on other should be possible + print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['m.fk_user_author']['checked'])) { + print_liste_field_titre($arrayfields['m.fk_user_author']['label'], $_SERVER["PHP_SELF"], "m.fk_user_author", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['m.inventorycode']['checked'])) { + print_liste_field_titre($arrayfields['m.inventorycode']['label'], $_SERVER["PHP_SELF"], "m.inventorycode", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['m.label']['checked'])) { + print_liste_field_titre($arrayfields['m.label']['label'], $_SERVER["PHP_SELF"], "m.label", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['origin']['checked'])) { + print_liste_field_titre($arrayfields['origin']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder); +} +if (!empty($arrayfields['m.fk_projet']['checked'])) { + print_liste_field_titre($arrayfields['m.fk_projet']['label'], $_SERVER["PHP_SELF"], "m.fk_projet", "", $param, '', $sortfield, $sortorder); +} +if (!empty($arrayfields['m.type_mouvement']['checked'])) { + print_liste_field_titre($arrayfields['m.type_mouvement']['label'], $_SERVER["PHP_SELF"], "m.type_mouvement", "", $param, '', $sortfield, $sortorder, 'center '); +} +if (!empty($arrayfields['m.value']['checked'])) { + print_liste_field_titre($arrayfields['m.value']['label'], $_SERVER["PHP_SELF"], "m.value", "", $param, '', $sortfield, $sortorder, 'right '); +} +if (!empty($arrayfields['m.price']['checked'])) { + print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right '); +} + +// Extra fields +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; + +// Hook fields +$parameters = array('arrayfields'=>$arrayfields, '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; +if (!empty($arrayfields['m.datec']['checked'])) { + print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +if (!empty($arrayfields['m.tms']['checked'])) { + print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); +} +print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); +print "\n"; + + +$arrayofuniqueproduct = array(); + +$i = 0; +$totalarray = array(); +while ($i < min($num, $limit)) { + $objp = $db->fetch_object($resql); + + $userstatic->id = $objp->fk_user_author; + $userstatic->login = $objp->login; + $userstatic->lastname = $objp->lastname; + $userstatic->firstname = $objp->firstname; + $userstatic->photo = $objp->photo; + $userstatic->email = $objp->user_email; + $userstatic->statut = $objp->user_status; + + $productstatic->id = $objp->rowid; + $productstatic->ref = $objp->product_ref; + $productstatic->label = $objp->produit; + $productstatic->type = $objp->type; + $productstatic->entity = $objp->entity; + $productstatic->status = $objp->tosell; + $productstatic->status_buy = $objp->tobuy; + $productstatic->status_batch = $objp->tobatch; + + $productlot->id = $objp->lotid; + $productlot->batch = $objp->batch; + $productlot->eatby = $objp->eatby; + $productlot->sellby = $objp->sellby; + + $warehousestatic->id = $objp->entrepot_id; + $warehousestatic->ref = $objp->warehouse_ref; + $warehousestatic->label = $objp->warehouse_ref; + $warehousestatic->lieu = $objp->lieu; + $warehousestatic->fk_parent = $objp->fk_parent; + $warehousestatic->statut = $objp->statut; + + $movement->type = $objp->type_mouvement; + + $arrayofuniqueproduct[$objp->rowid] = $objp->produit; + if (!empty($objp->fk_origin)) { + $origin = $movement->get_origin($objp->fk_origin, $objp->origintype); + } else { + $origin = ''; + } + + print ''; + // Id movement if (!empty($arrayfields['m.rowid']['checked'])) { - // Ref - print ''; + print ''; // This is primary not movement id } - if (! empty($arrayfields['m.datem']['checked'])) { + if (!empty($arrayfields['m.datem']['checked'])) { // Date - print ''; + print ''; } if (!empty($arrayfields['p.ref']['checked'])) { - // Product Ref - print ''; + // Product ref + print '\n"; } if (!empty($arrayfields['p.label']['checked'])) { // Product label - print ''; + print '\n"; } - // Batch if (!empty($arrayfields['m.batch']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['pl.eatby']['checked'])) { - print ''; + print ''; } if (!empty($arrayfields['pl.sellby']['checked'])) { - print ''; + print ''; } // Warehouse if (!empty($arrayfields['e.ref']['checked'])) { - print ''; + print '\n"; } + // Author if (!empty($arrayfields['m.fk_user_author']['checked'])) { - // Author - print ''; + print '\n"; } if (!empty($arrayfields['m.inventorycode']['checked'])) { // Inventory code - print ''; + print ''; } if (!empty($arrayfields['m.label']['checked'])) { // Label of movement - print ''; + print ''; } if (!empty($arrayfields['origin']['checked'])) { // Origin of movement - print ''; + print ''; } if (!empty($arrayfields['m.fk_projet']['checked'])) { // fk_project - print ''; } if (!empty($arrayfields['m.type_mouvement']['checked'])) { // Type of movement - print ''; } if (!empty($arrayfields['m.value']['checked'])) { // Qty - print ''; } if (!empty($arrayfields['m.price']['checked'])) { // Price - print ''; } // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; - + include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook - $parameters = array('arrayfields'=>$arrayfields); - $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook + $parameters = array('arrayfields'=>$arrayfields, 'objp'=>$objp, 'i'=>$i, 'totalarray'=>&$totalarray); + $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - // Date creation - if (!empty($arrayfields['m.datec']['checked'])) { - print ''; + + // Action column + print ''; - } - // Actions - print ''; + if (!$i) { + $totalarray['nbfield']++; + } + print "\n"; - - print ''; - if (!empty($arrayfields['m.rowid']['checked'])) { - print_liste_field_titre($arrayfields['m.rowid']['label'], $_SERVER["PHP_SELF"], 'm.rowid', '', $param, '', $sortfield, $sortorder); - } - if (!empty($arrayfields['m.datem']['checked'])) { - print_liste_field_titre($arrayfields['m.datem']['label'], $_SERVER["PHP_SELF"], 'm.datem', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['p.ref']['checked'])) { - print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder); - } - if (!empty($arrayfields['p.label']['checked'])) { - print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], 'p.label', '', $param, '', $sortfield, $sortorder); - } - if (!empty($arrayfields['m.batch']['checked'])) { - print_liste_field_titre($arrayfields['m.batch']['label'], $_SERVER["PHP_SELF"], 'm.batch', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['pl.eatby']['checked'])) { - print_liste_field_titre($arrayfields['pl.eatby']['label'], $_SERVER["PHP_SELF"], 'pl.eatby', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['pl.sellby']['checked'])) { - print_liste_field_titre($arrayfields['pl.sellby']['label'], $_SERVER["PHP_SELF"], 'pl.sellby', '', $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['e.ref']['checked'])) { - // We are on a specific warehouse card, no filter on other should be possible - print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['m.fk_user_author']['checked'])) { - print_liste_field_titre($arrayfields['m.fk_user_author']['label'], $_SERVER["PHP_SELF"], "m.fk_user_author", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['m.inventorycode']['checked'])) { - print_liste_field_titre($arrayfields['m.inventorycode']['label'], $_SERVER["PHP_SELF"], "m.inventorycode", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['m.label']['checked'])) { - print_liste_field_titre($arrayfields['m.label']['label'], $_SERVER["PHP_SELF"], "m.label", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['origin']['checked'])) { - print_liste_field_titre($arrayfields['origin']['label'], $_SERVER["PHP_SELF"], "", "", $param, "", $sortfield, $sortorder); - } - if (!empty($arrayfields['m.fk_projet']['checked'])) { - print_liste_field_titre($arrayfields['m.fk_projet']['label'], $_SERVER["PHP_SELF"], "m.fk_projet", "", $param, '', $sortfield, $sortorder); - } - if (!empty($arrayfields['m.type_mouvement']['checked'])) { - print_liste_field_titre($arrayfields['m.type_mouvement']['label'], $_SERVER["PHP_SELF"], "m.type_mouvement", "", $param, '', $sortfield, $sortorder, 'center '); - } - if (!empty($arrayfields['m.value']['checked'])) { - print_liste_field_titre($arrayfields['m.value']['label'], $_SERVER["PHP_SELF"], "m.value", "", $param, '', $sortfield, $sortorder, 'right '); - } - if (!empty($arrayfields['m.price']['checked'])) { - print_liste_field_titre($arrayfields['m.price']['label'], $_SERVER["PHP_SELF"], "m.price", "", $param, '', $sortfield, $sortorder, 'right '); - } - - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; - - // Hook fields - $parameters = array('arrayfields'=>$arrayfields, '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; - if (!empty($arrayfields['m.datec']['checked'])) { - print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - } - if (!empty($arrayfields['m.tms']['checked'])) { - print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - } - print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); - print "\n"; - - - $arrayofuniqueproduct = array(); - - $i = 0; - $totalarray = array(); - while ($i < min($num, $limit)) { - $objp = $db->fetch_object($resql); - - $userstatic->id = $objp->fk_user_author; - $userstatic->login = $objp->login; - $userstatic->lastname = $objp->lastname; - $userstatic->firstname = $objp->firstname; - $userstatic->photo = $objp->photo; - $userstatic->email = $objp->user_email; - $userstatic->statut = $objp->user_status; - - $productstatic->id = $objp->rowid; - $productstatic->ref = $objp->product_ref; - $productstatic->label = $objp->produit; - $productstatic->type = $objp->type; - $productstatic->entity = $objp->entity; - $productstatic->status = $objp->tosell; - $productstatic->status_buy = $objp->tobuy; - $productstatic->status_batch = $objp->tobatch; - - $productlot->id = $objp->lotid; - $productlot->batch = $objp->batch; - $productlot->eatby = $objp->eatby; - $productlot->sellby = $objp->sellby; - - $warehousestatic->id = $objp->entrepot_id; - $warehousestatic->ref = $objp->warehouse_ref; - $warehousestatic->label = $objp->warehouse_ref; - $warehousestatic->lieu = $objp->lieu; - $warehousestatic->fk_parent = $objp->fk_parent; - $warehousestatic->statut = $objp->statut; - - $movement->type = $objp->type_mouvement; - - $arrayofuniqueproduct[$objp->rowid] = $objp->produit; - if (!empty($objp->fk_origin)) { - $origin = $movement->get_origin($objp->fk_origin, $objp->origintype); - } else { - $origin = ''; - } - - print ''; - // Id movement - if (!empty($arrayfields['m.rowid']['checked'])) { - print ''; // This is primary not movement id - } - if (!empty($arrayfields['m.datem']['checked'])) { - // Date - print ''; - } - if (!empty($arrayfields['p.ref']['checked'])) { - // Product ref - print '\n"; - } - if (!empty($arrayfields['p.label']['checked'])) { - // Product label - print '\n"; - } - if (!empty($arrayfields['m.batch']['checked'])) { - print ''; - } - if (!empty($arrayfields['pl.eatby']['checked'])) { - print ''; - } - if (!empty($arrayfields['pl.sellby']['checked'])) { - print ''; - } - // Warehouse - if (!empty($arrayfields['e.ref']['checked'])) { - print '\n"; - } - // Author - if (!empty($arrayfields['m.fk_user_author']['checked'])) { - print '\n"; - } - if (!empty($arrayfields['m.inventorycode']['checked'])) { - // Inventory code - print ''; - } - if (!empty($arrayfields['m.label']['checked'])) { - // Label of movement - print ''; - } - if (!empty($arrayfields['origin']['checked'])) { - // Origin of movement - print ''; - } - if (!empty($arrayfields['m.fk_projet']['checked'])) { - // fk_project - print ''; - } - if (!empty($arrayfields['m.type_mouvement']['checked'])) { - // Type of movement - print ''; - } - if (!empty($arrayfields['m.value']['checked'])) { - // Qty - print ''; - } - if (!empty($arrayfields['m.price']['checked'])) { - // Price - print ''; - } - - // Extra fields - include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; - // Fields from hook - $parameters = array('arrayfields'=>$arrayfields, 'objp'=>$objp, 'i'=>$i, 'totalarray'=>&$totalarray); - $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - // Action column - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - - print "\n"; - $i++; - } - $db->free($resql); - - print "
'; + print ''; + print ''; + print '
'; + print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel'); + print '
'; + print '
'; + print $form->selectDate($search_date_end?$search_date_end:-1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'), 'tzuserrel'); + print '
'; + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; + print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '  '; + print ''; + print '  '; + print ''; + //print ''; + print ''; + print ajax_combobox('search_type_mouvement'); + // TODO: add new function $formentrepot->selectTypeOfMovement(...) like + // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); + print ''; + print ''; + print ''; + print '  '; + print ''; + print ''; + print ''; +$searchpicto = $form->showFilterAndCheckAddButtons(0); +print $searchpicto; +print '
'; - print ''; - print ''; + print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"'); + print $objp->mid; + print ''; - print '
'; - print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel'); - print '
'; - print '
'; - print $form->selectDate($search_date_end?$search_date_end:-1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'), 'tzuserrel'); - print '
'; - print '
'.dol_print_date($db->jdate($objp->datem), 'dayhour', 'tzuserrel').''; - print ''; - print ''; + print $productstatic->getNomUrl(1, 'stock', 16); + print "'; - print ''; - print ''; + print $productstatic->label; + print "'; + if ($productlot->id > 0) { + print $productlot->getNomUrl(1); + } else { + print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement. + } + print ''; - print ''.dol_print_date($objp->eatby, 'day').''; - print ''.dol_print_date($objp->sellby, 'day').''; - //print ''; - print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); - print ''; + print $warehousestatic->getNomUrl(1); + print "'; - print ''; - print ''; + print $userstatic->getNomUrl(-1); + print "'; - print ''; - print 'inventorycode.'$').'&search_type_mouvement='.urlencode($objp->type_mouvement).'">'.$objp->inventorycode.''; - print ''; - print ''.$objp->label.''; - print '  '; - print ''.$origin.''; - print '  '; + print ''; + if ($objp->fk_project != 0) { + print $movement->get_origin($objp->fk_project, 'project'); + } print ''; - //print ''; - print ''; - print ajax_combobox('search_type_mouvement'); - // TODO: add new function $formentrepot->selectTypeOfMovement(...) like - // print $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'maxwidth200'); + print ''; + print $movement->getTypeMovement(); print ''; - print ''; + print ''; + if ($objp->qty > 0) { + print ''; + print '+'; + print $objp->qty; + print ''; + } else { + print ''; + print $objp->qty; + print ''; + } print ''; - print '  '; + print ''; + if ($objp->price != 0) { + print price($objp->price); + } print ''; - print ''; + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined + $selected = 0; + if (in_array($objp->mid, $arrayofselected)) { + $selected = 1; + } + print ''; } - // Date modification - if (!empty($arrayfields['m.tms']['checked'])) { - print ''; - print ''; - $searchpicto = $form->showFilterAndCheckAddButtons(0); - print $searchpicto; print '
'; - print img_picto($langs->trans("StockMovement"), 'movement', 'class="pictofixedwidth"'); - print $objp->mid; - print ''.dol_print_date($db->jdate($objp->datem), 'dayhour', 'tzuserrel').''; - print $productstatic->getNomUrl(1, 'stock', 16); - print "'; - print $productstatic->label; - print "'; - if ($productlot->id > 0) { - print $productlot->getNomUrl(1); - } else { - print $productlot->batch; // the id may not be defined if movement was entered when lot was not saved or if lot was removed after movement. - } - print ''.dol_print_date($objp->eatby, 'day').''.dol_print_date($objp->sellby, 'day').''; - print $warehousestatic->getNomUrl(1); - print "'; - print $userstatic->getNomUrl(-1); - print "inventorycode.'$').'&search_type_mouvement='.urlencode($objp->type_mouvement).'">'.$objp->inventorycode.''.$objp->label.''.$origin.''; - if ($objp->fk_project != 0) { - print $movement->get_origin($objp->fk_project, 'project'); - } - print ''; - print $movement->getTypeMovement(); - print ''; - if ($objp->qty > 0) { - print ''; - print '+'; - print $objp->qty; - print ''; - } else { - print ''; - print $objp->qty; - print ''; - } - print ''; - if ($objp->price != 0) { - print price($objp->price); - } - print ''; - if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - $selected = 0; - if (in_array($objp->mid, $arrayofselected)) { - $selected = 1; - } - print ''; - } - print '
"; - print '
'; - print ""; - - // Add number of product when there is a filter on period - if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) { - print "
"; - - $productidselected = 0; - foreach ($arrayofuniqueproduct as $key => $val) { - $productidselected = $key; - $productlabelselected = $val; - } - $datebefore = dol_get_first_day($year ? $year : strftime("%Y", time()), $month ? $month : 1, true); - $dateafter = dol_get_last_day($year ? $year : strftime("%Y", time()), $month ? $month : 12, true); - $balancebefore = $movement->calculateBalanceForProductBefore($productidselected, $datebefore); - $balanceafter = $movement->calculateBalanceForProductBefore($productidselected, $dateafter); - - //print ''; - print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore, 'day', 'gmt')); - //print ''; - //print ''; - print ': '.$balancebefore; - print "
\n"; - //print ''; - //print ''; - print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter, 'day', 'gmt')); - //print ''; - //print ''; - print ': '.$balanceafter; - print "
\n"; - //print ''; - } -} else { - dol_print_error($db); + $i++; } +$db->free($resql); + +print ""; +print '
'; +print ""; + +// Add number of product when there is a filter on period +if (count($arrayofuniqueproduct) == 1 && is_numeric($year)) { + print "
"; + + $productidselected = 0; + foreach ($arrayofuniqueproduct as $key => $val) { + $productidselected = $key; + $productlabelselected = $val; + } + $datebefore = dol_get_first_day($year ? $year : strftime("%Y", time()), $month ? $month : 1, true); + $dateafter = dol_get_last_day($year ? $year : strftime("%Y", time()), $month ? $month : 12, true); + $balancebefore = $movement->calculateBalanceForProductBefore($productidselected, $datebefore); + $balanceafter = $movement->calculateBalanceForProductBefore($productidselected, $dateafter); + + //print ''; + print $langs->trans("NbOfProductBeforePeriod", $productlabelselected, dol_print_date($datebefore, 'day', 'gmt')); + //print ''; + //print ''; + print ': '.$balancebefore; + print "
\n"; + //print ''; + //print ''; + print $langs->trans("NbOfProductAfterPeriod", $productlabelselected, dol_print_date($dateafter, 'day', 'gmt')); + //print ''; + //print ''; + print ': '.$balanceafter; + print "
\n"; + //print ''; +} // End of page llxFooter(); diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 824d667e934..8dc40c3c78c 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -789,7 +789,12 @@ while ($i < ($limit ? min($num, $limit) : $num)) { $objp = $db->fetch_object($resql); if (!empty($conf->global->STOCK_SUPPORTS_SERVICES) || $objp->fk_product_type == 0) { - $prod->fetch($objp->rowid); + $result = $prod->fetch($objp->rowid); + if ($result < 0) { + dol_print_error($db); + exit; + } + $prod->load_stock('warehouseopen, warehouseinternal'.(!$usevirtualstock?', novirtual':''), $draftchecked); // Multilangs