Get a list of transactions belonging to the recurrence.

This commit is contained in:
James Cole 2018-07-02 20:39:45 +02:00
parent 10f195d334
commit e36a9fda1b
5 changed files with 56 additions and 5 deletions

View File

@ -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'));
}
/**

View File

@ -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.
*

View File

@ -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.
*

View File

@ -52,7 +52,7 @@ class RecurrenceTransformer extends TransformerAbstract
*
* @var array
*/
protected $availableIncludes = ['user'];
protected $availableIncludes = ['user', 'transactions'];
/**
* List of resources to automatically include
*

View File

@ -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>