| 
									
										
										
										
											2016-05-20 08:57:45 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * CurrencyController.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-04-09 07:44:22 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2016-05-20 08:57:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-10 17:26:31 +01:00
										 |  |  | use Cache; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | use FireflyIII\Http\Requests\CurrencyFormRequest; | 
					
						
							|  |  |  | use FireflyIII\Models\TransactionCurrency; | 
					
						
							| 
									
										
										
										
											2015-04-05 20:47:19 +02:00
										 |  |  | use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  | use FireflyIII\Repositories\User\UserRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2017-12-28 09:53:21 +01:00
										 |  |  | use Illuminate\Pagination\LengthAwarePaginator; | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  | use Log; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | use Preferences; | 
					
						
							| 
									
										
										
										
											2015-04-05 20:47:19 +02:00
										 |  |  | use View; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class CurrencyController. | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | class CurrencyController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |     /** @var CurrencyRepositoryInterface */ | 
					
						
							|  |  |  |     protected $repository; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |     /** @var UserRepositoryInterface */ | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |     protected $userRepository; | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-02-04 07:27:03 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-04-28 15:26:30 +02:00
										 |  |  |         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.currencies')); | 
					
						
							|  |  |  |                 app('view')->share('mainTitleIcon', 'fa-usd'); | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |                 $this->repository     = app(CurrencyRepositoryInterface::class); | 
					
						
							|  |  |  |                 $this->userRepository = app(UserRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2016-10-29 07:44:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 return $next($request); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-02-25 05:57:01 +01:00
										 |  |  |      * @param Request $request | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |     public function create(Request $request) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | 
					
						
							|  |  |  |             $request->session()->flash('error', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return redirect(route('currencies.index')); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |         $subTitleIcon = 'fa-plus'; | 
					
						
							| 
									
										
										
										
											2015-06-09 17:56:08 +02:00
										 |  |  |         $subTitle     = trans('firefly.create_currency'); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 18:59:34 +02:00
										 |  |  |         // put previous url in session if not redirect from store (not "create another").
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (true !== session('currencies.create.fromStore')) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |             $this->rememberPreviousUri('currencies.create.uri'); | 
					
						
							| 
									
										
										
										
											2015-04-01 18:59:34 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |         $request->session()->forget('currencies.create.fromStore'); | 
					
						
							| 
									
										
										
										
											2015-04-01 18:59:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |         return view('currencies.create', compact('subTitleIcon', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |      * @param Request             $request | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      * @param TransactionCurrency $currency | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |     public function defaultCurrency(Request $request, TransactionCurrency $currency) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-04-05 20:47:19 +02:00
										 |  |  |         Preferences::set('currencyPreference', $currency->code); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:44:50 +02:00
										 |  |  |         Preferences::mark(); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |         $request->session()->flash('success', trans('firefly.new_default_currency', ['name' => $currency->name])); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |         Cache::forget('FFCURRENCYSYMBOL'); | 
					
						
							|  |  |  |         Cache::forget('FFCURRENCYCODE'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |         return redirect(route('currencies.index')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @param Request             $request | 
					
						
							|  |  |  |      * @param TransactionCurrency $currency | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-12-11 16:25:46 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |     public function delete(Request $request, TransactionCurrency $currency) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | 
					
						
							|  |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							|  |  |  |             $request->session()->flash('error', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return redirect(route('currencies.index')); | 
					
						
							|  |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!$this->repository->canDeleteCurrency($currency)) { | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |             $request->session()->flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name])); | 
					
						
							| 
									
										
										
										
											2015-04-01 18:59:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |             return redirect(route('currencies.index')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-05 20:47:19 +02:00
										 |  |  |         // put previous url in session
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         $this->rememberPreviousUri('currencies.delete.uri'); | 
					
						
							| 
									
										
										
										
											2015-06-21 15:09:10 +02:00
										 |  |  |         $subTitle = trans('form.delete_currency', ['name' => $currency->name]); | 
					
						
							| 
									
										
										
										
											2015-04-05 20:47:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |         return view('currencies.delete', compact('currency', 'subTitle')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @param Request             $request | 
					
						
							|  |  |  |      * @param TransactionCurrency $currency | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-12-11 16:25:46 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |     public function destroy(Request $request, TransactionCurrency $currency) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | 
					
						
							|  |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							|  |  |  |             $request->session()->flash('error', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return redirect(route('currencies.index')); | 
					
						
							|  |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!$this->repository->canDeleteCurrency($currency)) { | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |             $request->session()->flash('error', trans('firefly.cannot_delete_currency', ['name' => $currency->name])); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |             return redirect(route('currencies.index')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         $this->repository->destroy($currency); | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |         $request->session()->flash('success', trans('firefly.deleted_currency', ['name' => $currency->name])); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         return redirect($this->getPreviousUri('currencies.delete.uri')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |      * @param Request             $request | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      * @param TransactionCurrency $currency | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |     public function edit(Request $request, TransactionCurrency $currency) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | 
					
						
							|  |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							|  |  |  |             $request->session()->flash('error', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return redirect(route('currencies.index')); | 
					
						
							|  |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |         $subTitleIcon     = 'fa-pencil'; | 
					
						
							| 
									
										
										
										
											2016-09-09 11:19:19 +02:00
										 |  |  |         $subTitle         = trans('breadcrumbs.edit_currency', ['name' => $currency->name]); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |         $currency->symbol = htmlentities($currency->symbol); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 18:59:34 +02:00
										 |  |  |         // 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('currencies.edit.fromUpdate')) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |             $this->rememberPreviousUri('currencies.edit.uri'); | 
					
						
							| 
									
										
										
										
											2015-04-01 18:59:34 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |         $request->session()->forget('currencies.edit.fromUpdate'); | 
					
						
							| 
									
										
										
										
											2015-04-01 18:59:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |         return view('currencies.edit', compact('currency', 'subTitle', 'subTitleIcon')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @param Request $request | 
					
						
							| 
									
										
										
										
											2015-05-03 12:58:55 +02:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-08-26 09:30:52 +02:00
										 |  |  |      * @return View | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |     public function index(Request $request) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-12-28 09:53:21 +01:00
										 |  |  |         $page       = 0 === intval($request->get('page')) ? 1 : intval($request->get('page')); | 
					
						
							|  |  |  |         $pageSize   = intval(Preferences::get('listPageSize', 50)->data); | 
					
						
							|  |  |  |         $collection = $this->repository->get(); | 
					
						
							|  |  |  |         $total      = $collection->count(); | 
					
						
							|  |  |  |         $collection = $collection->sortBy( | 
					
						
							| 
									
										
										
										
											2017-12-08 19:35:09 +01:00
										 |  |  |             function (TransactionCurrency $currency) { | 
					
						
							|  |  |  |                 return $currency->name; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2017-12-28 09:53:21 +01:00
										 |  |  |         $collection = $collection->slice(($page - 1) * $pageSize, $pageSize); | 
					
						
							|  |  |  |         $currencies = new LengthAwarePaginator($collection, $total, $pageSize, $page); | 
					
						
							|  |  |  |         $currencies->setPath(route('currencies.index')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         $defaultCurrency = $this->repository->getCurrencyByPreference(Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'))); | 
					
						
							| 
									
										
										
										
											2017-11-05 19:49:20 +01:00
										 |  |  |         $isOwner         = true; | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |             $request->session()->flash('info', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')])); | 
					
						
							| 
									
										
										
										
											2017-10-20 08:00:13 +02:00
										 |  |  |             $isOwner = false; | 
					
						
							| 
									
										
										
										
											2015-05-28 06:43:07 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 19:49:20 +01:00
										 |  |  |         return view('currencies.index', compact('currencies', 'defaultCurrency', 'isOwner')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @param CurrencyFormRequest $request | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |     public function store(CurrencyFormRequest $request) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | 
					
						
							|  |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2016-09-16 12:15:58 +02:00
										 |  |  |             Log::error('User ' . auth()->user()->id . ' is not admin, but tried to store a currency.'); | 
					
						
							| 
									
										
										
										
											2016-04-29 08:56:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |             return redirect($this->getPreviousUri('currencies.create.uri')); | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2015-05-28 06:43:07 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 08:56:56 +02:00
										 |  |  |         $data     = $request->getCurrencyData(); | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         $currency = $this->repository->store($data); | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |         $request->session()->flash('success', trans('firefly.created_currency', ['name' => $currency->name])); | 
					
						
							| 
									
										
										
										
											2016-04-29 08:56:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (1 === intval($request->get('create_another'))) { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |             $request->session()->put('currencies.create.fromStore', true); | 
					
						
							| 
									
										
										
										
											2015-04-05 20:47:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |             return redirect(route('currencies.create'))->withInput(); | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         return redirect($this->getPreviousUri('currencies.create.uri')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @param CurrencyFormRequest $request | 
					
						
							|  |  |  |      * @param TransactionCurrency $currency | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |     public function update(CurrencyFormRequest $request, TransactionCurrency $currency) | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |         if (!$this->userRepository->hasRole(auth()->user(), 'owner')) { | 
					
						
							|  |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							|  |  |  |             $request->session()->flash('error', trans('firefly.ask_site_owner', ['owner' => env('SITE_OWNER')])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return redirect(route('currencies.index')); | 
					
						
							|  |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2015-05-28 06:43:07 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $data     = $request->getCurrencyData(); | 
					
						
							|  |  |  |         $currency = $this->repository->update($currency, $data); | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |         $request->session()->flash('success', trans('firefly.updated_currency', ['name' => $currency->name])); | 
					
						
							| 
									
										
										
										
											2015-06-02 17:44:50 +02:00
										 |  |  |         Preferences::mark(); | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |         if (1 === intval($request->get('return_to_edit'))) { | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |             // @codeCoverageIgnoreStart
 | 
					
						
							| 
									
										
										
										
											2017-02-17 20:14:22 +01:00
										 |  |  |             $request->session()->put('currencies.edit.fromUpdate', true); | 
					
						
							| 
									
										
										
										
											2015-04-05 20:47:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-05 20:01:01 +01:00
										 |  |  |             return redirect(route('currencies.edit', [$currency->id])); | 
					
						
							| 
									
										
										
										
											2017-03-19 17:54:21 +01:00
										 |  |  |             // @codeCoverageIgnoreEnd
 | 
					
						
							| 
									
										
										
										
											2015-03-02 20:05:28 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 08:26:54 +01:00
										 |  |  |         return redirect($this->getPreviousUri('currencies.edit.uri')); | 
					
						
							| 
									
										
										
										
											2015-02-25 15:57:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } |