Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -29,7 +29,6 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Throwable;
/**
* Class AccountController.
@@ -39,11 +38,6 @@ class AccountController extends Controller
/**
* Show partial overview for account balances.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @throws FireflyException
*/
public function general(Collection $accounts, Carbon $start, Carbon $end): string
@@ -61,12 +55,14 @@ class AccountController extends Controller
/** @var AccountTaskerInterface $accountTasker */
$accountTasker = app(AccountTaskerInterface::class);
$accountReport = $accountTasker->getAccountReport($accounts, $start, $end);
try {
$result = view('reports.partials.accounts', compact('accountReport'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}

View File

@@ -32,7 +32,6 @@ use FireflyIII\Models\Budget;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection;
use Throwable;
/**
* Class BalanceController.
@@ -61,11 +60,8 @@ class BalanceController extends Controller
/**
* Show overview of budget balances.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function general(Collection $accounts, Carbon $start, Carbon $end)
@@ -74,6 +70,7 @@ class BalanceController extends Controller
'budgets' => [],
'accounts' => [],
];
/** @var Account $account */
foreach ($accounts as $account) {
$report['accounts'][$account->id] = [
@@ -96,10 +93,13 @@ class BalanceController extends Controller
'sums' => [], // per currency
];
$spent = [];
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
->getExtractedJournals();
->getExtractedJournals()
;
/** @var array $journal */
foreach ($journals as $journal) {
$sourceAccount = $journal['source_account_id'];
@@ -137,12 +137,14 @@ class BalanceController extends Controller
$report['budgets'][$budgetId]['spent'] = $spent;
// get transactions in budget
}
try {
$result = view('reports.partials.balance', compact('report'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.balance: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}

View File

@@ -29,7 +29,6 @@ use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Throwable;
/**
* Class BillController
@@ -37,11 +36,8 @@ use Throwable;
class BillController extends Controller
{
/**
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return mixed|string
*
* @throws FireflyException
*/
public function overview(Collection $accounts, Carbon $start, Carbon $end) // chart properties for cache:
@@ -54,15 +50,18 @@ class BillController extends Controller
if ($cache->has()) {
return $cache->get();
}
/** @var ReportHelperInterface $helper */
$helper = app(ReportHelperInterface::class);
$report = $helper->getBillReport($accounts, $start, $end);
try {
$result = view('reports.partials.bills', compact('report'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budgets: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}

View File

@@ -35,8 +35,6 @@ use FireflyIII\Support\Report\Budget\BudgetReportGenerator;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use JsonException;
use Throwable;
/**
* Class BudgetController.
@@ -49,8 +47,6 @@ class BudgetController extends Controller
/**
* ExpenseReportController constructor.
*
*/
public function __construct()
{
@@ -67,14 +63,10 @@ class BudgetController extends Controller
/**
* Partial used in the budget report.
*
* @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*
* @throws FireflyException
* @throws JsonException
* @throws \JsonException
*/
public function accountPerBudget(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
@@ -94,11 +86,6 @@ class BudgetController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function accounts(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
@@ -106,6 +93,7 @@ class BudgetController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$report = [];
$sums = [];
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
@@ -150,12 +138,8 @@ class BudgetController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
@@ -179,7 +163,7 @@ class BudgetController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$key]['transactions']++;
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
$result[$key]['avg_float'] = (float)$result[$key]['avg']; // intentional float
@@ -193,10 +177,11 @@ class BudgetController extends Controller
try {
$result = view('reports.budget.partials.avg-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
app('log')->error($e->getTraceAsString());
throw new FireflyException($result, 0, $e);
}
@@ -204,11 +189,6 @@ class BudgetController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function budgets(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
@@ -216,6 +196,7 @@ class BudgetController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$sums = [];
$report = [];
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budgetId = $budget->id;
@@ -234,6 +215,7 @@ class BudgetController extends Controller
'currency_decimal_places' => $currency['currency_decimal_places'],
'sum' => '0',
];
/** @var array $budget */
foreach ($currency['budgets'] as $budget) {
$budgetId = $budget['id'];
@@ -247,7 +229,6 @@ class BudgetController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$report[$budgetId]['currencies'][$currencyId]['sum'] = bcadd($report[$budgetId]['currencies'][$currencyId]['sum'], $journal['amount']);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
@@ -274,13 +255,10 @@ class BudgetController extends Controller
/**
* Show partial overview of budgets.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
* @throws JsonException
* @throws \JsonException
*/
public function general(Collection $accounts, Carbon $start, Carbon $end)
{
@@ -301,11 +279,8 @@ class BudgetController extends Controller
/**
* Show budget overview for a period.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return mixed|string
*
* @throws FireflyException
*/
public function period(Collection $accounts, Carbon $start, Carbon $end)
@@ -329,7 +304,7 @@ class BudgetController extends Controller
foreach ($currency['budgets'] as $budget) {
$count = 0;
foreach ($budget['transaction_journals'] as $journal) {
$count++;
++$count;
$key = sprintf('%d-%d', $budget['id'], $currency['currency_id']);
$dateKey = $journal['date']->format($keyFormat);
$report[$key] ??= [
@@ -344,18 +319,20 @@ class BudgetController extends Controller
'entries' => [],
];
$report[$key]['entries'][$dateKey] ??= '0';
$report[$key]['entries'][$dateKey] = bcadd($journal['amount'], $report[$key] ['entries'][$dateKey]);
$report[$key]['sum'] = bcadd($report[$key] ['sum'], $journal['amount']);
$report[$key]['entries'][$dateKey] = bcadd($journal['amount'], $report[$key]['entries'][$dateKey]);
$report[$key]['sum'] = bcadd($report[$key]['sum'], $journal['amount']);
$report[$key]['avg'] = bcdiv($report[$key]['sum'], (string)count($periods));
}
}
}
try {
$result = view('reports.partials.budget-period', compact('report', 'periods'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
@@ -365,12 +342,8 @@ class BudgetController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
@@ -406,9 +379,10 @@ class BudgetController extends Controller
try {
$result = view('reports.budget.partials.top-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
}

View File

@@ -36,7 +36,6 @@ use FireflyIII\Support\Report\Category\CategoryReportGenerator;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Throwable;
/**
* Class CategoryController.
@@ -50,8 +49,6 @@ class CategoryController extends Controller
/**
* ExpenseReportController constructor.
*
*/
public function __construct()
{
@@ -67,11 +64,6 @@ class CategoryController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function accountPerCategory(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
@@ -79,6 +71,7 @@ class CategoryController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
$earned = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
$report = [];
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
@@ -108,10 +101,10 @@ class CategoryController extends Controller
$report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]
??= [
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
$report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['spent'] = bcadd(
$report[$sourceAccountId]['currencies'][$currencyId]['categories'][$category['id']]['spent'],
$journal['amount']
@@ -133,18 +126,18 @@ class CategoryController extends Controller
$destinationId = $journal['destination_account_id'];
$report[$destinationId]['currencies'][$currencyId]
??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'categories' => [],
];
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'categories' => [],
];
$report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]
??= [
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
$report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['earned'] = bcadd(
$report[$destinationId]['currencies'][$currencyId]['categories'][$category['id']]['earned'],
$journal['amount']
@@ -161,11 +154,6 @@ class CategoryController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function accounts(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
@@ -174,6 +162,7 @@ class CategoryController extends Controller
$earned = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
$report = [];
$sums = [];
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
@@ -265,12 +254,8 @@ class CategoryController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function avgExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
@@ -294,7 +279,7 @@ class CategoryController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$key]['transactions']++;
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
$result[$key]['avg_float'] = (float)$result[$key]['avg']; // intentional float
@@ -308,9 +293,10 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.avg-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
@@ -318,12 +304,8 @@ class CategoryController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function avgIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
@@ -347,7 +329,7 @@ class CategoryController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$key]['transactions']++;
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
@@ -361,9 +343,10 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.avg-income', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
@@ -371,11 +354,6 @@ class CategoryController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function categories(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
@@ -384,6 +362,7 @@ class CategoryController extends Controller
$earned = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
$sums = [];
$report = [];
/** @var Category $category */
foreach ($categories as $category) {
$categoryId = $category->id;
@@ -404,6 +383,7 @@ class CategoryController extends Controller
'spent_sum' => '0',
'total_sum' => '0',
];
/** @var array $category */
foreach ($currency['categories'] as $category) {
$categoryId = $category['id'];
@@ -445,6 +425,7 @@ class CategoryController extends Controller
'spent_sum' => '0',
'total_sum' => '0',
];
/** @var array $category */
foreach ($currency['categories'] as $category) {
$categoryId = $category['id'];
@@ -481,11 +462,8 @@ class CategoryController extends Controller
/**
* Show overview of expenses in category.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return mixed|string
*
* @throws FireflyException
*/
public function expenses(Collection $accounts, Carbon $start, Carbon $end)
@@ -528,7 +506,6 @@ class CategoryController extends Controller
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
'sum' => '0',
'entries' => [],
];
foreach ($categoryRow['transaction_journals'] as $journal) {
$date = $journal['date']->format($format);
@@ -546,13 +523,13 @@ class CategoryController extends Controller
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
$cache->store($result);
return $result;
@@ -561,12 +538,6 @@ class CategoryController extends Controller
/**
* Show overview of income in category.
*
* @param Collection $accounts
*
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @throws FireflyException
*/
public function income(Collection $accounts, Carbon $start, Carbon $end): string
@@ -609,7 +580,6 @@ class CategoryController extends Controller
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
'sum' => '0',
'entries' => [],
];
foreach ($categoryRow['transaction_journals'] as $journal) {
$date = $journal['date']->format($format);
@@ -625,13 +595,13 @@ class CategoryController extends Controller
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
$cache->store($result);
return $result;
@@ -640,11 +610,6 @@ class CategoryController extends Controller
/**
* Show overview of category transactions on the default report.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @throws FireflyException
*/
public function operations(Collection $accounts, Carbon $start, Carbon $end): string
@@ -667,13 +632,13 @@ class CategoryController extends Controller
$generator->operations();
$report = $generator->getReport();
try {
$result = view('reports.partials.categories', compact('report'))->render();
$cache->store($result);
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
@@ -681,12 +646,8 @@ class CategoryController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function topExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
@@ -722,9 +683,10 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.top-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($e->getMessage(), 0, $e);
}
@@ -732,12 +694,8 @@ class CategoryController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $categories
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function topIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
@@ -773,9 +731,10 @@ class CategoryController extends Controller
try {
$result = view('reports.category.partials.top-income', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($e->getMessage(), 0, $e);
}

View File

@@ -33,11 +33,9 @@ use FireflyIII\Support\Http\Controllers\AugumentData;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Throwable;
/**
* Class DoubleController
*
*/
class DoubleController extends Controller
{
@@ -51,8 +49,6 @@ class DoubleController extends Controller
/**
* Constructor for ExpenseController
*
*/
public function __construct()
{
@@ -70,12 +66,8 @@ class DoubleController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $doubles
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function avgExpenses(Collection $accounts, Collection $doubles, Carbon $start, Carbon $end)
@@ -100,7 +92,7 @@ class DoubleController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$key]['transactions']++;
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
@@ -113,9 +105,10 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.avg-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($e->getMessage(), 0, $e);
}
@@ -123,12 +116,8 @@ class DoubleController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $doubles
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function avgIncome(Collection $accounts, Collection $doubles, Carbon $start, Carbon $end)
@@ -153,7 +142,7 @@ class DoubleController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$key]['transactions']++;
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
@@ -166,9 +155,10 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.avg-income', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($e->getMessage(), 0, $e);
}
@@ -176,11 +166,6 @@ class DoubleController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $double
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function operations(Collection $accounts, Collection $double, Carbon $start, Carbon $end)
@@ -295,36 +280,6 @@ class DoubleController extends Controller
}
/**
* TODO this method is duplicated.
*
* @param Collection $accounts
* @param int $id
* @param string $name
* @param string|null $iban
*
* @return string
*/
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
{
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name && $account->id !== $id) {
return $account->name;
}
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
return $account->iban;
}
}
return $name;
}
/**
* @param Collection $accounts
* @param Collection $double
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function operationsPerAsset(Collection $accounts, Collection $double, Carbon $start, Carbon $end)
@@ -420,12 +375,8 @@ class DoubleController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $doubles
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function topExpenses(Collection $accounts, Collection $doubles, Carbon $start, Carbon $end)
@@ -461,9 +412,10 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.top-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($e->getMessage(), 0, $e);
}
@@ -471,12 +423,8 @@ class DoubleController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $doubles
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function topIncome(Collection $accounts, Collection $doubles, Carbon $start, Carbon $end)
@@ -512,12 +460,31 @@ class DoubleController extends Controller
try {
$result = view('reports.double.partials.top-income', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($e->getMessage(), 0, $e);
}
return $result;
}
/**
* TODO this method is duplicated.
*/
private function getCounterpartName(Collection $accounts, int $id, string $name, ?string $iban): string
{
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->name === $name && $account->id !== $id) {
return $account->name;
}
if (null !== $account->iban && $account->iban === $iban && $account->id !== $id) {
return $account->iban;
}
}
return $name;
}
}

View File

@@ -29,7 +29,6 @@ use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Throwable;
/**
* Class OperationsController.
@@ -41,8 +40,6 @@ class OperationsController extends Controller
/**
* OperationsController constructor.
*
*/
public function __construct()
{
@@ -61,11 +58,8 @@ class OperationsController extends Controller
/**
* View of income and expense.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return mixed|string
*
* @throws FireflyException
*/
public function expenses(Collection $accounts, Carbon $start, Carbon $end)
@@ -81,12 +75,14 @@ class OperationsController extends Controller
}
$report = $this->tasker->getExpenseReport($start, $end, $accounts);
$type = 'expense-entry';
try {
$result = view('reports.partials.income-expenses', compact('report', 'type'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.income-expense: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
@@ -98,11 +94,6 @@ class OperationsController extends Controller
/**
* View of income.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @throws FireflyException
*/
public function income(Collection $accounts, Carbon $start, Carbon $end): string
@@ -118,12 +109,14 @@ class OperationsController extends Controller
}
$report = $this->tasker->getIncomeReport($start, $end, $accounts);
$type = 'income-entry';
try {
$result = view('reports.partials.income-expenses', compact('report', 'type'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.income-expenses: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
@@ -135,11 +128,8 @@ class OperationsController extends Controller
/**
* Overview of income and expense.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return mixed|string
*
* @throws FireflyException
*/
public function operations(Collection $accounts, Carbon $start, Carbon $end)
@@ -177,10 +167,11 @@ class OperationsController extends Controller
try {
$result = view('reports.partials.operations', compact('sums'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render reports.partials.operations: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
$cache->store($result);

View File

@@ -32,10 +32,8 @@ use FireflyIII\Repositories\Tag\OperationsRepositoryInterface;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Throwable;
/**
*
* Class TagController
*/
class TagController extends Controller
@@ -44,8 +42,6 @@ class TagController extends Controller
/**
* ExpenseReportController constructor.
*
*/
public function __construct()
{
@@ -60,11 +56,6 @@ class TagController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function accountPerTag(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
@@ -72,6 +63,7 @@ class TagController extends Controller
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$earned = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$report = [];
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
@@ -101,10 +93,10 @@ class TagController extends Controller
$report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]
??= [
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
$report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['spent'] = bcadd(
$report[$sourceAccountId]['currencies'][$currencyId]['tags'][$tag['id']]['spent'],
$journal['amount']
@@ -126,18 +118,18 @@ class TagController extends Controller
$destinationId = $journal['destination_account_id'];
$report[$destinationId]['currencies'][$currencyId]
??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'tags' => [],
];
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
'currency_decimal_places' => $currency['currency_decimal_places'],
'tags' => [],
];
$report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]
??= [
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
$report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['earned'] = bcadd(
$report[$destinationId]['currencies'][$currencyId]['tags'][$tag['id']]['earned'],
$journal['amount']
@@ -154,11 +146,6 @@ class TagController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function accounts(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
@@ -167,6 +154,7 @@ class TagController extends Controller
$earned = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$report = [];
$sums = [];
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
@@ -258,12 +246,8 @@ class TagController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function avgExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
@@ -287,7 +271,7 @@ class TagController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$key]['transactions']++;
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
@@ -301,9 +285,10 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.avg-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
@@ -311,12 +296,8 @@ class TagController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function avgIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
@@ -340,7 +321,7 @@ class TagController extends Controller
'currency_symbol' => $currency['currency_symbol'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
$result[$key]['transactions']++;
++$result[$key]['transactions'];
$result[$key]['sum'] = bcadd($journal['amount'], $result[$key]['sum']);
$result[$key]['avg'] = bcdiv($result[$key]['sum'], (string)$result[$key]['transactions']);
$result[$key]['avg_float'] = (float)$result[$key]['avg'];
@@ -354,9 +335,10 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.avg-income', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
@@ -364,11 +346,6 @@ class TagController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return Factory|View
*/
public function tags(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
@@ -377,6 +354,7 @@ class TagController extends Controller
$earned = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$sums = [];
$report = [];
/** @var Tag $tag */
foreach ($tags as $tag) {
$tagId = $tag->id;
@@ -397,6 +375,7 @@ class TagController extends Controller
'spent_sum' => '0',
'total_sum' => '0',
];
/** @var array $tag */
foreach ($currency['tags'] as $tag) {
$tagId = $tag['id'];
@@ -438,6 +417,7 @@ class TagController extends Controller
'spent_sum' => '0',
'total_sum' => '0',
];
/** @var array $tag */
foreach ($currency['tags'] as $tag) {
$tagId = $tag['id'];
@@ -472,12 +452,8 @@ class TagController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function topExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
@@ -513,9 +489,10 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.top-expenses', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
}
@@ -523,12 +500,8 @@ class TagController extends Controller
}
/**
* @param Collection $accounts
* @param Collection $tags
* @param Carbon $start
* @param Carbon $end
*
* @return string
*
* @throws FireflyException
*/
public function topIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
@@ -564,9 +537,10 @@ class TagController extends Controller
try {
$result = view('reports.tag.partials.top-income', compact('result'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
}