mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-26 13:36:15 +00:00
Merge branch 'develop' into 5.8-dev
# Conflicts: # composer.lock # config/firefly.php # public/v1/js/create_transaction.js # public/v1/js/edit_transaction.js # public/v1/js/profile.js # resources/assets/js/locales/pt-br.json # resources/lang/pt_BR/firefly.php # yarn.lock
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',
|
||||
|
||||
67
app/Console/Commands/Correction/FixBudgetLimits.php
Normal file
67
app/Console/Commands/Correction/FixBudgetLimits.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* FixBudgetLimits.php
|
||||
* Copyright (c) 2022 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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',
|
||||
|
||||
@@ -288,18 +288,27 @@ class AccountFactory
|
||||
$fields = $this->validCCFields;
|
||||
}
|
||||
|
||||
// remove currency_id if necessary.
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
if (!in_array($type, $list, true)) {
|
||||
$pos = array_search('currency_id', $fields);
|
||||
if ($pos !== false) {
|
||||
unset($fields[$pos]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var AccountMetaFactory $factory */
|
||||
$factory = app(AccountMetaFactory::class);
|
||||
foreach ($fields as $field) {
|
||||
// if the field is set but NULL, skip it.
|
||||
// if the field is set but "", update it.
|
||||
if (array_key_exists($field, $data) && null !== $data[$field]) {
|
||||
|
||||
// convert boolean value:
|
||||
if (is_bool($data[$field]) && false === $data[$field]) {
|
||||
$data[$field] = 0;
|
||||
}
|
||||
if (is_bool($data[$field]) && true === $data[$field]) {
|
||||
if (true === $data[$field]) {
|
||||
$data[$field] = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -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' => [],
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Transaction;
|
||||
|
||||
use FireflyIII\Events\UpdatedTransactionGroup;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\BulkEditJournalRequest;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@@ -32,6 +33,7 @@ use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\View\View;
|
||||
use Log;
|
||||
|
||||
@@ -102,8 +104,8 @@ class BulkController extends Controller
|
||||
$ignoreCategory = 1 === (int) $request->get('ignore_category');
|
||||
$ignoreBudget = 1 === (int) $request->get('ignore_budget');
|
||||
$tagsAction = $request->get('tags_action');
|
||||
|
||||
$count = 0;
|
||||
$collection = new Collection;
|
||||
$count = 0;
|
||||
|
||||
foreach ($journalIds as $journalId) {
|
||||
$journalId = (int) $journalId;
|
||||
@@ -114,9 +116,17 @@ class BulkController extends Controller
|
||||
$resultC = $this->updateJournalCategory($journal, $ignoreCategory, $request->convertString('category'));
|
||||
if ($resultA || $resultB || $resultC) {
|
||||
$count++;
|
||||
$collection->push($journal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run rules on changed journals:
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($collection as $journal) {
|
||||
event(new UpdatedTransactionGroup($journal->transactionGroup));
|
||||
}
|
||||
|
||||
app('preferences')->mark();
|
||||
$request->session()->flash('success', (string) trans_choice('firefly.mass_edited_transactions_success', $count));
|
||||
|
||||
|
||||
@@ -486,6 +486,13 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function getAccountCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
|
||||
// return null if not in this list.
|
||||
if(!in_array($type, $list, true)) {
|
||||
return null;
|
||||
}
|
||||
$currencyId = (int) $this->getMetaValue($account, 'currency_id');
|
||||
if ($currencyId > 0) {
|
||||
return TransactionCurrency::find($currencyId);
|
||||
|
||||
@@ -115,6 +115,16 @@ trait AccountServiceTrait
|
||||
$fields = $this->validAssetFields;
|
||||
}
|
||||
|
||||
// remove currency_id if necessary.
|
||||
$type = $account->accountType->type;
|
||||
$list = config('firefly.valid_currency_account_types');
|
||||
if(!in_array($type, $list, true)) {
|
||||
$pos = array_search('currency_id', $fields);
|
||||
if ($pos !== false) {
|
||||
unset($fields[$pos]);
|
||||
}
|
||||
}
|
||||
|
||||
// the account role may not be set in the data but we may have it already:
|
||||
if (!array_key_exists('account_role', $data)) {
|
||||
$data['account_role'] = null;
|
||||
|
||||
Reference in New Issue
Block a user