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
|
|
|
|
*
|
2016-10-04 23:52:15 -05:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-05-20 05:41:23 -05:00
|
|
|
*/
|
|
|
|
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2015-02-07 18:15:15 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
|
|
|
|
2016-10-23 05:41:54 -05:00
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
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
|
|
|
}
|
|
|
|
|
2016-10-22 14:40:31 -05:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-10-22 15:03:00 -05:00
|
|
|
public function getAccountData(): array
|
2016-10-22 14:40:31 -05:00
|
|
|
{
|
|
|
|
return [
|
2017-01-21 01:32:23 -06:00
|
|
|
'name' => $this->string('name'),
|
|
|
|
'active' => $this->boolean('active'),
|
|
|
|
'accountType' => $this->string('what'),
|
|
|
|
'currency_id' => $this->integer('currency_id'),
|
|
|
|
'virtualBalance' => $this->float('virtualBalance'),
|
|
|
|
'virtualBalanceCurrency' => $this->integer('amount_currency_id_virtualBalance'),
|
|
|
|
'iban' => $this->string('iban'),
|
|
|
|
'BIC' => $this->string('BIC'),
|
|
|
|
'accountNumber' => $this->string('accountNumber'),
|
|
|
|
'accountRole' => $this->string('accountRole'),
|
|
|
|
'openingBalance' => $this->float('openingBalance'),
|
|
|
|
'openingBalanceDate' => $this->date('openingBalanceDate'),
|
|
|
|
'openingBalanceCurrency' => $this->integer('amount_currency_id_openingBalance'),
|
|
|
|
'ccType' => $this->string('ccType'),
|
|
|
|
'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'),
|
2016-10-22 14:40:31 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-02-07 18:15:15 -06:00
|
|
|
public function rules()
|
|
|
|
{
|
2016-10-23 05:41:54 -05:00
|
|
|
/** @var AccountRepositoryInterface $repository */
|
|
|
|
$repository = app(AccountRepositoryInterface::class);
|
2017-02-02 13:36:32 -06:00
|
|
|
$accountRoles = join(',', config('firefly.accountRoles'));
|
2016-04-26 14:40:15 -05:00
|
|
|
$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 = '';
|
2016-10-23 05:41:54 -05:00
|
|
|
if (!is_null($repository->find(intval($this->get('id')))->id)) {
|
2015-04-01 12:42:14 -05:00
|
|
|
$idRule = 'belongsToUser:accounts';
|
2017-01-20 12:49:35 -06:00
|
|
|
$nameRule = 'required|min:1|uniqueAccountForUser:' . intval($this->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,
|
2017-02-11 11:35:16 -06:00
|
|
|
'openingBalance' => 'numeric|required_with:openingBalanceDate',
|
|
|
|
'openingBalanceDate' => 'date|required_with:openingBalance',
|
2015-12-25 10:10:04 -06:00
|
|
|
'iban' => 'iban',
|
2016-12-14 11:59:12 -06:00
|
|
|
'BIC' => 'bic',
|
2015-12-25 10:10:04 -06:00
|
|
|
'virtualBalance' => 'numeric',
|
2016-11-25 11:00:29 -06:00
|
|
|
'currency_id' => 'exists:transaction_currencies,id',
|
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
|
|
|
}
|