Fixed some report bugs.

This commit is contained in:
James Cole 2016-05-15 19:23:19 +02:00
parent 962965b5b7
commit 4effc95c5f
3 changed files with 11 additions and 8 deletions

View File

@ -67,8 +67,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget);
$budgetLine->setRepetition($repetition);
$expenses = $repository->spentInPeriod(new Collection([$budget]), $accounts, $repetition->startdate, $repetition->enddate);
$expenses = $repository->spentInPeriod(new Collection([$budget]), $accounts, $repetition->startdate, $repetition->enddate);
$left = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? bcadd($repetition->amount, $expenses) : '0';
$spent = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? $expenses : '0';
$overspent = bccomp(bcadd($repetition->amount, $expenses), '0') === 1 ? '0' : bcadd($expenses, $repetition->amount);

View File

@ -304,10 +304,14 @@ class BudgetRepository implements BudgetRepositoryInterface
// first collect actual transaction journals (fairly easy)
$query = $this->user
->transactionjournals()
->distinct()
->leftJoin(
'transactions as t', function (JoinClause $join) {
$join->on('t.transaction_journal_id', '=', 'transaction_journals.id')->where('amount', '<', 0);
'transactions as source', function (JoinClause $join) {
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0);
}
)
->leftJoin(
'transactions as destination', function (JoinClause $join) {
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0);
}
);
@ -316,7 +320,8 @@ class BudgetRepository implements BudgetRepositoryInterface
}
if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray();
$query->whereIn('t.account_id', $accountIds);
$set = join(', ', $accountIds);
$query->whereRaw('(source.account_id in (' . $set . ') XOR destination.account_id in (' . $set . '))');
}
if ($budgets->count() > 0) {
$budgetIds = $budgets->pluck('id')->toArray();
@ -325,7 +330,7 @@ class BudgetRepository implements BudgetRepositoryInterface
}
// that should do it:
$first = strval($query->sum('t.amount'));
$first = strval($query->sum('source.amount'));
// then collection transactions (harder)
$query = $this->user->transactions()

View File

@ -454,7 +454,6 @@ class CategoryRepository implements CategoryRepositoryInterface
// first collect actual transaction journals (fairly easy)
$query = $this->user
->transactionjournals()
->distinct()
->transactionTypes($types)
->leftJoin(
'transactions as source', function (JoinClause $join) {