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