2015-06-27 20:39:50 +02:00
|
|
|
<?php
|
2016-02-05 12:08:25 +01:00
|
|
|
declare(strict_types = 1);
|
2015-06-27 20:39:50 +02:00
|
|
|
namespace FireflyIII\Generator\Chart\Report;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
|
|
|
|
|
/**
|
2015-08-01 07:22:48 +02:00
|
|
|
* Class ChartJsReportChartGenerator
|
2015-06-27 20:39:50 +02:00
|
|
|
*
|
|
|
|
|
* @package FireflyIII\Generator\Chart\Report
|
|
|
|
|
*/
|
2016-01-28 21:59:40 +01:00
|
|
|
class ChartJsReportChartGenerator implements ReportChartGeneratorInterface
|
2015-06-27 20:39:50 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-28 07:12:47 +01:00
|
|
|
* Same as above but other translations.
|
|
|
|
|
*
|
2015-06-27 20:39:50 +02:00
|
|
|
* @param Collection $entries
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2016-02-18 07:21:48 +01:00
|
|
|
public function multiYearInOut(Collection $entries): array
|
2015-06-27 20:39:50 +02:00
|
|
|
{
|
|
|
|
|
$data = [
|
|
|
|
|
'count' => 2,
|
|
|
|
|
'labels' => [],
|
|
|
|
|
'datasets' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
2015-06-27 20:39:50 +02:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
|
|
|
|
],
|
2015-06-27 20:39:50 +02:00
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($entries as $entry) {
|
2015-12-28 07:12:47 +01:00
|
|
|
$data['labels'][] = $entry[0]->formatLocalized('%Y');
|
2015-06-27 20:39:50 +02:00
|
|
|
$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
|
|
|
/**
|
2015-12-28 07:12:47 +01:00
|
|
|
* @param string $income
|
|
|
|
|
* @param string $expense
|
|
|
|
|
* @param int $count
|
2015-12-14 21:11:26 +01:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2016-02-18 07:21:48 +01:00
|
|
|
public function multiYearInOutSummarized(string $income, string $expense, int $count): array
|
2015-12-14 21:11:26 +01:00
|
|
|
{
|
2015-12-28 07:12:47 +01:00
|
|
|
$data = [
|
2015-12-14 21:11:26 +01:00
|
|
|
'count' => 2,
|
2015-12-28 07:12:47 +01:00
|
|
|
'labels' => [trans('firefly.sum_of_years'), trans('firefly.average_of_years')],
|
2015-12-14 21:11:26 +01:00
|
|
|
'datasets' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
2015-12-14 21:11:26 +01:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
|
|
|
|
],
|
2015-12-14 21:11:26 +01:00
|
|
|
],
|
|
|
|
|
];
|
2015-12-28 07:12:47 +01: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 21:11:26 +01:00
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 10:04:53 +01:00
|
|
|
/**
|
|
|
|
|
* @param Collection $entries
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function netWorth(Collection $entries) : array
|
|
|
|
|
{
|
|
|
|
|
$format = (string)trans('config.month_and_day');
|
|
|
|
|
$data = [
|
|
|
|
|
'count' => 1,
|
|
|
|
|
'labels' => [],
|
|
|
|
|
'datasets' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.net-worth'),
|
|
|
|
|
'data' => [],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
foreach ($entries as $entry) {
|
2016-03-14 20:53:56 +01:00
|
|
|
$data['labels'][] = trim($entry['date']->formatLocalized($format));
|
2016-03-16 17:48:07 +01:00
|
|
|
$data['datasets'][0]['data'][] = round($entry['net-worth'], 2);
|
2016-02-18 10:04:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 20:39:50 +02:00
|
|
|
/**
|
2015-12-28 07:12:47 +01:00
|
|
|
* @param Collection $entries
|
2015-06-27 20:39:50 +02:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2016-02-18 07:21:48 +01:00
|
|
|
public function yearInOut(Collection $entries): array
|
2015-06-27 20:39:50 +02:00
|
|
|
{
|
2015-12-28 07:12:47 +01:00
|
|
|
// language:
|
2016-01-27 19:35:00 +01:00
|
|
|
$format = (string)trans('config.month');
|
2015-06-27 20:39:50 +02:00
|
|
|
|
2015-12-28 07:12:47 +01:00
|
|
|
$data = [
|
2015-06-27 20:39:50 +02:00
|
|
|
'count' => 2,
|
2015-12-28 07:12:47 +01:00
|
|
|
'labels' => [],
|
2015-06-27 20:39:50 +02:00
|
|
|
'datasets' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
2015-06-27 20:39:50 +02:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
|
|
|
|
],
|
2015-06-27 20:39:50 +02:00
|
|
|
],
|
|
|
|
|
];
|
2015-12-28 07:12:47 +01: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 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
|
|
|
|
|
*/
|
2016-02-18 07:21:48 +01:00
|
|
|
public function yearInOutSummarized(string $income, string $expense, int $count): array
|
2015-12-14 21:11:26 +01:00
|
|
|
{
|
2015-12-28 07:12:47 +01:00
|
|
|
|
2015-12-14 21:11:26 +01:00
|
|
|
$data = [
|
|
|
|
|
'count' => 2,
|
2015-12-28 07:12:47 +01:00
|
|
|
'labels' => [trans('firefly.sum_of_year'), trans('firefly.average_of_year')],
|
2015-12-14 21:11:26 +01:00
|
|
|
'datasets' => [
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.income'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
2015-12-14 21:11:26 +01:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'label' => trans('firefly.expenses'),
|
2016-01-15 23:12:52 +01:00
|
|
|
'data' => [],
|
|
|
|
|
],
|
2015-12-14 21:11:26 +01:00
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$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
|
|
|
}
|