Include chart with report

This commit is contained in:
James Cole
2016-12-03 21:48:40 +01:00
parent 0a844e4313
commit 9dc6f41c18
8 changed files with 142 additions and 2 deletions

View File

@@ -22,7 +22,6 @@ use Illuminate\Support\Collection;
*/
interface CategoryChartGeneratorInterface
{
/**
* @param Collection $entries
*
@@ -58,4 +57,11 @@ interface CategoryChartGeneratorInterface
*/
public function pieChart(array $data): array;
/**
* @param array $entries
*
* @return array
*/
public function reportPeriod(array $entries): array;
}

View File

@@ -142,6 +142,41 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
}
/**
* @param array $entries
*
* @return array
*/
public function reportPeriod(array $entries): array
{
$data = [
'labels' => array_keys($entries),
'datasets' => [
0 => [
'label' => trans('firefly.earned'),
'data' => [],
],
1 => [
'label' => trans('firefly.spent'),
'data' => [],
],
],
'count' => 2,
];
foreach ($entries as $label => $entry) {
// data set 0 is budgeted
// data set 1 is spent:
$data['datasets'][0]['data'][] = round($entry['earned'], 2);
$data['datasets'][1]['data'][] = round(bcmul($entry['spent'], '-1'), 2);
}
return $data;
}
/**
* @param array $entries
*