mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-01 02:21:45 +00:00
Attempted fix with sanity check for #11284
This commit is contained in:
@@ -248,14 +248,28 @@ class Navigation
|
||||
Log::debug(sprintf('Diff in days is %d', $diffInDays));
|
||||
$currentEnd->addDays($diffInDays);
|
||||
|
||||
// add sanity check.
|
||||
if ($currentEnd->lt($end)) {
|
||||
throw new FireflyException(sprintf('[a] endOfPeriod(%s, %s) failed, because it resulted in %s.', $end->toW3cString(), $repeatFreq, $currentEnd->toW3cString()));
|
||||
}
|
||||
|
||||
return $currentEnd;
|
||||
}
|
||||
if ('MTD' === $repeatFreq) {
|
||||
$today = today();
|
||||
if ($today->isSameMonth($end)) {
|
||||
return $today->endOfDay()->milli(0);
|
||||
$res = $today->endOfDay()->milli(0);
|
||||
// add sanity check.
|
||||
if($res->lt($end)) {
|
||||
throw new FireflyException(sprintf('[b] endOfPeriod(%s, %s) failed, because it resulted in %s.', $end->toW3cString(), $repeatFreq, $res->toW3cString()));
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
// add sanity check.
|
||||
if ($currentEnd->lt($end)) {
|
||||
throw new FireflyException(sprintf('[c] endOfPeriod(%s, %s) failed, because it resulted in %s.', $end->toW3cString(), $repeatFreq, $currentEnd->toW3cString()));
|
||||
}
|
||||
return $end->endOfMonth();
|
||||
}
|
||||
|
||||
@@ -270,6 +284,11 @@ class Navigation
|
||||
default => null,
|
||||
};
|
||||
if (null !== $result) {
|
||||
// add sanity check.
|
||||
if ($currentEnd->lt($end)) {
|
||||
throw new FireflyException(sprintf('[d] endOfPeriod(%s, %s) failed, because it resulted in %s.', $end->toW3cString(), $repeatFreq, $currentEnd->toW3cString()));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
unset($result);
|
||||
@@ -277,6 +296,11 @@ class Navigation
|
||||
if (!array_key_exists($repeatFreq, $functionMap)) {
|
||||
Log::error(sprintf('Cannot do endOfPeriod for $repeat_freq "%s"', $repeatFreq));
|
||||
|
||||
// add sanity check.
|
||||
if ($currentEnd->lt($end)) {
|
||||
throw new FireflyException(sprintf('[e] endOfPeriod(%s, %s) failed, because it resulted in %s.', $end->toW3cString(), $repeatFreq, $currentEnd->toW3cString()));
|
||||
}
|
||||
|
||||
return $end;
|
||||
}
|
||||
$function = $functionMap[$repeatFreq];
|
||||
@@ -288,6 +312,11 @@ class Navigation
|
||||
}
|
||||
$currentEnd->endOfDay()->milli(0);
|
||||
|
||||
// add sanity check.
|
||||
if ($currentEnd->lt($end)) {
|
||||
throw new FireflyException(sprintf('[f] endOfPeriod(%s, %s) failed, because it resulted in %s.', $end->toW3cString(), $repeatFreq, $currentEnd->toW3cString()));
|
||||
}
|
||||
|
||||
return $currentEnd;
|
||||
}
|
||||
$currentEnd->{$function}(); // @phpstan-ignore-line
|
||||
@@ -297,6 +326,11 @@ class Navigation
|
||||
}
|
||||
// Log::debug(sprintf('Final result: %s', $currentEnd->toIso8601String()));
|
||||
|
||||
// add sanity check.
|
||||
if ($currentEnd->lt($end)) {
|
||||
throw new FireflyException(sprintf('[g] endOfPeriod(%s, %s) failed, because it resulted in %s.', $end->toW3cString(), $repeatFreq, $currentEnd->toW3cString()));
|
||||
}
|
||||
|
||||
return $currentEnd;
|
||||
}
|
||||
|
||||
|
||||
@@ -201,18 +201,8 @@ trait RecalculatesAvailableBudgetsTrait
|
||||
Log::debug('Found 1 AB, will update.');
|
||||
$this->calculateAmount($availableBudget);
|
||||
}
|
||||
if (null === $availableBudget) {
|
||||
Log::debug('No AB found, will create.');
|
||||
|
||||
// if not exists:
|
||||
try {
|
||||
if (null === $availableBudget && $currentEnd->gte($current)) {
|
||||
$currentPeriod = Period::make($current, $currentEnd, precision: Precision::DAY(), boundaries: Boundaries::EXCLUDE_NONE());
|
||||
} catch (InvalidPeriod $e) {
|
||||
Log::error('Tried to make invalid period.');
|
||||
Log::error($e->getMessage());
|
||||
|
||||
continue;
|
||||
}
|
||||
$daily = $this->getDailyAmount($budgetLimit);
|
||||
$amount = bcmul((string)$daily, (string)$currentPeriod->length(), 12);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user