Skip to content

Firefly III: a personal finances manager

Get a list of transactions belonging to the recurrence.

James Colee36a9fda1bf6
diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.php
index 69f5847d95..d7f02b5071 100644
--- a/app/Http/Controllers/Recurring/IndexController.php
+++ b/app/Http/Controllers/Recurring/IndexController.php
@@ -179,15 +179,19 @@ class IndexController extends Controller
}
/**
+ * @param Request $request
* @param Recurrence $recurrence
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
- * @throws \FireflyIII\Exceptions\FireflyException
+ * @throws FireflyException
*/
- public function show(Recurrence $recurrence)
+ public function show(Request $request, Recurrence $recurrence)
{
$transformer = new RecurrenceTransformer(new ParameterBag);
$array = $transformer->transform($recurrence);
+ $page = (int)$request->get('page');
+ $pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
+ $transactions = $this->recurring->getTransactions($recurrence, $page, $pageSize);
// transform dates back to Carbon objects:
foreach ($array['recurrence_repetitions'] as $index => $repetition) {
@@ -198,7 +202,7 @@ class IndexController extends Controller
$subTitle = trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]);
- return view('recurring.show', compact('recurrence', 'subTitle', 'array'));
+ return view('recurring.show', compact('recurrence', 'subTitle', 'array','transactions'));
}
/**
diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.php
index 2d4b93e62a..22dfaa10aa 100644
--- a/app/Repositories/Recurring/RecurringRepository.php
+++ b/app/Repositories/Recurring/RecurringRepository.php
@@ -26,6 +26,7 @@ namespace FireflyIII\Repositories\Recurring;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\RecurrenceFactory;
+use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Note;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Recurrence;
@@ -34,9 +35,11 @@ use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Models\TransactionJournal;
+use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Services\Internal\Destroy\RecurrenceDestroyService;
use FireflyIII\Services\Internal\Update\RecurrenceUpdateService;
use FireflyIII\User;
+use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
@@ -328,6 +331,39 @@ class RecurringRepository implements RecurringRepositoryInterface
return $tags;
}
+ /**
+ * @param Recurrence $recurrence
+ *
+ * @param int $page
+ * @param int $pageSize
+ *
+ * @return LengthAwarePaginator
+ */
+ public function getTransactions(Recurrence $recurrence, int $page, int $pageSize): LengthAwarePaginator
+ {
+ $journalMeta = TransactionJournalMeta
+ ::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
+ ->whereNull('transaction_journals.deleted_at')
+ ->where('transaction_journals.user_id', $this->user->id)
+ ->where('name', 'recurrence_id')
+ ->where('data', json_encode((string)$recurrence->id))
+ ->get()->pluck('transaction_journal_id')->toArray();
+ $search = [];
+ foreach ($journalMeta as $journalId) {
+ $search[] = ['id' => (int)$journalId];
+ }
+ /** @var JournalCollectorInterface $collector */
+ $collector = app(JournalCollectorInterface::class);
+ $collector->setUser($recurrence->user);
+ $collector->withOpposingAccount()->setAllAssetAccounts()->
+
+ withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page);
+ // filter on specific journals.
+ $collector->setJournals(new Collection($search));
+
+ return $collector->getPaginatedJournals();
+ }
+
/**
* Calculate the next X iterations starting on the date given in $date.
*
diff --git a/app/Repositories/Recurring/RecurringRepositoryInterface.php b/app/Repositories/Recurring/RecurringRepositoryInterface.php
index 92f824d25a..f760972d01 100644
--- a/app/Repositories/Recurring/RecurringRepositoryInterface.php
+++ b/app/Repositories/Recurring/RecurringRepositoryInterface.php
@@ -29,6 +29,7 @@ use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\User;
+use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@@ -46,6 +47,16 @@ interface RecurringRepositoryInterface
*/
public function destroy(Recurrence $recurrence): void;
+ /**
+ * @param Recurrence $recurrence
+ *
+ * @param int $page
+ * @param int $pageSize
+ *
+ * @return LengthAwarePaginator
+ */
+ public function getTransactions(Recurrence $recurrence, int $page, int $pageSize): LengthAwarePaginator;
+
/**
* Returns all of the user's recurring transactions.
*
diff --git a/app/Transformers/RecurrenceTransformer.php b/app/Transformers/RecurrenceTransformer.php
index f0d83c5a21..f35df38ddd 100644
--- a/app/Transformers/RecurrenceTransformer.php
+++ b/app/Transformers/RecurrenceTransformer.php
@@ -52,7 +52,7 @@ class RecurrenceTransformer extends TransformerAbstract
*
* @var array
*/
- protected $availableIncludes = ['user'];
+ protected $availableIncludes = ['user', 'transactions'];
/**
* List of resources to automatically include
*
diff --git a/resources/views/recurring/show.twig b/resources/views/recurring/show.twig
index 85703b3282..f8d3507f26 100644
--- a/resources/views/recurring/show.twig
+++ b/resources/views/recurring/show.twig
@@ -194,7 +194,7 @@
</h3>
</div>
<div class="box-body">
- List be here.
+ {% include 'list.journals' with {sorting:false, hideBills:true, hideBudgets: true, hideCategories: true, showReconcile: false} %}
</div>
</div>
</div>