Move method to correct repository.

This commit is contained in:
James Cole
2019-08-30 08:00:52 +02:00
parent 1da4597f94
commit 97d87b0657
9 changed files with 110 additions and 91 deletions

View File

@@ -36,6 +36,7 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\User;
@@ -47,6 +48,8 @@ use Illuminate\Support\Collection;
*/
class SummaryController extends Controller
{
/** @var AvailableBudgetRepositoryInterface */
private $abRepository;
/** @var AccountRepositoryInterface */
private $accountRepository;
/** @var BillRepositoryInterface */
@@ -58,6 +61,7 @@ class SummaryController extends Controller
/**
* SummaryController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
@@ -71,11 +75,13 @@ class SummaryController extends Controller
$this->billRepository = app(BillRepositoryInterface::class);
$this->budgetRepository = app(BudgetRepositoryInterface::class);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->billRepository->setUser($user);
$this->currencyRepos->setUser($user);
$this->budgetRepository->setUser($user);
$this->accountRepository->setUser($user);
$this->abRepository->setUser($user);
return $next($request);
@@ -140,6 +146,25 @@ class SummaryController extends Controller
return $result;
}
/**
* This method will scroll through the results of the spentInPeriodMc() array and return the correct info.
*
* @param array $spentInfo
* @param TransactionCurrency $currency
*
* @return float
*/
private function findInSpentArray(array $spentInfo, TransactionCurrency $currency): float
{
foreach ($spentInfo as $array) {
if ($array['currency_id'] === $currency->id) {
return $array['amount'];
}
}
return 0.0; // @codeCoverageIgnore
}
/**
* @param Carbon $start
* @param Carbon $end
@@ -316,7 +341,7 @@ class SummaryController extends Controller
{
$return = [];
$today = new Carbon;
$available = $this->budgetRepository->getAvailableBudgetWithCurrency($start, $end);
$available = $this->abRepository->getAvailableBudgetWithCurrency($start, $end);
$budgets = $this->budgetRepository->getActiveBudgets();
$spentInfo = $this->budgetRepository->spentInPeriodMc($budgets, new Collection, $start, $end);
foreach ($available as $currencyId => $amount) {
@@ -350,25 +375,6 @@ class SummaryController extends Controller
return $return;
}
/**
* This method will scroll through the results of the spentInPeriodMc() array and return the correct info.
*
* @param array $spentInfo
* @param TransactionCurrency $currency
*
* @return float
*/
private function findInSpentArray(array $spentInfo, TransactionCurrency $currency): float
{
foreach ($spentInfo as $array) {
if ($array['currency_id'] === $currency->id) {
return $array['amount'];
}
}
return 0.0; // @codeCoverageIgnore
}
/**
* @param Carbon $start
* @param Carbon $end