Move some code around

This commit is contained in:
James Cole
2016-11-05 10:42:31 +01:00
parent 205a593721
commit aeca2ef3b2
7 changed files with 52 additions and 123 deletions

View File

@@ -54,7 +54,8 @@ class JournalCollector
'accounts.encrypted as account_encrypted',
'account_types.type as account_type',
];
/** @var bool */
private $filterTransfers = false;
/** @var array */
private $group
= [
@@ -68,7 +69,6 @@ class JournalCollector
'bills.name',
'transactions.amount',
];
/** @var bool */
private $joinedCategory = false;
/** @var int */
@@ -127,15 +127,17 @@ class JournalCollector
$set = $this->query->get(array_values($this->fields));
// filter out transfers:
$set = $set->filter(
function (Transaction $transaction) {
if (!($transaction->transaction_type_type === TransactionType::TRANSFER && bccomp($transaction->transaction_amount, '0') === -1)) {
return $transaction;
}
if ($this->filterTransfers) {
$set = $set->filter(
function (Transaction $transaction) {
if (!($transaction->transaction_type_type === TransactionType::TRANSFER && bccomp($transaction->transaction_amount, '0') === -1)) {
return $transaction;
}
return false;
}
);
return false;
}
);
}
// loop for decryption.
$set->each(
@@ -177,6 +179,10 @@ class JournalCollector
$this->query->whereIn('transactions.account_id', $accountIds);
}
if ($accounts->count() > 1) {
$this->filterTransfers = true;
}
return $this;
}
@@ -193,6 +199,10 @@ class JournalCollector
$this->query->whereIn('transactions.account_id', $accountIds);
}
if ($accounts->count() > 1) {
$this->filterTransfers = true;
}
return $this;
}