mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Remove double budget limits.
This commit is contained in:
@@ -588,6 +588,11 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, int $amount): BudgetLimit
|
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, int $amount): BudgetLimit
|
||||||
{
|
{
|
||||||
|
// count the limits:
|
||||||
|
$limits = $budget->budgetlimits()
|
||||||
|
->where('budget_limits.start_date', $start->format('Y-m-d'))
|
||||||
|
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
||||||
|
->get(['budget_limits.*'])->count();
|
||||||
// there might be a budget limit for these dates:
|
// there might be a budget limit for these dates:
|
||||||
/** @var BudgetLimit $limit */
|
/** @var BudgetLimit $limit */
|
||||||
$limit = $budget->budgetlimits()
|
$limit = $budget->budgetlimits()
|
||||||
@@ -595,6 +600,14 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
||||||
->first(['budget_limits.*']);
|
->first(['budget_limits.*']);
|
||||||
|
|
||||||
|
// if more than 1 limit found, delete the others:
|
||||||
|
if ($limits > 1 && !is_null($limit)) {
|
||||||
|
$budget->budgetlimits()
|
||||||
|
->where('budget_limits.start_date', $start->format('Y-m-d'))
|
||||||
|
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
||||||
|
->where('budget_limits.id', '!=', $limit->id)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
// delete if amount is zero.
|
// delete if amount is zero.
|
||||||
if (!is_null($limit) && $amount <= 0.0) {
|
if (!is_null($limit) && $amount <= 0.0) {
|
||||||
$limit->delete();
|
$limit->delete();
|
||||||
|
Reference in New Issue
Block a user