mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 08:11:20 +00:00
Improve code for edit routine #1469
This commit is contained in:
@@ -71,6 +71,7 @@ class CreateController extends Controller
|
||||
*/
|
||||
public function create(Request $request)
|
||||
{
|
||||
// todo create expandedform thing.
|
||||
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$tomorrow = new Carbon;
|
||||
@@ -83,8 +84,8 @@ class CreateController extends Controller
|
||||
}
|
||||
$request->session()->forget('recurring.create.fromStore');
|
||||
|
||||
// types of repetitions:
|
||||
$typesOfRepetitions = [
|
||||
// when will it end?
|
||||
$repetitionEnds = [
|
||||
'forever' => trans('firefly.repeat_forever'),
|
||||
'until_date' => trans('firefly.repeat_until_date'),
|
||||
'times' => trans('firefly.repeat_times'),
|
||||
@@ -99,7 +100,7 @@ class CreateController extends Controller
|
||||
];
|
||||
$request->session()->flash('preFilled', $preFilled);
|
||||
|
||||
return view('recurring.create', compact('tomorrow', 'oldRepetitionType', 'preFilled', 'piggies', 'typesOfRepetitions', 'defaultCurrency', 'budgets'));
|
||||
return view('recurring.create', compact('tomorrow', 'oldRepetitionType', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -27,7 +27,11 @@ namespace FireflyIII\Http\Controllers\Recurring;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Recurrence;
|
||||
use FireflyIII\Models\RecurrenceRepetition;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use FireflyIII\Transformers\RecurrenceTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -35,6 +39,8 @@ use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
*/
|
||||
class EditController extends Controller
|
||||
{
|
||||
/** @var BudgetRepositoryInterface */
|
||||
private $budgets;
|
||||
/** @var RecurringRepositoryInterface */
|
||||
private $recurring;
|
||||
|
||||
@@ -53,6 +59,7 @@ class EditController extends Controller
|
||||
app('view')->share('subTitle', trans('firefly.recurrences'));
|
||||
|
||||
$this->recurring = app(RecurringRepositoryInterface::class);
|
||||
$this->budgets = app(BudgetRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
@@ -60,24 +67,52 @@ class EditController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function edit(Recurrence $recurrence)
|
||||
public function edit(Request $request, Recurrence $recurrence)
|
||||
{
|
||||
// use transformer:
|
||||
$transformer = new RecurrenceTransformer(new ParameterBag);
|
||||
$array = $transformer->transform($recurrence);
|
||||
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||
|
||||
// get recurrence type:
|
||||
// todo move to repository
|
||||
// todo handle old repetition type as well.
|
||||
|
||||
|
||||
/** @var RecurrenceRepetition $repetition */
|
||||
$repetition = $recurrence->recurrenceRepetitions()->first();
|
||||
$currentRepetitionType = $repetition->repetition_type;
|
||||
if ('' !== $repetition->repetition_moment) {
|
||||
$currentRepetitionType .= ',' . $repetition->repetition_moment;
|
||||
}
|
||||
// assume repeats forever:
|
||||
$repetitionEnd = 'forever';
|
||||
// types of repetitions:
|
||||
$repetitionEnds = [
|
||||
'forever' => trans('firefly.repeat_forever'),
|
||||
'until_date' => trans('firefly.repeat_until_date'),
|
||||
'times' => trans('firefly.repeat_times'),
|
||||
];
|
||||
if (null !== $recurrence->repeat_until) {
|
||||
$repetitionEnd = 'until_date';
|
||||
}
|
||||
if ($recurrence->repetitions > 0) {
|
||||
$repetitionEnd = 'times';
|
||||
}
|
||||
|
||||
// todo handle old repetition type as well.
|
||||
// flash some data:
|
||||
$preFilled = [
|
||||
'transaction_type' => strtolower($recurrence->transactionType->type),
|
||||
];
|
||||
$request->flash('preFilled', $preFilled);
|
||||
|
||||
return view('recurring.edit', compact('recurrence','currentRepetitionType'));
|
||||
return view('recurring.edit', compact('recurrence', 'array','budgets', 'preFilled', 'currentRepetitionType', 'repetitionEnd', 'repetitionEnds'));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -189,9 +189,9 @@ class IndexController extends Controller
|
||||
$array = $transformer->transform($recurrence);
|
||||
|
||||
// transform dates back to Carbon objects:
|
||||
foreach ($array['repetitions'] as $index => $repetition) {
|
||||
foreach ($array['recurrence_repetitions'] as $index => $repetition) {
|
||||
foreach ($repetition['occurrences'] as $item => $occurrence) {
|
||||
$array['repetitions'][$index]['occurrences'][$item] = new Carbon($occurrence);
|
||||
$array['recurrence_repetitions'][$index]['occurrences'][$item] = new Carbon($occurrence);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user