More code for #159

This commit is contained in:
James Cole 2016-04-03 11:07:51 +02:00
parent 23cc7be231
commit 885b56c465
8 changed files with 92 additions and 9 deletions

View File

@ -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
*

View File

@ -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

View File

@ -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
*

View File

@ -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;

View File

@ -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');

View File

@ -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">&times;</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>

View File

@ -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">&times;</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>

View File

@ -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>