mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-11 16:05:50 -06:00
Improve code for edit routine #1469
This commit is contained in:
parent
d73cd4b515
commit
0374c32236
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property string $repetition_type
|
||||
* @property string $repetition_moment
|
||||
* @property int $repetition_skip
|
||||
* @property int $repetitions
|
||||
* @property bool $active
|
||||
* @property bool $apply_rules
|
||||
* @property \FireflyIII\User $user
|
||||
|
@ -99,23 +99,24 @@ class RecurrenceTransformer extends TransformerAbstract
|
||||
{
|
||||
$this->repository->setUser($recurrence->user);
|
||||
$return = [
|
||||
'id' => (int)$recurrence->id,
|
||||
'updated_at' => $recurrence->updated_at->toAtomString(),
|
||||
'created_at' => $recurrence->created_at->toAtomString(),
|
||||
'transaction_type_id' => $recurrence->transaction_type_id,
|
||||
'transaction_type' => $recurrence->transactionType->type,
|
||||
'title' => $recurrence->title,
|
||||
'description' => $recurrence->description,
|
||||
'first_date' => $recurrence->first_date->format('Y-m-d'),
|
||||
'latest_date' => null === $recurrence->latest_date ? null : $recurrence->latest_date->format('Y-m-d'),
|
||||
'repeat_until' => null === $recurrence->repeat_until ? null : $recurrence->repeat_until->format('Y-m-d'),
|
||||
'apply_rules' => $recurrence->apply_rules,
|
||||
'active' => $recurrence->active,
|
||||
'notes' => $this->repository->getNoteText($recurrence),
|
||||
'repetitions' => [],
|
||||
'transactions' => [],
|
||||
'meta' => [],
|
||||
'links' => [
|
||||
'id' => (int)$recurrence->id,
|
||||
'updated_at' => $recurrence->updated_at->toAtomString(),
|
||||
'created_at' => $recurrence->created_at->toAtomString(),
|
||||
'transaction_type_id' => $recurrence->transaction_type_id,
|
||||
'transaction_type' => $recurrence->transactionType->type,
|
||||
'title' => $recurrence->title,
|
||||
'description' => $recurrence->description,
|
||||
'first_date' => $recurrence->first_date->format('Y-m-d'),
|
||||
'latest_date' => null === $recurrence->latest_date ? null : $recurrence->latest_date->format('Y-m-d'),
|
||||
'repeat_until' => null === $recurrence->repeat_until ? null : $recurrence->repeat_until->format('Y-m-d'),
|
||||
'apply_rules' => $recurrence->apply_rules,
|
||||
'active' => $recurrence->active,
|
||||
'repetitions' => $recurrence->repetitions,
|
||||
'notes' => $this->repository->getNoteText($recurrence),
|
||||
'recurrence_repetitions' => [],
|
||||
'transactions' => [],
|
||||
'meta' => [],
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/recurring/' . $recurrence->id,
|
||||
@ -147,7 +148,7 @@ class RecurrenceTransformer extends TransformerAbstract
|
||||
$repetitionArray['occurrences'][] = $carbon->format('Y-m-d');
|
||||
}
|
||||
|
||||
$return['repetitions'][] = $repetitionArray;
|
||||
$return['recurrence_repetitions'][] = $repetitionArray;
|
||||
}
|
||||
unset($repetitionArray);
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
{{ ExpandedForm.date('first_date',null, {helpText: trans('firefly.help_first_date')}) }}
|
||||
{{ ExpandedForm.select('repetition_type', [], null, {helpText: trans('firefly.change_date_other_options')}) }}
|
||||
{{ ExpandedForm.number('skip', 0) }}
|
||||
{{ ExpandedForm.select('repetition_end', typesOfRepetitions) }}
|
||||
{{ ExpandedForm.select('repetition_end', repetitionEnds) }}
|
||||
{{ ExpandedForm.date('repeat_until',null) }}
|
||||
{{ ExpandedForm.number('repetitions',null) }}
|
||||
|
||||
|
@ -16,13 +16,13 @@
|
||||
<h3 class="box-title">{{ 'mandatory_for_recurring'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.text('title',recurrence.title) }}
|
||||
{{ ExpandedForm.date('first_date',recurrence.first_date.format('Y-m-d'), {helpText: trans('firefly.help_first_date_no_past')}) }}
|
||||
{{ ExpandedForm.text('title',array.title) }}
|
||||
{{ ExpandedForm.date('first_date',array.first_date, {helpText: trans('firefly.help_first_date_no_past')}) }}
|
||||
{{ ExpandedForm.select('repetition_type', [], null, {helpText: trans('firefly.change_date_other_options')}) }}
|
||||
{{ ExpandedForm.number('skip', 0) }}
|
||||
{{ ExpandedForm.select('repetition_end', []) }} {#typesOfRepetitions#}
|
||||
{{ ExpandedForm.date('repeat_until',null) }}
|
||||
{{ ExpandedForm.number('repetitions',null) }}
|
||||
{{ ExpandedForm.number('skip', array.recurrence_repetitions[0].repetition_skip) }}
|
||||
{{ ExpandedForm.select('repetition_end', repetitionEnds, repetitionEnd) }}
|
||||
{{ ExpandedForm.date('repeat_until',array.repeat_until) }}
|
||||
{{ ExpandedForm.number('repetitions', array.repetitions) }}
|
||||
|
||||
{# calendar in popup #}
|
||||
<div class="form-group" id="calendar_holder">
|
||||
@ -45,11 +45,11 @@
|
||||
<h3 class="box-title">{{ 'optional_for_recurring'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.textarea('recurring_description') }}
|
||||
{{ ExpandedForm.textarea('recurring_description',array.description) }}
|
||||
|
||||
{{ ExpandedForm.checkbox('active',1) }}
|
||||
{{ ExpandedForm.checkbox('active',1, array.active) }}
|
||||
|
||||
{{ ExpandedForm.checkbox('apply_rules',1) }}
|
||||
{{ ExpandedForm.checkbox('apply_rules',1, array.apply_rules) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -80,23 +80,22 @@
|
||||
</div>
|
||||
<input type="hidden" name="transaction_type" value="">
|
||||
{# end of three buttons#}
|
||||
|
||||
{{ ExpandedForm.text('transaction_description') }}
|
||||
{{ ExpandedForm.text('transaction_description', array.transactions[0].description) }}
|
||||
{# transaction information (mandatory) #}
|
||||
{{ ExpandedForm.currencyList('transaction_currency_id', defaultCurrency.id) }}
|
||||
{{ ExpandedForm.amountNoCurrency('amount', []) }}
|
||||
{{ ExpandedForm.currencyList('transaction_currency_id', array.transactions[0].currency_id) }}
|
||||
{{ ExpandedForm.amountNoCurrency('amount', array.transactions[0].amount) }}
|
||||
|
||||
{# source account if withdrawal, or if transfer: #}
|
||||
{{ ExpandedForm.assetAccountList('source_account_id', null, {label: trans('form.asset_source_account')}) }}
|
||||
{{ ExpandedForm.assetAccountList('source_account_id', array.transactions[0].source_account_id, {label: trans('form.asset_source_account')}) }}
|
||||
|
||||
{# source account name for deposits: #}
|
||||
{{ ExpandedForm.text('source_account_name', null, {label: trans('form.revenue_account')}) }}
|
||||
{{ ExpandedForm.text('source_account_name', array.transactions[0].source_account_name, {label: trans('form.revenue_account')}) }}
|
||||
|
||||
{# destination if deposit or transfer: #}
|
||||
{{ ExpandedForm.assetAccountList('destination_account_id', null, {label: trans('form.asset_destination_account')} ) }}
|
||||
{{ ExpandedForm.assetAccountList('destination_account_id', array.transactions[0].destination_account_id, {label: trans('form.asset_destination_account')} ) }}
|
||||
|
||||
{# destination account name for withdrawals #}
|
||||
{{ ExpandedForm.text('destination_account_name', null, {label: trans('form.expense_account')}) }}
|
||||
{{ ExpandedForm.text('destination_account_name', array.transactions[0].destination_account_name, {label: trans('form.expense_account')}) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -109,25 +108,46 @@
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{# transaction information (optional) #}
|
||||
{{ ExpandedForm.currencyList('foreign_currency_id', defaultCurrency.id) }}
|
||||
{{ ExpandedForm.amountNoCurrency('foreign_amount', []) }}
|
||||
{{ ExpandedForm.currencyList('foreign_currency_id', array.transactions[0].foreign_currency_id) }}
|
||||
{{ ExpandedForm.amountNoCurrency('foreign_amount', array.transactions[0].foreign_amount) }}
|
||||
|
||||
{# BUDGET ONLY WHEN CREATING A WITHDRAWAL #}
|
||||
{% set budgetId = 0 %}
|
||||
{% set categoryName = '' %}
|
||||
{% for metaValue in array.transactions[0].meta %}
|
||||
{% if metaValue.name == 'budget_id' %}
|
||||
{% set budgetId = metaValue.value %}
|
||||
{% endif %}
|
||||
{% if metaValue.name == 'category_name' %}
|
||||
{% set categoryName = metaValue.value %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if budgets|length > 1 %}
|
||||
{{ ExpandedForm.select('budget_id', [], null) }} {#budgets#}
|
||||
{{ ExpandedForm.select('budget_id', budgets, budgetId) }} {##}
|
||||
{% else %}
|
||||
{{ ExpandedForm.select('budget_id', [], null, {helpText: trans('firefly.no_budget_pointer')}) }}
|
||||
{{ ExpandedForm.select('budget_id', budgets, budgetId, {helpText: trans('firefly.no_budget_pointer')}) }}
|
||||
{#budgets#}
|
||||
{% endif %}
|
||||
|
||||
{# CATEGORY ALWAYS #}
|
||||
{{ ExpandedForm.text('category') }}
|
||||
{{ ExpandedForm.text('category',categoryName) }}
|
||||
|
||||
{# TAGS #}
|
||||
{{ ExpandedForm.text('tags') }}
|
||||
{% set tags = '' %}
|
||||
{% set piggyBankId = 0 %}
|
||||
{% for metaValue in array.meta %}
|
||||
{% if metaValue.name == 'tags' %}
|
||||
{% set tags = metaValue.value %}
|
||||
{% endif %}
|
||||
{% if metaValue.name == 'piggy_bank_id' %}
|
||||
{% set piggyBankId = metaValue.value %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{{ ExpandedForm.text('tags', tags) }}
|
||||
|
||||
{# RELATE THIS TRANSFER TO A PIGGY BANK #}
|
||||
{{ ExpandedForm.select('piggy_bank_id', [], 0) }} {#piggies#}
|
||||
{{ ExpandedForm.piggyBankList('piggy_bank_id',piggyBankId) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -81,7 +81,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<ul>
|
||||
{% for rep in rt.repetitions %}
|
||||
{% for rep in rt.recurrence_repetitions %}
|
||||
<li>{{ rep.description }}
|
||||
{% if rep.repetition_skip == 1 %}
|
||||
({{ trans('firefly.recurring_skips_one')|lower }})
|
||||
|
Loading…
Reference in New Issue
Block a user