Fix attachment overview

This commit is contained in:
James Cole 2023-06-21 06:04:26 +02:00
parent 1278f92355
commit 36021d84cf
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
2 changed files with 23 additions and 3 deletions

View File

@ -26,9 +26,12 @@ namespace FireflyIII\Http\Controllers\Recurring;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Support\Http\Controllers\GetConfigurationData; use FireflyIII\Support\Http\Controllers\GetConfigurationData;
use FireflyIII\Transformers\AttachmentTransformer;
use FireflyIII\Transformers\RecurrenceTransformer; use FireflyIII\Transformers\RecurrenceTransformer;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
use Illuminate\View\View; use Illuminate\View\View;
@ -71,13 +74,14 @@ class ShowController extends Controller
/** /**
* Show a single recurring transaction. * Show a single recurring transaction.
* *
* @param Recurrence $recurrence * @param Recurrence $recurrence
* *
* @return Factory|View * @return Factory|View
* @throws FireflyException * @throws FireflyException
*/ */
public function show(Recurrence $recurrence) public function show(Recurrence $recurrence)
{ {
$repos = app(AttachmentRepositoryInterface::class);
/** @var RecurrenceTransformer $transformer */ /** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class); $transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag()); $transformer->setParameters(new ParameterBag());
@ -93,12 +97,25 @@ class ShowController extends Controller
$date = (new Carbon($occurrence))->startOfDay(); $date = (new Carbon($occurrence))->startOfDay();
$set = [ $set = [
'date' => $date, 'date' => $date,
'fired' => $this->recurring->createdPreviously($recurrence, $date) || $this->recurring->getJournalCount($recurrence, $date) > 0, 'fired' => $this->recurring->createdPreviously($recurrence, $date)
|| $this->recurring->getJournalCount($recurrence, $date) > 0,
]; ];
$array['repetitions'][$index]['occurrences'][$item] = $set; $array['repetitions'][$index]['occurrences'][$item] = $set;
} }
} }
// add attachments to the recurrence object.
$attachments = $recurrence->attachments()->get();
$array['attachments'] = [];
$attachmentTransformer = app(AttachmentTransformer::class);
/** @var Attachment $attachment */
foreach ($attachments as $attachment) {
$item = $attachmentTransformer->transform($attachment);
$item['file_exists'] = $repos->exists($attachment); // TODO this should be part of the transformer
$array['attachments'][] = $item;
}
$subTitle = (string)trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]); $subTitle = (string)trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]);
return view('recurring.show', compact('recurrence', 'subTitle', 'array', 'groups', 'today')); return view('recurring.show', compact('recurrence', 'subTitle', 'array', 'groups', 'today'));

View File

@ -21,7 +21,8 @@
</h3> </h3>
</div> </div>
<div class="box-body"> <div class="box-body">
<p><em>{{ array.description }}</em></p> <h4>{{ 'transaction_journal_meta'|_ }}</h4>
<p>{{ 'description'|_ }}: <em>{{ array.description }}</em></p>
{% if array.active == false %} {% if array.active == false %}
<p> <p>
@ -34,6 +35,8 @@
<li>{{ rep.description }}</li> <li>{{ rep.description }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
<h4>{{ 'attachments'|_ }}</h4>
{% include 'list.attachments' with {attachments: array.attachments} %}
</div> </div>
<div class="box-footer"> <div class="box-footer">
<div class="btn-group"> <div class="btn-group">