mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Improve recurrences
This commit is contained in:
@@ -31,6 +31,7 @@ use FireflyIII\Models\Recurrence;
|
||||
use FireflyIII\Services\Internal\Support\RecurringTransactionTrait;
|
||||
use FireflyIII\Services\Internal\Support\TransactionTypeTrait;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,9 @@ class RecurrenceFactory
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/** @var MessageBag */
|
||||
private $errors;
|
||||
|
||||
use TransactionTypeTrait, RecurringTransactionTrait;
|
||||
|
||||
/**
|
||||
@@ -52,22 +56,25 @@ class RecurrenceFactory
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
||||
}
|
||||
$this->errors = new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function create(array $data): ?Recurrence
|
||||
public function create(array $data): Recurrence
|
||||
{
|
||||
try {
|
||||
$type = $this->findTransactionType(ucfirst($data['recurrence']['type']));
|
||||
} catch (FireflyException $e) {
|
||||
Log::error(sprintf('Cannot make a recurring transaction of type "%s"', $data['recurrence']['type']));
|
||||
Log::error($e->getMessage());
|
||||
$message = sprintf('Cannot make a recurring transaction of type "%s"', $data['recurrence']['type']);
|
||||
Log::error($message);
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
return null;
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
/** @var Carbon $firstDate */
|
||||
$firstDate = $data['recurrence']['first_date'];
|
||||
@@ -95,9 +102,14 @@ class RecurrenceFactory
|
||||
$this->createTransactions($recurrence, $data['transactions'] ?? []);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (FireflyException $e) {
|
||||
// TODO make sure error props to the user.
|
||||
Log::error($e->getMessage());
|
||||
$recurrence->forceDelete();
|
||||
$message = sprintf('Could not create recurring transaction: %s', $e->getMessage());
|
||||
$this->errors->add('store', $message);
|
||||
throw new FireflyException($message);
|
||||
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
return $recurrence;
|
||||
|
Reference in New Issue
Block a user