| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2020-06-30 19:05:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * ShowController.php | 
					
						
							|  |  |  |  * Copyright (c) 2020 james@firefly-iii.org | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program 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 Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers\PiggyBank; | 
					
						
							| 
									
										
										
										
											2021-03-28 11:46:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2023-02-22 18:03:31 +01:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  | use FireflyIII\Http\Controllers\Controller; | 
					
						
							|  |  |  | use FireflyIII\Models\PiggyBank; | 
					
						
							|  |  |  | use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2025-08-06 09:18:29 +02:00
										 |  |  | use FireflyIII\Support\JsonApi\Enrichments\PiggyBankEnrichment; | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  | use FireflyIII\Transformers\PiggyBankTransformer; | 
					
						
							| 
									
										
										
										
											2025-08-06 09:18:29 +02:00
										 |  |  | use FireflyIII\User; | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  | use Illuminate\Contracts\View\Factory; | 
					
						
							|  |  |  | use Illuminate\View\View; | 
					
						
							|  |  |  | use Symfony\Component\HttpFoundation\ParameterBag; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class ShowController | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class ShowController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     private PiggyBankRepositoryInterface $piggyRepos; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * PiggyBankController constructor. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::__construct(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->middleware( | 
					
						
							|  |  |  |             function ($request, $next) { | 
					
						
							| 
									
										
										
										
											2024-12-22 08:43:12 +01:00
										 |  |  |                 app('view')->share('title', (string) trans('firefly.piggyBanks')); | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  |                 app('view')->share('mainTitleIcon', 'fa-bullseye'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $this->piggyRepos = app(PiggyBankRepositoryInterface::class); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return $next($request); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Show a single piggy bank. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return Factory|View | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-02-22 18:03:31 +01:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2023-12-22 20:12:38 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  |     public function show(PiggyBank $piggyBank) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** @var Carbon $end */ | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $end         = session('end', today(config('app.timezone'))->endOfMonth()); | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  |         // transform piggies using the transformer:
 | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $parameters  = new ParameterBag(); | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  |         $parameters->set('end', $end); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-06 09:18:29 +02:00
										 |  |  |         // enrich
 | 
					
						
							|  |  |  |         /** @var User $admin */ | 
					
						
							|  |  |  |         $admin       = auth()->user(); | 
					
						
							|  |  |  |         $enrichment  = new PiggyBankEnrichment(); | 
					
						
							|  |  |  |         $enrichment->setUser($admin); | 
					
						
							| 
									
										
										
										
											2025-09-07 07:56:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-07 07:31:00 +02:00
										 |  |  |         /** @var PiggyBank $piggyBank */ | 
					
						
							| 
									
										
										
										
											2025-08-06 20:39:55 +02:00
										 |  |  |         $piggyBank   = $enrichment->enrichSingle($piggyBank); | 
					
						
							| 
									
										
										
										
											2025-08-06 09:18:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  |         /** @var PiggyBankTransformer $transformer */ | 
					
						
							|  |  |  |         $transformer = app(PiggyBankTransformer::class); | 
					
						
							|  |  |  |         $transformer->setParameters($parameters); | 
					
						
							|  |  |  |         $piggy       = $transformer->transform($piggyBank); | 
					
						
							|  |  |  |         $events      = $this->piggyRepos->getEvents($piggyBank); | 
					
						
							|  |  |  |         $subTitle    = $piggyBank->name; | 
					
						
							|  |  |  |         $attachments = $this->piggyRepos->getAttachments($piggyBank); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-14 17:32:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-29 14:11:12 +01:00
										 |  |  |         return view('piggy-banks.show', compact('piggyBank', 'events', 'subTitle', 'piggy', 'attachments')); | 
					
						
							| 
									
										
										
										
											2020-06-07 11:30:02 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |