Small adjustments to fix tests.

This commit is contained in:
James Cole
2018-02-23 16:21:28 +01:00
parent d804093f8b
commit 6591fa9fb4
13 changed files with 192 additions and 41 deletions

View File

@@ -61,13 +61,13 @@ class AccountRepository implements AccountRepositoryInterface
* Moved here from account CRUD.
*
* @param Account $account
* @param Account $moveTo
* @param Account|null $moveTo
*
* @return bool
*
* @throws \Exception
*/
public function destroy(Account $account, Account $moveTo): bool
public function destroy(Account $account, ?Account $moveTo): bool
{
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);

View File

@@ -48,11 +48,11 @@ interface AccountRepositoryInterface
* Moved here from account CRUD.
*
* @param Account $account
* @param Account $moveTo
* @param Account|null $moveTo
*
* @return bool
*/
public function destroy(Account $account, Account $moveTo): bool;
public function destroy(Account $account, ?Account $moveTo): bool;
/**
* @param int $accountId

View File

@@ -106,8 +106,8 @@ class BillRepository implements BillRepositoryInterface
/** @var Collection $set */
$set = $this->user->bills()
->where('active', 1)
->sortBy('name')
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),])
->sortBy('name');
return $set;
}

View File

@@ -195,6 +195,18 @@ class JournalRepository implements JournalRepositoryInterface
return null;
}
/**
* Get account of transaction that is more than zero. Only works with unsplit journals.
*
* @param TransactionJournal $journal
*
* @return Account
*/
public function getDestinationAccount(TransactionJournal $journal): Account
{
return $journal->transactions()->where('amount', '<', 0)->first()->account;
}
/**
* @param TransactionJournal $journal
*
@@ -205,6 +217,18 @@ class JournalRepository implements JournalRepositoryInterface
return $journal->notes()->first();
}
/**
* Get account of transaction that is less than zero. Only works with unsplit journals.
*
* @param TransactionJournal $journal
*
* @return Account
*/
public function getSourceAccount(TransactionJournal $journal): Account
{
return $journal->transactions()->where('amount', '>', 0)->first()->account;
}
/**
* @return Collection
*/
@@ -318,26 +342,55 @@ class JournalRepository implements JournalRepositoryInterface
}
/**
* Get account of transaction that is more than zero. Only works with unsplit journals.
* Update budget for a journal.
*
* @param TransactionJournal $journal
* @param int $budgetId
*
* @return Account
* @return TransactionJournal
*/
public function getDestinationAccount(TransactionJournal $journal): Account
public function updateBudget(TransactionJournal $journal, int $budgetId): TransactionJournal
{
return $journal->transactions()->where('amount','<',0)->first()->account;
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->setUser($this->user);
return $service->updateBudget($journal, $budgetId);
}
/**
* Get account of transaction that is less than zero. Only works with unsplit journals.
* Update category for a journal.
*
* @param TransactionJournal $journal
* @param string $category
*
* @return Account
* @return TransactionJournal
*/
public function getSourceAccount(TransactionJournal $journal): Account
public function updateCategory(TransactionJournal $journal, string $category): TransactionJournal
{
return $journal->transactions()->where('amount','>',0)->first()->account;
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->setUser($this->user);
return $service->updateCategory($journal, $category);
}
/**
* Update tag(s) for a journal.
*
* @param TransactionJournal $journal
* @param array $tags
*
* @return TransactionJournal
*/
public function updateTags(TransactionJournal $journal, array $tags): TransactionJournal
{
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service->setUser($this->user);
$service->connectTags($journal, $tags);
return $journal;
}
}

View File

@@ -171,4 +171,34 @@ interface JournalRepositoryInterface
* @return TransactionJournal
*/
public function update(TransactionJournal $journal, array $data): TransactionJournal;
/**
* Update budget for a journal.
*
* @param TransactionJournal $journal
* @param int $budgetId
*
* @return TransactionJournal
*/
public function updateBudget(TransactionJournal $journal, int $budgetId): TransactionJournal;
/**
* Update category for a journal.
*
* @param TransactionJournal $journal
* @param string $category
*
* @return TransactionJournal
*/
public function updateCategory(TransactionJournal $journal, string $category): TransactionJournal;
/**
* Update tag(s) for a journal.
*
* @param TransactionJournal $journal
* @param array $tags
*
* @return TransactionJournal
*/
public function updateTags(TransactionJournal $journal, array $tags): TransactionJournal;
}