Skip to content

Firefly III: a personal finances manager

Fix #3791

James Cole0b308cb5f284
diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php
index 0fa9bd416f..45a3bdc178 100644
--- a/app/Http/Controllers/Budget/ShowController.php
+++ b/app/Http/Controllers/Budget/ShowController.php
@@ -123,7 +123,7 @@ class ShowController extends Controller
$subTitle = (string) trans('firefly.all_journals_without_budget');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon : $first->date;
- $end = new Carbon;
+ $end = today(config('app.timezone'));
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
@@ -150,11 +150,7 @@ class ShowController extends Controller
{
/** @var Carbon $start */
$allStart = session('first', Carbon::now()->startOfYear());
- $allEnd = new Carbon;
-
- // use session range:
- $start = session('start');
- $end = session('end');
+ $allEnd = today();
$page = (int) $request->get('page');
@@ -166,7 +162,7 @@ class ShowController extends Controller
// collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
- $collector->setRange($start, $end)->setBudget($budget)
+ $collector->setRange($allStart, $allEnd)->setBudget($budget)
->withAccountInformation()
->setLimit($pageSize)->setPage($page)->withBudgetInformation()->withCategoryInformation();
$groups = $collector->getPaginatedGroups();
@@ -215,7 +211,7 @@ class ShowController extends Controller
$groups->setPath(route('budgets.show', [$budget->id, $budgetLimit->id]));
/** @var Carbon $start */
$start = session('first', Carbon::now()->startOfYear());
- $end = new Carbon;
+ $end = today(config('app.timezone'));
$attachments = $this->repository->getAttachments($budget);
$limits = $this->getLimits($budget, $start, $end);
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 12a898f5a5..ba44248e2b 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -48,6 +48,7 @@ use Illuminate\Support\Collection;
class BudgetController extends Controller
{
use DateCalculation, AugumentData;
+
/** @var GeneratorInterface Chart generation methods. */
protected $generator;
/** @var OperationsRepositoryInterface */
@@ -92,9 +93,9 @@ class BudgetController extends Controller
public function budget(Budget $budget): JsonResponse
{
/** @var Carbon $start */
- $start = $this->repository->firstUseDate($budget) ?? session('start', new Carbon);
+ $start = $this->repository->firstUseDate($budget) ?? session('start', today(config('app.timezone')));
/** @var Carbon $end */
- $end = session('end', new Carbon);
+ $end = session('end', today(config('app.timezone')));
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
@@ -102,7 +103,7 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
if ($cache->has()) {
- return response()->json($cache->get()); // @codeCoverageIgnore
+ //return response()->json($cache->get()); // @codeCoverageIgnore
}
$step = $this->calculateStep($start, $end); // depending on diff, do something with range of chart.
$collection = new Collection([$budget]);
@@ -114,9 +115,6 @@ class BudgetController extends Controller
while ($end >= $loopStart) {
/** @var Carbon $currentEnd */
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
- if ('1Y' === $step) {
- $loopEnd->subDay(); // @codeCoverageIgnore
- }
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
$label = trim(app('navigation')->periodShow($loopStart, $step));
@@ -141,7 +139,7 @@ class BudgetController extends Controller
'entries' => $defaultEntries,
];
foreach ($currency['spent'] as $label => $spent) {
- $chartData[$currencyId]['entries'][$label] = round(bcmul($spent, '-1'), $currency['currency_decimal_places']);
+ $chartData[$currencyId]['entries'][$label] = bcmul($spent, '-1');
}
}
$data = $this->generator->multiSet(array_values($chartData));
@@ -179,19 +177,19 @@ class BudgetController extends Controller
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
}
- $locale = app('steam')->getLocale();
+ $locale = app('steam')->getLocale();
$entries = [];
$amount = $budgetLimit->amount;
$budgetCollection = new Collection([$budget]);
while ($start <= $end) {
$spent = $this->opsRepository->spentInPeriod($budgetCollection, new Collection, $start, $start);
$amount = bcadd($amount, $spent);
- $format = $start->formatLocalized((string)trans('config.month_and_day', [], $locale));
+ $format = $start->formatLocalized((string) trans('config.month_and_day', [], $locale));
$entries[$format] = $amount;
$start->addDay();
}
- $data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
+ $data = $this->generator->singleSet((string) trans('firefly.left'), $entries);
// add currency symbol from budget limit:
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
$data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code;
@@ -218,8 +216,9 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-asset');
- $start = session()->get('start');
- $end = session()->get('end');
+ $start = session('first', Carbon::now()->startOfYear());
+ $end = today();
+
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
@@ -239,7 +238,7 @@ class BudgetController extends Controller
// group by asset account ID:
foreach ($journals as $journal) {
- $key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
+ $key = sprintf('%d-%d', (int) $journal['source_account_id'], $journal['currency_id']);
$result[$key] = $result[$key] ?? [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
@@ -252,13 +251,13 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
- $assetId = (int)$parts[0];
+ $assetId = (int) $parts[0];
$title = sprintf('%s (%s)', $names[$assetId] ?? '(empty)', $info['currency_name']);
$chartData[$title]
= [
'amount' => $info['amount'],
'currency_symbol' => $info['currency_symbol'],
- 'currency_code' => $info['currency_code'],
+ 'currency_code' => $info['currency_code'],
];
}
@@ -286,8 +285,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-category');
- $start = session()->get('start');
- $end = session()->get('end');
+ $start = session('first', Carbon::now()->startOfYear());
+ $end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
@@ -319,12 +318,12 @@ class BudgetController extends Controller
$names = $this->getCategoryNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
- $categoryId = (int)$parts[0];
+ $categoryId = (int) $parts[0];
$title = sprintf('%s (%s)', $names[$categoryId] ?? '(empty)', $info['currency_name']);
$chartData[$title] = [
'amount' => $info['amount'],
'currency_symbol' => $info['currency_symbol'],
- 'currency_code' => $info['currency_code'],
+ 'currency_code' => $info['currency_code'],
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
@@ -352,8 +351,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-expense');
- $start = session()->get('start');
- $end = session()->get('end');
+ $start = session('first', Carbon::now()->startOfYear());
+ $end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
@@ -385,13 +384,13 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
- $opposingId = (int)$parts[0];
+ $opposingId = (int) $parts[0];
$name = $names[$opposingId] ?? 'no name';
$title = sprintf('%s (%s)', $name, $info['currency_name']);
$chartData[$title] = [
'amount' => $info['amount'],
'currency_symbol' => $info['currency_symbol'],
- 'currency_code' => $info['currency_code'],
+ 'currency_code' => $info['currency_code'],
];
}
@@ -421,13 +420,13 @@ class BudgetController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.budget.frontpage');
if ($cache->has()) {
- return response()->json($cache->get()); // @codeCoverageIgnore
+ return response()->json($cache->get()); // @codeCoverageIgnore
}
$budgets = $this->repository->getActiveBudgets();
$chartData = [
- ['label' => (string)trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'],
- ['label' => (string)trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'],
- ['label' => (string)trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'],
+ ['label' => (string) trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'],
+ ['label' => (string) trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'],
+ ['label' => (string) trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'],
];
/** @var Budget $budget */
@@ -439,8 +438,8 @@ class BudgetController extends Controller
foreach ($spent as $entry) {
$title = sprintf('%s (%s)', $budget->name, $entry['currency_name']);
$chartData[0]['entries'][$title] = bcmul($entry['sum'], '-1'); // spent
- $chartData[1]['entries'][$title] = 0; // left to spend
- $chartData[2]['entries'][$title] = 0; // overspent
+ $chartData[1]['entries'][$title] = 0; // left to spend
+ $chartData[2]['entries'][$title] = 0; // overspent
}
}
if (0 !== $limits->count()) {
@@ -596,7 +595,7 @@ class BudgetController extends Controller
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}
- $data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
+ $data = $this->generator->singleSet((string) trans('firefly.spent'), $chartData);
$cache->store($data);
return response()->json($data);
diff --git a/resources/views/v1/budgets/show.twig b/resources/views/v1/budgets/show.twig
index b114f732c9..d4cfbdb76a 100644
--- a/resources/views/v1/budgets/show.twig
+++ b/resources/views/v1/budgets/show.twig
@@ -112,26 +112,23 @@
</div>
</div>
</div>
-
+ {% if limits|length > 0 %}
<div class="row">
<div class="col-lg-offset-9 col-lg-3 col-md-offset-9 col-md-3 col-sm-12 col-xs-12">
<p class="small text-center"><a href="{{ route('budgets.show',budget.id) }}">{{ 'showEverything'|_ }}</a></p>
</div>
</div>
+ {% endif %}
<div class="row">
- <div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
+ <div class="{% if limits|length > 0 %}col-lg-9 col-md-9 col-sm-12 col-xs-12{% else %}col-lg-12 col-md-12 col-sm-12 col-xs-12{% endif %}">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div>
<div class="box-body">
- {% if budgetLimit %}
- {% include 'list.groups' %}
- {% else %}
- {% include 'list.groups' %}
- {% endif %}
+ {% include 'list.groups' %}
{% if budgetLimit %}
<p>
<i class="fa fa-calendar"></i>
@@ -143,6 +140,7 @@
</div>
</div>
</div>
+ {% if limits|length > 0 %}
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
{% for limit in limits %}
<div class="box {% if limit.start_date == budgetLimit.start_date %}box-primary box-solid{% endif %}">
@@ -199,6 +197,7 @@
{% endfor %}
<p class="small text-center"><a href="{{ route('budgets.show',budget.id) }}">{{ 'showEverything'|_ }}</a></p>
</div>
+ {% endif %}
</div>
{% endblock %}