| 
									
										
										
										
											2016-05-20 08:57:45 +02:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-05-20 12:27:31 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * ReportController.php | 
					
						
							|  |  |  |  * Copyright (C) 2016 thegrumpydictator@gmail.com | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This software may be modified and distributed under the terms | 
					
						
							|  |  |  |  * of the MIT license.  See the LICENSE file for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 08:57:45 +02:00
										 |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace FireflyIII\Http\Controllers; | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							| 
									
										
										
										
											2016-05-20 11:02:07 +02:00
										 |  |  | use FireflyIII\Crud\Account\AccountCrudInterface; | 
					
						
							| 
									
										
										
										
											2016-02-06 05:01:34 +01:00
										 |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2016-03-02 13:13:33 +01:00
										 |  |  | use FireflyIII\Helpers\Report\AccountReportHelperInterface; | 
					
						
							|  |  |  | use FireflyIII\Helpers\Report\BalanceReportHelperInterface; | 
					
						
							|  |  |  | use FireflyIII\Helpers\Report\BudgetReportHelperInterface; | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  | use FireflyIII\Helpers\Report\ReportHelperInterface; | 
					
						
							|  |  |  | use FireflyIII\Models\Account; | 
					
						
							| 
									
										
										
										
											2016-05-20 11:02:07 +02:00
										 |  |  | use FireflyIII\Models\AccountType; | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							| 
									
										
										
										
											2015-12-30 08:00:52 +01:00
										 |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI; | 
					
						
							| 
									
										
										
										
											2016-05-02 20:49:19 +02:00
										 |  |  | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | 
					
						
							|  |  |  | use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2016-01-29 07:47:18 +01:00
										 |  |  | use Preferences; | 
					
						
							| 
									
										
										
										
											2015-03-04 20:47:00 +01:00
										 |  |  | use Session; | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  | use Steam; | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  | use View; | 
					
						
							| 
									
										
										
										
											2015-03-04 20:47:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Class ReportController | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package FireflyIII\Http\Controllers | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class ReportController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-02 13:13:33 +01:00
										 |  |  |     /** @var AccountReportHelperInterface */ | 
					
						
							| 
									
										
										
										
											2016-01-27 20:45:49 +01:00
										 |  |  |     protected $accountHelper; | 
					
						
							| 
									
										
										
										
											2016-03-02 13:13:33 +01:00
										 |  |  |     /** @var BalanceReportHelperInterface */ | 
					
						
							| 
									
										
										
										
											2016-01-27 21:35:59 +01:00
										 |  |  |     protected $balanceHelper; | 
					
						
							| 
									
										
										
										
											2016-03-02 13:13:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** @var BudgetReportHelperInterface */ | 
					
						
							| 
									
										
										
										
											2016-01-27 21:18:51 +01:00
										 |  |  |     protected $budgetHelper; | 
					
						
							| 
									
										
										
										
											2015-03-29 12:25:46 +02:00
										 |  |  |     /** @var ReportHelperInterface */ | 
					
						
							|  |  |  |     protected $helper; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-09-16 09:36:08 +02:00
										 |  |  |     public function __construct() | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-05-15 22:00:00 +02:00
										 |  |  |         parent::__construct(); | 
					
						
							| 
									
										
										
										
											2016-01-27 20:45:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-15 21:01:24 +02:00
										 |  |  |         View::share('title', trans('firefly.reports')); | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  |         View::share('mainTitleIcon', 'fa-line-chart'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-05-20 11:02:07 +02:00
										 |  |  |      * @param AccountCrudInterface $crud | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-05-20 11:02:07 +02:00
										 |  |  |     public function index(AccountCrudInterface $crud) | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-09-16 09:36:08 +02:00
										 |  |  |         $this->createRepositories(); | 
					
						
							| 
									
										
										
										
											2016-02-05 15:41:40 +01:00
										 |  |  |         /** @var Carbon $start */ | 
					
						
							| 
									
										
										
										
											2016-02-07 09:11:46 +01:00
										 |  |  |         $start            = clone session('first'); | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |         $months           = $this->helper->listOfMonths($start); | 
					
						
							|  |  |  |         $customFiscalYear = Preferences::get('customFiscalYear', 0)->data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // does the user have shared accounts?
 | 
					
						
							| 
									
										
										
										
											2016-05-20 11:02:07 +02:00
										 |  |  |         $accounts = $crud->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |         // get id's for quick links:
 | 
					
						
							|  |  |  |         $accountIds = []; | 
					
						
							|  |  |  |         /** @var Account $account */ | 
					
						
							|  |  |  |         foreach ($accounts as $account) { | 
					
						
							|  |  |  |             $accountIds [] = $account->id; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $accountList = join(',', $accountIds); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return view('reports.index', compact('months', 'accounts', 'start', 'accountList', 'customFiscalYear')); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-02-07 07:56:58 +01:00
										 |  |  |      * @param string     $reportType | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |      * @param Carbon     $start | 
					
						
							|  |  |  |      * @param Carbon     $end | 
					
						
							|  |  |  |      * @param Collection $accounts | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							| 
									
										
										
										
											2016-02-07 07:56:58 +01:00
										 |  |  |      * @throws FireflyException | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-05 09:25:15 +01:00
										 |  |  |     public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts) | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-09-16 09:36:08 +02:00
										 |  |  |         $this->createRepositories(); | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |         // throw an error if necessary.
 | 
					
						
							|  |  |  |         if ($end < $start) { | 
					
						
							| 
									
										
										
										
											2016-02-06 05:04:41 +01:00
										 |  |  |             throw new FireflyException('End date cannot be before start date, silly!'); | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // lower threshold
 | 
					
						
							|  |  |  |         if ($start < session('first')) { | 
					
						
							|  |  |  |             $start = session('first'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |         View::share( | 
					
						
							|  |  |  |             'subTitle', trans( | 
					
						
							|  |  |  |                           'firefly.report_' . $reportType, | 
					
						
							|  |  |  |                           [ | 
					
						
							|  |  |  |                               'start' => $start->formatLocalized($this->monthFormat), | 
					
						
							|  |  |  |                               'end'   => $end->formatLocalized($this->monthFormat), | 
					
						
							|  |  |  |                           ] | 
					
						
							|  |  |  |                       ) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         View::share('subTitleIcon', 'fa-calendar'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |         switch ($reportType) { | 
					
						
							|  |  |  |             default: | 
					
						
							| 
									
										
										
										
											2016-02-23 20:23:10 +01:00
										 |  |  |                 throw new FireflyException('Unfortunately, reports of the type "' . e($reportType) . '" are not yet available. '); | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |             case 'default': | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // more than one year date difference means year report.
 | 
					
						
							|  |  |  |                 if ($start->diffInMonths($end) > 12) { | 
					
						
							|  |  |  |                     return $this->defaultMultiYear($reportType, $start, $end, $accounts); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 // more than two months date difference means year report.
 | 
					
						
							|  |  |  |                 if ($start->diffInMonths($end) > 1) { | 
					
						
							|  |  |  |                     return $this->defaultYear($reportType, $start, $end, $accounts); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |                 // otherwise default
 | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |                 return $this->defaultMonth($reportType, $start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-02-23 20:23:10 +01:00
										 |  |  |             case 'audit': | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |                 // always default
 | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |                 return $this->auditReport($start, $end, $accounts); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-02-23 20:23:10 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param Carbon     $start | 
					
						
							|  |  |  |      * @param Carbon     $end | 
					
						
							|  |  |  |      * @param Collection $accounts | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function auditReport(Carbon $start, Carbon $end, Collection $accounts) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         /** @var ARI $repos */ | 
					
						
							| 
									
										
										
										
											2016-05-01 15:05:29 +02:00
										 |  |  |         $repos     = app(ARI::class); | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |         $auditData = []; | 
					
						
							|  |  |  |         $dayBefore = clone $start; | 
					
						
							|  |  |  |         $dayBefore->subDay(); | 
					
						
							|  |  |  |         /** @var Account $account */ | 
					
						
							|  |  |  |         foreach ($accounts as $account) { | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |             // balance the day before:
 | 
					
						
							|  |  |  |             $id               = $account->id; | 
					
						
							|  |  |  |             $first            = $repos->oldestJournalDate($account); | 
					
						
							|  |  |  |             $last             = $repos->newestJournalDate($account); | 
					
						
							|  |  |  |             $exists           = false; | 
					
						
							|  |  |  |             $journals         = new Collection; | 
					
						
							|  |  |  |             $dayBeforeBalance = Steam::balance($account, $dayBefore); | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |             /* | 
					
						
							|  |  |  |              * Is there even activity on this account between the requested dates? | 
					
						
							|  |  |  |              */ | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |             if ($start->between($first, $last) || $end->between($first, $last)) { | 
					
						
							| 
									
										
										
										
											2016-05-15 18:36:40 +02:00
										 |  |  |                 $exists   = true; | 
					
						
							| 
									
										
										
										
											2016-05-17 16:47:43 +02:00
										 |  |  |                 $journals = $repos->journalsInPeriod(new Collection([$account]), [], $start, $end); | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             /* | 
					
						
							|  |  |  |              * Reverse set, get balances. | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             $journals     = $journals->reverse(); | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |             $startBalance = $dayBeforeBalance; | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |             /** @var TransactionJournal $journal */ | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |             foreach ($journals as $journal) { | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |                 $journal->before   = $startBalance; | 
					
						
							| 
									
										
										
										
											2016-05-17 16:11:19 +02:00
										 |  |  |                 $transactionAmount = $journal->source_amount; | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 // get currently relevant transaction:
 | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |                 if (intval($journal->destination_account_id) === $account->id) { | 
					
						
							| 
									
										
										
										
											2016-05-17 16:11:19 +02:00
										 |  |  |                     $transactionAmount = $journal->destination_amount; | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 $newBalance     = bcadd($startBalance, $transactionAmount); | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |                 $journal->after = $newBalance; | 
					
						
							|  |  |  |                 $startBalance   = $newBalance; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 15:10:07 +02:00
										 |  |  |             /* | 
					
						
							|  |  |  |              * Reverse set again. | 
					
						
							|  |  |  |              */ | 
					
						
							|  |  |  |             $auditData[$id]['journals']         = $journals->reverse(); | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |             $auditData[$id]['exists']           = $exists; | 
					
						
							| 
									
										
										
										
											2016-05-20 08:00:35 +02:00
										 |  |  |             $auditData[$id]['end']              = $end->formatLocalized(strval(trans('config.month_and_day'))); | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |             $auditData[$id]['endBalance']       = Steam::balance($account, $end); | 
					
						
							| 
									
										
										
										
											2016-05-20 08:00:35 +02:00
										 |  |  |             $auditData[$id]['dayBefore']        = $dayBefore->formatLocalized(strval(trans('config.month_and_day'))); | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |             $auditData[$id]['dayBeforeBalance'] = $dayBeforeBalance; | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |         $reportType = 'audit'; | 
					
						
							|  |  |  |         $accountIds = join(',', $accounts->pluck('id')->toArray()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-10 18:37:16 +02:00
										 |  |  |         $hideable    = ['buttons', 'icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', | 
					
						
							| 
									
										
										
										
											2016-09-16 09:36:08 +02:00
										 |  |  |                         'interest_date', 'book_date', 'process_date', | 
					
						
							| 
									
										
										
										
											2016-09-10 18:37:16 +02:00
										 |  |  |                         // three new optional fields.
 | 
					
						
							|  |  |  |                         'due_date', 'payment_date', 'invoice_date', | 
					
						
							|  |  |  |                         'from', 'to', 'budget', 'category', 'bill', | 
					
						
							|  |  |  |                         // more new optional fields
 | 
					
						
							|  |  |  |                         'internal_reference', 'notes', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         'create_date', 'update_date', | 
					
						
							| 
									
										
										
										
											2016-04-08 14:50:18 +02:00
										 |  |  |         ]; | 
					
						
							|  |  |  |         $defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return view('reports.audit.report', compact('start', 'end', 'reportType', 'accountIds', 'accounts', 'auditData', 'hideable', 'defaultShow')); | 
					
						
							| 
									
										
										
										
											2016-02-04 07:28:39 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-16 09:36:08 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function createRepositories() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->helper        = app(ReportHelperInterface::class); | 
					
						
							|  |  |  |         $this->accountHelper = app(AccountReportHelperInterface::class); | 
					
						
							|  |  |  |         $this->budgetHelper  = app(BudgetReportHelperInterface::class); | 
					
						
							|  |  |  |         $this->balanceHelper = app(BalanceReportHelperInterface::class); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-12-28 20:04:54 +01:00
										 |  |  |      * @param            $reportType | 
					
						
							| 
									
										
										
										
											2015-12-12 17:51:07 +01:00
										 |  |  |      * @param Carbon     $start | 
					
						
							|  |  |  |      * @param Carbon     $end | 
					
						
							|  |  |  |      * @param Collection $accounts | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-05 09:25:15 +01:00
										 |  |  |     private function defaultMonth(string $reportType, Carbon $start, Carbon $end, Collection $accounts) | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $incomeTopLength  = 8; | 
					
						
							|  |  |  |         $expenseTopLength = 8; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // get report stuff!
 | 
					
						
							| 
									
										
										
										
											2016-01-27 21:52:21 +01:00
										 |  |  |         $accountReport = $this->accountHelper->getAccountReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $incomes       = $this->helper->getIncomeReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $expenses      = $this->helper->getExpenseReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $budgets       = $this->budgetHelper->getBudgetReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $categories    = $this->helper->getCategoryReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $balance       = $this->balanceHelper->getBalanceReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-01-01 19:52:55 +01:00
										 |  |  |         $bills         = $this->helper->getBillReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-03-01 21:31:25 +01:00
										 |  |  |         $tags          = $this->helper->tagReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2015-12-12 17:51:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // and some id's, joined:
 | 
					
						
							| 
									
										
										
										
											2016-01-01 19:46:12 +01:00
										 |  |  |         $accountIds = join(',', $accounts->pluck('id')->toArray()); | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // continue!
 | 
					
						
							|  |  |  |         return view( | 
					
						
							| 
									
										
										
										
											2015-12-13 09:01:17 +01:00
										 |  |  |             'reports.default.month', | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  |             compact( | 
					
						
							| 
									
										
										
										
											2015-12-28 20:04:54 +01:00
										 |  |  |                 'start', 'end', 'reportType', | 
					
						
							| 
									
										
										
										
											2016-03-01 21:31:25 +01:00
										 |  |  |                 'accountReport', 'tags', | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  |                 'incomes', 'incomeTopLength', | 
					
						
							|  |  |  |                 'expenses', 'expenseTopLength', | 
					
						
							| 
									
										
										
										
											2015-12-12 17:51:07 +01:00
										 |  |  |                 'budgets', 'balance', | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  |                 'categories', | 
					
						
							| 
									
										
										
										
											2015-12-12 17:51:07 +01:00
										 |  |  |                 'bills', | 
					
						
							| 
									
										
										
										
											2015-12-28 20:04:54 +01:00
										 |  |  |                 'accountIds', 'reportType' | 
					
						
							| 
									
										
										
										
											2015-12-06 13:11:43 +01:00
										 |  |  |             ) | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-12-12 19:04:30 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-28 07:55:09 +01:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2015-12-28 20:04:54 +01:00
										 |  |  |      * @param $reportType | 
					
						
							| 
									
										
										
										
											2015-12-28 07:55:09 +01:00
										 |  |  |      * @param $start | 
					
						
							|  |  |  |      * @param $end | 
					
						
							|  |  |  |      * @param $accounts | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-05 09:25:15 +01:00
										 |  |  |     private function defaultMultiYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts) | 
					
						
							| 
									
										
										
										
											2015-12-13 17:31:25 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-12-14 20:45:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-05 21:23:58 +01:00
										 |  |  |         $incomeTopLength  = 8; | 
					
						
							|  |  |  |         $expenseTopLength = 8; | 
					
						
							| 
									
										
										
										
											2015-12-13 17:31:25 +01:00
										 |  |  |         // list of users stuff:
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:49:19 +02:00
										 |  |  |         $budgets       = app(BudgetRepositoryInterface::class)->getActiveBudgets(); | 
					
						
							|  |  |  |         $categories    = app(CategoryRepositoryInterface::class)->getCategories(); | 
					
						
							| 
									
										
										
										
											2016-01-27 21:52:21 +01:00
										 |  |  |         $accountReport = $this->accountHelper->getAccountReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $incomes       = $this->helper->getIncomeReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $expenses      = $this->helper->getExpenseReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-03-02 07:08:08 +01:00
										 |  |  |         $tags          = $this->helper->tagReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2015-12-13 17:31:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // and some id's, joined:
 | 
					
						
							|  |  |  |         $accountIds = []; | 
					
						
							|  |  |  |         /** @var Account $account */ | 
					
						
							|  |  |  |         foreach ($accounts as $account) { | 
					
						
							|  |  |  |             $accountIds[] = $account->id; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-12-15 12:38:18 +01:00
										 |  |  |         $accountIds = join(',', $accountIds); | 
					
						
							| 
									
										
										
										
											2015-12-13 17:31:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-14 20:34:08 +01:00
										 |  |  |         return view( | 
					
						
							| 
									
										
										
										
											2016-01-05 21:23:58 +01:00
										 |  |  |             'reports.default.multi-year', | 
					
						
							|  |  |  |             compact( | 
					
						
							|  |  |  |                 'budgets', 'accounts', 'categories', 'start', 'end', 'accountIds', 'reportType', 'accountReport', 'incomes', 'expenses', | 
					
						
							| 
									
										
										
										
											2016-03-02 07:08:08 +01:00
										 |  |  |                 'incomeTopLength', 'expenseTopLength', 'tags' | 
					
						
							| 
									
										
										
										
											2016-01-05 21:23:58 +01:00
										 |  |  |             ) | 
					
						
							| 
									
										
										
										
											2015-12-14 20:34:08 +01:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-12-13 17:31:25 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param            $reportType | 
					
						
							|  |  |  |      * @param Carbon     $start | 
					
						
							|  |  |  |      * @param Carbon     $end | 
					
						
							|  |  |  |      * @param Collection $accounts | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return View | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-02-05 09:25:15 +01:00
										 |  |  |     private function defaultYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts) | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         $incomeTopLength  = 8; | 
					
						
							|  |  |  |         $expenseTopLength = 8; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-27 20:46:38 +01:00
										 |  |  |         $accountReport = $this->accountHelper->getAccountReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         $incomes       = $this->helper->getIncomeReport($start, $end, $accounts); | 
					
						
							|  |  |  |         $expenses      = $this->helper->getExpenseReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-03-01 21:31:25 +01:00
										 |  |  |         $tags          = $this->helper->tagReport($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-06-16 20:52:59 +02:00
										 |  |  |         $budgets       = $this->budgetHelper->budgetYearOverview($start, $end, $accounts); | 
					
						
							| 
									
										
										
										
											2016-04-24 20:00:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |         Session::flash('gaEventCategory', 'report'); | 
					
						
							|  |  |  |         Session::flash('gaEventAction', 'year'); | 
					
						
							|  |  |  |         Session::flash('gaEventLabel', $start->format('Y')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // and some id's, joined:
 | 
					
						
							|  |  |  |         $accountIds = []; | 
					
						
							|  |  |  |         /** @var Account $account */ | 
					
						
							|  |  |  |         foreach ($accounts as $account) { | 
					
						
							|  |  |  |             $accountIds[] = $account->id; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         $accountIds = join(',', $accountIds); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return view( | 
					
						
							|  |  |  |             'reports.default.year', | 
					
						
							|  |  |  |             compact( | 
					
						
							|  |  |  |                 'start', 'accountReport', 'incomes', 'reportType', 'accountIds', 'end', | 
					
						
							| 
									
										
										
										
											2016-05-15 16:13:05 +02:00
										 |  |  |                 'expenses', 'incomeTopLength', 'expenseTopLength', 'tags', 'budgets' | 
					
						
							| 
									
										
										
										
											2016-01-24 15:58:16 +01:00
										 |  |  |             ) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-23 20:25:48 +01:00
										 |  |  | } |