Skip to content

Firefly III: a personal finances manager

New endpoint, fixed logo, better account overview.

James Cole9078781d6153
diff --git a/app/Api/V2/Controllers/Controller.php b/app/Api/V2/Controllers/Controller.php
index 99f30570d0..110330f5a4 100644
--- a/app/Api/V2/Controllers/Controller.php
+++ b/app/Api/V2/Controllers/Controller.php
@@ -158,7 +158,8 @@ class Controller extends BaseController
// the transformer, at this point, needs to collect information that ALL items in the collection
// require, like meta-data and stuff like that, and save it for later.
- $transformer->collectMetaData($objects);
+ $objects = $transformer->collectMetaData($objects);
+ $paginator->setCollection($objects);
$resource = new FractalCollection($objects, $transformer, $key);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
diff --git a/app/Api/V2/Controllers/Model/Account/IndexController.php b/app/Api/V2/Controllers/Model/Account/IndexController.php
index 4679bee47e..912ac0a851 100644
--- a/app/Api/V2/Controllers/Model/Account/IndexController.php
+++ b/app/Api/V2/Controllers/Model/Account/IndexController.php
@@ -47,7 +47,7 @@ class IndexController extends Controller
function ($request, $next) {
$this->repository = app(AccountRepositoryInterface::class);
// new way of user group validation
- $userGroup = $this->validateUserGroup($request);
+ $userGroup = $this->validateUserGroup($request);
if (null !== $userGroup) {
$this->repository->setUserGroup($userGroup);
}
@@ -62,20 +62,23 @@ class IndexController extends Controller
*/
public function index(IndexRequest $request): JsonResponse
{
+
$this->repository->resetAccountOrder();
- $types = $request->getAccountTypes();
- $accounts = $this->repository->getAccountsByType($types);
- $pageSize = $this->parameters->get('limit');
- $count = $accounts->count();
- $accounts = $accounts->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
- $paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
- $transformer = new AccountTransformer();
+ $types = $request->getAccountTypes();
+ $instructions = $request->getSortInstructions('accounts');
+ $accounts = $this->repository->getAccountsByType($types, $instructions);
+ $pageSize = $this->parameters->get('limit');
+ $count = $accounts->count();
+ $accounts = $accounts->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
+ $paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
+ $transformer = new AccountTransformer();
+
+ $this->parameters->set('sort', $instructions);
$transformer->setParameters($this->parameters); // give params to transformer
return response()
->json($this->jsonApiList('accounts', $paginator, $transformer))
- ->header('Content-Type', self::CONTENT_TYPE)
- ;
+ ->header('Content-Type', self::CONTENT_TYPE);
}
public function infiniteList(InfiniteListRequest $request): JsonResponse
@@ -83,7 +86,7 @@ class IndexController extends Controller
$this->repository->resetAccountOrder();
// get accounts of the specified type, and return.
- $types = $request->getAccountTypes();
+ $types = $request->getAccountTypes();
// get from repository
$accounts = $this->repository->getAccountsInOrder($types, $request->getSortInstructions('accounts'), $request->getStartRow(), $request->getEndRow());
@@ -95,7 +98,6 @@ class IndexController extends Controller
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
- ->header('Content-Type', self::CONTENT_TYPE)
- ;
+ ->header('Content-Type', self::CONTENT_TYPE);
}
}
diff --git a/app/Api/V2/Request/Model/Account/IndexRequest.php b/app/Api/V2/Request/Model/Account/IndexRequest.php
index b07559ef3a..e9c7b3039d 100644
--- a/app/Api/V2/Request/Model/Account/IndexRequest.php
+++ b/app/Api/V2/Request/Model/Account/IndexRequest.php
@@ -27,6 +27,7 @@ use Carbon\Carbon;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
+use FireflyIII\Support\Request\GetSortInstructions;
use Illuminate\Foundation\Http\FormRequest;
/**
@@ -39,6 +40,7 @@ class IndexRequest extends FormRequest
use AccountFilter;
use ChecksLogin;
use ConvertsDataTypes;
+ use GetSortInstructions;
/**
* Get all data from the request.
diff --git a/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php b/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php
index 05e613185f..a7a17c75f9 100644
--- a/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php
+++ b/app/Api/V2/Request/Model/Transaction/InfiniteListRequest.php
@@ -29,6 +29,7 @@ use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Http\Api\TransactionFilter;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;
+use FireflyIII\Support\Request\GetSortInstructions;
use Illuminate\Foundation\Http\FormRequest;
/**
@@ -41,6 +42,7 @@ class InfiniteListRequest extends FormRequest
use ChecksLogin;
use ConvertsDataTypes;
use TransactionFilter;
+ use GetSortInstructions;
public function buildParams(): string
{
@@ -97,30 +99,6 @@ class InfiniteListRequest extends FormRequest
return 0 === $page || $page > 65536 ? 1 : $page;
}
- public function getSortInstructions(string $key): array
- {
- $allowed = config(sprintf('firefly.sorting.allowed.%s', $key));
- $set = $this->get('sorting', []);
- $result = [];
- if (0 === count($set)) {
- return [];
- }
- foreach ($set as $info) {
- $column = $info['column'] ?? 'NOPE';
- $direction = $info['direction'] ?? 'NOPE';
- if ('asc' !== $direction && 'desc' !== $direction) {
- // skip invalid direction
- continue;
- }
- if (false === in_array($column, $allowed, true)) {
- // skip invalid column
- continue;
- }
- $result[$column] = $direction;
- }
-
- return $result;
- }
public function getTransactionTypes(): array
{
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 9736462044..351a0cbb33 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -95,21 +95,21 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static Builder|Account withTrashed()
* @method static Builder|Account withoutTrashed()
*
- * @property Carbon $lastActivityDate
- * @property string $startBalance
- * @property string $endBalance
- * @property string $difference
- * @property string $interest
- * @property string $interestPeriod
- * @property string $accountTypeString
- * @property Location $location
- * @property string $liability_direction
- * @property string $current_debt
- * @property int $user_group_id
+ * @property Carbon $lastActivityDate
+ * @property string $startBalance
+ * @property string $endBalance
+ * @property string $difference
+ * @property string $interest
+ * @property string $interestPeriod
+ * @property string $accountTypeString
+ * @property Location $location
+ * @property string $liability_direction
+ * @property string $current_debt
+ * @property int $user_group_id
*
* @method static EloquentBuilder|Account whereUserGroupId($value)
*
- * @property null|UserGroup $userGroup
+ * @property null|UserGroup $userGroup
*
* @mixin Eloquent
*/
@@ -121,18 +121,18 @@ class Account extends Model
use SoftDeletes;
protected $casts
- = [
- 'created_at' => 'datetime',
- 'updated_at' => 'datetime',
- 'user_id' => 'integer',
- 'deleted_at' => 'datetime',
- 'active' => 'boolean',
- 'encrypted' => 'boolean',
- ];
-
- protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
-
- protected $hidden = ['encrypted'];
+ = [
+ 'created_at' => 'datetime',
+ 'updated_at' => 'datetime',
+ 'user_id' => 'integer',
+ 'deleted_at' => 'datetime',
+ 'active' => 'boolean',
+ 'encrypted' => 'boolean',
+ ];
+
+ protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban'];
+
+ protected $hidden = ['encrypted'];
private bool $joinedAccountTypes = false;
/**
@@ -146,10 +146,10 @@ class Account extends Model
$accountId = (int)$value;
/** @var User $user */
- $user = auth()->user();
+ $user = auth()->user();
/** @var null|Account $account */
- $account = $user->accounts()->with(['accountType'])->find($accountId);
+ $account = $user->accounts()->with(['accountType'])->find($accountId);
if (null !== $account) {
return $account;
}
@@ -180,9 +180,8 @@ class Account extends Model
{
/** @var null|AccountMeta $metaValue */
$metaValue = $this->accountMeta()
- ->where('name', 'account_number')
- ->first()
- ;
+ ->where('name', 'account_number')
+ ->first();
return null !== $metaValue ? $metaValue->data : '';
}
@@ -240,7 +239,7 @@ class Account extends Model
public function setVirtualBalanceAttribute(mixed $value): void
{
- $value = (string)$value;
+ $value = (string)$value;
if ('' === $value) {
$value = null;
}
@@ -260,7 +259,7 @@ class Account extends Model
protected function accountId(): Attribute
{
return Attribute::make(
- get: static fn ($value) => (int)$value,
+ get: static fn($value) => (int)$value,
);
}
@@ -270,14 +269,22 @@ class Account extends Model
protected function accountTypeId(): Attribute
{
return Attribute::make(
- get: static fn ($value) => (int)$value,
+ get: static fn($value) => (int)$value,
);
}
+ //
+ protected function iban(): Attribute
+ {
+ return Attribute::make(
+ get: static fn($value) => null === $value ? null : trim(str_replace(' ', '', (string)$value)),
+ );
+ }
+
protected function order(): Attribute
{
return Attribute::make(
- get: static fn ($value) => (int)$value,
+ get: static fn($value) => (int)$value,
);
}
@@ -287,7 +294,7 @@ class Account extends Model
protected function virtualBalance(): Attribute
{
return Attribute::make(
- get: static fn ($value) => (string)$value,
+ get: static fn($value) => (string)$value,
);
}
}
diff --git a/app/Repositories/UserGroups/Account/AccountRepository.php b/app/Repositories/UserGroups/Account/AccountRepository.php
index d3f43220f0..e4e656254f 100644
--- a/app/Repositories/UserGroups/Account/AccountRepository.php
+++ b/app/Repositories/UserGroups/Account/AccountRepository.php
@@ -62,8 +62,7 @@ class AccountRepository implements AccountRepositoryInterface
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}
- )
- ;
+ );
if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -89,7 +88,7 @@ class AccountRepository implements AccountRepositoryInterface
public function findByName(string $name, array $types): ?Account
{
- $query = $this->userGroup->accounts();
+ $query = $this->userGroup->accounts();
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -113,8 +112,8 @@ class AccountRepository implements AccountRepositoryInterface
public function getAccountCurrency(Account $account): ?TransactionCurrency
{
- $type = $account->accountType->type;
- $list = config('firefly.valid_currency_account_types');
+ $type = $account->accountType->type;
+ $list = config('firefly.valid_currency_account_types');
// return null if not in this list.
if (!in_array($type, $list, true)) {
@@ -239,16 +238,19 @@ class AccountRepository implements AccountRepositoryInterface
public function getAccountsByType(array $types, ?array $sort = []): Collection
{
- $res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
- $query = $this->userGroup->accounts();
+ $sortable = ['name', 'active']; // TODO yes this is a duplicate array.
+ $res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
+ $query = $this->userGroup->accounts();
if (0 !== count($types)) {
$query->accountTypeIn($types);
}
// add sort parameters. At this point they're filtered to allowed fields to sort by:
- if (0 !== count($sort)) {
- foreach ($sort as $param) {
- $query->orderBy($param[0], $param[1]);
+ if (count($sort) > 0) {
+ foreach ($sort as $column => $direction) {
+ if (in_array($column, $sortable, true)) {
+ $query->orderBy(sprintf('accounts.%s', $column), $direction);
+ }
}
}
@@ -267,12 +269,11 @@ class AccountRepository implements AccountRepositoryInterface
{
// search by group, not by user
$dbQuery = $this->userGroup->accounts()
- ->where('active', true)
- ->orderBy('accounts.order', 'ASC')
- ->orderBy('accounts.account_type_id', 'ASC')
- ->orderBy('accounts.name', 'ASC')
- ->with(['accountType'])
- ;
+ ->where('active', true)
+ ->orderBy('accounts.order', 'ASC')
+ ->orderBy('accounts.account_type_id', 'ASC')
+ ->orderBy('accounts.name', 'ASC')
+ ->with(['accountType']);
if ('' !== $query) {
// split query on spaces just in case:
$parts = explode(' ', $query);
diff --git a/app/Support/Request/GetSortInstructions.php b/app/Support/Request/GetSortInstructions.php
new file mode 100644
index 0000000000..f5eebea2cb
--- /dev/null
+++ b/app/Support/Request/GetSortInstructions.php
@@ -0,0 +1,54 @@
+<?php
+/*
+ * GetSortInstructions.php
+ * Copyright (c) 2024 [email protected].
+ *
+ * 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\Support\Request;
+
+trait GetSortInstructions
+{
+
+ final public function getSortInstructions(string $key): array
+ {
+ $allowed = config(sprintf('firefly.sorting.allowed.%s', $key));
+ $set = $this->get('sorting', []);
+ $result = [];
+ if (0 === count($set)) {
+ return [];
+ }
+ foreach ($set as $info) {
+ $column = $info['column'] ?? 'NOPE';
+ $direction = $info['direction'] ?? 'NOPE';
+ if ('asc' !== $direction && 'desc' !== $direction) {
+ // skip invalid direction
+ continue;
+ }
+ if (false === in_array($column, $allowed, true)) {
+ // skip invalid column
+ continue;
+ }
+ $result[$column] = $direction;
+ }
+
+ return $result;
+ }
+
+}
diff --git a/app/Transformers/V2/AbstractTransformer.php b/app/Transformers/V2/AbstractTransformer.php
index 9803753688..3964ca17f9 100644
--- a/app/Transformers/V2/AbstractTransformer.php
+++ b/app/Transformers/V2/AbstractTransformer.php
@@ -37,8 +37,11 @@ abstract class AbstractTransformer extends TransformerAbstract
/**
* This method is called exactly ONCE from FireflyIII\Api\V2\Controllers\Controller::jsonApiList
+ *
+ * @param Collection $objects
+ * @return Collection
*/
- abstract public function collectMetaData(Collection $objects): void;
+ abstract public function collectMetaData(Collection $objects): Collection;
final public function getParameters(): ParameterBag
{
diff --git a/app/Transformers/V2/AccountTransformer.php b/app/Transformers/V2/AccountTransformer.php
index 08d699a632..28cab1c69b 100644
--- a/app/Transformers/V2/AccountTransformer.php
+++ b/app/Transformers/V2/AccountTransformer.php
@@ -32,6 +32,7 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Log;
/**
* Class AccountTransformer
@@ -48,7 +49,7 @@ class AccountTransformer extends AbstractTransformer
/**
* @throws FireflyException
*/
- public function collectMetaData(Collection $objects): void
+ public function collectMetaData(Collection $objects): Collection
{
$this->currencies = [];
$this->accountMeta = [];
@@ -57,18 +58,17 @@ class AccountTransformer extends AbstractTransformer
$this->convertedBalances = app('steam')->balancesByAccountsConverted($objects, $this->getDate());
/** @var CurrencyRepositoryInterface $repository */
- $repository = app(CurrencyRepositoryInterface::class);
- $this->default = app('amount')->getDefaultCurrency();
+ $repository = app(CurrencyRepositoryInterface::class);
+ $this->default = app('amount')->getDefaultCurrency();
// get currencies:
- $accountIds = $objects->pluck('id')->toArray();
- $meta = AccountMeta::whereIn('account_id', $accountIds)
- ->where('name', 'currency_id')
- ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])
- ;
- $currencyIds = $meta->pluck('data')->toArray();
-
- $currencies = $repository->getByIds($currencyIds);
+ $accountIds = $objects->pluck('id')->toArray();
+ $meta = AccountMeta::whereIn('account_id', $accountIds)
+ ->whereIn('name', ['currency_id','account_role','account_number'])
+ ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']);
+ $currencyIds = $meta->where('name','currency_id')->pluck('data')->toArray();
+
+ $currencies = $repository->getByIds($currencyIds);
foreach ($currencies as $currency) {
$id = $currency->id;
$this->currencies[$id] = $currency;
@@ -79,15 +79,47 @@ class AccountTransformer extends AbstractTransformer
}
// get account types:
// select accounts.id, account_types.type from account_types left join accounts on accounts.account_type_id = account_types.id;
- $accountTypes = AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id')
- ->whereIn('accounts.id', $accountIds)
- ->get(['accounts.id', 'account_types.type'])
- ;
+ $accountTypes = AccountType::leftJoin('accounts', 'accounts.account_type_id', '=', 'account_types.id')
+ ->whereIn('accounts.id', $accountIds)
+ ->get(['accounts.id', 'account_types.type']);
/** @var AccountType $row */
foreach ($accountTypes as $row) {
$this->accountTypes[$row->id] = (string)config(sprintf('firefly.shortNamesByFullName.%s', $row->type));
}
+
+ // TODO needs separate method.
+ $sort = $this->parameters->get('sort');
+ if (count($sort) > 0) {
+ foreach ($sort as $column => $direction) {
+ // account_number + iban
+ if ('iban' === $column) {
+ $meta = $this->accountMeta;
+ $objects = $objects->sort(function (Account $left, Account $right) use ($meta, $direction) {
+ $leftIban = trim(sprintf('%s%s', $left->iban, ($meta[$left->id]['account_number'] ?? '')));
+ $rightIban = trim(sprintf('%s%s', $right->iban, ($meta[$right->id]['account_number'] ?? '')));
+ if ('asc' === $direction) {
+ return strcasecmp($leftIban, $rightIban);
+ }
+ return strcasecmp($rightIban, $leftIban);
+ });
+ }
+ if('balance' === $column) {
+ $balances = $this->convertedBalances;
+ $objects = $objects->sort(function (Account $left, Account $right) use ($balances, $direction) {
+ $leftBalance = (float)($balances[$left->id]['native_balance'] ?? 0);
+ $rightBalance = (float)($balances[$right->id]['native_balance'] ?? 0);
+ if ('asc' === $direction) {
+ return $leftBalance <=> $rightBalance;
+ }
+ return $rightBalance <=> $leftBalance;
+ });
+ }
+ }
+
+ }
+ //$objects = $objects->sortByDesc('name');
+ return $objects;
}
private function getDate(): Carbon
@@ -105,15 +137,15 @@ class AccountTransformer extends AbstractTransformer
*/
public function transform(Account $account): array
{
- $id = $account->id;
+ $id = $account->id;
// various meta
- $accountRole = $this->accountMeta[$id]['account_role'] ?? null;
- $accountType = $this->accountTypes[$id];
- $order = $account->order;
+ $accountRole = $this->accountMeta[$id]['account_role'] ?? null;
+ $accountType = $this->accountTypes[$id];
+ $order = $account->order;
// no currency? use default
- $currency = $this->default;
+ $currency = $this->default;
if (array_key_exists($id, $this->accountMeta) && 0 !== (int)$this->accountMeta[$id]['currency_id']) {
$currency = $this->currencies[(int)$this->accountMeta[$id]['currency_id']];
}
@@ -127,19 +159,20 @@ class AccountTransformer extends AbstractTransformer
}
return [
- 'id' => (string)$account->id,
- 'created_at' => $account->created_at->toAtomString(),
- 'updated_at' => $account->updated_at->toAtomString(),
- 'active' => $account->active,
- 'order' => $order,
- 'name' => $account->name,
- 'iban' => '' === $account->iban ? null : $account->iban,
- 'type' => strtolower($accountType),
- 'account_role' => $accountRole,
- 'currency_id' => (string)$currency->id,
- 'currency_code' => $currency->code,
- 'currency_symbol' => $currency->symbol,
- 'currency_decimal_places' => $currency->decimal_places,
+ 'id' => (string)$account->id,
+ 'created_at' => $account->created_at->toAtomString(),
+ 'updated_at' => $account->updated_at->toAtomString(),
+ 'active' => $account->active,
+ 'order' => $order,
+ 'name' => $account->name,
+ 'iban' => '' === (string)$account->iban ? null : $account->iban,
+ 'account_number' => $this->accountMeta[$id]['account_number'] ?? null,
+ 'type' => strtolower($accountType),
+ 'account_role' => $accountRole,
+ 'currency_id' => (string)$currency->id,
+ 'currency_code' => $currency->code,
+ 'currency_symbol' => $currency->symbol,
+ 'currency_decimal_places' => $currency->decimal_places,
'native_currency_id' => (string)$this->default->id,
'native_currency_code' => $this->default->code,
@@ -173,7 +206,7 @@ class AccountTransformer extends AbstractTransformer
'links' => [
[
'rel' => 'self',
- 'uri' => '/accounts/'.$account->id,
+ 'uri' => '/accounts/' . $account->id,
],
],
];
diff --git a/config/firefly.php b/config/firefly.php
index cb1a8ebe94..aedcdc71f7 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -432,7 +432,7 @@ return [
'transfers' => 'fa-exchange',
],
- 'bindables' => [
+ 'bindables' => [
// models
'account' => Account::class,
'attachment' => Attachment::class,
@@ -490,7 +490,7 @@ return [
'userGroupBill' => UserGroupBill::class,
'userGroup' => UserGroup::class,
],
- 'rule-actions' => [
+ 'rule-actions' => [
'set_category' => SetCategory::class,
'clear_category' => ClearCategory::class,
'set_budget' => SetBudget::class,
@@ -521,7 +521,7 @@ return [
'set_source_to_cash' => SetSourceToCashAccount::class,
'set_destination_to_cash' => SetDestinationToCashAccount::class,
],
- 'context-rule-actions' => [
+ 'context-rule-actions' => [
'set_category',
'set_budget',
'add_tag',
@@ -540,13 +540,13 @@ return [
'convert_transfer',
],
- 'test-triggers' => [
+ 'test-triggers' => [
'limit' => 10,
'range' => 200,
],
// expected source types for each transaction type, in order of preference.
- 'expected_source_types' => [
+ 'expected_source_types' => [
'source' => [
TransactionTypeModel::WITHDRAWAL => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
TransactionTypeEnum::DEPOSIT->value => [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::REVENUE, AccountType::CASH],
@@ -591,7 +591,7 @@ return [
TransactionTypeModel::LIABILITY_CREDIT => [AccountType::LIABILITY_CREDIT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
],
],
- 'allowed_opposing_types' => [
+ 'allowed_opposing_types' => [
'source' => [
AccountType::ASSET => [
AccountType::ASSET,
@@ -681,7 +681,7 @@ return [
],
],
// depending on the account type, return the allowed transaction types:
- 'allowed_transaction_types' => [
+ 'allowed_transaction_types' => [
'source' => [
AccountType::ASSET => [
TransactionTypeModel::WITHDRAWAL,
@@ -750,7 +750,7 @@ return [
],
// having the source + dest will tell you the transaction type.
- 'account_to_transaction' => [
+ 'account_to_transaction' => [
AccountType::ASSET => [
AccountType::ASSET => TransactionTypeModel::TRANSFER,
AccountType::CASH => TransactionTypeModel::WITHDRAWAL,
@@ -815,7 +815,7 @@ return [
],
// allowed source -> destination accounts.
- 'source_dests' => [
+ 'source_dests' => [
TransactionTypeModel::WITHDRAWAL => [
AccountType::ASSET => [AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::CASH],
AccountType::LOAN => [AccountType::EXPENSE, AccountType::CASH],
@@ -854,7 +854,7 @@ return [
],
],
// if you add fields to this array, don't forget to update the export routine (ExportDataGenerator).
- 'journal_meta_fields' => [
+ 'journal_meta_fields' => [
// sepa
'sepa_cc',
'sepa_ct_op',
@@ -888,36 +888,36 @@ return [
'recurrence_count',
'recurrence_date',
],
- 'webhooks' => [
+ 'webhooks' => [
'max_attempts' => env('WEBHOOK_MAX_ATTEMPTS', 3),
],
- 'can_have_virtual_amounts' => [AccountType::ASSET],
- 'can_have_opening_balance' => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
- 'dynamic_creation_allowed' => [
+ 'can_have_virtual_amounts' => [AccountType::ASSET],
+ 'can_have_opening_balance' => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
+ 'dynamic_creation_allowed' => [
AccountType::EXPENSE,
AccountType::REVENUE,
AccountType::INITIAL_BALANCE,
AccountType::RECONCILIATION,
AccountType::LIABILITY_CREDIT,
],
- 'valid_asset_fields' => ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
- 'valid_cc_fields' => ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
- 'valid_account_fields' => ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth', 'liability_direction'],
+ 'valid_asset_fields' => ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
+ 'valid_cc_fields' => ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'],
+ 'valid_account_fields' => ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth', 'liability_direction'],
// dynamic date ranges are as follows:
- 'dynamic_date_ranges' => ['last7', 'last30', 'last90', 'last365', 'MTD', 'QTD', 'YTD'],
+ 'dynamic_date_ranges' => ['last7', 'last30', 'last90', 'last365', 'MTD', 'QTD', 'YTD'],
// only used in v1
- 'allowed_sort_parameters' => ['order', 'name', 'iban'],
+ 'allowed_sort_parameters' => ['order', 'name', 'iban'],
// preselected account lists possibilities:
- 'preselected_accounts' => ['all', 'assets', 'liabilities'],
+ 'preselected_accounts' => ['all', 'assets', 'liabilities'],
// allowed sort columns for API's
- 'sorting' => [
+ 'sorting' => [
'allowed' => [
'transactions' => ['description', 'amount'],
- 'accounts' => ['name'],
+ 'accounts' => ['name', 'active', 'iban', 'balance'],
],
],
];
diff --git a/public/images/logo.png b/public/images/logo.png
new file mode 100644
index 0000000000..bed923b227
Binary files /dev/null and b/public/images/logo.png differ
diff --git a/resources/assets/v2/boot/bootstrap.js b/resources/assets/v2/boot/bootstrap.js
index ca6959b893..b9a9432ec5 100644
--- a/resources/assets/v2/boot/bootstrap.js
+++ b/resources/assets/v2/boot/bootstrap.js
@@ -36,12 +36,16 @@ import {getVariable} from "../store/get-variable.js";
import {getViewRange} from "../support/get-viewrange.js";
import {loadTranslations} from "../support/load-translations.js";
+import adminlte from 'admin-lte';
+
+
store.addPlugin(observePlugin);
window.bootstrapped = false;
window.store = store;
+
// always grab the preference "marker" from Firefly III.
getFreshVariable('lastActivity').then((serverValue) => {
const localValue = store.get('lastActivity');
diff --git a/resources/assets/v2/pages/accounts/index.js b/resources/assets/v2/pages/accounts/index.js
index 31859e2382..9a4da9963b 100644
--- a/resources/assets/v2/pages/accounts/index.js
+++ b/resources/assets/v2/pages/accounts/index.js
@@ -51,9 +51,17 @@ let index = function () {
enabled: true
},
},
-
+ sortingColumn: '',
+ sortDirection: '',
accounts: [],
+ sort(column) {
+ this.sortingColumn = column;
+ this.sortDirection = this.sortDirection === 'asc' ? 'desc' : 'asc';
+ this.loadAccounts();
+ return false;
+ },
+
formatMoney(amount, currencyCode) {
return formatMoney(amount, currencyCode);
},
@@ -69,14 +77,29 @@ let index = function () {
},
loadAccounts() {
+ this.notifications.wait.show = true;
+ this.notifications.wait.text = i18next.t('firefly.wait_loading_data')
+ this.accounts = [];
+ // sort instructions
+ // &sorting[0][column]=description&sorting[0][direction]=asc
+ const sorting = [{column: this.sortingColumn, direction: this.sortDirection}];
// one page only.
- (new Get()).index({type: type, page: this.page}).then(response => {
+ (new Get()).index({sorting: sorting, type: type, page: this.page}).then(response => {
for (let i = 0; i < response.data.data.length; i++) {
if (response.data.data.hasOwnProperty(i)) {
let current = response.data.data[i];
let account = {
id: parseInt(current.id),
+ active: current.attributes.active,
name: current.attributes.name,
+ type: current.attributes.type,
+ // role: current.attributes.account_role,
+ iban: null === current.attributes.iban ? '' : current.attributes.iban.match(/.{1,4}/g).join(' '),
+ account_number: null === current.attributes.account_number ? '' : current.attributes.account_number,
+ current_balance: current.attributes.current_balance,
+ currency_code: current.attributes.currency_code,
+ native_current_balance: current.attributes.native_current_balance,
+ native_currency_code: current.attributes.native_currency_code,
};
this.accounts.push(account);
}
diff --git a/resources/assets/v2/sass/adminlte-filtered.scss b/resources/assets/v2/sass/adminlte-filtered.scss
new file mode 100644
index 0000000000..5a322c63f9
--- /dev/null
+++ b/resources/assets/v2/sass/adminlte-filtered.scss
@@ -0,0 +1,105 @@
+/*!
+ * adminlte-filteres.scss
+ * Copyright (c) 2024 [email protected].
+ *
+ * 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/.
+ */
+
+
+// less adminlte code because the CSS is massive otherwise.
+// copied from:
+
+/*!
+ * AdminLTE v4.0.0-alpha2
+ * Author: Colorlib
+ * Website: AdminLTE.io <https://adminlte.io>
+ * License: Open source - MIT <https://opensource.org/licenses/MIT>
+ */
+
+// Bootstrap Configuration
+// ---------------------------------------------------
+@import "bootstrap/scss/functions";
+
+// AdminLTE Configuration
+// ---------------------------------------------------
+@import "admin-lte/src/scss/bootstrap-variables"; // little modified are here
+
+// Bootstrap Configuration
+// ---------------------------------------------------
+@import "bootstrap/scss/variables";
+@import "bootstrap/scss/variables-dark";
+@import "bootstrap/scss/maps";
+@import "bootstrap/scss/mixins";
+@import "bootstrap/scss/utilities";
+
+// Bootstrap Layout & components
+@import "bootstrap/scss/root";
+@import "bootstrap/scss/reboot";
+@import "bootstrap/scss/type";
+@import "bootstrap/scss/images";
+@import "bootstrap/scss/containers";
+@import "bootstrap/scss/grid";
+@import "bootstrap/scss/tables";
+@import "bootstrap/scss/forms";
+@import "bootstrap/scss/buttons";
+@import "bootstrap/scss/transitions";
+@import "bootstrap/scss/dropdown";
+@import "bootstrap/scss/button-group";
+@import "bootstrap/scss/nav";
+@import "bootstrap/scss/navbar";
+@import "bootstrap/scss/card";
+//@import "bootstrap/scss/accordion";
+@import "bootstrap/scss/breadcrumb";
+@import "bootstrap/scss/pagination";
+@import "bootstrap/scss/badge";
+@import "bootstrap/scss/alert";
+@import "bootstrap/scss/progress";
+@import "bootstrap/scss/list-group";
+@import "bootstrap/scss/close";
+//@import "bootstrap/scss/toasts";
+@import "bootstrap/scss/modal";
+@import "bootstrap/scss/tooltip";
+@import "bootstrap/scss/popover";
+//@import "bootstrap/scss/carousel";
+@import "bootstrap/scss/spinners";
+@import "bootstrap/scss/offcanvas";
+@import "bootstrap/scss/placeholders";
+
+// Bootstrap Helpers
+@import "bootstrap/scss/helpers";
+
+// Bootstrap Utilities
+@import "bootstrap/scss/utilities/api";
+
+
+// AdminLTE Configuration
+// ---------------------------------------------------
+@import "admin-lte/src/scss/variables";
+@import "admin-lte/src/scss/variables-dark";
+@import "admin-lte/src/scss/mixins";
+
+// AdiminLTE Parts
+// ---------------------------------------------------
+@import "admin-lte/src/scss/parts/core";
+@import "admin-lte/src/scss/parts/components";
+@import "admin-lte/src/scss/parts/extra-components";
+
+// @import "admin-lte/src/scss/parts/pages";
+@import "admin-lte/src/scss/pages/login_and_register";
+
+@import "admin-lte/src/scss/parts/miscellaneous";
+
+
diff --git a/resources/assets/v2/sass/app.scss b/resources/assets/v2/sass/app.scss
index 2d4cbaed8c..06a1b91471 100644
--- a/resources/assets/v2/sass/app.scss
+++ b/resources/assets/v2/sass/app.scss
@@ -38,7 +38,7 @@ $success: #64B624 !default;
// @import "bootstrap/scss/bootstrap";
// admin LTE
-@import "admin-lte/src/scss/adminlte";
+@import "adminlte-filtered";
// @import "~bootstrap-sass/assets/stylesheets/bootstrap";
diff --git a/resources/views/v2/accounts/index.blade.php b/resources/views/v2/accounts/index.blade.php
index 138fc6e0a0..4a1780cbc2 100644
--- a/resources/views/v2/accounts/index.blade.php
+++ b/resources/views/v2/accounts/index.blade.php
@@ -57,11 +57,27 @@
<thead>
<tr>
<td>&nbsp;</td>
- <td>Active?</td>
- <td>Name</td>
+ <td>
+ <a href="#" x-on:click.prevent="sort('active')">Active?</a>
+ <em x-show="sortingColumn === 'active' && sortDirection === 'asc'" class="fa-solid fa-arrow-down-wide-short"></em>
+ <em x-show="sortingColumn === 'active' && sortDirection === 'desc'" class="fa-solid fa-arrow-up-wide-short"></em>
+ </td>
+ <td>
+ <a href="#" x-on:click.prevent="sort('name')">Name</a>
+ <em x-show="sortingColumn === 'name' && sortDirection === 'asc'" class="fa-solid fa-arrow-down-z-a"></em>
+ <em x-show="sortingColumn === 'name' && sortDirection === 'desc'" class="fa-solid fa-arrow-up-z-a"></em>
+ </td>
<td>Type</td>
- <td>Account number</td>
- <td>Current balance</td>
+ <td>
+ <a href="#" x-on:click.prevent="sort('iban')">Account number</a>
+ <em x-show="sortingColumn === 'iban' && sortDirection === 'asc'" class="fa-solid fa-arrow-down-z-a"></em>
+ <em x-show="sortingColumn === 'iban' && sortDirection === 'desc'" class="fa-solid fa-arrow-up-z-a"></em>
+ </td>
+ <td>
+ <a href="#" x-on:click.prevent="sort('balance')">Current balance</a>
+ <em x-show="sortingColumn === 'balance' && sortDirection === 'asc'" class="fa-solid fa-arrow-down-wide-short"></em>
+ <em x-show="sortingColumn === 'balance' && sortDirection === 'desc'" class="fa-solid fa-arrow-up-wide-short"></em>
+ </td>
<td>Last activity</td>
<td>Balance difference</td>
<td>&nbsp;</td>
@@ -70,20 +86,46 @@
<tbody>
<template x-for="(account, index) in accounts" :key="index">
<tr>
- <td>&nbsp;</td>
+ <td>TODO</td>
<td>
- &nbsp;
+ <template x-if="account.active">
+ <em class="text-success fa-solid fa-check"></em>
+ &nbsp;</template>
+ <template x-if="!account.active">
+ <em class="text-danger fa-solid fa-xmark"></em>
+ &nbsp;</template>
</td>
<td>
<a :href="'./accounts/show/' + account.id">
<span x-text="account.name"></span>
</a>
</td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
+ <td>
+ <span x-text="account.type"></span>
+ <span x-text="account.role"></span>
+ </td>
+ <td>
+ <!-- IBAN and no account nr -->
+ <template x-if="'' === account.account_number && '' !== account.iban">
+ <span x-text="account.iban + 'A'"></span>
+ </template>
+ <!-- no IBAN and account nr -->
+ <template x-if="'' !== account.account_number && '' === account.iban">
+ <span x-text="account.account_number"></span>
+ </template>
+ <!-- both -->
+ <template x-if="'' !== account.account_number && '' !== account.iban">
+ <span>
+ <span x-text="account.iban"></span>
+ (<span x-text="account.account_number"></span>)
+ </span>
+ </template>
+ </td>
+ <td>
+ <span x-text="formatMoney(account.current_balance, account.currency_code)"></span>
+ </td>
+ <td>TODO</td>
+ <td>TODO</td>
<td>&nbsp;</td>
</tr>
</template>
diff --git a/resources/views/v2/partials/layout/sidebar.blade.php b/resources/views/v2/partials/layout/sidebar.blade.php
index f434bfaca3..f5d131e399 100644
--- a/resources/views/v2/partials/layout/sidebar.blade.php
+++ b/resources/views/v2/partials/layout/sidebar.blade.php
@@ -4,7 +4,7 @@
<!--begin::Brand Link-->
<a href="{{route('index') }}" class="brand-link">
<!--begin::Brand Image-->
- <img src="v2/i/logo.png" alt="Firefly III Logo"
+ <img src="images/logo.png" alt="Firefly III Logo"
class="brand-image opacity-75 shadow">
<!--end::Brand Image-->
<!--begin::Brand Text-->