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

163 lines
4.6 KiB
PHP
Raw Normal View History

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