mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-20 11:19:16 +00:00
Remove unused code.
This commit is contained in:
@@ -1,139 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BalanceReportHelper.php
|
|
||||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This file is part of Firefly III.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace FireflyIII\Helpers\Report;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
|
||||||
use FireflyIII\Models\Account;
|
|
||||||
use FireflyIII\Models\Budget;
|
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class BalanceReportHelper.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
class BalanceReportHelper implements BalanceReportHelperInterface
|
|
||||||
{
|
|
||||||
/** @var BudgetRepositoryInterface Budget repository */
|
|
||||||
protected $budgetRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ReportHelper constructor.
|
|
||||||
* @param BudgetRepositoryInterface $budgetRepository
|
|
||||||
*/
|
|
||||||
public function __construct(BudgetRepositoryInterface $budgetRepository)
|
|
||||||
{
|
|
||||||
$this->budgetRepository = $budgetRepository;
|
|
||||||
|
|
||||||
if ('testing' === config('app.env')) {
|
|
||||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a balance report.
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): array
|
|
||||||
{
|
|
||||||
Log::debug('Start of balance report');
|
|
||||||
$report = [
|
|
||||||
'budgets' => [],
|
|
||||||
'accounts' => [],
|
|
||||||
];
|
|
||||||
/** @var Account $account */
|
|
||||||
foreach ($accounts as $account) {
|
|
||||||
$report['accounts'][$account->id] = [
|
|
||||||
'id' => $account->id,
|
|
||||||
'name' => $account->name,
|
|
||||||
'iban' => $account->iban,
|
|
||||||
'sum' => '0',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$budgets = $this->budgetRepository->getBudgets();
|
|
||||||
|
|
||||||
/** @var Budget $budget */
|
|
||||||
foreach ($budgets as $budget) {
|
|
||||||
$budgetId = $budget->id;
|
|
||||||
$report['budgets'][$budgetId] = [
|
|
||||||
'budget_id' => $budgetId,
|
|
||||||
'budget_name' => $budget->name,
|
|
||||||
'spent' => [], // per account
|
|
||||||
'sums' => [], // per currency
|
|
||||||
];
|
|
||||||
$spent = [];
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
|
|
||||||
->getExtractedJournals();
|
|
||||||
/** @var array $journal */
|
|
||||||
foreach ($journals as $journal) {
|
|
||||||
$sourceAccount = $journal['source_account_id'];
|
|
||||||
$currencyId = $journal['currency_id'];
|
|
||||||
$spent[$sourceAccount] = $spent[$sourceAccount] ?? [
|
|
||||||
'source_account_id' => $sourceAccount,
|
|
||||||
'currency_id' => $journal['currency_id'],
|
|
||||||
'currency_code' => $journal['currency_code'],
|
|
||||||
'currency_name' => $journal['currency_name'],
|
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
|
||||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
|
||||||
'spent' => '0',
|
|
||||||
];
|
|
||||||
$spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']);
|
|
||||||
|
|
||||||
// also fix sum:
|
|
||||||
$report['sums'][$budgetId][$currencyId] = $report['sums'][$budgetId][$currencyId] ?? [
|
|
||||||
'sum' => '0',
|
|
||||||
'currency_id' => $journal['currency_id'],
|
|
||||||
'currency_code' => $journal['currency_code'],
|
|
||||||
'currency_name' => $journal['currency_name'],
|
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
|
||||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
|
||||||
];
|
|
||||||
$report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']);
|
|
||||||
$report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']);
|
|
||||||
|
|
||||||
// add currency info for account sum
|
|
||||||
$report['accounts'][$sourceAccount]['currency_id'] = $journal['currency_id'];
|
|
||||||
$report['accounts'][$sourceAccount]['currency_code'] = $journal['currency_code'];
|
|
||||||
$report['accounts'][$sourceAccount]['currency_name'] = $journal['currency_name'];
|
|
||||||
$report['accounts'][$sourceAccount]['currency_symbol'] = $journal['currency_symbol'];
|
|
||||||
$report['accounts'][$sourceAccount]['currency_decimal_places'] = $journal['currency_decimal_places'];
|
|
||||||
}
|
|
||||||
$report['budgets'][$budgetId]['spent'] = $spent;
|
|
||||||
// get transactions in budget
|
|
||||||
}
|
|
||||||
return $report;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* BalanceReportHelperInterface.php
|
|
||||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This file is part of Firefly III.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace FireflyIII\Helpers\Report;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use FireflyIII\Helpers\Collection\Balance;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface BalanceReportHelperInterface.
|
|
||||||
*/
|
|
||||||
interface BalanceReportHelperInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Generates the report (duh).
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getBalanceReport(Collection $accounts, Carbon $start, Carbon $end): array;
|
|
||||||
}
|
|
@@ -23,9 +23,12 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Controllers\Report;
|
namespace FireflyIII\Http\Controllers\Report;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Models\Account;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
@@ -35,6 +38,25 @@ use Throwable;
|
|||||||
*/
|
*/
|
||||||
class BalanceController extends Controller
|
class BalanceController extends Controller
|
||||||
{
|
{
|
||||||
|
/** @var BudgetRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BalanceController constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->middleware(
|
||||||
|
static function ($request, $next) {
|
||||||
|
$this->repository = app(BudgetRepositoryInterface::class);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show overview of budget balances.
|
* Show overview of budget balances.
|
||||||
@@ -47,18 +69,75 @@ class BalanceController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function general(Collection $accounts, Carbon $start, Carbon $end)
|
public function general(Collection $accounts, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
// chart properties for cache:
|
$report = [
|
||||||
$cache = new CacheProperties;
|
'budgets' => [],
|
||||||
$cache->addProperty($start);
|
'accounts' => [],
|
||||||
$cache->addProperty($end);
|
];
|
||||||
$cache->addProperty('balance-report');
|
/** @var Account $account */
|
||||||
$cache->addProperty($accounts->pluck('id')->toArray());
|
foreach ($accounts as $account) {
|
||||||
if ($cache->has()) {
|
$report['accounts'][$account->id] = [
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
'id' => $account->id,
|
||||||
|
'name' => $account->name,
|
||||||
|
'iban' => $account->iban,
|
||||||
|
'sum' => '0',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$helper = app(BalanceReportHelperInterface::class);
|
|
||||||
$report = $helper->getBalanceReport($accounts, $start, $end);
|
$budgets = $this->repository->getBudgets();
|
||||||
// TODO no budget.
|
|
||||||
|
/** @var Budget $budget */
|
||||||
|
foreach ($budgets as $budget) {
|
||||||
|
$budgetId = $budget->id;
|
||||||
|
$report['budgets'][$budgetId] = [
|
||||||
|
'budget_id' => $budgetId,
|
||||||
|
'budget_name' => $budget->name,
|
||||||
|
'spent' => [], // per account
|
||||||
|
'sums' => [], // per currency
|
||||||
|
];
|
||||||
|
$spent = [];
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
|
||||||
|
->getExtractedJournals();
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$sourceAccount = $journal['source_account_id'];
|
||||||
|
$currencyId = $journal['currency_id'];
|
||||||
|
$spent[$sourceAccount] = $spent[$sourceAccount] ?? [
|
||||||
|
'source_account_id' => $sourceAccount,
|
||||||
|
'currency_id' => $journal['currency_id'],
|
||||||
|
'currency_code' => $journal['currency_code'],
|
||||||
|
'currency_name' => $journal['currency_name'],
|
||||||
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
|
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||||
|
'spent' => '0',
|
||||||
|
];
|
||||||
|
$spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']);
|
||||||
|
|
||||||
|
// also fix sum:
|
||||||
|
$report['sums'][$budgetId][$currencyId] = $report['sums'][$budgetId][$currencyId] ?? [
|
||||||
|
'sum' => '0',
|
||||||
|
'currency_id' => $journal['currency_id'],
|
||||||
|
'currency_code' => $journal['currency_code'],
|
||||||
|
'currency_name' => $journal['currency_name'],
|
||||||
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
|
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||||
|
];
|
||||||
|
$report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']);
|
||||||
|
$report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']);
|
||||||
|
|
||||||
|
// add currency info for account sum
|
||||||
|
$report['accounts'][$sourceAccount]['currency_id'] = $journal['currency_id'];
|
||||||
|
$report['accounts'][$sourceAccount]['currency_code'] = $journal['currency_code'];
|
||||||
|
$report['accounts'][$sourceAccount]['currency_name'] = $journal['currency_name'];
|
||||||
|
$report['accounts'][$sourceAccount]['currency_symbol'] = $journal['currency_symbol'];
|
||||||
|
$report['accounts'][$sourceAccount]['currency_decimal_places'] = $journal['currency_decimal_places'];
|
||||||
|
}
|
||||||
|
$report['budgets'][$budgetId]['spent'] = $spent;
|
||||||
|
// get transactions in budget
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = view('reports.partials.balance', compact('report'))->render();
|
$result = view('reports.partials.balance', compact('report'))->render();
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
@@ -66,8 +145,6 @@ class BalanceController extends Controller
|
|||||||
Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
|
Log::debug(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
|
||||||
$result = 'Could not render view.';
|
$result = 'Could not render view.';
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
$cache->store($result);
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@@ -31,8 +31,6 @@ use FireflyIII\Helpers\Fiscal\FiscalHelper;
|
|||||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||||
use FireflyIII\Helpers\Help\Help;
|
use FireflyIII\Helpers\Help\Help;
|
||||||
use FireflyIII\Helpers\Help\HelpInterface;
|
use FireflyIII\Helpers\Help\HelpInterface;
|
||||||
use FireflyIII\Helpers\Report\BalanceReportHelper;
|
|
||||||
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
|
|
||||||
use FireflyIII\Helpers\Report\NetWorth;
|
use FireflyIII\Helpers\Report\NetWorth;
|
||||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||||
use FireflyIII\Helpers\Report\PopupReport;
|
use FireflyIII\Helpers\Report\PopupReport;
|
||||||
@@ -186,7 +184,6 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
$this->app->bind(HelpInterface::class, Help::class);
|
$this->app->bind(HelpInterface::class, Help::class);
|
||||||
$this->app->bind(ReportHelperInterface::class, ReportHelper::class);
|
$this->app->bind(ReportHelperInterface::class, ReportHelper::class);
|
||||||
$this->app->bind(FiscalHelperInterface::class, FiscalHelper::class);
|
$this->app->bind(FiscalHelperInterface::class, FiscalHelper::class);
|
||||||
$this->app->bind(BalanceReportHelperInterface::class, BalanceReportHelper::class);
|
|
||||||
$class = (string)config(sprintf('firefly.cer_providers.%s', (string)config('firefly.cer_provider')));
|
$class = (string)config(sprintf('firefly.cer_providers.%s', (string)config('firefly.cer_provider')));
|
||||||
if ('' === $class) {
|
if ('' === $class) {
|
||||||
throw new FireflyException('Invalid currency exchange rate provider. Cannot continue.');
|
throw new FireflyException('Invalid currency exchange rate provider. Cannot continue.');
|
||||||
|
@@ -24,7 +24,6 @@ namespace Tests\Feature\Controllers\Report;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
|
||||||
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
|
|
||||||
use Log;
|
use Log;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -54,14 +53,12 @@ class BalanceControllerTest extends TestCase
|
|||||||
public function testGeneral(): void
|
public function testGeneral(): void
|
||||||
{
|
{
|
||||||
$this->mockDefaultSession();
|
$this->mockDefaultSession();
|
||||||
$balance = $this->mock(BalanceReportHelperInterface::class);
|
|
||||||
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
|
||||||
$date = new Carbon;
|
$date = new Carbon;
|
||||||
|
|
||||||
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
|
||||||
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
|
||||||
$balance->shouldReceive('getBalanceReport')->andReturn([]);
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('report-data.balance.general', ['1', '20120101', '20120131']));
|
$response = $this->get(route('report-data.balance.general', ['1', '20120101', '20120131']));
|
||||||
|
Reference in New Issue
Block a user