mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-21 09:00:07 +00:00
Migrated all code to group collector.
This commit is contained in:
@@ -71,8 +71,8 @@ class ExpenseReportController extends Controller
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $expense
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
@@ -89,7 +89,7 @@ class ExpenseReportController extends Controller
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
// return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
@@ -97,44 +97,43 @@ class ExpenseReportController extends Controller
|
||||
$chartData = [];
|
||||
$currentStart = clone $start;
|
||||
$combined = $this->combineAccounts($expense);
|
||||
|
||||
// make "all" set:
|
||||
$all = new Collection;
|
||||
foreach ($combined as $name => $combi) {
|
||||
$all = $all->merge($combi);
|
||||
foreach ($combined as $name => $combination) {
|
||||
$all = $all->merge($combination);
|
||||
}
|
||||
|
||||
// prep chart data:
|
||||
/**
|
||||
* @var string $name
|
||||
* @var Collection $combi
|
||||
* @var string $name
|
||||
* @var Collection $combination
|
||||
*/
|
||||
foreach ($combined as $name => $combi) {
|
||||
foreach ($combined as $name => $combination) {
|
||||
// first is always expense account:
|
||||
/** @var Account $exp */
|
||||
$exp = $combi->first();
|
||||
$exp = $combination->first();
|
||||
$chartData[$exp->id . '-in'] = [
|
||||
'label' => $name . ' (' . strtolower((string)trans('firefly.income')) . ')',
|
||||
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.income'))),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$exp->id . '-out'] = [
|
||||
'label' => $name . ' (' . strtolower((string)trans('firefly.expenses')) . ')',
|
||||
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.expenses'))),
|
||||
'type' => 'bar',
|
||||
'yAxisID' => 'y-axis-0',
|
||||
'entries' => [],
|
||||
];
|
||||
// total in, total out:
|
||||
$chartData[$exp->id . '-total-in'] = [
|
||||
'label' => $name . ' (' . strtolower((string)trans('firefly.sum_of_income')) . ')',
|
||||
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_income'))),
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
'entries' => [],
|
||||
];
|
||||
$chartData[$exp->id . '-total-out'] = [
|
||||
'label' => $name . ' (' . strtolower((string)trans('firefly.sum_of_expenses')) . ')',
|
||||
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_expenses'))),
|
||||
'type' => 'line',
|
||||
'fill' => false,
|
||||
'yAxisID' => 'y-axis-1',
|
||||
@@ -154,15 +153,15 @@ class ExpenseReportController extends Controller
|
||||
$income = $this->groupByName($this->getIncomeForOpposing($accounts, $all, $currentStart, $currentEnd));
|
||||
$label = $currentStart->formatLocalized($format);
|
||||
|
||||
foreach ($combined as $name => $combi) {
|
||||
foreach ($combined as $name => $combination) {
|
||||
// first is always expense account:
|
||||
/** @var Account $exp */
|
||||
$exp = $combi->first();
|
||||
$exp = $combination->first();
|
||||
$labelIn = $exp->id . '-in';
|
||||
$labelOut = $exp->id . '-out';
|
||||
$labelSumIn = $exp->id . '-total-in';
|
||||
$labelSumOut = $exp->id . '-total-out';
|
||||
$currentIncome = $income[$name] ?? '0';
|
||||
$currentIncome = bcmul($income[$name] ?? '0', '-1');
|
||||
$currentExpense = $expenses[$name] ?? '0';
|
||||
|
||||
// add to sum:
|
||||
@@ -180,6 +179,7 @@ class ExpenseReportController extends Controller
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
$currentStart->startOfDay();
|
||||
}
|
||||
// remove all empty entries to prevent cluttering:
|
||||
$newSet = [];
|
||||
|
||||
@@ -32,6 +32,7 @@ use Illuminate\Http\Response as LaravelResponse;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* TODO make sure all import methods work.
|
||||
*
|
||||
* Class IndexController
|
||||
*/
|
||||
|
||||
@@ -96,6 +96,7 @@ class ReconcileController extends Controller
|
||||
*/
|
||||
public function overview(Request $request, Account $account, Carbon $start, Carbon $end): JsonResponse
|
||||
{
|
||||
|
||||
if (AccountType::ASSET !== $account->accountType->type) {
|
||||
throw new FireflyException(sprintf('Account %s is not an asset account.', $account->name));
|
||||
}
|
||||
@@ -107,6 +108,7 @@ class ReconcileController extends Controller
|
||||
$clearedAmount = '0';
|
||||
$route = route('accounts.reconcile.submit', [$account->id, $start->format('Ymd'), $end->format('Ymd')]);
|
||||
// get sum of transaction amounts:
|
||||
// TODO these methods no longer exist:
|
||||
$transactions = $this->repository->getTransactionsById($transactionIds);
|
||||
$cleared = $this->repository->getTransactionsById($clearedIds);
|
||||
$countCleared = 0;
|
||||
|
||||
@@ -70,7 +70,7 @@ class CategoryController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
@@ -112,7 +112,7 @@ class CategoryController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$cache->store($result);
|
||||
@@ -167,7 +167,7 @@ class CategoryController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
@@ -23,9 +23,8 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers\Report;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
@@ -70,8 +69,8 @@ class ExpenseController extends Controller
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $expense
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
@@ -110,7 +109,7 @@ class ExpenseController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::budget: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$cache->store($result);
|
||||
@@ -125,8 +124,8 @@ class ExpenseController extends Controller
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $expense
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
@@ -175,7 +174,7 @@ class ExpenseController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$cache->store($result);
|
||||
@@ -189,8 +188,8 @@ class ExpenseController extends Controller
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $expense
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array|mixed|string
|
||||
*/
|
||||
@@ -227,7 +226,7 @@ class ExpenseController extends Controller
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::expenses: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$cache->store($result);
|
||||
@@ -242,8 +241,8 @@ class ExpenseController extends Controller
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $expense
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -265,22 +264,23 @@ class ExpenseController extends Controller
|
||||
$all = $all->merge($combi);
|
||||
}
|
||||
// get all expenses in period:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAccounts($accounts);
|
||||
$collector->setOpposingAccounts($all);
|
||||
$set = $collector->getTransactions();
|
||||
$sorted = $set->sortBy(
|
||||
function (Transaction $transaction) {
|
||||
return (float)$transaction->transaction_amount;
|
||||
}
|
||||
);
|
||||
$collector->setAccounts($all);
|
||||
$set = $collector->getExtractedJournals();
|
||||
|
||||
usort($set, function ($a, $b) {
|
||||
return $a['amount'] <=> $b['amount'];
|
||||
});
|
||||
|
||||
try {
|
||||
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::topExpense: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$cache->store($result);
|
||||
@@ -293,8 +293,8 @@ class ExpenseController extends Controller
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Collection $expense
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
@@ -316,22 +316,24 @@ class ExpenseController extends Controller
|
||||
$all = $all->merge($combi);
|
||||
}
|
||||
// get all expenses in period:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($accounts);
|
||||
$collector->setOpposingAccounts($all);
|
||||
$set = $collector->getTransactions();
|
||||
$sorted = $set->sortByDesc(
|
||||
function (Transaction $transaction) {
|
||||
return (float)$transaction->transaction_amount;
|
||||
}
|
||||
);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$total = $accounts->merge($all);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAccounts($total);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
usort($journals, function ($a, $b) {
|
||||
return $a['amount'] <=> $b['amount'];
|
||||
});
|
||||
|
||||
try {
|
||||
$result = view('reports.partials.top-transactions', compact('sorted'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Could not render category::topIncome: %s', $e->getMessage()));
|
||||
$result = 'An error prevented Firefly III from rendering. Apologies.';
|
||||
$result = sprintf('An error prevented Firefly III from rendering: %s. Apologies.', $e->getMessage());
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
$cache->store($result);
|
||||
|
||||
@@ -165,11 +165,12 @@ class RuleGroupController extends Controller
|
||||
/**
|
||||
* Execute the given rulegroup on a set of existing transactions.
|
||||
*
|
||||
* @param SelectTransactionsRequest $request
|
||||
* @param SelectTransactionsRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, RuleGroup $ruleGroup): RedirectResponse
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace FireflyIII\Http\Controllers\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Events\UpdatedTransactionGroup;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\TransactionViewFilter;
|
||||
use FireflyIII\Helpers\Filter\TransferFilter;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
@@ -126,10 +126,13 @@ class MassController extends Controller
|
||||
* @param Collection $journals
|
||||
*
|
||||
* @return IlluminateView
|
||||
*
|
||||
* TODO rebuild this feature.
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function edit(Collection $journals): IlluminateView
|
||||
{
|
||||
throw new FireflyException('Needs refactor');
|
||||
throw new FireflyException(sprintf('The mass-editor is not available in v%s of Firefly III. Sorry about that. It will be back soon.', config('firefly.version')));
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$subTitle = (string)trans('firefly.mass_edit_journals');
|
||||
@@ -148,8 +151,8 @@ class MassController extends Controller
|
||||
$transformer = app(TransactionTransformer::class);
|
||||
$transformer->setParameters(new ParameterBag);
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withBudgetInformation();
|
||||
$collector->setJournals($journals);
|
||||
@@ -175,7 +178,7 @@ class MassController extends Controller
|
||||
/**
|
||||
* Mass update of journals.
|
||||
*
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param JournalRepositoryInterface $repository
|
||||
*
|
||||
* @return mixed
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* SplitController.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
use FireflyIII\Events\UpdatedTransactionGroup;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\SplitJournalFormRequest;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\ModelInformation;
|
||||
use FireflyIII\Support\Http\Controllers\RequestInformation;
|
||||
use Illuminate\Http\Request;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class SplitController.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class SplitController extends Controller
|
||||
{
|
||||
use ModelInformation, RequestInformation;
|
||||
|
||||
/** @var AttachmentHelperInterface Attachment helper */
|
||||
private $attachments;
|
||||
|
||||
/** @var BudgetRepositoryInterface The budget repository */
|
||||
private $budgets;
|
||||
|
||||
/** @var CurrencyRepositoryInterface The currency repository */
|
||||
private $currencies;
|
||||
/** @var JournalRepositoryInterface Journals and transactions overview */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* SplitController constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
throw new FireflyException('Do not use me.');
|
||||
parent::__construct();
|
||||
|
||||
// some useful repositories:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->budgets = app(BudgetRepositoryInterface::class);
|
||||
$this->attachments = app(AttachmentHelperInterface::class);
|
||||
$this->currencies = app(CurrencyRepositoryInterface::class);
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
app('view')->share('mainTitleIcon', 'fa-share-alt');
|
||||
app('view')->share('title', (string)trans('firefly.split-transactions'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a split.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function edit(Request $request, TransactionJournal $journal)
|
||||
{
|
||||
throw new FireflyException('Needs refactoring');
|
||||
if ($this->isOpeningBalance($journal)) {
|
||||
return $this->redirectToAccount($journal); // @codeCoverageIgnore
|
||||
}
|
||||
// basic fields:
|
||||
$uploadSize = min(app('steam')->phpBytes(ini_get('upload_max_filesize')), app('steam')->phpBytes(ini_get('post_max_size')));
|
||||
$subTitle = (string)trans('breadcrumbs.edit_journal', ['description' => $journal->description]);
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
|
||||
// lists and collections
|
||||
$currencies = $this->currencies->get();
|
||||
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||
|
||||
// other fields
|
||||
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$preFilled = $this->arrayFromJournal($request, $journal);
|
||||
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (true !== session('transactions.edit-split.fromUpdate')) {
|
||||
$this->rememberPreviousUri('transactions.edit-split.uri');
|
||||
}
|
||||
session()->forget('transactions.edit-split.fromUpdate');
|
||||
|
||||
return view(
|
||||
'transactions.split.edit', compact(
|
||||
'subTitleIcon', 'currencies', 'optionalFields', 'preFilled', 'subTitle', 'uploadSize', 'budgets',
|
||||
'journal'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new split journal.
|
||||
*
|
||||
* @param SplitJournalFormRequest $request
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function update(SplitJournalFormRequest $request, TransactionJournal $journal)
|
||||
{
|
||||
throw new FireflyException('Needs refactoring.');
|
||||
if ($this->isOpeningBalance($journal)) {
|
||||
return $this->redirectToAccount($journal); // @codeCoverageIgnore
|
||||
}
|
||||
$data = $request->getAll();
|
||||
|
||||
// keep current bill:
|
||||
$data['bill_id'] = $journal->bill_id;
|
||||
$journal = $this->repository->update($journal, $data);
|
||||
|
||||
/** @var array $files */
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
// save attachments:
|
||||
$this->attachments->saveAttachmentsForModel($journal, $files);
|
||||
event(new UpdatedTransactionGroup($group));
|
||||
|
||||
// flash messages
|
||||
// @codeCoverageIgnoreStart
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
$type = strtolower($this->repository->getTransactionType($journal));
|
||||
session()->flash('success', (string)trans('firefly.updated_' . $type, ['description' => $journal->description]));
|
||||
app('preferences')->mark();
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (1 === (int)$request->get('return_to_edit')) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
session()->put('transactions.edit-split.fromUpdate', true);
|
||||
|
||||
return redirect(route('transactions.split.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect($this->getPreviousUri('transactions.edit-split.uri'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user