Make sure the "classic" page uses the transformer as well.

This commit is contained in:
James Cole
2018-02-06 18:11:33 +01:00
parent 9a0672e359
commit c4507a7f75
5 changed files with 78 additions and 43 deletions

View File

@@ -30,8 +30,8 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Transformers\Bill\BillTransformer;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Preferences;
use URL;
@@ -167,36 +167,23 @@ class BillController extends Controller
*
* @return View
*/
public function index(Request $request, BillRepositoryInterface $repository)
public function index(BillRepositoryInterface $repository)
{
/** @var Carbon $start */
$start = session('start');
/** @var Carbon $end */
$end = session('end');
$page = 0 === intval($request->get('page')) ? 1 : intval($request->get('page'));
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
$collection = $repository->getBills();
$total = $collection->count();
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
$collection->each(
function (Bill $bill) use ($repository, $start, $end) {
// paid in this period?
$bill->paidDates = $repository->getPaidDatesInRange($bill, $start, $end);
$bill->payDates = $repository->getPayDatesInRange($bill, $start, $end);
$lastPaidDate = $this->lastPaidDate($repository->getPaidDatesInRange($bill, $start, $end), $start);
if ($bill->paidDates->count() >= $bill->payDates->count()) {
// if all bills have been been paid, jump to next period.
$lastPaidDate = $end;
}
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastPaidDate);
$start = session('start');
$end = session('end');
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
$paginator = $repository->getPaginator($pageSize);
$transformer = new BillTransformer($start, $end);
/** @var Collection $bills */
$bills = $paginator->getCollection()->map(
function (Bill $bill) use ($transformer) {
return $transformer->transform($bill);
}
);
// paginate bills
$bills = new LengthAwarePaginator($collection, $total, $pageSize, $page);
$bills->setPath(route('bills.index'));
return view('bills.index', compact('bills'));
$paginator->setPath(route('bills.index'));
return view('bills.index', compact('bills', 'paginator'));
}
/**
@@ -235,15 +222,16 @@ class BillController extends Controller
*/
public function show(Request $request, BillRepositoryInterface $repository, Bill $bill)
{
/** @var Carbon $date */
$date = session('start');
/** @var Carbon $end */
$subTitle = $bill->name;
$start = session('start');
$end = session('end');
$year = $date->year;
$year = $start->year;
$page = intval($request->get('page'));
$pageSize = intval(Preferences::get('listPageSize', 50)->data);
$yearAverage = $repository->getYearAverage($bill, $date);
$yearAverage = $repository->getYearAverage($bill, $start);
$overallAverage = $repository->getOverallAverage($bill);
$transformer = new BillTransformer($start, $end);
$object = $transformer->transform($bill);
// use collector:
/** @var JournalCollectorInterface $collector */
@@ -253,18 +241,8 @@ class BillController extends Controller
$transactions = $collector->getPaginatedJournals();
$transactions->setPath(route('bills.show', [$bill->id]));
$bill->paidDates = $repository->getPaidDatesInRange($bill, $date, $end);
$bill->payDates = $repository->getPayDatesInRange($bill, $date, $end);
$lastPaidDate = $this->lastPaidDate($repository->getPaidDatesInRange($bill, $date, $end), $date);
if ($bill->paidDates->count() >= $bill->payDates->count()) {
// if all bills have been been paid, jump to next period.
$lastPaidDate = $end;
}
$bill->nextExpectedMatch = $repository->nextExpectedMatch($bill, $lastPaidDate);
$hideBill = true;
$subTitle = $bill->name;
return view('bills.show', compact('transactions', 'yearAverage', 'overallAverage', 'year', 'hideBill', 'bill', 'subTitle'));
return view('bills.show', compact('transactions', 'yearAverage', 'overallAverage', 'year', 'object','bill', 'subTitle'));
}
/**