From 9a3d2f13a6291cd5d96554e9393b5c8310048b6b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 6 Jul 2021 10:55:23 +0200 Subject: [PATCH] Fix graph per type of expense report --- htdocs/expensereport/index.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/htdocs/expensereport/index.php b/htdocs/expensereport/index.php index 8198883e58f..4e01cfe7501 100644 --- a/htdocs/expensereport/index.php +++ b/htdocs/expensereport/index.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004-2021 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2015 Alexandre Spangaro @@ -132,6 +132,30 @@ foreach ($listoftype as $code => $label) { $dataseries[] = array($label, (isset($somme[$code]) ? (int) $somme[$code] : 0)); } +// Sort array with most important first +$dataseries = dol_sort_array($dataseries, 1, 'desc'); + +// Merge all entrie after the $KEEPNFIRST one into one entry called "Other..." (to avoid to have too much entries in graphic). +$KEEPNFIRST = 7; // Keep first $KEEPNFIRST one + 1 with the remain +$i = 0; +if (count($dataseries) > ($KEEPNFIRST + 1)) { + foreach($dataseries as $key => $val) { + if ($i < $KEEPNFIRST) { + $i++; + continue; + } + // Here $key = $KEEPNFIRST + $dataseries[$KEEPNFIRST][0] = $langs->trans("Other").'...'; + if ($key == $KEEPNFIRST) { + $i++; + continue; + } + $dataseries[$KEEPNFIRST][1] += $dataseries[$key][1]; + unset($dataseries[$key]); + $i++; + } +} + if ($conf->use_javascript_ajax) { print '';