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