New cron job for bills.

This commit is contained in:
James Cole
2022-03-28 12:23:46 +02:00
parent e5a08d2cf1
commit f2849c8058
29 changed files with 714 additions and 142 deletions

View File

@@ -28,6 +28,7 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Cronjobs\AutoBudgetCronjob;
use FireflyIII\Support\Cronjobs\RecurringCronjob;
use FireflyIII\Support\Cronjobs\BillWarningCronjob;
use Illuminate\Console\Command;
use InvalidArgumentException;
use Log;
@@ -66,7 +67,7 @@ class Cron extends Command
} catch (InvalidArgumentException $e) {
$this->error(sprintf('"%s" is not a valid date', $this->option('date')));
}
$force = (bool)$this->option('force');
$force = (bool) $this->option('force');
/*
* Fire recurring transaction cron job.
@@ -90,6 +91,17 @@ class Cron extends Command
$this->error($e->getMessage());
}
/*
* Fire bill warning cron job
*/
try {
$this->billWarningCronJob($force, $date);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->error($e->getMessage());
}
$this->info('More feedback on the cron jobs can be found in the log files.');
return 0;
@@ -150,4 +162,32 @@ class Cron extends Command
}
}
/**
* @param bool $force
* @param Carbon|null $date
*
*/
private function billWarningCronJob(bool $force, ?Carbon $date): void
{
$autoBudget = new BillWarningCronjob;
$autoBudget->setForce($force);
// set date in cron job:
if (null !== $date) {
$autoBudget->setDate($date);
}
$autoBudget->fire();
if ($autoBudget->jobErrored) {
$this->error(sprintf('Error in "bill warnings" cron: %s', $autoBudget->message));
}
if ($autoBudget->jobFired) {
$this->error(sprintf('"Send bill warnings" cron fired: %s', $autoBudget->message));
}
if ($autoBudget->jobSucceeded) {
$this->error(sprintf('"Send bill warnings" cron ran with success: %s', $autoBudget->message));
}
}
}