use journal repository instead of direct calls.

This commit is contained in:
James Cole
2018-02-25 19:09:05 +01:00
parent 99983a5c8f
commit 1b304bf85e
18 changed files with 175 additions and 222 deletions

View File

@@ -43,6 +43,8 @@ use View;
*/
class BulkController extends Controller
{
/** @var JournalRepositoryInterface */
private $repository;
/**
@@ -54,6 +56,7 @@ class BulkController extends Controller
$this->middleware(
function ($request, $next) {
$this->repository = app(JournalRepositoryInterface::class);
app('view')->share('title', trans('firefly.transactions'));
app('view')->share('mainTitleIcon', 'fa-repeat');
@@ -77,8 +80,8 @@ class BulkController extends Controller
$messages = [];
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
$sources = $journal->sourceAccountList();
$destinations = $journal->destinationAccountList();
$sources = $this->repository->getJournalSourceAccounts($journal);
$destinations = $this->repository->getJournalDestinationAccounts($journal);
if ($sources->count() > 1) {
$messages[] = trans('firefly.cannot_edit_multiple_source', ['description' => $journal->description, 'id' => $journal->id]);
continue;
@@ -88,13 +91,13 @@ class BulkController extends Controller
$messages[] = trans('firefly.cannot_edit_multiple_dest', ['description' => $journal->description, 'id' => $journal->id]);
continue;
}
if (TransactionType::OPENING_BALANCE === $journal->transactionType->type) {
if (TransactionType::OPENING_BALANCE === $this->repository->getTransactionType($journal)) {
$messages[] = trans('firefly.cannot_edit_opening_balance');
continue;
}
// cannot edit reconciled transactions / journals:
if ($journal->transactions->first()->reconciled) {
if ($this->repository->isJournalReconciled($journal)) {
$messages[] = trans('firefly.cannot_edit_reconciled', ['description' => $journal->description, 'id' => $journal->id]);
continue;
}