Skip to content

Firefly III: a personal finances manager

Fix #1449

James Cole4ad68b7dfa3c
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index 3ab8154910..c1b6faa275 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -87,6 +87,8 @@ class BudgetController extends Controller
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
$largeDiff = false;
$warnText = '';
+ $days = 0;
+ $daysInMonth = 0;
if (0 === bccomp($amount, '0')) {
$budgetLimit = null;
}
@@ -95,12 +97,15 @@ class BudgetController extends Controller
// otherwise, use diff between start and end.
$today = new Carbon;
if ($today->gte($start) && $today->lte($end)) {
- $days = $end->diffInDays($today);
+ $days = $end->diffInDays($today);
+ $daysInMonth = $start->diffInDays($today);
}
if ($today->lte($start) || $today->gte($end)) {
- $days = $start->diffInDays($end);
+ $days = $start->diffInDays($end);
+ $daysInMonth = $start->diffInDays($end);
}
- $days = $days === 0 ? 1 : $days;
+ $days = $days === 0 ? 1 : $days;
+ $daysInMonth = $daysInMonth === 0 ? 1 : $daysInMonth;
// calculate left in budget:
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
@@ -146,6 +151,7 @@ class BudgetController extends Controller
'large_diff' => $largeDiff,
'left_per_day' => $leftPerDay,
'warn_text' => $warnText,
+ 'daysInMonth' => $daysInMonth,
]
);
@@ -229,22 +235,27 @@ class BudgetController extends Controller
*/
public function index(Request $request, string $moment = null)
{
- $range = Preferences::get('viewRange', '1M')->data;
- $start = session('start', new Carbon);
- $end = session('end', new Carbon);
- $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
- $pageSize = (int)Preferences::get('listPageSize', 50)->data;
+ $range = Preferences::get('viewRange', '1M')->data;
+ $start = session('start', new Carbon);
+ $end = session('end', new Carbon);
+ $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
+ $pageSize = (int)Preferences::get('listPageSize', 50)->data;
+ $days = 0;
+ $daysInMonth = 0;
// if today is between start and end, use the diff in days between end and today (days left)
// otherwise, use diff between start and end.
$today = new Carbon;
if ($today->gte($start) && $today->lte($end)) {
- $days = $end->diffInDays($today);
+ $days = $end->diffInDays($today);
+ $daysInMonth = $start->diffInDays($today);
}
if ($today->lte($start) || $today->gte($end)) {
- $days = $start->diffInDays($end);
+ $days = $start->diffInDays($end);
+ $daysInMonth = $start->diffInDays($end);
}
- $days = $days === 0 ? 1 : $days;
+ $days = $days === 0 ? 1 : $days;
+ $daysInMonth = $daysInMonth === 0 ? 1 : $daysInMonth;
// make date if present:
if (null !== $moment || '' !== (string)$moment) {
@@ -312,7 +323,7 @@ class BudgetController extends Controller
return view(
'budgets.index', compact(
'available', 'currentMonth', 'next', 'nextText', 'prev', 'allBudgets', 'prevText', 'periodStart', 'periodEnd', 'days', 'page',
- 'budgetInformation',
+ 'budgetInformation', 'daysInMonth',
'inactive', 'budgets', 'spent', 'budgeted', 'previousLoop', 'nextLoop', 'start', 'end'
)
);
diff --git a/resources/views/budgets/index.twig b/resources/views/budgets/index.twig
index 71dad53b7e..476199250a 100644
--- a/resources/views/budgets/index.twig
+++ b/resources/views/budgets/index.twig
@@ -188,7 +188,7 @@
<td class="hidden-sm hidden-xs spent" data-id="{{ budget.id }}" data-spent="{{ budgetInformation[budget.id]['spent'] }}"
data-value="{{ budgetInformation[budget.id]['spent'] }}">
{{ budgetInformation[budget.id]['spent']|formatAmount }}
- ({{ (budgetInformation[budget.id]['spent'] / days)|formatAmount }})
+ ({{ (budgetInformation[budget.id]['spent'] / daysInMonth)|formatAmount }})
</td>
<td class="left" data-id="{{ budget.id }}"
data-value="{{ (repAmount + budgetInformation[budget.id]['spent']) }}">