mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix for #1111
This commit is contained in:
@@ -60,19 +60,17 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
// delete limits with amount 0:
|
||||
BudgetLimit::where('amount', 0)->delete();
|
||||
|
||||
// clean up:
|
||||
$set = BudgetLimit::groupBy(['budget_id', 'start_date', 'end_date'])
|
||||
->get(['budget_id', 'start_date', 'end_date', DB::raw('COUNT(*) as ct')]);
|
||||
foreach ($set as $entry) {
|
||||
if ($entry->ct > 1) {
|
||||
$newest = BudgetLimit::where('start_date', $entry->start_date)->where('end_date', $entry->end_date)
|
||||
->where('budget_id', $entry->budget_id)->orderBy('updated_at', 'DESC')->first(['budget_limits.*']);
|
||||
if (!is_null($newest)) {
|
||||
BudgetLimit::where('start_date', $entry->start_date)->where('end_date', $entry->end_date)
|
||||
->where('budget_id', $entry->budget_id)
|
||||
->where('id', '!=', $newest->id)->delete();
|
||||
}
|
||||
// do the clean up by hand because Sqlite can be tricky with this.
|
||||
$budgetLimits = BudgetLimit::orderBy('created_at', 'DESC')->get(['id', 'budget_id', 'start_date', 'end_date']);
|
||||
$count = [];
|
||||
/** @var BudgetLimit $budgetLimit */
|
||||
foreach ($budgetLimits as $budgetLimit) {
|
||||
$key = $budgetLimit->budget_id . '-' . $budgetLimit->start_date->format('Y-m-d') . $budgetLimit->end_date->format('Y-m-d');
|
||||
if (isset($count[$key])) {
|
||||
// delete it!
|
||||
BudgetLimit::find($budgetLimit->id)->delete();
|
||||
}
|
||||
$count[$key] = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -629,6 +627,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function updateLimitAmount(Budget $budget, Carbon $start, Carbon $end, string $amount): BudgetLimit
|
||||
{
|
||||
$this->cleanupBudgets();
|
||||
// count the limits:
|
||||
$limits = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
|
Reference in New Issue
Block a user