mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Experimental multi-budget overview.
This commit is contained in:
@@ -246,6 +246,54 @@ class BudgetController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
public function multiPeriod()
|
||||
{
|
||||
$start = new Carbon;
|
||||
$start->startOfYear();
|
||||
$end = clone $start;
|
||||
$end->endOfYear();
|
||||
$current = clone $start;
|
||||
$headers = [];
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$budgets = $this->repository->getBudgets();
|
||||
$limits = [];
|
||||
$defaultCurrency = Amount::getDefaultCurrency();
|
||||
|
||||
while ($current < $end) {
|
||||
$currentEnd = Navigation::endOfPeriod($current, $range);
|
||||
$format = Navigation::preferredCarbonLocalizedFormat($current, $currentEnd);
|
||||
$name = Navigation::periodShow($current, $range);
|
||||
$headers[] = [
|
||||
'start' => $current,
|
||||
'end' => $currentEnd,
|
||||
'date_str' => $current->format('Y_m_d'),
|
||||
'start_str' => $current->formatLocalized($format),
|
||||
'end_str' => $currentEnd->formatLocalized($format),
|
||||
'name' => $name,
|
||||
'key' => $current->format('Y-m-d') . '-' . $currentEnd->format('Y-m-d'),
|
||||
];
|
||||
|
||||
$current = Navigation::addPeriod($current, $range, 0);
|
||||
}
|
||||
|
||||
// for each budget, get the budget limits
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
/** @var array $header */
|
||||
foreach ($headers as $header) {
|
||||
/** @var BudgetLimit $limit */
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('start_date', $header['start']->format('Y-m-d'))
|
||||
->where('end_date', $header['end']->format('Y-m-d'))->first(['budget_limits.*']);
|
||||
$key = $header['start']->format('Y-m-d') . '-' . $header['end']->format('Y-m-d');
|
||||
if (!is_null($limit)) {
|
||||
$limits[$budget->id][$key] = round($limit->amount, $defaultCurrency->decimal_places);
|
||||
}
|
||||
}
|
||||
}
|
||||
return view('budgets.multi-period', compact('headers', 'budgets','limits'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param JournalRepositoryInterface $repository
|
||||
@@ -319,7 +367,7 @@ class BudgetController extends Controller
|
||||
$this->repository->setAvailableBudget($defaultCurrency, $start, $end, $amount);
|
||||
Preferences::mark();
|
||||
|
||||
return redirect(route('budgets.index',[$start->format('Y-m-d')]));
|
||||
return redirect(route('budgets.index', [$start->format('Y-m-d')]));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -111,6 +111,7 @@
|
||||
<a href="{{ route('budgets.index', [start.format('Y-m-d')]) }}" class="btn btn-default">{{ currentMonth }}</a>
|
||||
<a href="{{ route('budgets.index', [next.format('Y-m-d')]) }}" class="btn btn-default" title="{{ nextText }}">→</a>
|
||||
</div>
|
||||
<div><a href="{{ route('budgets.multi-period') }}">{{ 'multi_period_overview'|_ }}</a></div>
|
||||
</div>
|
||||
<div class="col-lg-2 col-md-4 col-sm-12 col-xs-12 text-right">
|
||||
<select class="form-control selectPeriod" name="next">
|
||||
|
50
resources/views/budgets/multi-period.twig
Normal file
50
resources/views/budgets/multi-period.twig
Normal file
@@ -0,0 +1,50 @@
|
||||
{% extends "./layout/default" %}
|
||||
|
||||
{% block breadcrumbs %}
|
||||
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">multi period table</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Budget</th>
|
||||
{% for header in headers %}
|
||||
<th title="{{ header.start_str }} - {{ header.end_str }}">{{ header.name }}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for budget in budgets %}
|
||||
<tr>
|
||||
<th>{{ budget.name }}</th>
|
||||
{% for header in headers %}
|
||||
<td>
|
||||
<input name="{{ budget.id }}_{{ header.date_str }}" id="{{ budget.id }}_{{ header.date_str }}"
|
||||
type="number" class="form-control budget-input" data-id="{{ budget.id }}" data-start="{{ budget.start_str }}"
|
||||
data-end="{{ budget.end_str }}" value="{{ limits[budget.id][header.key] }}"
|
||||
>
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block styles %}
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
{% endblock %}
|
@@ -136,6 +136,7 @@ Route::group(
|
||||
*/
|
||||
Route::group(
|
||||
['middleware' => 'user-full-auth', 'prefix' => 'budgets', 'as' => 'budgets.'], function () {
|
||||
|
||||
Route::get('income/{start_date}/{end_date}', ['uses' => 'BudgetController@updateIncome', 'as' => 'income']);
|
||||
Route::get('create', ['uses' => 'BudgetController@create', 'as' => 'create']);
|
||||
Route::get('edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'edit']);
|
||||
@@ -143,8 +144,10 @@ Route::group(
|
||||
Route::get('show/{budget}', ['uses' => 'BudgetController@show', 'as' => 'show']);
|
||||
Route::get('show/{budget}/{budgetlimit}', ['uses' => 'BudgetController@showByBudgetLimit', 'as' => 'show.limit']);
|
||||
Route::get('list/no-budget/{moment?}', ['uses' => 'BudgetController@noBudget', 'as' => 'no-budget']);
|
||||
Route::get('multi-period', ['uses' => 'BudgetController@multiPeriod', 'as' => 'multi-period']);
|
||||
Route::get('{moment?}', ['uses' => 'BudgetController@index', 'as' => 'index']);
|
||||
|
||||
|
||||
Route::post('income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'income.post']);
|
||||
Route::post('store', ['uses' => 'BudgetController@store', 'as' => 'store']);
|
||||
Route::post('update/{budget}', ['uses' => 'BudgetController@update', 'as' => 'update']);
|
||||
|
Reference in New Issue
Block a user