This should fix a bug in split expenses.

This commit is contained in:
James Cole 2016-08-02 19:12:18 +02:00
parent 7e3f9048fe
commit 0db9852769
3 changed files with 16 additions and 4 deletions

View File

@ -197,7 +197,7 @@ class TransactionController extends Controller
*/ */
public function index(Request $request, JournalRepositoryInterface $repository, string $what) public function index(Request $request, JournalRepositoryInterface $repository, string $what)
{ {
$pageSize = Preferences::get('transactionPageSize', 50)->data; $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what); $subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
$types = config('firefly.transactionTypesByWhat.' . $what); $types = config('firefly.transactionTypesByWhat.' . $what);
$subTitle = trans('firefly.title_' . $what); $subTitle = trans('firefly.title_' . $what);
@ -274,6 +274,8 @@ class TransactionController extends Controller
// store the journal only, flash the rest. // store the journal only, flash the rest.
if ($doSplit) { if ($doSplit) {
$journal = $repository->storeJournal($journalData); $journal = $repository->storeJournal($journalData);
$journal->completed = false;
$journal->save();
// store attachments: // store attachments:
$att->saveAttachmentsForModel($journal); $att->saveAttachmentsForModel($journal);

View File

@ -568,6 +568,7 @@ class AccountRepository implements AccountRepositoryInterface
$join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0); $join->on('source.transaction_journal_id', '=', 'transaction_journals.id')->where('source.amount', '<', 0);
} }
); );
$query->leftJoin( $query->leftJoin(
'transactions as destination', function (JoinClause $join) { 'transactions as destination', function (JoinClause $join) {
$join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0); $join->on('destination.transaction_journal_id', '=', 'transaction_journals.id')->where('destination.amount', '>', 0);
@ -575,15 +576,22 @@ class AccountRepository implements AccountRepositoryInterface
); );
$query->whereIn('source.account_id', $accountIds); $query->whereIn('source.account_id', $accountIds);
$query->whereNotIn('destination.account_id', $accountIds); $query->whereNotIn('destination.account_id', $accountIds);
$query->whereNull('source.deleted_at');
$query->whereNull('destination.deleted_at');
$query->distinct();
} }
// remove group by // remove group by
$query->getQuery()->getQuery()->groups = null; $query->getQuery()->getQuery()->groups = null;
$ids = $query->get(['transaction_journals.id'])->pluck('id')->toArray();
// that should do it: $sum = $this->user->transactions()
$sum = strval($query->sum('source.amount')); ->whereIn('transaction_journal_id', $ids)
->where('amount', '<', '0')
->whereNull('transactions.deleted_at')
->sum('amount');
return $sum; return strval($sum);
} }
} }

View File

@ -144,6 +144,7 @@ class JournalRepository implements JournalRepositoryInterface
{ {
$offset = ($page - 1) * $pageSize; $offset = ($page - 1) * $pageSize;
$query = $this->user->transactionJournals()->expanded()->sortCorrectly(); $query = $this->user->transactionJournals()->expanded()->sortCorrectly();
$query->where('transaction_journals.completed', 1);
if (count($types) > 0) { if (count($types) > 0) {
$query->transactionTypes($types); $query->transactionTypes($types);
} }
@ -166,6 +167,7 @@ class JournalRepository implements JournalRepositoryInterface
public function getJournalsInRange(Collection $accounts, Carbon $start, Carbon $end): Collection public function getJournalsInRange(Collection $accounts, Carbon $start, Carbon $end): Collection
{ {
$query = $this->user->transactionJournals()->expanded()->sortCorrectly(); $query = $this->user->transactionJournals()->expanded()->sortCorrectly();
$query->where('transaction_journals.completed', 1);
$query->before($end); $query->before($end);
$query->after($start); $query->after($start);