mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Move collecting journals to the collector.
This commit is contained in:
parent
43afdb021a
commit
8e542531b3
@ -14,7 +14,7 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Generator\Chart\Bill;
|
namespace FireflyIII\Generator\Chart\Bill;
|
||||||
|
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\Transaction;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,13 +61,13 @@ class ChartJsBillChartGenerator implements BillChartGeneratorInterface
|
|||||||
$minAmount = [];
|
$minAmount = [];
|
||||||
$maxAmount = [];
|
$maxAmount = [];
|
||||||
$actualAmount = [];
|
$actualAmount = [];
|
||||||
/** @var TransactionJournal $entry */
|
/** @var Transaction $entry */
|
||||||
foreach ($entries as $entry) {
|
foreach ($entries as $entry) {
|
||||||
$data['labels'][] = $entry->date->formatLocalized($format);
|
$data['labels'][] = $entry->date->formatLocalized($format);
|
||||||
$minAmount[] = round($bill->amount_min, 2);
|
$minAmount[] = round($bill->amount_min, 2);
|
||||||
$maxAmount[] = round($bill->amount_max, 2);
|
$maxAmount[] = round($bill->amount_max, 2);
|
||||||
// journalAmount has been collected in BillRepository::getJournals
|
// journalAmount has been collected in BillRepository::getJournals
|
||||||
$actualAmount[] = round(TransactionJournal::amountPositive($entry), 2);
|
$actualAmount[] = bcmul($entry->transaction_amount, '-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data['datasets'][] = [
|
$data['datasets'][] = [
|
||||||
|
@ -14,10 +14,12 @@ declare(strict_types = 1);
|
|||||||
namespace FireflyIII\Http\Controllers;
|
namespace FireflyIII\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||||
use FireflyIII\Http\Requests\BillFormRequest;
|
use FireflyIII\Http\Requests\BillFormRequest;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Input;
|
use Input;
|
||||||
use Preferences;
|
use Preferences;
|
||||||
use Session;
|
use Session;
|
||||||
@ -200,10 +202,15 @@ class BillController extends Controller
|
|||||||
$year = $date->year;
|
$year = $date->year;
|
||||||
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
$page = intval(Input::get('page')) == 0 ? 1 : intval(Input::get('page'));
|
||||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||||
$journals = $repository->getJournals($bill, $page, $pageSize);
|
|
||||||
$yearAverage = $repository->getYearAverage($bill, $date);
|
$yearAverage = $repository->getYearAverage($bill, $date);
|
||||||
$overallAverage = $repository->getOverallAverage($bill);
|
$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);
|
$journals->setPath('/bills/show/' . $bill->id);
|
||||||
|
|
||||||
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, new Carbon);
|
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, new Carbon);
|
||||||
$hideBill = true;
|
$hideBill = true;
|
||||||
$subTitle = e($bill->name);
|
$subTitle = e($bill->name);
|
||||||
|
@ -15,11 +15,13 @@ namespace FireflyIII\Http\Controllers\Chart;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface;
|
use FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollector;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Response;
|
use Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,12 +66,11 @@ class BillController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Shows the overview for a bill. The min/max amount and matched journals.
|
* 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
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
*/
|
*/
|
||||||
public function single(BillRepositoryInterface $repository, Bill $bill)
|
public function single(Bill $bill)
|
||||||
{
|
{
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty('single');
|
$cache->addProperty('single');
|
||||||
@ -80,12 +81,14 @@ class BillController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get first transaction or today for start:
|
// 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:
|
// resort:
|
||||||
$results = $results->sortBy(
|
$results = $results->sortBy(
|
||||||
function (TransactionJournal $journal) {
|
function (Transaction $transaction) {
|
||||||
return $journal->date->format('U');
|
return $transaction->date->format('U');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -252,30 +252,6 @@ class BillRepository implements BillRepositoryInterface
|
|||||||
return $sum;
|
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
|
* @param Bill $bill
|
||||||
*
|
*
|
||||||
|
@ -91,16 +91,6 @@ interface BillRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getBillsUnpaidInRange(Carbon $start, Carbon $end): string;
|
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
|
* @param Bill $bill
|
||||||
*
|
*
|
||||||
|
@ -105,8 +105,8 @@
|
|||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'connected_journals'|_ }}</h3>
|
<h3 class="box-title">{{ 'connected_journals'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body table-responsive no-padding">
|
||||||
{% include 'list.journals' %}
|
{% include 'list.journals-tasker' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user