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

75 lines
2.4 KiB
PHP
Raw Normal View History

2016-10-08 16:24:07 +02:00
<?php
/**
* AccountController.php
2020-01-31 07:32:04 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2016-10-08 16:24:07 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2016-10-08 16:24:07 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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;
use JsonException;
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-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
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:
2022-10-30 14:24:28 +01:00
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('account-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
return $cache->get();
}
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();
2022-10-31 05:40:59 +01:00
} catch (Throwable $e) {
2018-08-07 19:29:40 +02:00
Log::debug(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage()));
$result = 'Could not render view.';
}
2021-04-07 07:28:43 +02:00
$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
}