diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php index fc668dcd0b..b749834a52 100644 --- a/app/Http/Controllers/Popup/ReportController.php +++ b/app/Http/Controllers/Popup/ReportController.php @@ -14,6 +14,7 @@ namespace FireflyIII\Http\Controllers\Popup; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Http\Controllers\Controller; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Support\Binder\AccountList; use Illuminate\Http\Request; @@ -37,13 +38,15 @@ class ReportController extends Controller { $attributes = $request->get('attributes'); $attributes = $this->parseAttributes($attributes); - $html = ''; switch ($attributes['location']) { default: throw new FireflyException('Firefly cannot handle "' . e($attributes['location']) . '" '); case 'budget-spent-amount': $html = $this->budgetSpentAmount($attributes); + break; + case 'expense-entry': + $html = $this->expenseEntry($attributes); break; } @@ -53,6 +56,8 @@ class ReportController extends Controller } /** + * Returns all expenses inside the given budget for the given accounts. + * * @param array $attributes * * @return string @@ -73,12 +78,30 @@ class ReportController extends Controller $journals = $repository->getExpenses($budget, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']); } - $view = view('popup.report.budget-spent-amount', compact('journals'))->render(); return $view; } + /** + * Returns all the expenses that went to the given expense account. + * + * @param $attributes + * + * @return string + * @throws FireflyException + */ + private function expenseEntry($attributes) + { + /** @var AccountRepositoryInterface $repository */ + $repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface'); + $account = $repository->find(intval($attributes['accountId'])); + $journals = $repository->getExpensesByDestination($account, $attributes['accounts'], $attributes['startDate'], $attributes['endDate']); + $view = view('popup.report.expense-entry', compact('journals'))->render(); + + return $view; + } + /** * @param array $attributes * diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 6d8738107e..bcdf3e5907 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -33,7 +33,6 @@ class AccountRepository implements AccountRepositoryInterface /** @var User */ private $user; - /** @var array */ private $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber']; @@ -164,6 +163,31 @@ class AccountRepository implements AccountRepositoryInterface return $set; } + /** + * 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) + { + $ids = $accounts->pluck('id')->toArray(); + $journals = $this->user->transactionjournals() + ->expanded() + ->before($end) + ->where('destination_account.id', $account->id) + ->whereIn('source_account.id', $ids) + ->after($start) + ->get(TransactionJournal::QUERYFIELDS); + + return $journals; + } + /** * @param TransactionJournal $journal * @param Account $account diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 40a40d2c6d..0f982082b9 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -20,6 +20,19 @@ 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 * diff --git a/public/css/firefly.css b/public/css/firefly.css index bd6c9d6309..64c1c6712c 100644 --- a/public/css/firefly.css +++ b/public/css/firefly.css @@ -1,6 +1,9 @@ #daterange {cursor:pointer;} .general-chart-error {height:30px;background:url('/images/error.png') no-repeat center center;} .handle {cursor:move;} +body.waiting * { + cursor: progress; +} .ui-sortable-placeholder { display: inline-block; diff --git a/public/js/reports/default/all.js b/public/js/reports/default/all.js index e61be90c52..357c91b7d6 100644 --- a/public/js/reports/default/all.js +++ b/public/js/reports/default/all.js @@ -25,24 +25,29 @@ function clickInfoButton(e) { var element = $(e.target); var attributes = element.data(); + // set wait cursor + $('body').addClass('waiting'); + // add some more elements: attributes.startDate = startDate; attributes.endDate = endDate; attributes.reportType = reportType; attributes.accounts = accountIds; - console.log(attributes); $.getJSON('popup/report', {attributes: attributes}).success(respondInfoButton).fail(errorInfoButton); } function errorInfoButton(data) { "use strict"; - console.log(data); + // remove wait cursor + $('body').removeClass('waiting'); + alert('Apologies. The requested data is not (yet) available.'); } function respondInfoButton(data) { "use strict"; - console.log(123); + // remove wait cursor + $('body').removeClass('waiting'); $('#defaultModal').empty().html(data.html); $('#defaultModal').modal('show'); diff --git a/resources/views/popup/report/budget-spent-amount.twig b/resources/views/popup/report/budget-spent-amount.twig index 974a947777..ceb4e7d136 100644 --- a/resources/views/popup/report/budget-spent-amount.twig +++ b/resources/views/popup/report/budget-spent-amount.twig @@ -3,13 +3,13 @@ diff --git a/resources/views/popup/report/expense-entry.twig b/resources/views/popup/report/expense-entry.twig new file mode 100644 index 0000000000..977ee599f1 --- /dev/null +++ b/resources/views/popup/report/expense-entry.twig @@ -0,0 +1,15 @@ + + diff --git a/resources/views/rules/partials/test-trigger-modal.twig b/resources/views/rules/partials/test-trigger-modal.twig index 60e050175d..ff39116dc2 100644 --- a/resources/views/rules/partials/test-trigger-modal.twig +++ b/resources/views/rules/partials/test-trigger-modal.twig @@ -15,7 +15,7 @@