Clean up for budget limits.

This commit is contained in:
James Cole
2015-04-03 19:39:36 +02:00
parent 0faef542c1
commit 35cdbec70a
4 changed files with 53 additions and 1 deletions

View File

@@ -16,6 +16,31 @@ use Illuminate\Pagination\LengthAwarePaginator;
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
*

View File

@@ -20,6 +20,11 @@ interface BudgetRepositoryInterface
*/
public function destroy(Budget $budget);
/**
* @return void
*/
public function cleanupBudgets();
/**
* @param Budget $budget
* @param Carbon $date