mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-08 10:48:13 +00:00
Some new stuff for budget management. [skip ci]
This commit is contained in:
@@ -13,67 +13,57 @@ class BudgetController extends BaseController
|
||||
View::share('menu', 'budgets');
|
||||
}
|
||||
|
||||
public function index($group = null)
|
||||
public function indexByDate()
|
||||
{
|
||||
|
||||
$opts = ['date', 'budget'];
|
||||
$group = in_array($group, $opts) ? $group : 'date';
|
||||
|
||||
switch ($group) {
|
||||
case 'date':
|
||||
// get a list of dates by getting all repetitions:
|
||||
$budgets = $this->_budgets->get();
|
||||
$reps = [];
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
|
||||
$monthOrder = $rep->startdate->format('Y-m');
|
||||
$month = $rep->startdate->format('F Y');
|
||||
$reps[$monthOrder] = isset($reps[$monthOrder]) ? $reps[$monthOrder] : ['date' => $month];
|
||||
|
||||
}
|
||||
}
|
||||
// get a list of dates by getting all repetitions:
|
||||
$budgets = $this->_budgets->get();
|
||||
$reps = [];
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
$dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
|
||||
if(is_null($dateFormats)) {
|
||||
die('No date formats for ' . $limit->repeat_freq);
|
||||
}
|
||||
// put all the budgets under their respective date:
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$month = $rep->startdate->format('Y-m');
|
||||
$reps[$month]['limitrepetitions'][] = $rep;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
$periodOrder = $rep->startdate->format($dateFormats['group_date']);
|
||||
$period = $rep->startdate->format($dateFormats['display_date']);
|
||||
$reps[$periodOrder] = isset($reps[$periodOrder]) ? $reps[$periodOrder] : ['date' => $period];
|
||||
|
||||
}
|
||||
krsort($reps);
|
||||
|
||||
return View::make('budgets.index')->with('group', $group)->with('reps', $reps);
|
||||
|
||||
|
||||
break;
|
||||
case 'budget':
|
||||
$budgets = $this->_budgets->get();
|
||||
$today = new \Carbon\Carbon;
|
||||
return View::make('budgets.index')->with('budgets', $budgets)->with('today', $today)->with(
|
||||
'group', $group
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
// put all the budgets under their respective date:
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budget->limits as $limit) {
|
||||
$dateFormats = \Config::get('firefly.date_formats_by_period.' . $limit->repeat_freq);
|
||||
if(is_null($dateFormats)) {
|
||||
die('No date formats for ' . $limit->repeat_freq);
|
||||
}
|
||||
foreach ($limit->limitrepetitions as $rep) {
|
||||
|
||||
$month = $rep->startdate->format($dateFormats['group_date']);
|
||||
$reps[$month]['limitrepetitions'][] = $rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
krsort($reps);
|
||||
|
||||
return View::make('budgets.indexByDate')->with('reps', $reps);
|
||||
|
||||
}
|
||||
|
||||
public function indexByBudget()
|
||||
{
|
||||
$budgets = $this->_budgets->get();
|
||||
$today = new \Carbon\Carbon;
|
||||
return View::make('budgets.indexByBudget')->with('budgets', $budgets)->with('today', $today);
|
||||
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
|
||||
$periods = [
|
||||
'weekly' => 'A week',
|
||||
'monthly' => 'A month',
|
||||
'quarterly' => 'A quarter',
|
||||
'half-year' => 'Six months',
|
||||
'yearly' => 'A year',
|
||||
];
|
||||
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
return View::make('budgets.create')->with('periods', $periods);
|
||||
}
|
||||
|
||||
@@ -92,8 +82,15 @@ class BudgetController extends BaseController
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO actual view, actual content.
|
||||
* @param $budgetId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function show($budgetId)
|
||||
{
|
||||
/** @var \Budget $budget */
|
||||
$budget = $this->_budgets->find($budgetId);
|
||||
|
||||
$list = $budget->transactionjournals()->get();
|
||||
@@ -102,7 +99,6 @@ class BudgetController extends BaseController
|
||||
foreach ($list as $entry) {
|
||||
$month = $entry->date->format('F Y');
|
||||
$return[$month] = isset($return[$month]) ? $return[$month] : [];
|
||||
|
||||
$return[$month][] = $entry;
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ class ChartController extends BaseController
|
||||
*/
|
||||
public function homeAccount($accountId = null)
|
||||
{
|
||||
list($start, $end) = $this->_tk->getDateRange();
|
||||
\Log::debug('Start is (cannot clone?): ' . $start);
|
||||
list($start, $end) = $this->_tk->getDateRangeDates();
|
||||
$current = clone $start;
|
||||
$return = [];
|
||||
$account = null;
|
||||
@@ -75,10 +74,7 @@ class ChartController extends BaseController
|
||||
}
|
||||
} else {
|
||||
$return[0] = ['name' => $account->name, 'id' => $account->id, 'data' => []];
|
||||
\Log::debug('Start is: '.$start);
|
||||
\Log::debug('End is: '.$end);
|
||||
while ($current <= $end) {
|
||||
\Log::debug('Current: ' . $current.' is smaller or equal to ' . $end);
|
||||
if ($current > $today) {
|
||||
$return[0]['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)];
|
||||
} else {
|
||||
@@ -88,21 +84,6 @@ class ChartController extends BaseController
|
||||
$current->addDay();
|
||||
}
|
||||
}
|
||||
// // add an error bar as experiment:
|
||||
// foreach($return as $index => $serie) {
|
||||
// $err = [
|
||||
// 'type' => 'errorbar',
|
||||
// 'name' => $serie['name'].' pred',
|
||||
// 'linkedTo' => $serie['id'],
|
||||
// 'data' => []
|
||||
// ];
|
||||
// foreach($serie['data'] as $entry) {
|
||||
// $err['data'][] = [$entry[0],10,300];
|
||||
// }
|
||||
// $return[] = $err;
|
||||
// }
|
||||
|
||||
|
||||
return Response::json($return);
|
||||
}
|
||||
|
||||
@@ -140,7 +121,7 @@ class ChartController extends BaseController
|
||||
|
||||
public function homeCategories()
|
||||
{
|
||||
list($start, $end) =$this->_tk->getDateRange();
|
||||
list($start, $end) =$this->_tk->getDateRangeDates();
|
||||
$account = null;
|
||||
$result = [];
|
||||
// grab all transaction journals in this period:
|
||||
|
||||
@@ -17,8 +17,8 @@ class HomeController extends BaseController
|
||||
protected $_tk;
|
||||
|
||||
/**
|
||||
* @param ARI $accounts
|
||||
* @param PHI $preferences
|
||||
* @param ARI $accounts
|
||||
* @param PHI $preferences
|
||||
* @param TJRI $journal
|
||||
*/
|
||||
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal, Toolkit $toolkit, BRI $budgets)
|
||||
@@ -40,7 +40,7 @@ class HomeController extends BaseController
|
||||
{
|
||||
// count, maybe we need some introducing text to show:
|
||||
$count = $this->_accounts->count();
|
||||
list($start, $end) = $this->_tk->getDateRange();
|
||||
list($start, $end) = $this->_tk->getDateRangeDates();
|
||||
|
||||
|
||||
// get the preference for the home accounts to show:
|
||||
@@ -53,12 +53,14 @@ class HomeController extends BaseController
|
||||
|
||||
|
||||
// get the budgets for this period:
|
||||
$dates = $this->_tk->getDateRange();
|
||||
$budgets = $this->_budgets->getWithRepetitionsInPeriod($dates[0], \Session::get('range'));
|
||||
$budgets = $this->_budgets->getWithRepetitionsInPeriod($start, \Session::get('range'));
|
||||
|
||||
$transactions = [];
|
||||
foreach ($accounts as $account) {
|
||||
$transactions[] = [$this->_journal->getByAccountInDateRange($account, 15, $start, $end), $account];
|
||||
$set = $this->_journal->getByAccountInDateRange($account, 15, $start, $end);
|
||||
if (count($set) > 0) {
|
||||
$transactions[] = [$set, $account];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($transactions) % 2 == 0) {
|
||||
@@ -73,4 +75,10 @@ class HomeController extends BaseController
|
||||
'budgets', $budgets
|
||||
);
|
||||
}
|
||||
|
||||
public function flush()
|
||||
{
|
||||
Cache::flush();
|
||||
return Redirect::route('index');
|
||||
}
|
||||
}
|
||||
@@ -19,20 +19,16 @@ class LimitController extends BaseController
|
||||
|
||||
public function create($budgetId = null)
|
||||
{
|
||||
$periods = [
|
||||
'weekly' => 'A week',
|
||||
'monthly' => 'A month',
|
||||
'quarterly' => 'A quarter',
|
||||
'half-year' => 'Six months',
|
||||
'yearly' => 'A year',
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
$prefilled = [
|
||||
'startdate' => Input::get('startdate') ? : date('Y-m-d'),
|
||||
'repeat_freq' => Input::get('repeat_freq') ? : 'monthly'
|
||||
];
|
||||
|
||||
$budget = $this->_budgets->find($budgetId);
|
||||
$budget_id = is_null($budget) ? null : $budget->id;
|
||||
$budgets = $this->_budgets->getAsSelectList();
|
||||
return View::make('limits.create')->with('budgets', $budgets)->with('budget_id', $budget_id)->with(
|
||||
return View::make('limits.create')->with('budgets', $budgets)->with('budget_id', $budgetId)->with(
|
||||
'periods', $periods
|
||||
);
|
||||
)->with('prefilled', $prefilled);
|
||||
}
|
||||
|
||||
public function edit($limitId = null)
|
||||
@@ -50,8 +46,9 @@ class LimitController extends BaseController
|
||||
|
||||
|
||||
if ($limit) {
|
||||
return View::make('limits.edit')->with('limit', $limit)->with('budgets', $budgets)->
|
||||
with('periods',$periods);
|
||||
return View::make('limits.edit')->with('limit', $limit)->with('budgets', $budgets)->with(
|
||||
'periods', $periods
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -60,23 +57,23 @@ class LimitController extends BaseController
|
||||
{
|
||||
/** @var \Limit $limit */
|
||||
$limit = $this->_limits->find($limitId);
|
||||
if($limit) {
|
||||
if ($limit) {
|
||||
$limit->startdate = new \Carbon\Carbon(Input::get('date'));
|
||||
$limit->repeat_freq = Input::get('period');
|
||||
$limit->repeats = !is_null(Input::get('repeats')) && Input::get('repeats') == '1' ? 1 : 0;
|
||||
$limit->amount = floatval(Input::get('amount'));
|
||||
if(!$limit->save()) {
|
||||
Session::flash('error','Could not save new limit: ' . $limit->errors()->first());
|
||||
return Redirect::route('budgets.limits.edit',$limit->id)->withInput();
|
||||
if (!$limit->save()) {
|
||||
Session::flash('error', 'Could not save new limit: ' . $limit->errors()->first());
|
||||
return Redirect::route('budgets.limits.edit', $limit->id)->withInput();
|
||||
} else {
|
||||
Session::flash('success','Limit saved!');
|
||||
foreach($limit->limitrepetitions()->get() as $rep) {
|
||||
Session::flash('success', 'Limit saved!');
|
||||
foreach ($limit->limitrepetitions()->get() as $rep) {
|
||||
$rep->delete();
|
||||
}
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
}
|
||||
return View::make('error')->with('message','No limit!');
|
||||
return View::make('error')->with('message', 'No limit!');
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user