From 2d8c2221d862acaf0eebc293d235bf3ca1a677e4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 25 Nov 2015 23:20:41 +0100 Subject: [PATCH] NEW Provide an easier way to understand if an order can be shipped. --- htdocs/commande/list.php | 162 +++++++++++++++++++++++---------------- 1 file changed, 94 insertions(+), 68 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 6d90794dbd0..fa695dbaa50 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -8,7 +8,7 @@ * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2015 Frederic France * Copyright (C) 2015 Marcos García - * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Jean-François Ferry * * 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 @@ -402,88 +402,114 @@ if ($resql) print $generic_commande->getNomUrl(1,($viewstatut != 2?0:$objp->fk_statut)); print ''; - // Shippable Icon - if (($objp->fk_statut > 0) && ($objp->fk_statut < 3) && ! empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) { - $notshippable=0; - $warning = 0; - $text_info=''; - $nbprod=0; - for ($lig=0; $lig<(count($generic_commande->lines)); $lig++) { - if ($generic_commande->lines[$lig]->product_type==0) { - $nbprod++; // order contains real products - $generic_product->id = $generic_commande->lines[$lig]->fk_product; - if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) { - $generic_product->load_stock(); - $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel; - } else { - $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel']; - } - // stock order and stock order_supplier - $stock_order=0; - $stock_order_supplier=0; - if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) + // Show shippable Icon (create subloop, so may be slow) + if ($conf->stock->enabled) + { + $langs->load("stocks"); + if (($objp->fk_statut > 0) && ($objp->fk_statut < 3)) + { + $notshippable=0; + $warning = 0; + $text_info=''; + $nbprod=0; + + $num = count($generic_commande->lines); // Loop on each line of order + for ($lig=0; $lig < $num; $lig++) + { + if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) // If line is a product and not a service { - if (! empty($conf->commande->enabled)) - { - if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) { - $generic_product->load_stats_commande(0,'1,2'); - $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty']; - } else { - $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer']; - } - $stock_order=$generic_product->stats_commande['qty']; + $nbprod++; // order contains real products + $generic_product->id = $generic_commande->lines[$lig]->fk_product; + if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) { + $generic_product->load_stock(); + $generic_product->load_virtual_stock(); + $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel; + $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique; + } else { + $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel']; + $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique; } - if (! empty($conf->fournisseur->enabled)) + + if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) // Default code is when this option is not set, setting it create strange result { - if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) { - $generic_product->load_stats_commande_fournisseur(0,'3'); - $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty']; - } else { - $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier']; + $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.' '.dol_trunc($generic_commande->lines[$lig]->product_label, 25); + $text_info .= ' - '.$langs->trans("Stock").': '.$generic_product->stock_reel; + $text_info .= ' - '.$langs->trans("VirtualStock").': '.$generic_product->stock_theorique; + $text_info .= '
'; + + if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel) + { + $notshippable++; + } + } + else { // Detailed code, looks bugged + // stock order and stock order_supplier + $stock_order=0; + $stock_order_supplier=0; + if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) // What about other options ? + { + if (! empty($conf->commande->enabled)) + { + if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) { + $generic_product->load_stats_commande(0,'1,2'); + $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty']; + } else { + $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer']; + } + $stock_order=$generic_product->stats_commande['qty']; + } + if (! empty($conf->fournisseur->enabled)) + { + if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) { + $generic_product->load_stats_commande_fournisseur(0,'3'); + $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty']; + } else { + $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier']; + } + $stock_order_supplier=$generic_product->stats_commande_fournisseur['qty']; + } + } + $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.' '.dol_trunc($generic_commande->lines[$lig]->product_label, 25); + $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order; + if ($stock_order > $generic_product->stock_reel && ! ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) { + $warning++; + $text_warning.=''.$langs->trans('Available').' : '.$text_stock_reel.''; + } + if ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty) { + $notshippable++; + $text_info.=''.$langs->trans('Available').' : '.$text_stock_reel.''; + } else { + $text_info.=''.$langs->trans('Available').' : '.$text_stock_reel.''; + } + if (! empty($conf->fournisseur->enabled)) { + $text_info.= ' '.$langs->trans('SupplierOrder').' : '.$stock_order_supplier.'
'; + } else { + $text_info.= '
'; } - $stock_order_supplier=$generic_product->stats_commande_fournisseur['qty']; } - } - $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.' '.dol_trunc($generic_commande->lines[$lig]->product_label, 25); - $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order; - if ($stock_order > $generic_product->stock_reel && ! ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) { - $warning++; - $text_warning.=''.$langs->trans('Available').' : '.$text_stock_reel.''; - } - if ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty) { - $notshippable++; - $text_info.=''.$langs->trans('Available').' : '.$text_stock_reel.''; - } else { - $text_info.=''.$langs->trans('Available').' : '.$text_stock_reel.''; - } - if ($stock_order_supplier>0) { - $text_info.= ' '.$langs->trans('SupplierOrder').' : '.$stock_order_supplier.'
'; - } else { - $text_info.= '
'; } } + if ($notshippable==0) { + $text_icon = img_picto('', 'object_sending'); + $text_info = $langs->trans('Shippable').'
'.$text_info; + } else { + $text_icon = img_picto('', 'error'); + $text_info = $langs->trans('NonShippable').'
'.$text_info; + } } - if ($notshippable==0) { - $text_icon = img_picto('', 'object_sending'); - $text_info = $langs->trans('Shippable').'
'.$text_info; - } else { - $text_icon = img_picto('', 'error'); - $text_info = $langs->trans('NonShippable').'
'.$text_info; - } - if ($nbprod>0) { - print ''; + print ''; + if ($nbprod) + { print $form->textwithtooltip('',$text_info,2,1,$text_icon,'',2); - print ''; } if ($warning) { - print ''; print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'
'.$text_warning, 2, 1, img_picto('', 'error'),'',2); - print ''; } + print ''; } - // warning late icon - print ''; + // Warning late icon + print ''; if ($generic_commande->hasDelay()) { print img_picto($langs->trans("Late"), "warning"); }