2023-01-08 07:43:16 +01:00
|
|
|
<?php
|
|
|
|
|
2023-07-15 16:02:42 +02:00
|
|
|
/*
|
|
|
|
* TriggerCreditCalculation.php
|
|
|
|
* Copyright (c) 2023 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/>.
|
|
|
|
*/
|
|
|
|
|
2023-01-15 15:47:25 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-01-08 07:43:16 +01:00
|
|
|
namespace FireflyIII\Console\Commands\Correction;
|
|
|
|
|
|
|
|
use FireflyIII\Models\Account;
|
|
|
|
use FireflyIII\Services\Internal\Support\CreditRecalculateService;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CorrectionSkeleton
|
|
|
|
*/
|
|
|
|
class TriggerCreditCalculation extends Command
|
|
|
|
{
|
|
|
|
protected $description = 'Triggers the credit recalculation service for liabilities.';
|
2023-06-02 07:36:17 +02:00
|
|
|
protected $signature = 'firefly-iii:trigger-credit-recalculation';
|
2023-01-08 07:43:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
|
|
|
public function handle(): int
|
|
|
|
{
|
|
|
|
$this->processAccounts();
|
2023-05-29 13:56:55 +02:00
|
|
|
|
2023-01-08 07:43:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-21 12:34:58 +02:00
|
|
|
private function processAccounts(): void
|
|
|
|
{
|
|
|
|
$accounts = Account::leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
|
2023-12-20 19:35:52 +01:00
|
|
|
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
|
|
|
->get(['accounts.*'])
|
|
|
|
;
|
2023-06-21 12:34:58 +02:00
|
|
|
foreach ($accounts as $account) {
|
|
|
|
$this->processAccount($account);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 07:43:16 +01:00
|
|
|
private function processAccount(Account $account): void
|
|
|
|
{
|
|
|
|
/** @var CreditRecalculateService $object */
|
|
|
|
$object = app(CreditRecalculateService::class);
|
|
|
|
$object->setAccount($account);
|
|
|
|
$object->recalculate();
|
|
|
|
}
|
|
|
|
}
|