mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 12:11:19 +00:00
Various code cleanup and sorting.
This commit is contained in:
@@ -47,10 +47,9 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface, UserGroupIn
|
||||
public function findTransaction(int $transactionId): ?Transaction
|
||||
{
|
||||
return Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('transactions.id', $transactionId)
|
||||
->first(['transactions.*'])
|
||||
;
|
||||
->where('transaction_journals.user_id', $this->user->id)
|
||||
->where('transactions.id', $transactionId)
|
||||
->first(['transactions.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +59,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface, UserGroupIn
|
||||
*/
|
||||
public function getAttachments(TransactionJournal $journal): Collection
|
||||
{
|
||||
$set = $journal->attachments;
|
||||
$set = $journal->attachments;
|
||||
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
|
@@ -32,6 +32,7 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
|
||||
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class JournalCLIRepository
|
||||
@@ -46,10 +47,9 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
public function getAllJournals(array $types): Collection
|
||||
{
|
||||
return TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->whereIn('transaction_types.type', $types)
|
||||
->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account'])
|
||||
->get(['transaction_journals.*'])
|
||||
;
|
||||
->whereIn('transaction_types.type', $types)
|
||||
->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account'])
|
||||
->get(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,7 +57,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
*/
|
||||
public function getJournalBudgetId(TransactionJournal $journal): int
|
||||
{
|
||||
$budget = $journal->budgets()->first();
|
||||
$budget = $journal->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
return $budget->id;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
*/
|
||||
public function getJournalCategoryId(TransactionJournal $journal): int
|
||||
{
|
||||
$category = $journal->categories()->first();
|
||||
$category = $journal->categories()->first();
|
||||
if (null !== $category) {
|
||||
return $category->id;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
*/
|
||||
public function getMetaField(TransactionJournal $journal, string $field): ?string
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('journal-meta-updated');
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty($field);
|
||||
@@ -138,12 +138,12 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
if (null === $entry) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = $entry->data;
|
||||
$value = $entry->data;
|
||||
|
||||
if (is_array($value)) {
|
||||
$return = implode(',', $value);
|
||||
@@ -179,12 +179,11 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
public function getSplitJournals(): Collection
|
||||
{
|
||||
$query = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->groupBy('transaction_journals.id')
|
||||
;
|
||||
->groupBy('transaction_journals.id');
|
||||
$result = $query->get(['transaction_journals.id as id', DB::raw('count(transactions.id) as transaction_count')]); // @phpstan-ignore-line
|
||||
$journalIds = [];
|
||||
|
||||
/** @var \stdClass $row */
|
||||
/** @var stdClass $row */
|
||||
foreach ($result as $row) {
|
||||
if ((int) $row->transaction_count > 2) {
|
||||
$journalIds[] = (int) $row->id;
|
||||
@@ -193,8 +192,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface, UserGroupIn
|
||||
$journalIds = array_unique($journalIds);
|
||||
|
||||
return TransactionJournal::with(['transactions'])
|
||||
->whereIn('id', $journalIds)->get()
|
||||
;
|
||||
->whereIn('id', $journalIds)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -67,8 +67,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
->transactionJournals()
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->whereIn('transaction_types.type', $types)
|
||||
->get(['transaction_journals.*'])
|
||||
;
|
||||
->get(['transaction_journals.*']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +101,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()) {
|
||||
@@ -151,8 +150,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
return new Carbon($cache->get());
|
||||
}
|
||||
$entry = TransactionJournalMeta::where('transaction_journal_id', $journalId)
|
||||
->where('name', $field)->first()
|
||||
;
|
||||
->where('name', $field)->first();
|
||||
if (null === $entry) {
|
||||
return null;
|
||||
}
|
||||
@@ -195,8 +193,7 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
|
||||
public function searchJournalDescriptions(string $search, int $limit): Collection
|
||||
{
|
||||
$query = $this->user->transactionJournals()
|
||||
->orderBy('date', 'DESC')
|
||||
;
|
||||
->orderBy('date', 'DESC');
|
||||
if ('' !== $search) {
|
||||
$query->whereLike('description', sprintf('%%%s%%', $search));
|
||||
}
|
||||
|
Reference in New Issue
Block a user