From b12e87abc3d5aed6b9615e905d0e2046790563b8 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sun, 4 May 2014 18:42:00 +0200 Subject: [PATCH] Update index.php add the categories pie graph on product too (and correct some bug) --- htdocs/product/index.php | 86 +++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/htdocs/product/index.php b/htdocs/product/index.php index ece788ae34c..a46ee30669d 100644 --- a/htdocs/product/index.php +++ b/htdocs/product/index.php @@ -111,9 +111,10 @@ $sql.= " GROUP BY p.fk_product_type, p.tosell, p.tobuy"; $result = $db->query($sql); while ($objp = $db->fetch_object($result)) { - $status=1; + $status=2; if (! $objp->tosell && ! $objp->tobuy) $status=0; // To sell OR to buy - $prodser[$objp->fk_product_type][$status]+=$objp->total; + if ((! $objp->tosell && $objp->tobuy) || ($objp->tosell && ! $objp->tobuy)) $status=1; + $prodser[$objp->fk_product_type][$status]=$objp->total; } print ''; @@ -124,40 +125,105 @@ if (! empty($conf->product->enabled)) $statProducts.= ''; $statProducts.= ""; $statProducts.= ""; - $statProducts.= ''; + $statProducts.= ''; $statProducts.= ""; + $statProducts.= ""; + $statProducts.= ''; + $statProducts.= ""; + } if (! empty($conf->service->enabled)) { - $statServices = ""; + $statServices = ""; $statServices.= ''; $statServices.= ""; - $statServices.= ""; - $statServices.= ''; + $statServices.= ""; + $statServices.= ''; $statServices.= ""; + $statServices.= ""; + $statServices.= ''; + $statServices.= ""; + } $total=0; if ($type == '0') { print $statProducts; - $total=round($prodser[0][0])+round($prodser[0][1]); + $total=round($prodser[0][0])+round($prodser[0][1])+round($prodser[0][2]); } else if ($type == '1') { print $statServices; - $total=round($prodser[1][0])+round($prodser[1][1]); + $total=round($prodser[1][0])+round($prodser[1][1])+round($prodser[1][2]); } else { print $statProducts.$statServices; - $total=round($prodser[1][0])+round($prodser[1][1])+round($prodser[0][0])+round($prodser[0][1]); + $total=round($prodser[1][0])+round($prodser[1][1])+round($prodser[1][2])+round($prodser[0][0])+round($prodser[0][1])+round($prodser[0][2]); } print ''; print '
'.$langs->trans("ProductsNotOnSell").''.round($prodser[0][0]).'
'.$langs->trans("ProductsOnSell").''.round($prodser[0][1]).''.$langs->trans("ProductsOnSell").''.round($prodser[0][1]).'
'.$langs->trans("ProductsOnSellAndOnBuy").''.round($prodser[0][2]).'
'.$langs->trans("ServicesNotOnSell").''.round($prodser[1][0]).'
'.$langs->trans("ServicesOnSell").''.round($prodser[1][1]).'
'.$langs->trans("ServicesOnSell").''.round($prodser[1][1]).'
'.$langs->trans("ServicesOnSellAndOnBuy").''.round($prodser[1][2]).'
'.$langs->trans("Total").''; print $total; print '
'; - +if (! empty($conf->categorie->enabled)) +{ + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + print '
'; + print ''; + print ''; + print ''; + $total+=$obj->nb; + $i++; + } + } + } + print ''; + print ''; + print '
'.$langs->trans("Categories").'
'; + $sql = "SELECT c.label, count(*) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."categorie_product as cs"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid"; + $sql.= " WHERE c.type = 0"; + $sql.= " AND c.entity IN (".getEntity('category',1).")"; + $sql.= " GROUP BY c.label"; + $total=0; + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i=0; + if (! empty($conf->use_javascript_ajax)) + { + $dataseries=array(); + $rest=0; + $nbmax=10; + while ($i < $num) + { + $obj = $db->fetch_object($result); + if ($i < $nbmax) + $dataseries[]=array('label'=>$obj->label,'data'=>round($obj->nb)); + else + $rest+=$obj->nb; + $total+=$obj->nb; + $i++; + } + if ($i > $nbmax) + $dataseries[]=array('label'=>$langs->trans("Other"),'data'=>round($rest)); + $data=array('series'=>$dataseries); + dol_print_graph('statscategproduct',300,180,$data,1,'pie',0); + } + else + { + $var=true; + while ($i < $num) + { + $obj = $db->fetch_object($result); + $var=!$var; + print '
'.$obj->label.''.$obj->nb.'
'.$langs->trans("Total").''; + print $total; + print '
'; +} print '
';