mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Move some code around
This commit is contained in:
parent
205a593721
commit
aeca2ef3b2
@ -54,7 +54,8 @@ class JournalCollector
|
|||||||
'accounts.encrypted as account_encrypted',
|
'accounts.encrypted as account_encrypted',
|
||||||
'account_types.type as account_type',
|
'account_types.type as account_type',
|
||||||
];
|
];
|
||||||
|
/** @var bool */
|
||||||
|
private $filterTransfers = false;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $group
|
private $group
|
||||||
= [
|
= [
|
||||||
@ -68,7 +69,6 @@ class JournalCollector
|
|||||||
'bills.name',
|
'bills.name',
|
||||||
'transactions.amount',
|
'transactions.amount',
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $joinedCategory = false;
|
private $joinedCategory = false;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
@ -127,15 +127,17 @@ class JournalCollector
|
|||||||
$set = $this->query->get(array_values($this->fields));
|
$set = $this->query->get(array_values($this->fields));
|
||||||
|
|
||||||
// filter out transfers:
|
// filter out transfers:
|
||||||
$set = $set->filter(
|
if ($this->filterTransfers) {
|
||||||
function (Transaction $transaction) {
|
$set = $set->filter(
|
||||||
if (!($transaction->transaction_type_type === TransactionType::TRANSFER && bccomp($transaction->transaction_amount, '0') === -1)) {
|
function (Transaction $transaction) {
|
||||||
return $transaction;
|
if (!($transaction->transaction_type_type === TransactionType::TRANSFER && bccomp($transaction->transaction_amount, '0') === -1)) {
|
||||||
}
|
return $transaction;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// loop for decryption.
|
// loop for decryption.
|
||||||
$set->each(
|
$set->each(
|
||||||
@ -177,6 +179,10 @@ class JournalCollector
|
|||||||
$this->query->whereIn('transactions.account_id', $accountIds);
|
$this->query->whereIn('transactions.account_id', $accountIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($accounts->count() > 1) {
|
||||||
|
$this->filterTransfers = true;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +199,10 @@ class JournalCollector
|
|||||||
$this->query->whereIn('transactions.account_id', $accountIds);
|
$this->query->whereIn('transactions.account_id', $accountIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($accounts->count() > 1) {
|
||||||
|
$this->filterTransfers = true;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use ExpandedForm;
|
use ExpandedForm;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
@ -222,12 +223,12 @@ class AccountController extends Controller
|
|||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||||
$page = intval(Input::get('page'));
|
$page = intval(Input::get('page'));
|
||||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$offset = ($page - 1) * $pageSize;
|
|
||||||
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
// replace with journal collector:
|
||||||
$count = $set->count();
|
$collector = new JournalCollector(auth()->user());
|
||||||
$subSet = $set->splice($offset, $pageSize);
|
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
|
||||||
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('accounts/show/' . $account->id);
|
$journals->setPath('accounts/show/' . $account->id);
|
||||||
|
|
||||||
// grouped other months thing:
|
// grouped other months thing:
|
||||||
@ -290,12 +291,12 @@ class AccountController extends Controller
|
|||||||
$subTitle = $account->name . ' (' . Navigation::periodShow($start, $range) . ')';
|
$subTitle = $account->name . ' (' . Navigation::periodShow($start, $range) . ')';
|
||||||
$page = intval(Input::get('page'));
|
$page = intval(Input::get('page'));
|
||||||
$page = $page === 0 ? 1 : $page;
|
$page = $page === 0 ? 1 : $page;
|
||||||
$pageSize = Preferences::get('transactionPageSize', 50)->data;
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$offset = ($page - 1) * $pageSize;
|
|
||||||
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
// replace with journal collector:
|
||||||
$count = $set->count();
|
$collector = new JournalCollector(auth()->user());
|
||||||
$subSet = $set->splice($offset, $pageSize);
|
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
|
||||||
$journals = new LengthAwarePaginator($subSet, $count, $pageSize, $page);
|
$journals = $collector->getPaginatedJournals();
|
||||||
$journals->setPath('accounts/show/' . $account->id . '/' . $date);
|
$journals->setPath('accounts/show/' . $account->id . '/' . $date);
|
||||||
|
|
||||||
return view('accounts.show_with_date', compact('category', 'date', 'account', 'journals', 'subTitle', 'carbon'));
|
return view('accounts.show_with_date', compact('category', 'date', 'account', 'journals', 'subTitle', 'carbon'));
|
||||||
|
@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
use Artisan;
|
use Artisan;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
use FireflyIII\Models\Tag;
|
use FireflyIII\Models\Tag;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
|
||||||
@ -116,11 +117,10 @@ class HomeController extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ARI $repository
|
* @param ARI $repository
|
||||||
* @param AccountTaskerInterface $tasker
|
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function index(ARI $repository, AccountTaskerInterface $tasker)
|
public function index(ARI $repository)
|
||||||
{
|
{
|
||||||
|
|
||||||
$types = config('firefly.accountTypesByIdentifier.asset');
|
$types = config('firefly.accountTypesByIdentifier.asset');
|
||||||
@ -144,8 +144,9 @@ class HomeController extends Controller
|
|||||||
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$set = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
$collector = new JournalCollector(auth()->user());
|
||||||
$set = $set->splice(0, 10);
|
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit(10)->setPage(1);
|
||||||
|
$set = $collector->getJournals();
|
||||||
|
|
||||||
if (count($set) > 0) {
|
if (count($set) > 0) {
|
||||||
$transactions[] = [$set, $account];
|
$transactions[] = [$set, $account];
|
||||||
|
@ -197,14 +197,14 @@ class ReportController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function expenseEntry(array $attributes): string
|
private function expenseEntry(array $attributes): string
|
||||||
{
|
{
|
||||||
/** @var AccountTaskerInterface $tasker */
|
|
||||||
$tasker = app(AccountTaskerInterface::class);
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
|
||||||
$account = $repository->find(intval($attributes['accountId']));
|
$account = $repository->find(intval($attributes['accountId']));
|
||||||
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
$types = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
$journals = $tasker->getJournalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
|
$collector = new JournalCollector(auth()->user());
|
||||||
|
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])->setTypes($types);
|
||||||
|
$journals = $collector->getJournals();
|
||||||
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
||||||
|
|
||||||
// filter for transfers and withdrawals TO the given $account
|
// filter for transfers and withdrawals TO the given $account
|
||||||
@ -233,13 +233,13 @@ class ReportController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function incomeEntry(array $attributes): string
|
private function incomeEntry(array $attributes): string
|
||||||
{
|
{
|
||||||
/** @var AccountTaskerInterface $tasker */
|
|
||||||
$tasker = app(AccountTaskerInterface::class);
|
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app(AccountRepositoryInterface::class);
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
$account = $repository->find(intval($attributes['accountId']));
|
$account = $repository->find(intval($attributes['accountId']));
|
||||||
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
$types = [TransactionType::DEPOSIT, TransactionType::TRANSFER];
|
||||||
$journals = $tasker->getJournalsInPeriod(new Collection([$account]), $types, $attributes['startDate'], $attributes['endDate']);
|
$collector = new JournalCollector(auth()->user());
|
||||||
|
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])->setTypes($types);
|
||||||
|
$journals = $collector->getJournals();
|
||||||
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
||||||
|
|
||||||
// filter the set so the destinations outside of $attributes['accounts'] are not included.
|
// filter the set so the destinations outside of $attributes['accounts'] are not included.
|
||||||
|
@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||||
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
use FireflyIII\Helpers\Report\ReportHelperInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
use FireflyIII\Models\AccountType;
|
||||||
@ -150,8 +151,6 @@ class ReportController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function auditReport(Carbon $start, Carbon $end, Collection $accounts)
|
private function auditReport(Carbon $start, Carbon $end, Collection $accounts)
|
||||||
{
|
{
|
||||||
/** @var AccountTaskerInterface $tasker */
|
|
||||||
$tasker = app(AccountTaskerInterface::class);
|
|
||||||
$auditData = [];
|
$auditData = [];
|
||||||
$dayBefore = clone $start;
|
$dayBefore = clone $start;
|
||||||
$dayBefore->subDay();
|
$dayBefore->subDay();
|
||||||
@ -160,9 +159,11 @@ class ReportController extends Controller
|
|||||||
// balance the day before:
|
// balance the day before:
|
||||||
$id = $account->id;
|
$id = $account->id;
|
||||||
$dayBeforeBalance = Steam::balance($account, $dayBefore);
|
$dayBeforeBalance = Steam::balance($account, $dayBefore);
|
||||||
$journals = $tasker->getJournalsInPeriod(new Collection([$account]), [], $start, $end);
|
$collector = new JournalCollector(auth()->user());
|
||||||
$journals = $journals->reverse();
|
$collector->setAccounts(new Collection([$account]))->setRange($start, $end);
|
||||||
$startBalance = $dayBeforeBalance;
|
$journals = $collector->getJournals();
|
||||||
|
$journals = $journals->reverse();
|
||||||
|
$startBalance = $dayBeforeBalance;
|
||||||
|
|
||||||
|
|
||||||
/** @var Transaction $journal */
|
/** @var Transaction $journal */
|
||||||
@ -246,7 +247,6 @@ class ReportController extends Controller
|
|||||||
// need all years.
|
// need all years.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// and some id's, joined:
|
// and some id's, joined:
|
||||||
$accountIds = [];
|
$accountIds = [];
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
|
@ -190,77 +190,6 @@ class AccountTasker implements AccountTaskerInterface
|
|||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* It might be worth it to expand this query to include all account information required.
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param array $types
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getJournalsInPeriod(Collection $accounts, array $types, Carbon $start, Carbon $end): Collection
|
|
||||||
{
|
|
||||||
$accountIds = $accounts->pluck('id')->toArray();
|
|
||||||
$query = Transaction
|
|
||||||
::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
|
||||||
->leftJoin('transaction_currencies', 'transaction_currencies.id', 'transaction_journals.transaction_currency_id')
|
|
||||||
->leftJoin('transaction_types', 'transaction_types.id', 'transaction_journals.transaction_type_id')
|
|
||||||
->leftJoin('bills', 'bills.id', 'transaction_journals.bill_id')
|
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
|
||||||
->leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
|
||||||
->whereIn('transactions.account_id', $accountIds)
|
|
||||||
->whereNull('transactions.deleted_at')
|
|
||||||
->whereNull('transaction_journals.deleted_at')
|
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
|
||||||
->where('transaction_journals.user_id', $this->user->id)
|
|
||||||
->orderBy('transaction_journals.date', 'DESC')
|
|
||||||
->orderBy('transaction_journals.order', 'ASC')
|
|
||||||
->orderBy('transaction_journals.id', 'DESC');
|
|
||||||
|
|
||||||
if (count($types) > 0) {
|
|
||||||
$query->whereIn('transaction_types.type', $types);
|
|
||||||
}
|
|
||||||
|
|
||||||
$set = $query->get(
|
|
||||||
[
|
|
||||||
'transaction_journals.id as journal_id',
|
|
||||||
'transaction_journals.description',
|
|
||||||
'transaction_journals.date',
|
|
||||||
'transaction_journals.encrypted',
|
|
||||||
//'transaction_journals.transaction_currency_id',
|
|
||||||
'transaction_currencies.code as transaction_currency_code',
|
|
||||||
//'transaction_currencies.symbol as transaction_currency_symbol',
|
|
||||||
'transaction_types.type as transaction_type_type',
|
|
||||||
'transaction_journals.bill_id',
|
|
||||||
'bills.name as bill_name',
|
|
||||||
'transactions.id as id',
|
|
||||||
'transactions.amount as transaction_amount',
|
|
||||||
'transactions.description as transaction_description',
|
|
||||||
'transactions.account_id',
|
|
||||||
'transactions.identifier',
|
|
||||||
'transactions.transaction_journal_id',
|
|
||||||
'accounts.name as account_name',
|
|
||||||
'accounts.encrypted as account_encrypted',
|
|
||||||
'account_types.type as account_type',
|
|
||||||
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
// loop for decryption.
|
|
||||||
$set->each(
|
|
||||||
function (Transaction $transaction) {
|
|
||||||
$transaction->date = new Carbon($transaction->date);
|
|
||||||
$transaction->description = intval($transaction->encrypted) === 1 ? Crypt::decrypt($transaction->description) : $transaction->description;
|
|
||||||
$transaction->bill_name = !is_null($transaction->bill_name) ? Crypt::decrypt($transaction->bill_name) : '';
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $set;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param Collection $excluded
|
* @param Collection $excluded
|
||||||
|
@ -71,18 +71,6 @@ interface AccountTaskerInterface
|
|||||||
*/
|
*/
|
||||||
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts): AccountCollection;
|
public function getAccountReport(Carbon $start, Carbon $end, Collection $accounts): AccountCollection;
|
||||||
|
|
||||||
/**
|
|
||||||
* Experimental getJournals method.
|
|
||||||
*
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param array $types
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getJournalsInPeriod(Collection $accounts, array $types, Carbon $start, Carbon $end): Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Collection $accounts
|
* @param Collection $accounts
|
||||||
* @param Collection $excluded
|
* @param Collection $excluded
|
||||||
|
Loading…
Reference in New Issue
Block a user