| 
									
										
										
										
											2016-10-26 19:45:10 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * BalanceController.php | 
					
						
							|  |  |  |  * Copyright (C) 2016 thegrumpydictator@gmail.com | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This software may be modified and distributed under the terms of the | 
					
						
							|  |  |  |  * Creative Commons Attribution-ShareAlike 4.0 International License. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * See the LICENSE file for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers\Report; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							|  |  |  | use FireflyIII\Helpers\Report\BalanceReportHelperInterface; | 
					
						
							|  |  |  | use FireflyIII\Http\Controllers\Controller; | 
					
						
							|  |  |  | use FireflyIII\Support\CacheProperties; | 
					
						
							|  |  |  | use Illuminate\Support\Collection; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class BalanceController | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package FireflyIII\Http\Controllers\Report | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class BalanceController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param BalanceReportHelperInterface $helper | 
					
						
							| 
									
										
										
										
											2016-12-06 08:59:08 +01:00
										 |  |  |      * @param Collection                   $accounts | 
					
						
							| 
									
										
										
										
											2016-10-26 19:45:10 +02:00
										 |  |  |      * @param Carbon                       $start | 
					
						
							|  |  |  |      * @param Carbon                       $end | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-12-06 08:59:08 +01:00
										 |  |  |      * @return mixed|string | 
					
						
							| 
									
										
										
										
											2016-10-26 19:45:10 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-12-14 18:59:12 +01:00
										 |  |  |     public function general(BalanceReportHelperInterface $helper, Collection $accounts, Carbon $start, Carbon $end) | 
					
						
							| 
									
										
										
										
											2016-10-26 19:45:10 +02:00
										 |  |  |     { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // chart properties for cache:
 | 
					
						
							|  |  |  |         $cache = new CacheProperties; | 
					
						
							|  |  |  |         $cache->addProperty($start); | 
					
						
							|  |  |  |         $cache->addProperty($end); | 
					
						
							|  |  |  |         $cache->addProperty('balance-report'); | 
					
						
							|  |  |  |         $cache->addProperty($accounts->pluck('id')->toArray()); | 
					
						
							|  |  |  |         if ($cache->has()) { | 
					
						
							|  |  |  |             return $cache->get(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-06 08:59:08 +01:00
										 |  |  |         $balance = $helper->getBalanceReport($accounts, $start, $end); | 
					
						
							| 
									
										
										
										
											2016-10-26 19:45:10 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $result = view('reports.partials.balance', compact('balance'))->render(); | 
					
						
							|  |  |  |         $cache->store($result); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $result; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-12-22 19:42:45 +01:00
										 |  |  | } |