mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-03 20:14:31 +00:00
First attempt at unifying code for categories and budgets, which are basically the same thing.
This commit is contained in:
@@ -84,7 +84,7 @@ class BudgetController extends BaseController
|
||||
$budgets = $repos->get();
|
||||
|
||||
// get the limits for the current month.
|
||||
$date = \Session::get('start');
|
||||
$date = \Session::get('start');
|
||||
$spent = 0;
|
||||
/** @var \Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
@@ -114,9 +114,9 @@ class BudgetController extends BaseController
|
||||
}
|
||||
|
||||
$budgetAmount = $preferences->get('budgetIncomeTotal' . $date->format('FY'), 1000);
|
||||
$amount = floatval($budgetAmount->data);
|
||||
$overspent = $spent > $amount;
|
||||
if($overspent) {
|
||||
$amount = floatval($budgetAmount->data);
|
||||
$overspent = $spent > $amount;
|
||||
if ($overspent) {
|
||||
// overspent on total amount
|
||||
$spentPCT = ceil($amount / $spent * 100);
|
||||
} else {
|
||||
@@ -124,7 +124,7 @@ class BudgetController extends BaseController
|
||||
$spentPCT = ceil($spent / $amount * 100);
|
||||
}
|
||||
|
||||
return View::make('budgets.index', compact('budgets','spent','spentPCT','overspent'))->with('budgetAmount', $budgetAmount);
|
||||
return View::make('budgets.index', compact('budgets', 'spent', 'spentPCT', 'overspent'))->with('budgetAmount', $budgetAmount);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,15 +75,7 @@ class CategoryController extends BaseController
|
||||
*/
|
||||
public function show(Category $category)
|
||||
{
|
||||
$start = \Session::get('start');
|
||||
$end = \Session::get('end');
|
||||
|
||||
|
||||
$journals = $this->_category->journalsInRange($category, $start, $end);
|
||||
|
||||
return View::make('categories.show')->with('category', $category)->with('journals', $journals)->with(
|
||||
'highlight', Input::get('highlight')
|
||||
)->with('subTitle', 'Overview for category "' . $category->name . '"');
|
||||
return View::make('categories.show', compact('category'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -200,15 +200,26 @@ class GoogleChartController extends BaseController
|
||||
return Response::json($chart->getData());
|
||||
}
|
||||
|
||||
public function budgetsAndSpending(Budget $budget, $year) {
|
||||
/**
|
||||
* @param Component $component
|
||||
* @param $year
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function componentsAndSpending(Component $component, $year) {
|
||||
try {
|
||||
$start = new Carbon('01-01-' . $year);
|
||||
} catch (Exception $e) {
|
||||
App::abort(500);
|
||||
}
|
||||
|
||||
/** @var \FireflyIII\Database\Budget $bdt */
|
||||
$bdt = App::make('FireflyIII\Database\Budget');
|
||||
if($component->class == 'Budget') {
|
||||
/** @var \FireflyIII\Database\Budget $repos */
|
||||
$repos = App::make('FireflyIII\Database\Budget');
|
||||
} else {
|
||||
/** @var \FireflyIII\Database\Category $repos */
|
||||
$repos = App::make('FireflyIII\Database\Category');
|
||||
}
|
||||
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
@@ -220,12 +231,12 @@ class GoogleChartController extends BaseController
|
||||
$end->endOfYear();
|
||||
while($start <= $end) {
|
||||
|
||||
$spent = $bdt->spentInMonth($budget, $start);
|
||||
$repetition = $bdt->repetitionOnStartingOnDate($budget, $start);
|
||||
$spent = $repos->spentInMonth($component, $start);
|
||||
$repetition = $repos->repetitionOnStartingOnDate($component, $start);
|
||||
if($repetition) {
|
||||
$budgeted = floatval($repetition->amount);
|
||||
} else {
|
||||
$budgeted = 0;
|
||||
$budgeted = null;
|
||||
}
|
||||
|
||||
$chart->addRow(clone $start, $budgeted, $spent);
|
||||
|
||||
@@ -90,10 +90,10 @@ class GoogleTableController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Budget $budget
|
||||
* @param Component $component
|
||||
* @param LimitRepetition $repetition
|
||||
*/
|
||||
public function transactionsByBudget(Budget $budget, LimitRepetition $repetition = null)
|
||||
public function transactionsByComponent(Component $component, LimitRepetition $repetition = null)
|
||||
{
|
||||
/** @var \Grumpydictator\Gchart\GChart $chart */
|
||||
$chart = App::make('gchart');
|
||||
@@ -114,10 +114,13 @@ class GoogleTableController extends BaseController
|
||||
$chart->addColumn('Category', 'string');
|
||||
|
||||
if (is_null($repetition)) {
|
||||
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')->get();
|
||||
$journals = $component->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->orderBy('date', 'DESC')
|
||||
->get();
|
||||
} else {
|
||||
$journals = $budget->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->after($repetition->startdate)
|
||||
->before($repetition->enddate)->orderBy('date', 'DESC')->get();
|
||||
$journals = $component->transactionjournals()->with(['budgets', 'categories', 'transactions', 'transactions.account'])->after(
|
||||
$repetition->startdate
|
||||
)
|
||||
->before($repetition->enddate)->orderBy('date', 'DESC')->get();
|
||||
}
|
||||
/** @var TransactionJournal $transaction */
|
||||
foreach ($journals as $journal) {
|
||||
@@ -138,10 +141,10 @@ class GoogleTableController extends BaseController
|
||||
}
|
||||
if (isset($journal->budgets[0])) {
|
||||
$budgetURL = route('budgets.show', $journal->budgets[0]->id);
|
||||
$budget = $journal->budgets[0]->name;
|
||||
$component = $journal->budgets[0]->name;
|
||||
} else {
|
||||
$budgetURL = '';
|
||||
$budget = '';
|
||||
$component = '';
|
||||
}
|
||||
|
||||
if (isset($journal->categories[0])) {
|
||||
@@ -157,7 +160,7 @@ class GoogleTableController extends BaseController
|
||||
$edit = route('transactions.edit', $journal->id);
|
||||
$delete = route('transactions.delete', $journal->id);
|
||||
$chart->addRow(
|
||||
$id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $budget, $categoryURL,
|
||||
$id, $edit, $delete, $date, $descriptionURL, $description, $amount, $fromURL, $from, $toURL, $to, $budgetURL, $component, $categoryURL,
|
||||
$category
|
||||
);
|
||||
}
|
||||
|
||||
@@ -148,6 +148,32 @@ class Category implements CUD, CommonDatabaseCalls, CategoryInterface
|
||||
// TODO: Implement findByWhat() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Category $budget
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function repetitionOnStartingOnDate(\Category $category, Carbon $date)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Category $category
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function spentInMonth(\Category $category, Carbon $date)
|
||||
{
|
||||
$end = clone $date;
|
||||
$date->startOfMonth();
|
||||
$end->endOfMonth();
|
||||
$sum = floatval($category->transactionjournals()->before($end)->after($date)->lessThan(0)->sum('amount')) * -1;
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Ardent $model
|
||||
* @param array $data
|
||||
|
||||
@@ -50,6 +50,16 @@ Route::bind(
|
||||
}
|
||||
);
|
||||
|
||||
Route::bind(
|
||||
'component', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
return Component::
|
||||
where('id', $value)->where('user_id', Auth::user()->id)->first();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
Route::bind(
|
||||
'reminder', function ($value, $route) {
|
||||
if (Auth::check()) {
|
||||
@@ -169,13 +179,18 @@ Route::group(
|
||||
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
|
||||
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
|
||||
Route::get('/chart/reports/budgets/{year}', ['uses' => 'GoogleChartController@budgetsReportChart']);
|
||||
Route::get('/chart/budgets/{budget}/spending/{year}', ['uses' => 'GoogleChartController@budgetsAndSpending']);
|
||||
|
||||
// google chart (categories + budgets)
|
||||
Route::get('/chart/component/{component}/spending/{year}', ['uses' => 'GoogleChartController@componentsAndSpending']);
|
||||
|
||||
// google table controller
|
||||
Route::get('/table/account/{account}/transactions', ['uses' => 'GoogleTableController@transactionsByAccount']);
|
||||
Route::get('/table/accounts/{what}', ['uses' => 'GoogleTableController@accountList']);
|
||||
Route::get('/table/categories', ['uses' => 'GoogleTableController@categoryList']);
|
||||
Route::get('/table/budget/{budget}/{limitrepetition?}/transactions', ['uses' => 'GoogleTableController@transactionsByBudget']);
|
||||
|
||||
// google table (categories + budgets)
|
||||
|
||||
Route::get('/table/component/{component}/{limitrepetition}/transactions', ['uses' => 'GoogleTableController@transactionsByComponent']);
|
||||
|
||||
|
||||
Route::get('/chart/home/info/{accountnameA}/{day}/{month}/{year}', ['uses' => 'ChartController@homeAccountInfo', 'as' => 'chart.info']);
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
<div class="col-lg-9 col-md-9 col-sm-7">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Some stuff?
|
||||
Overview
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div id="budgetOverview"></div>
|
||||
<div id="componentOverview"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
@stop
|
||||
@section('scripts')
|
||||
<script type="text/javascript">
|
||||
var budgetID = {{$budget->id}};
|
||||
var componentID = {{$budget->id}};
|
||||
@if(!is_null($repetition))
|
||||
var repetitionID = {{$repetition->id}};
|
||||
var year = {{$repetition->startdate->format('Y')}};
|
||||
|
||||
@@ -1,44 +1,43 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<p class="lead">Use categories to group your expenses</p>
|
||||
<p class="text-info">
|
||||
Use categories to group expenses by hobby, for certain types of groceries or what bills are for.
|
||||
Expenses grouped in categories do not have to reoccur every month or every week, like budgets.
|
||||
</p>
|
||||
<p class="text-info">
|
||||
This overview will show you the expenses you've made in each [period] and show you the actual
|
||||
transactions for the currently selected period.
|
||||
</p>
|
||||
</div>
|
||||
</div><!-- TODO cleanup to match new theme & form -->
|
||||
<div class="col-lg-9 col-md-9 col-sm-7">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Overview
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div id="componentOverview"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@include('partials.date_nav')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<div id="chart"><img src="http://placehold.it/650x300" title="Placeholder" alt="" /></div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Transactions
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div id="transactions"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h4>Transactions<small> in current range</small></h4>
|
||||
@include('lists.transactions',['journals' => $journals,'sum' => true])
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3 col-sm-5">
|
||||
BLa bla something here.
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@stop
|
||||
@section('scripts')
|
||||
<script type="text/javascript">
|
||||
var categoryID = {{$category->id}};
|
||||
var componentID = {{$category->id}};
|
||||
var year = {{Session::get('start')->format('Y')}};
|
||||
|
||||
</script>
|
||||
|
||||
<!-- load the libraries and scripts necessary for Google Charts: -->
|
||||
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
||||
{{HTML::script('assets/javascript/firefly/gcharts.options.js')}}
|
||||
{{HTML::script('assets/javascript/firefly/gcharts.js')}}
|
||||
{{HTML::script('assets/javascript/firefly/categories.js')}}
|
||||
|
||||
@stop
|
||||
Reference in New Issue
Block a user