Skip to content

Firefly III: a personal finances manager

Take page size into account. [skip ci]

James Coleef48a79d0c94
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index 87be25b6e6..2d644726dc 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -174,7 +174,10 @@ class BillController extends Controller
*/
public function show(BillRepositoryInterface $repository, Bill $bill)
{
- $journals = $repository->getJournals($bill);
+ $page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
+ $pageSize = Preferences::get('transactionPageSize', 50)->data;
+ $journals = $repository->getJournals($bill, $page, $pageSize);
+ $journals->setPath('/bills/show/' . $bill->id);
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill);
$hideBill = true;
$subTitle = e($bill->name);
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index b371d9df23..44bafbd58b 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -13,6 +13,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
+use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Navigation;
@@ -77,7 +78,7 @@ class BillRepository implements BillRepositoryInterface
->get(
[
'bills.*',
- DB::raw('((`bills`.`amount_min` + `bills`.`amount_max`) / 2) as `expectedAmount`'),
+ DB::raw('((`bills`.`amount_min` + `bills`.`amount_max`) / 2) as `expectedAmount`'),
]
)->sortBy('name');
@@ -304,18 +305,24 @@ class BillRepository implements BillRepositoryInterface
*
* @param Bill $bill
*
- * @return Collection
+ * @param int $page
+ * @param int $pageSize
+ *
+ * @return LengthAwarePaginator|Collection
*/
- public function getJournals(Bill $bill): Collection
+ public function getJournals(Bill $bill, int $page, int $pageSize = 50): LengthAwarePaginator
{
- $set = $bill->transactionjournals()
- ->expanded()
- ->orderBy('transaction_journals.date', 'DESC')
- ->orderBy('transaction_journals.order', 'ASC')
- ->orderBy('transaction_journals.id', 'DESC')
- ->get(TransactionJournal::QUERYFIELDS);
-
- return $set;
+ $offset = ($page - 1) * $pageSize;
+ $query = $bill->transactionjournals()
+ ->expanded()
+ ->orderBy('transaction_journals.date', 'DESC')
+ ->orderBy('transaction_journals.order', 'ASC')
+ ->orderBy('transaction_journals.id', 'DESC');
+ $count = $query->count();
+ $set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::QUERYFIELDS);
+ $paginator = new LengthAwarePaginator($set, $count, $pageSize, $page);
+
+ return $paginator;
}
/**
diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.php
index 948e0c67fd..e1667fe83e 100644
--- a/app/Repositories/Bill/BillRepositoryInterface.php
+++ b/app/Repositories/Bill/BillRepositoryInterface.php
@@ -6,6 +6,7 @@ namespace FireflyIII\Repositories\Bill;
use Carbon\Carbon;
use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
+use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
/**
@@ -97,9 +98,12 @@ interface BillRepositoryInterface
/**
* @param Bill $bill
*
- * @return Collection
+ * @param int $page
+ * @param int $pageSize
+ *
+ * @return LengthAwarePaginator
*/
- public function getJournals(Bill $bill): Collection;
+ public function getJournals(Bill $bill, int $page, int $pageSize = 50): LengthAwarePaginator;
/**
* Get all journals that were recorded on this bill between these dates.
diff --git a/resources/views/bills/show.twig b/resources/views/bills/show.twig
index 30ffc95380..254a5efee6 100644
--- a/resources/views/bills/show.twig
+++ b/resources/views/bills/show.twig
@@ -96,7 +96,7 @@
<div class="col-lg-12 col-sm-12 col-md-12">
<div class="box">
<div class="box-header with-border">
- <h3 class="box-title">{{ 'connected_journals' }}</h3>
+ <h3 class="box-title">{{ 'connected_journals'|_ }}</h3>
</div>
<div class="box-body table-responsive no-padding">
{% include 'list/journals' %}