mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-09 11:18:10 +00:00
Restore cron options.
This commit is contained in:
@@ -77,7 +77,7 @@ class Cron extends Command
|
|||||||
*/
|
*/
|
||||||
if (true === config('cer.enabled')) {
|
if (true === config('cer.enabled')) {
|
||||||
try {
|
try {
|
||||||
//$this->exchangeRatesCronJob($force, $date);
|
$this->exchangeRatesCronJob($force, $date);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
@@ -89,7 +89,7 @@ class Cron extends Command
|
|||||||
* Fire recurring transaction cron job.
|
* Fire recurring transaction cron job.
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
//$this->recurringCronJob($force, $date);
|
$this->recurringCronJob($force, $date);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
@@ -111,7 +111,7 @@ class Cron extends Command
|
|||||||
* Fire bill warning cron job
|
* Fire bill warning cron job
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
//$this->billWarningCronJob($force, $date);
|
$this->billWarningCronJob($force, $date);
|
||||||
} catch (FireflyException $e) {
|
} catch (FireflyException $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
Log::error($e->getTraceAsString());
|
Log::error($e->getTraceAsString());
|
||||||
|
|||||||
@@ -128,20 +128,25 @@ class CreateAutoBudgetLimits implements ShouldQueue
|
|||||||
// what you spent in previous period PLUS the amount for the current period,
|
// what you spent in previous period PLUS the amount for the current period,
|
||||||
// if that is more than zero, that's the amount that will be set.
|
// if that is more than zero, that's the amount that will be set.
|
||||||
|
|
||||||
$budgetAvailable = bcadd(bcadd($budgetLimit->amount, $autoBudget->amount), $spentAmount);
|
$budgetAvailable = bcadd(bcadd($budgetLimit->amount, $autoBudget->amount), $spentAmount);
|
||||||
$totalAmount = $autoBudget->amount;
|
$totalAmount = $autoBudget->amount;
|
||||||
Log::debug(sprintf('Total amount available for current budget period is %s', $budgetAvailable));
|
Log::debug(sprintf('Total amount available for current budget period is %s', $budgetAvailable));
|
||||||
|
|
||||||
if (-1 !== bccomp( $budgetAvailable, $totalAmount)) {
|
if (-1 !== bccomp($budgetAvailable, $totalAmount)) {
|
||||||
Log::info(sprintf('There is no overspending, no need to adjust. Budget limit amount will be %s.', $totalAmount));
|
Log::info(sprintf('There is no overspending, no need to adjust. Budget limit amount will be %s.', $totalAmount));
|
||||||
// create budget limit:
|
// create budget limit:
|
||||||
$this->createBudgetLimit($autoBudget, $start, $end, $totalAmount);
|
$this->createBudgetLimit($autoBudget, $start, $end, $totalAmount);
|
||||||
}
|
}
|
||||||
if (1 !== bccomp($budgetAvailable, $totalAmount)) {
|
if (1 !== bccomp($budgetAvailable, $totalAmount) && 1 === bccomp($budgetAvailable, '0')) {
|
||||||
Log::info(sprintf('There was overspending, so the new amount will be %s.', $budgetAvailable));
|
Log::info(sprintf('There was overspending, so the new amount will be %s.', $budgetAvailable));
|
||||||
// create budget limit:
|
// create budget limit:
|
||||||
$this->createBudgetLimit($autoBudget, $start, $end, $budgetAvailable);
|
$this->createBudgetLimit($autoBudget, $start, $end, $budgetAvailable);
|
||||||
}
|
}
|
||||||
|
if (1 !== bccomp($budgetAvailable, $totalAmount) && -1 === bccomp($budgetAvailable, '0')) {
|
||||||
|
Log::info('There was overspending, but so much even this period cant fix that. Reset it to 1.');
|
||||||
|
// create budget limit:
|
||||||
|
$this->createBudgetLimit($autoBudget, $start, $end, '1');
|
||||||
|
}
|
||||||
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
|
Log::debug(sprintf('Done with auto budget #%d', $autoBudget->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ namespace FireflyIII\Support\Http\Controllers;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Support\Cronjobs\AutoBudgetCronjob;
|
use FireflyIII\Support\Cronjobs\AutoBudgetCronjob;
|
||||||
|
use FireflyIII\Support\Cronjobs\BillWarningCronjob;
|
||||||
|
use FireflyIII\Support\Cronjobs\ExchangeRatesCronjob;
|
||||||
use FireflyIII\Support\Cronjobs\RecurringCronjob;
|
use FireflyIII\Support\Cronjobs\RecurringCronjob;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
@@ -98,4 +100,70 @@ trait CronRunner
|
|||||||
'message' => $recurring->message,
|
'message' => $recurring->message,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $force
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function exchangeRatesCronJob(bool $force, Carbon $date): array
|
||||||
|
{
|
||||||
|
/** @var ExchangeRatesCronjob $exchangeRates */
|
||||||
|
$exchangeRates = app(ExchangeRatesCronjob::class);
|
||||||
|
$exchangeRates->setForce($force);
|
||||||
|
$exchangeRates->setDate($date);
|
||||||
|
try {
|
||||||
|
$exchangeRates->fire();
|
||||||
|
} catch (FireflyException $e) {
|
||||||
|
return [
|
||||||
|
'job_fired' => false,
|
||||||
|
'job_succeeded' => false,
|
||||||
|
'job_errored' => true,
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'job_fired' => $exchangeRates->jobFired,
|
||||||
|
'job_succeeded' => $exchangeRates->jobSucceeded,
|
||||||
|
'job_errored' => $exchangeRates->jobErrored,
|
||||||
|
'message' => $exchangeRates->message,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $force
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
protected function billWarningCronJob(bool $force, Carbon $date): array
|
||||||
|
{
|
||||||
|
/** @var BillWarningCronjob $billWarning */
|
||||||
|
$billWarning = app(BillWarningCronjob::class);
|
||||||
|
$billWarning->setForce($force);
|
||||||
|
$billWarning->setDate($date);
|
||||||
|
try {
|
||||||
|
$billWarning->fire();
|
||||||
|
} catch (FireflyException $e) {
|
||||||
|
return [
|
||||||
|
'job_fired' => false,
|
||||||
|
'job_succeeded' => false,
|
||||||
|
'job_errored' => true,
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'job_fired' => $billWarning->jobFired,
|
||||||
|
'job_succeeded' => $billWarning->jobSucceeded,
|
||||||
|
'job_errored' => $billWarning->jobErrored,
|
||||||
|
'message' => $billWarning->message,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user