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

77 lines
2.4 KiB
PHP
Raw Normal View History

2016-10-08 16:24:07 +02:00
<?php
/**
* AccountController.php
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
2016-10-08 16:24:07 +02:00
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
2016-10-08 16:24:07 +02:00
*
2017-10-21 08:40:00 +02:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 14:41:58 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-10-08 16:24:07 +02:00
*/
declare(strict_types=1);
2016-10-08 16:24:07 +02:00
namespace FireflyIII\Http\Controllers\Report;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
2016-10-08 16:24:07 +02:00
use Illuminate\Support\Collection;
2018-08-07 19:29:40 +02:00
use Log;
use Throwable;
2016-10-08 16:24:07 +02:00
/**
2017-11-15 12:25:49 +01:00
* Class AccountController.
2016-10-08 16:24:07 +02:00
*/
class AccountController extends Controller
{
2018-07-08 12:08:53 +02:00
2016-10-08 16:24:07 +02:00
/**
2018-07-21 08:55:32 +02:00
* Show partial overview for account balances.
*
2016-12-06 08:59:08 +01:00
* @param Collection $accounts
2016-10-08 16:24:07 +02:00
* @param Carbon $start
* @param Carbon $end
*
2016-12-06 08:59:08 +01:00
* @return mixed|string
2017-12-22 18:32:43 +01:00
*
2016-10-08 16:24:07 +02:00
*/
2016-12-06 08:59:08 +01:00
public function general(Collection $accounts, Carbon $start, Carbon $end)
2016-10-08 16:24:07 +02:00
{
// chart properties for cache:
$cache = new CacheProperties;
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('account-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
2017-03-04 11:19:44 +01:00
return $cache->get(); // @codeCoverageIgnore
}
2016-12-06 08:59:08 +01:00
/** @var AccountTaskerInterface $accountTasker */
2016-10-08 16:24:07 +02:00
$accountTasker = app(AccountTaskerInterface::class);
2016-12-06 08:59:08 +01:00
$accountReport = $accountTasker->getAccountReport($accounts, $start, $end);
2018-08-07 19:29:40 +02:00
try {
$result = view('reports.partials.accounts', compact('accountReport'))->render();
2018-09-02 20:13:25 +02:00
// @codeCoverageIgnoreStart
2018-08-07 19:29:40 +02:00
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage()));
$result = 'Could not render view.';
}
2018-09-02 20:13:25 +02:00
// @codeCoverageIgnoreEnd
$cache->store($result);
2016-10-29 07:44:46 +02:00
return $result;
2016-10-08 16:24:07 +02:00
}
2016-10-23 12:42:44 +02:00
}