Take page size into account.

This commit is contained in:
James Cole 2016-04-21 09:00:32 +02:00
parent e293d69798
commit 98c057c516
4 changed files with 27 additions and 12 deletions

View File

@ -194,7 +194,9 @@ class BudgetController extends Controller
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth()); $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( $subTitle = trans(
'firefly.without_budget_between', 'firefly.without_budget_between',
['start' => $start->formatLocalized($this->monthAndDayFormat), 'end' => $end->formatLocalized($this->monthAndDayFormat)] ['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.'); 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)) { if (is_null($repetition->id)) {
$start = $repository->firstActivity($budget); $start = $repository->firstActivity($budget);
$end = new Carbon; $end = new Carbon;
$set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get(); $set = $budget->limitrepetitions()->orderBy('startdate', 'DESC')->get();
$subTitle = e($budget->name); $subTitle = e($budget->name);
$journals->setPath('/budgets/show/' . $budget->id);
} else { } else {
$start = $repetition->startdate; $start = $repetition->startdate;
$end = $repetition->enddate; $end = $repetition->enddate;
$set = new Collection([$repetition]); $set = new Collection([$repetition]);
$subTitle = trans('firefly.budget_in_month', ['name' => $budget->name, 'month' => $repetition->startdate->formatLocalized($this->monthFormat)]); $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); $spentArray = $repository->spentPerDay($budget, $start, $end);
@ -258,7 +263,6 @@ class BudgetController extends Controller
$limits->push($entry); $limits->push($entry);
} }
$journals->setPath('/budgets/show/' . $budget->id);
return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle')); return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle'));
} }

View File

@ -60,6 +60,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
{ {
// delete limits with amount 0: // delete limits with amount 0:
BudgetLimit::where('amount', 0)->delete(); BudgetLimit::where('amount', 0)->delete();
return true; 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.startdate', $start->format('Y-m-d 00:00:00'))
->where('limit_repetitions.enddate', $end->format('Y-m-d 00:00:00')) ->where('limit_repetitions.enddate', $end->format('Y-m-d 00:00:00'))
->first(['limit_repetitions.*']); ->first(['limit_repetitions.*']);
if(is_null($data)) { if (is_null($data)) {
return new LimitRepetition; return new LimitRepetition;
} }
@ -540,20 +541,28 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
/** /**
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @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() ->transactionjournals()
->expanded() ->expanded()
->where('transaction_types.type', TransactionType::WITHDRAWAL) ->where('transaction_types.type', TransactionType::WITHDRAWAL)
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('budget_transaction_journal.id') ->whereNull('budget_transaction_journal.id')
->before($end) ->before($end)
->after($start) ->after($start);
->get(TransactionJournal::QUERYFIELDS);
$count = $query->count();
$set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::QUERYFIELDS);
$paginator = new LengthAwarePaginator($set, $count, $pageSize, $page);
return $paginator;
} }
/** /**

View File

@ -204,10 +204,12 @@ interface BudgetRepositoryInterface
/** /**
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @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 * @param Collection $accounts

View File

@ -38,7 +38,7 @@
<h3 class="box-title">{{ 'transactions'|_ }}</h3> <h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div> </div>
<div class="box-body table-responsive no-padding"> <div class="box-body table-responsive no-padding">
{% include 'list/journals.twig' with {sorting:true} %} {% include 'list/journals' with {sorting:true} %}
</div> </div>
</div> </div>
</div> </div>