diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.php index 4ba6653d25..9c006617bd 100644 --- a/app/Http/Controllers/Transaction/SingleController.php +++ b/app/Http/Controllers/Transaction/SingleController.php @@ -82,6 +82,42 @@ class SingleController extends Controller } + public function cloneTransaction(TransactionJournal $journal) + { + $source = TransactionJournal::sourceAccountList($journal)->first(); + $destination = TransactionJournal::destinationAccountList($journal)->first(); + $budget = $journal->budgets()->first(); + $budgetId = is_null($budget) ? 0 : $budget->id; + $category = $journal->categories()->first(); + $categoryName = is_null($category) ? '' : $category->name; + $tags = join(',', $journal->tags()->get()->pluck('tag')->toArray()); + + + $preFilled = [ + 'description' => $journal->description, + 'source_account_id' => $source->id, + 'source_account_name' => $source->name, + 'destination_account_id' => $destination->id, + 'destination_account_name' => $destination->name, + 'amount' => TransactionJournal::amountPositive($journal), + 'date' => $journal->date->format('Y-m-d'), + 'budget_id' => $budgetId, + 'category' => $categoryName, + 'tags' => $tags, + 'interest_date' => $journal->getMeta('interest_date'), + 'book_date' => $journal->getMeta('book_date'), + 'process_date' => $journal->getMeta('process_date'), + 'due_date' => $journal->getMeta('due_date'), + 'payment_date' => $journal->getMeta('payment_date'), + 'invoice_date' => $journal->getMeta('invoice_date'), + 'internal_reference' => $journal->getMeta('internal_reference'), + 'notes' => $journal->getMeta('notes'), + ]; + Session::flash('preFilled', $preFilled); + + return redirect(route('transactions.create', [strtolower($journal->transactionType->type)])); + } + /** * @param string $what * @@ -114,7 +150,8 @@ class SingleController extends Controller asort($piggies); return view( - 'transactions.single.create', compact('assetAccounts', 'subTitleIcon', 'uploadSize', 'budgets', 'what', 'piggies', 'subTitle', 'optionalFields') + 'transactions.single.create', + compact('assetAccounts', 'subTitleIcon', 'uploadSize', 'budgets', 'what', 'piggies', 'subTitle', 'optionalFields', 'preFilled') ); } diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 61367d9b2c..06c60e8258 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -106,6 +106,10 @@ return [ 'pref_languages_locale' => 'For a language other than English to work properly, your operating system must be equipped with the correct locale-information. If these are not present, currency data, dates and amounts may be formatted wrong.', 'budget_in_period' => '":name" between :start and :end', 'budget_in_period_breadcrumb' => 'Between :start and :end', + 'clone_withdrawal' => 'Clone this withdrawal', + 'clone_deposit' => 'Clone this deposit', + 'clone_transfer' => 'Clone this transfer', + 'transaction_journal_other_options' => 'Other options', // repeat frequencies: 'repeat_freq_yearly' => 'yearly', diff --git a/resources/views/transactions/show.twig b/resources/views/transactions/show.twig index f20e920b98..c3a0ab7079 100644 --- a/resources/views/transactions/show.twig +++ b/resources/views/transactions/show.twig @@ -82,6 +82,15 @@ {{ 'budgets'|_ }} {{ journalBudgets(journal)|raw }} + + {% if journal.hasMeta('interest_date') %} + + {{ trans('list.interest_date') }} + {{ journal.getMeta('interest_date').formatLocalized(monthAndDayFormat) }} + + + {% endif %} + {% if journal.hasMeta('book_date') %} {{ trans('list.book_date') }} @@ -95,13 +104,7 @@ {% endif %} - {% if journal.hasMeta('interest_date') %} - - {{ trans('list.interest_date') }} - {{ journal.getMeta('interest_date').formatLocalized(monthAndDayFormat) }} - - {% endif %} {% if journal.hasMeta('due_date') %} {{ trans('list.due_date') }} @@ -211,7 +214,7 @@ {% if transactions|length == 1 %}
-

{{ 'transaction_journal_convert_options'|_ }}

+

{{ 'transaction_journal_other_options'|_ }}

{% if journal.transactionType.type != "Withdrawal" %} @@ -239,6 +242,14 @@

{% endif %} + {% if transactions|length == 1 %} +

+ + + {{ ('clone_'~journal.transactionType.type|lower)|_ }} + +

+ {% endif %}
diff --git a/resources/views/transactions/single/create.twig b/resources/views/transactions/single/create.twig index b6f2edbfef..baa6544194 100644 --- a/resources/views/transactions/single/create.twig +++ b/resources/views/transactions/single/create.twig @@ -48,7 +48,7 @@ {{ ExpandedForm.amount('amount') }} - {{ ExpandedForm.date('date', phpdate('Y-m-d')) }} + {{ ExpandedForm.date('date', preFilled.date|default(phpdate('Y-m-d'))) }}