Skip to content

Firefly III: a personal finances manager

Move collecting journals to the collector.

James Cole8e542531b354
diff --git a/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php b/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
index e59b49f136..07f29dd58b 100644
--- a/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
+++ b/app/Generator/Chart/Bill/ChartJsBillChartGenerator.php
@@ -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'][] = [
diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php
index 31de91d724..e0efc0f812 100644
--- a/app/Http/Controllers/BillController.php
+++ b/app/Http/Controllers/BillController.php
@@ -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);
diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php
index 78385b915b..51ca561e75 100644
--- a/app/Http/Controllers/Chart/BillController.php
+++ b/app/Http/Controllers/Chart/BillController.php
@@ -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');
}
);
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index 2a34567986..4a35819c56 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -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
*
diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.php
index 8e7024240e..16368e53d1 100644
--- a/app/Repositories/Bill/BillRepositoryInterface.php
+++ b/app/Repositories/Bill/BillRepositoryInterface.php
@@ -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
*
diff --git a/resources/views/bills/show.twig b/resources/views/bills/show.twig
index 85dd232568..7622ee694d 100644
--- a/resources/views/bills/show.twig
+++ b/resources/views/bills/show.twig
@@ -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>