Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix 405 missing error page.
James Cole573438b90607
diff --git a/app/Api/V1/Controllers/Models/Account/ShowController.php b/app/Api/V1/Controllers/Models/Account/ShowController.phpindex ef115a720f..0934aae084 100644--- a/app/Api/V1/Controllers/Models/Account/ShowController.php+++ b/app/Api/V1/Controllers/Models/Account/ShowController.php@@ -77,11 +77,12 @@ final class ShowController extends Controller'sort' => $sort,'start' => $start,'end' => $end,+ 'active' => $active,'date' => $date,] = $request->attributes->all();// get list of accounts. Count it and split it.$this->repository->resetAccountOrder();- $collection = $this->repository->getAccountsByType($types, $sort);+ $collection = $this->repository->getAccountsByType($types, $sort, $active);$count = $collection->count();// continue sort:diff --git a/app/Api/V1/Requests/Generic/ActiveObjectRequest.php b/app/Api/V1/Requests/Generic/ActiveObjectRequest.phpnew file mode 100644index 0000000000..e39a2a654f--- /dev/null+++ b/app/Api/V1/Requests/Generic/ActiveObjectRequest.php@@ -0,0 +1,50 @@+<?php++/*+ * Copyright (c) 2025 https://github.com/ctrl-f5+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program 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 Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Requests\Generic;++use FireflyIII\Api\V1\Requests\ApiRequest;+use FireflyIII\Rules\IsBoolean;+use Illuminate\Contracts\Validation\Validator;++class ActiveObjectRequest extends ApiRequest+{+ public function rules(): array+ {+ return [+ 'active' => ['nullable', new IsBoolean()],+ ];+ }++ public function withValidator(Validator $validator): void+ {+ $validator->after(function (Validator $validator): void {+ $active = null;+ if($this->has('active')) {+ $active = $this->boolean('active', null);+ }++ $this->attributes->set('active', $active);+ });+ }+}diff --git a/app/Api/V1/Requests/Models/Account/ShowRequest.php b/app/Api/V1/Requests/Models/Account/ShowRequest.phpindex bad1db38cd..f303c645de 100644--- a/app/Api/V1/Requests/Models/Account/ShowRequest.php+++ b/app/Api/V1/Requests/Models/Account/ShowRequest.php@@ -27,6 +27,7 @@ namespace FireflyIII\Api\V1\Requests\Models\Account;use FireflyIII\Api\V1\Requests\AggregateFormRequest;use FireflyIII\Api\V1\Requests\DateRangeRequest;use FireflyIII\Api\V1\Requests\DateRequest;+use FireflyIII\Api\V1\Requests\Generic\ActiveObjectRequest;use FireflyIII\Api\V1\Requests\PaginationRequest;use FireflyIII\Models\Account;@@ -37,6 +38,7 @@ class ShowRequest extends AggregateFormRequestreturn [[PaginationRequest::class, 'sort_class' => Account::class],DateRangeRequest::class,+ ActiveObjectRequest::class,DateRequest::class,AccountTypeApiRequest::class,// [ObjectTypeApiRequest::class, 'object_type' => Account::class],diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex 141c887924..2f7975d42b 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -225,7 +225,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfacreturn $query->get(['accounts.*']);}- public function getAccountsByType(array $types, ?array $sort = []): Collection+ public function getAccountsByType(array $types, ?array $sort = [], ?bool $filterActive = null): Collection{$res = array_intersect([AccountTypeEnum::ASSET->value,@@ -237,6 +237,9 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfacif (0 !== count($types)) {$query->accountTypeIn($types);}+ if(null !== $filterActive) {+ $query->where('accounts.active', $filterActive);+ }// add sort parameters$allowed = config('firefly.allowed_db_sort_parameters.Account', []);diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.phpindex 930a590257..b3a1ca89d3 100644--- a/app/Repositories/Account/AccountRepositoryInterface.php+++ b/app/Repositories/Account/AccountRepositoryInterface.php@@ -90,7 +90,7 @@ interface AccountRepositoryInterface** @deprecated*/- public function getAccountsByType(array $types, ?array $sort = []): Collection;+ public function getAccountsByType(array $types, ?array $sort = [], ?bool $filterActive = null): Collection;public function getAccountsByTypeForGroup(array $types, ?array $sort = []): Collection;diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.jsindex acdfb54db6..c9aef4b499 100644--- a/resources/assets/v3/js/pages/accounts/index.js+++ b/resources/assets/v3/js/pages/accounts/index.js@@ -22,9 +22,11 @@ import "../../boot/bootstrap.js";import sidebar from "../shared/sidebar.js";import dates from "../shared/dates.js";import Alpine from "alpinejs";-import { getVariable } from "../../store/get-variable.js";+import {getVariable} from "../../store/get-variable.js";import Put from "../../api/model/account/put.js";import Get from "../../api/model/account/get.js";+import {format} from "date-fns";+import formatMoney from "../../util/format-money.js";window.enableDates = false;@@ -33,41 +35,40 @@ let index = function () {listPageSize: 50,objectType: 'invalid',sortColumn: 'order',+ accounts: [],sortDirection: 'asc',+ page: 1,init() {- const page = window.location.href.split("/");+ const page = window.location.href.split('?')[0].split("/");this.objectType = page[page.length - 1].substring(0, 15);const params = new Proxy(new URLSearchParams(window.location.search), {get: (searchParams, prop) => searchParams.get(prop),});this.sortColumn = params.column ?? 'order';this.sortDirection = params.direction ?? 'asc';- console.log('Sort "'+this.sortColumn+'" in direction "'+this.sortDirection+'"');+ this.page = parseInt(params.page) || 1;// grab the account list.+ this.downloadAccounts();- let sort = 'asc' === this.sortDirection ? this.sortColumn : '-' + this.sortColumn;-- (new Get).list({sort: sort}).then((response) => {- console.log(response.data);- });// get accounts by initial sort.document.querySelectorAll('table.sortable th').forEach((el) => {console.log('El', el);el.addEventListener('click', (event) => {let newColumn = event.currentTarget.dataset.column;- if(newColumn === this.sortColumn) {+ if (newColumn === this.sortColumn) {this.sortDirection = 'asc' === this.sortDirection ? 'desc' : 'asc';}- if(newColumn !== this.sortColumn) {+ if (newColumn !== this.sortColumn) {this.sortColumn = newColumn;}console.log('Will now sort on column', newColumn, 'direction', this.sortDirection);if (history.pushState) {let newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?column=' + this.sortColumn + '&direction=' + this.sortDirection;- window.history.pushState({path:newurl},'',newurl);+ window.history.pushState({path: newurl}, '', newurl);}+ this.downloadAccounts();});});@@ -81,7 +82,7 @@ let index = function () {let item = e.detail[i];if (item.order !== item.currentOrder) {// PUT new order to system.- new Put().put({ order: item.order }, { id: item.id });+ new Put().put({order: item.order}, {id: item.id});// save new order as current order in the row.document.querySelector(`tr[data-id="${item.id}"]`)@@ -93,6 +94,59 @@ let index = function () {});});},+ downloadAccounts() {+ let sort = 'asc' === this.sortDirection ? this.sortColumn : '-' + this.sortColumn;+ let start = window.store.get("start");+ let end = window.store.get("end");+ let active = true;+ (new Get).list({+ active: active,+ sort: sort,+ type: this.objectType,+ start: start,+ end: end+ }).then((response) => {+ this.accounts = [];+ for (let i = 1; i < response.data.data.length; i++) {+ if (Object.hasOwn(response.data.data, i)) {+ let current = response.data.data[i];+ let balanceDifference = formatMoney(current.attributes.balance_difference, current.attributes.currency_code, true);+ let balanceDiffFloat = parseFloat(current.attributes.balance_difference);+ if (window.store.get('convert_to_primary')) {+ balanceDifference = formatMoney(current.attributes.pc_balance_difference, current.attributes.primary_currency_code, true);+ balanceDiffFloat = parseFloat(current.attributes.pc_balance_difference);+ }+ console.log(current);+ let account = {+ id: parseInt(current.id),+ name: current.attributes.name,+ location: null !== current.attributes.longitude && null !== current.attributes.latitude,+ has_attachments: current.attributes.has_attachments,+ role: current.attributes.account_role,+ iban: this.addSpaces(current.attributes.iban),+ account_number: current.attributes.account_number,+ active: current.attributes.active,+ last_activity: this.formatDate(current.attributes.last_activity),+ balance_difference: balanceDifference,+ balance_difference_float: balanceDiffFloat,+ };+ this.accounts.push(account);+ }+ }+ });+ },+ addSpaces(iban) {+ if (null === iban) {+ return '';+ }+ return iban.match(/.{1,4}/g).join(' ');+ },+ formatDate(date) {+ if (null === date) {+ return '';+ }+ return format(new Date(date), i18next.t('config.date_time_fns_short', {lng: window.store.get('locale')}));+ }};};diff --git a/resources/lang/en_US/errors.php b/resources/lang/en_US/errors.phpindex 1102381751..1bcda0ae7c 100644--- a/resources/lang/en_US/errors.php+++ b/resources/lang/en_US/errors.php@@ -25,6 +25,10 @@ declare(strict_types=1);return ['404_header' => 'Firefly III cannot find this page.','404_page_does_not_exist' => 'The page you have requested does not exist. Please check that you have not entered the wrong URL. Did you make a typo perhaps?',++ '405_header' => 'Firefly III does not allow this method.',+ '405_page_does_not_exist' => 'You cannot use this request method on this page. Please check that you have not entered the wrong URL. Did you make a typo perhaps?',+ '405_github_link' => 'If you are sure this page should work, please open a ticket on <strong><a href="https://github.com/firefly-iii/firefly-iii/issues">GitHub</a></strong>.','404_send_error' => 'If you were redirected to this page automatically, please accept my apologies. There is a mention of this error in your log files and I would be grateful if you sent me the error to me.','404_github_link' => 'If you are sure this page should exist, please open a ticket on <strong><a href="https://github.com/firefly-iii/firefly-iii/issues">GitHub</a></strong>.','note_not_found_account' => 'Account ":name" has been deleted and can no longer be viewed. Please enjoy this overview of all other accounts of the same type.',diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.phpindex 047803aefe..a699841c28 100644--- a/resources/views/accounts/index.blade.php+++ b/resources/views/accounts/index.blade.php@@ -47,6 +47,105 @@<th> </th></tr></thead>+ <tbody>+ <template x-for="account in accounts" :key="account.id">+ <tr>+ <td>+ <template x-if="('asset' === objectType || 'liabilities' === objectType) && 'asc' === sortDirection && 'order' === sortColumn && accounts.length > 1">+ <span class="btn btn-outline-secondary btn-sm bi bi-list object-handle"></span>+ </template>+ </td>+ <td>+ <a :href="'./accounts/show/' + account.id" :title="account.name" x-text="account.name"></a>+ <template x-if="account.location">+ <span class="bi bi-map"></span>+ </template>+ <template x-if="true === account.has_attachments">+ <span class="bi bi-paperclip"></span>+ </template>+ </td>+ <template x-if="'asset' === objectType">+ <td class="d-lg-table-cell d-none">+ <template x-if="null !== account.role">+ <span x-text="i18next.t('firefly.account_role_' + account.role)"></span>+ </template>+ <template x-if="null === account.role || '' === account.role">+ <span>~</span>+ </template>+ </td>+ </template>+ <template x-if="'liabilities' === objectType">+ <td>+ TODO liabilitie type+ </td>+ </template>+ <template x-if="'liabilities' === objectType">+ <td>+ TODO liabilitie dir+ </td>+ </template>+ <template x-if="'liabilities' === objectType">+ <td>+ TODO interest+ </td>+ </template>+ <td>+ <span x-text="account.iban"></span>+ <template x-if="'' === account.iban">+ <span x-text="account.account_number"></span>+ </template>+ </td>+ <template x-if="'liabilities' === objectType">+ <td>+ TODO current blaance+ </td>+ </template>+ <template x-if="'liabilities' === objectType">+ <td>+ TODO left in debt+ </td>+ </template>+ <td class="d-md-table-cell d-none">+ <template x-if="true === account.active">+ <span class="bi bi-check text-success"></span>+ </template>+ <template x-if="false === account.active">+ <span class="bi bi-x text-danger"></span>+ </template>+ </td>+ <template x-if="'liabilities' !== objectType">+ <td>+ <span x-text="account.last_activity"></span>+ </td>+ </template>+ <td>+ <template x-if="0.0 === account.balance_difference_float">+ <span class="money-neutral" x-text="account.balance_difference"></span>+ </template>+ <template x-if="account.balance_difference_float > 0.0">+ <span class="money-positive" x-text="account.balance_difference"></span>+ </template>+ <template x-if="account.balance_difference_float < 0.0">+ <span class="money-negative" x-text="account.balance_difference"></span>+ </template>+ </td>+ <td class="justify-content-end">+ <div class="dropdown">+ <button class="btn btn-outline-secondary btn-sm dropdown-toggle" type="button" :id="'action_menu_' + account.id" data-bs-toggle="dropdown" aria-expanded="false">+ {{ __('firefly.actions') }}+ </button>+ <ul class="dropdown-menu" :aria-labelledby="'action_menu_' + account.id">+ <li><a class="dropdown-item" :href="'./accounts/edit/' + account.id + '?_from={{ urlencode($FF3_FROM) }}'"><span class="bi bi-pencil"></span> {{ __('firefly.edit') }}</a></li>+ <li><a class="dropdown-item" :href="'./accounts/delete/' + account.id + '?_from={{ urlencode($FF3_FROM) }}'"><span class="bi bi-trash"></span> {{ __('firefly.delete') }}</a></li>+ <template x-if="'asset' === objectType">+ <li><a class="dropdown-item" :href="'./accounts/reconcile/' + account.id"><span class="bi bi-check"></span> {{ __('firefly.reconcile_this_account') }}</a></li>+ </template>+ </ul>+ </div>+ </td>+ </tr>+ </template>+ </tbody></table>diff --git a/resources/views/errors/405.blade.php b/resources/views/errors/405.blade.phpnew file mode 100644index 0000000000..6ca27ce4a1--- /dev/null+++ b/resources/views/errors/405.blade.php@@ -0,0 +1,24 @@+@extends('layout.v3.blank')+@section('status_code','405')+@section('status','Method Not Allowed')+@section('sub_title', trans('errors.405_header'))+@section('content')+<div class="row">+ <div class="col">+ @if(str_starts_with($exception->getMessage(),'Webhooks'))+ <p class="lead">+ {{ $exception->getMessage() }}+ </p>+ @endif+ <p>+ {{ trans('errors.405_page_does_not_exist') }}+ </p>+ <p>+ {{ trans('errors.404_send_error') }}+ </p>+ <p>+ {!! trans('errors.405_github_link') !!}+ </p>+ </div>+</div>+@endsection