Skip to content

Firefly III: a personal finances manager

Little debug page with routes.

James Cole3a274dcaa763
diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php
index 5ddecb5bca..0d3bd93ec6 100644
--- a/app/Http/Controllers/DebugController.php
+++ b/app/Http/Controllers/DebugController.php
@@ -25,7 +25,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
-use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Models\AccountType;
@@ -34,14 +33,17 @@ use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
use FireflyIII\Support\Models\AccountBalanceCalculator;
use FireflyIII\User;
+use Http\Discovery\Exception\NotFoundException;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Route;
use Illuminate\View\View;
use Monolog\Handler\RotatingFileHandler;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class DebugController
@@ -59,6 +61,61 @@ class DebugController extends Controller
$this->middleware(IsDemoUser::class)->except(['displayError']);
}
+ public function routes(): never
+ {
+ if(!auth()->user()->hasRole('owner')) {
+ throw new NotFoundHttpException();
+ }
+ $routes = Route::getRoutes();
+ $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(), 'sanctum')
+ ) {
+ continue;
+ }
+ // skip non GET routes
+ if (!in_array('GET', $route->methods())) {
+ 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;
+ var_dump($return);
+ }
+
/**
* Show all possible errors.
*
@@ -119,12 +176,12 @@ class DebugController extends Controller
*/
public function index()
{
- $table = $this->generateTable();
- $table = str_replace(["\n", "\t", ' '], '', $table);
- $now = now(config('app.timezone'))->format('Y-m-d H:i:s');
+ $table = $this->generateTable();
+ $table = str_replace(["\n", "\t", ' '], '', $table);
+ $now = now(config('app.timezone'))->format('Y-m-d H:i:s');
// get latest log file:
- $logger = Log::driver();
+ $logger = Log::driver();
// PHPstan doesn't recognize the method because of its polymorphic nature.
$handlers = $logger->getHandlers(); // @phpstan-ignore-line
$logContent = '';
@@ -138,7 +195,7 @@ class DebugController extends Controller
}
if ('' !== $logContent) {
// last few lines
- $logContent = 'Truncated from this point <----|'.substr((string) $logContent, -16384);
+ $logContent = 'Truncated from this point <----|' . substr((string) $logContent, -16384);
}
return view('debug', compact('table', 'now', 'logContent'));
@@ -218,7 +275,7 @@ class DebugController extends Controller
private function getAppInfo(): array
{
- $userGuard = config('auth.defaults.guard');
+ $userGuard = config('auth.defaults.guard');
$config = app('fireflyconfig')->get('last_rt_job', 0);
$lastTime = (int) $config->data;
@@ -243,24 +300,24 @@ class DebugController extends Controller
// any of the cron jobs will do, they always run at the same time.
// but this job is the oldest, so the biggest chance it ran once
- 'last_cronjob' => $lastCronjob,
- 'last_cronjob_ago' => $lastCronjobAgo,
+ 'last_cronjob' => $lastCronjob,
+ 'last_cronjob_ago' => $lastCronjobAgo,
];
}
private function getuserInfo(): array
{
- $userFlags = $this->getUserFlags();
+ $userFlags = $this->getUserFlags();
// user info
- $userAgent = request()->header('user-agent');
+ $userAgent = request()->header('user-agent');
// set languages, see what happens:
$original = setlocale(LC_ALL, '0');
$localeAttempts = [];
$parts = app('steam')->getLocaleArray(app('steam')->getLocale());
foreach ($parts as $code) {
- $code = trim($code);
+ $code = trim($code);
app('log')->debug(sprintf('Trying to set %s', $code));
$result = setlocale(LC_ALL, $code);
$localeAttempts[$code] = $result === $code;
@@ -281,10 +338,10 @@ class DebugController extends Controller
private function getUserFlags(): string
{
- $flags = [];
+ $flags = [];
/** @var User $user */
- $user = auth()->user();
+ $user = auth()->user();
// has liabilities
if ($user->accounts()->accountTypeIn([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE])->count() > 0) {
@@ -300,7 +357,7 @@ class DebugController extends Controller
}
// has stored reconciliations
- $type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
+ $type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
if ($user->transactionJournals()->where('transaction_type_id', $type->id)->count() > 0) {
$flags[] = '<span title="Has reconciled">:ledger:</span>';
}
@@ -344,4 +401,93 @@ class DebugController extends Controller
return redirect(route('home'));
}
+
+ private function getParameter(string $name): string
+ {
+ switch ($name) {
+ default:
+ throw new FireflyException(sprintf('Unknown parameter "%s"', $name));
+ case 'cliToken':
+ case 'token':
+ case 'code':
+ case 'oldAddressHash':
+ return 'fake-token';
+ case 'objectType':
+ return 'asset';
+ case 'account':
+ return '1';
+ case 'start_date':
+ return '20241201';
+ case 'end_date':
+ return '20241231';
+ case 'attachment':
+ return '1';
+ case 'bill':
+ return '1';
+ case 'budget':
+ return '1';
+ case 'budgetLimit':
+ return '1';
+ case 'category':
+ return '1';
+ case 'currency':
+ return '1';
+ case 'fromCurrencyCode':
+ return 'EUR';
+ case 'toCurrencyCode':
+ return 'USD';
+ case 'accountList':
+ return '1,6';
+ case 'budgetList':
+ return '1,2';
+ case 'categoryList':
+ return '1,2';
+ case 'doubleList':
+ return '1,2';
+ case 'tagList':
+ return '1,2';
+ case 'tag':
+ return '1';
+ case 'piggyBank':
+ return '1';
+ case 'objectGroup':
+ return '1';
+ case 'route':
+ return 'accounts';
+ case 'specificPage':
+ return 'show';
+ case 'recurrence':
+ return '1';
+ case 'tj':
+ return '1';
+ case 'reportType':
+ return 'default';
+ case 'ruleGroup':
+ return '1';
+ case 'rule':
+ return '1';
+ case 'tagOrId':
+ return '1';
+ case 'transactionGroup':
+ return '1';
+ case 'journalList':
+ return '1,2';
+ case 'transactionType':
+ return 'withdrawal';
+ case 'journalLink':
+ return '1';
+ case 'webhook':
+ return '1';
+ case 'user':
+ return '1';
+ case 'linkType':
+ return '1';
+ case 'userGroup':
+ return '1';
+
+ case 'date':
+ return '20241201';
+
+ }
+ }
}
diff --git a/resources/views/list/groups.twig b/resources/views/list/groups.twig
index cd210e0a07..d103c0cea6 100644
--- a/resources/views/list/groups.twig
+++ b/resources/views/list/groups.twig
@@ -59,13 +59,14 @@
<td colspan="1" style="text-align:right;border-top:1px #aaa solid;">
{% for sum in group.sums %}
{% if group.transaction_type == 'Deposit' %}
- {{ formatAmountBySymbol(sum.amount*-1, sum.currency_symbol, sum.currency_decimal_places) }}{% if loop.index != group.sums|length %},{% endif %}
+ {{ formatAmountBySymbol(sum.amount*-1, sum.currency_symbol, sum.currency_decimal_places) }}(TODO NATIVE){% if loop.index != group.sums|length %},{% endif %}
+
{% elseif group.transaction_type == 'Transfer' %}
<span class="text-info money-transfer">
- {{ formatAmountBySymbol(sum.amount*-1, sum.currency_symbol, sum.currency_decimal_places, false) }}{% if loop.index != group.sums|length %},{% endif %}
+ {{ formatAmountBySymbol(sum.amount*-1, sum.currency_symbol, sum.currency_decimal_places, false) }}(TODO NATIVE){% if loop.index != group.sums|length %},{% endif %}
</span>
{% else %}
- {{ formatAmountBySymbol(sum.amount, sum.currency_symbol, sum.currency_decimal_places) }}{% if loop.index != group.sums|length %},{% endif %}
+ {{ formatAmountBySymbol(sum.amount, sum.currency_symbol, sum.currency_decimal_places) }}(TODO NATIVE){% if loop.index != group.sums|length %},{% endif %}
{% endif %}
{% endfor %}
</td>
@@ -153,6 +154,7 @@
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE1)
{# transfer #}
{% elseif transaction.transaction_type_type == 'Transfer' %}
<span class="text-info money-transfer">
@@ -160,6 +162,7 @@
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places, false) }})
{% endif %}
+ (TODO NATIVE2)
</span>
{# opening balance #}
{% elseif transaction.transaction_type_type == 'Opening balance' %}
@@ -168,11 +171,13 @@
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE3)
{% else %}
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE4)
{% endif %}
{# reconciliation #}
{% elseif transaction.transaction_type_type == 'Reconciliation' %}
@@ -181,11 +186,13 @@
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE5)
{% else %}
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE6)
{% endif %}
{# liability credit #}
{% elseif transaction.transaction_type_type == 'Liability credit' %}
@@ -194,11 +201,13 @@
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE7)
{% else %}
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE8)
{% endif %}
@@ -208,6 +217,7 @@
{% if null != transaction.foreign_amount %}
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
{% endif %}
+ (TODO NATIVE9)
{% endif %}
</td>
<td style=" {{ style|raw }}">
diff --git a/routes/web.php b/routes/web.php
index 53ec66f3e4..33c6b1e120 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -80,7 +80,7 @@ Route::group(
Route::group(
['middleware' => 'binders-only', 'namespace' => 'FireflyIII\Http\Controllers\System'],
static function (): void {
- Route::get('offline', static fn () => view('errors.offline'));
+ //Route::get('offline', static fn () => view('errors.offline'));
Route::get('health', ['uses' => 'HealthcheckController@check', 'as' => 'healthcheck']);
}
);
@@ -117,7 +117,7 @@ Route::group(
Route::get('error', ['uses' => 'DebugController@displayError', 'as' => 'error']);
Route::post('logout', ['uses' => 'Auth\LoginController@logout', 'as' => 'logout']);
Route::get('flush', ['uses' => 'DebugController@flush', 'as' => 'flush']);
- // Route::get('routes', ['uses' => 'DebugController@routes', 'as' => 'routes']);
+ Route::get('routes', ['uses' => 'DebugController@routes', 'as' => 'routes']);
Route::get('debug', 'DebugController@index')->name('debug');
}
);