| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-14 07:30:55 +01:00
										 |  |  |  * BudgetUpdateRequest.php | 
					
						
							| 
									
										
										
										
											2020-01-23 19:44:52 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <https://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Api\V1\Requests; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-14 18:33:07 +01:00
										 |  |  | use FireflyIII\Rules\IsBoolean; | 
					
						
							| 
									
										
										
										
											2020-11-08 13:36:13 +01:00
										 |  |  | use FireflyIII\Support\Request\ChecksLogin; | 
					
						
							| 
									
										
										
										
											2020-07-18 08:34:00 +02:00
										 |  |  | use FireflyIII\Support\Request\ConvertsDataTypes; | 
					
						
							|  |  |  | use FireflyIII\Validation\AutoBudget\ValidatesAutoBudgetRequest; | 
					
						
							| 
									
										
										
										
											2020-07-18 08:25:25 +02:00
										 |  |  | use Illuminate\Foundation\Http\FormRequest; | 
					
						
							| 
									
										
										
										
											2020-03-14 07:43:49 +01:00
										 |  |  | use Illuminate\Validation\Validator; | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-14 07:30:55 +01:00
										 |  |  |  * Class BudgetUpdateRequest | 
					
						
							| 
									
										
										
										
											2019-09-04 17:39:39 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-12 04:53:18 +02:00
										 |  |  |  * @codeCoverageIgnore | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-07-18 08:25:25 +02:00
										 |  |  | class BudgetUpdateRequest extends FormRequest | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-08 13:36:13 +01:00
										 |  |  |     use ConvertsDataTypes, ValidatesAutoBudgetRequest, ChecksLogin; | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-07-06 07:15:42 +02:00
										 |  |  |      * Get all data from the request. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function getAll(): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-21 15:42:57 +01:00
										 |  |  |         $active = true; | 
					
						
							|  |  |  |         if (null !== $this->get('active')) { | 
					
						
							|  |  |  |             $active = $this->boolean('active'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2020-03-14 07:43:49 +01:00
										 |  |  |             'name'                      => $this->string('name'), | 
					
						
							|  |  |  |             'active'                    => $active, | 
					
						
							|  |  |  |             'order'                     => 0, | 
					
						
							|  |  |  |             'auto_budget_type'          => $this->string('auto_budget_type'), | 
					
						
							|  |  |  |             'transaction_currency_id'   => $this->integer('auto_budget_currency_id'), | 
					
						
							|  |  |  |             'transaction_currency_code' => $this->string('auto_budget_currency_code'), | 
					
						
							|  |  |  |             'auto_budget_amount'        => $this->string('auto_budget_amount'), | 
					
						
							|  |  |  |             'auto_budget_period'        => $this->string('auto_budget_period'), | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-07-06 07:15:42 +02:00
										 |  |  |      * The rules that the incoming request must be matched against. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |      * @return array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function rules(): array | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-03-14 07:30:55 +01:00
										 |  |  |         $budget = $this->route()->parameter('budget'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return [ | 
					
						
							| 
									
										
										
										
											2020-03-14 07:43:49 +01:00
										 |  |  |             'name'                      => sprintf('required|between:1,100|uniqueObjectForUser:budgets,name,%d', $budget->id), | 
					
						
							|  |  |  |             'active'                    => [new IsBoolean], | 
					
						
							|  |  |  |             'auto_budget_type'          => 'in:reset,rollover,none', | 
					
						
							|  |  |  |             'auto_budget_currency_id'   => 'exists:transaction_currencies,id', | 
					
						
							|  |  |  |             'auto_budget_currency_code' => 'exists:transaction_currencies,code', | 
					
						
							|  |  |  |             'auto_budget_amount'        => 'min:0|max:1000000000', | 
					
						
							|  |  |  |             'auto_budget_period'        => 'in:daily,weekly,monthly,quarterly,half_year,yearly', | 
					
						
							| 
									
										
										
										
											2018-06-24 14:54:06 +02:00
										 |  |  |         ]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-03-14 07:43:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Configure the validator instance with special rules for after the basic validation rules. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Validator $validator | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function withValidator(Validator $validator): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $validator->after( | 
					
						
							|  |  |  |             function (Validator $validator) { | 
					
						
							|  |  |  |                 // validate all account info
 | 
					
						
							|  |  |  |                 $this->validateAutoBudgetAmount($validator); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-07-22 20:32:02 +02:00
										 |  |  | } |