2015-02-07 18:15:15 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
|
|
|
|
|
|
|
use Auth;
|
2015-02-09 00:23:39 -06:00
|
|
|
use Config;
|
2015-02-14 07:25:29 -06:00
|
|
|
use FireflyIII\Models\Account;
|
|
|
|
use Input;
|
2015-02-07 18:15:15 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AccountFormRequest
|
|
|
|
*
|
2015-05-10 01:08:07 -05:00
|
|
|
* @codeCoverageIgnore
|
2015-02-07 18:15:15 -06:00
|
|
|
* @package FireflyIII\Http\Requests
|
|
|
|
*/
|
|
|
|
class AccountFormRequest extends Request
|
|
|
|
{
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-02-07 18:15:15 -06:00
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
// Only allow logged in users
|
|
|
|
return Auth::check();
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-02-07 18:15:15 -06:00
|
|
|
public function rules()
|
|
|
|
{
|
2015-04-03 15:54:21 -05:00
|
|
|
$accountRoles = join(',', array_keys(Config::get('firefly.accountRoles')));
|
|
|
|
$types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));
|
|
|
|
$ccPaymentTypes = join(',', array_keys(Config::get('firefly.ccTypes')));
|
2015-02-09 00:23:39 -06:00
|
|
|
|
2015-04-05 14:12:54 -05:00
|
|
|
$nameRule = 'required|min:1|uniqueAccountForUser';
|
2015-04-01 12:42:14 -05:00
|
|
|
$idRule = '';
|
2015-02-14 07:25:29 -06:00
|
|
|
if (Account::find(Input::get('id'))) {
|
2015-04-01 12:42:14 -05:00
|
|
|
$idRule = 'belongsToUser:accounts';
|
2015-04-05 14:12:54 -05:00
|
|
|
$nameRule = 'required|min:1|uniqueAccountForUser:' . Input::get('id');
|
2015-02-14 07:25:29 -06:00
|
|
|
}
|
|
|
|
|
2015-02-07 18:15:15 -06:00
|
|
|
return [
|
2015-12-25 10:10:04 -06:00
|
|
|
'id' => $idRule,
|
|
|
|
'name' => $nameRule,
|
|
|
|
'openingBalance' => 'numeric',
|
|
|
|
'iban' => 'iban',
|
|
|
|
'virtualBalance' => 'numeric',
|
|
|
|
'openingBalanceDate' => 'date',
|
|
|
|
'accountRole' => 'in:' . $accountRoles,
|
|
|
|
'active' => 'boolean',
|
|
|
|
'ccType' => 'in:' . $ccPaymentTypes,
|
|
|
|
'ccMonthlyPaymentDate' => 'date',
|
|
|
|
'amount_currency_id_openingBalance' => 'exists:transaction_currencies,id',
|
|
|
|
'amount_currency_id_virtualBalance' => 'exists:transaction_currencies,id',
|
|
|
|
'what' => 'in:' . $types
|
2015-02-07 18:15:15 -06:00
|
|
|
];
|
|
|
|
}
|
2015-03-25 09:55:39 -05:00
|
|
|
}
|