First functional view of default report.

This commit is contained in:
James Cole 2015-12-06 13:11:43 +01:00
parent 16bfbc8a12
commit 77262f52a4
4 changed files with 213 additions and 20 deletions

View File

@ -19,6 +19,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget as BudgetModel;
use FireflyIII\Models\LimitRepetition;
use Illuminate\Support\Collection;
/**
* Class ReportHelper
@ -59,11 +60,6 @@ class ReportHelper implements ReportHelperInterface
$accounts = $this->query->getAllAccounts($date, $end, $shared);
$start = '0';
$end = '0';
$diff = '0';
bcscale(2);
// remove cash account, if any:
$accounts = $accounts->filter(
function (Account $account) {
@ -74,21 +70,7 @@ class ReportHelper implements ReportHelperInterface
return null;
}
);
// summarize:
foreach ($accounts as $account) {
$start = bcadd($start, $account->startBalance);
$end = bcadd($end, $account->endBalance);
$diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
}
$object = new AccountCollection;
$object->setStart($start);
$object->setEnd($end);
$object->setDifference($diff);
$object->setAccounts($accounts);
return $object;
return $this->getAccountReportForList($date, $end, $accounts);
}
/**
@ -418,4 +400,37 @@ class ReportHelper implements ReportHelperInterface
return $months;
}
/**
* This method generates a full report for the given period on all
* given accounts
*
* @param Carbon $date
* @param Carbon $end
* @param Collection $accounts
*
* @return AccountCollection
*/
public function getAccountReportForList(Carbon $date, Carbon $end, Collection $accounts)
{
$start = '0';
$end = '0';
$diff = '0';
bcscale(2);
// summarize:
foreach ($accounts as $account) {
$start = bcadd($start, $account->startBalance);
$end = bcadd($end, $account->endBalance);
$diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance));
}
$object = new AccountCollection;
$object->setStart($start);
$object->setEnd($end);
$object->setDifference($diff);
$object->setAccounts($accounts);
return $object;
}
}

View File

@ -10,6 +10,7 @@ use FireflyIII\Helpers\Collection\Budget as BudgetCollection;
use FireflyIII\Helpers\Collection\Category as CategoryCollection;
use FireflyIII\Helpers\Collection\Expense;
use FireflyIII\Helpers\Collection\Income;
use Illuminate\Support\Collection;
/**
* Interface ReportHelperInterface
@ -31,6 +32,18 @@ interface ReportHelperInterface
*/
public function getAccountReport(Carbon $date, Carbon $end, $shared);
/**
* This method generates a full report for the given period on all
* given accounts
*
* @param Carbon $date
* @param Carbon $end
* @param Collection $accounts
*
* @return AccountCollection
*/
public function getAccountReportForList(Carbon $date, Carbon $end, Collection $accounts);
/**
* This method generates a full report for the given period on all
* the users bills and their payments.

View File

@ -1,10 +1,14 @@
<?php namespace FireflyIII\Http\Controllers;
use Auth;
use Carbon\Carbon;
use Exception;
use FireflyIII\Helpers\Report\ReportHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Input;
use Log;
use Redirect;
use Session;
use View;
@ -201,5 +205,66 @@ class ReportController extends Controller
);
}
/**
* @param $url
*/
public function report($url, AccountRepositoryInterface $repository)
{
$parts = explode(';', $url);
// try to make a date out of parts 1 and 2:
try {
$start = new Carbon($parts[1]);
$end = new Carbon($parts[2]);
} catch (Exception $e) {
Log::error('Could not parse date "' . $parts[1] . '" or "' . $parts[2] . '" for user #' . Auth::user()->id);
abort(404);
}
if ($end < $start) {
abort(404);
}
// accounts:
$c = count($parts);
$list = new Collection();
for ($i = 3; $i < $c; $i++) {
$account = $repository->find($parts[$i]);
if ($account) {
$list->push($account);
}
}
// some fields:
$subTitle = trans('firefly.reportForMonth', ['month' => $start->formatLocalized($this->monthFormat)]);
$subTitleIcon = 'fa-calendar';
$incomeTopLength = 8;
$expenseTopLength = 8;
// get report stuff!
$accounts = $this->helper->getAccountReportForList($start, $end, $list);
// $incomes = $this->helper->getIncomeReportForList($start, $end, $list);
// $expenses = $this->helper->getExpenseReportForList($start, $end, $list);
// $budgets = $this->helper->getBudgetReportForList($start, $end, $list);
// $categories = $this->helper->getCategoryReportForList($start, $end, $list);
// $balance = $this->helper->getBalanceReportForList($start, $end, $list);
// $bills = $this->helper->getBillReportForList($start, $end);
// continue!
return view(
'reports.default',
compact(
'start',
'subTitle', 'subTitleIcon',
'accounts',
'incomes', 'incomeTopLength',
'expenses', 'expenseTopLength',
'budgets', 'balance',
'categories',
'bills'
)
);
}
}

View File

@ -0,0 +1,100 @@
{% extends "./layout/default.twig" %}
{% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, start, shared) }}
{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'accountBalances'|_ }}</h3>
</div>
<div class="box-body">
{% if Config.get('firefly.chart') == 'google' %}
<div id="account-balances-chart"></div>
{% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %}
<canvas id="account-balances-chart" style="width:100%;height:400px;"></canvas>
{% endif %}
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6">
{% include 'partials/reports/accounts.twig' %}
{% include 'partials/reports/income-vs-expenses.twig' %}
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- income -->
{% include 'partials/reports/income.twig' %}
</div>
<div class="col-lg-3 col-md-3 col-sm-3">
<!-- expenses -->
{% include 'partials/reports/expenses.twig' %}
</div>
</div>
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-12">
<!-- budgets -->
{% include 'partials/reports/budgets.twig' %}
</div>
<div class="col-lg-4 col-md-4 col-sm-12">
<!-- categories -->
{% include 'partials/reports/categories.twig' %}
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
{% include 'partials/reports/balance.twig' %}
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
{% include 'partials/reports/bills.twig' %}
</div>
</div>
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="css/bootstrap-sortable.css" type="text/css" media="all"/>
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="js/bootstrap-sortable.js"></script>
<!-- load the libraries and scripts necessary for Google Charts: -->
{% if Config.get('firefly.chart') == 'google' %}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/gcharts.js"></script>
{% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %}
<script type="text/javascript" src="js/Chart.min.js"></script>
<script type="text/javascript" src="js/charts.js"></script>
{% endif %}
<script type="text/javascript">
var year = {{ start.year }};
var month = {{ start.month }};
var shared = {% if shared %}'/shared'
{% else %}''{% endif %};
var incomeTopLength = {{ incomeTopLength }};
var expenseTopLength = {{ expenseTopLength }};
var incomeRestShow = false; // starts hidden.
var expenseRestShow = false; // starts hidden.
var showTheRest = '{{ trans('firefly.showTheRest',{number:incomeTopLength}) }}';
var hideTheRest = '{{ trans('firefly.hideTheRest',{number:incomeTopLength}) }}';
var showTheRestExpense = '{{ trans('firefly.showTheRest',{number:expenseTopLength}) }}';
var hideTheRestExpense = '{{ trans('firefly.hideTheRest',{number:expenseTopLength}) }}';
</script>
<script type="text/javascript" src="js/reports.js"></script>
{% endblock %}