| 
									
										
										
										
											2016-01-15 11:28:27 +01:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * RuleGroupController.php | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Copyright (c) 2017 thegrumpydictator@gmail.com | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * This file is part of Firefly III. | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * Firefly III is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Firefly III is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2017-12-17 14:41:58 +01:00
										 |  |  |  * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-24 11:07:38 +01:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2016-01-15 11:28:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 14:18:09 +01:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | use ExpandedForm; | 
					
						
							|  |  |  | use FireflyIII\Http\Requests\RuleGroupFormRequest; | 
					
						
							| 
									
										
										
										
											2016-02-23 14:18:09 +01:00
										 |  |  | use FireflyIII\Http\Requests\SelectTransactionsRequest; | 
					
						
							|  |  |  | use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions; | 
					
						
							| 
									
										
										
										
											2016-05-20 11:02:07 +02:00
										 |  |  | use FireflyIII\Models\AccountType; | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | use FireflyIII\Models\RuleGroup; | 
					
						
							| 
									
										
										
										
											2016-10-10 07:25:27 +02:00
										 |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  | use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2016-12-28 13:02:56 +01:00
										 |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | use Preferences; | 
					
						
							|  |  |  | use Session; | 
					
						
							| 
									
										
										
										
											2016-01-15 11:28:27 +01:00
										 |  |  | use View; | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 11:28:27 +01:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class RuleGroupController. | 
					
						
							| 
									
										
										
										
											2016-01-15 11:28:27 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | class RuleGroupController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * RuleGroupController constructor. | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-01-15 11:28:27 +01:00
										 |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::__construct(); | 
					
						
							| 
									
										
										
										
											2016-10-29 07:44:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->middleware( | 
					
						
							|  |  |  |             function ($request, $next) { | 
					
						
							| 
									
										
										
										
											2017-12-16 19:46:36 +01:00
										 |  |  |                 app('view')->share('title', trans('firefly.rules')); | 
					
						
							|  |  |  |                 app('view')->share('mainTitleIcon', 'fa-random'); | 
					
						
							| 
									
										
										
										
											2016-10-29 07:44:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return $next($request); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2016-01-15 11:28:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-01-15 13:09:27 +01:00
										 |  |  |     public function create() | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $subTitleIcon = 'fa-clone'; | 
					
						
							|  |  |  |         $subTitle     = trans('firefly.make_new_rule_group'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // put previous url in session if not redirect from store (not "create another").
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (true !== session('rule-groups.create.fromStore')) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |             $this->rememberPreviousUri('rule-groups.create.uri'); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-12-18 21:04:53 +01:00
										 |  |  |         Session::forget('rule-groups.create.fromStore'); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 17:53:54 +01:00
										 |  |  |         return view('rules.rule-group.create', compact('subTitleIcon', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param RuleGroupRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param RuleGroup                    $ruleGroup | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function delete(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $subTitle = trans('firefly.delete_rule_group', ['title' => $ruleGroup->title]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-27 19:21:47 +02:00
										 |  |  |         $ruleGroupList = ExpandedForm::makeSelectListWithEmpty($repository->get()); | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         unset($ruleGroupList[$ruleGroup->id]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // put previous url in session
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         $this->rememberPreviousUri('rule-groups.delete.uri'); | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return view('rules.rule-group.delete', compact('ruleGroup', 'subTitle', 'ruleGroupList')); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-12-28 13:02:56 +01:00
										 |  |  |      * @param Request                      $request | 
					
						
							| 
									
										
										
										
											2016-01-15 13:08:25 +01:00
										 |  |  |      * @param RuleGroupRepositoryInterface $repository | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |      * @param RuleGroup                    $ruleGroup | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-12-28 13:02:56 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-12-28 13:02:56 +01:00
										 |  |  |     public function destroy(Request $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         $title  = $ruleGroup->title; | 
					
						
							| 
									
										
										
										
											2016-12-28 13:02:56 +01:00
										 |  |  |         $moveTo = auth()->user()->ruleGroups()->find(intval($request->get('move_rules_before_delete'))); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         $repository->destroy($ruleGroup, $moveTo); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-20 11:38:01 +01:00
										 |  |  |         Session::flash('success', strval(trans('firefly.deleted_rule_group', ['title' => $title]))); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |         Preferences::mark(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         return redirect($this->getPreviousUri('rule-groups.delete.uri')); | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param RuleGroupRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param RuleGroup                    $ruleGroup | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function down(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $repository->moveDown($ruleGroup); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return redirect(route('rules.index')); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param RuleGroup $ruleGroup | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-01-15 13:09:27 +01:00
										 |  |  |     public function edit(RuleGroup $ruleGroup) | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $subTitle = trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // put previous url in session if not redirect from store (not "return_to_edit").
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (true !== session('rule-groups.edit.fromUpdate')) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |             $this->rememberPreviousUri('rule-groups.edit.uri'); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-12-18 21:04:53 +01:00
										 |  |  |         Session::forget('rule-groups.edit.fromUpdate'); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return view('rules.rule-group.edit', compact('ruleGroup', 'subTitle')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |      * Execute the given rulegroup on a set of existing transactions. | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-10-10 07:25:27 +02:00
										 |  |  |      * @param SelectTransactionsRequest  $request | 
					
						
							|  |  |  |      * @param AccountRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param RuleGroup                  $ruleGroup | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return \Illuminate\Http\RedirectResponse | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-10-10 07:25:27 +02:00
										 |  |  |     public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, RuleGroup $ruleGroup) | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         // Get parameters specified by the user
 | 
					
						
							| 
									
										
										
										
											2016-10-10 07:25:27 +02:00
										 |  |  |         $accounts  = $repository->getAccountsById($request->get('accounts')); | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |         $startDate = new Carbon($request->get('start_date')); | 
					
						
							|  |  |  |         $endDate   = new Carbon($request->get('end_date')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Create a job to do the work asynchronously
 | 
					
						
							|  |  |  |         $job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Apply parameters to the job
 | 
					
						
							| 
									
										
										
										
											2016-09-16 12:15:58 +02:00
										 |  |  |         $job->setUser(auth()->user()); | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |         $job->setAccounts($accounts); | 
					
						
							|  |  |  |         $job->setStartDate($startDate); | 
					
						
							|  |  |  |         $job->setEndDate($endDate); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Dispatch a new job to execute it in a queue
 | 
					
						
							|  |  |  |         $this->dispatch($job); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Tell the user that the job is queued
 | 
					
						
							| 
									
										
										
										
											2017-07-16 13:04:45 +02:00
										 |  |  |         Session::flash('success', strval(trans('firefly.applied_rule_group_selection', ['title' => $ruleGroup->title]))); | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return redirect()->route('rules.index'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-10-10 07:49:39 +02:00
										 |  |  |      * @param AccountRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param RuleGroup                  $ruleGroup | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-10-10 07:49:39 +02:00
										 |  |  |     public function selectTransactions(AccountRepositoryInterface $repository, RuleGroup $ruleGroup) | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         // does the user have shared accounts?
 | 
					
						
							| 
									
										
										
										
											2016-10-10 07:49:39 +02:00
										 |  |  |         $accounts        = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |         $accountList     = ExpandedForm::makeSelectList($accounts); | 
					
						
							|  |  |  |         $checkedAccounts = array_keys($accountList); | 
					
						
							|  |  |  |         $first           = session('first')->format('Y-m-d'); | 
					
						
							|  |  |  |         $today           = Carbon::create()->format('Y-m-d'); | 
					
						
							| 
									
										
										
										
											2017-07-16 13:04:45 +02:00
										 |  |  |         $subTitle        = (string)trans('firefly.apply_rule_group_selection', ['title' => $ruleGroup->title]); | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-23 16:02:37 +01:00
										 |  |  |         return view('rules.rule-group.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'ruleGroup', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2016-02-23 15:54:13 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-01-15 13:08:25 +01:00
										 |  |  |      * @param RuleGroupFormRequest         $request | 
					
						
							|  |  |  |      * @param RuleGroupRepositoryInterface $repository | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-08-26 09:30:52 +02:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |     public function store(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository) | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-10-29 07:44:46 +02:00
										 |  |  |         $data      = $request->getRuleGroupData(); | 
					
						
							|  |  |  |         $ruleGroup = $repository->store($data); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-20 11:38:01 +01:00
										 |  |  |         Session::flash('success', strval(trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]))); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |         Preferences::mark(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (1 === intval($request->get('create_another'))) { | 
					
						
							| 
									
										
										
										
											2017-03-24 11:07:38 +01:00
										 |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2016-12-18 21:04:53 +01:00
										 |  |  |             Session::put('rule-groups.create.fromStore', true); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-18 21:04:53 +01:00
										 |  |  |             return redirect(route('rule-groups.create'))->withInput(); | 
					
						
							| 
									
										
										
										
											2017-03-24 11:07:38 +01:00
										 |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         return redirect($this->getPreviousUri('rule-groups.create.uri')); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-01-15 13:08:25 +01:00
										 |  |  |      * @param RuleGroupRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param RuleGroup                    $ruleGroup | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |     public function up(RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         $repository->moveUp($ruleGroup); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         return redirect(route('rules.index')); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |      * @param RuleGroupFormRequest         $request | 
					
						
							| 
									
										
										
										
											2016-01-15 13:08:25 +01:00
										 |  |  |      * @param RuleGroupRepositoryInterface $repository | 
					
						
							|  |  |  |      * @param RuleGroup                    $ruleGroup | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-07-23 08:16:11 +02:00
										 |  |  |      * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |     public function update(RuleGroupFormRequest $request, RuleGroupRepositoryInterface $repository, RuleGroup $ruleGroup) | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         $data = [ | 
					
						
							|  |  |  |             'title'       => $request->input('title'), | 
					
						
							|  |  |  |             'description' => $request->input('description'), | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |             'active'      => 1 === intval($request->input('active')), | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         $repository->update($ruleGroup, $data); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-20 11:38:01 +01:00
										 |  |  |         Session::flash('success', strval(trans('firefly.updated_rule_group', ['title' => $ruleGroup->title]))); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |         Preferences::mark(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (1 === intval($request->get('return_to_edit'))) { | 
					
						
							| 
									
										
										
										
											2017-03-24 11:07:38 +01:00
										 |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2016-12-18 21:04:53 +01:00
										 |  |  |             Session::put('rule-groups.edit.fromUpdate', true); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-18 21:04:53 +01:00
										 |  |  |             return redirect(route('rule-groups.edit', [$ruleGroup->id]))->withInput(['return_to_edit' => 1]); | 
					
						
							| 
									
										
										
										
											2017-03-24 11:07:38 +01:00
										 |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         // redirect to previous URL.
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         return redirect($this->getPreviousUri('rule-groups.edit.uri')); | 
					
						
							| 
									
										
										
										
											2016-01-15 13:06:17 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-01-28 21:50:20 +01:00
										 |  |  | } |