mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-20 11:19:16 +00:00
Fix negative budget limits
This commit is contained in:
@@ -61,6 +61,7 @@ class CorrectDatabase extends Command
|
||||
'firefly-iii:create-link-types',
|
||||
'firefly-iii:create-access-tokens',
|
||||
'firefly-iii:remove-bills',
|
||||
'firefly-iii:fix-negative-limits',
|
||||
'firefly-iii:enable-currencies',
|
||||
'firefly-iii:fix-transfer-budgets',
|
||||
'firefly-iii:fix-uneven-amount',
|
||||
|
45
app/Console/Commands/Correction/FixBudgetLimits.php
Normal file
45
app/Console/Commands/Correction/FixBudgetLimits.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Console\Commands\Correction;
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Class CorrectionSkeleton
|
||||
*/
|
||||
class FixBudgetLimits extends Command
|
||||
{
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Fixes negative budget limits';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:fix-negative-limits';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$set = BudgetLimit::where('amount', '<', '0')->get();
|
||||
if (0 === $set->count()) {
|
||||
$this->info('All budget limits are OK.');
|
||||
return 0;
|
||||
}
|
||||
$count = BudgetLimit::where('amount', '<', '0')->update(['amount' => DB::raw('amount * -1')]);
|
||||
|
||||
$this->info(sprintf('Fixed %d budget limit(s)', $count));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@@ -82,6 +82,7 @@ class UpgradeDatabase extends Command
|
||||
'firefly-iii:create-link-types',
|
||||
'firefly-iii:create-access-tokens',
|
||||
'firefly-iii:remove-bills',
|
||||
'firefly-iii:fix-negative-limits',
|
||||
'firefly-iii:enable-currencies',
|
||||
'firefly-iii:fix-transfer-budgets',
|
||||
'firefly-iii:fix-uneven-amount',
|
||||
|
@@ -160,6 +160,9 @@ class BudgetLimitController extends Controller
|
||||
if ((int) $amount > 268435456) {
|
||||
$amount = '268435456';
|
||||
}
|
||||
if((float) $amount < 0.0) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
if (null !== $limit) {
|
||||
$limit->amount = $amount;
|
||||
@@ -226,6 +229,9 @@ class BudgetLimitController extends Controller
|
||||
if ((int) $amount > 268435456) { // 268 million
|
||||
$amount = '268435456';
|
||||
}
|
||||
if((float) $amount < 0.0) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
|
||||
$limit = $this->blRepository->update($budgetLimit, ['amount' => $amount]);
|
||||
$array = $limit->toArray();
|
||||
|
@@ -93,6 +93,7 @@ class InstallController extends Controller
|
||||
'firefly-iii:create-link-types' => [],
|
||||
'firefly-iii:create-access-tokens' => [],
|
||||
'firefly-iii:remove-bills' => [],
|
||||
'firefly-iii:fix-negative-limits' => [],
|
||||
'firefly-iii:enable-currencies' => [],
|
||||
'firefly-iii:fix-transfer-budgets' => [],
|
||||
'firefly-iii:fix-uneven-amount' => [],
|
||||
|
Reference in New Issue
Block a user