mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More cleanup [skip ci]
This commit is contained in:
parent
c2d2eb53e8
commit
6873336aca
@ -168,14 +168,18 @@ class AccountController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
|
/** @var \FireflyIII\Database\AccountType\AccountType $accountTypes */
|
||||||
|
$accountTypes = App::make('FireflyIII\Database\AccountType\AccountType');
|
||||||
|
|
||||||
|
|
||||||
$data = Input::except('_token');
|
$data = Input::except('_token');
|
||||||
|
$type = $accountTypes->findByWhat($data['what']);
|
||||||
|
$data['user_id'] = \Auth::user()->id;
|
||||||
|
$data['account_type_id'] = $type->id;
|
||||||
// always validate:
|
// always validate:
|
||||||
$messages = $this->_repository->validate($data);
|
$messages = $this->_repository->validate($data);
|
||||||
|
|
||||||
// flash messages:
|
// flash messages:
|
||||||
Session::flash('warnings', $messages['warnings']);
|
|
||||||
Session::flash('successes', $messages['successes']);
|
Session::flash('successes', $messages['successes']);
|
||||||
Session::flash('errors', $messages['errors']);
|
Session::flash('errors', $messages['errors']);
|
||||||
if ($messages['errors']->count() > 0) {
|
if ($messages['errors']->count() > 0) {
|
||||||
@ -206,7 +210,8 @@ class AccountController extends BaseController
|
|||||||
public function update(Account $account)
|
public function update(Account $account)
|
||||||
{
|
{
|
||||||
$data = Input::except('_token');
|
$data = Input::except('_token');
|
||||||
$data['what'] = $this->_shortNamesByFullName[$account->accountType->type];
|
$data['account_type_id'] = $account->account_type_id;
|
||||||
|
$data['user_id'] = \Auth::user()->id;
|
||||||
|
|
||||||
|
|
||||||
// always validate:
|
// always validate:
|
||||||
|
@ -129,7 +129,6 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
'amount' => $balance,
|
'amount' => $balance,
|
||||||
'from' => $fromAccount,
|
'from' => $fromAccount,
|
||||||
'completed' => 0,
|
'completed' => 0,
|
||||||
'what' => 'opening',
|
|
||||||
'to' => $toAccount,
|
'to' => $toAccount,
|
||||||
'date' => $date,
|
'date' => $date,
|
||||||
'description' => 'Opening balance for new account ' . $account->name
|
'description' => 'Opening balance for new account ' . $account->name
|
||||||
@ -347,41 +346,14 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
*/
|
*/
|
||||||
public function validate(array $model)
|
public function validate(array $model)
|
||||||
{
|
{
|
||||||
$warnings = new MessageBag;
|
|
||||||
$successes = new MessageBag;
|
$successes = new MessageBag;
|
||||||
$errors = new MessageBag;
|
$account = new \Account($model);
|
||||||
|
$account->isValid();
|
||||||
/*
|
$errors = $account->getErrors();
|
||||||
* Name validation:
|
|
||||||
*/
|
|
||||||
if (!isset($model['name'])) {
|
|
||||||
$errors->add('name', 'Name is mandatory');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($model['name']) && strlen($model['name']) == 0) {
|
|
||||||
$errors->add('name', 'Name is too short');
|
|
||||||
}
|
|
||||||
if (isset($model['name']) && strlen($model['name']) > 100) {
|
|
||||||
$errors->add('name', 'Name is too long');
|
|
||||||
}
|
|
||||||
$validator = \Validator::make([$model], \Account::$rules);
|
|
||||||
if ($validator->invalid()) {
|
|
||||||
$errors->merge($errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($model['account_role']) && !in_array($model['account_role'], array_keys(\Config::get('firefly.accountRoles')))) {
|
if (isset($model['account_role']) && !in_array($model['account_role'], array_keys(\Config::get('firefly.accountRoles')))) {
|
||||||
$errors->add('account_role', 'Invalid account role');
|
$errors->add('account_role', 'Invalid account role');
|
||||||
} else {
|
|
||||||
$successes->add('account_role', 'OK');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* type validation.
|
|
||||||
*/
|
|
||||||
if (!isset($model['what'])) {
|
|
||||||
$errors->add('name', 'Internal error: need to know type of account!');
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Opening balance and opening balance date.
|
* Opening balance and opening balance date.
|
||||||
*/
|
*/
|
||||||
@ -397,19 +369,14 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$fields = ['name', 'openingBalance', 'openingBalanceDate', 'active', 'account_role'];
|
||||||
|
foreach ($fields as $field) {
|
||||||
if (!$errors->has('name')) {
|
if (!$errors->has($field)) {
|
||||||
$successes->add('name', 'OK');
|
$successes->add($field, 'OK');
|
||||||
}
|
}
|
||||||
if (!$errors->has('openingBalance')) {
|
|
||||||
$successes->add('openingBalance', 'OK');
|
|
||||||
}
|
|
||||||
if (!$errors->has('openingBalanceDate')) {
|
|
||||||
$successes->add('openingBalanceDate', 'OK');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
|
return ['errors' => $errors, 'successes' => $successes];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +159,7 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
|
|||||||
$journal->isValid();
|
$journal->isValid();
|
||||||
$errors = $journal->getErrors();
|
$errors = $journal->getErrors();
|
||||||
|
|
||||||
if (!isset($model['what'])) {
|
if (!isset($model['what']) && !isset($model['transaction_type_id'])) {
|
||||||
$errors->add('description', 'Internal error: need to know type of transaction!');
|
$errors->add('description', 'Internal error: need to know type of transaction!');
|
||||||
}
|
}
|
||||||
if (strlen($model['description']) == 0) {
|
if (strlen($model['description']) == 0) {
|
||||||
|
@ -12,21 +12,20 @@ use Watson\Validating\ValidatingTrait;
|
|||||||
class Account extends Eloquent
|
class Account extends Eloquent
|
||||||
{
|
{
|
||||||
use SoftDeletingTrait, ValidatingTrait;
|
use SoftDeletingTrait, ValidatingTrait;
|
||||||
|
protected $dates = ['deleted_at', 'created_at', 'updated_at'];
|
||||||
|
protected $fillable = ['name', 'user_id', 'account_type_id', 'active'];
|
||||||
/**
|
/**
|
||||||
* Validation rules.
|
* Validation rules.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $rules
|
protected $rules
|
||||||
= [
|
= [
|
||||||
'name' => ['required', 'between:1,100'],
|
'name' => 'required|between:1,100',
|
||||||
'user_id' => 'required|exists:users,id',
|
'user_id' => 'required|exists:users,id',
|
||||||
'account_type_id' => 'required|exists:account_types,id',
|
'account_type_id' => 'required|exists:account_types,id',
|
||||||
'active' => 'required|boolean'
|
'active' => 'required|boolean'
|
||||||
|
|
||||||
];
|
];
|
||||||
protected $dates = ['deleted_at', 'created_at', 'updated_at'];
|
|
||||||
protected $fillable = ['name', 'user_id', 'account_type_id', 'active'];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account type.
|
* Account type.
|
||||||
|
Loading…
Reference in New Issue
Block a user