| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * ReportController.php | 
					
						
							| 
									
										
										
										
											2016-04-01 16:44:46 +02:00
										 |  |  |  * Copyright (C) 2016 thegrumpydictator@gmail.com | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-10-05 06:52:15 +02:00
										 |  |  |  * 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. | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-20 12:41:23 +02:00
										 |  |  | declare(strict_types = 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | namespace FireflyIII\Http\Controllers\Popup; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use Carbon\Carbon; | 
					
						
							|  |  |  | use FireflyIII\Exceptions\FireflyException; | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  | use FireflyIII\Helpers\Collection\BalanceLine; | 
					
						
							| 
									
										
										
										
											2016-11-05 08:46:55 +01:00
										 |  |  | use FireflyIII\Helpers\Collector\JournalCollector; | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | use FireflyIII\Http\Controllers\Controller; | 
					
						
							| 
									
										
										
										
											2016-10-09 21:36:03 +02:00
										 |  |  | use FireflyIII\Models\Transaction; | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  | use FireflyIII\Models\TransactionJournal; | 
					
						
							| 
									
										
										
										
											2016-05-13 15:53:39 +02:00
										 |  |  | use FireflyIII\Models\TransactionType; | 
					
						
							| 
									
										
										
										
											2016-10-10 07:12:39 +02:00
										 |  |  | use FireflyIII\Repositories\Account\AccountRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2016-05-08 13:45:23 +02:00
										 |  |  | use FireflyIII\Repositories\Category\CategoryRepositoryInterface; | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | use FireflyIII\Support\Binder\AccountList; | 
					
						
							|  |  |  | use Illuminate\Http\Request; | 
					
						
							| 
									
										
										
										
											2016-05-05 22:03:35 +02:00
										 |  |  | use Illuminate\Support\Collection; | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | use InvalidArgumentException; | 
					
						
							|  |  |  | use Response; | 
					
						
							| 
									
										
										
										
											2016-04-03 14:55:56 +02:00
										 |  |  | use View; | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Class ReportController | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package FireflyIII\Http\Controllers\Popup | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class ReportController extends Controller | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * @param Request $request | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-05-15 09:00:49 +02:00
										 |  |  |      * @return \Illuminate\Http\JsonResponse | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-12-06 09:07:50 +01:00
										 |  |  |     public function general(Request $request) | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-22 15:48:34 +02:00
										 |  |  |         $attributes = $request->get('attributes') ?? []; | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |         $attributes = $this->parseAttributes($attributes); | 
					
						
							| 
									
										
										
										
											2016-04-03 14:55:56 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         View::share('start', $attributes['startDate']); | 
					
						
							|  |  |  |         View::share('end', $attributes['endDate']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |         switch ($attributes['location']) { | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 throw new FireflyException('Firefly cannot handle "' . e($attributes['location']) . '" '); | 
					
						
							|  |  |  |             case 'budget-spent-amount': | 
					
						
							|  |  |  |                 $html = $this->budgetSpentAmount($attributes); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 11:07:51 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             case 'expense-entry': | 
					
						
							|  |  |  |                 $html = $this->expenseEntry($attributes); | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2016-04-03 11:14:36 +02:00
										 |  |  |             case 'income-entry': | 
					
						
							|  |  |  |                 $html = $this->incomeEntry($attributes); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2016-04-03 11:20:55 +02:00
										 |  |  |             case 'category-entry': | 
					
						
							|  |  |  |                 $html = $this->categoryEntry($attributes); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |             case 'balance-amount': | 
					
						
							|  |  |  |                 $html = $this->balanceAmount($attributes); | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return Response::json(['html' => $html]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param $attributes | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function balanceAmount(array $attributes): string | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $role = intval($attributes['role']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /** @var BudgetRepositoryInterface $budgetRepository */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:49:19 +02:00
										 |  |  |         $budgetRepository = app(BudgetRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |         $budget           = $budgetRepository->find(intval($attributes['budgetId'])); | 
					
						
							| 
									
										
										
										
											2016-10-10 07:12:39 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /** @var AccountRepositoryInterface $repository */ | 
					
						
							|  |  |  |         $repository = app(AccountRepositoryInterface::class); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $account = $repository->find(intval($attributes['accountId'])); | 
					
						
							| 
									
										
										
										
											2016-11-05 18:08:44 +01:00
										 |  |  |         $types   = [TransactionType::WITHDRAWAL]; | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         switch (true) { | 
					
						
							|  |  |  |             case ($role === BalanceLine::ROLE_DEFAULTROLE && !is_null($budget->id)): | 
					
						
							| 
									
										
										
										
											2016-11-05 17:47:50 +01:00
										 |  |  |                 $collector = new JournalCollector(auth()->user()); | 
					
						
							|  |  |  |                 $collector | 
					
						
							|  |  |  |                     ->setAccounts(new Collection([$account])) | 
					
						
							|  |  |  |                     ->setRange($attributes['startDate'], $attributes['endDate']) | 
					
						
							|  |  |  |                     ->setBudget($budget); | 
					
						
							|  |  |  |                 $journals = $collector->getJournals(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             case ($role === BalanceLine::ROLE_DEFAULTROLE && is_null($budget->id)): | 
					
						
							| 
									
										
										
										
											2016-04-03 14:55:56 +02:00
										 |  |  |                 $budget->name = strval(trans('firefly.no_budget')); | 
					
						
							| 
									
										
										
										
											2016-11-05 18:08:44 +01:00
										 |  |  |                 // collector
 | 
					
						
							|  |  |  |                 $collector = new JournalCollector(auth()->user()); | 
					
						
							|  |  |  |                 $collector | 
					
						
							|  |  |  |                     ->setAccounts(new Collection([$account])) | 
					
						
							|  |  |  |                     ->setTypes($types) | 
					
						
							|  |  |  |                     ->setRange($attributes['startDate'], $attributes['endDate']) | 
					
						
							|  |  |  |                     ->withoutBudget(); | 
					
						
							|  |  |  |                 $journals = $collector->getJournals(); | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             case ($role === BalanceLine::ROLE_DIFFROLE): | 
					
						
							|  |  |  |                 // journals no budget, not corrected by a tag.
 | 
					
						
							| 
									
										
										
										
											2016-11-05 18:08:44 +01:00
										 |  |  |                 $collector = new JournalCollector(auth()->user()); | 
					
						
							|  |  |  |                 $collector | 
					
						
							|  |  |  |                     ->setAccounts(new Collection([$account])) | 
					
						
							|  |  |  |                     ->setTypes($types) | 
					
						
							|  |  |  |                     ->setRange($attributes['startDate'], $attributes['endDate']) | 
					
						
							|  |  |  |                     ->withoutBudget(); | 
					
						
							|  |  |  |                 $journals = $collector->getJournals(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 14:55:56 +02:00
										 |  |  |                 $budget->name = strval(trans('firefly.leftUnbalanced')); | 
					
						
							| 
									
										
										
										
											2016-04-25 18:43:09 +02:00
										 |  |  |                 $journals     = $journals->filter( | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |                     function (TransactionJournal $journal) { | 
					
						
							|  |  |  |                         $tags = $journal->tags()->where('tagMode', 'balancingAct')->count(); | 
					
						
							|  |  |  |                         if ($tags === 0) { | 
					
						
							| 
									
										
										
										
											2016-08-26 09:30:52 +02:00
										 |  |  |                             return true; | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |                         } | 
					
						
							| 
									
										
										
										
											2016-09-16 12:07:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 09:30:52 +02:00
										 |  |  |                         return false; | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case ($role === BalanceLine::ROLE_TAGROLE): | 
					
						
							|  |  |  |                 throw new FireflyException('Firefly cannot handle this type of info-button (BalanceLine::TagRole)'); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-04-03 14:55:56 +02:00
										 |  |  |         $view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render(); | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $view; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-04-03 11:07:51 +02:00
										 |  |  |      * Returns all expenses inside the given budget for the given accounts. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |      * @param array $attributes | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function budgetSpentAmount(array $attributes): string | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // need to find the budget
 | 
					
						
							|  |  |  |         // then search for expenses in the given period
 | 
					
						
							|  |  |  |         // list them in some table format.
 | 
					
						
							|  |  |  |         /** @var BudgetRepositoryInterface $repository */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:49:19 +02:00
										 |  |  |         $repository = app(BudgetRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |         $budget     = $repository->find(intval($attributes['budgetId'])); | 
					
						
							| 
									
										
										
										
											2016-11-05 18:08:44 +01:00
										 |  |  |         $collector  = new JournalCollector(auth()->user()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $collector | 
					
						
							|  |  |  |             ->setAccounts($attributes['accounts']) | 
					
						
							|  |  |  |             ->setRange($attributes['startDate'], $attributes['endDate']); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |         if (is_null($budget->id)) { | 
					
						
							| 
									
										
										
										
											2016-11-05 18:08:44 +01:00
										 |  |  |             $collector->setTypes([TransactionType::WITHDRAWAL])->withoutBudget(); | 
					
						
							| 
									
										
										
										
											2016-11-05 17:47:50 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         if (!is_null($budget->id)) { | 
					
						
							| 
									
										
										
										
											2016-04-01 16:23:12 +02:00
										 |  |  |             // get all expenses in budget in period:
 | 
					
						
							| 
									
										
										
										
											2016-11-05 18:08:44 +01:00
										 |  |  |             $collector->setBudget($budget); | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-11-05 18:08:44 +01:00
										 |  |  |         $journals = $collector->getJournals(); | 
					
						
							|  |  |  |         $view     = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render(); | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $view; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 11:14:36 +02:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2016-04-03 11:20:55 +02:00
										 |  |  |      * Returns all expenses in category in range. | 
					
						
							| 
									
										
										
										
											2016-04-03 11:14:36 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param $attributes | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |     private function categoryEntry(array $attributes): string | 
					
						
							| 
									
										
										
										
											2016-04-03 11:14:36 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-05-08 13:45:23 +02:00
										 |  |  |         /** @var CategoryRepositoryInterface $repository */ | 
					
						
							|  |  |  |         $repository = app(CategoryRepositoryInterface::class); | 
					
						
							| 
									
										
										
										
											2016-04-03 11:20:55 +02:00
										 |  |  |         $category   = $repository->find(intval($attributes['categoryId'])); | 
					
						
							| 
									
										
										
										
											2016-10-25 18:53:54 +02:00
										 |  |  |         $types      = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER]; | 
					
						
							| 
									
										
										
										
											2016-11-05 08:46:55 +01:00
										 |  |  |         // get journal collector instead:
 | 
					
						
							|  |  |  |         $collector = new JournalCollector(auth()->user()); | 
					
						
							|  |  |  |         $collector->setAccounts($attributes['accounts'])->setTypes($types) | 
					
						
							|  |  |  |                   ->setRange($attributes['startDate'], $attributes['endDate']) | 
					
						
							|  |  |  |                   ->setCategory($category); | 
					
						
							|  |  |  |         $journals = $collector->getJournals(); // 7193
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $view = view('popup.report.category-entry', compact('journals', 'category'))->render(); | 
					
						
							| 
									
										
										
										
											2016-04-03 11:14:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $view; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 11:07:51 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Returns all the expenses that went to the given expense account. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param $attributes | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |     private function expenseEntry(array $attributes): string | 
					
						
							| 
									
										
										
										
											2016-04-03 11:07:51 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-10-10 07:12:39 +02:00
										 |  |  |         /** @var AccountRepositoryInterface $repository */ | 
					
						
							|  |  |  |         $repository = app(AccountRepositoryInterface::class); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 10:42:31 +01:00
										 |  |  |         $account   = $repository->find(intval($attributes['accountId'])); | 
					
						
							|  |  |  |         $types     = [TransactionType::WITHDRAWAL, TransactionType::TRANSFER]; | 
					
						
							|  |  |  |         $collector = new JournalCollector(auth()->user()); | 
					
						
							|  |  |  |         $collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])->setTypes($types); | 
					
						
							|  |  |  |         $journals = $collector->getJournals(); | 
					
						
							| 
									
										
										
										
											2016-10-09 21:36:03 +02:00
										 |  |  |         $report   = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
 | 
					
						
							| 
									
										
										
										
											2016-05-15 17:53:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // filter for transfers and withdrawals TO the given $account
 | 
					
						
							|  |  |  |         $journals = $journals->filter( | 
					
						
							| 
									
										
										
										
											2016-10-09 21:36:03 +02:00
										 |  |  |             function (Transaction $transaction) use ($report) { | 
					
						
							|  |  |  |                 // get the destinations:
 | 
					
						
							| 
									
										
										
										
											2016-10-10 06:40:50 +02:00
										 |  |  |                 $sources = TransactionJournal::sourceAccountList($transaction->transactionJournal)->pluck('id')->toArray(); | 
					
						
							| 
									
										
										
										
											2016-09-16 12:07:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-09 21:36:03 +02:00
										 |  |  |                 // do these intersect with the current list?
 | 
					
						
							| 
									
										
										
										
											2016-10-10 06:40:50 +02:00
										 |  |  |                 return !empty(array_intersect($report, $sources)); | 
					
						
							| 
									
										
										
										
											2016-05-15 17:53:00 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $view = view('popup.report.expense-entry', compact('journals', 'account'))->render(); | 
					
						
							| 
									
										
										
										
											2016-04-03 11:07:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $view; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 11:20:55 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Returns all the incomes that went to the given asset account. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param $attributes | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-04-03 13:56:06 +02:00
										 |  |  |     private function incomeEntry(array $attributes): string | 
					
						
							| 
									
										
										
										
											2016-04-03 11:20:55 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-10-10 07:12:39 +02:00
										 |  |  |         /** @var AccountRepositoryInterface $repository */ | 
					
						
							|  |  |  |         $repository = app(AccountRepositoryInterface::class); | 
					
						
							|  |  |  |         $account    = $repository->find(intval($attributes['accountId'])); | 
					
						
							|  |  |  |         $types      = [TransactionType::DEPOSIT, TransactionType::TRANSFER]; | 
					
						
							| 
									
										
										
										
											2016-11-05 11:47:21 +01:00
										 |  |  |         $collector  = new JournalCollector(auth()->user()); | 
					
						
							| 
									
										
										
										
											2016-11-05 10:42:31 +01:00
										 |  |  |         $collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])->setTypes($types); | 
					
						
							|  |  |  |         $journals = $collector->getJournals(); | 
					
						
							| 
									
										
										
										
											2016-11-05 11:47:21 +01:00
										 |  |  |         $report   = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
 | 
					
						
							| 
									
										
										
										
											2016-10-09 21:36:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // filter the set so the destinations outside of $attributes['accounts'] are not included.
 | 
					
						
							| 
									
										
										
										
											2016-05-15 17:53:00 +02:00
										 |  |  |         $journals = $journals->filter( | 
					
						
							| 
									
										
										
										
											2016-10-09 21:36:03 +02:00
										 |  |  |             function (Transaction $transaction) use ($report) { | 
					
						
							|  |  |  |                 // get the destinations:
 | 
					
						
							|  |  |  |                 $destinations = TransactionJournal::destinationAccountList($transaction->transactionJournal)->pluck('id')->toArray(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 // do these intersect with the current list?
 | 
					
						
							|  |  |  |                 return !empty(array_intersect($report, $destinations)); | 
					
						
							| 
									
										
										
										
											2016-05-15 17:53:00 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-15 18:36:40 +02:00
										 |  |  |         $view = view('popup.report.income-entry', compact('journals', 'account'))->render(); | 
					
						
							| 
									
										
										
										
											2016-04-03 14:55:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-03 11:20:55 +02:00
										 |  |  |         return $view; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-01 16:06:55 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * @param array $attributes | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws FireflyException | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     private function parseAttributes(array $attributes): array | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $attributes['location'] = $attributes['location'] ?? ''; | 
					
						
							|  |  |  |         $attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', ''); | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $attributes['startDate'] = Carbon::createFromFormat('Ymd', $attributes['startDate']); | 
					
						
							|  |  |  |         } catch (InvalidArgumentException $e) { | 
					
						
							|  |  |  |             throw new FireflyException('Could not parse start date "' . e($attributes['startDate']) . '".'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |             $attributes['endDate'] = Carbon::createFromFormat('Ymd', $attributes['endDate']); | 
					
						
							|  |  |  |         } catch (InvalidArgumentException $e) { | 
					
						
							|  |  |  |             throw new FireflyException('Could not parse start date "' . e($attributes['endDate']) . '".'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $attributes; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 17:54:25 +02:00
										 |  |  | } |