Clean up some code.

This commit is contained in:
James Cole 2020-10-13 06:35:33 +02:00
parent 3bd5ac21c9
commit 4e51f0abc4
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
33 changed files with 149 additions and 294 deletions

View File

@ -41,7 +41,6 @@ class AccountController extends Controller
use AccountFilter;
private array $balanceTypes;
private AccountRepositoryInterface $repository;
@ -76,16 +75,14 @@ class AccountController extends Controller
$query = $data['query'];
$date = $data['date'] ?? today(config('app.timezone'));
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$return = [];
$result = $repository->searchAccount((string) $query, $types, $data['limit']);
$result = $this->repository->searchAccount((string) $query, $types, $data['limit']);
$defaultCurrency = app('amount')->getDefaultCurrency();
/** @var Account $account */
foreach ($result as $account) {
$nameWithBalance = $account->name;
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
$currency = $this->repository->getAccountCurrency($account) ?? $defaultCurrency;
if (in_array($account->accountType->type, $this->balanceTypes, true)) {
$balance = app('steam')->balance($account, $date);

View File

@ -58,13 +58,10 @@ class BudgetController extends Controller
$this->middleware(
function ($request, $next) {
//$this->generator = app(GeneratorInterface::class);
$this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
//$this->nbRepository = app(NoBudgetRepositoryInterface::class);
return $next($request);
}
);
@ -195,7 +192,6 @@ class BudgetController extends Controller
{
foreach ($sets as $set) {
$label = $set['label'];
//$basic['spent']['entries'][$label] = $set['entries']['spent'];
$basic['spent_capped']['entries'][$label] = $set['entries']['spent_capped'];
$basic['left']['entries'][$label] = $set['entries']['left'];
$basic['overspent']['entries'][$label] = $set['entries']['overspent'];

View File

@ -46,14 +46,10 @@ class FixAccountTypes extends Command
* The name and signature of the console command.
* @var string
*/
protected $signature = 'firefly-iii:fix-account-types';
/** @var int */
private $count;
private array $expected;
/** @var AccountFactory */
private $factory;
/** @var array */
private $fixable;
protected $signature = 'firefly-iii:fix-account-types';
private int $count;
private array $expected;
private AccountFactory $factory;
/**
@ -65,19 +61,8 @@ class FixAccountTypes extends Command
{
$this->stupidLaravel();
Log::debug('Now in fix-account-types');
$start = microtime(true);
$this->factory = app(AccountFactory::class);
// some combinations can be fixed by this script:
$this->fixable = [// transfers from asset to liability and vice versa
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET),
// withdrawals with a revenue account as destination instead of an expense account.
sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE),
// deposits with an expense account as source instead of a revenue account.
sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET),];
$start = microtime(true);
$this->factory = app(AccountFactory::class);
$this->expected = config('firefly.source_dests');
$journals = TransactionJournal::with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accounttype'])->get();
Log::debug(sprintf('Found %d journals to inspect.', $journals->count()));
@ -203,10 +188,10 @@ class FixAccountTypes extends Command
*/
private function inspectJournal(TransactionJournal $journal): void
{
$count = $journal->transactions()->count();
if (2 !== $count) {
Log::debug(sprintf('Journal has %d transactions, so cant fix.', $count));
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $count));
$transactions = $journal->transactions()->count();
if (2 !== $transactions) {
Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions));
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions));
return;
}

View File

@ -44,8 +44,7 @@ class RenameMetaFields extends Command
*/
protected $signature = 'firefly-iii:rename-meta-fields';
/** @var int */
private $count;
private int $count;
/**
@ -93,9 +92,9 @@ class RenameMetaFields extends Command
*/
private function rename(string $original, string $update): void
{
$count = DB::table('journal_meta')
$total = DB::table('journal_meta')
->where('name', '=', $original)
->update(['name' => $update]);
$this->count += $count;
$this->count += $total;
}
}

View File

@ -98,8 +98,6 @@ class DecryptDatabase extends Command
} catch(JsonException $e) {
Log::error($e->getMessage());
}
//Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, print_r($value, true), $table, $id));
/** @var Preference $object */
$object = Preference::find((int) $id);
if (null !== $object) {
@ -110,7 +108,6 @@ class DecryptDatabase extends Command
}
if ($value !== $original) {
//Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, $value, $table, $id));
DB::table($table)->where('id', $id)->update([$field => $value]);
}
}

View File

