mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-17 09:51:40 +00:00
Fix #7478
This commit is contained in:
@@ -27,6 +27,7 @@ use FireflyIII\Events\Model\BudgetLimit\Created;
|
|||||||
use FireflyIII\Events\Model\BudgetLimit\Deleted;
|
use FireflyIII\Events\Model\BudgetLimit\Deleted;
|
||||||
use FireflyIII\Events\Model\BudgetLimit\Updated;
|
use FireflyIII\Events\Model\BudgetLimit\Updated;
|
||||||
use FireflyIII\Models\AvailableBudget;
|
use FireflyIII\Models\AvailableBudget;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
use FireflyIII\Models\BudgetLimit;
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@@ -144,7 +145,7 @@ class BudgetLimitHandler
|
|||||||
*/
|
*/
|
||||||
private function getDailyAmount(BudgetLimit $budgetLimit): string
|
private function getDailyAmount(BudgetLimit $budgetLimit): string
|
||||||
{
|
{
|
||||||
if(0 === (int)$budgetLimit->id) {
|
if (0 === (int)$budgetLimit->id) {
|
||||||
return '0';
|
return '0';
|
||||||
}
|
}
|
||||||
$limitPeriod = Period::make(
|
$limitPeriod = Period::make(
|
||||||
@@ -177,13 +178,14 @@ class BudgetLimitHandler
|
|||||||
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
|
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
|
||||||
$viewRange = '1M';
|
$viewRange = '1M';
|
||||||
}
|
}
|
||||||
$start = app('navigation')->startOfPeriod($budgetLimit->start_date, $viewRange);
|
$start = app('navigation')->startOfPeriod($budgetLimit->start_date, $viewRange);
|
||||||
$end = app('navigation')->startOfPeriod($budgetLimit->end_date, $viewRange);
|
$end = app('navigation')->startOfPeriod($budgetLimit->end_date, $viewRange);
|
||||||
$end = app('navigation')->endOfPeriod($end, $viewRange);
|
$end = app('navigation')->endOfPeriod($end, $viewRange);
|
||||||
$user = $budgetLimit?->budget?->user;
|
$budget = Budget::withTrashed()->find($budgetLimit->budget_id);
|
||||||
|
$user = $budget->user;
|
||||||
|
|
||||||
// sanity check. It's rare but this happens.
|
// sanity check. It happens when the budget has been deleted so the original user is unknown.
|
||||||
if(null === $user) {
|
if (null === $user) {
|
||||||
Log::warning('User is null, cannot continue.');
|
Log::warning('User is null, cannot continue.');
|
||||||
$budgetLimit->forceDelete();
|
$budgetLimit->forceDelete();
|
||||||
return;
|
return;
|
||||||
@@ -217,10 +219,10 @@ class BudgetLimitHandler
|
|||||||
if ($currentPeriod->equals($limitPeriod)) {
|
if ($currentPeriod->equals($limitPeriod)) {
|
||||||
$amount = 0 === (int)$budgetLimit->id ? '0' : $budgetLimit->amount;
|
$amount = 0 === (int)$budgetLimit->id ? '0' : $budgetLimit->amount;
|
||||||
}
|
}
|
||||||
if(0 === bccomp($amount, '0')) {
|
if (0 === bccomp($amount, '0')) {
|
||||||
Log::debug('Amount is zero, will not create AB.');
|
Log::debug('Amount is zero, will not create AB.');
|
||||||
}
|
}
|
||||||
if(0 !== bccomp($amount, '0')) {
|
if (0 !== bccomp($amount, '0')) {
|
||||||
Log::debug(sprintf('Will create AB for period %s to %s', $current->format('Y-m-d'), $currentEnd->format('Y-m-d')));
|
Log::debug(sprintf('Will create AB for period %s to %s', $current->format('Y-m-d'), $currentEnd->format('Y-m-d')));
|
||||||
$availableBudget = new AvailableBudget(
|
$availableBudget = new AvailableBudget(
|
||||||
[
|
[
|
||||||
|
@@ -52,6 +52,8 @@ class BudgetDestroyService
|
|||||||
DB::table('budget_transaction')->where('budget_id', (int)$budget->id)->delete();
|
DB::table('budget_transaction')->where('budget_id', (int)$budget->id)->delete();
|
||||||
|
|
||||||
// also delete all budget limits
|
// also delete all budget limits
|
||||||
$budget->budgetlimits()->delete();
|
foreach($budget->budgetlimits()->get() as $limit) {
|
||||||
|
$limit->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user