Also validate edits.

This commit is contained in:
Sander Dorigo 2014-10-05 08:49:36 +02:00
parent ec601efa6e
commit 980d9ce885
5 changed files with 30 additions and 118 deletions

View File

@ -342,8 +342,8 @@ class TransactionController extends BaseController
Session::flash('success', 'Transaction updated!');
Event::fire('journals.update', [$journal]);
if (Input::get('post_submit_action') == 'create_another') {
return Redirect::route('transactions.create', $what)->withInput();
if (Input::get('post_submit_action') == 'return_to_edit') {
return Redirect::route('transactions.edit', $journal->id);
} else {
return Redirect::route('transactions.index.' . $what);
}
@ -355,6 +355,16 @@ class TransactionController extends BaseController
);
}
break;
case 'validate_only':
$data = Input::all();
$data['what'] = strtolower($journal->transactionType->type);
$messageBags = $this->_helper->validate($data);
Session::flash('warnings', $messageBags['warnings']);
Session::flash('successes', $messageBags['successes']);
Session::flash('errors', $messageBags['errors']);
return Redirect::route('transactions.edit', $journal->id)->withInput();
break;
default:
throw new FireflyException('Method ' . Input::get('post_submit_action') . ' not implemented yet.');

View File

@ -16,7 +16,7 @@ class Form
* @return string
* @throws FireflyException
*/
public static function ffAmount($name, $value = null, array $options = [])
public static function ffNumber($name, $value = null, array $options = [])
{
$options['step'] = 'any';
$options['min'] = '0.01';

View File

@ -78,8 +78,8 @@ App::down(
\Form::macro('ffSelect', function ($name, array $list = [], $selected = null, array $options = []) {
return \Firefly\Form\Form::ffSelect($name, $list, $selected, $options);
});
\Form::macro('ffAmount', function ($name, $value = null, array $options = []) {
return \Firefly\Form\Form::ffAmount($name, $value, $options);
\Form::macro('ffNumber', function ($name, $value = null, array $options = []) {
return \Firefly\Form\Form::ffNumber($name, $value, $options);
});
\Form::macro('ffDate', function ($name, $value = null, array $options = []) {
return \Firefly\Form\Form::ffDate($name, $value, $options);

View File

@ -37,7 +37,7 @@
<!-- ALWAYS SHOW AMOUNT -->
{{Form::ffAmount('amount')}}
{{Form::ffNumber('amount')}}
<!-- ALWAYS SHOW DATE -->
{{Form::ffDate('date', date('Y-m-d'))}}

View File

@ -12,103 +12,33 @@
</div>
<div class="panel-body">
<!-- ALWAYS AVAILABLE -->
<div class="form-group">
<label for="description" class="col-sm-4 control-label">Description</label>
<div class="col-sm-8">
<input type="text"
name="description" value="{{{Input::old('description') ?: $journal->description}}}"
autocomplete="off" class="form-control" placeholder="Description" />
</div>
</div>
{{Form::ffText('description',$journal->description)}}
<!-- SHOW ACCOUNT (FROM) ONLY FOR WITHDRAWALS AND DEPOSITS -->
@if($what == 'deposit' || $what == 'withdrawal')
<div class="form-group">
<label for="account_id" class="col-sm-4 control-label">
@if($what == 'deposit')
Received into account
@endif
@if($what == 'withdrawal')
Paid from account
@endif
</label>
<div class="col-sm-8">
{{Form::select('account_id',$accounts,Input::old('account_id') ?: $data['account_id'],['class' => 'form-control'])}}
</div>
</div>
{{Form::ffSelect('account_id',$accounts,$data['account_id'])}}
@endif
<!-- SHOW EXPENSE ACCOUNT ONLY FOR WITHDRAWALS -->
@if($what == 'withdrawal')
<div class="form-group">
<label for="expense_account" class="col-sm-4 control-label">
Expense account
</label>
<div class="col-sm-8">
<input type="text"
name="expense_account"
value="{{{Input::old('expense_account') ?: $data['expense_account']}}}"
autocomplete="off" class="form-control" />
</div>
</div>
{{Form::ffText('expense_account',$data['expense_account'])}}
@endif
<!-- SHOW REVENUE ACCOUNT ONLY FOR DEPOSITS -->
@if($what == 'deposit')
<div class="form-group">
<label for="revenue_account" class="col-sm-4 control-label">
Revenue account
</label>
<div class="col-sm-8">
<input type="text"
name="revenue_account"
value="{{{Input::old('revenue_account') ?: $data['revenue_account']}}}"
autocomplete="off" class="form-control" placeholder="Beneficiary" />
</div>
</div>
{{Form::ffText('revenue_account',$data['revenue_account'])}}
@endif
<!-- ONLY SHOW FROM/TO ACCOUNT WHEN CREATING TRANSFER -->
@if($what == 'transfer')
<div class="form-group">
<label for="account_from_id" class="col-sm-4 control-label">Account from</label>
<div class="col-sm-8">
{{Form::select('account_to_id',$accounts,Input::old('account_from_id') ?: $data['account_from_id'],['class' => 'form-control'])}}
</div>
</div>
<div class="form-group">
<label for="account_to_id" class="col-sm-4 control-label">Account to</label>
<div class="col-sm-8">
{{Form::select('account_from_id',$accounts,Input::old('account_to_id') ?: $data['account_to_id'],['class' => 'form-control'])}}
</div>
</div>
{{Form::ffSelect('account_from_id',$accounts,$data['account_from_id'])}}
{{Form::ffSelect('account_to_id',$accounts,$data['account_to_id'])}}
@endif
<!-- ALWAYS SHOW AMOUNT -->
<div class="form-group">
<label for="amount" class="col-sm-4 control-label">
@if($what == 'withdrawal')
Amount spent
@endif
@if($what == 'deposit')
Amount received
@endif
@if($what == 'transfer')
Amount transferred
@endif
</label>
<div class="col-sm-8">
<input type="number" name="amount" min="0.01" value="{{Input::old('amount') ?: $data['amount']}}" step="any" class="form-control" />
</div>
</div>
{{Form::ffNumber('amount',$data['amount'])}}
<!-- ALWAYS SHOW DATE -->
<div class="form-group">
<label for="date" class="col-sm-4 control-label">Date</label>
<div class="col-sm-8">
<input type="date" name="date" value="{{Input::old('date') ?: $data['date']}}" class="form-control" />
</div>
</div>
{{Form::ffDate('date',$data['date'])}}
</div>
</div> <!-- close panel -->
@ -128,44 +58,16 @@
<div class="panel-body">
<!-- BUDGET ONLY WHEN CREATING A WITHDRAWAL -->
@if($what == 'withdrawal')
<div class="form-group">
<label for="budget_id" class="col-sm-4 control-label">Budget</label>
<div class="col-sm-8">
{{Form::select('budget_id',$budgets,Input::old('budget_id') ?: $data['budget_id'],['class' => 'form-control'])}}
<span class="help-block">Select one of your budgets to make this transaction a part of it.</span>
</div>
</div>
{{Form::ffSelect('budget_id',$budgets,$data['budget_id'])}}
@endif
<!-- CATEGORY ALWAYS -->
<div class="form-group">
<label for="category" class="col-sm-4 control-label">Category</label>
<div class="col-sm-8">
<input type="text" name="category" value="{{Input::old('category') ?: $data['category']}}" autocomplete="off" class="form-control" placeholder="Category" />
<span class="help-block">Add more fine-grained information to this transaction by entering a category.
Like the beneficiary-field, this field will auto-complete existing categories but can also be used
to create new ones.
</span>
</div>
</div>
{{Form::ffText('category',$data['category'])}}
<!-- TAGS -->
<!-- RELATE THIS TRANSFER TO A PIGGY BANK -->
@if($what == 'transfer' && count($piggies) > 0)
<div class="form-group">
<label for="piggybank_id" class="col-sm-4 control-label">
Piggy bank
</label>
<div class="col-sm-8">
{{Form::select('piggybank_id',$piggies,Input::old('piggybank_id') ?: $data['piggybank_id'],['class' => 'form-control'])}}
@if($errors->has('piggybank_id'))
<p class="text-danger">{{$errors->first('piggybank_id')}}</p>
@else
<span class="help-block">
You can directly add the amount you're transferring
to one of your piggy banks, provided they are related to the account your
transferring <em>to</em>.
</span>
@endif
</div>
</div>
{{Form::ffSelect('piggybank_id',$piggies,$data['piggybank_id'])}}
@endif
</div>
</div><!-- end of panel for options-->