2015-02-07 18:15:15 -06:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* AccountFormRequest.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
|
|
|
* of the MIT license. See the LICENSE file for details.
|
|
|
|
*/
|
|
|
|
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2015-02-07 18:15:15 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
|
|
|
|
2015-02-14 07:25:29 -06:00
|
|
|
use FireflyIII\Models\Account;
|
|
|
|
use Input;
|
2015-02-07 18:15:15 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AccountFormRequest
|
|
|
|
*
|
2016-02-04 00:28:39 -06:00
|
|
|
*
|
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
|
2016-09-16 05:07:45 -05:00
|
|
|
return auth()->check();
|
2015-02-07 18:15:15 -06:00
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-02-07 18:15:15 -06:00
|
|
|
public function rules()
|
|
|
|
{
|
2016-04-26 14:40:15 -05:00
|
|
|
$accountRoles = join(',', array_keys(config('firefly.accountRoles')));
|
|
|
|
$types = join(',', array_keys(config('firefly.subTitlesByIdentifier')));
|
|
|
|
$ccPaymentTypes = join(',', array_keys(config('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',
|
2016-02-10 23:40:06 -06:00
|
|
|
'accountNumber' => 'between:1,255|uniqueAccountNumberForUser',
|
2015-12-25 10:10:04 -06:00
|
|
|
'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',
|
2016-01-15 16:12:52 -06:00
|
|
|
'what' => 'in:' . $types,
|
2015-02-07 18:15:15 -06:00
|
|
|
];
|
|
|
|
}
|
2015-03-25 09:55:39 -05:00
|
|
|
}
|