mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Improve factories and tests.
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionJournalFactory;
|
||||
@@ -320,6 +321,28 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getJournalCategoryId(TransactionJournal $journal): int
|
||||
{
|
||||
$category = $journal->categories()->first();
|
||||
if (null !== $category) {
|
||||
return $category->id;
|
||||
}
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$category = $journal->transactions()->first()->categories()->first();
|
||||
if (null !== $category) {
|
||||
return $category->id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the category linked to the journal (if any) or to the transactions (if any).
|
||||
*
|
||||
@@ -615,6 +638,27 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return $transaction->transactionJournal->piggyBankEvents()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all journals with more than 2 transactions. Should only return empty collections
|
||||
* in Firefly III > v4.8.0.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getSplitJournals(): Collection
|
||||
{
|
||||
// grab all split transactions:
|
||||
$all = Transaction::groupBy('transaction_journal_id')->get(['transaction_journal_id', DB::raw('COUNT(transaction_journal_id) as result')]);
|
||||
/** @var Collection $filtered */
|
||||
$filtered = $all->filter(
|
||||
function (Transaction $transaction) {
|
||||
return (int)$transaction->result > 2;
|
||||
}
|
||||
);
|
||||
$journalIds = array_unique($filtered->pluck('transaction_journal_id')->toArray());
|
||||
|
||||
return TransactionJournal::whereIn('id', $journalIds)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all tags as strings in an array.
|
||||
*
|
||||
|
@@ -149,6 +149,15 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function getJournalBudgetId(TransactionJournal $journal): int;
|
||||
|
||||
/**
|
||||
* Return the ID of the category linked to the journal (if any) or to the transactions (if any).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getJournalCategoryId(TransactionJournal $journal): int;
|
||||
|
||||
/**
|
||||
* Return the name of the category linked to the journal (if any) or to the transactions (if any).
|
||||
*
|
||||
@@ -256,6 +265,14 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function getPiggyBankEventsbyTr(Transaction $transaction): Collection;
|
||||
|
||||
/**
|
||||
* Returns all journals with more than 2 transactions. Should only return empty collections
|
||||
* in Firefly III > v4.8.0.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getSplitJournals(): Collection;
|
||||
|
||||
/**
|
||||
* Return all tags as strings in an array.
|
||||
*
|
||||
|
Reference in New Issue
Block a user