mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #1356
This commit is contained in:
@@ -87,16 +87,31 @@ 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 = '';
|
||||||
$average = '0';
|
|
||||||
$current = '0';
|
|
||||||
if (0 === bccomp($amount, '0')) {
|
if (0 === bccomp($amount, '0')) {
|
||||||
$budgetLimit = null;
|
$budgetLimit = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
if ($today->lte($start) || $today->gte($end)) {
|
||||||
|
$days = $start->diffInDays($end);
|
||||||
|
}
|
||||||
|
$days = $days === 0 ? 1 : $days;
|
||||||
|
|
||||||
// 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);
|
||||||
$currency = app('amount')->getDefaultCurrency();
|
$currency = app('amount')->getDefaultCurrency();
|
||||||
$left = app('amount')->formatAnything($currency, bcadd($amount, $spent), true);
|
$left = app('amount')->formatAnything($currency, bcadd($amount, $spent), true);
|
||||||
|
$leftPerDay = 'none';
|
||||||
|
|
||||||
|
// is user has money left, calculate.
|
||||||
|
if (1 === bccomp(bcadd($amount, $spent), '0')) {
|
||||||
|
$leftPerDay = app('amount')->formatAnything($currency, bcdiv(bcadd($amount, $spent), (string)$days), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// over or under budgeting, compared to previous budgets?
|
// over or under budgeting, compared to previous budgets?
|
||||||
@@ -112,8 +127,8 @@ class BudgetController extends Controller
|
|||||||
$warnText = (string)trans(
|
$warnText = (string)trans(
|
||||||
'firefly.over_budget_warn',
|
'firefly.over_budget_warn',
|
||||||
[
|
[
|
||||||
'amount' => app('amount')->formatAnything($currency, $average, false),
|
'amount' => app('amount')->formatAnything($currency, $average, false),
|
||||||
'over_amount' => app('amount')->formatAnything($currency, $current, false),
|
'over_amount' => app('amount')->formatAnything($currency, $current, false),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -122,14 +137,15 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
return response()->json(
|
return response()->json(
|
||||||
[
|
[
|
||||||
'left' => $left,
|
'left' => $left,
|
||||||
'name' => $budget->name,
|
'name' => $budget->name,
|
||||||
'limit' => $budgetLimit ? $budgetLimit->id : 0,
|
'limit' => $budgetLimit ? $budgetLimit->id : 0,
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
'current' => $current,
|
'current' => $current,
|
||||||
'average' => $average,
|
'average' => $average,
|
||||||
'large_diff' => $largeDiff,
|
'large_diff' => $largeDiff,
|
||||||
'warn_text' => $warnText,
|
'left_per_day' => $leftPerDay,
|
||||||
|
'warn_text' => $warnText,
|
||||||
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@@ -219,6 +235,17 @@ class BudgetController extends Controller
|
|||||||
$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;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
if ($today->lte($start) || $today->gte($end)) {
|
||||||
|
$days = $start->diffInDays($end);
|
||||||
|
}
|
||||||
|
$days = $days === 0 ? 1 : $days;
|
||||||
|
|
||||||
// make date if present:
|
// make date if present:
|
||||||
if (null !== $moment || '' !== (string)$moment) {
|
if (null !== $moment || '' !== (string)$moment) {
|
||||||
try {
|
try {
|
||||||
@@ -283,27 +310,11 @@ class BudgetController extends Controller
|
|||||||
$prevText = app('navigation')->periodShow($prev, $range);
|
$prevText = app('navigation')->periodShow($prev, $range);
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'budgets.index',
|
'budgets.index', compact(
|
||||||
compact(
|
'available', 'currentMonth', 'next', 'nextText', 'prev', 'allBudgets', 'prevText', 'periodStart', 'periodEnd', 'days', 'page',
|
||||||
'available',
|
'budgetInformation',
|
||||||
'currentMonth',
|
'inactive', 'budgets', 'spent', 'budgeted', 'previousLoop', 'nextLoop', 'start', 'end'
|
||||||
'next',
|
)
|
||||||
'nextText',
|
|
||||||
'prev', 'allBudgets',
|
|
||||||
'prevText',
|
|
||||||
'periodStart',
|
|
||||||
'periodEnd',
|
|
||||||
'page',
|
|
||||||
'budgetInformation',
|
|
||||||
'inactive',
|
|
||||||
'budgets',
|
|
||||||
'spent',
|
|
||||||
'budgeted',
|
|
||||||
'previousLoop',
|
|
||||||
'nextLoop',
|
|
||||||
'start',
|
|
||||||
'end'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
8
public/js/ff/budgets/index.js
vendored
8
public/js/ff/budgets/index.js
vendored
@@ -129,7 +129,13 @@ function updateBudgetedAmounts(e) {
|
|||||||
budgeted = budgeted + difference;
|
budgeted = budgeted + difference;
|
||||||
|
|
||||||
// fill in "left" value:
|
// fill in "left" value:
|
||||||
leftCell.html(data.left);
|
|
||||||
|
|
||||||
|
if (data.left_per_day !== 'none') {
|
||||||
|
leftCell.html(data.left + '(' + data.left_per_day + ')');
|
||||||
|
} else {
|
||||||
|
leftCell.html(data.left);
|
||||||
|
}
|
||||||
|
|
||||||
// update "budgeted" input:
|
// update "budgeted" input:
|
||||||
target.val(data.amount);
|
target.val(data.amount);
|
||||||
|
|||||||
@@ -146,8 +146,8 @@
|
|||||||
<th data-defaultsort="disabled" class="hidden-sm hidden-xs" style="width:10%;"> </th>
|
<th data-defaultsort="disabled" class="hidden-sm hidden-xs" style="width:10%;"> </th>
|
||||||
<th data-defaultsign="az">{{ 'budget'|_ }}</th>
|
<th data-defaultsign="az">{{ 'budget'|_ }}</th>
|
||||||
<th data-defaultsign="_19" style="width:25%;">{{ 'budgeted'|_ }}</th>
|
<th data-defaultsign="_19" style="width:25%;">{{ 'budgeted'|_ }}</th>
|
||||||
<th data-defaultsign="_19" class="hidden-sm hidden-xs">{{ 'spent'|_ }}</th>
|
<th data-defaultsign="_19" class="hidden-sm hidden-xs">{{ 'spent'|_ }} ({{ 'per_day'|_|lower }})</th>
|
||||||
<th data-defaultsign="_19">{{ 'left'|_ }}</th>
|
<th data-defaultsign="_19">{{ 'left'|_ }} ({{ 'per_day'|_|lower }})</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -188,10 +188,14 @@
|
|||||||
<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 }})
|
||||||
</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']) }}">
|
||||||
{{ (repAmount + budgetInformation[budget.id]['spent'])|formatAmount }}
|
{{ (repAmount + budgetInformation[budget.id]['spent'])|formatAmount }}
|
||||||
|
{% if repAmount + budgetInformation[budget.id]['spent'] > 0 %}
|
||||||
|
({{ ((repAmount + budgetInformation[budget.id]['spent']) / days)|formatAmount }})
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user