mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Default value for when session is empty.
This commit is contained in:
parent
d3cda8811d
commit
9ab0a83f7c
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Database\Budget as BudgetRepository;
|
||||
use FireflyIII\Shared\Preferences\PreferencesInterface as Pref;
|
||||
|
||||
@ -43,7 +44,7 @@ class BudgetController extends BaseController
|
||||
public function amount(Budget $budget)
|
||||
{
|
||||
$amount = intval(Input::get('amount'));
|
||||
$date = Session::get('start');
|
||||
$date = Session::get('start',Carbon::now()->startOfMonth());
|
||||
$limitRepetition = $this->_repository->updateLimitAmount($budget, $date, $amount);
|
||||
|
||||
return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition->id]);
|
||||
@ -111,16 +112,16 @@ class BudgetController extends BaseController
|
||||
$budgets->each(
|
||||
function (Budget $budget) {
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$budget->spent = $this->_repository->spentInMonth($budget, \Session::get('start'));
|
||||
$budget->spent = $this->_repository->spentInMonth($budget, \Session::get('start',Carbon::now()->startOfMonth()));
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$budget->currentRep = $budget->limitrepetitions()->where('limit_repetitions.startdate', \Session::get('start')->format('Y-m-d'))->first(
|
||||
$budget->currentRep = $budget->limitrepetitions()->where('limit_repetitions.startdate', \Session::get('start',Carbon::now()->startOfMonth())->format('Y-m-d'))->first(
|
||||
['limit_repetitions.*']
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$spent = $budgets->sum('spent');
|
||||
$amount = $this->_preferences->get('budgetIncomeTotal' . \Session::get('start')->format('FY'), 1000)->data;
|
||||
$amount = $this->_preferences->get('budgetIncomeTotal' . \Session::get('start',Carbon::now()->startOfMonth())->format('FY'), 1000)->data;
|
||||
$overspent = $spent > $amount;
|
||||
$spentPCT = $overspent ? ceil($amount / $spent * 100) : ceil($spent / $amount * 100);
|
||||
|
||||
@ -132,7 +133,7 @@ class BudgetController extends BaseController
|
||||
*/
|
||||
public function postUpdateIncome()
|
||||
{
|
||||
$this->_preferences->set('budgetIncomeTotal' . Session::get('start')->format('FY'), intval(Input::get('amount')));
|
||||
$this->_preferences->set('budgetIncomeTotal' . Session::get('start',Carbon::now()->startOfMonth())->format('FY'), intval(Input::get('amount')));
|
||||
|
||||
return Redirect::route('budgets.index');
|
||||
}
|
||||
@ -151,7 +152,7 @@ class BudgetController extends BaseController
|
||||
|
||||
$hideBudget = true; // used in transaction list.
|
||||
$journals = $this->_repository->getJournals($budget, $repetition);
|
||||
$limits = $repetition ? $budget->limits()->orderBy('startdate', 'DESC')->get() : [$repetition->limit];
|
||||
$limits = $repetition ? [$repetition->limit] : $budget->limits()->orderBy('startdate', 'DESC')->get();
|
||||
$subTitle = $repetition ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name);
|
||||
|
||||
return View::make('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle', 'hideBudget'));
|
||||
@ -243,7 +244,7 @@ class BudgetController extends BaseController
|
||||
*/
|
||||
public function updateIncome()
|
||||
{
|
||||
$budgetAmount = $this->_preferences->get('budgetIncomeTotal' . Session::get('start')->format('FY'), 1000);
|
||||
$budgetAmount = $this->_preferences->get('budgetIncomeTotal' . Session::get('start',Carbon::now()->startOfMonth())->format('FY'), 1000);
|
||||
|
||||
return View::make('budgets.income')->with('amount', $budgetAmount);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class GoogleChartController extends BaseController
|
||||
$this->_chart->addColumn('Day of month', 'date');
|
||||
$this->_chart->addColumn('Balance for ' . $account->name, 'number');
|
||||
|
||||
$start = Session::get('start');
|
||||
$start = Session::get('start',Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end');
|
||||
$count = $account->transactions()->count();
|
||||
|
||||
@ -79,14 +79,14 @@ class GoogleChartController extends BaseController
|
||||
switch ($view) {
|
||||
default:
|
||||
case 'session':
|
||||
$start = Session::get('start');
|
||||
$start = Session::get('start',Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end');
|
||||
break;
|
||||
case 'all':
|
||||
$first = $account->transactionjournals()->orderBy('date', 'DESC')->first();
|
||||
$last = $account->transactionjournals()->orderBy('date', 'ASC')->first();
|
||||
if (is_null($first)) {
|
||||
$start = Session::get('start');
|
||||
$start = Session::get('start',Carbon::now()->startOfMonth());
|
||||
} else {
|
||||
$start = clone $first->date;
|
||||
}
|
||||
@ -161,7 +161,7 @@ class GoogleChartController extends BaseController
|
||||
['transactionjournal', 'transactionjournal.transactions', 'transactionjournal.budgets', 'transactionjournal.transactiontype',
|
||||
'transactionjournal.categories']
|
||||
)->before(Session::get('end'))->after(
|
||||
Session::get('start')
|
||||
Session::get('start',Carbon::now()->startOfMonth())
|
||||
)->get();
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
@ -235,7 +235,7 @@ class GoogleChartController extends BaseController
|
||||
/*
|
||||
* Loop the date, then loop the accounts, then add balance.
|
||||
*/
|
||||
$start = Session::get('start');
|
||||
$start = Session::get('start',Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end');
|
||||
$current = clone $start;
|
||||
|
||||
@ -281,14 +281,14 @@ class GoogleChartController extends BaseController
|
||||
* Is there a repetition starting on this particular date? We can use that.
|
||||
*/
|
||||
/** @var \LimitRepetition $repetition */
|
||||
$repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start'));
|
||||
$repetition = $bdt->repetitionOnStartingOnDate($budget, Session::get('start',Carbon::now()->startOfMonth()));
|
||||
|
||||
/*
|
||||
* If there is, use it. Otherwise, forget it.
|
||||
*/
|
||||
if (is_null($repetition)) {
|
||||
// use the session start and end for our search query
|
||||
$searchStart = Session::get('start');
|
||||
$searchStart = Session::get('start',Carbon::now()->startOfMonth());
|
||||
$searchEnd = Session::get('end');
|
||||
// the limit is zero:
|
||||
$limit = 0;
|
||||
@ -315,7 +315,7 @@ class GoogleChartController extends BaseController
|
||||
* Finally, get all transactions WITHOUT a budget and add those as well.
|
||||
* (yes this method is oddly specific).
|
||||
*/
|
||||
$noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start'), Session::get('end'));
|
||||
$noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start',Carbon::now()->startOfMonth()), Session::get('end'));
|
||||
$sum = $noBudgetSet->sum('amount') * -1;
|
||||
$chart->addRow('No budget', 0, $sum);
|
||||
|
||||
@ -343,7 +343,7 @@ class GoogleChartController extends BaseController
|
||||
/*
|
||||
* Get the journals:
|
||||
*/
|
||||
$journals = $tj->getInDateRange(Session::get('start'), Session::get('end'));
|
||||
$journals = $tj->getInDateRange(Session::get('start',Carbon::now()->startOfMonth()), Session::get('end'));
|
||||
|
||||
/** @var \TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
@ -627,7 +627,7 @@ class GoogleChartController extends BaseController
|
||||
/*
|
||||
* In the current session range?
|
||||
*/
|
||||
if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start')) {
|
||||
if (\Session::get('end') >= $current and $currentEnd >= \Session::get('start',Carbon::now()->startOfMonth())) {
|
||||
/*
|
||||
* Lets see if we've already spent money on this recurring transaction (it hath recurred).
|
||||
*/
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class HomeController
|
||||
@ -33,8 +34,8 @@ class HomeController extends BaseController
|
||||
|
||||
$count = $acct->countAssetAccounts();
|
||||
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||
|
||||
|
||||
// get the preference for the home accounts to show:
|
||||
|
@ -37,7 +37,7 @@ class TestContentSeeder extends Seeder
|
||||
$billsBudget = Budget::create(['user_id' => $user->id, 'name' => 'Bills']);
|
||||
|
||||
// create two categories:
|
||||
$dailyGroceries = Category::create(['user_id' => $user->id, 'name' => 'Daily groceries']);
|
||||
$dailyGroceries = Category::create(['user_id' => $user->id, 'name' => 'DailyGroceries']);
|
||||
$lunch = Category::create(['user_id' => $user->id, 'name' => 'Lunch']);
|
||||
$house = Category::create(['user_id' => $user->id, 'name' => 'House']);
|
||||
|
||||
|
@ -580,8 +580,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface
|
||||
->orderBy('date', 'DESC');
|
||||
|
||||
if ($range == 'session') {
|
||||
$query->before(\Session::get('end'));
|
||||
$query->after(\Session::get('start'));
|
||||
$query->before(\Session::get('end', \Carbon\Carbon::now()->startOfMonth()));
|
||||
$query->after(\Session::get('start', \Carbon\Carbon::now()->startOfMonth()));
|
||||
}
|
||||
$count = $query->count();
|
||||
$set = $query->take($limit)->offset($offset)->get(['transaction_journals.*']);
|
||||
|
@ -4,7 +4,7 @@
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
|
||||
<h4 class="modal-title" id="myModalLabel">Update (expected) income for {{Session::get('start')->format('F Y')}}</h4>
|
||||
<h4 class="modal-title" id="myModalLabel">Update (expected) income for {{Session::get('start', \Carbon\Carbon::now()->startOfMonth())->format('F Y')}}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="input-group">
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div class="col-lg-9 col-sm-8 col-md-8">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
{{\Session::get('start')->format('F Y')}}
|
||||
{{\Session::get('start', \Carbon\Carbon::now()->startOfMonth())->format('F Y')}}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
@ -13,7 +13,7 @@
|
||||
<small>Budgeted: <span id="budgetedAmount" data-value="300">{{mf(300)}}</span></small>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-4 col-sm-3" style="text-align:right;">
|
||||
<small>Income {{\Session::get('start')->format('F Y')}}:
|
||||
<small>Income {{\Session::get('start', \Carbon\Carbon::now()->startOfMonth())->format('F Y')}}:
|
||||
<a href="#" class="updateIncome"><span id="totalAmount" data-value="{{$amount}}">{{mf($amount)}}</span></a></small>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -76,7 +76,7 @@
|
||||
var repetitionID = {{$repetition->id}};
|
||||
var year = {{$repetition->startdate->format('Y')}};
|
||||
@else
|
||||
var year = {{Session::get('start')->format('Y')}};
|
||||
var year = {{Session::get('start',\Carbon\Carbon::now()->startOfMonth())->format('Y')}};
|
||||
@endif
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user