mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
Remove journal collector.
This commit is contained in:
parent
c66df3cb2c
commit
b80db054e2
@ -10,12 +10,11 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace FireflyIII\Export;
|
namespace FireflyIII\Export;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Export\Entry\Entry;
|
use FireflyIII\Export\Entry\Entry;
|
||||||
use FireflyIII\Models\ExportJob;
|
use FireflyIII\Models\ExportJob;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Journal\JournalCollector;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use Illuminate\Filesystem\FilesystemAdapter;
|
use Illuminate\Filesystem\FilesystemAdapter;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@ -91,10 +90,10 @@ class Processor
|
|||||||
*/
|
*/
|
||||||
public function collectJournals(): bool
|
public function collectJournals(): bool
|
||||||
{
|
{
|
||||||
$args = [$this->accounts, Auth::user(), $this->settings['startDate'], $this->settings['endDate']];
|
/** @var JournalRepositoryInterface $repository */
|
||||||
/** @var JournalCollector $journalCollector */
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
$journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args);
|
$this->journals = $repository->getJournalsInRange($this->accounts, $this->settings['startDate'], $this->settings['endDate']);
|
||||||
$this->journals = $journalCollector->collect();
|
|
||||||
Log::debug(
|
Log::debug(
|
||||||
'Collected ' .
|
'Collected ' .
|
||||||
$this->journals->count() . ' journals (between ' .
|
$this->journals->count() . ' journals (between ' .
|
||||||
|
@ -4,6 +4,7 @@ namespace FireflyIII\Jobs;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\RuleGroup;
|
use FireflyIII\Models\RuleGroup;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Rules\Processor;
|
use FireflyIII\Rules\Processor;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -143,10 +144,10 @@ class ExecuteRuleGroupOnExistingTransactions extends Job implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
protected function collectJournals()
|
protected function collectJournals()
|
||||||
{
|
{
|
||||||
$args = [$this->accounts, $this->user, $this->startDate, $this->endDate];
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$journalCollector = app('FireflyIII\Repositories\Journal\JournalCollector', $args);
|
$repository = app(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
return $journalCollector->collect();
|
return $repository->getJournalsInRange($this->accounts, $this->startDate, $this->endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types = 1);
|
|
||||||
/**
|
|
||||||
* JournalCollector.php
|
|
||||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This software may be modified and distributed under the terms
|
|
||||||
* of the MIT license. See the LICENSE file for details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace FireflyIII\Repositories\Journal;
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
|
||||||
use FireflyIII\User;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class JournalCollector
|
|
||||||
*
|
|
||||||
* @package FireflyIII\Export\Collector
|
|
||||||
*/
|
|
||||||
class JournalCollector
|
|
||||||
{
|
|
||||||
/** @var Collection */
|
|
||||||
private $accounts;
|
|
||||||
/** @var Carbon */
|
|
||||||
private $end;
|
|
||||||
/** @var Carbon */
|
|
||||||
private $start;
|
|
||||||
/** @var User */
|
|
||||||
private $user;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JournalCollector constructor.
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param User $user
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*/
|
|
||||||
public function __construct(Collection $accounts, User $user, Carbon $start, Carbon $end)
|
|
||||||
{
|
|
||||||
$this->accounts = $accounts;
|
|
||||||
$this->user = $user;
|
|
||||||
$this->start = $start;
|
|
||||||
$this->end = $end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function collect(): Collection
|
|
||||||
{
|
|
||||||
// get all the journals:
|
|
||||||
$ids = $this->accounts->pluck('id')->toArray();
|
|
||||||
|
|
||||||
return $this->user->transactionjournals()
|
|
||||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
|
||||||
->whereIn('transactions.account_id', $ids)
|
|
||||||
->before($this->end)
|
|
||||||
->after($this->start)
|
|
||||||
->orderBy('transaction_journals.date')
|
|
||||||
->get(['transaction_journals.*']);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -15,6 +15,7 @@ use FireflyIII\Models\Transaction;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@ -134,6 +135,36 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
return $journals;
|
return $journals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a collection of ALL journals, given a specific account and a date range.
|
||||||
|
*
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getJournalsInRange(Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||||
|
{
|
||||||
|
$query = $this->user->transactionJournals()->expanded();
|
||||||
|
$query->before($end);
|
||||||
|
$query->after($start);
|
||||||
|
|
||||||
|
if ($accounts->count() > 0) {
|
||||||
|
$ids = $accounts->pluck('id')->toArray();
|
||||||
|
$query->where(
|
||||||
|
function (Builder $q) use ($ids) {
|
||||||
|
$q->whereIn('destination.account_id', $ids);
|
||||||
|
$q->orWhereIn('source.account_id', $ids);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$set = $query->get(TransactionJournal::queryFields());
|
||||||
|
|
||||||
|
return $set;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
|
@ -6,7 +6,6 @@ namespace FireflyIII\Repositories\Journal;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
@ -55,6 +54,8 @@ interface JournalRepositoryInterface
|
|||||||
public function getAmountBefore(TransactionJournal $journal, Transaction $transaction): string;
|
public function getAmountBefore(TransactionJournal $journal, Transaction $transaction): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns a page of a specific type(s) of journal.
|
||||||
|
*
|
||||||
* @param array $types
|
* @param array $types
|
||||||
* @param int $page
|
* @param int $page
|
||||||
* @param int $pageSize
|
* @param int $pageSize
|
||||||
@ -63,6 +64,17 @@ interface JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getJournals(array $types, int $page, int $pageSize = 50): LengthAwarePaginator;
|
public function getJournals(array $types, int $page, int $pageSize = 50): LengthAwarePaginator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a collection of ALL journals, given a specific account and a date range.
|
||||||
|
*
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getJournalsInRange(Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user