From a3ae7a76b8771278b1e7cbdd73b048fb4186ce36 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 28 Jun 2020 19:35:24 +0200 Subject: [PATCH] WIP Stock at date --- htdocs/core/class/html.form.class.php | 4 +- htdocs/langs/en_US/stocks.lang | 3 +- htdocs/product/stock/stockatdate.php | 115 ++++++++++++++++---------- htdocs/theme/eldy/global.inc.php | 1 + 4 files changed, 78 insertions(+), 45 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c84c6ed12d2..0e570d8f5e9 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5349,7 +5349,7 @@ class Form if ($usecalendar == "eldy") { // Zone de saisie manuelle de la date - $retstring .= 'trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript $retstring .= '>'; @@ -5402,7 +5402,7 @@ class Form // Zone de saisie manuelle de la date $retstring .= '
'; - $retstring .= 'trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript $retstring .= '>'; diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 08846d35907..49362619f0d 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -231,4 +231,5 @@ StockIsRequiredToChooseWhichLotToUse=Stock is required to choose which lot to us ForceTo=Force to AlwaysShowFullArbo=Display full tree of warehouse on popup of warehouse links (Warning: This may decrease dramatically performances) StockAtDatePastDesc=You can view here the stock (real stock) at a given date in the past -StockAtDateFutureDesc=You can view here the stock (virtual stock) at a given date in future \ No newline at end of file +StockAtDateFutureDesc=You can view here the stock (virtual stock) at a given date in future +CurrentStock=Current stock \ No newline at end of file diff --git a/htdocs/product/stock/stockatdate.php b/htdocs/product/stock/stockatdate.php index cef50715598..f3482e22098 100644 --- a/htdocs/product/stock/stockatdate.php +++ b/htdocs/product/stock/stockatdate.php @@ -102,19 +102,23 @@ if ($conf->global->ENTREPOT_EXTRA_STATUS) { $stock_prod_warehouse = array(); $stock_prod = array(); if ($date) { // Avoid heavy sql if mandatory date is not defined - $sql = "SELECT sm.fk_product, sm.fk_entrepot as fk_warehouse,"; - $sql .= " SUM(sm.value) AS stock"; - $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as sm"; + $sql = "SELECT ps.fk_product, ps.fk_entrepot as fk_warehouse,"; + $sql .= " SUM(ps.reel) AS stock"; + $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; $sql .= ", ".MAIN_DB_PREFIX."entrepot as w"; $sql .= " WHERE w.entity IN (".getEntity('stock').")"; //$sql .= " AND p.entity IN (".getEntity('product').")"; - $sql .= " AND w.rowid = sm.fk_entrepot"; - if ($conf->global->ENTREPOT_EXTRA_STATUS && count($warehouseStatus)) { + $sql .= " AND w.rowid = ps.fk_entrepot"; + if (! empty($conf->global->ENTREPOT_EXTRA_STATUS) && count($warehouseStatus)) { $sql .= " AND w.statut IN (".$this->db->escape(implode(',', $warehouseStatus)).")"; } + if ($productid > 0) { + $sql .= " AND ps.fk_product = ".$productid; + } $sql .= " GROUP BY fk_product, fk_entrepot"; - $resql = $db->query($sql); + //print $sql; + $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -155,28 +159,36 @@ $num = 0; $title = $langs->trans('StockAtDate'); $sql = 'SELECT p.rowid, p.ref, p.label, p.description, p.price,'; -$sql .= ' p.price_ttc, p.price_base_type, p.fk_product_type,'; -$sql .= ' p.tms as datem, p.duration, p.tobuy, p.stock,'; -$sql .= ' p.desiredstock, p.seuil_stock_alerte'; +$sql .= ' p.price_ttc, p.price_base_type, p.fk_product_type, p.desiredstock, p.seuil_stock_alerte,'; +$sql .= ' p.tms as datem, p.duration, p.tobuy, p.stock'; +if ($fk_warehouse > 0) { + $sql .= ', SUM(ps.reel) as stock_reel'; +} // 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'; +if ($fk_warehouse > 0) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '.$fk_warehouse; +} // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListJoin', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; -if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { - $sql .= " AND p.fk_product_type = 0"; -} if ($productid > 0) { $sql .= " AND p.rowid = ".$productid; } +if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $sql .= " AND p.fk_product_type = 0"; +} if (!empty($canvas)) $sql .= ' AND p.canvas = "'.$db->escape($canvas).'"'; - +if ($fk_warehouse > 0) { + $sql .= ' GROUP BY p.rowid, p.ref, p.label, p.description, p.price, 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'; +} /* if ($usevirtualstock) { @@ -289,8 +301,7 @@ if ($date) { // We avoid a heavy sql if mandatory parameter date not yet defined } $i = 0; - - +//print $sql; $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|'; $helpurl .= 'ES:Módulo_Stocks'; @@ -317,7 +328,7 @@ if ($mode == 'future') $desc = $langs->trans("StockAtDateFutureDesc"); print ''.$desc.'
'."\n"; print '
'."\n"; -print '
'; +print ''; print ''; print ''; print ''; @@ -348,6 +359,9 @@ if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($l $param .= '&mode='.$mode; if ($fk_warehouse > 0) $param .= '&fk_warehouse='.$fk_warehouse; if ($productid > 0) $param .= '&fk_product='.$productid; +if (GETPOST('dateday', 'int') > 0) $param .= '&dateday='.GETPOST('dateday', 'int'); +if (GETPOST('datemonth', 'int') > 0) $param .= '&datemonth='.GETPOST('datemonth', 'int'); +if (GETPOST('dateyear', 'int') > 0) $param .= '&dateyear='.GETPOST('dateyear', 'int'); // TODO Move this into the title line ? print_barre_liste('', $page, $_SERVER["PHP_SELF"], $filters, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'stock', 0, '', '', $limit, 0, 0, 1); @@ -355,7 +369,7 @@ print_barre_liste('', $page, $_SERVER["PHP_SELF"], $filters, $sortfield, $sortor print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; -$stocklabel = $langs->trans('Stock'); +$stocklabel = $langs->trans('StockAtDate'); if ($mode == 'future') $stocklabel = $langs->trans("VirtualStock"); //print ''; @@ -369,10 +383,8 @@ print ''; print ''; print ''; print ''; -print ''; -print ''; -print ''; -print ''; +print ''; +print ''; // Fields from hook $parameters = array('param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook @@ -384,14 +396,17 @@ print $searchpicto; print ''; print ''; +$fieldtosortcurrentstock = 'stock'; +if ($fk_warehouse > 0) { + $fieldtosortcurrentstock = 'stock_reel'; +} + // Lines of title print ''; 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); -print_liste_field_titre('', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right '); -print_liste_field_titre('', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right '); -print_liste_field_titre($stocklabel, $_SERVER["PHP_SELF"], 'p.stock', $param, '', '', $sortfield, $sortorder, 'right '); -print_liste_field_titre('', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right '); +print_liste_field_titre('CurrentStock', $_SERVER["PHP_SELF"], $fieldtosortcurrentstock, $param, '', '', $sortfield, $sortorder, 'right '); +print_liste_field_titre($stocklabel, $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right '); print_liste_field_titre('', $_SERVER["PHP_SELF"], '', $param, '', '', $sortfield, $sortorder, 'right '); // Hook fields @@ -412,7 +427,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) $prod->load_stock('warehouseopen, warehouseinternal', 0); // Multilangs - if (!empty($conf->global->MAIN_MULTILANGS)) + /*if (!empty($conf->global->MAIN_MULTILANGS)) { $sql = 'SELECT label,description'; $sql .= ' FROM '.MAIN_DB_PREFIX.'product_lang'; @@ -427,39 +442,55 @@ while ($i < ($limit ? min($num, $limit) : $num)) if (!empty($objtp->description)) $objp->description = $objtp->description; if (!empty($objtp->label)) $objp->label = $objtp->label; } + }*/ + + $currentstock = ''; + if ($fk_warehouse > 0) + { + if ($productid > 0) { + $currentstock = $stock_prod_warehouse[$productid][$fk_warehouse]; + } else { + $currentstock = $objp->stock_reel; + } + } else { + if ($productid > 0) { + $currentstock = $stock_prod[$productid]; + } else { + $currentstock = $objp->stock; + } } - $stock = $prod->stock_reel; + if ($mode == 'future') { - $result = $prod->load_stats_reception(0, '4'); + $result = $prod->load_stats_reception(0, '4'); + //print $prod->stats_commande_fournisseur['qty'].'
'."\n"; + //print $prod->stats_reception['qty']; - //print $prod->stats_commande_fournisseur['qty'].'
'."\n"; - //print $prod->stats_reception['qty']; - $ordered = $prod->stats_commande_fournisseur['qty'] - $prod->stats_reception['qty']; + $stock = 123; + } else { + + + $stock = 123; + } print ''; + // Product ref print ''; + // Product label print ''; - // Desired stock - print ''; + // Current stock + print ''; - // Limit stock for alert - print ''; - - // Current stock (all warehouses) + // Stock at date print ''; - // Already ordered - print ''; - - // To order - //print ''; + // Action print ''; // Fields from hook diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index f0a0ac80ed1..51327b8e6fe 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -1075,6 +1075,7 @@ table[summary="list_of_modules"] .fa-cog { .maxwidth25 { max-width: 25px; } .maxwidth50 { max-width: 50px; } .maxwidth75 { max-width: 75px; } +.maxwidthdate { max-width: 80px; } .maxwidth100 { max-width: 100px; } .maxwidth125 { max-width: 125px; } .maxwidth150 { max-width: 150px; }
  
'.$prod->getNomUrl(1, '').''.$objp->label; print ''; // TODO Remove this and make a fetch to get description when creating order instead of a GETPOST print ''.$currentstock.''.$stock.'