mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up for budget limits.
This commit is contained in:
parent
0faef542c1
commit
35cdbec70a
@ -5,6 +5,7 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Http\Requests;
|
use FireflyIII\Http\Requests;
|
||||||
use FireflyIII\Http\Requests\BudgetFormRequest;
|
use FireflyIII\Http\Requests\BudgetFormRequest;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\LimitRepetition;
|
use FireflyIII\Models\LimitRepetition;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use Input;
|
use Input;
|
||||||
@ -120,6 +121,13 @@ class BudgetController extends Controller
|
|||||||
$budgets = Auth::user()->budgets()->where('active', 1)->get();
|
$budgets = Auth::user()->budgets()->where('active', 1)->get();
|
||||||
$inactive = Auth::user()->budgets()->where('active', 0)->get();
|
$inactive = Auth::user()->budgets()->where('active', 0)->get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do some cleanup:
|
||||||
|
*/
|
||||||
|
$repository->cleanupBudgets();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// loop the budgets:
|
// loop the budgets:
|
||||||
$budgets->each(
|
$budgets->each(
|
||||||
function (Budget $budget) use ($repository) {
|
function (Budget $budget) use ($repository) {
|
||||||
|
@ -16,6 +16,31 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
|||||||
class BudgetRepository implements BudgetRepositoryInterface
|
class BudgetRepository implements BudgetRepositoryInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function cleanupBudgets()
|
||||||
|
{
|
||||||
|
$limits = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')->get(['budget_limits.*']);
|
||||||
|
|
||||||
|
// loop budget limits:
|
||||||
|
$found = [];
|
||||||
|
/** @var BudgetLimit $limit */
|
||||||
|
foreach ($limits as $limit) {
|
||||||
|
$key = $limit->budget_id . '-' . $limit->startdate;
|
||||||
|
if (isset($found[$key])) {
|
||||||
|
$limit->delete();
|
||||||
|
} else {
|
||||||
|
$found[$key] = true;
|
||||||
|
}
|
||||||
|
unset($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete limits with amount 0:
|
||||||
|
BudgetLimit::where('amount',0)->delete();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
*
|
*
|
||||||
|
@ -20,6 +20,11 @@ interface BudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function destroy(Budget $budget);
|
public function destroy(Budget $budget);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function cleanupBudgets();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
* @param Carbon $date
|
* @param Carbon $date
|
||||||
|
@ -68,6 +68,13 @@ class ChangesForV336 extends Migration
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// remove a long forgotten index:
|
||||||
|
Schema::table(
|
||||||
|
'budget_limits', function (Blueprint $table) {
|
||||||
|
$table->dropUnique('unique_limit');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,7 +102,7 @@ class ChangesForV336 extends Migration
|
|||||||
Schema::table(
|
Schema::table(
|
||||||
'accounts', function (Blueprint $table) {
|
'accounts', function (Blueprint $table) {
|
||||||
$table->text('name')->change();
|
$table->text('name')->change();
|
||||||
$table->decimal('virtual_balance',10,2)->default(0);
|
$table->decimal('virtual_balance', 10, 2)->default(0);
|
||||||
$table->foreign('user_id', 'account_user_id')->references('id')->on('users')->onDelete('cascade');
|
$table->foreign('user_id', 'account_user_id')->references('id')->on('users')->onDelete('cascade');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -124,6 +131,13 @@ class ChangesForV336 extends Migration
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// reinstate a long forgotten index:
|
||||||
|
Schema::table(
|
||||||
|
'budget_limits', function (Blueprint $table) {
|
||||||
|
$table->unique(['budget_id', 'startdate'],'unique_limit');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BILLS
|
* BILLS
|
||||||
|
Loading…
Reference in New Issue
Block a user