mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Views must pick up on this #508
This commit is contained in:
parent
497400587d
commit
13f6bd759b
@ -22,7 +22,6 @@ use FireflyIII\Http\Requests\BudgetIncomeRequest;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
@ -77,7 +76,7 @@ class BudgetController extends Controller
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$budgetLimit = $repository->updateLimitAmount($budget, $start, $end, $amount);
|
||||
if ($amount == 0) {
|
||||
$budgetLimit = null;
|
||||
@ -263,13 +262,13 @@ class BudgetController extends Controller
|
||||
$journals->setPath('/budgets/show/' . $budget->id);
|
||||
|
||||
|
||||
$set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();
|
||||
$set = $budget->budgetlimits()->orderBy('start_date', 'DESC')->get();
|
||||
$subTitle = e($budget->name);
|
||||
$limits = new Collection();
|
||||
|
||||
/** @var LimitRepetition $entry */
|
||||
/** @var BudgetLimit $entry */
|
||||
foreach ($set as $entry) {
|
||||
$entry->spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $entry->startdate, $entry->enddate);
|
||||
$entry->spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $entry->start_date, $entry->end_date);
|
||||
$limits->push($entry);
|
||||
}
|
||||
|
||||
@ -277,16 +276,17 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Budget $budget
|
||||
* @param LimitRepetition $repetition
|
||||
* @param Request $request
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*
|
||||
* @return View
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function showByRepetition(Request $request, Budget $budget, LimitRepetition $repetition)
|
||||
public function showByBudgetLimit(Request $request, Budget $budget, BudgetLimit $budgetLimit)
|
||||
{
|
||||
if ($repetition->budgetLimit->budget->id != $budget->id) {
|
||||
if ($budgetLimit->budget->id
|
||||
!= $budget->id) {
|
||||
throw new FireflyException('This budget limit is not part of this budget.');
|
||||
}
|
||||
|
||||
@ -294,28 +294,30 @@ class BudgetController extends Controller
|
||||
$repository = app(BudgetRepositoryInterface::class);
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$start = $repetition->startdate;
|
||||
$end = $repetition->enddate;
|
||||
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$subTitle = trans(
|
||||
'firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]
|
||||
'firefly.budget_in_period', [
|
||||
'name' => $budget->name,
|
||||
'start' => $budgetLimit->start_date->formatLocalized($this->monthAndDayFormat),
|
||||
'end' => $budgetLimit->end_date->formatLocalized($this->monthAndDayFormat),
|
||||
]
|
||||
);
|
||||
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
|
||||
|
||||
|
||||
// collector:
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setBudget($budget)->setLimit($pageSize)->setPage($page)->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts()->setRange($budgetLimit->start_date, $budgetLimit->end_date)
|
||||
->setBudget($budget)->setLimit($pageSize)->setPage($page)->withCategoryInformation();
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('/budgets/show/' . $budget->id . '/' . $repetition->id);
|
||||
$journals->setPath('/budgets/show/' . $budget->id . '/' . $budgetLimit->id);
|
||||
|
||||
|
||||
$repetition->spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $repetition->startdate, $repetition->enddate);
|
||||
$limits = new Collection([$repetition]);
|
||||
$budgetLimit->spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $budgetLimit->start_date, $budgetLimit->end_date);
|
||||
$limits = new Collection([$budgetLimit]);
|
||||
|
||||
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));
|
||||
return view('budgets.show', compact('limits', 'budget', 'budgetLimit', 'journals', 'subTitle'));
|
||||
|
||||
}
|
||||
|
||||
@ -416,7 +418,7 @@ class BudgetController extends Controller
|
||||
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)
|
||||
) {
|
||||
$return[$budgetId]['currentLimit'] = $limit;
|
||||
$return[$budgetId]['budgeted'] = $limit->amount;
|
||||
$return[$budgetId]['budgeted'] = $limit->amount;
|
||||
continue;
|
||||
}
|
||||
// otherwise it's just one of the many relevant repetitions:
|
||||
|
@ -17,9 +17,9 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\LimitRepetition;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\Rule;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
@ -274,11 +274,20 @@ Breadcrumbs::register(
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'budgets.show.repetition', function (BreadCrumbGenerator $breadcrumbs, Budget $budget, LimitRepetition $repetition) {
|
||||
'budgets.show.limit', function (BreadCrumbGenerator $breadcrumbs, Budget $budget, BudgetLimit $budgetLimit) {
|
||||
$breadcrumbs->parent('budgets.index');
|
||||
$breadcrumbs->push(e($budget->name), route('budgets.show.repetition', [$budget->id, $repetition->id]));
|
||||
$breadcrumbs->push(e($budget->name), route('budgets.show', [$budget->id]));
|
||||
|
||||
$title = trans(
|
||||
'firefly.budget_in_period_breadcrumb', [
|
||||
'name' => $budget->name,
|
||||
'start' => $budgetLimit->start_date->formatLocalized(strval(trans('config.month_and_day'))),
|
||||
'end' => $budgetLimit->end_date->formatLocalized(strval(trans('config.month_and_day'))),
|
||||
]
|
||||
);
|
||||
|
||||
$breadcrumbs->push(
|
||||
Navigation::periodShow($repetition->startdate, $repetition->budgetLimit->repeat_freq), route('budgets.show', [$budget->id, $repetition->id])
|
||||
$title, route('budgets.show.limit', [$budget->id, $budgetLimit->id])
|
||||
);
|
||||
}
|
||||
);
|
||||
|
@ -14,6 +14,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class BudgetLimit
|
||||
@ -29,15 +30,34 @@ class BudgetLimit extends Model
|
||||
* @var array
|
||||
*/
|
||||
protected $casts
|
||||
= [
|
||||
= [
|
||||
'created_at' => 'date',
|
||||
'updated_at' => 'date',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'repeats' => 'boolean',
|
||||
];
|
||||
/** @var array */
|
||||
protected $dates = ['created_at', 'updated_at','start_date','end_date'];
|
||||
protected $dates = ['created_at', 'updated_at', 'start_date', 'end_date'];
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function routeBinder($value)
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$object = self::where('budget_limits.id', $value)
|
||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->where('budgets.user_id', auth()->user()->id)
|
||||
->first(['budget_limits.*']);
|
||||
if ($object) {
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
|
@ -149,6 +149,7 @@ return [
|
||||
'transaction_type' => 'FireflyIII\Models\TransactionType',
|
||||
'currency' => 'FireflyIII\Models\TransactionCurrency',
|
||||
'limitrepetition' => 'FireflyIII\Models\LimitRepetition',
|
||||
'budgetlimit' => 'FireflyIII\Models\BudgetLimit',
|
||||
'piggyBank' => 'FireflyIII\Models\PiggyBank',
|
||||
'tj' => 'FireflyIII\Models\TransactionJournal',
|
||||
'unfinishedJournal' => 'FireflyIII\Support\Binder\UnfinishedJournal',
|
||||
|
@ -1,7 +1,7 @@
|
||||
{% extends "./layout/default" %}
|
||||
|
||||
{% block breadcrumbs %}
|
||||
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, budget, repetition) }}
|
||||
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, budget, budgetLimit) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@ -45,7 +45,10 @@
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title"><a
|
||||
href="{{ route('budgets.show.repetition',[budget.id,limit.id]) }}">{{ limit.startdate.formatLocalized(monthFormat) }}</a>
|
||||
href="{{ route('budgets.show.limit',[budget.id,limit.id]) }}">
|
||||
{{ limit.start_date.formatLocalized(monthAndDayFormat) }} —
|
||||
{{ limit.end_date.formatLocalized(monthAndDayFormat) }}
|
||||
</a>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
@ -93,12 +96,10 @@
|
||||
{% block scripts %}
|
||||
<script type="text/javascript">
|
||||
var budgetID = {{ budget.id }};
|
||||
{% if repetition.id %}
|
||||
var repetitionID = {{ repetition.id }};
|
||||
var year = {{ repetition.startdate.format('Y') }};
|
||||
var budgetChartUri = '{{ route('chart.budget.budget-limit', [budget.id, repetition.id] ) }}';
|
||||
{% if budgetLimit.id %}
|
||||
var budgetLimitID = {{ budgetLimit.id }};
|
||||
var budgetChartUri = '{{ route('chart.budget.budget-limit', [budget.id, budgetLimit.id] ) }}';
|
||||
{% else %}
|
||||
var year = {{ Session.get('start').format('Y') }};
|
||||
var budgetChartUri = '{{ route('chart.budget.budget', [budget.id] ) }}';
|
||||
{% endif %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user