@ -131,11 +131,11 @@ class ApplyRules extends Command
$ruleEngine->setUser($this->getUser());
// add the accounts as filter:
$accounts = [];
$filterAccountList = [];
foreach($this->accounts as $account) {
$accounts[] = $account->id;
$filterAccountList[] = $account->id;
}
$list = implode(',', $accounts);
$list = implode(',', $filterAccountList);
$ruleEngine->addOperator(['type' => 'account_id', 'value' => $list]);
// add the date as a filter:
@ -295,7 +295,7 @@ class ApplyRules extends Command
private function verifyInputDates(): void
{
// parse start date.
$startDate = Carbon::now()->startOfMonth();
$inputStart = Carbon::now()->startOfMonth();
$startString = $this->option('start_date');
if (null === $startString) {
/** @var JournalRepositoryInterface $repository */
@ -303,26 +303,26 @@ class ApplyRules extends Command
$repository->setUser($this->getUser());
$first = $repository->firstNull();
if (null !== $first) {
$startDate = $first->date;
$inputStart = $first->date;
}
}
if (null !== $startString && '' !== $startString) {
$startDate = Carbon::createFromFormat('Y-m-d', $startString);
$inputStart = Carbon::createFromFormat('Y-m-d', $startString);
}
// parse end date
$endDate = Carbon::now();
$inputEnd = Carbon::now();
$endString = $this->option('end_date');
if (null !== $endString && '' !== $endString) {
$endDate = Carbon::createFromFormat('Y-m-d', $endString);
$inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
}
if ($startDate > $endDate) {
[$endDate, $startDate] = [$startDate, $endDate];
if ($inputStart > $inputEnd) {
[$inputEnd, $inputStart] = [$inputStart, $inputEnd];
}
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->startDate = $inputStart;
$this->endDate = $inputEnd;
}
/**

View File

@ -72,8 +72,8 @@ class MigrateAttachments extends Command
foreach ($attachments as $att) {
// move description:
$description = (string) $att->description;
if ('' !== $description) {
$attDescription = (string) $att->description;
if ('' !== $attDescription) {
// find or create note:
$note = $att->notes()->first();
@ -81,7 +81,7 @@ class MigrateAttachments extends Command
$note = new Note;
$note->noteable()->associate($att);
}
$note->text = $description;
$note->text = $attDescription;
$note->save();
// clear description:

View File

@ -58,23 +58,18 @@ class MigrateToGroups extends Command
*
* @var string
*/
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
/** @var JournalCLIRepositoryInterface */
private $cliRepository;
private $count;
/** @var TransactionGroupFactory */
private $groupFactory;
/** @var JournalRepositoryInterface */
private $journalRepository;
/** @var JournalDestroyService */
private $service;
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
private JournalCLIRepositoryInterface $cliRepository;
private int $count;
private TransactionGroupFactory $groupFactory;
private JournalRepositoryInterface $journalRepository;
private JournalDestroyService $service;
/**
* Execute the console command.
*
* @throws Exception
* @return int
* @throws Exception
*/
public function handle(): int
{
@ -254,16 +249,16 @@ class MigrateToGroups extends Command
private function makeGroupsFromAll(): void
{
$orphanedJournals = $this->cliRepository->getJournalsWithoutGroup();
$count = count($orphanedJournals);
if ($count > 0) {
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $count));
$this->line(sprintf('Going to convert %d transaction journals. Please hold..', $count));
$total = count($orphanedJournals);
if ($total > 0) {
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total));
$this->line(sprintf('Going to convert %d transaction journals. Please hold..', $total));
/** @var array $journal */
foreach ($orphanedJournals as $array) {
$this->giveGroup($array);
}
}
if (0 === $count) {
if (0 === $total) {
$this->info('No need to convert transaction journals.');
}
}

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Factory;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException;
@ -56,26 +55,17 @@ class TransactionJournalFactory
{
use JournalServiceTrait;
private AccountRepositoryInterface $accountRepository;
private AccountValidator $accountValidator;
private BillRepositoryInterface $billRepository;
/** @var CurrencyRepositoryInterface */
private $currencyRepository;
/** @var bool */
private $errorOnHash;
/** @var array */
private $fields;
/** @var PiggyBankEventFactory */
private $piggyEventFactory;
/** @var PiggyBankRepositoryInterface */
private $piggyRepository;
/** @var TransactionFactory */
private $transactionFactory;
/** @var TransactionTypeRepositoryInterface */
private $typeRepository;
/** @var User The user */
private $user;
private AccountRepositoryInterface $accountRepository;
private AccountValidator $accountValidator;
private BillRepositoryInterface $billRepository;
private CurrencyRepositoryInterface $currencyRepository;
private bool $errorOnHash;
private array $fields;
private PiggyBankEventFactory $piggyEventFactory;
private PiggyBankRepositoryInterface $piggyRepository;
private TransactionFactory $transactionFactory;
private TransactionTypeRepositoryInterface $typeRepository;
private User $user;
/**
* Constructor.
@ -112,7 +102,6 @@ class TransactionJournalFactory
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
$this->typeRepository = app(TransactionTypeRepositoryInterface::class);
$this->transactionFactory = app(TransactionFactory::class);
$this->billRepository = app(BillRepositoryInterface::class);
$this->budgetRepository = app(BudgetRepositoryInterface::class);
$this->categoryRepository = app(CategoryRepositoryInterface::class);
@ -196,7 +185,6 @@ class TransactionJournalFactory
$this->user = $user;
$this->currencyRepository->setUser($this->user);
$this->tagFactory->setUser($user);
$this->transactionFactory->setUser($this->user);
$this->billRepository->setUser($this->user);
$this->budgetRepository->setUser($this->user);
$this->categoryRepository->setUser($this->user);
@ -329,7 +317,6 @@ class TransactionJournalFactory
Log::debug(sprintf('Created new journal #%d: "%s"', $journal->id, $journal->description));
/** Create two transactions. */
/** @var TransactionFactory $transactionFactory */
$transactionFactory = app(TransactionFactory::class);
$transactionFactory->setUser($this->user);
$transactionFactory->setJournal($journal);

View File

@ -39,11 +39,8 @@ use Illuminate\View\View;
*/
class CreateController extends Controller
{
/** @var CategoryRepositoryInterface The category repository */
private $repository;
/** @var AttachmentHelperInterface Helper for attachments. */
private $attachments;
private CategoryRepositoryInterface $repository;
private AttachmentHelperInterface $attachments;
/**
* CategoryController constructor.
@ -58,7 +55,7 @@ class CreateController extends Controller
function ($request, $next) {
app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class);
$this->repository = app(CategoryRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
return $next($request);
@ -107,7 +104,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($category, $files);
}
if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info',(string)trans('firefly.no_att_demo_user'));
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {

View File

@ -45,6 +45,7 @@ use Illuminate\Support\Collection;
class CategoryController extends Controller
{
use DateCalculation, AugumentData, ChartGeneration;
/** @var GeneratorInterface Chart generation methods. */
protected $generator;
@ -85,10 +86,10 @@ class CategoryController extends Controller
$start = app('navigation')->startOfPeriod($start, $range);
$end = $this->getDate();
/** @var WholePeriodChartGenerator $generator */
$generator = app(WholePeriodChartGenerator::class);
$chartData = $generator->generate($category, $start, $end);
$data = $this->generator->multiSet($chartData);
/** @var WholePeriodChartGenerator $chartGenerator */
$chartGenerator = app(WholePeriodChartGenerator::class);
$chartData = $chartGenerator->generate($category, $start, $end);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@ -111,14 +112,14 @@ class CategoryController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.category.frontpage');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get()); // @codeCoverageIgnore
}
$frontPageGenerator = new FrontpageChartGenerator($start, $end);
$chartData = $frontPageGenerator->generate();
$data = $this->generator->multiSet($chartData);
$chartData = $frontPageGenerator->generate();
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@ -210,13 +211,10 @@ class CategoryController extends Controller
return response()->json($cache->get()); // @codeCoverageIgnore
}
/** @var GeneratorInterface $generator */
$generator = app(GeneratorInterface::class);
/** @var WholePeriodChartGenerator $chartGenerator */
$chartGenerator = app(WholePeriodChartGenerator::class);
$chartData = $chartGenerator->generate($category, $start, $end);
$data = $generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Recurring;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller;
@ -45,12 +44,9 @@ use Illuminate\View\View;
*/
class CreateController extends Controller
{
/** @var BudgetRepositoryInterface The budget repository */
private $budgets;
/** @var RecurringRepositoryInterface Recurring repository */
private $recurring;
private AttachmentHelperInterface $attachments;
private BudgetRepositoryInterface $budgetRepos;
private RecurringRepositoryInterface $recurring;
private AttachmentHelperInterface $attachments;
/**
* CreateController constructor.
@ -69,7 +65,7 @@ class CreateController extends Controller
app('view')->share('subTitle', (string) trans('firefly.create_new_recurrence'));
$this->recurring = app(RecurringRepositoryInterface::class);
$this->budgets = app(BudgetRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
return $next($request);
@ -83,7 +79,7 @@ class CreateController extends Controller
*/
public function createFromJournal(Request $request, TransactionJournal $journal)
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$defaultCurrency = app('amount')->getDefaultCurrency();
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
@ -177,7 +173,7 @@ class CreateController extends Controller
*/
public function create(Request $request)
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$defaultCurrency = app('amount')->getDefaultCurrency();
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');

View File

@ -46,11 +46,9 @@ use Symfony\Component\HttpFoundation\ParameterBag;
*/
class EditController extends Controller
{
/** @var BudgetRepositoryInterface The budget repository */
private $budgets;
/** @var RecurringRepositoryInterface Recurring repository */
private $recurring;
private AttachmentHelperInterface $attachments;
private BudgetRepositoryInterface $budgetRepos;
private RecurringRepositoryInterface $recurring;
private AttachmentHelperInterface $attachments;
/**
* EditController constructor.
@ -69,7 +67,7 @@ class EditController extends Controller
app('view')->share('subTitle', (string) trans('firefly.recurrences'));
$this->recurring = app(RecurringRepositoryInterface::class);
$this->budgets = app(BudgetRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
return $next($request);
}
@ -82,9 +80,9 @@ class EditController extends Controller
* @param Request $request
* @param Recurrence $recurrence
*
* @return Factory|View
* @throws FireflyException
*
* @return Factory|View
*/
public function edit(Request $request, Recurrence $recurrence)
{
@ -93,7 +91,7 @@ class EditController extends Controller
$transformer->setParameters(new ParameterBag);
$array = $transformer->transform($recurrence);
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
/** @var RecurrenceRepetition $repetition */
$repetition = $recurrence->recurrenceRepetitions()->first();
@ -108,7 +106,7 @@ class EditController extends Controller
}
$request->session()->forget('recurrences.edit.fromUpdate');
$repetitionEnd = 'forever';
$repetitionEnd = 'forever';
$repetitionEnds = [
'forever' => (string) trans('firefly.repeat_forever'),
'until_date' => (string) trans('firefly.repeat_until_date'),
@ -129,7 +127,7 @@ class EditController extends Controller
];
$hasOldInput = null !== $request->old('_token');
$preFilled = [
$preFilled = [
'transaction_type' => strtolower($recurrence->transactionType->type),
'active' => $hasOldInput ? (bool) $request->old('active') : $recurrence->active,
'apply_rules' => $hasOldInput ? (bool) $request->old('apply_rules') : $recurrence->apply_rules,
@ -151,8 +149,8 @@ class EditController extends Controller
* @param RecurrenceFormRequest $request
* @param Recurrence $recurrence
*
* @throws FireflyException
* @return RedirectResponse|Redirector
* @throws FireflyException
*/
public function update(RecurrenceFormRequest $request, Recurrence $recurrence)
{

View File

@ -45,8 +45,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
class IndexController extends Controller
{
use GetConfigurationData;
/** @var RecurringRepositoryInterface Recurring repository */
private $recurring;
private RecurringRepositoryInterface $recurringRepos;
/**
* IndexController constructor.
@ -63,7 +62,7 @@ class IndexController extends Controller
app('view')->share('mainTitleIcon', 'fa-paint-brush');
app('view')->share('title', (string) trans('firefly.recurrences'));
$this->recurring = app(RecurringRepositoryInterface::class);
$this->recurringRepos = app(RecurringRepositoryInterface::class);
return $next($request);
}
@ -84,13 +83,12 @@ class IndexController extends Controller
{
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$collection = $this->recurring->get();
$collection = $this->recurringRepos->get();
$today = today(config('app.timezone'));
$year = today(config('app.timezone'));
// split collection
$total = $collection->count();
/** @var Collection $recurrences */
$recurrences = $collection->slice(($page - 1) * $pageSize, $pageSize);
/** @var RecurrenceTransformer $transformer */

View File

@ -26,7 +26,6 @@ use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
use FireflyIII\Support\CacheProperties;
@ -44,9 +43,8 @@ class CategoryController extends Controller
{
use BasicDataSupport;
/** @var OperationsRepositoryInterface */
private $opsRepository;
private OperationsRepositoryInterface $opsRepository;
private NoCategoryRepositoryInterface $noCatRepository;
/**
* ExpenseReportController constructor.
@ -58,8 +56,8 @@ class CategoryController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->noCatRepository = app(NoCategoryRepositoryInterface::class);
return $next($request);
}
);
@ -505,14 +503,6 @@ class CategoryController extends Controller
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
/** @var NoCategoryRepositoryInterface $noCatRepos */
$noCatRepos = app(NoCategoryRepositoryInterface::class);
// depending on the carbon format (a reliable way to determine the general date difference)
// change the "listOfPeriods" call so the entire period gets included correctly.
@ -527,8 +517,8 @@ class CategoryController extends Controller
$periods = app('navigation')->listOfPeriods($start, $end);
$data = [];
$with = $opsRepository->listExpenses($start, $end, $accounts);
$without = $noCatRepos->listExpenses($start, $end, $accounts);
$with = $this->opsRepository->listExpenses($start, $end, $accounts);
$without = $this->noCatRepository->listExpenses($start, $end, $accounts);
foreach ([$with, $without] as $set) {
foreach ($set as $currencyId => $currencyRow) {
foreach ($currencyRow['categories'] as $categoryId => $categoryRow) {
@ -594,12 +584,6 @@ class CategoryController extends Controller
return $cache->get(); // @codeCoverageIgnore
}
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
/** @var NoCategoryRepositoryInterface $noCatRepos */
$noCatRepos = app(NoCategoryRepositoryInterface::class);
// depending on the carbon format (a reliable way to determine the general date difference)
// change the "listOfPeriods" call so the entire period gets included correctly.
$format = app('navigation')->preferredCarbonFormat($start, $end);
@ -613,8 +597,8 @@ class CategoryController extends Controller
$periods = app('navigation')->listOfPeriods($start, $end);
$data = [];
$with = $opsRepository->listIncome($start, $end, $accounts);
$without = $noCatRepos->listIncome($start, $end, $accounts);
$with = $this->opsRepository->listIncome($start, $end, $accounts);
$without = $this->noCatRepository->listIncome($start, $end, $accounts);
foreach ([$with, $without] as $set) {
foreach ($set as $currencyId => $currencyRow) {
foreach ($currencyRow['categories'] as $categoryId => $categoryRow) {
@ -677,19 +661,13 @@ class CategoryController extends Controller
$cache->addProperty('category-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
// return $cache->get(); // @codeCoverageIgnore
return $cache->get(); // @codeCoverageIgnore
}
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
/** @var NoCategoryRepositoryInterface $noCatRepository */
$noCatRepository = app(NoCategoryRepositoryInterface::class);
$earnedWith = $opsRepository->listIncome($start, $end, $accounts);
$spentWith = $opsRepository->listExpenses($start, $end, $accounts);
$earnedWithout = $noCatRepository->listIncome($start, $end, $accounts);
$spentWithout = $noCatRepository->listExpenses($start, $end, $accounts);
$earnedWith = $this->opsRepository->listIncome($start, $end, $accounts);
$spentWith = $this->opsRepository->listExpenses($start, $end, $accounts);
$earnedWithout = $this->noCatRepository->listIncome($start, $end, $accounts);
$spentWithout = $this->noCatRepository->listExpenses($start, $end, $accounts);
$report = [
'categories' => [],

View File

@ -43,11 +43,8 @@ class TagController extends Controller
{
use PeriodOverview;
/** @var TagRepositoryInterface The tag repository. */
protected $repository;
/** @var AttachmentHelperInterface Helper for attachments. */
private $attachments;
protected TagRepositoryInterface $repository;
private AttachmentHelperInterface $attachmentsHelper;
/**
* TagController constructor.
@ -62,7 +59,7 @@ class TagController extends Controller
app('view')->share('title', (string) trans('firefly.tags'));
app('view')->share('mainTitleIcon', 'fa-tag');
$this->attachments = app(AttachmentHelperInterface::class);
$this->attachmentsHelper = app(AttachmentHelperInterface::class);
$this->repository = app(TagRepositoryInterface::class);
return $next($request);
@ -323,14 +320,14 @@ class TagController extends Controller
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($result, $files);
$this->attachmentsHelper->saveAttachmentsForModel($result, $files);
}
if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info',(string)trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore
if (count($this->attachmentsHelper->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachmentsHelper->getMessages()->get('attachments')); // @codeCoverageIgnore
}
@ -366,14 +363,14 @@ class TagController extends Controller
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($tag, $files);
$this->attachmentsHelper->saveAttachmentsForModel($tag, $files);
}
if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info',(string)trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore
if (count($this->attachmentsHelper->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachmentsHelper->getMessages()->get('attachments')); // @codeCoverageIgnore
}

View File

@ -81,9 +81,9 @@ class BulkController extends Controller
// make amounts positive.
// get list of budgets:
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$budgetList = app('expandedform')->makeSelectListWithEmpty($repository->getActiveBudgets());
/** @var BudgetRepositoryInterface $budgetRepos */
$budgetRepos = app(BudgetRepositoryInterface::class);
$budgetList = app('expandedform')->makeSelectListWithEmpty($budgetRepos->getActiveBudgets());
return view('transactions.bulk.edit', compact('journals', 'subTitle', 'budgetList'));
}

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Transaction;
use Carbon\Carbon;
use Exception;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
@ -43,7 +42,6 @@ use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Log;
use View;
/**
* Class ConvertController.
@ -55,6 +53,7 @@ class ConvertController extends Controller
use ModelInformation, UserNavigation;
private JournalRepositoryInterface $repository;
private AccountRepositoryInterface $accountRepository;
/**
* ConvertController constructor.
@ -68,8 +67,8 @@ class ConvertController extends Controller
// some useful repositories:
$this->middleware(
function ($request, $next) {
$this->repository = app(JournalRepositoryInterface::class);
$this->repository = app(JournalRepositoryInterface::class);
$this->accountRepository = app(AccountRepositoryInterface::class);
app('view')->share('title', (string) trans('firefly.transactions'));
app('view')->share('mainTitleIcon', 'fa-exchange');
@ -85,9 +84,9 @@ class ConvertController extends Controller
* @param TransactionType $destinationType
* @param TransactionGroup $group
*
* @return RedirectResponse|Redirector|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws Exception
*
* @return RedirectResponse|Redirector|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(TransactionType $destinationType, TransactionGroup $group)
{
@ -151,9 +150,9 @@ class ConvertController extends Controller
* @param TransactionType $destinationType
* @param TransactionGroup $group
*
* @throws FireflyException
* @return RedirectResponse|Redirector
*
* @throws FireflyException
*/
public function postIndex(Request $request, TransactionType $destinationType, TransactionGroup $group)
{
@ -188,8 +187,8 @@ class ConvertController extends Controller
* @param TransactionType $transactionType
* @param array $data
*
* @throws FireflyException
* @return TransactionJournal
* @throws FireflyException
*/
private function convertJournal(TransactionJournal $journal, TransactionType $transactionType, array $data): TransactionJournal
{
@ -245,23 +244,23 @@ class ConvertController extends Controller
}
/**
* @throws Exception
* @return array
* @throws Exception
*/
private function getAssetAccounts(): array
{
// make repositories
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$accountList = $repository->getActiveAccountsByType([AccountType::ASSET]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountList = $accountRepository->getActiveAccountsByType([AccountType::ASSET]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string) $repository->getMetaValue($account, 'account_role');
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string) $accountRepository->getMetaValue($account, 'account_role');
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore
}
@ -274,22 +273,22 @@ class ConvertController extends Controller
}
/**
* @throws Exception
* @return array
* @throws Exception
*/
private function getLiabilities(): array
{
// make repositories
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$accountList = $repository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountList = $accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = 'l_' . $account->accountType->type;
$key = (string) trans('firefly.opt_group_' . $role);
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
@ -304,16 +303,16 @@ class ConvertController extends Controller
private function getValidDepositSources(): array
{
// make repositories
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $repository
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
$accountList = $accountRepository
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$grouped = [];
$grouped = [];
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string) $repository->getMetaValue($account, 'account_role');
$role = (string) $accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type'; // @codeCoverageIgnore

View File

@ -282,10 +282,8 @@ class CreateRecurringTransactions implements ShouldQueue
*/
private function handleOccurrence(Recurrence $recurrence, RecurrenceRepetition $repetition, Carbon $date): ?TransactionGroup
{
#Log::debug(sprintf('Now at date %s.', $date->format('Y-m-d')));
$date->startOfDay();
if ($date->ne($this->date)) {
#Log::debug(sprintf('%s is not today (%s)', $date->format('Y-m-d'), $this->date->format('Y-m-d')));
return null;
}

View File

@ -196,7 +196,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
}
// currency of the account + the piggy bank currency are almost the same.
// which amount from the transaction matches?
// $currency->id === $piggyBankCurrency->id
$amount = null;
if ((int)$source->transaction_currency_id === (int)$currency->id) {
Log::debug('Use normal amount');

View File

@ -89,7 +89,6 @@ class RecurrenceUpdateService
$recurrence->save();
// update all meta data:
//$this->updateMetaData($recurrence, $data);
if (isset($data['recurrence']['notes']) && null !== $data['recurrence']['notes']) {
$this->setNoteText($recurrence, $data['recurrence']['notes']);

View File

@ -311,7 +311,6 @@ class Amount
$currencyPrefStr = $currencyPreference ? $currencyPreference->data : 'EUR';
// at this point the currency preference could be encrypted, if coming from an old version.
//Log::debug('Going to try to decrypt users currency preference.');
$currencyCode = $this->tryDecrypt((string) $currencyPrefStr);
// could still be json encoded:
@ -351,7 +350,6 @@ class Amount
try {
$value = Crypt::decrypt($value); // verified
} catch (DecryptException $e) {
//Log::debug(sprintf('Could not decrypt "%s". %s', $value, $e->getMessage()));
}
return $value;

View File

@ -69,7 +69,6 @@ class BudgetList implements BinderInterface
// add empty budget if applicable.
if (in_array(0, $list, true)) {
//Log::debug('Add empty budget because $list contains 0.');
$collection->push(new Budget);
}

View File

@ -87,8 +87,6 @@ class FireflyConfig
/** @var Configuration $config */
$config = Configuration::where('name', $name)->first(['id', 'name', 'data']);
} catch (QueryException|Exception $e) {
//Log::error(sprintf('Query exception while polling for config var: %s', $e->getMessage()));
//Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not poll the database: %s', $e->getMessage()));
}
@ -156,7 +154,6 @@ class FireflyConfig
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
}
//Log::debug('Set new value for ', ['name' => $name]);
/** @var Configuration $config */
try {
$config = Configuration::whereName($name)->first();
@ -168,7 +165,6 @@ class FireflyConfig
return $item;
}
if (null === $config) {
//Log::debug('Does not exist yet ', ['name' => $name]);
/** @var Configuration $item */
$item = new Configuration;
$item->name = $name;
@ -179,7 +175,6 @@ class FireflyConfig
return $item;
}
//Log::debug('Exists already, overwrite value.', ['name' => $name]);
$config->data = $value;
$config->save();
Cache::forget('ff-config-' . $name);

View File

@ -46,11 +46,8 @@ trait CalculateRangeOccurrences
{
$return = [];
$attempts = 0;
#Log::debug('Rep is daily. Start of loop.');
while ($start <= $end) {
#Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
if (0 === $attempts % $skipMod) {
#Log::debug(sprintf('Attempts modulo skipmod is zero, include %s', $start->format('Y-m-d')));
$return[] = clone $start;
}
$start->addDay();
@ -77,27 +74,14 @@ trait CalculateRangeOccurrences
$return = [];
$attempts = 0;
$dayOfMonth = (int)$moment;
#Log::debug(sprintf('Day of month in repetition is %d', $dayOfMonth));
#Log::debug(sprintf('Start is %s.', $start->format('Y-m-d')));
#Log::debug(sprintf('End is %s.', $end->format('Y-m-d')));
if ($start->day > $dayOfMonth) {
#Log::debug('Add a month.');
// day has passed already, add a month.
$start->addMonth();
}
#Log::debug(sprintf('Start is now %s.', $start->format('Y-m-d')));
#Log::debug('Start loop.');
while ($start < $end) {
#Log::debug(sprintf('Mutator is now %s.', $start->format('Y-m-d')));
$domCorrected = min($dayOfMonth, $start->daysInMonth);
#Log::debug(sprintf('DoM corrected is %d', $domCorrected));
$start->day = $domCorrected;
#Log::debug(sprintf('Mutator is now %s.', $start->format('Y-m-d')));
#Log::debug(sprintf('$attempts %% $skipMod === 0 is %s', var_export(0 === $attempts % $skipMod, true)));
#Log::debug(sprintf('$start->lte($mutator) is %s', var_export($start->lte($start), true)));
#Log::debug(sprintf('$end->gte($mutator) is %s', var_export($end->gte($start), true)));
if (0 === $attempts % $skipMod && $start->lte($start) && $end->gte($start)) {
#Log::debug(sprintf('ADD %s to return!', $start->format('Y-m-d')));
$return[] = clone $start;
}
$attempts++;

View File

@ -240,7 +240,6 @@ class AccountTransformer extends AbstractTransformer
$openingBalance = null;
$openingBalanceDate = null;
if (in_array($accountType, ['asset', 'liabilities'], true)) {
//$journal = $this->repository->getOpeningBalance($account);
$amount = $this->repository->getOpeningBalanceAmount($account);
$openingBalance = $amount;
$openingBalanceDate = $this->repository->getOpeningBalanceDate($account);

View File

@ -53,7 +53,7 @@ trait ReconciliationValidation
return false;
}
// $types depends on type of source:
// types depends on type of source:
$types = [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE];
// if source is reconciliation, destination can't be.
if (null !== $this->source && AccountType::RECONCILIATION === $this->source->accountType->type) {

View File

@ -103,7 +103,7 @@ function updateBudgetedAmount(e) {
updateTotalBudgetedAmount(data.transaction_currency_id);
}).fail(function () {
alert('I failed :(');
console.error('I failed :(');
});
} else {
$.post(updateBudgetLimitUri.replace('REPLACEME', budgetLimitId.toString()), {
@ -119,7 +119,7 @@ function updateBudgetedAmount(e) {
// update budgeted amount
}).fail(function () {
alert('I failed :(');
console.error('I failed :(');
});
}
}

View File

@ -70,7 +70,7 @@ $(function () {
}).done(function () {
window.location.reload(true);
}).fail(function () {
alert('Could not change date range');
console.error('Could not change date range');
});
}
);

View File

@ -53,7 +53,7 @@ function enableGuidance(route, specialPage) {
$.post('json/intro/enable/' + route + '/' + specialPage, {_token: token}).done(function (data) {
alert(data.message);
}).fail(function () {
alert('Could not re-enable introduction.');
console.error('Could not re-enable introduction.');
});
}

View File

@ -18,7 +18,7 @@
<li role="presentation">
<a href="#cmd" aria-controls="profile" role="tab" data-toggle="tab">{{ 'command_line_token'|_ }}</a>
</li>
{% if false == externalIdentity %}
{% if false == isExternalIdentity %}
<li role="presentation">
<a href="#oauth" aria-controls="messages" role="tab" data-toggle="tab">{{ 'oauth'|_ }}</a>
</li>
@ -42,7 +42,7 @@
<div class="row">
<div class="col-lg-6">
<ul>
{% if false == externalIdentity %}
{% if false == isExternalIdentity %}
<li>
<a href="{{ route('profile.change-email') }}">{{ 'change_your_email'|_ }}</a>
</li>
@ -52,7 +52,7 @@
{% endif %}
<li><a href="{{ route('logout') }}">{{ 'logout'|_ }}</a></li>
{% if false == externalIdentity %}
{% if false == isExternalIdentity %}
<li>
<a href="{{ route('profile.logout-others') }}">{{ 'logout_other_sessions'|_ }}</a>
</li>
@ -93,7 +93,7 @@
</div>
</div>
{% if false == externalIdentity %}
{% if false == isExternalIdentity %}
<!-- OAuth -->
<div role="tabpanel" class="tab-pane" id="oauth">
<div id="passport_clients"></div>

View File

@ -240,18 +240,6 @@ Route::group(
}
);
//// Bills
//Route::group(
// ['namespace' => 'FireflyIII\Api\V1\Controllers\Chart', 'prefix' => 'chart/bill',
// 'as' => 'api.v1.chart.bill.',],
// static function () {
//
// // Overview API routes:
// // Route::get('overview', ['uses' => 'BillController@overview', 'as' => 'overview']);
// }
//);
// Configuration
Route::group(
['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'configuration',

View File

@ -78,10 +78,10 @@ Route::group(
}
);
///**
// * For the two factor routes, the user must be logged in, but NOT 2FA. Account confirmation does not matter here.
// *
// */
/**
* For the two factor routes, the user must be logged in, but NOT 2FA. Account confirmation does not matter here.
*
*/
Route::group(
['middleware' => 'user-logged-in-no-2fa', 'prefix' => 'two-factor', 'as' => 'two-factor.', 'namespace' => 'FireflyIII\Http\Controllers\Auth'],
static function () {
@ -603,11 +603,6 @@ Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'json', 'as' => 'json.'],
static function () {
// for auto complete
// Route::get('transaction-journals/all', ['uses' => 'Json\AutoCompleteController@allJournals', 'as' => 'autocomplete.all-journals']);
// Route::get('transaction-journals/with-id', ['uses' => 'Json\AutoCompleteController@allJournalsWithID', 'as' => 'autocomplete.all-journals-with-id']);
// Route::get('currency-names', ['uses' => 'Json\AutoCompleteController@currencyNames', 'as' => 'autocomplete.currency-names']);
// budgets:
Route::get(
'budget/total-budgeted/{currency}/{start_date}/{end_date}',
@ -909,8 +904,6 @@ Route::group(
// index controller
Route::get('', ['uses' => 'Rule\IndexController@index', 'as' => 'index']);
//Route::get('up/{rule}', ['uses' => 'Rule\IndexController@up', 'as' => 'up']);
//Route::get('down/{rule}', ['uses' => 'Rule\IndexController@down', 'as' => 'down']);
Route::post('move-rule/{rule}/{ruleGroup}', ['uses' => 'Rule\IndexController@moveRule', 'as' => 'move-rule']);
@ -1044,20 +1037,6 @@ Route::group(
}
);
/**
* Transaction Split Controller.
*/
//Route::group(
// ['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers\Transaction', 'prefix' => 'transactions/split',
// 'as' => 'transactions.split.'], static function () {
// // TODO improve these routes
// Route::get('edit/{tj}', ['uses' => 'SplitController@edit', 'as' => 'edit']);
// Route::post('update/{tj}', ['uses' => 'SplitController@update', 'as' => 'update']);
// // TODO end of todo.
//
//}
//);
/**
* Transaction Convert Controller.
*/