Fix query.

This commit is contained in:
James Cole 2015-12-12 20:10:52 +01:00
parent 9bd1503cb4
commit a985e09282

View File

@ -191,14 +191,14 @@ class ReportQuery implements ReportQueryInterface
{
return Auth::user()->transactionjournals()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->transactionTypes([TransactionType::WITHDRAWAL])
->where('transactions.account_id', $account->id)
->before($end)
->after($start)
->where('budget_transaction_journal.budget_id', $budget->id)
->get(['transaction_journals.*'])->sum('amount');
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->transactionTypes([TransactionType::WITHDRAWAL])
->where('transactions.account_id', $account->id)
->before($end)
->after($start)
->where('budget_transaction_journal.budget_id', $budget->id)
->get(['transaction_journals.*'])->sum('amount');
}
/**
@ -288,7 +288,6 @@ class ReportQuery implements ReportQueryInterface
// OR is a transfer from NOT a shared account to a shared account.
$query->where(
function (Builder $query) {
$query->where(
@ -367,28 +366,20 @@ class ReportQuery implements ReportQueryInterface
$query = $this->queryJournalsWithTransactions($start, $end);
// withdrawals from any account are an expense.
// transfers away, to an account not in the list, are an expense.
$query->where(
function (Builder $query) {
function (Builder $query) use ($ids) {
$query->where(
function (Builder $q) { // only get withdrawals from any account:
function (Builder $q) {
$q->where('transaction_types.type', TransactionType::WITHDRAWAL);
//$q->where('acm_from.data', '!=', '"sharedAsset"');
}
);
$query->orWhere(
function (Builder $q) { // and transfers from a shared account to a not-shared account.
function (Builder $q) use ($ids) {
$q->where('transaction_types.type', TransactionType::TRANSFER);
$q->where('acm_to.data', '=', '"sharedAsset"');
$q->where('acm_from.data', '!=', '"sharedAsset"');
}
);
// OR transfers from a NOT shared account to a shared account.
$query->orWhere(
function (Builder $q) { // and transfers from a shared account to a not-shared account.
$q->where('transaction_types.type', TransactionType::TRANSFER);
$q->where('acm_to.data', '!=', '"sharedAsset"');
$q->where('acm_from.data', '=', '"sharedAsset"');
$q->whereNotIn('ac_to.id', $ids);
}
);
}