mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-17 20:08:52 +00:00
Code cleanup.
This commit is contained in:
@@ -28,6 +28,4 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
/**
|
||||
* Class AutoCompleteController.
|
||||
*/
|
||||
class AutoCompleteController extends Controller
|
||||
{
|
||||
}
|
||||
class AutoCompleteController extends Controller {}
|
||||
|
||||
@@ -48,19 +48,21 @@ class BoxController extends Controller
|
||||
* 0) If the user has available amount this period and has overspent: overspent box.
|
||||
* 1) If the user has available amount this period and has NOT overspent: left to spend box.
|
||||
* 2) if the user has no available amount set this period: spent per day
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function available(): JsonResponse
|
||||
{
|
||||
app('log')->debug('Now in available()');
|
||||
|
||||
/** @var OperationsRepositoryInterface $opsRepository */
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
|
||||
/** @var AvailableBudgetRepositoryInterface $abRepository */
|
||||
$abRepository = app(AvailableBudgetRepositoryInterface::class);
|
||||
$abRepository->cleanup();
|
||||
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$today = today(config('app.timezone'));
|
||||
@@ -92,6 +94,7 @@ class BoxController extends Controller
|
||||
$availableBudget->end_date->format('Y-m-d'),
|
||||
$availableBudget->amount
|
||||
));
|
||||
|
||||
return $availableBudget;
|
||||
}
|
||||
|
||||
@@ -139,21 +142,19 @@ class BoxController extends Controller
|
||||
|
||||
$cache->store($return);
|
||||
app('log')->debug('Now done with available()');
|
||||
|
||||
return response()->json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Current total balance.
|
||||
*
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function balance(CurrencyRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
// Cache result, return cache if present.
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$cache = new CacheProperties();
|
||||
@@ -173,8 +174,10 @@ class BoxController extends Controller
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)
|
||||
->setTypes([TransactionType::DEPOSIT]);
|
||||
->setTypes([TransactionType::DEPOSIT])
|
||||
;
|
||||
$set = $collector->getExtractedJournals();
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
@@ -189,8 +192,10 @@ class BoxController extends Controller
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)
|
||||
->setTypes([TransactionType::WITHDRAWAL]);
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
;
|
||||
$set = $collector->getExtractedJournals();
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
@@ -229,8 +234,6 @@ class BoxController extends Controller
|
||||
|
||||
/**
|
||||
* Total user net worth.
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function netWorth(): JsonResponse
|
||||
{
|
||||
|
||||
@@ -46,8 +46,6 @@ class BudgetController extends Controller
|
||||
|
||||
/**
|
||||
* IndexController constructor.
|
||||
*
|
||||
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -67,13 +65,6 @@ class BudgetController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getBudgetInformation(TransactionCurrency $currency, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
$budgeted = $this->blRepository->budgeted($start, $end, $currency);
|
||||
|
||||
@@ -28,7 +28,6 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class FrontpageController.
|
||||
@@ -38,15 +37,13 @@ class FrontpageController extends Controller
|
||||
/**
|
||||
* Piggy bank pie chart.
|
||||
*
|
||||
* @param PiggyBankRepositoryInterface $repository
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function piggyBanks(PiggyBankRepositoryInterface $repository): JsonResponse
|
||||
{
|
||||
$set = $repository->getPiggyBanks();
|
||||
$info = [];
|
||||
|
||||
/** @var PiggyBank $piggyBank */
|
||||
foreach ($set as $piggyBank) {
|
||||
$amount = $repository->getCurrentAmount($piggyBank);
|
||||
@@ -72,10 +69,11 @@ class FrontpageController extends Controller
|
||||
if (0 !== count($info)) {
|
||||
try {
|
||||
$html = view('json.piggy-banks', compact('info'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$html = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($html, 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,11 +37,6 @@ class IntroController extends Controller
|
||||
|
||||
/**
|
||||
* Returns the introduction wizard for a page.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string|null $specificPage
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getIntroSteps(string $route, string $specificPage = null): JsonResponse
|
||||
{
|
||||
@@ -72,10 +67,6 @@ class IntroController extends Controller
|
||||
|
||||
/**
|
||||
* Returns true if there is a general outro step.
|
||||
*
|
||||
* @param string $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasOutroStep(string $route): bool
|
||||
{
|
||||
@@ -98,19 +89,15 @@ class IntroController extends Controller
|
||||
/**
|
||||
* Enable the boxes for a specific page again.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string|null $specialPage
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function postEnable(string $route, string $specialPage = null): JsonResponse
|
||||
{
|
||||
$specialPage ??= '';
|
||||
$route = str_replace('.', '_', $route);
|
||||
$key = 'shown_demo_' . $route;
|
||||
$key = 'shown_demo_'.$route;
|
||||
if ('' !== $specialPage) {
|
||||
$key .= '_' . $specialPage;
|
||||
$key .= '_'.$specialPage;
|
||||
}
|
||||
app('log')->debug(sprintf('Going to mark the following route as NOT done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
app('preferences')->set($key, false);
|
||||
@@ -122,18 +109,14 @@ class IntroController extends Controller
|
||||
/**
|
||||
* Set that you saw them.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string|null $specialPage
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function postFinished(string $route, string $specialPage = null): JsonResponse
|
||||
{
|
||||
$specialPage ??= '';
|
||||
$key = 'shown_demo_' . $route;
|
||||
$key = 'shown_demo_'.$route;
|
||||
if ('' !== $specialPage) {
|
||||
$key .= '_' . $specialPage;
|
||||
$key .= '_'.$specialPage;
|
||||
}
|
||||
app('log')->debug(sprintf('Going to mark the following route as done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
app('preferences')->set($key, true);
|
||||
|
||||
@@ -34,11 +34,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use JsonException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ReconcileController
|
||||
*/
|
||||
class ReconcileController extends Controller
|
||||
@@ -47,8 +44,6 @@ class ReconcileController extends Controller
|
||||
|
||||
/**
|
||||
* ReconcileController constructor.
|
||||
*
|
||||
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -69,14 +64,8 @@ class ReconcileController extends Controller
|
||||
/**
|
||||
* Overview of reconciliation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Account|null $account
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse
|
||||
{
|
||||
@@ -99,7 +88,7 @@ class ReconcileController extends Controller
|
||||
$clearedJournals = [];
|
||||
$clearedIds = $request->get('cleared') ?? [];
|
||||
$journals = [];
|
||||
/* Collect all submitted journals */
|
||||
// Collect all submitted journals
|
||||
if (count($selectedIds) > 0) {
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
@@ -107,7 +96,7 @@ class ReconcileController extends Controller
|
||||
$journals = $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/* Collect all journals already reconciled */
|
||||
// Collect all journals already reconciled
|
||||
if (count($clearedIds) > 0) {
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
@@ -116,6 +105,7 @@ class ReconcileController extends Controller
|
||||
}
|
||||
|
||||
app('log')->debug('Start transaction loop');
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$amount = $this->processJournal($account, $accountCurrency, $journal, $amount);
|
||||
@@ -154,10 +144,11 @@ class ReconcileController extends Controller
|
||||
'selectedIds'
|
||||
)
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('View error: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$view = sprintf('Could not render accounts.reconcile.overview: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
@@ -169,56 +160,13 @@ class ReconcileController extends Controller
|
||||
return response()->json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $journal
|
||||
* @param string $amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string
|
||||
{
|
||||
$toAdd = '0';
|
||||
app('log')->debug(sprintf('User submitted %s #%d: "%s"', $journal['transaction_type_type'], $journal['transaction_journal_id'], $journal['description']));
|
||||
|
||||
// not much magic below we need to cover using tests.
|
||||
|
||||
if ($account->id === $journal['source_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = $journal['amount'];
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = $journal['foreign_amount'];
|
||||
}
|
||||
}
|
||||
if ($account->id === $journal['destination_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = bcmul($journal['amount'], '-1');
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = bcmul($journal['foreign_amount'], '-1');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
app('log')->debug(sprintf('Going to add %s to %s', $toAdd, $amount));
|
||||
$amount = bcadd($amount, $toAdd);
|
||||
app('log')->debug(sprintf('Result is %s', $amount));
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of transactions in a modal.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function transactions(Account $account, Carbon $start = null, Carbon $end = null)
|
||||
{
|
||||
@@ -246,8 +194,9 @@ class ReconcileController extends Controller
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts(new Collection([$account]))
|
||||
->setRange($selectionStart, $selectionEnd)
|
||||
->withBudgetInformation()->withCategoryInformation()->withAccountInformation();
|
||||
->setRange($selectionStart, $selectionEnd)
|
||||
->withBudgetInformation()->withCategoryInformation()->withAccountInformation()
|
||||
;
|
||||
$array = $collector->getExtractedJournals();
|
||||
$journals = $this->processTransactions($account, $array);
|
||||
|
||||
@@ -256,27 +205,55 @@ class ReconcileController extends Controller
|
||||
'accounts.reconcile.transactions',
|
||||
compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd')
|
||||
)->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->debug(sprintf('Could not render: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$html = sprintf('Could not render accounts.reconcile.transactions: %s', $e->getMessage());
|
||||
|
||||
throw new FireflyException($html, 0, $e);
|
||||
}
|
||||
|
||||
return response()->json(['html' => $html, 'startBalance' => $startBalance, 'endBalance' => $endBalance]);
|
||||
}
|
||||
|
||||
private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string
|
||||
{
|
||||
$toAdd = '0';
|
||||
app('log')->debug(sprintf('User submitted %s #%d: "%s"', $journal['transaction_type_type'], $journal['transaction_journal_id'], $journal['description']));
|
||||
|
||||
// not much magic below we need to cover using tests.
|
||||
|
||||
if ($account->id === $journal['source_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = $journal['amount'];
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = $journal['foreign_amount'];
|
||||
}
|
||||
}
|
||||
if ($account->id === $journal['destination_account_id']) {
|
||||
if ($currency->id === $journal['currency_id']) {
|
||||
$toAdd = bcmul($journal['amount'], '-1');
|
||||
}
|
||||
if (null !== $journal['foreign_currency_id'] && $journal['foreign_currency_id'] === $currency->id) {
|
||||
$toAdd = bcmul($journal['foreign_amount'], '-1');
|
||||
}
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Going to add %s to %s', $toAdd, $amount));
|
||||
$amount = bcadd($amount, $toAdd);
|
||||
app('log')->debug(sprintf('Result is %s', $amount));
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* "fix" amounts to make it easier on the reconciliation overview:
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function processTransactions(Account $account, array $array): array
|
||||
{
|
||||
$journals = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$inverse = false;
|
||||
@@ -302,7 +279,6 @@ class ReconcileController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$journals[] = $journal;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@ class RecurrenceController extends Controller
|
||||
|
||||
/**
|
||||
* RecurrenceController constructor.
|
||||
*
|
||||
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -61,10 +59,6 @@ class RecurrenceController extends Controller
|
||||
/**
|
||||
* Shows all events for a repetition. Used in calendar.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function events(Request $request): JsonResponse
|
||||
@@ -126,7 +120,7 @@ class RecurrenceController extends Controller
|
||||
foreach ($occurrences as $current) {
|
||||
if ($current->gte($start)) {
|
||||
$event = [
|
||||
'id' => $repetitionType . $firstDate->format('Ymd'),
|
||||
'id' => $repetitionType.$firstDate->format('Ymd'),
|
||||
'title' => 'X',
|
||||
'allDay' => true,
|
||||
'start' => $current->format('Y-m-d'),
|
||||
@@ -143,15 +137,12 @@ class RecurrenceController extends Controller
|
||||
|
||||
/**
|
||||
* Suggests repetition moments.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function suggest(Request $request): JsonResponse
|
||||
{
|
||||
$string = '' === (string)$request->get('date') ? date('Y-m-d') : (string)$request->get('date');
|
||||
$today = today(config('app.timezone'))->startOfDay();
|
||||
|
||||
try {
|
||||
$date = Carbon::createFromFormat('Y-m-d', $string, config('app.timezone'));
|
||||
} catch (InvalidFormatException $e) {
|
||||
|
||||
@@ -27,7 +27,6 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Class RuleController
|
||||
@@ -37,9 +36,6 @@ class RuleController extends Controller
|
||||
/**
|
||||
* Render HTML form for rule action.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function action(Request $request): JsonResponse
|
||||
@@ -48,14 +44,16 @@ class RuleController extends Controller
|
||||
$keys = array_keys(config('firefly.rule-actions'));
|
||||
$actions = [];
|
||||
foreach ($keys as $key) {
|
||||
$actions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice');
|
||||
$actions[$key] = (string)trans('firefly.rule_action_'.$key.'_choice');
|
||||
}
|
||||
|
||||
try {
|
||||
$view = view('rules.partials.action', compact('actions', 'count'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render rules.partials.action: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$view = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
@@ -65,9 +63,6 @@ class RuleController extends Controller
|
||||
/**
|
||||
* Render HTML for rule trigger.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function trigger(Request $request): JsonResponse
|
||||
@@ -84,10 +79,11 @@ class RuleController extends Controller
|
||||
|
||||
try {
|
||||
$view = view('rules.partials.trigger', compact('triggers', 'count'))->render();
|
||||
} catch (Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
app('log')->error(sprintf('Cannot render rules.partials.trigger: %s', $e->getMessage()));
|
||||
app('log')->error($e->getTraceAsString());
|
||||
$view = 'Could not render view.';
|
||||
|
||||
throw new FireflyException($view, 0, $e);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user