This commit is contained in:
James Cole 2020-09-11 07:12:11 +02:00
parent 22dc03f32c
commit 0b308cb5f2
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
3 changed files with 39 additions and 45 deletions

View File

@ -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);

View File

@ -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));
@ -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;
@ -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;
@ -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;

View File

@ -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 %}
{% 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 %}