mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
Popups in the reports as we've always promised.
This commit is contained in:
parent
a349aac8a4
commit
8ad1ede0c5
@ -87,14 +87,32 @@ class ReportQuery implements ReportQueryInterface
|
||||
->whereNull('otherJournals.deleted_at')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->whereNotNull('transaction_group_transaction_journal.transaction_group_id')
|
||||
->first(
|
||||
->get(
|
||||
[
|
||||
DB::Raw('SUM(`transactions`.`amount`) as `amount`')
|
||||
'transaction_journals.*',
|
||||
'transactions.amount'
|
||||
]
|
||||
);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will get the sum of all expenses in a certain time period that have no budget
|
||||
* and are balanced by a transfer to make up for it.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
$set = $this->balancedTransactionsList($account, $start, $end);
|
||||
$sum = 0;
|
||||
if (!is_null($set)) {
|
||||
$sum = floatval($set->amount);
|
||||
foreach($set as $entry) {
|
||||
$sum += floatval($entry->amount);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
@ -167,7 +185,40 @@ class ReportQuery implements ReportQueryInterface
|
||||
|
||||
return $set;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of transaction journals that have no budget, filtered for the specified account
|
||||
* and the specified date range.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getTransactionsWithoutBudget(Account $account, Carbon $start, Carbon $end)
|
||||
{
|
||||
$set = TransactionJournal::
|
||||
leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_transaction_journal.budget_id')
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin(
|
||||
'transactions', function (JoinClause $join) {
|
||||
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->before($end)
|
||||
->after($start)
|
||||
->where('accounts.id', $account->id)
|
||||
->where('transaction_journals.user_id', Auth::user()->id)
|
||||
->where('transaction_types.type', 'Withdrawal')
|
||||
->whereNull('budgets.id')
|
||||
->orderBy('transaction_journals.date', 'ASC')
|
||||
->get(['budgets.name', 'transactions.amount', 'transaction_journals.*']);
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,6 +120,18 @@ interface ReportQueryInterface
|
||||
*/
|
||||
public function getBudgetSummary(Account $account, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* Get a list of transaction journals that have no budget, filtered for the specified account
|
||||
* and the specified date range.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getTransactionsWithoutBudget(Account $account, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* This method will get a list of all expenses in a certain time period that have no budget
|
||||
* and are balanced by a transfer to make up for it.
|
||||
@ -131,4 +143,16 @@ interface ReportQueryInterface
|
||||
* @return Collection
|
||||
*/
|
||||
public function balancedTransactionsList(Account $account, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* This method will get the sum of all expenses in a certain time period that have no budget
|
||||
* and are balanced by a transfer to make up for it.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function balancedTransactionsSum(Account $account, Carbon $start, Carbon $end);
|
||||
}
|
@ -7,10 +7,12 @@ use FireflyIII\Helpers\Report\ReportHelperInterface;
|
||||
use FireflyIII\Helpers\Report\ReportQueryInterface;
|
||||
use FireflyIII\Http\Requests;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Session;
|
||||
use Steam;
|
||||
use View;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Class ReportController
|
||||
*
|
||||
@ -59,7 +61,7 @@ class ReportController extends Controller
|
||||
$accounts->each(
|
||||
function (Account $account) use ($start, $end, $query) {
|
||||
$budgets = $query->getBudgetSummary($account, $start, $end);
|
||||
$balancedAmount = $query->balancedTransactionsList($account, $start, $end);
|
||||
$balancedAmount = $query->balancedTransactionsSum($account, $start, $end);
|
||||
$array = [];
|
||||
foreach ($budgets as $budget) {
|
||||
$id = intval($budget->id);
|
||||
@ -104,7 +106,7 @@ class ReportController extends Controller
|
||||
* End getBudgetsForMonth DONE
|
||||
*/
|
||||
|
||||
return view('reports.budget', compact('subTitle', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly'));
|
||||
return view('reports.budget', compact('subTitle', 'year', 'month', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly'));
|
||||
|
||||
}
|
||||
|
||||
@ -124,6 +126,79 @@ class ReportController extends Controller
|
||||
return view('reports.index', compact('years', 'months', 'title', 'mainTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function modalBalancedTransfers(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query)
|
||||
{
|
||||
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$start = new Carbon($year . '-' . $month . '-01');
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
|
||||
$journals = $query->balancedTransactionsList($account, $start, $end);
|
||||
|
||||
return view('reports.modal-journal-list', compact('journals'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function modalLeftUnbalanced(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query)
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$start = new Carbon($year . '-' . $month . '-01');
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
$set = $query->getTransactionsWithoutBudget($account, $start, $end);
|
||||
|
||||
$journals = $set->filter(
|
||||
function (TransactionJournal $journal) {
|
||||
$count = $journal->transactiongroups()->where('relation', 'balance')->count();
|
||||
if ($count == 0) {
|
||||
return $journal;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return view('reports.modal-journal-list', compact('journals'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
*
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function modalNoBudget(Account $account, $year = '2014', $month = '1', ReportQueryInterface $query)
|
||||
{
|
||||
try {
|
||||
new Carbon($year . '-' . $month . '-01');
|
||||
} catch (Exception $e) {
|
||||
return view('error')->with('message', 'Invalid date');
|
||||
}
|
||||
$start = new Carbon($year . '-' . $month . '-01');
|
||||
$end = clone $start;
|
||||
$end->endOfMonth();
|
||||
$journals = $query->getTransactionsWithoutBudget($account, $start, $end);
|
||||
|
||||
return view('reports.modal-journal-list', compact('journals'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $year
|
||||
* @param string $month
|
||||
|
@ -311,6 +311,11 @@ Route::group(
|
||||
Route::get('/reports/{year}/{month}', ['uses' => 'ReportController@month', 'as' => 'reports.month']);
|
||||
Route::get('/reports/budget/{year}/{month}', ['uses' => 'ReportController@budget', 'as' => 'reports.budget']);
|
||||
|
||||
// pop ups for budget report:
|
||||
Route::get('/reports/modal/{account}/{year}/{month}/no-budget', ['uses' => 'ReportController@modalNoBudget','as' => 'reports.no-budget']);
|
||||
Route::get('/reports/modal/{account}/{year}/{month}/balanced-transfers', ['uses' => 'ReportController@modalBalancedTransfers','as' => 'reports.balanced-transfers']);
|
||||
Route::get('/reports/modal/{account}/{year}/{month}/left-unbalanced', ['uses' => 'ReportController@modalLeftUnbalanced','as' => 'reports.left-unbalanced']);
|
||||
|
||||
/**
|
||||
* Search Controller
|
||||
*/
|
||||
|
@ -6,4 +6,24 @@ if (typeof(google) != 'undefined') {
|
||||
|
||||
googleStackedColumnChart('chart/budgets/spending/' + year, 'budgets');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$(function () {
|
||||
$('.openModal').on('click', openModal);
|
||||
});
|
||||
|
||||
function openModal(e) {
|
||||
"use strict";
|
||||
var target = $(e.target).parent();
|
||||
var URL = target.attr('href');
|
||||
|
||||
$.get(URL).success(function (data) {
|
||||
$('#defaultModal').empty().html(data).modal('show');
|
||||
|
||||
}).fail(function () {
|
||||
alert('Could not load data.');
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
@ -111,6 +111,10 @@
|
||||
<div class="modal fade" id="relationModal">
|
||||
</div>
|
||||
|
||||
<!-- default modal -->
|
||||
<div class="modal fade" id="defaultModal">
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
|
||||
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
|
||||
<script type="text/javascript" src="js/metisMenu.min.js"></script>
|
||||
|
@ -42,18 +42,16 @@
|
||||
</tr>
|
||||
@foreach($budgets as $id => $budget)
|
||||
<tr>
|
||||
<td>{{{$budget['name']}}}
|
||||
@if($id == 0)
|
||||
<i class="fa fa-fw fa-question-circle" data-toggle="tooltip" data-placement="top" title="The calculation used here is slightly different from the row below. The numbers should match."></i>
|
||||
@endif
|
||||
</td>
|
||||
<td>{{{$budget['name']}}}</td>
|
||||
<td>{!! Amount::format($budget['amount']) !!}</td>
|
||||
<?php $spent = 0;?>
|
||||
@foreach($accounts as $account)
|
||||
@if(isset($account->budgetInformation[$id]))
|
||||
<td>
|
||||
@if($id == 0)
|
||||
<a href="#">{!! Amount::format($account->budgetInformation[$id]['amount']) !!}</a>
|
||||
<a href="{{route('reports.no-budget',[$account, $year, $month])}}" class="openModal">
|
||||
{!! Amount::format($account->budgetInformation[$id]['amount']) !!}
|
||||
</a>
|
||||
@else
|
||||
{!! Amount::format($account->budgetInformation[$id]['amount']) !!}
|
||||
@endif
|
||||
@ -70,46 +68,15 @@
|
||||
<td>{!! Amount::format($budget['amount'] + $spent) !!}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
<tr>
|
||||
<td colspan="2">Without budget
|
||||
<i class="fa fa-fw fa-question-circle" data-toggle="tooltip" data-placement="top" title="The calculation used here is slightly different from the row above. The numbers should match."></i>
|
||||
</td>
|
||||
@foreach($accounts as $account)
|
||||
@if(isset($account->budgetInformation[0]))
|
||||
<td>
|
||||
<a href="#">{!! Amount::format($account->budgetInformation[0]['amount']) !!}</a>
|
||||
</td>
|
||||
@else
|
||||
<td>{!! Amount::format(0) !!}</td>
|
||||
@endif
|
||||
@endforeach
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">Balanced by transfers</td>
|
||||
@foreach($accounts as $account)
|
||||
<td>
|
||||
<a href="#">{!! Amount::format($account->balancedAmount) !!}</a>
|
||||
<a href="{{route('reports.balanced-transfers',[$account, $year, $month])}}" class="openModal">{!! Amount::format($account->balancedAmount) !!}</a>
|
||||
</td>
|
||||
@endforeach
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
<!--
|
||||
<tr>
|
||||
<td colspan="2">Balancing transfers</td>
|
||||
@foreach($accounts as $account)
|
||||
<td>{!! Amount::format(0) !!}</td>
|
||||
@endforeach
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">Income</td>
|
||||
@foreach($accounts as $account)
|
||||
<td>{!! Amount::format(0) !!}</td>
|
||||
@endforeach
|
||||
<td colspan="2"> </td>
|
||||
</tr>
|
||||
--->
|
||||
<tr>
|
||||
<td colspan="2">Left unbalanced</td>
|
||||
@foreach($accounts as $account)
|
||||
@ -118,7 +85,7 @@
|
||||
?>
|
||||
@if(isset($account->budgetInformation[0]))
|
||||
<td>
|
||||
<a href="#">{!! Amount::format($account->budgetInformation[0]['amount'] + $account->balancedAmount) !!}</a>
|
||||
<a href="{{route('reports.left-unbalanced',[$account, $year, $month])}}" class="openModal">{!! Amount::format($account->budgetInformation[0]['amount'] + $account->balancedAmount) !!}</a>
|
||||
</td>
|
||||
@else
|
||||
<td>{!! Amount::format(0) !!}</td>
|
||||
@ -152,5 +119,6 @@
|
||||
|
||||
@stop
|
||||
@section('scripts')
|
||||
|
||||
<script type="text/javascript" src="js/reports.js"></script>
|
||||
@stop
|
||||
|
14
resources/views/reports/modal-journal-list.blade.php
Normal file
14
resources/views/reports/modal-journal-list.blade.php
Normal file
@ -0,0 +1,14 @@
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
<h4 class="modal-title">No budget bla bla.</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@include('list.journals-full')
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user