From 03691c81c27496c48789076552f942d1edc8ec81 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 3 Apr 2016 11:14:36 +0200 Subject: [PATCH] More code for #159 [skip ci] --- .../Controllers/Popup/ReportController.php | 22 +++++++++++ .../Account/AccountRepository.php | 25 ++++++++++++ .../Account/AccountRepositoryInterface.php | 39 ++++++++++++------- .../views/popup/report/income-entry.twig | 15 +++++++ 4 files changed, 88 insertions(+), 13 deletions(-) create mode 100644 resources/views/popup/report/income-entry.twig diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php index b749834a52..9f521cff92 100644 --- a/app/Http/Controllers/Popup/ReportController.php +++ b/app/Http/Controllers/Popup/ReportController.php @@ -48,6 +48,9 @@ class ReportController extends Controller case 'expense-entry': $html = $this->expenseEntry($attributes); break; + case 'income-entry': + $html = $this->incomeEntry($attributes); + break; } return Response::json(['html' => $html]); @@ -83,6 +86,25 @@ class ReportController extends Controller return $view; } + /** + * Returns all the incomes that went to the given asset account. + * + * @param $attributes + * + * @return string + * @throws FireflyException + */ + private function incomeEntry($attributes) + { + /** @var AccountRepositoryInterface $repository */ + $repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + $account = $repository->find(intval($attributes['accountId'])); + $journals = $repository->getIncomeByDestination($account, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']); + $view = view('popup.report.income-entry', compact('journals'))->render(); + + return $view; + } + /** * Returns all the expenses that went to the given expense account. * diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index bcdf3e5907..e37a21abbc 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -676,4 +676,29 @@ class AccountRepository implements AccountRepositoryInterface } } + + /** + * Returns a list of transactions TO the given (asset) $account, but none from the + * given list of accounts + * + * @param Account $account + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function getIncomeByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end) + { + $ids = $accounts->pluck('id')->toArray(); + $journals = $this->user->transactionjournals() + ->expanded() + ->before($end) + ->where('source_account.id', $account->id) + ->whereIn('destination_account.id', $ids) + ->after($start) + ->get(TransactionJournal::QUERYFIELDS); + + return $journals; + } } diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 0f982082b9..0e7fba5fd0 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -20,19 +20,6 @@ use Illuminate\Support\Collection; interface AccountRepositoryInterface { - /** - * Returns a list of transactions TO the $account, not including transfers - * and/or expenses in the $accounts list. - * - * @param Account $account - * @param Collection $accounts - * @param Carbon $start - * @param Carbon $end - * - * @return Collection - */ - public function getExpensesByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end); - /** * @param array $types * @@ -84,6 +71,19 @@ interface AccountRepositoryInterface */ public function getCreditCards(Carbon $date): Collection; + /** + * Returns a list of transactions TO the given (expense) $account, all from the + * given list of accounts + * + * @param Account $account + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function getExpensesByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end); + /** * @param TransactionJournal $journal * @param Account $account @@ -108,6 +108,19 @@ interface AccountRepositoryInterface */ public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end): Collection; + /** + * Returns a list of transactions TO the given (asset) $account, but none from the + * given list of accounts + * + * @param Account $account + * @param Collection $accounts + * @param Carbon $start + * @param Carbon $end + * + * @return Collection + */ + public function getIncomeByDestination(Account $account, Collection $accounts, Carbon $start, Carbon $end); + /** * @param Account $account * @param $page diff --git a/resources/views/popup/report/income-entry.twig b/resources/views/popup/report/income-entry.twig new file mode 100644 index 0000000000..d77e4ea3c5 --- /dev/null +++ b/resources/views/popup/report/income-entry.twig @@ -0,0 +1,15 @@ + +