Files
firefly-iii/app/Console/Commands/Correction/TriggerCreditCalculation.php

56 lines
1.4 KiB
PHP
Raw Normal View History

2023-01-08 07:43:16 +01:00
<?php
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;
use Illuminate\Support\Facades\Log;
/**
* Class CorrectionSkeleton
* TODO DONT FORGET TO ADD THIS TO THE DOCKER BUILD
*/
class TriggerCreditCalculation extends Command
{
protected $description = 'Triggers the credit recalculation service for liabilities.';
protected $signature = 'firefly-iii:trigger-credit-recalculation';
2023-01-08 07:43:16 +01:00
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->processAccounts();
2023-05-29 13:56:55 +02:00
2023-01-08 07:43:16 +01:00
return 0;
}
/**
* @param Account $account
2023-05-29 13:56:55 +02:00
*
2023-01-08 07:43:16 +01:00
* @return void
*/
private function processAccount(Account $account): void
{
/** @var CreditRecalculateService $object */
$object = app(CreditRecalculateService::class);
$object->setAccount($account);
$object->recalculate();
}
2023-05-07 20:17:29 +02:00
private function processAccounts(): void
{
$accounts = Account::leftJoin('account_types', 'accounts.account_type_id', 'account_types.id')
->whereIn('account_types.type', config('firefly.valid_liabilities'))
->get(['accounts.*']);
foreach ($accounts as $account) {
$this->processAccount($account);
}
}
2023-01-08 07:43:16 +01:00
}