Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Add attachment to recurring.
James Cole54d5778bf335
diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.phpindex 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.phpindex 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 Controllerapp('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.phpindex 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 Controllerapp('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.phpindex 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 occurrencesforeach ($array['repetitions'] as $repIndex => $repetition) {diff --git a/app/Models/Account.php b/app/Models/Account.phpindex 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.phpindex 59444cfaf1..47956a6b8e 100644--- a/app/Models/Recurrence.php+++ b/app/Models/Recurrence.php@@ -189,6 +189,15 @@ class Recurrence extends Modelreturn $this->belongsTo(TransactionCurrency::class);}+ /**+ * @codeCoverageIgnore+ * @return MorphMany+ */+ public function attachments(): MorphMany+ {+ return $this->morphMany(Attachment::class, 'attachable');+ }+/*** @codeCoverageIgnore* @return BelongsTodiff --git a/resources/views/v1/recurring/create.twig b/resources/views/v1/recurring/create.twigindex 9de42801dd..e8f3990e72 100644--- a/resources/views/v1/recurring/create.twig+++ b/resources/views/v1/recurring/create.twig@@ -4,7 +4,7 @@{% endblock %}{% block content %}- <form action="{{ route('recurring.store') }}" method="post" id="store" class="form-horizontal">+ <form action="{{ route('recurring.store') }}" method="post" id="store" class="form-horizontal" enctype="multipart/form-data"><input type="hidden" name="_token" value="{{ csrf_token() }}"/>{# row with recurrence information #}<div class="row">@@ -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}) }) }}</div></div></div>diff --git a/resources/views/v1/recurring/edit.twig b/resources/views/v1/recurring/edit.twigindex 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}) }) }}</div></div></div>diff --git a/resources/views/v1/recurring/index.twig b/resources/views/v1/recurring/index.twigindex e7e66f1027..c1b7cdd02e 100644--- a/resources/views/v1/recurring/index.twig+++ b/resources/views/v1/recurring/index.twig@@ -56,6 +56,9 @@</div></td><td data-value="{{ rt.title }}">+ {% if rt.attachments > 0 %}+ <i class="fa fa-fw fa-paperclip"></i>+ {% endif %}{% if rt.active == false %}<s>{% endif %}{{ rt.type|_ }}:<a href="{{ route('recurring.show',rt.id) }}">{{ rt.title }}</a>