Views must pick up on this #508

This commit is contained in:
James Cole 2016-12-30 07:39:42 +01:00
parent 497400587d
commit 13f6bd759b
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 68 additions and 35 deletions

View File

@ -22,7 +22,6 @@ use FireflyIII\Http\Requests\BudgetIncomeRequest;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\LimitRepetition;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@ -77,7 +76,7 @@ class BudgetController extends Controller
/** @var Carbon $start */ /** @var Carbon $start */
$start = session('start', Carbon::now()->startOfMonth()); $start = session('start', Carbon::now()->startOfMonth());
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth()); $end = session('end', Carbon::now()->endOfMonth());
$budgetLimit = $repository->updateLimitAmount($budget, $start, $end, $amount); $budgetLimit = $repository->updateLimitAmount($budget, $start, $end, $amount);
if ($amount == 0) { if ($amount == 0) {
$budgetLimit = null; $budgetLimit = null;
@ -263,13 +262,13 @@ class BudgetController extends Controller
$journals->setPath('/budgets/show/' . $budget->id); $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); $subTitle = e($budget->name);
$limits = new Collection(); $limits = new Collection();
/** @var LimitRepetition $entry */ /** @var BudgetLimit $entry */
foreach ($set as $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); $limits->push($entry);
} }
@ -277,16 +276,17 @@ class BudgetController extends Controller
} }
/** /**
* @param Request $request * @param Request $request
* @param Budget $budget * @param Budget $budget
* @param LimitRepetition $repetition * @param BudgetLimit $budgetLimit
* *
* @return View * @return View
* @throws FireflyException * @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.'); throw new FireflyException('This budget limit is not part of this budget.');
} }
@ -294,28 +294,30 @@ class BudgetController extends Controller
$repository = app(BudgetRepositoryInterface::class); $repository = app(BudgetRepositoryInterface::class);
/** @var AccountRepositoryInterface $accountRepository */ /** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);
$start = $repetition->startdate;
$end = $repetition->enddate;
$page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page')); $page = intval($request->get('page')) == 0 ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data); $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$subTitle = trans( $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]); $accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
// collector: // collector:
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class, [auth()->user()]); $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 = $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); $budgetLimit->spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $budgetLimit->start_date, $budgetLimit->end_date);
$limits = new Collection([$repetition]); $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) if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)
) { ) {
$return[$budgetId]['currentLimit'] = $limit; $return[$budgetId]['currentLimit'] = $limit;
$return[$budgetId]['budgeted'] = $limit->amount; $return[$budgetId]['budgeted'] = $limit->amount;
continue; continue;
} }
// otherwise it's just one of the many relevant repetitions: // otherwise it's just one of the many relevant repetitions:

View File

@ -17,9 +17,9 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\ImportJob; use FireflyIII\Models\ImportJob;
use FireflyIII\Models\LimitRepetition;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
@ -274,11 +274,20 @@ Breadcrumbs::register(
); );
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->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( $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])
); );
} }
); );

View File

@ -14,6 +14,7 @@ declare(strict_types = 1);
namespace FireflyIII\Models; namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/** /**
* Class BudgetLimit * Class BudgetLimit
@ -29,15 +30,34 @@ class BudgetLimit extends Model
* @var array * @var array
*/ */
protected $casts protected $casts
= [ = [
'created_at' => 'date', 'created_at' => 'date',
'updated_at' => 'date', 'updated_at' => 'date',
'start_date' => 'date', 'start_date' => 'date',
'end_date' => 'date', 'end_date' => 'date',
'repeats' => 'boolean', 'repeats' => 'boolean',
]; ];
/** @var array */ /** @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 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo

View File

@ -149,6 +149,7 @@ return [
'transaction_type' => 'FireflyIII\Models\TransactionType', 'transaction_type' => 'FireflyIII\Models\TransactionType',
'currency' => 'FireflyIII\Models\TransactionCurrency', 'currency' => 'FireflyIII\Models\TransactionCurrency',
'limitrepetition' => 'FireflyIII\Models\LimitRepetition', 'limitrepetition' => 'FireflyIII\Models\LimitRepetition',
'budgetlimit' => 'FireflyIII\Models\BudgetLimit',
'piggyBank' => 'FireflyIII\Models\PiggyBank', 'piggyBank' => 'FireflyIII\Models\PiggyBank',
'tj' => 'FireflyIII\Models\TransactionJournal', 'tj' => 'FireflyIII\Models\TransactionJournal',
'unfinishedJournal' => 'FireflyIII\Support\Binder\UnfinishedJournal', 'unfinishedJournal' => 'FireflyIII\Support\Binder\UnfinishedJournal',

View File

@ -1,7 +1,7 @@
{% extends "./layout/default" %} {% extends "./layout/default" %}
{% block breadcrumbs %} {% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, budget, repetition) }} {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, budget, budgetLimit) }}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -45,7 +45,10 @@
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title"><a <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) }} &mdash;
{{ limit.end_date.formatLocalized(monthAndDayFormat) }}
</a>
</h3> </h3>
</div> </div>
<div class="box-body"> <div class="box-body">
@ -93,12 +96,10 @@
{% block scripts %} {% block scripts %}
<script type="text/javascript"> <script type="text/javascript">
var budgetID = {{ budget.id }}; var budgetID = {{ budget.id }};
{% if repetition.id %} {% if budgetLimit.id %}
var repetitionID = {{ repetition.id }}; var budgetLimitID = {{ budgetLimit.id }};
var year = {{ repetition.startdate.format('Y') }}; var budgetChartUri = '{{ route('chart.budget.budget-limit', [budget.id, budgetLimit.id] ) }}';
var budgetChartUri = '{{ route('chart.budget.budget-limit', [budget.id, repetition.id] ) }}';
{% else %} {% else %}
var year = {{ Session.get('start').format('Y') }};
var budgetChartUri = '{{ route('chart.budget.budget', [budget.id] ) }}'; var budgetChartUri = '{{ route('chart.budget.budget', [budget.id] ) }}';
{% endif %} {% endif %}