mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 18:54:58 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			69 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			69 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * 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.
 | |
|  */
 | |
| 
 | |
| declare(strict_types = 1);
 | |
| 
 | |
| namespace FireflyIII\Http\Requests;
 | |
| 
 | |
| use Auth;
 | |
| use FireflyIII\Models\Account;
 | |
| use Input;
 | |
| 
 | |
| /**
 | |
|  * Class AccountFormRequest
 | |
|  *
 | |
|  *
 | |
|  * @package FireflyIII\Http\Requests
 | |
|  */
 | |
| class AccountFormRequest extends Request
 | |
| {
 | |
|     /**
 | |
|      * @return bool
 | |
|      */
 | |
|     public function authorize()
 | |
|     {
 | |
|         // Only allow logged in users
 | |
|         return Auth::check();
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * @return array
 | |
|      */
 | |
|     public function rules()
 | |
|     {
 | |
|         $accountRoles   = join(',', array_keys(config('firefly.accountRoles')));
 | |
|         $types          = join(',', array_keys(config('firefly.subTitlesByIdentifier')));
 | |
|         $ccPaymentTypes = join(',', array_keys(config('firefly.ccTypes')));
 | |
| 
 | |
|         $nameRule = 'required|min:1|uniqueAccountForUser';
 | |
|         $idRule   = '';
 | |
|         if (Account::find(Input::get('id'))) {
 | |
|             $idRule   = 'belongsToUser:accounts';
 | |
|             $nameRule = 'required|min:1|uniqueAccountForUser:' . Input::get('id');
 | |
|         }
 | |
| 
 | |
|         return [
 | |
|             'id'                                => $idRule,
 | |
|             'name'                              => $nameRule,
 | |
|             'openingBalance'                    => 'numeric',
 | |
|             'iban'                              => 'iban',
 | |
|             'virtualBalance'                    => 'numeric',
 | |
|             'openingBalanceDate'                => 'date',
 | |
|             'accountNumber'                     => 'between:1,255|uniqueAccountNumberForUser',
 | |
|             '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,
 | |
|         ];
 | |
|     }
 | |
| }
 |