Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
More code for #159
James Cole885b56c465a6
diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.phpindex 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.phpindex 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 AccountRepositoryInterfacereturn $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 $accountdiff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.phpindex 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.cssindex 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.jsindex 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.twigindex 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 @@<div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="{{ 'close'|_ }}"><span aria-hidden="true">×</span></button>- <h4 class="modal-title" id="testTriggerLabel">{{ 'budget_spent_amount'|_ }}</h4>+ <h4 class="modal-title" id="budgetSpentAmountLabel">{{ 'budget_spent_amount'|_ }}</h4></div><div class="modal-body">{% include 'popup/list/journals.twig' %}</div><div class="modal-footer">- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>+ <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'close'|_ }}</button></div></div></div>diff --git a/resources/views/popup/report/expense-entry.twig b/resources/views/popup/report/expense-entry.twignew file mode 100644index 0000000000..977ee599f1--- /dev/null+++ b/resources/views/popup/report/expense-entry.twig@@ -0,0 +1,15 @@+<!-- Modal dialog to show budget expenses -->+<div class="modal-dialog modal-lg" role="document">+ <div class="modal-content">+ <div class="modal-header">+ <button type="button" class="close" data-dismiss="modal" aria-label="{{ 'close'|_ }}"><span aria-hidden="true">×</span></button>+ <h4 class="modal-title" id="expenseEntryTitle">{{ 'expense_entry'|_ }}</h4>+ </div>+ <div class="modal-body">+ {% include 'popup/list/journals.twig' %}+ </div>+ <div class="modal-footer">+ <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'close'|_ }}</button>+ </div>+ </div>+</div>diff --git a/resources/views/rules/partials/test-trigger-modal.twig b/resources/views/rules/partials/test-trigger-modal.twigindex 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 @@</div></div><div class="modal-footer">- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>+ <button type="button" class="btn btn-default" data-dismiss="modal">{{ 'close'|_ }}</button></div></div></div>