mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-16 22:58:09 +00:00
Code cleanup that (hopefully) matches style CI
This commit is contained in:
@@ -29,7 +29,9 @@ use FireflyIII\Http\Requests\BulkEditJournalRequest;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -43,6 +45,7 @@ class BulkController extends Controller
|
||||
|
||||
/**
|
||||
* BulkController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -52,7 +55,7 @@ class BulkController extends Controller
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||
|
||||
return $next($request);
|
||||
@@ -67,11 +70,11 @@ class BulkController extends Controller
|
||||
*
|
||||
* @param Collection $journals
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function edit(array $journals)
|
||||
{
|
||||
$subTitle = (string)trans('firefly.mass_bulk_journals');
|
||||
$subTitle = (string) trans('firefly.mass_bulk_journals');
|
||||
|
||||
$this->rememberPreviousUri('transactions.bulk-edit.uri');
|
||||
|
||||
@@ -97,13 +100,13 @@ class BulkController extends Controller
|
||||
{
|
||||
$journalIds = $request->get('journals');
|
||||
$journalIds = is_array($journalIds) ? $journalIds : [];
|
||||
$ignoreCategory = 1 === (int)$request->get('ignore_category');
|
||||
$ignoreBudget = 1 === (int)$request->get('ignore_budget');
|
||||
$ignoreTags = 1 === (int)$request->get('ignore_tags');
|
||||
$ignoreCategory = 1 === (int) $request->get('ignore_category');
|
||||
$ignoreBudget = 1 === (int) $request->get('ignore_budget');
|
||||
$ignoreTags = 1 === (int) $request->get('ignore_tags');
|
||||
$count = 0;
|
||||
|
||||
foreach ($journalIds as $journalId) {
|
||||
$journalId = (int)$journalId;
|
||||
$journalId = (int) $journalId;
|
||||
$journal = $this->repository->findNull($journalId);
|
||||
if (null !== $journal) {
|
||||
$resultA = $this->updateJournalBudget($journal, $ignoreBudget, $request->integer('budget_id'));
|
||||
@@ -115,7 +118,7 @@ class BulkController extends Controller
|
||||
}
|
||||
}
|
||||
app('preferences')->mark();
|
||||
$request->session()->flash('success', (string)trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
||||
$request->session()->flash('success', (string) trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
||||
|
||||
// redirect to previous URL:
|
||||
return redirect($this->getPreviousUri('transactions.bulk-edit.uri'));
|
||||
@@ -123,26 +126,27 @@ class BulkController extends Controller
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param bool $ignoreUpdate
|
||||
* @param array $tags
|
||||
* @param bool $ignoreUpdate
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function updateJournalTags(TransactionJournal $journal, bool $ignoreUpdate, array $tags): bool
|
||||
private function updateJournalBudget(TransactionJournal $journal, bool $ignoreUpdate, int $budgetId): bool
|
||||
{
|
||||
|
||||
if (true === $ignoreUpdate) {
|
||||
return false;
|
||||
}
|
||||
Log::debug(sprintf('Set tags to %s', implode(',', $tags)));
|
||||
$this->repository->updateTags($journal, $tags);
|
||||
Log::debug(sprintf('Set budget to %d', $budgetId));
|
||||
$this->repository->updateBudget($journal, $budgetId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param bool $ignoreUpdate
|
||||
* @param string $category
|
||||
* @param bool $ignoreUpdate
|
||||
* @param string $category
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function updateJournalCategory(TransactionJournal $journal, bool $ignoreUpdate, string $category): bool
|
||||
@@ -158,17 +162,19 @@ class BulkController extends Controller
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param bool $ignoreUpdate
|
||||
* @param int $budgetId
|
||||
* @param bool $ignoreUpdate
|
||||
* @param array $tags
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function updateJournalBudget(TransactionJournal $journal, bool $ignoreUpdate, int $budgetId): bool
|
||||
private function updateJournalTags(TransactionJournal $journal, bool $ignoreUpdate, array $tags): bool
|
||||
{
|
||||
|
||||
if (true === $ignoreUpdate) {
|
||||
return false;
|
||||
}
|
||||
Log::debug(sprintf('Set budget to %d', $budgetId));
|
||||
$this->repository->updateBudget($journal, $budgetId);
|
||||
Log::debug(sprintf('Set tags to %s', implode(',', $tags)));
|
||||
$this->repository->updateTags($journal, $tags);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Events\UpdatedTransactionGroup;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
@@ -38,11 +39,12 @@ use FireflyIII\Support\Http\Controllers\ModelInformation;
|
||||
use FireflyIII\Support\Http\Controllers\UserNavigation;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use FireflyIII\Validation\AccountValidator;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Log;
|
||||
use View;
|
||||
|
||||
|
||||
/**
|
||||
* Class ConvertController.
|
||||
*
|
||||
@@ -57,6 +59,7 @@ class ConvertController extends Controller
|
||||
|
||||
/**
|
||||
* ConvertController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -68,7 +71,7 @@ class ConvertController extends Controller
|
||||
function ($request, $next) {
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||
|
||||
return $next($request);
|
||||
@@ -80,11 +83,11 @@ class ConvertController extends Controller
|
||||
/**
|
||||
* Show overview of a to be converted transaction.
|
||||
*
|
||||
* @param TransactionType $destinationType
|
||||
* @param TransactionType $destinationType
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
* @return RedirectResponse|Redirector|View
|
||||
*/
|
||||
public function index(TransactionType $destinationType, TransactionGroup $group)
|
||||
{
|
||||
@@ -101,7 +104,7 @@ class ConvertController extends Controller
|
||||
|
||||
$groupTitle = $group->title ?? $first->description;
|
||||
$groupArray = $transformer->transformObject($group);
|
||||
$subTitle = (string)trans('firefly.convert_to_' . $destinationType->type, ['description' => $groupTitle]);
|
||||
$subTitle = (string) trans('firefly.convert_to_' . $destinationType->type, ['description' => $groupTitle]);
|
||||
$subTitleIcon = 'fa-exchange';
|
||||
|
||||
// get a list of asset accounts and liabilities and stuff, in various combinations:
|
||||
@@ -117,31 +120,40 @@ class ConvertController extends Controller
|
||||
|
||||
if ($sourceType->type === $destinationType->type) { // cannot convert to its own type.
|
||||
Log::debug('This is already a transaction of the expected type..');
|
||||
session()->flash('info', (string)trans('firefly.convert_is_already_type_' . $destinationType->type));
|
||||
session()->flash('info', (string) trans('firefly.convert_is_already_type_' . $destinationType->type));
|
||||
|
||||
return redirect(route('transactions.show', [$group->id]));
|
||||
}
|
||||
|
||||
return view(
|
||||
'transactions.convert', compact(
|
||||
'sourceType', 'destinationType',
|
||||
'group', 'groupTitle', 'groupArray', 'assets', 'validDepositSources', 'liabilities',
|
||||
'validWithdrawalDests', 'preFilled',
|
||||
'subTitle', 'subTitleIcon'
|
||||
)
|
||||
'transactions.convert',
|
||||
compact(
|
||||
'sourceType',
|
||||
'destinationType',
|
||||
'group',
|
||||
'groupTitle',
|
||||
'groupArray',
|
||||
'assets',
|
||||
'validDepositSources',
|
||||
'liabilities',
|
||||
'validWithdrawalDests',
|
||||
'preFilled',
|
||||
'subTitle',
|
||||
'subTitleIcon'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the conversion.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TransactionType $destinationType
|
||||
* @param Request $request
|
||||
* @param TransactionType $destinationType
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return RedirectResponse|Redirector
|
||||
*
|
||||
*/
|
||||
public function postIndex(Request $request, TransactionType $destinationType, TransactionGroup $group)
|
||||
{
|
||||
@@ -165,156 +177,19 @@ class ConvertController extends Controller
|
||||
$group->refresh();
|
||||
$this->correctTransfer($group);
|
||||
|
||||
session()->flash('success', (string)trans('firefly.converted_to_' . $destinationType->type));
|
||||
session()->flash('success', (string) trans('firefly.converted_to_' . $destinationType->type));
|
||||
event(new UpdatedTransactionGroup($group));
|
||||
|
||||
return redirect(route('transactions.show', [$group->id]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getAssetAccounts(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$accountList = $repository->getActiveAccountsByType([AccountType::ASSET]);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$balance = app('steam')->balance($account, new Carbon);
|
||||
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$role = (string)$repository->getMetaValue($account, 'account_role');
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$key = (string)trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getLiabilities(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$accountList = $repository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$balance = app('steam')->balance($account, new Carbon);
|
||||
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$role = 'l_' . $account->accountType->type;
|
||||
$key = (string)trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getValidDepositSources(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||
$accountList = $repository
|
||||
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$role = (string)$repository->getMetaValue($account, 'account_role');
|
||||
$name = $account->name;
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// maybe it's a liability thing:
|
||||
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
||||
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
||||
}
|
||||
if (AccountType::CASH === $account->accountType->type) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$role = 'cash_account';
|
||||
$name = sprintf('(%s)', trans('firefly.cash'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if (AccountType::REVENUE === $account->accountType->type) {
|
||||
$role = 'revenue_account'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$key = (string)trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $name;
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getValidWithdrawalDests(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||
$accountList = $repository
|
||||
->getActiveAccountsByType([AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$role = (string)$repository->getMetaValue($account, 'account_role');
|
||||
$name = $account->name;
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// maybe it's a liability thing:
|
||||
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
||||
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
||||
}
|
||||
if (AccountType::CASH === $account->accountType->type) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$role = 'cash_account';
|
||||
$name = sprintf('(%s)', trans('firefly.cash'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if (AccountType::EXPENSE === $account->accountType->type) {
|
||||
$role = 'expense_account'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$key = (string)trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $name;
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionType $transactionType
|
||||
* @param array $data
|
||||
* @return TransactionJournal
|
||||
* @param TransactionType $transactionType
|
||||
* @param array $data
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
private function convertJournal(TransactionJournal $journal, TransactionType $transactionType, array $data): TransactionJournal
|
||||
{
|
||||
@@ -329,9 +204,9 @@ class ConvertController extends Controller
|
||||
$destinationName = $data['destination_name'][$journal->id] ?? null;
|
||||
|
||||
// double check its not an empty string.
|
||||
$sourceId = '' === $sourceId || null === $sourceId ? null : (int)$sourceId;
|
||||
$sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId;
|
||||
$sourceName = '' === $sourceName ? null : $sourceName;
|
||||
$destinationId = '' === $destinationId || null === $destinationId ? null : (int)$destinationId;
|
||||
$destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId;
|
||||
$destinationName = '' === $destinationName ? null : $destinationName;
|
||||
$validSource = $validator->validateSource($sourceId, $sourceName);
|
||||
$validDestination = $validator->validateDestination($destinationId, $destinationName);
|
||||
@@ -366,4 +241,142 @@ class ConvertController extends Controller
|
||||
private function correctTransfer(TransactionGroup $group): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @return array
|
||||
*/
|
||||
private function getAssetAccounts(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$accountList = $repository->getActiveAccountsByType([AccountType::ASSET]);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$balance = app('steam')->balance($account, new Carbon);
|
||||
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$role = (string) $repository->getMetaValue($account, 'account_role');
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$key = (string) trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @return array
|
||||
*/
|
||||
private function getLiabilities(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$accountList = $repository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$balance = app('steam')->balance($account, new Carbon);
|
||||
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$role = 'l_' . $account->accountType->type;
|
||||
$key = (string) trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getValidDepositSources(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||
$accountList = $repository
|
||||
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$role = (string) $repository->getMetaValue($account, 'account_role');
|
||||
$name = $account->name;
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// maybe it's a liability thing:
|
||||
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
||||
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
||||
}
|
||||
if (AccountType::CASH === $account->accountType->type) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$role = 'cash_account';
|
||||
$name = sprintf('(%s)', trans('firefly.cash'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if (AccountType::REVENUE === $account->accountType->type) {
|
||||
$role = 'revenue_account'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$key = (string) trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $name;
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getValidWithdrawalDests(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||
$accountList = $repository
|
||||
->getActiveAccountsByType([AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$role = (string) $repository->getMetaValue($account, 'account_role');
|
||||
$name = $account->name;
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// maybe it's a liability thing:
|
||||
if (in_array($account->accountType->type, $liabilityTypes, true)) {
|
||||
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
||||
}
|
||||
if (AccountType::CASH === $account->accountType->type) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$role = 'cash_account';
|
||||
$name = sprintf('(%s)', trans('firefly.cash'));
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
if (AccountType::EXPENSE === $account->accountType->type) {
|
||||
$role = 'expense_account'; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$key = (string) trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $name;
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Update\GroupCloneService;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* Class CreateController
|
||||
@@ -49,8 +52,7 @@ class CreateController extends Controller
|
||||
app('view')->share('uploadSize', $uploadSize);
|
||||
$this->middleware(
|
||||
static function ($request, $next) {
|
||||
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||
|
||||
return $next($request);
|
||||
@@ -61,7 +63,7 @@ class CreateController extends Controller
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function cloneGroup(TransactionGroup $group)
|
||||
{
|
||||
@@ -84,20 +86,20 @@ class CreateController extends Controller
|
||||
*
|
||||
* @param string|null objectType
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function create(?string $objectType)
|
||||
{
|
||||
app('preferences')->mark();
|
||||
|
||||
$sourceId = (int)request()->get('source');
|
||||
$destinationId = (int)request()->get('destination');
|
||||
$sourceId = (int) request()->get('source');
|
||||
$destinationId = (int) request()->get('destination');
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$cash = $repository->getCashAccount();
|
||||
$preFilled = session()->has('preFilled') ? session('preFilled') : [];
|
||||
$subTitle = (string)trans('breadcrumbs.create_new_transaction');
|
||||
$subTitle = (string) trans('breadcrumbs.create_new_transaction');
|
||||
$subTitleIcon = 'fa-plus';
|
||||
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
|
||||
$allowedOpposingTypes = config('firefly.allowed_opposing_types');
|
||||
@@ -112,11 +114,21 @@ class CreateController extends Controller
|
||||
|
||||
|
||||
return view(
|
||||
'transactions.create', compact(
|
||||
'subTitleIcon', 'cash', 'objectType', 'subTitle', 'defaultCurrency', 'previousUri', 'optionalFields', 'preFilled',
|
||||
'allowedOpposingTypes',
|
||||
'accountToTypes','sourceId','destinationId'
|
||||
)
|
||||
'transactions.create',
|
||||
compact(
|
||||
'subTitleIcon',
|
||||
'cash',
|
||||
'objectType',
|
||||
'subTitle',
|
||||
'defaultCurrency',
|
||||
'previousUri',
|
||||
'optionalFields',
|
||||
'preFilled',
|
||||
'allowedOpposingTypes',
|
||||
'accountToTypes',
|
||||
'sourceId',
|
||||
'destinationId'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\UserNavigation;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Log;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use URL;
|
||||
@@ -45,6 +45,7 @@ class DeleteController extends Controller
|
||||
|
||||
/**
|
||||
* IndexController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -54,7 +55,7 @@ class DeleteController extends Controller
|
||||
// translations:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||
|
||||
$this->repository = app(TransactionGroupRepositoryInterface::class);
|
||||
@@ -69,7 +70,7 @@ class DeleteController extends Controller
|
||||
*
|
||||
* @param TransactionGroup $group
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
* @return RedirectResponse|Redirector|View
|
||||
*/
|
||||
public function delete(TransactionGroup $group)
|
||||
{
|
||||
@@ -84,7 +85,7 @@ class DeleteController extends Controller
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
$objectType = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||
$subTitle = (string)trans('firefly.delete_' . $objectType, ['description' => $group->title ?? $journal->description]);
|
||||
$subTitle = (string) trans('firefly.delete_' . $objectType, ['description' => $group->title ?? $journal->description]);
|
||||
$previous = URL::previous(route('index'));
|
||||
// put previous url in session
|
||||
Log::debug('Will try to remember previous URI');
|
||||
@@ -111,7 +112,7 @@ class DeleteController extends Controller
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
$objectType = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
|
||||
session()->flash('success', (string)trans('firefly.deleted_' . strtolower($objectType), ['description' => $group->title ?? $journal->description]));
|
||||
session()->flash('success', (string) trans('firefly.deleted_' . strtolower($objectType), ['description' => $group->title ?? $journal->description]));
|
||||
|
||||
$this->repository->destroy($group);
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\UserNavigation;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* Class EditController
|
||||
@@ -35,8 +37,10 @@ use FireflyIII\Support\Http\Controllers\UserNavigation;
|
||||
class EditController extends Controller
|
||||
{
|
||||
use UserNavigation;
|
||||
|
||||
/**
|
||||
* EditController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -54,7 +58,7 @@ class EditController extends Controller
|
||||
$this->middleware(
|
||||
static function ($request, $next) {
|
||||
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||
|
||||
return $next($request);
|
||||
@@ -65,7 +69,8 @@ class EditController extends Controller
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function edit(TransactionGroup $transactionGroup)
|
||||
{
|
||||
|
||||
@@ -25,11 +25,14 @@ namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* Class IndexController
|
||||
@@ -43,6 +46,7 @@ class IndexController extends Controller
|
||||
|
||||
/**
|
||||
* IndexController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -53,7 +57,7 @@ class IndexController extends Controller
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', (string)trans('firefly.accounts'));
|
||||
app('view')->share('title', (string) trans('firefly.accounts'));
|
||||
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
|
||||
@@ -65,20 +69,20 @@ class IndexController extends Controller
|
||||
/**
|
||||
* Index for a range of transactions.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $objectType
|
||||
* @param Request $request
|
||||
* @param string $objectType
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function index(Request $request, string $objectType, Carbon $start = null, Carbon $end = null)
|
||||
{
|
||||
$subTitleIcon = config('firefly.transactionIconsByType.' . $objectType);
|
||||
$types = config('firefly.transactionTypesByType.' . $objectType);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$page = (int) $request->get('page');
|
||||
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
||||
if (null === $start) {
|
||||
$start = session('start');
|
||||
$end = session('end');
|
||||
@@ -91,7 +95,7 @@ class IndexController extends Controller
|
||||
$path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||
$startStr = $start->formatLocalized($this->monthAndDayFormat);
|
||||
$endStr = $end->formatLocalized($this->monthAndDayFormat);
|
||||
$subTitle = (string)trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
|
||||
$subTitle = (string) trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
|
||||
|
||||
$firstJournal = $this->repository->firstNull();
|
||||
$startPeriod = null === $firstJournal ? new Carbon : $firstJournal->date;
|
||||
@@ -119,9 +123,10 @@ class IndexController extends Controller
|
||||
* Index for ALL transactions.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $objectType
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Exception
|
||||
* @param string $objectType
|
||||
*
|
||||
* @throws Exception
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function indexAll(Request $request, string $objectType)
|
||||
{
|
||||
@@ -131,13 +136,13 @@ class IndexController extends Controller
|
||||
|
||||
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $objectType);
|
||||
$types = config('firefly.transactionTypesByWhat.' . $objectType);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$page = (int) $request->get('page');
|
||||
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
||||
$path = route('transactions.index.all', [$objectType]);
|
||||
$first = $repository->firstNull();
|
||||
$start = null === $first ? new Carbon : $first->date;
|
||||
$end = new Carbon;
|
||||
$subTitle = (string)trans('firefly.all_' . $objectType);
|
||||
$subTitle = (string) trans('firefly.all_' . $objectType);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
@@ -29,6 +29,8 @@ use FireflyIII\Models\TransactionJournalLink;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
use URL;
|
||||
@@ -45,6 +47,7 @@ class LinkController extends Controller
|
||||
|
||||
/**
|
||||
* LinkController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -53,7 +56,7 @@ class LinkController extends Controller
|
||||
// some useful repositories:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||
|
||||
$this->journalRepository = app(JournalRepositoryInterface::class);
|
||||
@@ -64,17 +67,6 @@ class LinkController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function modal(TransactionJournal $journal)
|
||||
{
|
||||
$linkTypes = $this->repository->get();
|
||||
|
||||
return view('transactions.links.modal', compact('journal', 'linkTypes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a link.
|
||||
*
|
||||
@@ -85,7 +77,7 @@ class LinkController extends Controller
|
||||
public function delete(TransactionJournalLink $link)
|
||||
{
|
||||
$subTitleIcon = 'fa-link';
|
||||
$subTitle = (string)trans('breadcrumbs.delete_journal_link');
|
||||
$subTitle = (string) trans('breadcrumbs.delete_journal_link');
|
||||
$this->rememberPreviousUri('journal_links.delete.uri');
|
||||
|
||||
return view('transactions.links.delete', compact('link', 'subTitle', 'subTitleIcon'));
|
||||
@@ -96,16 +88,28 @@ class LinkController extends Controller
|
||||
*
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function destroy(TransactionJournalLink $link)
|
||||
{
|
||||
$this->repository->destroyLink($link);
|
||||
|
||||
session()->flash('success', (string)trans('firefly.deleted_link'));
|
||||
session()->flash('success', (string) trans('firefly.deleted_link'));
|
||||
app('preferences')->mark();
|
||||
|
||||
return redirect((string)session('journal_links.delete.uri'));
|
||||
return redirect((string) session('journal_links.delete.uri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function modal(TransactionJournal $journal)
|
||||
{
|
||||
$linkTypes = $this->repository->get();
|
||||
|
||||
return view('transactions.links.modal', compact('journal', 'linkTypes'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,16 +118,16 @@ class LinkController extends Controller
|
||||
* @param JournalLinkRequest $request
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function store(JournalLinkRequest $request, TransactionJournal $journal)
|
||||
{
|
||||
$linkInfo = $request->getLinkInfo();
|
||||
|
||||
Log::debug('We are here (store)');
|
||||
$other = $this->journalRepository->findNull($linkInfo['transaction_journal_id']);
|
||||
$other = $this->journalRepository->findNull($linkInfo['transaction_journal_id']);
|
||||
if (null === $other) {
|
||||
session()->flash('error', (string)trans('firefly.invalid_link_selection'));
|
||||
session()->flash('error', (string) trans('firefly.invalid_link_selection'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->transaction_group_id]));
|
||||
}
|
||||
@@ -131,19 +135,19 @@ class LinkController extends Controller
|
||||
$alreadyLinked = $this->repository->findLink($journal, $other);
|
||||
|
||||
if ($other->id === $journal->id) {
|
||||
session()->flash('error', (string)trans('firefly.journals_link_to_self'));
|
||||
session()->flash('error', (string) trans('firefly.journals_link_to_self'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->transaction_group_id]));
|
||||
}
|
||||
|
||||
if ($alreadyLinked) {
|
||||
session()->flash('error', (string)trans('firefly.journals_error_linked'));
|
||||
session()->flash('error', (string) trans('firefly.journals_error_linked'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->transaction_group_id]));
|
||||
}
|
||||
Log::debug(sprintf('Journal is %d, opposing is %d', $journal->id, $other->id));
|
||||
$this->repository->storeLink($linkInfo, $other, $journal);
|
||||
session()->flash('success', (string)trans('firefly.journals_linked'));
|
||||
session()->flash('success', (string) trans('firefly.journals_linked'));
|
||||
|
||||
return redirect(route('transactions.show', [$journal->transaction_group_id]));
|
||||
}
|
||||
@@ -153,7 +157,7 @@ class LinkController extends Controller
|
||||
*
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function switchLink(TransactionJournalLink $link)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Services\Internal\Update\JournalUpdateService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\View\View as IlluminateView;
|
||||
use InvalidArgumentException;
|
||||
use Log;
|
||||
@@ -50,6 +52,7 @@ class MassController extends Controller
|
||||
|
||||
/**
|
||||
* MassController constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct()
|
||||
@@ -58,9 +61,10 @@ class MassController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-repeat');
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
@@ -75,7 +79,7 @@ class MassController extends Controller
|
||||
*/
|
||||
public function delete(array $journals): IlluminateView
|
||||
{
|
||||
$subTitle = (string)trans('firefly.mass_delete_journals');
|
||||
$subTitle = (string) trans('firefly.mass_delete_journals');
|
||||
|
||||
// put previous url in session
|
||||
$this->rememberPreviousUri('transactions.mass-delete.uri');
|
||||
@@ -100,8 +104,8 @@ class MassController extends Controller
|
||||
foreach ($ids as $journalId) {
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->repository->findNull((int)$journalId);
|
||||
if (null !== $journal && (int)$journalId === $journal->id) {
|
||||
$journal = $this->repository->findNull((int) $journalId);
|
||||
if (null !== $journal && (int) $journalId === $journal->id) {
|
||||
$this->repository->destroyJournal($journal);
|
||||
++$count;
|
||||
}
|
||||
@@ -110,7 +114,7 @@ class MassController extends Controller
|
||||
|
||||
|
||||
app('preferences')->mark();
|
||||
session()->flash('success', (string)trans('firefly.mass_deleted_transactions_success', ['amount' => $count]));
|
||||
session()->flash('success', (string) trans('firefly.mass_deleted_transactions_success', ['amount' => $count]));
|
||||
|
||||
// redirect to previous URL:
|
||||
return redirect($this->getPreviousUri('transactions.mass-delete.uri'));
|
||||
@@ -125,7 +129,7 @@ class MassController extends Controller
|
||||
*/
|
||||
public function edit(array $journals): IlluminateView
|
||||
{
|
||||
$subTitle = (string)trans('firefly.mass_edit_journals');
|
||||
$subTitle = (string) trans('firefly.mass_edit_journals');
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
@@ -158,8 +162,9 @@ class MassController extends Controller
|
||||
* Mass update of journals.
|
||||
*
|
||||
* @param MassEditJournalRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return RedirectResponse|Redirector
|
||||
*/
|
||||
public function update(MassEditJournalRequest $request)
|
||||
{
|
||||
@@ -171,7 +176,7 @@ class MassController extends Controller
|
||||
$count = 0;
|
||||
/** @var string $journalId */
|
||||
foreach ($journalIds as $journalId) {
|
||||
$integer = (int)$journalId;
|
||||
$integer = (int) $journalId;
|
||||
try {
|
||||
$this->updateJournal($integer, $request);
|
||||
$count++;
|
||||
@@ -183,15 +188,86 @@ class MassController extends Controller
|
||||
}
|
||||
|
||||
app('preferences')->mark();
|
||||
session()->flash('success', (string)trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
||||
session()->flash('success', (string) trans('firefly.mass_edited_transactions_success', ['amount' => $count]));
|
||||
|
||||
// redirect to previous URL:
|
||||
return redirect($this->getPreviousUri('transactions.mass-edit.uri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $journalId
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param int $journalId
|
||||
* @param string $string
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getDateFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?Carbon
|
||||
{
|
||||
$value = $request->get($string);
|
||||
if (!is_array($value)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($value[$journalId])) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$carbon = Carbon::parse($value[$journalId]);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$e->getMessage();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $carbon;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param int $journalId
|
||||
* @param string $string
|
||||
*
|
||||
* @return int|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getIntFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?int
|
||||
{
|
||||
$value = $request->get($string);
|
||||
if (!is_array($value)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($value[$journalId])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $value[$journalId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param int $journalId
|
||||
* @param string $string
|
||||
*
|
||||
* @return string|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getStringFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?string
|
||||
{
|
||||
$value = $request->get($string);
|
||||
if (!is_array($value)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($value[$journalId])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string) $value[$journalId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $journalId
|
||||
* @param MassEditJournalRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function updateJournal(int $journalId, MassEditJournalRequest $request): void
|
||||
@@ -224,71 +300,4 @@ class MassController extends Controller
|
||||
// trigger rules
|
||||
event(new UpdatedTransactionGroup($journal->transactionGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param int $journalId
|
||||
* @param string $string
|
||||
* @return int|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getIntFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?int
|
||||
{
|
||||
$value = $request->get($string);
|
||||
if (!is_array($value)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($value[$journalId])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int)$value[$journalId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param int $journalId
|
||||
* @param string $string
|
||||
* @return string|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getStringFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?string
|
||||
{
|
||||
$value = $request->get($string);
|
||||
if (!is_array($value)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($value[$journalId])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (string)$value[$journalId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MassEditJournalRequest $request
|
||||
* @param int $journalId
|
||||
* @param string $string
|
||||
* @return Carbon|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function getDateFromRequest(MassEditJournalRequest $request, int $journalId, string $string): ?Carbon
|
||||
{
|
||||
$value = $request->get($string);
|
||||
if (!is_array($value)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($value[$journalId])) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$carbon = Carbon::parse($value[$journalId]);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
$e->getMessage();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $carbon;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,11 @@ use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
@@ -53,7 +56,7 @@ class ShowController extends Controller
|
||||
function ($request, $next) {
|
||||
$this->repository = app(TransactionGroupRepositoryInterface::class);
|
||||
|
||||
app('view')->share('title', (string)trans('firefly.transactions'));
|
||||
app('view')->share('title', (string) trans('firefly.transactions'));
|
||||
app('view')->share('mainTitleIcon', 'fa-exchange');
|
||||
|
||||
return $next($request);
|
||||
@@ -64,7 +67,7 @@ class ShowController extends Controller
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function debugShow(TransactionGroup $transactionGroup)
|
||||
{
|
||||
@@ -74,14 +77,14 @@ class ShowController extends Controller
|
||||
/**
|
||||
* @param TransactionGroup $transactionGroup
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws FireflyException
|
||||
* @return Factory|View
|
||||
*/
|
||||
public function show(Request $request, TransactionGroup $transactionGroup)
|
||||
{
|
||||
/** @var TransactionJournal $first */
|
||||
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
|
||||
$splits = $transactionGroup->transactionJournals()->count();
|
||||
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
|
||||
$splits = $transactionGroup->transactionJournals()->count();
|
||||
|
||||
if (null === $first) {
|
||||
throw new FireflyException('This transaction is broken :(.');
|
||||
|
||||
Reference in New Issue
Block a user