Files
firefly-iii/app/Http/Controllers/Chart/AccountController.php

161 lines
4.6 KiB
PHP
Raw Normal View History

2015-05-16 09:41:14 +02:00
<?php
namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
2015-06-03 18:22:47 +02:00
use FireflyIII\Support\CacheProperties;
2015-05-17 18:03:16 +02:00
use Illuminate\Support\Collection;
2015-05-16 09:41:14 +02:00
use Preferences;
use Response;
use Session;
/**
* Class AccountController
*
* @package FireflyIII\Http\Controllers\Chart
*/
class AccountController extends Controller
{
/** @var \FireflyIII\Generator\Chart\Account\AccountChartGenerator */
protected $generator;
/**
2015-06-28 10:03:34 +02:00
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
// create chart generator:
2015-07-07 19:09:45 +02:00
$this->generator = app('FireflyIII\Generator\Chart\Account\AccountChartGenerator');
}
2015-12-12 10:41:51 +01:00
/**
* Shows the balances for a given set of dates and accounts.
2015-12-28 07:38:02 +01:00
*
2015-12-28 20:04:54 +01:00
* @param $reportType
2015-12-28 07:31:48 +01:00
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
2015-12-12 10:41:51 +01:00
*
2015-12-28 07:31:48 +01:00
* @return \Illuminate\Http\JsonResponse
2015-12-12 10:41:51 +01:00
*/
2015-12-28 20:04:54 +01:00
public function report($reportType, Carbon $start, Carbon $end, Collection $accounts)
2015-12-12 10:41:51 +01:00
{
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('all');
$cache->addProperty('accounts');
$cache->addProperty('default');
2016-01-01 21:49:27 +01:00
$cache->addProperty($reportType);
2015-12-12 17:51:07 +01:00
$cache->addProperty($accounts);
2015-12-12 10:41:51 +01:00
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
// make chart:
2015-12-27 09:35:24 +01:00
$data = $this->generator->frontpage($accounts, $start, $end);
2015-12-12 10:41:51 +01:00
$cache->store($data);
return Response::json($data);
2015-05-17 18:03:16 +02:00
}
2015-08-01 07:04:41 +02:00
/**
* Shows the balances for all the user's expense accounts.
*
* @param ARI $repository
2015-08-01 07:04:41 +02:00
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function expenseAccounts(ARI $repository)
2015-08-01 07:04:41 +02:00
{
$start = clone Session::get('start', Carbon::now()->startOfMonth());
$end = clone Session::get('end', Carbon::now()->endOfMonth());
$accounts = $repository->getAccounts(['Expense account', 'Beneficiary account']);
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('expenseAccounts');
$cache->addProperty('accounts');
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
$data = $this->generator->expenseAccounts($accounts, $start, $end);
$cache->store($data);
return Response::json($data);
}
2015-05-16 09:41:14 +02:00
/**
* Shows the balances for all the user's frontpage accounts.
*
* @param ARI $repository
2015-05-16 09:41:14 +02:00
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function frontpage(ARI $repository)
2015-05-16 09:41:14 +02:00
{
$frontPage = Preferences::get('frontPageAccounts', []);
$start = clone Session::get('start', Carbon::now()->startOfMonth());
$end = clone Session::get('end', Carbon::now()->endOfMonth());
2015-05-16 09:41:14 +02:00
$accounts = $repository->getFrontpageAccounts($frontPage);
2015-06-01 18:41:18 +02:00
// chart properties for cache:
2015-06-03 21:25:11 +02:00
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('frontpage');
$cache->addProperty('accounts');
if ($cache->has()) {
2015-06-27 22:22:27 +02:00
return Response::json($cache->get()); // @codeCoverageIgnore
2015-06-01 18:41:18 +02:00
}
2015-06-27 08:38:27 +02:00
$data = $this->generator->frontpage($accounts, $start, $end);
2015-06-03 21:25:11 +02:00
$cache->store($data);
2015-06-01 18:41:18 +02:00
return Response::json($data);
2015-05-16 09:41:14 +02:00
}
/**
* Shows an account's balance for a single month.
*
* @param Account $account
*
* @return \Symfony\Component\HttpFoundation\Response
*/
2015-06-27 08:38:27 +02:00
public function single(Account $account)
2015-05-16 09:41:14 +02:00
{
2015-06-27 08:38:27 +02:00
2015-05-16 09:41:14 +02:00
2015-06-27 11:44:18 +02:00
$start = Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
2015-05-16 09:41:14 +02:00
// chart properties for cache:
2015-06-03 21:25:11 +02:00
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('frontpage');
$cache->addProperty('single');
$cache->addProperty($account->id);
if ($cache->has()) {
2015-06-27 22:22:27 +02:00
return Response::json($cache->get()); // @codeCoverageIgnore
}
2015-06-27 08:38:27 +02:00
$data = $this->generator->single($account, $start, $end);
2015-06-03 21:25:11 +02:00
$cache->store($data);
return Response::json($data);
2015-05-16 09:41:14 +02:00
}
2015-05-20 19:56:14 +02:00
}