mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 12:28:46 +00:00
More views and options for limits [skip ci]
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
use Firefly\Helper\Preferences\PreferencesHelperInterface as PHI;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
use Firefly\Helper\Toolkit\ToolkitInterface as Toolkit;
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\Budget\BudgetRepositoryInterface as BRI;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
|
||||
/**
|
||||
* Class HomeController
|
||||
@@ -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,6 +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();
|
||||
|
||||
|
||||
// get the preference for the home accounts to show:
|
||||
@@ -53,11 +54,11 @@ 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($dates[0], \Session::get('range'));
|
||||
|
||||
$transactions = [];
|
||||
foreach ($accounts as $account) {
|
||||
$transactions[] = [$this->_journal->getByAccount($account, 15), $account];
|
||||
$transactions[] = [$this->_journal->getByAccountInDateRange($account, 15, $start, $end), $account];
|
||||
}
|
||||
|
||||
if (count($transactions) % 2 == 0) {
|
||||
@@ -68,6 +69,8 @@ class HomeController extends BaseController
|
||||
$transactions = array_chunk($transactions, 3);
|
||||
}
|
||||
// build the home screen:
|
||||
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('budgets',$budgets);
|
||||
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with(
|
||||
'budgets', $budgets
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,51 @@ class LimitController extends BaseController
|
||||
);
|
||||
}
|
||||
|
||||
public function edit($limitId = null)
|
||||
{
|
||||
$limit = $this->_limits->find($limitId);
|
||||
$budgets = $this->_budgets->getAsSelectList();
|
||||
|
||||
$periods = [
|
||||
'weekly' => 'A week',
|
||||
'monthly' => 'A month',
|
||||
'quarterly' => 'A quarter',
|
||||
'half-year' => 'Six months',
|
||||
'yearly' => 'A year',
|
||||
];
|
||||
|
||||
|
||||
if ($limit) {
|
||||
return View::make('limits.edit')->with('limit', $limit)->with('budgets', $budgets)->
|
||||
with('periods',$periods);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function update($limitId = null)
|
||||
{
|
||||
/** @var \Limit $limit */
|
||||
$limit = $this->_limits->find($limitId);
|
||||
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();
|
||||
} else {
|
||||
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!');
|
||||
|
||||
}
|
||||
|
||||
public function store()
|
||||
{
|
||||
// find a limit with these properties, as we might already have one:
|
||||
|
||||
Reference in New Issue
Block a user