Skip to content

Firefly III: a personal finances manager

Add more sort options

James Cole78bfd467f361
diff --git a/app/Support/JsonApi/Enrichments/AccountEnrichment.php b/app/Support/JsonApi/Enrichments/AccountEnrichment.php
index 5601f75fee..d722b672fc 100644
--- a/app/Support/JsonApi/Enrichments/AccountEnrichment.php
+++ b/app/Support/JsonApi/Enrichments/AccountEnrichment.php
@@ -467,10 +467,20 @@ class AccountEnrichment implements EnrichmentInterface
if (in_array($parameter[0], $dbParams, true)) {
continue;
}
+ $field = $parameter[0];
- switch ($parameter[0]) {
+ switch ($field) {
default:
- throw new FireflyException(sprintf('Account enrichment cannot sort on field "%s"', $parameter[0]));
+ throw new FireflyException(sprintf('Account enrichment cannot sort on field "%s"', $field));
+ case 'account_number':
+ $this->collection = $this->collection->sortBy(static fn (Account $account) => $account->meta['account_number'] ?? '', SORT_REGULAR, 'desc' === $parameter[1]);
+ break;
+ case 'role':
+ $this->collection = $this->collection->sortBy(static fn (Account $account) => $account->meta['account_role'] ?? '', SORT_REGULAR, 'desc' === $parameter[1]);
+ break;
+ case 'account_number_and_iban':
+ $this->collection = $this->collection->sortBy(static fn (Account $account) => sprintf('%s-%s', $account->iban, $account->meta['account_number']), SORT_REGULAR, 'desc' === $parameter[1]);
+ break;
case 'current_balance':
case 'pc_current_balance':
diff --git a/config/firefly.php b/config/firefly.php
index e155ccaf57..a82544d109 100644
--- a/config/firefly.php
+++ b/config/firefly.php
@@ -850,7 +850,18 @@ return [
'dynamic_date_ranges' => ['last7', 'last30', 'last90', 'last365', 'MTD', 'QTD', 'YTD'],
'allowed_sort_parameters' => [
- 'Account' => ['id', 'order', 'name', 'iban', 'active', 'account_type_id',
+ 'Account' => [
+ 'id',
+ 'order',
+ 'name',
+ 'iban',
+ 'account_number',
+ 'account_number_and_iban',
+ 'liability_direction',
+ 'liability_interest',
+ 'active',
+ 'role',
+ 'account_type_id',
'current_balance',
'pc_current_balance',
'opening_balance',
diff --git a/resources/assets/v3/js/pages/accounts/index.js b/resources/assets/v3/js/pages/accounts/index.js
index 5f5bf6dca6..c63a79656e 100644
--- a/resources/assets/v3/js/pages/accounts/index.js
+++ b/resources/assets/v3/js/pages/accounts/index.js
@@ -87,17 +87,20 @@ let index = function () {
// grab the account list.
this.downloadAccounts();
// get accounts by initial sort.
- document.querySelectorAll("table.sortable th").forEach((el) => {
- el.addEventListener("click", (event) => {
- let newColumn = event.currentTarget.dataset.column;
- if (newColumn === this.sortColumn) {
- this.sortDirection = "asc" === this.sortDirection ? "desc" : "asc";
- }
- if (newColumn !== this.sortColumn) {
- this.sortColumn = newColumn;
- }
- this.updateHistory();
- this.downloadAccounts();
+ document.addEventListener('alpine:initialized', () => {
+ document.querySelectorAll("table.sortable th").forEach((el) => {
+ el.addEventListener("click", (event) => {
+ let newColumn = event.currentTarget.dataset.column;
+ if (newColumn === this.sortColumn) {
+ this.sortDirection = "asc" === this.sortDirection ? "desc" : "asc";
+ }
+ if (newColumn !== this.sortColumn) {
+ this.sortColumn = newColumn;
+ }
+ console.log('New sort instructions', this.sortColumn, this.sortDirection)
+ this.updateHistory();
+ this.downloadAccounts();
+ });
});
});
getVariable("listPageSize").then((listPageSize) => {
diff --git a/resources/views/accounts/index.blade.php b/resources/views/accounts/index.blade.php
index 6ea8fd5428..9e9b06304d 100644
--- a/resources/views/accounts/index.blade.php
+++ b/resources/views/accounts/index.blade.php
@@ -22,18 +22,19 @@
<th data-column="order" :class="{'w-5' : true,'sortable': true, 'sortable_sorted': 'order' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">&nbsp;</th>
<th data-column="name" :class="{'w-20' : true,'sortable': true, 'sortable_sorted': 'name' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">{{ trans('list.name') }}</th>
<template x-if="'asset' === objectType">
- <th {{-- hide on LG and smaller. --}} class="d-lg-table-cell d-none">{{ trans('list.role') }}</th>
+ {{-- hide on LG and smaller. --}}
+ <th data-column="role" :class="{'d-lg-table-cell': true, 'd-none': true,'sortable': true, 'sortable_sorted': 'role' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">{{ trans('list.role') }}</th>
</template>
<template x-if="'liabilities' === objectType">
- <th>{{ trans('list.liability_type') }}</th>
+ <th data-column="account_type_id" :class="{'sortable': true, 'sortable_sorted': 'account_type_id' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">{{ trans('list.liability_type') }}</th>
</template>
<template x-if="'liabilities' === objectType">
- <th>{{ trans('form.liability_direction') }}</th>
+ <th data-column="liability_direction" :class="{'sortable': true, 'sortable_sorted': 'liability_direction' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">{{ trans('form.liability_direction') }}</th>
</template>
<template x-if="'liabilities' === objectType">
- <th>{{ trans('list.interest') }} ({{ trans('list.interest_period') }})</th>
+ <th data-column="liability_interest" :class="{'sortable': true, 'sortable_sorted': 'liability_interest' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">{{ trans('list.interest') }} ({{ trans('list.interest_period') }})</th>
</template>
- <th>{{ trans('form.account_number') }}</th>
+ <th data-column="account_number_and_iban" :class="{'sortable': true, 'sortable_sorted': 'account_number_and_iban' === sortColumn, 'sortable_sorted_asc': 'asc' === sortDirection, 'sortable_sorted_desc': 'desc' === sortDirection }">{{ trans('form.account_number') }}</th>
<template x-if="'liabilities' !== objectType">
<th class="text-end">{{ trans('list.currentBalance') }}</th>
</template>