Move collecting journals to the collector.

This commit is contained in:
James Cole 2016-11-05 11:44:41 +01:00
parent 43afdb021a
commit 8e542531b3
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 23 additions and 47 deletions

View File

@ -14,7 +14,7 @@ declare(strict_types = 1);
namespace FireflyIII\Generator\Chart\Bill;
use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\Transaction;
use Illuminate\Support\Collection;
/**
@ -61,13 +61,13 @@ class ChartJsBillChartGenerator implements BillChartGeneratorInterface
$minAmount = [];
$maxAmount = [];
$actualAmount = [];
/** @var TransactionJournal $entry */
/** @var Transaction $entry */
foreach ($entries as $entry) {
$data['labels'][] = $entry->date->formatLocalized($format);
$minAmount[] = round($bill->amount_min, 2);
$maxAmount[] = round($bill->amount_max, 2);
// journalAmount has been collected in BillRepository::getJournals
$actualAmount[] = round(TransactionJournal::amountPositive($entry), 2);
$actualAmount[] = bcmul($entry->transaction_amount, '-1');
}
$data['datasets'][] = [

View File

@ -14,10 +14,12 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollector;
use FireflyIII\Http\Requests\BillFormRequest;
use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Support\Collection;
use Input;
use Preferences;
use Session;
@ -200,10 +202,15 @@ class BillController extends Controller
$year = $date->year;
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$journals = $repository->getJournals($bill, $page, $pageSize);
$yearAverage = $repository->getYearAverage($bill, $date);
$overallAverage = $repository->getOverallAverage($bill);
// use collector:
$collector = new JournalCollector(auth()->user());
$collector->setAllAssetAccounts()->setBills(new Collection([$bill]))->setPage($page)->setLimit($pageSize);
$journals = $collector->getPaginatedJournals();
$journals->setPath('/bills/show/' . $bill->id);
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, new Carbon);
$hideBill = true;
$subTitle = e($bill->name);

View File

@ -15,11 +15,13 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollector;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Response;
/**
@ -64,12 +66,11 @@ class BillController extends Controller
/**
* Shows the overview for a bill. The min/max amount and matched journals.
*
* @param BillRepositoryInterface $repository
* @param Bill $bill
* @param Bill $bill
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function single(BillRepositoryInterface $repository, Bill $bill)
public function single(Bill $bill)
{
$cache = new CacheProperties;
$cache->addProperty('single');
@ -80,12 +81,14 @@ class BillController extends Controller
}
// get first transaction or today for start:
$results = $repository->getJournals($bill, 1, 200);
$collector = new JournalCollector(auth()->user());
$collector->setAllAssetAccounts()->setBills(new Collection([$bill]));
$results = $collector->getJournals();
// resort:
$results = $results->sortBy(
function (TransactionJournal $journal) {
return $journal->date->format('U');
function (Transaction $transaction) {
return $transaction->date->format('U');
}
);

View File

@ -252,30 +252,6 @@ class BillRepository implements BillRepositoryInterface
return $sum;
}
/**
* This method also returns the amount of the journal in "journalAmount"
* for easy access.
*
* @param Bill $bill
*
* @param int $page
* @param int $pageSize
*
* @return LengthAwarePaginator|Collection
*/
public function getJournals(Bill $bill, int $page, int $pageSize = 50): LengthAwarePaginator
{
$offset = ($page - 1) * $pageSize;
$query = $bill->transactionJournals()
->expanded()
->sortCorrectly();
$count = $query->count();
$set = $query->take($pageSize)->offset($offset)->get(TransactionJournal::queryFields());
$paginator = new LengthAwarePaginator($set, $count, $pageSize, $page);
return $paginator;
}
/**
* @param Bill $bill
*

View File

@ -91,16 +91,6 @@ interface BillRepositoryInterface
*/
public function getBillsUnpaidInRange(Carbon $start, Carbon $end): string;
/**
* @param Bill $bill
*
* @param int $page
* @param int $pageSize
*
* @return LengthAwarePaginator
*/
public function getJournals(Bill $bill, int $page, int $pageSize = 50): LengthAwarePaginator;
/**
* @param Bill $bill
*

View File

@ -105,8 +105,8 @@
<div class="box-header with-border">
<h3 class="box-title">{{ 'connected_journals'|_ }}</h3>
</div>
<div class="box-body">
{% include 'list.journals' %}
<div class="box-body table-responsive no-padding">
{% include 'list.journals-tasker' %}
</div>
</div>
</div>