mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
Fixed routes and budgets.index #508
This commit is contained in:
@@ -21,6 +21,7 @@ use FireflyIII\Http\Requests\BudgetFormRequest;
|
|||||||
use FireflyIII\Http\Requests\BudgetIncomeRequest;
|
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\LimitRepetition;
|
use FireflyIII\Models\LimitRepetition;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
@@ -407,24 +408,22 @@ class BudgetController extends Controller
|
|||||||
'budgeted' => '0',
|
'budgeted' => '0',
|
||||||
'currentRep' => false,
|
'currentRep' => false,
|
||||||
];
|
];
|
||||||
$allRepetitions = $this->repository->getAllBudgetLimitRepetitions($start, $end);
|
$budgetLimits = $this->repository->getBudgetLimits($budget, $start, $end);
|
||||||
$otherRepetitions = new Collection;
|
$otherLimits = new Collection;
|
||||||
|
|
||||||
// get all the limit repetitions relevant between start and end and examine them:
|
// get all the budget limits relevant between start and end and examine them:
|
||||||
/** @var LimitRepetition $repetition */
|
/** @var BudgetLimit $limit */
|
||||||
foreach ($allRepetitions as $repetition) {
|
foreach ($budgetLimits as $limit) {
|
||||||
if ($repetition->budget_id == $budget->id) {
|
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)
|
||||||
if ($repetition->startdate->isSameDay($start) && $repetition->enddate->isSameDay($end)
|
) {
|
||||||
) {
|
$return[$budgetId]['currentLimit'] = $limit;
|
||||||
$return[$budgetId]['currentRep'] = $repetition;
|
$return[$budgetId]['budgeted'] = $limit->amount;
|
||||||
$return[$budgetId]['budgeted'] = $repetition->amount;
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// otherwise it's just one of the many relevant repetitions:
|
|
||||||
$otherRepetitions->push($repetition);
|
|
||||||
}
|
}
|
||||||
|
// otherwise it's just one of the many relevant repetitions:
|
||||||
|
$otherLimits->push($limit);
|
||||||
}
|
}
|
||||||
$return[$budgetId]['otherRepetitions'] = $otherRepetitions;
|
$return[$budgetId]['otherLimits'] = $otherLimits;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
@@ -32,12 +32,12 @@ class BudgetLimit extends Model
|
|||||||
= [
|
= [
|
||||||
'created_at' => 'date',
|
'created_at' => 'date',
|
||||||
'updated_at' => 'date',
|
'updated_at' => 'date',
|
||||||
'startdate' => 'date',
|
'start_date' => 'date',
|
||||||
|
'end_date' => 'date',
|
||||||
'repeats' => 'boolean',
|
'repeats' => 'boolean',
|
||||||
];
|
];
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $dates = ['created_at', 'updated_at'];
|
protected $dates = ['created_at', 'updated_at','start_date','end_date'];
|
||||||
protected $hidden = ['amount_encrypted'];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
|
@@ -14,8 +14,6 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Repositories\Budget;
|
namespace FireflyIII\Repositories\Budget;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Events\StoredBudgetLimit;
|
|
||||||
use FireflyIII\Events\UpdatedBudgetLimit;
|
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
use FireflyIII\Models\AvailableBudget;
|
use FireflyIII\Models\AvailableBudget;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
@@ -248,6 +246,36 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
return $amount;
|
return $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getBudgetLimits(Budget $budget, Carbon $start, Carbon $end): Collection
|
||||||
|
{
|
||||||
|
$set = $budget->budgetLimits()
|
||||||
|
->where(
|
||||||
|
function (Builder $q1) use ($start, $end) {
|
||||||
|
$q1->where(
|
||||||
|
function (Builder $q2) use ($start, $end) {
|
||||||
|
$q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d 00:00:00'));
|
||||||
|
$q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d 00:00:00'));
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->orWhere(
|
||||||
|
function (Builder $q3) use ($start, $end) {
|
||||||
|
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00'));
|
||||||
|
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 00:00:00'));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
)->get();
|
||||||
|
|
||||||
|
return $set;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is being used to generate the budget overview in the year/multi-year report. Its used
|
* This method is being used to generate the budget overview in the year/multi-year report. Its used
|
||||||
* in both the year/multi-year budget overview AND in the accompanying chart.
|
* in both the year/multi-year budget overview AND in the accompanying chart.
|
||||||
@@ -603,9 +631,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
$limit->amount = $amount;
|
$limit->amount = $amount;
|
||||||
$limit->save();
|
$limit->save();
|
||||||
|
|
||||||
// fire event to create or update LimitRepetition.
|
|
||||||
event(new UpdatedBudgetLimit($limit, $end));
|
|
||||||
|
|
||||||
return $limit;
|
return $limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,7 +642,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
$limit->repeat_freq = $repeatFreq;
|
$limit->repeat_freq = $repeatFreq;
|
||||||
$limit->repeats = 0;
|
$limit->repeats = 0;
|
||||||
$limit->save();
|
$limit->save();
|
||||||
event(new StoredBudgetLimit($limit, $end));
|
|
||||||
|
|
||||||
|
|
||||||
// likewise, there should be a limit repetition to match the end date
|
// likewise, there should be a limit repetition to match the end date
|
||||||
|
@@ -84,6 +84,8 @@ interface BudgetRepositoryInterface
|
|||||||
public function getActiveBudgets(): Collection;
|
public function getActiveBudgets(): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
@@ -100,6 +102,15 @@ interface BudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string;
|
public function getAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Budget $budget
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getBudgetLimits(Budget $budget, Carbon $start, Carbon $end): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param Collection $budgets
|
* @param Collection $budgets
|
||||||
|
@@ -90,8 +90,8 @@
|
|||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">
|
<h3 class="box-title">
|
||||||
<!-- link in header -->
|
<!-- link in header -->
|
||||||
{% if budgetInformation[budget.id]['currentRep'] %}
|
{% if budgetInformation[budget.id]['currentLimit'] %}
|
||||||
<a href="{{ route('budgets.show.repetition', [budget.id, budgetInformation[budget.id]['currentRep'].id]) }}" class="budget-link"
|
<a href="{{ route('budgets.show.limit', [budget.id, budgetInformation[budget.id]['currentLimit'].id]) }}" class="budget-link"
|
||||||
data-id="{{ budget.id }}">{{ budget.name }}</a>
|
data-id="{{ budget.id }}">{{ budget.name }}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ route('budgets.show',budget.id) }}" class="budget-link" data-id="{{ budget.id }}">{{ budget.name }}</a>
|
<a href="{{ route('budgets.show',budget.id) }}" class="budget-link" data-id="{{ budget.id }}">{{ budget.name }}</a>
|
||||||
@@ -123,8 +123,8 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-addon">{{ defaultCurrency.symbol|raw }}</div>
|
<div class="input-group-addon">{{ defaultCurrency.symbol|raw }}</div>
|
||||||
<input type="hidden" name="balance_currency_id" value="{{ defaultCurrency.id }}"/>
|
<input type="hidden" name="balance_currency_id" value="{{ defaultCurrency.id }}"/>
|
||||||
{% if budgetInformation[budget.id]['currentRep'] %}
|
{% if budgetInformation[budget.id]['currentLimit'] %}
|
||||||
{% set repAmount = budgetInformation[budget.id]['currentRep'].amount %}
|
{% set repAmount = budgetInformation[budget.id]['currentLimit'].amount %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set repAmount = '0' %}
|
{% set repAmount = '0' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -147,18 +147,18 @@
|
|||||||
{{ budgetInformation[budget.id]['spent']|formatAmount }}
|
{{ budgetInformation[budget.id]['spent']|formatAmount }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if budgetInformation[budget.id]['otherRepetitions'].count > 0 %}
|
{% if budgetInformation[budget.id]['otherLimits'].count > 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<ul class="list-unstyled">
|
<ul class="list-unstyled">
|
||||||
{% for other in budgetInformation[budget.id]['otherRepetitions'] %}
|
{% for other in budgetInformation[budget.id]['otherLimits'] %}
|
||||||
<li>
|
<li>
|
||||||
<!-- translate -->
|
<!-- translate -->
|
||||||
Budgeted
|
Budgeted
|
||||||
<a href="{{ route('budgets.show.repetition', [budget.id, other.id]) }}">{{ other.amount|formatAmountPlain }}</a>
|
<a href="{{ route('budgets.show.limit', [budget.id, other.id]) }}">{{ other.amount|formatAmountPlain }}</a>
|
||||||
between
|
between
|
||||||
{{ other.startdate.formatLocalized(monthAndDayFormat) }}
|
{{ other.start_date.formatLocalized(monthAndDayFormat) }}
|
||||||
and {{ other.enddate.formatLocalized(monthAndDayFormat) }}.
|
and {{ other.end_date.formatLocalized(monthAndDayFormat) }}.
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@@ -144,7 +144,7 @@ Route::group(
|
|||||||
Route::get('edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'edit']);
|
Route::get('edit/{budget}', ['uses' => 'BudgetController@edit', 'as' => 'edit']);
|
||||||
Route::get('delete/{budget}', ['uses' => 'BudgetController@delete', 'as' => 'delete']);
|
Route::get('delete/{budget}', ['uses' => 'BudgetController@delete', 'as' => 'delete']);
|
||||||
Route::get('show/{budget}', ['uses' => 'BudgetController@show', 'as' => 'show']);
|
Route::get('show/{budget}', ['uses' => 'BudgetController@show', 'as' => 'show']);
|
||||||
Route::get('show/{budget}/{limitrepetition}', ['uses' => 'BudgetController@showByRepetition', 'as' => 'show.repetition']);
|
Route::get('show/{budget}/{budgetlimit}', ['uses' => 'BudgetController@showByBudgetLimit', 'as' => 'show.limit']);
|
||||||
Route::get('list/no-budget', ['uses' => 'BudgetController@noBudget', 'as' => 'no-budget']);
|
Route::get('list/no-budget', ['uses' => 'BudgetController@noBudget', 'as' => 'no-budget']);
|
||||||
|
|
||||||
Route::post('income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'income.post']);
|
Route::post('income', ['uses' => 'BudgetController@postUpdateIncome', 'as' => 'income.post']);
|
||||||
@@ -250,7 +250,7 @@ Route::group(
|
|||||||
Route::get('frontpage', ['uses' => 'BudgetController@frontpage', 'as' => 'frontpage']);
|
Route::get('frontpage', ['uses' => 'BudgetController@frontpage', 'as' => 'frontpage']);
|
||||||
Route::get('period/0/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@periodNoBudget', 'as' => 'period.no-budget']);
|
Route::get('period/0/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@periodNoBudget', 'as' => 'period.no-budget']);
|
||||||
Route::get('period/{budget}/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@period', 'as' => 'period']);
|
Route::get('period/{budget}/{accountList}/{start_date}/{end_date}', ['uses' => 'BudgetController@period', 'as' => 'period']);
|
||||||
Route::get('budget/{budget}/{limitrepetition}', ['uses' => 'BudgetController@budgetLimit', 'as' => 'budget-limit']);
|
Route::get('budget/{budget}/{budgetlimit}', ['uses' => 'BudgetController@budgetLimit', 'as' => 'budget-limit']);
|
||||||
Route::get('budget/{budget}', ['uses' => 'BudgetController@budget', 'as' => 'budget']);
|
Route::get('budget/{budget}', ['uses' => 'BudgetController@budget', 'as' => 'budget']);
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user