This commit is contained in:
James Cole
2018-05-28 19:07:06 +02:00
parent 73aef1b9a4
commit 4ad68b7dfa
2 changed files with 24 additions and 13 deletions

View File

@@ -87,6 +87,8 @@ class BudgetController extends Controller
$budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount); $budgetLimit = $this->repository->updateLimitAmount($budget, $start, $end, $amount);
$largeDiff = false; $largeDiff = false;
$warnText = ''; $warnText = '';
$days = 0;
$daysInMonth = 0;
if (0 === bccomp($amount, '0')) { if (0 === bccomp($amount, '0')) {
$budgetLimit = null; $budgetLimit = null;
} }
@@ -95,12 +97,15 @@ class BudgetController extends Controller
// otherwise, use diff between start and end. // otherwise, use diff between start and end.
$today = new Carbon; $today = new Carbon;
if ($today->gte($start) && $today->lte($end)) { 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)) { 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: // calculate left in budget:
$spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end); $spent = $repository->spentInPeriod(new Collection([$budget]), new Collection, $start, $end);
@@ -146,6 +151,7 @@ class BudgetController extends Controller
'large_diff' => $largeDiff, 'large_diff' => $largeDiff,
'left_per_day' => $leftPerDay, 'left_per_day' => $leftPerDay,
'warn_text' => $warnText, 'warn_text' => $warnText,
'daysInMonth' => $daysInMonth,
] ]
); );
@@ -229,22 +235,27 @@ class BudgetController extends Controller
*/ */
public function index(Request $request, string $moment = null) public function index(Request $request, string $moment = null)
{ {
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$start = session('start', new Carbon); $start = session('start', new Carbon);
$end = session('end', new Carbon); $end = session('end', new Carbon);
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)Preferences::get('listPageSize', 50)->data; $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) // 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. // otherwise, use diff between start and end.
$today = new Carbon; $today = new Carbon;
if ($today->gte($start) && $today->lte($end)) { 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)) { 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: // make date if present:
if (null !== $moment || '' !== (string)$moment) { if (null !== $moment || '' !== (string)$moment) {
@@ -312,7 +323,7 @@ class BudgetController extends Controller
return view( return view(
'budgets.index', compact( 'budgets.index', compact(
'available', 'currentMonth', 'next', 'nextText', 'prev', 'allBudgets', 'prevText', 'periodStart', 'periodEnd', 'days', 'page', 'available', 'currentMonth', 'next', 'nextText', 'prev', 'allBudgets', 'prevText', 'periodStart', 'periodEnd', 'days', 'page',
'budgetInformation', 'budgetInformation', 'daysInMonth',
'inactive', 'budgets', 'spent', 'budgeted', 'previousLoop', 'nextLoop', 'start', 'end' 'inactive', 'budgets', 'spent', 'budgeted', 'previousLoop', 'nextLoop', 'start', 'end'
) )
); );

View File

@@ -188,7 +188,7 @@
<td class="hidden-sm hidden-xs spent" data-id="{{ budget.id }}" data-spent="{{ budgetInformation[budget.id]['spent'] }}" <td class="hidden-sm hidden-xs spent" data-id="{{ budget.id }}" data-spent="{{ budgetInformation[budget.id]['spent'] }}"
data-value="{{ budgetInformation[budget.id]['spent'] }}"> data-value="{{ budgetInformation[budget.id]['spent'] }}">
{{ budgetInformation[budget.id]['spent']|formatAmount }} {{ budgetInformation[budget.id]['spent']|formatAmount }}
({{ (budgetInformation[budget.id]['spent'] / days)|formatAmount }}) ({{ (budgetInformation[budget.id]['spent'] / daysInMonth)|formatAmount }})
</td> </td>
<td class="left" data-id="{{ budget.id }}" <td class="left" data-id="{{ budget.id }}"
data-value="{{ (repAmount + budgetInformation[budget.id]['spent']) }}"> data-value="{{ (repAmount + budgetInformation[budget.id]['spent']) }}">