New chart.

This commit is contained in:
James Cole
2015-08-01 07:04:41 +02:00
parent c04f08dfd8
commit 16b95ea78a
6 changed files with 120 additions and 27 deletions

View File

@@ -32,6 +32,51 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
return $this->frontpage($accounts, $start, $end);
}
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
public function expenseAccounts(Collection $accounts, Carbon $start, Carbon $end)
{
// language:
$data = [
'count' => 1,
'labels' => [],
'datasets' => [
[
'label' => trans('firefly.spent'),
'data' => []
]
],
];
$ids = [];
foreach ($accounts as $account) {
$ids[] = $account->id;
}
$startBalances = Steam::balancesById($ids, $start);
$endBalances = Steam::balancesById($ids, $end);
foreach ($accounts as $account) {
$id = $account->id;
$start = isset($startBalances[$id]) ? $startBalances[$id] : 0;
$end = isset($endBalances[$id]) ? $endBalances[$id] : 0;
$diff = $end - $start;
if ($diff > 0) {
$data['labels'][] = $account->name;
$data['datasets'][0]['data'][] = $diff;
}
}
return $data;
}
/**
* @param Collection $accounts
* @param Carbon $start