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

This commit is contained in:
James Cole 2017-01-20 12:23:52 +01:00
parent def3b3a155
commit 0d1d360d18
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 64 additions and 12 deletions

View File

@ -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')
);
}

View File

@ -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',

View File

@ -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>

View File

@ -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 -->

View File

@ -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']);
}
);