mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix #3435
This commit is contained in:
@@ -29,6 +29,8 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\RecurrenceFormRequest;
|
||||
use FireflyIII\Models\RecurrenceRepetition;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
@@ -75,6 +77,97 @@ class CreateController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
public function createFromJournal(Request $request, TransactionJournal $journal)
|
||||
{
|
||||
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$tomorrow = new Carbon;
|
||||
$oldRepetitionType = $request->old('repetition_type');
|
||||
$tomorrow->addDay();
|
||||
|
||||
// put previous url in session if not redirect from store (not "create another").
|
||||
if (true !== session('recurring.create.fromStore')) {
|
||||
$this->rememberPreviousUri('recurring.create.uri');
|
||||
}
|
||||
$request->session()->forget('recurring.create.fromStore');
|
||||
$repetitionEnds = [
|
||||
'forever' => (string) trans('firefly.repeat_forever'),
|
||||
'until_date' => (string) trans('firefly.repeat_until_date'),
|
||||
'times' => (string) trans('firefly.repeat_times'),
|
||||
];
|
||||
$weekendResponses = [
|
||||
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'),
|
||||
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'),
|
||||
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'),
|
||||
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'),
|
||||
];
|
||||
|
||||
/** @var Transaction $source */
|
||||
/** @var Transaction $dest */
|
||||
|
||||
// fill prefilled with journal info
|
||||
$type = strtolower($journal->transactionType->type);
|
||||
|
||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$dest = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$category = $journal->categories()->first() ? $journal->categories()->first()->name : '';
|
||||
$budget = $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;
|
||||
$hasOldInput = null !== $request->old('_token'); // flash some data
|
||||
$preFilled = [];
|
||||
if (true === $hasOldInput) {
|
||||
$preFilled = [
|
||||
'title' => $request->old('title'),
|
||||
'transaction_description' => $request->old('description'),
|
||||
'transaction_currency_id' => $request->old('transaction_currency_id'),
|
||||
'amount' => $request->old('amount'),
|
||||
'foreign_currency_id' => $request->old('foreign_currency_id'),
|
||||
'foreign_amount' => $request->old('foreign_amount'),
|
||||
'source_id' => $request->old('source_id'),
|
||||
'deposit_source_id' => $request->old('deposit_source_id'),
|
||||
'destination_id' => $request->old('destination_id'),
|
||||
'withdrawal_destination_id' => $request->old('withdrawal_destination_id'),
|
||||
'first_date' => $request->old('first_date'),
|
||||
'transaction_type' => $request->old('transaction_type'),
|
||||
'category' => $request->old('category'),
|
||||
'budget_id' => $request->old('budget_id'),
|
||||
'active' => (bool) $request->old('active'),
|
||||
'apply_rules' => (bool) $request->old('apply_rules'),
|
||||
];
|
||||
}
|
||||
if (false === $hasOldInput) {
|
||||
$preFilled = [
|
||||
'title' => $journal->description,
|
||||
'transaction_description' => $journal->description,
|
||||
'transaction_currency_id' => $journal->transaction_currency_id,
|
||||
'amount' => $dest->amount,
|
||||
'foreign_currency_id' => $dest->foreign_currency_id,
|
||||
'foreign_amount' => $dest->foreign_amount,
|
||||
'source_id' => $source->account_id,
|
||||
'deposit_source_id' => $source->account_id,
|
||||
'destination_id' => $dest->account_id,
|
||||
'withdrawal_destination_id' => $dest->account_id,
|
||||
'first_date' => $tomorrow->format('Y-m-d'),
|
||||
'transaction_type' => $type,
|
||||
'category' => $category,
|
||||
'budget_id' => $budget,
|
||||
'active' => true,
|
||||
'apply_rules' => true,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$request->session()->flash('preFilled', $preFilled);
|
||||
|
||||
return view(
|
||||
'recurring.create',
|
||||
compact('tomorrow', 'oldRepetitionType', 'weekendResponses', 'preFilled', 'repetitionEnds', 'defaultCurrency', 'budgets')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new recurring transaction.
|
||||
*
|
||||
|
@@ -555,6 +555,7 @@ return [
|
||||
'select_tags_to_delete' => 'Don\'t forget to select some tags.',
|
||||
'deleted_x_tags' => 'Deleted :count tag.|Deleted :count tags.',
|
||||
'create_rule_from_transaction' => 'Create rule based on transaction',
|
||||
'create_recurring_from_transaction' => 'Create recurring transaction based on transaction',
|
||||
|
||||
|
||||
// preferences
|
||||
|
@@ -87,7 +87,7 @@
|
||||
{{ ExpandedForm.text('transaction_description') }}
|
||||
{# transaction information (mandatory) #}
|
||||
{{ CurrencyForm.currencyList('transaction_currency_id', defaultCurrency.id) }}
|
||||
{{ ExpandedForm.amountNoCurrency('amount', []) }}
|
||||
{{ ExpandedForm.amountNoCurrency('amount') }}
|
||||
|
||||
{# source account if withdrawal, or if transfer: #}
|
||||
{{ AccountForm.activeLongAccountList('source_id', null, {label: trans('form.asset_source_account')}) }}
|
||||
@@ -115,8 +115,8 @@
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{# transaction information (optional) #}
|
||||
{{ CurrencyForm.currencyListEmpty('foreign_currency_id', 0) }}
|
||||
{{ ExpandedForm.amountNoCurrency('foreign_amount', []) }}
|
||||
{{ CurrencyForm.currencyListEmpty('foreign_currency_id') }}
|
||||
{{ ExpandedForm.amountNoCurrency('foreign_amount') }}
|
||||
|
||||
{# BUDGET ONLY WHEN CREATING A WITHDRAWAL #}
|
||||
{% if budgets|length > 1 %}
|
||||
@@ -132,7 +132,7 @@
|
||||
{{ ExpandedForm.text('tags') }}
|
||||
|
||||
{# RELATE THIS TRANSFER TO A PIGGY BANK #}
|
||||
{{ PiggyBankForm.piggyBankList('piggy_bank_id',0) }}
|
||||
{{ PiggyBankForm.piggyBankList('piggy_bank_id') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -310,6 +310,10 @@
|
||||
<i class="fa fa-fw fa-random"></i>
|
||||
{{ 'create_rule_from_transaction'|_ }}
|
||||
</a>
|
||||
<a href="{{ route('recurring.create-from-journal', [journal.transaction_journal_id]) }}" class="btn btn-default">
|
||||
<i class="fa fa-fw fa-paint-brush"></i>
|
||||
{{ 'create_recurring_from_transaction'|_ }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -851,6 +851,14 @@ try {
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'recurring.create-from-journal',
|
||||
static function (BreadcrumbsGenerator $breadcrumbs) {
|
||||
$breadcrumbs->parent('recurring.index');
|
||||
$breadcrumbs->push(trans('firefly.create_new_recurrence'), route('recurring.create'));
|
||||
}
|
||||
);
|
||||
|
||||
// Rules
|
||||
Breadcrumbs::register(
|
||||
'rules.index',
|
||||
|
@@ -724,6 +724,7 @@ Route::group(
|
||||
|
||||
Route::get('show/{recurrence}', ['uses' => 'Recurring\ShowController@show', 'as' => 'show']);
|
||||
Route::get('create', ['uses' => 'Recurring\CreateController@create', 'as' => 'create']);
|
||||
Route::get('create-from-transaction/{tj}', ['uses' => 'Recurring\CreateController@createFromJournal', 'as' => 'create-from-journal']);
|
||||
Route::get('edit/{recurrence}', ['uses' => 'Recurring\EditController@edit', 'as' => 'edit']);
|
||||
Route::get('delete/{recurrence}', ['uses' => 'Recurring\DeleteController@delete', 'as' => 'delete']);
|
||||
|
||||
|
Reference in New Issue
Block a user