2015-06-27 13:39:50 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FireflyIII\Generator\Chart\Report;
|
|
|
|
|
|
|
|
use Config;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Preferences;
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Collection $entries
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function yearInOut(Collection $entries)
|
|
|
|
{
|
|
|
|
// language:
|
|
|
|
$language = Preferences::get('language', 'en')->data;
|
|
|
|
$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 02:28:16 -05:00
|
|
|
$data['datasets'][1]['data'][] = round($entry[2], 2);
|
2015-06-27 13:39:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $income
|
|
|
|
* @param string $expense
|
|
|
|
* @param int $count
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function yearInOutSummarized($income, $expense, $count)
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'count' => 2,
|
2015-07-09 22:39:35 -05:00
|
|
|
'labels' => [trans('firefly.sum_of_year'), trans('firefly.average_of_year')],
|
2015-06-27 13:39:50 -05:00
|
|
|
'datasets' => [
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.income'),
|
|
|
|
'data' => []
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => trans('firefly.expenses'),
|
|
|
|
'data' => []
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$data['datasets'][0]['data'][] = round($income, 2);
|
2015-09-29 02:29:28 -05:00
|
|
|
$data['datasets'][1]['data'][] = round( $expense, 2);
|
2015-06-27 13:39:50 -05:00
|
|
|
$data['datasets'][0]['data'][] = round(($income / $count), 2);
|
2015-09-29 02:29:28 -05:00
|
|
|
$data['datasets'][1]['data'][] = round(( $expense / $count), 2);
|
2015-07-06 09:52:18 -05:00
|
|
|
|
2015-06-27 13:39:50 -05:00
|
|
|
return $data;
|
|
|
|
}
|
2015-06-28 01:24:12 -05:00
|
|
|
}
|