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 @@
+ + + {{ ('clone_'~journal.transactionType.type|lower)|_ }} + +
+ {% endif %}