2016-02-04 10:16:16 -06:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2016-02-04 10:16:16 -06:00
|
|
|
/**
|
|
|
|
* JournalCollector.php
|
|
|
|
* Copyright (C) 2016 Sander Dorigo
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
2016-02-18 13:01:53 -06:00
|
|
|
namespace FireflyIII\Repositories\Journal;
|
2016-02-04 10:16:16 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection
|
|
|
|
*/
|
|
|
|
public function collect()
|
|
|
|
{
|
|
|
|
// 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.*']);
|
|
|
|
}
|
|
|
|
|
2016-02-10 09:01:18 -06:00
|
|
|
}
|