diff --git a/app/controllers/CurrencyController.php b/app/controllers/CurrencyController.php index f8381e2600..bc2ae575ea 100644 --- a/app/controllers/CurrencyController.php +++ b/app/controllers/CurrencyController.php @@ -2,6 +2,10 @@ use FireflyIII\Database\TransactionCurrency\TransactionCurrency as Repository; /** + * + * @SuppressWarnings("CamelCase") // I'm fine with this. + * @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok. + * * Class CurrencyController */ class CurrencyController extends BaseController @@ -46,6 +50,8 @@ class CurrencyController extends BaseController $currencyPreference = $preferences->get('currencyPreference', 'EUR'); $currencyPreference->data = $currency->code; $currencyPreference->save(); + + Session::flash('success', $currency->name.' is now the default currency.'); Cache::forget('FFCURRENCYSYMBOL'); Cache::forget('FFCURRENCYCODE'); @@ -139,7 +145,7 @@ class CurrencyController extends BaseController public function update(TransactionCurrency $currency) { - $data = Input::except('_token'); + $data = Input::except('_token'); // always validate: $messages = $this->_repository->validate($data); diff --git a/app/database/seeds/TransactionCurrencySeeder.php b/app/database/seeds/TransactionCurrencySeeder.php index 46a08f74fb..20f50e9f60 100644 --- a/app/database/seeds/TransactionCurrencySeeder.php +++ b/app/database/seeds/TransactionCurrencySeeder.php @@ -10,9 +10,8 @@ class TransactionCurrencySeeder extends Seeder { DB::table('transaction_currencies')->delete(); - TransactionCurrency::create( - ['code' => 'EUR'] - ); + TransactionCurrency::create(['code' => 'EUR','name' => 'Euro','symbol' => '€']); + TransactionCurrency::create(['code' => 'USD','name' => 'US Dollar','symbol' => '$']); } } \ No newline at end of file diff --git a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php index 2e3648604f..887f792656 100644 --- a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php +++ b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php @@ -35,7 +35,9 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas public function store(array $data) { $currency = new \TransactionCurrency($data); + \Log::debug('Is valid? ' . boolstr($currency->isValid())); $currency->save(); + return $currency; } @@ -48,8 +50,9 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas public function update(Eloquent $model, array $data) { $model->symbol = $data['symbol']; - $model->code = $data['code']; - $model->name = $data['name']; + $model->code = $data['code']; + $model->name = $data['name']; + \Log::debug('Is valid? ' . boolstr($model->isValid())); $model->save(); return true; @@ -67,11 +70,16 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas { $warnings = new MessageBag; $successes = new MessageBag; + \Log::debug('Now in TransactionCurrency::validate()'); $currency = new \TransactionCurrency($model); $currency->isValid(); $errors = $currency->getErrors(); + \Log::debug('Data: ' . json_encode($model)); + \Log::debug('Error-content: ' . json_encode($errors->all())); + \Log::debug('Error count is: ' . $errors->count()); + $fields = ['name', 'code', 'symbol']; foreach ($fields as $field) { if (!$errors->has($field)) { diff --git a/app/models/TransactionCurrency.php b/app/models/TransactionCurrency.php index 4a15900633..8f55b14be6 100644 --- a/app/models/TransactionCurrency.php +++ b/app/models/TransactionCurrency.php @@ -12,20 +12,10 @@ class TransactionCurrency extends Eloquent use SoftDeletingTrait, ValidatingTrait; protected $fillable = ['name', 'symbol', 'code']; - protected $rules - = [ - 'creating' => [ - 'code' => 'required|min:3|max:3|alpha|unique:transaction_currencies,code', - 'name' => 'required|min:3|max:48|unique:transaction_currencies,name', - 'symbol' => 'required|min:1|max:8|unique:transaction_currencies,symbol', - ], - - 'updating' => [ - 'code' => 'required|min:3|max:3|alpha', - 'name' => 'required|min:3|max:48', - 'symbol' => 'required|min:1|max:8', - ], - + protected $rules = [ + 'code' => 'required|alpha|between:3,3|min:3|max:3', + 'name' => 'required|between:3,48|min:3|max:48', + 'symbol' => 'required|between:1,8|min:1|max:8', ]; /** diff --git a/app/views/currency/edit.blade.php b/app/views/currency/edit.blade.php index 56792058a7..f9482210b4 100644 --- a/app/views/currency/edit.blade.php +++ b/app/views/currency/edit.blade.php @@ -1,7 +1,7 @@ @extends('layouts.default') @section('content') {{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }} -{{Form::model($currency, ['class' => 'form-horizontal','id' => 'store','url' => route('currency.update',$currency->id)])}} +{{Form::model($currency, ['class' => 'form-horizontal','id' => 'update','url' => route('currency.update',$currency->id)])}}