Skip to content

Firefly III: a personal finances manager

Fix order auto complete.

James Cole0bb3cbc36de7
diff --git a/app/Api/V1/Controllers/Autocomplete/AccountController.php b/app/Api/V1/Controllers/Autocomplete/AccountController.php
index b8fd44c9cc..30f4e2b2c2 100644
--- a/app/Api/V1/Controllers/Autocomplete/AccountController.php
+++ b/app/Api/V1/Controllers/Autocomplete/AccountController.php
@@ -129,13 +129,13 @@ final class AccountController extends Controller
}
// custom order.
- usort($return, static function (array $left, array $right): int {
- $order = [AccountTypeEnum::ASSET->value, AccountTypeEnum::REVENUE->value, AccountTypeEnum::EXPENSE->value];
- $posA = (int) array_search($left['type'], $order, true);
- $posB = (int) array_search($right['type'], $order, true);
-
- return $posA - $posB;
- });
+// usort($return, static function (array $left, array $right): int {
+// $order = [AccountTypeEnum::ASSET->value, AccountTypeEnum::REVENUE->value, AccountTypeEnum::EXPENSE->value];
+// $posA = (int) array_search($left['type'], $order, true);
+// $posB = (int) array_search($right['type'], $order, true);
+//
+// return $posA - $posB;
+// });
return response()->api($return);
}
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 53e97d0c8c..5a71b4c004 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -56,7 +56,7 @@ class Account extends Model
use ReturnsIntegerUserIdTrait;
use SoftDeletes;
- protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban', 'native_virtual_balance'];
+ protected $fillable = ['user_id', 'user_group_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban', 'native_virtual_balance','order'];
protected $hidden = ['encrypted'];
private bool $joinedAccountTypes = false;
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index ccabdbfd97..85443dfde2 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -48,7 +48,6 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Override;
-
use function Safe\json_encode;
/**
@@ -115,14 +114,13 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function findByAccountNumber(string $number, array $types): ?Account
{
$dbQuery = $this->user->accounts()
- ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
- ->where('accounts.active', true)
- ->where(static function (EloquentBuilder $q1) use ($number): void {
- $json = json_encode($number);
- $q1->where('account_meta.name', '=', 'account_number');
- $q1->where('account_meta.data', '=', $json);
- })
- ;
+ ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
+ ->where('accounts.active', true)
+ ->where(static function (EloquentBuilder $q1) use ($number): void {
+ $json = json_encode($number);
+ $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');
@@ -149,7 +147,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function findByName(string $name, array $types): ?Account
{
- $query = $this->user->accounts();
+ $query = $this->user->accounts();
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
@@ -173,14 +171,14 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
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)) {
return null;
}
- $currencyId = (int) $this->getMetaValue($account, 'currency_id');
+ $currencyId = (int)$this->getMetaValue($account, 'currency_id');
if ($currencyId > 0) {
return Amount::getTransactionCurrencyById($currencyId);
}
@@ -204,13 +202,13 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getAccountsByType(array $types, ?array $sort = []): Collection
{
- $res = array_intersect([
- AccountTypeEnum::ASSET->value,
- AccountTypeEnum::MORTGAGE->value,
- AccountTypeEnum::LOAN->value,
- AccountTypeEnum::DEBT->value,
- ], $types);
- $query = $this->user->accounts();
+ $res = array_intersect([
+ AccountTypeEnum::ASSET->value,
+ AccountTypeEnum::MORTGAGE->value,
+ AccountTypeEnum::LOAN->value,
+ AccountTypeEnum::DEBT->value,
+ ], $types);
+ $query = $this->user->accounts();
if (0 !== count($types)) {
$query->accountTypeIn($types);
}
@@ -251,13 +249,12 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getActiveAccountsByType(array $types): Collection
{
$query = $this->user->accounts()
- ->with([
- 'accountmeta' => static function (HasMany $query): void {
- $query->where('name', 'account_role');
- },
- 'attachments',
- ])
- ;
+ ->with([
+ 'accountmeta' => static function (HasMany $query): void {
+ $query->where('name', 'account_role');
+ },
+ 'attachments',
+ ]);
if (0 !== count($types)) {
$query->accountTypeIn($types);
}
@@ -271,7 +268,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getAttachments(Account $account): Collection
{
- $set = $account->attachments()->get();
+ $set = $account->attachments()->get();
/** @var Storage $disk */
$disk = Storage::disk('upload');
@@ -291,7 +288,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getCashAccount(): Account
{
/** @var AccountType $type */
- $type = AccountType::query()->where('type', AccountTypeEnum::CASH->value)->first();
+ $type = AccountType::query()->where('type', AccountTypeEnum::CASH->value)->first();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@@ -303,10 +300,9 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getCreditTransactionGroup(Account $account): ?TransactionGroup
{
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->where('transactions.account_id', $account->id)
- ->transactionTypes([TransactionTypeEnum::LIABILITY_CREDIT->value])
- ->first(['transaction_journals.*'])
- ;
+ ->where('transactions.account_id', $account->id)
+ ->transactionTypes([TransactionTypeEnum::LIABILITY_CREDIT->value])
+ ->first(['transaction_journals.*']);
return $journal?->transactionGroup;
}
@@ -314,10 +310,9 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getInactiveAccountsByType(array $types): Collection
{
$query = $this->user->accounts()
- ->with(['accountmeta' => static function (HasMany $query): void {
- $query->where('name', 'account_role');
- }])
- ;
+ ->with(['accountmeta' => static function (HasMany $query): void {
+ $query->where('name', 'account_role');
+ }]);
if (0 !== count($types)) {
$query->accountTypeIn($types);
}
@@ -340,12 +335,12 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
*/
public function getMetaValue(Account $account, string $field): ?string
{
- $result = $account->accountMeta->filter(static fn (AccountMeta $meta): bool => strtolower($meta->name) === strtolower($field));
+ $result = $account->accountMeta->filter(static fn(AccountMeta $meta): bool => strtolower($meta->name) === strtolower($field));
if (0 === $result->count()) {
return null;
}
if (1 === $result->count()) {
- return (string) $result->first()->data;
+ return (string)$result->first()->data;
}
return null;
@@ -362,10 +357,9 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getOpeningBalance(Account $account): ?TransactionJournal
{
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->where('transactions.account_id', $account->id)
- ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value])
- ->first(['transaction_journals.*'])
- ;
+ ->where('transactions.account_id', $account->id)
+ ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value])
+ ->first(['transaction_journals.*']);
}
/**
@@ -373,11 +367,10 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
*/
public function getOpeningBalanceAmount(Account $account, bool $convertToPrimary): ?string
{
- $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->where('transactions.account_id', $account->id)
- ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value])
- ->first(['transaction_journals.*'])
- ;
+ $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
+ ->where('transactions.account_id', $account->id)
+ ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value])
+ ->first(['transaction_journals.*']);
if (null === $journal) {
return null;
}
@@ -398,11 +391,10 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function getOpeningBalanceDate(Account $account): ?string
{
return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->where('transactions.account_id', $account->id)
- ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value])
- ->first(['transaction_journals.*'])
- ?->date->format('Y-m-d H:i:s')
- ;
+ ->where('transactions.account_id', $account->id)
+ ->transactionTypes([TransactionTypeEnum::OPENING_BALANCE->value, TransactionTypeEnum::LIABILITY_CREDIT->value])
+ ->first(['transaction_journals.*'])
+ ?->date->format('Y-m-d H:i:s');
}
public function getOpeningBalanceGroup(Account $account): ?TransactionGroup
@@ -429,16 +421,16 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
$name = trans('firefly.reconciliation_account_name', ['name' => $account->name, 'currency' => $currency->code]);
/** @var AccountType $type */
- $type = AccountType::query()->where('type', AccountTypeEnum::RECONCILIATION->value)->first();
+ $type = AccountType::query()->where('type', AccountTypeEnum::RECONCILIATION->value)->first();
/** @var null|Account $current */
- $current = $this->user->accounts()->where('account_type_id', $type->id)->where('name', $name)->first();
+ $current = $this->user->accounts()->where('account_type_id', $type->id)->where('name', $name)->first();
if (null !== $current) {
return $current;
}
- $data = [
+ $data = [
'account_type_id' => null,
'account_type_name' => AccountTypeEnum::RECONCILIATION->value,
'active' => true,
@@ -448,7 +440,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
];
/** @var AccountFactory $factory */
- $factory = app(AccountFactory::class);
+ $factory = app(AccountFactory::class);
$factory->setUser($account->user);
return $factory->create($data);
@@ -459,7 +451,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
$info = $account->transactions()->distinct()->groupBy('transaction_currency_id')->get(['transaction_currency_id'])->toArray();
$currencyIds = [];
foreach ($info as $entry) {
- $currencyIds[] = (int) $entry['transaction_currency_id'];
+ $currencyIds[] = (int)$entry['transaction_currency_id'];
}
$currencyIds = array_unique($currencyIds);
@@ -477,7 +469,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function maxOrder(string $type): int
{
- $sets = [
+ $sets = [
AccountTypeEnum::ASSET->value => [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
AccountTypeEnum::EXPENSE->value => [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::BENEFICIARY->value],
AccountTypeEnum::REVENUE->value => [AccountTypeEnum::REVENUE->value],
@@ -501,7 +493,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
],
];
if (array_key_exists(ucfirst($type), $sets)) {
- $order = (int) $this->getAccountsByType($sets[ucfirst($type)])->max('order');
+ $order = (int)$this->getAccountsByType($sets[ucfirst($type)])->max('order');
Log::debug(sprintf('Return max order of "%s" set: %d', $type, $order));
return $order;
@@ -513,7 +505,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
AccountTypeEnum::RECONCILIATION->value,
];
- $order = (int) $this->getAccountsByType($specials)->max('order');
+ $order = (int)$this->getAccountsByType($specials)->max('order');
Log::debug(sprintf('Return max order of "%s" set (specials!): %d', $type, $order));
return $order;
@@ -532,8 +524,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
->orderBy('transaction_journals.order', 'DESC')
->where('transaction_journals.user_id', $this->user->id)
->orderBy('transaction_journals.id', 'ASC') // ASC, because the oldest must come FIRST
- ->first(['transaction_journals.id'])
- ;
+ ->first(['transaction_journals.id']);
if (null !== $first) {
/** @var null|TransactionJournal */
return TransactionJournal::find($first->id);
@@ -566,60 +557,59 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
->where('transaction_journals.date', '>=', $start)
->where('transaction_journals.date', '<=', $end)
->get([
- // currencies
- 'transaction_currencies.id as currency_id',
- 'transaction_currencies.code as currency_code',
- 'transaction_currencies.name as currency_name',
- 'transaction_currencies.symbol as currency_symbol',
- 'transaction_currencies.decimal_places as currency_decimal_places',
-
- // foreign
- 'foreign_currencies.id as foreign_currency_id',
- 'foreign_currencies.code as foreign_currency_code',
- 'foreign_currencies.name as foreign_currency_name',
- 'foreign_currencies.symbol as foreign_currency_symbol',
- 'foreign_currencies.decimal_places as foreign_currency_decimal_places',
-
- // fields
- 'transaction_journals.date',
- 'transaction_types.type',
- 'transaction_journals.transaction_currency_id',
- 'transactions.amount',
- 'transactions.native_amount as pc_amount',
- 'transactions.foreign_amount',
- ])
- ->toArray()
- ;
+ // currencies
+ 'transaction_currencies.id as currency_id',
+ 'transaction_currencies.code as currency_code',
+ 'transaction_currencies.name as currency_name',
+ 'transaction_currencies.symbol as currency_symbol',
+ 'transaction_currencies.decimal_places as currency_decimal_places',
+
+ // foreign
+ 'foreign_currencies.id as foreign_currency_id',
+ 'foreign_currencies.code as foreign_currency_code',
+ 'foreign_currencies.name as foreign_currency_name',
+ 'foreign_currencies.symbol as foreign_currency_symbol',
+ 'foreign_currencies.decimal_places as foreign_currency_decimal_places',
+
+ // fields
+ 'transaction_journals.date',
+ 'transaction_types.type',
+ 'transaction_journals.transaction_currency_id',
+ 'transactions.amount',
+ 'transactions.native_amount as pc_amount',
+ 'transactions.foreign_amount',
+ ])
+ ->toArray();
}
public function resetAccountOrder(): void
{
+ Log::debug('Now in resetAccountOrder()');
$sets = [
- [AccountTypeEnum::DEFAULT->value, AccountTypeEnum::ASSET->value],
- // [AccountTypeEnum::EXPENSE->value, AccountTypeEnum::BENEFICIARY->value],
- // [AccountTypeEnum::REVENUE->value],
+ [AccountTypeEnum::ASSET->value],
[AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::CREDITCARD->value, AccountTypeEnum::MORTGAGE->value],
- // [AccountTypeEnum::CASH->value, AccountTypeEnum::INITIAL_BALANCE->value, AccountTypeEnum::IMPORT->value, AccountTypeEnum::RECONCILIATION->value],
];
foreach ($sets as $set) {
$list = $this->getAccountsByType($set);
- $index = 1;
+ $index = 0;
foreach ($list as $account) {
if (false === $account->active) {
- $account->order = 0;
-
+ if (0 !== (int)$account->order) {
+ Log::debug(sprintf('Inactive account #%d ("%s"): order should be ZERO be but is %d.', $account->id, $account->name, $account->order));
+ $account->order = 0;
+ $account->save();
+ }
continue;
}
- if ($index !== (int) $account->order) {
- Log::debug(sprintf('Account #%d ("%s"): order should %d be but is %d.', $account->id, $account->name, $index, $account->order));
+ if ($index !== (int)$account->order) {
$account->order = $index;
$account->save();
}
- ++$index;
+ $index++;
}
}
// reset the rest to zero.
- $all = [
+ $all = [
AccountTypeEnum::DEFAULT->value,
AccountTypeEnum::ASSET->value,
AccountTypeEnum::LOAN->value,
@@ -628,21 +618,22 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
AccountTypeEnum::MORTGAGE->value,
];
$this->user->accounts()
- ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
- ->whereNotIn('account_types.type', $all)
- ->update(['order' => 0])
- ;
+ ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
+ ->where(function (EloquentBuilder $q1) use ($all) {
+ $q1->where('accounts.order', '!=', 0)
+ ->whereNotIn('account_types.type', $all);
+ })->update(['accounts.order' => 0]);
}
public function searchAccount(string $query, array $types, int $limit): Collection
{
$dbQuery = $this->user->accounts()
- ->where('active', true)
- ->orderBy('accounts.order', 'ASC')
+ ->where('active', true)
->orderBy('accounts.account_type_id', 'ASC')
- ->orderBy('accounts.name', 'ASC')
- ->with(['accountType'])
- ;
+ ->orderBy('accounts.order', 'ASC')
+ ->orderBy('accounts.updated_at', 'DESC')
+ ->orderBy('accounts.name', 'ASC')
+ ->with(['accountType']);
if ('' !== $query) {
// split query on spaces just in case:
$parts = explode(' ', $query);
@@ -662,11 +653,10 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function searchAccountIncludingInactive(string $query, array $types, int $limit): Collection
{
$dbQuery = $this->user->accounts()
- ->orderBy('accounts.order', 'ASC')
- ->orderBy('accounts.account_type_id', 'ASC')
- ->orderBy('accounts.name', 'ASC')
- ->with(['accountType'])
- ;
+ ->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);
@@ -686,14 +676,13 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
public function searchAccountNr(string $query, array $types, int $limit): Collection
{
$dbQuery = $this->user->accounts()
- ->distinct()
- ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
- ->where('accounts.active', true)
- ->orderBy('accounts.order', 'ASC')
- ->orderBy('accounts.account_type_id', 'ASC')
- ->orderBy('accounts.name', 'ASC')
- ->with(['accountType', 'accountMeta'])
- ;
+ ->distinct()
+ ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
+ ->where('accounts.active', true)
+ ->orderBy('accounts.order', 'ASC')
+ ->orderBy('accounts.account_type_id', 'ASC')
+ ->orderBy('accounts.name', 'ASC')
+ ->with(['accountType', 'accountMeta']);
if ('' !== $query) {
// split query on spaces just in case:
$parts = explode(' ', $query);
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index 1b69b56ddc..616fd27a96 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -40,7 +40,6 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Support\Collection;
use Override;
-
use function Safe\json_encode;
/**
@@ -65,10 +64,9 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
public function countByMeta(string $field, string $value, bool $includeDeleted): int
{
$search = TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
- ->where('name', $field)
- ->where('data', json_encode($value))
- ->where('transaction_journals.user_id', $this->user->id)
- ;
+ ->where('name', $field)
+ ->where('data', json_encode($value))
+ ->where('transaction_journals.user_id', $this->user->id);
if ($includeDeleted) {
$search->withTrashed();
}
@@ -80,11 +78,10 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
public function countByNotes(string $value, bool $includeDeleted): int
{
$search = Note::query()
- ->where('noteable_type', TransactionJournal::class)
- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'notes.noteable_id')
- ->where('transaction_journals.user_id', $this->user->id)
- ->where('text', 'LIKE', sprintf('%%%s%%', $value))
- ;
+ ->where('noteable_type', TransactionJournal::class)
+ ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'notes.noteable_id')
+ ->where('transaction_journals.user_id', $this->user->id)
+ ->where('text', 'LIKE', sprintf('%%%s%%', $value));
if ($includeDeleted) {
$search->withTrashed();
}
@@ -118,10 +115,9 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
public function findByType(array $types): Collection
{
return $this->user->transactionJournals()
- ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
- ->whereIn('transaction_types.type', $types)
- ->get(['transaction_journals.*'])
- ;
+ ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
+ ->whereIn('transaction_types.type', $types)
+ ->get(['transaction_journals.*']);
}
/**
@@ -152,7 +148,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
}
/** @var null|Account $res */
- $res = $transaction->account;
+ $res = $transaction->account;
if (null === $res) {
throw new FireflyException('Account is unexpectedly NULL.');
}
@@ -165,7 +161,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
*/
public function getJournalTotal(TransactionJournal $journal): string
{
- $cache = new CacheProperties();
+ $cache = new CacheProperties();
$cache->addProperty($journal->id);
$cache->addProperty('amount-positive');
if ($cache->has()) {
@@ -174,7 +170,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
// saves on queries:
$amount = $journal->transactions()->where('amount', '>', 0)->get()->sum('amount');
- $amount = (string) $amount;
+ $amount = (string)$amount;
$cache->store($amount);
return $amount;
@@ -191,7 +187,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
/** @var null|Note $note */
$note = $link->notes()->first();
- return (string) $note?->text;
+ return (string)$note?->text;
}
/**
@@ -226,7 +222,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
}
/** @var null|Account $res */
- $res = $transaction->account;
+ $res = $transaction->account;
if (null === $res) {
throw new FireflyException('Account is unexpectedly NULL.');
}
@@ -258,7 +254,11 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
*/
public function searchJournalDescriptions(string $search, int $limit): Collection
{
- $query = $this->user->transactionJournals()->orderBy('date', 'DESC')->orderBy('description', 'ASC');
+ $query = $this->user
+ ->transactionJournals()
+ ->orderBy('date', 'DESC')
+ ->orderBy('id', 'DESC')
+ ->orderBy('description', 'ASC');
if ('' !== $search) {
$query->whereLike('description', sprintf('%%%s%%', $search));
}
diff --git a/resources/assets/v3/js/pages/shared/drag-and-droppable-rows.js b/resources/assets/v3/js/pages/shared/drag-and-droppable-rows.js
index 31246a9e4d..50f4b11623 100644
--- a/resources/assets/v3/js/pages/shared/drag-and-droppable-rows.js
+++ b/resources/assets/v3/js/pages/shared/drag-and-droppable-rows.js
@@ -67,7 +67,7 @@ export function addDrag() {
}
function getRowOrder() {
- let index = 1;
+ let index = 0;
return Array.from(tbody.querySelectorAll("tr")).map((row) => ({
id: row.getAttribute("data-id"),
order: index++,
diff --git a/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js b/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
index dd61aa8a3b..cbf0452ad7 100644
--- a/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
+++ b/resources/assets/v3/js/pages/transactions/shared/add-autocomplete.js
@@ -104,7 +104,7 @@ export function addAllAutocompleteToForm() {
account_types: filters.source,
onRenderItem: renderAccount,
suggestionsThreshold: 0,
- debounceTime: 200,
+ debounceTime: 100,
valueField: "id",
labelField: "name",
onChange: changeSourceAccount,
@@ -116,7 +116,7 @@ export function addAllAutocompleteToForm() {
valueField: "id",
labelField: "name",
suggestionsThreshold: 0,
- debounceTime: 200,
+ debounceTime: 100,
autoselectFirst: true,
account_types: filters.destination,
onRenderItem: renderAccount,
@@ -128,7 +128,7 @@ export function addAllAutocompleteToForm() {
serverUrl: urls.category,
valueField: "id",
suggestionsThreshold: 0,
- debounceTime: 200,
+ debounceTime: 100,
labelField: "name",
onChange: changeCategory,
onSelectItem: changeCategory,