mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix issue in multi year reports
This commit is contained in:
parent
69af0c3d65
commit
1a583c771b
@ -1125,4 +1125,41 @@ class GroupCollector implements GroupCollectorInterface
|
|||||||
->orderBy('transaction_journals.description', 'DESC')
|
->orderBy('transaction_journals.description', 'DESC')
|
||||||
->orderBy('source.amount', 'DESC');
|
->orderBy('source.amount', 'DESC');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Either account can be set, but NOT both. This effectively excludes internal transfers.
|
||||||
|
*
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function setXorAccounts(Collection $accounts): GroupCollectorInterface
|
||||||
|
{
|
||||||
|
if ($accounts->count() > 0) {
|
||||||
|
$accountIds = $accounts->pluck('id')->toArray();
|
||||||
|
$this->query->where(
|
||||||
|
static function (EloquentBuilder $q1) use ($accountIds) {
|
||||||
|
// sourceAccount is in the set, and destination is NOT.
|
||||||
|
|
||||||
|
$q1->where(
|
||||||
|
static function (EloquentBuilder $q2) use ($accountIds) {
|
||||||
|
$q2->whereIn('source.account_id', $accountIds);
|
||||||
|
$q2->whereNotIn('destination.account_id', $accountIds);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// destination is in the set, and source is NOT
|
||||||
|
$q1->orWhere(
|
||||||
|
static function (EloquentBuilder $q3) use ($accountIds) {
|
||||||
|
$q3->whereNotIn('source.account_id', $accountIds);
|
||||||
|
$q3->whereIn('destination.account_id', $accountIds);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
app('log')->debug(sprintf('GroupCollector: setXorAccounts: %s', implode(', ', $accountIds)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,15 @@ interface GroupCollectorInterface
|
|||||||
*/
|
*/
|
||||||
public function setAccounts(Collection $accounts): GroupCollectorInterface;
|
public function setAccounts(Collection $accounts): GroupCollectorInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Either account can be set, but NOT both. This effectively excludes internal transfers.
|
||||||
|
*
|
||||||
|
* @param Collection $accounts
|
||||||
|
*
|
||||||
|
* @return GroupCollectorInterface
|
||||||
|
*/
|
||||||
|
public function setXorAccounts(Collection $accounts): GroupCollectorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect transactions after a specific date.
|
* Collect transactions after a specific date.
|
||||||
*
|
*
|
||||||
|
@ -162,8 +162,8 @@ class ReportController extends Controller
|
|||||||
$chartData = [];
|
$chartData = [];
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setRange($start, $end)->setAccounts($accounts)
|
$collector->setRange($start, $end)->withAccountInformation();
|
||||||
->withAccountInformation();
|
$collector->setXorAccounts($accounts);
|
||||||
$journals = $collector->getExtractedJournals();
|
$journals = $collector->getExtractedJournals();
|
||||||
|
|
||||||
// loop. group by currency and by period.
|
// loop. group by currency and by period.
|
||||||
@ -186,11 +186,10 @@ class ReportController extends Controller
|
|||||||
// in our outgoing?
|
// in our outgoing?
|
||||||
$key = 'spent';
|
$key = 'spent';
|
||||||
$amount = app('steam')->positive($journal['amount']);
|
$amount = app('steam')->positive($journal['amount']);
|
||||||
if (TransactionType::DEPOSIT === $journal['transaction_type_type']
|
if (TransactionType::DEPOSIT === $journal['transaction_type_type'] ||
|
||||||
|| (TransactionType::TRANSFER === $journal['transaction_type_type']
|
(TransactionType::TRANSFER === $journal['transaction_type_type']
|
||||||
&& in_array(
|
&& in_array($journal['destination_account_id'], $ids, true)
|
||||||
$journal['destination_account_id'], $ids, true
|
)) {
|
||||||
))) {
|
|
||||||
$key = 'earned';
|
$key = 'earned';
|
||||||
}
|
}
|
||||||
$data[$currencyId][$period][$key] = bcadd($data[$currencyId][$period][$key], $amount);
|
$data[$currencyId][$period][$key] = bcadd($data[$currencyId][$period][$key], $amount);
|
||||||
|
Loading…
Reference in New Issue
Block a user