mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 09:51:40 +00:00
Clean up code.
This commit is contained in:
@@ -121,6 +121,16 @@ class IndexController extends Controller
|
||||
return view('accounts.index', compact('objectType', 'inactivePage', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
|
||||
}
|
||||
|
||||
private function subtract(array $startBalances, array $endBalances): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($endBalances as $key => $value) {
|
||||
$result[$key] = bcsub((string) $value, $startBalances[$key] ?? '0');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show list of accounts.
|
||||
*
|
||||
@@ -199,14 +209,4 @@ class IndexController extends Controller
|
||||
|
||||
return view('accounts.index', compact('objectType', 'inactiveCount', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
|
||||
}
|
||||
|
||||
private function subtract(array $startBalances, array $endBalances): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($endBalances as $key => $value) {
|
||||
$result[$key] = bcsub((string) $value, $startBalances[$key] ?? '0');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@@ -225,10 +225,10 @@ class ReconcileController extends Controller
|
||||
]
|
||||
);
|
||||
$submission = [
|
||||
'user' => auth()->user(),
|
||||
'user_group' => auth()->user()->userGroup,
|
||||
'group_title' => null,
|
||||
'transactions' => [
|
||||
'user' => auth()->user(),
|
||||
'user_group' => auth()->user()->userGroup,
|
||||
'group_title' => null,
|
||||
'transactions' => [
|
||||
[
|
||||
'user' => auth()->user(),
|
||||
'user_group' => auth()->user()->userGroup,
|
||||
|
@@ -33,7 +33,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\Debug\Timer;
|
||||
use FireflyIII\Support\Facades\Steam;
|
||||
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
||||
use FireflyIII\Support\JsonApi\Enrichments\TransactionGroupEnrichment;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
@@ -287,11 +287,11 @@ class IndexController extends Controller
|
||||
// also calculate how much left from budgeted:
|
||||
$sums['left'][$currencyId]
|
||||
??= [
|
||||
'amount' => '0',
|
||||
'currency_id' => $budgeted['currency_id'],
|
||||
'currency_symbol' => $budgeted['currency_symbol'],
|
||||
'currency_decimal_places' => $budgeted['currency_decimal_places'],
|
||||
];
|
||||
'amount' => '0',
|
||||
'currency_id' => $budgeted['currency_id'],
|
||||
'currency_symbol' => $budgeted['currency_symbol'],
|
||||
'currency_decimal_places' => $budgeted['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,6 @@ use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\Support\Facades\Steam;
|
||||
use FireflyIII\Support\Http\Controllers\AugumentData;
|
||||
use FireflyIII\Support\Http\Controllers\ChartGeneration;
|
||||
@@ -535,6 +534,17 @@ class AccountController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private function updateChartKeys(array $array, array $balances): array
|
||||
{
|
||||
foreach (array_keys($balances) as $key) {
|
||||
$array[$key] ??= [
|
||||
'key' => $key,
|
||||
];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the balances for a given set of dates and accounts.
|
||||
*
|
||||
@@ -676,15 +686,4 @@ class AccountController extends Controller
|
||||
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
private function updateChartKeys(array $array, array $balances): array
|
||||
{
|
||||
foreach (array_keys($balances) as $key) {
|
||||
$array[$key] ??= [
|
||||
'key' => $key,
|
||||
];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
@@ -38,7 +38,6 @@ use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\Support\Chart\Budget\FrontpageChartGenerator;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use FireflyIII\Support\Http\Controllers\AugumentData;
|
||||
use FireflyIII\Support\Http\Controllers\DateCalculation;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
@@ -197,11 +197,11 @@ class CategoryController extends Controller
|
||||
|
||||
$chartData[$inKey]
|
||||
= [
|
||||
'label' => sprintf('%s (%s)', (string) trans('firefly.earned'), $currencyInfo['currency_name']),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
|
||||
];
|
||||
'label' => sprintf('%s (%s)', (string) trans('firefly.earned'), $currencyInfo['currency_name']),
|
||||
'entries' => [],
|
||||
'type' => 'bar',
|
||||
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
|
||||
];
|
||||
// loop empty periods:
|
||||
foreach (array_keys($periods) as $period) {
|
||||
$label = $periods[$period];
|
||||
|
@@ -51,13 +51,12 @@ abstract class Controller extends BaseController
|
||||
|
||||
// fails on PHP < 8.4
|
||||
public protected(set) string $name;
|
||||
|
||||
protected string $dateTimeFormat;
|
||||
protected string $monthAndDayFormat;
|
||||
protected bool $convertToNative = false;
|
||||
protected bool $convertToNative = false;
|
||||
protected string $dateTimeFormat;
|
||||
protected ?TransactionCurrency $defaultCurrency;
|
||||
protected string $monthFormat;
|
||||
protected string $redirectUrl = '/';
|
||||
protected string $monthAndDayFormat;
|
||||
protected string $monthFormat;
|
||||
protected string $redirectUrl = '/';
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
@@ -94,8 +93,8 @@ abstract class Controller extends BaseController
|
||||
View::share('uploadSize', $uploadSize);
|
||||
|
||||
// share is alpha, is beta
|
||||
$isAlpha = false;
|
||||
$isBeta = false;
|
||||
$isAlpha = false;
|
||||
$isBeta = false;
|
||||
$isDevelop = false;
|
||||
if (str_contains((string) config('firefly.version'), 'alpha')) {
|
||||
$isAlpha = true;
|
||||
@@ -120,16 +119,16 @@ abstract class Controller extends BaseController
|
||||
$this->monthAndDayFormat = (string) trans('config.month_and_day_js', [], $locale);
|
||||
$this->dateTimeFormat = (string) trans('config.date_time_js', [], $locale);
|
||||
$darkMode = 'browser';
|
||||
$this->defaultCurrency =null;
|
||||
$this->defaultCurrency = null;
|
||||
// get shown-intro-preference:
|
||||
if (auth()->check()) {
|
||||
$this->defaultCurrency = Amount::getNativeCurrency();
|
||||
$language = Steam::getLanguage();
|
||||
$locale = Steam::getLocale();
|
||||
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
||||
$this->convertToNative =Amount::convertToNative();
|
||||
$page = $this->getPageName();
|
||||
$shownDemo = $this->hasSeenDemo();
|
||||
$this->defaultCurrency = Amount::getNativeCurrency();
|
||||
$language = Steam::getLanguage();
|
||||
$locale = Steam::getLocale();
|
||||
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
||||
$this->convertToNative = Amount::convertToNative();
|
||||
$page = $this->getPageName();
|
||||
$shownDemo = $this->hasSeenDemo();
|
||||
View::share('language', $language);
|
||||
View::share('locale', $locale);
|
||||
View::share('convertToNative', $this->convertToNative);
|
||||
|
@@ -25,6 +25,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -65,110 +66,6 @@ class DebugController extends Controller
|
||||
$this->middleware(IsDemoUser::class)->except(['displayError']);
|
||||
}
|
||||
|
||||
public function routes(Request $request): never
|
||||
{
|
||||
if (!auth()->user()->hasRole('owner')) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
/** @var iterable $routes */
|
||||
$routes = Route::getRoutes();
|
||||
|
||||
if ('true' === $request->get('api')) {
|
||||
$collection = [];
|
||||
$i = 0;
|
||||
|
||||
echo 'PATHS="';
|
||||
|
||||
/** @var \Illuminate\Routing\Route $route */
|
||||
foreach ($routes as $route) {
|
||||
++$i;
|
||||
// skip API and other routes.
|
||||
if (!str_starts_with($route->uri(), 'api/v1')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// skip non GET routes
|
||||
if (!in_array('GET', $route->methods(), true)) {
|
||||
continue;
|
||||
}
|
||||
// no name route:
|
||||
if (null === $route->getName()) {
|
||||
var_dump($route);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
echo substr($route->uri(), 3);
|
||||
if (0 === $i % 5) {
|
||||
echo '"<br>PATHS="${PATHS},';
|
||||
}
|
||||
if (0 !== $i % 5) {
|
||||
echo ',';
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$return = [];
|
||||
|
||||
/** @var \Illuminate\Routing\Route $route */
|
||||
foreach ($routes as $route) {
|
||||
// skip API and other routes.
|
||||
if (
|
||||
str_starts_with($route->uri(), 'api')
|
||||
|| str_starts_with($route->uri(), '_debugbar')
|
||||
|| str_starts_with($route->uri(), '_ignition')
|
||||
|| str_starts_with($route->uri(), 'oauth')
|
||||
|| str_starts_with($route->uri(), 'chart')
|
||||
|| str_starts_with($route->uri(), 'v1/jscript')
|
||||
|| str_starts_with($route->uri(), 'v2/jscript')
|
||||
|| str_starts_with($route->uri(), 'json')
|
||||
|| str_starts_with($route->uri(), 'sanctum')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// skip non GET routes
|
||||
if (!in_array('GET', $route->methods(), true)) {
|
||||
continue;
|
||||
}
|
||||
// no name route:
|
||||
if (null === $route->getName()) {
|
||||
var_dump($route);
|
||||
|
||||
exit;
|
||||
}
|
||||
if (!str_contains($route->uri(), '{')) {
|
||||
|
||||
$return[$route->getName()] = route($route->getName());
|
||||
|
||||
continue;
|
||||
}
|
||||
$params = [];
|
||||
foreach ($route->parameterNames() as $name) {
|
||||
$params[] = $this->getParameter($name);
|
||||
}
|
||||
$return[$route->getName()] = route($route->getName(), $params);
|
||||
}
|
||||
$count = 0;
|
||||
echo '<hr>';
|
||||
echo '<h1>Routes</h1>';
|
||||
echo sprintf('<h2>%s</h2>', $count);
|
||||
foreach ($return as $name => $path) {
|
||||
echo sprintf('<a href="%1$s">%2$s</a><br>', $path, $name).PHP_EOL;
|
||||
++$count;
|
||||
if (0 === $count % 10) {
|
||||
echo '<hr>';
|
||||
echo sprintf('<h2>%s</h2>', $count);
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all possible errors.
|
||||
*
|
||||
@@ -316,10 +213,10 @@ class DebugController extends Controller
|
||||
app('log')->debug('Could not check build date, but thats ok.');
|
||||
app('log')->warning($e->getMessage());
|
||||
}
|
||||
if ('' !== (string) env('BASE_IMAGE_BUILD')) { // @phpstan-ignore-line
|
||||
if ('' !== (string) env('BASE_IMAGE_BUILD')) { // @phpstan-ignore-line
|
||||
$return['base_build'] = env('BASE_IMAGE_BUILD'); // @phpstan-ignore-line
|
||||
}
|
||||
if ('' !== (string) env('BASE_IMAGE_DATE')) { // @phpstan-ignore-line
|
||||
if ('' !== (string) env('BASE_IMAGE_DATE')) { // @phpstan-ignore-line
|
||||
$return['base_build_date'] = env('BASE_IMAGE_DATE'); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
@@ -442,19 +339,107 @@ class DebugController extends Controller
|
||||
return implode(' ', $flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash all types of messages.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function testFlash(Request $request)
|
||||
public function routes(Request $request): never
|
||||
{
|
||||
$request->session()->flash('success', 'This is a success message.');
|
||||
$request->session()->flash('info', 'This is an info message.');
|
||||
$request->session()->flash('warning', 'This is a warning.');
|
||||
$request->session()->flash('error', 'This is an error!');
|
||||
if (!auth()->user()->hasRole('owner')) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
return redirect(route('home'));
|
||||
/** @var iterable $routes */
|
||||
$routes = Route::getRoutes();
|
||||
|
||||
if ('true' === $request->get('api')) {
|
||||
$collection = [];
|
||||
$i = 0;
|
||||
|
||||
echo 'PATHS="';
|
||||
|
||||
/** @var \Illuminate\Routing\Route $route */
|
||||
foreach ($routes as $route) {
|
||||
++$i;
|
||||
// skip API and other routes.
|
||||
if (!str_starts_with($route->uri(), 'api/v1')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// skip non GET routes
|
||||
if (!in_array('GET', $route->methods(), true)) {
|
||||
continue;
|
||||
}
|
||||
// no name route:
|
||||
if (null === $route->getName()) {
|
||||
var_dump($route);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
echo substr($route->uri(), 3);
|
||||
if (0 === $i % 5) {
|
||||
echo '"<br>PATHS="${PATHS},';
|
||||
}
|
||||
if (0 !== $i % 5) {
|
||||
echo ',';
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$return = [];
|
||||
|
||||
/** @var \Illuminate\Routing\Route $route */
|
||||
foreach ($routes as $route) {
|
||||
// skip API and other routes.
|
||||
if (
|
||||
str_starts_with($route->uri(), 'api')
|
||||
|| str_starts_with($route->uri(), '_debugbar')
|
||||
|| str_starts_with($route->uri(), '_ignition')
|
||||
|| str_starts_with($route->uri(), 'oauth')
|
||||
|| str_starts_with($route->uri(), 'chart')
|
||||
|| str_starts_with($route->uri(), 'v1/jscript')
|
||||
|| str_starts_with($route->uri(), 'v2/jscript')
|
||||
|| str_starts_with($route->uri(), 'json')
|
||||
|| str_starts_with($route->uri(), 'sanctum')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// skip non GET routes
|
||||
if (!in_array('GET', $route->methods(), true)) {
|
||||
continue;
|
||||
}
|
||||
// no name route:
|
||||
if (null === $route->getName()) {
|
||||
var_dump($route);
|
||||
|
||||
exit;
|
||||
}
|
||||
if (!str_contains($route->uri(), '{')) {
|
||||
|
||||
$return[$route->getName()] = route($route->getName());
|
||||
|
||||
continue;
|
||||
}
|
||||
$params = [];
|
||||
foreach ($route->parameterNames() as $name) {
|
||||
$params[] = $this->getParameter($name);
|
||||
}
|
||||
$return[$route->getName()] = route($route->getName(), $params);
|
||||
}
|
||||
$count = 0;
|
||||
echo '<hr>';
|
||||
echo '<h1>Routes</h1>';
|
||||
echo sprintf('<h2>%s</h2>', $count);
|
||||
foreach ($return as $name => $path) {
|
||||
echo sprintf('<a href="%1$s">%2$s</a><br>', $path, $name).PHP_EOL;
|
||||
++$count;
|
||||
if (0 === $count % 10) {
|
||||
echo '<hr>';
|
||||
echo sprintf('<h2>%s</h2>', $count);
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
private function getParameter(string $name): string
|
||||
@@ -582,4 +567,19 @@ class DebugController extends Controller
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash all types of messages.
|
||||
*
|
||||
* @return Redirector|RedirectResponse
|
||||
*/
|
||||
public function testFlash(Request $request)
|
||||
{
|
||||
$request->session()->flash('success', 'This is a success message.');
|
||||
$request->session()->flash('info', 'This is an info message.');
|
||||
$request->session()->flash('warning', 'This is a warning.');
|
||||
$request->session()->flash('error', 'This is an error!');
|
||||
|
||||
return redirect(route('home'));
|
||||
}
|
||||
}
|
||||
|
@@ -142,7 +142,6 @@ class JavascriptController extends Controller
|
||||
|
||||
return response()
|
||||
->view('v2.javascript.variables', $data)
|
||||
->header('Content-Type', 'text/javascript')
|
||||
;
|
||||
->header('Content-Type', 'text/javascript');
|
||||
}
|
||||
}
|
||||
|
@@ -27,8 +27,8 @@ namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\CurrencyFormRequest;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
@@ -26,8 +26,8 @@ namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
@@ -27,8 +27,8 @@ namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\CurrencyFormRequest;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
@@ -26,8 +26,8 @@ namespace FireflyIII\Http\Controllers\TransactionCurrency;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\Request;
|
||||
|
Reference in New Issue
Block a user