Clean up code.

This commit is contained in:
James Cole
2024-01-04 14:59:55 +01:00
parent 566bb2f097
commit 3a083f88b5
5 changed files with 12 additions and 18 deletions

View File

@@ -65,7 +65,7 @@ class BudgetController extends Controller
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);
$this->currency = app('amount')->getDefaultCurrency(); $this->currency = app('amount')->getDefaultCurrency();
$userGroup = $this->validateUserGroup($request); $userGroup = $this->validateUserGroup($request);
if (null !== $userGroup) { if (null !== $userGroup) {
$this->repository->setUserGroup($userGroup); $this->repository->setUserGroup($userGroup);
$this->opsRepository->setUserGroup($userGroup); $this->opsRepository->setUserGroup($userGroup);
@@ -77,18 +77,17 @@ class BudgetController extends Controller
} }
/** /**
* @throws FireflyException * TODO see autocomplete/accountcontroller
* TODO see autocomplete/accountcontroller.
*/ */
public function dashboard(DateRequest $request): JsonResponse public function dashboard(DateRequest $request): JsonResponse
{ {
$params = $request->getAll(); $params = $request->getAll();
/** @var Carbon $start */ /** @var Carbon $start */
$start = $params['start']; $start = $params['start'];
/** @var Carbon $end */ /** @var Carbon $end */
$end = $params['end']; $end = $params['end'];
// code from FrontpageChartGenerator, but not in separate class // code from FrontpageChartGenerator, but not in separate class
$budgets = $this->repository->getActiveBudgets(); $budgets = $this->repository->getActiveBudgets();
@@ -209,14 +208,14 @@ class BudgetController extends Controller
'overspent' => '0', 'overspent' => '0',
'native_overspent' => '0', 'native_overspent' => '0',
]; ];
$currentBudgetArray = $block['budgets'][$budgetId]; $currentBudgetArray = $block['budgets'][$budgetId];
// var_dump($return); // var_dump($return);
/** @var array $journal */ /** @var array $journal */
foreach ($currentBudgetArray['transaction_journals'] as $journal) { foreach ($currentBudgetArray['transaction_journals'] as $journal) {
// convert the amount to the native currency. // convert the amount to the native currency.
$rate = $converter->getCurrencyRate($this->currencies[$currencyId], $this->currency, $journal['date']); $rate = $converter->getCurrencyRate($this->currencies[$currencyId], $this->currency, $journal['date']);
$convertedAmount = bcmul($journal['amount'], $rate); $convertedAmount = bcmul($journal['amount'], $rate);
if ($journal['foreign_currency_id'] === $this->currency->id) { if ($journal['foreign_currency_id'] === $this->currency->id) {
$convertedAmount = $journal['foreign_amount']; $convertedAmount = $journal['foreign_amount'];
} }
@@ -259,7 +258,7 @@ class BudgetController extends Controller
private function processLimit(Budget $budget, BudgetLimit $limit): array private function processLimit(Budget $budget, BudgetLimit $limit): array
{ {
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
$end = clone $limit->end_date; $end = clone $limit->end_date;
$end->endOfDay(); $end->endOfDay();
$spent = $this->opsRepository->listExpenses($limit->start_date, $end, null, new Collection([$budget])); $spent = $this->opsRepository->listExpenses($limit->start_date, $end, null, new Collection([$budget]));
$limitCurrencyId = $limit->transaction_currency_id; $limitCurrencyId = $limit->transaction_currency_id;
@@ -277,7 +276,7 @@ class BudgetController extends Controller
$filtered[$currencyId] = $entry; $filtered[$currencyId] = $entry;
} }
} }
$result = $this->processExpenses($budget->id, $filtered, $limit->start_date, $end); $result = $this->processExpenses($budget->id, $filtered, $limit->start_date, $end);
if (1 === count($result)) { if (1 === count($result)) {
$compare = bccomp($limit->amount, app('steam')->positive($result[$limitCurrencyId]['spent'])); $compare = bccomp($limit->amount, app('steam')->positive($result[$limitCurrencyId]['spent']));
if (1 === $compare) { if (1 === $compare) {

View File

@@ -223,6 +223,7 @@ class CreateController extends Controller
public function store(RecurrenceFormRequest $request) public function store(RecurrenceFormRequest $request)
{ {
$data = $request->getAll(); $data = $request->getAll();
try { try {
$recurrence = $this->recurring->store($data); $recurrence = $this->recurring->store($data);
} catch (FireflyException $e) { } catch (FireflyException $e) {

View File

@@ -173,6 +173,7 @@ class EditController extends Controller
$request->session()->flash('success', (string)trans('firefly.updated_recurrence', ['title' => $recurrence->title])); $request->session()->flash('success', (string)trans('firefly.updated_recurrence', ['title' => $recurrence->title]));
Log::channel('audit')->info(sprintf('Updated recurrence #%d.', $recurrence->id), $data); Log::channel('audit')->info(sprintf('Updated recurrence #%d.', $recurrence->id), $data);
// store new attachment(s): // store new attachment(s):
/** @var null|array $files */ /** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;

View File

@@ -347,8 +347,6 @@ class General extends AbstractExtension
/** /**
* TODO Remove me when v2 hits. * TODO Remove me when v2 hits.
*
* @return TwigFunction
*/ */
protected function getMetaField(): TwigFunction protected function getMetaField(): TwigFunction
{ {

View File

@@ -200,11 +200,6 @@ class AccountTransformer extends AbstractTransformer
/** /**
* TODO refactor call to get~OpeningBalanceAmount / Date because it is a lot of queries * TODO refactor call to get~OpeningBalanceAmount / Date because it is a lot of queries
*
* @param Account $account
* @param string $accountType
*
* @return array
*/ */
private function getOpeningBalance(Account $account, string $accountType): array private function getOpeningBalance(Account $account, string $accountType): array
{ {