| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2022-12-29 19:42:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * AccountController.php | 
					
						
							| 
									
										
										
										
											2020-01-31 07:32:04 +01:00
										 |  |  |  * Copyright (c) 2019 james@firefly-iii.org | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This file is part of Firefly III (https://github.com/firefly-iii). | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +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. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-10-02 06:37:26 +02:00
										 |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +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. | 
					
						
							| 
									
										
										
										
											2017-10-21 08:40:00 +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/>. | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-04-09 07:44:22 +02:00
										 |  |  | declare(strict_types=1); | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers\Report; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2022-11-02 06:25:37 +01:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  | use FireflyIII\Http\Controllers\Controller; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Account\AccountTaskerInterface; | 
					
						
							| 
									
										
										
										
											2016-10-26 16:46:43 +02:00
										 |  |  | use FireflyIII\Support\CacheProperties; | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2017-11-15 12:25:49 +01:00
										 |  |  |  * Class AccountController. | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | class AccountController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2018-07-21 08:55:32 +02:00
										 |  |  |      * Show partial overview for account balances. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2023-02-22 18:03:31 +01:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2023-06-04 06:30:22 +02:00
										 |  |  |     public function general(Collection $accounts, Carbon $start, Carbon $end): string | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-10-26 16:46:43 +02:00
										 |  |  |         // chart properties for cache:
 | 
					
						
							| 
									
										
										
										
											2024-01-01 14:43:56 +01:00
										 |  |  |         $cache         = new CacheProperties(); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:46:43 +02:00
										 |  |  |         $cache->addProperty($start); | 
					
						
							|  |  |  |         $cache->addProperty($end); | 
					
						
							|  |  |  |         $cache->addProperty('account-report'); | 
					
						
							|  |  |  |         $cache->addProperty($accounts->pluck('id')->toArray()); | 
					
						
							|  |  |  |         if ($cache->has()) { | 
					
						
							| 
									
										
										
										
											2021-09-18 10:26:12 +02:00
										 |  |  |             return $cache->get(); | 
					
						
							| 
									
										
										
										
											2016-10-26 16:46:43 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-06 08:59:08 +01:00
										 |  |  |         /** @var AccountTaskerInterface $accountTasker */ | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  |         $accountTasker = app(AccountTaskerInterface::class); | 
					
						
							| 
									
										
										
										
											2016-12-06 08:59:08 +01:00
										 |  |  |         $accountReport = $accountTasker->getAccountReport($accounts, $start, $end); | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-07 19:29:40 +02:00
										 |  |  |         try { | 
					
						
							| 
									
										
										
										
											2022-01-29 14:11:12 +01:00
										 |  |  |             $result = view('reports.partials.accounts', compact('accountReport'))->render(); | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  |         } catch (\Throwable $e) { | 
					
						
							| 
									
										
										
										
											2023-10-29 06:32:00 +01:00
										 |  |  |             app('log')->error(sprintf('Could not render reports.partials.accounts: %s', $e->getMessage())); | 
					
						
							|  |  |  |             app('log')->error($e->getTraceAsString()); | 
					
						
							| 
									
										
										
										
											2018-08-07 19:29:40 +02:00
										 |  |  |             $result = 'Could not render view.'; | 
					
						
							| 
									
										
										
										
											2023-12-20 19:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-02 06:25:37 +01:00
										 |  |  |             throw new FireflyException($result, 0, $e); | 
					
						
							| 
									
										
										
										
											2018-08-07 19:29:40 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-04-07 07:28:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 16:46:43 +02:00
										 |  |  |         $cache->store($result); | 
					
						
							| 
									
										
										
										
											2016-10-29 07:44:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-26 16:46:43 +02:00
										 |  |  |         return $result; | 
					
						
							| 
									
										
										
										
											2016-10-08 16:24:07 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-10-23 12:42:44 +02:00
										 |  |  | } |