Move some methods around, refactoring.

This commit is contained in:
James Cole
2016-10-09 07:58:27 +02:00
parent ea7ee7ee9a
commit c64771b76b
19 changed files with 207 additions and 343 deletions

View File

@@ -17,7 +17,7 @@ namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Report\ReportChartGeneratorInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
use Illuminate\Support\Collection;
use Navigation;
@@ -92,15 +92,16 @@ class ReportController extends Controller
/**
* @param AccountRepositoryInterface $repository
* @param string $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param AccountTaskerInterface $accountTasker
* @param string $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return \Illuminate\Http\JsonResponse
* @internal param AccountRepositoryInterface $repository
*/
public function yearInOut(AccountRepositoryInterface $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
public function yearInOut(AccountTaskerInterface $accountTasker, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache:
$cache = new CacheProperties;
@@ -120,8 +121,8 @@ class ReportController extends Controller
while ($currentStart <= $end) {
$currentEnd = Navigation::endOfPeriod($currentStart, '1M');
$date = $currentStart->format('Y-m');
$spent = $repository->spentInPeriod($accounts, $currentStart, $currentEnd);
$earned = $repository->earnedInPeriod($accounts, $currentStart, $currentEnd);
$spent = $accountTasker->amountOutInPeriod($accounts, $accounts, $currentStart, $currentEnd);
$earned = $accountTasker->amountInInPeriod($accounts, $accounts, $currentStart, $currentEnd);
$spentArray[$date] = bcmul($spent, '-1');
$earnedArray[$date] = $earned;
$currentStart = Navigation::addPeriod($currentStart, '1M', 0);
@@ -145,15 +146,16 @@ class ReportController extends Controller
}
/**
* @param AccountRepositoryInterface $repository
* @param string $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param AccountTaskerInterface $accountTasker
* @param string $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return \Illuminate\Http\JsonResponse
* @internal param AccountRepositoryInterface $repository
*/
public function yearInOutSummarized(AccountRepositoryInterface $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
public function yearInOutSummarized(AccountTaskerInterface $accountTasker, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache:
@@ -174,8 +176,8 @@ class ReportController extends Controller
while ($currentStart <= $end) {
$currentEnd = Navigation::endOfPeriod($currentStart, '1M');
$date = $currentStart->format('Y-m');
$spent = $repository->spentInPeriod($accounts, $currentStart, $currentEnd);
$earned = $repository->earnedInPeriod($accounts, $currentStart, $currentEnd);
$spent = $accountTasker->amountOutInPeriod($accounts, $accounts, $currentStart, $currentEnd);
$earned = $accountTasker->amountInInPeriod($accounts, $accounts, $currentStart, $currentEnd);
$spentArray[$date] = bcmul($spent, '-1');
$earnedArray[$date] = $earned;
$currentStart = Navigation::addPeriod($currentStart, '1M', 0);