mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-30 06:50:49 +00:00 
			
		
		
		
	Add attachment to recurring.
This commit is contained in:
		| @@ -49,8 +49,7 @@ class EditController extends Controller | |||||||
|     /** @var AccountRepositoryInterface The account repository */ |     /** @var AccountRepositoryInterface The account repository */ | ||||||
|     private $repository; |     private $repository; | ||||||
|  |  | ||||||
|     /** @var AttachmentHelperInterface Helper for attachments. */ |     private AttachmentHelperInterface $attachments; | ||||||
|     private $attachments; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * EditController constructor. |      * EditController constructor. | ||||||
| @@ -67,7 +66,7 @@ class EditController extends Controller | |||||||
|  |  | ||||||
|                 $this->repository    = app(AccountRepositoryInterface::class); |                 $this->repository    = app(AccountRepositoryInterface::class); | ||||||
|                 $this->currencyRepos = app(CurrencyRepositoryInterface::class); |                 $this->currencyRepos = app(CurrencyRepositoryInterface::class); | ||||||
|                 $this->attachments = app(AttachmentHelperInterface::class); |                 $this->attachments   = app(AttachmentHelperInterface::class); | ||||||
|  |  | ||||||
|                 return $next($request); |                 return $next($request); | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Recurring; | |||||||
|  |  | ||||||
| use Carbon\Carbon; | use Carbon\Carbon; | ||||||
| use FireflyIII\Exceptions\FireflyException; | use FireflyIII\Exceptions\FireflyException; | ||||||
|  | use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; | ||||||
| use FireflyIII\Http\Controllers\Controller; | use FireflyIII\Http\Controllers\Controller; | ||||||
| use FireflyIII\Http\Requests\RecurrenceFormRequest; | use FireflyIII\Http\Requests\RecurrenceFormRequest; | ||||||
| use FireflyIII\Models\RecurrenceRepetition; | use FireflyIII\Models\RecurrenceRepetition; | ||||||
| @@ -47,6 +48,8 @@ class CreateController extends Controller | |||||||
|     /** @var RecurringRepositoryInterface Recurring repository */ |     /** @var RecurringRepositoryInterface Recurring repository */ | ||||||
|     private $recurring; |     private $recurring; | ||||||
|  |  | ||||||
|  |     private AttachmentHelperInterface $attachments; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * CreateController constructor. |      * CreateController constructor. | ||||||
|      * |      * | ||||||
| @@ -63,8 +66,9 @@ class CreateController extends Controller | |||||||
|                 app('view')->share('title', (string) trans('firefly.recurrences')); |                 app('view')->share('title', (string) trans('firefly.recurrences')); | ||||||
|                 app('view')->share('subTitle', (string) trans('firefly.create_new_recurrence')); |                 app('view')->share('subTitle', (string) trans('firefly.create_new_recurrence')); | ||||||
|  |  | ||||||
|                 $this->recurring = app(RecurringRepositoryInterface::class); |                 $this->recurring   = app(RecurringRepositoryInterface::class); | ||||||
|                 $this->budgets   = app(BudgetRepositoryInterface::class); |                 $this->budgets     = app(BudgetRepositoryInterface::class); | ||||||
|  |                 $this->attachments = app(AttachmentHelperInterface::class); | ||||||
|  |  | ||||||
|                 return $next($request); |                 return $next($request); | ||||||
|             } |             } | ||||||
| @@ -140,6 +144,21 @@ class CreateController extends Controller | |||||||
|  |  | ||||||
|         $request->session()->flash('success', (string) trans('firefly.stored_new_recurrence', ['title' => $recurrence->title])); |         $request->session()->flash('success', (string) trans('firefly.stored_new_recurrence', ['title' => $recurrence->title])); | ||||||
|         app('preferences')->mark(); |         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')); |         $redirect = redirect($this->getPreviousUri('recurring.create.uri')); | ||||||
|         if (1 === (int) $request->get('create_another')) { |         if (1 === (int) $request->get('create_another')) { | ||||||
|             // set value so create routine will not overwrite URL: |             // set value so create routine will not overwrite URL: | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ namespace FireflyIII\Http\Controllers\Recurring; | |||||||
|  |  | ||||||
|  |  | ||||||
| use FireflyIII\Exceptions\FireflyException; | use FireflyIII\Exceptions\FireflyException; | ||||||
|  | use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; | ||||||
| use FireflyIII\Http\Controllers\Controller; | use FireflyIII\Http\Controllers\Controller; | ||||||
| use FireflyIII\Http\Requests\RecurrenceFormRequest; | use FireflyIII\Http\Requests\RecurrenceFormRequest; | ||||||
| use FireflyIII\Models\Recurrence; | use FireflyIII\Models\Recurrence; | ||||||
| @@ -48,7 +49,8 @@ class EditController extends Controller | |||||||
|     /** @var BudgetRepositoryInterface The budget repository */ |     /** @var BudgetRepositoryInterface The budget repository */ | ||||||
|     private $budgets; |     private $budgets; | ||||||
|     /** @var RecurringRepositoryInterface Recurring repository */ |     /** @var RecurringRepositoryInterface Recurring repository */ | ||||||
|     private $recurring; |     private                           $recurring; | ||||||
|  |     private AttachmentHelperInterface $attachments; | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * EditController constructor. |      * EditController constructor. | ||||||
| @@ -66,9 +68,9 @@ class EditController extends Controller | |||||||
|                 app('view')->share('title', (string) trans('firefly.recurrences')); |                 app('view')->share('title', (string) trans('firefly.recurrences')); | ||||||
|                 app('view')->share('subTitle', (string) trans('firefly.recurrences')); |                 app('view')->share('subTitle', (string) trans('firefly.recurrences')); | ||||||
|  |  | ||||||
|                 $this->recurring = app(RecurringRepositoryInterface::class); |                 $this->recurring   = app(RecurringRepositoryInterface::class); | ||||||
|                 $this->budgets   = app(BudgetRepositoryInterface::class); |                 $this->budgets     = app(BudgetRepositoryInterface::class); | ||||||
|  |                 $this->attachments = app(AttachmentHelperInterface::class); | ||||||
|                 return $next($request); |                 return $next($request); | ||||||
|             } |             } | ||||||
|         ); |         ); | ||||||
| @@ -159,6 +161,21 @@ class EditController extends Controller | |||||||
|         $this->recurring->update($recurrence, $data); |         $this->recurring->update($recurrence, $data); | ||||||
|  |  | ||||||
|         $request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title])); |         $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(); |         app('preferences')->mark(); | ||||||
|         $redirect = redirect($this->getPreviousUri('recurrences.edit.uri')); |         $redirect = redirect($this->getPreviousUri('recurrences.edit.uri')); | ||||||
|         if (1 === (int) $request->get('return_to_edit')) { |         if (1 === (int) $request->get('return_to_edit')) { | ||||||
|   | |||||||
| @@ -111,6 +111,8 @@ class IndexController extends Controller | |||||||
|             $array['first_date']   = new Carbon($array['first_date']); |             $array['first_date']   = new Carbon($array['first_date']); | ||||||
|             $array['repeat_until'] = null === $array['repeat_until'] ? null : new Carbon($array['repeat_until']); |             $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']); |             $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 |             // make carbon objects out of occurrences | ||||||
|             foreach ($array['repetitions'] as $repIndex => $repetition) { |             foreach ($array['repetitions'] as $repIndex => $repetition) { | ||||||
|   | |||||||
| @@ -94,12 +94,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | |||||||
|  * @property-read int|null                                              $notes_count |  * @property-read int|null                                              $notes_count | ||||||
|  * @property-read int|null                                              $piggy_banks_count |  * @property-read int|null                                              $piggy_banks_count | ||||||
|  * @property-read int|null                                              $transactions_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 | class Account extends Model | ||||||
| { | { | ||||||
|   | |||||||
| @@ -189,6 +189,15 @@ class Recurrence extends Model | |||||||
|         return $this->belongsTo(TransactionCurrency::class); |         return $this->belongsTo(TransactionCurrency::class); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * @codeCoverageIgnore | ||||||
|  |      * @return MorphMany | ||||||
|  |      */ | ||||||
|  |     public function attachments(): MorphMany | ||||||
|  |     { | ||||||
|  |         return $this->morphMany(Attachment::class, 'attachable'); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * @codeCoverageIgnore |      * @codeCoverageIgnore | ||||||
|      * @return BelongsTo |      * @return BelongsTo | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| {% endblock %} | {% endblock %} | ||||||
| {% block content %} | {% 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() }}"/> |         <input type="hidden" name="_token" value="{{ csrf_token() }}"/> | ||||||
|         {# row with recurrence information #} |         {# row with recurrence information #} | ||||||
|         <div class="row"> |         <div class="row"> | ||||||
| @@ -51,8 +51,8 @@ | |||||||
|  |  | ||||||
|                         {# only correct way to do active checkbox #} |                         {# only correct way to do active checkbox #} | ||||||
|                         {{ ExpandedForm.checkbox('active', 1) }} |                         {{ ExpandedForm.checkbox('active', 1) }} | ||||||
|  |  | ||||||
|                         {{ ExpandedForm.checkbox('apply_rules',1) }} |                         {{ ExpandedForm.checkbox('apply_rules',1) }} | ||||||
|  |                         {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }} | ||||||
|                     </div> |                     </div> | ||||||
|                 </div> |                 </div> | ||||||
|             </div> |             </div> | ||||||
|   | |||||||
| @@ -52,6 +52,7 @@ | |||||||
|                         {# only correct way to do active checkbox #} |                         {# only correct way to do active checkbox #} | ||||||
|                         {{ ExpandedForm.checkbox('active', 1, preFilled.active) }} |                         {{ ExpandedForm.checkbox('active', 1, preFilled.active) }} | ||||||
|                         {{ ExpandedForm.checkbox('apply_rules', 1, preFilled.apply_rules) }} |                         {{ 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> |                 </div> | ||||||
|             </div> |             </div> | ||||||
|   | |||||||
| @@ -56,6 +56,9 @@ | |||||||
|                                         </div> |                                         </div> | ||||||
|                                     </td> |                                     </td> | ||||||
|                                     <td data-value="{{ rt.title }}"> |                                     <td data-value="{{ rt.title }}"> | ||||||
|  |                                         {% if rt.attachments > 0 %} | ||||||
|  |                                             <i class="fa fa-fw fa-paperclip"></i> | ||||||
|  |                                         {% endif %} | ||||||
|                                         {% if rt.active == false %}<s>{% endif %} |                                         {% if rt.active == false %}<s>{% endif %} | ||||||
|                                             {{ rt.type|_ }}: |                                             {{ rt.type|_ }}: | ||||||
|                                             <a href="{{ route('recurring.show',rt.id) }}">{{ rt.title }}</a> |                                             <a href="{{ route('recurring.show',rt.id) }}">{{ rt.title }}</a> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user