Skip to content

Firefly III: a personal finances manager

Take page size into account.

James Cole98c057c516cd
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index 6223216e17..9a09af51a3 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -194,7 +194,9 @@ class BudgetController extends Controller
/** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth());
- $list = $repository->getWithoutBudget($start, $end);
+ $page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
+ $pageSize = Preferences::get('transactionPageSize', 50)->data;
+ $list = $repository->getWithoutBudget($start, $end, $page, $pageSize);
$subTitle = trans(
'firefly.without_budget_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)]
@@ -235,18 +237,21 @@ class BudgetController extends Controller
throw new FireflyException('This budget limit is not part of this budget.');
}
- $journals = $repository->getJournals($budget, $repetition, 50);
+ $pageSize = Preferences::get('transactionPageSize', 50)->data;
+ $journals = $repository->getJournals($budget, $repetition, $pageSize);
if (is_null($repetition->id)) {
$start = $repository->firstActivity($budget);
$end = new Carbon;
$set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();
$subTitle = e($budget->name);
+ $journals->setPath('/budgets/show/' . $budget->id);
} else {
$start = $repetition->startdate;
$end = $repetition->enddate;
$set = new Collection([$repetition]);
$subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]);
+ $journals->setPath('/budgets/show/' . $budget->id . '/' . $repetition->id);
}
$spentArray = $repository->spentPerDay($budget, $start, $end);
@@ -258,7 +263,6 @@ class BudgetController extends Controller
$limits->push($entry);
}
- $journals->setPath('/budgets/show/' . $budget->id);
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));
}
diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php
index fee7ec4421..bb2b0ee851 100644
--- a/app/Repositories/Budget/BudgetRepository.php
+++ b/app/Repositories/Budget/BudgetRepository.php
@@ -60,6 +60,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
{
// delete limits with amount 0:
BudgetLimit::where('amount', 0)->delete();
+
return true;
}
@@ -411,7 +412,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
->where('limit_repetitions.startdate', $start->format('Y-m-d 00:00:00'))
->where('limit_repetitions.enddate', $end->format('Y-m-d 00:00:00'))
->first(['limit_repetitions.*']);
- if(is_null($data)) {
+ if (is_null($data)) {
return new LimitRepetition;
}
@@ -540,20 +541,28 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
/**
* @param Carbon $start
* @param Carbon $end
+ * @param int $page
+ * @param int $pageSize
*
- * @return Collection
+ * @return LengthAwarePaginator
*/
- public function getWithoutBudget(Carbon $start, Carbon $end): Collection
+ public function getWithoutBudget(Carbon $start, Carbon $end, int $page, int $pageSize = 50): LengthAwarePaginator
{
- return $this->user
+ $offset = ($page - 1) * $pageSize;
+ $query = $this->user
->transactionjournals()
->expanded()
->where('transaction_types.type', TransactionType::WITHDRAWAL)
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('budget_transaction_journal.id')
->before($end)
- ->after($start)
- ->get(TransactionJournal::QUERYFIELDS);
+ ->after($start);
+
+ $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/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php
index 4d6e55cd52..b7ea891594 100644
--- a/app/Repositories/Budget/BudgetRepositoryInterface.php
+++ b/app/Repositories/Budget/BudgetRepositoryInterface.php
@@ -204,10 +204,12 @@ interface BudgetRepositoryInterface
/**
* @param Carbon $start
* @param Carbon $end
+ * @param int $page
+ * @param int $pageSize
*
- * @return Collection
+ * @return LengthAwarePaginator
*/
- public function getWithoutBudget(Carbon $start, Carbon $end): Collection;
+ public function getWithoutBudget(Carbon $start, Carbon $end, int $page, int $pageSize = 50): LengthAwarePaginator;
/**
* @param Collection $accounts
diff --git a/resources/views/accounts/show.twig b/resources/views/accounts/show.twig
index afb7876f7d..da328548ea 100644
--- a/resources/views/accounts/show.twig
+++ b/resources/views/accounts/show.twig
@@ -38,7 +38,7 @@
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div>
<div class="box-body table-responsive no-padding">
- {% include 'list/journals.twig' with {sorting:true} %}
+ {% include 'list/journals' with {sorting:true} %}
</div>
</div>
</div>