mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-15 09:53:36 -06:00
95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace FireflyIII\Http\Controllers\Chart;
|
||
|
|
||
|
use Carbon\Carbon;
|
||
|
use FireflyIII\Http\Controllers\Controller;
|
||
|
use FireflyIII\Models\Account;
|
||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||
|
use Grumpydictator\Gchart\GChart;
|
||
|
use Preferences;
|
||
|
use Response;
|
||
|
use Session;
|
||
|
use Steam;
|
||
|
|
||
|
/**
|
||
|
* Class AccountController
|
||
|
*
|
||
|
* @package FireflyIII\Http\Controllers\Chart
|
||
|
*/
|
||
|
class AccountController extends Controller
|
||
|
{
|
||
|
/**
|
||
|
* Shows the balances for all the user's frontpage accounts.
|
||
|
*
|
||
|
* @param GChart $chart
|
||
|
* @param AccountRepositoryInterface $repository
|
||
|
*
|
||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||
|
*/
|
||
|
public function frontpage(GChart $chart, AccountRepositoryInterface $repository)
|
||
|
{
|
||
|
$chart->addColumn(trans('firefly.dayOfMonth'), 'date');
|
||
|
|
||
|
$frontPage = Preferences::get('frontPageAccounts', []);
|
||
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||
|
$accounts = $repository->getFrontpageAccounts($frontPage);
|
||
|
|
||
|
$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 Response::json($chart->getData());
|
||
|
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Shows an account's balance for a single month.
|
||
|
*
|
||
|
* @param GChart $chart
|
||
|
* @param Account $account
|
||
|
*
|
||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||
|
*/
|
||
|
public function single(GChart $chart, 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());
|
||
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||
|
$current = clone $start;
|
||
|
$today = new Carbon;
|
||
|
|
||
|
while ($end >= $current) {
|
||
|
$certain = $current < $today;
|
||
|
$chart->addRow(clone $current, Steam::balance($account, $current), $certain);
|
||
|
$current->addDay();
|
||
|
}
|
||
|
|
||
|
|
||
|
$chart->generate();
|
||
|
|
||
|
return Response::json($chart->getData());
|
||
|
}
|
||
|
}
|