2015-06-27 13:39:50 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FireflyIII\Generator\Chart\Report;
|
|
|
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
/**
|
2015-08-01 00:22:48 -05:00
|
|
|
* Class ChartJsReportChartGenerator
|
2015-06-27 13:39:50 -05:00
|
|
|
*
|
|
|
|
* @package FireflyIII\Generator\Chart\Report
|
|
|
|
*/
|
|
|
|
class ChartJsReportChartGenerator implements ReportChartGenerator
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2015-12-28 00:12:47 -06:00
|
|
|
* Same as above but other translations.
|
|
|
|
*
|
2015-06-27 13:39:50 -05:00
|
|
|
* @param Collection $entries
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-12-28 00:12:47 -06:00
|
|
|
public function multiYearInOut(Collection $entries)
|
2015-06-27 13:39:50 -05:00
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'count' => 2,
|
|
|
|
'labels' => [],
|
|
|
|
'datasets' => [
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
2015-06-27 13:39:50 -05:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
|
|
|
],
|
2015-06-27 13:39:50 -05:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($entries as $entry) {
|
2015-12-28 00:12:47 -06:00
|
|
|
$data['labels'][] = $entry[0]->formatLocalized('%Y');
|
2015-06-27 13:39:50 -05:00
|
|
|
$data['datasets'][0]['data'][] = round($entry[1], 2);
|
2015-09-29 02:28:16 -05:00
|
|
|
$data['datasets'][1]['data'][] = round($entry[2], 2);
|
2015-06-27 13:39:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2015-12-14 14:11:26 -06:00
|
|
|
/**
|
2015-12-28 00:12:47 -06:00
|
|
|
* @param string $income
|
|
|
|
* @param string $expense
|
|
|
|
* @param int $count
|
2015-12-14 14:11:26 -06:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-12-28 00:12:47 -06:00
|
|
|
public function multiYearInOutSummarized($income, $expense, $count)
|
2015-12-14 14:11:26 -06:00
|
|
|
{
|
2015-12-28 00:12:47 -06:00
|
|
|
$data = [
|
2015-12-14 14:11:26 -06:00
|
|
|
'count' => 2,
|
2015-12-28 00:12:47 -06:00
|
|
|
'labels' => [trans('firefly.sum_of_years'), trans('firefly.average_of_years')],
|
2015-12-14 14:11:26 -06:00
|
|
|
'datasets' => [
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
2015-12-14 14:11:26 -06:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
|
|
|
],
|
2015-12-14 14:11:26 -06:00
|
|
|
],
|
|
|
|
];
|
2015-12-28 00:12:47 -06:00
|
|
|
$data['datasets'][0]['data'][] = round($income, 2);
|
|
|
|
$data['datasets'][1]['data'][] = round($expense, 2);
|
|
|
|
$data['datasets'][0]['data'][] = round(($income / $count), 2);
|
|
|
|
$data['datasets'][1]['data'][] = round(($expense / $count), 2);
|
2015-12-14 14:11:26 -06:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2015-06-27 13:39:50 -05:00
|
|
|
/**
|
2015-12-28 00:12:47 -06:00
|
|
|
* @param Collection $entries
|
2015-06-27 13:39:50 -05:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-12-28 00:12:47 -06:00
|
|
|
public function yearInOut(Collection $entries)
|
2015-06-27 13:39:50 -05:00
|
|
|
{
|
2015-12-28 00:12:47 -06:00
|
|
|
// language:
|
|
|
|
$format = trans('config.month');
|
2015-06-27 13:39:50 -05:00
|
|
|
|
2015-12-28 00:12:47 -06:00
|
|
|
$data = [
|
2015-06-27 13:39:50 -05:00
|
|
|
'count' => 2,
|
2015-12-28 00:12:47 -06:00
|
|
|
'labels' => [],
|
2015-06-27 13:39:50 -05:00
|
|
|
'datasets' => [
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
2015-06-27 13:39:50 -05:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
|
|
|
],
|
2015-06-27 13:39:50 -05:00
|
|
|
],
|
|
|
|
];
|
2015-12-28 00:12:47 -06:00
|
|
|
|
|
|
|
foreach ($entries as $entry) {
|
|
|
|
$data['labels'][] = $entry[0]->formatLocalized($format);
|
|
|
|
$data['datasets'][0]['data'][] = round($entry[1], 2);
|
|
|
|
$data['datasets'][1]['data'][] = round($entry[2], 2);
|
|
|
|
}
|
2015-07-06 09:52:18 -05:00
|
|
|
|
2015-06-27 13:39:50 -05:00
|
|
|
return $data;
|
|
|
|
}
|
2015-12-14 14:11:26 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $income
|
|
|
|
* @param string $expense
|
|
|
|
* @param int $count
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-12-28 00:12:47 -06:00
|
|
|
public function yearInOutSummarized($income, $expense, $count)
|
2015-12-14 14:11:26 -06:00
|
|
|
{
|
2015-12-28 00:12:47 -06:00
|
|
|
|
2015-12-14 14:11:26 -06:00
|
|
|
$data = [
|
|
|
|
'count' => 2,
|
2015-12-28 00:12:47 -06:00
|
|
|
'labels' => [trans('firefly.sum_of_year'), trans('firefly.average_of_year')],
|
2015-12-14 14:11:26 -06:00
|
|
|
'datasets' => [
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
2015-12-14 14:11:26 -06:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 16:12:52 -06:00
|
|
|
'data' => [],
|
|
|
|
],
|
2015-12-14 14:11:26 -06:00
|
|
|
],
|
|
|
|
];
|
|
|
|
$data['datasets'][0]['data'][] = round($income, 2);
|
2015-12-18 09:38:50 -06:00
|
|
|
$data['datasets'][1]['data'][] = round($expense, 2);
|
2015-12-14 14:11:26 -06:00
|
|
|
$data['datasets'][0]['data'][] = round(($income / $count), 2);
|
2015-12-18 09:38:50 -06:00
|
|
|
$data['datasets'][1]['data'][] = round(($expense / $count), 2);
|
2015-12-14 14:11:26 -06:00
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2015-06-28 01:24:12 -05:00
|
|
|
}
|