mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +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
|
||||
{
|
||||
// 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:
|
||||
/** @var BudgetLimit $limit */
|
||||
$limit = $budget->budgetlimits()
|
||||
@@ -595,6 +600,14 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d'))
|
||||
->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.
|
||||
if (!is_null($limit) && $amount <= 0.0) {
|
||||
$limit->delete();
|
||||
|
Reference in New Issue
Block a user