Use graph for stats on products/services

This commit is contained in:
Laurent Destailleur 2019-08-30 04:15:24 +02:00
parent adc0d2a133
commit 6009601254
2 changed files with 52 additions and 54 deletions

View File

@ -29,10 +29,14 @@ ProductOrService=Product or Service
ProductsAndServices=Products and Services
ProductsOrServices=Products or Services
ProductsPipeServices=Products | Services
ProductsOnSale=Products for sale
ProductsOnPurchase=Products for purchase
ProductsOnSaleOnly=Products for sale only
ProductsOnPurchaseOnly=Products for purchase only
ProductsNotOnSell=Products not for sale and not for purchase
ProductsOnSellAndOnBuy=Products for sale and for purchase
ProductsOnSale=Services for sale
ProductsOnPurchase=Services for purchase
ServicesOnSaleOnly=Services for sale only
ServicesOnPurchaseOnly=Services for purchase only
ServicesNotOnSell=Services not for sale and not for purchase

View File

@ -130,68 +130,62 @@ $sql.= " GROUP BY p.fk_product_type, p.tosell, p.tobuy";
$result = $db->query($sql);
while ($objp = $db->fetch_object($result))
{
$status=3;
$status=3; // On sale + On purchase
if (! $objp->tosell && ! $objp->tobuy) $status=0; // Not on sale, not on purchase
if ($objp->tosell && ! $objp->tobuy) $status=1; // On sale only
if (! $objp->tosell && $objp->tobuy) $status=2; // On purchase only
$prodser[$objp->fk_product_type][$status]=$objp->total;
if ((! empty($conf->product->enabled) && empty($objp->fk_product_type))
|| (! empty($conf->product->enabled) && ! empty($objp->fk_product_type)))
{
if ($objp->tosell) $prodser[$objp->fk_product_type]['sell']+=$objp->total;
if ($objp->tobuy) $prodser[$objp->fk_product_type]['buy']+=$objp->total;
if (! $objp->tosell && ! $objp->tobuy) $prodser[$objp->fk_product_type]['none']+=$objp->total;
}
}
if ($conf->use_javascript_ajax)
{
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
print '<tr><td class="center" colspan="2">';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
if (! empty($conf->product->enabled))
{
$statProducts = '<tr class="oddeven">';
$statProducts.= '<td><a href="list.php?type=0&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ProductsNotOnSell").'</a></td><td class="right">'.round($prodser[0][0]).'</td>';
$statProducts.= "</tr>";
$statProducts.= '<tr class="oddeven">';
$statProducts.= '<td><a href="list.php?type=0">'.$langs->trans("ProductsOnSaleOnly").'</a></td><td class="right">'.round($prodser[0][1]).'</td>';
$statProducts.= "</tr>";
$statProducts.= '<tr class="oddeven">';
$statProducts.= '<td><a href="list.php?type=0">'.$langs->trans("ProductsOnPurchaseOnly").'</a></td><td class="right">'.round($prodser[0][2]).'</td>';
$statProducts.= "</tr>";
$statProducts.= '<tr class="oddeven">';
$statProducts.= '<td><a href="list.php?type=0&amp;tosell=1&amp;tobuy=1">'.$langs->trans("ProductsOnSellAndOnBuy").'</a></td><td class="right">'.round($prodser[0][3]).'</td>';
$statProducts.= "</tr>";
$SommeA=$prodser[0]['sell'];
$SommeB=$prodser[0]['buy'];
$SommeC=$prodser[0]['none'];
$SommeD=$prodser[1]['sell'];
$SommeE=$prodser[1]['buy'];
$SommeF=$prodser[1]['none'];
$total=0;
$dataval=array();
$datalabels=array();
$i=0;
$total = $SommeA + $SommeB + $SommeC + $SommeD + $SommeE + $SommeF;
$dataseries=array();
$dataseries[]=array($langs->trans("ProductsOnSale"), round($SommeA));
$dataseries[]=array($langs->trans("ProductsOnPurchase"), round($SommeB));
$dataseries[]=array($langs->trans("ProductsNotOnSell"), round($SommeC));
$dataseries[]=array($langs->trans("ServicesOnSale"), round($SommeD));
$dataseries[]=array($langs->trans("ServicesOnPurchase"), round($SommeE));
$dataseries[]=array($langs->trans("ServicesNotOnSell"), round($SommeF));
include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
$dolgraph = new DolGraph();
$dolgraph->SetData($dataseries);
$dolgraph->setShowLegend(1);
$dolgraph->setShowPercent(0);
$dolgraph->SetType(array('pie'));
$dolgraph->setWidth('100%');
$dolgraph->draw('idgraphstatus');
print $dolgraph->show($total?0:1);
print '</td></tr>';
print '</table>';
print '</div>';
}
if (! empty($conf->service->enabled))
{
$statServices = '<tr class="oddeven">';
$statServices.= '<td><a href="list.php?type=1&amp;tosell=0&amp;tobuy=0">'.$langs->trans("ServicesNotOnSell").'</a></td><td class="right">'.round($prodser[1][0]).'</td>';
$statServices.= "</tr>";
$statServices.= '<tr class="oddeven">';
$statServices.= '<td><a href="list.php?type=1">'.$langs->trans("ServicesOnSaleOnly").'</a></td><td class="right">'.round($prodser[1][1]).'</td>';
$statServices.= "</tr>";
$statServices.= '<tr class="oddeven">';
$statServices.= '<td><a href="list.php?type=1">'.$langs->trans("ServicesOnPurchaseOnly").'</a></td><td class="right">'.round($prodser[1][2]).'</td>';
$statServices.= "</tr>";
$statServices.= '<tr class="oddeven">';
$statServices.= '<td><a href="list.php?type=1&amp;tosell=1&amp;tobuy=1">'.$langs->trans("ServicesOnSellAndOnBuy").'</a></td><td class="right">'.round($prodser[1][3]).'</td>';
$statServices.= "</tr>";
}
$total=0;
if ($type == '0')
{
print $statProducts;
$total=round($prodser[0][0])+round($prodser[0][1])+round($prodser[0][2])+round($prodser[0][3]);
}
elseif ($type == '1')
{
print $statServices;
$total=round($prodser[1][0])+round($prodser[1][1])+round($prodser[1][2])+round($prodser[1][3]);
}
else
{
print $statProducts.$statServices;
$total=round($prodser[0][0])+round($prodser[0][1])+round($prodser[0][2])+round($prodser[0][3])+round($prodser[1][0])+round($prodser[1][1])+round($prodser[1][2])+round($prodser[1][3]); //Calcul du Total des Produits et Services
}
print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
print $total;
print '</td></tr>';
print '</table>';
print '</div>';
if (! empty($conf->categorie->enabled) && ! empty($conf->global->CATEGORY_GRAPHSTATS_ON_PRODUCTS))
{