diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index 4afb528e68..576f9fb867 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -49,8 +49,7 @@ class EditController extends Controller /** @var AccountRepositoryInterface The account repository */ private $repository; - /** @var AttachmentHelperInterface Helper for attachments. */ - private $attachments; + private AttachmentHelperInterface $attachments; /** * EditController constructor. @@ -67,7 +66,7 @@ class EditController extends Controller $this->repository = app(AccountRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); - $this->attachments = app(AttachmentHelperInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } diff --git a/app/Http/Controllers/Recurring/CreateController.php b/app/Http/Controllers/Recurring/CreateController.php index f2c45d1ac3..37d7325c40 100644 --- a/app/Http/Controllers/Recurring/CreateController.php +++ b/app/Http/Controllers/Recurring/CreateController.php @@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Recurring; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RecurrenceFormRequest; use FireflyIII\Models\RecurrenceRepetition; @@ -47,6 +48,8 @@ class CreateController extends Controller /** @var RecurringRepositoryInterface Recurring repository */ private $recurring; + private AttachmentHelperInterface $attachments; + /** * CreateController constructor. * @@ -63,8 +66,9 @@ class CreateController extends Controller app('view')->share('title', (string) trans('firefly.recurrences')); app('view')->share('subTitle', (string) trans('firefly.create_new_recurrence')); - $this->recurring = app(RecurringRepositoryInterface::class); - $this->budgets = app(BudgetRepositoryInterface::class); + $this->recurring = app(RecurringRepositoryInterface::class); + $this->budgets = app(BudgetRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } @@ -140,6 +144,21 @@ class CreateController extends Controller $request->session()->flash('success', (string) trans('firefly.stored_new_recurrence', ['title' => $recurrence->title])); app('preferences')->mark(); + + // store attachment(s): + /** @var array $files */ + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + if (null !== $files && !auth()->user()->hasRole('demo')) { + $this->attachments->saveAttachmentsForModel($recurrence, $files); + } + if (null !== $files && auth()->user()->hasRole('demo')) { + session()->flash('info', (string) trans('firefly.no_att_demo_user')); + } + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + $redirect = redirect($this->getPreviousUri('recurring.create.uri')); if (1 === (int) $request->get('create_another')) { // set value so create routine will not overwrite URL: diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php index fad9ef560c..22f5b49226 100644 --- a/app/Http/Controllers/Recurring/EditController.php +++ b/app/Http/Controllers/Recurring/EditController.php @@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Recurring; use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RecurrenceFormRequest; use FireflyIII\Models\Recurrence; @@ -48,7 +49,8 @@ class EditController extends Controller /** @var BudgetRepositoryInterface The budget repository */ private $budgets; /** @var RecurringRepositoryInterface Recurring repository */ - private $recurring; + private $recurring; + private AttachmentHelperInterface $attachments; /** * EditController constructor. @@ -66,9 +68,9 @@ class EditController extends Controller app('view')->share('title', (string) trans('firefly.recurrences')); app('view')->share('subTitle', (string) trans('firefly.recurrences')); - $this->recurring = app(RecurringRepositoryInterface::class); - $this->budgets = app(BudgetRepositoryInterface::class); - + $this->recurring = app(RecurringRepositoryInterface::class); + $this->budgets = app(BudgetRepositoryInterface::class); + $this->attachments = app(AttachmentHelperInterface::class); return $next($request); } ); @@ -159,6 +161,21 @@ class EditController extends Controller $this->recurring->update($recurrence, $data); $request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title])); + + // store new attachment(s): + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + if (null !== $files && !auth()->user()->hasRole('demo')) { + $this->attachments->saveAttachmentsForModel($recurrence, $files); + } + if (null !== $files && auth()->user()->hasRole('demo')) { + session()->flash('info', (string) trans('firefly.no_att_demo_user')); + } + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + + app('preferences')->mark(); $redirect = redirect($this->getPreviousUri('recurrences.edit.uri')); if (1 === (int) $request->get('return_to_edit')) { diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php index bcb6123a43..f7f682fb07 100644 --- a/app/Http/Controllers/Recurring/IndexController.php +++ b/app/Http/Controllers/Recurring/IndexController.php @@ -111,6 +111,8 @@ class IndexController extends Controller $array['first_date'] = new Carbon($array['first_date']); $array['repeat_until'] = null === $array['repeat_until'] ? null : new Carbon($array['repeat_until']); $array['latest_date'] = null === $array['latest_date'] ? null : new Carbon($array['latest_date']); + // lazy but OK + $array['attachments'] = $recurrence->attachments()->count(); // make carbon objects out of occurrences foreach ($array['repetitions'] as $repIndex => $repetition) { diff --git a/app/Models/Account.php b/app/Models/Account.php index bf6e174537..1b92e96505 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -94,12 +94,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property-read int|null $notes_count * @property-read int|null $piggy_banks_count * @property-read int|null $transactions_count - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at - * @property int $account_type_id - * @property bool $encrypted - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta - * @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks */ class Account extends Model { diff --git a/app/Models/Recurrence.php b/app/Models/Recurrence.php index 59444cfaf1..47956a6b8e 100644 --- a/app/Models/Recurrence.php +++ b/app/Models/Recurrence.php @@ -189,6 +189,15 @@ class Recurrence extends Model return $this->belongsTo(TransactionCurrency::class); } + /** + * @codeCoverageIgnore + * @return MorphMany + */ + public function attachments(): MorphMany + { + return $this->morphMany(Attachment::class, 'attachable'); + } + /** * @codeCoverageIgnore * @return BelongsTo diff --git a/resources/views/v1/recurring/create.twig b/resources/views/v1/recurring/create.twig index 9de42801dd..e8f3990e72 100644 --- a/resources/views/v1/recurring/create.twig +++ b/resources/views/v1/recurring/create.twig @@ -4,7 +4,7 @@ {% endblock %} {% block content %} -
+ {# row with recurrence information #}
@@ -51,8 +51,8 @@ {# only correct way to do active checkbox #} {{ ExpandedForm.checkbox('active', 1) }} - {{ ExpandedForm.checkbox('apply_rules',1) }} + {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
diff --git a/resources/views/v1/recurring/edit.twig b/resources/views/v1/recurring/edit.twig index b241cd4efd..244cd3d9bf 100644 --- a/resources/views/v1/recurring/edit.twig +++ b/resources/views/v1/recurring/edit.twig @@ -52,6 +52,7 @@ {# only correct way to do active checkbox #} {{ ExpandedForm.checkbox('active', 1, preFilled.active) }} {{ ExpandedForm.checkbox('apply_rules', 1, preFilled.apply_rules) }} + {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }} diff --git a/resources/views/v1/recurring/index.twig b/resources/views/v1/recurring/index.twig index e7e66f1027..c1b7cdd02e 100644 --- a/resources/views/v1/recurring/index.twig +++ b/resources/views/v1/recurring/index.twig @@ -56,6 +56,9 @@ + {% if rt.attachments > 0 %} + + {% endif %} {% if rt.active == false %}{% endif %} {{ rt.type|_ }}: {{ rt.title }}