mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 11:48:05 +00:00
Fix tests for transaction storage.
This commit is contained in:
@@ -41,8 +41,9 @@ class RecurrenceFactory
|
||||
{
|
||||
|
||||
use TransactionTypeTrait, RecurringTransactionTrait;
|
||||
|
||||
private MessageBag $errors;
|
||||
private User $user;
|
||||
private User $user;
|
||||
|
||||
|
||||
/**
|
||||
@@ -58,8 +59,8 @@ class RecurrenceFactory
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function create(array $data): Recurrence
|
||||
{
|
||||
@@ -72,26 +73,60 @@ class RecurrenceFactory
|
||||
|
||||
throw new FireflyException($message);
|
||||
}
|
||||
/** @var Carbon $firstDate */
|
||||
$firstDate = $data['recurrence']['first_date'];
|
||||
$firstDate = null;
|
||||
$repeatUntil = null;
|
||||
$repetitions = 0;
|
||||
$title = null;
|
||||
$description = '';
|
||||
$applyRules = true;
|
||||
$active = true;
|
||||
if (array_key_exists('first_date', $data['recurrence'])) {
|
||||
/** @var Carbon $firstDate */
|
||||
$firstDate = $data['recurrence']['first_date'];
|
||||
}
|
||||
if (array_key_exists('nr_of_repetitions', $data['recurrence'])) {
|
||||
$repetitions = (int)$data['recurrence']['nr_of_repetitions'];
|
||||
}
|
||||
if (array_key_exists('repeat_until', $data['recurrence'])) {
|
||||
$repeatUntil = $data['recurrence']['repeat_until'];
|
||||
}
|
||||
if (array_key_exists('title', $data['recurrence'])) {
|
||||
$title = $data['recurrence']['title'];
|
||||
}
|
||||
if (array_key_exists('description', $data['recurrence'])) {
|
||||
$description = $data['recurrence']['description'];
|
||||
}
|
||||
if (array_key_exists('apply_rules', $data['recurrence'])) {
|
||||
$applyRules = $data['recurrence']['apply_rules'];
|
||||
}
|
||||
if (array_key_exists('active', $data['recurrence'])) {
|
||||
$active = $data['recurrence']['active'];
|
||||
}
|
||||
if ($repetitions > 0 && null === $repeatUntil) {
|
||||
$repeatUntil = Carbon::create()->addyear();
|
||||
}
|
||||
|
||||
$repetitions = (int) $data['recurrence']['repetitions'];
|
||||
$recurrence = new Recurrence(
|
||||
$recurrence = new Recurrence(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'transaction_type_id' => $type->id,
|
||||
'title' => $data['recurrence']['title'],
|
||||
'description' => $data['recurrence']['description'],
|
||||
'first_date' => $firstDate->format('Y-m-d'),
|
||||
'repeat_until' => $repetitions > 0 ? null : $data['recurrence']['repeat_until'],
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'first_date' => $firstDate ? $firstDate->format('Y-m-d') : null,
|
||||
'repeat_until' => $repetitions > 0 ? null : $repeatUntil->format('Y-m-d'),
|
||||
'latest_date' => null,
|
||||
'repetitions' => $data['recurrence']['repetitions'],
|
||||
'apply_rules' => $data['recurrence']['apply_rules'],
|
||||
'active' => $data['recurrence']['active'],
|
||||
'repetitions' => $repetitions,
|
||||
'apply_rules' => $applyRules,
|
||||
'active' => $active,
|
||||
]
|
||||
);
|
||||
$recurrence->save();
|
||||
|
||||
if (array_key_exists('notes', $data['recurrence'])) {
|
||||
$this->updateNote($recurrence, (string)$data['recurrence']['notes']);
|
||||
|
||||
}
|
||||
|
||||
$this->createRepetitions($recurrence, $data['repetitions'] ?? []);
|
||||
try {
|
||||
$this->createTransactions($recurrence, $data['transactions'] ?? []);
|
||||
|
Reference in New Issue
Block a user