Skip to content

Firefly III: a personal finances manager

Can now clone transaction #538. Wasn’t that difficult.

James Cole0d1d360d188f
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 @@
<td>{{ 'budgets'|_ }}</td>
<td>{{ journalBudgets(journal)|raw }}</td>
</tr>
+
+ {% if journal.hasMeta('interest_date') %}
+ <tr>
+ <td>{{ trans('list.interest_date') }}</td>
+ <td>{{ journal.getMeta('interest_date').formatLocalized(monthAndDayFormat) }}</td>
+ </tr>
+
+ {% endif %}
+
{% if journal.hasMeta('book_date') %}
<tr>
<td>{{ trans('list.book_date') }}</td>
@@ -95,13 +104,7 @@
</tr>
{% endif %}
- {% if journal.hasMeta('interest_date') %}
- <tr>
- <td>{{ trans('list.interest_date') }}</td>
- <td>{{ journal.getMeta('interest_date').formatLocalized(monthAndDayFormat) }}</td>
- </tr>
- {% endif %}
{% if journal.hasMeta('due_date') %}
<tr>
<td>{{ trans('list.due_date') }}</td>
@@ -211,7 +214,7 @@
{% if transactions|length == 1 %}
<div class="box">
<div class="box-header with-border">
- <h3 class="box-title">{{ 'transaction_journal_convert_options'|_ }}</h3>
+ <h3 class="box-title">{{ 'transaction_journal_other_options'|_ }}</h3>
</div>
<div class="box-body">
{% if journal.transactionType.type != "Withdrawal" %}
@@ -239,6 +242,14 @@
</a>
</p>
{% endif %}
+ {% if transactions|length == 1 %}
+ <p>
+ <i class="fa fa-copy" aria-hidden="true"></i>
+ <a href="{{ route('transactions.clone', [journal.id]) }}">
+ {{ ('clone_'~journal.transactionType.type|lower)|_ }}
+ </a>
+ </p>
+ {% endif %}
</div>
</div>
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') }}
<!-- ALWAYS SHOW DATE -->
- {{ ExpandedForm.date('date', phpdate('Y-m-d')) }}
+ {{ ExpandedForm.date('date', preFilled.date|default(phpdate('Y-m-d'))) }}
</div>
<div class="box-footer">
<button type="submit" id="transaction-btn" class="btn btn-success pull-right">
@@ -65,9 +65,9 @@
<div class="box-body">
<!-- BUDGET ONLY WHEN CREATING A WITHDRAWAL -->
{% if budgets|length > 1 %}
- {{ ExpandedForm.select('budget_id', budgets, 0) }}
+ {{ ExpandedForm.select('budget_id', budgets, null) }}
{% else %}
- {{ ExpandedForm.select('budget_id', budgets, 0, {helpText: trans('firefly.no_budget_pointer')}) }}
+ {{ ExpandedForm.select('budget_id', budgets, null, {helpText: trans('firefly.no_budget_pointer')}) }}
{% endif %}
<!-- CATEGORY ALWAYS -->
diff --git a/routes/web.php b/routes/web.php
index 04835588af..5e644f4dda 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -634,6 +634,7 @@ Route::group(
Route::post('store/{what}', ['uses' => 'SingleController@store', 'as' => 'store'])->where(['what' => 'withdrawal|deposit|transfer']);
Route::post('update/{tj}', ['uses' => 'SingleController@update', 'as' => 'update']);
Route::post('destroy/{tj}', ['uses' => 'SingleController@destroy', 'as' => 'destroy']);
+ Route::get('clone/{tj}', ['uses' => 'SingleController@cloneTransaction', 'as' => 'clone']);
}
);
@@ -667,7 +668,6 @@ Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Transaction', 'prefix' => 'transactions/convert', 'as' => 'transactions.convert.'], function () {
Route::get('{transaction_type}/{tj}', ['uses' => 'ConvertController@index', 'as' => 'index']);
Route::post('{transaction_type}/{tj}', ['uses' => 'ConvertController@postIndex', 'as' => 'index.post']);
-
}
);