mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Extra large code cleanup.
This commit is contained in:
@@ -55,7 +55,6 @@ class PiggyBanks
|
||||
/** @var Collection $set */
|
||||
$set = $this->auth->user()->piggybanks()
|
||||
->leftJoin('piggy_bank_repetitions', 'piggy_banks.id', '=', 'piggy_bank_repetitions.piggy_bank_id')
|
||||
->where('piggy_banks.repeats', 0)
|
||||
->whereNull('piggy_bank_repetitions.id')
|
||||
->get(['piggy_banks.id', 'piggy_banks.startdate', 'piggy_banks.targetdate']);
|
||||
if ($set->count() > 0) {
|
||||
@@ -70,68 +69,6 @@ class PiggyBanks
|
||||
}
|
||||
}
|
||||
unset($partialPiggy, $set, $repetition);
|
||||
|
||||
// get repeating piggy banks without a repetition for current time frame.
|
||||
/** @var Collection $set */
|
||||
$set = $this->auth->user()->piggybanks()->leftJoin(
|
||||
'piggy_bank_repetitions', function (JoinClause $join) {
|
||||
$join->on('piggy_bank_repetitions.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
->where('piggy_bank_repetitions.targetdate', '>=', Session::get('start')->format('Y-m-d'))
|
||||
->where('piggy_bank_repetitions.startdate', '<=', Session::get('end')->format('Y-m-d'));
|
||||
}
|
||||
)
|
||||
->where('repeats', 1)
|
||||
->whereNull('piggy_bank_repetitions.id')
|
||||
->get(['piggy_banks.*']);
|
||||
|
||||
// these piggy banks are missing a repetition. start looping and create them!
|
||||
if ($set->count() > 0) {
|
||||
/** @var PiggyBank $piggyBank */
|
||||
foreach ($set as $piggyBank) {
|
||||
$start = clone $piggyBank->startdate;
|
||||
$end = clone $piggyBank->targetdate;
|
||||
$max = clone $piggyBank->targetdate;
|
||||
|
||||
// first loop: start date to target date.
|
||||
// then, continue looping until end is > today
|
||||
while ($start <= $max) {
|
||||
// first loop fixes this date. or should fix it.
|
||||
$max = new Carbon;
|
||||
|
||||
echo '[#' . $piggyBank->id . ', from: ' . $start->format('Y-m-d.') . ' to ' . $end->format('Y-m-d.') . ']';
|
||||
// create stuff. Or at least, try:
|
||||
$repetition = $piggyBank->piggyBankRepetitions()->onDates($start, $end)->first();
|
||||
if (!$repetition) {
|
||||
$repetition = new PiggyBankRepetition;
|
||||
$repetition->piggyBank()->associate($piggyBank);
|
||||
$repetition->startdate = $start;
|
||||
$repetition->targetdate = $end;
|
||||
$repetition->currentamount = 0;
|
||||
// it might exist, catch:
|
||||
$repetition->save();
|
||||
}
|
||||
|
||||
// start where end 'ended':
|
||||
$start = clone $end;
|
||||
// move end.
|
||||
$end = Navigation::addPeriod($end, $piggyBank->rep_length, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// first repetition: from original start to original target.
|
||||
$repetition = new PiggyBankRepetition;
|
||||
$repetition->piggyBank()->associate($piggyBank);
|
||||
$repetition->startdate = is_null($piggyBank->startdate) ? null : $piggyBank->startdate;
|
||||
$repetition->targetdate = is_null($piggyBank->targetdate) ? null : $piggyBank->targetdate;
|
||||
$repetition->currentamount = 0;
|
||||
// it might exist, catch:
|
||||
|
||||
// then, loop from original target up to now.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
Reference in New Issue
Block a user