mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 08:30:06 +00:00
Some cleanup.
This commit is contained in:
@@ -22,6 +22,9 @@ class EloquentLimitTrigger
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function updateLimitRepetitions()
|
||||
{
|
||||
if (!\Auth::check()) {
|
||||
@@ -35,9 +38,6 @@ class EloquentLimitTrigger
|
||||
)
|
||||
->where('components.class', 'Budget')
|
||||
->get(['components.*']);
|
||||
$start = \Session::get('start');
|
||||
$end = new Carbon;
|
||||
|
||||
|
||||
// double check the non-repeating budgetlimits first.
|
||||
foreach ($budgets as $budget) {
|
||||
@@ -80,197 +80,10 @@ class EloquentLimitTrigger
|
||||
|
||||
}
|
||||
}
|
||||
// \Log::debug(
|
||||
// 'Now at budget ' . $budget->name . ', limit #' . $limit->id . ' (' . $limit->repeats . ', '
|
||||
// . $limit->repeat_freq . ', ' . $limit->startdate . ').'
|
||||
// );
|
||||
// $count = count($limit->limitrepetitions);
|
||||
// if ($count == 0) {
|
||||
// // create such a repetition:
|
||||
// $repetition = new \LimitRepetition();
|
||||
// $start = clone $limit->startdate;
|
||||
// $end = clone $start;
|
||||
//
|
||||
// // go to end:
|
||||
// switch ($limit->repeat_freq) {
|
||||
// case 'daily':
|
||||
// $end->addDay();
|
||||
// break;
|
||||
// case 'weekly':
|
||||
// $end->addWeek();
|
||||
// break;
|
||||
// case 'monthly':
|
||||
// $end->addMonth();
|
||||
// break;
|
||||
// case 'quarterly':
|
||||
// $end->addMonths(3);
|
||||
// break;
|
||||
// case 'half-year':
|
||||
// $end->addMonths(6);
|
||||
// break;
|
||||
// case 'yearly':
|
||||
// $end->addYear();
|
||||
// break;
|
||||
// }
|
||||
// $end->subDay();
|
||||
// $repetition->startdate = $start;
|
||||
// $repetition->enddate = $end;
|
||||
// $repetition->amount = $limit->amount;
|
||||
// $repetition->limit()->associate($limit);
|
||||
//
|
||||
// try {
|
||||
// $repetition->save();
|
||||
// \Log::debug('Created new repetition with id #' . $repetition->id);
|
||||
// } catch (QueryException $e) {
|
||||
// // do nothing
|
||||
// \Log::error('Trying to save new Limitrepetition failed!');
|
||||
// \Log::error($e->getMessage());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
// exit;
|
||||
//
|
||||
//
|
||||
// // get todays date.
|
||||
//
|
||||
// foreach ($budgets as $budget) {
|
||||
// // loop limits:
|
||||
// foreach ($budget->limits as $limit) {
|
||||
// // should have a repetition, at the very least
|
||||
// // for the period it starts (startdate and onwards).
|
||||
// \Log::debug('Limit #' . $limit->id . ' has ' . count($limit->limitrepetitions) . ' limitreps!');
|
||||
// if (count($limit->limitrepetitions) == 0) {
|
||||
//
|
||||
// // create such a repetition:
|
||||
// $repetition = new \LimitRepetition();
|
||||
// $start = clone $limit->startdate;
|
||||
// $end = clone $start;
|
||||
//
|
||||
// // go to end:
|
||||
// switch ($limit->repeat_freq) {
|
||||
// case 'daily':
|
||||
// $end->addDay();
|
||||
// break;
|
||||
// case 'weekly':
|
||||
// $end->addWeek();
|
||||
// break;
|
||||
// case 'monthly':
|
||||
// $end->addMonth();
|
||||
// break;
|
||||
// case 'quarterly':
|
||||
// $end->addMonths(3);
|
||||
// break;
|
||||
// case 'half-year':
|
||||
// $end->addMonths(6);
|
||||
// break;
|
||||
// case 'yearly':
|
||||
// $end->addYear();
|
||||
// break;
|
||||
// }
|
||||
// $end->subDay();
|
||||
// $repetition->startdate = $start;
|
||||
// $repetition->enddate = $end;
|
||||
// $repetition->amount = $limit->amount;
|
||||
// $repetition->limit()->associate($limit);
|
||||
//
|
||||
// try {
|
||||
// $repetition->save();
|
||||
// } catch (QueryException $e) {
|
||||
// // do nothing
|
||||
// \Log::error('Trying to save new Limitrepetition!');
|
||||
// \Log::error($e->getMessage());
|
||||
// }
|
||||
// } else {
|
||||
// // there are limits already, do they
|
||||
// // fall into the range surrounding today?
|
||||
// $today = new Carbon;
|
||||
// $today->addMonths(2);
|
||||
// if ($limit->repeats == 1 && $today >= $limit->startdate) {
|
||||
//
|
||||
// /** @var \Carbon\Carbon $flowStart */
|
||||
// $flowStart = clone $today;
|
||||
// /** @var \Carbon\Carbon $flowEnd */
|
||||
// $flowEnd = clone $today;
|
||||
//
|
||||
// switch ($limit->repeat_freq) {
|
||||
// case 'daily':
|
||||
// $flowStart->startOfDay();
|
||||
// $flowEnd->endOfDay();
|
||||
// break;
|
||||
// case 'weekly':
|
||||
// $flowStart->startOfWeek();
|
||||
// $flowEnd->endOfWeek();
|
||||
// break;
|
||||
// case 'monthly':
|
||||
// $flowStart->startOfMonth();
|
||||
// $flowEnd->endOfMonth();
|
||||
// break;
|
||||
// case 'quarterly':
|
||||
// $flowStart->firstOfQuarter();
|
||||
// $flowEnd->startOfMonth()->lastOfQuarter()->endOfDay();
|
||||
// break;
|
||||
// case 'half-year':
|
||||
//
|
||||
// if (intval($flowStart->format('m')) >= 7) {
|
||||
// $flowStart->startOfYear();
|
||||
// $flowStart->addMonths(6);
|
||||
// } else {
|
||||
// $flowStart->startOfYear();
|
||||
// }
|
||||
//
|
||||
// $flowEnd->endOfYear();
|
||||
// if (intval($start->format('m')) <= 6) {
|
||||
// $flowEnd->subMonths(6);
|
||||
// $flowEnd->subDay();
|
||||
//
|
||||
// }
|
||||
// break;
|
||||
// case 'yearly':
|
||||
// $flowStart->startOfYear();
|
||||
// $flowEnd->endOfYear();
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// $inRange = false;
|
||||
// foreach ($limit->limitrepetitions as $rep) {
|
||||
// if ($rep->startdate->format('dmY') == $flowStart->format('dmY')
|
||||
// && $rep->enddate->format('dmY') == $flowEnd->format('dmY')
|
||||
// ) {
|
||||
// // falls in current range, do nothing?
|
||||
// $inRange = true;
|
||||
// }
|
||||
// }
|
||||
// // if there is none that fall in range, create!
|
||||
// if ($inRange === false) {
|
||||
// // create (but check first)!
|
||||
// $count = \LimitRepetition::where('limit_id', $limit->id)->where('startdate', $flowStart)
|
||||
// ->where('enddate', $flowEnd)->count();
|
||||
// if ($count == 0) {
|
||||
// $repetition = new \LimitRepetition;
|
||||
// $repetition->startdate = $flowStart;
|
||||
// $repetition->enddate = $flowEnd;
|
||||
// $repetition->amount = $limit->amount;
|
||||
// $repetition->limit()->associate($limit);
|
||||
// try {
|
||||
// $repetition->save();
|
||||
// } catch (QueryException $e) {
|
||||
// // do nothing
|
||||
// \Log::error($e->getMessage());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
\Limit::observe(new EloquentLimitTrigger);
|
||||
Reference in New Issue
Block a user