mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Move method to correct repository.
This commit is contained in:
@@ -32,6 +32,7 @@ use FireflyIII\Models\BudgetLimit;
|
|||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use FireflyIII\Support\Http\Controllers\AugumentData;
|
use FireflyIII\Support\Http\Controllers\AugumentData;
|
||||||
@@ -55,6 +56,9 @@ class BudgetController extends Controller
|
|||||||
/** @var BudgetLimitRepositoryInterface */
|
/** @var BudgetLimitRepositoryInterface */
|
||||||
private $blRepository;
|
private $blRepository;
|
||||||
|
|
||||||
|
/** @var NoBudgetRepositoryInterface */
|
||||||
|
private $nbRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BudgetController constructor.
|
* BudgetController constructor.
|
||||||
*
|
*
|
||||||
@@ -70,6 +74,7 @@ class BudgetController extends Controller
|
|||||||
$this->repository = app(BudgetRepositoryInterface::class);
|
$this->repository = app(BudgetRepositoryInterface::class);
|
||||||
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
||||||
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
$this->nbRepository = app(NoBudgetRepositoryInterface::class);
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
}
|
}
|
||||||
@@ -453,7 +458,7 @@ class BudgetController extends Controller
|
|||||||
|
|
||||||
// the expenses:
|
// the expenses:
|
||||||
$periods = app('navigation')->listOfPeriods($start, $end);
|
$periods = app('navigation')->listOfPeriods($start, $end);
|
||||||
$entries = $this->repository->getNoBudgetPeriodReport($accounts, $start, $end);
|
$entries = $this->nbRepository->getNoBudgetPeriodReport($accounts, $start, $end);
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
|
|
||||||
// join them:
|
// join them:
|
||||||
|
@@ -26,6 +26,7 @@ use Carbon\Carbon;
|
|||||||
use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
|
use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
|
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
|
||||||
@@ -103,10 +104,13 @@ class BudgetController extends Controller
|
|||||||
/** @var OperationsRepositoryInterface $opsRepository */
|
/** @var OperationsRepositoryInterface $opsRepository */
|
||||||
$opsRepository= app(OperationsRepositoryInterface::class);
|
$opsRepository= app(OperationsRepositoryInterface::class);
|
||||||
|
|
||||||
|
/** @var NoBudgetRepositoryInterface $nbRepository */
|
||||||
|
$nbRepository = app(NoBudgetRepositoryInterface::class);
|
||||||
|
|
||||||
|
|
||||||
$budgets = $repository->getBudgets();
|
$budgets = $repository->getBudgets();
|
||||||
$data = $opsRepository->getBudgetPeriodReport($budgets, $accounts, $start, $end);
|
$data = $opsRepository->getBudgetPeriodReport($budgets, $accounts, $start, $end);
|
||||||
$noBudget = $repository->getNoBudgetPeriodReport($accounts, $start, $end); // append report data for "no budget"
|
$noBudget = $nbRepository->getNoBudgetPeriodReport($accounts, $start, $end); // append report data for "no budget"
|
||||||
$data = array_merge($data, $noBudget);
|
$data = array_merge($data, $noBudget);
|
||||||
$report = $this->filterPeriodReport($data);
|
$report = $this->filterPeriodReport($data);
|
||||||
|
|
||||||
|
@@ -242,52 +242,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array
|
|
||||||
{
|
|
||||||
$carbonFormat = Navigation::preferredCarbonFormat($start, $end);
|
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
|
|
||||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
|
||||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
|
||||||
$collector->withoutBudget();
|
|
||||||
$journals = $collector->getExtractedJournals();
|
|
||||||
$data = [];
|
|
||||||
|
|
||||||
/** @var array $journal */
|
|
||||||
foreach ($journals as $journal) {
|
|
||||||
$currencyId = (int)$journal['currency_id'];
|
|
||||||
|
|
||||||
$data[$currencyId] = $data[$currencyId] ?? [
|
|
||||||
'id' => 0,
|
|
||||||
'name' => sprintf('%s (%s)', trans('firefly.no_budget'), $journal['currency_name']),
|
|
||||||
'sum' => '0',
|
|
||||||
'currency_id' => $currencyId,
|
|
||||||
'currency_code' => $journal['currency_code'],
|
|
||||||
'currency_name' => $journal['currency_name'],
|
|
||||||
'currency_symbol' => $journal['currency_symbol'],
|
|
||||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
|
||||||
'entries' => [],
|
|
||||||
];
|
|
||||||
$date = $journal['date']->format($carbonFormat);
|
|
||||||
|
|
||||||
if (!isset($data[$currencyId]['entries'][$date])) {
|
|
||||||
$data[$currencyId]['entries'][$date] = '0';
|
|
||||||
}
|
|
||||||
$data[$currencyId]['entries'][$date] = bcadd($data[$currencyId]['entries'][$date], $journal['amount']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $query
|
* @param string $query
|
||||||
*
|
*
|
||||||
|
@@ -107,15 +107,6 @@ interface BudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getInactiveBudgets(): Collection;
|
public function getInactiveBudgets(): Collection;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection $accounts
|
|
||||||
* @param Carbon $start
|
|
||||||
* @param Carbon $end
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $query
|
* @param string $query
|
||||||
*
|
*
|
||||||
|
@@ -24,7 +24,11 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Budget;
|
namespace FireflyIII\Repositories\Budget;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +40,6 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
|||||||
/** @var User */
|
/** @var User */
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
@@ -48,6 +51,52 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array
|
||||||
|
{
|
||||||
|
$carbonFormat = app('navigation')->preferredCarbonFormat($start, $end);
|
||||||
|
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
|
||||||
|
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||||
|
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||||
|
$collector->withoutBudget();
|
||||||
|
$journals = $collector->getExtractedJournals();
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
/** @var array $journal */
|
||||||
|
foreach ($journals as $journal) {
|
||||||
|
$currencyId = (int)$journal['currency_id'];
|
||||||
|
|
||||||
|
$data[$currencyId] = $data[$currencyId] ?? [
|
||||||
|
'id' => 0,
|
||||||
|
'name' => sprintf('%s (%s)', trans('firefly.no_budget'), $journal['currency_name']),
|
||||||
|
'sum' => '0',
|
||||||
|
'currency_id' => $currencyId,
|
||||||
|
'currency_code' => $journal['currency_code'],
|
||||||
|
'currency_name' => $journal['currency_name'],
|
||||||
|
'currency_symbol' => $journal['currency_symbol'],
|
||||||
|
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||||
|
'entries' => [],
|
||||||
|
];
|
||||||
|
$date = $journal['date']->format($carbonFormat);
|
||||||
|
|
||||||
|
if (!isset($data[$currencyId]['entries'][$date])) {
|
||||||
|
$data[$currencyId]['entries'][$date] = '0';
|
||||||
|
}
|
||||||
|
$data[$currencyId]['entries'][$date] = bcadd($data[$currencyId]['entries'][$date], $journal['amount']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
|
@@ -24,7 +24,9 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Budget;
|
namespace FireflyIII\Repositories\Budget;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface NoBudgetRepositoryInterface
|
* Interface NoBudgetRepositoryInterface
|
||||||
@@ -35,4 +37,14 @@ interface NoBudgetRepositoryInterface
|
|||||||
* @param User $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
public function setUser(User $user): void;
|
public function setUser(User $user): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection $accounts
|
||||||
|
* @param Carbon $start
|
||||||
|
* @param Carbon $end
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||||
}
|
}
|
Reference in New Issue
Block a user