mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-03 12:47:17 -06:00
52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace FireflyIII\Generator\Chart\PiggyBank;
|
||
|
|
||
|
use Carbon\Carbon;
|
||
|
use Config;
|
||
|
use Illuminate\Support\Collection;
|
||
|
use Preferences;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Class GooglePiggyBankChartGenerator
|
||
|
*
|
||
|
* @package FireflyIII\Generator\Chart\PiggyBank
|
||
|
*/
|
||
|
class ChartJsPiggyBankChartGenerator implements PiggyBankChartGenerator
|
||
|
{
|
||
|
|
||
|
/**
|
||
|
* @param Collection $set
|
||
|
*
|
||
|
* @return array
|
||
|
*/
|
||
|
public function history(Collection $set)
|
||
|
{
|
||
|
|
||
|
// language:
|
||
|
$language = Preferences::get('language', 'en')->data;
|
||
|
$format = Config::get('firefly.month.' . $language);
|
||
|
|
||
|
$data = [
|
||
|
'count' => 1,
|
||
|
'labels' => [],
|
||
|
'datasets' => [
|
||
|
[
|
||
|
'label' => 'Diff',
|
||
|
'data' => []
|
||
|
]
|
||
|
],
|
||
|
];
|
||
|
$sum = '0';
|
||
|
bcscale(2);
|
||
|
foreach ($set as $entry) {
|
||
|
$date = new Carbon($entry->date);
|
||
|
$sum = bcadd($sum, $entry->sum);
|
||
|
$data['labels'][] = $date->formatLocalized($format);
|
||
|
$data['datasets'][0]['data'][] = round($sum, 2);
|
||
|
}
|
||
|
|
||
|
return $data;
|
||
|
}
|
||
|
}
|