mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-20 21:43:08 -06:00
Fixed the chart generator.
This commit is contained in:
parent
63ff01e78d
commit
6cc041cd39
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace FireflyIII\Generator\Chart\Account;
|
namespace FireflyIII\Generator\Chart\Account;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
@ -20,4 +21,22 @@ interface AccountChartGenerator
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function all(Collection $accounts, Carbon $start, Carbon $end);
|
public function all(Collection $accounts, Carbon $start, Carbon $end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $accounts, Carbon $start, Carbon $end);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function single(Account $account, Carbon $start, Carbon $end);
|
||||||
}
|
}
|
@ -3,6 +3,7 @@
|
|||||||
namespace FireflyIII\Generator\Chart\Account;
|
namespace FireflyIII\Generator\Chart\Account;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\Account;
|
||||||
use Grumpydictator\Gchart\GChart;
|
use Grumpydictator\Gchart\GChart;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Steam;
|
use Steam;
|
||||||
@ -53,4 +54,69 @@ class GoogleAccountChartGenerator implements AccountChartGenerator
|
|||||||
|
|
||||||
return $chart->getData();
|
return $chart->getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function frontpage(Collection $accounts, Carbon $start, Carbon $end)
|
||||||
|
{
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.dayOfMonth'), 'date');
|
||||||
|
|
||||||
|
$index = 1;
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number');
|
||||||
|
$chart->addCertainty($index);
|
||||||
|
$index++;
|
||||||
|
}
|
||||||
|
$current = clone $start;
|
||||||
|
$current->subDay();
|
||||||
|
$today = Carbon::now();
|
||||||
|
while ($end >= $current) {
|
||||||
|
$row = [clone $current];
|
||||||
|
$certain = $current < $today;
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
$row[] = Steam::balance($account, $current);
|
||||||
|
$row[] = $certain;
|
||||||
|
}
|
||||||
|
$chart->addRowArray($row);
|
||||||
|
$current->addDay();
|
||||||
|
}
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function single(Account $account, Carbon $start, Carbon $end)
|
||||||
|
{
|
||||||
|
$current = clone $start;
|
||||||
|
$today = new Carbon;
|
||||||
|
$chart = new GChart;
|
||||||
|
$chart->addColumn(trans('firefly.dayOfMonth'), 'date');
|
||||||
|
$chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number');
|
||||||
|
$chart->addCertainty(1);
|
||||||
|
|
||||||
|
while ($end >= $current) {
|
||||||
|
$certain = $current < $today;
|
||||||
|
$chart->addRow(clone $current, Steam::balance($account, $current), $certain);
|
||||||
|
$current->addDay();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$chart->generate();
|
||||||
|
|
||||||
|
return $chart->getData();
|
||||||
|
}
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ class AccountController extends Controller
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
// create chart generator:
|
// create chart generator:
|
||||||
$generator = App::make('FireflyIII\Generator\Chart\Account\AccountChartGenerator');
|
$this->generator = App::make('FireflyIII\Generator\Chart\Account\AccountChartGenerator');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,15 +85,12 @@ class AccountController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Shows the balances for all the user's frontpage accounts.
|
* Shows the balances for all the user's frontpage accounts.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param AccountRepositoryInterface $repository
|
* @param AccountRepositoryInterface $repository
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function frontpage(GChart $chart, AccountRepositoryInterface $repository)
|
public function frontpage(AccountRepositoryInterface $repository)
|
||||||
{
|
{
|
||||||
$chart->addColumn(trans('firefly.dayOfMonth'), 'date');
|
|
||||||
|
|
||||||
$frontPage = Preferences::get('frontPageAccounts', []);
|
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
@ -109,30 +106,7 @@ class AccountController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data = $this->generator->frontpage($accounts, $start, $end);
|
||||||
$index = 1;
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number');
|
|
||||||
$chart->addCertainty($index);
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
$current = clone $start;
|
|
||||||
$current->subDay();
|
|
||||||
$today = Carbon::now();
|
|
||||||
while ($end >= $current) {
|
|
||||||
$row = [clone $current];
|
|
||||||
$certain = $current < $today;
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$row[] = Steam::balance($account, $current);
|
|
||||||
$row[] = $certain;
|
|
||||||
}
|
|
||||||
$chart->addRowArray($row);
|
|
||||||
$current->addDay();
|
|
||||||
}
|
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
@ -142,21 +116,16 @@ class AccountController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Shows an account's balance for a single month.
|
* Shows an account's balance for a single month.
|
||||||
*
|
*
|
||||||
* @param GChart $chart
|
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function single(GChart $chart, Account $account)
|
public function single(Account $account)
|
||||||
{
|
{
|
||||||
$chart->addColumn(trans('firefly.dayOfMonth'), 'date');
|
|
||||||
$chart->addColumn(trans('firefly.balanceFor', ['name' => $account->name]), 'number');
|
|
||||||
$chart->addCertainty(1);
|
|
||||||
|
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
$current = clone $start;
|
|
||||||
$today = new Carbon;
|
|
||||||
|
|
||||||
// chart properties for cache:
|
// chart properties for cache:
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
@ -169,16 +138,7 @@ class AccountController extends Controller
|
|||||||
return Response::json($cache->get()); // @codeCoverageIgnore
|
return Response::json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
while ($end >= $current) {
|
$data = $this->generator->single($account, $start, $end);
|
||||||
$certain = $current < $today;
|
|
||||||
$chart->addRow(clone $current, Steam::balance($account, $current), $certain);
|
|
||||||
$current->addDay();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$chart->generate();
|
|
||||||
|
|
||||||
$data = $chart->getData();
|
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
Loading…
Reference in New Issue
Block a user